loadModel - 副本.js 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054
  1. var app = getApp(); //获取应用实例
  2. const util = require('@/static/utils/util.js');
  3. const config = require('@/static/config.js');
  4. import modelData from '@/webgl/static/layoutModelData.js';
  5. import globlShowModel from '@/webgl/static/globlShowModel.js';
  6. import requestConfig from '@/static/lib/requestConfig';
  7. import { DRACOLoader } from '@/webgl/jsm/loaders/DRACOLoader.js';
  8. const THREE = requirePlugin('ThreeX');
  9. // import { TWEEN } from '@/webgl/jsm/libs/tween.module.min.js';
  10. export default {
  11. data() {
  12. return {
  13. gltfLayouts: [],
  14. instancedFurList:[],
  15. arrFrunList:[],
  16. promise_list:[],
  17. dracoLoader:null,
  18. type:1,
  19. tmpList:[],
  20. realList:[],
  21. changeLayouts:[]
  22. }
  23. },
  24. watch: {},
  25. mounted() {
  26. console.warn("***loadmodel-mounted****")
  27. this.dracoLoader = new DRACOLoader();
  28. this.dracoLoader.setDecoderPath('/webgl/draco/gltf/');
  29. this.dracoLoader.setDecoderConfig( { type: 'js' } );
  30. this.dracoLoader.preload();
  31. },
  32. methods: {
  33. // 设置空间数组的墙体信息
  34. async setSpaceListWallInfo(){
  35. for (let index = 0; index < this.spaceList.length; index++) {
  36. let spaceWallInfo = {wallN:false, wallS:false, wallW:false, wallE:false}
  37. const element = this.spaceList[index];
  38. const wallWIndex = this.gltfWalls.findIndex(item=>{
  39. return element.spaceId == item.spaceId && item.wallDirection == "W"
  40. })
  41. spaceWallInfo.wallW = wallWIndex == -1 ? false : true;
  42. const wallEIndex = this.gltfWalls.findIndex(item=>{
  43. return element.spaceId == item.spaceId && item.wallDirection == "E"
  44. })
  45. spaceWallInfo.wallE = wallEIndex == -1 ? false : true;
  46. const wallNIndex = this.gltfWalls.findIndex(item=>{
  47. return element.spaceId == item.spaceId && item.wallDirection == "N"
  48. })
  49. spaceWallInfo.wallN = wallNIndex == -1 ? false : true;
  50. const wallSIndex = this.gltfWalls.findIndex(item=>{
  51. return element.spaceId == item.spaceId && item.wallDirection == "S"
  52. })
  53. spaceWallInfo.wallS = wallSIndex == -1 ? false : true;
  54. element.spaceWallInfo = spaceWallInfo;
  55. }
  56. },
  57. // 批量获取空间模型信息
  58. async getOverallArrangementDetailsList(type=1) {
  59. // 设置空间数组的墙体信息
  60. // this.setSpaceListWallInfo();
  61. this.type = type;//加载类型,1空间加载 2 全局精简加载
  62. let arr = this.spaceList.map(it => it.layoutId).filter(it => it != 0);
  63. let parmas = {
  64. ids: arr,
  65. };
  66. // 默认的布局
  67. let res = await requestConfig("getOverallArrangementDetailsList", parmas);
  68. if (!res.success || !res.list || res.list.length == 0) {
  69. return false;
  70. }
  71. this.promise_list = [];
  72. this.arrFrunList = res.list;
  73. console.log("空间布局数据", this.arrFrunList)
  74. // 通过默认布局
  75. this.furnHandle(this.arrFrunList);
  76. },
  77. //拆分家具模型加载逻辑
  78. furnHandle(arrFrunList){
  79. if(!arrFrunList || arrFrunList.length == 0){
  80. return
  81. }
  82. let startTime = new Date().getTime();
  83. let tmpList = [];//临时数据
  84. this.gltfLayouts = []; //模型列表,所有空间里面的每个模型(家具)对应一条记录
  85. let allowSpaceId = [this.curSpaceObj.spaceId];
  86. if(this.type == 2){//全局精简模型;需要的是所有空间的模型
  87. allowSpaceId = this.spaceList.map(it=>it.spaceId)
  88. }else{//空间模型模式
  89. allowSpaceId = [this.curSpaceObj.spaceId];
  90. if(this.curSpaceObj.spaceId==758){//二层主卧特殊处理
  91. allowSpaceId.push(735);//休闲小客厅
  92. }
  93. //花园类型的添加到家具加载目录里面
  94. // this.spaceList.forEach(it=>{
  95. // if(it.spaceType==14){
  96. // allowSpaceId.push(it.spaceId);
  97. // }
  98. // })
  99. }
  100. // allowSpaceId = [388];//模型有警告,需要看下
  101. console.log("重新加载布局", arrFrunList,this.spaceList,this.gltfLayouts);
  102. arrFrunList.forEach(signel => {
  103. let spaceId = this.spaceList.find(it => it.layoutId == signel.id).spaceId;
  104. if(allowSpaceId.includes(spaceId)){//只加载允许的空间的布局,其他不加载
  105. let md = JSON.parse(signel.modelJson); //获取布局里面的模型信息
  106. console.warn("***布局***", md, signel.id)
  107. //遍历模型信息,获取模型列表
  108. for (let i = 0; i < md.modelData.length; i++) {
  109. let item = md.modelData[i];
  110. item.spaceId = spaceId;
  111. item.layoutId = signel.id;
  112. item.h5Id = signel.id+""+item.id;//唯一标识
  113. if(item.modelName=='BP_furnitureBase_C'){
  114. continue;
  115. }else{
  116. tmpList.push(item);
  117. }
  118. }
  119. }
  120. })
  121. this.tmpList = tmpList;
  122. if(this.type==2){//全局精简模型;需要的是所有空间的模型
  123. this.fliterList(tmpList);
  124. console.warn("***fliterList***",this.realList.length ,this.realList);
  125. tmpList = this.realList;
  126. }
  127. let realFurArr = this.preFurnitureData(tmpList);//统一处理家具模型
  128. this.calculateLayoutModelSize() // 提前计算模型的位置
  129. console.log("***realFurArr***", realFurArr,this.gltfLayouts);
  130. realFurArr && realFurArr.forEach((item,index) => {
  131. this.promise_list.push(
  132. new Promise((resolve, reject) => {
  133. this.loadLayoutModels(item, resolve);
  134. })
  135. )
  136. });
  137. Promise.all(this.promise_list).then(() => {
  138. let endTime = new Date().getTime();
  139. console.log("家具模型全部加载完成,时间:", endTime - startTime, this.gltfLayouts);
  140. })
  141. },
  142. //过滤掉不需要的家具
  143. fliterList(list){
  144. this.realList = [];
  145. //找到直接的家具模型
  146. list && list.forEach((mod)=>{
  147. let name = mod.modelName.substring(0,mod.modelName.length-2);
  148. if(globlShowModel.includes(name)){
  149. this.realList.push(mod);
  150. }
  151. })
  152. this.realList.forEach((ref)=>{
  153. this.recursionFliter(ref)
  154. })
  155. },
  156. //递归处理不需要的家具
  157. recursionFliter(item){
  158. let _list = [];//
  159. if(parseInt(item.referenceModelBottom) > 0){
  160. _list.push(item.referenceModelBottom)
  161. }
  162. if(parseInt(item.referenceModelLeft) > 0){
  163. _list.push(item.referenceModelLeft)
  164. }
  165. if(parseInt(item.referenceModelRight) > 0){
  166. _list.push(item.referenceModelRight)
  167. }
  168. if(parseInt(item.referenceModelTop) > 0){
  169. _list.push(item.referenceModelTop)
  170. }
  171. if(_list.length==0){
  172. return false;
  173. }else{
  174. this.tmpList.forEach(tmp=>{
  175. if(_list.includes(tmp.id)){
  176. if(!this.realList.find(it=>it.h5Id==tmp.h5Id)){
  177. this.realList.push(tmp);
  178. this.recursionFliter(tmp);
  179. }
  180. }
  181. })
  182. }
  183. },
  184. //预处理需要加载墙体模型的数据-减少模型请求数
  185. preFurnitureData(list){
  186. let realFurnitureArr = [];//家具列表
  187. list && list.forEach((item, index) => {
  188. item.uniId = Date.now() + index;//唯一标识
  189. //获取墙体对应的gltb模型的相关信息
  190. let modelName = item.modelName;
  191. // console.log("布局模型名称", modelName);
  192. let layoutModel = modelData.find(it => modelName.indexOf(it.modelName) == 0); //模型地址
  193. if (layoutModel && layoutModel.url) {//该数据存在模型地址
  194. let object = realFurnitureArr.find(it=>it.url==layoutModel.url);
  195. //列表中还没有这个数据
  196. if(!object){
  197. let it = {
  198. url:layoutModel.url,
  199. name:layoutModel.modelName,
  200. list:[item],
  201. }
  202. realFurnitureArr.push(it)
  203. }else{
  204. object.list.push(item);
  205. }
  206. let position = new THREE.Vector3();//当前几何体的位置参数
  207. let scale = new THREE.Vector3();//当前几何体的缩放参数
  208. let rotation = new THREE.Vector3();//当前几何体的缩放参数
  209. let md = {
  210. uniId:item.uniId,//家具模型实例的唯一标识
  211. spaceId:item.spaceId,
  212. id:item.id,
  213. userData:item,
  214. position:position,
  215. scale:scale,
  216. rotation:rotation,
  217. loaded:false,
  218. };
  219. this.gltfLayouts.push(md);
  220. }
  221. });
  222. return realFurnitureArr;
  223. },
  224. //加载家具模型-实例化方案
  225. loadLayoutModels(realData, resolve){
  226. var that = this;
  227. if(!realData.url){
  228. console.warn("***家具模型不存在***",realData);
  229. resolve();
  230. return false;
  231. }
  232. if(realData.name.includes('BP_XSPACE_deng_01')){//灯光
  233. resolve();
  234. }else{
  235. that.loader.setDRACOLoader(this.dracoLoader);
  236. that.loader.load(realData.url, ( gltf ) => {
  237. gltf.scene.traverse((child)=> {
  238. if (child.isMesh && child.visible) {
  239. let instancedMesh = new THREE.InstancedMesh(child.geometry.clone(), child.material.clone(), realData.list.length);
  240. this.instancedFurList.push(instancedMesh);
  241. //realData 该模型被重复使用时的每一次的形变参数等
  242. realData.list && realData.list.forEach((it,i)=>{
  243. let gltfFurn = that.gltfLayouts.find(itme=>itme.uniId==it.uniId);//判断是否已经添加过
  244. gltf.scene.rotation.y = gltfFurn.rotation.y;
  245. gltf.scene.position.set(gltfFurn.position.x,0,gltfFurn.position.z);
  246. gltf.scene.scale.set(gltfFurn.scale.x,1,gltfFurn.scale.z);
  247. gltf.scene.updateMatrixWorld();//更新世界坐标-这样,子模型也同步更新了
  248. instancedMesh.setMatrixAt(i, child.matrixWorld);
  249. instancedMesh.instanceMatrix.needsUpdate = true;
  250. gltfFurn.loaded = true;
  251. if(!gltfFurn.instancedMeshIndexList){//标识网格实例数组的序号 以及 当前几何体 在网格实例的序号
  252. gltfFurn.instancedMeshIndexList = [
  253. {instancedMeshIndex:this.instancedFurList.length-1,instancedAtIndex:i},
  254. ]
  255. }else{
  256. gltfFurn.instancedMeshIndexList.push({
  257. instancedMeshIndex:this.instancedFurList.length-1,instancedAtIndex:i
  258. })
  259. }
  260. })
  261. instancedMesh.userType = "layoutMesh";
  262. if(realData.name.includes("BP_L_carpet01")){//地毯接收阴影
  263. instancedMesh.receiveShadow = true;//对象是否接收阴影
  264. }else{
  265. instancedMesh.castShadow = true;//对象是否产生阴影
  266. }
  267. this.scene.add(instancedMesh);//添加到场景中
  268. }
  269. });
  270. resolve();
  271. });
  272. }
  273. },
  274. //加载模型
  275. loadLayoutModelsOld(modelObj, resolve) {
  276. let that = this;
  277. const modelName = modelObj.modelName;
  278. console.log("布局模型名称", modelName);
  279. let layoutModel = modelData.find(it => modelName.indexOf(it.modelName) == 0); //模型地址
  280. if (!layoutModel || !layoutModel.url) {
  281. resolve();
  282. return false
  283. }
  284. let url = layoutModel.url;
  285. console.log("布局模型数据", layoutModel);
  286. that.loader.load(url, (gltf) => {
  287. // console.log("布局模型加载成功", gltf);
  288. let model = gltf.scene; // 获取模型
  289. model.name = layoutModel.modelName;
  290. model.userType = "layoutMesh";
  291. model.userData = modelObj;
  292. // model.rotation.y = Math.PI / 2 ; // 旋转 90 度
  293. this.gltfLayouts.push(model);
  294. resolve();
  295. });
  296. },
  297. // 切换家具的显示隐藏
  298. changeLayoutModelState(isShow=false){
  299. console.log("移动过程中显示隐藏空间家具", this.gltfLayouts,isShow, this.leftSpaces, this.rightSpaces);
  300. const changeSpaceList = this.leftSpaces.concat(this.rightSpaces); // 只改变空间尺寸变化的家具模型
  301. for (let index = 0; index < changeSpaceList.length; index++) {
  302. const element = changeSpaceList[index];
  303. const gltfLayoutModels = this.gltfLayouts.filter(item => {
  304. return element.layoutId == item.userData.layoutId && element.spaceId == item.userData.spaceId;
  305. })
  306. if (!gltfLayoutModels || gltfLayoutModels.length == 0) {
  307. continue;
  308. }
  309. for (let j = 0; j < gltfLayoutModels.length; j++) {
  310. const cube = gltfLayoutModels[j];
  311. this.changeCubeState(cube, isShow);
  312. }
  313. }
  314. },
  315. // 显示隐藏指定cube的状态
  316. changeCubeState(cube, isShow){
  317. let lay = this.gltfLayouts.find(it=>it.uniId==cube.uniId);
  318. if(cube.instancedMeshIndexList && cube.instancedMeshIndexList.length>0){
  319. cube.instancedMeshIndexList.forEach(item=>{
  320. let index = item.instancedMeshIndex;
  321. let instancedMesh = this.instancedFurList[index];//网格实例对象
  322. let curMeshIndex = item.instancedAtIndex;//当前家具模型在网格实例对象里面的序号
  323. let stratMatrix = new THREE.Matrix4();//定义一个四维矩阵
  324. instancedMesh.getMatrixAt(curMeshIndex,stratMatrix);//获取当前几何体的四维矩阵到stratMatrix里面
  325. instancedMesh.instanceMatrix.needsUpdate = true;//更新之前,必须开启开关
  326. instancedMesh.visible = isShow;
  327. instancedMesh.setMatrixAt(curMeshIndex,stratMatrix);//更新几何体的世界矩阵
  328. })
  329. }
  330. },
  331. deleteLayoutModel(spaceObj, layoutObj){
  332. // 删除布局数据
  333. for (let index = 0; index < this.arrFrunList.length; index++) {
  334. const element = this.arrFrunList[index];
  335. }
  336. const oldLayoutIndex = this.arrFrunList.findIndex((item)=>{
  337. return item.id == spaceObj.layoutId
  338. })
  339. if(oldLayoutIndex!=-1){
  340. this.arrFrunList[oldLayoutIndex] = layoutObj;
  341. }
  342. console.log("准备删除模型", spaceObj, this.gltfLayouts, this.arrFrunList);
  343. const gltfLayoutModels = this.gltfLayouts.filter(item => {
  344. return spaceObj.layoutId == item.userData.layoutId && spaceObj.spaceId == item.userData.spaceId;
  345. })
  346. if (!gltfLayoutModels || gltfLayoutModels.length == 0) {
  347. return;
  348. }
  349. for (let j = 0; j < gltfLayoutModels.length; j++) {
  350. const cube = gltfLayoutModels[j];
  351. if(cube.instancedMeshIndexList && cube.instancedMeshIndexList.length>0){
  352. cube.instancedMeshIndexList.forEach(item=>{
  353. let index = item.instancedMeshIndex;
  354. let instancedMesh = this.instancedFurList[index];//网格实例对象
  355. this.scene.remove(instancedMesh);//添加到场景中
  356. })
  357. }
  358. console.log("删除原有模型", spaceObj.layoutId, cube);
  359. }
  360. },
  361. // 计算家具的位置
  362. calculateLayoutModelSize() {
  363. console.log("计算家具的位置", this.gltfLayouts);
  364. for (let index = 0; index < this.spaceList.length; index++) {
  365. const element = this.spaceList[index];
  366. const gltfLayoutModels = this.gltfLayouts.filter(item => {
  367. return element.layoutId == item.userData.layoutId && element.spaceId == item.userData.spaceId;
  368. })
  369. //空间下不存在家具模型,则该空间不需要进行下一步处理
  370. if (!gltfLayoutModels || gltfLayoutModels.length == 0) {
  371. continue;
  372. }
  373. gltfLayoutModels.sort(function(a, b) {
  374. return a.userData.level - b.userData.level
  375. });
  376. // console.log("对应空间ID的模型数组", this.gltfLayouts, element.spaceId, gltfLayoutModels)
  377. for (let j = 0; j < gltfLayoutModels.length; j++) {
  378. const cube = gltfLayoutModels[j];
  379. this.drawLayoutModel(element, cube);
  380. }
  381. }
  382. },
  383. // 绘制模型
  384. drawLayoutModel(curSpace, cube) {
  385. const {
  386. centerX,
  387. spaceId
  388. } = curSpace;
  389. const cubeInfo = this.resetModelParameters(curSpace, cube.userData);
  390. // const cubeInfo = cube.userData;
  391. let centerY = curSpace.centerY * -1; // UE和ThreeJS坐标做相反
  392. // 默认空间中心点
  393. let positionX = centerX;
  394. let positionY = centerY;
  395. let rotationY = Math.PI / 2;
  396. let scaleX = 1;
  397. let scaleY = 1;
  398. // 空间尺寸
  399. let spaceWidth = curSpace.spaceWidth;
  400. let spaceHeight = curSpace.spaceHeight;
  401. // 模型尺寸
  402. let modelWidth = cubeInfo.modelWidth;
  403. let modelHeight = cubeInfo.modelHeight;
  404. // 判断旋转
  405. if (parseFloat(cubeInfo.rotation) == 90) {
  406. rotationY = 0;
  407. // 交换尺寸
  408. // modelWidth = cubeInfo.modelHeight;
  409. // modelHeight = cubeInfo.modelWidth;
  410. }
  411. if (parseFloat(cubeInfo.rotation) == 180) {
  412. rotationY = -Math.PI / 2;
  413. // modelWidth = cubeInfo.modelHeight;
  414. // modelHeight = cubeInfo.modelWidth;
  415. }
  416. if (parseFloat(cubeInfo.rotation) == -90) {
  417. rotationY = -Math.PI;
  418. // 交换尺寸
  419. // modelWidth = cubeInfo.modelHeight;
  420. // modelHeight = cubeInfo.modelWidth;
  421. }
  422. // 判断靠墙
  423. if (cubeInfo.isStepAsideLeft == 'true') {
  424. positionX = centerX - (spaceWidth / 2 - modelWidth / 2);
  425. if (parseFloat(cubeInfo.rotation) == 90 || parseFloat(cubeInfo.rotation) == -90) {
  426. positionX = centerX - (spaceWidth / 2 - modelWidth / 2);
  427. }
  428. positionX += parseFloat(cubeInfo.marginLeft);
  429. positionX += curSpace.spaceWallInfo.wallW ? 10 : 0;
  430. }
  431. if (cubeInfo.isStepAsideRight == 'true') {
  432. positionX = centerX + (spaceWidth / 2 - modelWidth / 2);
  433. if (parseFloat(cubeInfo.rotation) == 90 || parseFloat(cubeInfo.rotation) == -90) {
  434. positionX = centerX + (spaceWidth / 2 - modelWidth / 2);
  435. }
  436. positionX -= parseFloat(cubeInfo.marginRight);
  437. positionX -= curSpace.spaceWallInfo.wallE ? 10 : 0;
  438. }
  439. if (cubeInfo.isStepAsideTop == 'true') {
  440. positionY = centerY - (spaceHeight / 2 - modelHeight / 2);
  441. if (parseFloat(cubeInfo.rotation) == 90 || parseFloat(cubeInfo.rotation) == -90) {
  442. positionY = centerY - (spaceHeight / 2 - modelHeight / 2);
  443. }
  444. positionY += parseFloat(cubeInfo.marginTop);
  445. positionY += curSpace.spaceWallInfo.wallN ? 10 : 0;
  446. }
  447. if (cubeInfo.isStepAsideBottom == 'true') {
  448. positionY = centerY + (spaceHeight / 2 - modelHeight / 2);
  449. if (parseFloat(cubeInfo.rotation) == 90 || parseFloat(cubeInfo.rotation) == -90) {
  450. positionY = centerY + (spaceHeight / 2 - modelHeight / 2);
  451. }
  452. positionY -= parseFloat(cubeInfo.marginBottom);
  453. positionY -= curSpace.spaceWallInfo.wallS ? 10 : 0;
  454. }
  455. // 参照物
  456. if (parseInt(cubeInfo.referenceModelTop) > 0) {
  457. const referenceModel = this.gltfLayouts.find(item => {
  458. const layoutModelData = item.userData;
  459. return layoutModelData.id == parseInt(cubeInfo.referenceModelTop) && layoutModelData
  460. .spaceId == cubeInfo.spaceId && layoutModelData.layoutId == cubeInfo.layoutId;
  461. })
  462. if(!referenceModel){
  463. console.warn("***no-data***",cubeInfo.referenceModelTop,cubeInfo)
  464. return false
  465. }
  466. positionY = referenceModel.position.z * 100 + (referenceModel.userData.modelHeight / 2 + cubeInfo
  467. .modelHeight / 2);
  468. positionY = positionY + parseFloat(cubeInfo.marginTop);
  469. }
  470. if (parseInt(cubeInfo.referenceModelBottom) > 0) {
  471. const referenceModel = this.gltfLayouts.find(item => {
  472. const layoutModelData = item.userData;
  473. return layoutModelData.id == parseInt(cubeInfo.referenceModelBottom) && layoutModelData
  474. .spaceId == cubeInfo.spaceId && layoutModelData.layoutId == cubeInfo.layoutId;
  475. })
  476. if(!referenceModel){
  477. console.warn("***no-data***",cubeInfo.referenceModelBottom,cubeInfo)
  478. return false
  479. }
  480. positionY = referenceModel.position.z * 100 - (referenceModel.userData.modelHeight / 2 + cubeInfo
  481. .modelHeight / 2);
  482. positionY = positionY - parseFloat(cubeInfo.marginBottom);
  483. }
  484. if (parseInt(cubeInfo.referenceModelLeft) > 0) {
  485. const referenceModel = this.gltfLayouts.find(item => {
  486. const layoutModelData = item.userData;
  487. return layoutModelData.id == parseInt(cubeInfo.referenceModelLeft) && layoutModelData
  488. .spaceId == cubeInfo.spaceId && layoutModelData.layoutId == cubeInfo.layoutId;
  489. })
  490. if(!referenceModel){
  491. console.warn("***no-data***",cubeInfo.referenceModelLeft,cubeInfo)
  492. return false
  493. }
  494. positionX = referenceModel.position.x * 100 + (referenceModel.userData.modelWidth / 2 + cubeInfo
  495. .modelWidth / 2);
  496. positionX = positionX + parseFloat(cubeInfo.marginLeft);
  497. }
  498. if (parseInt(cubeInfo.referenceModelRight) > 0) {
  499. const referenceModel = this.gltfLayouts.find(item => {
  500. const layoutModelData = item.userData;
  501. return layoutModelData.id == parseInt(cubeInfo.referenceModelRight) && layoutModelData
  502. .spaceId == cubeInfo.spaceId && layoutModelData.layoutId == cubeInfo.layoutId;
  503. })
  504. if(!referenceModel){
  505. console.warn("***no-data***",cubeInfo.referenceModelRight,cubeInfo)
  506. return false
  507. }
  508. positionX = referenceModel.position.x * 100 - (referenceModel.userData.modelWidth / 2 + cubeInfo
  509. .modelWidth / 2);
  510. positionX = positionX - parseFloat(cubeInfo.marginRight);
  511. }
  512. if (cubeInfo.isFixedWidth == "false" || cubeInfo.isFixedHeight == "false") { // 固定尺寸
  513. // 靠墙拉伸
  514. if (cubeInfo.isStepAsideTop == 'true' && cubeInfo.isStepAsideBottom == 'true') {
  515. // console.log("高度拉伸", spaceHeight / modelHeight)
  516. positionY = centerY;
  517. if (curSpace.spaceWallInfo.wallN && curSpace.spaceWallInfo.wallS) {
  518. spaceHeight -= 20 + parseFloat(cubeInfo.marginTop) + parseFloat(cubeInfo.marginBottom);
  519. } else if (curSpace.spaceWallInfo.wallN) {
  520. spaceHeight -= 10 + parseFloat(cubeInfo.marginTop);
  521. positionY += 10 / 2;
  522. positionY += parseFloat(cubeInfo.marginTop) / 2;
  523. } else if (curSpace.spaceWallInfo.wallS) {
  524. spaceHeight -= 10 + parseFloat(cubeInfo.marginBottom);
  525. positionY -= 10 / 2;
  526. positionY -= parseFloat(cubeInfo.marginBottom) / 2;
  527. }else {
  528. spaceHeight -= parseFloat(cubeInfo.marginTop) + parseFloat(cubeInfo.marginBottom);
  529. positionY += parseFloat(cubeInfo.marginTop) / 2 ;
  530. positionY -= parseFloat(cubeInfo.marginBottom) / 2;
  531. }
  532. // 计算缩放
  533. if (parseFloat(cubeInfo.rotation) == 90 || parseFloat(cubeInfo.rotation) == -90) {
  534. scaleY = spaceHeight / modelHeight;
  535. } else {
  536. scaleX = spaceHeight / modelHeight;
  537. }
  538. }
  539. if (cubeInfo.isStepAsideLeft == 'true' && cubeInfo.isStepAsideRight == 'true') {
  540. // console.log("宽度拉伸11111", spaceWidth / modelWidth)
  541. positionX = centerX;
  542. if (curSpace.spaceWallInfo.wallW && curSpace.spaceWallInfo.wallE) {
  543. spaceWidth -= 20 + parseFloat(cubeInfo.marginLeft) + parseFloat(cubeInfo.marginRight);;
  544. } else if (curSpace.spaceWallInfo.wallW) {
  545. spaceWidth -= 10 + parseFloat(cubeInfo.marginLeft);
  546. positionX += 10 / 2;
  547. positionX += parseFloat(cubeInfo.marginLeft) / 2;
  548. } else if (curSpace.spaceWallInfo.wallE) {
  549. spaceWidth -= 10 + parseFloat(cubeInfo.marginRight);
  550. positionX -= 10 / 2;
  551. positionX -= parseFloat(cubeInfo.marginRight) / 2;
  552. }else {
  553. spaceWidth -= parseFloat(cubeInfo.marginLeft) + parseFloat(cubeInfo.marginRight);
  554. positionX += parseFloat(cubeInfo.marginLeft) / 2;
  555. positionX -= parseFloat(cubeInfo.marginRight) / 2;
  556. }
  557. // console.log("模型计算位置" , parseFloat(cubeInfo.rotation))
  558. // 计算缩放
  559. if (parseFloat(cubeInfo.rotation) == 90 || parseFloat(cubeInfo.rotation) == -90) {
  560. scaleX = spaceWidth / modelWidth;
  561. } else {
  562. scaleY = spaceWidth / modelWidth;
  563. }
  564. }
  565. // 单个参照物和墙面拉伸
  566. if (cubeInfo.isStepAsideTop == 'true' && parseInt(cubeInfo.referenceModelBottom) > 0) {
  567. const referenceModel = this.gltfLayouts.find(item => {
  568. const layoutModelData = item.userData;
  569. return layoutModelData.id == parseInt(cubeInfo.referenceModelBottom) && layoutModelData
  570. .spaceId == cubeInfo.spaceId && layoutModelData.layoutId == cubeInfo.layoutId;
  571. })
  572. const referenceModelPositionY = referenceModel.position.z * 100 - referenceModel.userData
  573. .modelHeight / 2 - parseFloat(cubeInfo.marginBottom);
  574. const wallPositionY = centerY - spaceHeight / 2 + (curSpace.spaceWallInfo.wallN ? 10 : 0) +
  575. parseFloat(cubeInfo.marginTop);
  576. const newModelHeight = Math.abs(referenceModelPositionY - wallPositionY);
  577. // console.log("上边拉伸", referenceModelPositionY, wallPositionY, newModelHeight)
  578. if (Math.abs(parseFloat(cubeInfo.rotation)) == 90) {
  579. scaleY = newModelHeight / modelHeight;
  580. } else {
  581. scaleX = newModelHeight / modelHeight;
  582. }
  583. positionY = wallPositionY + newModelHeight / 2;
  584. }
  585. if (cubeInfo.isStepAsideBottom == 'true' && parseInt(cubeInfo.referenceModelTop) > 0) {
  586. const referenceModel = this.gltfLayouts.find(item => {
  587. const layoutModelData = item.userData;
  588. return layoutModelData.id == parseInt(cubeInfo.referenceModelTop) && layoutModelData
  589. .spaceId == cubeInfo.spaceId && layoutModelData.layoutId == cubeInfo.layoutId;
  590. })
  591. const referenceModelPositionY = referenceModel.position.z * 100 + referenceModel.userData
  592. .modelHeight / 2 + parseFloat(cubeInfo.marginTop) + (curSpace.spaceWallInfo.wallN ? 10 : 0);
  593. const wallPositionY = centerY + spaceHeight / 2 - (curSpace.spaceWallInfo.wallS ? 10 : 0) -
  594. parseFloat(cubeInfo.marginBottom);
  595. const newModelHeight = Math.abs(referenceModelPositionY - wallPositionY);
  596. if (Math.abs(parseFloat(cubeInfo.rotation)) == 90) {
  597. scaleY = newModelHeight / modelHeight;
  598. } else {
  599. scaleX = newModelHeight / modelHeight;
  600. }
  601. positionY = wallPositionY - newModelHeight / 2;
  602. }
  603. if (cubeInfo.isStepAsideLeft == 'true' && parseInt(cubeInfo.referenceModelRight) > 0) {
  604. // console.log("左边拉伸")
  605. const referenceModel = this.gltfLayouts.find(item => {
  606. const layoutModelData = item.userData;
  607. return layoutModelData.id == parseInt(cubeInfo.referenceModelRight) && layoutModelData
  608. .spaceId == cubeInfo.spaceId && layoutModelData.layoutId == cubeInfo.layoutId;
  609. })
  610. const referenceModelPositionX = referenceModel.position.x * 100 - referenceModel.userData
  611. .modelWidth / 2 - parseFloat(cubeInfo.marginLeft);
  612. const wallPositionX = centerX - spaceWidth / 2 + (curSpace.spaceWallInfo.wallE ? 10 : 0) +
  613. parseFloat(cubeInfo.marginRight);
  614. const newModelWidth = Math.abs(referenceModelPositionX - wallPositionX);
  615. if (Math.abs(parseFloat(cubeInfo.rotation)) == 90) {
  616. scaleX = newModelWidth / modelWidth;
  617. } else {
  618. scaleY = newModelWidth / modelWidth;
  619. }
  620. positionX = wallPositionX + newModelWidth / 2;
  621. }
  622. if (cubeInfo.isStepAsideRight == 'true' && parseInt(cubeInfo.referenceModelLeft) > 0) {
  623. const referenceModel = this.gltfLayouts.find(item => {
  624. const layoutModelData = item.userData;
  625. return layoutModelData.id == parseInt(cubeInfo.referenceModelLeft) && layoutModelData
  626. .spaceId == cubeInfo.spaceId && layoutModelData.layoutId == cubeInfo.layoutId;
  627. })
  628. const referenceModelPositionX = referenceModel.position.x * 100 + referenceModel.userData
  629. .modelWidth / 2 + parseFloat(cubeInfo.marginLeft);
  630. const wallPositionX = centerX + spaceWidth / 2 - (curSpace.spaceWallInfo.wallE ? 10 : 0) -
  631. parseFloat(cubeInfo.marginRight);
  632. const newModelWidth = Math.abs(referenceModelPositionX - wallPositionX);
  633. if (Math.abs(parseFloat(cubeInfo.rotation)) == 90) {
  634. scaleX = newModelWidth / modelWidth;
  635. } else {
  636. scaleY = newModelWidth / modelWidth;
  637. }
  638. positionX = wallPositionX - newModelWidth / 2;
  639. // console.log("右边拉伸", Math.abs(parseFloat(cubeInfo.rotation)))
  640. }
  641. if(parseInt(cubeInfo.referenceModelBottom) > 0 && parseInt(cubeInfo.referenceModelTop) > 0){
  642. // 上边惨遭物
  643. const referenceModelTop = this.gltfLayouts.find(item => {
  644. const layoutModelData = item.userData;
  645. return layoutModelData.id == parseInt(cubeInfo.referenceModelTop) && layoutModelData
  646. .spaceId == cubeInfo.spaceId && layoutModelData.layoutId == cubeInfo.layoutId;
  647. })
  648. // 下边参照物
  649. const referenceModelBottom = this.gltfLayouts.find(item => {
  650. const layoutModelData = item.userData;
  651. return layoutModelData.id == parseInt(cubeInfo.referenceModelBottom) && layoutModelData
  652. .spaceId == cubeInfo.spaceId && layoutModelData.layoutId == cubeInfo.layoutId;
  653. })
  654. const referenceModelTopPositionY = referenceModelTop.position.z * 100 + referenceModelTop.userData
  655. .modelHeight / 2 + parseFloat(cubeInfo.marginTop);
  656. const referenceModelBottomPositionY = referenceModelBottom.position.z * 100 - referenceModelBottom.userData
  657. .modelHeight / 2 - parseFloat(cubeInfo.marginBottom);
  658. const newModelHeight = Math.abs(referenceModelTopPositionY - referenceModelBottomPositionY);
  659. if (Math.abs(parseFloat(cubeInfo.rotation)) == 90) {
  660. scaleY = newModelHeight / modelHeight;
  661. } else {
  662. scaleX = newModelHeight / modelHeight;
  663. }
  664. positionY = referenceModelBottomPositionY - newModelHeight / 2;
  665. }
  666. if(parseInt(cubeInfo.referenceModelLeft) > 0 && parseInt(cubeInfo.referenceModelRight) > 0){
  667. const referenceModelLeft = this.gltfLayouts.find(item => {
  668. const layoutModelData = item.userData;
  669. return layoutModelData.id == parseInt(cubeInfo.referenceModelLeft) && layoutModelData
  670. .spaceId == cubeInfo.spaceId && layoutModelData.layoutId == cubeInfo.layoutId;
  671. })
  672. const referenceModelRight = this.gltfLayouts.find(item => {
  673. const layoutModelData = item.userData;
  674. return layoutModelData.id == parseInt(cubeInfo.referenceModelRight) && layoutModelData
  675. .spaceId == cubeInfo.spaceId && layoutModelData.layoutId == cubeInfo.layoutId;
  676. })
  677. const referenceModelLeftPositionX = referenceModelLeft.position.x * 100 + referenceModelLeft.userData
  678. .modelWidth / 2 + parseFloat(cubeInfo.marginLeft);
  679. const referenceModelRightPositionX = referenceModelRight.position.x * 100 - referenceModelRight.userData
  680. .modelWidth / 2 - parseFloat(cubeInfo.marginRight);
  681. const newModelWidth = Math.abs(referenceModelLeftPositionX - referenceModelRightPositionX);
  682. if (Math.abs(parseFloat(cubeInfo.rotation)) == 90) {
  683. scaleX = newModelWidth / modelWidth;
  684. } else {
  685. scaleY = newModelWidth / modelWidth;
  686. }
  687. positionX = referenceModelRightPositionX - newModelWidth / 2;
  688. }
  689. }
  690. // console.log("模型计算位置--", positionX, positionY)
  691. console.log("模型计算位置", cubeInfo, centerX, centerY, spaceWidth, spaceHeight, modelWidth, modelHeight, spaceId, scaleX, scaleY, positionX, positionY)
  692. let oldPosition = new THREE.Vector3();//当前几何体的位置参数
  693. oldPosition.copy(cube.position);
  694. cube.position.x = positionX / 100;
  695. cube.position.z = positionY / 100;
  696. cube.rotation.y = rotationY;
  697. cube.scale.x = scaleX;
  698. cube.scale.z = scaleY;
  699. cube.scale.y = 1;
  700. // if (!cube.parent) { //说明还没添加到场景中-旧版方法
  701. // this.scene.add(cube); //处理完毕后在加入场景中
  702. // }
  703. // if(scaleX>1 || scaleY>1){
  704. // console.warn("***scaleinfo***",cubeInfo.id,scaleX,scaleY,cubeInfo.modelName)
  705. // }
  706. if(this.type==2){//全局精简加载
  707. let name = cubeInfo.modelName.substring(0, cubeInfo.modelName.length - 2);
  708. if(globlShowModel.includes(name)){
  709. if(cubeInfo.modelName=='BP_XSPACE_deng_01_C'){//灯光
  710. this.lightHandle(cube)
  711. }else{
  712. this.updateInfo(cube,oldPosition,scaleX,scaleY);//实例化方法
  713. }
  714. }
  715. }else{
  716. if(cubeInfo.modelName=='BP_XSPACE_deng_01_C'){//灯光
  717. this.lightHandle(cube)
  718. }else{
  719. this.updateInfo(cube,oldPosition,scaleX,scaleY);//实例化方法
  720. }
  721. }
  722. },
  723. //更新家具模型到页面中
  724. updateInfo(cube,oldPosition,scaleX,scaleY){
  725. console.log("更新布局模型");
  726. let lay = this.gltfLayouts.find(it=>it.uniId==cube.uniId);
  727. if(cube.instancedMeshIndexList && cube.instancedMeshIndexList.length>0){
  728. cube.instancedMeshIndexList.forEach(item=>{
  729. let index = item.instancedMeshIndex;
  730. let instancedMesh = this.instancedFurList[index];//网格实例对象
  731. let curMeshIndex = item.instancedAtIndex;//当前家具模型在网格实例对象里面的序号
  732. let stratMatrix = new THREE.Matrix4();//定义一个四维矩阵
  733. instancedMesh.getMatrixAt(curMeshIndex,stratMatrix);//获取当前几何体的四维矩阵到stratMatrix里面
  734. let scaleMatrix = new THREE.Matrix4(); //定义一个缩放变化矩阵
  735. let panMatrix = new THREE.Matrix4(); //定义一个平移变化矩阵
  736. if (!lay.loaded) { //说明还没添加到场景中
  737. // scaleMatrix.makeScale(scaleX,1,scaleY); //获得缩放变化矩阵
  738. // panMatrix.makeTranslation(cube.position.x,0,cube.position.z); //获得平移变化矩阵
  739. // stratMatrix.multiply(scaleMatrix).premultiply(panMatrix);//通过矩阵计算获得最终的形变矩阵
  740. // instancedMesh.instanceMatrix.needsUpdate = true;//更新之前,必须开启开关
  741. // instancedMesh.setMatrixAt(curMeshIndex,stratMatrix);//更新几何体的世界矩阵
  742. // this.scene.add(instancedMesh);
  743. }else{//更新形变矩阵
  744. scaleMatrix.makeScale(scaleX, 1, scaleY); //获得缩放变化矩阵
  745. panMatrix.makeTranslation(cube.position.x - oldPosition.x,0,cube.position.z - oldPosition.z); //获得平移变化矩阵
  746. stratMatrix.multiply(scaleMatrix).premultiply(panMatrix);//通过矩阵计算获得最终的形变矩阵
  747. instancedMesh.instanceMatrix.needsUpdate = true;//更新之前,必须开启开关
  748. instancedMesh.setMatrixAt(curMeshIndex,stratMatrix);//更新几何体的世界矩阵
  749. }
  750. })
  751. lay.loaded = true;
  752. }
  753. },
  754. // 空间处理光源
  755. lightHandle(cube){
  756. let light = this.gltfLayouts.find(it=>it.uniId==cube.uniId);
  757. if(!light.loaded){
  758. // 从一个点向各个方向发射的光源。一个常见的例子是模拟一个灯泡发出的光。
  759. let pointLight = new THREE.PointLight(0xffd7b3, 1.5, 5, 1);
  760. pointLight.position.set(cube.position.x, 1.5, cube.position.z); //default; light shining from top
  761. this.scene.add(pointLight);
  762. let sphereSize = 0.1;
  763. let pointLightHelper = new THREE.PointLightHelper( pointLight, sphereSize );
  764. this.scene.add( pointLightHelper);
  765. pointLight.castShadow = true; // default false
  766. // 默认情况下光投影相机区域是一个长宽高为10x10x500的长方体区域,光源投射方向为通过坐标原点
  767. pointLight.shadow.camera.left = -200; // default
  768. pointLight.shadow.camera.right = 200; // default
  769. pointLight.shadow.camera.top = 200; // default
  770. pointLight.shadow.camera.bottom = -200; // default
  771. this.scene.add(pointLight);
  772. light.loaded = true;
  773. }else{
  774. }
  775. },
  776. // 空间布局旋转镜像重置模型约束
  777. resetModelParameters(curSpace, cubeInfo) {
  778. // 旋转
  779. const defaultLayout = curSpace.layouts.find(item => {
  780. return item.isDefault
  781. })
  782. if (!defaultLayout) {
  783. return cubeInfo
  784. }
  785. let count = 0;
  786. switch (parseInt(defaultLayout.layoutRotate)) {
  787. case 90:
  788. count = 1;
  789. break;
  790. case 180:
  791. count = 2;
  792. break;
  793. case -90:
  794. count = 3;
  795. break;
  796. default:
  797. break;
  798. }
  799. for (let index = 0; index < count; index++) {
  800. let oldCubeInfo = JSON.parse(JSON.stringify(cubeInfo))
  801. oldCubeInfo.isStepAsideLeft = "false"
  802. oldCubeInfo.isStepAsideTop = "false"
  803. oldCubeInfo.isStepAsideRight = "false"
  804. oldCubeInfo.isStepAsideBottom = "false"
  805. oldCubeInfo.referenceModelLeft = "0"
  806. oldCubeInfo.referenceModelTop = "0"
  807. oldCubeInfo.referenceModelRight = "0"
  808. oldCubeInfo.referenceModelBottom = "0"
  809. oldCubeInfo.rotation = "0"
  810. oldCubeInfo.marginLeft = "0";
  811. oldCubeInfo.marginTop = "0";
  812. oldCubeInfo.marginRight = "0";
  813. oldCubeInfo.marginBottom = "0";
  814. // 是否靠墙
  815. if (cubeInfo.isStepAsideLeft == 'true') {
  816. oldCubeInfo.isStepAsideTop = 'true'
  817. }
  818. if (cubeInfo.isStepAsideTop == 'true') {
  819. oldCubeInfo.isStepAsideRight = 'true'
  820. }
  821. if (cubeInfo.isStepAsideRight == 'true') {
  822. oldCubeInfo.isStepAsideBottom = 'true'
  823. }
  824. if (cubeInfo.isStepAsideBottom == 'true') {
  825. oldCubeInfo.isStepAsideLeft = 'true'
  826. }
  827. // 参照物体
  828. if (parseInt(cubeInfo.referenceModelLeft) > 0) {
  829. oldCubeInfo.referenceModelTop = cubeInfo.referenceModelLeft;
  830. }
  831. if (parseInt(cubeInfo.referenceModelTop) > 0) {
  832. oldCubeInfo.referenceModelRight = cubeInfo.referenceModelTop;
  833. }
  834. if (parseInt(cubeInfo.referenceModelRight) > 0) {
  835. oldCubeInfo.referenceModelBottom = cubeInfo.referenceModelRight;
  836. }
  837. if (parseInt(cubeInfo.referenceModelBottom) > 0) {
  838. oldCubeInfo.referenceModelLeft = cubeInfo.referenceModelBottom;
  839. }
  840. // 边距
  841. oldCubeInfo.marginLeft = cubeInfo.marginTop;
  842. oldCubeInfo.marginTop = cubeInfo.marginRight;
  843. oldCubeInfo.marginRight = cubeInfo.marginBottom;
  844. oldCubeInfo.marginBottom = cubeInfo.marginLeft;
  845. oldCubeInfo.modelWidth = cubeInfo.modelHeight;
  846. oldCubeInfo.modelHeight = cubeInfo.modelWidth;
  847. // 旋转
  848. if (parseInt(cubeInfo.rotation) == 0 || parseInt(cubeInfo.rotation) == 90) {
  849. oldCubeInfo.rotation = parseInt(cubeInfo.rotation) + 90;
  850. }
  851. if (parseInt(cubeInfo.rotation) == 180) {
  852. oldCubeInfo.rotation = "-90";
  853. }
  854. if (parseInt(cubeInfo.rotation) == -90) {
  855. oldCubeInfo.rotation = "0";
  856. }
  857. // console.log("旋转前的模型参数X", cubeInfo, oldCubeInfo, defaultLayout)
  858. cubeInfo = oldCubeInfo;
  859. // console.log("旋转后的模型参数X", cubeInfo, oldCubeInfo, defaultLayout)
  860. }
  861. return cubeInfo;
  862. },
  863. // 改变空间模型
  864. changeLayoutModel(){
  865. let changeSpaces = [];
  866. // 去重
  867. for (let index = 0; index < this.changeSpaces.length; index++) {
  868. const element = this.changeSpaces[index];
  869. const findIndex = changeSpaces.findIndex((item)=>{
  870. return item.spaceId == element.spaceId;
  871. })
  872. if(findIndex==-1){
  873. const findListIndex = this.spaceList.findIndex((item)=>{
  874. return item.spaceId == element.spaceId;
  875. })
  876. if(findListIndex !=-1){
  877. changeSpaces.push(this.spaceList[findListIndex])
  878. }
  879. }
  880. }
  881. console.log("所有变化的空间", changeSpaces)
  882. this.changeLayouts = [];
  883. let promise_list = [];
  884. for (let index = 0; index < changeSpaces.length; index++) {
  885. const element = changeSpaces[index];
  886. const layoutObj = this.arrFrunList.find((item)=>{
  887. return item.id == element.layoutId;
  888. })
  889. console.log("请求布局的对象", layoutObj, element);
  890. if(layoutObj){
  891. promise_list.push(
  892. new Promise((resolve, reject) => {
  893. this.loadlayoutByID(layoutObj.groupType, element, resolve);
  894. })
  895. )
  896. }
  897. }
  898. Promise.all(promise_list).then(()=>{
  899. this.$nextTick(()=>{
  900. console.log("新布局替换完成");
  901. this.furnHandle(this.changeLayouts);
  902. })
  903. })
  904. },
  905. async loadlayoutByID(groupType,spaceObj, resolve){
  906. let param = {
  907. "brandId": config.brandId,
  908. "houseId": this.curHouseObj.houseId,
  909. "groupType": groupType
  910. }
  911. // 默认的布局
  912. let res = await requestConfig("findOverallArrangementList", param);
  913. if (!res.success || !res.pageModel || res.pageModel.resultSet.length == 0) {
  914. return resolve();
  915. }
  916. const groupLayouts = res.pageModel.resultSet;
  917. console.log("查询指定分组的布局", groupType, groupLayouts, spaceObj.spaceWidth, spaceObj.spaceHeight)
  918. // 根据空间的尺寸和布局的最小尺寸,筛选出合适的最大的布局
  919. const layouts01 = groupLayouts.filter((item)=>{
  920. return item.minWidth <= spaceObj.spaceWidth && item.minDepth <= spaceObj.spaceHeight
  921. })
  922. console.log("过滤适合的布局01", layouts01)
  923. // 长度和宽度都满足空间尺寸
  924. const layouts02 = layouts01.filter((item)=>{
  925. return (item.minWidth * item.minDepth ) <= (spaceObj.spaceWidth * spaceObj.spaceHeight)
  926. })
  927. console.log("过滤适合的布局02", layouts02)
  928. // 取布局面积最大的一个
  929. let layoutObj = null
  930. for (let index = 0; index < layouts02.length; index++) {
  931. const element = layouts02[index];
  932. if(!layoutObj){
  933. layoutObj = element;
  934. }else{
  935. if((layoutObj.minWidth * layoutObj.minDepth) < (element.minWidth * element.minDepth)){
  936. layoutObj = element;
  937. }
  938. }
  939. }
  940. console.log("找出最合适的布局", layoutObj)
  941. console.log("更新空间的布局ID=", layoutObj.id)
  942. // 合适的布局更现有布局相同
  943. if(spaceObj.layoutId == layoutObj.id){
  944. this.changeLayoutModelState(true); // 显示家具模型
  945. return resolve()
  946. }
  947. // 更新空间的布局id
  948. for (let index = 0; index < this.spaceList.length; index++) {
  949. const element = this.spaceList[index];
  950. if(element.spaceId == spaceObj.spaceId){
  951. this.deleteLayoutModel(element, layoutObj)
  952. element.layoutId = layoutObj.id
  953. console.log("替换空间的布局ID", spaceObj.spaceId, layoutObj.id);
  954. }
  955. }
  956. this.changeLayouts.push(layoutObj)
  957. resolve()
  958. }
  959. }
  960. }