Search - User list
Full Version: VEXify Geometry
Root » Work in Progress » VEXify Geometry
animatrix_
Python code that converts any polygonal geometry into VEX code executed via AttribWrangle SOP. Useful for embedding geometry into HDAs without locking nodes or sharing geometry via text. Supports open/closed polygons and point colors.



Python code (copy paste into Python SOP):

node = hou.pwd()
geo = node.geometry()
parentNode = node.parent ( )
wrangleNode = parentNode.createNode ( "attribwrangle", "attribwrangle_geometry" )
wrangleNode.setPosition ( node.position ( ) + hou.Vector2 ( 0, -1 ) )
wrangleNode.parm ( "class" ).set ( 0 )
wrangleNode.setDisplayFlag ( True )
wrangleNode.setRenderFlag ( True )
wrangleNode.setSelected ( True, clear_all_selected = True )
items = [ str ( pt.position ( ) ).replace ( "[", "{" ).replace ( "]", "}" ) for pt in geo.points ( ) ]
points = "vector points [ ] = {" + ",".join ( items ) + "};\n"
items = [ ",".join ( [ str ( vtx.point ( ).number ( ) ) for vtx in pr.vertices ( ) ] ) for pr in geo.prims ( ) ]
primpts = "int primpts [ ] = {" + ",".join ( items ) + "};\n"
items = [ str ( pr.numVertices ( ) ) for pr in geo.prims ( ) ]
vertices = "int nprimpts [ ] = {" + ",".join ( items ) + "};\n"
color = "vector color [ ] = { };\n"
if geo.findPointAttrib ( "Cd" ) != None:
    items = [ str ( pt.attribValue ( "Cd" ) ).replace ( "(", "{" ).replace ( ")", "}" ) for pt in geo.points ( ) ]
    color = "vector color [ ] = {" + ",".join ( items ) + "};\n"
openpolys = [ ]
for pr in geo.prims ( ):
    if not pr.isClosed ( ):
        openpolys.append ( pr.number ( ) )
items = [ str ( index ) for index in openpolys ]
openprims = "int openpolys [ ] = {" + ",".join ( items ) + "};\n"
creategeo = """
foreach ( vector p; points )
    addpoint ( geoself ( ), p );
    
int ncolor = len ( color );
if ( ncolor > 0 )
{
    addattrib ( geoself ( ), \"point\", \"Cd\", { 1, 1, 1 } );
    for ( int i = 0; i < ncolor; ++i )
        setattrib ( geoself ( ), \"point\", \"Cd\", i, -1, color [ i ], \"set\" );
}
int start = 0;
int npoints = len ( nprimpts );
for ( int i = 0; i < npoints; ++i )
{
    string type = \"poly\";
    if ( find ( openpolys, i ) >= 0 )
        type = \"polyline\";
        
    int pr = addprim ( geoself ( ), type );
    for ( int f = 0; f < nprimpts [ i ]; ++f )
        addvertex ( geoself ( ), pr, primpts [ start + f ] );
    start += nprimpts [ i ];
}"""
vexcode = points + primpts + vertices + color + openprims + creategeo
wrangleNode.parm ( "snippet" ).set ( vexcode )
Sadjad Rabiee
Woow , That's perfect , I really like this Tool :wink:
bonsak
Great!

-b
animatrix_
Thanks guys, appreciate it
animatrix_
Updated Python code, it's now twice as fast.
Sadjad Rabiee
Dear pusat , I made a simple tool for locking Animation (Sequenced) geometries such as Alembic files inside the Houdini's project before.

I think we can combine these two tools to achieve new VEXify node for saving Alembic geometries inside Houdini projects too.

for example we can change my tool for saving too many Point Wrangle nodes that each one contain point's data for each frame.

my Tool's name is JK_Embedded_Alembic Please download it from my download page and check it .

Download Link :

http://jkcompany.org/JK_Houdini_Tools.html [jkcompany.org]

Specially thanks :wink:
NAHASSIA
sounds exciting and a very good idea but iit gives me an error on the python node (line 15.. could not figure it thow)

Woud like to have it working..

THX

(H14.0.201.13)
animatrix_
@NAHASSIA: I fixed the code. It should work now.

@Joker386: I saw your tool, it's good. You can definitely use my tool to create a VEXified node for each frame.
NAHASSIA
THX a lot

Will try it at home this eve…
Sadjad Rabiee
pusat
@NAHASSIA: I fixed the code. It should work now.

@Joker386: I saw your tool, it's good. You can definitely use my tool to create a VEXified node for each frame.

Thanks a lot , I waiting for another new and perfectly tools from you 8)
edward
Interesting approach… Personally, I just add the .bgeo file as an extra file in the Type Properties dialog. Then one can bring it back using a File SOP with an opdef: path. Back in the day, someone scripted this so one could just right-click on any SOP node, and say “Embed into OTL” that did all of these steps automatically.
Sadjad Rabiee
edward
Interesting approach… Personally, I just add the .bgeo file as an extra file in the Type Properties dialog. Then one can bring it back using a File SOP with an opdef: path. Back in the day, someone scripted this so one could just right-click on any SOP node, and say “Embed into OTL” that did all of these steps automatically.

Yes , that's perfectly Idea , I like to write this tool :idea:

Thanks
animatrix_
edward
Interesting approach… Personally, I just add the .bgeo file as an extra file in the Type Properties dialog. Then one can bring it back using a File SOP with an opdef: path. Back in the day, someone scripted this so one could just right-click on any SOP node, and say “Embed into OTL” that did all of these steps automatically.

That would be a good RFE. I submitted one for embedding presets into an OTL automatically in case you wanna add/append new presets to your OTL to be distributed rather than storing them locally.

I also noticed VEX spends a lot of time if I store these arrays as detail attributes or if I only “paste” them into code editor as if I typed the array manually:

vector pts = `chs(“../pts”)`
@P = pts ;

So it's hard to gauge how much time is actually spent creating the geometry.

Is there a better alternative to accessing large arrays like this from VEX?
edward
pusat
Is there a better alternative to accessing large arrays like this from VEX?

Er, like accessing the geometry directly?
goldfarb
edward
Interesting approach… Personally, I just add the .bgeo file as an extra file in the Type Properties dialog. Then one can bring it back using a File SOP with an opdef: path. Back in the day, someone scripted this so one could just right-click on any SOP node, and say “Embed into OTL” that did all of these steps automatically.

ah the good old days!
animatrix_
edward
Er, like accessing the geometry directly?

Yes but I need the result to be persistent, saving the data into detail or just using it in the code editor seem to take the same amount of time unfortunately. I thought maybe there would be a way to serialize the data onto the node.
blove
So Cool!!
Thanks!
animatrix_
blove
So Cool!!
Thanks!

Thank you
sajadalavi
very nice thank you very much
animatrix_
Thanks man
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB