# Anim8or Community

• July 17, 2018, 03:53:16 pm
• Welcome, Guest

### News:

An update to Anim8or, v1.00b, is available with a few bug fixes. Get your copy HERE. See the "ReadMe" file for details.

Pages: [1] 2

### AuthorTopic: SMD skeleton to an8 skeleton  (Read 7712 times)

#### Deepthought

• Full Member
• Posts: 157
##### SMD skeleton to an8 skeleton
« on: November 08, 2014, 07:44:59 pm »

I am writing a program to convert SMD files to an8.
The bones of an smd file are defined by a position and 3 euler angles in radians. I am using the following code to convert to an8

Code: [Select]
`smdbone sb=bones.get(x); Bone b = new Bone(); b.name=sb.name; b.length=new Vector3f(sb.x,sb.y,sb.z).length(); b.diameter=.2f;`
Quat4f orientation= new Quat4f();
Quat4f xrot=new Quat4f();
Quat4f yrot=new Quat4f();
Quat4f zrot=new Quat4f();

xrot.set(new AxisAngle4f(1,0,0,sb.rotx));
yrot.set(new AxisAngle4f(0,1,0,sb.roty));
zrot.set(new AxisAngle4f(0,0,1,sb.rotz));

orientation.set(xrot);
orientation.mul(yrot);// same as orientation=orientation*yrot
orientation.mul(zrot);

System.out.println("orientation "+orientation.x+" "+orientation.y+" "+orientation.z+" "+orientation.w);

b.orientation=(Quat4f) orientation.clone();[/code]
the output skeleton looks like a torture victim.
any ideas where i'm going wrong?
Logged

#### NickE

• Full Member
• Posts: 158
##### Re: SMD skeleton to an8 skeleton
« Reply #1 on: November 08, 2014, 09:31:42 pm »

I ran into the same sorts of problems when I was writing a BVH to Anim8or converter.  You need to know the reference frame for the SMD skeleton and rotate the SMD skeleton to the Anim8or reference frame right-handed (0,1,0).  The SMD reference frame is unclear, but seems to be left-handed (0,0,1).

Attached is the VB6 source code for the BVHtoAnim8or program.  To follow execution, look at cmd_sel_input_Click() and cmd_convert_Click().

NickE
Logged

#### Deepthought

• Full Member
• Posts: 157
##### Re: SMD skeleton to an8 skeleton
« Reply #2 on: November 08, 2014, 10:45:14 pm »

for SMD x is left, y is forward, z is up.
could you walk me through the math?
I'm still trying to make sense of that VB code
« Last Edit: November 08, 2014, 10:48:29 pm by Deepthought »
Logged

#### NickE

• Full Member
• Posts: 158
##### Re: SMD skeleton to an8 skeleton
« Reply #3 on: November 09, 2014, 01:37:19 pm »

Deepthought,

Is it your intention to (1) gain the experience and satisfaction of having written a converter for SMD files for Anim8or or (2) do you just want something that works?

If (1), then you need to gain a thorough understanding of the both the SMD file format(s) and reference frames and Anim8or's conventions for handling figures, sequences, and scenes.  The code in the BVH converter is not going to make sense unless you understand those concepts.  In a nutshell, the code reads and parses a BVH file, constructs an Anim8or figure, constructs a sequence for the non-positional movements, and then constructs a scene containing the figure and sequence so that position can be added.  In Anim8or, the figure's root bone is relative to the world coordinate system, but each child bone is relative to it's parent.  A cursory reading of the SMD format suggests the same arrangement (although it is not completely clear), but the world coordinate system is different from Anim8or's.

The math part essentially steps through the bones, rotates the bones into the reference frame, performs the relative rotation of child to parent, then rotates them back.

If (2), I'd be happy to help you out if you can be patient.  I would need some sample SMD's and either some viewer program or screenshots to see what the SMD file is supposed to look like.  My first guess is that the BVH conversion program can be easily adapted by writing a new parsing routine and other small changes.

NickE
Logged

#### Deepthought

• Full Member
• Posts: 157
##### Re: SMD skeleton to an8 skeleton
« Reply #4 on: November 09, 2014, 08:02:22 pm »

https://www.dropbox.com/s/tcufr4o27p9pze0/smd_package.zip?dl=0 contains a viewer and some decompiled SMDs

Right now I'm just trying to get some source models into anim8or. I already have code for parsing SMD files and for parsing and saving an8 files. the math for converting in between is what's giving me problems.
Logged

#### NickE

• Full Member
• Posts: 158
##### Re: SMD skeleton to an8 skeleton
« Reply #5 on: December 01, 2014, 03:30:43 pm »

Deepthought,

