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

Math: Add convenience methods #25637

Merged
merged 1 commit into from
Mar 9, 2023
Merged

Conversation

WestLangley
Copy link
Collaborator

In ColorManagement.js this pattern is used:

_vector.set( color.r, color.g, color.b ).applyMatrix3( LINEAR_DISPLAY_P3_TO_LINEAR_SRGB );
return color.setRGB( _vector.x, _vector.y, _vector.z );

This PR adds convenience methods to simplify these calculations:

Vector3.setFromColor( c )
Color.setFromVector3( v )
Color.applyMatrix3( m )

/ping @donmccurdy

@WestLangley WestLangley added this to the r151 milestone Mar 9, 2023
@github-actions
Copy link

github-actions bot commented Mar 9, 2023

📦 Bundle size

Full ESM build, minified and gzipped.

Filesize Gzipped Diff from dev
618 kB 154.7 kB +282 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Filesize Gzipped Diff from dev
409.7 kB 100.8 kB +282 B


return this;

}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I inlined this method to avoid an unnecessary conversion to -- and from -- a Vector3.

@Mugen87 Mugen87 merged commit c34c99d into mrdoob:dev Mar 9, 2023
@WestLangley WestLangley deleted the dev-color_vector3 branch March 9, 2023 17:52
@donmccurdy
Copy link
Collaborator

Thanks @WestLangley! Being able to apply a Matrix3 directly to a Color is helpful for sure. Now that we can do that, perhaps we don't need the to/from Vector3 methods? Or do you think there are other cases requiring that conversion? Either way is OK with me.

@WestLangley
Copy link
Collaborator Author

@donmccurdy I added those methods because Vector3 already supports conversion from multiple classes.

I was thinking we will have to support proper gamut mapping. It remains to be seen how that will be implemented.

@donmccurdy
Copy link
Collaborator

donmccurdy commented Mar 9, 2023

Ok — I'm unsure about whether we will need to provide gamut mapping methods, but have no concerns with keeping these methods.

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.

3 participants