Creating bones in miniB3D

BlitzMax Forums/MiniB3D Module/Creating bones in miniB3D

AdamRedwoods(Posted 2011) [#1]
I noticed there isn't really a function to create bones on their own in miniB3D.

Looking through the code, it isn't that explanatory. Does anyone have any knowledge regarding how miniB3D creates bones and what information is needed to create one from scratch?

What I understand thus far, is that bones are created when the B3D files is loaded. Each bone is a bunch of information, but closely linked with a surface as well. The surface relates to vertices that have bone influence on them. Then, to move these points in the bone space, there is a quaternion associated with the bone.

The fields: vert_bone1_no:int and vert_weight1:Float --I don't understand exactly how these values (why 4 of them?) are being used or what goes into them.

I also don't know the fields, aside from the obvious "n_qw#" quaternion values (I'm guessing they are a start and end):
n_px#,n_py#,n_pz#,n_sx#,n_sy#,n_sz#,n_rx#,n_ry#,n_rz#,n_qw#,n_qx#,n_qy#,n_qz#

Can anyone help clarify? Ultimately, I'd like to add bones via a function and have them animate programmaticaly, for use in say, a tentacle.


Kryzon(Posted 2011) [#2]
There are only four values because that's a common value for many engines to support. Imagine having more than four bones influencing the same vertex - one of them is prone to having a neglectable influence. Even having 5 bones, 20% of influence for each is very little.
Four is mostly enough; however, since we are dealing with a software solution I don't see why it couldn't be more (we could have 'n' influences), if that's what you are asking.

A 'TMesh' has a 'bones:TBone' array which stores all the bones that influence this mesh.

vert_boneN_no[ vertIndex ] -> The index of the Nth bone affecting the vertex of index 'vertIndex'.
vert_weightN[ vertIndex ] -> Weight this Nth bone has over vertex of index 'vertIndex'. Weight are ordered and the 4th bone is always the one to have the weakest. This is done at model load-time.

The "n_something" values are back from when the bone had its NODE chunk read ('n' for Node, see? if you go up in the TModel.BMX you'll see that when the code detects a NODE chunk it fills these 'n_' variables).
Bones are nodes as well. They have a name, position (p values), rotation (q values - they are converted to euler and become r values) and scale (s values).

Adding bones through code is most likely going to be a pain. I'd suggest adding them through modelling software (export the mesh with the bind pose), and then animating them programatically; you could read up on how to calculate real-time solvers for that great tentacle-like IK.

Last edited 2011


AdamRedwoods(Posted 2011) [#3]
Thanks for the info, I'm going to work on it some more and see what I can come up with. I know it's a nasty task.

I also found this:
http://www.blitzbasic.com/codearcs/codearcs.php?code=2485


AdamRedwoods(Posted 2011) [#4]
I've gotten pretty far with making bones in miniB3D, the problem is I've encountered a slight oddity.

The code from TAnimation.bmx under VertexDeform():
' transform vertex position with transform mat
x= ( bone.tform_mat.grid[0,0]*ovx + bone.tform_mat.grid[1,0]*ovy + bone.tform_mat.grid[2,0]*ovz + bone.tform_mat.grid[3,0] ) * weight
y= ( bone.tform_mat.grid[0,1]*ovx + bone.tform_mat.grid[1,1]*ovy + bone.tform_mat.grid[2,1]*ovz + bone.tform_mat.grid[3,1] ) * weight
z= ( bone.tform_mat.grid[0,2]*ovx + bone.tform_mat.grid[1,2]*ovy + bone.tform_mat.grid[2,2]*ovz + bone.tform_mat.grid[3,2] ) * weight


seems to be wrong. If I put a weight of "0" in, the vertexes collapse to 0. I suspect it should be ovx, ovy, ovz instead of "0".

Has anyone heard of problems with importing weights into miniB3D? I don't want to "fix anything that ain't broke".

UPDATE:
I added "+ (1.0-weight)*ovx" and "+ (1.0-weight)*ovy" and "+ (1.0-weight)*ovz"
to the above sections in VertexDeform() and it worked ok for the zombie example, but not for a separate .b3d file example. I'll keep hacking...

Last edited 2011
UPDATE:
I remember now that all the weights should equal =1.

That explains why when I use only one bone with less than 1 weight why it fails.

Last edited 2011