123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194 |
- const config = require('@/services/urlConfig.js');
- import modelData from '@/static/layoutModelData.js';
- import globlShowModel from '@/static/globlShowModel.js';
- import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
- import * as THREE from 'three';
- export default {
- data() {
- return {
- gltfLayouts: [],
- instancedFurList:[],
-
-
-
-
- arrFrunList:[],
- promise_list:[],
- dracoLoader:null,
- type:1,
- tmpList:[],
- realList:[],
- nextString:'_simple',
-
- }
- },
- watch: {},
- mounted() {
- console.warn("***loadmodel-mounted****")
- this.dracoLoader = new DRACOLoader();
- this.dracoLoader.setDecoderPath('./gltf/');
- this.dracoLoader.setDecoderConfig( { type: 'js' } );
- this.dracoLoader.preload();
- },
- 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;
- }
- },
-
- async getOverallArrangementDetailsList(type=1) {
-
-
- this.type = type;
- let arr = this.spaceList.map(it => it.layoutId).filter(it => it != 0);
- let parmas = {
- ids: arr,
- };
-
- 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.gltfLayouts = [];
-
- this.furnHandle(this.arrFrunList,[]);
- },
-
- loadLastSpaceModel(){
- if(!this.changeSpaces || this.changeSpaces.length==0){
- return false;
- }
- let spaceIds = this.changeSpaces.map(it=>it.spaceId);
- let layoutIds = this.spaceList.filter(item=>spaceIds.includes(item.spaceId)).map(it=>it.layoutId);
- let list = this.arrFrunList.filter(item=>{
- return !layoutIds.includes(item.id)
- })
- let spaceList = this.spaceList.filter(item=>{
- return !spaceIds.includes(item.spaceId)
- })
-
- this.furnHandle(list,spaceList)
- this.changeSpaces = []
- },
-
- furnHandle(arrFrunList, tmpSpaceList=[]){
- console.log("bug修复", arrFrunList, tmpSpaceList)
- if(!arrFrunList || arrFrunList.length == 0){
- return
- }
- let startTime = new Date().getTime();
- let tmpList = [];
-
- let allowSpaceId = [this.curSpaceObj.spaceId];
- if(this.type == 2){
- allowSpaceId = this.spaceList.map(it=>it.spaceId)
- }else{
- allowSpaceId = [this.curSpaceObj.spaceId];
- if(this.curSpaceObj.spaceType==4){
- let list = this.spaceList.filter(it=>it.spaceType==2)
- allowSpaceId.push(...list.map(it=>it.spaceId));
- }
- if(this.curSpaceObj.spaceType==2){
- let list = this.spaceList.filter(it=>it.spaceType==4)
- allowSpaceId.push(...list.map(it=>it.spaceId));
- }
- }
- console.warn("重新加载布局", arrFrunList,this.spaceList,this.gltfLayouts,allowSpaceId);
- arrFrunList.forEach(signel => {
- let spaceId = this.spaceList.find(it => it.layoutId == signel.id).spaceId;
- if(allowSpaceId.includes(spaceId)){
- let md = JSON.parse(signel.modelJson);
-
- for (let i = 0; i < md.modelData.length; i++) {
- let item = md.modelData[i];
- item.spaceId = spaceId;
- item.layoutId = signel.id;
- item.h5Id = signel.id+""+item.id;
- if(item.modelName=='BP_furnitureBase_C'){
-
- continue;
- }else{
- tmpList.push(item);
-
- }
- }
- }
- })
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- this.tmpList = tmpList;
- if(this.type==2){
- this.fliterList(tmpList);
- console.warn("***fliterList***",this.realList.length);
- tmpList = this.realList;
- }
- let realFurArr = this.preFurnitureData(tmpList);
- if(tmpSpaceList && tmpSpaceList.length>0){
- this.calculateLayoutModelSizeBySpace(tmpSpaceList)
- }else{
- this.calculateLayoutModelSize()
- }
- console.log("***realFurArr***", realFurArr,this.gltfLayouts);
- realFurArr && realFurArr.forEach((item,index) => {
- this.promise_list.push(
- new Promise((resolve, reject) => {
- this.loadLayoutModels(item, resolve);
- })
- )
- });
- Promise.all(this.promise_list).then(() => {
- let endTime = new Date().getTime();
- console.log("家具模型全部加载完成,时间:", endTime - startTime, this.gltfLayouts);
- this.loadLastSpaceModel();
- })
- },
-
- fliterList(list){
- this.realList = [];
- let tempList = globlShowModel.map(it=>it.replace(this.nextString,''));
-
- list && list.forEach((mod)=>{
- let name = mod.modelName.substring(0,mod.modelName.length-2);
- if(tempList.includes(name)){
- this.realList.push(mod);
- }
- })
- this.realList.forEach((ref)=>{
- this.recursionFliter(ref)
- })
- },
-
- recursionFliter(item){
- let _list = [];
- if(parseInt(item.referenceModelBottom) > 0){
- _list.push(item.referenceModelBottom)
- }
- if(parseInt(item.referenceModelLeft) > 0){
- _list.push(item.referenceModelLeft)
- }
- if(parseInt(item.referenceModelRight) > 0){
- _list.push(item.referenceModelRight)
- }
- if(parseInt(item.referenceModelTop) > 0){
- _list.push(item.referenceModelTop)
- }
- if(_list.length==0){
- return false;
- }else{
- this.tmpList.forEach(tmp=>{
- if(_list.includes(tmp.id)){
- if(!this.realList.find(it=>it.h5Id==tmp.h5Id)){
- this.realList.push(tmp);
- this.recursionFliter(tmp);
- }
- }
- })
- }
-
- },
-
- preFurnitureData(list){
- let realFurnitureArr = [];
- list && list.forEach((item, index) => {
- item.uniId = Date.now() + index;
-
- let modelName = item.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 url = layoutModel.url;
- if(this.type==2){
-
- if(globlShowModel.includes(layoutModel.modelName + this.nextString)){
- let idx = layoutModel.url.lastIndexOf('.');
- url = url.substr(0,idx) + this.nextString + url.substr(idx)
- }
- }
- let it = {
- url:url,
- name:layoutModel.modelName,
- list:[item],
- }
- realFurnitureArr.push(it)
- }else{
- object.list.push(item);
- }
-
- let position = new THREE.Vector3();
- let scale = new THREE.Vector3();
- let rotation = new THREE.Vector3();
- let md = {
- uniId:item.uniId,
- spaceId:item.spaceId,
- id:item.id,
- userData:item,
- position:position,
- scale:scale,
- rotation:rotation,
- loaded:false,
- };
- this.gltfLayouts.push(md);
- }
- });
- return realFurnitureArr;
- },
-
- loadLayoutModels(realData, resolve){
- var that = this;
- if(!realData.url){
- console.warn("***家具模型不存在***",realData);
- resolve();
- return false;
- }
- if(realData.name.includes('BP_XSPACE_deng_01')){
- resolve();
- }else{
-
- if(!globlShowModel.includes(realData.name)){
- resolve();
- return false;
- }
- that.loader.setDRACOLoader(this.dracoLoader);
- that.loader.load(realData.url, ( 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.list && realData.list.forEach((it,i)=>{
- let gltfFurn = that.gltfLayouts.find(itme=>itme.uniId==it.uniId);
- gltf.scene.rotation.y = gltfFurn.rotation.y;
- gltf.scene.position.set(gltfFurn.position.x,0,gltfFurn.position.z);
- gltf.scene.scale.set(gltfFurn.scale.x,1,gltfFurn.scale.z);
- gltf.scene.updateMatrixWorld();
- instancedMesh.setMatrixAt(i, child.matrixWorld);
- instancedMesh.instanceMatrix.needsUpdate = true;
- gltfFurn.loaded = true;
- if(!gltfFurn.instancedMeshIndexList){
- gltfFurn.instancedMeshIndexList = [
- {instancedMeshIndex:this.instancedFurList.length-1,instancedAtIndex:i},
- ]
- }else{
- gltfFurn.instancedMeshIndexList.push({
- instancedMeshIndex:this.instancedFurList.length-1,instancedAtIndex:i
- })
- }
- })
- instancedMesh.userType = "layoutMesh";
- if(realData.name.includes("BP_L_carpet01")){
- instancedMesh.receiveShadow = true;
- }else{
- instancedMesh.castShadow = true;
- }
- this.scene.add(instancedMesh);
- }
- });
- 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) => {
-
- let model = gltf.scene;
-
- model.name = layoutModel.modelName;
- model.userType = "layoutMesh";
- model.userData = modelObj;
-
-
- this.gltfLayouts.push(model);
- resolve();
- });
- },
-
- clearAllLayoutData(){
- let deleList = this.scene && this.scene.children.filter(object=>{
- if(object.userType=="layoutMesh"){
- return object
- }
- })
-
- if(deleList && deleList.length>0){
- this.scene.remove(...deleList);
- }
- this.gltfLayouts = [];
- this.instancedFurList = [];
- },
-
- changeLayoutModelState(isShow=false){
- if(isShow){
- this.instancedFurList.forEach(it=>{
- if(it){
- it.visible = isShow;
- }
- })
- console.log("移动过程中显示隐藏空间家具", this.gltfLayouts,isShow,this.changeSpaces)
- return false;
- }
-
- const changeSpaceList = this.leftSpaces.concat(this.rightSpaces);
- console.log("移动过程中显示隐藏空间家具", this.gltfLayouts,isShow, this.leftSpaces, this.rightSpaces,this.changeSpaces);
- for (let index = 0; index < changeSpaceList.length; index++) {
- let element = changeSpaceList[index];
- let gltfLayoutModels = this.gltfLayouts.filter(item => {
- return element.layoutId == item.userData.layoutId && element.spaceId == item.userData.spaceId;
- })
-
- if (!gltfLayoutModels || gltfLayoutModels.length == 0) {
- continue;
- }
- console.warn("***隐藏空间家具***",element,gltfLayoutModels)
- for (let j = 0; j < gltfLayoutModels.length; j++) {
- let cube = gltfLayoutModels[j];
- this.changeCubeState(cube, isShow);
- }
- }
- },
-
- changeCubeState(cube, isShow){
- let lay = this.gltfLayouts.find(it=>it.uniId==cube.uniId);
- if(cube.instancedMeshIndexList && cube.instancedMeshIndexList.length>0){
- cube.instancedMeshIndexList.forEach(item=>{
- let index = item.instancedMeshIndex;
- let instancedMesh = this.instancedFurList[index];
-
-
-
-
-
- instancedMesh.visible = isShow;
-
- })
- }
- },
-
- deleteLayoutModel(spaceObj, layoutObj){
- const oldLayoutIndex = this.arrFrunList.findIndex((item)=>{
- return item.id == spaceObj.layoutId
- })
-
- if(oldLayoutIndex!=-1 && layoutObj){
- this.arrFrunList[oldLayoutIndex] = layoutObj
-
- }
- if(!layoutObj){
- this.arrFrunList.splice(oldLayoutIndex,1)
- spaceObj.layoutId = null;
- }
- console.log("准备删除模型", spaceObj,oldLayoutIndex, this.gltfLayouts);
-
- const gltfLayoutModels = this.gltfLayouts.filter(item => {
- return spaceObj.layoutId == item.userData.layoutId && spaceObj.spaceId == item.userData.spaceId;
- })
-
- if (!gltfLayoutModels || gltfLayoutModels.length == 0) {
- return;
- }
- let deleList = []
- for (let j = 0; j < gltfLayoutModels.length; j++) {
- const cube = gltfLayoutModels[j];
- this.gltfLayouts.splice(this.gltfLayouts.findIndex(it=>it.uniId==cube.uniId),1);
- if(cube.instancedMeshIndexList && cube.instancedMeshIndexList.length>0){
- cube.instancedMeshIndexList.forEach(item=>{
- let index = item.instancedMeshIndex;
- let instancedMesh = this.instancedFurList[index];
- if(instancedMesh){
- instancedMesh.dispose();
- deleList.push(instancedMesh);
- this.instancedFurList[index] = null;
-
-
-
-
-
- }
- })
- }
- }
- this.scene.remove(...deleList);
- console.log("删除模型了", spaceObj, this.gltfLayouts);
- },
-
- calculateLayoutModelSize() {
- console.log("计算家具的位置", this.gltfLayouts,this.changeSpaces);
-
- const spaceList = (!this.changeSpaces || this.changeSpaces.length ==0) ? this.spaceList : this.changeSpaces;
- for (let index = 0; index < spaceList.length; index++) {
- const element = 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
- });
-
- for (let j = 0; j < gltfLayoutModels.length; j++) {
- const cube = gltfLayoutModels[j];
- this.drawLayoutModel(element, cube);
- }
- }
- },
-
- calculateLayoutModelSizeBySpace(spaceList) {
- for (let index = 0; index < spaceList.length; index++) {
- const element = 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
- });
-
- 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);
-
- let centerY = curSpace.centerY * -1;
-
- 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;
-
-
-
- }
- if (parseFloat(cubeInfo.rotation) == 180) {
- rotationY = -Math.PI / 2;
-
-
- }
-
- if (parseFloat(cubeInfo.rotation) == -90) {
- rotationY = -Math.PI;
-
-
-
- }
-
- 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 - modelWidth / 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 - modelHeight / 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;
- })
- if(!referenceModel){
- console.warn("***no-data***",cubeInfo.referenceModelTop,cubeInfo)
- return false
- }
- 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;
- })
- if(!referenceModel){
- console.warn("***no-data***",cubeInfo.referenceModelBottom,cubeInfo)
- return false
- }
- 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;
- })
- if(!referenceModel){
- console.warn("***no-data***",cubeInfo.referenceModelLeft,cubeInfo)
- return false
- }
- 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;
- })
- if(!referenceModel){
- console.warn("***no-data***",cubeInfo.referenceModelRight,cubeInfo)
- return false
- }
- 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') {
-
-
- positionY = centerY;
-
- if (curSpace.spaceWallInfo.wallN && curSpace.spaceWallInfo.wallS) {
- spaceHeight -= 20 + parseFloat(cubeInfo.marginTop) + parseFloat(cubeInfo.marginBottom);
- positionY += parseFloat(cubeInfo.marginTop) / 2 ;
- positionY -= parseFloat(cubeInfo.marginBottom) / 2;
- } else if (curSpace.spaceWallInfo.wallN) {
- spaceHeight -= 10 + parseFloat(cubeInfo.marginTop) + parseFloat(cubeInfo.marginBottom);
- positionY += 10 / 2;
- positionY += parseFloat(cubeInfo.marginTop) / 2;
- positionY -= parseFloat(cubeInfo.marginBottom) / 2;
- } else if (curSpace.spaceWallInfo.wallS) {
- spaceHeight -= 10 + parseFloat(cubeInfo.marginTop) + parseFloat(cubeInfo.marginBottom);
- positionY -= 10 / 2;
- positionY += parseFloat(cubeInfo.marginTop) / 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') {
-
- positionX = centerX;
-
- if (curSpace.spaceWallInfo.wallW && curSpace.spaceWallInfo.wallE) {
- spaceWidth -= 20 + parseFloat(cubeInfo.marginLeft) + parseFloat(cubeInfo.marginRight);
- positionX += parseFloat(cubeInfo.marginLeft) / 2;
- positionX -= parseFloat(cubeInfo.marginRight) / 2;
- } else if (curSpace.spaceWallInfo.wallW) {
- spaceWidth -= 10 + parseFloat(cubeInfo.marginLeft) + parseFloat(cubeInfo.marginRight);
- positionX += 10 / 2;
- positionX += parseFloat(cubeInfo.marginLeft) / 2;
- positionX -= parseFloat(cubeInfo.marginRight) / 2;
- } else if (curSpace.spaceWallInfo.wallE) {
- spaceWidth -= 10 + parseFloat(cubeInfo.marginLeft) + parseFloat(cubeInfo.marginRight);
- positionX -= 10 / 2;
- positionX += parseFloat(cubeInfo.marginLeft) / 2;
- positionX -= parseFloat(cubeInfo.marginRight) / 2;
- }else {
- spaceWidth -= parseFloat(cubeInfo.marginLeft) + parseFloat(cubeInfo.marginRight);
- positionX += parseFloat(cubeInfo.marginLeft) / 2;
- positionX -= parseFloat(cubeInfo.marginRight) / 2;
- }
-
-
- 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);
-
- 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) {
-
-
- 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;
-
-
- }
- if(parseInt(cubeInfo.referenceModelBottom) > 0 && parseInt(cubeInfo.referenceModelTop) > 0){
-
-
- const referenceModelTop = this.gltfLayouts.find(item => {
- const layoutModelData = item.userData;
- return layoutModelData.id == parseInt(cubeInfo.referenceModelTop) && layoutModelData
- .spaceId == cubeInfo.spaceId && layoutModelData.layoutId == cubeInfo.layoutId;
- })
-
- const referenceModelBottom = this.gltfLayouts.find(item => {
- const layoutModelData = item.userData;
- return layoutModelData.id == parseInt(cubeInfo.referenceModelBottom) && layoutModelData
- .spaceId == cubeInfo.spaceId && layoutModelData.layoutId == cubeInfo.layoutId;
- })
-
- const referenceModelTopPositionY = referenceModelTop.position.z * 100 + referenceModelTop.userData
- .modelHeight / 2 + parseFloat(cubeInfo.marginTop);
-
- const referenceModelBottomPositionY = referenceModelBottom.position.z * 100 - referenceModelBottom.userData
- .modelHeight / 2 - parseFloat(cubeInfo.marginBottom);
-
- const newModelHeight = Math.abs(referenceModelTopPositionY - referenceModelBottomPositionY);
- if (Math.abs(parseFloat(cubeInfo.rotation)) == 90) {
- scaleY = newModelHeight / modelHeight;
- } else {
- scaleX = newModelHeight / modelHeight;
- }
- positionY = referenceModelBottomPositionY - newModelHeight / 2;
- }
-
- if(parseInt(cubeInfo.referenceModelLeft) > 0 && parseInt(cubeInfo.referenceModelRight) > 0){
-
- const referenceModelLeft = this.gltfLayouts.find(item => {
- const layoutModelData = item.userData;
- return layoutModelData.id == parseInt(cubeInfo.referenceModelLeft) && layoutModelData
- .spaceId == cubeInfo.spaceId && layoutModelData.layoutId == cubeInfo.layoutId;
- })
-
- const referenceModelRight = this.gltfLayouts.find(item => {
- const layoutModelData = item.userData;
- return layoutModelData.id == parseInt(cubeInfo.referenceModelRight) && layoutModelData
- .spaceId == cubeInfo.spaceId && layoutModelData.layoutId == cubeInfo.layoutId;
- })
- const referenceModelLeftPositionX = referenceModelLeft.position.x * 100 + referenceModelLeft.userData
- .modelWidth / 2 + parseFloat(cubeInfo.marginLeft);
- const referenceModelRightPositionX = referenceModelRight.position.x * 100 - referenceModelRight.userData
- .modelWidth / 2 - parseFloat(cubeInfo.marginRight);
-
- const newModelWidth = Math.abs(referenceModelLeftPositionX - referenceModelRightPositionX);
-
- if (Math.abs(parseFloat(cubeInfo.rotation)) == 90) {
- scaleX = newModelWidth / modelWidth;
- } else {
- scaleY = newModelWidth / modelWidth;
- }
-
- positionX = referenceModelRightPositionX - newModelWidth / 2;
- }
-
- }
-
-
- 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;
- cube.scale.y = 1;
-
-
-
-
-
-
- if(this.type==2){
- let name = cubeInfo.modelName.substring(0, cubeInfo.modelName.length - 2);
- if(globlShowModel.includes(name)){
- if(cubeInfo.modelName=='BP_XSPACE_deng_01_C'){
- this.lightHandle(cube)
- }else{
- this.updateInfo(cube,oldPosition,scaleX,scaleY);
- }
- }
- }else{
- if(cubeInfo.modelName=='BP_XSPACE_deng_01_C'){
- this.lightHandle(cube)
- }else{
- this.updateInfo(cube,oldPosition,scaleX,scaleY);
- }
- }
- },
-
- updateInfo(cube,oldPosition,scaleX,scaleY){
- let lay = this.gltfLayouts.find(it=>it.uniId==cube.uniId);
- if(cube.instancedMeshIndexList && cube.instancedMeshIndexList.length>0){
- 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);
- let scaleMatrix = new THREE.Matrix4();
- let panMatrix = new THREE.Matrix4();
- if (!lay.loaded) {
-
-
-
-
-
-
- }else{
- scaleMatrix.makeScale(scaleX, 1, scaleY);
- panMatrix.makeTranslation(cube.position.x - oldPosition.x,0,cube.position.z - oldPosition.z);
- stratMatrix.multiply(scaleMatrix).premultiply(panMatrix);
- instancedMesh.instanceMatrix.needsUpdate = true;
- instancedMesh.setMatrixAt(curMeshIndex,stratMatrix);
- }
- })
- lay.loaded = true;
- }
- },
-
- lightHandle(cube){
- let light = this.gltfLayouts.find(it=>it.uniId==cube.uniId);
- if(!light.loaded){
-
- let pointLight = new THREE.PointLight(0xffd7b3, 1, 5, 1);
- pointLight.position.set(cube.position.x, 1.5, cube.position.z);
- this.scene.add(pointLight);
- let sphereSize = 0.1;
- let pointLightHelper = new THREE.PointLightHelper( pointLight, sphereSize );
- this.scene.add( pointLightHelper);
-
-
-
-
-
-
-
- this.scene.add(pointLight);
-
- light.loaded = true;
- }else{
-
- }
- },
-
- 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.marginBottom;
- oldCubeInfo.marginTop = cubeInfo.marginLeft;
- oldCubeInfo.marginRight = cubeInfo.marginTop;
- oldCubeInfo.marginBottom = cubeInfo.marginRight;
- 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";
- }
-
-
-
- cubeInfo = oldCubeInfo;
-
-
- }
-
- return cubeInfo;
- },
-
- changeLayoutModel(){
- let changeSpaces = [];
-
- for (let index = 0; index < this.changeSpaces.length; index++) {
- const element = this.changeSpaces[index];
- const findIndex = changeSpaces.findIndex((item)=>{
- return item.spaceId == element.spaceId;
- })
- if(findIndex==-1){
- const findListIndex = this.spaceList.findIndex((item)=>{
- return item.spaceId == element.spaceId;
- })
- if(findListIndex !=-1 && this.spaceList[findListIndex].spaceType!=14){
- changeSpaces.push(this.spaceList[findListIndex])
- }
- }
- }
- console.log("所有变化的空间", changeSpaces)
- this.changeLayouts = [];
- let promise_list = [];
- if(!changeSpaces || changeSpaces.length==0){
-
- return false;
- }
- this.clearAllLayoutData();
- for (let index = 0; index < changeSpaces.length; index++) {
- let element = changeSpaces[index];
- let layoutObj = this.arrFrunList.find((item)=>{
- return item.id == element.layoutId;
- })
- console.log("请求布局的对象", layoutObj, element);
- if(layoutObj){
- promise_list.push(
- new Promise((resolve, reject) => {
- this.loadlayoutByID(layoutObj.groupType, element, resolve);
- })
- )
- }else{
- promise_list.push(
- new Promise((resolve, reject) => {
- this.loadlayoutByID(element.groupType, element, resolve);
- })
- )
- }
- }
- Promise.all(promise_list).then(()=>{
- this.$nextTick(()=>{
- console.log("新布局替换完成",this.changeLayouts, changeSpaces,this.arrFrunList.map(it=>it.id));
- this.furnHandle(this.changeLayouts, changeSpaces);
- this.updataPageData();
- })
- })
- },
- async loadlayoutByID(groupType,spaceObj, resolve){
- let param = {
- "brandId": $config.brandId,
- "houseId": this.curHouseObj.houseId,
- "groupType": groupType
- }
-
-
- let res = await requestConfig("findOverallArrangementList", param);
- if (!res.success || !res.pageModel || res.pageModel.resultSet.length == 0) {
- return resolve();
- }
-
- const groupLayouts = res.pageModel.resultSet;
- console.log("查询指定分组的布局", groupType, groupLayouts, spaceObj.spaceWidth, spaceObj.spaceHeight)
-
-
- const layouts01 = groupLayouts.filter((item)=>{
- return item.minWidth <= spaceObj.spaceWidth && item.minDepth <= spaceObj.spaceHeight
- })
- console.log("过滤适合的布局01", layouts01)
-
- const layouts02 = layouts01.filter((item)=>{
- return (item.minWidth * item.minDepth ) <= (spaceObj.spaceWidth * spaceObj.spaceHeight)
- })
- console.log("过滤适合的布局02", layouts02)
-
- let layoutObj = null
- for (let index = 0; index < layouts02.length; index++) {
- const element = layouts02[index];
- if(!layoutObj){
- layoutObj = element;
- }else{
- if((layoutObj.minWidth * layoutObj.minDepth) < (element.minWidth * element.minDepth)){
- layoutObj = element;
- }
- }
- }
- if(layoutObj==null){
- console.warn("没有合适的布局", layoutObj,spaceObj.layoutId);
- spaceObj.groupType = groupType;
- this.deleteLayoutModel(spaceObj, layoutObj);
- return resolve()
- }
- console.log("找出最合适的布局", layoutObj)
- console.log("更新空间的布局ID=", spaceObj.layoutId,'=>',layoutObj.id)
-
-
-
-
-
-
-
-
-
- const element = this.spaceList.find(it=>it.spaceId == spaceObj.spaceId);
- if(element){
- this.deleteLayoutModel(element, layoutObj)
- element.layoutId = layoutObj.id
- console.log("替换空间的布局ID", spaceObj.spaceId, layoutObj.id);
- }
- this.changeLayouts.push(layoutObj)
- resolve()
- }
- }
- }
|