| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696 | var app = getApp(); //获取应用实例const util = require('@/static/utils/util.js');const config = require('@/static/config.js');import modelData from '@/webgl/static/layoutModelData.js';// import requestConfig from '@/services/requestConfig.js';const THREE = requirePlugin('ThreeX');// import { TWEEN } from '@/webgl/jsm/libs/tween.module.min.js';export default {	data() {		return {			gltfLayouts: [],			instancedFurList:[],			arrFrunList:[],			promise_list:[],			loadFurPromise: new Promise((resolve) => {			    this.loadedCompleteFun = function() {			        console.log('家具模型接口结束');			        resolve()			    }			}),		}	},	watch: {},	onReady() {	},	methods: {		// 设置空间数组的墙体信息 		async setSpaceListWallInfo(){			for (let index = 0; index < this.spaceList.length; index++) {				let spaceWallInfo = {wallN:false, wallS:false, wallW:false, wallE:false}				const element = this.spaceList[index];						const wallWIndex = this.gltfWalls.findIndex(item=>{					return element.spaceId == item.spaceId && item.wallDirection == "W"				})				spaceWallInfo.wallW = wallWIndex == -1 ? false : true;				const wallEIndex = this.gltfWalls.findIndex(item=>{					return element.spaceId == item.spaceId && item.wallDirection == "E"				})				spaceWallInfo.wallE = wallEIndex == -1 ? false : true;						const wallNIndex = this.gltfWalls.findIndex(item=>{					return element.spaceId == item.spaceId && item.wallDirection == "N"				})				spaceWallInfo.wallN = wallNIndex == -1 ? false : true;				const wallSIndex = this.gltfWalls.findIndex(item=>{					return element.spaceId == item.spaceId && item.wallDirection == "S"				})				spaceWallInfo.wallS = wallSIndex == -1 ? false : true;				element.spaceWallInfo = spaceWallInfo;			}			await this.loadFurPromise;//等待解析分享者参数结束			this.$nextTick(() => {				this.calculateLayoutModelSize() // 计算模型的位置			})		},		// 批量获取空间模型信息		async getOverallArrangementDetailsList() {			// 设置空间数组的墙体信息			// this.setSpaceListWallInfo();			let arr = this.spaceList.map(it => it.layoutId).filter(it => it != 0);			let parmas = {				ids: arr,			};			this.loadFurPromise = new Promise((resolve, reject) => {				this.loadedCompleteFun = function() {				    console.log('家具模型接口结束');				    resolve()				}			})			let res = await requestConfig("getOverallArrangementDetailsList", parmas);			if (!res.success || !res.list || res.list.length == 0) {				return false;			}			this.promise_list = [];			this.arrFrunList = res.list;			this.furnHandle();		},		//拆分家具模型加载逻辑		furnHandle(){			let startTime = new Date().getTime();			let tmpList = [];//临时数据			this.gltfLayouts = []; //模型列表,所有空间里面的每个模型(家具)对应一条记录						let allowSpaceId = [this.curSpaceObj.spaceId];			if(this.curSpaceObj.spaceId==758){//二层主卧特殊处理				allowSpaceId.push(735);//休闲小客厅			}			//花园类型的添加到家具加载目录里面			// this.spaceList.forEach(it=>{			// 	if(it.spaceType==14){			// 		allowSpaceId.push(it.spaceId);			// 	}			// })			this.arrFrunList.forEach(signel => {				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];						item.spaceId = spaceId;						item.layoutId = signel.id;						// tmpList.push(item);						this.promise_list.push(							new Promise((resolve, reject) => {								this.loadLayoutModelsOld(item , resolve);							})						)					}				}							})			// let realFurArr = this.preFurnitureData(tmpList);//统一处理家具模型			// let arrLength = realFurArr.length;			// console.log("***realFurArr***", realFurArr);			// realFurArr && realFurArr.forEach((item,index) => {			// 	this.promise_list.push(			// 		new Promise((resolve, reject) => {			// 			this.loadLayoutModels(item, arrLength , resolve);			// 		})			// 	)			// });			Promise.all(this.promise_list).then(() => {				let endTime = new Date().getTime();				console.log("家具模型全部加载完成,时间:", endTime - startTime);				this.loadedCompleteFun()				// this.$nextTick(() => {				// 	this.calculateLayoutModelSize() // 计算模型的位置				// })			})		},		//预处理需要加载墙体模型的数据-减少模型请求数		preFurnitureData(list){			let realFurnitureArr = [];//家具列表			let dataList = [];			dataList = list.map(item=>{				let curSpace = this.spaceList.find(space=>space.spaceId==item.spaceId);				return this.resetModelParameters(curSpace, item);			})			dataList && dataList.forEach((item, index) => {				item.uniId = Date.now() + index;//唯一标识				//获取墙体对应的gltb模型的相关信息				let modelName = item.modelName;				// console.log("布局模型名称", modelName);				let layoutModel = modelData.find(it => modelName.indexOf(it.modelName) == 0); //模型地址				if (layoutModel && layoutModel.url) {//该数据存在模型地址					let object = realFurnitureArr.find(it=>it.url==layoutModel.url);					//列表中还没有这个数据					if(!object){						let it = {							url:layoutModel.url,							name:layoutModel.modelName,							list:[item],						}						realFurnitureArr.push(it)					}else{						object.list.push(item);					}				}			});			return realFurnitureArr;		},		//加载家具模型-实例化方案		loadLayoutModels(realData, arrLength, resolve){		    var that = this;			if(!realData.url){				console.warn("***家具模型不存在***",realData);				resolve();				return false;			}			that.loader.load(realData.url, ( gltf ) => {				// that.progress = parseInt(100/arrLength) + that.progress;				// if(that.progress>100){				// 	that.progress = 100;				// }				// that.$refs.myLoading.showLoading("加载中..." + that.progress+'%')				// console.log("家具加载成功",that.progress,realData,gltf);				gltf.scene.traverse((child)=> {					if (child.isMesh && child.visible) {						let instancedMesh = new THREE.InstancedMesh(child.geometry.clone(), child.material.clone(), realData.list.length);						this.instancedFurList.push(instancedMesh);						//realData 该模型被重复使用时的每一次的形变参数等						realData.list && realData.list.forEach((it,i)=>{							let rotationY = Math.PI / 2;							if (parseFloat(it.rotation) == 90) {								rotationY = 0;							}							if (parseFloat(it.rotation) == 180) {								rotationY = -Math.PI / 2;							}							if (parseFloat(it.rotation) == -90) {								rotationY = -Math.PI;							}							gltf.scene.rotation.y = rotationY;							gltf.scene.updateMatrixWorld();//更新世界坐标-这样,子模型也同步更新了							instancedMesh.setMatrixAt(i, child.matrixWorld);							instancedMesh.instanceMatrix.needsUpdate = true;							// instancedMesh.setColorAt(i, child.material.color);							// instancedMesh.instanceColor.needsUpdate = true;							let gltfFurn = that.gltfLayouts.find(itme=>itme.uniId==it.uniId);//判断是否已经添加过							if(!gltfFurn){								let position = new THREE.Vector3();//当前几何体的位置参数								let scale = new THREE.Vector3();//当前几何体的缩放参数								let rotation = new THREE.Vector3();//当前几何体的缩放参数								let md = {									uniId:it.uniId,//家具模型实例的唯一标识									spaceId:it.spaceId,									id:it.id,									instancedMeshIndexList:[//标识网格实例数组的序号 以及 当前几何体 在网格实例的序号										{instancedMeshIndex:this.instancedFurList.length-1,instancedAtIndex:i},									],									userData:it,									position:position,									scale:scale,									rotation:rotation,									loaded:false,								};								that.gltfLayouts.push(md);							}else{								gltfFurn.instancedMeshIndexList.push({									instancedMeshIndex:this.instancedFurList.length-1,instancedAtIndex:i								})							}						})						instancedMesh.userType = "layoutMesh";					}				});				resolve();			});		},		//加载模型		loadLayoutModelsOld(modelObj, resolve) {			let that = this;			const modelName = modelObj.modelName;			console.log("布局模型名称", modelName);			let layoutModel = modelData.find(it => modelName.indexOf(it.modelName) == 0); //模型地址			if (!layoutModel || !layoutModel.url) {				resolve();				return false			}			let url = layoutModel.url;			console.log("布局模型数据", layoutModel);			that.loader.load(url, (gltf) => {				// console.log("布局模型加载成功", gltf);				let model = gltf.scene; // 获取模型				model.name = layoutModel.modelName;				model.userType = "layoutMesh";				model.userData = modelObj;				// model.rotation.y =  Math.PI / 2 ;  // 旋转 90 度				this.gltfLayouts.push(model);				resolve();			});		},		// 计算家具的位置		calculateLayoutModelSize() {			console.log("计算家具的位置", this.gltfLayouts);			for (let index = 0; index < this.spaceList.length; index++) {				const element = this.spaceList[index];				const gltfLayoutModels = this.gltfLayouts.filter(item => {					return element.layoutId == item.userData.layoutId && element.spaceId == item.userData.spaceId;				})				//空间下不存在家具模型,则该空间不需要进行下一步处理				if (!gltfLayoutModels || gltfLayoutModels.length == 0) {					continue;				}				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 {				centerX,				spaceId			} = curSpace;			const cubeInfo = this.resetModelParameters(curSpace, cube.userData);			// const cubeInfo = cube.userData;			let centerY = curSpace.centerY * -1; // UE和ThreeJS坐标做相反			// 默认空间中心点			let positionX = centerX;			let positionY = centerY;			let rotationY = Math.PI / 2;			let scaleX = 1;			let scaleY = 1;			// 空间尺寸			let spaceWidth = curSpace.spaceWidth;			let spaceHeight = curSpace.spaceHeight;			// 模型尺寸			let modelWidth = cubeInfo.modelWidth;			let modelHeight = cubeInfo.modelHeight;			// // 判断旋转			if (parseFloat(cubeInfo.rotation) == 90) {				rotationY = 0;				// 交换尺寸				// modelWidth = cubeInfo.modelHeight;				// modelHeight = cubeInfo.modelWidth;			}			if (parseFloat(cubeInfo.rotation) == 180) {				rotationY = -Math.PI / 2;				// modelWidth = cubeInfo.modelHeight;				// modelHeight = cubeInfo.modelWidth;			}			if (parseFloat(cubeInfo.rotation) == -90) {				rotationY = -Math.PI;				// 交换尺寸				// modelWidth = cubeInfo.modelHeight;				// modelHeight = cubeInfo.modelWidth;			}			// 判断靠墙			if (cubeInfo.isStepAsideLeft == 'true') {				positionX = centerX - (spaceWidth / 2 - modelWidth / 2);				if (parseFloat(cubeInfo.rotation) == 90 || parseFloat(cubeInfo.rotation) == -90) {					positionX = centerX - (spaceWidth / 2 - modelWidth / 2);				}				positionX += parseFloat(cubeInfo.marginLeft);				positionX += curSpace.spaceWallInfo.wallW ? 10 : 0;			}			if (cubeInfo.isStepAsideRight == 'true') {				positionX = centerX + (spaceWidth / 2 - modelHeight / 2);				if (parseFloat(cubeInfo.rotation) == 90 || parseFloat(cubeInfo.rotation) == -90) {					positionX = centerX + (spaceWidth / 2 - modelWidth / 2);				}				positionX -= parseFloat(cubeInfo.marginRight);				positionX -= curSpace.spaceWallInfo.wallE ? 10 : 0;			}			if (cubeInfo.isStepAsideTop == 'true') {				positionY = centerY - (spaceHeight / 2 - modelWidth / 2);				if (parseFloat(cubeInfo.rotation) == 90 || parseFloat(cubeInfo.rotation) == -90) {					positionY = centerY - (spaceHeight / 2 - modelHeight / 2);				}								positionY += parseFloat(cubeInfo.marginTop);				positionY += curSpace.spaceWallInfo.wallN ? 10 : 0;			}			if (cubeInfo.isStepAsideBottom == 'true') {				positionY = centerY + (spaceHeight / 2 - modelHeight / 2);				if (parseFloat(cubeInfo.rotation) == 90 || parseFloat(cubeInfo.rotation) == -90) {					positionY = centerY + (spaceHeight / 2 - modelHeight / 2);				}								positionY -= parseFloat(cubeInfo.marginBottom);				positionY -= curSpace.spaceWallInfo.wallS ? 10 : 0;			}			// 参照物			if (parseInt(cubeInfo.referenceModelTop) > 0) {				const referenceModel = this.gltfLayouts.find(item => {					const layoutModelData = item.userData;					return layoutModelData.id == parseInt(cubeInfo.referenceModelTop) && layoutModelData						.spaceId == cubeInfo.spaceId && layoutModelData.layoutId == cubeInfo.layoutId;				})				positionY = referenceModel.position.z * 100 + (referenceModel.userData.modelHeight / 2 + cubeInfo					.modelHeight / 2);				positionY = positionY + parseFloat(cubeInfo.marginTop);			}			if (parseInt(cubeInfo.referenceModelBottom) > 0) {				const referenceModel = this.gltfLayouts.find(item => {					const layoutModelData = item.userData;					return layoutModelData.id == parseInt(cubeInfo.referenceModelBottom) && layoutModelData						.spaceId == cubeInfo.spaceId && layoutModelData.layoutId == cubeInfo.layoutId;				})				positionY = referenceModel.position.z * 100 - (referenceModel.userData.modelHeight / 2 + cubeInfo					.modelHeight / 2);				positionY = positionY - parseFloat(cubeInfo.marginBottom);			}			if (parseInt(cubeInfo.referenceModelLeft) > 0) {				const referenceModel = this.gltfLayouts.find(item => {					const layoutModelData = item.userData;					return layoutModelData.id == parseInt(cubeInfo.referenceModelLeft) && layoutModelData						.spaceId == cubeInfo.spaceId && layoutModelData.layoutId == cubeInfo.layoutId;				})				positionX = referenceModel.position.x * 100 + (referenceModel.userData.modelWidth / 2 + cubeInfo					.modelWidth / 2);				positionX = positionX + parseFloat(cubeInfo.marginLeft);			}			if (parseInt(cubeInfo.referenceModelRight) > 0) {				const referenceModel = this.gltfLayouts.find(item => {					const layoutModelData = item.userData;					return layoutModelData.id == parseInt(cubeInfo.referenceModelRight) && layoutModelData						.spaceId == cubeInfo.spaceId && layoutModelData.layoutId == cubeInfo.layoutId;				})				positionX = referenceModel.position.x * 100 - (referenceModel.userData.modelWidth / 2 + cubeInfo					.modelWidth / 2);				positionX = positionX - parseFloat(cubeInfo.marginRight);			}			if (cubeInfo.isFixedWidth == "false" || cubeInfo.isFixedHeight == "false") { // 固定尺寸				// 靠墙拉伸				if (cubeInfo.isStepAsideTop == 'true' && cubeInfo.isStepAsideBottom == 'true') {					// console.log("高度拉伸", spaceHeight / modelHeight)					positionY = centerY;					if (curSpace.spaceWallInfo.wallN && curSpace.spaceWallInfo.wallS) {						spaceHeight -= 20 + parseFloat(cubeInfo.marginTop) + parseFloat(cubeInfo.marginBottom);					} else if (curSpace.spaceWallInfo.wallN) {						spaceHeight -= 10 + parseFloat(cubeInfo.marginTop);						positionY += 10 / 2;						positionY += parseFloat(cubeInfo.marginTop) / 2;					} else if (curSpace.spaceWallInfo.wallS) {						spaceHeight -= 10 + parseFloat(cubeInfo.marginBottom);						positionY -= 10 / 2;						positionY -= parseFloat(cubeInfo.marginBottom) / 2;					}else {						spaceHeight -= parseFloat(cubeInfo.marginTop) + parseFloat(cubeInfo.marginBottom);						positionY += parseFloat(cubeInfo.marginTop) / 2 ;						positionY -= parseFloat(cubeInfo.marginBottom) / 2;					}					// 计算缩放					if (parseFloat(cubeInfo.rotation) == 90 || parseFloat(cubeInfo.rotation) == -90) {						scaleY = spaceHeight / modelHeight;					} else {						scaleX = spaceHeight / modelHeight;					}				}				if (cubeInfo.isStepAsideLeft == 'true' && cubeInfo.isStepAsideRight == 'true') {					// console.log("宽度拉伸11111", spaceWidth / modelWidth)					positionX = centerX;					if (curSpace.spaceWallInfo.wallW && curSpace.spaceWallInfo.wallE) {						spaceWidth -= 20 + parseFloat(cubeInfo.marginLeft) + parseFloat(cubeInfo.marginRight);;					} else if (curSpace.spaceWallInfo.wallW) {						spaceWidth -= 10 + parseFloat(cubeInfo.marginLeft);						positionX += 10 / 2;						positionX += parseFloat(cubeInfo.marginLeft) / 2;					} else if (curSpace.spaceWallInfo.wallE) {						spaceWidth -= 10 + parseFloat(cubeInfo.marginRight);						positionX -= 10 / 2;						positionX -= parseFloat(cubeInfo.marginRight) / 2;					}else {						spaceWidth -= parseFloat(cubeInfo.marginLeft) + parseFloat(cubeInfo.marginRight);						positionX += parseFloat(cubeInfo.marginLeft) / 2;						positionX -= parseFloat(cubeInfo.marginRight) / 2;					}					// console.log("模型计算位置" , parseFloat(cubeInfo.rotation))					// 计算缩放					if (parseFloat(cubeInfo.rotation) == 90 || parseFloat(cubeInfo.rotation) == -90) {						scaleX = spaceWidth / modelWidth;					} else {						scaleY = spaceWidth / modelWidth;					}				}				// 单个参照物和墙面拉伸				if (cubeInfo.isStepAsideTop == 'true' && parseInt(cubeInfo.referenceModelBottom) > 0) {					const referenceModel = this.gltfLayouts.find(item => {						const layoutModelData = item.userData;						return layoutModelData.id == parseInt(cubeInfo.referenceModelBottom) && layoutModelData							.spaceId == cubeInfo.spaceId && layoutModelData.layoutId == cubeInfo.layoutId;					})					const referenceModelPositionY = referenceModel.position.z * 100 - referenceModel.userData						.modelHeight / 2 - parseFloat(cubeInfo.marginBottom);					const wallPositionY = centerY - spaceHeight / 2 + (curSpace.spaceWallInfo.wallN ? 10 : 0) +						parseFloat(cubeInfo.marginTop);					const newModelHeight = Math.abs(referenceModelPositionY - wallPositionY);					// console.log("上边拉伸", referenceModelPositionY, wallPositionY, newModelHeight)					if (Math.abs(parseFloat(cubeInfo.rotation)) == 90) {						scaleY = newModelHeight / modelHeight;					} else {						scaleX = newModelHeight / modelHeight;					}					positionY = wallPositionY + newModelHeight / 2;				}				if (cubeInfo.isStepAsideBottom == 'true' && parseInt(cubeInfo.referenceModelTop) > 0) {					const referenceModel = this.gltfLayouts.find(item => {						const layoutModelData = item.userData;						return layoutModelData.id == parseInt(cubeInfo.referenceModelTop) && layoutModelData							.spaceId == cubeInfo.spaceId && layoutModelData.layoutId == cubeInfo.layoutId;					})					const referenceModelPositionY = referenceModel.position.z * 100 + referenceModel.userData						.modelHeight / 2 + parseFloat(cubeInfo.marginTop) + (curSpace.spaceWallInfo.wallN ? 10 : 0);					const wallPositionY = centerY + spaceHeight / 2 - (curSpace.spaceWallInfo.wallS ? 10 : 0) -					parseFloat(cubeInfo.marginBottom);					const newModelHeight = Math.abs(referenceModelPositionY - wallPositionY);					if (Math.abs(parseFloat(cubeInfo.rotation)) == 90) {						scaleY = newModelHeight / modelHeight;					} else {						scaleX = newModelHeight / modelHeight;					}					positionY = wallPositionY - newModelHeight / 2;				}				if (cubeInfo.isStepAsideLeft == 'true' && parseInt(cubeInfo.referenceModelRight) > 0) {					// console.log("左边拉伸")					const referenceModel = this.gltfLayouts.find(item => {						const layoutModelData = item.userData;						return layoutModelData.id == parseInt(cubeInfo.referenceModelRight) && layoutModelData							.spaceId == cubeInfo.spaceId && layoutModelData.layoutId == cubeInfo.layoutId;					})					const referenceModelPositionX = referenceModel.position.x * 100 - referenceModel.userData						.modelWidth / 2 - parseFloat(cubeInfo.marginLeft);					const wallPositionX = centerX - spaceWidth / 2 + (curSpace.spaceWallInfo.wallE ? 10 : 0) +						parseFloat(cubeInfo.marginRight);					const newModelWidth = Math.abs(referenceModelPositionX - wallPositionX);					if (Math.abs(parseFloat(cubeInfo.rotation)) == 90) {						scaleX = newModelWidth / modelWidth;					} else {						scaleY = newModelWidth / modelWidth;					}					positionX = wallPositionX + newModelWidth / 2;				}				if (cubeInfo.isStepAsideRight == 'true' && parseInt(cubeInfo.referenceModelLeft) > 0) {					const referenceModel = this.gltfLayouts.find(item => {						const layoutModelData = item.userData;						return layoutModelData.id == parseInt(cubeInfo.referenceModelLeft) && layoutModelData							.spaceId == cubeInfo.spaceId && layoutModelData.layoutId == cubeInfo.layoutId;					})					const referenceModelPositionX = referenceModel.position.x * 100 + referenceModel.userData						.modelWidth / 2 + parseFloat(cubeInfo.marginLeft);					const wallPositionX = centerX + spaceWidth / 2 - (curSpace.spaceWallInfo.wallE ? 10 : 0) -						parseFloat(cubeInfo.marginRight);					const newModelWidth = Math.abs(referenceModelPositionX - wallPositionX);					if (Math.abs(parseFloat(cubeInfo.rotation)) == 90) {						scaleX = newModelWidth / modelWidth;					} else {						scaleY = newModelWidth / modelWidth;					}					positionX = wallPositionX - newModelWidth / 2;					// console.log("右边拉伸", Math.abs(parseFloat(cubeInfo.rotation)))				}			}			// console.log("模型计算位置--", positionX, positionY)			// console.log("模型计算位置", cubeInfo, centerX, centerY, spaceWidth, spaceHeight, modelWidth, modelHeight, spaceId, scaleX, scaleY, rotationY)			let oldPosition = new THREE.Vector3();//当前几何体的位置参数			oldPosition.copy(cube.position);			cube.position.x = positionX / 100;			cube.position.z = positionY / 100;			cube.rotation.y = rotationY;			cube.scale.x = scaleX ;			cube.scale.z = scaleY;			if (!cube.parent) { //说明还没添加到场景中-旧版方法				this.scene.add(cube); //处理完毕后在加入场景中			}			if(scaleX>1 || scaleY>1){				console.warn("***scaleinfo***",cubeInfo.id,scaleX,scaleY,cubeInfo.modelName)			}			// this.updateInfo(cube,oldPosition,scaleX,scaleY);//实例化方法		},		//更新家具模型到页面中		updateInfo(cube,oldPosition,scaleX,scaleY){			let lay = this.gltfLayouts.find(it=>it.uniId==cube.uniId);			cube.instancedMeshIndexList.forEach(item=>{				let index = item.instancedMeshIndex;				let instancedMesh = this.instancedFurList[index];//网格实例对象				let curMeshIndex = item.instancedAtIndex;//当前家具模型在网格实例对象里面的序号				let stratMatrix = new THREE.Matrix4();//定义一个四维矩阵				instancedMesh.getMatrixAt(curMeshIndex,stratMatrix);//获取当前几何体的四维矩阵到stratMatrix里面				let scaleMatrix = new THREE.Matrix4();	//定义一个缩放变化矩阵				let panMatrix = new THREE.Matrix4();	//定义一个平移变化矩阵				if (!lay.loaded) { //说明还没添加到场景中					scaleMatrix.makeScale(scaleX,1,scaleY);	//获得缩放变化矩阵					panMatrix.makeTranslation(cube.position.x,0,cube.position.z);	//获得平移变化矩阵					stratMatrix.multiply(scaleMatrix).premultiply(panMatrix);//通过矩阵计算获得最终的形变矩阵					instancedMesh.instanceMatrix.needsUpdate = true;//更新之前,必须开启开关					instancedMesh.setMatrixAt(curMeshIndex,stratMatrix);//更新几何体的世界矩阵					this.scene.add(instancedMesh);				}else{//更新形变矩阵					panMatrix.makeTranslation(cube.position.x - oldPosition.x,0,cube.position.z - oldPosition.z);	//获得平移变化矩阵					stratMatrix.premultiply(panMatrix);//通过矩阵计算获得最终的形变矩阵					instancedMesh.instanceMatrix.needsUpdate = true;//更新之前,必须开启开关					instancedMesh.setMatrixAt(curMeshIndex,stratMatrix);//更新几何体的世界矩阵				}			})			lay.loaded = true;		},		// 空间布局旋转镜像重置模型约束		resetModelParameters(curSpace, cubeInfo) {			// 旋转			const defaultLayout = curSpace.layouts.find(item => {				return item.isDefault			})			if (!defaultLayout) {				return cubeInfo			}			let count = 0;			switch (parseInt(defaultLayout.layoutRotate)) {				case 90:					count = 1;					break;				case 180:					count = 2;					break;				case -90:					count = 3;					break;				default:					break;			}			for (let index = 0; index < count; index++) {				let oldCubeInfo = JSON.parse(JSON.stringify(cubeInfo))				oldCubeInfo.isStepAsideLeft = "false"				oldCubeInfo.isStepAsideTop = "false"				oldCubeInfo.isStepAsideRight = "false"				oldCubeInfo.isStepAsideBottom = "false"				oldCubeInfo.referenceModelLeft = "0"				oldCubeInfo.referenceModelTop = "0"				oldCubeInfo.referenceModelRight = "0"				oldCubeInfo.referenceModelBottom = "0"				oldCubeInfo.rotation = "0"				oldCubeInfo.marginLeft = "0";				oldCubeInfo.marginTop = "0";				oldCubeInfo.marginRight = "0";				oldCubeInfo.marginBottom = "0";				// 是否靠墙				if (cubeInfo.isStepAsideLeft == 'true') {					oldCubeInfo.isStepAsideTop = 'true'				}				if (cubeInfo.isStepAsideTop == 'true') {					oldCubeInfo.isStepAsideRight = 'true'				}				if (cubeInfo.isStepAsideRight == 'true') {					oldCubeInfo.isStepAsideBottom = 'true'				}				if (cubeInfo.isStepAsideBottom == 'true') {					oldCubeInfo.isStepAsideLeft = 'true'				}				// 参照物体				if (parseInt(cubeInfo.referenceModelLeft) > 0) {					oldCubeInfo.referenceModelTop = cubeInfo.referenceModelLeft;				}				if (parseInt(cubeInfo.referenceModelTop) > 0) {					oldCubeInfo.referenceModelRight = cubeInfo.referenceModelTop;				}				if (parseInt(cubeInfo.referenceModelRight) > 0) {					oldCubeInfo.referenceModelBottom = cubeInfo.referenceModelRight;				}				if (parseInt(cubeInfo.referenceModelBottom) > 0) {					oldCubeInfo.referenceModelLeft = cubeInfo.referenceModelBottom;				}				// 边距				oldCubeInfo.marginLeft = cubeInfo.marginTop;				oldCubeInfo.marginTop = cubeInfo.marginRight;				oldCubeInfo.marginRight = cubeInfo.marginBottom;				oldCubeInfo.marginBottom = cubeInfo.marginLeft;				oldCubeInfo.modelWidth = cubeInfo.modelHeight;				oldCubeInfo.modelHeight = cubeInfo.modelWidth;				// 旋转				if (parseInt(cubeInfo.rotation) == 0 || parseInt(cubeInfo.rotation) == 90) {					oldCubeInfo.rotation = parseInt(cubeInfo.rotation) + 90;				}				if (parseInt(cubeInfo.rotation) == 180) {					oldCubeInfo.rotation = "-90";				}				if (parseInt(cubeInfo.rotation) == -90) {					oldCubeInfo.rotation = "0";				}				// console.log("旋转前的模型参数X", cubeInfo, oldCubeInfo, defaultLayout)				cubeInfo = oldCubeInfo;				// console.log("旋转后的模型参数X", cubeInfo, oldCubeInfo, defaultLayout)			}			return cubeInfo;		},	}}
 |