@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.
- package/bitbucket-pipelines.yml +394 -108
- package/package.json +1 -1
- package/src/App.vue +4 -8
- package/src/components/ThreeCanvasViewer.vue +68 -65
- package/src/config.js +1 -1
- package/src/helper/cameraMixin.js +246 -69
- package/src/helper/materialMixin.js +1 -1
- package/src/helper/render/moduleField.js +0 -5
- package/src/helper/render/panel.js +15 -6
- package/src/helper/renderMixin.js +15 -40
- package/src/helper/threeMixin.js +157 -99
- package/src/main.js +0 -1
- package/src/store/three-d-module.js +3 -0
package/package.json
CHANGED
package/src/App.vue
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div
|
|
2
|
+
<div
|
|
3
|
+
class="frame"
|
|
4
|
+
:style="{ height: '100%', width: '100%', display: 'flex' }"
|
|
5
|
+
>
|
|
3
6
|
<ThreeCanvas />
|
|
4
7
|
</div>
|
|
5
8
|
</template>
|
|
@@ -19,10 +22,3 @@ export default {
|
|
|
19
22
|
}
|
|
20
23
|
}
|
|
21
24
|
</script>
|
|
22
|
-
|
|
23
|
-
<style scoped>
|
|
24
|
-
.frame {
|
|
25
|
-
width: 100%;
|
|
26
|
-
height: 100%;
|
|
27
|
-
}
|
|
28
|
-
</style>
|
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
<div
|
|
3
3
|
class="canvas3DContainer"
|
|
4
4
|
ref="canvas3DContainer"
|
|
5
|
-
:style="{ height: '100%' }"
|
|
5
|
+
:style="{ height: '100%', width: '100%', display: 'flex' }"
|
|
6
6
|
crossorigin
|
|
7
7
|
/>
|
|
8
8
|
</template>
|
|
9
9
|
|
|
10
10
|
<script>
|
|
11
11
|
import { mapActions, mapState, mapGetters, mapMutations } from 'vuex'
|
|
12
|
-
import * as THREE from 'three'
|
|
13
12
|
import {
|
|
14
13
|
addVector,
|
|
15
14
|
multiplyVector,
|
|
@@ -18,95 +17,63 @@ import {
|
|
|
18
17
|
} from '@eturnity/eturnity_maths'
|
|
19
18
|
|
|
20
19
|
import threeMixin from '../helper/threeMixin'
|
|
21
|
-
|
|
22
|
-
import renderMixin from '../helper/renderMixin'
|
|
20
|
+
|
|
23
21
|
export default {
|
|
24
22
|
name: 'ThreeCanvas',
|
|
25
23
|
data() {
|
|
26
24
|
return {
|
|
27
|
-
scene: new THREE.Scene(),
|
|
28
25
|
layers: null,
|
|
29
26
|
provider: null,
|
|
30
|
-
cameraProjection: null,
|
|
31
|
-
texture: null,
|
|
32
|
-
renderer: new THREE.WebGLRenderer({
|
|
33
|
-
antialias: true,
|
|
34
|
-
preserveDrawingBuffer: true
|
|
35
|
-
}),
|
|
36
|
-
orbitControl: null,
|
|
37
|
-
raycaster: new THREE.Raycaster(),
|
|
38
|
-
loader: new THREE.TextureLoader(),
|
|
39
27
|
pointer: { x: 0, y: 0 },
|
|
40
|
-
canvasHeight: null,
|
|
41
|
-
canvasWidth: null,
|
|
42
|
-
canvasOffset: { x: 0, y: 0 },
|
|
43
|
-
tweenCamera: null,
|
|
44
|
-
tweenOrbit: null,
|
|
45
|
-
three_map: null,
|
|
46
|
-
isReady: {
|
|
47
|
-
texturesLoaded: 0,
|
|
48
|
-
texturesToLoad: 0,
|
|
49
|
-
threeMap: false,
|
|
50
|
-
geometry: false,
|
|
51
|
-
camera: false
|
|
52
|
-
},
|
|
53
|
-
screenshotable: false,
|
|
54
28
|
areModuleFieldsVisible: false,
|
|
55
29
|
areUserDeactivatedPanelsVisible: false,
|
|
56
30
|
animationFrameId: null,
|
|
57
|
-
intervalId: null
|
|
31
|
+
intervalId: null
|
|
58
32
|
}
|
|
59
33
|
},
|
|
60
34
|
beforeDestroy() {
|
|
61
35
|
clearInterval(this.intervalId)
|
|
62
36
|
cancelAnimationFrame(this.animationFrameId)
|
|
63
37
|
},
|
|
64
|
-
mixins: [
|
|
38
|
+
mixins: [threeMixin],
|
|
65
39
|
async mounted() {
|
|
66
40
|
await this.hydrateData(this.geometryData)
|
|
67
|
-
|
|
68
|
-
this.
|
|
41
|
+
let isPerspectiveCamera = true
|
|
42
|
+
if (this.useCustomCamera && this.cameraPerspectiveSettings) {
|
|
43
|
+
isPerspectiveCamera = this.cameraPerspectiveSettings.viewType == 'perspective'
|
|
44
|
+
}
|
|
45
|
+
this.initialiseThree({
|
|
46
|
+
isInteractive: this.isInteractive,
|
|
47
|
+
isPerspectiveCamera,
|
|
48
|
+
DOMElement: this.$refs.canvas3DContainer
|
|
49
|
+
})
|
|
69
50
|
|
|
70
|
-
this.initialiseThree(this.isInteractive)
|
|
71
|
-
this.initialiseThreeMap()
|
|
72
51
|
await this.loadPanelsTexture()
|
|
73
|
-
this.
|
|
52
|
+
this.renderRealisticGeometry()
|
|
74
53
|
if (!this.isBuildingVisible) {
|
|
75
|
-
|
|
76
|
-
(mesh) => (mesh.visible = false)
|
|
77
|
-
)
|
|
78
|
-
Object.values(this.meshes.baseMeshes).forEach(
|
|
79
|
-
(mesh) => (mesh.visible = false)
|
|
80
|
-
)
|
|
81
|
-
Object.values(this.meshes.obstacleMeshes).forEach(
|
|
82
|
-
(mesh) => (mesh.visible = false)
|
|
83
|
-
)
|
|
84
|
-
Object.values(this.meshes.edgeMeshes).forEach(
|
|
85
|
-
(mesh) => (mesh.visible = false)
|
|
86
|
-
)
|
|
87
|
-
Object.values(this.meshes.panelsMeshes).forEach(
|
|
88
|
-
(mesh) => (mesh.visible = false)
|
|
89
|
-
)
|
|
90
|
-
this.hideMesh(this.mergedBaseMesh)
|
|
91
|
-
this.hideMesh(this.mergedRoofMesh)
|
|
92
|
-
this.hideMesh(this.mergedObstacleMesh)
|
|
93
|
-
this.hideMesh(this.mergedObstacleSideMesh)
|
|
94
|
-
this.hidePanels()
|
|
54
|
+
this.hideBuildings()
|
|
95
55
|
}
|
|
96
|
-
|
|
97
|
-
(mesh) => (mesh.visible = false)
|
|
98
|
-
)
|
|
99
|
-
Object.values(this.meshes.edgeMeshes).forEach(
|
|
100
|
-
(mesh) => (mesh.visible = false)
|
|
101
|
-
)
|
|
102
|
-
this.onWindowResize()
|
|
56
|
+
|
|
103
57
|
this.$root.$on('on-roofSelected', (polygon) =>
|
|
104
58
|
this.setCameraOrthogonalTo(polygon)
|
|
105
59
|
)
|
|
106
60
|
await this.updateProjectionMaterials()
|
|
107
61
|
|
|
108
|
-
|
|
109
|
-
|
|
62
|
+
if (this.useCustomCamera) {
|
|
63
|
+
if (isPerspectiveCamera) {
|
|
64
|
+
this.setPerspectiveCameraPositionTo(
|
|
65
|
+
this.cameraPerspectiveSettings.position,
|
|
66
|
+
this.cameraPerspectiveSettings.target
|
|
67
|
+
)
|
|
68
|
+
} else {
|
|
69
|
+
this.setOrthographicCameraPositionFromCameraParameters(
|
|
70
|
+
this.cameraPerspectiveSettings.cameraParameters
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
const polygon = this.polygons.find((p) => p.id == this.uuid)
|
|
75
|
+
this.setCamera(polygon, this.view_mode)
|
|
76
|
+
}
|
|
110
77
|
this.isReady.geometry = true
|
|
111
78
|
this.render()
|
|
112
79
|
this.intervalId = setInterval(() => this.render(), 500)
|
|
@@ -116,6 +83,8 @@ export default {
|
|
|
116
83
|
geometryData: (state) => state.threeDModule.geometryData,
|
|
117
84
|
uuid: (state) => state.threeDModule.uuid,
|
|
118
85
|
view_mode: (state) => state.threeDModule.view_mode,
|
|
86
|
+
useCustomCamera: (state) => state.threeDModule.useCustomCamera,
|
|
87
|
+
cameraPerspectiveSettings: (state) => state.threeDModule.cameraPerspectiveSettings,
|
|
119
88
|
isInteractive: (state) => state.threeDModule.isInteractive,
|
|
120
89
|
isBuildingVisible: (state) => state.threeDModule.isBuildingVisible,
|
|
121
90
|
imageOverlay: (state) => state.threeDModule.imageOverlay
|
|
@@ -141,6 +110,38 @@ export default {
|
|
|
141
110
|
...mapMutations({
|
|
142
111
|
setSelectedMapLayer: 'mutate_selectedMapLayer'
|
|
143
112
|
}),
|
|
113
|
+
hideEdges() {
|
|
114
|
+
Object.values(this.meshes.edgeMeshes).forEach(
|
|
115
|
+
(mesh) => (mesh.visible = false)
|
|
116
|
+
)
|
|
117
|
+
},
|
|
118
|
+
hideWarningRoofs() {
|
|
119
|
+
Object.values(this.meshes.flatRoofMeshes).forEach(
|
|
120
|
+
(mesh) => (mesh.visible = false)
|
|
121
|
+
)
|
|
122
|
+
},
|
|
123
|
+
hideBuildings() {
|
|
124
|
+
Object.values(this.meshes.roofMeshes).forEach(
|
|
125
|
+
(mesh) => (mesh.visible = false)
|
|
126
|
+
)
|
|
127
|
+
Object.values(this.meshes.baseMeshes).forEach(
|
|
128
|
+
(mesh) => (mesh.visible = false)
|
|
129
|
+
)
|
|
130
|
+
Object.values(this.meshes.obstacleMeshes).forEach(
|
|
131
|
+
(mesh) => (mesh.visible = false)
|
|
132
|
+
)
|
|
133
|
+
Object.values(this.meshes.edgeMeshes).forEach(
|
|
134
|
+
(mesh) => (mesh.visible = false)
|
|
135
|
+
)
|
|
136
|
+
Object.values(this.meshes.panelsMeshes).forEach(
|
|
137
|
+
(mesh) => (mesh.visible = false)
|
|
138
|
+
)
|
|
139
|
+
this.hideMesh(this.mergedBaseMesh)
|
|
140
|
+
this.hideMesh(this.mergedRoofMesh)
|
|
141
|
+
this.hideMesh(this.mergedObstacleMesh)
|
|
142
|
+
this.hideMesh(this.mergedObstacleSideMesh)
|
|
143
|
+
this.hidePanels()
|
|
144
|
+
},
|
|
144
145
|
hideMesh(mesh) {
|
|
145
146
|
if (mesh) {
|
|
146
147
|
mesh.visible = false
|
|
@@ -284,7 +285,7 @@ export default {
|
|
|
284
285
|
},
|
|
285
286
|
render() {
|
|
286
287
|
this.renderer.clear()
|
|
287
|
-
if (['top', 'global'].includes(this.view_mode)) {
|
|
288
|
+
if (['top', 'global'].includes(this.view_mode) && !this.useCustomCamera) {
|
|
288
289
|
this.renderer.render(this.scene, this.orthographicCamera)
|
|
289
290
|
} else {
|
|
290
291
|
this.renderer.render(this.scene, this.camera)
|
|
@@ -316,10 +317,12 @@ export default {
|
|
|
316
317
|
.canvas3DContainer {
|
|
317
318
|
width: 100%;
|
|
318
319
|
height: 100%;
|
|
320
|
+
width: 100%;
|
|
319
321
|
}
|
|
320
322
|
|
|
321
323
|
.canvas3DContainer > canvas {
|
|
322
324
|
width: 100%;
|
|
323
325
|
height: 100%;
|
|
326
|
+
width: 100%;
|
|
324
327
|
}
|
|
325
328
|
</style>
|
package/src/config.js
CHANGED
|
@@ -6,7 +6,7 @@ export const snapToLineTolerance = 10
|
|
|
6
6
|
export const distanceToCloseNode = 70
|
|
7
7
|
export const mmTolerance = 1
|
|
8
8
|
export const earthRadius = 6371008
|
|
9
|
-
|
|
9
|
+
export const marginAroundBuildingForCameraViewInMeter = 5
|
|
10
10
|
export const layerColors = {
|
|
11
11
|
construction: {
|
|
12
12
|
fillColor: 'transparent',
|
|
@@ -7,16 +7,65 @@ import {
|
|
|
7
7
|
multiplyVector,
|
|
8
8
|
substractVector
|
|
9
9
|
} from '@eturnity/eturnity_maths'
|
|
10
|
-
|
|
10
|
+
import { marginAroundBuildingForCameraViewInMeter } from '../config'
|
|
11
11
|
export default {
|
|
12
12
|
data() {
|
|
13
13
|
return {
|
|
14
14
|
camera: null,
|
|
15
15
|
perspectiveCamera: new THREE.PerspectiveCamera(50, 300 / 300, 1, 50000),
|
|
16
|
-
orthographicCamera: new THREE.OrthographicCamera(
|
|
16
|
+
orthographicCamera: new THREE.OrthographicCamera(
|
|
17
|
+
-50,
|
|
18
|
+
50,
|
|
19
|
+
50,
|
|
20
|
+
-50,
|
|
21
|
+
1,
|
|
22
|
+
1000
|
|
23
|
+
),
|
|
24
|
+
animationFrameId: null
|
|
17
25
|
}
|
|
18
26
|
},
|
|
19
27
|
methods: {
|
|
28
|
+
initialiseCameras(isPerspectiveCamera) {
|
|
29
|
+
if (isPerspectiveCamera) {
|
|
30
|
+
this.camera = this.perspectiveCamera
|
|
31
|
+
this.camera.position.set(0, -100, 50)
|
|
32
|
+
this.camera.up.set(0, 0, 1)
|
|
33
|
+
} else {
|
|
34
|
+
this.camera = this.orthographicCamera
|
|
35
|
+
this.camera.position.set(0, 0, 100)
|
|
36
|
+
this.camera.up.set(0, 1, 0)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
this.cameraProjection = new THREE.PerspectiveCamera(
|
|
40
|
+
1,
|
|
41
|
+
300 / 300,
|
|
42
|
+
100,
|
|
43
|
+
1000
|
|
44
|
+
)
|
|
45
|
+
this.cameraProjection.position.set(0, 0, 500)
|
|
46
|
+
this.cameraProjection.up.set(0, 0, 1)
|
|
47
|
+
this.scene.add(this.camera)
|
|
48
|
+
},
|
|
49
|
+
setCameraAspectRatio() {
|
|
50
|
+
const canvasRatio =
|
|
51
|
+
this.DOMElement.clientWidth / this.DOMElement.clientHeight
|
|
52
|
+
if (this.camera.isOrthographicCamera) {
|
|
53
|
+
const currentAspect = Math.abs(
|
|
54
|
+
(this.camera.right - this.camera.left) /
|
|
55
|
+
(this.camera.top - this.camera.bottom)
|
|
56
|
+
)
|
|
57
|
+
if (canvasRatio / currentAspect > 1) {
|
|
58
|
+
this.camera.left *= canvasRatio / currentAspect
|
|
59
|
+
this.camera.right *= canvasRatio / currentAspect
|
|
60
|
+
} else {
|
|
61
|
+
this.camera.top *= canvasRatio / currentAspect
|
|
62
|
+
this.camera.bottom *= canvasRatio / currentAspect
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
this.camera.aspect = canvasRatio
|
|
66
|
+
}
|
|
67
|
+
this.camera.updateProjectionMatrix()
|
|
68
|
+
},
|
|
20
69
|
turnPerspectiveCameraToOrthogonal() {
|
|
21
70
|
const cameraPosition = new THREE.Vector3(
|
|
22
71
|
this.camera.position.x,
|
|
@@ -47,11 +96,6 @@ export default {
|
|
|
47
96
|
cameraPosition.y,
|
|
48
97
|
cameraPosition.z
|
|
49
98
|
)
|
|
50
|
-
this.camera.position.set(
|
|
51
|
-
cameraPosition.x,
|
|
52
|
-
cameraPosition.y,
|
|
53
|
-
cameraPosition.z
|
|
54
|
-
)
|
|
55
99
|
this.camera.updateProjectionMatrix()
|
|
56
100
|
this.renderer.camera = this.camera
|
|
57
101
|
this.composer.renderCamera = this.camera
|
|
@@ -60,7 +104,7 @@ export default {
|
|
|
60
104
|
this.overlayRenderPass.camera = this.camera
|
|
61
105
|
this.outlinePassHighlight.renderCamera = this.camera
|
|
62
106
|
this.outlinePassSelected.renderCamera = this.camera
|
|
63
|
-
|
|
107
|
+
|
|
64
108
|
this.orbitControl.screenSpacePanning = true
|
|
65
109
|
this.orbitControl.object = this.camera
|
|
66
110
|
this.orbitControl.target.set(cameraPosition.x, cameraPosition.y, 0)
|
|
@@ -70,9 +114,6 @@ export default {
|
|
|
70
114
|
RIGHT: THREE.MOUSE.ROTATE
|
|
71
115
|
}
|
|
72
116
|
this.orbitControl.enableRotate = false
|
|
73
|
-
this.orbitControl.addEventListener('change', () => {
|
|
74
|
-
this.orbitControlChange()
|
|
75
|
-
})
|
|
76
117
|
this.orbitControl.update()
|
|
77
118
|
this.camera.position.set(
|
|
78
119
|
cameraPosition.x,
|
|
@@ -89,7 +130,6 @@ export default {
|
|
|
89
130
|
},
|
|
90
131
|
turnOrthogonalCameraToPerspective() {
|
|
91
132
|
this.camera = this.perspectiveCamera
|
|
92
|
-
console.log(this.orthographicCamera)
|
|
93
133
|
let altitude =
|
|
94
134
|
(this.orthographicCamera.right - this.orthographicCamera.left) /
|
|
95
135
|
((this.perspectiveCamera.fov * Math.PI) / 180) /
|
|
@@ -132,59 +172,178 @@ export default {
|
|
|
132
172
|
this.composer.render()
|
|
133
173
|
},
|
|
134
174
|
zoomIn3D() {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
newCameraPosition
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
175
|
+
if (this.camera.isOrthographicCamera) {
|
|
176
|
+
this.camera.zoom *= 1.3
|
|
177
|
+
this.camera.updateProjectionMatrix()
|
|
178
|
+
this.render()
|
|
179
|
+
} else {
|
|
180
|
+
let target = this.orbitControl.target
|
|
181
|
+
let curentPosition = this.camera.position
|
|
182
|
+
let newCameraPosition = addVector(
|
|
183
|
+
target,
|
|
184
|
+
multiplyVector(1 / 1.5, substractVector(curentPosition, target))
|
|
185
|
+
)
|
|
186
|
+
newCameraPosition = [
|
|
187
|
+
newCameraPosition.x,
|
|
188
|
+
newCameraPosition.y,
|
|
189
|
+
newCameraPosition.z
|
|
190
|
+
]
|
|
191
|
+
target = [target.x, target.y, target.z]
|
|
192
|
+
this.setTweenTo({ position: newCameraPosition, target, duration: 500 })
|
|
193
|
+
}
|
|
148
194
|
},
|
|
149
195
|
zoomOut3D() {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
196
|
+
if (this.camera.isOrthographicCamera) {
|
|
197
|
+
this.camera.zoom /= 1.3
|
|
198
|
+
this.camera.updateProjectionMatrix()
|
|
199
|
+
this.render()
|
|
200
|
+
} else {
|
|
201
|
+
let target = this.orbitControl.target
|
|
202
|
+
let curentPosition = this.camera.position
|
|
203
|
+
let newCameraPosition = addVector(
|
|
204
|
+
target,
|
|
205
|
+
multiplyVector(1.5, substractVector(curentPosition, target))
|
|
206
|
+
)
|
|
207
|
+
newCameraPosition = [
|
|
208
|
+
newCameraPosition.x,
|
|
209
|
+
newCameraPosition.y,
|
|
210
|
+
newCameraPosition.z
|
|
211
|
+
]
|
|
212
|
+
target = [target.x, target.y, target.z]
|
|
213
|
+
this.setTweenTo({ position: newCameraPosition, target, duration: 500 })
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
setPerspectiveCameraPositionTo(cameraPosition, targetPosition) {
|
|
217
|
+
this.camera.position.set(
|
|
218
|
+
cameraPosition.x,
|
|
219
|
+
cameraPosition.y,
|
|
220
|
+
cameraPosition.z
|
|
155
221
|
)
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
222
|
+
this.camera.lookAt(targetPosition.x, targetPosition.y, targetPosition.z)
|
|
223
|
+
this.camera.updateProjectionMatrix()
|
|
224
|
+
if (this.orbitControl && this.orbitControl.update) {
|
|
225
|
+
this.orbitControl.target.set(
|
|
226
|
+
targetPosition.x,
|
|
227
|
+
targetPosition.y,
|
|
228
|
+
targetPosition.z
|
|
229
|
+
)
|
|
230
|
+
this.orbitControl.update()
|
|
231
|
+
}
|
|
232
|
+
this.render()
|
|
233
|
+
},
|
|
234
|
+
sanitizeOrthographicCameraParameters({
|
|
235
|
+
left,
|
|
236
|
+
right,
|
|
237
|
+
top,
|
|
238
|
+
bottom,
|
|
239
|
+
zoom,
|
|
240
|
+
x,
|
|
241
|
+
y
|
|
242
|
+
}) {
|
|
243
|
+
if (left > right) {
|
|
244
|
+
;[left, right] = [right, left]
|
|
245
|
+
}
|
|
246
|
+
if (top < bottom) {
|
|
247
|
+
;[top, bottom] = [bottom, top]
|
|
248
|
+
}
|
|
249
|
+
return {
|
|
250
|
+
left,
|
|
251
|
+
right,
|
|
252
|
+
top,
|
|
253
|
+
bottom,
|
|
254
|
+
zoom,
|
|
255
|
+
x,
|
|
256
|
+
y
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
setOrthographicCameraPositionFromCameraParameters(cameraParams) {
|
|
260
|
+
if (!cameraParams || Object.keys(cameraParams).length === 0) {
|
|
261
|
+
this.setOrthographicCameraGlobalPosition()
|
|
262
|
+
return
|
|
263
|
+
}
|
|
264
|
+
let { x, y, left, right, top, bottom, zoom } =
|
|
265
|
+
this.sanitizeOrthographicCameraParameters(cameraParams)
|
|
266
|
+
this.camera.up = new THREE.Vector3(0, 1, 0)
|
|
267
|
+
|
|
268
|
+
this.camera.left = left
|
|
269
|
+
this.camera.right = right
|
|
270
|
+
this.camera.top = top
|
|
271
|
+
this.camera.bottom = bottom
|
|
272
|
+
this.camera.near = 1
|
|
273
|
+
this.camera.far = 10000
|
|
274
|
+
this.camera.zoom = zoom
|
|
275
|
+
|
|
276
|
+
this.camera.position.set(x, y, 100)
|
|
277
|
+
this.camera.lookAt(x, y, 0)
|
|
278
|
+
this.camera.updateProjectionMatrix()
|
|
279
|
+
|
|
280
|
+
if (this.orbitControl) {
|
|
281
|
+
this.orbitControl.maxPolarAngle = Math.PI / 2
|
|
282
|
+
this.orbitControl.target.set(x, y, 0)
|
|
283
|
+
|
|
284
|
+
this.orbitControl.screenSpacePanning = true
|
|
285
|
+
this.orbitControl.object = this.camera
|
|
286
|
+
this.orbitControl.mouseButtons = {
|
|
287
|
+
LEFT: THREE.MOUSE.PAN,
|
|
288
|
+
MIDDLE: THREE.MOUSE.DOLLY,
|
|
289
|
+
RIGHT: THREE.MOUSE.ROTATE
|
|
290
|
+
}
|
|
291
|
+
this.orbitControl.enableRotate = false
|
|
292
|
+
this.orbitControl.update()
|
|
293
|
+
}
|
|
294
|
+
},
|
|
295
|
+
setOrthographicCameraGlobalPosition() {
|
|
296
|
+
const left =
|
|
297
|
+
this.roofsBounds.xMin / 1000 - marginAroundBuildingForCameraViewInMeter
|
|
298
|
+
const right =
|
|
299
|
+
this.roofsBounds.xMax / 1000 + marginAroundBuildingForCameraViewInMeter
|
|
300
|
+
const top =
|
|
301
|
+
this.roofsBounds.yMax / 1000 + marginAroundBuildingForCameraViewInMeter
|
|
302
|
+
const bottom =
|
|
303
|
+
this.roofsBounds.yMin / 1000 - marginAroundBuildingForCameraViewInMeter
|
|
304
|
+
const zoom = 1
|
|
305
|
+
const x = (this.roofsBounds.xMin + this.roofsBounds.xMax) / 2000
|
|
306
|
+
const y = (this.roofsBounds.yMin + this.roofsBounds.yMax) / 2000
|
|
307
|
+
|
|
308
|
+
this.setOrthographicCameraPositionFromCameraParameters({
|
|
309
|
+
left,
|
|
310
|
+
right,
|
|
311
|
+
top,
|
|
312
|
+
bottom,
|
|
313
|
+
zoom,
|
|
314
|
+
x,
|
|
315
|
+
y
|
|
316
|
+
})
|
|
163
317
|
},
|
|
164
318
|
setCameraGlobalPosition() {
|
|
165
319
|
if (this.roofs.length == 0) return
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
320
|
+
if (this.camera.isOrthographicCamera) {
|
|
321
|
+
this.setOrthographicCameraGlobalPosition()
|
|
322
|
+
} else {
|
|
323
|
+
let newFov = 50
|
|
324
|
+
let bounds = this.roofsBounds
|
|
325
|
+
let targetVector = {
|
|
326
|
+
x: (bounds.xMax + bounds.xMin) / 2000,
|
|
327
|
+
y: (bounds.yMax + bounds.yMin) / 2000,
|
|
328
|
+
z: 0
|
|
329
|
+
}
|
|
330
|
+
let objectRadius_m =
|
|
331
|
+
marginAroundBuildingForCameraViewInMeter +
|
|
332
|
+
Math.max(
|
|
333
|
+
(bounds.xMax - bounds.xMin) / 2000,
|
|
334
|
+
(bounds.yMax - bounds.yMin) / 2000
|
|
335
|
+
)
|
|
336
|
+
let distance = objectRadius_m / Math.sin(((newFov / 2) * Math.PI) / 180)
|
|
337
|
+
let cameraMoveVector = { x: 0, y: 0, z: distance }
|
|
338
|
+
const positionVector = addVector(targetVector, cameraMoveVector)
|
|
339
|
+
const position = [
|
|
340
|
+
positionVector.x,
|
|
341
|
+
positionVector.y - distance,
|
|
342
|
+
positionVector.z
|
|
343
|
+
]
|
|
344
|
+
let target = [targetVector.x, targetVector.y, targetVector.z]
|
|
345
|
+
this.setTweenTo({ position, target, fov: newFov })
|
|
172
346
|
}
|
|
173
|
-
let objectRadius_m = Math.max(
|
|
174
|
-
(bounds.xMax - bounds.xMin) / 2000,
|
|
175
|
-
(bounds.yMax - bounds.yMin) / 2000
|
|
176
|
-
)
|
|
177
|
-
let distance =
|
|
178
|
-
5 + objectRadius_m / Math.sin(((newFov / 2) * Math.PI) / 180)
|
|
179
|
-
let cameraMoveVector = { x: 0, y: 0, z: distance }
|
|
180
|
-
const positionVector = addVector(targetVector, cameraMoveVector)
|
|
181
|
-
const position = [
|
|
182
|
-
positionVector.x,
|
|
183
|
-
positionVector.y - distance,
|
|
184
|
-
positionVector.z
|
|
185
|
-
]
|
|
186
|
-
let target = [targetVector.x, targetVector.y, targetVector.z]
|
|
187
|
-
this.setTweenTo(position, target, newFov)
|
|
188
347
|
},
|
|
189
348
|
setCameraGlobalVerticalPosition() {
|
|
190
349
|
let position, target
|
|
@@ -211,12 +370,12 @@ export default {
|
|
|
211
370
|
position = [0, 0, 300]
|
|
212
371
|
target = [0, 0, 0]
|
|
213
372
|
}
|
|
214
|
-
this.setTweenTo(
|
|
373
|
+
this.setTweenTo({
|
|
215
374
|
position,
|
|
216
375
|
target,
|
|
217
|
-
newFov,
|
|
218
|
-
this.turnPerspectiveCameraToOrthogonal
|
|
219
|
-
)
|
|
376
|
+
fov: newFov,
|
|
377
|
+
callback: this.turnPerspectiveCameraToOrthogonal
|
|
378
|
+
})
|
|
220
379
|
},
|
|
221
380
|
setCameraOrthogonalTo(polygon) {
|
|
222
381
|
if (polygon) {
|
|
@@ -236,7 +395,7 @@ export default {
|
|
|
236
395
|
positionVector.y / 1000 - 1,
|
|
237
396
|
positionVector.z / 1000
|
|
238
397
|
]
|
|
239
|
-
this.setTweenTo(position, target)
|
|
398
|
+
this.setTweenTo({ position, target })
|
|
240
399
|
}
|
|
241
400
|
},
|
|
242
401
|
setCameraSideTo(polygon) {
|
|
@@ -262,10 +421,17 @@ export default {
|
|
|
262
421
|
positionVector.y / 1000,
|
|
263
422
|
positionVector.z / 1000 + 5
|
|
264
423
|
]
|
|
265
|
-
this.setTweenTo(position, target)
|
|
424
|
+
this.setTweenTo({ position, target })
|
|
266
425
|
}
|
|
267
426
|
},
|
|
268
|
-
setTweenTo(
|
|
427
|
+
setTweenTo(payload) {
|
|
428
|
+
const {
|
|
429
|
+
position,
|
|
430
|
+
target,
|
|
431
|
+
fov = 50,
|
|
432
|
+
duration = 2000,
|
|
433
|
+
callback = () => {}
|
|
434
|
+
} = payload
|
|
269
435
|
TWEEN.removeAll()
|
|
270
436
|
if (this.camera) {
|
|
271
437
|
const currentTweenVar = {
|
|
@@ -298,7 +464,7 @@ export default {
|
|
|
298
464
|
initialCameraPosition.x - finalCameraPosition.x
|
|
299
465
|
)
|
|
300
466
|
this.tweenCamera = new TWEEN.Tween(currentTweenVar)
|
|
301
|
-
.to({ t: 1 },
|
|
467
|
+
.to({ t: 1 }, duration)
|
|
302
468
|
.easing(TWEEN.Easing.Sinusoidal.Out)
|
|
303
469
|
.onUpdate(() => {
|
|
304
470
|
const t = currentTweenVar.t
|
|
@@ -341,13 +507,12 @@ export default {
|
|
|
341
507
|
this.orbitControl.update()
|
|
342
508
|
})
|
|
343
509
|
.onComplete(() => {
|
|
344
|
-
|
|
510
|
+
callback()
|
|
345
511
|
})
|
|
346
512
|
} else {
|
|
347
|
-
console.log('setTween Camera not Vertical')
|
|
348
513
|
this.camera.up = { x: 0, y: 0, z: 1 }
|
|
349
514
|
this.tweenCamera = new TWEEN.Tween(currentTweenVar)
|
|
350
|
-
.to({ t: 1 },
|
|
515
|
+
.to({ t: 1 }, duration)
|
|
351
516
|
.easing(TWEEN.Easing.Sinusoidal.Out)
|
|
352
517
|
.onUpdate(() => {
|
|
353
518
|
const t = currentTweenVar.t
|
|
@@ -383,12 +548,24 @@ export default {
|
|
|
383
548
|
if (this.orbitControl && this.orbitControl.update)
|
|
384
549
|
this.orbitControl.update()
|
|
385
550
|
})
|
|
551
|
+
.onComplete(() => {
|
|
552
|
+
callback()
|
|
553
|
+
})
|
|
386
554
|
}
|
|
387
555
|
this.tweenCamera.start()
|
|
556
|
+
TWEEN.update()
|
|
557
|
+
}
|
|
558
|
+
},
|
|
559
|
+
animate(e) {
|
|
560
|
+
if (!!TWEEN) {
|
|
561
|
+
TWEEN.update()
|
|
388
562
|
}
|
|
563
|
+
this.animationFrameId = requestAnimationFrame(this.animate)
|
|
389
564
|
}
|
|
390
565
|
},
|
|
566
|
+
|
|
391
567
|
beforeDestroy() {
|
|
392
568
|
TWEEN.removeAll()
|
|
569
|
+
cancelAnimationFrame(this.animationFrameId)
|
|
393
570
|
}
|
|
394
571
|
}
|