Hello! I'm working on a Object Plugin that I want to take an entire spline hierarchy and return a modified output. I was running into a problem though that when I use Make Editable (using the C key), it is only returning the first element in the hierarchy. I stripped it all the way down to this code and it's still happening. I used the following python code on it and it was able to return the correct hierarchy along with being live in the viewport. The only issue is when it is made editable.
My python script's output is at the top, with the result of me making the plugin editable at the bottom.
#include "c4d.h"
#include "c4d_symbols.h"
#include "c4d_general.h"
class SimpleTest : public ObjectData
{
INSTANCEOF(SimpleTest, ObjectData)
public:
virtual Bool Init(GeListNode *node);
virtual BaseObject* GetVirtualObjects(BaseObject *op, HierarchyHelp *hh);
static NodeData *Alloc() { return NewObjClear(SimpleTest); }
void CheckDirty( BaseObject* op,BaseDocument* doc);
void HierarchyIterator(BaseObject* obj, maxon::BaseArray<BaseObject*>* objectlist);
SplineObject* GetContour(BaseObject *op,BaseDocument *doc,Float lod,BaseThread *bt);
Int32 childContourDirty;
Int32 childGVODirty;
};
void SimpleTest::HierarchyIterator(BaseObject* obj, maxon::BaseArray<BaseObject*>* objectlist)
{
while (obj != nullptr)
{
HierarchyIterator(obj->GetDown(), objectlist);
obj = obj->GetNext();
}
}
void SimpleTest::CheckDirty( BaseObject* op,BaseDocument* doc)
{
BaseObject* child = op->GetDown();
if(child == nullptr)
{
childContourDirty = -1;
op->SetDirty(DIRTYFLAGS::DATA);
return;
}
Int32 childDirty = child->GetDirty(DIRTYFLAGS::DATA | DIRTYFLAGS::MATRIX | DIRTYFLAGS::CACHE);
if( childDirty != childContourDirty)
{
childContourDirty = childDirty;
op->SetDirty(DIRTYFLAGS::DATA);
}
}
BaseObject* SimpleTest::GetVirtualObjects(BaseObject *op, HierarchyHelp *hh)
{
if (op == nullptr || hh==nullptr)
{
return BaseObject::Alloc(Onull);
}
BaseObject* childspline = op->GetDown();
if (childspline == nullptr)
{
SplineObject* temp = SplineObject::Alloc(0, SPLINETYPE::LINEAR);
return temp;
}
Bool opDirty = op->IsDirty(DIRTYFLAGS::DATA | DIRTYFLAGS::MATRIX);
Int32 childDirty = childspline->GetDirty(DIRTYFLAGS::DATA |DIRTYFLAGS::MATRIX | DIRTYFLAGS::CACHE);
if (childDirty ==childGVODirty && !opDirty)
{
return op->GetCache();
}
op->NewDependenceList();
op->AddDependence(hh, childspline);
Bool dirty = FALSE;
if (!dirty)
{
dirty = op->CheckCache(hh);
}
if (!dirty)
{
dirty = op->IsDirty(DIRTYFLAGS::DATA | DIRTYFLAGS::MATRIX);
}
if (!dirty)
{
dirty = !op->CompareDependenceList();
}
if (!dirty)
{
return op->GetCache(hh);
}
if (op->GetDown()!= nullptr)
{
SplineObject*obj =static_cast<SplineObject*>( op->GetDown()->GetClone(COPYFLAGS::NONE, nullptr));
return obj;
}
return BaseObject::Alloc(Onull);
}
SplineObject* SimpleTest::GetContour( BaseObject * op,
BaseDocument * doc,
Float lod,
BaseThread * bt
)
{
if (op->GetDown()!= nullptr)
{
SplineObject*obj =static_cast<SplineObject*>( op->GetDown()->GetClone(COPYFLAGS::NONE, nullptr));
return obj;
}
SplineObject* temp = SplineObject::Alloc(0, SPLINETYPE::LINEAR);
return temp;
}
Bool SimpleTest::Init(GeListNode *node)
{
BaseObject *op = (BaseObject*)node;
if (!op)
{
return FALSE;
}
childContourDirty = 0;
childGVODirty = -1;
return TRUE;
}
Bool RegisterSimpleTest()
{
AutoAlloc<BaseBitmap> bases;
Filename bg;
return RegisterObjectPlugin(1052851, "Simple Test"_s, OBJECT_GENERATOR| OBJECT_INPUT| OBJECT_ISSPLINE , SimpleTest::Alloc, "Simple Test"_s, bases, 0);
}
Python Script
import c4d
from c4d import gui
# Main function
def main():
doc.InsertObject(op.GetCache().GetClone())
c4d.EventAdd()
# Execute main()
if __name__=='__main__':
main()
I'm not really sure the issue, I've had trouble with caches in the past and any help would be greatly appreciated.
Dan