@jdultra/threedtiles 5.1.0 → 5.1.2
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/README.md +17 -2
- package/package.json +1 -1
- package/src/decoder/B3DMDecoder.js +2 -2
- package/src/index.js +16 -6
- package/src/tileset/OGC3DTile.js +11 -3
- package/src/tileset/instanced/InstancedTile.js +2 -3
package/README.md
CHANGED
|
@@ -46,6 +46,7 @@ Currently, the library is limmited to B3DM files.
|
|
|
46
46
|
- Optimal tile load order
|
|
47
47
|
- Occlusion culling
|
|
48
48
|
- Instanced tilesets
|
|
49
|
+
- Center tileset and re-orient geolocated data
|
|
49
50
|
|
|
50
51
|
### geometric Error Multiplier
|
|
51
52
|
The geometric error multiplier allows you to multiply the geometric error by a factor.
|
|
@@ -88,11 +89,12 @@ This can be useful to position the tileset at a specific location when it is not
|
|
|
88
89
|
const ogc3DTile = new OGC3DTile({
|
|
89
90
|
url: "https://storage.googleapis.com/ogc-3d-tiles/ayutthaya/tileset.json",
|
|
90
91
|
renderer: renderer,
|
|
91
|
-
onLoadCallback:
|
|
92
|
-
console.log(tileset.boundingVolume);
|
|
92
|
+
onLoadCallback: tileset => {
|
|
93
|
+
console.log(tileset.json.boundingVolume);
|
|
93
94
|
}
|
|
94
95
|
});
|
|
95
96
|
```
|
|
97
|
+
Note that the callback is called with the OGC3DTile object as parameter and that this object has a "json" property giving you access to the original tileset.json with it's transform, geometric error, bounding volume, etc...
|
|
96
98
|
|
|
97
99
|
#### Mesh callback
|
|
98
100
|
Add a callback on loaded tiles in order to set a material or do some logic on the meshes.
|
|
@@ -239,6 +241,19 @@ function animate() {
|
|
|
239
241
|
animate();
|
|
240
242
|
|
|
241
243
|
```
|
|
244
|
+
### Center tileset and re-orient geolocated data
|
|
245
|
+
|
|
246
|
+
OGC3DTiles data is not necessarily centered on the origin and when it's georeferenced, it's also rotated relative to the cartesian coordinate system.
|
|
247
|
+
The optional property "centerModel" will center the model on the origin. In the case of georeferenced models, identified as those using the "region" bounding volume, it will also rotate it so that it's up-axis alligns with the y axis.
|
|
248
|
+
|
|
249
|
+
```
|
|
250
|
+
const ogc3DTile = new OGC3DTile({
|
|
251
|
+
url: "https://storage.googleapis.com/ogc-3d-tiles/ayutthaya/tileset.json",
|
|
252
|
+
renderer: renderer,
|
|
253
|
+
centerModel:true
|
|
254
|
+
});
|
|
255
|
+
```
|
|
256
|
+
This property is also available for instanced models.
|
|
242
257
|
|
|
243
258
|
### static tilesets and other performance tips
|
|
244
259
|
When you know your tileset will be static, you can specify it in the OGC3DTile object constructor parameter.
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@ 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
|
-
|
|
11
|
+
|
|
12
12
|
//const legacyGLTFLoader = new LegacyGLTFLoader();
|
|
13
13
|
|
|
14
14
|
function parseB3DM(arrayBuffer, meshCallback) {
|
|
@@ -63,7 +63,7 @@ function parseB3DM(arrayBuffer, meshCallback) {
|
|
|
63
63
|
|
|
64
64
|
const rtcCenter = featureTable.getData('RTC_CENTER');
|
|
65
65
|
if (rtcCenter) {
|
|
66
|
-
tempMatrix.makeTranslation(rtcCenter[0], rtcCenter[
|
|
66
|
+
tempMatrix.makeTranslation(rtcCenter[0], rtcCenter[1], rtcCenter[2])
|
|
67
67
|
model.scene.applyMatrix4(tempMatrix);
|
|
68
68
|
}
|
|
69
69
|
|
package/src/index.js
CHANGED
|
@@ -32,7 +32,6 @@ const controller = initController(camera, domContainer);
|
|
|
32
32
|
|
|
33
33
|
const composer = initComposer(scene, camera, renderer);
|
|
34
34
|
|
|
35
|
-
|
|
36
35
|
animate();
|
|
37
36
|
|
|
38
37
|
|
|
@@ -128,24 +127,35 @@ function initTileset(scene, gem) {
|
|
|
128
127
|
mesh.material.wireframe = false;
|
|
129
128
|
mesh.material.side = THREE.DoubleSide;
|
|
130
129
|
mesh.material.metalness = 0.0
|
|
131
|
-
}, 100)
|
|
130
|
+
}, 100);
|
|
131
|
+
|
|
132
132
|
const ogc3DTile = new OGC3DTile({
|
|
133
133
|
//url: "https://sampledata.luciad.com/data/ogc3dtiles/LucerneAirborneMesh/tileset.json",
|
|
134
134
|
url: "https://sampleservices.luciad.com/ogc/3dtiles/marseille-mesh/tileset.json",
|
|
135
135
|
//url: "https://storage.googleapis.com/ogc-3d-tiles/baltimore/tileset.json",
|
|
136
|
-
//url: "
|
|
136
|
+
//url: "https://storage.googleapis.com/ogc-3d-tiles/berlinTileset/tileset.json",
|
|
137
137
|
geometricErrorMultiplier: gem,
|
|
138
138
|
loadOutsideView: false,
|
|
139
139
|
tileLoader: tileLoader,
|
|
140
140
|
//occlusionCullingService: occlusionCullingService,
|
|
141
141
|
static: false,
|
|
142
142
|
centerModel:true,
|
|
143
|
-
renderer: renderer
|
|
143
|
+
renderer: renderer,
|
|
144
|
+
/* onLoadCallback: (tile)=>{
|
|
145
|
+
if (!!tile.json.boundingVolume.region) {
|
|
146
|
+
const halfHeight = (tile.json.boundingVolume.region[5] - tile.json.boundingVolume.region[4]) * 0.5;
|
|
147
|
+
ogc3DTile.translateOnAxis(new THREE.Vector3(0, 1, 0), halfHeight);
|
|
148
|
+
//ogc3DTile.updateWorldMatrix(true, true);
|
|
149
|
+
}
|
|
150
|
+
} */
|
|
144
151
|
|
|
145
152
|
});
|
|
146
153
|
setIntervalAsync(function () {
|
|
147
154
|
ogc3DTile.update(camera);
|
|
148
155
|
}, 20);
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
149
159
|
//ogc3DTile.rotateOnAxis(new THREE.Vector3(1, 0, 0), Math.PI * -0.5) // Z-UP to Y-UP
|
|
150
160
|
//ogc3DTile.translateOnAxis(new THREE.Vector3(0, 0, 1), 1)
|
|
151
161
|
/*
|
|
@@ -176,9 +186,9 @@ function initInstancedTilesets(instancedTileLoader) {
|
|
|
176
186
|
|
|
177
187
|
const tileset = new InstancedOGC3DTile({
|
|
178
188
|
//url: "https://storage.googleapis.com/ogc-3d-tiles/berlinTileset/tileset.json",
|
|
179
|
-
|
|
189
|
+
url: "https://sampleservices.luciad.com/ogc/3dtiles/marseille-mesh/tileset.json",
|
|
180
190
|
//url: "https://s3.eu-central-2.wasabisys.com/construkted-assets-eu/ab13lasdc9i/tileset.json",
|
|
181
|
-
url: "http://localhost:8081/tileset.json",
|
|
191
|
+
//url: "http://localhost:8081/tileset.json",
|
|
182
192
|
geometricErrorMultiplier: 1.0,
|
|
183
193
|
loadOutsideView: true,
|
|
184
194
|
tileLoader: instancedTileLoader,
|
package/src/tileset/OGC3DTile.js
CHANGED
|
@@ -11,6 +11,11 @@ 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
|
class OGC3DTile extends THREE.Object3D {
|
|
16
21
|
|
|
@@ -116,9 +121,8 @@ class OGC3DTile extends THREE.Object3D {
|
|
|
116
121
|
(this.json.boundingVolume.region[1] + this.json.boundingVolume.region[3]) * 0.5,
|
|
117
122
|
(this.json.boundingVolume.region[4] + this.json.boundingVolume.region[5]) * 0.5,
|
|
118
123
|
tempVec1);
|
|
119
|
-
tempVec2.set(tempVec1.x, tempVec1.z, -tempVec1.y);
|
|
120
124
|
|
|
121
|
-
tempQuaternion.setFromUnitVectors(
|
|
125
|
+
tempQuaternion.setFromUnitVectors(tempVec1.normalize(), upVector.normalize());
|
|
122
126
|
self.applyQuaternion(tempQuaternion);
|
|
123
127
|
}
|
|
124
128
|
|
|
@@ -171,7 +175,7 @@ class OGC3DTile extends THREE.Object3D {
|
|
|
171
175
|
this.transformWGS84ToCartesian(region[0], region[1], region[4], tempVec1);
|
|
172
176
|
this.transformWGS84ToCartesian(region[2], region[3], region[5], tempVec2);
|
|
173
177
|
tempVec1.lerp(tempVec2, 0.5);
|
|
174
|
-
this.boundingVolume = new THREE.Sphere(new THREE.Vector3(tempVec1.x, tempVec1.
|
|
178
|
+
this.boundingVolume = new THREE.Sphere(new THREE.Vector3(tempVec1.x, tempVec1.y, tempVec1.z), tempVec1.distanceTo(tempVec2));
|
|
175
179
|
} else if (!!this.json.boundingVolume.sphere) {
|
|
176
180
|
const sphere = this.json.boundingVolume.sphere;
|
|
177
181
|
this.boundingVolume = new THREE.Sphere(new THREE.Vector3(sphere[0], sphere[2], -sphere[1]), sphere[3]);
|
|
@@ -216,10 +220,14 @@ class OGC3DTile extends THREE.Object3D {
|
|
|
216
220
|
if (!!url) {
|
|
217
221
|
if (url.includes(".b3dm")) {
|
|
218
222
|
self.contentURL = url;
|
|
223
|
+
const rotateToYUp = !!self.json.boundingVolume.region;
|
|
219
224
|
self.tileLoader.get(self.abortController, this.uuid, url, mesh => {
|
|
220
225
|
if (!!self.deleted) return;
|
|
221
226
|
mesh.traverse((o) => {
|
|
222
227
|
if (o.isMesh) {
|
|
228
|
+
if(rotateToYUp){
|
|
229
|
+
o.applyMatrix4(zUpToYUp);
|
|
230
|
+
}
|
|
223
231
|
o.layers.disable(0);
|
|
224
232
|
if (self.occlusionCullingService) {
|
|
225
233
|
const position = o.geometry.attributes.position;
|
|
@@ -99,9 +99,8 @@ class InstancedTile extends THREE.Object3D {
|
|
|
99
99
|
(self.json.boundingVolume.region[1] + self.json.boundingVolume.region[3]) * 0.5,
|
|
100
100
|
(self.json.boundingVolume.region[4] + self.json.boundingVolume.region[5]) * 0.5,
|
|
101
101
|
tempVec1);
|
|
102
|
-
tempVec2.set(tempVec1.x, tempVec1.z, -tempVec1.y);
|
|
103
102
|
|
|
104
|
-
tempQuaternion.setFromUnitVectors(
|
|
103
|
+
tempQuaternion.setFromUnitVectors(tempVec1.normalize(), upVector.normalize());
|
|
105
104
|
self.master.applyQuaternion(tempQuaternion);
|
|
106
105
|
self.master.updateWorldMatrix(false, false)
|
|
107
106
|
}
|
|
@@ -170,7 +169,7 @@ class InstancedTile extends THREE.Object3D {
|
|
|
170
169
|
this.transformWGS84ToCartesian(region[0], region[1], region[4], tempVec1);
|
|
171
170
|
this.transformWGS84ToCartesian(region[2], region[3], region[5], tempVec2);
|
|
172
171
|
tempVec1.lerp(tempVec2, 0.5);
|
|
173
|
-
this.boundingVolume = new THREE.Sphere(new THREE.Vector3(tempVec1.x, tempVec1.
|
|
172
|
+
this.boundingVolume = new THREE.Sphere(new THREE.Vector3(tempVec1.x, tempVec1.y, tempVec1.z), tempVec1.distanceTo(tempVec2));
|
|
174
173
|
} else if (!!this.json.boundingVolume.sphere) {
|
|
175
174
|
const sphere = this.json.boundingVolume.sphere;
|
|
176
175
|
this.boundingVolume = new THREE.Sphere(new THREE.Vector3(sphere[0], sphere[2], -sphere[1]), sphere[3]);
|