webgl_rxdz.vue 96 KB

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