user2550696
user2550696

Reputation: 111

Three.js, WebGl Object position

Im working with WebGl, Three.js. Can anyone tell me what am i doing wrong ? I try to get the position of my custom made mesh. Each time i get values (0,0,0) no matter what method i try.

Non of the methods worked for me :

Here is 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; // 0,0,0
worldPosition = vec.getPositionFromMatrix( matrix ); // 0,0,0

// this also doesnt work 
squareMesh.matrix.getPosition().x // 0

Upvotes: 2

Views: 3550

Answers (1)

Dragan Okanovic
Dragan Okanovic

Reputation: 7761

Why you say it doesn't work?

Whole mesh has 0,0,0 position. To change it, try changing squareMesh.position property.

Upvotes: 4

Related Questions