Currently, I am exploring WebGl and Three.js to work on a project. Unfortunately, I seem to be encountering an issue regarding retrieving the position of a custom mesh that I created. Each time I attempt to obtain the position, I consistently receive values of (0,0,0) regardless of the method I use.
None of the following methods have proven successful for me:
- vector.getPositionFromMatrix( matrix );
- obj.matrix.getPosition().x
Below is the snippet of my code:
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; // Output: 0,0,0
worldPosition = vec.getPositionFromMatrix( matrix ); // Output: 0,0,0
// The following line also does not yield the desired result
squareMesh.matrix.getPosition().x // Output: 0