javascript - Three.js update rotation of grandchild of Object3D -
i'm trying grandchild of rotated object3d element lookat()
camera.
i've tried lot of approaches. source code of three.js object3d.lookat()
function states that: // method not support objects rotated and/or translated parent(s)
which understand part of rendering graph in scene. i've tried copying lookat()
code.
my structure goes object3d()
[rotated] -> object3d()
-> object3d()
[text mesh want face camera in each frame]
lookat(textobject, artistprops) { let m1 = textobject.matrixworld.clone(); textobject.matrixautoupdate = false; m1.lookat(textobject.localtoworld(textobject.position), props.camera.position, three.object3d.defaultup); textobject.quaternion.setfromrotationmatrix(m1); textobject.matrixworld.makerotationfromquaternion(textobject.quaternion); textobject.matrixworldneedsupdate = true; textobject.updatematrixworld(); }
this example of i've tried. approach wrong. i'm thinking i'll need keep child objects in own scene level container can relate world space independently of rotating parent.
nothing happens text mesh (grandchild object3d) rotation. acts nothing has been updated in case. checked docs , still can't see why it's not changing anything.
thanks in advance help!
you can use function :
var alwayslookatcamera = function () { var worldpos = new three.vector3(); if (+three.revision > 85) { return function (object, camera) { object.onbeforerender = function() { worldpos.setfrommatrixposition(object.matrixworld); object.matrixworld.lookat(camera.position, worldpos, three.object3d.defaultup); object.modelviewmatrix.multiplymatrices(camera.matrixworldinverse, object.matrixworld); object.normalmatrix.getnormalmatrix(object.modelviewmatrix); }; }; } else { return function (object, camera) { object.onbeforerender = function() { worldpos.setfrommatrixposition(object.matrixworld); object.matrixworld.lookat(camera.position, worldpos, three.object3d.defaultup); }; } } }();
use on object rotated parent : (check this fiddle)
alwayslookatcamera(anyobjectfromthescene, camera);
basically, overrides matrixworld
of given object before rendering it.
however, not recommend use function three.js not built used this.
check westlangley's answer proper solution
Comments
Post a Comment