Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

In three.js, I want to add a mesh to a position in the scene

I've tried:

// mesh is a THREE.Mesh scene is a THREE.Scene scene.add(mesh) scene.updateMatrixWorld(true) mesh.matrixWorld.setPosition(new THREE.Vector3(100, 100, 100)) scene.updateMatrix() 

BUT it didn't affect anything.

What should I do ?

like image 397
user1783292 Avatar asked Jan 08 '13 20:01

user1783292


People also ask

What is three js used for?

js is a cross-browser JavaScript library and application programming interface (API) used to create and display animated 3D computer graphics in a web browser using WebGL.

How can I learn three js?

Download the three. js library and play around with all the examples included, there's a lot in there. If you want to really throw yourself in at the deep end, start by applying the use of three. js to something you already know how to do, but making it 3D.


1 Answers

i would recommend you to check the documenation 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 will find propertie ".position". Click on ".position" to see what data-type it is. Paha..its Vector3.

So try to do the following:

//scene is a THREE.Scene scene.add(mesh); mesh.position.set(100, 100, 100); 
like image 127
chsymann Avatar answered Sep 28 '22 04:09

chsymann