0
101 Feb 28, 2007 at 22:40

Hi, I am newbie in Blender, and I have modelled a character and added an armature, I am trying to load the mesh using cal3d in my project.

I am using a cal3d exporter but I am having strange results.

I ckecked the mesh with cal3d viewer.

The rotation of the animation is not right. Apart from that the arms are separated from the body and are larger and twisted , and the subsurf effect is not applied in the mesh so it doesn’t have a smooth shape. And no material is drawn.

I would like to know if this problem is because I did something wrong modelling or adding the armatures.

Thank you very much for you help.

(I am using the cal3d exporter 1.5 (8/2006) and I get a warning related to the weights, but I don’t know if it is for that.)

7 Replies

0
101 Mar 01, 2007 at 05:42

The cal3d exporter for blender is broken. There have been too many hacks on it over the years. We use cal3d also and I had to pretty much rewrite the entire export function of the script. I remember there was an issue with bone roll values. The script uses bone roll values in radians and since version 2.41 blender gives roll values in degrees.

Before you ask me for my current script let me say, the current script is too heavily modified for our engine and I can’t directly post it over here because of legal issues. But I can help you with yours. For a start, try changing the following pieces of code.

def matrix_rotate_x(angle):
cos = math.cos(angle)
sin = math.sin(angle)
return [
[1.0,  0.0, 0.0, 0.0],
[0.0,  cos, sin, 0.0],
[0.0, -sin, cos, 0.0],
[0.0,  0.0, 0.0, 1.0],
]

def matrix_rotate_y(angle):
cos = math.cos(angle)
sin = math.sin(angle)
return [
[cos, 0.0, -sin, 0.0],
[0.0, 1.0,  0.0, 0.0],
[sin, 0.0,  cos, 0.0],
[0.0, 0.0,  0.0, 1.0],
]

def matrix_rotate_z(angle):
cos = math.cos(angle)
sin = math.sin(angle)
return [
[ cos, sin, 0.0, 0.0],
[-sin, cos, 0.0, 0.0],
[ 0.0, 0.0, 1.0, 0.0],
[ 0.0, 0.0, 0.0, 1.0],
]

def matrix_rotate(axis, angle):
vx  = axis[0]
vy  = axis[1]
vz  = axis[2]
vx2 = vx * vx
vy2 = vy * vy
vz2 = vz * vz
cos = math.cos(angle)
sin = math.sin(angle)
co1 = 1.0 - cos
return [
[vx2 * co1 + cos, vx * vy * co1 + vz * sin, vz * vx * co1 - vy * sin, 0.0],
[vx * vy * co1 - vz * sin, vy2 * co1 + cos, vy * vz * co1 + vx * sin, 0.0],
[vz * vx * co1 + vy * sin, vy * vz * co1 - vx * sin, vz2 * co1 + cos, 0.0],
[0.0, 0.0, 0.0, 1.0],
]


with

def matrix_rotate_x(angle):
return [
[1.0,  0.0, 0.0, 0.0],
[0.0,  cos, sin, 0.0],
[0.0, -sin, cos, 0.0],
[0.0,  0.0, 0.0, 1.0],
]

def matrix_rotate_y(angle):
return [
[cos, 0.0, -sin, 0.0],
[0.0, 1.0,  0.0, 0.0],
[sin, 0.0,  cos, 0.0],
[0.0, 0.0,  0.0, 1.0],
]

def matrix_rotate_z(angle):
return [
[ cos, sin, 0.0, 0.0],
[-sin, cos, 0.0, 0.0],
[ 0.0, 0.0, 1.0, 0.0],
[ 0.0, 0.0, 0.0, 1.0],
]

