I followed through a tutorial on how to Create Geometry From Scratch to get a comparison of how to procedurally model geometry using two different scripting languages: VEX and Python.
Using Houdini, I can opt to use both the Attribute Wrangle (for VEX Expressions) and the Python node to perform the necessary actions to create geometry using code.
VEX
// create basic geometry
// grab index of it's own geometry
int geo = geoself();
// add 5 points to geometry
int p0 = addpoint(geo,{0,0,0});
int p1 = addpoint(geo,{.5,.5,.5});
int p2 = addpoint(geo,{.5,-.5,-.5});
int p3 = addpoint(geo,{-.5,.5,-.5});
int p4 = addpoint(geo,{-.5,-.5,.5});
// define function to create triangles
int addtriangle(const int g,p,q,r){
// create a polygon index
int f = addprim(g,"poly");
// and add vertices to the polygon
addvertex(g,f,p);
addvertex(g,f,q);
addvertex(g,f,r);
return f;
}
// add the 6 triangles
addtriangle(geo,p0,p1,p2);
addtriangle(geo,p0,p1,p3);
addtriangle(geo,p0,p1,p4);
addtriangle(geo,p0,p2,p3);
addtriangle(geo,p0,p2,p4);
addtriangle(geo,p0,p3,p4);
PYTHON
# all python code runs only once
# create basic geometry
# grab self geometry index
node = hou.pwd()
geo = node.geometry()
# create four points and remember their names
p0 = geo.createPoint()
p1 = geo.createPoint()
p2 = geo.createPoint()
p3 = geo.createPoint()
p4 = geo.createPoint()
# edit position values
p0.setPosition((0,0,0))
p1.setPosition((.5,.5,.5))
p2.setPosition((.5,-.5,-.5))
p3.setPosition((-.5,.5,-.5))
p4.setPosition((-.5,-.5,.5))
# define a function to create triangles
def addTriangle(p,q,r):
# create polygon of 3 corners
f = geo.createPolygon()
f.addVertex(p)
f.addVertex(q)
f.addVertex(r)
#create triangles between the points
addTriangle(p0,p1,p2)
addTriangle(p0,p1,p3)
addTriangle(p0,p1,p4)
addTriangle(p0,p2,p3)
addTriangle(p0,p2,p4)
addTriangle(p0,p3,p4)
Both instances, when running the code, create the same exact geometry with the same values applied. The syntax is definitely different based on the language used. The lines of code used to create the vex code is relatively shorter than the python code version. And this is expected since VEX is the native language used in Houdini, which means that the functions necessary to run a command is simplified. When adding points for the geometry creation, in VEX you can create the points with the position values in one line whereas in Python you’ll need to create the points first and then set the position values afterwards.