Reading external data files for animation
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 04/02/2006 at 23:37, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 9.012
Platform: Windows ;
Language(s) : C.O.F.F.E.E ; C++ ; XPRESSO ;---------
Assume we have an external ASCII data file consist of multiple lines. Each line correspond to an animation frame and contains postion (Xp,Yp,Zp) and rotation angles (Xr,Yr,Zr) for a 3D object.What I would like to do effectively is as follows
Create a scene in C4D Ver9.012(Win) with a 3D object
Open External data file
while (! End of file) {
// Read next data line for Position and rotation angles
Read next data line (Xp,Yp,Zp, Xr,Yr,Zr)
Move MyObject to Xp,Yp,Zp
Rotate MyObject by Xr,Yr,Zr
Render frame
}
Send a apprecition message to helper Cinema 4D gurusHow this can be implemented either in C.O.F.F.E.E., C++ or
any other mean ?Thx
Miem Chan
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 05/02/2006 at 09:10, xxxxxxxx wrote:
For C++, something like this (sketch) :
* Create a scene in C4D with a 3D object *
obj = BaseObject::Alloc(type);
document->InsertObject(obj);* Open External data file *
Either use C4D C++ SDK Filename and BaseFile classes or C/C++ standard methods classes.If you use Filename/BaseFile, you'll need to write your own ReadLine() function to read each character (until EOL character) and return the line.
There are two ways to apply affine transformations to the object: locally using SetPos() and SetRot() or via matrices. If your objects are in a hierarchy, you must consider whether or not the translation and rotation data is local (to parent coordinates) or global (world coordinates). Also, you will need to know what kind of rotations these are (Euler, HPB, ordered-XYZ, etc.). Finally, are these translations/rotations always from initial orientation or deltas from previous?
If the object will not have any parents, you can just use obj->SetPos(vector) and obj->SetRot(vector) to set the rotations. Personally, I would rather do it with matrices.
There are many ways to 'Render Frame'. Do you want to render each frame and save it to disk or as part of an animation? If you are attempting to end with an animation file, you'll need to set up tracks/sequences/keyframes with the data and then render the document with appropriate settings.
More details please.
Thanks,
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 08/02/2006 at 07:32, xxxxxxxx wrote:
Dear Robert,
Thank you for your reply.
The robot figure shown above is similar to one that i want to visualize in Cinema 4D. Starting from the main horizontal translation axis (blue) and followed rotational axis (red, green) up to last translation axis (blue) for the end effectors are all in a hirarchy.I think I used wrong terminology by saying "Render Frame", what I want at the end is not frame by frame rendered collection of images, but an *.avi file showing the robot's motion.
Thx
Miem Chan
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 08/02/2006 at 10:42, xxxxxxxx wrote:
1. Looks like you'll want to create a set of primitive objects (scaled cylinders and cubes). Either way, something like this is best animated as a set of objects in hierarchy rather than a single object (which would require bones and some form of weighting).
2. Opening and reading the data is rather simple. You can use simple C fileIO functions (fopen, fread, fscanf) to read the data:
Real Px,Py,Pz,Rx,Ry,Rz;
LONG frame = 0;
File* fp;
char buffer[BUFFER_SIZE];
char oname[64];
char* filename = "C:\MyFolder\data.txt";
if (!(fp = fopen(filename, "r"))) handleError();
while (fReadLine(fp, &buffer;[0]))
{
sscanf(&buffer;[0], "%s %f %f %f %f %f %f", &oname;[0], &Px;, &Py;, &Pz;, &Rx;, &Ry;, &Rz;);
// Call function to create tracks/seqs/keys on object for data
frame++;
}The problem here is how you intend to organize the data in the file. Since the data affects a set of objects, you must somehow specify which object is being modified by the pos/rot data at each frame. Maybe add a string identifier that matches the created object's name so that you can find it in the document.
Creating Tracks/Sequences/Keys is a little tricky. There is code for doing this in the plugins/cinema4dsdk folder. For something like this, a hierarchical animation, you may want to concatenate matrices (MatrixMove(), MatrixRotX(), MatrixRotY(), and MatrixRotZ()) and apply to the object (obj->SetMg(m) or obj->SetMl(m)), then use obj->GetPos() and obj->GetRot() to set the key values. Shouldn't need to advance to the frame since any object matrix settings should be nullified by the keyframes.
Rendering in C++ should be possible using RenderDocument(). You'll need to set up a RenderData structure which contains all of the render settings, such as file format and so on. Hopefully someone with experience in this can help as I have not used this before.