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

BufferAttribute: Support (de)normalization in accessors (v2) #24087

Closed

Conversation

donmccurdy
Copy link
Collaborator

@donmccurdy donmccurdy commented May 18, 2022

More compact code, using internal ._normalize(value) and ._denormalize(value) helper functions, created to match the underlying array type. Requires turning .normalized into a getter/setter. Making .normalized readonly would also be an option.

@@ -22,7 +23,10 @@ class BufferAttribute {
this.array = array;
this.itemSize = itemSize;
this.count = array !== undefined ? array.length / itemSize : 0;
this.normalized = normalized === true;

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is not needed because the original line will perform the same steps in the setter?

@@ -222,7 +241,9 @@ class BufferAttribute {

for ( let i = 0, l = this.count; i < l; i ++ ) {

_vector.fromBufferAttribute( this, i );
_vector.x = this.getX( i );
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is better to fix Vector.fromBufferAttribute...

Copy link
Contributor

Choose a reason for hiding this comment

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

No, it still works.
Then I don't think this line (and lines similar to this) should be changed?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Indeed. Inlining fromBufferAttribute() only makes the code more verbose.

@donmccurdy
Copy link
Collaborator Author

Thanks for the comments @LeviPesin! I'll wait to address feedback until we've agreed on a direction between this and #22874.

@elalish
Copy link
Contributor

elalish commented Jul 11, 2022

Wild guess says this PR might fix this bug: google/model-viewer#3577

I like this approach; @mrdoob any feelings one way or the other? Would be nice to get this merged.

@Mugen87
Copy link
Collaborator

Mugen87 commented Jul 12, 2022

._normalize(value) and ._denormalize(value) are always invocated, even when no normalization or denormalization is required. How does the invocation of a "dummy method" influences the performance?

The setter/getter interface of BufferAttribute is sometimes used per frame to manipulate vertex data. We should make sure that this change does not introduce a noticeable performance drop.

@Mugen87
Copy link
Collaborator

Mugen87 commented Jul 12, 2022

I'll wait to address feedback until we've agreed on a direction between this and #22874.

I tend towards #22874. #24087 is more compact but after all I like the simplicity in #22874.

@donmccurdy
Copy link
Collaborator Author

@Mugen87 thanks! I'm not sure if the "dummy method" invocation has overhead for non-normalized attributes or not. I could set up a benchmark on that, if it makes a difference in the choice? Or if you prefer the simplicity in #22874 even if performance is the same, that's OK with me.

@Mugen87
Copy link
Collaborator

Mugen87 commented Jul 13, 2022

Or if you prefer the simplicity in #22874 even if performance is the same, that's OK with me.

Then I vote for #22874. 😇

@donmccurdy donmccurdy closed this Jul 13, 2022
@donmccurdy donmccurdy deleted the feat-normalized-accessors-v2 branch September 7, 2022 20:15
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.

4 participants