mrdoob / three.js

JavaScript 3D Library.
https://threejs.org/
MIT License
99.19k stars 35.11k forks source link

Pivot for rotation of Mesh #24

Closed kapilreddy closed 13 years ago

kapilreddy commented 13 years ago

A pivot for rotation for a objects would useful. Right now I am doing that using a locus equation but in built feature would be useful

mrdoob commented 13 years ago

Depending of what you're after you could just offset all the vertices instead. But I agree, having a pivot could be useful. I haven't had a chance to implement yet (there have been some branches that implemented that, plus hierarchy, but haven't had a chance to properly merge them and test it yet).

kapilreddy commented 13 years ago

Yes hierarchy is also a good addition. Could you please point me to the brances that actually implement pivot and hierarchy

525c1e21-bd67-4735-ac99-b4b0e5262290 commented 13 years ago

Why has this been closed? Hierarchy will be an essential feature moving forwards although I cannot find any trace of support yet...correct me if I am wrong.

I'll open an issue for Hierarchy

mrdoob commented 13 years ago

A workaround was suggested. I think it was via twitter :S

525c1e21-bd67-4735-ac99-b4b0e5262290 commented 13 years ago

I had a quick search but couldn't find anything relevant. Do you remember what was suggested?

mrdoob commented 13 years ago

Basically, offset the vertices instead. If you want the pivot to be at 100,0,0... offset all the vertices -100,0,0. Not an ideal solution but is a good workaround and saves a bunch of computations.

kapilreddy commented 13 years ago

Hey i am back on it after a while but seems like offseting vertices is not a good idea if you want alot of objects rotating on a same pivot.

mrdoob commented 13 years ago

Have you tried grouping them? Take a look at examples/webgl_geometry_hierarchy.html

kapilreddy commented 13 years ago

So basically children and parent properties are used to define hierarchy?? Can two parents have same children?

mrdoob commented 13 years ago

Yes and no.

kapilreddy commented 13 years ago

Still the problem remains how to define pivot of group. I am trying to make a rubik's cube I can now changing grouping of small groups according to mousemove vector but pivot of each group still giving problem.

mrdoob commented 13 years ago

That's an interesting use case. Wouldn't the pivot be the center of the group?

kapilreddy commented 13 years ago

The pivot is pivot of object first in the group and not the center.

kapilreddy commented 13 years ago

http://dl.dropbox.com/u/13195512/rubik/rubikscube.html you can check if its done wrong way here.

mrdoob commented 13 years ago

Hope this illustrates:

var group = new THREE.Object3D();

var geometry = new Cube( 10, 10, 10 );
var material = new THREE.MeshBasicMaterial( { color: 0x00ffff } );

var cube1 = new THREE.Mesh( geometry, material );
cube1.position.x = 30;
cube1.position.z = 30;

group.addChild( cube1 );

var cube2 = new THREE.Mesh( geometry, material );
cube2.position.x = 30;
cube2.position.z = - 30;

group.addChild( cube2 );

var cube3 = new THREE.Mesh( geometry, material );
cube3.position.x = - 30;
cube3.position.z = - 30;

group.addChild( cube3 );

scene.addObject( group );

group.rotation.y += 0.5;
kapilreddy commented 13 years ago

Yes that is ok if i want the pivot to be fixed but as you can imagine pivot and group in case of rubik's cube would be dynamic

shravanimmy commented 5 years ago

i have a wind turbine. i want to rotate the wind turbine. wind turbine is a 3d object. when i am trying to rotating it is getting displaced from it center. the rotation is not perfect. it maybe an issue with my pivot point. pls help

var pointToRotateAround;
var objectToRotate;

var pivot = new THREE.Object3D();
//loading 3d turbine

var loader = new THREE.JSONLoader();
    loader.load("model/fan.js", handle_load11);
    function handle_load11(geometry){
          fan1 = new THREE.Mesh(geometry, material);
          fan1.scale.set(8,8,8);
          position=fan1.position;
          var box = new THREE.Box3().setFromObject( fan1 );
          geometry.applyMatrix( new THREE.Matrix4().makeTranslation(position.x, position.y, position.z) );
          box.center( fan1.position ); // this re-sets the mesh position
         fan1.position.multiplyScalar( -1);
        var axis = new THREE.Vector3(-0.5 ,0, 0 )
         pivot.position= axis;
           //pivot.position=fan1.position;
        pivot.add(fan1);
        scene.add(pivot);

    }

//rotating turbine 

   pivot.rotation.x += .2;
Mugen87 commented 5 years ago

@shravanimmy Please use the forum or stackoverflow for help requests.

arnavzek commented 5 years ago

ummm...