Impostazione JavaScript Questo.Value sta modificando la variabile Temp
-
12-12-2019 - |
Domanda
Ho una variabile temp a tre.veettore3 che trasmetto nella creazione di un oggetto
object[i] = new Object(new THREE.Vector3(0,0,0));
.
Nell'oggetto della classe ho una trama variabile che ho impostato sul nuovo tre.Vector3 chiamato POS
function Object(pos){
this.texture = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { map:
THREE.ImageUtils.loadTexture( '../img/img.png' ) } ) );
this.texture.position = pos;
this.texture.rotation.x = 0;
this.texture.rotation.y = 1.57;
this.texture.rotation.z = 1.57;
this.texture.scale.x = 100;
this.texture.scale.y = 50;
this.texture.scale.z = 100;
this.texture.position.y = 1000;
}
.
Il problema che sto avendo è che voglio passare POS in un altro oggetto creato all'interno di questo oggetto.
object2 = new Object2(pos);
.
Comunque POS è stato modificato per avere il Y a 1000. Non sono sicuro del motivo per cui questo sta accadendo ho letto alcune guide sulle variabili di passaggio ma sono ancora un po 'confuso su come la variabile POS viene modificata.Qualsiasi aiuto sarebbe molto apprezzato.
Soluzione
Basta cambiare oggetto per prendere sempre un clone della posizione
function Object(pos){
this.texture = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { map:
THREE.ImageUtils.loadTexture( '../img/img.png' ) } ) );
this.texture.position = pos.clone();
this.texture.rotation.x = 0;
this.texture.rotation.y = 1.57;
this.texture.rotation.z = 1.57;
this.texture.scale.x = 100;
this.texture.scale.y = 50;
this.texture.scale.z = 100;
this.texture.position.y = 1000;
}
. Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow