webgl_rxdz.vue 95 KB

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