AnimateDocument -> Expressions



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 11/11/2008 at 11:08, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   R10+ 
    Platform:   Windows  ;   
    Language(s) :     C++  ;

    ---------
    I'm implementing a sequenced .obj file export in my Riptide Pro plugin and just got the basic/framework implementation working last night.  Here is a code-snippet:

        
        
          
        ------ S N I P -----
        
        
        
        
        //----------------------------------------------------------------  
        // Next, we're going to need a path to save the files to...  
        //----------------------------------------------------------------  
        String tStr = String("Select Export Path");
        
        
        if( !m_rootPath.FileSelect(FSTYPE_ANYTHING,GE_DIRECTORY,&tStr) )  
            return;  
        EventAdd();
        
        
        
        
        //----------------------------------------------------------------  
        // ok, now we need to:  
        // - loop through the frames  
        // --- animate the document  
        // --- polygonize it for that frame  
        // --- export a file  
        // --- free the polygonized doc  
        //----------------------------------------------------------------
        
        
        LONG i;  
        LONG startf = m_XpOpts.XpStartFrame();  
        LONG endf = m_XpOpts.XpEndFrame();  
        LONG fps = m_XpOpts.XpFps();  
        BaseDocument *pRealDoc = GetActiveDocument();  
        if( !pRealDoc ) break;
        
        
        
        
        m_fileSeq = m_XpOpts.XpSequenceStart();  
        for(i=startf; i<endf; i++)  
        {  
            //----------------------------------------------------------------  
            // animate the document to the next frame  
            //----------------------------------------------------------------  
            BaseTime stime = BaseTime::BaseTime(i, fps);  
            pRealDoc->SetTime(stime);  
            pRealDoc->AnimateDocument(NULL, **TRUE** , **TRUE** );  
            EventAdd();
        
        
        
        
            //----------------------------------------------------------------  
            // polygonize the document, keeping animations  
            //----------------------------------------------------------------  
            m_baseDoc = pRealDoc->Polygonize( **true** );  
            if( !m_baseDoc ) break;  
            if( !PrepFileName() ) break;  
            if( !BeginOBJFile() ) break;
        
        
        
        
            //----------------------------------------------------------------  
            // get element count for progress bar updates  
            //----------------------------------------------------------------  
            m_elements = 0;  
            CountSceneElements(m_baseDoc->GetFirstObject(), true, 0);
        
        
        
        
            //----------------------------------------------------------------  
            // Call the tree-walker routine to get the export underway...  
            //----------------------------------------------------------------  
            m_rootPath.CopyTo(&fPath);  
            WriteObjects(m_baseDoc->GetFirstObject(),Matrix(), true, 0, NULL, NULL, fPath);
        
        
        
        
            //----------------------------------------------------------------  
            // clean up and prep for next frame  
            //----------------------------------------------------------------  
            EndOBJFile();  
            BaseDocument::Free(m_baseDoc); m_baseDoc = NULL;  
            m_fileSeq++;  
        }
        
        
        
        
        ------ S N I P -----
    

    ...ok, so far, so good - the document animates as intended and files are saved out fine...
    Exception:  Expressions are not being evaluated.
    I have a sample scene that has an Xresso tag that drives the position of one of the objects and while the Bend deformer in the scene is working fine (animating and affecting the mesh), the Xpresso expression is not being evaluated like it does if I just scrub the timeline by hand or hit play.
    Any ideas?  Is this an issue wth doc->Polygonize(true) ?  Or an issue with doc->AnimateDocument(NULL, true, true) ?
    Thanks,
    Keith



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 11/11/2008 at 11:51, xxxxxxxx wrote:

    Everything looks correct and 'doexpressions' should cover Xpresso (?). I haven't dealt with it in this situation myself. In what position is your Xpresso tag on the object? Though, it does sound like you are getting the result in the Editor. Have you tried a render (to Picture) to see if it evaluates there as well?



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 11/11/2008 at 11:59, xxxxxxxx wrote:

    Ok, I found the problem... it's what appears to be a bug (?) in doc->Polygonize().
    Take a look at this image:

    ...see that Null object named "Top-Target"?  It's referenced by the Target Tag on "Top-Null", and is affected by the Xpresso tag, but since it doesn't have anything attached to it, the call to doc->Polygonize() removes it from the scene entirely.
    This leaves the Target tag and Xpresso tag referencing nothing - which I would consider a bug :).
    To fix this, I put a (non-visible) cube object in the scene as a child of the "Top-Target" null and it's working fine now (doc->Polygonize() is forced to leave it in the scene).
    Cheers,
    Keith



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 11/11/2008 at 12:11, xxxxxxxx wrote:

    BTW, for the curious, that scene was created following this: http://www.base80.com/index.php/2006/04/04/follow_bend_deformer#more134
    ...as just something simple for me to test animation-export with.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 11/11/2008 at 12:30, xxxxxxxx wrote:

    You would think that all transformations (including animation, expressions, Xpresso) would be considered before Polygonize() actually polygonizes, huh?

    I'd mention this to Maxon.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 12/11/2008 at 02:00, xxxxxxxx wrote:

    Please attach the scene, thanks.

    cheers,
    Matthias



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 12/11/2008 at 06:31, xxxxxxxx wrote:

    Here you go: Link
    (keep in mind that I suck at animations :) - just no experience with them yet)



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 12/11/2008 at 06:54, xxxxxxxx wrote:

    ...btw, to find the problem, I just altered my code above from this:

        
        
          
        /* -- S N I P -- */  
            //----------------------------------------------------------------  
            // clean up and prep for next frame  
            //----------------------------------------------------------------  
            EndOBJFile();  
            BaseDocument::Free(m_baseDoc); m_baseDoc = NULL;  
            m_fileSeq++;  
        /* -- S N I P -- */  
        
    

    ...to this:

        
        
          
        /* -- S N I P -- */  
            //----------------------------------------------------------------  
            // clean up and prep for next frame  
            //----------------------------------------------------------------  
            EndOBJFile();  
            if( i == 20 )  InsertBaseDocument(m_baseDoc);  
            else BaseDocument::Free(m_baseDoc);  
            m_baseDoc = NULL;  
            m_fileSeq++;  
        /* -- S N I P -- */  
        
    

    ...so the code added frame 20 as a new document, so I could see what it looked like.  At that point, I could see that the "Top-Target" null object was missing and that the links to it were broken.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 12/11/2008 at 07:51, xxxxxxxx wrote:

    Hmm... it broke again... (even with the hidden cube there).  Still investigating.
    ...I guess that was just not a reliable 'fix'.  Even with the invisible cube there to keep the Null around, the expression is not being evaluated (the Xpresso tag and Target tag are still correctly referencing the "Top-Target" null, but it's just not affecting the sphere object like it should be).



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 12/11/2008 at 08:09, xxxxxxxx wrote:

    BTW, just to be clear, this is a R10.1 SDK compiled plugin, but being used in R10.5



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 12/11/2008 at 08:18, xxxxxxxx wrote:

    ...seems to be an issue related to the 'Priority' of the Xpresso and Target tags...  I was following that guide link I posted above and changed the priorities to "Generators" 1 and 2, but I get different results if I reset them back to "Expression" 0 and 10 priorities (thier defaults).  But I still need the hidden cube to keep the Top-Target null around.
    EDIT: sorry, I may have spoke too soon... the results just kind of seem to be random - even with the "Expression" priorities, I'm back where I started - sometimes it kinda works (maybe off by a frame) and sometimes the sphere doesn't move at all.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 13/11/2008 at 02:08, xxxxxxxx wrote:

    It seems you have to use Polygonize(FALSE). This code works fine for me with your attached example scene.

    > \> Bool MenuTest::Execute(BaseDocument \*doc) \> { \>      StopAllThreads(); \> \>      Filename fdir; \>      if(!fdir.FileSelect(FSTYPE_ANYTHING, GE_DIRECTORY, "Select Directory")) return TRUE; \> \>      Real fps = doc->GetFps(); \>      LONG i, frames = doc->GetMaxTime().GetFrame(fps); \> \>      for(i=0; i<frames; i++) \>      { \>           StopAllThreads(); \> \>           Filename fn("frame"+LongToString(i)); \>           fn.SetDirectory(fdir); \>           fn.SetSuffix("obj"); \>           GePrint(fn.GetString()); \> \>           doc->SetTime(BaseTime(i,fps)); \>           doc->AnimateDocument(NULL, TRUE, TRUE); \>           EventAdd(); \>           DrawViews(DA_FORCEFULLREDRAW, NULL); \> \>           BaseDocument \*pdoc = NULL; \>           pdoc = doc->Polygonize(FALSE); \>           if(!pdoc) return FALSE; \> \>           if(!SaveDocument(pdoc, fn, SAVEFLAG_DONTADDTORECENTLIST, FORMAT_OBJEXPORT)) \>           { \>                BaseDocument::Free(pdoc); \>                return FALSE; \>           } \> \>           BaseDocument::Free(pdoc); \>      } \> \>      return TRUE; \> } \>

    cheers,
    Matthias



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 13/11/2008 at 06:21, xxxxxxxx wrote:

    How odd - but... whatever works - thanks Matthias!
    That DrawViews() helps a lot too ;).



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 15/11/2008 at 08:26, xxxxxxxx wrote:

    A final question about this... does anyone know how I might add some sort of "Abort" checking in that loop?
    I see that the Thread class has a thread->TestDBreak() that could be overloaded (to check for ESC pressed, for example), but I'm not using my own thread.
    I tried adding a non-modal 'Progress' type dialog with a Cancel button on it, but that dialog's Command() routine never gets called (I'm assuming this has to do with the StopAllThreads() being called repeatedly).
    Is there some system call that will allow me to give up the cpu long enough to check for events or some other way of letting the user hit ESC or click on some button to Abort the process? (writing out 400 .obj files and animating a complex scene for each of those 400 frames might take a long time).
    Any help or suggestions would be appreciated.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 15/11/2008 at 09:39, xxxxxxxx wrote:

    Update:
    I'm actually calling a routine in my non-modal dialog to set the current filename before opening each file for writing.  Since this is a good spot to 'abort' anyway, I've figured out that I can call GetInputEvent(BFM_INPUT_KEYBOARD, msg) from within that routine and check for ESC pressed there.  So far, so good.
    The issue I'm still having is that my 'Cancel' button is still not working (the dialog's Command() routine is never called) and I'm also having trouble with updating the dialog's display after changing values (setting the filename string in a Static Text gadget, for example).
    Since I've set an hour-glass cursor anyway, I may just get rid of the Cancel button and replace that with some text that says "Press ESC to Cancel", but I'd still like to get the dialog display updates working... is there some way to force it to redraw itself?



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 15/11/2008 at 10:41, xxxxxxxx wrote:

    ...nevermind... it seems that my problem is with trying to use a Static Text element as a Dynamic String element (the number of characters displayed is set in stone on creation), so it was not showing the new string.
    Now I just need to figure out which dialog element/gadget type to use (or initialize the Static Text with a longer string, or.. something).



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 15/11/2008 at 12:43, xxxxxxxx wrote:

    SetString() is the correct way for Static Text. I think you can set the display size using the width part of AddStaticText() - but you must set the value carefully (SizePix(), SizeChr(), etc. for best results).

    You need to call GeUserArea::Redraw().



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 15/11/2008 at 12:56, xxxxxxxx wrote:

    Thanks... I figured out my problem - not enough coffee ;).


Log in to reply