How can I set the position of a mesh before I add it to the scene in three.js

I would recommend you to check the documentation over here: http://threejs.org/docs/#Reference/Objects/Mesh As you can see on the top of the docu-page, Mesh inherits from “Object3D“. That means that you can use all methods or properties that are provided by Object3D. So click on the “Object3D” link on the docu-page and check the properties list. You … Read more

How to create a custom mesh on THREE.JS?

You’ve added vertices, but forgot to put those vertices into a face and add that to the geometry: geom.faces.push( new THREE.Face3( 0, 1, 2 ) ); so your snippet becomes: var geom = new THREE.Geometry(); var v1 = new THREE.Vector3(0,0,0); var v2 = new THREE.Vector3(0,500,0); var v3 = new THREE.Vector3(0,500,500); geom.vertices.push(v1); geom.vertices.push(v2); geom.vertices.push(v3); geom.faces.push( new … Read more

How to Fit Camera to Object

I am assuming you are using a perspective camera. You can set the camera’s position, field-of-view, or both. The following calculation is exact for an object that is a cube, so think in terms of the object’s bounding box, aligned to face the camera. If the camera is centered and viewing the cube head-on, define … Read more

Converting World coordinates to Screen coordinates in Three.js using Projection

Try with this: var width = 640, height = 480; var widthHalf = width / 2, heightHalf = height / 2; var vector = new THREE.Vector3(); var projector = new THREE.Projector(); projector.projectVector( vector.setFromMatrixPosition( object.matrixWorld ), camera ); vector.x = ( vector.x * widthHalf ) + widthHalf; vector.y = – ( vector.y * heightHalf ) + … Read more