@eturnity/eturnity_3d 7.4.0 → 7.6.0-EPDM-9696.21

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,23 +3,27 @@ import { getBufferModuleFieldGeometry } from './geometryHandler'
3
3
  export default {
4
4
  methods: {
5
5
  renderModuleFields() {
6
+ console.log('renderModuleField', this.areModuleFieldsVisible)
6
7
  this.clearByType('moduleFieldsMeshes')
7
- if (!this.areModuleFieldsVisible) {
8
- return
9
- }
10
8
  const moduleFieldPolygons = this.polygons.filter((p) =>
11
9
  ['moduleField', 'tmpModuleField'].includes(p.layer)
12
10
  )
13
11
  moduleFieldPolygons.forEach((moduleFieldPolygon) => {
12
+ let material
13
+ if (moduleFieldPolygon.data.number_of_panels_override) {
14
+ material = this.material.moduleFieldWithPanelOveride
15
+ } else if (this.areModuleFieldsVisible) {
16
+ material = this.material.moduleField
17
+ } else {
18
+ return
19
+ }
14
20
  const geometry = getBufferModuleFieldGeometry(moduleFieldPolygon)
15
21
  if (geometry) {
16
- let material
17
- if (moduleFieldPolygon.data.number_of_panels_override) {
18
- material = this.material.moduleFieldWithPanelOveride
19
- } else {
20
- material = this.material.moduleField
21
- }
22
- const mesh = new THREE.Mesh(geometry, this.material.moduleField)
22
+ console.log(
23
+ 'override',
24
+ moduleFieldPolygon.data.number_of_panels_override
25
+ )
26
+ const mesh = new THREE.Mesh(geometry, material)
23
27
  mesh.matrixAutoUpdate = false
24
28
  mesh.userData.version = moduleFieldPolygon.version
25
29
  mesh.userData.type = 'moduleFieldsMeshes'
@@ -392,14 +392,20 @@ export default {
392
392
  this.renderModuleFields()
393
393
  this.renderPanels()
394
394
  this.renderRoofsMargin()
395
+ this.renderNodes()
396
+ this.renderEdges()
397
+ this.renderFlatRoofs()
398
+ },
399
+ renderRealisticGeometry() {
400
+ this.renderBuilding()
401
+ this.renderModuleFields()
402
+ this.renderPanels()
403
+ 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()
403
409
  },
404
410
 
405
411
  getCanvasOffset() {
@@ -421,34 +427,6 @@ export default {
421
427
  docEl = null
422
428
  box = null
423
429
  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
430
  }
453
431
  },
454
432
  watch: {
@@ -470,13 +448,10 @@ export default {
470
448
  },
471
449
  beforeDestroy() {
472
450
  this.clearThreeObjects(this.scene)
473
-
474
- if (this.three_map) {
475
- this.three_map.clear()
476
- this.clearThreeObjects(this.three_map)
451
+ if (this.renderer) {
452
+ this.renderer.clear()
453
+ this.renderer.dispose()
477
454
  }
478
- this.renderer.clear()
479
- this.renderer.dispose()
480
455
  if (this.orbitControl && this.orbitControl.dispose) {
481
456
  this.orbitControl.dispose()
482
457
  }
@@ -493,6 +468,5 @@ export default {
493
468
  this.raycaster = null
494
469
  this.loader = null
495
470
  this.provider = null
496
- window.removeEventListener('resize', this.onWindowResize, false)
497
471
  }
498
472
  }
@@ -3,40 +3,121 @@ 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()
13
- }
14
- this.provider = new CustomProvider('', this.selectedMapLayer.key)
15
- this.renderTiles()
16
- },
17
- setInitialMapLayer() {
18
- if (!this.layers || this.layers.length == 0) {
19
- this.layers = getLayers()
39
+ initialiseThree({
40
+ isInteractive = true,
41
+ isPerspectiveCamera = true,
42
+ DOMElement = this.$refs.canvas3DContainer
43
+ } = {}) {
44
+ console.log('initialiseThree')
45
+ this.DOMElement = DOMElement
46
+
47
+ if (!this.scene) {
48
+ this.scene = new THREE.Scene()
20
49
  }
21
- this.setSelectedMapLayer(null)
50
+ this.scene.background = new THREE.Color(0xb0b0b0)
22
51
 
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
- }
31
- }
32
- }
52
+ this.initialiseRenderer(DOMElement)
33
53
 
34
- if (this.selectedMapLayer === null) {
35
- this.setSelectedMapLayer(this.layers[7])
54
+ this.initialiseCameras(isPerspectiveCamera)
55
+
56
+ this.initialiseLights()
57
+
58
+ this.initialiseSky()
59
+
60
+ this.initialiseThreeMap()
61
+
62
+ if (isInteractive) {
63
+ this.initialiseControl(isPerspectiveCamera)
36
64
  }
65
+ this.onWindowResize()
66
+ window.addEventListener('resize', this.onWindowResize, false)
67
+ },
68
+ initialiseRenderer() {
69
+ this.resizeRenderer(this.DOMElement)
70
+ this.renderer.setPixelRatio(window.devicePixelRatio)
71
+ this.renderer.toneMappingExposure = 0.01
72
+ this.DOMElement.appendChild(this.renderer.domElement)
73
+ },
74
+ resizeRenderer() {
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)
37
81
  },
82
+ initialiseControl(isPerspectiveCamera) {
83
+ this.orbitControl = new OrbitControls(
84
+ this.camera,
85
+ this.renderer.domElement
86
+ )
87
+ if (isPerspectiveCamera) {
88
+ this.orbitControl.screenSpacePanning = false
89
+ this.orbitControl.maxPolarAngle = (0.95 * Math.PI) / 2
90
+ this.orbitControl.mouseButtons = {
91
+ RIGHT: THREE.MOUSE.PAN,
92
+ LEFT: THREE.MOUSE.ROTATE,
93
+ MIDDLE: THREE.MOUSE.DOLLY
94
+ }
95
+ } else {
96
+ this.orbitControl.screenSpacePanning = true
97
+ this.orbitControl.maxPolarAngle = Math.PI / 2
98
+ this.orbitControl.enableRotate = false
99
+ this.orbitControl.mouseButtons = {
100
+ LEFT: THREE.MOUSE.PAN,
101
+ MIDDLE: THREE.MOUSE.DOLLY,
102
+ RIGHT: THREE.MOUSE.ROTATE
103
+ }
104
+ }
105
+ this.orbitControl.addEventListener('change', () => {
106
+ this.orbitControlChange()
107
+ })
108
+ },
109
+ initialiseLights() {
110
+ const ambientLight = new THREE.AmbientLight(0xf0f0f0, 0.5)
111
+ var directionalLight = new THREE.DirectionalLight(0xffffff, 0.5)
112
+ directionalLight.position.set(0, 1000, 500)
113
+ var directionalLight2 = new THREE.DirectionalLight(0xffffff, 0.5)
114
+ directionalLight2.position.set(0, -1000, 500)
38
115
 
39
- initSky() {
116
+ this.scene.add(ambientLight)
117
+ this.scene.add(directionalLight)
118
+ this.scene.add(directionalLight2)
119
+ },
120
+ initialiseSky() {
40
121
  // Add Sky
41
122
  let sky = new Sky()
42
123
  sky.scale.setScalar(450000)
@@ -60,101 +141,77 @@ export default {
60
141
  uniforms['sunPosition'].value.copy(sun)
61
142
  sun = null
62
143
  },
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)
144
+ initialiseThreeMap() {
145
+ //Extention of the map with geo-map
146
+ if (!this.selectedMapLayer) {
147
+ this.initialiseMapLayer()
148
+ }
149
+ this.provider = new CustomProvider('', this.selectedMapLayer.key)
150
+ this.renderTiles()
151
+ },
152
+ initialiseMapLayer() {
153
+ if (!this.layers || this.layers.length == 0) {
154
+ this.layers = getLayers()
155
+ }
156
+ this.setSelectedMapLayer(null)
101
157
 
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
158
+ if (this.selectedMapLayer === null) {
159
+ for (var i in this.layers) {
160
+ if (
161
+ this.globalProjectProperties &&
162
+ this.layers[i].key === this.globalProjectProperties.map_type
163
+ ) {
164
+ this.setSelectedMapLayer(this.layers[i])
165
+ }
114
166
  }
115
- this.orbitControl.screenSpacePanning = false
116
- this.orbitControl.addEventListener('change', () => {
117
- this.orbitControlChange()
118
- })
119
167
  }
120
- window.addEventListener('resize', this.onWindowResize, false)
121
168
 
122
- ambientLight.dispose()
123
- directionalLight.dispose()
124
- directionalLight2.dispose()
169
+ if (this.selectedMapLayer === null) {
170
+ this.setSelectedMapLayer(this.layers[7])
171
+ }
172
+ },
173
+ render() {
174
+ if (this.composer) {
175
+ this.composer.render()
176
+ } else if (this.renderer) {
177
+ this.renderer.clear()
178
+ this.renderer.render(this.scene, this.camera)
179
+ }
125
180
  },
126
181
  orbitControlChange() {
127
182
  this.render()
128
183
  },
129
184
  onWindowResize() {
130
- this.camera.aspect = window.innerWidth / window.innerHeight
131
- this.camera.updateProjectionMatrix()
185
+ if (this.orbitControl) {
186
+ this.orbitControl.update()
187
+ }
132
188
  this.canvasOffset = this.getCanvasOffset()
133
- this.canvasHeight = this.$refs.canvas3DContainer.clientHeight
134
- this.canvasWidth = this.$refs.canvas3DContainer.clientWidth
135
- this.resizeCanvasToDisplaySize()
189
+ this.canvasHeight = this.DOMElement.clientHeight
190
+ this.canvasWidth = this.DOMElement.clientWidth
191
+ this.resizeRenderer()
192
+ this.setCameraAspectRatio()
193
+ this.render()
136
194
  },
137
- resizeCanvasToDisplaySize() {
195
+ onCanvasResize() {
138
196
  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
197
+ const width = this.DOMElement.clientWidth
198
+ const height = this.DOMElement.clientHeight
143
199
  if (canvas.width !== width || canvas.height !== height) {
144
- // you must pass false here or three.js sadly fights the browser
200
+ this.resizeRenderer()
145
201
 
146
- this.renderer.setSize(width, height, false)
147
- this.renderer.setViewport(0, 0, width, height)
148
202
  if (this.composer) {
149
- //this.composer.setSize(width, height, false)
150
203
  this.composer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
151
204
  if (this.composer.setViewport) {
152
205
  this.composer.setViewport(0, 0, width, height)
153
206
  }
154
207
  }
155
- this.camera.aspect = width / height
156
- this.camera.updateProjectionMatrix()
208
+ this.setCameraAspectRatio()
209
+ this.render()
157
210
  }
158
211
  }
212
+ },
213
+ beforeDestroy() {
214
+ this.DOMElement = null
215
+ window.removeEventListener('resize', this.onWindowResize, false)
159
216
  }
160
217
  }
package/src/main.js CHANGED
@@ -4,10 +4,11 @@ import App from './App.vue'
4
4
  import threeDModule from './store/three-d-module'
5
5
 
6
6
  Vue.use(Vuex)
7
-
7
+ console.log('eturnity_3d 9696v21 loaded')
8
8
  const Renderer = class {
9
9
  constructor() {}
10
10
  mount(identifier, geometryData, specificData, isInteractive = false) {
11
+ console.log('Renderer mount ', identifier, geometryData, specificData)
11
12
  if (specificData.isBuildingVisible === undefined) {
12
13
  specificData.isBuildingVisible = true
13
14
  }
@@ -120,6 +120,7 @@ export async function hydratePolygons({
120
120
  moduleField.pvData.module_texture_version_id =
121
121
  moduleFieldResp.module_texture_version_id
122
122
  moduleField.data = {}
123
+ moduleField.data.texture_img_url = moduleFieldResp.texture_img_url
123
124
  moduleField.data.col_spacing_mm = moduleFieldResp.col_spacing_mm
124
125
  moduleField.data.row_spacing_mm = moduleFieldResp.row_spacing_mm
125
126
  moduleField.data.row_spacing_hill_mm = moduleFieldResp.row_spacing_hill_mm