Skip to content

updateMaterialIndexAttribute when it needs #666

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

Merged
merged 3 commits into from
Jul 31, 2024

Conversation

dongho-shin
Copy link
Contributor

@dongho-shin dongho-shin commented Jul 29, 2024

related : #665

This needs to be tested to make sure it's okay

but don't worry, I'll test it, if it's okay, I'll comment
the reason for the PR is that I wonder this solution is right way.

Copy link
Owner

@gkjohnson gkjohnson left a comment

Choose a reason for hiding this comment

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

This is great! I've added some comments on small stylistic preference but overall the logic here looks right!

let needsMaterialIndexUpdate = result.changeType !== NO_CHANGE || materialUuids === null || materialUuids.length !== length;
for ( let index = 0, length = materials.length; ( index < length ) && ! needsMaterialIndexUpdate; index ++ ) {

if ( materialUuids === null || materialUuids.length !== length ) {
Copy link
Owner

Choose a reason for hiding this comment

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

These conditions can be pulled out of the for loop and used in the above needsMaterialIndexUpdate initialization since it's not using the index value at all.

@@ -176,9 +178,29 @@ export class PathTracingSceneGenerator {
// generate the geometry
const result = staticGeometryGenerator.generate( geometry );
const materials = result.materials;
let needsMaterialIndexUpdate = result.changeType !== NO_CHANGE || materialUuids === null || materialUuids.length !== length;
for ( let index = 0, length = materials.length; ( index < length ) && ! needsMaterialIndexUpdate; index ++ ) {
Copy link
Owner

Choose a reason for hiding this comment

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

nit: Lets rename index to i for consistency with other loops.

And for readability if we could move the needsMaterialIndexUpdate check to a condition block that would best, I think:

if ( ! needsMaterialIndexUpdate ) {

  for ( ... ) {

    // ...

  }

}

}

const material = materials[ index ];
if ( material.uuid !== materialUuids[ index ] ) needsMaterialIndexUpdate = true;
Copy link
Owner

Choose a reason for hiding this comment

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

We can add a break statement once this is set to true.


}

materialUuids = materials.map( material => material.uuid );
Copy link
Owner

Choose a reason for hiding this comment

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

This can move inside the below condition since the uuids won't have changed otherwise.

if ( needsMaterialIndexUpdate ) {

  updateMaterialIndexAttribute( geometry, materials, materials );
  materialUuids = materials.map( material => material.uuid );

}

Comment on lines 76 to 77
let materialUuids = null;

Copy link
Owner

Choose a reason for hiding this comment

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

This should be assigned on the PathTracingSceneGenerator instance itself. Otherwise if we have two different instances of the generator created they will overwrite each others results.

@dongho-shin
Copy link
Contributor Author

fix styles as you recommended(also duplicated logic removed)
also I test it, lgtm

@gkjohnson
Copy link
Owner

Looks excellent! Thank you

@gkjohnson gkjohnson merged commit 46b395e into gkjohnson:main Jul 31, 2024
4 checks passed
@dongho-shin dongho-shin deleted the dev/fix-materialAttributeIndex branch July 31, 2024 06:10
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