繁体   English   中英

Three.js,WebGL对象位置

[英]Three.js, WebGl Object position

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

没有一种方法对我有用:

  • vector.getPositionFromMatrix(matrix);
  • 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

为什么您说它不起作用?

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM