@jdultra/threedtiles 5.1.2 → 5.1.4

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@jdultra/threedtiles",
3
- "version": "5.1.2",
3
+ "version": "5.1.4",
4
4
  "description": "An OGC 3DTiles viewer for Three.js",
5
5
  "main": "tileset.js",
6
6
  "scripts": {
@@ -8,10 +8,15 @@ const dracoLoader = new DRACOLoader();
8
8
  const tempMatrix = new THREE.Matrix4();
9
9
  dracoLoader.setDecoderPath('https://www.gstatic.com/draco/versioned/decoders/1.4.3/');
10
10
  gltfLoader.setDRACOLoader(dracoLoader);
11
+ const zUpToYUpMatrix = new THREE.Matrix4();
12
+ zUpToYUpMatrix.set(1,0,0,0,
13
+ 0,0,-1,0,
14
+ 0,1,0,0,
15
+ 0,0,0,1);
11
16
 
12
17
  //const legacyGLTFLoader = new LegacyGLTFLoader();
13
18
 
14
- function parseB3DM(arrayBuffer, meshCallback) {
19
+ function parseB3DM(arrayBuffer, meshCallback, zUpToYUp) {
15
20
  const dataView = new DataView(arrayBuffer);
16
21
 
17
22
  const magic =
@@ -68,7 +73,11 @@ function parseB3DM(arrayBuffer, meshCallback) {
68
73
  }
69
74
 
70
75
  model.scene.traverse((o) => {
76
+
71
77
  if (o.isMesh) {
78
+ if(zUpToYUp){
79
+ o.applyMatrix4(zUpToYUpMatrix);
80
+ }
72
81
  if (!!meshCallback) {
73
82
  meshCallback(o);
74
83
  }
@@ -84,9 +93,9 @@ function parseB3DM(arrayBuffer, meshCallback) {
84
93
 
85
94
  const B3DMDecoder = {
86
95
  parseB3DM: parseB3DM,
87
- parseB3DMInstanced: (arrayBuffer, meshCallback, maxCount) => { // expects GLTF with one node level
96
+ parseB3DMInstanced: (arrayBuffer, meshCallback, maxCount, zUpToYUp) => { // expects GLTF with one node level
88
97
 
89
- return parseB3DM(arrayBuffer, meshCallback).then(mesh => {
98
+ return parseB3DM(arrayBuffer, meshCallback, zUpToYUp).then(mesh => {
90
99
  let instancedMesh;
91
100
  mesh.updateWorldMatrix(false, true)
92
101
  mesh.traverse(child => {
package/src/index.js CHANGED
@@ -51,7 +51,7 @@ function initScene() {
51
51
  //scene.matrixWorldAutoUpdate = false;
52
52
  scene.background = new THREE.Color(0xffffff);
53
53
  scene.add(new THREE.AmbientLight(0xFFFFFF, 1.0));
54
-
54
+
55
55
  /* const light = new THREE.PointLight(0xbbbbff, 2, 5000);
56
56
  const sphere = new THREE.SphereGeometry(2, 16, 8);
57
57
  light.add(new THREE.Mesh(sphere, new THREE.MeshBasicMaterial({ color: 0xbbbbff })));
@@ -113,7 +113,7 @@ function initStats(dom) {
113
113
 
114
114
  function initCamera(width, height) {
115
115
  const camera = new THREE.PerspectiveCamera(60, width / height, 1, 100000);
116
- camera.position.set(10000,0,0);
116
+ camera.position.set(15,0,0);
117
117
  camera.lookAt(0,0,0);
118
118
 
119
119
  camera.matrixAutoUpdate = true;
@@ -130,9 +130,7 @@ function initTileset(scene, gem) {
130
130
  }, 100);
131
131
 
132
132
  const ogc3DTile = new OGC3DTile({
133
- //url: "https://sampledata.luciad.com/data/ogc3dtiles/LucerneAirborneMesh/tileset.json",
134
- url: "https://sampleservices.luciad.com/ogc/3dtiles/marseille-mesh/tileset.json",
135
- //url: "https://storage.googleapis.com/ogc-3d-tiles/baltimore/tileset.json",
133
+ url: "https://storage.googleapis.com/ogc-3d-tiles/baltimore/tileset.json",
136
134
  //url: "https://storage.googleapis.com/ogc-3d-tiles/berlinTileset/tileset.json",
137
135
  geometricErrorMultiplier: gem,
138
136
  loadOutsideView: false,
@@ -141,13 +139,12 @@ function initTileset(scene, gem) {
141
139
  static: false,
142
140
  centerModel:true,
143
141
  renderer: renderer,
144
- /* onLoadCallback: (tile)=>{
142
+ onLoadCallback: (tile)=>{ // move tileset base to origin
145
143
  if (!!tile.json.boundingVolume.region) {
146
144
  const halfHeight = (tile.json.boundingVolume.region[5] - tile.json.boundingVolume.region[4]) * 0.5;
147
145
  ogc3DTile.translateOnAxis(new THREE.Vector3(0, 1, 0), halfHeight);
148
- //ogc3DTile.updateWorldMatrix(true, true);
149
146
  }
150
- } */
147
+ }
151
148
 
152
149
  });
153
150
  setIntervalAsync(function () {
@@ -185,10 +182,7 @@ function initInstancedTilesets(instancedTileLoader) {
185
182
 
186
183
 
187
184
  const tileset = new InstancedOGC3DTile({
188
- //url: "https://storage.googleapis.com/ogc-3d-tiles/berlinTileset/tileset.json",
189
- url: "https://sampleservices.luciad.com/ogc/3dtiles/marseille-mesh/tileset.json",
190
- //url: "https://s3.eu-central-2.wasabisys.com/construkted-assets-eu/ab13lasdc9i/tileset.json",
191
- //url: "http://localhost:8081/tileset.json",
185
+ url: "https://storage.googleapis.com/ogc-3d-tiles/berlinTileset/tileset.json",
192
186
  geometricErrorMultiplier: 1.0,
193
187
  loadOutsideView: true,
194
188
  tileLoader: instancedTileLoader,
@@ -236,8 +230,8 @@ function initLODMultiplierSlider(instancedTilesets) {
236
230
  function initController(camera, dom) {
237
231
  const controller = new OrbitControls(camera, dom);
238
232
 
233
+ //controller.target.set(4629210.73133627, 435359.7901640832, 4351492.357788198);
239
234
  controller.target.set(0,0,0);
240
- //controller.target.set(0,0,0);
241
235
 
242
236
 
243
237
  controller.minDistance = 0.1;
@@ -11,11 +11,7 @@ const tempVec2 = new THREE.Vector3(0, 0, 0);
11
11
  const upVector = new THREE.Vector3(0, 1, 0);
12
12
  const rendererSize = new THREE.Vector2();
13
13
  const tempQuaternion = new THREE.Quaternion();
14
- const zUpToYUp = new THREE.Matrix4();
15
- zUpToYUp.set(1,0,0,0,
16
- 0,0,-1,0,
17
- 0,1,0,0,
18
- 0,0,0,1);
14
+
19
15
 
20
16
  class OGC3DTile extends THREE.Object3D {
21
17
 
@@ -220,14 +216,14 @@ class OGC3DTile extends THREE.Object3D {
220
216
  if (!!url) {
221
217
  if (url.includes(".b3dm")) {
222
218
  self.contentURL = url;
223
- const rotateToYUp = !!self.json.boundingVolume.region;
219
+ if(!!self.json.boundingVolume.region){
220
+ //self.applyMatrix4(zUpToYUp);
221
+ }
224
222
  self.tileLoader.get(self.abortController, this.uuid, url, mesh => {
225
223
  if (!!self.deleted) return;
226
224
  mesh.traverse((o) => {
227
225
  if (o.isMesh) {
228
- if(rotateToYUp){
229
- o.applyMatrix4(zUpToYUp);
230
- }
226
+
231
227
  o.layers.disable(0);
232
228
  if (self.occlusionCullingService) {
233
229
  const position = o.geometry.attributes.position;
@@ -250,7 +246,10 @@ class OGC3DTile extends THREE.Object3D {
250
246
  self.meshContent = mesh;
251
247
  }, !self.cameraOnLoad ? () => 0 : () => {
252
248
  return self.calculateDistanceToCamera(self.cameraOnLoad);
253
- }, () => self.getSiblings(), self.level);
249
+ }, () => self.getSiblings(),
250
+ self.level,
251
+ !!this.json.boundingVolume.region
252
+ );
254
253
  } else if (url.includes(".json")) {
255
254
  self.tileLoader.get(self.abortController, this.uuid, url, json => {
256
255
  if (!!self.deleted) return;
@@ -142,7 +142,7 @@ class TileLoader {
142
142
  }
143
143
 
144
144
 
145
- get(abortController, tileIdentifier, path, callback, distanceFunction, getSiblings, level) {
145
+ get(abortController, tileIdentifier, path, callback, distanceFunction, getSiblings, level, zUpToYUp) {
146
146
  const self = this;
147
147
  const key = simplifyPath(path);
148
148
 
@@ -183,7 +183,7 @@ class TileLoader {
183
183
 
184
184
  })
185
185
  .then(resultArrayBuffer=>{
186
- return B3DMDecoder.parseB3DM(resultArrayBuffer, self.meshCallback);
186
+ return B3DMDecoder.parseB3DM(resultArrayBuffer, self.meshCallback, zUpToYUp);
187
187
  })
188
188
  .then(mesh=>{
189
189
  self.cache.put(key, mesh);
@@ -228,7 +228,9 @@ class TileLoader {
228
228
 
229
229
  invalidate(path, tileIdentifier) {
230
230
  const key = simplifyPath(path);
231
- delete this.register[key][tileIdentifier];
231
+ if(!!this.register[key]){
232
+ delete this.register[key][tileIdentifier];
233
+ }
232
234
  }
233
235
 
234
236
  checkSize() {
@@ -217,7 +217,9 @@ class InstancedTile extends THREE.Object3D {
217
217
 
218
218
  self.tileLoader.get(self.abortController, url, self.uuid, self, !self.cameraOnLoad ? () => 0 : () => {
219
219
  return self.calculateDistanceToCamera(self.cameraOnLoad);
220
- }, () => self.getSiblings(), self.level);
220
+ }, () => self.getSiblings(),
221
+ self.level,
222
+ !!self.json.boundingVolume.region);
221
223
  } else if (url.includes(".json")) {
222
224
  self.tileLoader.get(self.abortController, url, self.uuid, self);
223
225
 
@@ -68,7 +68,7 @@ class InstancedTileLoader {
68
68
 
69
69
  })
70
70
  .then(resultArrayBuffer=>{
71
- return B3DMDecoder.parseB3DMInstanced(resultArrayBuffer, self.meshCallback, self.maxInstances);
71
+ return B3DMDecoder.parseB3DMInstanced(resultArrayBuffer, self.meshCallback, self.maxInstances, nextDownload.zUpToYUp);
72
72
  })
73
73
  .then(mesh=>{
74
74
  nextDownload.tile.setObject(mesh);
@@ -138,7 +138,7 @@ class InstancedTileLoader {
138
138
  }
139
139
  }
140
140
 
141
- get(abortController, path, uuid, instancedOGC3DTile, distanceFunction, getSiblings, level) {
141
+ get(abortController, path, uuid, instancedOGC3DTile, distanceFunction, getSiblings, level, zUpToYUp) {
142
142
  const self = this;
143
143
  const key = simplifyPath(path);
144
144
 
@@ -156,9 +156,7 @@ class InstancedTileLoader {
156
156
  if (path.includes(".b3dm")) {
157
157
  const tile = new MeshTile(self.scene);
158
158
  tile.addInstance(instancedOGC3DTile);
159
- if(self.cache.has(key)){
160
- console.log("élkbhj")
161
- }
159
+
162
160
  self.cache.put(key, tile);
163
161
 
164
162
  const realAbortController = new AbortController();
@@ -176,6 +174,7 @@ class InstancedTileLoader {
176
174
  getSiblings: getSiblings,
177
175
  level: level,
178
176
  uuid: uuid,
177
+ zUpToYUp: zUpToYUp,
179
178
  shouldDoDownload: () => {
180
179
  return true;
181
180
  },