Game Development Community

dev|Pro Game Development Curriculum

DTS with Morphs

by David Mathews · 08/12/2005 (5:42 pm) · 34 comments

Download Code File

For a game I'm building, I wanted to use morphs for some of the character animations. But instead of the vertex animation (which makes huge file) I wanted to predefine a morph by just those points I needed to move and then control them with a float value on each frame, 0.0 being no morph applied and 1.0 being fully applied, with values greater than one and negative allowed.

My implementation defines morphs for detail level 0 only, assuming farther away they will not be visible and to keep the runtime impact down. Morphs are much faster then bone animation, but every little bit is important.

As you can see in the DTS shape.h and mesh.h files, I added morph controls to the shape and sequence definition and morph data to the mesh definition. I added it to the base mesh in the engine, so you can use morphs on both skinned and standard meshes (boned and unboned).

In the engine, morphs are only applied if the current frame value is not 0.0. If 0.0, the morph processing is skipped.

All the places I made changes in the files (there are a lot) are marked with my initials - DSM, so you can find them easily. Code changes are only in the ts engine folder and DTSsdk folder.

Since the coding is done for both the engine and the exporter library, hopefully this will make it into TGE 1.4 and TSE (I'd be happy to put it in either of those guys, if desired - I have a TSE copy also).

I have tested some simple human models with morphs and I'm now building my game models that will use several morphs each.

Code Example for loading a morphs in an exporter:

In the Mesh loader -
// set dummy entries for morphs - setting local morph to shape morphs to be the same (same as for bones)

for(i=0;i M->morphIndex.push_back(i);
}

// push morph data
for(i=0;i for(j=0;jused;j++){ // for each vertex referened by this morph (only verts affected by this morph - you do NOT need to use them all!!
int curPt = mlist[i]->offsets[j].ptindex; // getting vert index

M->mindex.push_back(i); // which morph
M->mvindex.push_back(curPt); // which mesh vert index
M->mverts.push_back(DTS::Point(mlist[i]->offsets[j].offset.x * Scale,-mlist[i]->offsets[j].offset.z * Scale,
mlist[i]->offsets[j].offset.y * Scale)); // morph offset at setting 1.0

}
}

IN the shape loader - I do after materials and before nodes

// Load list of morphs

DTS::Morph mp;

mlist = curmesh->GetMorphList();
mcount = curmesh->GetMorphCount();
for(i=0;i mp.name = addName(mlist[i]->name) ;
morphs.push_back (mp) ;
morphDefSettings.push_back (mlist[i]->value) ; // can be just 0.0
}

Added to sequence set up- I do during bone export, so I only set them up when processing bone zero

s.baseTranslation = nodeTranslations.size() ;
s.baseRotation = nodeRotations.size();
s.baseMorph = morphSettings.size();


s.matters.morphs.assign (mcount, false);

for (i = 0 ; i < mcount ; i++)
{
s.matters.morphs[i] = true;
}


for (i = 0 ; i < bcount ; i++){
for (j = startSeq ; j <= endSeq ; j++){
if(i == 0){ //set morph settings only for bone zero (will be the same for all bones)
for (k = 0 ; k < mcount ; k++) // for each morph
{
morphSettings.push_back(mlist[k]->value); // morph setting for this frame
}
}

That's all the code I added to my ToolBox DTS exporter to support morphs (based on the milkshape exporter example).

Why morphs? They are faster than bones, they can simulate hard to do dynamics (I use them to animate hair and cloth for one) as well as the usual morph tricks - face animation, talking, changing from one critter to another, pulsing objects.

Have fun with morphs!

This is my first contribution to Torque. I'm building a game using just my ToolBox app (my pet project) and Photoshop in addition to TGE. This is making me add all the parts I find missing - like I just added a texture resize function, as my textures are always an invalid size.
The new map2dif got past a lot of dif export problems I was having. I can finally export all the special node and light types and just added the path nodes so I can pre set them up in ToolBox.

About the author

Recent Blogs

Page«First 1 2 Next»
#21
05/30/2006 (9:38 pm)
This has been on my radar for a while and is something that I plan on adding to the new 3ds Max exporter shortly after its initial release.
#22
05/30/2006 (10:16 pm)
I think it would be a fantastic thing all around; personally I have zero time to put into it. (Working on Atlas, TDN, Other New Stuff, and some Secret Projects too, class on the side, also have to move both office and home this month!)

Definitely good to coordinate with the exporter guys on this. :)
#23
06/29/2006 (11:24 am)
I'm really looking forward to seeing this in TSE as well as the Maya Exporter. Hope you're still interested in implementing these. It will sure make the difference for realistic looking deformations, expressive characters, or choosing any body shape. These are the sort of shared community developments that make the Torque products so valuable for the price!
#24
08/31/2006 (5:36 am)
I compiled this code to tge 1.4...
And i am not undestand how to use it after i export model with morph ... what scripts commands should i use ??
If it is not to hard can someone post some examples on resource topic...
#25
11/13/2006 (12:37 pm)
As Ilya said, does anyone have anymore information about setting up morph targets?
#26
08/29/2007 (6:15 pm)
What happend to this is it in the current exporters? Especially the maya one.
#27
09/06/2007 (12:20 pm)
Interesting I will keep watch and add input as I come accross it.
#29
10/08/2007 (11:44 am)
I am interested in using this as well, by the looks of it I need to integrate it with a DTS exporter though. Does any 3dsMax DTS exporter support this currently? Any help would be appreciated.
#30
04/16/2008 (7:27 am)
is it too difficult to port this to TGEA?
i am very interested in using poser as animation tool and export it for torque dsq using ToolBox.
has anybody tried this?
#31
04/16/2008 (7:36 am)
The last time i talk to David the creator of toolbox he was trying to add these features in TGEA 1.7.

So i'm with you, hope he can get this code to work.
#32
06/25/2008 (12:19 am)
Is this currently a part of tge 1.5.2? Has anyone supported this in any of the exporters? If not, I can add it to the maya exporter.
#33
06/25/2008 (6:24 am)
that would be sweet. if we can use it with bones too
#34
03/21/2010 (10:16 pm)
Necro BUMP.
Page«First 1 2 Next»