Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Animating whole document from C++ plugin [SOLVED]

    SDK Help
    0
    3
    330
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      On 23/02/2014 at 14:10, xxxxxxxx wrote:

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

      ---------
      Hi plugincafe-community,

      I am writing a plugin that should fulfill the following task:
      * Analyze the whole document and search for polygon-objects, cameras and lights
      * Write some useful information that I need about the objects to a file

      What I have so far:
      * Command plugin with a nice GUI that has an export button
      * Iterates the whole document, finds the required objects, and exports meaningful values
      * Plugin computes frame times and does the analysis for each frame (and here comes the problem!)

      In a test scene I have a cloth simulation, a moving camera and a deformer. When I hit "Play" in Cinema4d everything animates just fine. When i hit the "Pause" button, I can run my plugin and everything works just great. All deformations of the mesh (vertex positions, normals,...) all camera settings (positions, orientation, fov,...) are in the correct state.

      But I want to do the simulation/animation from my plugin. So my plugin should step to the next frame and get a valid state of the whole document. Then it should export all required data as before.

      I use the following code to simulate/animate the document from code:

      BaseObject* pObject = m_pDocument->GetFirstObject();
      while( pObject != nullptr )
      {
      m_pDocument->SetTime( BaseTime( time ) );
      m_pDocument->AnimateObject( pObject, BaseTime( time ), ANIMATEFLAGS::ANIMATEFLAGS_0);
      pObject = Utility::crawlScene( pObject );
      }

      time... computed value for the current time of a frame
      Utility::crawlScene... function that returns the next child or sibling or nullptr

      The strange thing is that the field of view of my camera is animated just fine as well as the position changes of a light source. But my camera matrix (Mg), the changes caused by a deformer and a simple cloth-simulation are ignored.

      Maybe I am using the wrong plugin type? My goal is to write some sort of exporter for Cinema4d and therefore I need the valid states for each frame.

      I could guess that the physics is a problem, because I have to simulate this separately. But where is the problem with the deformers and the simple matrix (Mg) of my camera?

      Thanks for your help!

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        On 23/02/2014 at 23:58, xxxxxxxx wrote:

        Rather then animating each object in turn, why not try BaseDocument::ExecutePasses(), which animates the current frame of the document. Then all you need to do is move to each frame in turn, call ExecutePasses() (and maybe EventAdd() as shown in the SDK docs), do your export, and move to the next frmae.

        I don't know if this would work but it seems more logical to do it this way.

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          On 24/02/2014 at 10:01, xxxxxxxx wrote:

          Hi spedler,

          thank you so much! Everything works great now.

          BTW: My camera didn't move because I called GetMg() on the wrong object:

          BaseDraw* pBaseDraw = m_pDocument->GetRenderBaseDraw();
          BaseObject* pCamera = pBaseDraw->GetSceneCamera( m_pDocument ); // type == Ocamera

          // Matrix viewMatrix = pBaseDraw ->GetMg(); // I used this code, which is wrong!
          Matrix viewMatrix = pCamera->GetMg();

          1 Reply Last reply Reply Quote 0
          • First post
            Last post