Jump to content

Vertex Split


Recommended Posts

Sorry, you'll have to roll your own. The VertexSplit SOP is not too complicated anyhow. It loops through each point, comparing the vertices around it (via GEO_PointRefArray), and then adds a new point for each vertex if needed. The tricky part is making sure the new point has all the same attributes using the right version of GEO_Detail::appendPoint(), destroying the old point references in your GEO_PointRefArray via GB_PointRefArray::destroyReference(), and then using GB_Vertex::setPt() to insert the new point into the adjacent primitives.

Link to comment
Share on other sites

Hi Edward,

Having a small problem with this, I written this function to do the splitting, which seems to run and loop through all the points, but I'm obviously doing something rather wrong since it causes Houdini to crash when it exits. Any pointers? :unsure:

void
SOP_UVuniform::splitVertexUVs(GEO_Detail *gdp,int uvoff)
{
  GEO_Point		 *ppt;
  UT_Vector4		pos;

  GEO_PointRefArray pointRefArray(gdp);

  for(int i=0;i<pointRefArray.entries();i++)
  {
	GEO_Vertex *vtx,*nextvtx;

	vtx = (GEO_Vertex*)pointRefArray(i)->vtx;
	float *uvatt = (float*)vtx->getAttribData(uvoff);

	for(GB_PointRef *pointRef = pointRefArray(i)->next; pointRef; pointRef = pointRef->next)
	{
	  nextvtx = (GEO_Vertex*)pointRef->vtx;
	  float *nextuvatt = (float*)nextvtx->getAttribData(uvoff);

	  if (abs(nextuvatt[0]-uvatt[0]) > 0.001 ||
		  abs(nextuvatt[1]-uvatt[1]) > 0.001 ||
		  abs(nextuvatt[2]-uvatt[2]) > 0.001)
	  {
		//split point
		//append point into the gdp
		GB_AttributeData  adata;
		pos = vtx->getPt()->getPos();
		ppt = gdp->appendPoint(pos, adata, 1);
		//destroy old point ref
		pointRefArray.destroyReference(pointRef);
		//insert point into prim
		pointRef->vtx->setPt(ppt);
	  }
	}
  }
  cout<<"end"<<endl;
}

Link to comment
Share on other sites

For appendPoint(), I think you need something more like this to make sure the attribute data is the same:

ppt = gdp->appendPoint(pos, vtx->getPt()->getAttrib(), false /*steal*/);

But I suspect the real problem is that you're trying to destroy the vertex references in the pointRefArray while you're still looping through the data structures inside it. So try making a UT_PtrArray<GEO_Vertex *> array which copies out all the GEO_Vertex pointers that you want to process out of pointRef first. Once you have this, then do the splitting by looping through this independent array instead.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...