Pregunta

Tengo una variable temporal un tres.Verector3 que paso a la creación de un objeto

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

En el objeto de clase, tengo una textura variable que configuré en el nuevo three.vector3 llamado 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;
}

El problema que estoy teniendo es que quiero pasar POS en otro objeto creado dentro de este objeto.

object2 = new Object2(pos);

Sin embargo, POS se ha modificado para tener la Y a 1000. No estoy seguro de por qué está sucediendo, leí algunas guías sobre las variables que pasan, pero todavía estoy un poco confundido sobre cómo se modifica la variable POS.Cualquier ayuda sería muy apreciada.

¿Fue útil?

Solución

Simplemente cambie su objeto para tomar siempre un clon de la posición

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top