webgl_rxdz.vue 94 KB

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