@eturnity/eturnity_3d 7.6.0 → 7.8.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.
@@ -3,7 +3,6 @@ import { getBufferModuleFieldGeometry } from './geometryHandler'
3
3
  export default {
4
4
  methods: {
5
5
  renderModuleFields() {
6
- console.log('renderModuleField', this.areModuleFieldsVisible)
7
6
  this.clearByType('moduleFieldsMeshes')
8
7
  const moduleFieldPolygons = this.polygons.filter((p) =>
9
8
  ['moduleField', 'tmpModuleField'].includes(p.layer)
@@ -19,10 +18,6 @@ export default {
19
18
  }
20
19
  const geometry = getBufferModuleFieldGeometry(moduleFieldPolygon)
21
20
  if (geometry) {
22
- console.log(
23
- 'override',
24
- moduleFieldPolygon.data.number_of_panels_override
25
- )
26
21
  const mesh = new THREE.Mesh(geometry, material)
27
22
  mesh.matrixAutoUpdate = false
28
23
  mesh.userData.version = moduleFieldPolygon.version
@@ -9,11 +9,13 @@ export default {
9
9
  data() {
10
10
  return {
11
11
  mergedPanelSideMesh: null,
12
- mergedPanelTopMeshes: {}
12
+ mergedPanelTopMeshes: {},
13
+ arePanelVisible: true
13
14
  }
14
15
  },
15
16
  methods: {
16
17
  hidePanels() {
18
+ this.arePanelVisible = false
17
19
  if (this.mergedPanelTopMeshes) {
18
20
  Object.values(this.mergedPanelTopMeshes).forEach((mesh) => {
19
21
  mesh.visible = false
@@ -24,6 +26,7 @@ export default {
24
26
  }
25
27
  },
26
28
  showPanels() {
29
+ this.arePanelVisible = true
27
30
  if (this.mergedPanelTopMeshes) {
28
31
  Object.values(this.mergedPanelTopMeshes).forEach((mesh) => {
29
32
  mesh.visible = true
@@ -67,7 +70,7 @@ export default {
67
70
  panels.forEach((panelPolygon) => {
68
71
  //for each visible panels
69
72
  //1. define materialId and material
70
- //2. create or update individual meshes
73
+ //2. create or update individual meshes
71
74
  // 2a. Fill in panelTopGeometries & panelSideGeometries
72
75
  if (!panelPolygon.visible) {
73
76
  return
@@ -89,11 +92,10 @@ export default {
89
92
  ) && panelPolygon.moduleField.pvData.module_texture_version_id
90
93
  ? panelPolygon.moduleField.pvData.module_texture_version_id
91
94
  : 0
92
-
95
+
93
96
  materialId = 'default_' + moduleTextureId
94
97
  material = this.material.panel[materialId]
95
- material.transparent = true
96
- material.opacity = this.panelOpacity
98
+
97
99
  if (panelPolygon.moduleField.data) {
98
100
  if (
99
101
  this.material.panel[
@@ -109,8 +111,10 @@ export default {
109
111
  material = this.material.panel[materialId]
110
112
  }
111
113
  }
114
+ material.transparent = true
115
+ material.opacity = this.panelOpacity
112
116
  }
113
- //2. create or update individual meshes
117
+ //2. create or update individual meshes
114
118
  if (
115
119
  !this.meshes.panelsMeshes[panelPolygon.id + '_top'] ||
116
120
  !this.meshes.panelsMeshes[panelPolygon.id + '_side']
@@ -199,6 +203,11 @@ export default {
199
203
  'panelTop_' + key
200
204
  )
201
205
  }
206
+ if (this.arePanelVisible) {
207
+ this.showPanels()
208
+ } else {
209
+ this.hidePanels()
210
+ }
202
211
  }
203
212
  }
204
213
  }
@@ -25,7 +25,9 @@ export default {
25
25
  }
26
26
  }
27
27
  },
28
- created() {},
28
+ mounted() {
29
+ this.lastGeometryEventIdDone = this.lastGeometryEventId
30
+ },
29
31
  computed: {
30
32
  ...mapState({
31
33
  wallColor: (state) => state.threeDModule.wallColor,
@@ -386,20 +388,25 @@ export default {
386
388
  await item.method(...item.arg)
387
389
  }
388
390
  }
391
+ this.render()
389
392
  },
390
393
  renderGeometry() {
394
+ this.renderRealisticGeometry()
395
+ this.renderRoofsMargin()
396
+ this.renderNodes()
397
+ this.renderEdges()
398
+ this.renderFlatRoofs()
399
+ },
400
+ renderRealisticGeometry() {
391
401
  this.renderBuilding()
392
402
  this.renderModuleFields()
393
403
  this.renderPanels()
394
- this.renderRoofsMargin()
395
404
  },
396
405
  renderBuilding() {
397
406
  this.renderBase()
398
407
  this.renderRoofs()
399
408
  this.renderObstacles()
400
- this.renderNodes()
401
- this.renderEdges()
402
- this.renderFlatRoofs()
409
+ this.updateProjectionMaterials()
403
410
  },
404
411
 
405
412
  getCanvasOffset() {
@@ -421,34 +428,6 @@ export default {
421
428
  docEl = null
422
429
  box = null
423
430
  return { top: Math.round(top), left: Math.round(left) }
424
- },
425
- onWindowResize() {
426
- this.camera.aspect = window.innerWidth / window.innerHeight
427
- this.camera.updateProjectionMatrix()
428
- this.canvasOffset = this.getCanvasOffset()
429
- this.canvasHeight = this.$refs.canvas3DContainer.clientHeight
430
- this.canvasWidth = this.$refs.canvas3DContainer.clientWidth
431
- this.resizeCanvasToDisplaySize()
432
- //this.renderer.setSize(window.innerWidth / 2, window.innerHeight / 2)
433
- },
434
- resizeCanvasToDisplaySize() {
435
- let canvas = this.renderer.domElement
436
- // look up the size the canvas is being displayed
437
- const width = canvas.clientWidth
438
- const height = canvas.clientHeight
439
-
440
- // adjust displayBuffer size to match
441
- if (canvas.width !== width || canvas.height !== height) {
442
- // you must pass false here or three.js sadly fights the browser
443
- this.renderer.setSize(width, height, false)
444
- this.renderer.setViewport(0, 0, width, height)
445
-
446
- this.camera.aspect = width / height
447
- this.camera.updateProjectionMatrix()
448
-
449
- // update any render target sizes here
450
- }
451
- canvas = null
452
431
  }
453
432
  },
454
433
  watch: {
@@ -470,13 +449,10 @@ export default {
470
449
  },
471
450
  beforeDestroy() {
472
451
  this.clearThreeObjects(this.scene)
473
-
474
- if (this.three_map) {
475
- this.three_map.clear()
476
- this.clearThreeObjects(this.three_map)
452
+ if (this.renderer) {
453
+ this.renderer.clear()
454
+ this.renderer.dispose()
477
455
  }
478
- this.renderer.clear()
479
- this.renderer.dispose()
480
456
  if (this.orbitControl && this.orbitControl.dispose) {
481
457
  this.orbitControl.dispose()
482
458
  }
@@ -493,6 +469,5 @@ export default {
493
469
  this.raycaster = null
494
470
  this.loader = null
495
471
  this.provider = null
496
- window.removeEventListener('resize', this.onWindowResize, false)
497
472
  }
498
473
  }
@@ -3,40 +3,122 @@ import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'
3
3
  import { Sky } from 'three/examples/jsm/objects/Sky.js'
4
4
  import { CustomProvider } from './customProvider'
5
5
  import getLayers from '../utils/layers'
6
-
6
+ import materialMixin from './materialMixin'
7
+ import renderMixin from './renderMixin'
7
8
  export default {
9
+ data() {
10
+ return {
11
+ scene: new THREE.Scene(),
12
+ cameraProjection: null,
13
+ renderer: new THREE.WebGLRenderer({
14
+ antialias: true,
15
+ preserveDrawingBuffer: true,
16
+ powerPreference: 'high-performance'
17
+ }),
18
+ orbitControl: null,
19
+ raycaster: new THREE.Raycaster(),
20
+ loader: new THREE.TextureLoader(),
21
+ canvasHeight: null,
22
+ canvasWidth: null,
23
+ canvasOffset: { x: 0, y: 0 },
24
+ tweenCamera: null,
25
+ tweenOrbit: null,
26
+ isReady: {
27
+ texturesLoaded: 0,
28
+ texturesToLoad: 0,
29
+ threeMap: false,
30
+ geometry: false,
31
+ camera: false
32
+ },
33
+ screenshotable: false,
34
+ DOMElement: null
35
+ }
36
+ },
37
+ mixins: [renderMixin, materialMixin],
8
38
  methods: {
9
- initialiseThreeMap() {
10
- //Extention of the map with geo-map
11
- if (!this.selectedMapLayer) {
12
- this.setInitialMapLayer()
39
+ initialiseThree({
40
+ isInteractive = true,
41
+ isPerspectiveCamera = true,
42
+ DOMElement = this.$refs.canvas3DContainer
43
+ } = {}) {
44
+ this.DOMElement = DOMElement
45
+
46
+ if (!this.scene) {
47
+ this.scene = new THREE.Scene()
13
48
  }
14
- this.provider = new CustomProvider('', this.selectedMapLayer.key)
15
- this.renderTiles()
49
+ this.scene.background = new THREE.Color(0xb0b0b0)
50
+
51
+ this.initialiseRenderer(DOMElement)
52
+
53
+ this.initialiseCameras(isPerspectiveCamera)
54
+
55
+ this.initialiseLights()
56
+
57
+ this.initialiseSky()
58
+
59
+ this.initialiseThreeMap()
60
+
61
+ if (isInteractive) {
62
+ this.initialiseControl(isPerspectiveCamera)
63
+ }
64
+ this.onWindowResize()
65
+ window.addEventListener('resize', this.onWindowResize, false)
16
66
  },
17
- setInitialMapLayer() {
18
- if (!this.layers || this.layers.length == 0) {
19
- this.layers = getLayers()
67
+ initialiseRenderer() {
68
+ this.resizeRenderer(this.DOMElement)
69
+ this.renderer.setPixelRatio(window.devicePixelRatio)
70
+ this.renderer.toneMappingExposure = 0.01
71
+ this.DOMElement.appendChild(this.renderer.domElement)
72
+ },
73
+ resizeRenderer() {
74
+ if(this.DOMElement){
75
+ const width = this.DOMElement.clientWidth
76
+ const height = this.DOMElement.clientHeight
77
+ this.renderer.domElement.style.width = width + 'px'
78
+ this.renderer.domElement.style.height = height + 'px'
79
+ this.renderer.setSize(width, height, false)
80
+ this.renderer.setViewport(0, 0, width, height)
20
81
  }
21
- this.setSelectedMapLayer(null)
22
-
23
- if (this.selectedMapLayer === null) {
24
- for (var i in this.layers) {
25
- if (
26
- this.globalProjectProperties &&
27
- this.layers[i].key === this.globalProjectProperties.map_type
28
- ) {
29
- this.setSelectedMapLayer(this.layers[i])
30
- }
82
+ },
83
+ initialiseControl(isPerspectiveCamera) {
84
+ this.orbitControl = new OrbitControls(
85
+ this.camera,
86
+ this.renderer.domElement
87
+ )
88
+ if (isPerspectiveCamera) {
89
+ this.orbitControl.screenSpacePanning = false
90
+ this.orbitControl.maxPolarAngle = (0.95 * Math.PI) / 2
91
+ this.orbitControl.mouseButtons = {
92
+ RIGHT: THREE.MOUSE.PAN,
93
+ LEFT: THREE.MOUSE.ROTATE,
94
+ MIDDLE: THREE.MOUSE.DOLLY
95
+ }
96
+ } else {
97
+ this.orbitControl.screenSpacePanning = true
98
+ this.orbitControl.maxPolarAngle = Math.PI / 2
99
+ this.orbitControl.enableRotate = false
100
+ this.orbitControl.mouseButtons = {
101
+ LEFT: THREE.MOUSE.PAN,
102
+ MIDDLE: THREE.MOUSE.DOLLY,
103
+ RIGHT: THREE.MOUSE.ROTATE
31
104
  }
32
105
  }
33
-
34
- if (this.selectedMapLayer === null) {
35
- this.setSelectedMapLayer(this.layers[7])
36
- }
106
+ this.orbitControl.addEventListener('change', () => {
107
+ this.orbitControlChange()
108
+ })
37
109
  },
110
+ initialiseLights() {
111
+ const ambientLight = new THREE.AmbientLight(0xf0f0f0, 0.5)
112
+ var directionalLight = new THREE.DirectionalLight(0xffffff, 0.5)
113
+ directionalLight.position.set(0, 1000, 500)
114
+ var directionalLight2 = new THREE.DirectionalLight(0xffffff, 0.5)
115
+ directionalLight2.position.set(0, -1000, 500)
38
116
 
39
- initSky() {
117
+ this.scene.add(ambientLight)
118
+ this.scene.add(directionalLight)
119
+ this.scene.add(directionalLight2)
120
+ },
121
+ initialiseSky() {
40
122
  // Add Sky
41
123
  let sky = new Sky()
42
124
  sky.scale.setScalar(450000)
@@ -60,101 +142,77 @@ export default {
60
142
  uniforms['sunPosition'].value.copy(sun)
61
143
  sun = null
62
144
  },
63
- initialiseThree(isInteractive = true) {
64
- this.scene.background = new THREE.Color(0xb0b0b0)
65
- this.camera = this.perspectiveCamera
66
- this.camera.position.set(0, -100, 50)
67
- this.camera.up.set(0, 0, 1)
68
-
69
- this.cameraProjection = new THREE.PerspectiveCamera(
70
- 1,
71
- 300 / 300,
72
- 100,
73
- 1000
74
- )
75
- this.cameraProjection.position.set(0, 0, 24)
76
- this.cameraProjection.up.set(0, 0, 1)
77
-
78
- // const helper = new THREE.CameraHelper( this.cameraProjection );
79
- // this.scene.add( helper );
80
-
81
- // const axesHelper = new THREE.AxesHelper( 20 );
82
- // this.scene.add( axesHelper );
83
-
84
- this.scene.add(this.perspectiveCamera)
85
- this.scene.add(this.orthographicCamera)
86
-
87
- //Light
88
- const ambientLight = new THREE.AmbientLight(0xf0f0f0, 0.5)
89
- this.scene.add(ambientLight)
90
-
91
- var directionalLight = new THREE.DirectionalLight(0xffffff, 0.5)
92
- directionalLight.position.set(0, 1000, 500)
93
- var directionalLight2 = new THREE.DirectionalLight(0xffffff, 0.5)
94
- directionalLight2.position.set(0, -1000, 500)
95
- this.scene.add(directionalLight)
96
- this.scene.add(directionalLight2)
97
-
98
- this.renderer.setPixelRatio(window.devicePixelRatio)
99
- this.renderer.toneMappingExposure = 0.01
100
- this.$refs.canvas3DContainer.appendChild(this.renderer.domElement)
145
+ initialiseThreeMap() {
146
+ //Extention of the map with geo-map
147
+ if (!this.selectedMapLayer) {
148
+ this.initialiseMapLayer()
149
+ }
150
+ this.provider = new CustomProvider('', this.selectedMapLayer.key)
151
+ this.renderTiles()
152
+ },
153
+ initialiseMapLayer() {
154
+ if (!this.layers || this.layers.length == 0) {
155
+ this.layers = getLayers()
156
+ }
157
+ this.setSelectedMapLayer(null)
101
158
 
102
- //sky
103
- this.initSky()
104
- if (isInteractive) {
105
- this.orbitControl = new OrbitControls(
106
- this.camera,
107
- this.renderer.domElement
108
- )
109
- this.orbitControl.maxPolarAngle = (0.95 * Math.PI) / 2
110
- this.orbitControl.mouseButtons = {
111
- RIGHT: THREE.MOUSE.PAN,
112
- LEFT: THREE.MOUSE.ROTATE,
113
- MIDDLE: THREE.MOUSE.DOLLY
159
+ if (this.selectedMapLayer === null) {
160
+ for (var i in this.layers) {
161
+ if (
162
+ this.globalProjectProperties &&
163
+ this.layers[i].key === this.globalProjectProperties.map_type
164
+ ) {
165
+ this.setSelectedMapLayer(this.layers[i])
166
+ }
114
167
  }
115
- this.orbitControl.screenSpacePanning = false
116
- this.orbitControl.addEventListener('change', () => {
117
- this.orbitControlChange()
118
- })
119
168
  }
120
- window.addEventListener('resize', this.onWindowResize, false)
121
169
 
122
- ambientLight.dispose()
123
- directionalLight.dispose()
124
- directionalLight2.dispose()
170
+ if (this.selectedMapLayer === null) {
171
+ this.setSelectedMapLayer(this.layers[7])
172
+ }
173
+ },
174
+ render() {
175
+ if (this.composer) {
176
+ this.composer.render()
177
+ } else if (this.renderer) {
178
+ this.renderer.clear()
179
+ this.renderer.render(this.scene, this.camera)
180
+ }
125
181
  },
126
182
  orbitControlChange() {
127
183
  this.render()
128
184
  },
129
185
  onWindowResize() {
130
- this.camera.aspect = window.innerWidth / window.innerHeight
131
- this.camera.updateProjectionMatrix()
186
+ if (this.orbitControl) {
187
+ this.orbitControl.update()
188
+ }
132
189
  this.canvasOffset = this.getCanvasOffset()
133
- this.canvasHeight = this.$refs.canvas3DContainer.clientHeight
134
- this.canvasWidth = this.$refs.canvas3DContainer.clientWidth
135
- this.resizeCanvasToDisplaySize()
190
+ this.canvasHeight = this.DOMElement.clientHeight
191
+ this.canvasWidth = this.DOMElement.clientWidth
192
+ this.resizeRenderer()
193
+ this.setCameraAspectRatio()
194
+ this.render()
136
195
  },
137
- resizeCanvasToDisplaySize() {
196
+ onCanvasResize() {
138
197
  const canvas = this.renderer.domElement
139
- // look up the size the canvas is being displayed
140
- const width = canvas.clientWidth
141
- const height = canvas.clientHeight
142
- // adjust displayBuffer size to match
198
+ const width = this.DOMElement.clientWidth
199
+ const height = this.DOMElement.clientHeight
143
200
  if (canvas.width !== width || canvas.height !== height) {
144
- // you must pass false here or three.js sadly fights the browser
201
+ this.resizeRenderer()
145
202
 
146
- this.renderer.setSize(width, height, false)
147
- this.renderer.setViewport(0, 0, width, height)
148
203
  if (this.composer) {
149
- //this.composer.setSize(width, height, false)
150
204
  this.composer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
151
205
  if (this.composer.setViewport) {
152
206
  this.composer.setViewport(0, 0, width, height)
153
207
  }
154
208
  }
155
- this.camera.aspect = width / height
156
- this.camera.updateProjectionMatrix()
209
+ this.setCameraAspectRatio()
210
+ this.render()
157
211
  }
158
212
  }
213
+ },
214
+ beforeDestroy() {
215
+ this.DOMElement = null
216
+ window.removeEventListener('resize', this.onWindowResize, false)
159
217
  }
160
218
  }
package/src/main.js CHANGED
@@ -4,7 +4,6 @@ import App from './App.vue'
4
4
  import threeDModule from './store/three-d-module'
5
5
 
6
6
  Vue.use(Vuex)
7
-
8
7
  const Renderer = class {
9
8
  constructor() {}
10
9
  mount(identifier, geometryData, specificData, isInteractive = false) {
@@ -38,6 +38,9 @@ const init_state = {
38
38
  const state = init_state
39
39
 
40
40
  const getters = {
41
+ getLastGeometryEventId(){
42
+ return -1
43
+ },
41
44
  getSelectedTool() {
42
45
  return ''
43
46
  },