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 に答える