Skip to content

Commit cceedd7

Browse files
committed
Merge branch 'master' of github.com:NASA-AMMOS/3DTilesRendererJS into master
# Conflicts: # src/index.js # src/three/DebugTilesRenderer.js
2 parents e531bd1 + 86c69c4 commit cceedd7

File tree

12 files changed

+206
-52
lines changed

12 files changed

+206
-52
lines changed

.github/workflows/examples-build.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ jobs:
2525
node-version: ${{ matrix.node-version }}
2626
cache: 'npm'
2727
- run: npm ci
28-
- run: npm run build-examples --if-present
28+
- run: npm run build-examples
2929

3030
- name: Commit Examples
3131
uses: EndBug/add-and-commit@v7
3232
with:
3333
add: 'example/bundle'
34-
branch: examples
3534
message: 'update builds'
36-
push: 'origin examples --force --set-upstream'
37-
# pull_strategy: 'NO-PULL'
35+
push: 'origin HEAD:examples --force'

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,19 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
88
### Changed
99
- DebugTilesRenderer: "RANDOM_COLOR" debug colors are now consistent between flag toggles.
1010
- DebugTilesRenderer: "MeshStandardMaterial" is now used instead of "MeshBasicMaterial" for debugging.
11+
- TilesRenderer: add `getBoundingSphere` function.
1112

1213
### Added
1314
- DebugTilesRenderer: "RANDOM_NODE_COLOR" visualization setting.
1415
- Names for various tile objects.
1516
- DebugTilesRenderer: Added `getDebugColor` function for adjusing the debug visualization colors.
1617
- Support for computing screen space error for tiles that had sphere bounds but no box bounds.
18+
- Support for embedded tileset / tile geometry URLs with hashes, search query parameters.
19+
- DebugTilesRenderer: Added `customColorCallback` and `CUSTOM_COLOR` mode for custom debug coloring.
20+
21+
### Fixed
22+
- I3DMLoader: Fixed embedded absolute URLs not working correctly.
23+
- TilesRenderer: "getBounds" function throwing an error if no bounding box is present on the tileset.
1724

1825
## [0.3.1] - 2021-07-28
1926
### Fixed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,17 @@ RANDOM_COLOR
532532

