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

Cancellable models load #326

Closed
wants to merge 1 commit into from

Conversation

sdumetz
Copy link
Contributor

@sdumetz sdumetz commented Nov 14, 2024

Currently if a model's derivative is no longer needed while still loading, the request still runs through.

This is a known limitation in three's FileLoader (see mrdoob/three.js#20705) that will probably not get fixed anytime soon because it is easy to fix in user-space (3D-tiles, among others, does so) and a general-purpose one-size-fits-all solution is not trivial.

Fortunately in our case, it is relatively easy to implement.

this should have practically no effect unless you are switching quality levels in the Derivatives task faster than they could load but it is a hard requirement for #324 or any similar feature.

Also, shouldn't break or slow down anything.

fix a race condition on derivative load callback. Explain early return cases in comments
@gjcope
Copy link
Collaborator

gjcope commented Nov 22, 2024

I'm getting a couple of TS errors on build that seem to be missing type definitions. We must have some difference in build environment.

ERROR in /app/source/client/io/ModelReader.ts
./io/ModelReader.ts 129:48-54
[tsl] ERROR in /app/source/client/io/ModelReader.ts(129,49)
TS2339: Property 'reason' does not exist on type 'AbortSignal'.

ERROR in /app/source/client/models/Derivative.ts
./models/Derivative.ts 82:36-63
[tsl] ERROR in /app/source/client/models/Derivative.ts(82,37)
TS2554: Expected 0 arguments, but got 1.

@gjcope
Copy link
Collaborator

gjcope commented Nov 22, 2024

Different Node version maybe?

@sdumetz
Copy link
Contributor Author

sdumetz commented Nov 22, 2024

Ah, you must be using node 14? Just checked, it's been introduced in v16.

As it's not something that's immediately needed, should I wait for the project to move to v16 or try to make it work on v14 if that's not happening anytime soon?

Asking because latest versions of some tools don't support v14 anymore so this might block future updates.

@gjcope
Copy link
Collaborator

gjcope commented Nov 22, 2024

I'm using the Docker file in the repo which is currently on v16.20.2

@gjcope
Copy link
Collaborator

gjcope commented Nov 22, 2024

The types in package.json are still on v14. I've updated to v16 types locally and it's all good. When this gets merged it sounds like we will also need to up the minimum Node version to 16.14

@gjcope
Copy link
Collaborator

gjcope commented Nov 22, 2024

This is working really nicely, thanks again for the PR. We've needed this for awhile but I was leaving it to Three.js...

Similar to #325 the only issue I'm seeing is problems with the interaction prompt, probably also due to the async load here.

@@ -306,7 +312,7 @@ export default class CVModel2 extends CObject3D
}
else if (ins.quality.changed) {
const derivative = this.derivatives.select(EDerivativeUsage.Web3D, ins.quality.value);
if (derivative && derivative !== this.activeDerivative) {
if (derivative) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the rationale for removing the activeDerivative check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's checked inside this.loadDerivative. Otherwise if you had Highfully loaded and switched from to Low then to High again before Low was loaded, you'd have derivative === this.activeDerivative and Lowwouldn't get cancelled.

Here loadDerivative get called, this._loadingDerivative (Low) gets cancelled and loadDerivative returns early here.

Could have been the other way around and added and interrupt here but I'd rather have loadDerivative as robust as possible.

@gjcope
Copy link
Collaborator

gjcope commented Nov 22, 2024

This is working really nicely, thanks again for the PR. We've needed this for awhile but I was leaving it to Three.js...

Similar to #325 the only issue I'm seeing is problems with the interaction prompt, probably also due to the async load here.

I think the main culprit here is that we are trying to only show the interaction prompt once the initial model load finishes. We were previously using the 'busy' state of CVAssetManager as a proxy for this, which worked because of the synchronous loading. Now the loading comes in spurts and "finishes" multiple times during one load.

@sdumetz
Copy link
Contributor Author

sdumetz commented Nov 25, 2024

Busy might still be a good thing to track (though I'd like to surface this as an event or something to improve the experience when using voyager-explorer's public API).

It's just the loadingManager that is no longer hooked-up properly no? Maybe just d28f7b5 would do the trick?

I tested on a few scenes locally and it seemed to work.

@gjcope
Copy link
Collaborator

gjcope commented Nov 25, 2024

It's just the loadingManager that is no longer hooked-up properly no? Maybe just d28f7b5 would do the trick?

Was this meant for #325? This PR looks to already be handling the loadingManager more or less the same way.

@sdumetz
Copy link
Contributor Author

sdumetz commented Nov 25, 2024

It can be used as-is on master and would work on #325 . Some changes might be needed to apply over this PR.

It all depends in which order you wish to apply the commits. I can merge the three changes together, make it work and submit a signel PR for the whole package if you think it's easier to review?

@gjcope
Copy link
Collaborator

gjcope commented Nov 25, 2024

Yeah it's not clear to me how it would change execution in this PR, so if you can submit something that would be helpful. Doesn't need to be all as one, but that's fine if it's easier.

@sdumetz sdumetz mentioned this pull request Nov 29, 2024
@sdumetz
Copy link
Contributor Author

sdumetz commented Dec 11, 2024

Closed by #332

@sdumetz sdumetz closed this Dec 11, 2024
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