Skip to content

NodeMaterial: Dynamically copy properties in copy()#33775

Merged
sunag merged 5 commits into
mrdoob:devfrom
sunag:dev-copy
Jun 12, 2026
Merged

NodeMaterial: Dynamically copy properties in copy()#33775
sunag merged 5 commits into
mrdoob:devfrom
sunag:dev-copy

Conversation

@sunag

@sunag sunag commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Related issue: N/A

Description

This PR refactors NodeMaterial.copy() to dynamically copy properties instead of relying on a hardcoded list of node property assignments.

The new implementation ensures compatibility by verifying that a property is defined on both the source and the target before copying, also ignoring common properties like is*, uuid, id, and private properties.

Currently the code below does not work.

// A common use case

const mesh = gltf.scene.children[ 0 ];

const nodeMaterial = new THREE.MeshStandardNodeMaterial();
nodeMaterial.copy( mesh.material ); // copy from MeshStandardMaterial

mesh.material = nodeMaterial;

The defaults values currently are defined procedurally, the PR #28328 improve this, but it's require major changes.

The copying process honors nested .copy() calls for properties that implement them (such as Color or Vector2), ensuring that sub-object values are properly copied instead of just overwriting references and additionally, it deep-copies userData and clones individual elements inside the clippingPlanes array.

@sunag sunag added this to the r185 milestone Jun 11, 2026
@github-actions

github-actions Bot commented Jun 11, 2026

Copy link
Copy Markdown

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 365.48
86.82
365.48
86.82
+0 B
+0 B
WebGPU 666.43
184.37
664.42
184.1
-2.01 kB
-267 B
WebGPU Nodes 664.47
184.06
662.47
183.8
-2.01 kB
-264 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 507.44
123.35
507.44
123.35
+0 B
+0 B
WebGPU 745.68
200.56
744.33
200.43
-1.35 kB
-135 B
WebGPU Nodes 694.9
188
694.65
188.02
-249 B
+17 B

Comment thread src/materials/nodes/NodeMaterial.js
@sunag sunag marked this pull request as ready for review June 12, 2026 06:25
@sunag sunag merged commit ebc835e into mrdoob:dev Jun 12, 2026
10 checks passed
@sunag sunag deleted the dev-copy branch June 12, 2026 13:25
@sunag

sunag commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator Author

/cc @brunosimon

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