4
0

2 Commits 618c5da330 ... 0427587e8c

Autor SHA1 Nachricht Datum
  caodongdong 0427587e8c Merge branch 'feature_UI调整' of http://101.231.166.56:3000/elab-damai-h5/h5-webgl-program into feature_UI调整 vor 1 Jahr
  caodongdong 6588bb037f 重新计算指定空间的布局模型 vor 1 Jahr
1 geänderte Dateien mit 39 neuen und 7 gelöschten Zeilen
  1. 39 7
      src/mixins/loadModel.js

+ 39 - 7
src/mixins/loadModel.js

@@ -75,7 +75,7 @@ export default {
 			this.furnHandle(this.arrFrunList);
 		},
 		//拆分家具模型加载逻辑
-		furnHandle(arrFrunList){
+		furnHandle(arrFrunList, spaceObj = null){
 			if(!arrFrunList || arrFrunList.length == 0){
 				return
 			}
@@ -109,7 +109,6 @@ export default {
 				let spaceId = this.spaceList.find(it => it.layoutId == signel.id).spaceId;
 				if(allowSpaceId.includes(spaceId)){//只加载允许的空间的布局,其他不加载
 					let md = JSON.parse(signel.modelJson); //获取布局里面的模型信息
-					console.warn("***布局***", md, signel.id)
 					//遍历模型信息,获取模型列表
 					for (let i = 0; i < md.modelData.length; i++) {
 						let item = md.modelData[i];
@@ -117,9 +116,12 @@ export default {
 						item.layoutId = signel.id;
 						item.h5Id = signel.id+""+item.id;//唯一标识
 						if(item.modelName=='BP_furnitureBase_C'){
+							
+							console.warn("***布局1***", item, signel.id)
 							continue;
 						}else{
 							tmpList.push(item);
+							console.warn("***布局***", item, signel.id)
 						}
 					}
 				}
@@ -131,7 +133,12 @@ export default {
 				tmpList = this.realList;
 			}
 			let realFurArr = this.preFurnitureData(tmpList);//统一处理家具模型
-			this.calculateLayoutModelSize() // 提前计算模型的位置
+			if(spaceObj){
+				this.calculateLayoutModelSizeBySpace(spaceObj) // 提前计算模型的位置
+			}else{
+				this.calculateLayoutModelSize() // 提前计算模型的位置
+			}
+			
 			console.log("***realFurArr***", realFurArr,this.gltfLayouts);
 			realFurArr && realFurArr.forEach((item,index) => {
 				this.promise_list.push(
@@ -198,6 +205,8 @@ export default {
 				let modelName = item.modelName;
 				// console.log("布局模型名称", modelName);
 				let layoutModel = modelData.find(it => modelName.indexOf(it.modelName) == 0); //模型地址
+				
+				console.log("要加载的模型数据", item.modelName, layoutModel)
 				if (layoutModel && layoutModel.url) {//该数据存在模型地址
 					let object = realFurnitureArr.find(it=>it.url==layoutModel.url);
 					//列表中还没有这个数据
@@ -420,6 +429,29 @@ export default {
 				}
 			}
 		},
+		// 计算家具的位置
+		calculateLayoutModelSizeBySpace(spaceObj) {
+			// for (let index = 0; index < this.spaceList.length; index++) {
+				const element = spaceObj;
+				const gltfLayoutModels = this.gltfLayouts.filter(item => {
+					return element.layoutId == item.userData.layoutId && element.spaceId == item.userData.spaceId;
+				})
+				
+				console.log("计算指定空间的家具的位置", spaceObj, element.layoutId, gltfLayoutModels);
+				//空间下不存在家具模型,则该空间不需要进行下一步处理
+				if (!gltfLayoutModels || gltfLayoutModels.length == 0) {
+					return;
+				}
+				gltfLayoutModels.sort(function(a, b) {
+					return a.userData.level - b.userData.level
+				});
+				// console.log("对应空间ID的模型数组", this.gltfLayouts, element.spaceId, gltfLayoutModels)
+				for (let j = 0; j < gltfLayoutModels.length; j++) {
+					const cube = gltfLayoutModels[j];
+					this.drawLayoutModel(element, cube);
+				}
+			// }
+		},
 		// 绘制模型
 		drawLayoutModel(curSpace, cube) {
 			const {
@@ -775,7 +807,7 @@ export default {
 			
 			}
 			// console.log("模型计算位置--", positionX, positionY)
-			console.log("模型计算位置", cubeInfo, centerX, centerY, spaceWidth, spaceHeight, modelWidth, modelHeight, spaceId, scaleX, scaleY, positionX, positionY)
+			console.log("模型计算位置", cubeInfo, centerX, centerY, spaceWidth, spaceHeight, modelWidth, modelHeight, spaceId, scaleX, scaleY, positionX, positionY, cubeInfo.modelName)
 			let oldPosition = new THREE.Vector3();//当前几何体的位置参数
 			oldPosition.copy(cube.position);
 			cube.position.x = positionX / 100;
@@ -1007,8 +1039,8 @@ export default {
 			}
 			Promise.all(promise_list).then(()=>{
 				this.$nextTick(()=>{
-					console.warn("新布局替换完成",this.changeLayouts);
-					this.furnHandle(this.changeLayouts);
+					console.log("新布局替换完成",this.changeLayouts, changeSpaces);
+					this.furnHandle(this.changeLayouts, changeSpaces[0]);
 				})
 			})
 		},
@@ -1061,7 +1093,7 @@ export default {
 		
 			// 合适的布局更现有布局相同
 			if(spaceObj.layoutId == layoutObj.id){
-				this.calculateLayoutModelSize() // 提前计算模型的位置
+				this.calculateLayoutModelSizeBySpace(spaceObj) // 提前计算模型的位置
 				// this.changeLayoutModelState(true); // 显示家具模型
 				return resolve()
 			}