webgl_rxdz.vue 96 KB

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