-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
LDrawLoader: Cache geometry versions of parts, reduce geometry redundancy, improve parse time #23232
Conversation
…als as ids in final part geometry
I'm sorry I didn't see this PR and made the other conflicting PR. For the moment I see great performance improvements! |
Heh, I hadn't made it! The conflicts are easy to resolve I just wanted to get ahead of any more. I just added the changes from your previous PR back in. I see that merge the model, has somehow broken, though. It's going to be hard to spin this as a feature 😄 I'll fix that, as well |
# Conflicts: # examples/jsm/loaders/LDrawLoader.js
Fixed! Because the geometry was now shared the world matrices were being applied multiple times to the same geometry instance. |
It seems the X-Wing model does not load, it gives error. If I add It seems the solution is to support direct colors (0x2CFD7DD) in the |
Thanks missed that somehow! Just pushed a fix along with an extra log in the ldraw example to output the error. And with the "direct" materials only being evaluated on the last material pass for geometry now we actually generate fewer materials (And therefore fewer draw calls) than we did before because previously a new material was being produced for every primitive. It could still be improved to afford caching of materials across multiple meshes but another time. |
I think that's all. Congrats for the refactor, this one was big :-) I couldn't resist to make an animation with physics :-) |
Small change I forgot to commit -- just pushed it. It's because current material was initialized to "undefined" rather than "null" which it was checking for so an empty group was always added first. Should be fixed now. And looks like the |
Yes, I think the last geometry group is always open-ended. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the PR is ready to merge, we have not observed any more errors.
Thanks! |
Related issue: #23157 (comment)
Description
This one took a bit to get my head around because of the scoping, deferred cloning of geometry, and asynchronous processing but this is the last big LDrawLoader PR I'm planning to do (for awhile, at least). It reworks LDrawLoader to move all the subobject processing and geometry generation to a separate cache class called "LDrawPartsGeometryCache". The
.loadModel
function will return a promise that resolves with a built group and (if relevant) unfinished material array so pass through color codes or out-of-scope material cods can be applied later. The missing materials are saved in the materials array as string color codes which are replaced when they're actually being added to a model. Those pre-built parts are cached so any redundant processing can be saved.Here are some of the stats for the AT-AT model. You can see we have a significant improvement in the number of unique geometries generated and a parse time improvement of around 35-45% depending on whether normal smoothing is enabled or not:
AT-AT Stats
Live Demo
https://raw.githack.com/gkjohnson/three.js/cached-parts/examples/webgl_loader_ldraw.html
Here's how I tested:
I'll keep these in draft until #23231 is merged but feel free to give feedback or ask questions in the mean time. I know it's a big one to dig in to.