Jump to content

Insert a vertex from the HOM?


bsilva07

Recommended Posts

I have a bunch of polygon curve primitives, and I'd like to insert a vertex into the middle of each of them. I see that the hou.Face class has an "addVertex" method, but that just adds the vertex at the end. Is there any way to insert a vertex at a particular position in the list of vertices for a Prim? This is my first crack at creating a new SOP with Python, so forgive me if I'm missing something obvious.

Cheers,

Link to comment
Share on other sites

Unfortunately there is no way to insert a vertex into the middle of a face. You would have to rebuild your curve and insert it during the building process.

You might also try looking at an HDK solution using inlinecpp since the HDK structures have much more control than HOM, however that can get much more advanced relatively quickly.

  • Like 1
Link to comment
Share on other sites

Ah! The inlinecpp module is absolutely brilliant, thank you for pointing that out! It took a little bit of digging through the HDK but it wasn't too bad to write a wrapper for the insertVertex call on a GEO_PrimPoly. In case anyone else wants to do this, here's the code for the top of a Python SOP:

import inlinecpp

myModule = inlinecpp.createLibrary(
    name='cpp_myModule',
    includes='''

#include <GU/GU_Detail.h>
#include <GEO/GEO_PrimPoly.h>
#include <GEO/GEO_Point.h>

''',
    function_sources=['''

int insertVertex( GU_Detail* gdp, unsigned int prim_num, unsigned int vertex_ix, unsigned int point_num ) {

    GB_ElementList& prims = gdp->basePrims();
    GB_ElementList& pts = gdp->basePoints();

    GEO_PrimPoly* prim = (GEO_PrimPoly*) prims[prim_num];
    GEO_Point* pt = (GEO_Point*) pts[point_num];

    prim->insertVertex(pt, vertex_ix);

    return 1;
}

'''])

And then it's called as such from Python (for example):

myModule.insertVertex( geo, prim.number(), int(math.ceil(u)), vtx.point().number() )

I definitely welcome any suggestions on the C++ code, it's been a while. I have no idea what the return value should be but it works this way.

Thanks again, Graham!

Unfortunately there is no way to insert a vertex into the middle of a face. You would have to rebuild your curve and insert it during the building process.

You might also try looking at an HDK solution using inlinecpp since the HDK structures have much more control than HOM, however that can get much more advanced relatively quickly.

Link to comment
Share on other sites

Yep, that's about it. Glad you figured it out. I was going to post an example just like that but I was on my way out.

As for the return value it's pretty much whatever in this case. I suppose you could verify that the polygon is a GU_PrimPoly and return whether the operation was successful or not but it doesn't really matter.

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...