fixing BlenderToCal3D script to work with 2.4

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Roja
Posts: 0
Joined: Tue May 04, 2004 4:36 pm

Post by Roja »

Hey,

Ok I tested it on a file I had. It does export the files, but it didn't work correctly in my game, we are using Cal3d version 0.10 in our client.

Things I noticed:

The animation is not working. Nothing moves. (tested in our game client and in a cal3d viewer).

The .csf file I exported from 2.37 was 2kb in size. The skeleton file using your exporter is about 9kb in size. Is this because of the new armature stuff in Blender?

The mesh files are NOT the same size, and it is the mesh files that cause our game client to crash, and to crash the cal3d viewer as well. An old mesh file is: 7.264kb. new file is: 5.868
Perhaps they are lacking animation data? That would explain things.

animation files are the same size as the old.

One other question: with this new exporter, it seems i can't use old files mixed in with the new(like if certain models share a mesh/animation/skeleton) the model looks like a jumbled mesh in the game when it uses an old animation with the new skeleton file for example. So I'm guessing they arne't compatible and i'd have to reexport everything, right?

oh and i was not exporting to .xml files, but to .csf, .caf, cmf

kostya_z
Posts: 0
Joined: Mon Oct 24, 2005 12:29 pm

Post by kostya_z »

Hello,
First of all thank you for giving it a try!
Yes, there is something wrong with exporting vertices data and I'll be working on that today. That's why you got your model looking jumbled.
I can't say anything about animations yet because I didn't get that far, but in my model a simple animation was working properly.
And lastly I am not a Python or Blender or Cal3D professional, but I just need this exporter for my work too, that's why I decided to fix it.
All I changed so far is treat_bone function and this little cycle where treat_bone is being called. I guess it's not enough...

kostya_z
Posts: 0
Joined: Mon Oct 24, 2005 12:29 pm

Post by kostya_z »

Roja, could you download it again and try, please, and tell whether your models still look jumbled? Just one little try. I've got hold of another, more comlicated model. The more comlicated one looks jumbled, the simpler one does not, but it's rotated different (roll values are different because of some reasons).

Roja
Posts: 0
Joined: Tue May 04, 2004 4:36 pm

Post by Roja »

Hi,

Ok tested it again, this time nothing exported, I got this error message:

Traceback (most recent call last):
File "<string>", line 1674, in bevent
File "<string>", line 1471, in export
NameError: global name 'outputFile' is not defined

btw, if you have an IM program i'd be more than happy to help you test this like immediately :) I'll be online for the next 6hours or so, let me know what i can message you on if you want.

Edit:
I'm not a programmer at all, but I opened the script and searched for outputFile, and found that line 1057 was commented out, so i deleted the # and it exported!

Test Results:
The MESH object still crashes the client/cal3d viewer. I get a Microsoft Visual C++ Runtime Error when I run our game client.

When I use an old mesh object, and the new skeleton/animation, the mesh is still all jumbled-but so is the skeleton. Instead of a normal walk animation the skeleton's legs are far apart, the arm is up in the air..pretty weird :p

When I use an old mesh object, and an old animation file with the new skeleton, the skeleton looks fine (mesh is warped but I think you're right-it's because the rotation is different)

I found out the Rotation difference: If you are FACING the skeleton, look at the front of it, the old mesh files are rotated 90 counter clockwise. So it seems that in the new exporter eventhing is rotated 90 clockwise. (hopefully this can be changed to the old way so old meshes can be used?)

kostya_z
Posts: 0
Joined: Mon Oct 24, 2005 12:29 pm

Post by kostya_z »

Hi,
I am sorry, I didn't check the file again before I posted it there. Also I posted it at the end of a work, so I couldn't reply. But thank you for the offer. My time is GMT here.
Try to load the new skeleton file with an old mesh, but turn off the animation (comment out all the lines for animation in .cfg file)
It's interesting because when I merely load the mesh the model actually looks OK, but when an animation starts, this is when it's all twisted. Maybe tha's the way it should be, because unless the hand moves Bone's roll value has no actual effect on the way the bone is displayed. I am all confused myself and stuck with that stuff. I posted the question about that to Coding Blender section, but no one seems to want to reply :wink:

