VEXify Geometry

   10339   20   6
User Avatar
Member
4512 posts
Joined: Feb. 2012
Offline
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 )
Edited by animatrix_ - Sept. 8, 2016 11:57:06
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
User Avatar
Member
1391 posts
Joined: Dec. 2010
Offline
Woow , That's perfect , I really like this Tool :wink:
https://www.youtube.com/c/sadjadrabiee [www.youtube.com]
Rabiee.Sadjad@Gmail.Com
User Avatar
Member
459 posts
Joined: Oct. 2011
Offline
Great!

-b
http://www.racecar.no [www.racecar.no]
User Avatar
Member
4512 posts
Joined: Feb. 2012
Offline
Thanks guys, appreciate it
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
User Avatar
Member
4512 posts
Joined: Feb. 2012
Offline
Updated Python code, it's now twice as fast.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
User Avatar
Member
1391 posts
Joined: Dec. 2010
Offline
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:
https://www.youtube.com/c/sadjadrabiee [www.youtube.com]
Rabiee.Sadjad@Gmail.Com
User Avatar
Member
125 posts
Joined: June 2008
Offline
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)
User Avatar
Member
4512 posts
Joined: Feb. 2012
Offline
@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.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
User Avatar
Member
125 posts
Joined: June 2008
Offline
THX a lot

Will try it at home this eve…
User Avatar
Member
1391 posts
Joined: Dec. 2010
Offline
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)
https://www.youtube.com/c/sadjadrabiee [www.youtube.com]
Rabiee.Sadjad@Gmail.Com
User Avatar
Member
7715 posts
Joined: July 2005
Online
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.
User Avatar
Member
1391 posts
Joined: Dec. 2010
Offline
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
https://www.youtube.com/c/sadjadrabiee [www.youtube.com]
Rabiee.Sadjad@Gmail.Com
User Avatar
Member
4512 posts
Joined: Feb. 2012
Offline
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?
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
User Avatar
Member
7715 posts
Joined: July 2005
Online
pusat
Is there a better alternative to accessing large arrays like this from VEX?

Er, like accessing the geometry directly?
User Avatar
Staff
3455 posts
Joined: July 2005
Offline
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!
Michael Goldfarb | www.odforce.net
Training Lead
SideFX
www.sidefx.com
User Avatar
Member
4512 posts
Joined: Feb. 2012
Offline
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.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
User Avatar
Member
24 posts
Joined: May 2012
Offline
So Cool!!
Thanks!
User Avatar
Member
4512 posts
Joined: Feb. 2012
Offline
blove
So Cool!!
Thanks!

Thank you
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
User Avatar
Member
30 posts
Joined: May 2017
Offline
very nice thank you very much
User Avatar
Member
4512 posts
Joined: Feb. 2012
Offline
Thanks man
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
  • Quick Links