Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update shouldRender so it support multiple models #6

Merged
merged 6 commits into from
Feb 12, 2025

Conversation

alexandremottet
Copy link
Owner

No description provided.

export type Model = IDisposable &
ModelInternal &

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to merge ModelInternal into Model. I think we want to do the opposite, and then use ModelInternal for the private backing fields.

type ModelInternal = Model & {
    _animationPlaying(): boolean;
    _shouldRender(): boolean;
};
...
private _loadedModelsBacking: ModelInternal[] = [];
private _activeModelBacking: Nullable<ModelInternal> = null;

Comment on lines 1387 to 1389
private _shouldModelRenderPredicate(model: Model) {
return model._shouldRender();
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is actually ok for this to just be an inline lambda. I did some quick memory profiling and it doesn't look like the lambdas on line 1060 actually result in any memory allocations. I'm guessing the JS engine is smart enough to see that this lambda doesn't need to be re-allocated since it doesn't capture any local state.

this._setActiveModel(await this._loadModel(source, options, abortController.signal), Object.assign({ source, interpolateCamera: false }, options));
const model = await this._loadModel(source, options, abortController.signal);
model.makeActive(Object.assign({ source, interpolateCamera: false }, options));
} else {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I added this else block but somehow I didn't notice that line 1152 already sets the _activeModelBacking to null, so I don't think this else block actually does anything.

@alexandremottet alexandremottet merged commit 1de1ebb into use-loaded-models Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants