webgl_rxdz_test.vue 111 KB

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