webgl_rxdz.vue 103 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731
  1. <template src="./webgl_rxdz.html"></template>
  2. <script>
  3. import * as THREE from 'three';
  4. import Stats from 'three/addons/libs/stats.module.js';
  5. import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
  6. import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
  7. import spaceTypes from '@/static/spaceTypesIE.js';
  8. import TWEEN from 'three/addons/libs/tween.module.js';
  9. import router from "@/router";
  10. import {
  11. setStorage,
  12. getStorage,
  13. } from '@/utils/localStorage';
  14. var requestId = "";
  15. const util = require('@/utils/util.js').default;
  16. // const config = require('@/services/urlConfig.js');
  17. import wallType from '@/static/wallData.js';
  18. // import modelData from '@/webgl/static/layoutModelData.js';
  19. // import requestConfig from '@/services/requestConfig.js';
  20. // import viewShell from'@/webgl/components/newBottomCom/viewShell/viewShell.vue';
  21. // import * as BufferGeometryUtils from '@/webgl/jsm/utils/BufferGeometryUtils.js';
  22. import screenshot from '@/mixins/screenshot.js';
  23. import floorMethod from '@/mixins/floorMethod.js';
  24. import wallMethod from '@/mixins/wallMethod.js';
  25. import loadModel from '@/mixins/loadModel.js';
  26. import commonPageMethod from '@/mixins/commonPageMethod.js';
  27. import viewShell from'@/components/newBottomCom/viewShell/viewShell.vue';
  28. export default {
  29. name:"webgl_rxdz",
  30. components:{viewShell},
  31. mixins:[screenshot,floorMethod,wallMethod,loadModel,commonPageMethod],
  32. /**
  33. * 页面的初始数据
  34. */
  35. data() {
  36. return {
  37. pvCurPageName: "home_show",
  38. locusBehaviorName: "主界面",
  39. pvCurPageParams: null,
  40. houseId: "",
  41. pvId: 'p_2cmina_23080401',
  42. canvas:null,
  43. navbar: {
  44. showCapsule: 0,
  45. title: '',
  46. titleColor: '#000',
  47. navPadding: 0,
  48. navPaddingBg:'transparent',
  49. navBarColor: 'transparent',
  50. navBackColor: 'transparent',
  51. haveCallback: false,
  52. fromShare: false,
  53. fromProject: 0,
  54. shareToken: "",
  55. pageName: this.pvCurPageName,
  56. },
  57. id:'232',// 户型编号
  58. spaceList:[], // 空间列表
  59. spaceListBackup:[], // 空间列表原始尺寸备份,用于墙体比例计算
  60. gltfSpaces:[], // 场景中地板模型数组
  61. gltfSpaceRoofs:[], // 屋顶模型数组
  62. curSpaceObj:null, // 当前选中的空间
  63. // curSpaceIndex:-1, // 当前选中的空间索引
  64. curWallDirection:"", // 当前选中的墙面
  65. curWallValue:0, // 当前墙面的滑动值
  66. curWallMaxValue:300,
  67. curWallHidden:false, // 当前墙面的状态
  68. wallIds:[], // 空间墙体id
  69. wallList:[], // 墙体数据
  70. gltfWalls:[], // 场景中墙体模型数组
  71. gltfAutoWalls:[],// 空间自动补墙模型数组
  72. // lastWallPosition:0, // 当面墙中墙体模型的开始位置
  73. tempSpaceList:[],// 全部空间临时数组,寻找关联空间,递归使用
  74. leftSpaces:[], // 移动空间左边数组
  75. rightSpaces:[],// 移动空间右边数组
  76. changeSpaces:[],// 尺寸变化涉及到的全部空间
  77. loader:null,
  78. scene:null,
  79. sky:null,
  80. camera:null,
  81. houseList:[], //当前户型所有的户型详情,可以切换
  82. curHouseType: null, //当前选中的户型类型
  83. curHouseName:'',//当前选中的户型类型名称
  84. curHouseFloor: null, //当前选中的户型楼层
  85. curHouseObj: null,
  86. controlStarPosition : { x:0, y:0, z:0}, //控制器初始位置
  87. cameraStarPosition : { x:0, y:20, z:0} ,//摄像头初始位置
  88. // cameraLastPosition: null, //摄像头上一次移动到的位置
  89. // controlLastPosition: null, //观察点上一次移动到的位置
  90. canvasHeight:200, //canvas视图的高度-计算得出
  91. chooseMesh:null,//标记鼠标拾取到的mesh
  92. // chooseMeshColor:'', //拾取到的mesh的原始颜色;
  93. chooseWallMeshColor:'', // 拾取墙体原始颜色
  94. curWallArr:[], // 当前空间选中墙面的墙体模型
  95. isManyou: false, //当前是否处在漫游状态
  96. pageShowIndex: 2, // 默认户型列表页面
  97. aleadyLoaderModel:[], //已经加载的墙体元数据模型列表
  98. // fontLabelGroup: [],
  99. shottingImg: [],
  100. progress:1, //进度条
  101. myLoadingStatus:false,
  102. // textGeoList:[],
  103. repeatFlag:false, //重复点击
  104. skyPlan: null, // 天空盒子
  105. instancedMeshList: [],
  106. lableItem:[],
  107. showLables:false,
  108. loadOver:false,
  109. voiceMaskShow:false, //录音时的蒙层是否显示
  110. minspace1: null,
  111. minspace2: null,
  112. minspace3: null,
  113. minspace4 : null,
  114. spaces1 : [],
  115. spaces2 : [],
  116. spaces3 : [],
  117. spaces4 : [],
  118. layoutIds:[], // 空间墙体id
  119. layoutLists:[], // 墙体数据
  120. gltfLayouts:[], // 场景中墙体模型数组
  121. screenshotResolve:null,
  122. curLayoutStruct:null,//当前户型大类下所有楼层数据-用于提交
  123. overChange:false, //是否形变中
  124. isIOS:false, //是否ios手机。默认不是
  125. currentChangeSpaceId:null, //当前变化的空间id
  126. styleType:1,
  127. sumArea:0, //总面积
  128. changeArea:0, //当次变化的面积
  129. fixedArea:0, //初始面积值
  130. layoutArea:0, //总面积
  131. }
  132. },
  133. beforeDestroy() {
  134. cancelAnimationFrame(requestId, this.canvas)
  135. this.worker && this.worker.terminate()
  136. if (this.renderer instanceof THREE.WebGLRenderer) {
  137. // 遍历场景中的所有子对象,找到类型为Mesh的对象并移除
  138. let deleList = this.scene.children.filter(object=>{
  139. if (object instanceof THREE.Mesh) {
  140. return object
  141. }
  142. })
  143. if(deleList && deleList.length>0){
  144. this.scene.remove(...deleList);
  145. }
  146. this.scene.traverse(function(object) {
  147. if (object instanceof THREE.Mesh) {
  148. if(object.geometry && typeof(object.geometry.dispose)=='function'){
  149. object.geometry.dispose();
  150. }
  151. if(object.material && typeof(object.material.dispose)=='function'){
  152. object.material.dispose();
  153. }
  154. if(object.texture && typeof(object.texture.dispose)=='function'){
  155. object.texture.dispose();
  156. }
  157. }
  158. });
  159. this.renderer.clear();
  160. this.renderer.dispose();
  161. this.renderer.forceContextLoss();
  162. this.renderer.context = null;
  163. this.renderer.domElement = null;
  164. this.renderer = null;;
  165. this.clearEvent()
  166. }
  167. this.gltfWalls = [];
  168. this.gltfSpaces = [];
  169. this.gltfSpaceRoofs = [];
  170. this.gltfLayouts = [];
  171. this.instancedMeshList = [];
  172. this.instancedSpaceMeshList = [];
  173. this.lableItem = [];
  174. this.instancedFurList = [];
  175. this.wallList = [];
  176. TWEEN && TWEEN.removeAll();//清除所有的tween;
  177. console.warn("***beforeDestroy-webgl_rxdz***");
  178. },
  179. mounted() {
  180. console.log("***onLoad-webgl_rxdz***", this.$route.query);
  181. let isIOS = !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
  182. this.isIOS = isIOS;
  183. var that = this;
  184. this.houseId = this.$store.state.houseId || '';
  185. this.childLayout = this.$route.query.childLayout || 0;//4-测试户型
  186. let screenWidth = window.screen.width;
  187. let screenHeight = window.screen.height;
  188. if(window.innerWidth && window.screen.width){
  189. screenWidth = Math.min(window.innerWidth,window.screen.width)
  190. }
  191. if(window.innerHeight && window.screen.height){
  192. screenHeight = Math.min(window.innerHeight,window.screen.height)
  193. }
  194. let unit = screenWidth / 750;//单位rpm 对应 px 的值
  195. that.canvasHeight = screenHeight - (200 * unit) + (20 * unit);
  196. const container = this.$refs.webgl;
  197. const canvas3d = this.canvas = this.$refs.glcanvas;
  198. let camera = null, renderer = null, controls=null;
  199. // let trackballControls = null;
  200. console.warn("***loader0***",this.loader)
  201. let loader = null;
  202. loader = this.loader = new GLTFLoader();
  203. this.getInitData();//请求获取页面模型数据等
  204. let scene = this.scene = new THREE.Scene();
  205. let chooseMesh = this.chooseMesh;//标记鼠标拾取到的mesh
  206. let isUserContorl = false;
  207. let tweenCameraAnma = false; //表示当前是否处在动画过程中
  208. let needRender = false; //是否需要渲染 false表示不需要渲染;true 表示需要渲染
  209. let frustumSize = 30;//正交相机的视窗宽度距离
  210. let stats;
  211. init();
  212. // render();
  213. // this.$refs.myLoading.showLoading("加载中..." + this.progress+"%")
  214. // this.myLoadingStatus = true;
  215. this.progress = 1;
  216. this.clearEvent = clearEvent;
  217. this.attendEvent = attendEvent;
  218. this.updateLables = updateLables;
  219. this.enableRenderHandle = enableRender;
  220. this.tweenCameraAnmaChange = tweenCameraAnmaChange;
  221. this.gradientResize = gradientResize;
  222. this.moveMeshCenterHandle = moveMeshCenterHandle;
  223. this.starRender = starRender;//对外暴露启动渲染的方法
  224. this.stopRender = stopRender;//对外暴露停止渲染的方法
  225. this.cameraInit = cameraInit;
  226. this.resetControl = resetControl;
  227. function init() {
  228. scene.background = new THREE.Color("#FFFFFF");
  229. // scene.environment = new THREE.Color("#F2F2F2");
  230. // 创建相机位置-投影相机
  231. camera = new THREE.PerspectiveCamera( 80, screenWidth / that.canvasHeight, 0.1, 10000 );
  232. // let aspect = screenWidth / that.canvasHeight;
  233. // camera = new THREE.OrthographicCamera( frustumSize * aspect / - 2, frustumSize * aspect / 2, frustumSize / 2, frustumSize / - 2, 0.1,1000);
  234. camera.up.set(0, 1, 0);//俯视状态,将相机的up向量设置为z轴负方向
  235. scene.add(camera);
  236. that.camera = camera;
  237. // 辅助方格
  238. // const axesHelper = new THREE.AxesHelper( 50 );
  239. // scene.add( axesHelper );
  240. // const gridHelper = new THREE.GridHelper(50, 10, 0xcccccc, 0xcccccc);
  241. // gridHelper.position.y = 0;
  242. // gridHelper.position.x = 0;
  243. // scene.add(gridHelper);
  244. // 环境光会均匀的照亮场景中的所有物体
  245. const ambientLight = new THREE.AmbientLight(0xFFEFE0, 3);
  246. scene.add(ambientLight);
  247. //平行光
  248. const light = new THREE.DirectionalLight(0xFFF8E5, 3);
  249. light.position.set(-3, 9, 3); //default; light shining from top
  250. light.castShadow = true; // default false
  251. // 默认情况下光投影相机区域是一个长宽高为10x10x500的长方体区域,光源投射方向为通过坐标原点
  252. light.shadow.camera.left = -100; // default
  253. light.shadow.camera.right = 100; // default
  254. light.shadow.camera.top = 100; // default
  255. light.shadow.camera.bottom = -100; // default
  256. light.shadow.mapSize.width = 8192; // default
  257. light.shadow.mapSize.height = 8192; // default
  258. // light.shadow.camera.near = 0.1; // default
  259. // light.shadow.camera.far = 500; // default
  260. // light.shadow.bias = -0.01;
  261. // light.shadow.radius = 1;
  262. // light.shadow.darkness = 1; // 设置阴影强度为0.5
  263. scene.add(light);
  264. // const helper = new THREE.CameraHelper( light.shadow.camera );
  265. // scene.add(helper);
  266. // 从一个点向各个方向发射的光源。一个常见的例子是模拟一个灯泡发出的光。
  267. // const pointLight = new THREE.PointLight( 0xffffff, 0.3 );
  268. // camera.add( pointLight );
  269. //antialias 这个值得设置为false,不然IOS上截图会失效
  270. renderer = that.renderer = new THREE.WebGLRenderer({
  271. canvas:canvas3d,
  272. alpha: true,
  273. antialias:false,
  274. // 如果想保存three.js canvas画布上的信息,注意设置preserveDrawingBuffer
  275. preserveDrawingBuffer: true,
  276. });
  277. renderer.shadowMap.enabled = true;//产生阴影
  278. renderer.shadowMap.type = THREE.PCFSoftShadowMap; // 阴影属性
  279. renderer.outputEncoding = THREE.sRGBEncoding;
  280. renderer.outputColorSpace = THREE.SRGBColorSpace;
  281. // renderer.toneMappingExposure = 0.1;//色调映射的曝光级别。默认是1
  282. renderer.toneMapping = THREE.NoToneMapping;//色调映射
  283. renderer.physicallyCorrectLights = true;//关键参数,模拟物理光照影响,必须设置为true
  284. renderer.setPixelRatio( window.devicePixelRatio );
  285. renderer.setSize( screenWidth, that.canvasHeight );
  286. container.appendChild( renderer.domElement );
  287. controls = new OrbitControls(camera, renderer.domElement);
  288. controls.screenSpacePanning = true;
  289. controls.enableDamping = true;
  290. controls.minDistance = 1;
  291. controls.maxDistance = 400;
  292. controls.minPolarAngle = 0;// 默认0
  293. controls.maxPolarAngle = Math.PI / 2; // 默认Math.PI,即可以向下旋转到的视角。
  294. controls.target.set(that.controlStarPosition.x, that.controlStarPosition.y, that.controlStarPosition.z);
  295. controls.enableZoom = true;//启用摄像机的缩放
  296. // 监听相机移动事件-限制只能在当前空间范围内移动
  297. // controls.addEventListener('change', () => {
  298. // // 检查相机位置是否超出边界框
  299. // if (camera.position.y < 0) {
  300. // camera.position.y = 0;
  301. // }
  302. // });
  303. // stats = new Stats();
  304. // container.appendChild(stats.dom);
  305. // stats.domElement.style.top = '100px';
  306. attendEvent(); //注册监听事件
  307. starRender(); //启动渲染
  308. cameraInit(); //初始化摄像头
  309. controls.saveState();//保存当前控制器的状态
  310. }
  311. //初始化相机位置
  312. function cameraInit(){
  313. camera.position.set(that.cameraStarPosition.x, that.cameraStarPosition.y, that.cameraStarPosition.z);
  314. camera.lookAt(that.controlStarPosition.x,that.controlStarPosition.y,that.controlStarPosition.z);
  315. }
  316. //初始状态
  317. function resetControl(){
  318. controls.reset();
  319. }
  320. function onWindowResize() {
  321. camera.aspect = screenWidth / that.canvasHeight;
  322. camera.updateProjectionMatrix();
  323. renderer.setSize( screenWidth, that.canvasHeight );
  324. console.warn("****onWindowResize**")
  325. }
  326. function attendEvent () {
  327. window.addEventListener('resize', onWindowResize);
  328. renderer.domElement.addEventListener('touchstart', onPointerStart, false);
  329. renderer.domElement.addEventListener('touchmove', onPointerMove, false);
  330. renderer.domElement.addEventListener('touchend', onPointerUp, false);
  331. }
  332. function tweenCameraAnmaChange (value) {
  333. tweenCameraAnma = value
  334. }
  335. //开启渲染-帧率优化,不触发时停止渲染
  336. function enableRender() {
  337. }
  338. //取消事件监听-避免二次进入时触发多次事件
  339. function clearEvent(){
  340. console.warn("**clearEvent****")
  341. renderer && renderer.domElement && renderer.domElement.removeEventListener('touchstart', onPointerStart);
  342. renderer && renderer.domElement && renderer.domElement.removeEventListener('touchmove', onPointerMove );
  343. renderer && renderer.domElement && renderer.domElement.removeEventListener('touchend', onPointerUp );
  344. }
  345. // 手指移动开始
  346. function onPointerStart(event){
  347. console.log('开始触摸事件:',that.overChange)
  348. if(that.overChange){//形变中,不能相应用户操作
  349. return false;
  350. }
  351. }
  352. //持续触摸中
  353. function onPointerMove( event ) {
  354. if(that.overChange){//形变中,不能相应用户操作
  355. return false;
  356. }
  357. // that.showLables = false;
  358. }
  359. //触摸结束
  360. function onPointerUp(event) {
  361. if(that.overChange){//形变中,不能相应用户操作
  362. return false;
  363. }
  364. // enableRender();
  365. if(event.touches.length==0){
  366. // that.showLables = true;
  367. // updateLables();
  368. }
  369. }
  370. //把摄像机移动的选中模型的正上方,观察点也变更为模型中心点,同时选中模型
  371. function moveMeshCenterHandle(mesh = null,noChangeColor = true){
  372. if(mesh){//如果传入了模型,则取模型
  373. let spaceId = mesh.spaceId;//空间id
  374. if(chooseMesh && spaceId == chooseMesh.spaceId){
  375. console.warn("**moveMeshCenterHandle-重复选中了***")
  376. return false;
  377. }
  378. chooseMesh = mesh;
  379. }
  380. if(!chooseMesh){
  381. console.warn("**moveMeshCenterHandle-没有数据***")
  382. return false;
  383. }
  384. that.showLables = false;//隐藏
  385. // controls.enable = false;//控制器不响应用户的操作
  386. let spaceObj = chooseMesh;//获取空间模型的相关数据
  387. // controls.panTo(spaceObj.centerX/100, camera.position.y, -spaceObj.centerY/100);
  388. let cameraNewPosition ={};
  389. let targetNewPosition ={};
  390. let oldUp = {};
  391. let newUp = {};
  392. if (isUserContorl === false) { // 非漫游状态
  393. cameraNewPosition = {
  394. x:spaceObj.centerX/100,
  395. y:camera.position.y,
  396. z:-spaceObj.centerY/100 + 0.5,//增加偏差,防止极点翻转问题?不知道为啥会有用
  397. }
  398. //新的观察点的位置-取模型的中心点坐标,加上高度,由于模型都是贴地的,所以高度设置为0
  399. targetNewPosition = {
  400. x:spaceObj.centerX/100,
  401. y:0,
  402. z:-spaceObj.centerY/100,
  403. }
  404. oldUp = camera.up;//俯视状态
  405. newUp = camera.up;
  406. // newUp = new THREE.Vector3(0,0,-1);
  407. // that.cameraLastPosition = cameraNewPosition;//记录下上一次摄像头位置
  408. // that.controlLastPosition = targetNewPosition;//记录下上一次观察点位置
  409. // if(cameraNewPosition.x<0){
  410. // cameraNewPosition.x = 0;
  411. // }
  412. }
  413. console.warn("**moveMeshCenter***",isUserContorl,spaceObj,JSON.stringify(camera.position),JSON.stringify(controls.target)
  414. ,cameraNewPosition,targetNewPosition,JSON.stringify(camera.up))
  415. tweenCamera(camera.position,controls.target,cameraNewPosition,targetNewPosition,oldUp,newUp,1000);
  416. setTimeout(()=>{
  417. that.showLables = true;
  418. // camera.up = new THREE.Vector3(0,1,0);
  419. // updateLables();
  420. },1001);//动画结束后回复原始状态
  421. }
  422. // oldP 相机原来的位置
  423. // oldT target原来的位置
  424. // newP 相机新的位置
  425. // newT target新的位置
  426. function tweenCamera(oldP, oldT, newP, newT, oldUp, newUp, time=1000) {
  427. if(JSON.stringify(oldP) == JSON.stringify(newP) && JSON.stringify(oldT) == JSON.stringify(newT)){
  428. return false;
  429. }
  430. if (!chooseMesh) {
  431. return false;
  432. }
  433. tweenCameraAnma = true;
  434. var tween = new TWEEN.Tween({
  435. x1: oldP.x, // 相机x
  436. y1: oldP.y, // 相机y
  437. z1: oldP.z, // 相机z
  438. x2: oldT.x, // 控制点的中心点x
  439. y2: oldT.y, // 控制点的中心点y
  440. z2: oldT.z, // 控制点的中心点z
  441. x3: oldUp.x, // 控制点的中心点x
  442. y3: oldUp.y, // 控制点的中心点y
  443. z3: oldUp.z // 控制点的中心点z
  444. })
  445. .to({
  446. x1: newP.x,
  447. y1: newP.y,
  448. z1: newP.z,
  449. x2: newT.x,
  450. y2: newT.y,
  451. z2: newT.z,
  452. x3: newUp.x, // up向量
  453. y3: newUp.y, // 控制点的中心点y
  454. z3: newUp.z // 控制点的中心点z
  455. }, time)
  456. .easing(TWEEN.Easing.Quadratic.InOut)
  457. .onUpdate((object)=> {
  458. camera.position.x = object.x1;
  459. camera.position.y = object.y1;
  460. camera.position.z = object.z1;
  461. let newTarget = new THREE.Vector3(object.x3,object.y3,object.z3);
  462. camera.up.copy(newTarget);
  463. camera.lookAt(object.x2,object.y2,object.z2);
  464. // controls.target.x = object.x2;
  465. // controls.target.y = object.y2;
  466. // controls.target.z = object.z2;
  467. // controls.update();
  468. // console.warn("****onUpdate**",object.x1,object.y1,object.z1,object.x2,object.y2,object.z2)
  469. }).onComplete(()=>{
  470. controls.target.x = newT.x;
  471. controls.target.y = newT.y;
  472. controls.target.z = newT.z;
  473. //修正最后的视角
  474. let up = new THREE.Vector3(newUp.x,newUp.y,newUp.z);
  475. camera.up.copy(up);
  476. camera.lookAt(controls.target.x,controls.target.y,controls.target.z);
  477. tweenCameraAnma = false;
  478. })
  479. // 开始动画
  480. tween.start();
  481. }
  482. //高度持续变化处理 time 动画持续时间 单位秒
  483. function gradientResize (time,startHeight,endHeight) {
  484. // let _timeStep = 20;//单位 毫秒
  485. // let unit = screenWidth / 750;//单位rpm 对应 px 的值
  486. // that.canvasHeight = screenHeight - (200 * unit) + (20 * unit);
  487. let unit = screenWidth / 750;//单位rpx 对应 px 的值
  488. let _height = startHeight - endHeight;//高度变化-单位rpx
  489. let _jisua = that.canvasHeight;
  490. let lastHeight = _jisua + (_height * unit);//动画结束时的高度值; 单位 px
  491. that.canvasHeight = lastHeight;//触发css动画
  492. // let step = (_height * unit) / (time*1000 / _timeStep);//真实大小 单位px
  493. console.warn("***gradientResize***",lastHeight,_jisua,startHeight,endHeight)
  494. // that.showLables = false;
  495. // let canvas_webgl = document.getElementById('canvas_webgl');
  496. var tween = new TWEEN.Tween({
  497. h1: _jisua,
  498. })
  499. .to({
  500. h1: lastHeight,
  501. }, 1000)
  502. .easing(TWEEN.Easing.Linear.None)
  503. .onUpdate((object)=> {
  504. if(camera.isOrthographicCamera){//正交相机
  505. let aspect = screenWidth / object.h1;
  506. camera.left = frustumSize * aspect / - 2;
  507. camera.right = frustumSize * aspect / 2;
  508. camera.top = frustumSize / 2;
  509. camera.bottom = frustumSize / -2;
  510. camera.updateProjectionMatrix();
  511. // that.canvasHeight = object.h1;
  512. }
  513. else if(camera.isPerspectiveCamera){//透视相机
  514. camera.aspect = screenWidth / object.h1;
  515. camera.updateProjectionMatrix();
  516. renderer.setSize( screenWidth, object.h1 );
  517. // that.canvasHeight = object.h1;
  518. }
  519. }).onComplete(()=>{
  520. camera.aspect = screenWidth / that.canvasHeight;
  521. camera.updateProjectionMatrix();
  522. renderer.setSize( screenWidth, that.canvasHeight );
  523. tweenCameraAnma = false;
  524. // that.showLables = true;
  525. // updateLables();//更新lable
  526. });
  527. // 开始动画
  528. tween.start();
  529. tweenCameraAnma = true;
  530. }
  531. //更新lables
  532. function updateLables(){
  533. if(!that.showLables){
  534. return false;
  535. }
  536. that.lableItem.forEach(lable =>{
  537. if(!that.gltfSpaces[lable.cubeIndex] || !that.gltfSpaces[lable.cubeIndex].instancedMeshIndexList){
  538. return false;
  539. }
  540. let item = that.gltfSpaces[lable.cubeIndex].instancedMeshIndexList[0];//获取地板模型的第一个geometry实例
  541. let _index = item.instancedMeshIndex;//第一个geometry实例 在 全局InstancedMesh实例的位置
  542. let instancedMesh = that.instancedSpaceMeshList[_index];//获取具体的网格实例
  543. let stratMatrix = new THREE.Matrix4();//定义一个四维矩阵
  544. instancedMesh.getMatrixAt(item.instancedAtIndex,stratMatrix);//获取当前几何体的四维矩阵到stratMatrix里面
  545. let position = new THREE.Vector3();//当前几何体的位置参数
  546. position.setFromMatrixPosition(stratMatrix);//从四维向量中提取位置信息
  547. // console.warn("***updateLables***",item.instancedAtIndex,JSON.stringify(position));
  548. position.project(camera);
  549. const x = (position.x * .5 + .5) * screenWidth;
  550. const y = (position.y * -.5 + .5) * that.canvasHeight;
  551. lable.transform = `translate(-50%, -50%) translate(${x}px,${y}px)`;
  552. })
  553. }
  554. function stopRender () {
  555. needRender = false;
  556. }
  557. function starRender () {
  558. if(needRender==true){//如果已经在渲染中了,则不能再次开启,避免渲染过多
  559. false;
  560. }
  561. needRender = true;
  562. render();//开始渲染
  563. }
  564. function render() {
  565. if(needRender==false){
  566. return false;
  567. }
  568. TWEEN && TWEEN.update();
  569. // stats.update();
  570. //不处在动画过程中,则可以处理移动等动作
  571. if(tweenCameraAnma==false){
  572. controls.update();
  573. updateLables();//更新lable
  574. }
  575. requestId = requestAnimationFrame(render, canvas3d);
  576. renderer.render(scene, camera);//单次渲染
  577. if (that.screenshotResolve) {
  578. // if(that.isIOS){//IOS手机
  579. stopRender();
  580. that.screenshotResolve()
  581. that.screenshotResolve = null;//释放Promise
  582. // }else{//安卓手机
  583. // let gl = renderer.getContext();
  584. // let frameBuffer = new THREE.Vector2();
  585. // renderer.getDrawingBufferSize(frameBuffer);
  586. // let pixelData = new Uint8Array(frameBuffer.x * frameBuffer.y * 4);
  587. // //参考 Threejs WebGLRenderer.readRenderTargetPixels
  588. // if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) === gl.FRAMEBUFFER_COMPLETE) {
  589. // gl.readPixels(0, 0, frameBuffer.x, frameBuffer.y, gl.RGBA, gl.UNSIGNED_BYTE, pixelData);
  590. // // 确保有像素,微信小程序安卓在进入子页面返回本页面后,再一次readPixels稳定无像素
  591. // if (pixelData.some(i => i !== 0)) {
  592. // stopRender();
  593. // console.warn("***screenshotResolve-pixelData***");
  594. // that.screenshotResolve([pixelData, frameBuffer.x, frameBuffer.y])
  595. // that.screenshotResolve = null;//释放Promise
  596. // frameBuffer = null;//清空内存中的数据
  597. // pixelData = null;//清空内存中的数据
  598. // }
  599. // }
  600. // }
  601. }
  602. }
  603. },
  604. onShow(){
  605. console.warn("---onShow1---",this.pvId)
  606. if(this.attendEvent){
  607. this.attendEvent()
  608. }
  609. },
  610. onHide(){
  611. this.clearEvent();
  612. },
  613. computed: {
  614. aiData() {
  615. return this.$store.state.aiData;
  616. },
  617. userId() {
  618. return this.$store.state.userId;
  619. },
  620. },
  621. methods: {
  622. voiceMaskChange(voiceMask){
  623. this.voiceMaskShow = voiceMask;
  624. },
  625. //黄山数据处理
  626. hushangHandle(param){
  627. let expand = {};
  628. expand.landImg = this.$route.query.landImg || '';
  629. expand.baseImg = this.$route.query.baseImg || '';
  630. expand.bgPrototypeImg = this.$route.query.bgPrototypeImg || '';
  631. expand.landNo = this.$route.query.landNo || '';//地块
  632. expand.landArea = this.$route.query.landArea || '';//地块面积
  633. expand.buildingAreaPreference = this.$route.query.buildingAreaPreference || '';//建筑面积
  634. expand.layer = this.$route.query.layer || '大平层';//层数
  635. expand.structureName = this.$route.query.structureName || '';//结构-L形等
  636. expand.landDescription = this.$route.query.landDescription || '';//地形地势
  637. expand.scenery = this.$route.query.scenery || '';//景观
  638. expand.structureDescription = this.$route.query.structureDescription || '';//空间特质-结构
  639. setStorage('expand', expand);//把空间选择的数据存入本地缓存里面,方便后续使用
  640. return JSON.stringify(expand);
  641. },
  642. async submitHouse(){
  643. if(this.overChange){
  644. this.$message.warning("空间正在调整");
  645. return false
  646. }
  647. const loading = this.$loading({
  648. lock: true,
  649. text: '提交中...',
  650. spinner: 'el-icon-loading',
  651. background: 'rgba(0, 0, 0, 0.7)'
  652. });
  653. let shottingImg = await this.shottingAction() + "?x-oss-process=image/auto-orient,1/quality,Q_46/format,jpg";//开始截图
  654. console.warn("***shottingImg***",shottingImg);
  655. let userId = this.userId ? this.userId : '';
  656. let param = {
  657. "brandId": $config.brandId,
  658. "houseId": this.curHouseObj.houseId,
  659. "userId": userId,
  660. "floot": this.curHouseObj.houseFloor,
  661. "spaceName": this.curHouseName ,
  662. "spaceStructure": this.curHouseType,
  663. "curFloor":this.curHouseFloor,
  664. // "layoutImgCustomized": shottingImg,
  665. // "style": "",
  666. layoutStruct:[],
  667. }
  668. //处理每一个楼层
  669. this.curLayoutStruct.forEach((layoutStruct,index)=>{
  670. let houseData = {
  671. "layoutId": layoutStruct.id,
  672. "layoutName": layoutStruct.name,
  673. "layoutArea": layoutStruct.houseArea,
  674. "floor": layoutStruct.houseFloor,
  675. "layoutImgCustomized": layoutStruct.houseFloor == this.curHouseFloor ? shottingImg:'',
  676. "style": "",
  677. "houseJson": []
  678. }
  679. let spaceList = JSON.parse(layoutStruct.houseJson);
  680. let styleList = [];
  681. //遍历当前户型下的每一个空间
  682. spaceList.forEach((item)=>{
  683. let space = JSON.parse(JSON.stringify(item));
  684. //找到当前空间对象对应的AI数据对象
  685. let AISpace = null;
  686. AISpace = this.aiData && this.aiData.find(it=>{
  687. return it.houseFloor == layoutStruct.houseFloor && it.spaceId == space.spaceId
  688. });
  689. if(AISpace){
  690. let list = AISpace.aiImagesList.filter(it=>it.checked==true);//过滤选中的
  691. list.forEach(it=>{
  692. styleList.push(it.aiStyleName);
  693. })
  694. list = list.map(it=>{
  695. return it.image
  696. })
  697. space.hardboundEffect = list;
  698. console.warn("submitHouse: ", list,space);
  699. }
  700. let wallList = this.wallList.find(it=>it.id==space.wallId);
  701. if(wallList){//找到当前空间的墙体数据
  702. space.wallList = JSON.stringify(wallList);
  703. }
  704. houseData.houseJson.push(space)
  705. })
  706. //寻找styleList里面出现最多次数的风格
  707. if(styleList && styleList.length>0){
  708. let maxEle = styleList[0];
  709. let maxNum = 1;
  710. styleList.reduce((p,k)=>{
  711. p[k] ? p[k]++ : p[k]=1;
  712. if(p[k] > maxNum){
  713. maxEle = k;
  714. maxNum ++
  715. }
  716. return p;
  717. },{});
  718. houseData.style = maxEle;
  719. }
  720. param.layoutStruct.push(houseData)
  721. })
  722. param.expand = this.hushangHandle()
  723. console.warn("submitHouse-param: ", param);
  724. let trackparam = {
  725. type: 'CLK', //埋点类型
  726. clkId: 'clk_2cmina_23080409', //点击ID
  727. clkName: 'submit_clk', //点击前往的页面名称
  728. clkParams: {
  729. locusName: "数据提交",
  730. postAIData:this.aiData,
  731. }
  732. };
  733. util.trackRequest(trackparam);
  734. let res = await requestConfig("saveCustomizedRecord", param);
  735. loading.close();
  736. if(res && res.success && res.single){//提交成功
  737. let data = {
  738. houseId:this.houseId,
  739. id:res.single,
  740. }
  741. router.push({
  742. name: "webgl_rxdz_customize",
  743. query:data
  744. });
  745. }
  746. },
  747. enableRender(){
  748. this.enableRenderHandle();
  749. },
  750. /**
  751. * 选中墙体触发
  752. */
  753. selectWall(wallIndex){
  754. console.log("index",wallIndex)
  755. if(this.chooseWallMeshColor){
  756. for (let index = 0; index < this.curWallArr.length; index++) {
  757. const element = this.curWallArr[index];
  758. const cube = element.obj;
  759. this.chooseWallMeshColor.convertSRGBToLinear(); // 将颜色值转换为线性颜色值
  760. if(cube && cube.children[0].children[0] && cube.children[0].children[0].material){
  761. cube.children[0].children[0].material.color = this.chooseWallMeshColor;//修改选中模型的颜色-高亮显示 当前选中的模型
  762. }else{//新版逻辑
  763. // element.instancedMeshIndexList.forEach(item=>{
  764. // let _index = item.instancedMeshIndex;
  765. // let instancedMesh = this.instancedMeshList[_index];//网格实例
  766. // instancedMesh.instanceColor.needsUpdate = true;//打开颜色修改开关,不开,颜色是不能修改额
  767. // instancedMesh.setColorAt(item.instancedAtIndex, this.chooseWallMeshColor);//修改这个几何体的颜色
  768. // })
  769. }
  770. }
  771. }
  772. switch (wallIndex) {
  773. case 1:
  774. this.curWallDirection = "N";
  775. break;
  776. case 2:
  777. this.curWallDirection = "S";
  778. break;
  779. case 3:
  780. this.curWallDirection = "W";
  781. break;
  782. case 4:
  783. this.curWallDirection = "E";
  784. break;
  785. }
  786. this.selectedWall(this.curWallDirection)
  787. this.curWallArr = [];
  788. if(wallIndex!=0){
  789. const wallMoveValues = this.curSpaceObj.wallMoveValue;
  790. console.log
  791. const values = JSON.parse(wallMoveValues);
  792. if(this.curWallValue == 150){
  793. this.curWallValue = values[wallIndex-1]
  794. }else{
  795. let wallIndex = 0
  796. switch (this.curWallDirection) {
  797. case "N":
  798. wallIndex = 0;
  799. values[wallIndex] = this.curWallValue;
  800. values[1] = this.curWallValue;
  801. break;
  802. case "S":
  803. wallIndex = 1;
  804. values[wallIndex] = this.curWallValue;
  805. values[0] = this.curWallValue;
  806. break;
  807. case "W":
  808. wallIndex = 2;
  809. values[wallIndex] = this.curWallValue;
  810. values[3] = this.curWallValue;
  811. break;
  812. case "E":
  813. wallIndex = 3;
  814. values[wallIndex] = this.curWallValue;
  815. values[2] = this.curWallValue;
  816. break;
  817. }
  818. }
  819. this.curSpaceObj.wallMoveValue = JSON.stringify(values)
  820. console.log("墙体可移动数据:", this.curSpaceObj.wallMoveValue, this.spaceList);
  821. const wallStatus = this.curSpaceObj.wallStatus || "[false,false,false,false]"
  822. const status = JSON.parse(wallStatus);
  823. this.curWallHidden = status[wallIndex-1]
  824. console.log("当前墙面数据:", wallStatus , status, wallIndex);
  825. const curSpaceGltfWall = this.gltfWalls.filter((item)=>{
  826. return this.curSpaceObj.spaceId == item.spaceId && item.wallDirection == this.curWallDirection
  827. })
  828. if(curSpaceGltfWall.length != 0){
  829. this.curWallArr.push(...curSpaceGltfWall);
  830. }else{
  831. let rightWallD = "";
  832. switch (wallIndex-1) {
  833. case 0:
  834. rightWallD= "S";
  835. break;
  836. case 1:
  837. rightWallD= "N";
  838. break;
  839. case 2:
  840. rightWallD= "E";
  841. break;
  842. case 3:
  843. rightWallD= "W";
  844. break;
  845. }
  846. for (let index = 0; index < this.leftSpaces.length; index++) {
  847. const element = this.leftSpaces[index];
  848. const gltfWall = this.gltfWalls.filter((item)=>{
  849. return element.spaceId == item.spaceId && item.wallDirection == this.curWallDirection
  850. })
  851. if(gltfWall){
  852. this.curWallArr.push(...gltfWall);
  853. }
  854. }
  855. for (let index = 0; index < this.rightSpaces.length; index++) {
  856. const element = this.rightSpaces[index];
  857. const gltfWall = this.gltfWalls.filter((item)=>{
  858. return element.spaceId == item.spaceId && item.wallDirection == rightWallD;
  859. })
  860. if(gltfWall){
  861. this.curWallArr.push(...gltfWall);
  862. }
  863. }
  864. }
  865. for (let index = 0; index < this.curWallArr.length; index++) {
  866. const element = this.curWallArr[index];
  867. const cube = element.obj;
  868. if(cube && cube.children[0].children[0] && cube.children[0].children[0].material){
  869. this.chooseWallMeshColor = cube.children[0].children[0].material.color.clone();
  870. let color = new THREE.Color(0xff0000); // 使用sRGB颜色值
  871. color.convertSRGBToLinear(); // 将颜色值转换为线性颜色值
  872. cube.children[0].children[0].material.color = color;//修改选中模型的颜色-高亮显示 当前选中的模型
  873. }else{//新版逻辑
  874. // element.instancedMeshIndexList.forEach(item=>{
  875. // let _index = item.instancedMeshIndex;
  876. // let instancedMesh = this.instancedMeshList[_index];//网格实例
  877. // this.chooseWallMeshColor = instancedMesh.material.color.clone();;
  878. // let color = new THREE.Color(0xff0000); // 使用sRGB颜色值
  879. // color.convertSRGBToLinear(); // 将颜色值转换为线性颜色值
  880. // instancedMesh.instanceColor.needsUpdate = true;//打开颜色修改开关,不开,颜色是不能修改额
  881. // instancedMesh.setColorAt(item.instancedAtIndex, color);//修改这个几何体的颜色
  882. // })
  883. }
  884. }
  885. }
  886. },
  887. curSpaceSelect(data){
  888. console.warn("***curSpaceSelect***",data);
  889. if(this.selectSpace){
  890. this.changeSpaceColor(this.selectSpace.spaceId,2);//取消上一个空间的颜色
  891. }
  892. let spaceId = data.spaceId;
  893. let space = this.spaceList.find(it=>it.spaceId==spaceId);
  894. this.selectSpace = space;
  895. this.currentChangeSpaceId = spaceId;
  896. this.$store.state.curSpaceId = data.spaceId;
  897. this.changeSpaceColor(data.spaceId,1);//设置选中空间的颜色
  898. this.moveMeshCenter(space);
  899. },
  900. //具体空间面积变化-拖动产生的
  901. //data = {
  902. // spaceId:245,
  903. // area:12, //正负值 单位平方米
  904. // }
  905. curSpaceChange(data){
  906. console.warn("***空间面积变化***",this.overChange,data);
  907. // let changArea = data.isZoomIn ? parseFloat(data.area.toFixed(2)) : -parseFloat(data.area.toFixed(2));
  908. // this.changeArea = changArea;//当次变化的面积,有正负值
  909. // this.sumArea = parseFloat((this.sumArea + changArea).toFixed(2));
  910. this.overChange = true;//变形开始 防止在形变结束前,再次形变
  911. this.currentChangeSpaceId = data.spaceId;
  912. this.$store.state.curSpaceId = data.spaceId;
  913. this.changCurSpaceArea(data);
  914. let space = this.spaceList.find(it=>it.spaceId==this.currentChangeSpaceId);
  915. this.moveMeshCenter(space);
  916. },
  917. // 空间移动,
  918. changCurSpaceArea(data){
  919. console.log("当前户型的核心点", this.curHouseObj.houseCore, this.overChange);
  920. const houseCore = this.curHouseObj.houseCore.split(',');
  921. const coreX = houseCore[0] | 0
  922. const coreY = houseCore[1] | 0
  923. // 根据核心点计算空间所在象限
  924. this.spaces1 = [];
  925. this.spaces2 = [];
  926. this.spaces3 = [];
  927. this.spaces4 = [];
  928. let curSpace = null;
  929. for (let index = 0; index < this.spaceList.length; index++) {
  930. const element = this.spaceList[index];
  931. if(element.centerX > coreX){ // 2 3象限
  932. if(element.centerY > coreY){ // 2象限
  933. console.log(`象限2 ${element}`);
  934. element.quadrant = 2;
  935. this.spaces2.push(element)
  936. }else{// 3象限
  937. console.log(`象限3 ${element}`);
  938. element.quadrant = 3;
  939. this.spaces3.push(element)
  940. }
  941. }else{// 1 4象限
  942. if(element.centerY > coreY){ // 1象限
  943. console.log(`象限1 ${element}`);
  944. element.quadrant = 1;
  945. this.spaces1.push(element)
  946. }else{ // 4象限
  947. console.log(`象限4 ${element}`);
  948. element.quadrant = 4;
  949. this.spaces4.push(element)
  950. }
  951. }
  952. if(element.spaceId == data.spaceId){
  953. curSpace = element;
  954. }
  955. }
  956. console.log("当前space所在象限",data.spaceId, curSpace.spaceId , curSpace.quadrant);
  957. console.log("象限", this.spaces1, this.spaces2, this.spaces3, this.spaces4);
  958. this.calculateSpaceData(curSpace, data)
  959. },
  960. calculateSpaceData(curSpace, data){
  961. let that = this;
  962. this.curSpaceObj = curSpace;
  963. // 计算宽高移动数值
  964. const changeArea = data.area;
  965. const isZoomIn = data.isZoomIn;
  966. const oldArea = (curSpace.spaceWidth / 100) * (curSpace.spaceHeight / 100);
  967. const newArea = oldArea + changeArea * (data.isZoomIn ? 1 : -1);
  968. const sizeScale = Math.sqrt(newArea/oldArea) ;
  969. // 新的宽度
  970. let newWidth = curSpace.spaceWidth * sizeScale;
  971. if(newWidth < curSpace.spaceWidthMin){
  972. newWidth = curSpace.spaceWidthMin
  973. }
  974. if(newWidth > curSpace.spaceWidthMax){
  975. newWidth = curSpace.spaceWidthMax
  976. }
  977. // 新的高度
  978. let newHeight = newArea * 10000 / newWidth;
  979. if(newHeight < curSpace.spaceHeightMin){
  980. newHeight = curSpace.spaceHeightMin
  981. }
  982. if(newHeight > curSpace.spaceHeightMax){
  983. newHeight = curSpace.spaceHeightMax
  984. }
  985. newWidth = newArea * 10000 / newHeight;
  986. let changeWidth = Math.abs(newWidth - curSpace.spaceWidth)
  987. let changeHeight = Math.abs(newHeight - curSpace.spaceHeight)
  988. console.log("变化的尺寸", changeWidth, changeHeight, newWidth, newHeight, curSpace.spaceWidth, curSpace.spaceHeight);
  989. if(curSpace.quadrant == 1){
  990. // 默认往南 往西移动
  991. this.moveSpace(curSpace, 1, 3, isZoomIn, newArea, newWidth, newHeight, changeWidth, changeHeight)
  992. }
  993. if(curSpace.quadrant == 2){
  994. // 默认往南 往西移动
  995. this.moveSpace(curSpace, 1, 4, isZoomIn, newArea, newWidth, newHeight, changeWidth, changeHeight)
  996. }
  997. if(curSpace.quadrant == 3){
  998. // this.selectWall(4);
  999. // // // 移动墙面
  1000. // this.moveSpaceWall(this.curWallDirection, isZoomIn, changeWidth);
  1001. // 默认往南 往东移动
  1002. this.moveSpace(curSpace, 2, 4, isZoomIn, newArea, newWidth, newHeight, changeWidth, changeHeight)
  1003. }
  1004. if(curSpace.quadrant == 4){
  1005. // 默认往南 往西移动
  1006. this.moveSpace(curSpace, 2, 3, isZoomIn, newArea, newWidth, newHeight, changeWidth, changeHeight)
  1007. }
  1008. setTimeout(() => {
  1009. // that.updataPageData();
  1010. that.overChange = false;
  1011. that.callBackFun && that.callBackFun(true);
  1012. // that.calculateLayoutModelSize(); //重新计算家具位置
  1013. that.updateWallModels(); // 替换墙体模型
  1014. that.changeLayoutModel(); // 改变空间模型
  1015. // that.changeLayoutModelState(true); // 显示家具模型
  1016. }, 4200);
  1017. },
  1018. moveSpace(curSpace, directionIndex, directionIndex01, isZoomIn, newArea, newWidth, newHeight, changeWidth, changeHeight){
  1019. let that = this;
  1020. const wallLock = this.currWallLock(directionIndex, curSpace); //南边
  1021. const wallLock01 = this.currWallLock(directionIndex01, curSpace); //东边
  1022. console.log("移动空间", wallLock, wallLock01)
  1023. if(wallLock ==-1 && wallLock01 == -1){
  1024. return this.$message.warning("空间尺寸已锁定");
  1025. }
  1026. let changeValue = changeHeight;
  1027. if(wallLock == -1){
  1028. if(wallLock01 == 0){
  1029. directionIndex01 = directionIndex01 == 4 ? 3 : 4; // 往西移动
  1030. }
  1031. // 南北锁死,重新计算移动的方向
  1032. newWidth = newArea / (curSpace.spaceHeight / 100) * 100
  1033. changeWidth = newWidth / 100 - curSpace.spaceWidth / 100;
  1034. changeWidth = Math.abs(changeWidth * 100);
  1035. directionIndex = directionIndex01; // 往东移动
  1036. changeValue = changeWidth;
  1037. console.log("高度锁死不能拉伸, 宽度变化1",newWidth, directionIndex,curSpace.spaceWidth, curSpace.spaceHeight, changeValue);
  1038. that.selectWall(directionIndex);
  1039. let checkResult = this.checkRightSpace(!isZoomIn, changeWidth, false, curSpace)
  1040. if(!checkResult.result){
  1041. changeWidth = checkResult.newValue
  1042. }
  1043. console.log("宽度达到极限值结果++++++++++++++", checkResult, changeWidth)
  1044. that.moveSpaceWall(that.curWallDirection, isZoomIn, changeWidth);
  1045. // that.autoCreateWall(directionIndex, curSpace)
  1046. return;
  1047. }else{
  1048. if(wallLock == 0){
  1049. directionIndex = directionIndex == 2 ? 1 : 2; // 往北边移动
  1050. }
  1051. if(wallLock01 == -1){
  1052. // 东西锁死,重新计算移动方向
  1053. newHeight = newArea / (curSpace.spaceWidth / 100) * 100
  1054. changeHeight = newHeight / 100 - curSpace.spaceHeight / 100;
  1055. changeHeight = Math.abs(changeHeight * 100);
  1056. changeValue = changeHeight;
  1057. that.selectWall(directionIndex);
  1058. let checkResult = this.checkRightSpace(!isZoomIn, changeHeight, true, curSpace)
  1059. console.log("高度达到极限值结果++++++++++++++", checkResult, changeHeight)
  1060. if(!checkResult.result){
  1061. changeHeight = checkResult.newValue
  1062. }
  1063. that.moveSpaceWall(that.curWallDirection, isZoomIn, changeHeight);
  1064. // 自动补墙逻辑
  1065. // that.autoCreateWall(directionIndex, curSpace);
  1066. return
  1067. }
  1068. if(wallLock01 == 0){
  1069. directionIndex01 = directionIndex01 == 4 ? 3 : 4; // 往西移动
  1070. }
  1071. console.log("要变化的宽度", newWidth, newHeight)
  1072. // 目标宽度
  1073. if(newHeight > curSpace.spaceHeightMax){
  1074. newHeight = curSpace.spaceHeightMax;
  1075. changeHeight = Math.abs(newHeight - curSpace.spaceHeight)
  1076. // 重新计算宽度值
  1077. newWidth = (newArea / (newHeight / 100)) * 100
  1078. changeWidth = (newWidth / 100 - curSpace.spaceWidth / 100) * 100;
  1079. console.log("高度达到最大值,重新计算宽度",newWidth, newHeight, changeWidth, changeHeight)
  1080. }
  1081. if(newHeight < curSpace.spaceHeightMin){
  1082. newHeight = curSpace.spaceHeightMin;
  1083. changeHeight = Math.abs(newHeight - curSpace.spaceHeight)
  1084. // 重新计算宽度值
  1085. newWidth = (newArea / (newHeight / 100)) * 100
  1086. changeWidth = Math.abs((newWidth / 100 - curSpace.spaceWidth / 100) * 100);
  1087. console.log("高度达到最小值,重新计算宽度",newWidth, newHeight, changeWidth, changeHeight)
  1088. }
  1089. if(newWidth > curSpace.spaceWidthMax){
  1090. newWidth = curSpace.spaceWidthMax;
  1091. changeWidth = Math.abs(newWidth - curSpace.spaceWidth)
  1092. // 重新计算宽度值
  1093. newHeight = (newArea / (newWidth / 100)) * 100
  1094. changeHeight = (newHeight / 100 - curSpace.spaceHeight / 100) * 100;
  1095. console.log("宽度达到最大值,重新计算高度",newWidth, newHeight, changeWidth, changeHeight)
  1096. }
  1097. if(newWidth < curSpace.spaceWidthMin){
  1098. newWidth = curSpace.spaceWidthMin;
  1099. changeWidth = Math.abs(newWidth - curSpace.spaceWidth)
  1100. // 重新计算宽度值
  1101. newHeight = (newArea / (newWidth / 100)) * 100
  1102. changeHeight = Math.abs((newHeight / 100 - curSpace.spaceHeight / 100) * 100);
  1103. console.log("宽度达到最小值,重新计算高度",newWidth, newHeight, changeWidth, changeHeight)
  1104. }
  1105. // if(!checkWidth || !checkHeight){
  1106. // return
  1107. // }
  1108. if(changeHeight > 0){
  1109. that.changeSpaces = [];
  1110. that.selectWall(directionIndex);
  1111. let checkResult = this.checkRightSpace(!isZoomIn, changeHeight, true, curSpace)
  1112. console.log("高度达到极限值结果++++++++++++++", checkResult, changeHeight)
  1113. if(!checkResult.result){
  1114. changeHeight = checkResult.newValue
  1115. }
  1116. that.moveSpaceWall(that.curWallDirection, isZoomIn, changeHeight);
  1117. // 自动补墙逻辑
  1118. // that.autoCreateWall(directionIndex, curSpace)
  1119. }
  1120. let timeout = 0
  1121. if(changeWidth > 0 && changeHeight > 0 ){
  1122. timeout = 2100
  1123. }
  1124. console.log("改变尺寸",changeWidth, changeHeight,newWidth, newHeight, timeout, directionIndex, directionIndex01, wallLock, wallLock01)
  1125. if(changeWidth > 0){
  1126. setTimeout(() => {
  1127. that.changeSpaces = [];
  1128. // // 选中墙面
  1129. that.selectWall(directionIndex01);
  1130. // 计算
  1131. let checkResult = this.checkRightSpace(!isZoomIn, changeWidth, false, curSpace)
  1132. if(!checkResult.result){
  1133. changeWidth = checkResult.newValue
  1134. }
  1135. console.log("宽度达到极限值结果++++++++++++++", checkResult, changeWidth)
  1136. // 移动墙面
  1137. that.moveSpaceWall(that.curWallDirection, isZoomIn, changeWidth);
  1138. // 自动补墙逻辑
  1139. // that.autoCreateWall(directionIndex01, curSpace)
  1140. }, timeout);
  1141. }
  1142. }
  1143. },
  1144. currWallLock(direction, curSpace){
  1145. let curDirection = ""
  1146. let faceDirection = ""
  1147. switch (direction) {
  1148. case 1:
  1149. curDirection = "N";
  1150. faceDirection = "S";
  1151. break;
  1152. case 2:
  1153. curDirection = "S";
  1154. faceDirection = "N";
  1155. break;
  1156. case 3:
  1157. curDirection = "W";
  1158. faceDirection = "E";
  1159. break;
  1160. case 4:
  1161. curDirection = "E";
  1162. faceDirection = "W";
  1163. break;
  1164. }
  1165. const wallInfo = this.wallList.find((item)=>{
  1166. let element = JSON.parse(item.wallJson);
  1167. return element.spaceId == curSpace.spaceId;
  1168. })
  1169. let walls = JSON.parse(wallInfo.wallJson).wallData;
  1170. const wall = walls.find((item)=>{ // 当前墙面锁定
  1171. return item.wallDirection==curDirection && item.isLocked=="true"
  1172. })
  1173. const faceWall = walls.find((item)=>{ // 对面墙面锁定
  1174. return item.wallDirection==faceDirection && item.isLocked=="true"
  1175. })
  1176. if(wall){
  1177. if(faceWall){
  1178. return -1 // 当前对面同时锁定
  1179. }
  1180. return 0 // 当前锁定
  1181. }else{
  1182. return 1 // 不锁定,可以移动
  1183. }
  1184. },
  1185. // 排查关联空间是否达到极限值
  1186. checkRightSpace(isZoomIn, changeValue, isNS, curSpace){
  1187. if(changeValue == 0){
  1188. return;
  1189. }
  1190. let n = isZoomIn?1:-1;
  1191. let l = isZoomIn?-1:1;
  1192. let result = true;
  1193. let space = null;
  1194. let newValue = changeValue;
  1195. console.log("排查空间",isZoomIn, changeValue,isNS, this.leftSpaces, this.rightSpaces);
  1196. for (let index = 0; index < this.leftSpaces.length; index++) {
  1197. const element = this.leftSpaces[index];
  1198. // 过滤掉花园判断
  1199. if(element.spaceType == 14 || element.spaceId == curSpace.spaceId){
  1200. continue;
  1201. }
  1202. let newWidth = element.spaceWidth + l * changeValue;
  1203. let newHeight = element.spaceHeight + l * changeValue;
  1204. if(isNS){
  1205. if( newHeight > element.spaceHeightMax || newHeight < element.spaceHeightMin){
  1206. result = false;
  1207. space = element;
  1208. break;
  1209. }
  1210. }else{
  1211. if(newWidth > element.spaceWidthMax || newWidth < element.spaceWidthMin){
  1212. result = false;
  1213. space = element;
  1214. break;
  1215. }
  1216. }
  1217. }
  1218. for (let index = 0; index < this.rightSpaces.length; index++) {
  1219. const element = this.rightSpaces[index];
  1220. // 过滤掉花园判断
  1221. if(element.spaceType == 14){
  1222. console.log("空间排查跳出")
  1223. continue;
  1224. }
  1225. let newWidth = element.spaceWidth + n * changeValue;
  1226. let newHeight = element.spaceHeight + n * changeValue;
  1227. if(isNS){
  1228. if( newHeight > element.spaceHeightMax || newHeight < element.spaceHeightMin){
  1229. result = false;
  1230. space = element;
  1231. const newHeightValue = newHeight > element.spaceHeightMax ? element.spaceHeightMax : element.spaceHeightMin;
  1232. newHeight = newHeightValue - newHeight;
  1233. const newChangeValue = changeValue - newHeight;
  1234. if(newValue > newChangeValue){
  1235. newValue = newChangeValue;
  1236. }
  1237. break;
  1238. }
  1239. }else{
  1240. console.log("排查右边空间",newWidth, element.spaceWidthMax,newWidth, element.spaceWidthMin);
  1241. if(newWidth > element.spaceWidthMax || newWidth < element.spaceWidthMin){
  1242. result = false;
  1243. space = element;
  1244. let newWidthValue = newWidth > element.spaceWidthMax ? element.spaceWidthMax : element.spaceWidthMin
  1245. if(isZoomIn){ // 放大
  1246. if(newWidth>element.spaceWidthMax){ // 关联空间放大时已经是最大,则变化值为0
  1247. newValue = 0
  1248. break;
  1249. }
  1250. }else{
  1251. newWidthValue = newWidth < element.spaceWidthMin ? element.spaceWidthMin : newWidth;
  1252. console.log("排查右边空间2",newWidth, element.spaceWidthMax, element.spaceWidthMin);
  1253. }
  1254. newWidth = newWidthValue - newWidth;
  1255. const newChangeValue = changeValue - newWidth;
  1256. if(newValue > newChangeValue){
  1257. newValue = newChangeValue;
  1258. }
  1259. break;
  1260. }
  1261. }
  1262. }
  1263. if(!result){
  1264. this.$message.warning(`关联空间[${ space && space.spaceName || ''}]达到极限值`);
  1265. }
  1266. return {"result":result,"newValue":newValue}
  1267. },
  1268. checkSpaceSize(isZoomIn, changeWidth, changeHeight){
  1269. console.log("检查尺寸", isZoomIn, changeWidth, changeHeight, this.leftSpaces, this.rightSpaces)
  1270. for (let index = 0; index < this.leftSpaces.length; index++) {
  1271. const element = this.leftSpaces[index];
  1272. if(isZoomIn){
  1273. if(element.spaceWidth + changeWidth > element.spaceWidthMax || element.spaceHeight + changeHeight > element.spaceHeightMax){
  1274. console.log("++++++++++移动空间达到极大值1", element.spaceId, element.spaceWidth + changeWidth > element.spaceWidthMax, element.spaceHeight + changeHeight > element.spaceHeightMax)
  1275. console.log("++++++++++移动空间达到极大值宽", element.spaceWidth, changeWidth, element.spaceWidthMax)
  1276. console.log("++++++++++移动空间达到极大值高", element.spaceHeight, changeHeight, element.spaceHeightMax)
  1277. return false;
  1278. }
  1279. }else{
  1280. if(element.spaceWidth - changeWidth < element.spaceWidthMin || element.spaceHeight - changeHeight < element.spaceHeightMin){
  1281. console.log("++++++++++移动空间达到极小值2", element.spaceId)
  1282. console.log("++++++++++移动空间达到极大值宽", element.spaceWidth, changeWidth, element.spaceWidthMin)
  1283. console.log("++++++++++移动空间达到极大值高", element.spaceHeight, changeHeight, element.spaceHeightMin)
  1284. return false;
  1285. }
  1286. }
  1287. }
  1288. for (let index = 0; index < this.rightSpaces.length; index++) {
  1289. const element = this.rightSpaces[index];
  1290. if(!isZoomIn){
  1291. if(element.spaceWidth - changeWidth < element.spaceWidthMin || element.spaceHeight - changeHeight < element.spaceHeightMin){
  1292. console.log("++++++++++其他空间达到极小值4", element.spaceId)
  1293. console.log("++++++++++移动空间达到极大值宽", element.spaceWidth, changeWidth, element.spaceWidthMin)
  1294. console.log("++++++++++移动空间达到极大值高", element.spaceHeight, changeHeight, element.spaceHeightMin)
  1295. return false;
  1296. }
  1297. }else{
  1298. if(element.spaceWidth + changeWidth > element.spaceWidthMax || element.spaceHeight + changeHeight > element.spaceHeightMax){
  1299. console.log("++++++++++其他空间达到极大值3", element.spaceId)
  1300. console.log("++++++++++移动空间达到极大值宽", element.spaceWidth, changeWidth, element.spaceWidthMax)
  1301. console.log("++++++++++移动空间达到极大值高", element.spaceHeight, changeHeight, element.spaceHeightMax)
  1302. return false;
  1303. }
  1304. }
  1305. }
  1306. return true
  1307. },
  1308. // 新版本空间移动计算
  1309. changeCurSpaceSize(curSpace, changeArea, isZoomIn){
  1310. // 计算当前空间的变化
  1311. // 1.原先面积
  1312. const oldArea = (curSpace.spaceWidth / 100) * (curSpace.spaceHeight / 100);
  1313. const newArea = oldArea + changeArea * isZoomIn;
  1314. const sizeScale = Math.sqrt(newArea/oldArea) ;
  1315. console.log(`新面积:${newArea} 老面积:${oldArea}缩放比例:${sizeScale} 改变的面积:${changeArea} 是否放大:${isZoomIn} 中心点:${curSpace.centerX} ${curSpace.centerX}`);
  1316. console.log(`改变前:尺寸:${curSpace.spaceWidth} ${curSpace.spaceHeight} 中心点:${curSpace.centerX} ${curSpace.centerY}`);
  1317. curSpace.toScaleX = curSpace.spaceWidth * sizeScale / 300 ;
  1318. curSpace.toScaleZ = curSpace.spaceHeight * sizeScale / 300 ;
  1319. if(this.minspace1 && this.minspace1.spaceId == curSpace.spaceId){
  1320. curSpace.toPx = (curSpace.spaceWidth * sizeScale - curSpace.spaceWidth) / 2 / 100 * -1;
  1321. curSpace.toPz = (curSpace.spaceHeight * sizeScale - curSpace.spaceHeight) / 2 / 100 * -1;
  1322. console.log("XXXXXXXX-计算空间变化信息1", curSpace.toScaleX, curSpace.toScaleZ, curSpace.toPx, curSpace.toPz);
  1323. }else if(this.minspace2 && this.minspace2.spaceId == curSpace.spaceId){
  1324. curSpace.toPx = (curSpace.spaceWidth * sizeScale - curSpace.spaceWidth) / 2 / 100;
  1325. curSpace.toPz = (curSpace.spaceHeight * sizeScale - curSpace.spaceHeight) / 2 / 100 * -1;
  1326. console.log("XXXXXXXX-计算空间变化信息2", curSpace.toScaleX, curSpace.toScaleZ, curSpace.toPx, curSpace.toPz);
  1327. }else if(this.minspace3 && this.minspace3.spaceId == curSpace.spaceId){
  1328. curSpace.toPx = (curSpace.spaceWidth * sizeScale - curSpace.spaceWidth) / 2 / 100;
  1329. curSpace.toPz = (curSpace.spaceHeight * sizeScale - curSpace.spaceHeight) / 2 / 100;
  1330. console.log("XXXXXXXX-计算空间变化信息3", curSpace.toScaleX, curSpace.toScaleZ, curSpace.toPx, curSpace.toPz);
  1331. }else if(this.minspace4 && this.minspace4.spaceId == curSpace.spaceId){
  1332. curSpace.toPx = (curSpace.spaceWidth * sizeScale - curSpace.spaceWidth) / 2 / 100 * -1;
  1333. curSpace.toPz = (curSpace.spaceHeight * sizeScale - curSpace.spaceHeight) / 2 / 100;
  1334. console.log("XXXXXXXX-计算空间变化信息4", curSpace.toScaleX, curSpace.toScaleZ, curSpace.toPx, curSpace.toPz);
  1335. }else{
  1336. return
  1337. }
  1338. // 更新数据:
  1339. curSpace.spaceWidth = curSpace.spaceWidth * sizeScale;
  1340. curSpace.spaceHeight = curSpace.spaceHeight * sizeScale;
  1341. curSpace.centerX = curSpace.centerX + curSpace.toPx * 100
  1342. curSpace.centerY = curSpace.centerY + curSpace.toPz * 100
  1343. const spaceIndex = this.spaceList.findIndex((item)=>{
  1344. return item.spaceId == curSpace.spaceId;
  1345. })
  1346. if(spaceIndex!=-1){
  1347. this.spaceList[spaceIndex] = curSpace;
  1348. }
  1349. console.log(`改变后:尺寸:${curSpace.spaceWidth} ${curSpace.spaceHeight} 中心点:${curSpace.centerX} ${curSpace.centerY} `, curSpace.toPx, curSpace.toPz);
  1350. },
  1351. findxxSpace(manSpace,changeArea, xiangxian, isZoomIn){
  1352. if(xiangxian == 1){
  1353. const spaceE = this.spaces1.find((item)=>{
  1354. return item.spaceId == manSpace.eastId;
  1355. })
  1356. const spaceS = this.spaces1.find((item)=>{
  1357. return item.spaceId == manSpace.southId;
  1358. })
  1359. const oldArea = (manSpace.spaceWidth / 100) * (manSpace.spaceHeight / 100);
  1360. const newArea = oldArea + changeArea * isZoomIn;
  1361. const sizeScale = Math.sqrt(newArea/oldArea) ;
  1362. manSpace.toScaleX = manSpace.spaceWidth * sizeScale / 300 ;
  1363. manSpace.toScaleZ = manSpace.spaceHeight * sizeScale / 300 ;
  1364. if(spaceE){
  1365. manSpace.toPx = (manSpace.spaceWidth * sizeScale - manSpace.spaceWidth) / 2 / 100 * -1 + spaceE.toPx * 2;
  1366. console.log("XXXXXXXX东边有空间", manSpace.spaceId, spaceE.toPx)
  1367. }else{
  1368. manSpace.toPx = (manSpace.spaceWidth * sizeScale - manSpace.spaceWidth) / 2 / 100 * -1;
  1369. console.log("XXXXXXXX东边没空间", manSpace.spaceId)
  1370. }
  1371. if(spaceS){
  1372. manSpace.toPz = (manSpace.spaceHeight * sizeScale - manSpace.spaceHeight) / 2 / 100 * -1 + spaceS.toPz * 2;
  1373. console.log("XXXXXXXX南边有空间", manSpace.spaceId, spaceS.toPz)
  1374. }else{
  1375. manSpace.toPz = (manSpace.spaceHeight * sizeScale - manSpace.spaceHeight) / 2 / 100 * -1;
  1376. console.log("XXXXXXXX南边没空间", manSpace.spaceId)
  1377. }
  1378. console.log("XXXXXXXX-前象限1的其他空间", manSpace.spaceId, manSpace.spaceWidth, manSpace.spaceHeight, manSpace.centerX, manSpace.centerY, manSpace.toPx);
  1379. manSpace.spaceWidth = manSpace.spaceWidth * sizeScale;
  1380. manSpace.spaceHeight = manSpace.spaceHeight * sizeScale;
  1381. manSpace.centerX += manSpace.toPx * 100
  1382. manSpace.centerY += manSpace.toPz * 100
  1383. console.log("XXXXXXXX-后象限1的其他空间", manSpace.spaceId, manSpace.spaceWidth, manSpace.spaceHeight, manSpace.centerX, manSpace.centerY);
  1384. const spaceIndex = this.spaceList.findIndex((item)=>{
  1385. return item.spaceId == manSpace.spaceId;
  1386. })
  1387. if(spaceIndex!=-1){
  1388. this.spaceList[spaceIndex] = manSpace;
  1389. }
  1390. const spacesIndex = this.spaces1.findIndex((item)=>{
  1391. return item.spaceId == manSpace.spaceId;
  1392. })
  1393. if(spacesIndex!=-1){
  1394. this.spaces1[spacesIndex] = manSpace;
  1395. }
  1396. }
  1397. if(xiangxian == 2){
  1398. const spaceW = this.spaces2.find((item)=>{
  1399. return item.spaceId == manSpace.westId;
  1400. })
  1401. const spaceS = this.spaces2.find((item)=>{
  1402. return item.spaceId == manSpace.southId;
  1403. })
  1404. const oldArea = (manSpace.spaceWidth / 100) * (manSpace.spaceHeight / 100);
  1405. const newArea = oldArea + changeArea * isZoomIn;
  1406. const sizeScale = Math.sqrt(newArea/oldArea) ;
  1407. manSpace.toScaleX = manSpace.spaceWidth * sizeScale / 300 ;
  1408. manSpace.toScaleZ = manSpace.spaceHeight * sizeScale / 300 ;
  1409. if(spaceW){
  1410. manSpace.toPx = (manSpace.spaceWidth * sizeScale - manSpace.spaceWidth) / 2 / 100 + spaceW.toPx * 2;
  1411. console.log("XXXXXXXX西边有空间", manSpace.spaceId, spaceW.toPx)
  1412. }else{
  1413. manSpace.toPx = (manSpace.spaceWidth * sizeScale - manSpace.spaceWidth) / 2 / 100;
  1414. console.log("XXXXXXXX西边没空间", manSpace.spaceId)
  1415. }
  1416. if(spaceS){
  1417. manSpace.toPz = (manSpace.spaceHeight * sizeScale - manSpace.spaceHeight) / 2 / 100 * -1 + spaceS.toPz * 2;
  1418. console.log("XXXXXXXX南边有空间", manSpace.spaceId, spaceS.toPz)
  1419. }else{
  1420. manSpace.toPz = (manSpace.spaceHeight * sizeScale - manSpace.spaceHeight) / 2 / 100 * -1;
  1421. console.log("XXXXXXXX南边没空间", manSpace.spaceId)
  1422. }
  1423. console.log("XXXXXXXX-前象限2的其他空间", manSpace.spaceId, manSpace.spaceWidth, manSpace.spaceHeight, manSpace.centerX, manSpace.centerY, manSpace.toPx);
  1424. manSpace.spaceWidth = manSpace.spaceWidth * sizeScale;
  1425. manSpace.spaceHeight = manSpace.spaceHeight * sizeScale;
  1426. manSpace.centerX += manSpace.toPx * 100
  1427. manSpace.centerY += manSpace.toPz * 100
  1428. console.log("XXXXXXXX-后象限2的其他空间", manSpace.spaceId, manSpace.spaceWidth, manSpace.spaceHeight, manSpace.centerX, manSpace.centerY);
  1429. const spaceIndex = this.spaceList.findIndex((item)=>{
  1430. return item.spaceId == manSpace.spaceId;
  1431. })
  1432. if(spaceIndex!=-1){
  1433. this.spaceList[spaceIndex] = manSpace;
  1434. }
  1435. const spacesIndex = this.spaces2.findIndex((item)=>{
  1436. return item.spaceId == manSpace.spaceId;
  1437. })
  1438. if(spacesIndex!=-1){
  1439. this.spaces2[spacesIndex] = manSpace;
  1440. }
  1441. }
  1442. if(xiangxian == 3){
  1443. const spaceW = this.spaces3.find((item)=>{
  1444. return item.spaceId == manSpace.westId;
  1445. })
  1446. const spaceN = this.spaces3.find((item)=>{
  1447. return item.spaceId == manSpace.northId;
  1448. })
  1449. const oldArea = (manSpace.spaceWidth / 100) * (manSpace.spaceHeight / 100);
  1450. const newArea = oldArea + changeArea * isZoomIn;
  1451. const sizeScale = Math.sqrt(newArea/oldArea) ;
  1452. manSpace.toScaleX = manSpace.spaceWidth * sizeScale / 300 ;
  1453. manSpace.toScaleZ = manSpace.spaceHeight * sizeScale / 300 ;
  1454. if(spaceW){
  1455. manSpace.toPx = (manSpace.spaceWidth * sizeScale - manSpace.spaceWidth) / 2 / 100 + spaceW.toPx * 2;
  1456. console.log("XXXXXXXX西边有空间", manSpace.spaceId, spaceW.toPx)
  1457. }else{
  1458. manSpace.toPx = (manSpace.spaceWidth * sizeScale - manSpace.spaceWidth) / 2 / 100;
  1459. console.log("XXXXXXXX西边没空间", manSpace.spaceId)
  1460. }
  1461. if(spaceN){
  1462. manSpace.toPz = (manSpace.spaceHeight * sizeScale - manSpace.spaceHeight) / 2 / 100 + spaceN.toPz * 2;
  1463. console.log("XXXXXXXX北边有空间", manSpace.spaceId, spaceN.toPz)
  1464. }else{
  1465. manSpace.toPz = (manSpace.spaceHeight * sizeScale - manSpace.spaceHeight) / 2 / 100;
  1466. console.log("XXXXXXXX北边没空间", manSpace.spaceId)
  1467. }
  1468. console.log("XXXXXXXX-前象限3的其他空间", manSpace.spaceId, manSpace.spaceWidth, manSpace.spaceHeight, manSpace.centerX, manSpace.centerY, manSpace.toPx);
  1469. manSpace.spaceWidth = manSpace.spaceWidth * sizeScale;
  1470. manSpace.spaceHeight = manSpace.spaceHeight * sizeScale;
  1471. manSpace.centerX += manSpace.toPx * 100
  1472. manSpace.centerY += manSpace.toPz * 100
  1473. console.log("XXXXXXXX-后象限3的其他空间", manSpace.spaceId, manSpace.spaceWidth, manSpace.spaceHeight, manSpace.centerX, manSpace.centerY);
  1474. const spaceIndex = this.spaceList.findIndex((item)=>{
  1475. return item.spaceId == manSpace.spaceId;
  1476. })
  1477. if(spaceIndex!=-1){
  1478. this.spaceList[spaceIndex] = manSpace;
  1479. }
  1480. const spacesIndex = this.spaces3.findIndex((item)=>{
  1481. return item.spaceId == manSpace.spaceId;
  1482. })
  1483. if(spacesIndex!=-1){
  1484. this.spaces3[spacesIndex] = manSpace;
  1485. }
  1486. }
  1487. if(xiangxian == 4){
  1488. const spaceE = this.spaces4.find((item)=>{
  1489. return item.spaceId == manSpace.eastId;
  1490. })
  1491. const spaceN = this.spaces4.find((item)=>{
  1492. return item.spaceId == manSpace.northId;
  1493. })
  1494. const oldArea = (manSpace.spaceWidth / 100) * (manSpace.spaceHeight / 100);
  1495. const newArea = oldArea + changeArea * isZoomIn;
  1496. const sizeScale = Math.sqrt(newArea/oldArea) ;
  1497. manSpace.toScaleX = manSpace.spaceWidth * sizeScale / 300 ;
  1498. manSpace.toScaleZ = manSpace.spaceHeight * sizeScale / 300 ;
  1499. if(spaceE){
  1500. manSpace.toPx = (manSpace.spaceWidth * sizeScale - manSpace.spaceWidth) / 2 / 100 * -1 + spaceE.toPx * 2;
  1501. console.log("XXXXXXXX东边有空间", manSpace.spaceId, spaceE.toPx)
  1502. }else{
  1503. manSpace.toPx = (manSpace.spaceWidth * sizeScale - manSpace.spaceWidth) / 2 / 100 * -1;
  1504. console.log("XXXXXXXX东边没空间", manSpace.spaceId)
  1505. }
  1506. if(spaceN){
  1507. manSpace.toPz = (manSpace.spaceHeight * sizeScale - manSpace.spaceHeight) / 2 / 100 + spaceN.toPz * 2;
  1508. console.log("XXXXXXXX北边有空间", manSpace.spaceId, spaceN.toPz)
  1509. }else{
  1510. manSpace.toPz = (manSpace.spaceHeight * sizeScale - manSpace.spaceHeight) / 2 / 100;
  1511. console.log("XXXXXXXX北边没空间", manSpace.spaceId)
  1512. }
  1513. console.log("XXXXXXXX-前象限4的其他空间", manSpace.spaceId, manSpace.spaceWidth, manSpace.spaceHeight, manSpace.centerX, manSpace.centerY, manSpace.toPx);
  1514. manSpace.spaceWidth = manSpace.spaceWidth * sizeScale;
  1515. manSpace.spaceHeight = manSpace.spaceHeight * sizeScale;
  1516. manSpace.centerX += manSpace.toPx * 100
  1517. manSpace.centerY += manSpace.toPz * 100
  1518. console.log("XXXXXXXX-后象限4的其他空间", manSpace.spaceId, manSpace.spaceWidth, manSpace.spaceHeight, manSpace.centerX, manSpace.centerY);
  1519. const spaceIndex = this.spaceList.findIndex((item)=>{
  1520. return item.spaceId == manSpace.spaceId;
  1521. })
  1522. if(spaceIndex!=-1){
  1523. this.spaceList[spaceIndex] = manSpace;
  1524. }
  1525. const spacesIndex = this.spaces4.findIndex((item)=>{
  1526. return item.spaceId == manSpace.spaceId;
  1527. })
  1528. if(spacesIndex!=-1){
  1529. this.spaces4[spacesIndex] = manSpace;
  1530. }
  1531. }
  1532. },
  1533. //空间面积等变更后-同步更新其他数据对象
  1534. updataPageData(){
  1535. let sumArea = 0;
  1536. this.spaceList.forEach(space=>{
  1537. let curSpaceArea = parseFloat((
  1538. (space.spaceWidth * space.spaceHeight) * space.spaceRatio / 10000
  1539. ).toFixed(2));
  1540. sumArea +=curSpaceArea;
  1541. })
  1542. this.changeArea = parseFloat((sumArea - this.fixedArea).toFixed(2));
  1543. this.sumArea = parseFloat(sumArea.toFixed(2));
  1544. let str = JSON.stringify(this.spaceList)
  1545. //更新当前空间对象
  1546. this.curHouseObj.houseJson = str;
  1547. //更新提交的数据
  1548. let layoutStruct = this.curLayoutStruct.find(it=>{
  1549. return it.houseFloor == this.curHouseFloor
  1550. })
  1551. layoutStruct.houseJson = str;
  1552. setStorage('curLayoutStruct', this.curLayoutStruct);//把楼层的数据存入缓存中
  1553. this.currentChangeSpaceId = null;//变化结束后
  1554. console.warn("***curLayoutStruct-updataPageData***",this.changeArea,this.sumArea,this.curHouseFloor,this.curHouseObj,layoutStruct)
  1555. },
  1556. //户型大类发生了变更
  1557. curHouseTypeChange(item){
  1558. this.curHouseType = item.spaceStructure;//当前选中的户型类型-传递给子组件触发具体的户型数据选取
  1559. this.curHouseName = item.spaceName;//当前选中的户型类型名称
  1560. setStorage('curHouseType', this.curHouseType);//把楼层的数据存入缓存中
  1561. setStorage('curHouseName', this.curHouseName);//把楼层的数据存入缓存中
  1562. //获取当前户型大类下的所有户型信息-用于用户提交
  1563. this.curLayoutStruct = this.houseList.find(it=>it.spaceStructure == this.curHouseType).layoutStruct;
  1564. this.curLayoutStruct.forEach(it=>{
  1565. this.layoutArea += it.houseArea
  1566. })
  1567. setStorage('curLayoutStruct', this.curLayoutStruct);//把楼层的数据存入缓存中
  1568. console.warn("***curLayoutStruct***",this.curLayoutStruct)
  1569. },
  1570. //户型楼层发生了变更
  1571. curHouseFloorChange(item){
  1572. let that = this;
  1573. this.curHouseFloor = item.houseFloor;//当前选中的户型楼层
  1574. this.curHouseObj = item;//更新当前具体的户型数据
  1575. this.id = this.curHouseObj.id;
  1576. // 遍历场景中的所有子对象,找到类型为Mesh的对象并移除
  1577. let deleList = that.scene && that.scene.children.filter(object=>{
  1578. if(object.userType=="mesh" || object.userType=="layoutMesh"){
  1579. return object
  1580. }
  1581. })
  1582. // console.warn("***deleList***",deleList)
  1583. if(deleList && deleList.length>0){
  1584. that.showLables = false;//隐藏lable
  1585. that.scene.remove(...deleList);
  1586. }
  1587. this.gltfWalls = [];
  1588. this.gltfSpaces = [];
  1589. this.gltfSpaceRoofs = [];
  1590. this.instancedMeshList = [];
  1591. this.instancedSpaceMeshList = [];
  1592. this.lableItem = [];
  1593. this.gltfLayouts = [];
  1594. this.instancedFurList = [];
  1595. this.wallList = [];
  1596. this.changeArea = 0;
  1597. //恢复初始视角
  1598. this.cameraInit();
  1599. this.resetControl();
  1600. setTimeout(()=>{
  1601. that.loadSpace();
  1602. }, 100);
  1603. console.warn("***curHouseObj***",this.curHouseObj,this.aiData)
  1604. // this.navbar.title = this.curHouseObj.name + " " + this.curHouseObj.houseArea + "㎡";
  1605. this.navbar.title = "空间定制";
  1606. this.sumArea = this.curHouseObj.houseArea;
  1607. this.fixedArea = this.curHouseObj.houseArea;
  1608. },
  1609. async getInitData(){
  1610. let parmas = {
  1611. childLayout:this.childLayout || 0,
  1612. houseId:this.houseId,
  1613. }
  1614. const res = await requestConfig('getHouseTypeSpaceDetailsV2', parmas, true);
  1615. if (res.success && res.list) {
  1616. let list = res.list || [];
  1617. list && list.forEach((single,index)=>{
  1618. single.layoutStruct.forEach((item)=>{
  1619. if(item.houseJson){
  1620. let spaceList = JSON.parse(item.houseJson);
  1621. // 交换centerX, centerY
  1622. for (let index = 0; index < spaceList.length; index++) {
  1623. var element = spaceList[index];
  1624. const {centerX, centerY} = element;
  1625. element.centerX = centerY;
  1626. element.centerY = centerX;
  1627. }
  1628. item.houseJson = JSON.stringify(spaceList);
  1629. }
  1630. })
  1631. })
  1632. console.log("户型详情列表-接口原始数据: ", list);
  1633. this.houseList = list;//数据会同步到组件中-进而反馈更新页面数据
  1634. }
  1635. },
  1636. //进入布局选择模式
  1637. enterPlot(gltf){
  1638. if(gltf.spaceType==13){//楼梯不处理
  1639. return false
  1640. }
  1641. // this.selectSpace = this.spaceList.find(it=>it.spaceId==gltf.spaceId);
  1642. this.$refs.viewShell.changeStyleType(3,this.selectSpace)
  1643. },
  1644. selectSpaceHandle(gltf){
  1645. if(gltf.spaceType==13){//楼梯不处理
  1646. return false
  1647. }
  1648. if(this.selectSpace){
  1649. this.changeSpaceColor(this.selectSpace.spaceId,2);//取消上一个空间的颜色
  1650. }
  1651. this.selectSpace = this.spaceList.find(it=>it.spaceId==gltf.spaceId);
  1652. this.$store.state.curSpaceId = this.selectSpace.spaceId;
  1653. this.currentChangeSpaceId = this.selectSpace.spaceId;
  1654. // this.moveMeshCenter(this.selectSpace);
  1655. this.changeSpaceColor(this.selectSpace.spaceId,1);//设置选中空间的颜色
  1656. console.warn("***selectSpaceHandle***",this.selectSpace)
  1657. },
  1658. //用户选择的布局id-需要切换到这个布局去
  1659. userSelectPlot(layoutObj,space=null){
  1660. if(!layoutObj){
  1661. console.warn("***userSelectPlot***数据错误")
  1662. return false
  1663. }
  1664. let spaceId = space ? space.spaceId : this.selectSpace.spaceId;
  1665. console.warn("***userSelectPlot***",spaceId,layoutObj)
  1666. this.changeSingleLayout(space,layoutObj);
  1667. this.updataLable(spaceId,layoutObj);
  1668. },
  1669. async goRoam1(spaceId){
  1670. let gltf = this.lableItem.find(it=>it.spaceId==spaceId);
  1671. let shottingImg = await this.shottingAction() + "?x-oss-process=image/auto-orient,1/quality,Q_46/format,jpg";//开始截图
  1672. console.warn("***shottingImg***",shottingImg);
  1673. setStorage('shottingImg', shottingImg);//把空间选择的数据存入本地缓存里面,方便后续使用
  1674. this.hushangHandle()
  1675. if(gltf){
  1676. this.goRoam(gltf)
  1677. }
  1678. },
  1679. //物体漫游-切换页面的方式进入
  1680. goRoam(gltf){
  1681. // console.log('是否漫游',this.isManyou ? '漫游' : '俯视',isManyou,this.repeatFlag);
  1682. if(gltf.spaceType==13){//楼梯不能跳转
  1683. return false
  1684. }
  1685. let spaceId = gltf.spaceId;//具体的空间Id
  1686. let data = {
  1687. spaceId:spaceId,
  1688. houseId:this.houseId,
  1689. }
  1690. if(this.repeatFlag){
  1691. return false;
  1692. }
  1693. this.repeatFlag = true;
  1694. router.push({
  1695. name: "webgl_rxdz_roam",
  1696. query:data
  1697. });
  1698. if(this.isIOS){
  1699. setStorage('curHouseObj', this.curHouseObj);
  1700. setStorage('wallList', this.wallList);
  1701. }
  1702. this.$store.dispatch('setCurHouseObj', this.curHouseObj);
  1703. this.$store.dispatch('setWallList', this.wallList);
  1704. setTimeout(()=> {
  1705. this.repeatFlag = false;
  1706. }, 1000);
  1707. },
  1708. //obj 物体对象,type 是否改变颜色
  1709. moveMeshCenter(obj,type){
  1710. console.warn("**moveMeshCenter***",obj)
  1711. if(obj && this.gltfSpaces && this.gltfSpaces.length>0){
  1712. this.moveMeshCenterHandle(obj,type);
  1713. }
  1714. },
  1715. // 绘制地板
  1716. async loadSpace(){
  1717. this.spaceList = [];
  1718. this.wallIds = [];
  1719. this.layoutIds = [];
  1720. this.gltfSpaces = [];
  1721. this.curWallArr = [];
  1722. this.progress = 0;
  1723. if(!this.curHouseObj){//减少重复请求
  1724. return false
  1725. }
  1726. let type=[];
  1727. if(this.curHouseObj){
  1728. const spaceDetail = this.curHouseObj;
  1729. const spaceList = JSON.parse(spaceDetail.houseJson);
  1730. // 交换centerX, centerY;上一页面已经处理过了,这里不在需要处理
  1731. for (let index = 0; index < spaceList.length; index++) {
  1732. var element = spaceList[index];
  1733. // const centerX = JSON.parse(JSON.stringify(element.centerX))
  1734. // element.centerX = element.centerY;
  1735. // element.centerY = centerX;
  1736. element.wallMoveValue = "[0,0,0,0]"
  1737. this.spaceList.push(element);
  1738. this.wallIds.push(element.wallId);
  1739. this.layoutIds.push(element.layoutId);
  1740. type.push(element.spaceType);
  1741. if(element.isSelected){ // 默认选中空间
  1742. this.curSpaceObj = element;
  1743. }
  1744. }
  1745. if(!this.curSpaceObj && this.spaceList.length > 0){
  1746. this.curSpaceObj = this.spaceList[0];
  1747. }
  1748. }
  1749. console.log("该户型空间数据:", this.spaceList, this.layoutIds,type);
  1750. console.log("当前选中的空间:", this.curSpaceObj,this.curHouseObj);
  1751. this.spaceListBackup = JSON.parse(JSON.stringify(this.spaceList));
  1752. this.$store.state.curSpaceId = this.curSpaceObj.spaceId;
  1753. this.loaderSpaceArr(this.spaceList);
  1754. // 绘制墙体
  1755. this.getHouseTypeSpaceWalls();
  1756. },
  1757. //更改空间显示名称 X空间 类型 根据布局所属类型来显示
  1758. updataLable(spaceId,layoutObj){
  1759. let list = this.arrFrunList;
  1760. let lable = this.lableItem.find(it=>it.spaceId == spaceId);
  1761. let name = spaceTypes[layoutObj.type - 1];
  1762. lable.text = name;
  1763. console.warn("***updataLable***",lable)
  1764. this.$refs.viewShell.$refs.viewCareful.updataData(spaceId,layoutObj);
  1765. },
  1766. // 添加文字标签
  1767. addWordLabel(){
  1768. if(!this.gltfSpaces || this.gltfSpaces.length <= 0){
  1769. return false;
  1770. }
  1771. // 方案二
  1772. this.lableItem = [];
  1773. this.gltfSpaces.forEach((cube,index) =>{
  1774. // 给地板加上空间类型标注, 空间为链接空间的不显示
  1775. if(cube.spaceName && !cube.isSizeLock){
  1776. let spaceIndex = this.spaceList.filter(it=>it.spaceName && !it.isSizeLock).findIndex(item=>item.spaceId==cube.spaceId);
  1777. let name = spaceTypes[cube.spaceType - 1];
  1778. if(cube.spaceType==15){ //更改空间显示名称 X空间 类型 根据布局所属类型来显示
  1779. let layoutId = this.spaceList.find(it => it.spaceId == cube.spaceId).layoutId;
  1780. let layout = this.arrFrunList.find(it=>it.id == layoutId);
  1781. if(layout){
  1782. name = spaceTypes[layout.type - 1];
  1783. }
  1784. }
  1785. this.lableItem.push(
  1786. {
  1787. text:name,
  1788. spaceId:cube.spaceId,
  1789. spaceType:cube.spaceType,
  1790. transform:'',
  1791. spaceIndex:spaceIndex,
  1792. cubeIndex:index,
  1793. }
  1794. )
  1795. }
  1796. })
  1797. this.showLables = true;
  1798. // this.updateLables();//更新lable
  1799. },
  1800. // 获取墙体数据
  1801. async getHouseTypeSpaceWalls(){
  1802. let data = {id:this.wallIds}
  1803. const res = await requestConfig('getHouseTypeSpaceWalls', data, true);
  1804. console.log("墙体数据:", res.list)
  1805. let wallList = [];
  1806. if(res.success){
  1807. wallList = this.wallList = res.list;
  1808. }
  1809. let wallArr = []
  1810. for (let index = 0; index < wallList.length; index++) {//每个空间对应一个数据
  1811. let element = JSON.parse(wallList[index].wallJson);
  1812. let space = this.spaceList.find(space=>space.spaceId==element.spaceId);
  1813. this.computeWallHandleOld(space,element);//提前计算
  1814. for (let i = 0; i < element.wallData.length; i ++) {//对应空间里面的4个方向的墙壁数据
  1815. let wallData = element.wallData[i];
  1816. //对应方向的墙壁的墙体模型数据列表,每一面墙可能有多个模型
  1817. for (let j = 0; j < wallData.wallModelData.length; j ++) {
  1818. let wallModelData = wallData.wallModelData[j];
  1819. wallArr.push({spaceId:element.spaceId, wallModelData:wallModelData, wallDirection:wallData.wallDirection})
  1820. // console.log("wallModelData", element,wallData.wallDirection, wallModelData.wallType );
  1821. }
  1822. }
  1823. }
  1824. this.loadSpaceObjWalls(wallArr, wallList);
  1825. this.getOverallArrangementDetailsList(2);
  1826. },
  1827. // 加载单个空间墙体资源
  1828. async loadSpaceObjWalls(wallArr, wallList){
  1829. // 加载远程墙体模型资源
  1830. let startTime = new Date().getTime();
  1831. // console.log("wallArr:", wallArr)
  1832. let promise_list = [];
  1833. let realWallArr = this.preWallData(wallArr);
  1834. let arrLength = realWallArr.length;
  1835. realWallArr && realWallArr.forEach((item,index) => {
  1836. promise_list.push(
  1837. new Promise((resolve, reject) => {
  1838. this.loadWallModels(item, wallList, arrLength , resolve);
  1839. })
  1840. )
  1841. });
  1842. Promise.all(promise_list).then(()=>{
  1843. let endTime = new Date().getTime();
  1844. console.log("模型全部加载完成,时间:",endTime - startTime);
  1845. this.progress = 100;
  1846. // this.$refs.myLoading.showLoading("加载中..." + this.progress + '%')
  1847. // 设置空间数组的墙体信息
  1848. // this.setSpaceListWallInfo();
  1849. this.$nextTick(()=>{
  1850. this.moveMeshCenter(this.curSpaceObj);
  1851. // this.myLoadingStatus = false;
  1852. // this.$refs.myLoading.hideLoading();
  1853. setTimeout(()=>{
  1854. this.addWordLabel(); // 添加文字标签
  1855. }, 610);
  1856. // 设置空间数组的墙体信息
  1857. })
  1858. })
  1859. },
  1860. // 选择墙体
  1861. selectedWall(direction){
  1862. if(!direction || direction==""){
  1863. return
  1864. }
  1865. console.log(`当前空间的id:${this.curSpaceObj.spaceId};墙面方向:${direction};宽度:${this.curSpaceObj.spaceWidth};宽度:${this.curSpaceObj.spaceHeight}`)
  1866. console.log("当前空间的:", this.curSpaceObj);
  1867. this.leftSpaces = [];
  1868. this.rightSpaces = [];
  1869. this.tempSpaceList = JSON.parse(JSON.stringify(this.spaceList));
  1870. // 计算关联空间
  1871. this.findLeftRelateSpace(this.curSpaceObj, direction);
  1872. console.log("空间数组:", this.leftSpaces, this.rightSpaces);
  1873. // 计算墙体的可移动范围
  1874. var min = 0;
  1875. var max = 300;
  1876. // 计算最小值
  1877. for (let index = 0; index < this.leftSpaces.length; index++) {
  1878. const element = this.leftSpaces[index];
  1879. console.log("左边空间数据:", element);
  1880. var spaceMoveNW = element.spaceWidth;
  1881. var spaceMoveSW = element.spaceWidth;
  1882. var spaceMoveEH = element.spaceHeight;
  1883. var spaceMoveWH = element.spaceHeight;
  1884. var curSpaceWall = [];
  1885. for (let index = 0; index < this.gltfWalls.length; index++) {
  1886. const wall = this.gltfWalls[index];
  1887. if(element.spaceId == wall.spaceId && wall.wallDirection != direction){
  1888. curSpaceWall.push(wall);
  1889. if((direction == "W" || direction == "E") && wall.wallDirection != direction){
  1890. if(wall.wallDirection == "N"){
  1891. spaceMoveNW -= wall.wallModelData.wallWidth;
  1892. console.log("北边墙:", spaceMoveNW, wall.wallModelData.wallWidth, wall.id);
  1893. }
  1894. if(wall.wallDirection == "S"){
  1895. spaceMoveSW -= wall.wallModelData.wallWidth;
  1896. console.log("南边墙:", spaceMoveSW, wall.wallModelData.wallWidth, wall.id);
  1897. }
  1898. this.curWallValue = Math.floor(Math.min(Math.min(spaceMoveNW, spaceMoveSW), this.curWallValue));
  1899. }
  1900. if((direction == "N" || direction == "S") && wall.wallDirection != direction){
  1901. if(wall.wallDirection == "E"){
  1902. spaceMoveEH -= wall.wallModelData.wallWidth;
  1903. console.log("东边墙:", spaceMoveNW, wall.wallModelData.wallWidth, wall.id);
  1904. }
  1905. if(wall.wallDirection == "W"){
  1906. spaceMoveWH -= wall.wallModelData.wallWidth;
  1907. console.log("西边墙:", spaceMoveSW, wall.wallModelData.wallWidth, wall.id);
  1908. }
  1909. this.curWallValue = Math.floor(Math.min(Math.min(spaceMoveEH, spaceMoveWH), this.curWallValue));
  1910. }
  1911. }
  1912. }
  1913. // 排序墙体数据
  1914. curSpaceWall.sort(function(a,b){return a.wallModelData.id -b.wallModelData.id});
  1915. curSpaceWall.sort(function(a,b){return a.wallDirection.localeCompare(b.wallDirection)})
  1916. console.log("墙体模型:", curSpaceWall, spaceMoveNW, spaceMoveSW);
  1917. console.log("可缩小的最小值:", Math.floor(Math.min(spaceMoveNW, spaceMoveSW)));
  1918. if((direction == "W" || direction == "E") && element.spaceWidth == this.curWallValue){
  1919. this.curWallValue = 149;
  1920. }
  1921. if((direction == "N" || direction == "S") && element.spaceHeight == this.curWallValue){
  1922. this.curWallValue = 149;
  1923. }
  1924. // this.curWallValue = Math.floor(Math.min(spaceMoveNW, spaceMoveSW));
  1925. }
  1926. // 计算最大值
  1927. for (let index = 0; index < this.rightSpaces.length; index++) {
  1928. const element = this.rightSpaces[index];
  1929. console.log("右边空间数据:", element);
  1930. var spaceMoveNW = element.spaceWidth;
  1931. var spaceMoveSW = element.spaceWidth;
  1932. var spaceMoveEH = element.spaceHeight;
  1933. var spaceMoveWH = element.spaceHeight;
  1934. var curSpaceWall = [];
  1935. for (let index = 0; index < this.gltfWalls.length; index++) {
  1936. const wall = this.gltfWalls[index];
  1937. if(element.spaceId == wall.spaceId && wall.wallDirection != direction){
  1938. curSpaceWall.push(wall);
  1939. if((direction == "W" || direction == "E") && wall.wallDirection != direction){
  1940. if(wall.wallDirection == "N"){
  1941. spaceMoveNW -= wall.wallModelData.wallWidth;
  1942. console.log("北边墙:", spaceMoveNW, wall.wallModelData.wallWidth, wall.id);
  1943. }
  1944. if(wall.wallDirection == "S"){
  1945. spaceMoveSW -= wall.wallModelData.wallWidth;
  1946. console.log("南边墙:", spaceMoveSW, wall.wallModelData.wallWidth, wall.id);
  1947. }
  1948. this.curWallMaxValue = Math.floor(Math.min(spaceMoveNW, spaceMoveSW)) + this.curWallValue;
  1949. }
  1950. if((direction == "N" || direction == "S") && wall.wallDirection != direction){
  1951. if(wall.wallDirection == "E"){
  1952. spaceMoveEH -= wall.wallModelData.wallWidth;
  1953. console.log("东边墙:", spaceMoveNW, wall.wallModelData.wallWidth, wall.id);
  1954. }
  1955. if(wall.wallDirection == "W"){
  1956. spaceMoveWH -= wall.wallModelData.wallWidth;
  1957. console.log("西边墙:", spaceMoveSW, wall.wallModelData.wallWidth, wall.id);
  1958. }
  1959. this.curWallMaxValue = Math.floor(Math.min(spaceMoveEH, spaceMoveWH)) + this.curWallValue;
  1960. }
  1961. }
  1962. }
  1963. // 排序墙体数据
  1964. curSpaceWall.sort(function(a,b){return a.wallModelData.id -b.wallModelData.id});
  1965. curSpaceWall.sort(function(a,b){return a.wallDirection.localeCompare(b.wallDirection)})
  1966. console.log("墙体模型:", curSpaceWall, spaceMoveNW, spaceMoveSW);
  1967. console.log("可缩小的最小值:", Math.floor(Math.min(spaceMoveNW, spaceMoveSW)));
  1968. }
  1969. console.log(`当前墙面的最大值:${this.curWallMaxValue}, 最小值:${this.curWallValue}`)
  1970. // 统计变化的空间
  1971. this.changeSpaces.push(...this.leftSpaces)
  1972. this.changeSpaces.push(...this.rightSpaces)
  1973. },
  1974. // 递归寻找左边->右边关联空间
  1975. findLeftRelateSpace(spaceObj, direction){
  1976. const {eastId, westId, northId, southId, spaceId} = spaceObj;
  1977. const leftIndex = this.tempSpaceList.findIndex((item)=>{
  1978. return item.spaceId == spaceId;
  1979. })
  1980. if(leftIndex!=-1){
  1981. const spaceObj = this.tempSpaceList[leftIndex];
  1982. this.leftSpaces.push(spaceObj);
  1983. this.tempSpaceList.splice(leftIndex,1);
  1984. const leftNextIndex = this.tempSpaceList.findIndex((item)=>{
  1985. if(direction == "E"){
  1986. return item.spaceId == eastId;
  1987. }else if(direction == "W"){
  1988. return item.spaceId == westId;
  1989. }else if(direction == "S"){
  1990. return item.spaceId == southId;
  1991. }else if(direction == "N"){
  1992. return item.spaceId == northId;
  1993. }
  1994. })
  1995. if(leftNextIndex!=-1){
  1996. const nextSpaceObj = this.tempSpaceList[leftNextIndex];
  1997. console.log("递归再一次", nextSpaceObj);
  1998. this.findRightRelateSpace(nextSpaceObj, direction);
  1999. }
  2000. const rightArr = this.tempSpaceList.filter((item)=>{
  2001. if(direction == "E"){
  2002. return item.westId == spaceId;
  2003. }else if(direction == "W"){
  2004. return item.eastId == spaceId;
  2005. }else if(direction == "S"){
  2006. return item.northId == spaceId;
  2007. }else if(direction == "N"){
  2008. return item.southId == spaceId;
  2009. }
  2010. })
  2011. for (let index = 0; index < rightArr.length; index++) {
  2012. const nextSpaceObj = rightArr[index];
  2013. // const nextSpaceObj = this.tempSpaceList[rightNextIndex];
  2014. console.log("递归再一次", nextSpaceObj);
  2015. this.findRightRelateSpace(nextSpaceObj, direction);
  2016. }
  2017. }
  2018. },
  2019. // 递归寻找右边->左边关联空间
  2020. findRightRelateSpace(spaceObj, direction){
  2021. const {eastId, westId, northId, southId, spaceId} = spaceObj;
  2022. const rightIndex = this.tempSpaceList.findIndex((item)=>{
  2023. return item.spaceId == spaceId;
  2024. })
  2025. if(rightIndex!=-1){
  2026. const spaceObj = this.tempSpaceList[rightIndex];
  2027. this.rightSpaces.push(spaceObj);
  2028. this.tempSpaceList.splice(rightIndex,1);
  2029. console.log("当前空间数组:", this.tempSpaceList);
  2030. const leftNextIndex = this.tempSpaceList.findIndex((item)=>{
  2031. if(direction == "E"){
  2032. return item.spaceId == westId;
  2033. }else if(direction == "W"){
  2034. return item.spaceId == eastId;
  2035. }else if(direction == "N"){
  2036. return item.spaceId == southId;
  2037. }else if(direction == "S"){
  2038. return item.spaceId == northId;
  2039. }
  2040. })
  2041. if(leftNextIndex!=-1){
  2042. const nextSpaceObj = this.tempSpaceList[leftNextIndex];
  2043. console.log("递归再一次", nextSpaceObj);
  2044. this.findLeftRelateSpace(nextSpaceObj, direction);
  2045. }
  2046. const rightArr = this.tempSpaceList.filter((item)=>{
  2047. if(direction == "E"){
  2048. return item.eastId == spaceId;
  2049. }else if(direction == "W"){
  2050. return item.westId == spaceId;
  2051. }else if(direction == "N"){
  2052. return item.northId == spaceId;
  2053. }else if(direction == "S"){
  2054. return item.southId == spaceId;
  2055. }
  2056. });
  2057. for (let index = 0; index < rightArr.length; index++) {
  2058. const nextSpaceObj = rightArr[index];
  2059. console.log("递归再一次", nextSpaceObj);
  2060. this.findLeftRelateSpace(nextSpaceObj, direction);
  2061. }
  2062. }
  2063. },
  2064. moveSpaceWall(direction, moveOut, moveValue){
  2065. // let isNS = (direction == "N" || direction == "S")
  2066. // if(!this.checkRightSpace(!moveOut, moveValue, isNS)){
  2067. // return
  2068. // }
  2069. // 隐藏变化空间的家具模型,空间动画结束后显示
  2070. if(moveValue<= 0){ // 无需变化
  2071. return
  2072. }
  2073. this.changeLayoutModelState();
  2074. console.log("关联空间XXXXX", this.leftSpaces, this.rightSpaces)
  2075. for (let index = 0; index < this.leftSpaces.length; index++) {
  2076. const element = this.leftSpaces[index];
  2077. const space = this.spaceList.find((item)=>{
  2078. return item.spaceId == element.spaceId;
  2079. })
  2080. this.moveWall(space, direction, moveOut, moveValue);
  2081. // this.wallTransform(space, direction, moveOut, moveValue);
  2082. }
  2083. let otherdirection = "";
  2084. switch (direction) {
  2085. case "E":
  2086. otherdirection = "W"
  2087. break;
  2088. case "W":
  2089. otherdirection = "E"
  2090. break;
  2091. case "N":
  2092. otherdirection = "S"
  2093. break;
  2094. case "S":
  2095. otherdirection = "N"
  2096. break;
  2097. }
  2098. for (let index = 0; index < this.rightSpaces.length; index++) {
  2099. const element = this.rightSpaces[index];
  2100. this.moveWall(element, otherdirection, !moveOut, moveValue);
  2101. }
  2102. console.log(`当前空间的后id:${this.curSpaceObj.spaceId};墙面方向:${direction};宽度:${this.curSpaceObj.spaceWidth};高度:${this.curSpaceObj.spaceHeight}`)
  2103. },
  2104. // 调整大小
  2105. // direction:方向
  2106. // moveOut:是否外移
  2107. // moveValue: 移动距离
  2108. moveWall(spaceObj, direction, moveOut, moveValue){
  2109. console.log(`移动的空间的id-------:${spaceObj.spaceId};移动方向:${direction};是否外移:${moveOut};移动距离:${moveValue}`)
  2110. const oldSpaceObj = JSON.parse(JSON.stringify(spaceObj))
  2111. const cube = this.gltfSpaces.find((item)=>{
  2112. return item.spaceId == spaceObj.spaceId;
  2113. })
  2114. if(!cube){
  2115. return
  2116. }
  2117. if(!moveOut){
  2118. moveValue = moveValue * -1;
  2119. }
  2120. const {position,scale} = cube;
  2121. // 重新计算缩放 和 位置
  2122. let toScaleX = scale.x;
  2123. let toScaleZ = scale.z;
  2124. let toPx = position.x;
  2125. let toPz = position.z;
  2126. if(direction == 'E' || direction == 'W'){
  2127. let spaceWidth = scale.x * 300;
  2128. toScaleX = (spaceWidth + moveValue) / 300;
  2129. if(direction == 'W'){
  2130. toPx = position.x - moveValue / 2 / 100;
  2131. }else{
  2132. toPx = position.x + moveValue / 2 / 100;
  2133. }
  2134. spaceObj.spaceWidth += moveValue;
  2135. spaceObj.centerX = toPx * 100;
  2136. }
  2137. if(direction == 'N' || direction == 'S'){
  2138. let spaceHeight = scale.z * 300;
  2139. toScaleZ = (spaceHeight + moveValue) / 300;
  2140. if(direction == 'N'){
  2141. toPz = position.z - moveValue / 2 / 100;
  2142. }else{
  2143. toPz = position.z + moveValue / 2 / 100;
  2144. }
  2145. spaceObj.spaceHeight += moveValue;
  2146. spaceObj.centerY = toPz * 100 * -1;
  2147. }
  2148. console.log("curSpaceObj",this.curSpaceObj.spaceId, spaceObj.spaceId, spaceObj.centerX, spaceObj.centerY, toScaleX,toScaleZ,toPx,toPz)
  2149. console.log("当前空间变化后的尺寸",spaceObj.spaceWidth, spaceObj.spaceHeight, spaceObj.spaceId)
  2150. // 更新数据
  2151. const spaceIndex = this.spaceList.findIndex((item)=>{
  2152. return item.spaceId == spaceObj.spaceId;
  2153. })
  2154. if(spaceIndex!=-1){
  2155. this.spaceList[spaceIndex] = spaceObj;
  2156. if(this.curSpaceObj.spaceId == spaceObj.spaceId){
  2157. this.curSpaceObj = spaceObj;
  2158. }
  2159. }
  2160. this.curHouseObj.houseJson = JSON.stringify(this.spaceList);
  2161. //空间动画处理-提取到floorMethod.js中
  2162. this.changeSpacesAnim({spaceId:spaceObj.spaceId,toScaleX,toScaleZ,toPx,toPz,spaceObj})
  2163. // 墙体动画处理
  2164. //// 根据空间尺寸,更新前提数据
  2165. const wallObj = this.wallList.find((item)=>{
  2166. return item.id == spaceObj.wallId;
  2167. })
  2168. const initSpaceObj = this.spaceListBackup.find((item)=>{
  2169. return item.spaceId == spaceObj.spaceId;
  2170. })
  2171. if(wallObj){
  2172. let element = JSON.parse(wallObj.wallJson);
  2173. console.warn("****wallObj**",element)
  2174. this.computeWallHandle(initSpaceObj, spaceObj, element, moveOut, direction); // 重新计算-并把空间的计算结果同步到gltfWalls中
  2175. }
  2176. // 移动墙体
  2177. let curSpaceWall = [];
  2178. for (let index = 0; index < this.gltfWalls.length; index++) {
  2179. const element = this.gltfWalls[index];
  2180. if(spaceObj.spaceId == element.spaceId){
  2181. curSpaceWall.push(element);
  2182. }
  2183. }
  2184. //移动的是西方的墙壁 和 南方的墙壁,该空间的几何体中心则移动变化
  2185. if(direction == 'W' || direction == 'S'){
  2186. spaceObj.rightCenter = true;
  2187. }
  2188. //移动的是东方的墙壁 和 北方的墙壁,该空间的几何体中心则不移动变化
  2189. if(direction == 'E'|| direction == 'N'){
  2190. spaceObj.rightCenter = false;
  2191. }
  2192. spaceObj.direction = direction
  2193. // 排序墙体数据
  2194. curSpaceWall.sort(function(a,b){return a.wallModelData.id -b.wallModelData.id});
  2195. curSpaceWall.sort(function(a,b){return a.wallDirection.localeCompare(b.wallDirection)})
  2196. console.log("移动的墙体:", spaceObj, direction, curSpaceWall);
  2197. // return;
  2198. for (let index = 0; index < curSpaceWall.length; index++) {
  2199. const element = curSpaceWall[index];
  2200. console.log("重新计算墙体-墙体数据:", element, element);
  2201. this.drawModel(element.wallModelData, spaceObj, element, true)
  2202. }
  2203. // }
  2204. },
  2205. // 空隙自动补签逻辑
  2206. autoCreateWall(directionIndex, spaceObj){
  2207. let direction = ""
  2208. switch (directionIndex) {
  2209. case 1:
  2210. direction = "N"
  2211. break;
  2212. case 2:
  2213. direction = "S"
  2214. break;
  2215. case 3:
  2216. direction = "W"
  2217. break;
  2218. case 4:
  2219. direction = "E"
  2220. break;
  2221. default:
  2222. break;
  2223. }
  2224. // 东西墙 检查 南北墙关联空间 南北墙 检查 东西墙关联空间
  2225. if(direction == "E" || direction == "W"){
  2226. if(spaceObj.quadrant == 3 || spaceObj.quadrant == 4){ // 南边空间
  2227. console.log("南北朝向墙自动补齐", this.leftSpaces, this.rightSpaces)
  2228. this.selectedWall("N");
  2229. this.checkIsAutoCreateWall("N", spaceObj)
  2230. this.selectedWall("S");
  2231. this.checkIsAutoCreateWall("S", spaceObj)
  2232. let autoWall = this.gltfAutoWalls.find(item=>{
  2233. return item.spaceId == spaceObj.spaceId ;
  2234. })
  2235. if(autoWall){
  2236. console.log("南北朝向墙自动补齐---", autoWall, this.gltfAutoWalls)
  2237. if(autoWall.wallDirection == "E"){
  2238. autoWall.obj.position.x = (spaceObj.centerX + (spaceObj.spaceWidth / 2) - 5) / 100
  2239. }
  2240. }
  2241. }else{ // 北边关联空间
  2242. }
  2243. }else{
  2244. if(spaceObj.quadrant == 3 || spaceObj.quadrant == 4){ // 南边空间
  2245. console.log("东西朝向墙自动补齐", this.leftSpaces, this.rightSpaces)
  2246. this.selectedWall("E");
  2247. this.checkIsAutoCreateWall("E", spaceObj)
  2248. this.selectedWall("W");
  2249. this.checkIsAutoCreateWall("W", spaceObj)
  2250. }else{ // 北边关联空间
  2251. }
  2252. }
  2253. },
  2254. // 检测是否需要补强
  2255. checkIsAutoCreateWall(direction, spaceObj){
  2256. var that = this;
  2257. // 判断南边墙是否需要补充
  2258. if(this.rightSpaces.length == 0){
  2259. console.log("不需要补墙1", direction, this.gltfAutoWalls)
  2260. return;
  2261. }
  2262. const n = (direction == "S" || direction == "E") ? 1 : -1; // 南北方向计算系数
  2263. console.log("自动补墙", this.leftSpaces, this.rightSpaces);
  2264. let px = 0;
  2265. let pz = 0;
  2266. let sx = 1;
  2267. let sz = 1;
  2268. let rightids = []
  2269. if(spaceObj.quadrant == 3){
  2270. // 左边空间的最大值
  2271. let leftMaxValue = 0;
  2272. for (let index = 0; index < this.leftSpaces.length; index++) {
  2273. const element = this.leftSpaces[index];
  2274. if(direction=="S" || direction == "N"){
  2275. const curvalue = element.centerX + element.spaceWidth / 2
  2276. if(leftMaxValue < curvalue){
  2277. leftMaxValue = curvalue
  2278. }
  2279. }else{
  2280. leftMaxValue += (-element.centerY + element.spaceHeight / 2)
  2281. }
  2282. }
  2283. // rightSpaces右边最大值
  2284. let rightMaxValue = 0;
  2285. for (let index = 0; index < this.rightSpaces.length; index++) {
  2286. const element = this.rightSpaces[index];
  2287. if(direction=="S" || direction == "N"){
  2288. const curvalue = element.centerX + element.spaceWidth / 2
  2289. if(rightMaxValue < curvalue){
  2290. rightMaxValue = curvalue
  2291. }
  2292. }else{
  2293. rightMaxValue += -element.centerY + element.spaceHeight / 2
  2294. }
  2295. rightids.push(element.spaceId)
  2296. }
  2297. // 是否有墙
  2298. const index = this.gltfWalls.findIndex(item=>{
  2299. // console.log("墙面模型", item)
  2300. return spaceObj.spaceId == item.spaceId && item.wallDirection == direction;
  2301. })
  2302. // 有墙,左边墙>右边墙,计算南北墙
  2303. if(index != -1 && leftMaxValue > rightMaxValue && (direction == "S" || direction == "N")){
  2304. console.log("不需要补墙251",index, leftMaxValue, rightMaxValue)
  2305. // 是否补过墙
  2306. const autoWall = this.gltfAutoWalls.find(item=>{
  2307. return item.rightids.indexOf(spaceObj.spaceId) != -1 && item.wallDirection == (direction == "S" ? "N": "S");
  2308. })
  2309. if(autoWall){
  2310. let cube = autoWall.obj;
  2311. if(cube){
  2312. cube.scale.set(0,0,0);
  2313. }
  2314. }
  2315. return
  2316. }
  2317. // 有墙,左边墙>右边墙,计算东西墙
  2318. if(index != -1 && leftMaxValue > rightMaxValue && (direction == "E" || direction == "W")){
  2319. console.log("不需要补墙252",index, leftMaxValue, rightMaxValue, spaceObj.spaceId, direction, this.gltfAutoWalls)
  2320. const autoWall = this.gltfAutoWalls.find(item=>{
  2321. return item.rightids.indexOf(spaceObj.spaceId) != -1 && item.wallDirection == (direction == "E" ? "W": "E");
  2322. })
  2323. if(autoWall){
  2324. let cube = autoWall.obj;
  2325. if(cube){
  2326. cube.scale.set(0,0,0);
  2327. }
  2328. }
  2329. return
  2330. }
  2331. let wallOffset = index != -1 ? -5 : 5;
  2332. console.log("空间最大值", leftMaxValue, rightMaxValue, direction, index);
  2333. const cubeW = Math.abs(leftMaxValue - rightMaxValue);
  2334. if(direction=="S" || direction == "N"){
  2335. px = (Math.min(leftMaxValue, rightMaxValue) + cubeW / 2) / 100
  2336. pz = (-spaceObj.centerY + spaceObj.spaceHeight * n / 2 + wallOffset * n) / 100;
  2337. sx = cubeW / 10 ;
  2338. // 长边有墙
  2339. }else{
  2340. px = (spaceObj.centerX + spaceObj.spaceWidth * n / 2 + wallOffset * n) / 100;
  2341. pz = (Math.max(leftMaxValue, rightMaxValue) - cubeW / 2) / 100
  2342. sz = cubeW / 10;
  2343. }
  2344. }else{
  2345. let leftMinValue = 0;
  2346. for (let index = 0; index < this.leftSpaces.length; index++) {
  2347. const element = this.leftSpaces[index];
  2348. if(direction=="S" || direction == "N"){
  2349. leftMinValue += (element.centerX - element.spaceWidth / 2)
  2350. }else{
  2351. leftMinValue += (-element.centerY + element.spaceHeight / 2)
  2352. }
  2353. }
  2354. // rightSpaces右边最大值
  2355. let rightMinValue = 0;
  2356. for (let index = 0; index < this.rightSpaces.length; index++) {
  2357. const element = this.rightSpaces[index];
  2358. if(direction=="S" || direction == "N"){
  2359. rightMinValue += (element.centerX - element.spaceWidth / 2)
  2360. }else{
  2361. rightMinValue = (-element.centerY + element.spaceHeight / 2)
  2362. }
  2363. rightids.push(element.spaceId)
  2364. }
  2365. const index = this.gltfWalls.findIndex(item=>{
  2366. // console.log("墙面模型", item)
  2367. return spaceObj.spaceId == item.spaceId && item.wallDirection == direction;
  2368. })
  2369. if(index != -1 && leftMinValue < rightMinValue && (direction == "S" || direction == "N")){
  2370. console.log("不需要补墙251")
  2371. return
  2372. }
  2373. if(index != -1 && leftMinValue > rightMinValue && (direction == "E" || direction == "W")){
  2374. console.log("不需要补墙252")
  2375. return
  2376. }
  2377. let wallOffset = index != -1 ? -5 : 5;
  2378. console.log("空间最大值", leftMinValue, rightMinValue);
  2379. const cubeW = Math.abs(leftMinValue - rightMinValue);
  2380. if(leftMinValue > rightMinValue && index == -1 && (direction == "S" || direction == "N")){
  2381. console.log("不需要补墙241", leftMinValue, rightMinValue)
  2382. const autoWall = this.gltfAutoWalls.find(item=>{
  2383. return item.rightids.indexOf(spaceObj.spaceId) != -1 && item.wallDirection == (direction == "S" ? "N": "S");
  2384. })
  2385. if(autoWall){
  2386. let cube = autoWall.obj;
  2387. if(cube){
  2388. cube.scale.set(0,0,0);
  2389. }
  2390. }
  2391. return
  2392. }
  2393. if(leftMinValue < rightMinValue && index == -1 && (direction == "E" || direction == "W")){
  2394. console.log("不需要补墙242", leftMinValue, rightMinValue)
  2395. const autoWall = this.gltfAutoWalls.find(item=>{
  2396. return item.rightids.indexOf(spaceObj.spaceId) != -1 && item.wallDirection == (direction == "W" ? "E": "W");
  2397. })
  2398. if(autoWall){
  2399. let cube = autoWall.obj;
  2400. if(cube){
  2401. cube.scale.set(0,0,0);
  2402. }
  2403. }
  2404. return
  2405. }
  2406. if(direction=="S" || direction == "N"){
  2407. px = (Math.max(leftMinValue, rightMinValue) - cubeW / 2) / 100
  2408. pz = (-spaceObj.centerY + spaceObj.spaceHeight * n / 2 + wallOffset * n) / 100;
  2409. sx = cubeW / 10;
  2410. }else{
  2411. px = (spaceObj.centerX + spaceObj.spaceWidth * n / 2 + wallOffset * n) / 100;
  2412. pz = (Math.max(leftMinValue, rightMinValue) - cubeW / 2) / 100
  2413. sz = cubeW / 10;
  2414. }
  2415. }
  2416. console.log("空间最大值", px, pz, sx, sz, this.gltfAutoWalls);
  2417. // 寻找是否已添加过墙面
  2418. const autoWall = this.gltfAutoWalls.find(item=>{
  2419. return (item.spaceId == spaceObj.spaceId && item.wallDirection == direction)
  2420. || (item.rightids.findIndex(it=>{ return it == spaceObj.spaceId})!=-1 && item.wallDirection == direction == "S"?"N":"S")
  2421. || (item.rightids.findIndex(it=>{ return it == spaceObj.spaceId})!=-1 && item.wallDirection == direction == "E"?"W":"E")
  2422. })
  2423. if(this.curWallDirection == "S"){
  2424. if(spaceObj.southId > 0){
  2425. return
  2426. }
  2427. }
  2428. if(this.curWallDirection == "E"){
  2429. if(spaceObj.eastId > 0){
  2430. return
  2431. }
  2432. }
  2433. if(this.curWallDirection == "N"){
  2434. if(spaceObj.northId > 0){
  2435. return
  2436. }
  2437. }
  2438. if(this.curWallDirection == "W"){
  2439. if(spaceObj.westId > 0){
  2440. return
  2441. }
  2442. }
  2443. if(autoWall){
  2444. console.log("修改补墙的信息", px, pz, sx, sz);
  2445. let cube = autoWall.obj;
  2446. cube.position.set(px,0,pz);
  2447. cube.scale.set(sx,1,sz);
  2448. }else{
  2449. console.log("添加补墙的信息", px, pz, sx, sz);
  2450. that.loader.load(wallType[0].url, ( gltf ) => {
  2451. let cube = gltf.scene;
  2452. cube.position.set(px,0,pz);
  2453. cube.scale.set(sx,1,sz);
  2454. that.scene.add(cube);
  2455. let md = {
  2456. obj:cube,
  2457. wallDirection:direction,
  2458. spaceId:spaceObj.spaceId,
  2459. quadrant:spaceObj.quadrant,
  2460. rightids:rightids
  2461. };
  2462. that.gltfAutoWalls.push(md);
  2463. // console.log("模型加载成功", that.gltfAutoWalls, spaceObj.spaceId);
  2464. });
  2465. }
  2466. },
  2467. // 墙体缩放逻辑
  2468. wallTransform(spaceObj, direction, moveOut, moveValue){
  2469. console.log(`移动的空间的id:${spaceObj.spaceId};移动方向:${direction};是否外移:${moveOut};移动距离:${moveValue}`)
  2470. },
  2471. updateWallModels(){
  2472. let that = this;
  2473. console.log("开始替换墙体模型", this.leftSpaces, this.rightSpaces, this.gltfWalls);
  2474. let promise_list = [];
  2475. // const gltfWalls = JSON.parse(JSON.stringify(this.gltfWalls))
  2476. this.gltfWalls.forEach((item,index) => {
  2477. promise_list.push(
  2478. new Promise((resolve, reject) => {
  2479. this.loadChangeWallModels(item, resolve);
  2480. })
  2481. )
  2482. });
  2483. Promise.all(promise_list).then(()=>{
  2484. this.$nextTick(()=>{
  2485. let newArr = [];
  2486. const newWalls = that.gltfWalls.filter(it=>{
  2487. return !it.isDidWall
  2488. })
  2489. that.gltfWalls = newWalls;
  2490. console.log("加载完成2",newWalls, newArr, that.gltfWalls, that.wallList);
  2491. })
  2492. })
  2493. },
  2494. }
  2495. }
  2496. </script>
  2497. <style lang="scss" scoped>
  2498. @import "./webgl_rxdz.scss";
  2499. </style>