webgl_rxdz.vue 95 KB

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