def matrix_rotate(axis, angle):
vx  = axis[0]
vy  = axis[1]
vz  = axis[2]
vx2 = vx * vx
vy2 = vy * vy
vz2 = vz * vz
co1 = 1.0 - cos
return [
[vx2 * co1 + cos, vx * vy * co1 + vz * sin, vz * vx * co1 - vy * sin, 0.0],
[vx * vy * co1 - vz * sin, vy2 * co1 + cos, vy * vz * co1 + vx * sin, 0.0],
[vz * vx * co1 + vy * sin, vy * vz * co1 - vx * sin, vz2 * co1 + cos, 0.0],
[0.0, 0.0, 0.0, 1.0],
]


then

def blender_bone2matrix(head, tail, roll):
# Convert bone rest state (defined by bone.head, bone.tail and bone.roll)
# to a matrix (the more standard notation).
# Taken from blenkernel/intern/armature.c in Blender source.

target = [0.0, 1.0, 0.0]
delta  = [tail[0] - head[0], tail[1] - head[1], tail[2] - head[2]]
nor    = vector_normalize(delta)
axis   = vector_crossproduct(target, nor)

if vector_dotproduct(axis, axis) > 0.0000000000001:
axis    = vector_normalize(axis)
theta   = math.acos(vector_dotproduct(target, nor))
bMatrix = matrix_rotate(axis, theta)

else:
if vector_crossproduct(target, nor) > 0.0: updown =  1.0
else:                                      updown = -1.0

# Quoted from Blender source : "I think this should work ..."
bMatrix = [
[updown, 0.0, 0.0, 0.0],
[0.0, updown, 0.0, 0.0],
[0.0, 0.0, 1.0, 0.0],
[0.0, 0.0, 0.0, 1.0],
]

rMatrix = matrix_rotate(nor, roll)
return matrix_multiply(rMatrix, bMatrix)


with

def blender_bone2matrix(head, tail, roll):
# Convert bone rest state (defined by bone.head, bone.tail and bone.roll)
# to a matrix (the more standard notation).
# Taken from blenkernel/intern/armature.c in Blender source.

target = [0.0, 1.0, 0.0]
delta  = [tail[0] - head[0], tail[1] - head[1], tail[2] - head[2]]
nor    = vector_normalize(delta)
axis   = vector_crossproduct(target, nor)

if vector_dotproduct(axis, axis) > 0.0000000000001:
axis    = vector_normalize(axis)
theta   = math.acos(vector_dotproduct(target, nor))
bMatrix = matrix_rotate(axis, math.degrees(theta))

else:
if vector_crossproduct(target, nor) > 0.0: updown =  1.0
else:                                      updown = -1.0

# Quoted from Blender source : "I think this should work ..."
bMatrix = [
[updown, 0.0, 0.0, 0.0],
[0.0, updown, 0.0, 0.0],
[0.0, 0.0, 1.0, 0.0],
[0.0, 0.0, 0.0, 1.0],
]

rMatrix = matrix_rotate(nor, roll)
return matrix_multiply(rMatrix, bMatrix)


This should work with v2.42a. I haven’t tested it with 2.43 yet. Hope that helps.

0
101 Mar 01, 2007 at 15:39

Thank you for answering, I have modified the code, but I still have the same problems, I have read other threads about this but they haven’t found the solution either.

One of them shows the same problem I have.
This urls shows a pic of a deformed mesh, that It looks like mine.

http://img93.imageshack.us/my.php?image=dummyfemaleshotwalkanim1fc.png

Maybe it is because I do something wrong, I have tried to use baked animation, but I don’t get a good result either.

Is there any rule to follow before applying the script like the type of animation,… or it is because the script changes the axis ???

I am quite lost.

Thank you very much

0
101 Mar 01, 2007 at 18:09

Yup seeing that image it seems like a combination of axis and bone roll problems. I will outline the problems in the script that I faced. The fact is when I modified the script about 6 months back, I used a combination of scripts what were half baked themselves and through a lot of head scratching and hair pulling and sifting through a mountain of Cal3D code and spec could get a script that correctly exports a model. :wallbash: To modify the script you must be more than thorough with with Cal3D library and its format to some extent.

