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

Object3D: Clone material arrays #26589

Merged
merged 4 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/objects/Line.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Line extends Object3D {

super.copy( source, recursive );

this.material = source.material;
this.material = Array.isArray( source.material ) ? source.material.slice() : source.material;
this.geometry = source.geometry;

return this;
Expand Down
2 changes: 1 addition & 1 deletion src/objects/Mesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Mesh extends Object3D {

}

this.material = source.material;
this.material = Array.isArray( source.material ) ? source.material.slice() : source.material;
this.geometry = source.geometry;

return this;
Expand Down
2 changes: 1 addition & 1 deletion src/objects/Points.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Points extends Object3D {

super.copy( source, recursive );

this.material = source.material;
this.material = Array.isArray( source.material ) ? source.material.slice() : source.material;
this.geometry = source.geometry;

return this;
Expand Down
18 changes: 18 additions & 0 deletions test/unit/src/objects/Line.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { Line } from '../../../../src/objects/Line.js';

import { Object3D } from '../../../../src/core/Object3D.js';
import { Material } from '../../../../src/materials/Material.js';

export default QUnit.module( 'Objects', () => {

Expand Down Expand Up @@ -67,6 +68,23 @@ export default QUnit.module( 'Objects', () => {

} );

QUnit.test( 'copy/material', ( assert ) => {

// Material arrays are cloned
const mesh1 = new Line();
mesh1.material = [ new Material() ];

const copy1 = mesh1.clone();
assert.notStrictEqual( mesh1.material, copy1.material );

// Non arrays are not cloned
const mesh2 = new Line();
mesh1.material = new Material();
const copy2 = mesh2.clone();
assert.strictEqual( mesh2.material, copy2.material );

} );

QUnit.todo( 'computeLineDistances', ( assert ) => {

assert.ok( false, 'everything\'s gonna be alright' );
Expand Down
18 changes: 18 additions & 0 deletions test/unit/src/objects/Mesh.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { MeshBasicMaterial } from '../../../../src/materials/MeshBasicMaterial.j
import { Vector2 } from '../../../../src/math/Vector2.js';
import { Vector3 } from '../../../../src/math/Vector3.js';
import { DoubleSide } from '../../../../src/constants.js';
import { Material } from '../../../../src/materials/Material.js';

export default QUnit.module( 'Objects', () => {

Expand Down Expand Up @@ -73,6 +74,23 @@ export default QUnit.module( 'Objects', () => {

} );

QUnit.test( 'copy/material', ( assert ) => {

// Material arrays are cloned
const mesh1 = new Mesh();
mesh1.material = [ new Material() ];

const copy1 = mesh1.clone();
assert.notStrictEqual( mesh1.material, copy1.material );

// Non arrays are not cloned
const mesh2 = new Mesh();
mesh1.material = new Material();
const copy2 = mesh2.clone();
assert.strictEqual( mesh2.material, copy2.material );

} );

QUnit.todo( 'updateMorphTargets', ( assert ) => {

assert.ok( false, 'everything\'s gonna be alright' );
Expand Down
18 changes: 18 additions & 0 deletions test/unit/src/objects/Points.tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* global QUnit */

import { Object3D } from '../../../../src/core/Object3D.js';
import { Material } from '../../../../src/materials/Material.js';
import { Points } from '../../../../src/objects/Points.js';

export default QUnit.module( 'Objects', () => {
Expand Down Expand Up @@ -66,6 +67,23 @@ export default QUnit.module( 'Objects', () => {

} );

QUnit.test( 'copy/material', ( assert ) => {

// Material arrays are cloned
const mesh1 = new Points();
mesh1.material = [ new Material() ];

const copy1 = mesh1.clone();
assert.notStrictEqual( mesh1.material, copy1.material );

// Non arrays are not cloned
const mesh2 = new Points();
mesh1.material = new Material();
const copy2 = mesh2.clone();
assert.strictEqual( mesh2.material, copy2.material );

} );

QUnit.todo( 'raycast', ( assert ) => {

assert.ok( false, 'everything\'s gonna be alright' );
Expand Down