533533
// Render every individual mesh in the scene with a random color.
534534
RANDOM_NODE_COLOR
535+
536+
// Sets a custom color using the customColorCallback call back.
537+
CUSTOM_COLOR_MODE
535538
```
539+
### .customColorCallback
540+
541+
```js
542+
customColorCallback: (tile: Tile, child: Object3D) => void
543+
```
544+
545+
The callback used if `debugColor` is set to `CUSTOM_COLOR_MODE`. Value defaults to `null` and must be set explicitly.
536546

537547
### .displayBoxBounds
538548

example/customMaterial.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ import {
1212
ShaderMaterial,
1313
MeshStandardMaterial,
1414
PCFSoftShadowMap,
15+
Sphere,
1516
} from 'three';
1617
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
1718
import * as dat from 'three/examples/jsm/libs/dat.gui.module.js';
1819
import Stats from 'three/examples/jsm/libs/stats.module.js';
1920

2021
let camera, controls, scene, renderer, tiles, orthoCamera;
21-
let offsetParent, box, dirLight, statsContainer;
22+
let offsetParent, box, sphere, dirLight, statsContainer;
2223
let stats;
2324

2425
const DEFAULT = 0;
@@ -258,6 +259,7 @@ function init() {
258259
scene.add( ambLight );
259260

260261
box = new Box3();
262+
sphere = new Sphere();
261263

262264
offsetParent = new Group();
263265
scene.add( offsetParent );
@@ -359,6 +361,11 @@ function animate() {
359361
box.getCenter( tiles.group.position );
360362
tiles.group.position.multiplyScalar( - 1 );
361363

364+
} else if ( tiles.getBoundingSphere( sphere ) ) {
365+
366+
tiles.group.position.copy( sphere.center );
367+
tiles.group.position.multiplyScalar( - 1 );
368+
362369
}
363370

364371
// update tiles

example/index.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
IS_LEAF,
1010
RANDOM_COLOR,
1111
RANDOM_NODE_COLOR,
12+
CUSTOM_COLOR_MODE
1213
} from '../src/index.js';
1314
import {
1415
Scene,
@@ -27,6 +28,7 @@ import {
2728
TorusBufferGeometry,
2829
OrthographicCamera,
2930
sRGBEncoding,
31+
Sphere,
3032
} from 'three';
3133
import { FlyOrbitControls } from './FlyOrbitControls.js';
3234
import { BufferGeometryUtils } from 'three/examples/jsm/utils/BufferGeometryUtils.js';
@@ -43,7 +45,7 @@ let camera, controls, scene, renderer, tiles, cameraHelper;
4345
let thirdPersonCamera, thirdPersonRenderer, thirdPersonControls;
4446
let secondRenderer, secondCameraHelper, secondControls, secondCamera;
4547
let orthoCamera, orthoCameraHelper;
46-
let box;
48+
let box, sphere;
4749
let raycaster, mouse, rayIntersect, lastHoveredElement;
4850
let offsetParent;
4951
let statsContainer, stats;
@@ -102,6 +104,23 @@ function reinstantiateTiles() {
102104
tiles.manager.addHandler( /\.gltf$/, loader );
103105
offsetParent.add( tiles.group );
104106

107+
// Used with CUSTOM_COLOR_MODE
108+
tiles.customColorCallback = ( tile, object ) => {
109+
110+
const depthIsEven = tile.__depth % 2 === 0;
111+
const hex = depthIsEven ? 0xff0000 : 0xffffff;
112+
object.traverse( c => {
113+
114+
if ( c.isMesh ) {
115+
116+
c.material.color.set( hex );
117+
118+
}
119+
120+
} );
121+
122+
};
123+
105124
}
106125

107126
function init() {
@@ -190,6 +209,7 @@ function init() {
190209
scene.add( ambLight );
191210

192211
box = new Box3();
212+
sphere = new Sphere();
193213

194214
offsetParent = new Group();
195215
scene.add( offsetParent );
@@ -253,6 +273,7 @@ function init() {
253273
IS_LEAF,
254274
RANDOM_COLOR,
255275
RANDOM_NODE_COLOR,
276+
CUSTOM_COLOR_MODE
256277

257278
} );
258279
debug.open();
@@ -497,6 +518,11 @@ function animate() {
497518
box.getCenter( tiles.group.position );
498519
tiles.group.position.multiplyScalar( - 1 );
499520

521+
} else if ( tiles.getBoundingSphere( sphere ) ) {
522+
523+
tiles.group.position.copy( sphere.center );
524+
tiles.group.position.multiplyScalar( - 1 );
525+
500526
}
501527

502528
if ( parseFloat( params.raycast ) !== NONE && lastHoveredElement !== null ) {

example/ionExample.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
sRGBEncoding,
3030
Matrix4,
3131
Box3,
32+
Sphere,
3233
} from 'three';
3334
import { FlyOrbitControls } from './FlyOrbitControls.js';
3435
import { BufferGeometryUtils } from 'three/examples/jsm/utils/BufferGeometryUtils.js';
@@ -176,10 +177,23 @@ function reinstantiateTiles() {
176177
tiles.onLoadTileSet = () => {
177178

178179
const box = new Box3();
180+
const sphere = new Sphere();
179181
const matrix = new Matrix4();
180-
tiles.getOrientedBounds( box, matrix );
181-
const position = new Vector3().setFromMatrixPosition( matrix );
182-
const distanceToEllipsoidCenter = position.length();
182+
183+
let position;
184+
let distanceToEllipsoidCenter;
185+
186+
if ( tiles.getOrientedBounds( box, matrix ) ) {
187+
188+
position = new Vector3().setFromMatrixPosition( matrix );
189+
distanceToEllipsoidCenter = position.length();
190+
191+
} else if ( tiles.getBoundingSphere( sphere ) ) {
192+
193+
position = sphere.center.clone();
194+
distanceToEllipsoidCenter = position.length();
195+
196+
}
183197

184198
const surfaceDirection = position.normalize();
185199
const up = new Vector3( 0, 1, 0 );

example/offscreenShadows.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ import {
1111
Group,
1212
MeshStandardMaterial,
1313
PCFSoftShadowMap,
14+
Sphere,
1415
} from 'three';
1516
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
1617
import * as dat from 'three/examples/jsm/libs/dat.gui.module.js';
1718
import Stats from 'three/examples/jsm/libs/stats.module.js';
1819

1920
let camera, controls, scene, renderer, tiles, orthoCamera;
20-
let offsetParent, box, dirLight;
21+
let offsetParent, box, sphere, dirLight;
2122
let stats;
2223

2324
const NONE = 0;
@@ -110,6 +111,7 @@ function init() {
110111
scene.add( ambLight );
111112

112113
box = new Box3();
114+
sphere = new Sphere();
113115

114116
offsetParent = new Group();
115117
scene.add( offsetParent );
@@ -224,6 +226,11 @@ function animate() {
224226
box.getCenter( tiles.group.position );
225227
tiles.group.position.multiplyScalar( - 1 );
226228

229+
} else if ( tiles.getBoundingSphere( sphere ) ) {
230+
231+
tiles.group.position.copy( sphere.center );
232+
tiles.group.position.multiplyScalar( - 1 );
233+
227234
}
228235

229236
// update tiles

example/vr.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ import {
3030
Line,
3131
Vector3,
3232
RingBufferGeometry,
33+
Sphere,
3334
} from 'three';
3435
import * as dat from 'three/examples/jsm/libs/dat.gui.module.js';
3536
import { VRButton } from 'three/examples/jsm/webxr/VRButton.js';
3637
import { XRControllerModelFactory } from 'three/examples/jsm/webxr/XRControllerModelFactory.js';
3738

3839
let camera, scene, renderer, tiles;
3940
let workspace;
40-
let box, grid;
41+
let box, sphere, grid;
4142
let raycaster, fwdVector, intersectRing;
4243
let offsetParent;
4344
let controller, controllerGrip;
@@ -92,6 +93,7 @@ function init() {
9293

9394
// tile set
9495
box = new Box3();
96+
sphere = new Sphere();
9597

9698
// parent for centering the tileset
9799
offsetParent = new Group();
@@ -227,6 +229,11 @@ function render() {
227229
box.getCenter( tiles.group.position );
228230
tiles.group.position.multiplyScalar( - 1 );
229231

232+
} else if ( tiles.getBoundingSphere( sphere ) ) {
233+
234+
tiles.group.position.copy( sphere.center );
235+
tiles.group.position.multiplyScalar( - 1 );
236+
230237
}
231238

232239
// remove all cameras so we can use the VR camera instead

src/base/TilesRendererBase.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,31 @@ import { UNLOADED, LOADING, PARSING, LOADED, FAILED } from './constants.js';
1414
*/
1515
const priorityCallback = ( a, b ) => {
1616

17-
if ( a.__inFrustum !== b.__inFrustum ) {
17+
if ( a.__depth !== b.__depth ) {
1818

19-
// prioritize loading whatever is in the frame
19+
// load shallower tiles first
20+
return a.__depth > b.__depth ? - 1 : 1;
21+
22+
} else if ( a.__inFrustum !== b.__inFrustum ) {
23+
24+
// load tiles that are in the frustum at the current depth
2025
return a.__inFrustum ? 1 : - 1;
2126

2227
} else if ( a.__used !== b.__used ) {
2328

24-
// prioritize tiles that were used most recently
29+
// load tiles that have been used
2530
return a.__used ? 1 : - 1;
2631

27-
} if ( a.__error !== b.__error ) {
32+
} else if ( a.__error !== b.__error ) {
2833

29-
// tiles which have greater error next
30-
return a.__error - b.__error;
34+
// load the tile with the higher error
35+
return a.__error > b.__error ? 1 : - 1;
3136

3237
} else if ( a.__distanceFromCamera !== b.__distanceFromCamera ) {
3338

3439
// and finally visible tiles which have equal error (ex: if geometricError === 0)
3540
// should prioritize based on distance.
36-
return a.__distanceFromCamera - b.__distanceFromCamera;
41+
return a.__distanceFromCamera > b.__distanceFromCamera ? - 1 : 1;
3742

3843
}
3944

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
IS_LEAF,
1010
RANDOM_COLOR,
1111
RANDOM_NODE_COLOR,
12+
CUSTOM_COLOR_MODE,
1213
} from './three/DebugTilesRenderer.js';
1314
import { TilesRenderer } from './three/TilesRenderer.js';
1415
import { B3DMLoader } from './three/B3DMLoader.js';
@@ -51,4 +52,5 @@ export {
5152
IS_LEAF,
5253
RANDOM_COLOR,
5354
RANDOM_NODE_COLOR,
55+
CUSTOM_COLOR_MODE,
5456
};

0 commit comments

Comments
 (0)