webgl_rxdz.vue 97 KB

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