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):
cos = math.cos(math.radians(angle))
sin = math.sin(math.radians(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(math.radians(angle))
sin = math.sin(math.radians(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(math.radians(angle))
sin = math.sin(math.radians(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(math.radians(angle))
sin = math.sin(math.radians(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],
]
```

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.
# See also DNA_armature_types.h:47.
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.
# See also DNA_armature_types.h:47.
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.

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.)