@eturnity/eturnity_3d 8.37.0 → 8.40.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@eturnity/eturnity_3d",
3
3
  "private": false,
4
- "version": "8.37.0",
4
+ "version": "8.40.1",
5
5
  "files": [
6
6
  "dist",
7
7
  "src"
@@ -73,22 +73,32 @@ export default {
73
73
  setCameraAspectRatio() {
74
74
  const canvasRatio = this.getCanvasRatio()
75
75
  if (this.camera.isOrthographicCamera) {
76
- const width = this.camera.right - this.camera.left
77
- const height = this.camera.top - this.camera.bottom
78
- const currentAspect = width / height
76
+ const currentAspect = Math.abs(
77
+ (this.camera.right - this.camera.left) /
78
+ (this.camera.top - this.camera.bottom)
79
+ )
80
+
81
+ // Calculate current half-width and half-height
82
+ const halfWidth = (this.camera.right - this.camera.left) / 2
83
+ const halfHeight = (this.camera.top - this.camera.bottom) / 2
84
+
85
+ // Adjust dimensions to match new aspect ratio
86
+ let newHalfWidth, newHalfHeight
79
87
  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
88
+ // Canvas is wider, adjust width
89
+ newHalfHeight = halfHeight
90
+ newHalfWidth = halfHeight * canvasRatio
85
91
  } else {
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
92
+ // Canvas is taller, adjust height
93
+ newHalfWidth = halfWidth
94
+ newHalfHeight = halfWidth / canvasRatio
91
95
  }
96
+
97
+ // Set new boundaries (left+right=0, top+bottom=0)
98
+ this.camera.left = -newHalfWidth
99
+ this.camera.right = newHalfWidth
100
+ this.camera.top = newHalfHeight
101
+ this.camera.bottom = -newHalfHeight
92
102
  } else {
93
103
  this.camera.aspect = canvasRatio
94
104
  }
@@ -160,6 +170,7 @@ export default {
160
170
  if (this.composer) {
161
171
  this.composer.render()
162
172
  }
173
+ this.onWindowResize()
163
174
  },
164
175
  turnOrthogonalCameraToPerspective() {
165
176
  if (this.perspectiveCamera.id == this.camera.id) {
@@ -215,6 +226,7 @@ export default {
215
226
  if (this.composer) {
216
227
  this.composer.render()
217
228
  }
229
+ this.onWindowResize()
218
230
  },
219
231
  zoomIn3D() {
220
232
  if (this.camera.isOrthographicCamera) {
@@ -318,7 +330,9 @@ export default {
318
330
  this.camera.far = 10000
319
331
  this.camera.zoom = zoom
320
332
 
321
- this.camera.position.set(x, y, 100)
333
+ const cameraAltitude =
334
+ (top - bottom) / Math.sin(((50 / 2) * Math.PI) / 180) / zoom
335
+ this.camera.position.set(x, y, cameraAltitude * zoom)
322
336
  this.camera.lookAt(x, y, 0)
323
337
  this.setCameraAspectRatio()
324
338
  this.camera.updateProjectionMatrix()
@@ -341,20 +355,34 @@ export default {
341
355
  setOrthographicCameraGlobalPosition(
342
356
  cameraOffset = { x_m: 0, y_m: 0, z_m: 0 }
343
357
  ) {
358
+ const cameraRatio =
359
+ (this.camera.right - this.camera.left) /
360
+ (this.camera.top - this.camera.bottom)
361
+
344
362
  const halfWidth = (this.roofsBounds.xMax - this.roofsBounds.xMin) / 2000
345
363
  const halfHeight = (this.roofsBounds.yMax - this.roofsBounds.yMin) / 2000
346
364
 
347
- let left = -halfWidth - marginAroundBuildingForCameraViewInMeter
348
- let right = halfWidth + marginAroundBuildingForCameraViewInMeter
365
+ let left = halfWidth - marginAroundBuildingForCameraViewInMeter
366
+ let right = -left
349
367
  let top = halfHeight + marginAroundBuildingForCameraViewInMeter
350
- let bottom = -halfHeight - marginAroundBuildingForCameraViewInMeter
368
+ let bottom = -top
369
+ let width = right - left
370
+ let height = top - bottom
371
+ if (cameraRatio < width / height) {
372
+ top = width / cameraRatio / 2
373
+ bottom = -width / cameraRatio / 2
374
+ } else {
375
+ left = -(height * cameraRatio) / 2
376
+ right = (height * cameraRatio) / 2
377
+ }
351
378
 
352
379
  const zoom = 1
380
+
353
381
  const x =
354
- (this.roofsBounds.xMin + this.roofsBounds.xMax) / 2000 +
382
+ (this.roofsBounds.xMax + this.roofsBounds.xMin) / 2000 +
355
383
  cameraOffset.x_m
356
384
  const y =
357
- (this.roofsBounds.yMin + this.roofsBounds.yMax) / 2000 +
385
+ (this.roofsBounds.yMax + this.roofsBounds.yMin) / 2000 +
358
386
  cameraOffset.y_m
359
387
 
360
388
  this.setOrthographicCameraPositionFromCameraParameters({
@@ -0,0 +1,65 @@
1
+ import * as THREE from 'three'
2
+
3
+ // Helper vectors for distance calculations
4
+ const _v1 = new THREE.Vector3()
5
+ const _v2 = new THREE.Vector3()
6
+
7
+ export class CustomLOD extends THREE.LOD {
8
+ constructor() {
9
+ super()
10
+ }
11
+
12
+ update(camera) {
13
+ // Check if camera is orthographic
14
+ if (camera.isOrthographicCamera) {
15
+ // Custom implementation for orthographic cameras
16
+ const levels = this.levels
17
+
18
+ if (levels.length > 1) {
19
+ _v1.setFromMatrixPosition(camera.matrixWorld)
20
+ _v2.setFromMatrixPosition(this.matrixWorld)
21
+
22
+ // For orthographic cameras, use distance along the camera's vertical axis
23
+ const cameraDirection = new THREE.Vector3()
24
+ camera.getWorldDirection(cameraDirection)
25
+
26
+ // Calculate the vector from camera to object
27
+ const toObject = _v2.clone().sub(_v1)
28
+
29
+ // Get distance along camera's view direction
30
+ const distance = Math.abs(toObject.dot(cameraDirection)) / camera.zoom
31
+
32
+ levels[0].object.visible = true
33
+
34
+ let i, l
35
+
36
+ for (i = 1, l = levels.length; i < l; i++) {
37
+ let levelDistance = levels[i].distance
38
+
39
+ if (levels[i].object.visible) {
40
+ levelDistance -= levelDistance * levels[i].hysteresis
41
+ }
42
+
43
+ if (distance >= levelDistance) {
44
+ levels[i - 1].object.visible = false
45
+ levels[i].object.visible = true
46
+ } else {
47
+ break
48
+ }
49
+ }
50
+
51
+ this._currentLevel = i - 1
52
+
53
+ for (; i < l; i++) {
54
+ levels[i].object.visible = false
55
+ }
56
+ }
57
+ } else {
58
+ // Use the original THREE.LOD update method for perspective cameras
59
+ super.update(camera)
60
+ }
61
+ }
62
+ }
63
+
64
+ // Also export as default for convenience
65
+ export default CustomLOD
@@ -1,5 +1,5 @@
1
1
  import * as THREE from 'three'
2
-
2
+ import { CustomLOD } from './CustomLOD'
3
3
  export default {
4
4
  created() {},
5
5
  methods: {
@@ -10,7 +10,7 @@ export default {
10
10
  if (this.meshes.markerMesh) {
11
11
  return
12
12
  }
13
- //const lod = new THREE.LOD()
13
+ const lod = new CustomLOD()
14
14
  const sphereGeometry = new THREE.SphereGeometry(1, 32, 32) // Initial radius of 5
15
15
  const coneGeometry = new THREE.ConeGeometry(0.98, 2, 32)
16
16
 
@@ -41,21 +41,18 @@ export default {
41
41
 
42
42
  markerMesh.add(sphereMesh)
43
43
  markerMesh.userData = { id: 'marker' }
44
- markerMesh.position.set(roofCenter.x, roofCenter.y, roofCenter.z + 10)
45
- markerMesh.scale.set(3, 3, 3)
46
- // for (let i = 1; i < 10; i++) {
47
- // const mesh = markerMesh.clone()
48
- // mesh.scale.set(i * 3, i * 3, i * 3)
49
- // mesh.position.set(0, 0, 12 * i)
50
- // lod.addLevel(mesh, (i - 1) * 100)
51
- // }
52
- // const lastMesh = markerMesh.clone()
53
- // lastMesh.scale.set(150, 150, 150)
54
- // lastMesh.position.set(0, 0, 600)
55
- // lod.addLevel(lastMesh, 1000)
56
- // this.scene.add(lod)
57
- this.scene.add(markerMesh)
58
- this.meshes.markerMesh = markerMesh
44
+ markerMesh.position.set(0, 0, 0)
45
+ markerMesh.scale.set(1, 1, 1)
46
+ for (let i = 1; i < 50; i++) {
47
+ const mesh = markerMesh.clone()
48
+ mesh.scale.set(2 * i, 2 * i, 2 * i)
49
+ mesh.position.set(0, 0, 5 * i)
50
+ lod.addLevel(mesh, (i - 1) * 200)
51
+ }
52
+ lod.position.set(roofCenter.x, roofCenter.y, 2 * roofCenter.z)
53
+ lod.updateMatrix()
54
+ this.scene.add(lod)
55
+ this.meshes.markerMesh = lod
59
56
  },
60
57
  showMarker() {
61
58
  if (!this.meshes.markerMesh) {
@@ -20,7 +20,7 @@ export default {
20
20
  params.is_marker_visible || params.is_marker_visible == undefined
21
21
  ? this.showMarker()
22
22
  : this.hideMarker()
23
- params.view_mode == '3d' || params.is_panel_visible == undefined
23
+ params.view_mode == '3d'
24
24
  ? this.turnOrthogonalCameraToPerspective()
25
25
  : this.turnPerspectiveCameraToOrthogonal()
26
26
  if (params.map_layer != undefined) {
@@ -70,7 +70,6 @@ export default {
70
70
  const latitude = this.layoutSettings.layout_latitude
71
71
  const longitude = this.layoutSettings.layout_longitude
72
72
  let { xMin, xMax, yMin, yMax } = this.roofsBounds
73
-
74
73
  if (xMin == Infinity) {
75
74
  xMin = 0
76
75
  yMin = 0
@@ -107,10 +106,10 @@ export default {
107
106
  longitude + lngMax,
108
107
  zoomLvl
109
108
  )
110
- xTileMin = xTileMin - (xTileMin % 2)
111
- xTileMax = xTileMax + 1 - (xTileMax % 2)
112
- yTileMin = yTileMin - (yTileMin % 2)
113
- yTileMax = yTileMax + 1 - (yTileMax % 2)
109
+ xTileMin = xTileMin - (xTileMin % 2) - 2
110
+ xTileMax = xTileMax + 1 - (xTileMax % 2) + 2
111
+ yTileMin = yTileMin - (yTileMin % 2) - 2
112
+ yTileMax = yTileMax + 1 - (yTileMax % 2) + 2
114
113
  this.tileToRender = []
115
114
  for (let xTile = xTileMin; xTile <= xTileMax; xTile++) {
116
115
  for (let yTile = yTileMin; yTile <= yTileMax; yTile++) {
@@ -132,7 +131,7 @@ export default {
132
131
  })
133
132
  }
134
133
  }
135
- while (zoomLvl > 17) {
134
+ while (zoomLvl > 16) {
136
135
  xTileMin = xTileMin / 2 - 1
137
136
  xTileMax = (xTileMax + 1) / 2
138
137
  yTileMin = yTileMin / 2 - 1
@@ -333,7 +332,11 @@ export default {
333
332
  resolve()
334
333
  })
335
334
  .catch((err) => {
336
- reject()
335
+ this.isReady = {
336
+ ...this.isReady,
337
+ texturesToLoad: this.isReady.texturesToLoad - 1,
338
+ }
339
+ reject(err)
337
340
  })
338
341
  })
339
342
  return promise
@@ -444,6 +447,10 @@ export default {
444
447
  texturesToLoad: this.isReady.texturesToLoad + 1,
445
448
  }
446
449
  this.loader.load(googleBackgroundUrl, (texture) => {
450
+ this.isReady = {
451
+ ...this.isReady,
452
+ texturesLoaded: this.isReady.texturesLoaded + 1,
453
+ }
447
454
  texture.encoding = THREE.sRGBEncoding
448
455
  texture.colorSpace = THREE.SRGBColorSpace
449
456
  planeTexture[indexGoogleBackground] = texture
@@ -494,10 +501,6 @@ export default {
494
501
  this.googleBackgroundMap.castShadow = false
495
502
  this.render()
496
503
  }
497
- this.isReady = {
498
- ...this.isReady,
499
- texturesLoaded: this.isReady.texturesLoaded + 1,
500
- }
501
504
  })
502
505
  }
503
506
 
@@ -509,6 +512,10 @@ export default {
509
512
  this.pendingTiles = this.pendingTiles.filter((t) => {
510
513
  if (t.mapLayer != newMapLayer.key) {
511
514
  t.imagePromise.cancel()
515
+ this.isReady = {
516
+ ...this.isReady,
517
+ texturesToLoad: this.isReady.texturesToLoad - 1,
518
+ }
512
519
  return false
513
520
  }
514
521
  return true
@@ -115,6 +115,9 @@ export default {
115
115
  if (methodList.length) {
116
116
  this.renderMethods(methodList)
117
117
  this.render()
118
+ if (this.handleOrbitControlChange) {
119
+ this.handleOrbitControlChange()
120
+ }
118
121
  }
119
122
 
120
123
  this.lastGeometryEventIdDone = this.lastGeometryEventId
@@ -262,15 +262,19 @@ export default {
262
262
  this.render()
263
263
  },
264
264
  onWindowResize() {
265
- if (this.orbitControl) {
266
- this.orbitControl.update()
265
+ const clientHeight = this.DOMElement.clientHeight
266
+ const clientWidth = this.DOMElement.clientWidth
267
+ if (clientHeight && clientWidth) {
268
+ if (this.orbitControl) {
269
+ this.orbitControl.update()
270
+ }
271
+ this.canvasOffset = this.getCanvasOffset()
272
+ this.canvasHeight = clientHeight
273
+ this.canvasWidth = clientWidth
274
+ this.resizeRenderer()
275
+ this.setCameraAspectRatio()
276
+ this.render()
267
277
  }
268
- this.canvasOffset = this.getCanvasOffset()
269
- this.canvasHeight = this.DOMElement.clientHeight
270
- this.canvasWidth = this.DOMElement.clientWidth
271
- this.resizeRenderer()
272
- this.setCameraAspectRatio()
273
- this.render()
274
278
  },
275
279
  onCanvasResize() {
276
280
  const canvas = this.renderer.domElement
@@ -280,7 +284,7 @@ export default {
280
284
  this.resizeRenderer()
281
285
 
282
286
  if (this.composer) {
283
- this.composer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
287
+ this.composer.setPixelRatio(window.devicePixelRatio)
284
288
  if (this.composer.setViewport) {
285
289
  this.composer.setViewport(0, 0, width, height)
286
290
  }