1. When compared to our engine, Blender’s axis is rotated around the X - Axis. So for blender +Z faces up. In our engine +Y faces up. The problem is, you can’t just rotate the vertices of your model, you will have to rotate the bones and the roll values too. This is tricky. Find the piece of code where roll values are written and multiple with the proper orientation matrix. Check the function blender_bone2matrix(head, tail, roll). You will have to rotate the matrix according to your requirement. You can get around this by maybe rotating the model while loading. I haven’t tried it, maybe it will work maybe it wont!

2. The original script does not handle materials well. Actually it does not handle materials at all. Meaning, if you assign materials to your mesh, then only one material gets exported. This is fine if you have a UV mapped model using a single texture. We had a specific requirement where we wanted our cal3d meshes with multiple materials. Cal3D does not support multiple materials on one sub-mesh. The only option was to export the model in multiple sub-meshes. One submesh for each material. This was a nasty hack but it actually turned out great in the end.

3. Is the problem with radian-degree values that I mentioned earlier. Blender team changed the way bone roll values are given. ie. they were given off as radians prior to 2.37 (i think) and now are given as degrees. Why? I am as surprised as you are.

4. Another thing that I needed to changed was triangle-face orientation on the model. This actually had me stumped. For some reason, the triangle faces were oriented anti-clockwise. I don’t understand the reason. Maybe you just have to call “Recalculate normals outside” or something. But for me the triangle winding was always in the opposite direction. Maybe the script is genuinely wrong and this is a bug.

0
101 Mar 01, 2007 at 18:31

Hey! I actually downloaded blender v2.43 and there is no Cal3D export option anymore! Looks like the script got broken so bad they removed it.

0
101 Mar 01, 2007 at 23:55

Yes, there is no cal3d exporter in v2.43, I was looking for it, when I downloaded the new version but it wasn’t.

I will change the code a bit, with the changes you proposed me.

there is a new version of the cald3d exporter and a mesh example, and It works fine with this mesh, but when I use it with mine I still have the same problem, I think there must be something that I don’t take into account, I don’t know, maybe the IKSolver, because the example I downloaded hasn’t IKSolvers.

And there is another example here with another mesh without IKSolvers, maybe I can see what’s wrong with my mesh checking the examples:

Can It be for the IKSolvers??.

Because I just create vertex groups in the mesh with the same names as the bones, and after that I make parent the armature of the mesh without creating groups, and then I just go to the action menu, and I select all the bones and press ‘i’ lock and rotation, and I do the same for the last frame of the animation, like I read in one tutorial.

Do I have to do anything else if I want to use an exporter ???.

I thought It would be the axis, and the roll too but then I don’t understand why these meshes work fine with the script,.

Thanks for your help again !!!

Bye

0
101 Mar 02, 2007 at 05:47

@last_year23

Because I just create vertex groups in the mesh with the same names as the bones, and after that I make parent the armature of the mesh without creating groups, and then I just go to the action menu, and I select all the bones and press ‘i’ lock and rotation, and I do the same for the last frame of the animation, like I read in one tutorial.

Yup that is pretty much what we do too. That should not be a problem. Are you parenting the bones correctly? Cal3D can’t deal with multiple root bones. Try creating a fresh project and then try exporting it.

OK I will take a look at the script and run some tests on it. I am a little preoccupied right now, maybe over the weekend. I tested my script on 2.43 and it did not show any problems, so thankfully, they haven’t made any breaking changes. That’s :yes:

Will update my findings.

0
101 Mar 02, 2007 at 18:19

Yes, in the object section, I choose first the mesh and second the armature, and I make parent to the armature, but sometimes I click on the armature and It goes to the pose pannel with just one bone selected.

If you try these scripts tell me if they work with your meshes, please.
I am using free meshes now for my university project but I will continue trying because I would like to add my own meshes.

When I manage to load my mesh I will tell you. Thank you very much for your help.

Bye!!!!