THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 27/01/2007 at 08:56, xxxxxxxx wrote:
If creating a hair object from a generator as the cache will be destroyed at various times dynamics won't work as any previous data is lost. You would need to hold a copy of the hair object and update it in Execute (with Update(), this does the dynamics also).
As for not rendering, I added a quick SDK example and this works fine (code below). Had you added the Hair Renderer? Also you would need to copy any tags from your generator to the created hair object for any materials to be used at render time.
This is the sdk example code and seems fine:
/////////////////////////////////////////////////////////////
// CINEMA 4D SDK //
/////////////////////////////////////////////////////////////
// (c) 1989-2007 MAXON Computer GmbH, all rights reserved //
/////////////////////////////////////////////////////////////
// example code for creating a generator that creates Hair
//////////////////////////////////////////////////////////////////////////
#include "c4d.h"
#include "c4d_symbols.h"
#include "lib_hair.h"
#include "ohairsdkgen.h"
//////////////////////////////////////////////////////////////////////////
class HairGeneratorObject : public ObjectData
{
INSTANCEOF(HairGeneratorObject,ObjectData)
public:
virtual Bool Init(GeListNode *node);
virtual void Free(GeListNode *node);
virtual Bool Message(GeListNode *node, LONG type, void *data);
virtual Bool Draw(PluginObject* op, LONG drawpass, BaseDraw* bd, BaseDrawHelp* bh);
virtual BaseObject* GetVirtualObjects(PluginObject *op, HierarchyHelp *hh);
virtual Bool AddToExecution(PluginObject* op, PriorityList* list);
virtual LONG Execute(PluginObject* op, BaseDocument* doc, BaseThread* bt, LONG priority, LONG flags);
static NodeData *Alloc(void) { return gNew HairGeneratorObject; }
};
//////////////////////////////////////////////////////////////////////////
Bool HairGeneratorObject::Init(GeListNode *node)
{
BaseContainer *bc=((BaseList2D* )node)->GetDataInstance();
bc->SetLong(HAIR_GEN_COUNT,5000);
bc->SetLong(HAIR_GEN_SEGMENTS,6);
bc->SetReal(HAIR_GEN_LENGTH,15);
bc->SetReal(HAIR_GEN_LENGTH_VAR,5);
bc->SetReal(HAIR_GEN_NOISE,0.2);
bc->SetBool(HAIR_GEN_GENERATE,FALSE);
return TRUE;
}
void HairGeneratorObject::Free(GeListNode *node)
{
}
Bool HairGeneratorObject::Message(GeListNode *node, LONG type, void *data)
{
return SUPER::Message(node,type,data);
}
Bool HairGeneratorObject::Draw(PluginObject* op, LONG drawpass, BaseDraw* bd, BaseDrawHelp* bh)
{
return TRUE;
}
Bool HairGeneratorObject::AddToExecution(PluginObject* op, PriorityList* list)
{
list->Add(op,EXECUTION_GENERATOR,-1);
return TRUE;
}
static void RunExecute(BaseObject *op, BaseDocument *doc)
{
while (op)
{
if (op->IsInstanceOf(Ohair)) ((HairObject* )op)->Update(doc);
RunExecute(op->GetDown(),doc);
op=op->GetNext();
}
}
LONG HairGeneratorObject::Execute(PluginObject* op, BaseDocument* doc, BaseThread* bt, LONG priority, LONG flags)
{
RunExecute(op->GetCache(),doc);
return EXECUTION_RESULT_OK;
}
BaseObject *HairGeneratorObject::GetVirtualObjects(PluginObject *pObject, HierarchyHelp *hh)
{
Bool bDirty = pObject->CheckCache(hh);
HairObject *main=NULL;
if (!bDirty) bDirty = pObject->IsDirty(DIRTY_DATA|DIRTY_MATRIX);
if (!bDirty) return pObject->GetCache(hh);
BaseContainer *bc=pObject->GetDataInstance();
main = HairObject::Alloc();
if (!main) goto Error;
main->Lock(hh->GetDocument(),hh->GetThread(),FALSE,0);
HairGuides *guides = HairGuides::Alloc(1000,8);
if (!guides) goto Error;
main->SetGuides(guides,FALSE);
//guides->SetMg(mg);
Vector *pnts = guides->GetPoints();
LONG i,l;
for (i=0;i<1000;i++)
{
for (l=0;l<=8;l++)
{
pnts[i*9+l]=Vector(i,l*20.0,0.0);
}
}
main->Unlock();
if (!pObject->CopyTagsTo(main,TRUE,FALSE,FALSE,NULL)) goto Error;
main->Update(hh->GetDocument());
return main;
Error:
HairObject::Free(main);
return BaseObject::Alloc(Onull);
}
//////////////////////////////////////////////////////////////////////////
#define ID_HAIR_GENERATOR_EXAMPLE 1020787
Bool RegisterGeneratorObject()
{
return RegisterObjectPlugin(ID_HAIR_GENERATOR_EXAMPLE,GeLoadString(IDS_HAIR_GENERATOR_EXAMPLE),OBJECT_GENERATOR|OBJECT_INPUT,HairGeneratorObject::Alloc,"Ohairsdkgen","hairgen.tif",0);
}