Animating whole document from C++ plugin [SOLVED]
On 23/02/2014 at 14:10, xxxxxxxx wrote:
Cinema 4D Version: 15
Platform: Windows ;
Language(s) : C++ ;
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!
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.
On 24/02/2014 at 10:01, xxxxxxxx wrote:
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();