2

我正在使用 WebGl,Three.js。谁能告诉我我做错了什么?我试图获得我的定制网格的位置。无论我尝试什么方法,每次我得到值(0,0,0)。

没有一种方法对我有用:

  • vector.getPositionFromMatrix(矩阵);
  • obj.matrix.getPosition().x

这是我的代码:

squareGeometry = new THREE.Geometry();
squareGeometry.vertices.push(new THREE.Vector3( this.x, this.y, this.z));
squareGeometry.vertices.push(new THREE.Vector3( this.x + this.w, this.y, this.z));
squareGeometry.vertices.push(new THREE.Vector3( this.x + this.w, this.y - this.h, this.z));
squareGeometry.vertices.push(new THREE.Vector3( this.x, this.y - this.h, this.z));
squareGeometry.faces.push(new THREE.Face4(0, 1, 2, 3));

squareMaterial = new THREE.MeshBasicMaterial({
color:this.color,
side:THREE.DoubleSide
});

squareMesh = new THREE.Mesh(squareGeometry, squareMaterial);

scene.add(squareMesh);
squareMesh.updateMatrix()
scene.updateMatrixWorld();

vec = new THREE.Vector3();
matrix = squareMesh.matrix;
localPosition = squareMesh.position; // 0,0,0
worldPosition = vec.getPositionFromMatrix( matrix ); // 0,0,0

// this also doesnt work 
squareMesh.matrix.getPosition().x // 0
4

1 回答 1

4

为什么你说它不起作用?

整个网格有 0,0,0 位置。要更改它,请尝试更改squareMesh.position属性。

于 2013-07-04T13:57:18.473 回答