Rotation Bones
BlitzMax Forums/MiniB3D Module/Rotation Bones
| ||
I'm working on a posing program using BM and miniB3D. I got a model with bones. Now I want to rotate/move every bone. But everything I tried failed. At least I tried the functions from http://blitzmax.com/Community/posts.php?topic=89614#1018156 but they don't work nothing is moving. So, what's the right way to rotate/move bones from a model? |
| ||
So it's never been easy to maneuver bones in minib3d, which is why i started to rearrange the code when i did the bmax->monkey conversion. in TBones.bmx, I suggest adding this to make things easier: (I converted it from monkey to bmax in my head, so there may be something i missed, but shouldn't be difficult at all to convert.) With the above method, you use a bone and input position and quaternion rotation which will update the correct matrices and children. PLEASE NOTE: would would also need to update the keyframes yourself, which is what that link you supplied above shows. Then you need to call VertexDeform(mesh) to view the mesh changes. Last edited 2012 Last edited 2012 |
| ||
Thanks Adam, but I got some problems to bring this to run. I'm really lame on 3D stuff ^^ Curently I'm stuck at this lines: rx=-mat.GetYaw() '-eul[0] ry=mat.GetPitch() 'eul[1] rz=mat.GetRoll() 'eul[2] The TMatrix in miniB3D do not have GetYaw, GetPitch or GetRoll methods. Also it doesn't have fields for that. It only has a array of float [4,4]. I'm sure yaw, pitch and roll are stores in the array but I'm not sure. What about the comment line 'Local eul:Float[] = Quaternion.QuatToEuler(quat.x,quat.y,quat.z,quat.w)? Can I use this, too? But then QuatToEuler needs more parameters (pitch ...) Every help is welcome :) Last edited 2012 |
| ||
I think bones are accessible as children of the mesh they deform, and as such can be treated like any entity - you can use all entity transformation methods on them (Move, Position, Scale, Turn and RotateEntity). There's a bone animation demo that comes with mB3D, it aligns a sphere with a bone to show its transformations through the course of the animation. |
| ||
It's not as easy as you say Kryzon. I'm using the sample you describe to test bone movement, rotation and just use MoveEntity/TurnEntity on a bone has no effect. Also when I call TAnimation. VertexDeform(mesh) after it. It's very confusing me. |
| ||
updated the code above for yaw, pitch, roll equations. Note: updating the bones individually does not work since the bones use a different matrix (tform_mat). |
| ||
This is working:Function rotateBone(mesh: TMesh, bone: TBone, rx: Float, ry: Float, rz: Float) Local w:Float,x:Float,y:Float,z:Float Local pos: TVector = New TVector Local quat: TQuaternion = New TQuaternion mesh.anim = True EulerToQuart(ry,rx,rz,w,x,y,z) pos.x = rx pos.y = ry pos.z = rz quat.x = x quat.y = y quat.z = z quat.w = w bone.keys.qw[0] = w bone.keys.qx[0] = x bone.keys.qy[0] = y bone.keys.qz[0] = z bone.keys.flags[0] = 5 bone.keys.px[0] = bone.n_px# bone.keys.py[0] = bone.n_py# bone.keys.pz[0] = bone.n_pz# TAnimation.AnimateMesh(mesh, 0, 0, 0) End Function Function EulerToQuart(yaw:Float,pitch:Float,roll:Float,w:Float Var,x:Float Var,y:Float Var,z:Float Var) Local c1:Float = Cos(yaw/2),c2:Float=Cos(pitch/2),c3:Float = Cos(roll/2) Local s1:Float = Sin(yaw/2),s2:Float=Sin(pitch/2),s3:Float = Sin(roll/2) Local c1c2:Float = c1*c2 Local s1s2:Float = s1*s2 w = (c1c2 * c3) - (s1s2 * s3) x = (c1c2 * s3) + (s1s2 * c3) y = (s1 * c2 * c3) + (c1* s2 * s3) z = (c1 * s2 * c3) - (s1 * c2 * s3) End Function Last edited 2012 Last edited 2012 |