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

NodeMaterial : fix properties shared across instances #23706

Merged
merged 1 commit into from
Mar 12, 2022

Conversation

wmcmurray
Copy link
Contributor

Description

Since v138, every properties of a NodeMaterial (except primitive values) will be shared across all instances of the same material. This codepen illustrates the problem, there are 2 sets of points, each with a differently coloured material (red and blue), but both are rendered blue.

Explanation

My understanding is that NodeMaterials does not extend base material classes anymore, instead the NodeMaterial.setDefaultValues() is used to copy properties into the NodeMaterial instances. But since properties are copied from a single instance of the base material, properties that are an instance of Color (for example) will be copied by reference, therefore every material instances will share the same value.

Disclaimer

I tested this PR only with PointsNodeMaterial, and only inside my project.

cc @sunag

@mrdoob mrdoob requested a review from sunag March 11, 2022 19:07
@mrdoob mrdoob added this to the r139 milestone Mar 11, 2022
@sunag
Copy link
Collaborator

sunag commented Mar 12, 2022

@wmcmurray I was thinking of moving this function setDefaultValues to WebGLNodeBuilder just.

@mrdoob mrdoob merged commit a825851 into mrdoob:dev Mar 12, 2022
@mrdoob
Copy link
Owner

mrdoob commented Mar 12, 2022

Thanks!

abernier pushed a commit to abernier/three.js that referenced this pull request Sep 16, 2022
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