Polygonize the scene

On 02/12/2015 at 15:05, xxxxxxxx wrote:

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


I am trying to implement a renderer and i need to convert the whole hierarchy to polygons.
What i do right know is to traverse the hierarchy and make everything editable using MCOMMAND_MAKEEDITABLE.
That way i need to take care of the links (instance, Moinstance, Splire Wrapper , etc), because in some cases they break (depending on where they point to).
Even though it works, the way i have implemented it seems way too complex.

  1. Is there any better way to do this ?

Also, this procedure doesn't work for emitter that emit objects (e.g. spheres).
I have seen in the forum that GetDeformCache returns a polygonized object (if the cache is built previously with a Hierarchy subclass).
2) Is it safe to use insertObject to added to the document afterwards ?

Sometimes i cannot use the Hierarchy class to build the caches.
So i try to use the following code:
cache = object->GetCache();
deform_cache = cache->GetDeformCache();
After that i clone deform_cache and use InsertObject to add it to the document.
For primitives it works, but for clones it doesn't (GetDeformCache returns NULL).
3) How can i get the deform cache without using Hierarchy class ?

My purpose is to polygonize the whole scene. 
4) Which is the best way to do it ?
Sorry if I am asking something obvious but my knowledge and experience in C4D C++ SDK is limited.

Thank you for your time.

On 02/12/2015 at 15:50, xxxxxxxx wrote:

2. Use it at each root object.
3. You will end up (still) with a hierarchy in many cases.  Your best recourse is to study the documentation on the process, experiment on the results that best match your expectations, and work your solutions to match those.  To the point, when using CSTO you may still end up with a hierarchy of Null objects and results (Polygon mesh object/Spline objects/etc.).
4. Implementing a renderer, I sincerely hope that you are using a copy of the scene/document.  Then you can have some leverage in manipulation.  Never alter the original scene/document.
5.  BaseDocument:Polygonize() returns a polygonized representation of the entire scene/document.

On 03/12/2015 at 00:05, xxxxxxxx wrote:


First of all thank you for your response.
The reason why i don't currentstatetoobject is because it doesn't handle properly the render instances.

Array (render instance ON)

If i use CSTO on the array, it will produce only the first cube as polygon, while with Make Editable command on the cube and then on the Array, i will get :

     Cube as Polygon

which I think is the correct result.

Thank you.

On 03/12/2015 at 01:18, xxxxxxxx wrote:


please notice that the cache returned by GetCache() or GetDeformCache() does not necessarily contain only polygon objects. It can also contain generator objects with their own cache. You would have to browse trough the hierarchy of the cache objects to get all polygon data. This is shown in the documentation of GetCache().

Best wishes,

On 05/12/2015 at 00:27, xxxxxxxx wrote:

Hello !

Isn't it necessary to build the cache prior of getting it (via GetCache and GetDeformCache).
If any object (e.g. hair) doesn't have built cache, how do i build it for a specific frame ?

Thank you.

On 07/12/2015 at 02:22, xxxxxxxx wrote:


if you want to make sure the scene is build you can call ExecutePasses() on the given document.

Best wishes,