Stefano Maglione
Stefano Maglione

Reputation: 4150

Threejs clone method

I am trying to clone some Vector3 but the copy that clone method makes is made by all zero in x,y and z values. An example:

The output of this statement

 console.log(this.geometries[j].vertices[i].multiplyScalar(1));

is

LabeledVertex {x: -0.5, y: 0.5, z: 2.6745e-12, label: "U", constructor: function…} 

(LabeledVertex is simply an extension of THREE.Vector3)

if I clone this last one position = this.geometries[j].vertices[i].clone().multiplyScalar(1); the content inside position is: THREE.Vector3 {x: 0, y: 0, z: 0, constructor: function, set: function…}. As you can see is made by all zeros. This happens with version r71 of Threejs.

Upvotes: 4

Views: 3930

Answers (1)

Martin
Martin

Reputation: 2673

Always make new vector, if you want calculate with, or clone itn fist and calculate with it after in new syntax:

var v2 = v1.clone();
v2 = v2.multiplyScalar( 2 );

//or 
v2 = new THREE.Vector3(v1.x,v1.y,v1.z).multiplyScalar( 2 );

//or from gaitat comment
v2 = v1.clone().multiplyScalar( 2 );

Upvotes: 5

Related Questions