Reputation: 41
var orientation = {dim1: 100, dim2: 100, dim3: 100}
geom = new THREE.BoxGeometry(orientation.dim1, orientation.dim2, orientation.dim3);
//geom.translate(orientation.dim1 / 2, orientation.dim2 / 2, orientation.dim3 / 2);
box_material = new THREE.MeshPhongMaterial({
color: 0xffffff,
transparent: false,
opacity: 0.5,
alphaTest: 0.5
});
box_material.depthWrite = true;
var vertices = [];
vertices.push( 0, 0, 0 );
geom.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 )) ;
var mesh = new THREE.Mesh(geom, box_material)
//mesh.frustumCulled = false;
scene.add(mesh);
This is the code that should create a box. If I don't set the attribute "position" it appear, but when I try to set its position it simply disappear. And if I try to move manually its position from the console it remains stuck.
What's the problem?
Thank you!
Upvotes: 0
Views: 222
Reputation: 1889
make sure x,y, z are in number format, not string
or you can apply a transform
pos.x = parseFloat((pos.x))
pos.y = parseFloat((pos.y))
pos.z = parseFloat((pos.z))
Upvotes: 0
Reputation: 28492
If you just want to change the position of the box, simply use:
mesh.position.set(x, y, z);
Don't touch the geom.setAttribute('position')
method because that would be destroying its vertices, which is probably not what you want.
Upvotes: 2