webgl_rxdz_test.vue 98 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612
  1. <template src="./webgl_rxdz_test.html"></template>
  2. <script>
  3. import * as THREE from 'three';
  4. import Stats from 'three/addons/libs/stats.module.js';
  5. import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
  6. import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
  7. import spaceTypes from '@/static/spaceTypesIE.js';
  8. import TWEEN from 'three/addons/libs/tween.module.js';
  9. import router from "@/router";
  10. import {
  11. setStorage,
  12. getStorage,
  13. } from '@/utils/localStorage';
  14. var requestId = "";
  15. const util = require('@/utils/util.js').default;
  16. // const config = require('@/services/urlConfig.js');
  17. import wallType from '@/static/wallData.js';
  18. // import modelData from '@/webgl/static/layoutModelData.js';
  19. // import requestConfig from '@/services/requestConfig.js';
  20. // import viewShell from'@/webgl/components/newBottomCom/viewShell/viewShell.vue';
  21. // import * as BufferGeometryUtils from '@/webgl/jsm/utils/BufferGeometryUtils.js';
  22. import screenshot from '@/mixins/screenshot.js';
  23. import floorMethod from '@/mixins/floorMethod.js';
  24. import wallMethod from '@/mixins/wallMethod.js';
  25. import loadModel from '@/mixins/loadModel.js';
  26. import commonPageMethod from '@/mixins/commonPageMethod.js';
  27. import viewShell from'@/components/newBottomCom/viewShell/viewShell.vue';
  28. export default {
  29. name:"webgl_rxdz",
  30. components:{viewShell},
  31. mixins:[screenshot,floorMethod,wallMethod,loadModel,commonPageMethod],
  32. /**
  33. * 页面的初始数据
  34. */
  35. data() {
  36. return {
  37. pvCurPageName: "home_show",
  38. locusBehaviorName: "主界面",
  39. pvCurPageParams: null,
  40. houseId: "",
  41. pvId: 'p_2cmina_23080401',
  42. canvas:null,
  43. navbar: {
  44. showCapsule: 0,
  45. title: '空间定制',
  46. titleColor: '#000',
  47. navPadding: 0,
  48. navPaddingBg:'transparent',
  49. navBarColor: 'transparent',
  50. navBackColor: 'transparent',
  51. haveCallback: false,
  52. fromShare: false,
  53. fromProject: 0,
  54. shareToken: "",
  55. pageName: this.pvCurPageName,
  56. },
  57. id:'232',// 户型编号
  58. spaceList:[], // 空间列表
  59. spaceListBackup:[], // 空间列表原始尺寸备份,用于墙体比例计算
  60. gltfSpaces:[], // 场景中地板模型数组
  61. gltfSpaceRoofs:[], // 屋顶模型数组
  62. curSpaceObj:null, // 当前选中的空间
  63. // curSpaceIndex:-1, // 当前选中的空间索引
  64. curWallDirection:"", // 当前选中的墙面
  65. curWallValue:0, // 当前墙面的滑动值
  66. curWallMaxValue:300,
  67. curWallHidden:false, // 当前墙面的状态
  68. wallIds:[], // 空间墙体id
  69. wallList:[], // 墙体数据
  70. gltfWalls:[], // 场景中墙体模型数组
  71. gltfAutoWalls:[],// 空间自动补墙模型数组
  72. // lastWallPosition:0, // 当面墙中墙体模型的开始位置
  73. tempSpaceList:[],// 全部空间临时数组,寻找关联空间,递归使用
  74. leftSpaces:[], // 移动空间左边数组
  75. rightSpaces:[],// 移动空间右边数组
  76. changeSpaces:[],// 尺寸变化涉及到的全部空间
  77. loader:null,
  78. scene:null,
  79. sky:null,
  80. camera:null,
  81. houseList:[], //当前户型所有的户型详情,可以切换
  82. curHouseType: null, //当前选中的户型类型
  83. curHouseName:'',//当前选中的户型类型名称
  84. curHouseFloor: null, //当前选中的户型楼层
  85. curHouseObj: null,
  86. controlStarPosition : { x:0, y:0, z:0}, //控制器初始位置
  87. cameraStarPosition : { x:0, y:30, z:0} ,//摄像头初始位置
  88. // cameraLastPosition: null, //摄像头上一次移动到的位置
  89. // controlLastPosition: null, //观察点上一次移动到的位置
  90. canvasHeight:200, //canvas视图的高度-计算得出
  91. chooseMesh:null,//标记鼠标拾取到的mesh
  92. // chooseMeshColor:'', //拾取到的mesh的原始颜色;
  93. chooseWallMeshColor:'', // 拾取墙体原始颜色
  94. curWallArr:[], // 当前空间选中墙面的墙体模型
  95. isManyou: false, //当前是否处在漫游状态
  96. pageShowIndex: 2, // 默认户型列表页面
  97. aleadyLoaderModel:[], //已经加载的墙体元数据模型列表
  98. // fontLabelGroup: [],
  99. shottingImg: [],
  100. progress:1, //进度条
  101. myLoadingStatus:false,
  102. // textGeoList:[],
  103. repeatFlag:false, //重复点击
  104. skyPlan: null, // 天空盒子
  105. instancedMeshList: [],
  106. lableItem:[],
  107. showLables:false,
  108. loadOver:false,
  109. voiceMaskShow:false, //录音时的蒙层是否显示
  110. minspace1: null,
  111. minspace2: null,
  112. minspace3: null,
  113. minspace4 : null,
  114. spaces1 : [],
  115. spaces2 : [],
  116. spaces3 : [],
  117. spaces4 : [],
  118. layoutIds:[], // 空间墙体id
  119. layoutLists:[], // 墙体数据
  120. gltfLayouts:[], // 场景中墙体模型数组
  121. screenshotResolve:null,
  122. curLayoutStruct:null,//当前户型大类下所有楼层数据-用于提交
  123. overChange:false, //是否形变中
  124. isIOS:false, //是否ios手机。默认不是
  125. currentChangeSpaceId:null, //当前变化的空间id
  126. styleType:1,
  127. sumArea:0, //总面积
  128. changeArea:0, //当次变化的面积
  129. fixedArea:0, //初始面积值
  130. layoutArea:0, //总面积
  131. selectSpace:null,//
  132. }
  133. },
  134. beforeDestroy() {
  135. cancelAnimationFrame(requestId, this.canvas)
  136. this.worker && this.worker.terminate()
  137. if (this.renderer instanceof THREE.WebGLRenderer) {
  138. // 遍历场景中的所有子对象,找到类型为Mesh的对象并移除
  139. let deleList = this.scene.children.filter(object=>{
  140. if (object instanceof THREE.Mesh) {
  141. return object
  142. }
  143. })
  144. if(deleList && deleList.length>0){
  145. this.scene.remove(...deleList);
  146. }
  147. this.scene.traverse(function(object) {
  148. if (object instanceof THREE.Mesh) {
  149. if(object.geometry && typeof(object.geometry.dispose)=='function'){
  150. object.geometry.dispose();
  151. }
  152. if(object.material && typeof(object.material.dispose)=='function'){
  153. object.material.dispose();
  154. }
  155. if(object.texture && typeof(object.texture.dispose)=='function'){
  156. object.texture.dispose();
  157. }
  158. }
  159. });
  160. this.renderer.clear();
  161. this.renderer.dispose();
  162. this.renderer.forceContextLoss();
  163. this.renderer.context = null;
  164. this.renderer.domElement = null;
  165. this.renderer = null;;
  166. this.clearEvent()
  167. }
  168. this.gltfWalls = [];
  169. this.gltfSpaces = [];
  170. this.gltfSpaceRoofs = [];
  171. this.gltfLayouts = [];
  172. this.instancedMeshList = [];
  173. this.instancedSpaceMeshList = [];
  174. this.lableItem = [];
  175. this.instancedFurList = [];
  176. this.wallList = [];
  177. TWEEN && TWEEN.removeAll();//清除所有的tween;
  178. console.warn("***beforeDestroy-webgl_rxdz***");
  179. },
  180. mounted() {
  181. console.log("***onLoad-webgl_rxdz_test***", this.$route.query,this.$store.state.houseId);
  182. let isIOS = !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
  183. this.isIOS = isIOS;
  184. var that = this;
  185. this.houseId = this.$store.state.houseId || '';
  186. if(true){
  187. this.curHouseObj = JSON.parse(getStorage('curHouseObj'));
  188. }else{
  189. this.curHouseObj = JSON.parse(JSON.stringify(this.$store.state.curHouseObj));
  190. }
  191. console.warn("***this.curHouseObj***",this.curHouseObj)
  192. let screenWidth = window.screen.width;
  193. let screenHeight = window.screen.height;
  194. if(window.innerWidth && window.screen.width){
  195. screenWidth = Math.min(window.innerWidth,window.screen.width)
  196. }
  197. if(window.innerHeight && window.screen.height){
  198. screenHeight = Math.min(window.innerHeight,window.screen.height)
  199. }
  200. let unit = screenWidth / 750;//单位rpm 对应 px 的值
  201. that.canvasHeight = screenHeight - (200 * unit) + (20 * unit);
  202. const container = this.$refs.webgl;
  203. const canvas3d = this.canvas = this.$refs.glcanvas;
  204. let camera = null, renderer = null, controls=null;
  205. // let trackballControls = null;
  206. console.warn("***loader0***",this.loader)
  207. let loader = null;
  208. loader = this.loader = new GLTFLoader();
  209. // this.getInitData();//请求获取页面模型数据等
  210. let scene = this.scene = new THREE.Scene();
  211. let chooseMesh = this.chooseMesh;//标记鼠标拾取到的mesh
  212. let isUserContorl = false;
  213. let tweenCameraAnma = false; //表示当前是否处在动画过程中
  214. let needRender = false; //是否需要渲染 false表示不需要渲染;true 表示需要渲染
  215. let frustumSize = 30;//正交相机的视窗宽度距离
  216. let stats;
  217. init();
  218. // render();
  219. // this.$refs.myLoading.showLoading("加载中..." + this.progress+"%")
  220. // this.myLoadingStatus = true;
  221. this.progress = 1;
  222. this.clearEvent = clearEvent;
  223. this.attendEvent = attendEvent;
  224. this.updateLables = updateLables;
  225. this.enableRenderHandle = enableRender;
  226. this.tweenCameraAnmaChange = tweenCameraAnmaChange;
  227. this.gradientResize = gradientResize;
  228. this.moveMeshCenterHandle = moveMeshCenterHandle;
  229. this.starRender = starRender;//对外暴露启动渲染的方法
  230. this.stopRender = stopRender;//对外暴露停止渲染的方法
  231. this.cameraInit = cameraInit;
  232. this.resetControl = resetControl;
  233. if(this.curHouseObj){
  234. this.houseInit()
  235. }
  236. function init() {
  237. scene.background = new THREE.Color("#FFFFFF");
  238. // scene.environment = new THREE.Color("#F2F2F2");
  239. // 创建相机位置-投影相机
  240. camera = new THREE.PerspectiveCamera( 80, screenWidth / that.canvasHeight, 0.1, 10000 );
  241. // let aspect = screenWidth / that.canvasHeight;
  242. // camera = new THREE.OrthographicCamera( frustumSize * aspect / - 2, frustumSize * aspect / 2, frustumSize / 2, frustumSize / - 2, 0.1,1000);
  243. camera.up.set(0, 1, 0);//俯视状态,将相机的up向量设置为z轴负方向
  244. scene.add(camera);
  245. that.camera = camera;
  246. // 辅助方格
  247. // const axesHelper = new THREE.AxesHelper( 50 );
  248. // scene.add( axesHelper );
  249. // const gridHelper = new THREE.GridHelper(50, 10, 0xcccccc, 0xcccccc);
  250. // gridHelper.position.y = 0;
  251. // gridHelper.position.x = 0;
  252. // scene.add(gridHelper);
  253. // 环境光会均匀的照亮场景中的所有物体
  254. const ambientLight = new THREE.AmbientLight(0xFFEFE0, 3);
  255. scene.add(ambientLight);
  256. //平行光
  257. const light = new THREE.DirectionalLight(0xFFF8E5, 3);
  258. light.position.set(-3, 9, 3); //default; light shining from top
  259. light.castShadow = true; // default false
  260. // 默认情况下光投影相机区域是一个长宽高为10x10x500的长方体区域,光源投射方向为通过坐标原点
  261. light.shadow.camera.left = -100; // default
  262. light.shadow.camera.right = 100; // default
  263. light.shadow.camera.top = 100; // default
  264. light.shadow.camera.bottom = -100; // default
  265. light.shadow.mapSize.width = 8192; // default
  266. light.shadow.mapSize.height = 8192; // default
  267. // light.shadow.camera.near = 0.1; // default
  268. // light.shadow.camera.far = 500; // default
  269. // light.shadow.bias = -0.01;
  270. // light.shadow.radius = 1;
  271. // light.shadow.darkness = 1; // 设置阴影强度为0.5
  272. scene.add(light);
  273. // const helper = new THREE.CameraHelper( light.shadow.camera );
  274. // scene.add(helper);
  275. // 从一个点向各个方向发射的光源。一个常见的例子是模拟一个灯泡发出的光。
  276. // const pointLight = new THREE.PointLight( 0xffffff, 0.3 );
  277. // camera.add( pointLight );
  278. //antialias 这个值得设置为false,不然IOS上截图会失效
  279. renderer = that.renderer = new THREE.WebGLRenderer({
  280. canvas:canvas3d,
  281. alpha: true,
  282. antialias:false,
  283. // 如果想保存three.js canvas画布上的信息,注意设置preserveDrawingBuffer
  284. preserveDrawingBuffer: true,
  285. });
  286. renderer.shadowMap.enabled = true;//产生阴影
  287. renderer.shadowMap.type = THREE.PCFSoftShadowMap; // 阴影属性
  288. renderer.outputEncoding = THREE.sRGBEncoding;
  289. renderer.outputColorSpace = THREE.SRGBColorSpace;
  290. // renderer.toneMappingExposure = 0.1;//色调映射的曝光级别。默认是1
  291. renderer.toneMapping = THREE.NoToneMapping;//色调映射
  292. renderer.physicallyCorrectLights = true;//关键参数,模拟物理光照影响,必须设置为true
  293. renderer.setPixelRatio( window.devicePixelRatio );
  294. renderer.setSize( screenWidth, that.canvasHeight );
  295. container.appendChild( renderer.domElement );
  296. controls = new OrbitControls(camera, renderer.domElement);
  297. controls.screenSpacePanning = false;//平移时确保不超过PolarAngle限制
  298. controls.enableDamping = true;
  299. controls.minDistance = 1;
  300. controls.maxDistance = 400;
  301. controls.minPolarAngle = Math.PI / 8;// 默认0
  302. controls.maxPolarAngle = Math.PI / 2; // 默认Math.PI,即可以向下旋转到的视角。
  303. controls.target.set(that.controlStarPosition.x, that.controlStarPosition.y, that.controlStarPosition.z);
  304. controls.enableZoom = true;//启用摄像机的缩放
  305. // 监听相机移动事件-限制只能在当前空间范围内移动
  306. // controls.addEventListener('change', () => {
  307. // // 检查相机位置是否超出边界框
  308. // if (camera.position.y < 0) {
  309. // camera.position.y = 0;
  310. // }
  311. // });
  312. // stats = new Stats();
  313. // container.appendChild(stats.dom);
  314. // stats.domElement.style.top = '100px';
  315. attendEvent(); //注册监听事件
  316. starRender(); //启动渲染
  317. cameraInit(); //初始化摄像头
  318. controls.saveState();//保存当前控制器的状态
  319. }
  320. //初始化相机位置
  321. function cameraInit(){
  322. camera.position.set(that.cameraStarPosition.x, that.cameraStarPosition.y, that.cameraStarPosition.z);
  323. camera.lookAt(that.controlStarPosition.x,that.controlStarPosition.y,that.controlStarPosition.z);
  324. }
  325. //初始状态
  326. function resetControl(){
  327. controls.reset();
  328. }
  329. function onWindowResize() {
  330. camera.aspect = screenWidth / that.canvasHeight;
  331. camera.updateProjectionMatrix();
  332. renderer.setSize( screenWidth, that.canvasHeight );
  333. console.warn("****onWindowResize**")
  334. }
  335. function attendEvent () {
  336. window.addEventListener('resize', onWindowResize);
  337. renderer.domElement.addEventListener('touchstart', onPointerStart, false);
  338. renderer.domElement.addEventListener('touchmove', onPointerMove, false);
  339. renderer.domElement.addEventListener('touchend', onPointerUp, false);
  340. }
  341. function tweenCameraAnmaChange (value) {
  342. tweenCameraAnma = value
  343. }
  344. //开启渲染-帧率优化,不触发时停止渲染
  345. function enableRender() {
  346. }
  347. //取消事件监听-避免二次进入时触发多次事件
  348. function clearEvent(){
  349. console.warn("**clearEvent****")
  350. renderer && renderer.domElement && renderer.domElement.removeEventListener('touchstart', onPointerStart);
  351. renderer && renderer.domElement && renderer.domElement.removeEventListener('touchmove', onPointerMove );
  352. renderer && renderer.domElement && renderer.domElement.removeEventListener('touchend', onPointerUp );
  353. }
  354. // 手指移动开始
  355. function onPointerStart(event){
  356. console.log('开始触摸事件:',that.overChange)
  357. if(that.overChange){//形变中,不能相应用户操作
  358. return false;
  359. }
  360. }
  361. //持续触摸中
  362. function onPointerMove( event ) {
  363. if(that.overChange){//形变中,不能相应用户操作
  364. return false;
  365. }
  366. // that.showLables = false;
  367. }
  368. //触摸结束
  369. function onPointerUp(event) {
  370. if(that.overChange){//形变中,不能相应用户操作
  371. return false;
  372. }
  373. // enableRender();
  374. if(event.touches.length==0){
  375. // that.showLables = true;
  376. // updateLables();
  377. }
  378. }
  379. //把摄像机移动的选中模型的正上方,观察点也变更为模型中心点,同时选中模型
  380. function moveMeshCenterHandle(mesh = null,noChangeColor = true){
  381. if(mesh){//如果传入了模型,则取模型
  382. let spaceId = mesh.spaceId;//空间id
  383. if(chooseMesh && spaceId == chooseMesh.spaceId){
  384. console.warn("**moveMeshCenterHandle-重复选中了***")
  385. return false;
  386. }
  387. chooseMesh = mesh;
  388. }
  389. if(!chooseMesh){
  390. console.warn("**moveMeshCenterHandle-没有数据***")
  391. return false;
  392. }
  393. that.showLables = false;//隐藏
  394. // controls.enable = false;//控制器不响应用户的操作
  395. let spaceObj = chooseMesh;//获取空间模型的相关数据
  396. // controls.panTo(spaceObj.centerX/100, camera.position.y, -spaceObj.centerY/100);
  397. let cameraNewPosition ={};
  398. let targetNewPosition ={};
  399. let oldUp = {};
  400. let newUp = {};
  401. if (isUserContorl === false) { // 非漫游状态
  402. let _juli = camera.position.y * Math.tan(Math.PI / 8);
  403. cameraNewPosition = {
  404. x:spaceObj.centerX/100,
  405. y:camera.position.y,
  406. z:-spaceObj.centerY/100 + _juli,//增加偏差,防止极点翻转问题?不知道为啥会有用
  407. }
  408. //新的观察点的位置-取模型的中心点坐标,加上高度,由于模型都是贴地的,所以高度设置为0
  409. targetNewPosition = {
  410. x:spaceObj.centerX/100,
  411. y:0,
  412. z:-spaceObj.centerY/100,
  413. }
  414. oldUp = camera.up;//俯视状态
  415. newUp = camera.up;
  416. // newUp = new THREE.Vector3(0,0,-1);
  417. // that.cameraLastPosition = cameraNewPosition;//记录下上一次摄像头位置
  418. // that.controlLastPosition = targetNewPosition;//记录下上一次观察点位置
  419. // if(cameraNewPosition.x<0){
  420. // cameraNewPosition.x = 0;
  421. // }
  422. }
  423. console.warn("**moveMeshCenter***",isUserContorl,spaceObj,JSON.stringify(camera.position),JSON.stringify(controls.target)
  424. ,cameraNewPosition,targetNewPosition,JSON.stringify(camera.up))
  425. tweenCamera(camera.position,controls.target,cameraNewPosition,targetNewPosition,oldUp,newUp,1000);
  426. setTimeout(()=>{
  427. that.showLables = true;
  428. // camera.up = new THREE.Vector3(0,1,0);
  429. // updateLables();
  430. },1001);//动画结束后回复原始状态
  431. }
  432. // oldP 相机原来的位置
  433. // oldT target原来的位置
  434. // newP 相机新的位置
  435. // newT target新的位置
  436. function tweenCamera(oldP, oldT, newP, newT, oldUp, newUp, time=1000) {
  437. if(JSON.stringify(oldP) == JSON.stringify(newP) && JSON.stringify(oldT) == JSON.stringify(newT)){
  438. return false;
  439. }
  440. if (!chooseMesh) {
  441. return false;
  442. }
  443. tweenCameraAnma = true;
  444. var tween = new TWEEN.Tween({
  445. x1: oldP.x, // 相机x
  446. y1: oldP.y, // 相机y
  447. z1: oldP.z, // 相机z
  448. x2: oldT.x, // 控制点的中心点x
  449. y2: oldT.y, // 控制点的中心点y
  450. z2: oldT.z, // 控制点的中心点z
  451. x3: oldUp.x, // 控制点的中心点x
  452. y3: oldUp.y, // 控制点的中心点y
  453. z3: oldUp.z // 控制点的中心点z
  454. })
  455. .to({
  456. x1: newP.x,
  457. y1: newP.y,
  458. z1: newP.z,
  459. x2: newT.x,
  460. y2: newT.y,
  461. z2: newT.z,
  462. x3: newUp.x, // up向量
  463. y3: newUp.y, // 控制点的中心点y
  464. z3: newUp.z // 控制点的中心点z
  465. }, time)
  466. .easing(TWEEN.Easing.Quadratic.InOut)
  467. .onUpdate((object)=> {
  468. camera.position.x = object.x1;
  469. camera.position.y = object.y1;
  470. camera.position.z = object.z1;
  471. let newTarget = new THREE.Vector3(object.x3,object.y3,object.z3);
  472. camera.up.copy(newTarget);
  473. camera.lookAt(object.x2,object.y2,object.z2);
  474. // controls.target.x = object.x2;
  475. // controls.target.y = object.y2;
  476. // controls.target.z = object.z2;
  477. // controls.update();
  478. // console.warn("****onUpdate**",object.x1,object.y1,object.z1,object.x2,object.y2,object.z2)
  479. }).onComplete(()=>{
  480. controls.target.x = newT.x;
  481. controls.target.y = newT.y;
  482. controls.target.z = newT.z;
  483. //修正最后的视角
  484. let up = new THREE.Vector3(newUp.x,newUp.y,newUp.z);
  485. camera.up.copy(up);
  486. camera.lookAt(controls.target.x,controls.target.y,controls.target.z);
  487. tweenCameraAnma = false;
  488. })
  489. // 开始动画
  490. tween.start();
  491. }
  492. //高度持续变化处理 time 动画持续时间 单位秒
  493. function gradientResize (time,startHeight,endHeight) {
  494. // let _timeStep = 20;//单位 毫秒
  495. // let unit = screenWidth / 750;//单位rpm 对应 px 的值
  496. // that.canvasHeight = screenHeight - (200 * unit) + (20 * unit);
  497. let unit = screenWidth / 750;//单位rpx 对应 px 的值
  498. let _height = startHeight - endHeight;//高度变化-单位rpx
  499. let _jisua = that.canvasHeight;
  500. let lastHeight = _jisua + (_height * unit);//动画结束时的高度值; 单位 px
  501. that.canvasHeight = lastHeight;//触发css动画
  502. // let step = (_height * unit) / (time*1000 / _timeStep);//真实大小 单位px
  503. console.warn("***gradientResize***",lastHeight,_jisua,startHeight,endHeight)
  504. // that.showLables = false;
  505. // let canvas_webgl = document.getElementById('canvas_webgl');
  506. var tween = new TWEEN.Tween({
  507. h1: _jisua,
  508. })
  509. .to({
  510. h1: lastHeight,
  511. }, 1000)
  512. .easing(TWEEN.Easing.Linear.None)
  513. .onUpdate((object)=> {
  514. if(camera.isOrthographicCamera){//正交相机
  515. let aspect = screenWidth / object.h1;
  516. camera.left = frustumSize * aspect / - 2;
  517. camera.right = frustumSize * aspect / 2;
  518. camera.top = frustumSize / 2;
  519. camera.bottom = frustumSize / -2;
  520. camera.updateProjectionMatrix();
  521. // that.canvasHeight = object.h1;
  522. }
  523. else if(camera.isPerspectiveCamera){//透视相机
  524. camera.aspect = screenWidth / object.h1;
  525. camera.updateProjectionMatrix();
  526. renderer.setSize( screenWidth, object.h1 );
  527. // that.canvasHeight = object.h1;
  528. }
  529. }).onComplete(()=>{
  530. camera.aspect = screenWidth / that.canvasHeight;
  531. camera.updateProjectionMatrix();
  532. renderer.setSize(screenWidth, that.canvasHeight );
  533. tweenCameraAnma = false;
  534. // that.showLables = true;
  535. // updateLables();//更新lable
  536. });
  537. // 开始动画
  538. tween.start();
  539. tweenCameraAnma = true;
  540. }
  541. //更新lables
  542. function updateLables(){
  543. if(!that.showLables){
  544. return false;
  545. }
  546. that.lableItem.forEach(lable =>{
  547. if(!that.gltfSpaces[lable.cubeIndex] || !that.gltfSpaces[lable.cubeIndex].instancedMeshIndexList){
  548. return false;
  549. }
  550. let item = that.gltfSpaces[lable.cubeIndex].instancedMeshIndexList[0];//获取地板模型的第一个geometry实例
  551. let _index = item.instancedMeshIndex;//第一个geometry实例 在 全局InstancedMesh实例的位置
  552. let instancedMesh = that.instancedSpaceMeshList[_index];//获取具体的网格实例
  553. let stratMatrix = new THREE.Matrix4();//定义一个四维矩阵
  554. instancedMesh.getMatrixAt(item.instancedAtIndex,stratMatrix);//获取当前几何体的四维矩阵到stratMatrix里面
  555. let position = new THREE.Vector3();//当前几何体的位置参数
  556. position.setFromMatrixPosition(stratMatrix);//从四维向量中提取位置信息
  557. // console.warn("***updateLables***",item.instancedAtIndex,JSON.stringify(position));
  558. position.project(camera);
  559. const x = (position.x * .5 + .5) * screenWidth;
  560. const y = (position.y * -.5 + .5) * that.canvasHeight;
  561. lable.transform = `translate(-50%, -50%) translate(${x}px,${y}px)`;
  562. })
  563. }
  564. function stopRender () {
  565. needRender = false;
  566. }
  567. function starRender () {
  568. if(needRender==true){//如果已经在渲染中了,则不能再次开启,避免渲染过多
  569. false;
  570. }
  571. needRender = true;
  572. render();//开始渲染
  573. }
  574. function render() {
  575. if(needRender==false){
  576. return false;
  577. }
  578. TWEEN && TWEEN.update();
  579. // stats.update();
  580. //不处在动画过程中,则可以处理移动等动作
  581. if(tweenCameraAnma==false){
  582. controls.update();
  583. updateLables();//更新lable
  584. }
  585. requestId = requestAnimationFrame(render, canvas3d);
  586. renderer.render(scene, camera);//单次渲染
  587. if (that.screenshotResolve) {
  588. stopRender();
  589. that.screenshotResolve()
  590. that.screenshotResolve = null;//释放Promise
  591. }
  592. }
  593. },
  594. onShow(){
  595. console.warn("---onShow1---",this.pvId)
  596. if(this.attendEvent){
  597. this.attendEvent()
  598. }
  599. },
  600. onHide(){
  601. this.clearEvent();
  602. },
  603. computed: {
  604. aiData() {
  605. return this.$store.state.aiData;
  606. },
  607. userId() {
  608. return this.$store.state.userId;
  609. },
  610. },
  611. methods: {
  612. voiceMaskChange(voiceMask){
  613. this.voiceMaskShow = voiceMask;
  614. },
  615. // async submitHouse(){
  616. // if(this.overChange){
  617. // this.$message.warning("空间正在调整");
  618. // return false
  619. // }
  620. // let shottingImg = await this.shottingAction() + "?x-oss-process=image/auto-orient,1/quality,Q_46/format,jpg";//开始截图
  621. // console.warn("***shottingImg***",shottingImg);
  622. // },
  623. enableRender(){
  624. this.enableRenderHandle();
  625. },
  626. /**
  627. * 选中墙体触发
  628. */
  629. selectWall(wallIndex){
  630. console.log("index",wallIndex)
  631. if(this.chooseWallMeshColor){
  632. for (let index = 0; index < this.curWallArr.length; index++) {
  633. const element = this.curWallArr[index];
  634. const cube = element.obj;
  635. this.chooseWallMeshColor.convertSRGBToLinear(); // 将颜色值转换为线性颜色值
  636. if(cube && cube.children[0].children[0] && cube.children[0].children[0].material){
  637. cube.children[0].children[0].material.color = this.chooseWallMeshColor;//修改选中模型的颜色-高亮显示 当前选中的模型
  638. }else{//新版逻辑
  639. // element.instancedMeshIndexList.forEach(item=>{
  640. // let _index = item.instancedMeshIndex;
  641. // let instancedMesh = this.instancedMeshList[_index];//网格实例
  642. // instancedMesh.instanceColor.needsUpdate = true;//打开颜色修改开关,不开,颜色是不能修改额
  643. // instancedMesh.setColorAt(item.instancedAtIndex, this.chooseWallMeshColor);//修改这个几何体的颜色
  644. // })
  645. }
  646. }
  647. }
  648. switch (wallIndex) {
  649. case 1:
  650. this.curWallDirection = "N";
  651. break;
  652. case 2:
  653. this.curWallDirection = "S";
  654. break;
  655. case 3:
  656. this.curWallDirection = "W";
  657. break;
  658. case 4:
  659. this.curWallDirection = "E";
  660. break;
  661. }
  662. this.selectedWall(this.curWallDirection)
  663. this.curWallArr = [];
  664. if(wallIndex!=0){
  665. const wallMoveValues = this.curSpaceObj.wallMoveValue;
  666. console.log
  667. const values = JSON.parse(wallMoveValues);
  668. if(this.curWallValue == 150){
  669. this.curWallValue = values[wallIndex-1]
  670. }else{
  671. let wallIndex = 0
  672. switch (this.curWallDirection) {
  673. case "N":
  674. wallIndex = 0;
  675. values[wallIndex] = this.curWallValue;
  676. values[1] = this.curWallValue;
  677. break;
  678. case "S":
  679. wallIndex = 1;
  680. values[wallIndex] = this.curWallValue;
  681. values[0] = this.curWallValue;
  682. break;
  683. case "W":
  684. wallIndex = 2;
  685. values[wallIndex] = this.curWallValue;
  686. values[3] = this.curWallValue;
  687. break;
  688. case "E":
  689. wallIndex = 3;
  690. values[wallIndex] = this.curWallValue;
  691. values[2] = this.curWallValue;
  692. break;
  693. }
  694. }
  695. this.curSpaceObj.wallMoveValue = JSON.stringify(values)
  696. console.log("墙体可移动数据:", this.curSpaceObj.wallMoveValue, this.spaceList);
  697. const wallStatus = this.curSpaceObj.wallStatus || "[false,false,false,false]"
  698. const status = JSON.parse(wallStatus);
  699. this.curWallHidden = status[wallIndex-1]
  700. console.log("当前墙面数据:", wallStatus , status, wallIndex);
  701. const curSpaceGltfWall = this.gltfWalls.filter((item)=>{
  702. return this.curSpaceObj.spaceId == item.spaceId && item.wallDirection == this.curWallDirection
  703. })
  704. if(curSpaceGltfWall.length != 0){
  705. this.curWallArr.push(...curSpaceGltfWall);
  706. }else{
  707. let rightWallD = "";
  708. switch (wallIndex-1) {
  709. case 0:
  710. rightWallD= "S";
  711. break;
  712. case 1:
  713. rightWallD= "N";
  714. break;
  715. case 2:
  716. rightWallD= "E";
  717. break;
  718. case 3:
  719. rightWallD= "W";
  720. break;
  721. }
  722. for (let index = 0; index < this.leftSpaces.length; index++) {
  723. const element = this.leftSpaces[index];
  724. const gltfWall = this.gltfWalls.filter((item)=>{
  725. return element.spaceId == item.spaceId && item.wallDirection == this.curWallDirection
  726. })
  727. if(gltfWall){
  728. this.curWallArr.push(...gltfWall);
  729. }
  730. }
  731. for (let index = 0; index < this.rightSpaces.length; index++) {
  732. const element = this.rightSpaces[index];
  733. const gltfWall = this.gltfWalls.filter((item)=>{
  734. return element.spaceId == item.spaceId && item.wallDirection == rightWallD;
  735. })
  736. if(gltfWall){
  737. this.curWallArr.push(...gltfWall);
  738. }
  739. }
  740. }
  741. for (let index = 0; index < this.curWallArr.length; index++) {
  742. const element = this.curWallArr[index];
  743. const cube = element.obj;
  744. if(cube && cube.children[0].children[0] && cube.children[0].children[0].material){
  745. this.chooseWallMeshColor = cube.children[0].children[0].material.color.clone();
  746. let color = new THREE.Color(0xff0000); // 使用sRGB颜色值
  747. color.convertSRGBToLinear(); // 将颜色值转换为线性颜色值
  748. cube.children[0].children[0].material.color = color;//修改选中模型的颜色-高亮显示 当前选中的模型
  749. }else{//新版逻辑
  750. // element.instancedMeshIndexList.forEach(item=>{
  751. // let _index = item.instancedMeshIndex;
  752. // let instancedMesh = this.instancedMeshList[_index];//网格实例
  753. // this.chooseWallMeshColor = instancedMesh.material.color.clone();;
  754. // let color = new THREE.Color(0xff0000); // 使用sRGB颜色值
  755. // color.convertSRGBToLinear(); // 将颜色值转换为线性颜色值
  756. // instancedMesh.instanceColor.needsUpdate = true;//打开颜色修改开关,不开,颜色是不能修改额
  757. // instancedMesh.setColorAt(item.instancedAtIndex, color);//修改这个几何体的颜色
  758. // })
  759. }
  760. }
  761. }
  762. },
  763. //具体空间面积变化-拖动产生的
  764. //data = {
  765. // spaceId:245,
  766. // area:12, //正负值 单位平方米
  767. // }
  768. curSpaceChange(data){
  769. console.warn("***空间面积变化***",this.overChange,data);
  770. // let changArea = data.isZoomIn ? parseFloat(data.area.toFixed(2)) : -parseFloat(data.area.toFixed(2));
  771. // this.changeArea = changArea;//当次变化的面积,有正负值
  772. // this.sumArea = parseFloat((this.sumArea + changArea).toFixed(2));
  773. this.overChange = true;//变形开始 防止在形变结束前,再次形变
  774. this.currentChangeSpaceId = data.spaceId
  775. this.changCurSpaceArea(data);
  776. let space = this.spaceList.find(it=>it.spaceId==this.currentChangeSpaceId);
  777. this.moveMeshCenter(space);
  778. },
  779. // 空间移动,
  780. changCurSpaceArea(data){
  781. console.log("当前户型的核心点", this.curHouseObj.houseCore, this.overChange);
  782. const houseCore = this.curHouseObj.houseCore.split(',');
  783. const coreX = houseCore[0] | 0
  784. const coreY = houseCore[1] | 0
  785. // 根据核心点计算空间所在象限
  786. this.spaces1 = [];
  787. this.spaces2 = [];
  788. this.spaces3 = [];
  789. this.spaces4 = [];
  790. let curSpace = null;
  791. for (let index = 0; index < this.spaceList.length; index++) {
  792. const element = this.spaceList[index];
  793. if(element.centerX > coreX){ // 2 3象限
  794. if(element.centerY > coreY){ // 2象限
  795. console.log(`象限2 ${element}`);
  796. element.quadrant = 2;
  797. this.spaces2.push(element)
  798. }else{// 3象限
  799. console.log(`象限3 ${element}`);
  800. element.quadrant = 3;
  801. this.spaces3.push(element)
  802. }
  803. }else{// 1 4象限
  804. if(element.centerY > coreY){ // 1象限
  805. console.log(`象限1 ${element}`);
  806. element.quadrant = 1;
  807. this.spaces1.push(element)
  808. }else{ // 4象限
  809. console.log(`象限4 ${element}`);
  810. element.quadrant = 4;
  811. this.spaces4.push(element)
  812. }
  813. }
  814. if(element.spaceId == data.spaceId){
  815. curSpace = element;
  816. }
  817. }
  818. console.log("当前space所在象限",data.spaceId, curSpace.spaceId , curSpace.quadrant);
  819. console.log("象限", this.spaces1, this.spaces2, this.spaces3, this.spaces4);
  820. this.calculateSpaceData(curSpace, data)
  821. },
  822. calculateSpaceData(curSpace, data){
  823. let that = this;
  824. this.curSpaceObj = curSpace;
  825. // 计算宽高移动数值
  826. const changeArea = data.area;
  827. const isZoomIn = data.isZoomIn;
  828. const oldArea = (curSpace.spaceWidth / 100) * (curSpace.spaceHeight / 100);
  829. const newArea = oldArea + changeArea * (data.isZoomIn ? 1 : -1);
  830. const sizeScale = Math.sqrt(newArea/oldArea) ;
  831. // 新的宽度
  832. let newWidth = curSpace.spaceWidth * sizeScale;
  833. if(newWidth < curSpace.spaceWidthMin){
  834. newWidth = curSpace.spaceWidthMin
  835. }
  836. if(newWidth > curSpace.spaceWidthMax){
  837. newWidth = curSpace.spaceWidthMax
  838. }
  839. // 新的高度
  840. let newHeight = newArea * 10000 / newWidth;
  841. if(newHeight < curSpace.spaceHeightMin){
  842. newHeight = curSpace.spaceHeightMin
  843. }
  844. if(newHeight > curSpace.spaceHeightMax){
  845. newHeight = curSpace.spaceHeightMax
  846. }
  847. newWidth = newArea * 10000 / newHeight;
  848. let changeWidth = Math.abs(newWidth - curSpace.spaceWidth)
  849. let changeHeight = Math.abs(newHeight - curSpace.spaceHeight)
  850. console.log("变化的尺寸", changeWidth, changeHeight, newWidth, newHeight, curSpace.spaceWidth, curSpace.spaceHeight);
  851. if(curSpace.quadrant == 1){
  852. // 默认往南 往西移动
  853. this.moveSpace(curSpace, 1, 3, isZoomIn, newArea, newWidth, newHeight, changeWidth, changeHeight)
  854. }
  855. if(curSpace.quadrant == 2){
  856. // 默认往南 往西移动
  857. this.moveSpace(curSpace, 1, 4, isZoomIn, newArea, newWidth, newHeight, changeWidth, changeHeight)
  858. }
  859. if(curSpace.quadrant == 3){
  860. // this.selectWall(4);
  861. // // // 移动墙面
  862. // this.moveSpaceWall(this.curWallDirection, isZoomIn, changeWidth);
  863. // 默认往南 往东移动
  864. this.moveSpace(curSpace, 2, 4, isZoomIn, newArea, newWidth, newHeight, changeWidth, changeHeight)
  865. }
  866. if(curSpace.quadrant == 4){
  867. // 默认往南 往西移动
  868. this.moveSpace(curSpace, 2, 3, isZoomIn, newArea, newWidth, newHeight, changeWidth, changeHeight)
  869. }
  870. setTimeout(() => {
  871. // that.updataPageData();
  872. that.overChange = false;
  873. that.callBackFun && that.callBackFun(true);
  874. // that.calculateLayoutModelSize(); //重新计算家具位置
  875. that.updateWallModels(); // 替换墙体模型
  876. that.changeLayoutModel(); // 改变空间模型
  877. // that.changeLayoutModelState(true); // 显示家具模型
  878. }, 4200);
  879. },
  880. moveSpace(curSpace, directionIndex, directionIndex01, isZoomIn, newArea, newWidth, newHeight, changeWidth, changeHeight){
  881. let that = this;
  882. const wallLock = this.currWallLock(directionIndex, curSpace); //南边
  883. const wallLock01 = this.currWallLock(directionIndex01, curSpace); //东边
  884. console.log("移动空间", wallLock, wallLock01)
  885. if(wallLock ==-1 && wallLock01 == -1){
  886. return this.$message.warning("空间尺寸已锁定");
  887. }
  888. let changeValue = changeHeight;
  889. if(wallLock == -1){
  890. if(wallLock01 == 0){
  891. directionIndex01 = directionIndex01 == 4 ? 3 : 4; // 往西移动
  892. }
  893. // 南北锁死,重新计算移动的方向
  894. newWidth = newArea / (curSpace.spaceHeight / 100) * 100
  895. changeWidth = newWidth / 100 - curSpace.spaceWidth / 100;
  896. changeWidth = Math.abs(changeWidth * 100);
  897. directionIndex = directionIndex01; // 往东移动
  898. changeValue = changeWidth;
  899. console.log("高度锁死不能拉伸, 宽度变化1",newWidth, directionIndex,curSpace.spaceWidth, curSpace.spaceHeight, changeValue);
  900. that.selectWall(directionIndex);
  901. let checkResult = this.checkRightSpace(!isZoomIn, changeWidth, false, curSpace)
  902. if(!checkResult.result){
  903. changeWidth = checkResult.newValue
  904. }
  905. console.log("宽度达到极限值结果++++++++++++++", checkResult, changeWidth)
  906. that.moveSpaceWall(that.curWallDirection, isZoomIn, changeWidth);
  907. // that.autoCreateWall(directionIndex, curSpace)
  908. return;
  909. }else{
  910. if(wallLock == 0){
  911. directionIndex = directionIndex == 2 ? 1 : 2; // 往北边移动
  912. }
  913. if(wallLock01 == -1){
  914. // 东西锁死,重新计算移动方向
  915. newHeight = newArea / (curSpace.spaceWidth / 100) * 100
  916. changeHeight = newHeight / 100 - curSpace.spaceHeight / 100;
  917. changeHeight = Math.abs(changeHeight * 100);
  918. changeValue = changeHeight;
  919. that.selectWall(directionIndex);
  920. let checkResult = this.checkRightSpace(!isZoomIn, changeHeight, true, curSpace)
  921. console.log("高度达到极限值结果++++++++++++++", checkResult, changeHeight)
  922. if(!checkResult.result){
  923. changeHeight = checkResult.newValue
  924. }
  925. that.moveSpaceWall(that.curWallDirection, isZoomIn, changeHeight);
  926. // 自动补墙逻辑
  927. // that.autoCreateWall(directionIndex, curSpace);
  928. return
  929. }
  930. if(wallLock01 == 0){
  931. directionIndex01 = directionIndex01 == 4 ? 3 : 4; // 往西移动
  932. }
  933. console.log("要变化的宽度", newWidth, newHeight)
  934. // 目标宽度
  935. if(newHeight > curSpace.spaceHeightMax){
  936. newHeight = curSpace.spaceHeightMax;
  937. changeHeight = Math.abs(newHeight - curSpace.spaceHeight)
  938. // 重新计算宽度值
  939. newWidth = (newArea / (newHeight / 100)) * 100
  940. changeWidth = (newWidth / 100 - curSpace.spaceWidth / 100) * 100;
  941. console.log("高度达到最大值,重新计算宽度",newWidth, newHeight, changeWidth, changeHeight)
  942. }
  943. if(newHeight < curSpace.spaceHeightMin){
  944. newHeight = curSpace.spaceHeightMin;
  945. changeHeight = Math.abs(newHeight - curSpace.spaceHeight)
  946. // 重新计算宽度值
  947. newWidth = (newArea / (newHeight / 100)) * 100
  948. changeWidth = Math.abs((newWidth / 100 - curSpace.spaceWidth / 100) * 100);
  949. console.log("高度达到最小值,重新计算宽度",newWidth, newHeight, changeWidth, changeHeight)
  950. }
  951. if(newWidth > curSpace.spaceWidthMax){
  952. newWidth = curSpace.spaceWidthMax;
  953. changeWidth = Math.abs(newWidth - curSpace.spaceWidth)
  954. // 重新计算宽度值
  955. newHeight = (newArea / (newWidth / 100)) * 100
  956. changeHeight = (newHeight / 100 - curSpace.spaceHeight / 100) * 100;
  957. console.log("宽度达到最大值,重新计算高度",newWidth, newHeight, changeWidth, changeHeight)
  958. }
  959. if(newWidth < curSpace.spaceWidthMin){
  960. newWidth = curSpace.spaceWidthMin;
  961. changeWidth = Math.abs(newWidth - curSpace.spaceWidth)
  962. // 重新计算宽度值
  963. newHeight = (newArea / (newWidth / 100)) * 100
  964. changeHeight = Math.abs((newHeight / 100 - curSpace.spaceHeight / 100) * 100);
  965. console.log("宽度达到最小值,重新计算高度",newWidth, newHeight, changeWidth, changeHeight)
  966. }
  967. // if(!checkWidth || !checkHeight){
  968. // return
  969. // }
  970. if(changeHeight > 0){
  971. that.changeSpaces = [];
  972. that.selectWall(directionIndex);
  973. let checkResult = this.checkRightSpace(!isZoomIn, changeHeight, true, curSpace)
  974. console.log("高度达到极限值结果++++++++++++++", checkResult, changeHeight)
  975. if(!checkResult.result){
  976. changeHeight = checkResult.newValue
  977. }
  978. that.moveSpaceWall(that.curWallDirection, isZoomIn, changeHeight);
  979. // 自动补墙逻辑
  980. // that.autoCreateWall(directionIndex, curSpace)
  981. }
  982. let timeout = 0
  983. if(changeWidth > 0 && changeHeight > 0 ){
  984. timeout = 2100
  985. }
  986. console.log("改变尺寸",changeWidth, changeHeight,newWidth, newHeight, timeout, directionIndex, directionIndex01, wallLock, wallLock01)
  987. if(changeWidth > 0){
  988. setTimeout(() => {
  989. that.changeSpaces = [];
  990. // // 选中墙面
  991. that.selectWall(directionIndex01);
  992. // 计算
  993. let checkResult = this.checkRightSpace(!isZoomIn, changeWidth, false, curSpace)
  994. if(!checkResult.result){
  995. changeWidth = checkResult.newValue
  996. }
  997. console.log("宽度达到极限值结果++++++++++++++", checkResult, changeWidth)
  998. // 移动墙面
  999. that.moveSpaceWall(that.curWallDirection, isZoomIn, changeWidth);
  1000. // 自动补墙逻辑
  1001. // that.autoCreateWall(directionIndex01, curSpace)
  1002. }, timeout);
  1003. }
  1004. }
  1005. },
  1006. currWallLock(direction, curSpace){
  1007. let curDirection = ""
  1008. let faceDirection = ""
  1009. switch (direction) {
  1010. case 1:
  1011. curDirection = "N";
  1012. faceDirection = "S";
  1013. break;
  1014. case 2:
  1015. curDirection = "S";
  1016. faceDirection = "N";
  1017. break;
  1018. case 3:
  1019. curDirection = "W";
  1020. faceDirection = "E";
  1021. break;
  1022. case 4:
  1023. curDirection = "E";
  1024. faceDirection = "W";
  1025. break;
  1026. }
  1027. const wallInfo = this.wallList.find((item)=>{
  1028. let element = JSON.parse(item.wallJson);
  1029. return element.spaceId == curSpace.spaceId;
  1030. })
  1031. let walls = JSON.parse(wallInfo.wallJson).wallData;
  1032. const wall = walls.find((item)=>{ // 当前墙面锁定
  1033. return item.wallDirection==curDirection && item.isLocked=="true"
  1034. })
  1035. const faceWall = walls.find((item)=>{ // 对面墙面锁定
  1036. return item.wallDirection==faceDirection && item.isLocked=="true"
  1037. })
  1038. if(wall){
  1039. if(faceWall){
  1040. return -1 // 当前对面同时锁定
  1041. }
  1042. return 0 // 当前锁定
  1043. }else{
  1044. return 1 // 不锁定,可以移动
  1045. }
  1046. },
  1047. // 排查关联空间是否达到极限值
  1048. checkRightSpace(isZoomIn, changeValue, isNS, curSpace){
  1049. if(changeValue == 0){
  1050. return;
  1051. }
  1052. let n = isZoomIn?1:-1;
  1053. let l = isZoomIn?-1:1;
  1054. let result = true;
  1055. let space = null;
  1056. let newValue = changeValue;
  1057. console.log("排查空间",isZoomIn, changeValue,isNS, this.leftSpaces, this.rightSpaces);
  1058. for (let index = 0; index < this.leftSpaces.length; index++) {
  1059. const element = this.leftSpaces[index];
  1060. // 过滤掉花园判断
  1061. if(element.spaceType == 14 || element.spaceId == curSpace.spaceId){
  1062. continue;
  1063. }
  1064. let newWidth = element.spaceWidth + l * changeValue;
  1065. let newHeight = element.spaceHeight + l * changeValue;
  1066. if(isNS){
  1067. if( newHeight > element.spaceHeightMax || newHeight < element.spaceHeightMin){
  1068. result = false;
  1069. space = element;
  1070. break;
  1071. }
  1072. }else{
  1073. if(newWidth > element.spaceWidthMax || newWidth < element.spaceWidthMin){
  1074. result = false;
  1075. space = element;
  1076. break;
  1077. }
  1078. }
  1079. }
  1080. for (let index = 0; index < this.rightSpaces.length; index++) {
  1081. const element = this.rightSpaces[index];
  1082. // 过滤掉花园判断
  1083. if(element.spaceType == 14){
  1084. console.log("空间排查跳出")
  1085. continue;
  1086. }
  1087. let newWidth = element.spaceWidth + n * changeValue;
  1088. let newHeight = element.spaceHeight + n * changeValue;
  1089. if(isNS){
  1090. if( newHeight > element.spaceHeightMax || newHeight < element.spaceHeightMin){
  1091. result = false;
  1092. space = element;
  1093. const newHeightValue = newHeight > element.spaceHeightMax ? element.spaceHeightMax : element.spaceHeightMin;
  1094. newHeight = newHeightValue - newHeight;
  1095. const newChangeValue = changeValue - newHeight;
  1096. if(newValue > newChangeValue){
  1097. newValue = newChangeValue;
  1098. }
  1099. break;
  1100. }
  1101. }else{
  1102. console.log("排查右边空间",newWidth, element.spaceWidthMax,newWidth, element.spaceWidthMin);
  1103. if(newWidth > element.spaceWidthMax || newWidth < element.spaceWidthMin){
  1104. result = false;
  1105. space = element;
  1106. let newWidthValue = newWidth > element.spaceWidthMax ? element.spaceWidthMax : element.spaceWidthMin
  1107. if(isZoomIn){ // 放大
  1108. if(newWidth>element.spaceWidthMax){ // 关联空间放大时已经是最大,则变化值为0
  1109. newValue = 0
  1110. break;
  1111. }
  1112. }else{
  1113. newWidthValue = newWidth < element.spaceWidthMin ? element.spaceWidthMin : newWidth;
  1114. console.log("排查右边空间2",newWidth, element.spaceWidthMax, element.spaceWidthMin);
  1115. }
  1116. newWidth = newWidthValue - newWidth;
  1117. const newChangeValue = changeValue - newWidth;
  1118. if(newValue > newChangeValue){
  1119. newValue = newChangeValue;
  1120. }
  1121. break;
  1122. }
  1123. }
  1124. }
  1125. if(!result){
  1126. this.$message.warning(`关联空间[${ space && space.spaceName || ''}]达到极限值`);
  1127. }
  1128. return {"result":result,"newValue":newValue}
  1129. },
  1130. checkSpaceSize(isZoomIn, changeWidth, changeHeight){
  1131. console.log("检查尺寸", isZoomIn, changeWidth, changeHeight, this.leftSpaces, this.rightSpaces)
  1132. for (let index = 0; index < this.leftSpaces.length; index++) {
  1133. const element = this.leftSpaces[index];
  1134. if(isZoomIn){
  1135. if(element.spaceWidth + changeWidth > element.spaceWidthMax || element.spaceHeight + changeHeight > element.spaceHeightMax){
  1136. console.log("++++++++++移动空间达到极大值1", element.spaceId, element.spaceWidth + changeWidth > element.spaceWidthMax, element.spaceHeight + changeHeight > element.spaceHeightMax)
  1137. console.log("++++++++++移动空间达到极大值宽", element.spaceWidth, changeWidth, element.spaceWidthMax)
  1138. console.log("++++++++++移动空间达到极大值高", element.spaceHeight, changeHeight, element.spaceHeightMax)
  1139. return false;
  1140. }
  1141. }else{
  1142. if(element.spaceWidth - changeWidth < element.spaceWidthMin || element.spaceHeight - changeHeight < element.spaceHeightMin){
  1143. console.log("++++++++++移动空间达到极小值2", element.spaceId)
  1144. console.log("++++++++++移动空间达到极大值宽", element.spaceWidth, changeWidth, element.spaceWidthMin)
  1145. console.log("++++++++++移动空间达到极大值高", element.spaceHeight, changeHeight, element.spaceHeightMin)
  1146. return false;
  1147. }
  1148. }
  1149. }
  1150. for (let index = 0; index < this.rightSpaces.length; index++) {
  1151. const element = this.rightSpaces[index];
  1152. if(!isZoomIn){
  1153. if(element.spaceWidth - changeWidth < element.spaceWidthMin || element.spaceHeight - changeHeight < element.spaceHeightMin){
  1154. console.log("++++++++++其他空间达到极小值4", element.spaceId)
  1155. console.log("++++++++++移动空间达到极大值宽", element.spaceWidth, changeWidth, element.spaceWidthMin)
  1156. console.log("++++++++++移动空间达到极大值高", element.spaceHeight, changeHeight, element.spaceHeightMin)
  1157. return false;
  1158. }
  1159. }else{
  1160. if(element.spaceWidth + changeWidth > element.spaceWidthMax || element.spaceHeight + changeHeight > element.spaceHeightMax){
  1161. console.log("++++++++++其他空间达到极大值3", element.spaceId)
  1162. console.log("++++++++++移动空间达到极大值宽", element.spaceWidth, changeWidth, element.spaceWidthMax)
  1163. console.log("++++++++++移动空间达到极大值高", element.spaceHeight, changeHeight, element.spaceHeightMax)
  1164. return false;
  1165. }
  1166. }
  1167. }
  1168. return true
  1169. },
  1170. // 新版本空间移动计算
  1171. changeCurSpaceSize(curSpace, changeArea, isZoomIn){
  1172. // 计算当前空间的变化
  1173. // 1.原先面积
  1174. const oldArea = (curSpace.spaceWidth / 100) * (curSpace.spaceHeight / 100);
  1175. const newArea = oldArea + changeArea * isZoomIn;
  1176. const sizeScale = Math.sqrt(newArea/oldArea) ;
  1177. console.log(`新面积:${newArea} 老面积:${oldArea}缩放比例:${sizeScale} 改变的面积:${changeArea} 是否放大:${isZoomIn} 中心点:${curSpace.centerX} ${curSpace.centerX}`);
  1178. console.log(`改变前:尺寸:${curSpace.spaceWidth} ${curSpace.spaceHeight} 中心点:${curSpace.centerX} ${curSpace.centerY}`);
  1179. curSpace.toScaleX = curSpace.spaceWidth * sizeScale / 300 ;
  1180. curSpace.toScaleZ = curSpace.spaceHeight * sizeScale / 300 ;
  1181. if(this.minspace1 && this.minspace1.spaceId == curSpace.spaceId){
  1182. curSpace.toPx = (curSpace.spaceWidth * sizeScale - curSpace.spaceWidth) / 2 / 100 * -1;
  1183. curSpace.toPz = (curSpace.spaceHeight * sizeScale - curSpace.spaceHeight) / 2 / 100 * -1;
  1184. console.log("XXXXXXXX-计算空间变化信息1", curSpace.toScaleX, curSpace.toScaleZ, curSpace.toPx, curSpace.toPz);
  1185. }else if(this.minspace2 && this.minspace2.spaceId == curSpace.spaceId){
  1186. curSpace.toPx = (curSpace.spaceWidth * sizeScale - curSpace.spaceWidth) / 2 / 100;
  1187. curSpace.toPz = (curSpace.spaceHeight * sizeScale - curSpace.spaceHeight) / 2 / 100 * -1;
  1188. console.log("XXXXXXXX-计算空间变化信息2", curSpace.toScaleX, curSpace.toScaleZ, curSpace.toPx, curSpace.toPz);
  1189. }else if(this.minspace3 && this.minspace3.spaceId == curSpace.spaceId){
  1190. curSpace.toPx = (curSpace.spaceWidth * sizeScale - curSpace.spaceWidth) / 2 / 100;
  1191. curSpace.toPz = (curSpace.spaceHeight * sizeScale - curSpace.spaceHeight) / 2 / 100;
  1192. console.log("XXXXXXXX-计算空间变化信息3", curSpace.toScaleX, curSpace.toScaleZ, curSpace.toPx, curSpace.toPz);
  1193. }else if(this.minspace4 && this.minspace4.spaceId == curSpace.spaceId){
  1194. curSpace.toPx = (curSpace.spaceWidth * sizeScale - curSpace.spaceWidth) / 2 / 100 * -1;
  1195. curSpace.toPz = (curSpace.spaceHeight * sizeScale - curSpace.spaceHeight) / 2 / 100;
  1196. console.log("XXXXXXXX-计算空间变化信息4", curSpace.toScaleX, curSpace.toScaleZ, curSpace.toPx, curSpace.toPz);
  1197. }else{
  1198. return
  1199. }
  1200. // 更新数据:
  1201. curSpace.spaceWidth = curSpace.spaceWidth * sizeScale;
  1202. curSpace.spaceHeight = curSpace.spaceHeight * sizeScale;
  1203. curSpace.centerX = curSpace.centerX + curSpace.toPx * 100
  1204. curSpace.centerY = curSpace.centerY + curSpace.toPz * 100
  1205. const spaceIndex = this.spaceList.findIndex((item)=>{
  1206. return item.spaceId == curSpace.spaceId;
  1207. })
  1208. if(spaceIndex!=-1){
  1209. this.spaceList[spaceIndex] = curSpace;
  1210. }
  1211. console.log(`改变后:尺寸:${curSpace.spaceWidth} ${curSpace.spaceHeight} 中心点:${curSpace.centerX} ${curSpace.centerY} `, curSpace.toPx, curSpace.toPz);
  1212. },
  1213. findxxSpace(manSpace,changeArea, xiangxian, isZoomIn){
  1214. if(xiangxian == 1){
  1215. const spaceE = this.spaces1.find((item)=>{
  1216. return item.spaceId == manSpace.eastId;
  1217. })
  1218. const spaceS = this.spaces1.find((item)=>{
  1219. return item.spaceId == manSpace.southId;
  1220. })
  1221. const oldArea = (manSpace.spaceWidth / 100) * (manSpace.spaceHeight / 100);
  1222. const newArea = oldArea + changeArea * isZoomIn;
  1223. const sizeScale = Math.sqrt(newArea/oldArea) ;
  1224. manSpace.toScaleX = manSpace.spaceWidth * sizeScale / 300 ;
  1225. manSpace.toScaleZ = manSpace.spaceHeight * sizeScale / 300 ;
  1226. if(spaceE){
  1227. manSpace.toPx = (manSpace.spaceWidth * sizeScale - manSpace.spaceWidth) / 2 / 100 * -1 + spaceE.toPx * 2;
  1228. console.log("XXXXXXXX东边有空间", manSpace.spaceId, spaceE.toPx)
  1229. }else{
  1230. manSpace.toPx = (manSpace.spaceWidth * sizeScale - manSpace.spaceWidth) / 2 / 100 * -1;
  1231. console.log("XXXXXXXX东边没空间", manSpace.spaceId)
  1232. }
  1233. if(spaceS){
  1234. manSpace.toPz = (manSpace.spaceHeight * sizeScale - manSpace.spaceHeight) / 2 / 100 * -1 + spaceS.toPz * 2;
  1235. console.log("XXXXXXXX南边有空间", manSpace.spaceId, spaceS.toPz)
  1236. }else{
  1237. manSpace.toPz = (manSpace.spaceHeight * sizeScale - manSpace.spaceHeight) / 2 / 100 * -1;
  1238. console.log("XXXXXXXX南边没空间", manSpace.spaceId)
  1239. }
  1240. console.log("XXXXXXXX-前象限1的其他空间", manSpace.spaceId, manSpace.spaceWidth, manSpace.spaceHeight, manSpace.centerX, manSpace.centerY, manSpace.toPx);
  1241. manSpace.spaceWidth = manSpace.spaceWidth * sizeScale;
  1242. manSpace.spaceHeight = manSpace.spaceHeight * sizeScale;
  1243. manSpace.centerX += manSpace.toPx * 100
  1244. manSpace.centerY += manSpace.toPz * 100
  1245. console.log("XXXXXXXX-后象限1的其他空间", manSpace.spaceId, manSpace.spaceWidth, manSpace.spaceHeight, manSpace.centerX, manSpace.centerY);
  1246. const spaceIndex = this.spaceList.findIndex((item)=>{
  1247. return item.spaceId == manSpace.spaceId;
  1248. })
  1249. if(spaceIndex!=-1){
  1250. this.spaceList[spaceIndex] = manSpace;
  1251. }
  1252. const spacesIndex = this.spaces1.findIndex((item)=>{
  1253. return item.spaceId == manSpace.spaceId;
  1254. })
  1255. if(spacesIndex!=-1){
  1256. this.spaces1[spacesIndex] = manSpace;
  1257. }
  1258. }
  1259. if(xiangxian == 2){
  1260. const spaceW = this.spaces2.find((item)=>{
  1261. return item.spaceId == manSpace.westId;
  1262. })
  1263. const spaceS = this.spaces2.find((item)=>{
  1264. return item.spaceId == manSpace.southId;
  1265. })
  1266. const oldArea = (manSpace.spaceWidth / 100) * (manSpace.spaceHeight / 100);
  1267. const newArea = oldArea + changeArea * isZoomIn;
  1268. const sizeScale = Math.sqrt(newArea/oldArea) ;
  1269. manSpace.toScaleX = manSpace.spaceWidth * sizeScale / 300 ;
  1270. manSpace.toScaleZ = manSpace.spaceHeight * sizeScale / 300 ;
  1271. if(spaceW){
  1272. manSpace.toPx = (manSpace.spaceWidth * sizeScale - manSpace.spaceWidth) / 2 / 100 + spaceW.toPx * 2;
  1273. console.log("XXXXXXXX西边有空间", manSpace.spaceId, spaceW.toPx)
  1274. }else{
  1275. manSpace.toPx = (manSpace.spaceWidth * sizeScale - manSpace.spaceWidth) / 2 / 100;
  1276. console.log("XXXXXXXX西边没空间", manSpace.spaceId)
  1277. }
  1278. if(spaceS){
  1279. manSpace.toPz = (manSpace.spaceHeight * sizeScale - manSpace.spaceHeight) / 2 / 100 * -1 + spaceS.toPz * 2;
  1280. console.log("XXXXXXXX南边有空间", manSpace.spaceId, spaceS.toPz)
  1281. }else{
  1282. manSpace.toPz = (manSpace.spaceHeight * sizeScale - manSpace.spaceHeight) / 2 / 100 * -1;
  1283. console.log("XXXXXXXX南边没空间", manSpace.spaceId)
  1284. }
  1285. console.log("XXXXXXXX-前象限2的其他空间", manSpace.spaceId, manSpace.spaceWidth, manSpace.spaceHeight, manSpace.centerX, manSpace.centerY, manSpace.toPx);
  1286. manSpace.spaceWidth = manSpace.spaceWidth * sizeScale;
  1287. manSpace.spaceHeight = manSpace.spaceHeight * sizeScale;
  1288. manSpace.centerX += manSpace.toPx * 100
  1289. manSpace.centerY += manSpace.toPz * 100
  1290. console.log("XXXXXXXX-后象限2的其他空间", manSpace.spaceId, manSpace.spaceWidth, manSpace.spaceHeight, manSpace.centerX, manSpace.centerY);
  1291. const spaceIndex = this.spaceList.findIndex((item)=>{
  1292. return item.spaceId == manSpace.spaceId;
  1293. })
  1294. if(spaceIndex!=-1){
  1295. this.spaceList[spaceIndex] = manSpace;
  1296. }
  1297. const spacesIndex = this.spaces2.findIndex((item)=>{
  1298. return item.spaceId == manSpace.spaceId;
  1299. })
  1300. if(spacesIndex!=-1){
  1301. this.spaces2[spacesIndex] = manSpace;
  1302. }
  1303. }
  1304. if(xiangxian == 3){
  1305. const spaceW = this.spaces3.find((item)=>{
  1306. return item.spaceId == manSpace.westId;
  1307. })
  1308. const spaceN = this.spaces3.find((item)=>{
  1309. return item.spaceId == manSpace.northId;
  1310. })
  1311. const oldArea = (manSpace.spaceWidth / 100) * (manSpace.spaceHeight / 100);
  1312. const newArea = oldArea + changeArea * isZoomIn;
  1313. const sizeScale = Math.sqrt(newArea/oldArea) ;
  1314. manSpace.toScaleX = manSpace.spaceWidth * sizeScale / 300 ;
  1315. manSpace.toScaleZ = manSpace.spaceHeight * sizeScale / 300 ;
  1316. if(spaceW){
  1317. manSpace.toPx = (manSpace.spaceWidth * sizeScale - manSpace.spaceWidth) / 2 / 100 + spaceW.toPx * 2;
  1318. console.log("XXXXXXXX西边有空间", manSpace.spaceId, spaceW.toPx)
  1319. }else{
  1320. manSpace.toPx = (manSpace.spaceWidth * sizeScale - manSpace.spaceWidth) / 2 / 100;
  1321. console.log("XXXXXXXX西边没空间", manSpace.spaceId)
  1322. }
  1323. if(spaceN){
  1324. manSpace.toPz = (manSpace.spaceHeight * sizeScale - manSpace.spaceHeight) / 2 / 100 + spaceN.toPz * 2;
  1325. console.log("XXXXXXXX北边有空间", manSpace.spaceId, spaceN.toPz)
  1326. }else{
  1327. manSpace.toPz = (manSpace.spaceHeight * sizeScale - manSpace.spaceHeight) / 2 / 100;
  1328. console.log("XXXXXXXX北边没空间", manSpace.spaceId)
  1329. }
  1330. console.log("XXXXXXXX-前象限3的其他空间", manSpace.spaceId, manSpace.spaceWidth, manSpace.spaceHeight, manSpace.centerX, manSpace.centerY, manSpace.toPx);
  1331. manSpace.spaceWidth = manSpace.spaceWidth * sizeScale;
  1332. manSpace.spaceHeight = manSpace.spaceHeight * sizeScale;
  1333. manSpace.centerX += manSpace.toPx * 100
  1334. manSpace.centerY += manSpace.toPz * 100
  1335. console.log("XXXXXXXX-后象限3的其他空间", manSpace.spaceId, manSpace.spaceWidth, manSpace.spaceHeight, manSpace.centerX, manSpace.centerY);
  1336. const spaceIndex = this.spaceList.findIndex((item)=>{
  1337. return item.spaceId == manSpace.spaceId;
  1338. })
  1339. if(spaceIndex!=-1){
  1340. this.spaceList[spaceIndex] = manSpace;
  1341. }
  1342. const spacesIndex = this.spaces3.findIndex((item)=>{
  1343. return item.spaceId == manSpace.spaceId;
  1344. })
  1345. if(spacesIndex!=-1){
  1346. this.spaces3[spacesIndex] = manSpace;
  1347. }
  1348. }
  1349. if(xiangxian == 4){
  1350. const spaceE = this.spaces4.find((item)=>{
  1351. return item.spaceId == manSpace.eastId;
  1352. })
  1353. const spaceN = this.spaces4.find((item)=>{
  1354. return item.spaceId == manSpace.northId;
  1355. })
  1356. const oldArea = (manSpace.spaceWidth / 100) * (manSpace.spaceHeight / 100);
  1357. const newArea = oldArea + changeArea * isZoomIn;
  1358. const sizeScale = Math.sqrt(newArea/oldArea) ;
  1359. manSpace.toScaleX = manSpace.spaceWidth * sizeScale / 300 ;
  1360. manSpace.toScaleZ = manSpace.spaceHeight * sizeScale / 300 ;
  1361. if(spaceE){
  1362. manSpace.toPx = (manSpace.spaceWidth * sizeScale - manSpace.spaceWidth) / 2 / 100 * -1 + spaceE.toPx * 2;
  1363. console.log("XXXXXXXX东边有空间", manSpace.spaceId, spaceE.toPx)
  1364. }else{
  1365. manSpace.toPx = (manSpace.spaceWidth * sizeScale - manSpace.spaceWidth) / 2 / 100 * -1;
  1366. console.log("XXXXXXXX东边没空间", manSpace.spaceId)
  1367. }
  1368. if(spaceN){
  1369. manSpace.toPz = (manSpace.spaceHeight * sizeScale - manSpace.spaceHeight) / 2 / 100 + spaceN.toPz * 2;
  1370. console.log("XXXXXXXX北边有空间", manSpace.spaceId, spaceN.toPz)
  1371. }else{
  1372. manSpace.toPz = (manSpace.spaceHeight * sizeScale - manSpace.spaceHeight) / 2 / 100;
  1373. console.log("XXXXXXXX北边没空间", manSpace.spaceId)
  1374. }
  1375. console.log("XXXXXXXX-前象限4的其他空间", manSpace.spaceId, manSpace.spaceWidth, manSpace.spaceHeight, manSpace.centerX, manSpace.centerY, manSpace.toPx);
  1376. manSpace.spaceWidth = manSpace.spaceWidth * sizeScale;
  1377. manSpace.spaceHeight = manSpace.spaceHeight * sizeScale;
  1378. manSpace.centerX += manSpace.toPx * 100
  1379. manSpace.centerY += manSpace.toPz * 100
  1380. console.log("XXXXXXXX-后象限4的其他空间", manSpace.spaceId, manSpace.spaceWidth, manSpace.spaceHeight, manSpace.centerX, manSpace.centerY);
  1381. const spaceIndex = this.spaceList.findIndex((item)=>{
  1382. return item.spaceId == manSpace.spaceId;
  1383. })
  1384. if(spaceIndex!=-1){
  1385. this.spaceList[spaceIndex] = manSpace;
  1386. }
  1387. const spacesIndex = this.spaces4.findIndex((item)=>{
  1388. return item.spaceId == manSpace.spaceId;
  1389. })
  1390. if(spacesIndex!=-1){
  1391. this.spaces4[spacesIndex] = manSpace;
  1392. }
  1393. }
  1394. },
  1395. //空间面积等变更后-同步更新其他数据对象
  1396. updataPageData(){
  1397. let sumArea = 0;
  1398. this.spaceList.forEach(space=>{
  1399. let curSpaceArea = parseFloat((
  1400. (space.spaceWidth * space.spaceHeight) * space.spaceRatio / 10000
  1401. ).toFixed(2));
  1402. sumArea +=curSpaceArea;
  1403. })
  1404. this.changeArea = parseFloat((sumArea - this.fixedArea).toFixed(2));
  1405. this.sumArea = parseFloat(sumArea.toFixed(2));
  1406. let str = JSON.stringify(this.spaceList)
  1407. //更新当前空间对象
  1408. this.curHouseObj.houseJson = str;
  1409. this.curHouseObj.houseArea = this.sumArea;
  1410. //更新提交的数据
  1411. // let layoutStruct = this.curLayoutStruct.find(it=>{
  1412. // return it.houseFloor == this.curHouseFloor
  1413. // })
  1414. // layoutStruct.houseJson = str;
  1415. this.currentChangeSpaceId = null;//变化结束后
  1416. console.warn("***curLayoutStruct-updataPageData***",this.changeArea,this.sumArea,this.curHouseFloor,this.curHouseObj)
  1417. },
  1418. // //户型大类发生了变更
  1419. // curHouseTypeChange(item){
  1420. // this.curHouseType = item.spaceStructure;//当前选中的户型类型-传递给子组件触发具体的户型数据选取
  1421. // this.curHouseName = item.spaceName;//当前选中的户型类型名称
  1422. // //获取当前户型大类下的所有户型信息-用于用户提交
  1423. // this.curLayoutStruct = this.houseList.find(it=>it.spaceStructure == this.curHouseType).layoutStruct;
  1424. // this.curLayoutStruct.forEach(it=>{
  1425. // this.layoutArea += it.houseArea
  1426. // })
  1427. // console.warn("***curLayoutStruct***",this.curLayoutStruct)
  1428. // },
  1429. // //户型楼层发生了变更
  1430. // curHouseFloorChange(item){
  1431. // let that = this;
  1432. // this.curHouseFloor = item.houseFloor;//当前选中的户型楼层
  1433. // this.curHouseObj = item;//更新当前具体的户型数据
  1434. // this.id = this.curHouseObj.id;
  1435. // // 遍历场景中的所有子对象,找到类型为Mesh的对象并移除
  1436. // let deleList = that.scene && that.scene.children.filter(object=>{
  1437. // if(object.userType=="mesh" || object.userType=="layoutMesh"){
  1438. // return object
  1439. // }
  1440. // })
  1441. // // console.warn("***deleList***",deleList)
  1442. // if(deleList && deleList.length>0){
  1443. // that.showLables = false;//隐藏lable
  1444. // that.scene.remove(...deleList);
  1445. // }
  1446. // this.houseInit()
  1447. // },
  1448. //当前户型初始化
  1449. houseInit(item){
  1450. this.gltfWalls = [];
  1451. this.gltfSpaces = [];
  1452. this.gltfSpaceRoofs = [];
  1453. this.instancedMeshList = [];
  1454. this.instancedSpaceMeshList = [];
  1455. this.lableItem = [];
  1456. this.gltfLayouts = [];
  1457. this.instancedFurList = [];
  1458. this.wallList = [];
  1459. this.changeArea = 0;
  1460. //恢复初始视角
  1461. this.cameraInit();
  1462. this.resetControl();
  1463. setTimeout(()=>{
  1464. this.loadSpace();
  1465. }, 100);
  1466. console.warn("***curHouseObj***",this.curHouseObj,this.aiData)
  1467. // this.navbar.title = this.curHouseObj.name + " " + this.curHouseObj.houseArea + "㎡";
  1468. this.navbar.title = "空间定制";
  1469. document.title = this.navbar.title;
  1470. this.sumArea = this.curHouseObj.houseArea;
  1471. this.fixedArea = this.curHouseObj.houseArea;
  1472. this.curHouseName = this.curHouseObj.name;
  1473. },
  1474. // async getInitData(){
  1475. // let parmas = {
  1476. // childLayout:this.childLayout || 0,
  1477. // houseId:this.houseId,
  1478. // }
  1479. // const res = await requestConfig('getHouseTypeSpaceDetailsV2', parmas, true);
  1480. // if (res.success && res.list) {
  1481. // let list = res.list || [];
  1482. // list && list.forEach((single,index)=>{
  1483. // single.layoutStruct.forEach((item)=>{
  1484. // if(item.houseJson){
  1485. // let spaceList = JSON.parse(item.houseJson);
  1486. // // 交换centerX, centerY
  1487. // for (let index = 0; index < spaceList.length; index++) {
  1488. // var element = spaceList[index];
  1489. // const {centerX, centerY} = element;
  1490. // element.centerX = centerY;
  1491. // element.centerY = centerX;
  1492. // }
  1493. // item.houseJson = JSON.stringify(spaceList);
  1494. // }
  1495. // })
  1496. // })
  1497. // console.log("户型详情列表-接口原始数据: ", list);
  1498. // this.houseList = list;//数据会同步到组件中-进而反馈更新页面数据
  1499. // }
  1500. // },
  1501. onMouseMove(e){
  1502. return false;
  1503. },
  1504. //进入布局选择模式
  1505. enterPlot(gltf){
  1506. if(gltf.spaceType==13){//楼梯不处理
  1507. return false
  1508. }
  1509. // this.selectSpace = this.spaceList.find(it=>it.spaceId==gltf.spaceId);
  1510. this.$refs.viewShell.changeStyleType(3,this.selectSpace)
  1511. },
  1512. selectSpaceHandle(gltf){
  1513. if(gltf.spaceType==13){//楼梯不处理
  1514. return false
  1515. }
  1516. if(this.selectSpace){
  1517. this.changeSpaceColor(this.selectSpace.spaceId,2);//取消上一个空间的颜色
  1518. }
  1519. this.selectSpace = this.spaceList.find(it=>it.spaceId==gltf.spaceId);
  1520. this.changeSpaceColor(this.selectSpace.spaceId,1);//设置选中空间的颜色
  1521. },
  1522. //用户选择的布局id-需要切换到这个布局去
  1523. userSelectPlot(layoutObj){
  1524. if(!layoutObj){
  1525. console.warn("***userSelectPlot***数据错误")
  1526. return false
  1527. }
  1528. let spaceId = this.selectSpace.spaceId;
  1529. console.warn("***userSelectPlot***",spaceId,layoutObj)
  1530. this.changeSingleLayout(spaceId,layoutObj);
  1531. this.updataLable(spaceId,layoutObj);
  1532. },
  1533. async goRoam1(spaceId){
  1534. if(this.overChange){
  1535. this.$message.warning("空间正在调整");
  1536. return false
  1537. }
  1538. let shottingImg = await this.shottingAction() + "?x-oss-process=image/auto-orient,1/quality,Q_46/format,jpg";//开始截图
  1539. console.warn("***shottingImg***",shottingImg);
  1540. setStorage('shottingImg', shottingImg);//把空间选择的数据存入本地缓存里面,方便后续使用
  1541. let gltf = this.lableItem.find(it=>it.spaceId==spaceId);
  1542. if(gltf){
  1543. this.goRoam(gltf)
  1544. }
  1545. },
  1546. //物体漫游-切换页面的方式进入
  1547. goRoam(gltf){
  1548. console.warn('goRoam',gltf,this.selectSpace);
  1549. if(gltf.spaceType==13){//楼梯不能跳转
  1550. return false
  1551. }
  1552. let spaceId = this.selectSpace ? this.selectSpace.spaceId : gltf.spaceId;//具体的空间Id
  1553. let data = {
  1554. spaceId:spaceId,
  1555. houseId:this.houseId,
  1556. }
  1557. if(this.repeatFlag){
  1558. return false;
  1559. }
  1560. this.repeatFlag = true;
  1561. router.push({
  1562. name: "webgl_rxdz_roam",
  1563. query:data
  1564. });
  1565. if(this.isIOS){
  1566. setStorage('curHouseObj', this.curHouseObj);
  1567. setStorage('wallList', this.wallList);
  1568. }
  1569. this.$store.dispatch('setCurHouseObj', this.curHouseObj);
  1570. this.$store.dispatch('setWallList', this.wallList);
  1571. setTimeout(()=> {
  1572. this.repeatFlag = false;
  1573. }, 1000);
  1574. },
  1575. //obj 物体对象,type 是否改变颜色
  1576. moveMeshCenter(obj,type){
  1577. console.warn("**moveMeshCenter***",obj)
  1578. if(obj && this.gltfSpaces && this.gltfSpaces.length>0){
  1579. this.moveMeshCenterHandle(obj,type);
  1580. }
  1581. },
  1582. // 绘制地板
  1583. async loadSpace(){
  1584. this.spaceList = [];
  1585. this.wallIds = [];
  1586. this.layoutIds = [];
  1587. this.gltfSpaces = [];
  1588. this.curWallArr = [];
  1589. this.progress = 0;
  1590. if(!this.curHouseObj){//减少重复请求
  1591. return false
  1592. }
  1593. let type=[];
  1594. if(this.curHouseObj){
  1595. const spaceDetail = this.curHouseObj;
  1596. const spaceList = JSON.parse(spaceDetail.houseJson);
  1597. // 交换centerX, centerY;上一页面已经处理过了,这里不在需要处理
  1598. for (let index = 0; index < spaceList.length; index++) {
  1599. var element = spaceList[index];
  1600. // const centerX = JSON.parse(JSON.stringify(element.centerX))
  1601. // element.centerX = element.centerY;
  1602. // element.centerY = centerX;
  1603. element.wallMoveValue = "[0,0,0,0]"
  1604. this.spaceList.push(element);
  1605. this.wallIds.push(element.wallId);
  1606. this.layoutIds.push(element.layoutId);
  1607. type.push(element.spaceType);
  1608. if(element.isSelected){ // 默认选中空间
  1609. this.curSpaceObj = element;
  1610. }
  1611. }
  1612. if(!this.curSpaceObj && this.spaceList.length > 0){
  1613. this.curSpaceObj = this.spaceList[0];
  1614. }
  1615. }
  1616. console.log("该户型空间数据:", this.spaceList, this.layoutIds,type);
  1617. console.log("当前选中的空间:", this.curSpaceObj,this.curHouseObj);
  1618. this.spaceListBackup = JSON.parse(JSON.stringify(this.spaceList));
  1619. this.loaderSpaceArr(this.spaceList);
  1620. // 绘制墙体
  1621. this.getHouseTypeSpaceWalls();
  1622. },
  1623. //更改空间显示名称 X空间 类型 根据布局所属类型来显示
  1624. updataLable(spaceId,layoutObj){
  1625. let list = this.arrFrunList;
  1626. let lable = this.lableItem.find(it=>it.spaceId == spaceId);
  1627. let name = spaceTypes[layoutObj.type - 1];
  1628. lable.text = name;
  1629. // this.lableItem.forEach(lable=>{
  1630. // if(lable.spaceType==15){
  1631. // let layoutId = this.spaceList.find(it => it.spaceId == lable.spaceId).layoutId;
  1632. // let layout = list.find(it=>it.id == layoutId);
  1633. // if(layout){
  1634. // let name = spaceTypes[layout.type - 1];
  1635. // lable.text = name
  1636. // }
  1637. // }
  1638. // })
  1639. console.warn("***updataLable***",lable)
  1640. this.$refs.viewShell.$refs.viewCareful.updataData(spaceId,layoutObj);
  1641. },
  1642. // 添加文字标签
  1643. addWordLabel(){
  1644. if(!this.gltfSpaces || this.gltfSpaces.length <= 0){
  1645. return false;
  1646. }
  1647. // 方案二
  1648. this.lableItem = [];
  1649. this.gltfSpaces.forEach((cube,index) =>{
  1650. // 给地板加上空间类型标注, 空间为链接空间的不显示
  1651. if(cube.spaceName && !cube.isSizeLock){
  1652. let spaceIndex = this.spaceList.filter(it=>it.spaceName && !it.isSizeLock).findIndex(item=>item.spaceId==cube.spaceId);
  1653. let name = spaceTypes[cube.spaceType - 1];
  1654. if(cube.spaceType==15){ //更改空间显示名称 X空间 类型 根据布局所属类型来显示
  1655. let layoutId = this.spaceList.find(it => it.spaceId == cube.spaceId).layoutId;
  1656. let layout = this.arrFrunList.find(it=>it.id == layoutId);
  1657. if(layout){
  1658. name = spaceTypes[layout.type - 1];
  1659. }
  1660. }
  1661. this.lableItem.push(
  1662. {
  1663. text:name,
  1664. spaceId:cube.spaceId,
  1665. spaceType:cube.spaceType,
  1666. transform:'',
  1667. spaceIndex:spaceIndex,
  1668. cubeIndex:index,
  1669. }
  1670. )
  1671. }
  1672. })
  1673. this.showLables = true;
  1674. // this.updateLables();//更新lable
  1675. },
  1676. // 获取墙体数据
  1677. async getHouseTypeSpaceWalls(){
  1678. let data = {id:this.wallIds}
  1679. const res = await requestConfig('getHouseTypeSpaceWalls', data, true);
  1680. console.log("墙体数据:", res.list)
  1681. let wallList = [];
  1682. if(res.success){
  1683. wallList = this.wallList = res.list;
  1684. }
  1685. let wallArr = []
  1686. for (let index = 0; index < wallList.length; index++) {//每个空间对应一个数据
  1687. let element = JSON.parse(wallList[index].wallJson);
  1688. let space = this.spaceList.find(space=>space.spaceId==element.spaceId);
  1689. if(!space){//存在映射不上的数据
  1690. console.warn("***computeWallHandleOld-warn***",index,element,this.spaceList)
  1691. continue;
  1692. }
  1693. this.computeWallHandleOld(space,element);//提前计算
  1694. for (let i = 0; i < element.wallData.length; i ++) {//对应空间里面的4个方向的墙壁数据
  1695. let wallData = element.wallData[i];
  1696. //对应方向的墙壁的墙体模型数据列表,每一面墙可能有多个模型
  1697. for (let j = 0; j < wallData.wallModelData.length; j ++) {
  1698. let wallModelData = wallData.wallModelData[j];
  1699. wallArr.push({spaceId:element.spaceId, wallModelData:wallModelData, wallDirection:wallData.wallDirection})
  1700. // console.log("wallModelData", element,wallData.wallDirection, wallModelData.wallType );
  1701. }
  1702. }
  1703. }
  1704. this.loadSpaceObjWalls(wallArr, wallList);
  1705. this.getOverallArrangementDetailsList(2);
  1706. },
  1707. // 加载单个空间墙体资源
  1708. async loadSpaceObjWalls(wallArr, wallList){
  1709. // 加载远程墙体模型资源
  1710. let startTime = new Date().getTime();
  1711. // console.log("wallArr:", wallArr)
  1712. let promise_list = [];
  1713. let realWallArr = this.preWallData(wallArr);
  1714. let arrLength = realWallArr.length;
  1715. realWallArr && realWallArr.forEach((item,index) => {
  1716. promise_list.push(
  1717. new Promise((resolve, reject) => {
  1718. this.loadWallModels(item, wallList, arrLength , resolve);
  1719. })
  1720. )
  1721. });
  1722. Promise.all(promise_list).then(()=>{
  1723. let endTime = new Date().getTime();
  1724. console.log("模型全部加载完成,时间:",endTime - startTime);
  1725. this.progress = 100;
  1726. // this.$refs.myLoading.showLoading("加载中..." + this.progress + '%')
  1727. // 设置空间数组的墙体信息
  1728. // this.setSpaceListWallInfo();
  1729. this.$nextTick(()=>{
  1730. this.moveMeshCenter(this.curSpaceObj);
  1731. // this.myLoadingStatus = false;
  1732. // this.$refs.myLoading.hideLoading();
  1733. setTimeout(()=>{
  1734. this.addWordLabel(); // 添加文字标签
  1735. }, 610);
  1736. // 设置空间数组的墙体信息
  1737. })
  1738. })
  1739. },
  1740. // 选择墙体
  1741. selectedWall(direction){
  1742. if(!direction || direction==""){
  1743. return
  1744. }
  1745. console.log(`当前空间的id:${this.curSpaceObj.spaceId};墙面方向:${direction};宽度:${this.curSpaceObj.spaceWidth};宽度:${this.curSpaceObj.spaceHeight}`)
  1746. console.log("当前空间的:", this.curSpaceObj);
  1747. this.leftSpaces = [];
  1748. this.rightSpaces = [];
  1749. this.tempSpaceList = JSON.parse(JSON.stringify(this.spaceList));
  1750. // 计算关联空间
  1751. this.findLeftRelateSpace(this.curSpaceObj, direction);
  1752. console.log("空间数组:", this.leftSpaces, this.rightSpaces);
  1753. // 计算墙体的可移动范围
  1754. var min = 0;
  1755. var max = 300;
  1756. // 计算最小值
  1757. for (let index = 0; index < this.leftSpaces.length; index++) {
  1758. const element = this.leftSpaces[index];
  1759. console.log("左边空间数据:", element);
  1760. var spaceMoveNW = element.spaceWidth;
  1761. var spaceMoveSW = element.spaceWidth;
  1762. var spaceMoveEH = element.spaceHeight;
  1763. var spaceMoveWH = element.spaceHeight;
  1764. var curSpaceWall = [];
  1765. for (let index = 0; index < this.gltfWalls.length; index++) {
  1766. const wall = this.gltfWalls[index];
  1767. if(element.spaceId == wall.spaceId && wall.wallDirection != direction){
  1768. curSpaceWall.push(wall);
  1769. if((direction == "W" || direction == "E") && wall.wallDirection != direction){
  1770. if(wall.wallDirection == "N"){
  1771. spaceMoveNW -= wall.wallModelData.wallWidth;
  1772. console.log("北边墙:", spaceMoveNW, wall.wallModelData.wallWidth, wall.id);
  1773. }
  1774. if(wall.wallDirection == "S"){
  1775. spaceMoveSW -= wall.wallModelData.wallWidth;
  1776. console.log("南边墙:", spaceMoveSW, wall.wallModelData.wallWidth, wall.id);
  1777. }
  1778. this.curWallValue = Math.floor(Math.min(Math.min(spaceMoveNW, spaceMoveSW), this.curWallValue));
  1779. }
  1780. if((direction == "N" || direction == "S") && wall.wallDirection != direction){
  1781. if(wall.wallDirection == "E"){
  1782. spaceMoveEH -= wall.wallModelData.wallWidth;
  1783. console.log("东边墙:", spaceMoveNW, wall.wallModelData.wallWidth, wall.id);
  1784. }
  1785. if(wall.wallDirection == "W"){
  1786. spaceMoveWH -= wall.wallModelData.wallWidth;
  1787. console.log("西边墙:", spaceMoveSW, wall.wallModelData.wallWidth, wall.id);
  1788. }
  1789. this.curWallValue = Math.floor(Math.min(Math.min(spaceMoveEH, spaceMoveWH), this.curWallValue));
  1790. }
  1791. }
  1792. }
  1793. // 排序墙体数据
  1794. curSpaceWall.sort(function(a,b){return a.wallModelData.id -b.wallModelData.id});
  1795. curSpaceWall.sort(function(a,b){return a.wallDirection.localeCompare(b.wallDirection)})
  1796. console.log("墙体模型:", curSpaceWall, spaceMoveNW, spaceMoveSW);
  1797. console.log("可缩小的最小值:", Math.floor(Math.min(spaceMoveNW, spaceMoveSW)));
  1798. if((direction == "W" || direction == "E") && element.spaceWidth == this.curWallValue){
  1799. this.curWallValue = 149;
  1800. }
  1801. if((direction == "N" || direction == "S") && element.spaceHeight == this.curWallValue){
  1802. this.curWallValue = 149;
  1803. }
  1804. // this.curWallValue = Math.floor(Math.min(spaceMoveNW, spaceMoveSW));
  1805. }
  1806. // 计算最大值
  1807. for (let index = 0; index < this.rightSpaces.length; index++) {
  1808. const element = this.rightSpaces[index];
  1809. console.log("右边空间数据:", element);
  1810. var spaceMoveNW = element.spaceWidth;
  1811. var spaceMoveSW = element.spaceWidth;
  1812. var spaceMoveEH = element.spaceHeight;
  1813. var spaceMoveWH = element.spaceHeight;
  1814. var curSpaceWall = [];
  1815. for (let index = 0; index < this.gltfWalls.length; index++) {
  1816. const wall = this.gltfWalls[index];
  1817. if(element.spaceId == wall.spaceId && wall.wallDirection != direction){
  1818. curSpaceWall.push(wall);
  1819. if((direction == "W" || direction == "E") && wall.wallDirection != direction){
  1820. if(wall.wallDirection == "N"){
  1821. spaceMoveNW -= wall.wallModelData.wallWidth;
  1822. console.log("北边墙:", spaceMoveNW, wall.wallModelData.wallWidth, wall.id);
  1823. }
  1824. if(wall.wallDirection == "S"){
  1825. spaceMoveSW -= wall.wallModelData.wallWidth;
  1826. console.log("南边墙:", spaceMoveSW, wall.wallModelData.wallWidth, wall.id);
  1827. }
  1828. this.curWallMaxValue = Math.floor(Math.min(spaceMoveNW, spaceMoveSW)) + this.curWallValue;
  1829. }
  1830. if((direction == "N" || direction == "S") && wall.wallDirection != direction){
  1831. if(wall.wallDirection == "E"){
  1832. spaceMoveEH -= wall.wallModelData.wallWidth;
  1833. console.log("东边墙:", spaceMoveNW, wall.wallModelData.wallWidth, wall.id);
  1834. }
  1835. if(wall.wallDirection == "W"){
  1836. spaceMoveWH -= wall.wallModelData.wallWidth;
  1837. console.log("西边墙:", spaceMoveSW, wall.wallModelData.wallWidth, wall.id);
  1838. }
  1839. this.curWallMaxValue = Math.floor(Math.min(spaceMoveEH, spaceMoveWH)) + this.curWallValue;
  1840. }
  1841. }
  1842. }
  1843. // 排序墙体数据
  1844. curSpaceWall.sort(function(a,b){return a.wallModelData.id -b.wallModelData.id});
  1845. curSpaceWall.sort(function(a,b){return a.wallDirection.localeCompare(b.wallDirection)})
  1846. console.log("墙体模型:", curSpaceWall, spaceMoveNW, spaceMoveSW);
  1847. console.log("可缩小的最小值:", Math.floor(Math.min(spaceMoveNW, spaceMoveSW)));
  1848. }
  1849. console.log(`当前墙面的最大值:${this.curWallMaxValue}, 最小值:${this.curWallValue}`)
  1850. // 统计变化的空间
  1851. this.changeSpaces.push(...this.leftSpaces)
  1852. this.changeSpaces.push(...this.rightSpaces)
  1853. },
  1854. // 递归寻找左边->右边关联空间
  1855. findLeftRelateSpace(spaceObj, direction){
  1856. const {eastId, westId, northId, southId, spaceId} = spaceObj;
  1857. const leftIndex = this.tempSpaceList.findIndex((item)=>{
  1858. return item.spaceId == spaceId;
  1859. })
  1860. if(leftIndex!=-1){
  1861. const spaceObj = this.tempSpaceList[leftIndex];
  1862. this.leftSpaces.push(spaceObj);
  1863. this.tempSpaceList.splice(leftIndex,1);
  1864. const leftNextIndex = this.tempSpaceList.findIndex((item)=>{
  1865. if(direction == "E"){
  1866. return item.spaceId == eastId;
  1867. }else if(direction == "W"){
  1868. return item.spaceId == westId;
  1869. }else if(direction == "S"){
  1870. return item.spaceId == southId;
  1871. }else if(direction == "N"){
  1872. return item.spaceId == northId;
  1873. }
  1874. })
  1875. if(leftNextIndex!=-1){
  1876. const nextSpaceObj = this.tempSpaceList[leftNextIndex];
  1877. console.log("递归再一次", nextSpaceObj);
  1878. this.findRightRelateSpace(nextSpaceObj, direction);
  1879. }
  1880. const rightArr = this.tempSpaceList.filter((item)=>{
  1881. if(direction == "E"){
  1882. return item.westId == spaceId;
  1883. }else if(direction == "W"){
  1884. return item.eastId == spaceId;
  1885. }else if(direction == "S"){
  1886. return item.northId == spaceId;
  1887. }else if(direction == "N"){
  1888. return item.southId == spaceId;
  1889. }
  1890. })
  1891. for (let index = 0; index < rightArr.length; index++) {
  1892. const nextSpaceObj = rightArr[index];
  1893. // const nextSpaceObj = this.tempSpaceList[rightNextIndex];
  1894. console.log("递归再一次", nextSpaceObj);
  1895. this.findRightRelateSpace(nextSpaceObj, direction);
  1896. }
  1897. }
  1898. },
  1899. // 递归寻找右边->左边关联空间
  1900. findRightRelateSpace(spaceObj, direction){
  1901. const {eastId, westId, northId, southId, spaceId} = spaceObj;
  1902. const rightIndex = this.tempSpaceList.findIndex((item)=>{
  1903. return item.spaceId == spaceId;
  1904. })
  1905. if(rightIndex!=-1){
  1906. const spaceObj = this.tempSpaceList[rightIndex];
  1907. this.rightSpaces.push(spaceObj);
  1908. this.tempSpaceList.splice(rightIndex,1);
  1909. console.log("当前空间数组:", this.tempSpaceList);
  1910. const leftNextIndex = this.tempSpaceList.findIndex((item)=>{
  1911. if(direction == "E"){
  1912. return item.spaceId == westId;
  1913. }else if(direction == "W"){
  1914. return item.spaceId == eastId;
  1915. }else if(direction == "N"){
  1916. return item.spaceId == southId;
  1917. }else if(direction == "S"){
  1918. return item.spaceId == northId;
  1919. }
  1920. })
  1921. if(leftNextIndex!=-1){
  1922. const nextSpaceObj = this.tempSpaceList[leftNextIndex];
  1923. console.log("递归再一次", nextSpaceObj);
  1924. this.findLeftRelateSpace(nextSpaceObj, direction);
  1925. }
  1926. const rightArr = this.tempSpaceList.filter((item)=>{
  1927. if(direction == "E"){
  1928. return item.eastId == spaceId;
  1929. }else if(direction == "W"){
  1930. return item.westId == spaceId;
  1931. }else if(direction == "N"){
  1932. return item.northId == spaceId;
  1933. }else if(direction == "S"){
  1934. return item.southId == spaceId;
  1935. }
  1936. });
  1937. for (let index = 0; index < rightArr.length; index++) {
  1938. const nextSpaceObj = rightArr[index];
  1939. console.log("递归再一次", nextSpaceObj);
  1940. this.findLeftRelateSpace(nextSpaceObj, direction);
  1941. }
  1942. }
  1943. },
  1944. moveSpaceWall(direction, moveOut, moveValue){
  1945. // let isNS = (direction == "N" || direction == "S")
  1946. // if(!this.checkRightSpace(!moveOut, moveValue, isNS)){
  1947. // return
  1948. // }
  1949. // 隐藏变化空间的家具模型,空间动画结束后显示
  1950. if(moveValue<= 0){ // 无需变化
  1951. return
  1952. }
  1953. this.changeLayoutModelState();
  1954. console.log("关联空间XXXXX", this.leftSpaces, this.rightSpaces)
  1955. for (let index = 0; index < this.leftSpaces.length; index++) {
  1956. const element = this.leftSpaces[index];
  1957. const space = this.spaceList.find((item)=>{
  1958. return item.spaceId == element.spaceId;
  1959. })
  1960. this.moveWall(space, direction, moveOut, moveValue);
  1961. // this.wallTransform(space, direction, moveOut, moveValue);
  1962. }
  1963. let otherdirection = "";
  1964. switch (direction) {
  1965. case "E":
  1966. otherdirection = "W"
  1967. break;
  1968. case "W":
  1969. otherdirection = "E"
  1970. break;
  1971. case "N":
  1972. otherdirection = "S"
  1973. break;
  1974. case "S":
  1975. otherdirection = "N"
  1976. break;
  1977. }
  1978. for (let index = 0; index < this.rightSpaces.length; index++) {
  1979. const element = this.rightSpaces[index];
  1980. this.moveWall(element, otherdirection, !moveOut, moveValue);
  1981. }
  1982. console.log(`当前空间的后id:${this.curSpaceObj.spaceId};墙面方向:${direction};宽度:${this.curSpaceObj.spaceWidth};高度:${this.curSpaceObj.spaceHeight}`)
  1983. },
  1984. // 调整大小
  1985. // direction:方向
  1986. // moveOut:是否外移
  1987. // moveValue: 移动距离
  1988. moveWall(spaceObj, direction, moveOut, moveValue){
  1989. console.log(`移动的空间的id-------:${spaceObj.spaceId};移动方向:${direction};是否外移:${moveOut};移动距离:${moveValue}`)
  1990. const oldSpaceObj = JSON.parse(JSON.stringify(spaceObj))
  1991. const cube = this.gltfSpaces.find((item)=>{
  1992. return item.spaceId == spaceObj.spaceId;
  1993. })
  1994. if(!cube){
  1995. return
  1996. }
  1997. if(!moveOut){
  1998. moveValue = moveValue * -1;
  1999. }
  2000. const {position,scale} = cube;
  2001. // 重新计算缩放 和 位置
  2002. let toScaleX = scale.x;
  2003. let toScaleZ = scale.z;
  2004. let toPx = position.x;
  2005. let toPz = position.z;
  2006. if(direction == 'E' || direction == 'W'){
  2007. let spaceWidth = scale.x * 300;
  2008. toScaleX = (spaceWidth + moveValue) / 300;
  2009. if(direction == 'W'){
  2010. toPx = position.x - moveValue / 2 / 100;
  2011. }else{
  2012. toPx = position.x + moveValue / 2 / 100;
  2013. }
  2014. spaceObj.spaceWidth += moveValue;
  2015. spaceObj.centerX = toPx * 100;
  2016. }
  2017. if(direction == 'N' || direction == 'S'){
  2018. let spaceHeight = scale.z * 300;
  2019. toScaleZ = (spaceHeight + moveValue) / 300;
  2020. if(direction == 'N'){
  2021. toPz = position.z - moveValue / 2 / 100;
  2022. }else{
  2023. toPz = position.z + moveValue / 2 / 100;
  2024. }
  2025. spaceObj.spaceHeight += moveValue;
  2026. spaceObj.centerY = toPz * 100 * -1;
  2027. }
  2028. console.log("curSpaceObj",this.curSpaceObj.spaceId, spaceObj.spaceId, spaceObj.centerX, spaceObj.centerY, toScaleX,toScaleZ,toPx,toPz)
  2029. console.log("当前空间变化后的尺寸",spaceObj.spaceWidth, spaceObj.spaceHeight, spaceObj.spaceId)
  2030. // 更新数据
  2031. const spaceIndex = this.spaceList.findIndex((item)=>{
  2032. return item.spaceId == spaceObj.spaceId;
  2033. })
  2034. if(spaceIndex!=-1){
  2035. this.spaceList[spaceIndex] = spaceObj;
  2036. if(this.curSpaceObj.spaceId == spaceObj.spaceId){
  2037. this.curSpaceObj = spaceObj;
  2038. }
  2039. }
  2040. this.curHouseObj.houseJson = JSON.stringify(this.spaceList);
  2041. //空间动画处理-提取到floorMethod.js中
  2042. this.changeSpacesAnim({spaceId:spaceObj.spaceId,toScaleX,toScaleZ,toPx,toPz,spaceObj})
  2043. // 墙体动画处理
  2044. //// 根据空间尺寸,更新前提数据
  2045. const wallObj = this.wallList.find((item)=>{
  2046. return item.id == spaceObj.wallId;
  2047. })
  2048. const initSpaceObj = this.spaceListBackup.find((item)=>{
  2049. return item.spaceId == spaceObj.spaceId;
  2050. })
  2051. if(wallObj){
  2052. let element = JSON.parse(wallObj.wallJson);
  2053. console.warn("****wallObj**",element)
  2054. this.computeWallHandle(initSpaceObj, spaceObj, element, moveOut, direction); // 重新计算-并把空间的计算结果同步到gltfWalls中
  2055. }
  2056. // 移动墙体
  2057. let curSpaceWall = [];
  2058. for (let index = 0; index < this.gltfWalls.length; index++) {
  2059. const element = this.gltfWalls[index];
  2060. if(spaceObj.spaceId == element.spaceId){
  2061. curSpaceWall.push(element);
  2062. }
  2063. }
  2064. //移动的是西方的墙壁 和 南方的墙壁,该空间的几何体中心则移动变化
  2065. if(direction == 'W' || direction == 'S'){
  2066. spaceObj.rightCenter = true;
  2067. }
  2068. //移动的是东方的墙壁 和 北方的墙壁,该空间的几何体中心则不移动变化
  2069. if(direction == 'E'|| direction == 'N'){
  2070. spaceObj.rightCenter = false;
  2071. }
  2072. spaceObj.direction = direction
  2073. // 排序墙体数据
  2074. curSpaceWall.sort(function(a,b){return a.wallModelData.id -b.wallModelData.id});
  2075. curSpaceWall.sort(function(a,b){return a.wallDirection.localeCompare(b.wallDirection)})
  2076. console.log("移动的墙体:", spaceObj, direction, curSpaceWall);
  2077. // return;
  2078. for (let index = 0; index < curSpaceWall.length; index++) {
  2079. const element = curSpaceWall[index];
  2080. console.log("重新计算墙体-墙体数据:", element, element);
  2081. this.drawModel(element.wallModelData, spaceObj, element, true)
  2082. }
  2083. // }
  2084. },
  2085. // 空隙自动补签逻辑
  2086. autoCreateWall(directionIndex, spaceObj){
  2087. let direction = ""
  2088. switch (directionIndex) {
  2089. case 1:
  2090. direction = "N"
  2091. break;
  2092. case 2:
  2093. direction = "S"
  2094. break;
  2095. case 3:
  2096. direction = "W"
  2097. break;
  2098. case 4:
  2099. direction = "E"
  2100. break;
  2101. default:
  2102. break;
  2103. }
  2104. // 东西墙 检查 南北墙关联空间 南北墙 检查 东西墙关联空间
  2105. if(direction == "E" || direction == "W"){
  2106. if(spaceObj.quadrant == 3 || spaceObj.quadrant == 4){ // 南边空间
  2107. console.log("南北朝向墙自动补齐", this.leftSpaces, this.rightSpaces)
  2108. this.selectedWall("N");
  2109. this.checkIsAutoCreateWall("N", spaceObj)
  2110. this.selectedWall("S");
  2111. this.checkIsAutoCreateWall("S", spaceObj)
  2112. let autoWall = this.gltfAutoWalls.find(item=>{
  2113. return item.spaceId == spaceObj.spaceId ;
  2114. })
  2115. if(autoWall){
  2116. console.log("南北朝向墙自动补齐---", autoWall, this.gltfAutoWalls)
  2117. if(autoWall.wallDirection == "E"){
  2118. autoWall.obj.position.x = (spaceObj.centerX + (spaceObj.spaceWidth / 2) - 5) / 100
  2119. }
  2120. }
  2121. }else{ // 北边关联空间
  2122. }
  2123. }else{
  2124. if(spaceObj.quadrant == 3 || spaceObj.quadrant == 4){ // 南边空间
  2125. console.log("东西朝向墙自动补齐", this.leftSpaces, this.rightSpaces)
  2126. this.selectedWall("E");
  2127. this.checkIsAutoCreateWall("E", spaceObj)
  2128. this.selectedWall("W");
  2129. this.checkIsAutoCreateWall("W", spaceObj)
  2130. }else{ // 北边关联空间
  2131. }
  2132. }
  2133. },
  2134. // 检测是否需要补强
  2135. checkIsAutoCreateWall(direction, spaceObj){
  2136. var that = this;
  2137. // 判断南边墙是否需要补充
  2138. if(this.rightSpaces.length == 0){
  2139. console.log("不需要补墙1", direction, this.gltfAutoWalls)
  2140. return;
  2141. }
  2142. const n = (direction == "S" || direction == "E") ? 1 : -1; // 南北方向计算系数
  2143. console.log("自动补墙", this.leftSpaces, this.rightSpaces);
  2144. let px = 0;
  2145. let pz = 0;
  2146. let sx = 1;
  2147. let sz = 1;
  2148. let rightids = []
  2149. if(spaceObj.quadrant == 3){
  2150. // 左边空间的最大值
  2151. let leftMaxValue = 0;
  2152. for (let index = 0; index < this.leftSpaces.length; index++) {
  2153. const element = this.leftSpaces[index];
  2154. if(direction=="S" || direction == "N"){
  2155. const curvalue = element.centerX + element.spaceWidth / 2
  2156. if(leftMaxValue < curvalue){
  2157. leftMaxValue = curvalue
  2158. }
  2159. }else{
  2160. leftMaxValue += (-element.centerY + element.spaceHeight / 2)
  2161. }
  2162. }
  2163. // rightSpaces右边最大值
  2164. let rightMaxValue = 0;
  2165. for (let index = 0; index < this.rightSpaces.length; index++) {
  2166. const element = this.rightSpaces[index];
  2167. if(direction=="S" || direction == "N"){
  2168. const curvalue = element.centerX + element.spaceWidth / 2
  2169. if(rightMaxValue < curvalue){
  2170. rightMaxValue = curvalue
  2171. }
  2172. }else{
  2173. rightMaxValue += -element.centerY + element.spaceHeight / 2
  2174. }
  2175. rightids.push(element.spaceId)
  2176. }
  2177. // 是否有墙
  2178. const index = this.gltfWalls.findIndex(item=>{
  2179. // console.log("墙面模型", item)
  2180. return spaceObj.spaceId == item.spaceId && item.wallDirection == direction;
  2181. })
  2182. // 有墙,左边墙>右边墙,计算南北墙
  2183. if(index != -1 && leftMaxValue > rightMaxValue && (direction == "S" || direction == "N")){
  2184. console.log("不需要补墙251",index, leftMaxValue, rightMaxValue)
  2185. // 是否补过墙
  2186. const autoWall = this.gltfAutoWalls.find(item=>{
  2187. return item.rightids.indexOf(spaceObj.spaceId) != -1 && item.wallDirection == (direction == "S" ? "N": "S");
  2188. })
  2189. if(autoWall){
  2190. let cube = autoWall.obj;
  2191. if(cube){
  2192. cube.scale.set(0,0,0);
  2193. }
  2194. }
  2195. return
  2196. }
  2197. // 有墙,左边墙>右边墙,计算东西墙
  2198. if(index != -1 && leftMaxValue > rightMaxValue && (direction == "E" || direction == "W")){
  2199. console.log("不需要补墙252",index, leftMaxValue, rightMaxValue, spaceObj.spaceId, direction, this.gltfAutoWalls)
  2200. const autoWall = this.gltfAutoWalls.find(item=>{
  2201. return item.rightids.indexOf(spaceObj.spaceId) != -1 && item.wallDirection == (direction == "E" ? "W": "E");
  2202. })
  2203. if(autoWall){
  2204. let cube = autoWall.obj;
  2205. if(cube){
  2206. cube.scale.set(0,0,0);
  2207. }
  2208. }
  2209. return
  2210. }
  2211. let wallOffset = index != -1 ? -5 : 5;
  2212. console.log("空间最大值", leftMaxValue, rightMaxValue, direction, index);
  2213. const cubeW = Math.abs(leftMaxValue - rightMaxValue);
  2214. if(direction=="S" || direction == "N"){
  2215. px = (Math.min(leftMaxValue, rightMaxValue) + cubeW / 2) / 100
  2216. pz = (-spaceObj.centerY + spaceObj.spaceHeight * n / 2 + wallOffset * n) / 100;
  2217. sx = cubeW / 10 ;
  2218. // 长边有墙
  2219. }else{
  2220. px = (spaceObj.centerX + spaceObj.spaceWidth * n / 2 + wallOffset * n) / 100;
  2221. pz = (Math.max(leftMaxValue, rightMaxValue) - cubeW / 2) / 100
  2222. sz = cubeW / 10;
  2223. }
  2224. }else{
  2225. let leftMinValue = 0;
  2226. for (let index = 0; index < this.leftSpaces.length; index++) {
  2227. const element = this.leftSpaces[index];
  2228. if(direction=="S" || direction == "N"){
  2229. leftMinValue += (element.centerX - element.spaceWidth / 2)
  2230. }else{
  2231. leftMinValue += (-element.centerY + element.spaceHeight / 2)
  2232. }
  2233. }
  2234. // rightSpaces右边最大值
  2235. let rightMinValue = 0;
  2236. for (let index = 0; index < this.rightSpaces.length; index++) {
  2237. const element = this.rightSpaces[index];
  2238. if(direction=="S" || direction == "N"){
  2239. rightMinValue += (element.centerX - element.spaceWidth / 2)
  2240. }else{
  2241. rightMinValue = (-element.centerY + element.spaceHeight / 2)
  2242. }
  2243. rightids.push(element.spaceId)
  2244. }
  2245. const index = this.gltfWalls.findIndex(item=>{
  2246. // console.log("墙面模型", item)
  2247. return spaceObj.spaceId == item.spaceId && item.wallDirection == direction;
  2248. })
  2249. if(index != -1 && leftMinValue < rightMinValue && (direction == "S" || direction == "N")){
  2250. console.log("不需要补墙251")
  2251. return
  2252. }
  2253. if(index != -1 && leftMinValue > rightMinValue && (direction == "E" || direction == "W")){
  2254. console.log("不需要补墙252")
  2255. return
  2256. }
  2257. let wallOffset = index != -1 ? -5 : 5;
  2258. console.log("空间最大值", leftMinValue, rightMinValue);
  2259. const cubeW = Math.abs(leftMinValue - rightMinValue);
  2260. if(leftMinValue > rightMinValue && index == -1 && (direction == "S" || direction == "N")){
  2261. console.log("不需要补墙241", leftMinValue, rightMinValue)
  2262. const autoWall = this.gltfAutoWalls.find(item=>{
  2263. return item.rightids.indexOf(spaceObj.spaceId) != -1 && item.wallDirection == (direction == "S" ? "N": "S");
  2264. })
  2265. if(autoWall){
  2266. let cube = autoWall.obj;
  2267. if(cube){
  2268. cube.scale.set(0,0,0);
  2269. }
  2270. }
  2271. return
  2272. }
  2273. if(leftMinValue < rightMinValue && index == -1 && (direction == "E" || direction == "W")){
  2274. console.log("不需要补墙242", leftMinValue, rightMinValue)
  2275. const autoWall = this.gltfAutoWalls.find(item=>{
  2276. return item.rightids.indexOf(spaceObj.spaceId) != -1 && item.wallDirection == (direction == "W" ? "E": "W");
  2277. })
  2278. if(autoWall){
  2279. let cube = autoWall.obj;
  2280. if(cube){
  2281. cube.scale.set(0,0,0);
  2282. }
  2283. }
  2284. return
  2285. }
  2286. if(direction=="S" || direction == "N"){
  2287. px = (Math.max(leftMinValue, rightMinValue) - cubeW / 2) / 100
  2288. pz = (-spaceObj.centerY + spaceObj.spaceHeight * n / 2 + wallOffset * n) / 100;
  2289. sx = cubeW / 10;
  2290. }else{
  2291. px = (spaceObj.centerX + spaceObj.spaceWidth * n / 2 + wallOffset * n) / 100;
  2292. pz = (Math.max(leftMinValue, rightMinValue) - cubeW / 2) / 100
  2293. sz = cubeW / 10;
  2294. }
  2295. }
  2296. console.log("空间最大值", px, pz, sx, sz, this.gltfAutoWalls);
  2297. // 寻找是否已添加过墙面
  2298. const autoWall = this.gltfAutoWalls.find(item=>{
  2299. return (item.spaceId == spaceObj.spaceId && item.wallDirection == direction)
  2300. || (item.rightids.findIndex(it=>{ return it == spaceObj.spaceId})!=-1 && item.wallDirection == direction == "S"?"N":"S")
  2301. || (item.rightids.findIndex(it=>{ return it == spaceObj.spaceId})!=-1 && item.wallDirection == direction == "E"?"W":"E")
  2302. })
  2303. if(this.curWallDirection == "S"){
  2304. if(spaceObj.southId > 0){
  2305. return
  2306. }
  2307. }
  2308. if(this.curWallDirection == "E"){
  2309. if(spaceObj.eastId > 0){
  2310. return
  2311. }
  2312. }
  2313. if(this.curWallDirection == "N"){
  2314. if(spaceObj.northId > 0){
  2315. return
  2316. }
  2317. }
  2318. if(this.curWallDirection == "W"){
  2319. if(spaceObj.westId > 0){
  2320. return
  2321. }
  2322. }
  2323. if(autoWall){
  2324. console.log("修改补墙的信息", px, pz, sx, sz);
  2325. let cube = autoWall.obj;
  2326. cube.position.set(px,0,pz);
  2327. cube.scale.set(sx,1,sz);
  2328. }else{
  2329. console.log("添加补墙的信息", px, pz, sx, sz);
  2330. that.loader.load(wallType[0].url, ( gltf ) => {
  2331. let cube = gltf.scene;
  2332. cube.position.set(px,0,pz);
  2333. cube.scale.set(sx,1,sz);
  2334. that.scene.add(cube);
  2335. let md = {
  2336. obj:cube,
  2337. wallDirection:direction,
  2338. spaceId:spaceObj.spaceId,
  2339. quadrant:spaceObj.quadrant,
  2340. rightids:rightids
  2341. };
  2342. that.gltfAutoWalls.push(md);
  2343. // console.log("模型加载成功", that.gltfAutoWalls, spaceObj.spaceId);
  2344. });
  2345. }
  2346. },
  2347. // 墙体缩放逻辑
  2348. wallTransform(spaceObj, direction, moveOut, moveValue){
  2349. console.log(`移动的空间的id:${spaceObj.spaceId};移动方向:${direction};是否外移:${moveOut};移动距离:${moveValue}`)
  2350. },
  2351. updateWallModels(){
  2352. let that = this;
  2353. console.log("开始替换墙体模型", this.leftSpaces, this.rightSpaces, this.gltfWalls);
  2354. let promise_list = [];
  2355. // const gltfWalls = JSON.parse(JSON.stringify(this.gltfWalls))
  2356. this.gltfWalls.forEach((item,index) => {
  2357. promise_list.push(
  2358. new Promise((resolve, reject) => {
  2359. this.loadChangeWallModels(item, resolve);
  2360. })
  2361. )
  2362. });
  2363. Promise.all(promise_list).then(()=>{
  2364. this.$nextTick(()=>{
  2365. let newArr = [];
  2366. const newWalls = that.gltfWalls.filter(it=>{
  2367. return !it.isDidWall
  2368. })
  2369. that.gltfWalls = newWalls;
  2370. console.log("加载完成2",newWalls, newArr, that.gltfWalls, that.wallList);
  2371. })
  2372. })
  2373. },
  2374. }
  2375. }
  2376. </script>
  2377. <style lang="scss" scoped>
  2378. @import "./webgl_rxdz_test.scss";
  2379. </style>