Skip to content

Commit 19bad36

Browse files
authored
Fix CesiumIon shadeless MeshStandardMaterial and readme typo preprocessURL (#474)
* Update README.md code blocks with preprocessURL instead of onPreprocessURL * Update ionExample.js for bad meshStandardMaterial tilesets * bugfix missing brackets and linting * Linting fixes * ionExample: Enforce material metalness = 0 for MeshStandardMaterial and add ambient light * Use 64x64 DataTexture env map * Only set scene.environment, not background
1 parent 23f9388 commit 19bad36

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,11 @@ fetch( url, { mode: 'cors' } )
199199

200200
// Prefilter each model fetch by setting the cesium Ion version to the search
201201
// parameters of the url.
202-
tiles.onPreprocessURL = uri => {
202+
tiles.preprocessURL = uri => {
203203

204204
uri = new URL( uri );
205205
uri.searchParams.append( 'v', version );
206-
return uri;
206+
return uri.toString();
207207

208208
};
209209

@@ -368,10 +368,10 @@ If true then the `raycast` functions of the loaded tile objects are overriden to
368368

369369
If you would like to manage raycasting against tiles yourself this behavior can be disabled if needed by setting `optizeRaycast` to false.
370370

371-
### .onPreprocessURL
371+
### .preprocessURL
372372

373373
```js
374-
onPreprocessURL = null : ( uri : string | URL ) => string | URL;
374+
preprocessURL = null : ( uri : string | URL ) => string | URL;
375375
```
376376

377377
Function to preprocess the url for each individual tile geometry or child tile set to be loaded. If null then the url is used directly.

example/ionExample.js

+25-8
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import {
55
PerspectiveCamera,
66
Vector3,
77
Quaternion,
8-
Group,
98
Sphere,
9+
AmbientLight,
10+
DataTexture,
11+
EquirectangularReflectionMapping
1012
} from 'three';
1113
import { FlyOrbitControls } from './src/controls/FlyOrbitControls.js';
1214
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
@@ -16,11 +18,10 @@ import { GUI } from 'three/examples/jsm/libs/lil-gui.module.min.js';
1618
let camera, controls, scene, renderer, tiles;
1719

1820
const params = {
19-
20-
'ionAssetId': '40866',
21-
'ionAccessToken': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJmYmE2YWEzOS1lZDUyLTQ0YWMtOTlkNS0wN2VhZWI3NTc4MmEiLCJpZCI6MjU5LCJpYXQiOjE2ODU2MzQ0Njl9.AswCMxsN03WYwuZL-r183OZicN64Ks9aPExWhA3fuLY',
22-
'reload': reinstantiateTiles,
23-
21+
ionAssetId: '40866',
22+
ionAccessToken:
23+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJmYmE2YWEzOS1lZDUyLTQ0YWMtOTlkNS0wN2VhZWI3NTc4MmEiLCJpZCI6MjU5LCJpYXQiOjE2ODU2MzQ0Njl9.AswCMxsN03WYwuZL-r183OZicN64Ks9aPExWhA3fuLY',
24+
reload: reinstantiateTiles,
2425
};
2526

2627
init();
@@ -47,7 +48,9 @@ function setupTiles() {
4748
// Note the DRACO compression files need to be supplied via an explicit source.
4849
// We use unpkg here but in practice should be provided by the application.
4950
const dracoLoader = new DRACOLoader();
50-
dracoLoader.setDecoderPath( 'https://unpkg.com/[email protected]/examples/jsm/libs/draco/gltf/' );
51+
dracoLoader.setDecoderPath(
52+
'https://unpkg.com/[email protected]/examples/jsm/libs/draco/gltf/'
53+
);
5154

5255
const loader = new GLTFLoader( tiles.manager );
5356
loader.setDRACOLoader( dracoLoader );
@@ -99,14 +102,28 @@ function init() {
99102

100103
scene = new Scene();
101104

105+
// Add scene light for MeshStandardMaterial to react properly if its metalness is set to 0
106+
const light = new AmbientLight( 0xffffff, 1 );
107+
scene.add( light );
108+
109+
const env = new DataTexture( new Uint8Array( 64 * 64 * 4 ).fill( 255 ), 64, 64 );
110+
env.mapping = EquirectangularReflectionMapping;
111+
env.needsUpdate = true;
112+
scene.environment = env;
113+
102114
// primary camera view
103115
renderer = new WebGLRenderer( { antialias: true } );
104116
renderer.setClearColor( 0x151c1f );
105117

106118
document.body.appendChild( renderer.domElement );
107119
renderer.domElement.tabIndex = 1;
108120

109-
camera = new PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 4000 );
121+
camera = new PerspectiveCamera(
122+
60,
123+
window.innerWidth / window.innerHeight,
124+
1,
125+
4000
126+
);
110127
camera.position.set( 400, 400, 400 );
111128

112129
// controls

0 commit comments

Comments
 (0)