Export of Cloth to ASCII
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 06/02/2006 at 04:25, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 9.5
Platform: Mac ;
Language(s) : C.O.F.F.E.E ;---------
Hello,I'm right now struggling with an export of a Clothobject. I want to export all Points of the object for each frame of the animation to an ascii file.
I wanted to use an coffee expression to write the points of each frame to the file, but as I've read coffee expressions can't write files for security reasons.
Now I'm struggling with a coffee plugin. Can anyone please tell me how to advance the time frame by frame with a plugin?
Or is there another way to easily export the animation of an cloth object?
Thanks
Bernd -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 07/02/2006 at 03:49, xxxxxxxx wrote:
Hello Bernd,
there are some usefull script-commands making it easy to advance for example to timeposition of your scene to the next frame and then calculate each objects animation for that frame. After that you may grab the rotations and position of the object.
First you need to get the framerate of your document (i assume here that "doc" was assign to this document by var doc=GetActiveDocument(); for example)
var FramesPerSecond=doc->GetFps(); // Getting the framerate
Second you will need the number of frames in your document. You may retrieve this by
var MaxTime=doc->GetMaxTime(); // Getting animations length
This will return a BaseTime-Object. To get the Framenumber you need to retrieve it from the BaseTime-Object by passing the doc's framerate as parameter:
var MaxFrame = MaxTime->GetFrame(FramesPerSecond); // Getting last frame
Now you got the number of frames you have to iterate through.
"for (i=0;i<MaxFrame+1;i++) {..." // loop through frames
To set the documents timeposition from the framenumber inside the loop you will have to reconvert it to a BaseTime-Object's timedata:
var TimeNow=new(BaseTime);// create new BaseTime
TimeNow->SetFrame(i,FramesPerSecond);// Set new times frame
And afterward you must set the documents timeposition to that value:
doc->SetTime(TimeNow); // set documents time position
We are not done yet! To make every object being rotated and positioned according to this time position we will have to animate the document to that timepoint:
doc->AnimateDocument(ANIMATE_NO_PARTICLES);
(ANIMATE_NO_PARTICLES is one of several options you may use here to speed up the command a little by excluding parts of the scene from the animation by this value)
After this command, every object in your scene should have its rotation and position according to the timelines position.
You may now retrieve these values by obj->GetRotation() or
obj->GetPosition(); but you have to take care of course concerning local matrix and global matrix on your export.
I hope this will help you,
best wishes,
COFFEJUNKIE -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 07/02/2006 at 14:27, xxxxxxxx wrote:
Thanks for the answer! Works now!
Now I can start writing the files.Thanks
Bernd -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 07/02/2006 at 16:24, xxxxxxxx wrote:
OK, the part of generating files for each frame works, but it seems like I can't export the point information. I'm using:
var StoffObject = doc->FindObject("Stoff");
var Punkte = StoffObject->GetPointCount();
for (j=0; j <Punkte; j++)
{
file->WriteString(stradd(tostring(j), " ", tostring(StoffObject->GetPoint(j))));
}I get the same points for each frame. It works with other Values (like position).
I've already cached the cloth simulation.I get the right point values if I use export ascii file in the structure manages.
Anyone has an idea what to do?
Thanks for your help!
Bernd
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 07/02/2006 at 18:22, xxxxxxxx wrote:
Yes, you will get the same points for each frame.
The array returned by GetPoint() is the untransformed vertex array. You need to animate the document/object frame by frame and do this:
var mg; var pt; for (each frame) { AnimateObject(StoffObject, frame, 0); // Check flags in AnimateDocument() mg = StoffObject->GetMg(); for (each point j) { pt = mg * StoffObject->GetPoint(j); // write point to file } }
This gets the object's global matrix at the frame (after animating the object to that frame) and transforms the point respectively.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 08/02/2006 at 05:56, xxxxxxxx wrote:
Thanks for the answer. I now have AnimateDocument and AnimateObject, but it still doesn't work.
Seems to be a problem of the cloth simulation, because it works with Objects with a PLA.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 08/02/2006 at 10:50, xxxxxxxx wrote:
Hello Bernd,
I am not quite sure, but it is possible that you will need another optionflag in the AnimateDocument-command to garantuee the usage of PLA-animation in its execution. I was looking for an overview of these flags but I did not find a complete list so far. Another possibility could be to use SendModelingCommand to convert the actual mesh into a new polygonobject. In my german C4D the menu-command to do so calls "Aktuellen Zustand in Objekt wandeln" (sorry I do not no the correct english version of this text). This command will create a new Polygonobject from the actual state of the animated object at the frame's time. This object will have the translatet and rotated points.
Another possibility could be to manually calculate the point's positions and rotations via GetMulP commands. You setup new matrixes for translations and rotations and multiply every point with these to get the transformed point-coords.
One more tipp: If you do not access every point with Getpoint(.. but create a new array at the size of the point's array (var points=new(array, sizeof(StoffObject->GetPoints())); ),
you may grab all points with one command: points=StoffObject->GetPoints();
If you iterate through this array of vectors your process will speed up a lot.
(Maybe a small object hides the difference but if you take a mesh with more than 20000 points you will recognize a significant difference in performance of your plugin).
Have fun!
Best wishes,
COFFEJUNKIE