@jdultra/threedtiles 5.1.0 → 5.1.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/README.md +17 -2
- package/package.json +1 -1
- package/src/decoder/B3DMDecoder.js +7 -2
- package/src/index.js +15 -5
- package/src/tileset/OGC3DTile.js +2 -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,11 @@ 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
|
|
11
|
+
const zUpToYUp = new THREE.Matrix4();
|
|
12
|
+
zUpToYUp.set(1,0,0,0,
|
|
13
|
+
0,0,-1,0,
|
|
14
|
+
0,1,0,0,
|
|
15
|
+
0,0,0,1);
|
|
12
16
|
//const legacyGLTFLoader = new LegacyGLTFLoader();
|
|
13
17
|
|
|
14
18
|
function parseB3DM(arrayBuffer, meshCallback) {
|
|
@@ -63,12 +67,13 @@ function parseB3DM(arrayBuffer, meshCallback) {
|
|
|
63
67
|
|
|
64
68
|
const rtcCenter = featureTable.getData('RTC_CENTER');
|
|
65
69
|
if (rtcCenter) {
|
|
66
|
-
tempMatrix.makeTranslation(rtcCenter[0], rtcCenter[
|
|
70
|
+
tempMatrix.makeTranslation(rtcCenter[0], rtcCenter[1], rtcCenter[2])
|
|
67
71
|
model.scene.applyMatrix4(tempMatrix);
|
|
68
72
|
}
|
|
69
73
|
|
|
70
74
|
model.scene.traverse((o) => {
|
|
71
75
|
if (o.isMesh) {
|
|
76
|
+
o.applyMatrix4(zUpToYUp);
|
|
72
77
|
if (!!meshCallback) {
|
|
73
78
|
meshCallback(o);
|
|
74
79
|
}
|
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,7 +127,8 @@ 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",
|
|
@@ -140,12 +140,22 @@ function initTileset(scene, gem) {
|
|
|
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
|
@@ -116,9 +116,8 @@ class OGC3DTile extends THREE.Object3D {
|
|
|
116
116
|
(this.json.boundingVolume.region[1] + this.json.boundingVolume.region[3]) * 0.5,
|
|
117
117
|
(this.json.boundingVolume.region[4] + this.json.boundingVolume.region[5]) * 0.5,
|
|
118
118
|
tempVec1);
|
|
119
|
-
tempVec2.set(tempVec1.x, tempVec1.z, -tempVec1.y);
|
|
120
119
|
|
|
121
|
-
tempQuaternion.setFromUnitVectors(
|
|
120
|
+
tempQuaternion.setFromUnitVectors(tempVec1.normalize(), upVector.normalize());
|
|
122
121
|
self.applyQuaternion(tempQuaternion);
|
|
123
122
|
}
|
|
124
123
|
|
|
@@ -171,7 +170,7 @@ class OGC3DTile extends THREE.Object3D {
|
|
|
171
170
|
this.transformWGS84ToCartesian(region[0], region[1], region[4], tempVec1);
|
|
172
171
|
this.transformWGS84ToCartesian(region[2], region[3], region[5], tempVec2);
|
|
173
172
|
tempVec1.lerp(tempVec2, 0.5);
|
|
174
|
-
this.boundingVolume = new THREE.Sphere(new THREE.Vector3(tempVec1.x, tempVec1.
|
|
173
|
+
this.boundingVolume = new THREE.Sphere(new THREE.Vector3(tempVec1.x, tempVec1.y, tempVec1.z), tempVec1.distanceTo(tempVec2));
|
|
175
174
|
} else if (!!this.json.boundingVolume.sphere) {
|
|
176
175
|
const sphere = this.json.boundingVolume.sphere;
|
|
177
176
|
this.boundingVolume = new THREE.Sphere(new THREE.Vector3(sphere[0], sphere[2], -sphere[1]), sphere[3]);
|
|
@@ -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]);
|