Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 621
Stefano Maglione Avatar asked Oct 25 '25 02:10

Stefano Maglione


1 Answers

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 );
like image 193
Martin Avatar answered Oct 27 '25 16:10

Martin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!