kostya_z
Posts: 0
Joined: Mon Oct 24, 2005 12:29 pm

Post by kostya_z »

Hello,
I got some interesting results by multiplying Bone's ARMATURESPACE and BONESPACE values. The rotation values are still different, but it's not warped anymore. This is for easy mesh though. More comlicated one still looks jumbled. I also submitted a blend file to a bug tracker. I think it will still cause your viewer to crash, because I didn't fix the mesh problem. So you may try if you want, but I don't think it would work.

Thank you!

Roja
Posts: 0
Joined: Tue May 04, 2004 4:36 pm

Post by Roja »

Hi,

I don't use the .cfg files at all, so i can't try that thing.

Anyway I wish I was a programmer so i can help with this! All I can do is testing. Just let me know when you've made any progress as i'm very anxious to see it working too :)

kostya_z
Posts: 0
Joined: Mon Oct 24, 2005 12:29 pm

Post by kostya_z »

Roja:
Could you give the script a try again, please? I got the more complicated mesh to export as it was before.
In my case the problem was that there were some additional vertex groups that were not actually mapped to Bone names. I don't really know what they are there for. But they caused for script to calculate the wrong weight per vertex and therefore the model was looking jumbled.
Thanks!

an-toni
Posts: 0
Joined: Wed Mar 17, 2004 5:20 pm

Post by an-toni »

uh, how come does the script even care about vertex groups that dont have influences, and how do they end up affecting the result? havent read the code, i guess that is not a crucial one but a nasty bug anyways.

~Toni

kostya_z
Posts: 0
Joined: Mon Oct 24, 2005 12:29 pm

Post by kostya_z »

This piece of code:

Code: Select all

influences = data.getVertexInfluences(face.v[i].index)
returns the list of ALL vertex groups that influence the given vertex, not bones only as it was before. I don't know why. This resulted in that:

Code: Select all

for bone_name, weight in influences:
                      if not BONES.has_key(bone_name):
                        continue
Script needs to check if this is a bone or a vertex group only.

Roja
Posts: 0
Joined: Tue May 04, 2004 4:36 pm

Post by Roja »

Alright, tested:

1. Old Mesh files are no longer jumbled..BUT, any new mesh I export STILL crashes the client/viewer. I can't get a new mesh to work.
--I exported XMF versions(so that you can actually read the file) of the new mesh, and the old mesh(with the old exporter/blender), and noticed that in the new mesh it is missing the texture coordinate info completely. This sounds like it's the reason for the crashes. There are also not as many vertices in the file..no idea why that is.

Here is a comparison of the headers & 1 vertex ID of the same mesh with the different exporters/blender versions:

OLD Mesh:

Code: Select all

<HEADER MAGIC="XMF" VERSION="900"/>
<MESH NUMSUBMESH="1">
  <SUBMESH NUMVERTICES="417" NUMFACES="638" MATERIAL="2" NUMLODSTEPS="0" NUMSPRINGS="0" NUMTEXCOORDS="1">
    <VERTEX ID="0" NUMINFLUENCES="1">
      <POS>-0.097176 0.222498 -0.001344</POS>
      <NORM>-0.000000 0.000000 -1.000000</NORM>
      <TEXCOORD>0.035156 0.207031</TEXCOORD>
      <INFLUENCE ID="10">1.000000</INFLUENCE>
    </VERTEX>
New mesh:

Code: Select all

<HEADER MAGIC="XMF" VERSION="900"/>
<MESH NUMSUBMESH="1">
  <SUBMESH NUMVERTICES="321" NUMFACES="638" MATERIAL="2" NUMLODSTEPS="0" NUMSPRINGS="0" NUMTEXCOORDS="1">
    <VERTEX ID="0" NUMINFLUENCES="1">
      <POS>-0.097176 0.222498 -0.001344</POS>
      <NORM>-0.000000 0.000000 -1.000000</NORM>
      <INFLUENCE ID="10">1.000000</INFLUENCE>
    </VERTEX>

