File tree Expand file tree Collapse file tree 6 files changed +57
-3
lines changed Expand file tree Collapse file tree 6 files changed +57
-3
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ class Line extends Object3D {
3434
3535 super . copy ( source , recursive ) ;
3636
37- this . material = source . material ;
37+ this . material = Array . isArray ( source . material ) ? source . material . slice ( ) : source . material ;
3838 this . geometry = source . geometry ;
3939
4040 return this ;
Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ class Mesh extends Object3D {
6565
6666 }
6767
68- this . material = source . material ;
68+ this . material = Array . isArray ( source . material ) ? source . material . slice ( ) : source . material ;
6969 this . geometry = source . geometry ;
7070
7171 return this ;
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ class Points extends Object3D {
3232
3333 super . copy ( source , recursive ) ;
3434
35- this . material = source . material ;
35+ this . material = Array . isArray ( source . material ) ? source . material . slice ( ) : source . material ;
3636 this . geometry = source . geometry ;
3737
3838 return this ;
Original file line number Diff line number Diff line change 33import { Line } from '../../../../src/objects/Line.js' ;
44
55import { Object3D } from '../../../../src/core/Object3D.js' ;
6+ import { Material } from '../../../../src/materials/Material.js' ;
67
78export default QUnit . module ( 'Objects' , ( ) => {
89
@@ -67,6 +68,23 @@ export default QUnit.module( 'Objects', () => {
6768
6869 } ) ;
6970
71+ QUnit . test ( 'copy/material' , ( assert ) => {
72+
73+ // Material arrays are cloned
74+ const mesh1 = new Line ( ) ;
75+ mesh1 . material = [ new Material ( ) ] ;
76+
77+ const copy1 = mesh1 . clone ( ) ;
78+ assert . notStrictEqual ( mesh1 . material , copy1 . material ) ;
79+
80+ // Non arrays are not cloned
81+ const mesh2 = new Line ( ) ;
82+ mesh1 . material = new Material ( ) ;
83+ const copy2 = mesh2 . clone ( ) ;
84+ assert . strictEqual ( mesh2 . material , copy2 . material ) ;
85+
86+ } ) ;
87+
7088 QUnit . todo ( 'computeLineDistances' , ( assert ) => {
7189
7290 assert . ok ( false , 'everything\'s gonna be alright' ) ;
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import { MeshBasicMaterial } from '../../../../src/materials/MeshBasicMaterial.j
99import { Vector2 } from '../../../../src/math/Vector2.js' ;
1010import { Vector3 } from '../../../../src/math/Vector3.js' ;
1111import { DoubleSide } from '../../../../src/constants.js' ;
12+ import { Material } from '../../../../src/materials/Material.js' ;
1213
1314export default QUnit . module ( 'Objects' , ( ) => {
1415
@@ -73,6 +74,23 @@ export default QUnit.module( 'Objects', () => {
7374
7475 } ) ;
7576
77+ QUnit . test ( 'copy/material' , ( assert ) => {
78+
79+ // Material arrays are cloned
80+ const mesh1 = new Mesh ( ) ;
81+ mesh1 . material = [ new Material ( ) ] ;
82+
83+ const copy1 = mesh1 . clone ( ) ;
84+ assert . notStrictEqual ( mesh1 . material , copy1 . material ) ;
85+
86+ // Non arrays are not cloned
87+ const mesh2 = new Mesh ( ) ;
88+ mesh1 . material = new Material ( ) ;
89+ const copy2 = mesh2 . clone ( ) ;
90+ assert . strictEqual ( mesh2 . material , copy2 . material ) ;
91+
92+ } ) ;
93+
7694 QUnit . todo ( 'updateMorphTargets' , ( assert ) => {
7795
7896 assert . ok ( false , 'everything\'s gonna be alright' ) ;
Original file line number Diff line number Diff line change 11/* global QUnit */
22
33import { Object3D } from '../../../../src/core/Object3D.js' ;
4+ import { Material } from '../../../../src/materials/Material.js' ;
45import { Points } from '../../../../src/objects/Points.js' ;
56
67export default QUnit . module ( 'Objects' , ( ) => {
@@ -66,6 +67,23 @@ export default QUnit.module( 'Objects', () => {
6667
6768 } ) ;
6869
70+ QUnit . test ( 'copy/material' , ( assert ) => {
71+
72+ // Material arrays are cloned
73+ const mesh1 = new Points ( ) ;
74+ mesh1 . material = [ new Material ( ) ] ;
75+
76+ const copy1 = mesh1 . clone ( ) ;
77+ assert . notStrictEqual ( mesh1 . material , copy1 . material ) ;
78+
79+ // Non arrays are not cloned
80+ const mesh2 = new Points ( ) ;
81+ mesh1 . material = new Material ( ) ;
82+ const copy2 = mesh2 . clone ( ) ;
83+ assert . strictEqual ( mesh2 . material , copy2 . material ) ;
84+
85+ } ) ;
86+
6987 QUnit . todo ( 'raycast' , ( assert ) => {
7088
7189 assert . ok ( false , 'everything\'s gonna be alright' ) ;
You can’t perform that action at this time.
0 commit comments