[英]Three.js, WebGl Object position
我正在使用WebGl Three.js。 誰能告訴我我在做什么錯? 我嘗試獲取定制網格的位置。 無論我嘗試哪種方法,每次我得到值(0,0,0)。
沒有一種方法對我有用:
這是我的代碼:
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
為什么您說它不起作用?
整個網格的位置為0,0,0。 要更改它,請嘗試更改squareMesh.position
屬性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.