Hierarchy Class Referenceabstract

#include <c4d_basedocument.h>

Detailed Description

This class allows to perform some functions on all of the objects in a hierarchy.
Example:

struct ExampleStruct
{
Int32 parent_state;
};
class ExampleHierarchy : public Hierarchy
{
public:
virtual void *Alloc() { return NewObjPtr(ExampleStruct); }
virtual void Free(void *data) { ExampleStruct *es = (ExampleStruct*)data; DeleteObj(es); }
virtual void CopyTo(void *src, void *dst) { *((ExampleStruct*)dst) = *((ExampleStruct*)src); }
virtual Bool Do(void *data, BaseObject *op, const Matrix &mg, Bool controlobject);
};
Bool ExampleHierarchy::Do(void *data, BaseObject *op, const Matrix &mg, Bool controlobject)
{
ExampleStruct* dt = (ExampleStruct*)data;
Int32 mode = op->GetRenderMode();
if (mode != MODE_UNDEF) // if mode is MODE_ON or MODE_OFF
d->parent_state = mode;
// Important: Do this parent-data inheritance always, even if you do not evaluate an object
// Reason: A child of an invisible control object might be visible again...
if (controlobject)
return true; // This object is not visible, has been used by generator
if (op->GetType() != Opolygon)
return true; // We cannot use this
// Do something with polygonized object op
// The object has matrix mg and local data dt
return true;
}
Definition: c4d_baseobject.h:225
Definition: c4d_basedocument.h:1664
virtual void * Alloc()=0
virtual void Free(void *data)=0
virtual void CopyTo(void *src, void *dst)=0
virtual Bool Do(void *data, BaseObject *op, const Matrix &mg, Bool controlobject)=0
PyObject * src
Definition: abstract.h:305
const wchar_t * mode
Definition: fileutils.h:96
maxon::Bool Bool
Definition: ge_sys_math.h:55
maxon::Int32 Int32
Definition: ge_sys_math.h:60
#define MODE_UNDEF
The object is enabled by default, but the state of any parent object is used if it is enabled or disa...
Definition: c4d_baseobject.h:37
#define Opolygon
Polygon - PolygonObject.
Definition: ge_prepass.h:1032
#define DeleteObj(obj)
Definition: newobj.h:159
#define NewObjPtr(T,...)
Deprecated.
Definition: newobj.h:113
PyObject * op
Definition: object.h:520

Public Member Functions

virtual void * Alloc ()=0
 
virtual void Free (void *data)=0
 
virtual void CopyTo (void *src, void *dst)=0
 
virtual Bool Do (void *data, BaseObject *op, const Matrix &mg, Bool controlobject)=0
 
Bool Run (BaseDocument *doc, Bool spheres, Float lod, Bool uselod, BUILDFLAGS flags, void *startdata, BaseThread *bt)
 

Private Attributes

BaseDocumentdoc
 
BaseThreadbt
 

Member Function Documentation

◆ Alloc()

virtual void* Alloc ( )
pure virtual

Override the method to allocate the private data for a single level in the hierarchy.
Cinema 4D itself will pass the parent matrix but all other data that might be needed must be passed down the hierarchy using a private data structure and this is where it is allocated.

Returns
The private data that is allocated.

◆ Free()

virtual void Free ( void *  data)
pure virtual

Override the method so that the private data allocated in Alloc() can be freed.

Parameters
[in,out]dataThe private data to free.

◆ CopyTo()

virtual void CopyTo ( void *  src,
void *  dst 
)
pure virtual

Override the method so that the private data can be copied.

Parameters
[in]srcThe source private data to copy from.
[out]dstThe destination private data to copy to.

◆ Do()

virtual Bool Do ( void *  data,
BaseObject op,
const Matrix mg,
Bool  controlobject 
)
pure virtual

Override the method to be called for every object, virtual and non-virtual, in the hierarchy run.

Parameters
[in]dataThe private data allocated in Alloc().
[in]opThe object the function is being called for.
[in]mgThe global matrix for this object down the hierarchy chain.
[in]controlobjectIf true then the object has been used by a generator and usually will no longer be used (but the routine goes through all objects in any case).
Returns
true if the function was successful and the run through the hierarchy should continue, otherwise false.

◆ Run()

Bool Run ( BaseDocument doc,
Bool  spheres,
Float  lod,
Bool  uselod,
BUILDFLAGS  flags,
void *  startdata,
BaseThread bt 
)

Performs Do() on all objects (virtual and non-virtual) in the hierarchy.
Using this class will build all caches for dirty objects for the entire hierarchy, this can be time intensive and should be used carefully.
If a polygon object is needed it is generally faster to call SendModelingCommand() with MCOMMAND_CURRENTSTATETOOBJECT.

Parameters
[in]docThe document with the objects you want to process.
[in]spheresIf true the process will not polygonize perfect spheres.
[in]lodThe level of detail to use.
[in]uselodIf true the level of detail lod should be evaluated.
[in]flagsThe build flags are: BUILDFLAGS Note: Either BUILDFLAGS::INTERNALRENDERER or BUILDFLAGS::EXTERNALRENDERER must be set because some generators check for these flags and generate different results.
For example the Metaball object has different settings in the edit dialog for internal and external rendering.
[in]startdataThe initial private data to pass into the hierarchy.
[in]btThe custom thread, or nullptr if called from the main Cinema 4D thread.
Returns
The success of calling Do() for each object.

Member Data Documentation

◆ doc

BaseDocument* doc
private

◆ bt

BaseThread* bt
private