@eturnity/eturnity_3d 6.28.0 → 6.29.0-qa.0

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
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: {
@@ -276,11 +240,6 @@ export default {
276
240
  this.renderFlatRoofs()
277
241
  },
278
242
 
279
- renderBackground() {
280
- if(!this.background_map){
281
- this.initialiseThreeMap()
282
- }
283
- },
284
243
  applyTextureOnRoofs(){
285
244
  this.roofs.forEach(roof=>{
286
245
  //roofs
@@ -297,650 +256,13 @@ export default {
297
256
  })
298
257
  })
299
258
  },
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
- }
355
- })
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
- })
456
- },
457
- renderRoofsMargin() {
458
- this.clearByType('roofMarginMeshes')
459
-
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
- },
259
+
792
260
  async updateProjectionMaterial(){
793
261
  await this.loadProjectionMaterial()
794
262
  this.applyTextureOnRoofs()
795
263
  this.renderBackground()
796
264
  },
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
-
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
- this.orbitControl.update()
931
- })
932
- .start()
933
- }
934
- if (this.camera) {
935
- this.tweenCamera = new TWEEN.Tween(this.camera.position)
936
- .to({ x: position[0], y: position[1], z: position[2] }, 2000)
937
- .easing(TWEEN.Easing.Sinusoidal.Out)
938
- .onUpdate(() => {
939
- this.orbitControl.update()
940
- })
941
- .start()
942
- }
943
- },
265
+
944
266
  getCanvasOffset() {
945
267
  if (!this.$refs.canvas3DContainer) return { top: 0, left: 0 }
946
268
  var box = this.$refs.canvas3DContainer.getBoundingClientRect()
@@ -989,94 +311,6 @@ export default {
989
311
  }
990
312
  canvas = null
991
313
  },
992
- clearMesh(mesh) {
993
- if (!mesh) return
994
- this.scene.remove(mesh)
995
- if (mesh.geometry && mesh.geometry.dispose) {
996
- mesh.geometry.dispose()
997
- mesh.geometry = null
998
- }
999
- if (mesh.material && mesh.material.dispose) {
1000
- mesh.material.dispose()
1001
- mesh.material = null
1002
- }
1003
- if (
1004
- mesh.userData.meshId &&
1005
- this.meshes[mesh.userData.type][mesh.userData.meshId]
1006
- ) {
1007
- delete this.meshes[mesh.userData.type][mesh.userData.meshId]
1008
- } else {
1009
- this.meshes[mesh.userData.type] = null
1010
- }
1011
- mesh = null
1012
- },
1013
- clearEdgesRemovedOnes() {
1014
- Object.values(this.meshes['edgeMeshes']).forEach((mesh) => {
1015
- if (!this.edgeIds.includes(mesh.userData.edgeId)) {
1016
- this.clearMesh(mesh)
1017
- }
1018
- })
1019
- },
1020
- clearNodesRemovedOnes() {
1021
- Object.values(this.meshes['nodeMeshes']).forEach((mesh) => {
1022
- if (!this.nodeIds.includes(mesh.userData.nodeId)) {
1023
- this.clearMesh(mesh)
1024
- }
1025
- })
1026
- },
1027
- clearRemovedOnes(type) {
1028
- Object.values(this.meshes[type]).forEach((mesh) => {
1029
- if (!this.polygonIds.includes(mesh.userData.polygonId)) {
1030
- this.clearMesh(mesh)
1031
- }
1032
- })
1033
- },
1034
- clearByType(type) {
1035
- Object.values(this.meshes[type]).forEach((mesh) => {
1036
- mesh.geometry.dispose()
1037
- mesh.geometry = null
1038
- if (mesh.material.dispose) {
1039
- mesh.material.dispose()
1040
- }
1041
- mesh.material = null
1042
- this.scene.remove(mesh)
1043
- })
1044
- this.meshes[type] = {}
1045
- this.renderer.renderLists.dispose()
1046
- },
1047
- loadNewTexture(){
1048
- Object.values(this.pvDataMemo).forEach((component) => {
1049
- const pvId = component.id
1050
- if (!this.material.panel[pvId]) {
1051
- if (!component.texture_img_url) {
1052
- this.material.panel[pvId] = this.material.panel.default
1053
- } else {
1054
- let texture = this.loader.load(component.texture_img_url)
1055
- this.material.panel[pvId] = new THREE.MeshBasicMaterial({
1056
- map: texture,
1057
- side: THREE.DoubleSide
1058
- })
1059
- }
1060
- }
1061
- })
1062
- },
1063
- async loadTextureFromModuleFields(){
1064
- for(let k=0;k<this.moduleFields.length;k++){
1065
- let mf=this.moduleFields[k]
1066
- const pvId = mf.data.component_id_pv_module
1067
- if (!this.material.panel[pvId]) {
1068
- if (!mf.data.texture_img_url) {
1069
- this.material.panel[pvId] = this.material.panel.default
1070
- } else {
1071
- let texture = await this.loader.load(mf.data.texture_img_url)
1072
- this.material.panel[pvId] = new THREE.MeshBasicMaterial({
1073
- map: texture,
1074
- side: THREE.DoubleSide
1075
- })
1076
- }
1077
- }
1078
- }
1079
- }
1080
314
  },
1081
315
  watch: {
1082
316
  wallColor(color) {
@@ -1106,10 +340,10 @@ export default {
1106
340
  if (this.tweenCamera) {
1107
341
  this.tweenCamera = null
1108
342
  }
1109
- clearThreeObjects(this.scene)
343
+ this.clearThreeObjects(this.scene)
1110
344
  if(this.three_map){
1111
345
  this.three_map.clear()
1112
- clearThreeObjects(this.three_map)
346
+ this.clearThreeObjects(this.three_map)
1113
347
  }
1114
348
  this.renderer.clear()
1115
349
  this.renderer.dispose()