Question

J'ai une variable TEMP A trois.veectory3 que je passe dans la création d'un objet

object[i] = new Object(new THREE.Vector3(0,0,0));

Dans l'objet de la classe, j'ai une texture variable que j'ai définie sur le nouveau Three.Vector3 appelé 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;
}

Le problème que je vais avoir, c'est que je veux passer dans un autre objet créé à l'intérieur de cet objet.

object2 = new Object2(pos);

Cependant, POS a été modifié pour avoir le y à 1000. Je ne suis pas tout à fait sûr pourquoi cela se passe-t-il, je lisais des guides sur les variables de passage, mais je suis toujours un peu confus sur la modification de la variable de POS.Toute aide serait très appréciée.

Était-ce utile?

La solution

changez simplement votre objet pour toujours prendre un clone de la position

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;
}

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top