View Full Version : Help Wanted -- Blender Plugin Creator for TS3 Animator
rothn
23rd Jan 2011, 06:56 AM
Could anybody here or anybody you know code an importer/exporter for Blender? The format follows.
QWORD "ANIMATOR"
DWORD 2
DWORD "_RIG"
DWORD boneCount
REP boneCount
{
BYTE charCount
CHAR[charCount] boneName
DWORD parentIndex
FLOAT[4][4] localTransformMatrix
}
DWORD "ANIM"
DWORD animatedBoneCount
REP animatedBoneCount
{
DWORD boneIndex
DWORD numTranslationFrames
DWORD numRotationFrames
REP numTranslationFrames
{
DWORD frameNumber
FLOAT[3] translation
}
REP numRotationFrames
{
DWORD frameNumber
FLOAT[4] quaternion
}
}
In order to accommodate the programmer, I am willing to make changes to this format. The reason that I am making my own format is that I plan on adding lots of stuff to it later from additional data I extract from rig files (e.g. IK chains, compress joints, etc). The reason that I ask desperately for help with this is because I don't know the first thing about the Blender API. While I have learned Python (it is just another language, after all) I would rather continue development on the jazz editor and the animator, rather than do stuff with Blender, an excellent platform that I know very little about
Please feel free to contact me if you plan to work on this importer/exporter. Also, tell me if you need a sample file, as I can provide one.
:alarm: Developer Note: There are some bones that are in the same place as their parent in the rigging. Therefore, you need to keep Blender from deleting those automatically by not connecting them. Cmomonkey can explain this "connected" thing better. :alarm:
lenglel
26th Jan 2011, 12:33 AM
I downloaded blender 2.56a, the exact filename is blender-
2.56a-beta-windows32.exe is that the right one? If it isn't can
someone point me to the right one, because this was the most
recent version I could find when I started from the link in blender 2.55
I also downloaded blender_python_reference_2_55_0.pdf is that the
one I should be using?
For python I d/led python-2.7.1.msi, wxPython2.8-win32-unicode-
2.8.11.0-py27.exe and wxPython2.8-win32-docs-demos-2.8.11.0
.exe
I'm going to install what I've got and start learning. Please let me
know if I should be using different versions of any of the above.
TIA Lloyd
cmomoney
26th Jan 2011, 03:30 AM
I downloaded blender 2.56a, the exact filename is blender-
2.56a-beta-windows32.exe is that the right one? If it isn't can
someone point me to the right one, because this was the most
recent version I could find when I started from the link in blender 2.55
Yes, currently that is the most recent version.
I also downloaded blender_python_reference_2_55_0.pdf is that the
one I should be using?
There is a api reference for 2.56 here (http://www.blender.org/documentation/blender_python_api_2_56_0/blender_python_reference_2_56_0.pdf)
For python I d/led python-2.7.1.msi, wxPython2.8-win32-unicode-
2.8.11.0-py27.exe and wxPython2.8-win32-docs-demos-2.8.11.0
.exe
Blender uses Python 3.1 (http://www.python.org/download/releases/3.1.3/) (I've never downloaded it, though).
rothn
26th Jan 2011, 11:50 PM
Save my script for last; I may end up releasing my own Blender importer...
lenglel
27th Jan 2011, 01:19 AM
Cmomoney: Thanks for the links, it's good to have the right tools for the job.
I tried your script, but got indexing errors on all three of the .s3asc files I
tried, which were exported with wes howe's s3objtool v1.01 Should I be
using a different tool to get the .s3asc files? I'm using your ts3 import/
export plugin as a working example while I try to learn this stuff.
I'd have it done by now if I were already familiar with python and
blender as the data structure is clear as a bell, but my experience
is limited to writing ruby plugins for sketchup. Do you use and ide
for python scripting, or just the default ui that comes with python?
rothn: if that was directed at me, your script might end up saving
itself for last, as I'm still very near the start of the learning curve.
I did manage to load a blank template to the proper menu today,
and plan to continue as I think other plugins will be needed in
the future, regardless of who writes this particular importer.
I plan to spend today going through the rest of the blender
video tutorials. Tomorrow I should be able to learn enough
python to get my version of the importer to read and write
some data, then I'll check back here for any news.
cmomoney
27th Jan 2011, 02:05 AM
Could you please report in my script's thread, stating the objects you were trying to import? As for using my scripts as an example, I wouldn't advise it, as I have very little experience in programming, so you may be dooming yourself from the start. :P If you look in Blender's script folder there are many examples there. I do my scripting inside Blender.
rothn
27th Jan 2011, 03:12 AM
I will probably write my own Blender script. I'm about halfway done.
lenglel
27th Jan 2011, 11:08 AM
I'm glad to hear that, because while python isn't much different from ruby
blender is a lot more complex than sketchup and *that* took me about
six weeks to learn. I'm still going to keep working on it, though, just
for the experience.
rothn
29th Jan 2011, 10:49 PM
You know, on second thoughts, I'll leave the importer in your hands, as I totally don't understand Blender's animation format... I did leave a post in the Blender development forums asking about the weird curves, etc. I may still be able to do something if they tell me, but as it is, I don't see how a series quaternions can become a "curve" with points like (0.0, 1.0). It makes no sense!
cmomoney
29th Jan 2011, 10:58 PM
Well, my issue was getting the rig in correctly.
rothn
29th Jan 2011, 10:59 PM
The rig doesn't need to be correct, only the hierarchy does.
lenglel
30th Jan 2011, 12:52 AM
RothN:
A quaternion is basically a description of the rotation of a unit vector. Add the vectors tail-to-head and you've got a curve
consisting of the sum of the rotations.
Can you send me a PM with the .py file you've got and a sample
skeleton, and I'll see what I can do to extend it?
Meanwhile, I'll read up on quaternions. They're definitely not Euler
angles, which are easier to comprehend as a set of three rotations,
one for each axis. A quaternion is a direct arc from one point to
another, rather than a sum of three seperate rotations. :blink:
rothn
31st Jan 2011, 11:45 PM
I know what I am doing; I know what a quaternion is. I actually wrote a game engine in C++ before I did this. By the way, I stopped working on the game engine because I realized that I needed an idea for a game to actually use the engine... As for quaternions, think of them as the 4-d version of Euler angles. They don't suffer from gimbal lock when representing 3D orientations for the same reason that Euler angles don't when representing 2D orientations. As for as the animations, I've got that covered. I have almost figured out the Blender API. That said, I no longer need help developing the plugin. Do you still want the source code? Note that the Blender importer is not yet completed.
cmomoney
1st Feb 2011, 12:15 AM
If possible, could you send me a .blend file with the skeleton?
Inge Jones
1st Feb 2011, 08:35 AM
By the way, I stopped working on the game engine because I realized that I needed an idea for a game to actually use the engine.
This is wisdom.
rothn
1st Feb 2011, 11:04 PM
This blend file has just the auRig. Note that my Blender scripts still cannot import animations. I am working on this... If you want to start working on animations, though, be my guest!
P.S. Cmomoney, do you know anything about the Blender animation API; anything helps!
P.P.S. Why do you want this file, anyway? Will you also want cuRig, puRig, etc?
cmomoney
1st Feb 2011, 11:19 PM
Thanks! :D How are you trying to go about importing the animations, as actions? Also, you might want to change the bone shape to 'STICK'.
re: p.s. Mostly experimenting. I'd love to have the rest of the rigs(if it's not to much trouble). :)
orangemittens
3rd Feb 2011, 02:46 AM
rothn, I would also like the rest of the rigs...were you planning on posting them?
rothn
3rd Feb 2011, 03:15 AM
OK, guys, I have just released the next version of the TS3 Animator. The animations do play in Blender, but they don't look right because I haven't finished the part of TS3 Animator that exports the animations to Blender. In fact, you'll probably want to just delete the animation for the time being.
You can, however, use TS3 Animator to change the IK chains and events in animations as well as to export rigs to Blender. I suppose that what I'm saying is that if you want the rigs, get them yourselves!!! (http://nene.modthesims.info/download.php?t=420327)
Thanks for your understanding,
RothN
P.S. Please tell me if you don't know how to use plugins in Blender 2.56a, as I assume that everybody here does.
rothn
4th Feb 2011, 10:07 PM
Could someone here please explain to me the specifics of the Blender animation system, as I'm really having trouble here...
lenglel
5th Feb 2011, 06:53 AM
trying to figure out why it flops all around when you click the 'play animation' button in 'object mode' or 'pose mode'?
Hey, at least it does *something*, which is a big improvement over the nothing I came up with when I tried to write
an import script. :heyhey:
Is it supposed to do anything in 'edit mode' when you click play?
On another note, I had to use the version of the animator posted in this thread to create the project,
when I tried with the version in the download thread I got an exception when I tried to load the rig file.
Trying from the 'clip animation' submenu of the 'new' menu opened a dialog box with a rig filter and
threw an exception no matter what I tried to open. Trying from the import menu, a dialog box with
a clip filter opened and I was able to select a clip file. Then a dialog box with a rig filter opened, and
trying to open a rig file caused an exception.
When I created a project (.s3p) with the version attached to this thread, I was able to open it with the
version in the download thread and 'save animated rig' (.s3a) from the 'frame data' dropdown. I'm
going to try all possible combinations of the checkboxes in the 'frame data' dropdown for
saving the rig, then try editing my copy of your import script (the one from the download thread)
and see what explodes first. That ought to keep me from posting silly messages for a little while.
:lol:
lenglel
5th Feb 2011, 07:08 AM
orangemittens: you can get all the rigfiles you could ever want from fullbuild0.
Just use s3pe to sort by tag, select _RIG resources and export to a directory.
To find the auRig sort the directory by size, it'll be at or near the end as it's
one of the largest rig files. Then move or copy it to your project directory.
Get a clip file pretty much the same way. Loading fullbuild0 and exporting
the files takes a while, but if you do it right you only have to do it once.
I've decomposed all the fullbuild and deltabuild files, plus the jazzdata
package so now I've got a nice subdirectory tree with resources
sorted by type. Try it, you'll like it. :D
orangemittens
5th Feb 2011, 07:51 AM
Thank you Lenglel...I know where the rigs are...I was looking to get Blender versions of them :)
rothn
5th Feb 2011, 06:12 PM
Lenglel, hear this:
Download the Granny Crowd Scene Demo, install it, and copy granny2.dll from the Granny Crowd Scene Demo directory in Program Files to the directory that contains TS3 Animator.exe
This is the first instruction on the Overview page of the "Sims 3 Animator" thread.
By the way, the checkboxes don't matter. They are no longer attached to actual properties.
rothn
5th Feb 2011, 07:22 PM
Here is the C# code that writes the animation:
bw.Write((byte)'A');
bw.Write((byte)'N');
bw.Write((byte)'I');
bw.Write((byte)'M');
bw.Write((byte)'A');
bw.Write((byte)'T');
bw.Write((byte)'O');
bw.Write((byte)'R');
bw.Write(2);
bw.Write((byte)'_');
bw.Write((byte)'R');
bw.Write((byte)'I');
bw.Write((byte)'G');
bw.Write(thisAnimation.ourRig.SkeletonName);
bw.Write(thisAnimation.ourRig.numBones);
recurseThroughRig(thisAnimation.ourRig.Root, ref bw, new float[4,4] {{1.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 1.0f}});
bw.Write((byte)'A');
bw.Write((byte)'N');
bw.Write((byte)'I');
bw.Write((byte)'M');
bw.Write(thisAnimation.animationName);
bw.Write(thisAnimation.joints.Count);
foreach (ClipSupportFunctions.clipAnimation.jointDefinition jd in thisAnimation.joints)
{
bw.Write(jd.jointName);
bw.Write(jd.transFrames.Count);
bw.Write(jd.rotFrames.Count);
tempTransFrame[] translationFrames = new tempTransFrame[jd.transFrames.Count];
tempTransFrame[] rotationFrames = new tempTransFrame[jd.rotFrames.Count];
float[] currentTranslation = { -jd.position[0], -jd.position[1], -jd.position[2] };
int i = 0;
foreach (ClipSupportFunctions.frameData fd in jd.transFrames)
{
translationFrames[i].frame = fd.frame_index;
float[] relativeTranslation = (float[])fd.typeDependent.ToArray(typeof(float));
currentTranslation = translationFrames[i++].transformation = new float[3] { relativeTranslation[0] + currentTranslation[0], relativeTranslation[1] + currentTranslation[1], relativeTranslation[2] + currentTranslation[2] };
}
i = 0;
//float[] currentRotation = new float[4] { 0.0f, 0.0f, 0.0f, 1.0f };
float[] currentRotation = jd.quaternion;
foreach (ClipSupportFunctions.frameData fd in jd.rotFrames)
{
rotationFrames[i].frame = fd.frame_index;
float[] quat = ((float[])fd.typeDependent.ToArray(typeof(float)));
float[,] mat = quatToMat(quat);
mat = new float[,] { { mat[0, 0], mat[0, 1], mat[0, 2], 0.0f }, { mat[1, 0], mat[1, 1], mat[1, 2], 0.0f }, { mat[2, 0], mat[2, 1], mat[2, 2], 0.0f }, { 0.0f, 0.0f, 0.0f, 1.0f } };
//mat = matrixMult(mat, new float[4, 4] { { 1.0f, 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f, 1.0f } });
//mat = matrixMult(mat, new float[4, 4] { { -1.0f, 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, -1.0f, 0.0f }, { 0.0f, 0.0f, 0.0f, 1.0f } });
float[] newMat = new float[] { mat[0, 0], mat[0, 1], mat[0, 2], 0.0f, mat[1, 0], mat[1, 1], mat[1, 2], 0.0f, mat[2, 0], mat[2, 1], mat[2, 2], 0.0f, 0.0f, 0.0f, 0.0f, 1.0f };
float[] newQuat = MatToQuat(newMat);
rotationFrames[i++].transformation = multQuats(currentRotation, newQuat);
}
for (i = 0; i < 3; i++) // First the X channel, then the Y channel, then the Z channel
{
foreach (tempTransFrame fd in translationFrames)
{
bw.Write((float)fd.frame);
bw.Write((float)fd.transformation[i]);
}
}
for (i = 0; i < 4; i++) // First the the i channel, then the j channel, then the k channel, then the W channel
{
foreach (tempTransFrame fd in rotationFrames)
{
bw.Write((float)fd.frame);
bw.Write((float)fd.transformation[i]);
}
}
}
rothn
5th Feb 2011, 07:22 PM
What's wrong ?!!!!
lenglel
6th Feb 2011, 07:32 AM
orangemittens: you get the blender version of the rig from loading the rig in the
animator along with the clip, then exporting to .s3a
rothn: I've had the granny2.dll in the right places all along, so that's not it. I'm
not going to worry about for now. About the code you posted. I still have a
lot of python and blender stuff to learn, but my first guess would be that
one or another of the arrays is getting written in the wrong order. Sorry I
can't be more helpful right now.
orangemittens
6th Feb 2011, 03:05 PM
I know how to get em...but thank you anyway lenglel :)
rothn
6th Feb 2011, 06:13 PM
try this one
rothn
6th Feb 2011, 07:25 PM
If somebody feels confident enough to fix my code, I'll add a new dll file to the project that must contain a function that accepts an array of joints, each having an array of rotation and transformation frames and that returns that array of joints. I will call this function in the main program, and then export those things to Blender. Otherwise, I'm going to take a little (maybe a week or two) break from TS3 Animator and then come back to it fresh.
Inge Jones
6th Feb 2011, 08:12 PM
Have you had any further thoughts about making this open source?
rothn
8th Feb 2011, 01:20 AM
Are you saying that you would fix it yourself if I made TS3 Animator open source?
Inge Jones
8th Feb 2011, 09:40 AM
It would certainly invite the best brains to start looking at it - to make it a true community project led by yourself. It may not get fixed straight away but people could at least start trying to work out how to make it work.
rothn
8th Feb 2011, 11:07 PM
I know how to find out exactly what I should do.
I must:
Analyze Wes's code that takes a CLIP animation and converts it to an SMD file
Trace through the Blender SMD importer to figure out exactly what is then done with the SMD file
While stepping through these two programs, I will create a list of steps in Notepad, adding a step every time a transformation is made to a matrix. I will then take out any transformations I make to position / rotation data in my own code and replace it with the steps that I have gathered. There, no open source required. It's a tedious job, but somebody has to do it :lol: .
Inge Jones
9th Feb 2011, 07:16 AM
So why did you post a Help Wanted post if you want to do it yourself?
lenglel
9th Feb 2011, 08:15 AM
Because he wants help doing it himself?
I've read the python 3.13 tutorial http://docs.python.org/py3k/tutorial/index.html
and the blender plug-in tutorial http://en.wikibooks.org/wiki/Blender_3D:_Noob_to_Pro/Advanced_Tutorials/Python_Scripting/Introduction_New
and I'm tracing through the importer script. The bone transforms
look like they want to be unit transforms, or inverses thereof,
but if that's the case, they're out of order. I'm going to try
rearranging them and see what looks different. Just for
something to do.
Inge Jones
9th Feb 2011, 09:08 AM
Because he wants help doing it himself?
Then I was misled by the thread title. I thought he was asking for a Blender Plugin Creator to join his project.
lenglel
9th Feb 2011, 02:54 PM
Nope, he's the blender plug-in creator that needs help.
I found a good book for anyone interested in learning
blender:
http://en.wikibooks.org/wiki/Blender_3D:_Noob_to_Pro
rothn
9th Feb 2011, 11:45 PM
My problem isn't in getting the animations into Blender anymore. The problem is the math, and fixing the program now is merely grunt work.
orangemittens
10th Feb 2011, 03:04 AM
The math has been the problem all the way along, right from the first S3 animation tool, if you read the thread where that tool was introduced. Are you going to be able to work with it?
lenglel
10th Feb 2011, 12:04 PM
near line 145 in the python script, in the readRig method:
myRig = bpy.data.armatures.new(rigName+"Data");
added this->> myRig.draw_type='STICK'
ob_new = bpy.data.objects.new(rigName, myRig);
Makes the rig look like it did in milkshape.
I also loaded the meshes from the older version of the program
into milkshape and exported to obj, then imported to blender.
They almost fit, the arms are only slightly off. I think it's the
mesh that needs changed, not the rig.
OTOH, when I align view to front, I'm looking at the back of
the rig. Is that as it should be?
cmomoney
10th Feb 2011, 01:35 PM
near line 145 in the python script, in the readRig method:
myRig = bpy.data.armatures.new(rigName+"Data");
added this->> myRig.draw_type='STICK'
ob_new = bpy.data.objects.new(rigName, myRig);
Makes the rig look like it did in milkshape.
I mentioned that in post 17 (though I didn't say how to do it).
OTOH, when I align view to front, I'm looking at the back of
the rig. Is that as it should be?
No. The rig is facing the wrong way.
lenglel
11th Feb 2011, 05:45 AM
Your mention in post 17 is where I got the idea. It took me this
long to figure out how to change it :)
cmomoney
11th Feb 2011, 06:34 AM
Aww, I could have told you. But you probably had more fun figuring it out. ;)
lenglel
11th Feb 2011, 10:59 PM
Yup, I've gotta learn this stuff sometime, may as well be naaaow.
Found an even better tutorial link, more up-to-date.
http://gryllus.net/Blender/LearningUnits1_5.html
Theoretically it is possible to write a plug-in that
will read s3pe output files directly into blender,
given the formats in the wiki, an in-depth knowledge
of python and intimate understanding of the blender
api. This should keep me occupied for a while, as I've
only just browsed the wiki, know just enough python
to really bork things up and have about six more
chapters before I get to the api.
cmomoney
12th Feb 2011, 01:22 AM
I pm'd you some info, lenglel. :)
rothn
13th Feb 2011, 05:36 AM
OK, TS3 Animator now exports and imports SMD files. Yeah, I gave up on my own format. Please continue discussion in the main TS3 Animator thread.
vBulletin v3.0.14, Copyright ©2000-2013, Jelsoft Enterprises Ltd.