webgl_rxdz.vue 95 KB

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