Hello @ferdinand,
thank you for you reply!
I am sorry, I should have been more specific.
- I am currently doing everything in
ObjectData::ModifyObject()
and was (am) using TP_MasterSystem::AllocParticle()
.
- The (maximum) number of particles I would allocate is always bound by the point count of the object I am modifying.
The simplyfied version of my ParallelFor routine in ModifyObject is like this:
Matrix m;
m = (~mod_mg) * op_mg;
auto worker = [.../*There would normally be more here*/](maxon::Int i)
{
Vector p;
//holds information about the sampled result
sample_t result;
p = m * m_padr[i];
//these calculations are expensive, thats why the parallel for in the first place
result = sampler->doSomeCalculations(p.x, p.z);
p += result.deformVector;
m_padr[i] = ~m * p;
}
};
maxon::ParallelFor::Dynamic(0, m_pcnt, worker);
where this sample_t result
would also hold information (for that point) if it should spawn a particle for it, its lifetime/velocity etc. are derived from that as well.
And currently right after this ParallelFor I have this (also simplified):
Vector p;
Float32 particleValue;
for (int i = 0; i < m_pcnt; i++)
{
p = m * m_padr[i];
result = sampler->doSomeCalculations(p.x, p.z);
particleValue = 1 - result.particleValue;
if (particleValue > 0) //should a particle even be spawned
if (i % m_particleReduction == 0) //just some simple reduction for viewport speed
{
if (m_masterSystem)
{
Int32 particle = m_masterSystem->AllocParticle();
if (particle != NOTOK)
{
m_masterSystem->SetLife(particle, ...);
m_masterSystem->SetColor(particle, ...);
m_masterSystem->SetPosition(particle, op_mg * m_padr[i]);
m_masterSystem->SetVelocity(particle, ...);
if(m_ioParticleGroup)
m_masterSystem->SetGroup(particle, m_ioParticleGroup);
}
}
}
}
Since doing TP Allocation in ObjectData/ModifyObject is not something I should do, where else, appart from maybe Message would be a place for that? The only information for pre-allocation that I would need is the point count of the object to modify.
Or should I scrap the idea of generating the particles on my own alltogether? The plugin itself should later on be used in a more dynamic (mesh - subdivisions etc.) context that's why I initially did not want to simply set vertex weights as that would not quite work for the use case of this plugin.
Hope I could give more useful information on what it is I am trying to achieve.
Thanks again for your quick and detailed reply!
Best Regards,
Florian