NodeMaterial : fix properties shared across instances #23706
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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