HDK: speedup creating geometry

   2783   2   0
User Avatar
Member
45 posts
Joined: July 2005
Offline
Hi,

I want to export my particles from maya to houdini to use it in mantra. Now I wrote an exporter which will export a simple particle file format. Then I start a houdini standalone which reads this file and crates a .geo file. At the moment it works fine, but it is really extremly slow. I have about 145000 particles. These are written from maya in less than a second and the creation of a houdini .geo file taks more than 5 minutes! This leads me to the conclusion that there must be something wrong with my code. I do the following:


GU_Detail gdp;
GU_PrimParticle *particle;

int defaultId = -1;
GB_AttributeRef idAttr = gdp.addPointAttrib(“id”, sizeof(int), GB_ATTRIB_INT, &defaultId);

UT_Vector3 vel(1,2,3);
GB_AttributeRef velAttr = gdp.addPointAttrib(“v”, sizeof(UT_Vector3), GB_ATTRIB_VECTOR, &vel);

float pscale = 1.234;
GB_AttributeRef scaleAttr = gdp.addPointAttrib(“pscale”, sizeof(float), GB_ATTRIB_FLOAT, &pscale);

particle = (GU_PrimParticle *)GU_PrimParticle::build(&gdp, numParticles);


int sizeId = 0;
for( uint i = 0; i < numParticles; i++)
{
uint index = i * 3;
particle->getVertex(i).getPt()->setPos(posList, posList, posList);
particle->getVertex(i).getPt()->setValue<UT_Vector3>(velAttr, UT_Vector3(velList,velList,velList));
particle->getVertex(i).getPt()->setValue<float>(scaleAttr, sizeList);
}



First I create an GU_Detail with the necessary points and attributes. The data is read from the file in posList, velList and sizeList. And the loop takes a long time. It would be great if there would be a faster way to assign the values to the points. Without the attributes it takes about 40sec with both attributes, more than 5 minutes.

Thanks for any tips.

haggi
renderwiki.com openmaya.net
User Avatar
Member
51 posts
Joined: Oct. 2006
Offline
The slowdown is probably because of the getVertex() calls - particles are stored in a linked list and it goes through the list every time up to the current i. Try using iterate*() methods.

But why don't you write .geo file directly from Maya? GEO format is very simple, especially since you only need to store a list of points with attributes - you'll probably only need minor modifications to your existing code.

edit
(You probably meant +1 for the 2nd index here: velList,velList[index+2],velList)

Here is some code:
Merely caching vertex ref inside the loop makes it 3 times faster as expected (note that this can't be optimized by the compiler):
for (uint i = 0; i < numParticles; i++) {
uint index = i * 3;
GEO_Vertex& vtx = particle->getVertex(i);
vtx.getPt()->setPos(…);
vtx.getPt()->setValue<UT_Vector3>(…);
vtx.getPt()->setValue<float>(…);
}


But what you really want is this:
GEO_ParticleVertex* vtx = particle->iterateInit();
for (uint i = 0; i < numParticles; i++) {
uint index = i * 3;
vtx->getPt()->setPos(…);
vtx->getPt()->setValue<UT_Vector3>(…);
vtx->getPt()->setValue<float>(…);
vtx = particle->iterateNext(vtx);
}

The last fragment is almost 200x faster on my machine for 10K points.
Edited by - Aug. 29, 2011 17:21:51
User Avatar
Member
45 posts
Joined: July 2005
Offline
Thanks, meanwhile I tried another approach. The reason is indeed the point access in the loop. Now I create a GEO_Point() and do a particle->appendParticle() which is really fast too.

And.. yes you are right, the indices are wrong

Concerning geo files from maya. You are right, the geo format ist not too complicated. But I'd like to be able to write all types of geometry like nurbs, meshes, particles, curves, fluids as geo and as bgeo files. And to write clean bgeo files, this would take several weeks to find out how it has do be done correctly. Maybe I'll switch to an open source format like alembic, partio or field3d for data exchange. But at the moment I'll concentrate on clean export and on shaders. Then I'll streamline the procedures.
renderwiki.com openmaya.net
  • Quick Links