@jdultra/threedtiles 8.0.1 → 9.0.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.
@@ -1,47 +0,0 @@
1
- import { Matrix3, Sphere, Vector3 } from "three";
2
-
3
- class OBB {
4
- constructor(values) {
5
- this.center = new Vector3(values[0], values[1], values[2]);
6
- var e1 = new Vector3(values[3], values[4], values[4]);
7
- var e2 = new Vector3(values[6], values[7], values[8]);
8
- var e3 = new Vector3(values[9], values[10], values[11]);
9
-
10
- this.halfWidth = e1.length();
11
- this.halfHeight = e2.length();
12
- this.halfDepth = e3.length();
13
-
14
- e1.normalize();
15
- e2.normalize();
16
- e3.normalize();
17
-
18
- // A sphere is used for frustum culling
19
- this.sphere = new Sphere(this.center, Math.sqrt(this.halfWidth * this.halfWidth + this.halfHeight * this.halfHeight + this.halfDepth * this.halfDepth));
20
-
21
- this.matrixToOBBCoordinateSystem = new Matrix3();
22
- this.matrixToOBBCoordinateSystem.set(
23
- e1.x, e1.y, e1.z,
24
- e2.x, e2.y, e2.z,
25
- e3.x, e3.y, e3.z);
26
- }
27
-
28
- inFrustum(frustum) {
29
- // frustum check simplified to bounding sphere intersection
30
- return frustum.intersectsSphere(this.sphere);
31
- }
32
- distanceToPoint(point) {
33
-
34
- let transformedPoint = point.clone();
35
- transformedPoint.sub(this.center);
36
- transformedPoint.applyMatrix3(this.matrixToOBBCoordinateSystem);
37
-
38
- //// point to bounds
39
- let dx = Math.max(0, Math.max(-this.halfWidth - transformedPoint.x, transformedPoint.x - this.halfWidth));
40
- let dy = Math.max(0, Math.max(-this.halfHeight - transformedPoint.y, transformedPoint.y - this.halfHeight));
41
- let dz = Math.max(0, Math.max(-this.halfDepth - transformedPoint.z, transformedPoint.z - this.halfDepth));
42
- return Math.sqrt(dx * dx + dy * dy + dz * dz);
43
- }
44
-
45
- }
46
-
47
- export { OBB };
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/src/index.js DELETED
@@ -1,331 +0,0 @@
1
- import "regenerator-runtime/runtime.js";
2
- import * as THREE from 'three';
3
- import Stats from 'three/examples/jsm/libs/stats.module.js';
4
- import { OGC3DTile } from "./tileset/OGC3DTile";
5
- import { TileLoader } from "./tileset/TileLoader";
6
- import { MapControls, OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
7
- import { setIntervalAsync } from 'set-interval-async/dynamic';
8
- import { OcclusionCullingService } from "./tileset/OcclusionCullingService";
9
- import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer';
10
- import { RenderPass } from 'three/examples/jsm/postprocessing/RenderPass.js';
11
-
12
- import { InstancedOGC3DTile } from "./tileset/instanced/InstancedOGC3DTile.js"
13
- import { InstancedTileLoader } from "./tileset/instanced/InstancedTileLoader.js"
14
- import { Sky } from 'three/addons/objects/Sky.js';
15
-
16
- import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
17
- import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js';
18
- import { KTX2Loader } from "three/examples/jsm/loaders/KTX2Loader";
19
-
20
- const occlusionCullingService = new OcclusionCullingService();
21
- occlusionCullingService.setSide(THREE.DoubleSide);
22
- const scene = initScene();
23
-
24
- const domContainer = initDomContainer("screen");
25
- const camera = initCamera(domContainer.offsetWidth, domContainer.offsetHeight);
26
- const stats = initStats(domContainer);
27
- const renderer = initRenderer(camera, domContainer);
28
- const ogc3DTiles = initTileset(scene, 1.0);
29
- //const instancedTileLoader = createInstancedTileLoader(scene);
30
- //const ogc3DTiles = initInstancedTilesets(instancedTileLoader);
31
-
32
-
33
- /*const gltfLoader = new GLTFLoader();
34
- const dracoLoader = new DRACOLoader();
35
- dracoLoader.setDecoderPath('https://www.gstatic.com/draco/versioned/decoders/1.4.3/');
36
- gltfLoader.setDRACOLoader(dracoLoader);
37
-
38
- const ktx2Loader = new KTX2Loader();
39
- ktx2Loader.setTranscoderPath('jsm/libs/basis/');
40
- //gltfLoader.setKTX2Loader(ktx2Loader)
41
-
42
-
43
- gltfLoader.load(
44
- // resource URL
45
- 'http://localhost:8080/3/15.glb',
46
- // called when the resource is loaded
47
- function (gltf) {
48
-
49
- scene.add(gltf.scene);
50
-
51
- },
52
- // called while loading is progressing
53
- function (xhr) {
54
-
55
- console.log((xhr.loaded / xhr.total * 100) + '% loaded');
56
-
57
- },
58
- // called when loading has errors
59
- function (error) {
60
-
61
- console.log('An error happened : ' + error);
62
-
63
- }
64
- );*/
65
- // Optional: Provide a DRACOLoader instance to decode compressed mesh data
66
-
67
- const controller = initController(camera, domContainer);
68
-
69
- const composer = initComposer(scene, camera, renderer);
70
-
71
- animate();
72
-
73
- let sky, sun;
74
- initSky();
75
- function initSky() {
76
- sky = new Sky();
77
- sky.scale.setScalar(450000);
78
- scene.add(sky);
79
-
80
- sun = new THREE.Vector3();
81
-
82
- const effectController = {
83
- turbidity: 10,
84
- rayleigh: 1,
85
- mieCoefficient: 0.005,
86
- mieDirectionalG: 0.3,
87
- elevation: 5,
88
- azimuth: 40,
89
- exposure: renderer.toneMappingExposure
90
- };
91
-
92
- const uniforms = sky.material.uniforms;
93
- uniforms['turbidity'].value = effectController.turbidity;
94
- uniforms['rayleigh'].value = effectController.rayleigh;
95
- uniforms['mieCoefficient'].value = effectController.mieCoefficient;
96
- uniforms['mieDirectionalG'].value = effectController.mieDirectionalG;
97
-
98
- const phi = THREE.MathUtils.degToRad(90 - effectController.elevation);
99
- const theta = THREE.MathUtils.degToRad(effectController.azimuth);
100
-
101
- sun.setFromSphericalCoords(1, phi, theta);
102
-
103
- uniforms['sunPosition'].value.copy(sun);
104
-
105
- renderer.toneMappingExposure = effectController.exposure;
106
- renderer.render(scene, camera);
107
- }
108
- function initComposer(scene, camera, renderer) {
109
- const renderScene = new RenderPass(scene, camera);
110
- //const bloomPass = new UnrealBloomPass(new THREE.Vector2(window.innerWidth, window.innerHeight), 0.4, 0.5, 0);
111
-
112
-
113
- const composer = new EffectComposer(renderer);
114
- composer.addPass(renderScene);
115
- //composer.addPass(bloomPass);
116
- return composer;
117
- }
118
- function initScene() {
119
- const scene = new THREE.Scene();
120
- scene.matrixAutoUpdate = false;
121
- //scene.matrixWorldAutoUpdate = false;
122
- scene.background = new THREE.Color(0xE5E3E4);
123
- //const dirLight = new THREE.DirectionalLight(0xFFFFFF, 1.0);
124
- //dirLight.position.set(100,100,100);
125
- //dirLight.lookAt(new THREE.Vector3(0,0,0));
126
- scene.add(new THREE.AmbientLight(0xFFFFFF, 1.0));
127
-
128
- //scene.add(dirLight)
129
-
130
- /* const light = new THREE.PointLight(0xbbbbff, 2, 5000);
131
- const sphere = new THREE.SphereGeometry(2, 16, 8);
132
- light.add(new THREE.Mesh(sphere, new THREE.MeshBasicMaterial({ color: 0xbbbbff })));
133
- scene.add(light);
134
- light.position.set(200, 200, 200);
135
-
136
-
137
- const light2 = new THREE.PointLight(0xffbbbb, 2, 5000);
138
- const sphere2 = new THREE.SphereGeometry(2, 16, 8);
139
- light2.add(new THREE.Mesh(sphere2, new THREE.MeshBasicMaterial({ color: 0xffbbbb })));
140
- scene.add(light2);
141
- light2.position.set(200, 100, -100); */
142
-
143
-
144
- return scene;
145
- }
146
-
147
- function initDomContainer(divID) {
148
-
149
- const domContainer = document.getElementById(divID);
150
- domContainer.style = "position: absolute; height:100%; width:100%; left: 0px; top:0px;";
151
- document.body.appendChild(domContainer);
152
- return domContainer;
153
- }
154
-
155
-
156
- function initRenderer(camera, dom) {
157
-
158
- const renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: "high-performance" });
159
- renderer.setPixelRatio(window.devicePixelRatio);
160
- renderer.setSize(dom.offsetWidth, dom.offsetHeight);
161
- renderer.outputEncoding = THREE.sRGBEncoding;
162
- //renderer.toneMapping = THREE.ReinhardToneMapping;
163
- //renderer.toneMappingExposure = Math.pow(0.8, 4.0);
164
- renderer.autoClear = false;
165
-
166
- dom.appendChild(renderer.domElement);
167
-
168
- onWindowResize();
169
- window.addEventListener('resize', onWindowResize);
170
- function onWindowResize() {
171
-
172
- const aspect = window.innerWidth / window.innerHeight;
173
- camera.aspect = aspect;
174
- camera.updateProjectionMatrix();
175
-
176
- renderer.setSize(dom.offsetWidth, dom.offsetHeight);
177
- }
178
-
179
- return renderer;
180
- }
181
-
182
- function initStats(dom) {
183
- const stats = Stats();
184
- document.body.appendChild(stats.dom);
185
- return stats;
186
- }
187
-
188
-
189
-
190
-
191
- function initTileset(scene, gem) {
192
-
193
- const tileLoader = new TileLoader({
194
- renderer: renderer,
195
- maxCachedItems: 100,
196
- meshCallback: mesh => {
197
- //// Insert code to be called on every newly decoded mesh e.g.:
198
- mesh.material.wireframe = false;
199
- mesh.material.side = THREE.DoubleSide;
200
- //mesh.material.metalness = 0.0
201
- },
202
- pointsCallback: points => {
203
- points.material.size = Math.min(1.0, 0.5 * Math.sqrt(points.geometricError));
204
- points.material.sizeAttenuation = true;
205
- }
206
- });
207
-
208
- const ogc3DTile = new OGC3DTile({
209
- //url: "https://storage.googleapis.com/ogc-3d-tiles/berlinTileset/tileset.json",
210
- //url: "https://storage.googleapis.com/ogc-3d-tiles/ayutthaya/tiledWithSkirts/tileset.json",
211
- url: "http://localhost:8080/tileset.json",
212
- geometricErrorMultiplier: gem,
213
- loadOutsideView: true,
214
- tileLoader: tileLoader,
215
- //occlusionCullingService: occlusionCullingService,
216
- static: false,
217
- centerModel: true,
218
- renderer: renderer
219
-
220
- });
221
- setIntervalAsync(function () {
222
- ogc3DTile.update(camera);
223
- }, 10);
224
-
225
- //ogc3DTile.scale.set(0.1,0.1,0.1)
226
-
227
- ogc3DTile.rotateOnAxis(new THREE.Vector3(1, 0, 0), -Math.PI * 0.5) // Z-UP to Y-UP
228
- //ogc3DTile.translateOnAxis(new THREE.Vector3(0, 0, 1), 1)
229
- /*
230
- ogc3DTile.translateOnAxis(new THREE.Vector3(0, 0, 1), 10) // Z-UP to Y-UP
231
- ogc3DTile.translateOnAxis(new THREE.Vector3(0, 1, 0), 18.5) // Z-UP to Y-UP */
232
- scene.add(ogc3DTile);
233
-
234
- return ogc3DTile;
235
- }
236
-
237
-
238
- function createInstancedTileLoader(scene) {
239
- return new InstancedTileLoader(scene, {
240
- renderer: renderer,
241
- maxCachedItems : 100,
242
- maxInstances : 1,
243
- meshCallback: mesh => {
244
- //// Insert code to be called on every newly decoded mesh e.g.:
245
- mesh.material.wireframe = false;
246
- mesh.material.side = THREE.DoubleSide;
247
- },
248
- pointsCallback: points => {
249
- points.material.size = Math.min(1.0, 0.5 * Math.sqrt(points.geometricError));
250
- points.material.sizeAttenuation = true;
251
- }
252
- });
253
- }
254
- function initInstancedTilesets(instancedTileLoader) {
255
-
256
- /*new GLTFLoader().load('http://localhost:8080/test.glb', function ( gltf ) {
257
- scene.add(gltf.scene);
258
- } );*/
259
-
260
- const instancedTilesets = [];
261
-
262
-
263
- const tileset = new InstancedOGC3DTile({
264
- //url: "https://storage.googleapis.com/ogc-3d-tiles/berlinTileset/tileset.json",
265
- url: "http://localhost:8080/tileset.json",
266
- geometricErrorMultiplier: 1,
267
- loadOutsideView: true,
268
- tileLoader: instancedTileLoader,
269
- static: false,
270
- centerModel: true,
271
- renderer: renderer
272
- });
273
- tileset.rotateOnAxis(new THREE.Vector3(1, 0, 0), Math.PI * -1) // Z-UP to Y-UP
274
-
275
- tileset.updateMatrix()
276
- scene.add(tileset);
277
- instancedTilesets.push(tileset);
278
-
279
- scene.updateMatrixWorld(true)
280
- function now() {
281
- return (typeof performance === 'undefined' ? Date : performance).now();
282
- }
283
- let updateIndex = 0;
284
- setInterval(() => {
285
- let startTime = now();
286
- do {
287
- const frustum = new THREE.Frustum();
288
- frustum.setFromProjectionMatrix(new THREE.Matrix4().multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse));
289
- instancedTilesets[updateIndex].update(camera, frustum);
290
- updateIndex = (updateIndex + 1) % instancedTilesets.length;
291
- } while (updateIndex < instancedTilesets.length && now() - startTime < 4);
292
- }, 40);
293
-
294
- //initLODMultiplierSlider(instancedTilesets);
295
- }
296
-
297
-
298
- function initCamera(width, height) {
299
- const camera = new THREE.PerspectiveCamera(60, width / height, 0.1, 20000);
300
- camera.position.set(50, 50, 50);
301
- camera.lookAt(0, 0, 0);
302
-
303
- camera.matrixAutoUpdate = true;
304
- return camera;
305
- }
306
- function initController(camera, dom) {
307
- const controller = new OrbitControls(camera, dom);
308
-
309
- //controller.target.set(4629210.73133627, 435359.7901640832, 4351492.357788198);
310
- controller.target.set(0, 0, 0);
311
-
312
-
313
- controller.minDistance = 0.1;
314
- controller.maxDistance = 10000;
315
- controller.update();
316
- return controller;
317
- }
318
-
319
-
320
- function animate() {
321
- requestAnimationFrame(animate);
322
- //instancedTileLoader.update();
323
- composer.render();
324
- //occlusionCullingService.update(scene, renderer, camera)
325
- stats.update();
326
- }
327
-
328
-
329
-
330
-
331
-