Skip to content

Commit

Permalink
Merge c1480ee into 60f395b
Browse files Browse the repository at this point in the history
  • Loading branch information
georgios-uber committed Jun 20, 2019
2 parents 60f395b + c1480ee commit 7eb75d3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/layers/scenegraph-layer.md
Expand Up @@ -71,6 +71,10 @@ Can be a URL of an object. You need to provide the `fetch` function to load the
Can also be a luma.gl [ScenegraphNode](http://uber.github.io/luma.gl/#/documentation/api-reference/), or a `Promise` that resolves to one.
The layer calls _delete()_ on _scenegraph_ when a new one is provided or the layer is finalized.

##### `scenegraphLoader` (Object, optional)

If you provide a URL for `scenegraph` you can optionally provide a `scenegraphLoader` to load the URL.
If not provided `loaders.gl` will select one automatically.

### Render Options

Expand Down
8 changes: 7 additions & 1 deletion modules/mesh-layers/src/scenegraph-layer/scenegraph-layer.js
Expand Up @@ -34,10 +34,16 @@ const DEFAULT_COLOR = [255, 255, 255, 255];

const defaultProps = {
scenegraph: {type: 'object', value: null, async: true},
scenegraphLoader: null,

fetch: (url, {propName, layer}) => {
if (propName === 'scenegraph') {
return load(url, layer.getLoadOptions());
const options = layer.getLoadOptions();

if (layer.props.scenegraphLoader) {
return load(url, layer.props.scenegraphLoader, options);
}
return load(url, options);
}

return fetch(url).then(response => response.json());
Expand Down
22 changes: 22 additions & 0 deletions test/modules/layers/scenegraph-layer.spec.js
Expand Up @@ -126,3 +126,25 @@ test('ScenegraphLayer#tests', t => {

t.end();
});

test('ScenegraphLayer#defaultProps.fetch', async t => {
const loadOptions = {
load: true
};
const url = new ArrayBuffer();
const propName = 'scenegraph';
const layer = {
props: {
scenegraphLoader: {
parse: () => 9,
loadAndParse: () => 9,
extensions: '.glb'
}
},
getLoadOptions: () => loadOptions
};

const loaded = await ScenegraphLayer.defaultProps.fetch(url, {propName, layer});
t.ok(loaded === 9, 'Using loader success');
t.end();
});

0 comments on commit 7eb75d3

Please sign in to comment.