javascript - Transferring rotation from parent Object3D to child - three js -
i have mesh
nested in object3d
. i'd rotate object3d
on x , y axis during drag, , on release reset object3d
rotation 0, 0, 0 after transferring rotation on mesh
inside.
my approach may totally wrong, seems work first movement breaks after that. i'm thinking have eueler order.
the code i'm using is:
function mousedown(e) { hold.x = e.pagex; hold.y = e.pagey; window.addeventlistener('mousemove', mousemove); } function mousemove(e) { var diffx = e.pagex - hold.x; var diffy = e.pagey - hold.y; object.rotation.x = (diffy * 0.25) * radian; object.rotation.y = (diffx * 0.25) * radian; } function mouseup() { window.removeeventlistener('mousemove', mousemove); cube.rotation.x += object.rotation.x; cube.rotation.y += object.rotation.y; object.rotation.x = 0; object.rotation.y = 0; }
i made jsfiddle demonstrate exact issue: http://jsfiddle.net/bjaju/4/
to transfer parent's world transform child, need call
child.applymatrix( parent.matrixworld );
so in case, be
function mouseup() { window.removeeventlistener('mousemove', mousemove); cube.applymatrix( object.matrixworld ); object.rotation.x = 0; object.rotation.y = 0;
}
fiddle: http://jsfiddle.net/bjaju/5/
three.js r.59
Comments
Post a Comment