threejs_playGnd icon indicating copy to clipboard operation
threejs_playGnd copied to clipboard

2 Objects

Open bigsby-exe opened this issue 12 years ago • 7 comments

Hi i'm pretty new to the whole of java script and was just wondering how would I add 2 meshes to a sketch and say have 2 adjacent objects rotating separately

Thanks bzyg7b

bigsby-exe avatar Oct 02 '13 15:10 bigsby-exe

you would just need to instantiate two different mesh objects:

ie:

geometry = new THREE.CubeGeometry(200, 200, 200);
material = new THREE.MeshNormalMaterial({shading: THREE.FlatShading});
mesh = new THREE.Mesh(geometry, material);
mesh_two = new THREE.Mesh(geometry,material);
scene.add(mesh);
scene.add(mesh_two);

a mesh = a geometry and a material mesh & mesh_two are essentially the same object visually but to the environment it's two different objects.

yyolk avatar Oct 02 '13 16:10 yyolk

Ahhh ok awesome and I can get these to rotate independently right?

bigsby-exe avatar Oct 02 '13 16:10 bigsby-exe

Yes. Use methods as you would normally.

Going off the example above…

mesh.position.x = Math.random() * 1500 - 750;
mesh.position.y = Math.random() * 1500 - 750;
mesh.position.z = Math.random() * 1500 - 750;
mesh_two.position.x = Math.random() * 1500 - 750;
mesh_two.position.y = Math.random() * 1500 - 750;
mesh_two.position.z = Math.random() * 1500 - 750;

yyolk avatar Oct 02 '13 16:10 yyolk

Ohh ok i'll have a mess round and see if I can work it out thanks XD

bigsby-exe avatar Oct 02 '13 16:10 bigsby-exe

Yay thank you I got it all working but do you know how i can set position and size based on the window size so it all fits on whatever window/screen size it is viewed on?

bigsby-exe avatar Oct 02 '13 17:10 bigsby-exe

if you want your entire sketch to adjust to the full window size add this event listener to your setup:

window.addEventListener( 'resize', onWindowResize, false );

that goes before the closing bracket } of your setup, somewhere after the mesh code above and then inbetween your setup function and your draw function add this function:

function onWindowResize() { camera.aspect = window.innerWidth / window.innerHeight; camera.updateProjectionMatrix(); renderer.setSize( window.innerWidth, window.innerHeight ); }

nbriz avatar Oct 03 '13 14:10 nbriz

ok thank you i'll give it a try XD

bigsby-exe avatar Oct 05 '13 20:10 bigsby-exe