kevzettler Posted January 31, 2017 Share Posted January 31, 2017 I have a complex modular character. The character has a parent (Anchor) mesh and many child meshes. I want to target FollowCamera on one of the child meshes (Head). When I assign Head to FollowCamera.lockedTarget the behavior is not desired. The camera points at coordinates that match the Anchor element. The camera appears to follow the local position of Head and not the expected world position. Check this play groundhttp://www.babylonjs-playground.com/#ZXP4M#11 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 31, 2017 Share Posted January 31, 2017 Hello, Because your head object is tied to bones, it's world position is controlled by bones. So the idea would be to attach a mesh to the bone controlling the head and point your target to this dummy mesh. Here is a sample of how AttachToBone works: http://www.babylonjs-playground.com/#11BH6Z#154 (see line #54) Quote Link to comment Share on other sites More sharing options...
kevzettler Posted January 31, 2017 Author Share Posted January 31, 2017 @Deltakosh Thanks for the answer. I'm confused though and have a follow-up question. How would I get relative positions to the bound meshes? I'd want to position the "Dummy" LockedTarget mesh relative to the Head. I will also want to get other positions relative to the hands and such. I don't believe the bones have positions. Are you saying I would have to first attach Dummy Meshes to bones and position relatively from there? Quote Link to comment Share on other sites More sharing options...
kevzettler Posted February 2, 2017 Author Share Posted February 2, 2017 @Deltakosh i've updated the PG with your suggestion and added: var targetDummy = BABYLON.Mesh.CreateSphere("root", 16, 1, scene, true); var headBone = skeletons[0].bones[skeletons[0].getBoneIndexByName('Head')]; var headMesh = scene.getMeshByName('Head'); targetDummy.attachToBone(headBone, headMesh); var target = targetDummy; It did not have the expected behavior. See: http://www.babylonjs-playground.com/#ZXP4M#15 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 3, 2017 Share Posted February 3, 2017 Hello, are you sure of the mesh and bone names? Even without talking about the FollowCamera, it seems to me that your mesh is not linked to the bone: http://www.babylonjs-playground.com/#ZXP4M#16 Quote Link to comment Share on other sites More sharing options...
kevzettler Posted February 4, 2017 Author Share Posted February 4, 2017 Hi @Deltakosh Thanks for helping with this. I'd rather you spend your time updating Babylon, much appreciated Quote Hello, are you sure of the mesh and bone names? Do you mean the "Head" mesh and bone? I added log output showing that they are objects How else can I verify? var headBone = skeletons[0].bones[skeletons[0].getBoneIndexByName('Head')]; var headMesh = scene.getMeshByName('Head'); console.log(headBone); console.log(headMesh); Quote Even without talking about the FollowCamera, it seems to me that your mesh is not linked to the bone: Again which mesh to which bone? The "Dummy" mesh or the "Head" mesh. How do I verify? These meshes and bones are exported straight from Blender. I have not manually attached them in Babylon. I also enabled an animation. The animation would not play if the bones were not linked, correct?http://www.babylonjs-playground.com/#ZXP4M#18 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 6, 2017 Share Posted February 6, 2017 if you turn on the debugLayer and enable skeleton viewer + labels, you can see that the dummy is at the right spot: http://www.babylonjs-playground.com/#ZXP4M#19 So here is an update that should be ok: http://www.babylonjs-playground.com/#ZXP4M#21 Quote Link to comment Share on other sites More sharing options...
kevzettler Posted February 7, 2017 Author Share Posted February 7, 2017 Thanks @Deltakosh, looks like the mesh is now attached to the bone. Going back to the original question, I have updated the PG to use FollowCamera and target the TargetDummy mesh, see http://www.babylonjs-playground.com/#ZXP4M#23. Unfortunately, it does not actually follow the meshes position. I see in PG#22 there was a condition added to the render loop: This forces the camera to target on the meshes "absolute position" each frame. If I log TargetDummy.position and Target.getAbsolutePosition() I see that .position is never updated its always {x: 0, y: 0, z: 0} Unfortunately, it looks like FollowCamera internally assumes mesh.position is updated. see:https://github.com/BabylonJS/Babylon.js/blob/master/src/Cameras/babylon.followCamera.ts#L47-L49 So I don't think this will work without a method of updating the target's position or updating FollowCamera to use getAbsolutePosition() Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 7, 2017 Share Posted February 7, 2017 Correct, I'll fix it in next update Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 7, 2017 Share Posted February 7, 2017 Should be good now Quote Link to comment Share on other sites More sharing options...
kevzettler Posted February 8, 2017 Author Share Posted February 8, 2017 cool thanks @Deltakosh I think you need to update ArcFollowCamera while you're at it too : https://github.com/BabylonJS/Babylon.js/blob/master/src/Cameras/babylon.followCamera.ts#L95-L96 Quote Link to comment Share on other sites More sharing options...
kevzettler Posted February 8, 2017 Author Share Posted February 8, 2017 I created a PR here: https://github.com/BabylonJS/Babylon.js/pull/1755 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 8, 2017 Share Posted February 8, 2017 Merged thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.