@eturnity/eturnity_3d 6.29.0 → 6.29.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,46 +1,10 @@
1
- import {mapState, mapGetters } from 'vuex'
1
+ import { mapState, mapGetters } from 'vuex'
2
+ import renderMixin from './render'
3
+ import cameraMixin from './cameraMixin'
2
4
  import * as THREE from 'three'
3
- import TWEEN from 'tween'
4
- import {
5
- maximumGapLimit,
6
- colorArrayBase,
7
- } from '../config'
8
- import {
9
- addVector,
10
- multiplyVector,
11
- verticalProjectionOnPlane,
12
- } from '@eturnity/eturnity_maths'
13
- import {
14
- getBufferWallGeometry,
15
- updateBufferWallGeometry,
16
- getBufferRoofGeometry,
17
- updateBufferRoofGeometry,
18
- getBufferObstacleGeometry,
19
- getBufferObstacleSideGeometry,
20
- getBufferModuleFieldGeometry,
21
- getBufferPanelGeometry,
22
- updateBufferPanelGeometry,
23
- getBufferPanelSideGeometry,
24
- updateBufferPanelSideGeometry,
25
- getBufferRoofMarginGeometry
26
- } from './geometryHandler'
27
- import ProjectedMaterial from 'three-projected-material'
28
- import { material } from './materials'
29
- import { intersectOutlines } from '@eturnity/eturnity_maths'
30
- import clearThreeObjects from './clearThreeObjects'
31
- const meshTypes = [
32
- 'baseMeshes',
33
- 'roofMeshes',
34
- 'flatRoofMeshes',
35
- 'obstacleMeshes',
36
- 'panelsMeshes',
37
- 'nodeMeshes',
38
- 'edgeMeshes',
39
- 'roofMarginMeshes',
40
- 'moduleFieldsMeshes'
41
- ]
42
5
 
