Inheritance |
|
A hou.Face, on the other hand, stores a sequence of vertices, and might be a polygon or NURBS curve.
Methods ¶
numCols()
Return the number of columns in the 2D array of vertices.
numRows()
Return the number of rows in the 2D array of vertices.
vertex(u_index, v_index)
Return an element in the 2D array of vertices, given the u (column) and v (row) indices into the array.
Negative indices are allowed, in which case Houdini will index starting from the last vertex.
For non-negative indices, this method is roughly equivalent to writing
surf.vertices()[v_index * surf.numCols() + u_index]
.
Raises hou.OperationFailed if the u or v indices are invalid.
# Use a grid SOP to create a NURBS grid with 3 rows and 2 columns. geo = hou.node("/obj").createNode("geo").createNode("grid").geometry() grid_node = geo.sopNode() grid_node.setDisplayFlag(True) for name, value in ("type", "nurbs"), ("rows", 5), ("cols", 4): grid_node.parm(name).set(value) # Print out the x positions of all the vertices in the surface. surf = geo.iterPrims()[0] for v_index in surf.numRows(): for u_index in surf.numCols(): print surf.vertex(u_index, v_index).point().position()[0], print
See also:
verticesInCol(u_index)
Given a u (i.e. column) index, return a tuple containing all the vertices in that column.
See also hou.Prim.vertices.
verticesInRow(v_index)
Given a v (i.e. row) index, return a tuple containing all the vertices in that row.
See also hou.Prim.vertices.
addCol(after=-1)
Add a column of vertices after the given u (i.e. column) index. You would typically call this method from the code of a Python-defined SOP.
This method also adds one point per vertex added. The new points are located at the origin until you move them.
The u (i.e. column) index after
may be negative, in which case the
indexing starts from the end. By default, after
is -1, meaning that
the new column will go after the last column. Raises
hou.OperationFailed if the after
index is invalid.
# This code will work from inside a Python SOP, but not from the Python # shell. def vertexPos(vertex): return hou.Vector3(vertex.point().position()) # Build a NURBS surface. geo = hou.pwd().geometry() surf = geo.createNURBSSurface(10, 10) # Add a new column, and set the new point positions to the average of # the adjacent point positions. surf.addCol(after=7) for v_index in range(surf.numRows()): vertex_before = surf.vertex(7, v_index) vertex_after = surf.vertex(9, v_index) surf.vertex(8, v_index).point().setPosition( (vertexPos(vertex_before) + vertexPos(vertex_after)) * 0.5)
addRow(after=-1)
Add a row of vertices after the given v (i.e. row) index. The new vertices are located at the origin until you move them. You would typically call this method from the code of a Python-defined SOP.
See hou.Surface.addCol for more information.
positionAt(u, v)
→ hou.Vector3
Given normalized (i.e. from 0 to 1) u and v values, returns the position of the surface at that parametric location.
See the surface_wires cookbook example for an example.
normalAt(u, v)
→ Vector3
Given normalized (i.e. from 0 to 1) u and v values, returns the normal of the surface at that parametric location. The normal is a vector that is perpendicular to the surface at that location.
The normal vector is normalized (i.e. it is a unit vector, so its length is 1).
See the surface_wires cookbook example for an example.
attribValueAt(attrib_or_name, u, v, du=0, dv=0)
→ int
, float
, str
or tuple
Return an attribute value at a normalized (u, v) parametric position on the surface. If du and dv are both 0, returns the interpolated attribute value; otherwise, returns the (partial) derivative of the attribute value.
Raises hou.OperationFailed if the attribute is not a point or vertex attribute. If you want a primitive attribute value, it doesn’t vary across the surface, so use hou.Prim.attribValue.
isClosedInU()
Return whether the first and last columns of vertices are connected.
A grid, for example, is open in both U and V. A tube is open in one of U or V and closed in the other. A torus is closed in both U and V.
isClosedInV()
Return whether the first and last rows of vertices are connected.
See hou.Surface.isClosedInU for more information.
Methods from hou.Prim ¶
attribValue(name_or_attrib)
→ int
, float
, str
, tuple
or dict
Return the value stored in this primitive for a particular attribute. The attribute may be specified by name or by hou.Attrib object.
Looking an attribute value using a hou.Attrib object is slightly faster than looking it up by name. When looking up attribute values inside a loop, look up the hou.Attrib object outside the loop, and pass it into this method.
When looking up the attribute values of all primitives, it is faster to call hou.Geometry.primFloatAttribValues or hou.Geometry.primFloatAttribValuesAsString than to call this method for each primitive in the geometry.
Raises hou.OperationFailed if no attribute exists with this name.
floatAttribValue(attrib)
→ float
Return the primitive attribute value for a particular floating point attribute. The attribute may be specified by name or by hou.Attrib object.
Raises hou.OperationFailed if no attribute exists with this name or the attribute is not float of size 1.
In most cases, you’ll just use hou.Prim.attribValue to access attribute values. Houdini uses this method internally to implement attribValue.
floatListAttribValue(name_or_attrib)
→ tuple
of float
Return the primitive attribute value for a particular floating point attribute. The attribute may be specified by name or by hou.Attrib object. The return value is a tuple of floats.
It is valid to call this method when the attribute’s size is 1. In this case, a tuple with one element is returned.
See also hou.Prim.attribValue.
intAttribValue(name_or_attrib)
→ int
Return the primitive attribute value for a particular integer attribute of size 1. The attribute may be specified by name or by hou.Attrib object. See hou.Point.floatAttribValue for more information.
intListAttribValue(name_or_attrib)
→ tuple
of int
Return the primitive attribute value for a particular integer attribute. The attribute may be specified by name or by hou.Attrib object. The return value is a tuple of ints. See hou.Prim.floatListAttribValue for more information.
stringAttribValue(name_or_attrib)
→ str
Return the primitive attribute value for a particular string attribute. The attribute may be specified by name or by hou.Attrib object. See hou.Prim.floatAttribValue for more information.
stringListAttribValue(name_or_attrib)
→ tuple
of str
Return the primitive attribute value for a particular string attribute. The attribute may be specified by name or by hou.Attrib object. The return value is a tuple of strings.
It is valid to call this method when the attribute’s size is 1. In this case, a tuple with one element is returned.
See also hou.Prim.attribValue.
dictAttribValue(name_or_attrib)
→ dict
Return the primitive attribute value for a particular dictionary attribute. The attribute may be specified by name or by hou.Attrib object. See hou.Prim.floatAttribValue for more information.
dictListAttribValue(name_or_attrib)
→ tuple
of str
Return the primitive attribute value for a particular dictionary attribute. The attribute may be specified by name or by hou.Attrib object. The return value is a tuple of dictionaries.
It is valid to call this method when the attribute’s size is 1. In this case, a tuple with one element is returned. See hou.Prim.floatAttribValue for more information.
setAttribValue(name_or_attrib, attrib_value)
Store an attribute value in this primitive. The attribute may be specified by name or by hou.Attrib object, and must be an existing primitive attribute in the geometry. You would typically call this method from the code of a Python-defined SOP.
Raises hou.OperationFailed if no attribute exists with this name or if the attribute’s data type does not match the value passed in. If the attribute’s size is more than 1, the attribute value must be a sequence of integers/floats, and the size of the sequence must match the attribute’s size.
If the attribute is an array, the seqeunce must be a flat array, not an array of tuples. If the attribute is float, ensure the python objects are float, and not integer (1.0, not 1).
Raises hou.GeometryPermissionError if this geometry is not modifiable.
# Create a float primitive attribute of size 3 named "Cd", and assign # each primitive a unique color. This code will work from inside a Python # SOP, but not from the Python shell. geo = hou.pwd().geometry() color_attrib = geo.addAttrib(hou.attribType.Prim, "Cd", (1.0, 1.0, 1.0)) num_prims = len(geo.prims()) color = hou.Color() for prim in geo.prims(): fraction = float(prim.number()) / num_prims # Give each primitive a different hue, but full saturation and value. # Store the RGB value in the attribute. color.setHSV((fraction * 255, 1, 1)) prim.setAttribValue(color_attrib, color.rgb())
attribType()
→ hou.attribType enum value
Return the enumerated value hou.attribType.Prim. Points, primitives, vertices, and geometry support the same set of methods for querying their attributes, and this method is one of them.
See also:
intrinsicValueDict()
→ dict
of str
to value
Returns a dictionary mapping intrinsic names to their values.
intrinsicValue(intrinsic_name)
→ int
, float
, str
, or tuple
Gets the value of an “intrinsic”, often computed, value of the primitive, such as bounds
, measuredarea
, vertexcount
, and so on.
Most intrinsic values are computed, such as measuredarea
, however a few are writeable with hou.Prim.setIntrinsicValue.
For example, sphere primitives have a transform matrix as part of their definition.
You can also view these values in the user interface using the geometry spreadsheet.
Raises hou.OperationFailed if the given intrinsic name does not exist. You can get a list of the available intrinsic value names with hou.Prim.intrinsicNames. Different primitive types will have different intrinsic values available.
Bounding box intrinsic values like bounds
or packedbounds
are returned
in (xmin, xmax, ymin, ymax, zmin, zmax) order.
intrinsicNames()
→ tuple
of str
Returns a tuple of strings representing the intrinsic values available for this primitive. Different primitive types will have different intrinsic values available. You can then get or set the value using hou.Prim.intrinsicValue and/or hou.Prim.setIntrinsicValue.
setIntrinsicValue(intrinsic_name, value)
Some “intrinsic” values can be modified. For example, you change the internal size and rotation (transform) of a sphere primitive by passing a 9 float tuple representing the transform to hou.Prim.setIntrinsicValue. Raises hou.OperationFailed if the intrinsic is not writeable or does not accept the passed value, or if the given intrinsic name does not exist.
intrinsicReadOnly(intrinsic_name)
→ bool
Returns whether the intrinsic is read-only or can be modified with hou.Prim.setIntrinsicValue.
intrinsicSize(intrinsic_name)
→ int
Returns the intrinsic value’s tuple size.
positionAtInterior(u, v, w=0.0)
→ hou.Vector3
Given normalized (i.e. from 0 to 1) u, v, w values, return the interior position of the primitive at that parametric location.
Use hou.Face.positionAt for querying positions along the perimeter.
attribValueAtInterior(attrib_or_name, u, v, w=0.0)
→ int
, float
, str
or tuple
Return an attribute value at the normalized u, v, w parametric position in the interior of the primitive.
Raises hou.OperationFailed if the attribute is not a point or vertex attribute. If you want a primitive attribute value, it doesn’t vary across the surface, so use hou.Prim.attribValue.
If the attribute name is “N” the primitive’s intrinsic normal is evaluated, not the value from any point or primitive attributes.
Use hou.Face.attribValueAt for querying attributes along the perimeter.
geometry()
→ hou.Geometry
Return the hou.Geometry object containing this primitive.
number()
→ int
Return the number of this primitive. Primitives are numbered sequentially starting from 0, and the primitives returned by hou.Geometry.prims are in order by their number.
type()
→ hou.primType enum value
Return a hou.primType value containing the type of this primitive (e.g. polygon, NURBS curve, metaball, etc).
vertices()
→ generator of hou.Vertex
Return a sequence of the vertices contained in this primitive.
If the primitive is a face (e.g. a polygon or NURBS curve), the result corresponds to the order of the vertices in that face. If it is a surface (e.g. a NURBS mesh), however, the primitive has a 2D array of vertices, and this method returns all vertices in the 2D array, ordered by the rows.
See hou.Surface.vertex for more information about the relationship between the 2D vertex array and the sequential vertex index, and for more ways to access the vertices in a surface.
numVertices()
→ int
A shortcut for len(self.vertices())
. You probably don’t need to call
this method.
points()
→ list of hou.Point
Shortcut for getting all the points of a primitive without iterating through each vertex.
boundingBox()
→ hou.BoundingBox
Return an axis-aligned 3D bounding box that is sized and positioned to be large enough to hold this primitive.
nearestToPosition(pos3)
Given a sequence of three floats containing a position, find the location on this primitive that is closest to that position. Returns a tuple containing the u value on this primitive, the v value on this primitive, and the distance to this primitive.
NOTE: The returned UVs are in real coordinates, use the primuvConvert to switch to unit coordinates to match VEX’s xyzdist.
primuvConvert(uv, mode, tol)
Given a 2D uv coordinate, compute the location in a different coordinate system. The tol argument is optional. See the primuvconvert VEX function for the different valid modes.
primuConvert(u, mode, tol)
Given a 1D u coordinate, compute the location in a different coordinate system. The tol argument is optional. See the primuvconvert VEX function for the different valid modes.
groups()
→ tuple
of hou.PrimGroup
Return a tuple of the primitive groups that contain this primitive.