Attached is a program that will convert the SMD files you posted to an8 format.  I will only do the object and figure, since none of the files you posted contain animation.  I do not have any other SMD files to test with, so it may not work with other SMD files that vary in format, spacing, white spaces, etc.

Sorry this took so long.  Family medical problems have kept me far from home the last several weeks.  I'll post the source code when I get a chance to clean it up.

NickE
Logged

#### Deepthought

• Full Member
• Posts: 157
##### Re: SMD skeleton to an8 skeleton
« Reply #6 on: December 01, 2014, 11:47:52 pm »

that is NICE! looking forward to seeing how you did that
Logged

#### NickE

• Full Member
• Posts: 158
##### Re: SMD skeleton to an8 skeleton
« Reply #7 on: December 02, 2014, 08:31:50 pm »

I have attached a zip file containing the VB 2013 source code for the SMDtoAnim8or converter.  The previous executable I posted was written in VB6.  I did the minimum required to port it to VS 2013 VB and tested it to be sure it works.

The source code for the converter (especially the parsing routines) is very inefficient in VB.net terms given it is minimally changed from VB6.  There are nice parsing libraries available in VB.net, but I did not take the time to implement them.

VS 2013 Community version is free (takes forever to install) if you want to compile or modify it.

In this converter, unlike the BVH converter, the program calculates the joint offsets, then the figure's bone orientation from the offsets.  I implemented it this way since the SMD format is not in hierarchical format (unlike BVH), so the parent/child relationships are not known until all the bones are read.  It was easier to calculate the offsets first (in this case), then the orientation rather than the other way around.  The math concepts are the same.

I explained the difficulties in writing this kind of converter in http://www.anim8or.com/smf/index.php/topic,4861.msg36976.html#msg36976

NickE
Logged

#### Deepthought

• Full Member
• Posts: 157
##### Re: SMD skeleton to an8 skeleton
« Reply #8 on: December 03, 2014, 09:03:51 am »

huh, what's with the extra bones being added on the ends?
Logged

#### NickE

• Full Member
• Posts: 158
##### Re: SMD skeleton to an8 skeleton
« Reply #9 on: December 03, 2014, 02:05:46 pm »

In the SMD format, the skeleton is represented explicitly by joints (or the vertices between bones).  The "bones" in SMD format are implicit.  In AN8 format, the skeleton is represented explicitly by bones, and the joints are implicit.  To be able to map orientation, motion, and skinning from SMD to AN8, one must convert the explicit joints to explicit bones.  This requires that the implicit bone after the last joint in the SMD kinematic chain be formed explicitly in the AN8 kinematic chain.  If it is not done, there is no AN8 structure to carry the motion of the last SMD joint.

Dizzy yet?  Me too, just from writing that.  It is much easier to see in the picture.
Logged

#### Deepthought

• Full Member
• Posts: 157
##### Re: SMD skeleton to an8 skeleton
« Reply #10 on: December 03, 2014, 11:33:04 pm »

Well, this proves my "Source engine is evil" theory
Logged

#### Smirkyguy

• Newbie
• Posts: 21
##### Re: SMD skeleton to an8 skeleton
« Reply #11 on: December 29, 2014, 12:24:45 am »

Can you get this to work with all SMD formats? the files I tried it on came up with "type mismatch" errors.
Logged

#### NickE

• Full Member
• Posts: 158
##### Re: SMD skeleton to an8 skeleton
« Reply #12 on: December 29, 2014, 01:38:03 am »

Smirkyguy,
I do not have any other SMD example files to work from except the ones from Deepthough.  If you would post some files, I can try to alter the program to work with them.  The source code has been posted earlier, if you'd like to do it yourself.

NickE
Logged

#### Smirkyguy

• Newbie
• Posts: 21
##### Re: SMD skeleton to an8 skeleton
« Reply #13 on: December 29, 2014, 08:48:02 pm »

here are 3 samples, I hope they are good enough to work with
https://www.dropbox.com/s/xg0tc1bqui62zvn/TailsEV.SMD?dl=0
https://www.dropbox.com/s/9ufsbamdi8i2jzu/Tails.SMD?dl=0
https://www.dropbox.com/s/6cp6hj4xxo4t3ry/Eevee.SMD?dl=0

I don't know what program made these files, but I believe them to be from the same program.
« Last Edit: December 29, 2014, 08:49:07 pm by Smirkyguy »
Logged

#### NickE

• Full Member
• Posts: 158
##### Re: SMD skeleton to an8 skeleton
« Reply #14 on: December 29, 2014, 09:54:07 pm »

Smirkguy,

The attached zip file contains the SMD2Anim8or conversion executable.  It works with all three of the SMD files you gave links to.

NickE
Logged
Pages: [1] 2