Get data about moving objects in c4d file
-
Here is a file in C4D format, and the object in the file is motion, and I want to get the pose of each frame in motion, or I want to read the data of key frames in the file, as shown in the figure
What should I do?
-
Hi,
Just to be sure, you want to use Cineware and read that file from another software than Cinema 4D?
Cheers,
Manuel -
Hi
I wanted to use the Cineware SDK, but could not find the relevant information!
Thank you! -
hi,
This is like retrieving the information from a document inside cinema4D. You need to get the CTrack first, fromt that CTrack you can retrieve the CCurve and retrieve the values from CCurve.To retrieve the information, you will need to understand the concept of DescID, check our manual about them. You can read our manual about CTrack You will find interesting manual about animation at this page
const char* fn = "cube_anim.c4d"; auto ExitError = [](const String& msg ) -> int { printf("error : %s", msg); char value; printf("\n <press return to exit>"); scanf("%c", &value); return 0; }; // check if the file exists if (!GeFExist(fn)) ExitError("\n file do not exist\n aborting..."); // in this document, i've got the first object that is a cube with several tracks with an animation of the cube moving along the Z axis. BaseDocument* doc = LoadDocument(fn, SCENEFILTER_MATERIALS | SCENEFILTER_OBJECTS); if (!doc) ExitError("no document found"); BaseObject* cube = doc->GetFirstObject(); if (!cube) ExitError("no object found found");; // To retrieve the position.z track we need to define its DescID DescID trackID = DescID(DescLevel(ID_BASEOBJECT_REL_POSITION, DTYPE_VECTOR, 0), DescLevel(VECTOR_Z, DTYPE_REAL, 0)); CTrack* cubeTrack = cube->FindCTrack(trackID); if (!cubeTrack) ExitError("no track found");; // Get the curve of that track CCurve* curve = cubeTrack->GetCurve(); if (!curve) ExitError("no curve found"); const Int32 docFPS = doc->GetFps(); for (Int32 frame = 0; frame < 30; frame++) { const BaseTime timeToSample = BaseTime(frame, docFPS); doc->SetTime(timeToSample); doc->Execute(); const Float value = curve->GetValue(timeToSample); printf("value at this frame : %i value %i\n", frame, value); } // display all values of all tracks for (Int32 frame = 0; frame < 30; frame++) { // define the document's time and execute so everything update correctly. const BaseTime timeToSample = BaseTime(frame, docFPS); doc->SetTime(timeToSample); doc->Execute(); // Retrieve the first track CTrack* track = cube->GetFirstCTrack(); while (track) { CCurve* trackCurve = track->GetCurve(); if (!trackCurve) continue; const Float value = trackCurve->GetValue(timeToSample); // display the name of the track and the value sampled. printf("value of track %s at this frame : %i value %i\n", track->GetName().GetCStringCopy(STRINGENCODING::STRINGENCODING_8BIT), frame, value); track = track->GetNext(); } } // to keep the console window open wait here for input char value; printf("\n <press return to exit>"); scanf("%c", &value);
Cheers,
Manuel -
Hello @tsj_JNU,
without any further questions we will consider this topic as solved by Friday, December the 17th.
Thank you for your understanding,
Ferdinand