0

我有一个临时变量 a THREE.Veector3 ,我将其传递给对象的创建

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

在 Object 类中,我有一个变量纹理,我将其设置为名为 pos 的新 THREE.Vector3

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

我遇到的问题是我想将 pos 传递给在这个对象中创建的另一个对象。

object2 = new Object2(pos);

然而 pos 已被修改为 1000 的 y。我不太确定为什么会发生这种情况 我阅读了一些关于传递变量的指南,但我仍然对如何修改 pos 变量感到有些困惑。任何帮助将非常感激。

4

1 回答 1

1

只需更改您的对象以始终克隆该位置

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;
}
于 2012-10-01T08:42:38.043 回答