// Poser Animation Import Suite (PAIS) - "Part 3" // http://www.elderwyn.com/films/PAIS/index.html // This expression automatically creates morph target keys. // The number of keys created ranges from const var START_KEY=0, /* to */ END_KEY=299; // The morph track and sequence are created automatically by the expression. // If one already exists, that doesn't matter, this will just create another one! // To activate this expression, rename the object to this name with an underscore in front. // If the expression is successful, the object will automatically be renamed // to remove the underscore ... which stops the expression running over and over again. const var OBJECT="Man"; // Each new morph target key is given the following name ... const var MTNAME="AnimTest"; // plus the frame number, eg Target32 // so naturally your morph target objects must have these names also // Written by Gwydion Elderwyn ... Gwydion@Elderwyn.com // 23rd November 2000. // Released into the public domain. // Do what you want with it except sell it. main(doc,op) { // Find the object the user has specified var obj=doc->FindObject("_"+OBJECT); if (!obj) { println("Can't find the object"); return; } // Get document frame rate var fps=doc->GetFps(); if (!fps) { println("Can't retrieve the frame rate of the document"); return; } // Create a new morph track var mt=new(MorphTrack); if (!mt) { println("Can't create a new morph track"); return; } // Create a new sequence var seq=new(MorphSequence); if (!seq) { println("Can't create a new sequence"); return; } // Create time keys for the start and end of the sequence var start=new(BaseTime); if (!start) { println("Couldn't allocate a start time"); return; } start->SetFrame(START_KEY,fps); var end=new(BaseTime); if (!end) { println("Couldn't allocate an end time"); return; } end->SetFrame(END_KEY,fps); // and use them to set the length of the sequence seq->SetT1(start); seq->SetT2(end); // Insert the sequence into the track if ( !(mt->InsertSequence(seq)) ) { println("Couldn't insert sequence into track"); return; } // And insert the track into the object if ( !(obj->InsertTrack(mt,NULL)) ) { println("Couldn't insert track into object"); return; } // Here's the loop where we create the keys :-) var n; for (n=START_KEY; n<=END_KEY; n++) { // Create a new morphkey var mk=new(MorphKey); if (!mk) { println("Couldn't get a new morph key"); return; } // Create a time object and set the time into it var t=new(BaseTime); if (!t) { println("Couldn't create a time object"); return; } t->SetFrame(n,fps); // Get a container and put the target name into it var c=new(BaseContainer); if (!c) { println("Couldn't get a base container"); return; } c=mk->GetContainer(); c->SetData(MORPHKEY_NAME,MTNAME+tostring(n)); // Put the values back into our new MorphKey mk->SetTime(t); mk->SetContainer(c); // Now insert the morph key if ( !(seq->InsertKey(mk)) ) { println("Couldn't insert the Morph Target Key '"+MTNAME+tostring(n)+"'"); return; } } // We're done, remember it by removing the underscore from the name. obj->SetName(OBJECT); println("Morph keys set successfully, object name changed."); }