@eturnity/eturnity_3d 8.34.6 → 8.37.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/package.json +1 -1
- package/src/helper/cameraMixin.js +48 -46
package/package.json
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import TWEEN from 'tween'
|
|
2
2
|
import * as THREE from 'three'
|
|
3
|
-
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'
|
|
4
3
|
import {
|
|
5
4
|
addVector,
|
|
6
5
|
getDistanceBetweenPoints,
|
|
@@ -24,8 +23,27 @@ export default {
|
|
|
24
23
|
),
|
|
25
24
|
}
|
|
26
25
|
},
|
|
27
|
-
created() {},
|
|
28
26
|
methods: {
|
|
27
|
+
getCanvasRatio() {
|
|
28
|
+
const w = this.DOMElement.clientWidth
|
|
29
|
+
const h = this.DOMElement.clientHeight
|
|
30
|
+
if (w > 0 && h > 0) {
|
|
31
|
+
return w / h
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Fallback use canvas size
|
|
35
|
+
const canvas = this.DOMElement.querySelector('canvas')
|
|
36
|
+
if (canvas) {
|
|
37
|
+
const w = canvas.clientWidth || canvas.width
|
|
38
|
+
const h = canvas.clientHeight || canvas.height
|
|
39
|
+
if (w > 0 && h > 0) {
|
|
40
|
+
return w / h
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Safe default
|
|
45
|
+
return 1
|
|
46
|
+
},
|
|
29
47
|
initialiseCameras(isPerspectiveCamera) {
|
|
30
48
|
if (isPerspectiveCamera) {
|
|
31
49
|
this.camera = this.perspectiveCamera
|
|
@@ -53,19 +71,23 @@ export default {
|
|
|
53
71
|
this.render()
|
|
54
72
|
},
|
|
55
73
|
setCameraAspectRatio() {
|
|
56
|
-
const canvasRatio =
|
|
57
|
-
this.DOMElement.clientWidth / this.DOMElement.clientHeight
|
|
74
|
+
const canvasRatio = this.getCanvasRatio()
|
|
58
75
|
if (this.camera.isOrthographicCamera) {
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
this.camera.
|
|
76
|
+
const width = this.camera.right - this.camera.left
|
|
77
|
+
const height = this.camera.top - this.camera.bottom
|
|
78
|
+
const currentAspect = width / height
|
|
79
|
+
if (canvasRatio > currentAspect) {
|
|
80
|
+
// canvas is wider expand width
|
|
81
|
+
const newWidth = height * canvasRatio
|
|
82
|
+
const centerX = (this.camera.left + this.camera.right) / 2
|
|
83
|
+
this.camera.left = centerX - newWidth / 2
|
|
84
|
+
this.camera.right = centerX + newWidth / 2
|
|
66
85
|
} else {
|
|
67
|
-
|
|
68
|
-
|
|
86
|
+
// canvas is taller expand height
|
|
87
|
+
const newHeight = width / canvasRatio
|
|
88
|
+
const centerY = (this.camera.top + this.camera.bottom) / 2
|
|
89
|
+
this.camera.top = centerY + newHeight / 2
|
|
90
|
+
this.camera.bottom = centerY - newHeight / 2
|
|
69
91
|
}
|
|
70
92
|
} else {
|
|
71
93
|
this.camera.aspect = canvasRatio
|
|
@@ -298,6 +320,7 @@ export default {
|
|
|
298
320
|
|
|
299
321
|
this.camera.position.set(x, y, 100)
|
|
300
322
|
this.camera.lookAt(x, y, 0)
|
|
323
|
+
this.setCameraAspectRatio()
|
|
301
324
|
this.camera.updateProjectionMatrix()
|
|
302
325
|
|
|
303
326
|
if (this.orbitControl) {
|
|
@@ -318,42 +341,21 @@ export default {
|
|
|
318
341
|
setOrthographicCameraGlobalPosition(
|
|
319
342
|
cameraOffset = { x_m: 0, y_m: 0, z_m: 0 }
|
|
320
343
|
) {
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
(this.camera.top - this.camera.bottom)
|
|
344
|
+
const halfWidth = (this.roofsBounds.xMax - this.roofsBounds.xMin) / 2000
|
|
345
|
+
const halfHeight = (this.roofsBounds.yMax - this.roofsBounds.yMin) / 2000
|
|
324
346
|
|
|
325
|
-
let left =
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
let right =
|
|
330
|
-
this.roofsBounds.xMax / 1000 +
|
|
331
|
-
marginAroundBuildingForCameraViewInMeter +
|
|
332
|
-
cameraOffset.x_m
|
|
333
|
-
let top =
|
|
334
|
-
this.roofsBounds.yMax / 1000 +
|
|
335
|
-
marginAroundBuildingForCameraViewInMeter +
|
|
336
|
-
cameraOffset.y_m
|
|
337
|
-
let bottom =
|
|
338
|
-
this.roofsBounds.yMin / 1000 -
|
|
339
|
-
marginAroundBuildingForCameraViewInMeter +
|
|
340
|
-
cameraOffset.y_m
|
|
341
|
-
let width = right - left
|
|
342
|
-
let height = top - bottom
|
|
343
|
-
if (cameraRatio < width / height) {
|
|
344
|
-
const centerY = (top + bottom) / 2
|
|
345
|
-
top = centerY + width / cameraRatio / 2
|
|
346
|
-
bottom = centerY - width / cameraRatio / 2
|
|
347
|
-
} else {
|
|
348
|
-
const centerX = (left + right) / 2
|
|
349
|
-
left = centerX - (height * cameraRatio) / 2
|
|
350
|
-
right = centerX + (height * cameraRatio) / 2
|
|
351
|
-
}
|
|
347
|
+
let left = -halfWidth - marginAroundBuildingForCameraViewInMeter
|
|
348
|
+
let right = halfWidth + marginAroundBuildingForCameraViewInMeter
|
|
349
|
+
let top = halfHeight + marginAroundBuildingForCameraViewInMeter
|
|
350
|
+
let bottom = -halfHeight - marginAroundBuildingForCameraViewInMeter
|
|
352
351
|
|
|
353
352
|
const zoom = 1
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
353
|
+
const x =
|
|
354
|
+
(this.roofsBounds.xMin + this.roofsBounds.xMax) / 2000 +
|
|
355
|
+
cameraOffset.x_m
|
|
356
|
+
const y =
|
|
357
|
+
(this.roofsBounds.yMin + this.roofsBounds.yMax) / 2000 +
|
|
358
|
+
cameraOffset.y_m
|
|
357
359
|
|
|
358
360
|
this.setOrthographicCameraPositionFromCameraParameters({
|
|
359
361
|
left,
|