-
Notifications
You must be signed in to change notification settings - Fork 281
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
Lazy initialization of the upAdjustment matrix (Three.js) #601
Conversation
Nmzik
commented
Jul 5, 2024
•
edited
Loading
edited
- Instead of creating a new Matrix4 per tile, reuse it.
- Pass the upAdjustment matrix to each loader constructor, keeping a reference to it without instantiating and copying the matrix itself.
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.
Thanks! I'd prefer not to change the Loader constructor signatures, though, and think we should keep the new Matrix4 on the class. There's already a ton of memory allocation that's going to necessarily happen during during loading and parsing of model geometry and one more Matrix4 is going to be really minor.
src/three/TilesRenderer.js
Outdated
this.upAdjustment = null; | ||
|
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.
Can we move this to a global value, instead? See tempMat etc above.
loader.adjustmentTransform.copy( upAdjustment ); | ||
loader.adjustmentTransform = upAdjustment; |
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.
Let's still use the "copy" function instead of assigning the variable.
const cached = tile.cached; | ||
const cachedTransform = cached.transform; | ||
|
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.
Is there a reason these were moved? It would be best to only perform a minimal amount of changes in a PR, I think, and avoid unneeded code organization updates. IT makes it easier to understand what's changing and why.
@@ -24,6 +24,7 @@ const INITIAL_FRUSTUM_CULLED = Symbol( 'INITIAL_FRUSTUM_CULLED' ); | |||
const tempMat = new Matrix4(); | |||
const tempMat2 = new Matrix4(); | |||
const tempVector = new Vector3(); | |||
let upAdjustment = null; |
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.
Let's just create the matrix4 here. Only creating something like a matrix4 when needed is a bit of an over optimization, I think, especially when we're creating other variables. In fact we can probably just use of the existing tempMat
objects as long as it's not being used in the parseTiles function, already.