Non-destructive Triangulation
-
On 08/11/2016 at 13:16, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R18
Platform: Windows ;
Language(s) : C++ ;---------
Hello. SDK Newbie hereI'm working on a exporter and need to triangulate the polygons, but I don't want to destroy the polygon
object so I guess I must make a clone of the object and work on that. I found some functions that may
do that ? GetAndCheckHierarchyClone and GetHierarchyClone, but I don't really understand how to
use them. Can't find any example. Its the HierarchyHelp argument that I don't understand.So first of all. Is this the correct approach to do my triangulation before saving out the point-list and
secondly, is there any example on how to clone the polygon object (and its childs) around. I don't need to
clone any materials, just the polys -
On 09/11/2016 at 02:52, xxxxxxxx wrote:
Hi Roland,
welcome to the Plugin Café community
GetAndCheckHierarchyClone() and GetHierarchyClone() functions are the wrong approach. These functions are meant to be used in ObjectData plugins (e.g. in GetVirtualObjects()) and there C4D provides the HierarchyHelp object, which you usually don't have to worry about.
For more information on this topic, I recommend the BaseObject manual in the SDK docs, especially the Generating sub-chapter.
Now, in your case (most likely a SceneSaverData plugin) you have two options for the first step (getting the actual polygonal data).
a) Use SendModelingCommand() with MCOMMAND_MAKEEDITABLE. This is probably the easier solution
b) Get the cache(s) for the object in question, via GetCache() and GetDeformCache(). Please see the notes and the code snippets provided in the docs of these two functions for more information. Again also the BaseObject manual has a chapter about object caches.Second step is then the actual triangulation. Here SendModelingCommand() comes to help again, this time with MCOMMAND_TRIANGULATE.
On the question of cloning objects (doesn't matter if polygonal or not, if they have children or not, actually almost every entity in C4D), see C4DAtom::GetClone() function.
I hope, this helps to get you going.
-
On 09/11/2016 at 03:31, xxxxxxxx wrote:
Thank a lot Andreas. That worked just great!
Tested with this code on s simple cube and
got polycount=6 before triangulation and
polycount=12 after.--- CODE
// Create clone to work on
auto pclone = static_cast<PolygonObject*>(po->GetClone(COPYFLAGS_0, nullptr));
// Make it editable
ModelingCommandData cmd;
cmd.doc = _doc;
cmd.op = pclone;
if (!SendModelingCommand(MCOMMAND_MAKEEDITABLE, cmd))
{
return;
}
// debug: polygon count before triangulation
auto numpolys = pclone->GetPolygonCount();
// Triangulate
if (!SendModelingCommand(MCOMMAND_TRIANGULATE, cmd))
{
return;
}
// debug: polygon count after triangulation
numpolys = pclone->GetPolygonCount();Thanks a bunch !
Thumbs Up
[URL-REMOVED]****__~~~~
[URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.
-
On 09/11/2016 at 04:56, xxxxxxxx wrote:
Hi Roland,
glad I was able to help.
Just one note, you need to check the result of GetClone() for nullptr.
I'm getting picky on this, as we had some discussion in other threads lately. -
On 09/11/2016 at 05:01, xxxxxxxx wrote:
Yes I will certainly do that in the real exporter code. This was just a quick test of cloning and triangulation. I will now start building the exporter step by step. Will then test all return values for validity. Thanks again