refactor to ImportManager to significantly improve performance,#934
refactor to ImportManager to significantly improve performance,#934lavjeetrai wants to merge 1 commit into
Conversation
|
@sponce @EdwardMoyse hey guys, whenever you have a minute, could you take a look at this refactor? Cleaned up some of the GLTF loading logic. |
|
Just a tiny question : shall we squash the 3 commits, for the history to be cleaner ? Or feel free to rewrite the history yourself and push the new version |
ab6d4b4 to
14025ae
Compare
|
I've squashed the commits into a single commit. Let me know if everything else looks good to go. Also, PR #931 has been waiting for more than a week. Since the @EdwardMoyse seems to be offline, could you advise on whether there are any remaining blockers to getting it merged? |
| child.material.dispose(); | ||
| child.material = material2; | ||
|
|
||
| if (child.material) { |
There was a problem hiding this comment.
May be a stupid question : why do we not check anymore the type ? disposeMaterial needs a Material
There was a problem hiding this comment.
In Three.js, a mesh's material can be either a single Material or an array (Material[]).
The previous instanceof Material check evaluated to false for arrays, skipping disposal and causing memory leaks. By removing the strict type check, we safely pass both types to the new disposeMaterial helper, which is designed to iterate through and dispose of them correctly.
Does this approach make sense to you?
Description
This PR introduces a major refactor to
ImportManagerto significantly improve performance, memory management, and overall code architecture for importing 3D assets. It addresses several bottlenecks and enforces stricter TypeScript type safety.Key Improvements
GLTFLoader,OBJLoader,DRACOLoader) are now lazily instantiated and cached to prevent upfront CPU/Memory spikes when the module is loaded.disposeMaterialhelper that reliably disposes of intermediate materials and their deeply nested textures.BufferGeometryUtils.mergeGeometries. This drastically reduces WebGL draw calls, with a safe fallback to individual meshes if attribute mismatches occur.parsePhnxScene) in favor of modernasync/awaitand Promises, making the codebase much easier to trace and maintain.jsziplibrary is now loaded dynamically (await import('jszip')) only when a.zipfile is detected, reducing the initial JavaScript bundle size.Promise.alltoPromise.allSettledwhen extracting multiple files from a.zip, ensuring that a single corrupted file won't reject the entire valid payload.anyassertions across material property checks and geometry arrays, leveraging strict type guards (e.g.,MeshStandardMaterial | MeshBasicMaterial | MeshPhongMaterial) to prevent runtime errors.Testing Instructions
.objfile and ensure it renders with the correct flat/double-sided properties..gltfor.glbscene (with and without DRACO compression) and confirm textures/geometries are correctly preserved..zipfile containing multiple geometries and verify it unpacks and renders properly..phnxevent scene and verify that both the event data and geometries are initialized without callback errors.