1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515 |
- <template src="./webgl_rxdz.html"></template>
- <script>
- import * as THREE from 'three';
- import Stats from 'three/addons/libs/stats.module.js';
- import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
- import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
- import TWEEN from 'three/addons/libs/tween.module.js';
- import router from "@/router";
- var requestId = "";
- const util = require('@/utils/util.js').default;
-
- import wallType from '@/static/wallData.js';
-
-
-
-
- import screenshot from '@/mixins/screenshot.js';
- import floorMethod from '@/mixins/floorMethod.js';
- import wallMethod from '@/mixins/wallMethod.js';
- import loadModel from '@/mixins/loadModel.js';
- import viewShell from'@/components/newBottomCom/viewShell/viewShell.vue';
- export default {
- name:"webgl_rxdz",
- components:{viewShell},
- mixins:[screenshot,floorMethod,wallMethod,loadModel],
-
- data() {
- return {
- pvCurPageName: "home_show",
- locusBehaviorName: "主界面",
- pvCurPageParams: null,
- houseId: "",
- pvId: 'p_2cmina_23080401',
- canvas:null,
- navbar: {
- showCapsule: 0,
- title: '',
- titleColor: '#000',
- navPadding: 0,
- navPaddingBg:'transparent',
- navBarColor: 'transparent',
- navBackColor: 'transparent',
- haveCallback: false,
- fromShare: false,
- fromProject: 0,
- shareToken: "",
- pageName: this.pvCurPageName,
- },
- id:'232',
- spaceList:[],
- spaceListBackup:[],
- gltfSpaces:[],
- curSpaceObj:null,
-
- curWallDirection:"",
- curWallValue:0,
- curWallMaxValue:300,
- curWallHidden:false,
- wallIds:[],
- wallList:[],
- gltfWalls:[],
- gltfAutoWalls:[],
-
- tempSpaceList:[],
- leftSpaces:[],
- rightSpaces:[],
- changeSpaces:[],
- loader:null,
- scene:null,
- sky:null,
- camera:null,
- houseList:[],
- curHouseType: null,
- curHouseName:'',
- curHouseFloor: null,
- curHouseObj: null,
- controlStarPosition : { x:0, y:0, z:0},
- cameraStarPosition : { x:0, y:20, z:0} ,
-
-
- canvasHeight:200,
- chooseMesh:null,
-
- chooseWallMeshColor:'',
- curWallArr:[],
- isManyou: false,
- pageShowIndex: 2,
- aleadyLoaderModel:[],
-
- shottingImg: [],
- progress:1,
- myLoadingStatus:false,
-
- repeatFlag:false,
- skyPlan: null,
- instancedMeshList: [],
- lableItem:[],
- showLables:false,
- loadOver:false,
- voiceMaskShow:false,
- minspace1: null,
- minspace2: null,
- minspace3: null,
- minspace4 : null,
- spaces1 : [],
- spaces2 : [],
- spaces3 : [],
- spaces4 : [],
-
- layoutIds:[],
- layoutLists:[],
- gltfLayouts:[],
- screenshotResolve:null,
- curLayoutStruct:null,
- overChange:false,
- isIos:false,
- currentChangeSpaceId:null,
- styleType:1,
- }
- },
- beforeDestroy() {
- cancelAnimationFrame(requestId, this.canvas)
- this.worker && this.worker.terminate()
-
- if (this.renderer instanceof THREE.WebGLRenderer) {
- this.renderer.dispose()
- this.renderer.forceContextLoss()
- this.renderer.context = null
- this.renderer.domElement = null
- this.renderer = null;
- this.clearEvent()
- }
- this.gltfWalls = [];
- this.gltfSpaces = [];
- this.instancedMeshList = [];
- this.instancedSpaceMeshList = [];
- this.lableItem = [];
- this.gltfLayouts = [];
- this.instancedFurList = [];
- this.wallList = [];
- TWEEN && TWEEN.removeAll();
-
- },
- mounted() {
- console.log("***onLoad-webgl_rxdz***", this.$route.query)
- var that = this;
- this.houseId = this.$store.state.houseId || '';
- this.childLayout = '4';
- let unit = window.screen.width / 750;
- that.canvasHeight = window.screen.height - (200 * unit) + (20 * unit);
-
- const container = this.$refs.webgl;
- const canvas3d = this.canvas = this.$refs.glcanvas;
-
- let camera = null, renderer = null, controls=null;
-
- console.warn("***loader0***",this.loader)
- let loader = null;
- loader = this.loader = new GLTFLoader();
- this.getInitData();
- let scene = this.scene = new THREE.Scene();
- let chooseMesh = this.chooseMesh;
- let isUserContorl = false;
- let tweenCameraAnma = false;
- let needRender = false;
- let frustumSize = 30;
- let stats;
- init();
-
-
-
- this.progress = 1;
- this.clearEvent = clearEvent;
- this.attendEvent = attendEvent;
- this.updateLables = updateLables;
- this.enableRenderHandle = enableRender;
- this.tweenCameraAnmaChange = tweenCameraAnmaChange;
- this.gradientResize = gradientResize;
- this.moveMeshCenterHandle = moveMeshCenterHandle;
- this.starRender = starRender;
- this.cameraInit = cameraInit;
- this.resetControl = resetControl;
- function init() {
- scene.background = new THREE.Color("#FFFFFF");
-
-
- camera = new THREE.PerspectiveCamera( 80, window.screen.width / that.canvasHeight, 0.1, 10000 );
-
-
- camera.up.set(0, 1, 0);
- scene.add(camera);
- that.camera = camera;
-
-
-
-
-
-
-
-
- const ambientLight = new THREE.AmbientLight(0xFFEFE0, 3);
- scene.add(ambientLight);
-
- const light = new THREE.DirectionalLight(0xFFF8E5, 3);
- light.position.set(-3, 9, 3);
- light.castShadow = true;
-
- light.shadow.camera.left = -100;
- light.shadow.camera.right = 100;
- light.shadow.camera.top = 100;
- light.shadow.camera.bottom = -100;
-
- light.shadow.mapSize.width = 8192;
- light.shadow.mapSize.height = 8192;
-
-
-
-
-
-
- scene.add(light);
-
-
-
-
-
-
-
-
- renderer = that.renderer = new THREE.WebGLRenderer({
- canvas:canvas3d,
- alpha: true,
- antialias:false,
-
- preserveDrawingBuffer: true,
- });
- renderer.shadowMap.enabled = true;
- renderer.shadowMap.type = THREE.PCFSoftShadowMap;
- renderer.outputEncoding = THREE.sRGBEncoding;
- renderer.outputColorSpace = THREE.SRGBColorSpace;
-
- renderer.toneMapping = THREE.NoToneMapping;
- renderer.physicallyCorrectLights = true;
-
- renderer.setPixelRatio( window.devicePixelRatio );
- renderer.setSize( window.screen.width, that.canvasHeight );
- container.appendChild( renderer.domElement );
-
- controls = new OrbitControls(camera, renderer.domElement);
- controls.screenSpacePanning = true;
- controls.enableDamping = true;
- controls.minDistance = 1;
- controls.maxDistance = 400;
- controls.minPolarAngle = 0;
- controls.maxPolarAngle = Math.PI / 2;
- controls.target.set(that.controlStarPosition.x, that.controlStarPosition.y, that.controlStarPosition.z);
- controls.enableZoom = true;
-
-
- controls.addEventListener('change', () => {
-
- if (camera.position.y < 0) {
- camera.position.y = 0;
- }
- });
-
-
-
-
- attendEvent();
- starRender();
- cameraInit();
- controls.saveState();
- }
-
- function cameraInit(){
- camera.position.set(that.cameraStarPosition.x, that.cameraStarPosition.y, that.cameraStarPosition.z);
- camera.lookAt(that.controlStarPosition.x,that.controlStarPosition.y,that.controlStarPosition.z);
- }
-
- function resetControl(){
- controls.reset();
- }
- function onWindowResize() {
- camera.aspect = window.screen.width / that.canvasHeight;
- camera.updateProjectionMatrix();
- renderer.setSize( window.screen.width, that.canvasHeight );
- console.warn("****onWindowResize**")
- }
- function attendEvent () {
- window.addEventListener('resize', onWindowResize);
- renderer.domElement.addEventListener('touchstart', onPointerStart, false);
- renderer.domElement.addEventListener('touchmove', onPointerMove, false);
- renderer.domElement.addEventListener('touchend', onPointerUp, false);
- }
- function tweenCameraAnmaChange (value) {
- tweenCameraAnma = value
- }
-
- function enableRender() {
- }
-
- function clearEvent(){
- console.warn("**clearEvent****")
- renderer && renderer.domElement && renderer.domElement.removeEventListener('touchstart', onPointerStart);
- renderer && renderer.domElement && renderer.domElement.removeEventListener('touchmove', onPointerMove );
- renderer && renderer.domElement && renderer.domElement.removeEventListener('touchend', onPointerUp );
- }
-
- function onPointerStart(event){
- console.log('开始触摸事件:',that.overChange)
- if(that.overChange){
- return false;
- }
- }
-
- function onPointerMove( event ) {
- if(that.overChange){
- return false;
- }
-
- }
-
- function onPointerUp(event) {
- if(that.overChange){
- return false;
- }
-
- if(event.touches.length==0){
-
-
- }
- }
-
- function moveMeshCenterHandle(mesh = null,noChangeColor = true){
- if(mesh){
- let spaceId = mesh.spaceId;
- if(chooseMesh && spaceId == chooseMesh.spaceId){
- console.warn("**moveMeshCenterHandle-重复选中了***")
- return false;
- }
- chooseMesh = mesh;
- }
- if(!chooseMesh){
- console.warn("**moveMeshCenterHandle-没有数据***")
- return false;
- }
- that.showLables = false;
-
- let spaceObj = chooseMesh;
-
- let cameraNewPosition ={};
- let targetNewPosition ={};
- let oldUp = {};
- let newUp = {};
- if (isUserContorl === false) {
- cameraNewPosition = {
- x:spaceObj.centerX/100,
- y:camera.position.y,
- z:-spaceObj.centerY/100,
- }
-
- targetNewPosition = {
- x:spaceObj.centerX/100,
- y:0,
- z:-spaceObj.centerY/100,
- }
- oldUp = camera.up;
- newUp = camera.up
-
-
- }
- console.warn("**moveMeshCenter***",isUserContorl,spaceObj,JSON.stringify(camera.position),JSON.stringify(controls.target)
- ,cameraNewPosition,targetNewPosition,JSON.stringify(camera.up))
- tweenCamera(camera.position,controls.target,cameraNewPosition,targetNewPosition,oldUp,newUp,1000);
- setTimeout(()=>{
- that.showLables = true;
-
- },1001);
- }
-
-
-
-
-
- function tweenCamera(oldP, oldT, newP, newT, oldUp, newUp, time=1000) {
- if(JSON.stringify(oldP) == JSON.stringify(newP) && JSON.stringify(oldT) == JSON.stringify(newT)){
- return false;
- }
- if (!chooseMesh) {
- return false;
- }
- tweenCameraAnma = true;
- var tween = new TWEEN.Tween({
- x1: oldP.x,
- y1: oldP.y,
- z1: oldP.z,
- x2: oldT.x,
- y2: oldT.y,
- z2: oldT.z,
- x3: oldUp.x,
- y3: oldUp.y,
- z3: oldUp.z
- })
- .to({
- x1: newP.x,
- y1: newP.y,
- z1: newP.z,
- x2: newT.x,
- y2: newT.y,
- z2: newT.z,
- x3: newUp.x,
- y3: newUp.y,
- z3: newUp.z
- }, time)
- .easing(TWEEN.Easing.Quadratic.InOut)
- .onUpdate((object)=> {
- camera.position.x = object.x1;
- camera.position.y = object.y1;
- camera.position.z = object.z1;
- let newTarget = new THREE.Vector3(object.x3,object.y3,object.z3);
- camera.up.copy(newTarget);
- camera.lookAt(object.x2,object.y2,object.z2);
-
-
-
-
-
- }).onComplete(()=>{
- controls.target.x = newT.x;
- controls.target.y = newT.y;
- controls.target.z = newT.z;
-
- let up = new THREE.Vector3(newUp.x,newUp.y,newUp.z);
- camera.up.copy(up);
- camera.lookAt(controls.target.x,controls.target.y,controls.target.z);
- tweenCameraAnma = false;
- })
-
- tween.start();
- }
-
- function gradientResize (time,startHeight,endHeight) {
- let _timeStep = 20;
-
-
-
- let unit = window.screen.width / 750;
- let _height = startHeight - endHeight;
- let _jisua = that.canvasHeight;
- let lastHeight = _jisua + (_height * unit);
- that.canvasHeight = lastHeight;
- let step = (_height * unit) / (time*1000 / _timeStep);
- console.warn("***gradientResize***",step,lastHeight,_jisua,startHeight,endHeight)
-
-
- var tween = new TWEEN.Tween({
- h1: _jisua,
- })
- .to({
- h1: lastHeight,
- }, 1000)
- .easing(TWEEN.Easing.Linear.None)
- .onUpdate((object)=> {
- if(camera.isOrthographicCamera){
- let aspect = window.screen.width / object.h1;
- camera.left = frustumSize * aspect / - 2;
- camera.right = frustumSize * aspect / 2;
- camera.top = frustumSize / 2;
- camera.bottom = frustumSize / -2;
- camera.updateProjectionMatrix();
-
- }
- else if(camera.isPerspectiveCamera){
- camera.aspect = window.screen.width / object.h1;
- camera.updateProjectionMatrix();
- renderer.setSize( window.screen.width, object.h1 );
-
- }
- }).onComplete(()=>{
- camera.aspect = window.screen.width / that.canvasHeight;
- camera.updateProjectionMatrix();
- renderer.setSize( window.screen.width, that.canvasHeight );
- tweenCameraAnma = false;
-
-
- });
-
- tween.start();
- tweenCameraAnma = true;
- }
-
- function updateLables(){
- if(!that.showLables){
- return false;
- }
- that.lableItem.forEach(lable =>{
- if(!that.gltfSpaces[lable.cubeIndex] || !that.gltfSpaces[lable.cubeIndex].instancedMeshIndexList){
- return false;
- }
- let item = that.gltfSpaces[lable.cubeIndex].instancedMeshIndexList[0];
- let _index = item.instancedMeshIndex;
- let instancedMesh = that.instancedSpaceMeshList[_index];
- let stratMatrix = new THREE.Matrix4();
- instancedMesh.getMatrixAt(item.instancedAtIndex,stratMatrix);
- let position = new THREE.Vector3();
- position.setFromMatrixPosition(stratMatrix);
-
- position.project(camera);
- const x = (position.x * .5 + .5) * window.screen.width;
- const y = (position.y * -.5 + .5) * that.canvasHeight;
- lable.transform = `translate(-50%, -50%) translate(${x}px,${y}px)`;
- })
- }
- function stopRender () {
- needRender = false;
- }
- function starRender () {
- if(needRender==true){
- false;
- }
- needRender = true;
- render();
- }
- function render() {
- if(needRender==false){
- return false;
- }
- TWEEN && TWEEN.update();
-
-
- if(tweenCameraAnma==false){
- controls.update();
- updateLables();
- }
- requestId = requestAnimationFrame(render, canvas3d);
- renderer.render(scene, camera);
- if (that.screenshotResolve) {
-
- stopRender();
- that.screenshotResolve()
- that.screenshotResolve = null;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- }
-
- },
- onShow(){
- if(this.attendEvent){
- this.attendEvent()
- }
- },
- onHide(){
- this.clearEvent();
- },
- computed: {
- aiData() {
- return this.$store.state.aiData;
- },
- userId() {
- return this.$store.state.userId;
- },
- },
- methods: {
- voiceMaskChange(voiceMask){
- this.voiceMaskShow = voiceMask;
- },
-
- hushangHandle(param){
- let expand = {};
- expand.landImg = this.$route.query.landImg || '';
- expand.baseImg = this.$route.query.baseImg || '';
- expand.bgPrototypeImg = this.$route.query.bgPrototypeImg || '';
- expand.landNo = this.$route.query.landNo || '';
- expand.landArea = this.$route.query.landArea || '';
- expand.buildingAreaPreference = this.$route.query.buildingAreaPreference || '';
- expand.layer = this.$route.query.layer || '大平层';
- expand.structureName = this.$route.query.structureName || '';
- expand.landDescription = this.$route.query.landDescription || '';
- expand.scenery = this.$route.query.scenery || '';
- expand.structureDescription = this.$route.query.structureDescription || '';
- param.expand = JSON.stringify(expand);
- return param;
- },
- async submitHouse(){
- if(this.overChange){
- this.$message.warning("空间正在调整");
- return false
- }
-
- let shottingImg = await this.shottingAction() + "?x-oss-process=image/auto-orient,1/quality,Q_46/format,jpg";
- console.warn("***shottingImg***",shottingImg);
- let userId = this.userId ? this.userId : '';
- let param = {
- "brandId": $config.brandId,
- "houseId": this.curHouseObj.houseId,
- "userId": userId,
- "floot": this.curHouseObj.houseFloor,
- "spaceName": this.curHouseName ,
- "spaceStructure": this.curHouseType,
- "curFloor":this.curHouseFloor,
-
-
- layoutStruct:[],
- }
-
- this.curLayoutStruct.forEach((layoutStruct,index)=>{
- let houseData = {
- "layoutId": layoutStruct.id,
- "layoutName": layoutStruct.name,
- "layoutArea": layoutStruct.houseArea,
- "floor": layoutStruct.houseFloor,
- "layoutImgCustomized": layoutStruct.houseFloor == this.curHouseFloor ? shottingImg:'',
- "style": "",
- "houseJson": []
- }
- let spaceList = JSON.parse(layoutStruct.houseJson);
- let styleList = [];
-
- spaceList.forEach((item)=>{
- let space = JSON.parse(JSON.stringify(item));
-
- let AISpace = null;
- AISpace = this.aiData && this.aiData.find(it=>{
- return it.houseFloor == layoutStruct.houseFloor && it.spaceId == space.spaceId
- });
- if(AISpace){
- let list = AISpace.aiImagesList.filter(it=>it.checked==true);
- list.forEach(it=>{
- styleList.push(it.aiStyleName);
- })
- list = list.map(it=>{
- return it.image
- })
- space.hardboundEffect = list;
- console.warn("submitHouse: ", list,space);
- }
- let wallList = this.wallList.find(it=>it.id==space.wallId);
- if(wallList){
- space.wallList = JSON.stringify(wallList);
- }
- houseData.houseJson.push(space)
- })
-
- if(styleList && styleList.length>0){
- let maxEle = styleList[0];
- let maxNum = 1;
- styleList.reduce((p,k)=>{
- p[k] ? p[k]++ : p[k]=1;
- if(p[k] > maxNum){
- maxEle = k;
- maxNum ++
- }
- return p;
- },{});
- houseData.style = maxEle;
- }
- param.layoutStruct.push(houseData)
- })
- param = this.hushangHandle(param)
- console.warn("submitHouse-param: ", param);
- let trackparam = {
- type: 'CLK',
- clkId: 'clk_2cmina_23080409',
- clkName: 'submit_clk',
- clkParams: {
- locusName: "数据提交",
- postAIData:this.aiData,
- }
- };
- util.trackRequest(trackparam);
- let res = await requestConfig("saveCustomizedRecord", param);
- if(res && res.success && res.single){
- let data = {
- houseId:this.houseId,
- id:res.single,
- }
- router.push({
- name: "webgl_rxdz_customize",
- query:data
- });
- }
- },
- enableRender(){
- this.enableRenderHandle();
- },
-
- selectWall(wallIndex){
- console.log("index",wallIndex)
-
- if(this.chooseWallMeshColor){
- for (let index = 0; index < this.curWallArr.length; index++) {
- const element = this.curWallArr[index];
- const cube = element.obj;
- this.chooseWallMeshColor.convertSRGBToLinear();
- if(cube && cube.children[0].children[0] && cube.children[0].children[0].material){
- cube.children[0].children[0].material.color = this.chooseWallMeshColor;
- }else{
-
-
-
-
-
-
- }
- }
- }
-
- switch (wallIndex) {
- case 1:
- this.curWallDirection = "N";
- break;
- case 2:
- this.curWallDirection = "S";
- break;
- case 3:
- this.curWallDirection = "W";
- break;
- case 4:
- this.curWallDirection = "E";
- break;
- }
- this.selectedWall(this.curWallDirection)
-
- this.curWallArr = [];
- if(wallIndex!=0){
- const wallMoveValues = this.curSpaceObj.wallMoveValue;
- console.log
- const values = JSON.parse(wallMoveValues);
- if(this.curWallValue == 150){
- this.curWallValue = values[wallIndex-1]
- }else{
- let wallIndex = 0
- switch (this.curWallDirection) {
- case "N":
- wallIndex = 0;
- values[wallIndex] = this.curWallValue;
- values[1] = this.curWallValue;
- break;
- case "S":
- wallIndex = 1;
- values[wallIndex] = this.curWallValue;
- values[0] = this.curWallValue;
- break;
- case "W":
- wallIndex = 2;
- values[wallIndex] = this.curWallValue;
- values[3] = this.curWallValue;
- break;
- case "E":
- wallIndex = 3;
- values[wallIndex] = this.curWallValue;
- values[2] = this.curWallValue;
- break;
- }
- }
- this.curSpaceObj.wallMoveValue = JSON.stringify(values)
- console.log("墙体可移动数据:", this.curSpaceObj.wallMoveValue, this.spaceList);
-
- const wallStatus = this.curSpaceObj.wallStatus || "[false,false,false,false]"
- const status = JSON.parse(wallStatus);
- this.curWallHidden = status[wallIndex-1]
- console.log("当前墙面数据:", wallStatus , status, wallIndex);
-
- const curSpaceGltfWall = this.gltfWalls.filter((item)=>{
- return this.curSpaceObj.spaceId == item.spaceId && item.wallDirection == this.curWallDirection
- })
- if(curSpaceGltfWall.length != 0){
- this.curWallArr.push(...curSpaceGltfWall);
- }else{
- let rightWallD = "";
- switch (wallIndex-1) {
- case 0:
- rightWallD= "S";
- break;
- case 1:
- rightWallD= "N";
- break;
- case 2:
- rightWallD= "E";
- break;
- case 3:
- rightWallD= "W";
- break;
- }
- for (let index = 0; index < this.leftSpaces.length; index++) {
- const element = this.leftSpaces[index];
- const gltfWall = this.gltfWalls.filter((item)=>{
- return element.spaceId == item.spaceId && item.wallDirection == this.curWallDirection
- })
- if(gltfWall){
- this.curWallArr.push(...gltfWall);
- }
- }
-
- for (let index = 0; index < this.rightSpaces.length; index++) {
- const element = this.rightSpaces[index];
- const gltfWall = this.gltfWalls.filter((item)=>{
- return element.spaceId == item.spaceId && item.wallDirection == rightWallD;
- })
- if(gltfWall){
- this.curWallArr.push(...gltfWall);
- }
- }
- }
- for (let index = 0; index < this.curWallArr.length; index++) {
- const element = this.curWallArr[index];
- const cube = element.obj;
- if(cube && cube.children[0].children[0] && cube.children[0].children[0].material){
- this.chooseWallMeshColor = cube.children[0].children[0].material.color.clone();
- let color = new THREE.Color(0xff0000);
- color.convertSRGBToLinear();
- cube.children[0].children[0].material.color = color;
- }else{
-
-
-
-
-
-
-
-
-
-
-
- }
-
- }
-
- }
- },
-
-
-
-
-
-
- curSpaceChange(data){
- console.warn("***空间面积变化***",this.overChange,data)
- this.overChange = true;
- this.currentChangeSpaceId = data.spaceId
- this.changCurSpaceArea(data);
- let space = this.spaceList.find(it=>it.spaceId==this.currentChangeSpaceId);
- this.moveMeshCenter(space);
- },
-
-
- changCurSpaceArea(data){
- console.log("当前户型的核心点", this.curHouseObj.houseCore, this.overChange);
- const houseCore = this.curHouseObj.houseCore.split(',');
- const coreX = houseCore[0] | 0
- const coreY = houseCore[1] | 0
-
- this.spaces1 = [];
- this.spaces2 = [];
- this.spaces3 = [];
- this.spaces4 = [];
- let curSpace = null;
- for (let index = 0; index < this.spaceList.length; index++) {
- const element = this.spaceList[index];
- if(element.centerX > coreX){
- if(element.centerY > coreY){
- console.log(`象限2 ${element}`);
- element.quadrant = 2;
- this.spaces2.push(element)
- }else{
- console.log(`象限3 ${element}`);
- element.quadrant = 3;
- this.spaces3.push(element)
- }
- }else{
- if(element.centerY > coreY){
- console.log(`象限1 ${element}`);
- element.quadrant = 1;
- this.spaces1.push(element)
- }else{
- console.log(`象限4 ${element}`);
- element.quadrant = 4;
- this.spaces4.push(element)
- }
- }
- if(element.spaceId == data.spaceId){
- curSpace = element;
- }
- }
-
- console.log("当前space所在象限",data.spaceId, curSpace.spaceId , curSpace.quadrant);
- console.log("象限", this.spaces1, this.spaces2, this.spaces3, this.spaces4);
-
-
- this.calculateSpaceData(curSpace, data)
- },
- calculateSpaceData(curSpace, data){
- let that = this;
- this.curSpaceObj = curSpace;
-
-
- const changeArea = data.area;
- const isZoomIn = data.isZoomIn;
- const oldArea = (curSpace.spaceWidth / 100) * (curSpace.spaceHeight / 100);
- const newArea = oldArea + changeArea * (data.isZoomIn ? 1 : -1);
- const sizeScale = Math.sqrt(newArea/oldArea) ;
-
-
- let newWidth = curSpace.spaceWidth * sizeScale;
- if(newWidth < curSpace.spaceWidthMin){
- newWidth = curSpace.spaceWidthMin
- }
- if(newWidth > curSpace.spaceWidthMax){
- newWidth = curSpace.spaceWidthMax
- }
-
- let newHeight = newArea * 10000 / newWidth;
- if(newHeight < curSpace.spaceHeightMin){
- newHeight = curSpace.spaceHeightMin
- }
- if(newHeight > curSpace.spaceHeightMax){
- newHeight = curSpace.spaceHeightMax
- }
- let changeWidth = Math.abs(newWidth - curSpace.spaceWidth)
- let changeHeight = Math.abs(newHeight - curSpace.spaceHeight)
-
- console.log("变化的尺寸", changeWidth, changeHeight, data, curSpace.spaceWidth, curSpace.spaceHeight);
-
- if(curSpace.quadrant == 1){
-
- this.moveSpace(curSpace, 1, 3, isZoomIn, newArea, newWidth, newHeight, changeWidth, changeHeight)
- }
- if(curSpace.quadrant == 2){
-
- this.moveSpace(curSpace, 1, 4, isZoomIn, newArea, newWidth, newHeight, changeWidth, changeHeight)
- }
- if(curSpace.quadrant == 3){
-
-
-
-
- this.moveSpace(curSpace, 2, 4, isZoomIn, newArea, newWidth, newHeight, changeWidth, changeHeight)
- }
- if(curSpace.quadrant == 4){
-
- this.moveSpace(curSpace, 2, 3, isZoomIn, newArea, newWidth, newHeight, changeWidth, changeHeight)
- }
- setTimeout(() => {
-
- that.overChange = false;
- that.callBackFun && that.callBackFun(true);
-
- that.updateWallModels();
- that.changeLayoutModel();
-
- }, 4200);
- },
- moveSpace(curSpace, directionIndex, directionIndex01, isZoomIn, newArea, newWidth, newHeight, changeWidth, changeHeight){
- let that = this;
-
- const wallLock = this.currWallLock(directionIndex, curSpace);
- const wallLock01 = this.currWallLock(directionIndex01, curSpace);
-
- console.log("移动空间", wallLock, wallLock01)
-
- if(wallLock ==-1 && wallLock01 == -1){
- return this.$message.warning("空间尺寸已锁定");
- }
- let changeValue = changeHeight;
- if(wallLock == -1){
-
- if(wallLock01 == 0){
- directionIndex01 = directionIndex01 == 4 ? 3 : 4;
- }
-
-
- newWidth = newArea / (curSpace.spaceHeight / 100) * 100
- changeWidth = newWidth / 100 - curSpace.spaceWidth / 100;
- changeWidth = Math.abs(changeWidth * 100);
- directionIndex = directionIndex01;
-
- changeValue = changeWidth;
-
- console.log("高度锁死不能拉伸, 宽度变化1",newWidth, directionIndex,curSpace.spaceWidth, curSpace.spaceHeight, changeValue);
- that.selectWall(directionIndex);
- that.moveSpaceWall(that.curWallDirection, isZoomIn, changeValue);
-
- return;
- }else{
- if(wallLock == 0){
- directionIndex = directionIndex == 2 ? 1 : 2;
- }
-
- if(wallLock01 == -1){
-
- newHeight = newArea / (curSpace.spaceWidth / 100) * 100
- changeHeight = newHeight / 100 - curSpace.spaceHeight / 100;
- changeHeight = Math.abs(changeHeight * 100);
- changeValue = changeHeight;
-
- that.selectWall(directionIndex);
- that.moveSpaceWall(that.curWallDirection, isZoomIn, changeValue);
-
-
- return
- }
-
- if(wallLock01 == 0){
- directionIndex01 = directionIndex01 == 4 ? 3 : 4;
- }
-
- console.log("要变化的宽度", newWidth, newHeight)
-
- if(newHeight > curSpace.spaceHeightMax){
- newHeight = curSpace.spaceHeightMax;
- changeHeight = Math.abs(newHeight - curSpace.spaceHeight)
-
- newWidth = (newArea / (newHeight / 100)) * 100
- changeWidth = (newWidth / 100 - curSpace.spaceWidth / 100) * 100;
- console.log("高度达到最大值,重新计算宽度",newWidth, newHeight, changeWidth, changeHeight)
- }
-
- if(newHeight < curSpace.spaceHeightMin){
- newHeight = curSpace.spaceHeightMin;
- changeHeight = Math.abs(newHeight - curSpace.spaceHeight)
-
- newWidth = (newArea / (newHeight / 100)) * 100
- changeWidth = Math.abs((newWidth / 100 - curSpace.spaceWidth / 100) * 100);
- console.log("高度达到最小值,重新计算宽度",newWidth, newHeight, changeWidth, changeHeight)
- }
-
- if(newWidth > curSpace.spaceWidthMax){
- newWidth = curSpace.spaceWidthMax;
- changeWidth = Math.abs(newWidth - curSpace.spaceWidth)
-
- newHeight = (newArea / (newWidth / 100)) * 100
- changeHeight = (newHeight / 100 - curSpace.spaceHeight / 100) * 100;
- console.log("宽度达到最大值,重新计算高度",newWidth, newHeight, changeWidth, changeHeight)
- }
-
- if(newWidth < curSpace.spaceWidthMin){
- newWidth = curSpace.spaceWidthMin;
- changeWidth = Math.abs(newWidth - curSpace.spaceWidth)
-
- newHeight = (newArea / (newWidth / 100)) * 100
- changeHeight = Math.abs((newHeight / 100 - curSpace.spaceHeight / 100) * 100);
- console.log("宽度达到最小值,重新计算高度",newWidth, newHeight, changeWidth, changeHeight)
- }
-
-
-
-
-
-
-
-
-
- if(changeHeight > 0){
-
- that.changeSpaces = [];
-
- that.selectWall(directionIndex);
-
-
- that.moveSpaceWall(that.curWallDirection, isZoomIn, changeHeight);
-
-
- }
-
- let timeout = 0
- if(changeWidth > 0 && changeHeight > 0 ){
- timeout = 2100
- }
-
- console.log("改变尺寸",changeWidth, changeHeight,newWidth, newHeight, timeout, directionIndex, directionIndex01, wallLock, wallLock01)
-
- if(changeWidth > 0){
- setTimeout(() => {
-
- that.changeSpaces = [];
-
- that.selectWall(directionIndex01);
-
-
-
- that.moveSpaceWall(that.curWallDirection, isZoomIn, changeWidth);
-
-
- }, timeout);
- }
- }
- },
- currWallLock(direction, curSpace){
-
- let curDirection = ""
- let faceDirection = ""
- switch (direction) {
- case 1:
- curDirection = "N";
- faceDirection = "S";
- break;
- case 2:
- curDirection = "S";
- faceDirection = "N";
- break;
- case 3:
- curDirection = "W";
- faceDirection = "E";
- break;
- case 4:
- curDirection = "E";
- faceDirection = "W";
- break;
- }
- const wallInfo = this.wallList.find((item)=>{
- let element = JSON.parse(item.wallJson);
- return element.spaceId == curSpace.spaceId;
- })
- let walls = JSON.parse(wallInfo.wallJson).wallData;
-
- const wall = walls.find((item)=>{
- return item.wallDirection==curDirection && item.isLocked=="true"
- })
- const faceWall = walls.find((item)=>{
- return item.wallDirection==faceDirection && item.isLocked=="true"
- })
-
- if(wall){
- if(faceWall){
- return -1
- }
- return 0
- }else{
- return 1
- }
-
- },
- checkRightSpace(isZoomIn, changeValue, isNS){
- let n = isZoomIn?1:-1;
- let l = isZoomIn?-1:1;
- let result = true;
- let space = null;
-
-
- for (let index = 0; index < this.leftSpaces.length; index++) {
- const element = this.leftSpaces[index];
- let newWidth = element.spaceWidth + l * changeValue;
- let newHeight = element.spaceHeight + l * changeValue;
- console.log("关联左空间排查", isZoomIn, changeValue, isNS, newWidth, newHeight)
- if(isNS){
- if( newHeight > element.spaceHeightMax || newHeight < element.spaceHeightMin){
- result = false;
- space = element;
- break;
- }
- }else{
- if(newWidth > element.spaceWidthMax || newWidth < element.spaceWidthMin){
- result = false;
- space = element;
- break;
- }
- }
- }
-
- for (let index = 0; index < this.rightSpaces.length; index++) {
- const element = this.rightSpaces[index];
- let newWidth = element.spaceWidth + n * changeValue;
- let newHeight = element.spaceHeight + n * changeValue;
- console.log("关联右空间排查", isZoomIn, changeValue, isNS, newWidth, newHeight)
- if(isNS){
- if( newHeight > element.spaceHeightMax || newHeight < element.spaceHeightMin){
- result = false;
- space = element;
- break;
- }
- }else{
- if(newWidth > element.spaceWidthMax || newWidth < element.spaceWidthMin){
- result = false;
- space = element;
- break;
- }
- }
- }
- console.log("空间排查", this.leftSpaces, this.rightSpaces, result, space)
- if(!result){
- this.$message.warning(`关联空间[${ space && space.spaceName || ''}]达到极限值`);
- }
- return result
- },
- checkSpaceSize(isZoomIn, changeWidth, changeHeight){
- console.log("检查尺寸", isZoomIn, changeWidth, changeHeight, this.leftSpaces, this.rightSpaces)
-
- for (let index = 0; index < this.leftSpaces.length; index++) {
- const element = this.leftSpaces[index];
- if(isZoomIn){
- if(element.spaceWidth + changeWidth > element.spaceWidthMax || element.spaceHeight + changeHeight > element.spaceHeightMax){
- console.log("++++++++++移动空间达到极大值1", element.spaceId, element.spaceWidth + changeWidth > element.spaceWidthMax, element.spaceHeight + changeHeight > element.spaceHeightMax)
- console.log("++++++++++移动空间达到极大值宽", element.spaceWidth, changeWidth, element.spaceWidthMax)
- console.log("++++++++++移动空间达到极大值高", element.spaceHeight, changeHeight, element.spaceHeightMax)
- return false;
- }
- }else{
- if(element.spaceWidth - changeWidth < element.spaceWidthMin || element.spaceHeight - changeHeight < element.spaceHeightMin){
- console.log("++++++++++移动空间达到极小值2", element.spaceId)
- console.log("++++++++++移动空间达到极大值宽", element.spaceWidth, changeWidth, element.spaceWidthMin)
- console.log("++++++++++移动空间达到极大值高", element.spaceHeight, changeHeight, element.spaceHeightMin)
- return false;
- }
- }
- }
- for (let index = 0; index < this.rightSpaces.length; index++) {
- const element = this.rightSpaces[index];
- if(!isZoomIn){
- if(element.spaceWidth - changeWidth < element.spaceWidthMin || element.spaceHeight - changeHeight < element.spaceHeightMin){
- console.log("++++++++++其他空间达到极小值4", element.spaceId)
- console.log("++++++++++移动空间达到极大值宽", element.spaceWidth, changeWidth, element.spaceWidthMin)
- console.log("++++++++++移动空间达到极大值高", element.spaceHeight, changeHeight, element.spaceHeightMin)
- return false;
- }
- }else{
- if(element.spaceWidth + changeWidth > element.spaceWidthMax || element.spaceHeight + changeHeight > element.spaceHeightMax){
- console.log("++++++++++其他空间达到极大值3", element.spaceId)
- console.log("++++++++++移动空间达到极大值宽", element.spaceWidth, changeWidth, element.spaceWidthMax)
- console.log("++++++++++移动空间达到极大值高", element.spaceHeight, changeHeight, element.spaceHeightMax)
- return false;
- }
- }
- }
-
- return true
- },
-
- changeCurSpaceSize(curSpace, changeArea, isZoomIn){
-
-
-
- const oldArea = (curSpace.spaceWidth / 100) * (curSpace.spaceHeight / 100);
- const newArea = oldArea + changeArea * isZoomIn;
-
- const sizeScale = Math.sqrt(newArea/oldArea) ;
-
- console.log(`新面积:${newArea} 老面积:${oldArea}缩放比例:${sizeScale} 改变的面积:${changeArea} 是否放大:${isZoomIn} 中心点:${curSpace.centerX} ${curSpace.centerX}`);
- console.log(`改变前:尺寸:${curSpace.spaceWidth} ${curSpace.spaceHeight} 中心点:${curSpace.centerX} ${curSpace.centerY}`);
-
- curSpace.toScaleX = curSpace.spaceWidth * sizeScale / 300 ;
- curSpace.toScaleZ = curSpace.spaceHeight * sizeScale / 300 ;
-
-
- if(this.minspace1 && this.minspace1.spaceId == curSpace.spaceId){
- curSpace.toPx = (curSpace.spaceWidth * sizeScale - curSpace.spaceWidth) / 2 / 100 * -1;
- curSpace.toPz = (curSpace.spaceHeight * sizeScale - curSpace.spaceHeight) / 2 / 100 * -1;
- console.log("XXXXXXXX-计算空间变化信息1", curSpace.toScaleX, curSpace.toScaleZ, curSpace.toPx, curSpace.toPz);
- }else if(this.minspace2 && this.minspace2.spaceId == curSpace.spaceId){
- curSpace.toPx = (curSpace.spaceWidth * sizeScale - curSpace.spaceWidth) / 2 / 100;
- curSpace.toPz = (curSpace.spaceHeight * sizeScale - curSpace.spaceHeight) / 2 / 100 * -1;
- console.log("XXXXXXXX-计算空间变化信息2", curSpace.toScaleX, curSpace.toScaleZ, curSpace.toPx, curSpace.toPz);
- }else if(this.minspace3 && this.minspace3.spaceId == curSpace.spaceId){
- curSpace.toPx = (curSpace.spaceWidth * sizeScale - curSpace.spaceWidth) / 2 / 100;
- curSpace.toPz = (curSpace.spaceHeight * sizeScale - curSpace.spaceHeight) / 2 / 100;
- console.log("XXXXXXXX-计算空间变化信息3", curSpace.toScaleX, curSpace.toScaleZ, curSpace.toPx, curSpace.toPz);
- }else if(this.minspace4 && this.minspace4.spaceId == curSpace.spaceId){
- curSpace.toPx = (curSpace.spaceWidth * sizeScale - curSpace.spaceWidth) / 2 / 100 * -1;
- curSpace.toPz = (curSpace.spaceHeight * sizeScale - curSpace.spaceHeight) / 2 / 100;
- console.log("XXXXXXXX-计算空间变化信息4", curSpace.toScaleX, curSpace.toScaleZ, curSpace.toPx, curSpace.toPz);
- }else{
- return
- }
-
-
-
-
- curSpace.spaceWidth = curSpace.spaceWidth * sizeScale;
- curSpace.spaceHeight = curSpace.spaceHeight * sizeScale;
- curSpace.centerX = curSpace.centerX + curSpace.toPx * 100
- curSpace.centerY = curSpace.centerY + curSpace.toPz * 100
- const spaceIndex = this.spaceList.findIndex((item)=>{
- return item.spaceId == curSpace.spaceId;
- })
- if(spaceIndex!=-1){
- this.spaceList[spaceIndex] = curSpace;
- }
- console.log(`改变后:尺寸:${curSpace.spaceWidth} ${curSpace.spaceHeight} 中心点:${curSpace.centerX} ${curSpace.centerY} `, curSpace.toPx, curSpace.toPz);
-
-
- },
-
- findxxSpace(manSpace,changeArea, xiangxian, isZoomIn){
- if(xiangxian == 1){
- const spaceE = this.spaces1.find((item)=>{
- return item.spaceId == manSpace.eastId;
- })
- const spaceS = this.spaces1.find((item)=>{
- return item.spaceId == manSpace.southId;
- })
-
- const oldArea = (manSpace.spaceWidth / 100) * (manSpace.spaceHeight / 100);
- const newArea = oldArea + changeArea * isZoomIn;
-
- const sizeScale = Math.sqrt(newArea/oldArea) ;
-
- manSpace.toScaleX = manSpace.spaceWidth * sizeScale / 300 ;
- manSpace.toScaleZ = manSpace.spaceHeight * sizeScale / 300 ;
-
- if(spaceE){
- manSpace.toPx = (manSpace.spaceWidth * sizeScale - manSpace.spaceWidth) / 2 / 100 * -1 + spaceE.toPx * 2;
- console.log("XXXXXXXX东边有空间", manSpace.spaceId, spaceE.toPx)
- }else{
- manSpace.toPx = (manSpace.spaceWidth * sizeScale - manSpace.spaceWidth) / 2 / 100 * -1;
- console.log("XXXXXXXX东边没空间", manSpace.spaceId)
- }
-
- if(spaceS){
- manSpace.toPz = (manSpace.spaceHeight * sizeScale - manSpace.spaceHeight) / 2 / 100 * -1 + spaceS.toPz * 2;
- console.log("XXXXXXXX南边有空间", manSpace.spaceId, spaceS.toPz)
- }else{
- manSpace.toPz = (manSpace.spaceHeight * sizeScale - manSpace.spaceHeight) / 2 / 100 * -1;
- console.log("XXXXXXXX南边没空间", manSpace.spaceId)
- }
-
-
- console.log("XXXXXXXX-前象限1的其他空间", manSpace.spaceId, manSpace.spaceWidth, manSpace.spaceHeight, manSpace.centerX, manSpace.centerY, manSpace.toPx);
-
- manSpace.spaceWidth = manSpace.spaceWidth * sizeScale;
- manSpace.spaceHeight = manSpace.spaceHeight * sizeScale;
- manSpace.centerX += manSpace.toPx * 100
- manSpace.centerY += manSpace.toPz * 100
-
- console.log("XXXXXXXX-后象限1的其他空间", manSpace.spaceId, manSpace.spaceWidth, manSpace.spaceHeight, manSpace.centerX, manSpace.centerY);
-
- const spaceIndex = this.spaceList.findIndex((item)=>{
- return item.spaceId == manSpace.spaceId;
- })
- if(spaceIndex!=-1){
- this.spaceList[spaceIndex] = manSpace;
- }
- const spacesIndex = this.spaces1.findIndex((item)=>{
- return item.spaceId == manSpace.spaceId;
- })
- if(spacesIndex!=-1){
- this.spaces1[spacesIndex] = manSpace;
- }
- }
- if(xiangxian == 2){
- const spaceW = this.spaces2.find((item)=>{
- return item.spaceId == manSpace.westId;
- })
- const spaceS = this.spaces2.find((item)=>{
- return item.spaceId == manSpace.southId;
- })
-
- const oldArea = (manSpace.spaceWidth / 100) * (manSpace.spaceHeight / 100);
- const newArea = oldArea + changeArea * isZoomIn;
-
- const sizeScale = Math.sqrt(newArea/oldArea) ;
-
- manSpace.toScaleX = manSpace.spaceWidth * sizeScale / 300 ;
- manSpace.toScaleZ = manSpace.spaceHeight * sizeScale / 300 ;
-
- if(spaceW){
- manSpace.toPx = (manSpace.spaceWidth * sizeScale - manSpace.spaceWidth) / 2 / 100 + spaceW.toPx * 2;
- console.log("XXXXXXXX西边有空间", manSpace.spaceId, spaceW.toPx)
- }else{
- manSpace.toPx = (manSpace.spaceWidth * sizeScale - manSpace.spaceWidth) / 2 / 100;
- console.log("XXXXXXXX西边没空间", manSpace.spaceId)
- }
-
- if(spaceS){
- manSpace.toPz = (manSpace.spaceHeight * sizeScale - manSpace.spaceHeight) / 2 / 100 * -1 + spaceS.toPz * 2;
- console.log("XXXXXXXX南边有空间", manSpace.spaceId, spaceS.toPz)
- }else{
- manSpace.toPz = (manSpace.spaceHeight * sizeScale - manSpace.spaceHeight) / 2 / 100 * -1;
- console.log("XXXXXXXX南边没空间", manSpace.spaceId)
- }
-
-
- console.log("XXXXXXXX-前象限2的其他空间", manSpace.spaceId, manSpace.spaceWidth, manSpace.spaceHeight, manSpace.centerX, manSpace.centerY, manSpace.toPx);
-
- manSpace.spaceWidth = manSpace.spaceWidth * sizeScale;
- manSpace.spaceHeight = manSpace.spaceHeight * sizeScale;
- manSpace.centerX += manSpace.toPx * 100
- manSpace.centerY += manSpace.toPz * 100
-
- console.log("XXXXXXXX-后象限2的其他空间", manSpace.spaceId, manSpace.spaceWidth, manSpace.spaceHeight, manSpace.centerX, manSpace.centerY);
-
- const spaceIndex = this.spaceList.findIndex((item)=>{
- return item.spaceId == manSpace.spaceId;
- })
- if(spaceIndex!=-1){
- this.spaceList[spaceIndex] = manSpace;
- }
- const spacesIndex = this.spaces2.findIndex((item)=>{
- return item.spaceId == manSpace.spaceId;
- })
- if(spacesIndex!=-1){
- this.spaces2[spacesIndex] = manSpace;
- }
- }
- if(xiangxian == 3){
- const spaceW = this.spaces3.find((item)=>{
- return item.spaceId == manSpace.westId;
- })
- const spaceN = this.spaces3.find((item)=>{
- return item.spaceId == manSpace.northId;
- })
-
- const oldArea = (manSpace.spaceWidth / 100) * (manSpace.spaceHeight / 100);
- const newArea = oldArea + changeArea * isZoomIn;
-
- const sizeScale = Math.sqrt(newArea/oldArea) ;
-
- manSpace.toScaleX = manSpace.spaceWidth * sizeScale / 300 ;
- manSpace.toScaleZ = manSpace.spaceHeight * sizeScale / 300 ;
-
- if(spaceW){
- manSpace.toPx = (manSpace.spaceWidth * sizeScale - manSpace.spaceWidth) / 2 / 100 + spaceW.toPx * 2;
- console.log("XXXXXXXX西边有空间", manSpace.spaceId, spaceW.toPx)
- }else{
- manSpace.toPx = (manSpace.spaceWidth * sizeScale - manSpace.spaceWidth) / 2 / 100;
- console.log("XXXXXXXX西边没空间", manSpace.spaceId)
- }
-
- if(spaceN){
- manSpace.toPz = (manSpace.spaceHeight * sizeScale - manSpace.spaceHeight) / 2 / 100 + spaceN.toPz * 2;
- console.log("XXXXXXXX北边有空间", manSpace.spaceId, spaceN.toPz)
- }else{
- manSpace.toPz = (manSpace.spaceHeight * sizeScale - manSpace.spaceHeight) / 2 / 100;
- console.log("XXXXXXXX北边没空间", manSpace.spaceId)
- }
-
-
- console.log("XXXXXXXX-前象限3的其他空间", manSpace.spaceId, manSpace.spaceWidth, manSpace.spaceHeight, manSpace.centerX, manSpace.centerY, manSpace.toPx);
-
- manSpace.spaceWidth = manSpace.spaceWidth * sizeScale;
- manSpace.spaceHeight = manSpace.spaceHeight * sizeScale;
- manSpace.centerX += manSpace.toPx * 100
- manSpace.centerY += manSpace.toPz * 100
-
- console.log("XXXXXXXX-后象限3的其他空间", manSpace.spaceId, manSpace.spaceWidth, manSpace.spaceHeight, manSpace.centerX, manSpace.centerY);
-
- const spaceIndex = this.spaceList.findIndex((item)=>{
- return item.spaceId == manSpace.spaceId;
- })
- if(spaceIndex!=-1){
- this.spaceList[spaceIndex] = manSpace;
- }
- const spacesIndex = this.spaces3.findIndex((item)=>{
- return item.spaceId == manSpace.spaceId;
- })
- if(spacesIndex!=-1){
- this.spaces3[spacesIndex] = manSpace;
- }
- }
- if(xiangxian == 4){
- const spaceE = this.spaces4.find((item)=>{
- return item.spaceId == manSpace.eastId;
- })
- const spaceN = this.spaces4.find((item)=>{
- return item.spaceId == manSpace.northId;
- })
-
- const oldArea = (manSpace.spaceWidth / 100) * (manSpace.spaceHeight / 100);
- const newArea = oldArea + changeArea * isZoomIn;
-
- const sizeScale = Math.sqrt(newArea/oldArea) ;
-
- manSpace.toScaleX = manSpace.spaceWidth * sizeScale / 300 ;
- manSpace.toScaleZ = manSpace.spaceHeight * sizeScale / 300 ;
-
- if(spaceE){
- manSpace.toPx = (manSpace.spaceWidth * sizeScale - manSpace.spaceWidth) / 2 / 100 * -1 + spaceE.toPx * 2;
- console.log("XXXXXXXX东边有空间", manSpace.spaceId, spaceE.toPx)
- }else{
- manSpace.toPx = (manSpace.spaceWidth * sizeScale - manSpace.spaceWidth) / 2 / 100 * -1;
- console.log("XXXXXXXX东边没空间", manSpace.spaceId)
- }
-
- if(spaceN){
- manSpace.toPz = (manSpace.spaceHeight * sizeScale - manSpace.spaceHeight) / 2 / 100 + spaceN.toPz * 2;
- console.log("XXXXXXXX北边有空间", manSpace.spaceId, spaceN.toPz)
- }else{
- manSpace.toPz = (manSpace.spaceHeight * sizeScale - manSpace.spaceHeight) / 2 / 100;
- console.log("XXXXXXXX北边没空间", manSpace.spaceId)
- }
-
-
- console.log("XXXXXXXX-前象限4的其他空间", manSpace.spaceId, manSpace.spaceWidth, manSpace.spaceHeight, manSpace.centerX, manSpace.centerY, manSpace.toPx);
-
- manSpace.spaceWidth = manSpace.spaceWidth * sizeScale;
- manSpace.spaceHeight = manSpace.spaceHeight * sizeScale;
- manSpace.centerX += manSpace.toPx * 100
- manSpace.centerY += manSpace.toPz * 100
-
- console.log("XXXXXXXX-后象限4的其他空间", manSpace.spaceId, manSpace.spaceWidth, manSpace.spaceHeight, manSpace.centerX, manSpace.centerY);
-
- const spaceIndex = this.spaceList.findIndex((item)=>{
- return item.spaceId == manSpace.spaceId;
- })
- if(spaceIndex!=-1){
- this.spaceList[spaceIndex] = manSpace;
- }
- const spacesIndex = this.spaces4.findIndex((item)=>{
- return item.spaceId == manSpace.spaceId;
- })
- if(spacesIndex!=-1){
- this.spaces4[spacesIndex] = manSpace;
- }
- }
- },
-
-
- updataPageData(){
- let str = JSON.stringify(this.spaceList)
-
- this.curHouseObj.houseJson = str;
-
- let layoutStruct = this.curLayoutStruct.find(it=>{
- return it.houseFloor == this.curHouseFloor
- })
- layoutStruct.houseJson = str;
- this.currentChangeSpaceId = null;
- console.warn("***curLayoutStruct-updataPageData***",this.curHouseFloor,this.curHouseObj,layoutStruct)
- },
-
- curHouseTypeChange(item){
- this.curHouseType = item.spaceStructure;
- this.curHouseName = item.spaceName;
-
- this.curLayoutStruct = this.houseList.find(it=>it.spaceStructure == this.curHouseType).layoutStruct;
- console.warn("***curLayoutStruct***",this.curLayoutStruct)
- },
-
- curHouseFloorChange(item){
- let that = this;
- this.curHouseFloor = item.houseFloor;
- this.curHouseObj = item;
- this.id = this.curHouseObj.id;
-
- let deleList = that.scene && that.scene.children.filter(object=>{
- if(object.userType=="mesh" || object.userType=="layoutMesh"){
- return object
- }
- })
-
- if(deleList && deleList.length>0){
- that.showLables = false;
- that.scene.remove(...deleList);
- }
-
- this.gltfWalls = [];
- this.gltfSpaces = [];
- this.instancedMeshList = [];
- this.instancedSpaceMeshList = [];
- this.lableItem = [];
- this.gltfLayouts = [];
- this.instancedFurList = [];
- this.wallList = [];
-
- this.cameraInit();
- this.resetControl();
- setTimeout(()=>{
- that.loadSpace();
- }, 100);
- console.warn("***curHouseObj***",this.curHouseObj,that.aiData)
- this.navbar.title = this.curHouseObj.name + " " + this.curHouseObj.houseArea + "㎡"
- },
- async getInitData(){
- let parmas = {
- childLayout:this.childLayout || 0,
- houseId:this.houseId,
- }
- const res = await requestConfig('getHouseTypeSpaceDetailsV2', parmas, true);
- if (res.success && res.list) {
- let list = res.list || [];
- list && list.forEach((single,index)=>{
- single.layoutStruct.forEach((item)=>{
- if(item.houseJson){
- let spaceList = JSON.parse(item.houseJson);
-
- for (let index = 0; index < spaceList.length; index++) {
- var element = spaceList[index];
- const {centerX, centerY} = element;
- element.centerX = centerY;
- element.centerY = centerX;
- }
- item.houseJson = JSON.stringify(spaceList);
- }
- })
- })
- console.log("户型详情列表-接口原始数据: ", list);
- this.houseList = list;
- }
- },
-
- onMouseMove(e){
- return false;
- },
- goRoam1(spaceId){
- let gltf = this.lableItem.find(it=>it.spaceId==spaceId);
- if(gltf){
- this.goRoam(gltf)
- }
- },
-
- goRoam(gltf){
-
- if(gltf.spaceType==13){
- return false
- }
- let spaceId = gltf.spaceId;
- let data = {
- spaceId:spaceId,
-
- houseId:this.houseId,
- }
- if(this.repeatFlag){
- return false;
- }
- this.repeatFlag = true;
- router.push({
- name: "webgl_rxdz_roam",
- query:data
- });
- this.$store.dispatch('setCurHouseObj', this.curHouseObj);
- this.$store.dispatch('setWallList', this.wallList);
- setTimeout(()=> {
- this.repeatFlag = false;
- }, 1000);
- },
-
- moveMeshCenter(obj,type){
- console.warn("**moveMeshCenter***",obj)
- if(obj && this.gltfSpaces && this.gltfSpaces.length>0){
- this.moveMeshCenterHandle(obj,type);
- }
- },
-
- async loadSpace(){
- this.spaceList = [];
- this.wallIds = [];
- this.layoutIds = [];
- this.gltfSpaces = [];
- this.curWallArr = [];
- this.progress = 0;
- if(!this.curHouseObj){
- return false
- }
- let type=[];
- if(this.curHouseObj){
- const spaceDetail = this.curHouseObj;
- const spaceList = JSON.parse(spaceDetail.houseJson);
-
- for (let index = 0; index < spaceList.length; index++) {
- var element = spaceList[index];
-
-
-
- element.wallMoveValue = "[0,0,0,0]"
- this.spaceList.push(element);
- this.wallIds.push(element.wallId);
- this.layoutIds.push(element.layoutId);
- type.push(element.spaceType);
- if(element.isSelected){
- this.curSpaceObj = element;
- }
- }
- if(!this.curSpaceObj && this.spaceList.length > 0){
- this.curSpaceObj = this.spaceList[0];
- }
- }
- console.log("该户型空间数据:", this.spaceList, this.layoutIds,type);
- console.log("当前选中的空间:", this.curSpaceObj,this.curHouseObj);
- this.spaceListBackup = JSON.parse(JSON.stringify(this.spaceList));
- this.loaderSpaceArr(this.spaceList);
-
- this.getHouseTypeSpaceWalls();
- },
-
- addWordLabel(){
- if(!this.gltfSpaces || this.gltfSpaces.length <= 0){
- return false;
- }
-
- this.lableItem = [];
- this.gltfSpaces.forEach((cube,index) =>{
-
- if(cube.spaceName && !cube.isSizeLock){
- let spaceIndex = this.spaceList.filter(it=>it.spaceName && !it.isSizeLock).findIndex(item=>item.spaceId==cube.spaceId);
- this.lableItem.push(
- {
- text:cube.spaceName,
- spaceId:cube.spaceId,
- spaceType:cube.spaceType,
- transform:'',
- spaceIndex:spaceIndex,
- cubeIndex:index,
- }
- )
- }
- })
- this.showLables = true;
-
- },
-
- async getHouseTypeSpaceWalls(){
- let data = {id:this.wallIds}
- const res = await requestConfig('getHouseTypeSpaceWalls', data, true);
- console.log("墙体数据:", res.list)
- let wallList = [];
- if(res.success){
- wallList = this.wallList = res.list;
- }
- let wallArr = []
- for (let index = 0; index < wallList.length; index++) {
- let element = JSON.parse(wallList[index].wallJson);
- let space = this.spaceList.find(space=>space.spaceId==element.spaceId);
- this.computeWallHandleOld(space,element);
- for (let i = 0; i < element.wallData.length; i ++) {
- let wallData = element.wallData[i];
-
- for (let j = 0; j < wallData.wallModelData.length; j ++) {
- let wallModelData = wallData.wallModelData[j];
- wallArr.push({spaceId:element.spaceId, wallModelData:wallModelData, wallDirection:wallData.wallDirection})
-
- }
- }
- }
- this.loadSpaceObjWalls(wallArr, wallList);
- this.getOverallArrangementDetailsList(2);
- },
-
- async loadSpaceObjWalls(wallArr, wallList){
-
- let startTime = new Date().getTime();
-
- let promise_list = [];
- let realWallArr = this.preWallData(wallArr);
- let arrLength = realWallArr.length;
- realWallArr && realWallArr.forEach((item,index) => {
- promise_list.push(
- new Promise((resolve, reject) => {
- this.loadWallModels(item, wallList, arrLength , resolve);
- })
- )
- });
- Promise.all(promise_list).then(()=>{
- let endTime = new Date().getTime();
- console.log("模型全部加载完成,时间:",endTime - startTime);
- this.progress = 100;
-
-
-
- this.$nextTick(()=>{
- this.moveMeshCenter(this.curSpaceObj);
-
-
- setTimeout(()=>{
- this.addWordLabel();
- }, 610);
-
- })
- })
- },
-
- selectedWall(direction){
- if(!direction || direction==""){
- return
- }
- console.log(`当前空间的id:${this.curSpaceObj.spaceId};墙面方向:${direction};宽度:${this.curSpaceObj.spaceWidth};宽度:${this.curSpaceObj.spaceHeight}`)
- console.log("当前空间的:", this.curSpaceObj);
- this.leftSpaces = [];
- this.rightSpaces = [];
- this.tempSpaceList = JSON.parse(JSON.stringify(this.spaceList));
-
- this.findLeftRelateSpace(this.curSpaceObj, direction);
- console.log("空间数组:", this.leftSpaces, this.rightSpaces);
-
-
- var min = 0;
- var max = 300;
-
- for (let index = 0; index < this.leftSpaces.length; index++) {
- const element = this.leftSpaces[index];
- console.log("左边空间数据:", element);
- var spaceMoveNW = element.spaceWidth;
- var spaceMoveSW = element.spaceWidth;
- var spaceMoveEH = element.spaceHeight;
- var spaceMoveWH = element.spaceHeight;
- var curSpaceWall = [];
- for (let index = 0; index < this.gltfWalls.length; index++) {
- const wall = this.gltfWalls[index];
- if(element.spaceId == wall.spaceId && wall.wallDirection != direction){
- curSpaceWall.push(wall);
- if((direction == "W" || direction == "E") && wall.wallDirection != direction){
- if(wall.wallDirection == "N"){
- spaceMoveNW -= wall.wallModelData.wallWidth;
- console.log("北边墙:", spaceMoveNW, wall.wallModelData.wallWidth, wall.id);
- }
- if(wall.wallDirection == "S"){
- spaceMoveSW -= wall.wallModelData.wallWidth;
- console.log("南边墙:", spaceMoveSW, wall.wallModelData.wallWidth, wall.id);
- }
-
- this.curWallValue = Math.floor(Math.min(Math.min(spaceMoveNW, spaceMoveSW), this.curWallValue));
- }
- if((direction == "N" || direction == "S") && wall.wallDirection != direction){
- if(wall.wallDirection == "E"){
- spaceMoveEH -= wall.wallModelData.wallWidth;
- console.log("东边墙:", spaceMoveNW, wall.wallModelData.wallWidth, wall.id);
- }
- if(wall.wallDirection == "W"){
- spaceMoveWH -= wall.wallModelData.wallWidth;
- console.log("西边墙:", spaceMoveSW, wall.wallModelData.wallWidth, wall.id);
- }
- this.curWallValue = Math.floor(Math.min(Math.min(spaceMoveEH, spaceMoveWH), this.curWallValue));
- }
- }
- }
-
-
- curSpaceWall.sort(function(a,b){return a.wallModelData.id -b.wallModelData.id});
- curSpaceWall.sort(function(a,b){return a.wallDirection.localeCompare(b.wallDirection)})
-
- console.log("墙体模型:", curSpaceWall, spaceMoveNW, spaceMoveSW);
- console.log("可缩小的最小值:", Math.floor(Math.min(spaceMoveNW, spaceMoveSW)));
-
- if((direction == "W" || direction == "E") && element.spaceWidth == this.curWallValue){
- this.curWallValue = 149;
- }
- if((direction == "N" || direction == "S") && element.spaceHeight == this.curWallValue){
- this.curWallValue = 149;
- }
-
- }
-
-
-
- for (let index = 0; index < this.rightSpaces.length; index++) {
- const element = this.rightSpaces[index];
- console.log("右边空间数据:", element);
- var spaceMoveNW = element.spaceWidth;
- var spaceMoveSW = element.spaceWidth;
- var spaceMoveEH = element.spaceHeight;
- var spaceMoveWH = element.spaceHeight;
- var curSpaceWall = [];
- for (let index = 0; index < this.gltfWalls.length; index++) {
- const wall = this.gltfWalls[index];
- if(element.spaceId == wall.spaceId && wall.wallDirection != direction){
- curSpaceWall.push(wall);
- if((direction == "W" || direction == "E") && wall.wallDirection != direction){
- if(wall.wallDirection == "N"){
- spaceMoveNW -= wall.wallModelData.wallWidth;
- console.log("北边墙:", spaceMoveNW, wall.wallModelData.wallWidth, wall.id);
- }
- if(wall.wallDirection == "S"){
- spaceMoveSW -= wall.wallModelData.wallWidth;
- console.log("南边墙:", spaceMoveSW, wall.wallModelData.wallWidth, wall.id);
- }
-
- this.curWallMaxValue = Math.floor(Math.min(spaceMoveNW, spaceMoveSW)) + this.curWallValue;
- }
- if((direction == "N" || direction == "S") && wall.wallDirection != direction){
- if(wall.wallDirection == "E"){
- spaceMoveEH -= wall.wallModelData.wallWidth;
- console.log("东边墙:", spaceMoveNW, wall.wallModelData.wallWidth, wall.id);
- }
- if(wall.wallDirection == "W"){
- spaceMoveWH -= wall.wallModelData.wallWidth;
- console.log("西边墙:", spaceMoveSW, wall.wallModelData.wallWidth, wall.id);
- }
- this.curWallMaxValue = Math.floor(Math.min(spaceMoveEH, spaceMoveWH)) + this.curWallValue;
- }
- }
- }
-
-
- curSpaceWall.sort(function(a,b){return a.wallModelData.id -b.wallModelData.id});
- curSpaceWall.sort(function(a,b){return a.wallDirection.localeCompare(b.wallDirection)})
-
- console.log("墙体模型:", curSpaceWall, spaceMoveNW, spaceMoveSW);
- console.log("可缩小的最小值:", Math.floor(Math.min(spaceMoveNW, spaceMoveSW)));
- }
-
-
- console.log(`当前墙面的最大值:${this.curWallMaxValue}, 最小值:${this.curWallValue}`)
-
- this.changeSpaces.push(...this.leftSpaces)
- this.changeSpaces.push(...this.rightSpaces)
- },
-
- findLeftRelateSpace(spaceObj, direction){
- const {eastId, westId, northId, southId, spaceId} = spaceObj;
-
- const leftIndex = this.tempSpaceList.findIndex((item)=>{
- return item.spaceId == spaceId;
- })
- if(leftIndex!=-1){
- const spaceObj = this.tempSpaceList[leftIndex];
- this.leftSpaces.push(spaceObj);
- this.tempSpaceList.splice(leftIndex,1);
-
- const leftNextIndex = this.tempSpaceList.findIndex((item)=>{
- if(direction == "E"){
- return item.spaceId == eastId;
- }else if(direction == "W"){
- return item.spaceId == westId;
- }else if(direction == "S"){
- return item.spaceId == southId;
- }else if(direction == "N"){
- return item.spaceId == northId;
- }
- })
- if(leftNextIndex!=-1){
- const nextSpaceObj = this.tempSpaceList[leftNextIndex];
- console.log("递归再一次", nextSpaceObj);
- this.findRightRelateSpace(nextSpaceObj, direction);
- }
-
- const rightArr = this.tempSpaceList.filter((item)=>{
- if(direction == "E"){
- return item.westId == spaceId;
- }else if(direction == "W"){
- return item.eastId == spaceId;
- }else if(direction == "S"){
- return item.northId == spaceId;
- }else if(direction == "N"){
- return item.southId == spaceId;
- }
- })
-
- for (let index = 0; index < rightArr.length; index++) {
- const nextSpaceObj = rightArr[index];
-
- console.log("递归再一次", nextSpaceObj);
- this.findRightRelateSpace(nextSpaceObj, direction);
- }
-
- }
-
- },
-
- findRightRelateSpace(spaceObj, direction){
- const {eastId, westId, northId, southId, spaceId} = spaceObj;
-
- const rightIndex = this.tempSpaceList.findIndex((item)=>{
- return item.spaceId == spaceId;
- })
-
- if(rightIndex!=-1){
- const spaceObj = this.tempSpaceList[rightIndex];
- this.rightSpaces.push(spaceObj);
- this.tempSpaceList.splice(rightIndex,1);
- console.log("当前空间数组:", this.tempSpaceList);
-
- const leftNextIndex = this.tempSpaceList.findIndex((item)=>{
- if(direction == "E"){
- return item.spaceId == westId;
- }else if(direction == "W"){
- return item.spaceId == eastId;
- }else if(direction == "N"){
- return item.spaceId == southId;
- }else if(direction == "S"){
- return item.spaceId == northId;
- }
- })
- if(leftNextIndex!=-1){
- const nextSpaceObj = this.tempSpaceList[leftNextIndex];
- console.log("递归再一次", nextSpaceObj);
- this.findLeftRelateSpace(nextSpaceObj, direction);
- }
-
- const rightArr = this.tempSpaceList.filter((item)=>{
- if(direction == "E"){
- return item.eastId == spaceId;
- }else if(direction == "W"){
- return item.westId == spaceId;
- }else if(direction == "N"){
- return item.northId == spaceId;
- }else if(direction == "S"){
- return item.southId == spaceId;
- }
- });
-
- for (let index = 0; index < rightArr.length; index++) {
- const nextSpaceObj = rightArr[index];
- console.log("递归再一次", nextSpaceObj);
- this.findLeftRelateSpace(nextSpaceObj, direction);
- }
-
- }
- },
- moveSpaceWall(direction, moveOut, moveValue){
-
-
-
-
-
-
- this.changeLayoutModelState();
- console.log("关联空间XXXXX", this.leftSpaces, this.rightSpaces)
- for (let index = 0; index < this.leftSpaces.length; index++) {
- const element = this.leftSpaces[index];
- const space = this.spaceList.find((item)=>{
- return item.spaceId == element.spaceId;
- })
- this.moveWall(space, direction, moveOut, moveValue);
-
- }
- let otherdirection = "";
- switch (direction) {
- case "E":
- otherdirection = "W"
- break;
- case "W":
- otherdirection = "E"
- break;
- case "N":
- otherdirection = "S"
- break;
- case "S":
- otherdirection = "N"
- break;
- }
- for (let index = 0; index < this.rightSpaces.length; index++) {
- const element = this.rightSpaces[index];
- this.moveWall(element, otherdirection, !moveOut, moveValue);
- }
- console.log(`当前空间的后id:${this.curSpaceObj.spaceId};墙面方向:${direction};宽度:${this.curSpaceObj.spaceWidth};高度:${this.curSpaceObj.spaceHeight}`)
- },
-
-
-
-
- moveWall(spaceObj, direction, moveOut, moveValue){
- console.log(`移动的空间的id-------:${spaceObj.spaceId};移动方向:${direction};是否外移:${moveOut};移动距离:${moveValue}`)
- const oldSpaceObj = JSON.parse(JSON.stringify(spaceObj))
-
- const cube = this.gltfSpaces.find((item)=>{
- return item.spaceId == spaceObj.spaceId;
- })
-
- if(!cube){
- return
- }
-
- if(!moveOut){
- moveValue = moveValue * -1;
- }
- const {position,scale} = cube;
-
- let toScaleX = scale.x;
- let toScaleZ = scale.z;
- let toPx = position.x;
- let toPz = position.z;
- if(direction == 'E' || direction == 'W'){
- let spaceWidth = scale.x * 300;
- toScaleX = (spaceWidth + moveValue) / 300;
- if(direction == 'W'){
- toPx = position.x - moveValue / 2 / 100;
- }else{
- toPx = position.x + moveValue / 2 / 100;
- }
- spaceObj.spaceWidth += moveValue;
- spaceObj.centerX = toPx * 100;
- }
-
- if(direction == 'N' || direction == 'S'){
- let spaceHeight = scale.z * 300;
- toScaleZ = (spaceHeight + moveValue) / 300;
- if(direction == 'N'){
- toPz = position.z - moveValue / 2 / 100;
- }else{
- toPz = position.z + moveValue / 2 / 100;
- }
- spaceObj.spaceHeight += moveValue;
- spaceObj.centerY = toPz * 100 * -1;
- }
- console.log("curSpaceObj",this.curSpaceObj.spaceId, spaceObj.spaceId, spaceObj.centerX, spaceObj.centerY, toScaleX,toScaleZ,toPx,toPz)
- console.log("当前空间变化后的尺寸",spaceObj.spaceWidth, spaceObj.spaceHeight, spaceObj.spaceId)
-
-
- const spaceIndex = this.spaceList.findIndex((item)=>{
- return item.spaceId == spaceObj.spaceId;
- })
- if(spaceIndex!=-1){
- this.spaceList[spaceIndex] = spaceObj;
- if(this.curSpaceObj.spaceId == spaceObj.spaceId){
- this.curSpaceObj = spaceObj;
- }
- }
- this.curHouseObj.houseJson = JSON.stringify(this.spaceList);
-
- this.changeSpacesAnim({spaceId:spaceObj.spaceId,toScaleX,toScaleZ,toPx,toPz})
-
-
- const wallObj = this.wallList.find((item)=>{
- return item.id == spaceObj.wallId;
- })
-
- const initSpaceObj = this.spaceListBackup.find((item)=>{
- return item.spaceId == spaceObj.spaceId;
- })
-
- if(wallObj){
- let element = JSON.parse(wallObj.wallJson);
- console.warn("****wallObj**",element)
- this.computeWallHandle(initSpaceObj, spaceObj, element, moveOut, direction);
- }
-
-
- let curSpaceWall = [];
- for (let index = 0; index < this.gltfWalls.length; index++) {
- const element = this.gltfWalls[index];
- if(spaceObj.spaceId == element.spaceId){
- curSpaceWall.push(element);
- }
- }
-
-
- if(direction == 'W' || direction == 'S'){
- spaceObj.rightCenter = true;
- }
-
- if(direction == 'E'|| direction == 'N'){
- spaceObj.rightCenter = false;
- }
-
- curSpaceWall.sort(function(a,b){return a.wallModelData.id -b.wallModelData.id});
- curSpaceWall.sort(function(a,b){return a.wallDirection.localeCompare(b.wallDirection)})
-
- console.log("移动的墙体:", spaceObj, direction, curSpaceWall);
-
-
- for (let index = 0; index < curSpaceWall.length; index++) {
- const element = curSpaceWall[index];
-
- this.drawModel(element.wallModelData, spaceObj, element, true)
- }
- },
-
- autoCreateWall(directionIndex, spaceObj){
-
- let direction = ""
- switch (directionIndex) {
- case 1:
- direction = "N"
- break;
- case 2:
- direction = "S"
- break;
- case 3:
- direction = "W"
- break;
- case 4:
- direction = "E"
- break;
- default:
- break;
- }
-
-
- if(direction == "E" || direction == "W"){
- if(spaceObj.quadrant == 3 || spaceObj.quadrant == 4){
- console.log("南北朝向墙自动补齐", this.leftSpaces, this.rightSpaces)
-
-
-
- this.selectedWall("N");
- this.checkIsAutoCreateWall("N", spaceObj)
-
-
-
- this.selectedWall("S");
- this.checkIsAutoCreateWall("S", spaceObj)
-
- let autoWall = this.gltfAutoWalls.find(item=>{
- return item.spaceId == spaceObj.spaceId ;
- })
-
- if(autoWall){
- console.log("南北朝向墙自动补齐---", autoWall, this.gltfAutoWalls)
- if(autoWall.wallDirection == "E"){
- autoWall.obj.position.x = (spaceObj.centerX + (spaceObj.spaceWidth / 2) - 5) / 100
- }
-
- }
-
- }else{
-
- }
- }else{
- if(spaceObj.quadrant == 3 || spaceObj.quadrant == 4){
-
- console.log("东西朝向墙自动补齐", this.leftSpaces, this.rightSpaces)
-
- this.selectedWall("E");
- this.checkIsAutoCreateWall("E", spaceObj)
-
- this.selectedWall("W");
- this.checkIsAutoCreateWall("W", spaceObj)
-
-
-
- }else{
-
- }
- }
-
- },
-
- checkIsAutoCreateWall(direction, spaceObj){
- var that = this;
-
- if(this.rightSpaces.length == 0){
- console.log("不需要补墙1", direction, this.gltfAutoWalls)
- return;
- }
- const n = (direction == "S" || direction == "E") ? 1 : -1;
-
- console.log("自动补墙", this.leftSpaces, this.rightSpaces);
-
- let px = 0;
- let pz = 0;
- let sx = 1;
- let sz = 1;
- let rightids = []
- if(spaceObj.quadrant == 3){
-
-
- let leftMaxValue = 0;
- for (let index = 0; index < this.leftSpaces.length; index++) {
- const element = this.leftSpaces[index];
- if(direction=="S" || direction == "N"){
- const curvalue = element.centerX + element.spaceWidth / 2
- if(leftMaxValue < curvalue){
- leftMaxValue = curvalue
- }
- }else{
- leftMaxValue += (-element.centerY + element.spaceHeight / 2)
- }
- }
-
- let rightMaxValue = 0;
- for (let index = 0; index < this.rightSpaces.length; index++) {
- const element = this.rightSpaces[index];
- if(direction=="S" || direction == "N"){
- const curvalue = element.centerX + element.spaceWidth / 2
- if(rightMaxValue < curvalue){
- rightMaxValue = curvalue
- }
- }else{
- rightMaxValue += -element.centerY + element.spaceHeight / 2
- }
- rightids.push(element.spaceId)
- }
-
-
- const index = this.gltfWalls.findIndex(item=>{
-
- return spaceObj.spaceId == item.spaceId && item.wallDirection == direction;
- })
-
-
- if(index != -1 && leftMaxValue > rightMaxValue && (direction == "S" || direction == "N")){
- console.log("不需要补墙251",index, leftMaxValue, rightMaxValue)
-
- const autoWall = this.gltfAutoWalls.find(item=>{
- return item.rightids.indexOf(spaceObj.spaceId) != -1 && item.wallDirection == (direction == "S" ? "N": "S");
- })
- if(autoWall){
- let cube = autoWall.obj;
- if(cube){
- cube.scale.set(0,0,0);
- }
- }
- return
- }
-
- if(index != -1 && leftMaxValue > rightMaxValue && (direction == "E" || direction == "W")){
- console.log("不需要补墙252",index, leftMaxValue, rightMaxValue, spaceObj.spaceId, direction, this.gltfAutoWalls)
- const autoWall = this.gltfAutoWalls.find(item=>{
- return item.rightids.indexOf(spaceObj.spaceId) != -1 && item.wallDirection == (direction == "E" ? "W": "E");
- })
- if(autoWall){
- let cube = autoWall.obj;
- if(cube){
- cube.scale.set(0,0,0);
- }
- }
- return
- }
-
- let wallOffset = index != -1 ? -5 : 5;
-
- console.log("空间最大值", leftMaxValue, rightMaxValue, direction, index);
- const cubeW = Math.abs(leftMaxValue - rightMaxValue);
-
- if(direction=="S" || direction == "N"){
- px = (Math.min(leftMaxValue, rightMaxValue) + cubeW / 2) / 100
- pz = (-spaceObj.centerY + spaceObj.spaceHeight * n / 2 + wallOffset * n) / 100;
- sx = cubeW / 10 ;
-
- }else{
- px = (spaceObj.centerX + spaceObj.spaceWidth * n / 2 + wallOffset * n) / 100;
- pz = (Math.max(leftMaxValue, rightMaxValue) - cubeW / 2) / 100
- sz = cubeW / 10;
- }
-
-
-
-
- }else{
- let leftMinValue = 0;
- for (let index = 0; index < this.leftSpaces.length; index++) {
- const element = this.leftSpaces[index];
- if(direction=="S" || direction == "N"){
- leftMinValue += (element.centerX - element.spaceWidth / 2)
- }else{
- leftMinValue += (-element.centerY + element.spaceHeight / 2)
- }
- }
-
- let rightMinValue = 0;
- for (let index = 0; index < this.rightSpaces.length; index++) {
- const element = this.rightSpaces[index];
- if(direction=="S" || direction == "N"){
- rightMinValue += (element.centerX - element.spaceWidth / 2)
- }else{
- rightMinValue = (-element.centerY + element.spaceHeight / 2)
- }
- rightids.push(element.spaceId)
- }
-
-
- const index = this.gltfWalls.findIndex(item=>{
-
- return spaceObj.spaceId == item.spaceId && item.wallDirection == direction;
- })
-
- if(index != -1 && leftMinValue < rightMinValue && (direction == "S" || direction == "N")){
- console.log("不需要补墙251")
- return
- }
-
- if(index != -1 && leftMinValue > rightMinValue && (direction == "E" || direction == "W")){
- console.log("不需要补墙252")
- return
- }
-
- let wallOffset = index != -1 ? -5 : 5;
-
- console.log("空间最大值", leftMinValue, rightMinValue);
- const cubeW = Math.abs(leftMinValue - rightMinValue);
-
- if(leftMinValue > rightMinValue && index == -1 && (direction == "S" || direction == "N")){
- console.log("不需要补墙241", leftMinValue, rightMinValue)
-
- const autoWall = this.gltfAutoWalls.find(item=>{
- return item.rightids.indexOf(spaceObj.spaceId) != -1 && item.wallDirection == (direction == "S" ? "N": "S");
- })
- if(autoWall){
- let cube = autoWall.obj;
- if(cube){
- cube.scale.set(0,0,0);
- }
- }
- return
- }
- if(leftMinValue < rightMinValue && index == -1 && (direction == "E" || direction == "W")){
- console.log("不需要补墙242", leftMinValue, rightMinValue)
-
- const autoWall = this.gltfAutoWalls.find(item=>{
- return item.rightids.indexOf(spaceObj.spaceId) != -1 && item.wallDirection == (direction == "W" ? "E": "W");
- })
- if(autoWall){
- let cube = autoWall.obj;
- if(cube){
- cube.scale.set(0,0,0);
- }
- }
- return
- }
- if(direction=="S" || direction == "N"){
- px = (Math.max(leftMinValue, rightMinValue) - cubeW / 2) / 100
- pz = (-spaceObj.centerY + spaceObj.spaceHeight * n / 2 + wallOffset * n) / 100;
- sx = cubeW / 10;
- }else{
- px = (spaceObj.centerX + spaceObj.spaceWidth * n / 2 + wallOffset * n) / 100;
- pz = (Math.max(leftMinValue, rightMinValue) - cubeW / 2) / 100
- sz = cubeW / 10;
- }
- }
-
- console.log("空间最大值", px, pz, sx, sz, this.gltfAutoWalls);
-
-
- const autoWall = this.gltfAutoWalls.find(item=>{
- return (item.spaceId == spaceObj.spaceId && item.wallDirection == direction)
- || (item.rightids.findIndex(it=>{ return it == spaceObj.spaceId})!=-1 && item.wallDirection == direction == "S"?"N":"S")
- || (item.rightids.findIndex(it=>{ return it == spaceObj.spaceId})!=-1 && item.wallDirection == direction == "E"?"W":"E")
- })
-
- if(this.curWallDirection == "S"){
- if(spaceObj.southId > 0){
- return
- }
- }
- if(this.curWallDirection == "E"){
- if(spaceObj.eastId > 0){
- return
- }
- }
- if(this.curWallDirection == "N"){
- if(spaceObj.northId > 0){
- return
- }
- }
-
- if(this.curWallDirection == "W"){
- if(spaceObj.westId > 0){
- return
- }
- }
-
- if(autoWall){
- console.log("修改补墙的信息", px, pz, sx, sz);
- let cube = autoWall.obj;
- cube.position.set(px,0,pz);
- cube.scale.set(sx,1,sz);
- }else{
- console.log("添加补墙的信息", px, pz, sx, sz);
-
- that.loader.load(wallType[0].url, ( gltf ) => {
- let cube = gltf.scene;
-
- cube.position.set(px,0,pz);
- cube.scale.set(sx,1,sz);
- that.scene.add(cube);
- let md = {
- obj:cube,
- wallDirection:direction,
- spaceId:spaceObj.spaceId,
- quadrant:spaceObj.quadrant,
- rightids:rightids
- };
- that.gltfAutoWalls.push(md);
-
- });
- }
- },
-
- wallTransform(spaceObj, direction, moveOut, moveValue){
- console.log(`移动的空间的id:${spaceObj.spaceId};移动方向:${direction};是否外移:${moveOut};移动距离:${moveValue}`)
- },
- updateWallModels(){
- let that = this;
- console.log("开始替换墙体模型", this.leftSpaces, this.rightSpaces, this.gltfWalls);
- let promise_list = [];
-
- this.gltfWalls.forEach((item,index) => {
- promise_list.push(
- new Promise((resolve, reject) => {
- this.loadChangeWallModels(item, resolve);
- })
- )
- });
- Promise.all(promise_list).then(()=>{
- this.$nextTick(()=>{
- let newArr = [];
- const newWalls = that.gltfWalls.filter(it=>{
- return !it.isDidWall
- })
- that.gltfWalls = newWalls;
- console.log("加载完成2",newWalls, newArr, that.gltfWalls, that.wallList);
- })
- })
- },
-
- }
- }
- </script>
- <style lang="scss" scoped>
- @import "./webgl_rxdz.scss";
- </style>
|