On 26/04/2018 at 06:34, xxxxxxxx wrote:
Hi Kent,
First of all, about the video, It's looks like the group is already here (just folded) even before he adds a group. So it's probably the object within the scene which add a new group.
Here is a CommandData to demonstrate how to add a group, create particles, then assign them to the group and finally move them.
Same things should work for an ObjectData.
#include "c4d.h"
#include <c4d_particles.h>
class TpGenerator : public CommandData
{
INSTANCEOF(TpGenerator, CommandData)
private:
TP_MasterSystem* GetTpMasterSystem(BaseDocument* doc);
TP_PGroup* GetRootGroup(TP_MasterSystem* master);
public:
virtual Bool Execute(BaseDocument* doc);
virtual Int32 GetState(BaseDocument* doc);
};
TP_MasterSystem* TpGenerator::GetTpMasterSystem(BaseDocument* doc)
{
if (!doc)
return nullptr;
BaseSceneHook* hook = doc->FindSceneHook(ID_THINKINGPARTICLES);
if (!hook || hook->GetType() != ID_THINKINGPARTICLES)
return nullptr;
return static_cast<TP_MasterSystem*>(hook);
}
TP_PGroup* TpGenerator::GetRootGroup(TP_MasterSystem* master)
{
if(!master)
return nullptr;
TP_PGroupArray groups;
Int32 gcnt = master->GetParticleGroups(nullptr, &groups, TP_GETPGROUP_ALL, false);
if (gcnt == 0)
return nullptr;
TP_PGroup* grp = (TP_PGroup* )groups.GetIndex(0);
return grp;
}
Bool TpGenerator::Execute(BaseDocument* doc)
{
// Get the TP master system
TP_MasterSystem* master = GetTpMasterSystem(doc);
if (!master)
return false;
// Get the Root Group
TP_PGroup* rootGroup = GetRootGroup(master);
if (!rootGroup)
return false;
// Create a new group
TP_PGroup* customGroup = master->AllocParticleGroup();
if (!customGroup)
return false;
customGroup->SetName("Custom Particle Group");
// Insert customGroup as a child of root ("All")
master->SetPGroupHierarchy(rootGroup, customGroup, TP_INSERT_UNDERFIRST);
// Create 100 particles
Int32 particleIds[100];
if (master->AllocParticles(100, particleIds) == NOTOK)
return false;
// Set all particles to the group and move them
for (auto pId : particleIds)
{
master->SetGroup(pId, customGroup);
master->SetPosition(pId, Vector(pId * 10));
};
EventAdd();
return true;
}
Moreover please make sure to call InitThinkingParticles before to use any TP function, the recommended way is to call it in C4DPL_STARTACTIVITY
Bool PluginMessage(Int32 id, void* data)
{
switch (id)
{
case C4DPL_STARTACTIVITY:
{
InitThinkingParticles();
}
break;
}
retun true;
}
Hope it helps,
Cheers,
Maxime