Skip to content

Commit

Permalink
Merge 1aefb03 into 77503b8
Browse files Browse the repository at this point in the history
  • Loading branch information
georgios-uber committed Apr 2, 2019
2 parents 77503b8 + 1aefb03 commit 705262a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
8 changes: 8 additions & 0 deletions docs/api-reference/core/scenegraph/model-node.md
@@ -1,4 +1,12 @@
# ModelNode

## Constructor

### Model(gl: WebGLRenderingContext, props: Object) _or_ Model(model: Model, props: Object)

* `props` is the same props as `Model`
* Additionally you can pass `props.managedResources` array of objects that this model owns.
Will automatically call `delete()` on all of them when you call `ModelNode.delete()`

## Methods

1 change: 1 addition & 0 deletions examples/core/gltf/app.js
Expand Up @@ -384,6 +384,7 @@ export class DemoApp {
// TODO: Find better way to do this
(this.gltf.meshes || []).forEach(mesh => delete mesh._mesh);
(this.gltf.nodes || []).forEach(node => delete node._node);
(this.gltf.bufferViews || []).forEach(bufferView => delete bufferView.lumaBuffers);

this._deleteScenes();
Object.assign(this, createGLTFObjects(this.gl, this.gltf, this.loadOptions));
Expand Down
9 changes: 8 additions & 1 deletion modules/addons/src/gltf/create-gltf-model.js
Expand Up @@ -72,6 +72,13 @@ export default function createGLTFModel(gl, options) {

log.info(4, 'createGLTFModel defines: ', materialParser.defines)();

// Calculate managedResources
// TODO: Implement resource management logic that will
// not deallocate resources/textures/buffers that are shared
const managedResources = [];
managedResources.push(...materialParser.generatedTextures);
managedResources.push(...Object.values(attributes).map(attribute => attribute.buffer));

const model = new ModelNode(
gl,
Object.assign(
Expand All @@ -84,7 +91,7 @@ export default function createGLTFModel(gl, options) {
parameters: materialParser.parameters,
vs: addVersionToShader(gl, vs),
fs: addVersionToShader(gl, fs),
generatedTextures: materialParser.generatedTextures
managedResources
},
modelOptions
)
Expand Down
11 changes: 5 additions & 6 deletions modules/core/src/scenegraph/nodes/model-node.js
Expand Up @@ -15,8 +15,9 @@ export default class ModelNode extends ScenegraphNode {
this._setModelNodeProps(props);
} else {
this.model = new Model(gl, props);
this.generatedTextures = props.generatedTextures;
}

this.managedResources = props.managedResources || [];
}

setProps(props) {
Expand All @@ -30,11 +31,9 @@ export default class ModelNode extends ScenegraphNode {
this.model.delete();
this.model = null;
}
if (Array.isArray(this.generatedTextures)) {
this.generatedTextures.forEach(texture => texture.delete());
this.generatedTextures = null;
}
// TODO: delete buffers after making sure there are not shared!

this.managedResources.forEach(resource => resource.delete());
this.managedResources = [];
}

// Forward node methods
Expand Down

0 comments on commit 705262a

Please sign in to comment.