43
6
  export default {
7
+ mixins: [renderMixin, cameraMixin],
44
8
  data() {
45
9
  return {
46
10
  meshes: {
@@ -57,7 +21,7 @@ export default {
57
21
  lastTic: new Date().getTime() * 1e4,
58
22
  //lastTic:(new Date()).getTime()
59
23
  lastGeometryEventIdDone: -1,
60
- backgroundImagesizeInMm:null,
24
+ backgroundImagesizeInMm: null
61
25
  }
62
26
  },
63
27
  created() {
@@ -72,7 +36,7 @@ export default {
72
36
  roofMarginMeshes: {},
73
37
  moduleFieldsMeshes: {}
74
38
  }
75
- if(this.wallColor){
39
+ if (this.wallColor) {
76
40
  let wallColor = new THREE.Color(this.wallColor)
77
41
  this.material.wall.color.set(wallColor)
78
42
  }
@@ -80,7 +44,8 @@ export default {
80
44
 
81
45
  computed: {
82
46
  ...mapState({
83
- moduleTextureVersionId: (state) => state.threeDModule.moduleTextureVersionId,
47
+ moduleTextureVersionId: (state) =>
48
+ state.threeDModule.moduleTextureVersionId,
84
49
  wallColor: (state) => state.threeDModule.wallColor,
85
50
  selectedMapLayer: (state) => state.threeDModule.selectedMapLayer,
86
51
  pvDataMemo: (state) => state.threeDModule.pvDataMemo
@@ -89,13 +54,13 @@ export default {
89
54
  selectedTool: 'getSelectedTool',
90
55
  roofs: 'getRoofs',
91
56
  lastGeometryEventId: 'getLastGeometryEventId',
92
- roofsBounds:'getRoofsBounds',
57
+ roofsBounds: 'getRoofsBounds',
93
58
  geometryEvents: 'getGeometryEvents'
94
59
  }),
95
- layerKey(){
96
- if(this.selectedMapLayer){
60
+ layerKey() {
61
+ if (this.selectedMapLayer) {
97
62
  return this.selectedMapLayer.key
98
- }else{
63
+ } else {
99
64
  return null
100
65
  }
101
66
  },
@@ -139,8 +104,7 @@ export default {
139
104
  this.renderMethods(methodList)
140
105
  }
141
106
  }
142
-
143
-
107
+
144
108
  this.lastGeometryEventIdDone = this.lastGeometryEventId
145
109
  },
146
110
  renderingMethodsByEvent(geometryEvent) {
@@ -245,13 +209,13 @@ export default {
245
209
  arg: []
246
210
  })
247
211
  break
248
- case 'clearPanelFromChangingRoofs':
249
- methodList.push({
250
- name: 'clearPanelsFromChangingRoofs',
251
- method: this.clearPanelsFromChangingRoofs,
252
- arg: [params.roofIds]
253
- })
254
- break
212
+ case 'clearPanelFromChangingRoofs':
213
+ methodList.push({
214
+ name: 'clearPanelsFromChangingRoofs',
215
+ method: this.clearPanelsFromChangingRoofs,
216
+ arg: [params.roofIds]
217
+ })
218
+ break
255
219
  }
256
220
  return methodList
257
221
  },
@@ -276,675 +240,33 @@ export default {
276
240
  this.renderFlatRoofs()
277
241
  },
278
242
 
279
- renderBackground() {
280
- if(!this.background_map){
281
- this.initialiseThreeMap()
282
- }
283
- },
284
- applyTextureOnRoofs(){
285
- this.roofs.forEach(roof=>{
243
+ applyTextureOnRoofs() {
244
+ this.roofs.forEach((roof) => {
286
245
  //roofs
287
- let mesh=this.meshes.roofMeshes[roof.id]
288
- mesh.material=this.material.roof
289
- if(this.material.roof && this.material.roof.project){
246
+ let mesh = this.meshes.roofMeshes[roof.id]
247
+ mesh.material = this.material.roof
248
+ if (this.material.roof && this.material.roof.project) {
290
249
  this.material.roof.project(mesh)
291
250
  }
292
251
  //obstacle on roof
293
- roof.holes.filter(p=>p.layer=="obstacle").forEach(obstacle=>{
294
- let meshObstacle=this.meshes.obstacleMeshes[obstacle.id + '-' + roof.id + '_top']
295
- meshObstacle.material=this.material.roof
296
- if(this.material.roof && this.material.roof.project) this.material.roof.project(meshObstacle)
297
- })
298
- })
299
- },
300
- renderBase() {
301
- //rendering of walls
302
- //this.clearByType('baseMeshes')
303
- this.clearRemovedOnes('baseMeshes')
304
- let geometry
305
- let mesh
306
- this.roofs.forEach((roofPolygon) => {
307
- //everythime the essencials data are changed, version goes up. we compare polygon version and mesh version to know if we have to rerender
308
- if (
309
- this.meshes.baseMeshes[roofPolygon.id] &&
310
- this.meshes.baseMeshes[roofPolygon.id].userData.version <
311
- roofPolygon.version
312
- ) {
313
- //this.clearMesh(this.meshes.baseMeshes[roofPolygon.id])
314
- mesh = this.meshes.baseMeshes[roofPolygon.id]
315
- geometry = mesh.geometry
316
- geometry = updateBufferWallGeometry(roofPolygon, geometry)
317
- mesh.geometry = geometry
318
- mesh.updateMatrix()
319
- }
320
- if (!this.meshes.baseMeshes[roofPolygon.id]) {
321
- //create
322
- geometry = getBufferWallGeometry(roofPolygon)
323
- mesh = new THREE.Mesh(geometry, this.material.wall)
324
- mesh.userData.version = roofPolygon.version
325
- mesh.userData.type = 'baseMeshes'
326
- mesh.userData.meshId = roofPolygon.id
327
- mesh.userData.polygonId = roofPolygon.id
328
- mesh.matrixAutoUpdate = false
329
- mesh.frustumCulled = false
330
- //geometry.dispose()
331
- //geometry=null
332
- this.scene.add(mesh)
333
- this.meshes.baseMeshes[roofPolygon.id] = mesh
334
- }
335
- })
336
- },
337
- updateRoofGeometry(geometry, roofPolygon) {
338
- const roofOutline = roofPolygon.outline
339
- let cropedHolesOutline = roofPolygon.holes
340
- .filter((h) => h.layer == 'obstacle')
341
- .map((h) => {
342
- //let's crop obstacle with roof outline
343
- const cropedHoleOutline =
344
- intersectOutlines(h.outline, roofPolygon.outline)[0] || []
345
- const outline = cropedHoleOutline.map((p) => {
346
- return {
347
- x: p.x,
348
- y: p.y,
349
- z: verticalProjectionOnPlane(
350
- p,
351
- roofPolygon.normalVector,
352
- roofPolygon.flatOutline[0]
353
- ).z
354
- }
252
+ roof.holes
253
+ .filter((p) => p.layer == 'obstacle')
254
+ .forEach((obstacle) => {
255
+ let meshObstacle =
256
+ this.meshes.obstacleMeshes[obstacle.id + '-' + roof.id + '_top']
257
+ meshObstacle.material = this.material.roof
258
+ if (this.material.roof && this.material.roof.project)
259
+ this.material.roof.project(meshObstacle)
355
260
  })
356
- return outline
357
- })
358
-
359
- cropedHolesOutline = cropedHolesOutline.filter((outline) => !!outline)
360
- geometry = updateBufferRoofGeometry(
361
- roofOutline,
362
- cropedHolesOutline,
363
- geometry
364
- )
365
-
366
- return geometry
367
- },
368
- createRoofGeometry(roofPolygon) {
369
- const roofOutline = roofPolygon.outline
370
- let cropedHolesOutline = roofPolygon.holes
371
- .filter((h) => h.layer == 'obstacle')
372
- .map((h) => {
373
- //let's crop obstacle with roof outline
374
- const cropedHoleOutline =
375
- intersectOutlines(h.outline, roofPolygon.outline)[0] || []
376
- const outline = cropedHoleOutline.map((p) => {
377
- return {
378
- x: p.x,
379
- y: p.y,
380
- z: verticalProjectionOnPlane(
381
- p,
382
- roofPolygon.normalVector,
383
- roofPolygon.flatOutline[0]
384
- ).z
385
- }
386
- })
387
- return outline
388
- })
389
-
390
- cropedHolesOutline = cropedHolesOutline.filter((outline) => !!outline)
391
- let geometry = getBufferRoofGeometry(roofOutline, cropedHolesOutline)
392
-
393
- return geometry
394
- },
395
- renderRoofs() {
396
- this.clearRemovedOnes('roofMeshes')
397
- this.roofs.forEach((roofPolygon) => {
398
- let mesh
399
- let geometry
400
- if (
401
- this.meshes.roofMeshes[roofPolygon.id] &&
402
- this.meshes.roofMeshes[roofPolygon.id].userData.version <
403
- roofPolygon.version
404
- ) {
405
- //update mesh
406
- mesh = this.meshes.roofMeshes[roofPolygon.id]
407
- geometry = mesh.geometry
408
- geometry = this.updateRoofGeometry(geometry, roofPolygon)
409
- mesh.geometry = geometry
410
- if(this.material.roof){
411
- mesh.material=this.material.roof
412
- if(this.material.roof && this.material.roof.project) this.material.roof.project(mesh)
413
- }
414
- mesh.frustumCulled = false
415
- mesh.updateMatrix()
416
- }
417
- if (!this.meshes.roofMeshes[roofPolygon.id]) {
418
- //create
419
- geometry = this.createRoofGeometry(roofPolygon)
420
- if (geometry) {
421
- mesh = new THREE.Mesh(geometry, this.material.roof)
422
- mesh.userData.version = roofPolygon.version
423
- mesh.userData.type = 'roofMeshes'
424
- mesh.userData.meshId = roofPolygon.id
425
- mesh.userData.polygonId = roofPolygon.id
426
- mesh.matrixAutoUpdate = false
427
- this.scene.add(mesh)
428
- if(this.material.roof){
429
- mesh.material=this.material.roof
430
- if(this.material.roof.project) this.material.roof.project(mesh)
431
- }
432
- mesh.frustumCulled = false
433
- this.meshes.roofMeshes[roofPolygon.id] = mesh
434
- }
435
- }
436
- })
437
- },
438
- renderFlatRoofs() {
439
- //this.clearRemovedOnes('flatRoofMeshes')
440
- this.clearByType('flatRoofMeshes')
441
- this.roofs.forEach((roofPolygon) => {
442
- //if(this.meshes.flatRoofMeshes[roofPolygon.id])
443
- if(roofPolygon.maximumGap < maximumGapLimit) return
444
- let geometry = getBufferRoofGeometry(roofPolygon.flatOutline)
445
- if (geometry) {
446
- const material =this.material.curvedRoof
447
- const mesh = new THREE.Mesh(geometry, material)
448
- geometry.dispose()
449
- geometry = null
450
- mesh.itemData = roofPolygon
451
- mesh.frustumCulled = false
452
- this.scene.add(mesh)
453
- this.meshes.flatRoofMeshes[roofPolygon.id] = mesh
454
- }
455
261
  })
456
262
  },
457
- renderRoofsMargin() {
458
- this.clearByType('roofMarginMeshes')
459
263
 
460
- if (this.selectedTool == 'selectMargin') {
461
- this.roofs.forEach((roofPolygon) => {
462
- const geometries = getBufferRoofMarginGeometry(roofPolygon)
463
-
464
- geometries.forEach((geometry, index) => {
465
- if (geometry) {
466
- const marginColor = roofPolygon.margins.isSameMargin
467
- ? colorArrayBase[0]
468
- : colorArrayBase[index % colorArrayBase.length]
469
- let material = new THREE.MeshPhongMaterial({
470
- color: marginColor,
471
- specular: 0x009900,
472
- shininess: 0,
473
- flatShading: true,
474
- side: THREE.DoubleSide,
475
- transparent: true,
476
- opacity: 0.8
477
- })
478
- const mesh = new THREE.Mesh(geometry, material)
479
- geometry.dispose()
480
- this.scene.add(mesh)
481
- this.meshes.roofMarginMeshes[roofPolygon.id + '_' + index] = mesh
482
- }
483
- })
484
- roofPolygon.holes.forEach((obstaclePolygon) => {
485
- const geometries = getBufferRoofMarginGeometry(
486
- obstaclePolygon,
487
- roofPolygon
488
- )
489
- geometries.forEach((geometry, index) => {
490
- if (geometry) {
491
- const marginColor = obstaclePolygon.margins.isSameMargin
492
- ? colorArrayBase[0]
493
- : colorArrayBase[index % colorArrayBase.length]
494
- let material = new THREE.MeshPhongMaterial({
495
- color: marginColor,
496
- specular: 0x009900,
497
- shininess: 0,
498
- flatShading: true,
499
- side: THREE.DoubleSide,
500
- transparent: true,
501
- opacity: 0.8
502
- })
503
- const mesh = new THREE.Mesh(geometry, material)
504
- geometry.dispose()
505
- geometry = null
506
- material.dispose()
507
- material = null
508
- this.scene.add(mesh)
509
- this.meshes.roofMarginMeshes[
510
- obstaclePolygon.id + '_' + roofPolygon.id + '_' + index
511
- ] = mesh
512
- }
513
- })
514
- })
515
- })
516
- }
517
- },
518
- renderNodes() {
519
- let geometry
520
- if (this.meshes.nodeMeshes) {
521
- geometry = this.meshes.nodeMeshes.geometry
522
- geometry.attributes.position.needsUpdate = true
523
- } else {
524
- geometry = new THREE.BufferGeometry()
525
- }
526
- // let geometry = new THREE.SphereGeometry(node3DRadius, 4, 4)
527
- const vertices = []
528
- this.nodes
529
- .filter((node) => node.layer == 'roof')
530
- .forEach((node) => {
531
- vertices.push(node.x / 1000, node.y / 1000, node.z / 1000)
532
- })
533
-
534
- if (
535
- geometry.attributes.position &&
536
- geometry.attributes.position.array.length <= vertices.length
537
- ) {
538
- let positions = geometry.attributes.position.array
539
- for (let k in vertices) {
540
- positions[k] = vertices[k]
541
- }
542
- geometry.setDrawRange(0, vertices.length / 3)
543
- } else {
544
- geometry.setAttribute(
545
- 'position',
546
- new THREE.Float32BufferAttribute(vertices, 3)
547
- )
548
- }
549
- let material = this.material.node
550
- const nodeMeshes = new THREE.Points(geometry, material)
551
- nodeMeshes.userData.version = 0
552
- nodeMeshes.userData.type = 'nodeMeshes'
553
- nodeMeshes.userData.meshId = null
554
- nodeMeshes.userData.polygonId = null
555
- nodeMeshes.matrixAutoUpdate = false
556
- this.meshes.nodeMeshes = nodeMeshes
557
- this.scene.add(nodeMeshes)
558
-
559
- },
560
- renderEdges() {
561
- this.clearEdgesRemovedOnes('edgeMeshes')
562
- let cylinder
563
- //this.clearByType('edgeMeshes')
564
- // const material = new THREE.LineBasicMaterial( { color: beamColor,transparent:true,opacity:beamOpacity ,sizeAttenuation: true} );
565
- // material.linewidth=5
566
- const material = this.material.edge
567
- this.edges
568
- .filter((edge) => edge.layer == 'roof')
569
- .forEach((edge) => {
570
- cylinder = this.meshes.edgeMeshes[edge.id]
571
- if (cylinder) {
572
- //update
573
- const point_0 = new THREE.Vector3(
574
- edge.outline[0].x / 1000,
575
- edge.outline[0].y / 1000,
576
- edge.outline[0].z / 1000
577
- )
578
- const point_1 = new THREE.Vector3(
579
- edge.outline[1].x / 1000,
580
- edge.outline[1].y / 1000,
581
- edge.outline[1].z / 1000
582
- )
583
- const midPoint = point_0.clone().add(point_1).multiplyScalar(0.5)
584
- var direction = new THREE.Vector3().subVectors(point_1, point_0)
585
- let length = direction.length()
586
- //cylinder.rotation.set(arrow.rotation)
587
- var axis = new THREE.Vector3(0, 1, 0)
588
- cylinder.quaternion.setFromUnitVectors(
589
- axis,
590
- direction.clone().normalize()
591
- )
592
- //cylinder.position.set(new THREE.Vector3().addVectors( pointX, direction.multiplyScalar(0.5) ))
593
- cylinder.position.copy(midPoint.clone())
594
- let oldLength = cylinder.userData.cylinderLength
595
- let newLength = length
596
- if (oldLength != 0) {
597
- let scaleRatio = newLength / oldLength
598
- //let scaleVector=direction.multiplyScalar(scaleRatio-1)
599
- cylinder.scale.set(1, newLength, 1)
600
- cylinder.userData.cylinderLength = newLength
601
- }
602
- cylinder.updateMatrix()
603
- //change cylinder length
604
- } else {
605
- const point_0 = new THREE.Vector3(
606
- edge.outline[0].x / 1000,
607
- edge.outline[0].y / 1000,
608
- edge.outline[0].z / 1000
609
- )
610
- const point_1 = new THREE.Vector3(
611
- edge.outline[1].x / 1000,
612
- edge.outline[1].y / 1000,
613
- edge.outline[1].z / 1000
614
- )
615
-
616
- const midPoint = point_0.clone().add(point_1).multiplyScalar(0.5)
617
- var direction = new THREE.Vector3().subVectors(point_1, point_0)
618
- let length = direction.length()
619
- const geometry = new THREE.CylinderGeometry(0.1, 0.1, 1, 6)
620
- cylinder = new THREE.Mesh(geometry, material)
621
- cylinder.scale.set(1, length, 1)
622
- cylinder.userData.cylinderLength = length
623
- //cylinder.rotation.set(arrow.rotation)
624
- var axis = new THREE.Vector3(0, 1, 0)
625
- cylinder.quaternion.setFromUnitVectors(
626
- axis,
627
- direction.clone().normalize()
628
- )
629
- //cylinder.position.set(new THREE.Vector3().addVectors( pointX, direction.multiplyScalar(0.5) ))
630
- cylinder.position.copy(midPoint.clone())
631
- //cylinder.position.set(edge.outline[0].x/1000, edge.outline[0].y/1000, edge.outline[0].z/1000);
632
- cylinder.userData.edgeId = edge.id
633
- cylinder.matrixAutoUpdate = false
634
- this.meshes.edgeMeshes[edge.id] = cylinder
635
- this.scene.add(cylinder)
636
-
637
- }
638
- })
639
- },
640
-
641
- renderObstacles() {
642
- this.clearByType('obstacleMeshes')
643
-
644
- this.roofs.forEach((roofPolygon) => {
645
- roofPolygon.holes
646
- .filter((poly) => poly.layer == 'obstacle')
647
- .forEach((obstaclePolygon) => {
648
- const geometry = getBufferObstacleGeometry(
649
- obstaclePolygon,
650
- roofPolygon
651
- )
652
-
653
- const geometrySide = getBufferObstacleSideGeometry(
654
- obstaclePolygon,
655
- roofPolygon
656
- )
657
- if (geometry && geometrySide) {
658
- const mesh = new THREE.Mesh(geometry, this.material.roof)
659
- const meshSide = new THREE.Mesh(geometrySide, material.wall)
660
- geometry.dispose()
661
- geometrySide.dispose()
662
- if(this.material.roof){
663
- mesh.material=this.material.roof
664
- if(this.material.roof.project) this.material.roof.project(mesh)
665
- }
666
- mesh.matrixAutoUpdate = false
667
- meshSide.matrixAutoUpdate = false
668
- mesh.frustumCulled = false
669
- meshSide.frustumCulled = false
670
- this.scene.add(mesh)
671
- this.scene.add(meshSide)
672
- this.meshes.obstacleMeshes[
673
- obstaclePolygon.id + '-' + roofPolygon.id + '_top'
674
- ] = mesh
675
- this.meshes.obstacleMeshes[
676
- obstaclePolygon.id + '-' + roofPolygon.id + '_side'
677
- ] = meshSide
678
- }
679
- })
680
- })
681
- },
682
- renderModuleFields() {
683
- this.clearByType('moduleFieldsMeshes')
684
-
685
- this.moduleFields.forEach((moduleFieldPolygon) => {
686
- if(!moduleFieldPolygon.data.number_of_panels_override && !this.areModuleFieldsVisible )return
687
- const geometry = getBufferModuleFieldGeometry(moduleFieldPolygon)
688
- if (geometry) {
689
- const mesh = new THREE.Mesh(geometry, this.material.moduleField)
690
- geometry.dispose()
691
- mesh.matrixAutoUpdate = false
692
- mesh.userData.version = moduleFieldPolygon.version
693
- mesh.userData.type = 'moduleFieldsMeshes'
694
- mesh.userData.meshId = moduleFieldPolygon.id
695
- mesh.userData.polygonId = moduleFieldPolygon.id
696
- this.scene.add(mesh)
697
- this.meshes.moduleFieldsMeshes[moduleFieldPolygon.id] = mesh
698
- }
699
- })
700
- },
701
- clearPanelsFromChangingRoofs(roofIds){
702
- const roofs=this.polygons.filter(polygon=>roofIds.includes(polygon.id))
703
- roofs.forEach(roof=>roof.moduleFields.forEach(mf=>mf.panels.forEach(panel=>{
704
- let meshTop=this.meshes.panelsMeshes[panel.id+'_top']
705
- let meshSide=this.meshes.panelsMeshes[panel.id+'_side']
706
- if(meshTop || meshSide){
707
- this.clearMesh(meshTop)
708
- this.clearMesh(meshSide)
709
- }
710
- })
711
- )
712
- )
713
- },
714
- renderPanels() {
715
- this.clearRemovedOnes('panelsMeshes')
716
- Object.values(this.meshes.panelsMeshes).forEach((mesh) => {
717
- //clear UserDeactivatedModules
718
- if (
719
- this.polygons.find(
720
- (poly) =>
721
- poly.id == mesh.userData.polygonId &&
722
- poly.layer == 'user_deactivated_panel'
723
- )
724
- ) {
725
- this.clearMesh(mesh)
726
- }
727
- //clear panel on moduleField with overriden number of panel
728
- let panel=this.polygons.find(poly=>mesh.userData.polygonId==poly.id)
729
- if (
730
- !panel || panel.moduleField.data.number_of_panels_override
731
- ) {
732
- this.clearMesh(mesh)
733
- }
734
- })
735
-
736
- this.panels.forEach((panelPolygon) => {
737
- //definition of the material
738
- if(panelPolygon.moduleField.data.number_of_panels_override) return
739
- let material = this.material.panel['default_'+this.moduleTextureVersionId]
740
- if (panelPolygon.moduleField.pvData) {
741
- let pvId = panelPolygon.moduleField.pvData.id
742
- if (this.material.panel[pvId]) {
743
- material = this.material.panel[pvId]
744
- }
745
- }else if(panelPolygon.moduleField.data){
746
- let pvId = panelPolygon.moduleField.data.component_id_pv_module
747
- if (this.material.panel[pvId]) {
748
- material = this.material.panel[pvId]
749
- }
750
- }
751
-
752
- if (
753
- !this.meshes.panelsMeshes[panelPolygon.id + '_top'] ||
754
- !this.meshes.panelsMeshes[panelPolygon.id + '_side']
755
- ) {
756
- const geometry = getBufferPanelGeometry(panelPolygon)
757
- const geometrySide = getBufferPanelSideGeometry(panelPolygon)
758
-
759
- if (geometry && geometrySide) {
760
-
761
- const mesh = new THREE.Mesh(geometry, material)
762
- const meshSide = new THREE.Mesh(geometrySide, this.material.wall)
763
- mesh.userData.version = panelPolygon.version
764
- mesh.userData.type = 'panelsMeshes'
765
- mesh.userData.meshId = panelPolygon.id + '_top'
766
- mesh.userData.polygonId = panelPolygon.id
767
- meshSide.userData.version = panelPolygon.version
768
- meshSide.userData.type = 'panelsMeshes'
769
- meshSide.userData.meshId = panelPolygon.id + '_side'
770
- meshSide.userData.polygonId = panelPolygon.id
771
- geometry.dispose()
772
- geometrySide.dispose()
773
- this.scene.add(mesh)
774
- this.scene.add(meshSide)
775
- mesh.matrixAutoUpdate = false
776
- meshSide.matrixAutoUpdate = false
777
- this.meshes.panelsMeshes[panelPolygon.id + '_top'] = mesh
778
- this.meshes.panelsMeshes[panelPolygon.id + '_side'] = meshSide
779
- }
780
- }else{
781
- const topMesh=this.meshes.panelsMeshes[panelPolygon.id + '_top']
782
- const sideMesh=this.meshes.panelsMeshes[panelPolygon.id + '_side']
783
- if(panelPolygon.version>topMesh.userData.version){
784
- topMesh.geometry=updateBufferPanelGeometry(panelPolygon,topMesh.geometry)
785
- sideMesh.geometry=updateBufferPanelSideGeometry(panelPolygon,sideMesh.geometry)
786
- }
787
- topMesh.material= material
788
-
789
- }
790
- })
791
- },
792
- async updateProjectionMaterial(){
264
+ async updateProjectionMaterial() {
793
265
  await this.loadProjectionMaterial()
794
266
  this.applyTextureOnRoofs()
795
267
  this.renderBackground()
796
268
  },
797
- async loadProjectionMaterial() {
798
- const _this=this
799
- if(!this.layoutSettings.base64_image_url)
800
- {
801
- this.loader.load(require("../assets/images/white_tile.png"),(texture)=>{
802
- let projectionMaterial = new ProjectedMaterial({
803
- camera: _this.cameraprojection,
804
- texture: texture
805
- })
806
- this.material.roof = projectionMaterial
807
- })
808
- return
809
- }
810
- let projectedMaterialLoaded= await new Promise((resolve,reject) => {
811
- this.loader.load(this.layoutSettings.base64_image_url,(texture)=>{
812
- let backgroundImageZoomLvl=_this.layoutSettings.map_zoom
813
- let backgroundImageCenter={
814
- lat:_this.layoutSettings.layout_latitude,
815
- lng:_this.layoutSettings.layout_longitude
816
- }
817
- if(_this.layoutSettings.background_map_settings){
818
- backgroundImageZoomLvl=_this.layoutSettings.background_map_settings.zoom_lvl
819
- backgroundImageCenter={
820
- lat:_this.layoutSettings.background_map_settings.lat,
821
- lng:_this.layoutSettings.background_map_settings.lng
822
- }
823
- }
824
- _this.backgroundImagesizeInMm=_this.layoutSettings.background_map_settings.sizeInMm
825
- if (_this.backgroundImagesizeInMm) {
826
- _this.cameraprojection.aspect =
827
- _this.backgroundImagesizeInMm.width / _this.backgroundImagesizeInMm.height
828
- let projectionAltitude =
829
- _this.backgroundImagesizeInMm.height /
830
- (2 * Math.tan((_this.cameraprojection.fov * Math.PI) / 360))
831
-
832
269
 
833
- //set projection camera over background_map_center
834
- let cameraProjectionPosition={x:0,y:0,z:projectionAltitude / 1000}
835
- if(_this.layoutSettings.background_map_settings && _this.layoutSettings.background_map_settings.positionInMm){
836
- // let averageLat=(_this.layoutSettings.layout_latitude+_this.layoutSettings.background_map_settings.lat)/2
837
- // let deltaLat=_this.layoutSettings.background_map_settings.lat-_this.layoutSettings.layout_latitude
838
- // let deltaLng=_this.layoutSettings.background_map_settings.lng-_this.layoutSettings.layout_longitude
839
- // let {x:x_mm,y:y_mm}=deltaLatLngToDistance(deltaLat,deltaLng,averageLat)
840
- let positionInMm=this.layoutSettings.background_map_settings.positionInMm
841
- cameraProjectionPosition.x=positionInMm.x/1000
842
- cameraProjectionPosition.y=positionInMm.y/1000
843
- }
844
-
845
- _this.cameraprojection.position.set(cameraProjectionPosition.x, cameraProjectionPosition.y, projectionAltitude / 1000)
846
- _this.cameraprojection.far = projectionAltitude * 16
847
- _this.cameraprojection.updateProjectionMatrix()
848
- }
849
-
850
- let projectionMaterial = new ProjectedMaterial({
851
- camera: _this.cameraprojection,
852
- texture: texture
853
- })
854
- resolve(projectionMaterial)
855
- })
856
- })
857
- this.material.roof =projectedMaterialLoaded
858
- },
859
- setCameraGlobalPosition() {
860
- if(this.roofs.length==0)return
861
- let bounds=this.roofsBounds
862
- let targetVector={x:(bounds.xMax+bounds.xMin)/2000,y:(bounds.yMax+bounds.yMin)/2000,z:0}
863
- let objectRadius_m=Math.max((bounds.xMax-bounds.xMin)/2000,(bounds.yMax-bounds.yMin)/2000)
864
- let distance =
865
- 5 + objectRadius_m / Math.sin(((this.camera.fov / 2) * Math.PI) / 180)
866
- let cameraMoveVector = { x: 0, y: 0, z: distance }
867
- const positionVector = addVector(targetVector, cameraMoveVector)
868
- const position = [
869
- positionVector.x,
870
- positionVector.y - distance,
871
- positionVector.z
872
- ]
873
- let target=[
874
- targetVector.x,
875
- targetVector.y,
876
- targetVector.z
877
- ]
878
-
879
- this.setTweenTo(position,target)
880
- },
881
- setCameraOrthogonalTo(polygon) {
882
- if (polygon) {
883
- let polygonRef = polygon
884
- const targetVector = polygonRef.meanPoint
885
- const target = [
886
- targetVector.x / 1000,
887
- targetVector.y / 1000,
888
- targetVector.z / 1000
889
- ]
890
- const positionVector = addVector(
891
- polygonRef.meanPoint,
892
- multiplyVector(45000, polygonRef.normalVector)
893
- )
894
- const position = [
895
- positionVector.x / 1000,
896
- positionVector.y / 1000 - 1,
897
- positionVector.z / 1000
898
- ]
899
- this.setTweenTo(position,target)
900
- }
901
- },
902
- setCameraSideTo(polygon) {
903
- if (polygon) {
904
- let polygonRef = polygon
905
- const targetVector = polygonRef.meanPoint
906
- const target = [
907
- targetVector.x / 1000,
908
- targetVector.y / 1000,
909
- targetVector.z / 1000
910
- ]
911
- let sideVector={x:-Math.cos((polygonRef.direction+45)*Math.PI/180),y:Math.sin((polygonRef.direction+45)*Math.PI/180),z: 0}
912
- const positionVector = addVector(
913
- polygonRef.meanPoint,
914
- multiplyVector(45000, sideVector)
915
- )
916
- const position = [
917
- positionVector.x / 1000,
918
- positionVector.y / 1000,
919
- positionVector.z / 1000 +5
920
- ]
921
- this.setTweenTo(position,target)
922
- }
923
- },
924
- setTweenTo(position,target){
925
- if (this.orbitControl) {
926
- this.tweenOrbit = new TWEEN.Tween(this.orbitControl.target)
927
- .to({ x: target[0], y: target[1], z: target[2] }, 2000)
928
- .easing(TWEEN.Easing.Sinusoidal.Out)
929
- .onUpdate(() => {
930
- if(this.orbitControl){
931
- this.orbitControl.update()
932
- }
933
- })
934
- .start()
935
- }
936
- if (this.camera) {
937
- this.tweenCamera = new TWEEN.Tween(this.camera.position)
938
- .to({ x: position[0], y: position[1], z: position[2] }, 2000)
939
- .easing(TWEEN.Easing.Sinusoidal.Out)
940
- .onUpdate(() => {
941
- if(this.orbitControl){
942
- this.orbitControl.update()
943
- }
944
- })
945
- .start()
946
- }
947
- },
948
270
  getCanvasOffset() {
949
271
  if (!this.$refs.canvas3DContainer) return { top: 0, left: 0 }
950
272
  var box = this.$refs.canvas3DContainer.getBoundingClientRect()
@@ -992,94 +314,6 @@ export default {
992
314
  // update any render target sizes here
993
315
  }
994
316
  canvas = null
995
- },
996
- clearMesh(mesh) {
997
- if (!mesh) return
998
- this.scene.remove(mesh)
999
- if (mesh.geometry && mesh.geometry.dispose) {
1000
- mesh.geometry.dispose()
1001
- mesh.geometry = null
1002
- }
1003
- if (mesh.material && mesh.material.dispose) {
1004
- mesh.material.dispose()
1005
- mesh.material = null
1006
- }
1007
- if (
1008
- mesh.userData.meshId &&
1009
- this.meshes[mesh.userData.type][mesh.userData.meshId]
1010
- ) {
1011
- delete this.meshes[mesh.userData.type][mesh.userData.meshId]
1012
- } else {
1013
- this.meshes[mesh.userData.type] = null
1014
- }
1015
- mesh = null
1016
- },
1017
- clearEdgesRemovedOnes() {
1018
- Object.values(this.meshes['edgeMeshes']).forEach((mesh) => {
1019
- if (!this.edgeIds.includes(mesh.userData.edgeId)) {
1020
- this.clearMesh(mesh)
1021
- }
1022
- })
1023
- },
1024
- clearNodesRemovedOnes() {
1025
- Object.values(this.meshes['nodeMeshes']).forEach((mesh) => {
1026
- if (!this.nodeIds.includes(mesh.userData.nodeId)) {
1027
- this.clearMesh(mesh)
1028
- }
1029
- })
1030
- },
1031
- clearRemovedOnes(type) {
1032
- Object.values(this.meshes[type]).forEach((mesh) => {
1033
- if (!this.polygonIds.includes(mesh.userData.polygonId)) {
1034
- this.clearMesh(mesh)
1035
- }
1036
- })
1037
- },
1038
- clearByType(type) {
1039
- Object.values(this.meshes[type]).forEach((mesh) => {
1040
- mesh.geometry.dispose()
1041
- mesh.geometry = null
1042
- if (mesh.material.dispose) {
1043
- mesh.material.dispose()
1044
- }
1045
- mesh.material = null
1046
- this.scene.remove(mesh)
1047
- })
1048
- this.meshes[type] = {}
1049
- this.renderer.renderLists.dispose()
1050
- },
1051
- loadNewTexture(){
1052
- Object.values(this.pvDataMemo).forEach((component) => {
1053
- const pvId = component.id
1054
- if (!this.material.panel[pvId]) {
1055
- if (!component.texture_img_url) {
1056
- this.material.panel[pvId] = this.material.panel.default
1057
- } else {
1058
- let texture = this.loader.load(component.texture_img_url)
1059
- this.material.panel[pvId] = new THREE.MeshBasicMaterial({
1060
- map: texture,
1061
- side: THREE.DoubleSide
1062
- })
1063
- }
1064
- }
1065
- })
1066
- },
1067
- async loadTextureFromModuleFields(){
1068
- for(let k=0;k<this.moduleFields.length;k++){
1069
- let mf=this.moduleFields[k]
1070
- const pvId = mf.data.component_id_pv_module
1071
- if (!this.material.panel[pvId]) {
1072
- if (!mf.data.texture_img_url) {
1073
- this.material.panel[pvId] = this.material.panel.default
1074
- } else {
1075
- let texture = await this.loader.load(mf.data.texture_img_url)
1076
- this.material.panel[pvId] = new THREE.MeshBasicMaterial({
1077
- map: texture,
1078
- side: THREE.DoubleSide
1079
- })
1080
- }
1081
- }
1082
- }
1083
317
  }
1084
318
  },
1085
319
  watch: {
@@ -1092,8 +326,8 @@ export default {
1092
326
  this.loadNewTexture()
1093
327
  }
1094
328
  },
1095
- 'material.panel':{
1096
- handler(){
329
+ 'material.panel': {
330
+ handler() {
1097
331
  this.renderPanels()
1098
332
  }
1099
333
  },
@@ -1110,10 +344,10 @@ export default {
1110
344
  if (this.tweenCamera) {
1111
345
  this.tweenCamera = null
1112
346
  }
1113
- clearThreeObjects(this.scene)
1114
- if(this.three_map){
347
+ this.clearThreeObjects(this.scene)
348
+ if (this.three_map) {
1115
349
  this.three_map.clear()
1116
- clearThreeObjects(this.three_map)
350
+ this.clearThreeObjects(this.three_map)
1117
351
  }
1118
352
  this.renderer.clear()
1119
353
  this.renderer.dispose()