2013-07-04 70 views
2

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

的方法不工作对我来说:

  • 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

为什么你说这是行不通的?

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