2. Skeleton seems to be jumbeled still when i look at it in the viewer.
--Tested the NEW skeleton with an OLD mesh and OLD animation and the new skeleton looks fine. Testing the NEW skeleton with OLD mesh and NEW animation, the skeleton appears jumbeled-seems to be the animation doing this...let's look at the XAF files....:

OLD animation:

Code: Select all

   <TRACK BONEID="6" NUMKEYFRAMES="3">
    <KEYFRAME TIME="0.000000">
      <TRANSLATION>0.000000 0.169735 -0.000000</TRANSLATION>
      <ROTATION>-0.182221 0.000000 -0.000000 -0.983258</ROTATION>
    </KEYFRAME>
    <KEYFRAME TIME="0.239000">
      <TRANSLATION>0.000000 0.169735 -0.000000</TRANSLATION>
      <ROTATION>-0.182221 0.000000 -0.000000 -0.983258</ROTATION>
    </KEYFRAME>
    <KEYFRAME TIME="0.473156">
      <TRANSLATION>0.000000 0.169735 -0.000000</TRANSLATION>
      <ROTATION>-0.182221 0.000000 -0.000000 -0.983258</ROTATION>
    </KEYFRAME>
  </TRACK>
New Animation

Code: Select all

  <TRACK BONEID="6" NUMKEYFRAMES="3">
    <KEYFRAME TIME="0.000000">
      <TRANSLATION>0.000000 0.169735 0.000000</TRANSLATION>
      <ROTATION>-0.182221 -0.000000 -0.000000 -0.983258</ROTATION>
    </KEYFRAME>
    <KEYFRAME TIME="0.239000">
      <TRANSLATION>0.000000 0.169735 0.000000</TRANSLATION>
      <ROTATION>-0.182221 -0.000000 -0.000000 -0.983258</ROTATION>
    </KEYFRAME>
    <KEYFRAME TIME="0.473156">
      <TRANSLATION>0.000000 0.169735 0.000000</TRANSLATION>
      <ROTATION>-0.182221 -0.000000 -0.000000 -0.983258</ROTATION>
    </KEYFRAME>
  </TRACK>

As you can see, it's not only Rotation that's off, but Translation as well(that's why in addition to the skeleton being rotated 90degrees in the wrong direction, it appears jumbeled too.
Oh, and this is an example of just 1 bone ID in the animation, in others the -/+ values are all swapped differently.

kostya_z
Posts: 0
Joined: Mon Oct 24, 2005 12:29 pm

Post by kostya_z »

Thank you very much for such a thorough testing!
I am sorry, long time ago I disabled UV coordinates in this script as I was having some troubles with it. I absolutely forgot about that. I enabled them back again and uploaded exporter to geocities. As to problems with Actions I got some weird results too. Still working on it. If you take a look at the bug tracker discussion, it seems that Roll values are different due to Blender's internal changes and shouldn't be like that. Let's wait on Blender 2.41a or 2.42 :wink:

Roja
Posts: 0
Joined: Tue May 04, 2004 4:36 pm

Post by Roja »

ah ok. Guess that means i gotta stick with 2.37 for a few more months. Oh well, at least we know what the problem is :)

dcyoung
Posts: 0
Joined: Fri Feb 17, 2006 9:28 pm

Post by dcyoung »

Here's another updated version of the exporter, which seems to work with animation constraints and with models created in 2.37:

http://purple.worldforge.org/cvs/forge/ ... cal3d_2.py

Roja
Posts: 0
Joined: Tue May 04, 2004 4:36 pm

Post by Roja »

Hi, ok I tested it out, here's my results:

new mesh works with old skeleton and animations,
BUT, the UV coords of the new mesh are flipped.

New skeleton seems to be fine, but does not work with new mesh & animation OR old animation. So from this I would assume that it's the animation that didnt' export properly. The new animation seems to be screwed up as when it's shown with the mesh and skeleton the mesh is not where it should be positioned and is moving all goofy.

Using the old or new animation with the new skeleton and mesh gives the same result.

Also note that the old and new Mesh and Skeleton files are both the same in file size, the animation files are not, the newer one is bigger.

Post Reply