On this page |
If you ask a SOP for its geometry via hou.SopNode.geometry, you’ll get a read-only reference to it. If the SOP recooks, the corresponding Geometry object will update to the SOP’s new geometry. If the SOP is deleted, accessing the Geometry object will raise a hou.ObjectWasDeleted exception. If you call methods that try to modify the geometry, they will raise a hou.GeometryPermissionError exception.
Note
Whenever you call a method on a hou.Geometry object, Houdini will first attempt to acquire a handle to the underlying geometry. When working with read-only references to geometry on a SOP node, if the SOP in question fails to cook after the read-only reference has been assigned to a variable then any calls to methods on that variable will throw a hou.InvalidGeometry exception. If you receive this exception, your read-only reference is still 'live' and so methods on it will be accessible when the node errors are resolved, until then your code should handle this exception to avoid getting further errors. See hou.Geometry.isValid
If you do not want the geometry to update when the SOP recooks, you can call hou.Geometry.freeze. freeze returns another Geometry object that will not change when the SOP recooks. Accessing frozen Geometry is slightly faster, since Houdini does not need to look up the SOP node for each access, so you may want to use frozen geometry for speed-crucial operations.
If you're writing a SOP using Python, you will have read-write access to the geometry, and it will be frozen. To create a Python-defined SOP, select File ▸ New Operator Type… and place the Python code in the Code tab.
Finally, you can allocate a new frozen geometry with read-write access by creating an instance of hou.Geometry.
Geometry Modification ¶
Since Houdini 18, modifying geometry outside of cooking that is then passed into other HOM methods requires a corresponding increment of the appropriate data ids as well as incrementing the modification counter. This is especially important if you pass this geometry to be processed such as hou.SopVerb.execute since it uses data id optimizations. The simplest way to do this is to call hou.Geometry.incrementAllDataIds. However, a fine-grained list of methods can used to obtain the best performance: hou.Geometry.incrementDataIdsForAddOrRemove, hou.Geometry.incrementPrimitiveIntrinsicsDataId, hou.Geometry.incrementTopologyDataId, hou.Attrib.incrementDataId, hou.PointGroup.incrementDataId, hou.PrimGroup.incrementDataId, hou.EdgeGroup.incrementDataId, hou.VertexGroup.incrementDataId, hou.Geometry.incrementModificationCounter.
When modifying geometry while inside a Python SOP, all data ids are
automatically incremented, as well as the geometry change counter. To opt out
of automatic data ids incrementing, call
hou.SopNode.setManagesAttribDataIds with True
. Note that you cannot
opt out of incrementing the geometry change counter, it must be always done
whenever a SOP node cooks. When unsure, it is better to leave
hou.SopNode.managesAttribDataIds to the default False
or else there is
a risk that users of the output geometry (eg. the viewport) will fail to update
when the geometry has changed.
Methods ¶
__init__(src_geo=None, clone_data_ids=False)
Return a new Geometry
as either empty if src_geo
is None
, or as a
deep copy of src_geo
.
When src_geo
is not None
, clone_data_ids
specifies whether the new
copy has the same data ids. This is useful to enable optimizations that
cache data by only looking at the attribute data id regardless of whether
it is from the same geometry object or not. Otherwise, the new copy will
have data ids that are unique.
isValid()
Check that the hou.Geometry object references a non-null geometry.
Will only be False
when the hou.Geometry is a read-only reference to a
SOP node’s geometry that has failed to cook since the reference was assigned.
Will always be True
for a 'frozen' geometry, see also hou.Geometry.freeze.
Attributes ¶
findPointAttrib(name, scope=hou.attribScope.Public)
→ hou.Attrib or None
Look up a point attribute by name. Returns the corresponding hou.Attrib object, or None if no attribute exists with that name.
name
The name of the point attribute.
scope
A hou.attribScope value to specify whether the attribute is public or private.
Note that the point position attribute is named P
and is 3 floats in
size. Also, the point weight attribute is named Pw
and is 1 float in
size. P
always exists, but Pw
may not.
See hou.Point.attribValue for an example.
findPrimAttrib(name, scope=hou.attribScope.Public)
→ hou.Attrib or None
Look up a primitive attribute by name. Returns the corresponding hou.Attrib object, or None if no attribute exists with that name.
name
The name of the primitive attribute.
scope
A hou.attribScope value to specify whether the attribute is public or private.
findVertexAttrib(name, scope=hou.attribScope.Public)
→ hou.Attrib or None
Look up a vertex attribute by name. Returns the corresponding hou.Attrib object, or None if no attribute exists with that name.
name
The name of the vertex attribute.
scope
A hou.attribScope value to specify whether the attribute is public or private.
findGlobalAttrib(name, scope=hou.attribScope.Public)
→ hou.Attrib or None
Look up a global (a.k.a. detail) attribute by name. Returns the corresponding hou.Attrib object, or None if no attribute exists with that name.
name
The name of the global attribute.
scope
A hou.attribScope value to specify whether the attribute is public or private.
pointAttribs(scope=hou.attribScope.Public)
→ tuple
of hou.Attrib
Return a tuple of all the point attributes.
scope
A hou.attribScope value to specify whether the public or private attributes should be listed.
Note that the point position attribute is named P
and is 3 floats in
size. Also, the point weight attribute is named Pw
and is 1 float in
size. P
always exists, but Pw
may not.
primAttribs(scope=hou.attribScope.Public)
→ tuple
of hou.Attrib
Return a tuple of all the primitive attributes.
scope
A hou.attribScope value to specify whether the public or private attributes should be listed.
vertexAttribs(scope=hou.attribScope.Public)
→ tuple
of hou.Attrib
Return a tuple of all the vertex attributes.
scope
A hou.attribScope value to specify whether the public or private attributes should be listed.
globalAttribs(scope=hou.attribScope.Public)
→ tuple
of hou.Attrib
Return a tuple of all the global (a.k.a. detail) attributes.
scope
A hou.attribScope value to specify whether the public or private attributes should be listed.
addAttrib(type, name, default_value, transform_as_normal=False, create_local_variable=True)
→ hou.Attrib
Create a new point, primitive, vertex, or global (a.k.a. detail) attribute. Returns a hou.Attrib object describing the newly created attribute. You would typically call this method from the code of a Python-defined SOP.
type
A hou.attribType value to specify if the new attribute should be a point, primitive, vertex, or global attribute.
name
The new attribute’s name. Each attribute in the geometry must have a unique name.
default_value
The default value for this attribute. When an attribute is created, all existing elements (e.g. primitives or points) will store this value. As well, elements that you add later will also use this value.
This value also determines the attribute’s data type.
You can use one of the following Python types:
-
int
-
float
-
str
-
sequence (generator, iterator, list, or tuple) of
int
-
sequence of
float
-
sequence of
str
-
dict
-
sequence of
dict
If the default value is a sequence of integers or floats, the sequence size will determine the attribute’s size. Otherwise, the attribute’s size is 1.
String attributes do not support a default value and use this value solely for type determination.
transform_as_normal
This parameter may only be set to True
when the default value is a
sequence of 3 floats. For such attributes, Houdini will not modify the
attribute values when it transforms (translates, rotates, etc.) the
geometry. If you want to the attribute to be transformed as a vector
(such as a normal vector) when Houdini transforms the geometry, set
this parameter to True
.
create_local_variable
If True
, Houdini will create a local variable for this attribute
that may be used in parameter expressions. The name of the local
variable is the attribute’s name, all in upper case. The mapping from
attribute names to local variables is stored in a special global
attribute named "varmap"
.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
Raises hou.OperationFailed if an attribute with this name already exists. If you are familiar with the C++ Houdini Development Kit (HDK), you know that Houdini can support attributes with the same name but with different types. However, many SOPs do not let you distinguish between attributes that have the same name, and multiple attributes with the same name are discouraged. For this reason, you cannot create them with this method.
Raises hou.OperationFailed if transform_as_normal is True
and the
default value is not a sequence of 3 floats.
# Create an integer point attribute of size 1 named "population", and # create 5 points with attribute values 0, 5, 10, 15, and 20. This code # will work from inside a Python SOP, but not from the Python shell. geo = hou.pwd().geometry() population_attrib = geo.addAttrib(hou.attribType.Point, "population", 0) for i in range(5): point = geo.createPoint() point.setPosition((i, 0, 0)) point.setAttribValue(population_attrib, i * 5)
The following example shows how to copy an existing attribute:
def copyAttrib(attrib, new_name): return attrib.geometry().addAttrib( attrib.type(), new_name, attrib.defaultValue(), attrib.isTransformedAsNormal())
If create_local_variable
is True
, this function performs the equivalent
of the following code:
def addLocalVariable(geo, attrib_name): '''Create a geometry attribute and add a local variable for it.''' # The variable mappings are stored in the varmap attribute's string # table. This table is different than varmap's current value, which # simply refers to an entry in that table. So, to ensure an entry # exists in the table, we simply set varmap's value. map_value = "%s -> %s" % (attrib_name, attrib_name.upper()) if geo.findGlobalAttrib("varmap") is None: geo.addAttrib(hou.attribType.Global, "varmap", "") geo.setGlobalAttribValue("varmap", map_value)
See also:
addArrayAttrib(type, name, data_type, tuple_size=1)
→ hou.Attrib
Create a new point, primitive, vertex, or global (a.k.a. detail) array attribute. Returns a hou.Attrib object describing the newly created attribute. You would typically call this method from the code of a Python-defined SOP.
type
A hou.attribType value to specify if the new attribute should be a point, primitive, vertex, or global attribute.
name
The new attribute’s name. Each attribute in the geometry must have a unique name.
data_type
A hou.attribData value to specify if the new attribute should be an int, float, or string attribute.
tuple_size
The new attribute’s tuple size.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
Raises hou.OperationFailed if an attribute with this name already exists. If you are familiar with the C++ Houdini Development Kit (HDK), you know that Houdini can support attributes with the same name but with different types. However, many SOPs do not let you distinguish between attributes that have the same name, and multiple attributes with the same name are discouraged. For this reason, you cannot create them with this method.
attribValue(name_or_attrib)
→ int
, float
, str
, tuple
or dict
Return the global (a.k.a. detail) attribute value for a particular attribute. The attribute may be specified by name or by hou.Attrib object.
Raises hou.OperationFailed if no attribute exists with this name.
floatAttribValue(name_or_attrib)
→ float
Return the global (a.k.a. detail) 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 a float of size 1.
In most cases, you’ll just use hou.Geometry.attribValue to access attribute values. Houdini uses this method internally to implement attribValue.
floatListAttribValue(name_or_attrib)
→ tuple
of float
Return the global (a.k.a. detail) 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 list of floats.
It is valid to call this method when the attribute’s size is 1. In this case, a list with one element is returned.
See also:
intAttribValue(name_or_attrib)
→ int
Return the global (a.k.a. detail) attribute value for a particular integer attribute of size 1. The attribute may be specified by name or by hou.Attrib object. See hou.Geometry.floatAttribValue for more information.
intListAttribValue(name_or_attrib)
→ tuple
of int
Return the global (a.k.a. detail) attribute value for a particular integer attribute. The attribute may be specified by name or by hou.Attrib object. The return value is a list of ints. See hou.Geometry.floatListAttribValue for more information.
stringAttribValue(name_or_attrib)
→ str
Return the global (a.k.a. detail) attribute value for a particular string attribute. The attribute may be specified by name or by hou.Attrib object. See hou.Geometry.floatAttribValue for more information.
stringListAttribValue(name_or_attrib)
→ tuple
of str
Return the global (a.k.a. detail) attribute value for a particular string attribute. The attribute may be specified by name or by hou.Attrib object. The return value is a list of strings. See hou.Geometry.floatListAttribValue for more information.
dictAttribValue(name_or_attrib)
→ dict
Return the global (a.k.a detail) attribute value for a particular dictionary attribute. The attribute may be specified by name or by hou.Attrib object. See hou.Geometry.floatAttribValue for more information.
dictListAttribValue(name_or_attrib)
→ tuple
of str
Return the global (a.k.a detail) 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.Geometry.floatAttribValue for more information.
setGlobalAttribValue(name_or_attrib, attrib_value)
Set a global (a.k.a. detail) attribute value. The attribute may be specified by name or by hou.Attrib object. You would typically call this method from the code of a Python-defined SOP.
If the attribute is an array attribute, then a sequence of values with
length divisble by the attribute’s tuple size must be passed in for
attrib_value
. Any values at the end of the sequence that do not complete
a tuple with the desired size are discarded.
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.
# This code will work from inside a Python SOP, but not from the Python # shell. geo = hou.pwd().geometry() geo.addAttrib(hou.attribType.Global, "author", "") geo.addAttrib(hou.attribType.Global, "version", (0, 0, 0)) geo.setGlobalAttribValue("author", "Joe") geo.setGlobalAttribValue("version", (1, 0, 7))
Here is an example for setting values in a global array attribute:
geo = hou.pwd().geometry() geo.addArrayAttrib( hou.attribType.Global, "data", hou.attribData.Float, tuple_size=3) # This will set the global attribute's value to # [(1.0, 2.0, 3.0), (4.0, 5.0, 6.0)]. geo.setGlobalAttribValue("data", [1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
See also:
attributeCaptureRegions()
→ tuple
of str
Returns a tuple of strings representing the capture region paths for this geometry. The capture regions are identified from the geometry’s capture attributes.
See also:
attributeCaptureObjectPaths()
→ tuple
of str
Returns a tuple of strings representing the capture object paths for this geometry. The capture objects are those used to capture this geometry and are identified from the geometry’s capture attributes. The skeleton root path is prepended to the capture object paths and the object nodes are given by:
# This code will work from inside a Python SOP, but not from the Python # shell. geo = hou.pwd().geometry() nodes = [hou.node(x) for x in geo.attributeCaptureObjectPaths()]
See also:
attribType()
→ hou.attribType enum value
Return the enumerated value hou.attribType.Global. Points, primitives, vertices, and geometry support the same set of methods for querying their attributes, and this method is one of them.
See also:
renamePointAttrib(old_name, new_name)
Rename the point attribute with the specified old name to the new name. This method is typically called from within a Python-defined SOP when the SOP’s geometry is writable.
Raises GeometryPermissionError
if called on a read-only geometry.
Raises TypeError
if old_name
or new_name
is None.
Raises OperationFailed
if no such point attribute with the old name
exists.
Raises OperationFailed
if a point attribute with the new name already
exists.
renamePrimAttrib(old_name, new_name)
Rename the primitive attribute with the specified old name to the new name. This method is typically called from within a Python-defined SOP when the SOP’s geometry is writable.
Raises GeometryPermissionError
if called on a read-only geometry.
Raises TypeError
if old_name
or new_name
is None.
Raises OperationFailed
if no such primitive attribute with the old name
exists.
Raises OperationFailed
if a primitive attribute with the new name already
exists.
renameVertexAttrib(old_name, new_name)
Rename the vertex attribute with the specified old name to the new name. This method is typically called from within a Python-defined SOP when the SOP’s geometry is writable.
Raises GeometryPermissionError
if called on a read-only geometry.
Raises TypeError
if old_name
or new_name
is None.
Raises OperationFailed
if no such vertex attribute with the old name
exists.
Raises OperationFailed
if a vertex attribute with the new name already
exists.
renameGlobalAttrib(old_name, new_name)
Rename the global attribute with the specified old name to the new name. This method is typically called from within a Python-defined SOP when the SOP’s geometry is writable.
Raises GeometryPermissionError
if called on a read-only geometry.
Raises TypeError
if old_name
or new_name
is None.
Raises OperationFailed
if no such global attribute with the old name
exists.
Raises OperationFailed
if a global attribute with the new name already
exists.
generateAttribMenu(attrib_type=None, data_type=None, min_size=1, max_size=-1, array_type=True, scalar_type=True, case_sensitive=True, pattern="*", decode_tokens=False)
→ tuple
of str
Generates the tokens and labels for a parameter menu listing the geometry’s attributes.
attrib_type
A hou.attribType value specifying whether to list point, primitive, vertex, or global attributes.
Providing a value of None
will list attributes of all types.
data_type
Filters the attribute list to include only attributes with the specified hou.attribData data type.
Providing a value of None
will list attributes of all data types.
min_size
Includes only attributes whose size is at least this value.
max_size
If greater than min_size
, includes only attributes whose size is at most this value.
array_type
Specifies whether array attributes should be included.
scalar_type
Specifies whether attributes that do not contain array data should be included.
case_sensitive
Specifies whether the menu labels are produced in a case-sensitive order.
This also controls whether the pattern
is treated as case-sensitive.
pattern
Specifies a pattern of attribute names that should be included.
decode_tokens
If enabled, the menu tokens will contain the decoded attribute names rather than the actual attribute names. This can be useful for parameters that support matching against decoded attribute names.
copyAttrib(attrib)
Copy an attribute from another geometry. The attribute with the same name and
right context must exist on the current geometry.
Raises OperationFailed
on failure describing the error condition in detail.
copyAttrib(attrib)
Copy an attribute hou.Attrib from another geometry. An attribute with the same name and
right context must exist on the current geometry.
Raises OperationFailed
on failure describing the error condition in detail.
copyAttribs(attribs)
Copy a list of attributes hou.Attrib from another geometry. Attributes with the same name and right context must exist on the current geometry.
Raises OperationFailed
on failure describing the error condition in detail.
Intrinsics ¶
intrinsicValue(intrinsic_name)
→ int
, float
, str
, or tuple
Gets the value of an “intrinsic”, often computed, value of the geometry,
such as memoryusage
, pointcount
, pointattributes
, and so on. Raises
OperationFailed
if the given intrinsic name does not exist.
You can also view these values in the user interface using the geometry spreadsheet.
In Houdini, some primitives have “intrinsic” values which can’t be accessed
directly through the attribute interface. Most intrinsic values are
computed, such as measuredarea
, however a few are writeable with the
setIntrinsicValue method. For example, sphere
primitives have a transform matrix as part of their definition.
You can get a list of the available intrinsic value names with the intrinsicNames method. Different geometry types will have different intrinsic values available.
Bounding box intrinsic values like bounds
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 geometry. Different geometry types will have different intrinsic values available. You can then get or set the value using intrinsicValue and/or setIntrinsicValue.
See the intrinsicValue method for more information.
intrinsicValueDict()
→ dict
of str
to value
Returns a dictionary mapping intrinsic names to their values.
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 16
float tuple representing the transform to setIntrinsicValue
. Raises
Error
if the intrinsic is not writeable or does not accept the passed
value, or if the given intrinsic name does not exist.
Note
Modifying the geometry directly will lock the geometry’s parent node.
See the intrinsicValue method for more information.
intrinsicReadOnly(intrinsic_name)
→ bool
intrinsicSize(intrinsic_name)
→ int
preferredPrecision()
→ int
Returns the preferred computation precision of the geometry. This can be used to determine what sort of attributes to create and what precision to run intermediate computations in. Can be either 32 or 64.
setPreferredPrecision(int)
Adjusts the preferred precision of the geometry. The value should be either 32 or 64. Nodes may use this precision as a hint to set default attribute creation and computation to a certain precision.
Data Modification ¶
vexAttribDataId()
→ tuple of int
Return the same list of integers that the attribdataid VEX function
returns when calling attribdataid(geo, "meta", "detail")
. It is an
identifier that can be used as a conservative check whether there are any
modifications to this object. The value of
hou.Geometry.modificationCounter is included in the return value.
modificationCounter()
→ int
or long
Return a counter that can be used as a conservative check to determine if changes have been made to this object. Note that this counter is not unique across different hou.Geometry objects. To compare these values across different geometries, use hou.Geometry.vexAttribDataId instead.
incrementModificationCounter()
Increment the modification counter to mark this object as having its contents modified.
incrementAllDataIds()
Increment all data ids on attributes in this geometry. Use this as an easy way to mark that everything in this geometry has changed. Internally, this also calls hou.Geometry.incrementModificationCounter.
incrementDataIdsForAddOrRemove(for_points=True, for_prims=True)
Increment data ids which indicate that points and/or primitives have been added or removed.
primitiveIntrinsicsDataId()
Returns the data id that represents the contents of primitives, excluding primitive attributes. Note that this data id is also incremented whenever the number of primitives changes as well.
incrementPrimitiveIntrinsicsDataId()
Increment the primitive intrinsics data id to indicate that the contents of primitives have changed, excluding primitive attributes.
topologyDataId()
Returns the data id that represents the topology of this geometry such as when points are wired to primitives.
incrementTopologyDataId()
Increment data ids to indicate that topology in this geometry has changed in some way.
Averages ¶
pointBoundingBox(pointpattern)
→ hou.BoundingBox
Return an axis-aligned 3D bounding box that is sized and positioned to include the points specified by the point pattern. If the pattern is blank, all points will be included.
Some primitives, such as spheres, extend beyond their points. This extension will not be included.
primBoundingBox(primpattern)
→ hou.BoundingBox
Return an axis-aligned 3D bounding box that is sized and positioned to include the primitives specified by the primitive pattern. If the pattern is blank, all primitives will be included.
Some primitives, such as spheres, extend beyond their points. This extension will be included.
boundingBox(transform=None)
→ hou.BoundingBox
Return an axis-aligned 3D bounding box (of optionally transformed instantiation) that is sized and positioned to be large enough to hold this geometry.
transform
A hou.Matrix4 that transforms the geometry instance. Does not change the original geometry.
orientedBoundingBox()
→ hou.orientedBoundingBox
Return an oriented 3D bounding box that is sized and positioned to be large enough to hold this geometry.
orientedPointBoundingBox(pointpattern)
→ hou.OrientedBoundingBox
Return an oriented 3D bounding box that is sized and positioned to include the points specified by the point pattern. If the pattern is blank, all points will be included.
Some primitives, such as spheres, extend beyond their points. This extension will not be included.
orientedPrimBoundingBox(primpattern)
→ hou.OrientedBoundingBox
Return an oriented 3D bounding box that is sized and positioned to include the primitives specified by the primitive pattern. If the pattern is blank, all primitives will be included.
Some primitives, such as spheres, extend beyond their points. This extension will be included.
averageMinDistance(local_transform, geometry, geometry_transform)
→ float
Return the average over all points in ‹geometry› of the minimum distance to the point set of ‹self›
local_transform
A transform to be applied to all points in this geometry.
geometry
The geometry to find distances from.
geometry_transform
A transform to be applied to all points in ‹geometry›.
Raises hou.OperationFailed if ‹geometry› has no vertices.
query_geometry = query_node.geometry() queried_geometry = queried_node.geometry() # Return the average over all points in <queried_geometry> of the minimum # distance to the point set of <query_geometry> query_geometry.averageMinDistance( query_node.worldTransform(), queried_geometry, queried_node.worldTransform())
averageEdgeLength()
→ float
Return the average edge length of the mesh.
Raises hou.OperationFailed if mesh does not contain any edges.
# Return the average edge length. geo.averageEdgeLength()
Creation ¶
createPoint()
→ hou.Point
Create a new point located at (0, 0, 0) and return the corresponding hou.Point object. You would typically call this method from the code of a Python-defined SOP.
If the geometry contains point attributes, the new point receives the default values for those attributes.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
See hou.Geometry.addAttrib, hou.Geometry.createPolygon, and hou.Face.addVertex for examples.
createPoints(point_positions)
→ tuple
of hou.Point
Create a set of points located at the specified positions and return a tuple of the new hou.Point objects. You would typically call this method from the code of a Python-defined SOP.
point_positions
can be either a tuple of hou.Vector3 objects or a
tuple of 3-tuple floating point numbers. For example, if point_positions
is ((0, 1, 2), (1, 2, 3))
then this method will create 2 points with one
positioned at (0, 1, 2) and the other at (1, 2, 3).
If the geometry contains point attributes, the new points receive the default values for those attributes.
Raises hou.GeometryPermissionError if this geometry is not modifiable. Raises hou.InvalidSize if one of the specified point positions does not contain 3 values (for x, y, z).
See hou.Geometry.addAttrib, hou.Geometry.createPolygons, and hou.Face.addVertex for examples.
createPolygon(is_closed=True)
→ hou.Polygon
Create a new polygon and return the corresponding hou.Polygon object. You would typically call this method from the code of a Python-defined SOP.
The newly created polygon has no vertices. Use hou.Face.addVertex to add them. The polygon is also closed (see hou.Face.isClosed for more information) by default unless specified otherwise for a polygon curve.
If the geometry contains primitive attributes, the new polygon receives the default values for those attributes.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
geo = hou.pwd().geometry() poly = geo.createPolygon() for position in (0,0,0), (1,0,0), (0,1,0): point = geo.createPoint() point.setPosition(position) poly.addVertex(point)
See hou.Face.addVertex for a slightly more complicated example.
createPolygons(points, is_closed=True)
→ tuple
of hou.Polygon
Create a set of polygons with the specified points as vertices and return a tuple of the new hou.Polygon objects. You would typically call this method from the code of a Python-defined SOP.
points
can be either a tuple of tuples of hou.Point objects
or a tuple of tuples of integers representing the point numbers. For
example, if points
is ((0, 1, 2), (3, 4, 5, 6))
then this method will
create 2 polygons with one having points 0, 1 and 2 as its vertices and the
other one having points 3, 4, 5 and 6 as its vertices.
The created polygons are closed (see hou.Face.isClosed for more information) by default unless specified otherwise for polygon curves.
If the geometry contains primitive attributes, then the new polygons receive the default values for those attributes.
Raises hou.GeometryPermissionError if this geometry is not modifiable. Raises hou.InvalidSize if one of the specified point tuples does not contain at least 3 elements. Raises hou.InvalidInput if one of the point numbers or hou.Point objects do not exist in the geometry.
Example:
# Create 6 points in the geometry. geo = hou.pwd().geometry() point_positions = ( (1, 0, 0), (0, 1, 0), (0, 0, 1), (1, 1, 0), (1, 0, 1), (0, 1, 1), ) points = geo.createPoints(point_positions) # Create 2 polygons. # The first polygon uses the first 3 points in the geometry as its vertices. # The second polygon uses the last 3 points in the geometry as its vertices. polygons = geo.createPolygons( ((points[0], points[1], points[2]), (points[3], points[4], points[5])))
createTetrahedron()
→ hou.Prim
Create a new tetrahedron and return the corresponding hou.Prim object. You would typically call this method from the code of a Python-defined SOP.
The newly created tetrahedron has four vertices and new points have been allocated for them. To build a tetrahedron out of existing points, use hou.Geometry.createTetrahedronInPlace
Raises hou.GeometryPermissionError if this geometry is not modifiable.
createTetrahedronInPlace(p0, p1, p2, p3)
→ hou.Prim
Create a new tetrahedron and return the corresponding hou.Prim object. You would typically call this method from the code of a Python-defined SOP.
The newly created tetrahedron has four vertices and uses the points that have been passed into it.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
createHexahedron()
→ hou.Prim
Create a new hexahedron and return the corresponding hou.Prim object. You would typically call this method from the code of a Python-defined SOP.
The newly created hexahedron has eight vertices and new points have been allocated for them. To build a hexahedron out of existing points, use hou.Geometry.createHexahedronInPlace
Raises hou.GeometryPermissionError if this geometry is not modifiable.
createHexahedronInPlace(p0, p1, p2, p3, p4, p5, p6, p7)
→ hou.Prim
Create a new hexahedron and return the corresponding hou.Prim object. You would typically call this method from the code of a Python-defined SOP.
The newly created hexahedron has eight vertices and uses the points that have been passed into it.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
createNURBSCurve(num_vertices=4, is_closed=False, order=4)
→ hou.Face
Create a new NURBS with the specified number of vertices and return it. You would typically call this method from the code of a Python-defined SOP.
num_vertices
The number of verticies in the curve. A new point is added to the geometry for each vertex, and this point is located at the origin until you change its position. You can also add more vertices with hou.Face.addVertex.
The minimum number of vertices for a NURBS curve is identical to its order. So for the default order of 4, the curve must have a minimum of 4 vertices. If you specify too few vertices, this method raises hou.OperationFailed.
is_closed
Controls if the curve is open or closed; see hou.Face.isClosed for more information. If not specified, the resulting curve is open. This behavior is different from hou.Geometry.createPolygon, where the new polygon is closed. You can also open or close it with hou.Face.setIsClosed.
order
Specifies the curve’s order. The default order is 4, corresponding to a cubic NURBS curve. An order of 2, the lowest order, will give a curve with linear segments.
If the geometry contains primitive attributes, the new curve receives the default values for those attributes.
# This code will work from inside a Python SOP, but not from the Python # shell. geo = hou.pwd().geometry() curve = geo.createNURBSCurve(10) i = 0 for vertex in curve.vertices(): vertex.point().setPosition((i, i % 3, 0)) i = i + 1
Raises hou.GeometryPermissionError if this geometry is not modifiable.
See also:
createBezierCurve(num_points: 'int' = 4, is_closed: 'bool' = False, order: 'int' = 4)
→ hou.Face
Create a new Bezier curve with the specified number of vertices and return it. You would typically call this method from the code of a Python-defined SOP.
num_vertices
The number of verticies in the curve. A new point is added to the geometry for each vertex, and this point is located at the origin until you change its position. You can also add more vertices with hou.Face.addVertex.
is_closed
Controls if the curve is open or closed; see hou.Face.isClosed for more information. If not specified, the resulting curve is open. This behavior is different from hou.Geometry.createPolygon, where the new polygon is closed.
order
Specifies the curve’s order. The default order is 4, corresponding to a cubic Bezier curve. An order of 2, the lowest order, will give a curve with linear segments.
An open Bezier curve must have (order - 1) * n + 1
vertices for some
integer n>=1
(so valid values for order 4 curves are 4, 7, 10, etc.).
A closed Bezier curve must have (order - 1) * n
vertices (e.g. 3, 6, 9, etc.
for order 4 curve). This restriction does not apply to curves of order 2, however.
As a consequence, you cannot use hou.Face.setIsClosed on non-linear Bezier curves, since the number of vertices would need to change.
See hou.Geometry.createNURBSCurve for more information.
createNURBSSurface(rows, cols, is_closed_in_u=False, is_closed_in_v=False)
→ hou.Surface
Create a NURBS surface in the XY plane centered at the origin with size (1, 1) and return it. You would typically call this method from the code of a Python-defined SOP.
rows, cols
Determines the size of the 2D array of vertices defining the control points of the surface. The number of cols and rows in each direction, must be equal to or larger than the U and V orders, respectively.
is_closed_in_u, is_closed_in_v
Controls if the surface is open or closed in each of the U and V directions; see hou.Surface.isClosedInU for more information. If not specified, the default behavior is to build an open surface.
order_u, order_v
Specifies the surface’s order in each of the U and V directions. The default order for both is 4, corresponding to a cubic NURBS surface. An order of 2, the lowest order, will give a surface with linear segments, essentially a mesh.
If the geometry contains primitive attributes, the new surface receives the default values for those attributes.
You can move or resize the surface using hou.Geometry.transformPrims.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
Raises hou.OperationFailed if the number of rows and/or columns is invalid.
# This code will work from inside a Python SOP, but not from the Python # shell. geo = hou.pwd().geometry() # Create a surface with a 10x10 grid of vertices. surf = geo.createNURBSSurface(10, 10) # Initially, the center is at (0, 0, 0), size is (1, 1, 1), on the XY # plane. Scale to (20, 10) and rotate into the XZ plane. geo.transformPrims((surf,), hou.hmath.buildScale((20, 10, 1)) * hou.hmath.buildRotateAboutAxis((1, 0, 0), 90))
See also:
createBezierSurface(rows, cols, is_closed_in_u=False, is_closed_in_v=False)
→ hou.Surface
Create a Bezier surface in the XY plane centered at the origin with size (1, 1) and return it. You would typically call this method from the code of a Python-defined SOP.
rows, cols
Determines the size of the 2D array of vertices defining the control points of the surface.
Note that the number of rows corresponds to v
and the number or
columns corresponds to u
, which can be slightly confusing. For
example, geo.createBezierSurface(9, 7, is_closed_in_u=False, is_closed_in_v=True)
is valid, but geo.createBezierSurface(9, 7, is_closed_in_u=True, is_closed_in_v=False)
raises hou.OperationFailed.
is_closed_in_u, is_closed_in_v
Determines if it is open or closed in each of the u
and v
directions; see hou.Surface.isClosedInU for more information.
order_u, order_v
Specifies the surface’s order in of the U and V directions. The default order for both is 4, corresponding to a cubic NURBS surface. An order of 2, the lowest order, will give a surface with linear segments, essentially a mesh.
As with Bezier curves, a Bezier surface has some restrictions on the point
count in each of the U and V directions. For a given direction; if it’s
open the number of points in the direction must be (order - 1) * n + 1
for some integer n >= 1
(e.g. 4, 7, 10, …). If it’s open, the number of
points must be (order - 1) * n
where n >= 1
in that direction (e.g.
2, 4, 6, .. for order 3).
You can move or resize the surface using hou.Geometry.transformPrims.
If the geometry contains primitive attributes, the new surface receives the default values for those attributes.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
import math # This code will work from inside a Python SOP, but not from the Python # shell. geo = hou.pwd().geometry() # Build a tube-like object about the y axis. num_rows, num_cols = (10, 9) surf = geo.createBezierSurface(num_rows, num_cols, is_closed_in_u=True) for v_index in range(num_rows): for u_index in range(num_cols): angle = u_index * (2.0 * math.pi) / num_cols surf.vertex(u_index, v_index).point().setPosition( (math.cos(angle), v_index / float(num_cols-1), math.sin(angle)))
createMeshSurface(rows, cols, is_closed_in_u=False, is_closed_in_v=False)
→ hou.Surface
Create a quadrilateral mesh surface in the XY plane centered at the origin with size (1, 1) and return it. You would typically call this method from the code of a Python-defined SOP.
Note that a mesh object is not the same as a set of polygons defining the same shape. A mesh object is a single primitive.
See hou.Geometry.createNURBSSurface for more information.
createVolume(xres, yres, zres, bounding_box=None)
→ hou.Volume
Given the x, y, and z resolution (or size) of a voxel array, add a new volume primitive to the geometry and return it. The values in the new volume’s voxels are all zero.
xres, yres, zres
Integers greater than zero that specify the size of the voxel array in one dimension. Raises hou.OperationFailed if any of these values are not positive.
bounding_box
A hou.BoundingBox that specifies the volume’s 3D size. Note that this size is independent of the volume’s voxel resolution. If this parameter is None, Houdini uses a bounding box going from (-1,-1,-1) to (1,1,1).
createChannelPrim()
→ hou.ChannelPrim
Creates and adds a new channel primitive to the geometry and returns it. The new channel primitive is initialized to an empty channel.
createPacked(typename, point=None)
→ hou.PackedPrim
typename
A string containing the name of a type of packed primitive.
Typical examples are "PackedDisk"
(on-disk geometry file)
or "AlembicRef"
(Alembic file).
To see a complete list of possible typename
values,
run ginfo -P
on a Houdini tools command line.
point
See hou.PackedPrim for more information.
createPackedGeometry(geo, point=None)
→ hou.PackedPrim
Create a geometry packed primitive that uses the given embedded geometry.
geo
hou.Geometry object to create PackedGeometry primitive with
point
See hou.PackedPrim for more information.
Deletion ¶
deletePrims(prims, keep_points=False)
Delete a sequence of primitives. You would typically call this method from the code of a Python-defined SOP.
prims
A list of hou.Prim objects or hou.PrimGroup to delete with.
keep_points
If True
, the primitive will be deleted but its points will remain.
To delete a single primitive, pass in a sequence with one primitive.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
# Delete every other primitive: prims = [p for p in geo.prims() if p.number() % 2 == 0] geo.deletePrims(prims) # Delete the first primitive: geo.deletePrims([geo.iterPrims()[0]])
deletePrimsOutsideBoundingBox(bbox)
Delete primitives who’s bounding boxes are entirely outside of the specified bounding box.
Also deletes points associated with the deleted primitives.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
deletePoints(points)
Delete a sequence of points. You would typically call this method from the code of a Python-defined SOP.
Note that Houdini will delete any vertices that reference the point. For example, suppose you have a box with 6 polygons, each with 4 vertices. Also suppose that each point on the box is shared by 3 vertices on 3 separate polygons. If you delete one of those points, Houdini will remove each of those vertices from their corresponding polygons, leaving 3 polygons with 4 vertices and 3 polygons with 3 vertices.
To delete a single primitive, pass in a sequence with one point.
points
A list of hou.Point objects or hou.PointGroup to delete with.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
Groups ¶
findPointGroup(name, scope=hou.groupScope.Public)
→ hou.PointGroup or None
Return the point group with the given name, or None
if no such group
exists.
name
The name of the point group.
scope
A hou.groupScope value to specify whether the group is public or private.
pointGroups(scope=hou.groupScope.Public)
→ tuple
of hou.PointGroup
Return a tuple of all the point groups in the geometry.
scope
A hou.groupScope value to specify whether the public or private groups should be listed.
The following function returns the names of all the groups in the geometry:
def pointGroupNames(geometry): return [group.name() for group in geometry.pointGroups()]
createPointGroup(name, is_ordered=False, unique_name=False)
→ hou.PointGroup
Create a new point group in this geometry.
name
The name of the new group. Raises hou.OperationFailed if a group with this name already exists.
is_ordered
Whether or not the new group should be ordered. See hou.PointGroup for more information about ordered groups.
unique_name
By default, an exception is thrown if the given group already exists. If ‹unique_name› is set to True, then the name will instead be modified to a non-existing name based on ‹name›.
Use hou.PointGroup.destroy to remove a point group from the geometry.
Note
Group names cannot start with a digit and can only contain alphanumeric characters or underscores.
findPrimGroup(name, scope=hou.groupScope.Public)
→ hou.PrimGroup or None
Return the primitive group with the given name, or None
if no such group
exists.
name
The name of the primitive group.
scope
A hou.groupScope value to specify whether the group is public or private.
primGroups(scope=hou.groupScope.Public)
→ tuple
of hou.PrimGroup
Return a tuple of all the primitive groups in the geometry.
scope
A hou.groupScope value to specify whether the public or private groups should be listed.
createPrimGroup(name, is_ordered=False, unique_name=False)
→ hou.PrimGroup
Create a new primitive group in this geometry.
name
The name of the new group. Raises hou.OperationFailed if a group with this name already exists.
is_ordered
Whether or not the new group should be ordered. See hou.PrimGroup for more information about ordered groups.
unique_name
By default, an exception is thrown if the given group already exists. If ‹unique_name› is set to True, then the name will instead be modified to a non-existing name based on ‹name›.
Use hou.PrimGroup.destroy to remove a primitive group from the geometry.
Note
Group names cannot start with a digit and can only contain alphanumeric characters or underscores.
findEdgeGroup(name, scope=hou.groupScope.Public)
→ hou.EdgeGroup or None
name
The name of the edge group.
scope
A hou.groupScope value to specify whether the group is public or private.
Return the edge group with the given name, or None
if no such group
exists.
edgeGroups(scope=hou.groupScope.Public)
→ tuple
of hou.EdgeGroup
Return a tuple of all the edge groups in the geometry.
scope
A hou.groupScope value to specify whether the public or private groups should be listed.
createEdgeGroup(name)
→ hou.EdgeGroup
Create a new edge group in this geometry.
name
The name of the new group. Raises hou.OperationFailed if a group with this name already exists.
Use hou.EdgeGroup.destroy to remove an edge group from the geometry.
findVertexGroup(name, scope=hou.groupScope.Public)
→ hou.VertexGroup or None
Return the vertex group with the given name, or None
if no such group
exists.
name
The name of the vertex group.
scope
A hou.groupScope value to specify whether the group is public or private.
vertexGroups(scope=hou.groupScope.Public)
→ tuple
of hou.VertexGroup
Return a tuple of all the vertex groups in the geometry.
scope
A hou.groupScope value to specify whether the public or private groups should be listed.
The following function returns the names of all the groups in the geometry:
def vertexGroupNames(geometry): return [group.name() for group in geometry.vertexGroups()]
createVertexGroup(name, is_ordered=False)
→ hou.VertexGroup
Create a new vertex group in this geometry.
name
The name of the new group. Raises hou.OperationFailed if a group with this name already exists.
is_ordered
Whether or not the new group should be ordered. See hou.VertexGroup for more information about ordered groups.
Use hou.VertexGroup.destroy to remove a vertex group from the geometry.
generateGroupMenu(group_types=None, include_selection=True, include_name_attrib=True, case_sensitive=True, pattern="*", decode_tokens=False, parm=None)
→ tuple
of str
Generates the tokens and labels for a parameter menu listing the geometry’s groups.
group_types
A hou.geometryType value (or sequence of hou.geometryType) specifying the component types to list groups for.
The default value of None
will list all point, primitive, and edge groups.
include_selection
Includes the current component selection in the group menu, if this geometry is from a SOP.
include_name_attrib
If a primitive name
attribute exists, includes the unique names in the menu (for example, @name=piece2
).
case_sensitive
Specifies whether the menu labels are produced in a case-sensitive order.
This also controls whether the pattern
is treated as case-sensitive.
pattern
Specifies a pattern of group names that should be included.
decode_tokens
If enabled, the menu tokens will contain the decoded group names rather than the actual group names. This can be useful for parameters that support matching against decoded group names.
parm
Optionally specifies the hou.Parm for which the menu is being generated. The parameter’s current group string is used to indicate which groups have already been toggled on.
Freezing ¶
freeze(read_only=False, clone_data_ids=False)
→ hou.Geometry
Return another Geometry object that is not linked to a particular SOP.
Normally, when you call hou.SopNode.geometry, the resultant Geometry object retains a reference to that SOP, and is said to be unfrozen. Each time you access points, primitives, attributes, etc. in an unfrozen Geometry object, Houdini uses the SOP’s latest cooked geometry. So, if you change parameters or change the time for an animated SOP, the Geometry object will update to the SOP’s new geometry.
Unless Python SOPs are involved, a frozen Geometry object does not have a similar live association with a particular SOP. If you ask a SOP for its geometry and then store a frozen copy of that geometry, when the SOP recooks the frozen Geometry object will not update. Instead, the frozen geometry saves its own copy of the point and primitive data, and is unaffected by subsequent changes to the SOP. When a frozen Geometry object is destroyed, any geometry copy it created is also destroyed.
Note that accessing a Geometry object’s points, primitives, attributes, etc. may be faster when dealing with frozen objects. You may want to work with frozen Geometry in speed-sensitive operations.
Calling this method on an unfrozen Geometry object returns a frozen one. Calling it on a frozen object has no effect, and it returns a frozen object.
When a Python-defined SOP cooks and runs Python code that asks for the SOP’s geometry, the returned Geometry object is writable. Modifying this Geometry object affects the output of this SOP. For efficiency, this geometry object is already frozen, so calling freeze on it has no effect.
read_only
If True, the resulting frozen geometry will be read-only. Use read-only frozen geometry to share embedded geometry among multiple packed primitives.
clone_data_ids
If the conditions of this method causes a copy of the geometry to be made, then this specifies whether the new copy will have the same data ids. This is useful to enable optimizations that cache data by only looking at the attribute data id regardless of whether it is from the same geometry object or not. Otherwise, the new copy will have data ids that are unique.
isReadOnly()
→ bool
Return true if the geometry is read-only.
Nodes ¶
sopNode()
→ hou.SopNode
If the Geometry is not frozen, return the hou.SopNode object corresponding to this Geometry. Otherwise, return None.
See hou.Geometry.freeze for more information on frozen geometry.
sopNodeOutputIndex()
→ int
If the Geometry is not frozen, return the index of the SOP node output that this geometry corresponds to. Otherwise, return -1.
For most cases this method will return 0 to indicate that the geometry corresponds to the first output. This method will only return a value other than 0 for SOP nodes that have multiple outputs.
See hou.Geometry.freeze for more information on frozen geometry.
Points ¶
points()
→ tuple
of hou.Point
Return a tuple of all the points in the geometry.
See also the hou.Geometry.iterPoints method.
iterPoints()
→ generator of hou.Point
Return a generator that iterates through all the points in the geometry.
Whereas hou.Geometry.points allocates and returns a tuple of all the points in the geometry, this method returns a generator object that will allocate hou.Point objects on demand. This object is very fast at random access into the sequence.
If you're accessing a specific point by index and the geometry contains many
points, it is faster to use iterPoints()
than points()
. If, however, you
are iterating over all the points in the geometry, it is generally faster
to use points()
than iterPoints()
.
# This is preferred: geo.iterPoints()[23] # over this: geo.points()[23] # But this is preferred: for point in geo.points(): ...process point... # over this: for point in geo.iterPoints(): ...process point...
globPoints(pattern, ordered=False)
→ tuple
of hou.Point
Return a tuple of points corresponding to a pattern of point numbers.
The pattern format is the same one used by the group fields on SOP nodes that take point selections. Elements in the pattern are separated by spaces, and elements can be point numbers, point number ranges, or group names.
Optionally, the points can be returned in the order they were added to the group.
This method can be useful when writing a Python SOP that works on only a selected set of points.
Raises hou.OperationFailed if the pattern is not valid or if it refers to a group that does not exist. Note that an empty pattern is considered to be invalid. Numbers that do not refer to valid points are not errors, and simply do not match points.
# Return a tuple containing points 5 and 7. geo.globPoints("5 7") # Return a tuple containing points 5 to 10. geo.globPoints("5-10") # Return a tuple containing all the points in the pointgroup called group1. geo.globPoints("group1") # Return all the points except those from 0 to 98. geo.globPoints("!0-98") # Return points 5, 10 to 20, and those in group1. geo.globPoints("5 group1 10-20")
The following Python SOP example is behaves similarly to the Point sop.
# This code will work from inside a Python SOP, but not from the Python # shell. It assumes the Python sop has the following parm tuples: # group: A string containing which points to affect # t: A set of 3 floats that behaves like the point sop's position # parameter. Set these parameters to the expressions ($TX, $TY, $TZ). geo = hou.pwd().geometry() # Use the group field to determine which points to affect. If it's blank, # operate on all points. pattern = hou.ch("group") if pattern == "": points = geo.points() else: points = geo.globPoints(pattern) # Loop through the points, setting the SOP's current point as we go. # Then evaluate the t parm tuple, so it can use the current point (e.g. # with hscript's $TX or Python's pwd().curPoint()). for point in points: hou.pwd().setCurPoint(point) new_position = hou.pwd().evalParmTuple("t") point.setPosition(new_position)
point(index)
→ hou.Point
Return the point at the specified index.
This is a convenience method for accessing a particular point without the overhead of obtaining all points via hou.Geometry.points.
Return None if no such point at the specified index exists.
nearestPoint(position, ptgroup=None, max_radius=1E18)
→ hou.Point or None
Given a sequence of three floats containing a query position, find the
closest point in the geometry to that position within max_radius
.
If ptgroup is a string group pattern, then the search will be restricted to the points specified.
Note that None
is returned when there are no points in the geometry.
See also: hou.nearestPoints
nearestPoints(position, max_points, ptgroup=None, max_radius=1E18)
→ tuple
of hou.Point
Given a sequence of three floats containing a query position, find the
closest max_points
in the geometry to that position within max_radius
.
If ptgroup is a string group pattern, then the search will be restricted to the points specified.
Note that None
is returned when there are no points in the geometry.
See also: hou.nearestPoint
pointFloatAttribValues(name)
→ tuple
of float
Return a tuple of floats containing one attribute’s values for all the points.
This method only works on int or float attributes. If the attribute
contains more than one element, each point will correspond to multiple
values in the result. For example, if Cd
is a float attribute of size 3
and there are 3 points with values (0.1, 0.2, 0.3), (0.5, 0.5, 0.5), and
(0.8, 0.7, 0.6) then the result will be (0.1, 0.2, 0.3, 0.5, 0.5, 0.5, 0.8,
0.7, 0.6).
Calling this method is faster than looping over all the points and calling hou.Point.attribValue.
If the attribute name is invalid or the attribute is not an int or float (e.g. it’s a string attribute), this method raises hou.OperationFailed.
Note that you cannot pass a hou.Attrib object to this method like you can with many methods dealing with attributes. However, you can use hou.Attrib.name to easily get the name from an Attrib object.
pointFloatAttribValuesAsString(name, float_type=hou.numericData.Float32)
→ str
for Python 2, bytes
for Python 3
Return a binary string representation of the floats of
one attribute’s value for all the points. This method is faster than
hou.Geometry.pointFloatAttribValues, and you can use the array
module to convert the string into a Python sequence.
The returned binary string is a bytes
object in Python 3 and a str
object in Python 2. See HOM binary data for
more information.
float_type
A hou.numericData value to specify the float data type (either Float16, Float32 or Float64).
This method provides a faster implementation of the following:
import array def pointFloatAttribValuesAsString(self, name): return array.array("f", self.pointFloatAttribValues(name)).tostring()
You can convert the return value from this method to an array using the following method:
import array def pointFloatAttribValuesAsArray(geometry, name): a = array.array("f") a.fromstring(geometry.pointFloatAttribValuesAsString(name)) return a
See hou.Geometry.pointFloatAttribValues for more information.
setPointFloatAttribValues(name, values)
For a particular attribute, set the attribute values for all points. You would typically call this method from the code of a Python-defined SOP.
name
The name of the point attribute.
values
A sequence of int or float values in the same format as that returned by hou.Geometry.pointFloatAttribValues. See that method for more information.
Raises hou.OperationFailed if the attribute name is not valid, the attribute is not an int or float (i.e. it’s a string), or the array of values is not the correct size.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
Also see hou.Geometry.pointFloatAttribValues.
setPointFloatAttribValuesFromString(name, values, float_type=hou.numericData.Float32)
For a particular attribute, set the attribute values for all points from a string representation of a sequence of the specified float_type values. This method is faster than hou.Geometry.setPointFloatAttribValues.
Note that this method can accept more types that just a string: it can
receive any Python object that supports the buffer interface. In
particular, arrays from the array
and numpy
Python modules are
supported, so there is no need to first construct strings from those
arrays.
float_type
A hou.numericData value to specify the float data type (either Float16, Float32 or Float64).
Raises hou.OperationFailed if the length of the string is not
len(self.iterPoints() * byte_size_of_float_type)
.
See hou.Geometry.setPointFloatAttribValues and hou.Geometry.pointFloatAttribValuesAsString for more information.
The following example function accepts an array.array("f")
and sets
the attribute values to its contents:
def setPointFloatAttribValuesFromArray(geometry, arr): assert(arr.typecode == "f") geometry.setPointFloatAttribValuesFromString(arr))
pointIntAttribValues(name)
→ tuple
of int
Return a tuple of integers containing one attribute’s values for all the points.
This method only works on int or float attributes. If the attribute contains more than one element, each point will correspond to multiple values in the result. For example, if “idmap” is an integer attribute of size 2 and there are 3 points with values (1, 2), (2, 3), and (3, 4) then the result will be (1, 2, 2, 3, 3, 4).
Calling this method is faster than looping over all the points and calling hou.Point.attribValue.
If the attribute name is invalid or the attribute is not an int or float (e.g. it’s a string attribute), this method raises hou.OperationFailed.
Note that you cannot pass a hou.Attrib object to this method like you can with many methods dealing with attributes. However, you can use hou.Attrib.name to easily get the name from an Attrib object.
pointIntAttribValuesAsString(name, int_type=hou.numericData.Int32)
→ str
for Python 2, bytes
for Python 3
Return a binary string representation of the integers
of one attribute’s value for all the points. This method is faster than
hou.Geometry.pointIntAttribValues, and you can use the array
module
to convert the string into a Python sequence.
The returned binary string is a bytes
object in Python 3 and a str
object in Python 2. See HOM binary data for
more information.
int_type
A hou.numericData value to specify the integer data type (either Int8, Int16, Int32 or Int64).
This method provides a faster implementation of the following:
import array def pointIntAttribValuesAsString(self, name): return array.array("i", self.pointIntAttribValues(name)).tostring()
You can convert the return value from this method to an array using the following method:
import array def pointIntAttribValuesAsArray(geometry, name): a = array.array("i") a.fromstring(geometry.pointIntAttribValuesAsString(name)) return a
See hou.Geometry.pointIntAttribValues for more information.
setPointIntAttribValues(name, values)
For a particular attribute, set the attribute values for all points. You would typically call this method from the code of a Python-defined SOP.
name
The name of the point attribute.
values
A sequence of int or float values in the same format as that returned by hou.Geometry.pointIntAttribValues. See that method for more information.
Raises hou.OperationFailed if the attribute name is not valid, the attribute is not an int or float (i.e. it’s a string), or the array of values is not the correct size.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
Also see hou.Geometry.pointIntAttribValues.
setPointIntAttribValuesFromString(name, values, int_type=hou.numericData.Int32)
For a particular attribute, set the attribute values for all points from a string representation of a sequence of the specified int_type values. This method is faster than hou.Geometry.setPointIntAttribValues.
Note that this method can accept more types that just a string: it can
receive any Python object that supports the buffer interface. In
particular, arrays from the array
and numpy
Python modules are
supported, so there is no need to first construct strings from those
arrays.
int_type
A hou.numericData value to specify the integer data type (either Int8, Int16, Int32 or Int64).
Raises hou.OperationFailed if the length of the string is not
len(self.iterPoints() * byte_size_of_int_type)
.
See hou.Geometry.setPointIntAttribValues and hou.Geometry.pointIntAttribValuesAsString for more information.
The following example function accepts an array.array("i")
and sets
the attribute values to its contents, assuming sizeof(signed int) == 4:
def setPointIntAttribValuesFromArray(geometry, arr): assert(arr.typecode == "i") geometry.setPointIntAttribValuesFromString(arr))
pointStringAttribValues(name)
→ tuple
of str
Return a tuple of strings containing one attribute’s values for all the points.
This method only works on string attributes. If the attribute contains more than one element, each point will correspond to multiple values in the result. For example, if “strmap” is a string attribute of size 2 and there are 3 points with values (“apple”, “orange”), (“red”, “blue”), and (“one”, “two”) then the result will be (“apple”, “orange”, “red”, “blue”, “one”, “two”).
Calling this method is faster than looping over all the points and calling hou.Point.attribValue.
If the attribute name is invalid or the attribute is not a string attribute then this method raises hou.OperationFailed.
Note that you cannot pass a hou.Attrib object to this method like you can with many methods dealing with attributes. However, you can use hou.Attrib.name to easily get the name from an Attrib object.
setPointStringAttribValues(name, values)
For a particular attribute, set the attribute values for all points. You would typically call this method from the code of a Python-defined SOP.
name
The name of the point attribute.
values
A sequence of string values in the same format as that returned by hou.Geometry.pointStringAttribValues. See that method for more information.
Raises hou.OperationFailed if the attribute name is not valid, the attribute is not a string, or the array of values is not the correct size.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
Also see hou.Geometry.pointStringAttribValues.
Edges ¶
findEdge(p0, p1)
→ hou.Edge
p0
The first point that makes up the edge. See hou.Point for more information.
p1
The second point that makes up the edge. See hou.Point for more information.
finds an edge given two points, or None
if no such edge exists
globEdges(pattern)
→ tuple
of hou.Edge
Return a tuple of edges corresponding to an edge pattern.
The pattern format is the same one used by the group fields on SOP nodes that take edge selections. See hou.Geometry.globPoints for more information.
Primitives ¶
nearestPrim(position)
→ (hou.Prim or None
, float
, float
, float
)
Given a sequence of three floats containing a position, find the location on the primitive closest to that position and return a tuple containing that primitive, the u value on the primitive, the v value on the primitive, and the distance to the primitive.
Note that the first value in the return tuple can be None if there are no primitives in the geometry.
NOTE: The returned UVs are in real coordinates, use the hou.Prim.primuvConvert to switch to unit coordinates to match VEX’s xyzdist.
prims()
→ tuple
of hou.Prim
Return a tuple of all the primitives in the geometry. The primitives returned will be subclasses of hou.Prim (e.g.polygons, volumes, etc.).
See also:
iterPrims()
→ generator of hou.Prim
Return a generator that iterates through all the primitives in the geometry.
Whereas hou.Geometry.prims allocates and returns a tuple of all the primitives in the geometry, this method returns a generator object that will yield hou.Prim objects on demand. This object is very fast at random access into the sequence.
If you're accessing a specific primitive by index and the geometry contains
many primitives, it is faster to use iterPrims()
than prims()
. If, however,
you are iterating over all the primitives in the geometry, it is generally
faster to use prims()
than iterPrims()
.
# This is preferred: geo.iterPrims()[23] # over this: geo.prims()[23] # But this is preferred: for prim in geo.prims(): ...process prim... # over this: for prim in geo.iterPrims(): ...process prim...
See also the hou.Geometry.prims method.
primsOfType(primtype)
→ tuple
of hou.Prim
Return a tuple of the primitives of the specified type in the geometry. The primitives returned will be subclasses of hou.Prim (e.g.polygons, volumes, etc.).
iterPrimsOfType(primtype)
→ generator of hou.Prim
Return a generator that iterates through all the primitives of the specified type in the geometry.
See also the hou.Geometry.prims and hou.Geometry.iterPrims methods.
globPrims(pattern)
→ tuple
of hou.Prim
Return a tuple of primitives corresponding to a pattern of primitive numbers.
The pattern format is the same one used by the group fields on SOP nodes that take primitive selections. See hou.Geometry.globPoints for more information.
prim(index)
→ hou.Prim
Return the primitive at the specified index.
This is a convenience method for accessing a particular primitive without the overhead of obtaining all primitives via hou.Geometry.prims.
Return None if no such primitive at the specified index exists.
containsPrimType(type_or_name)
→ bool
Returns whether the geometry contains at least one primitive of the specified type.
type_or_name
A hou.primType, or a string containing the name of a primitive type.
Typical examples of string values are "Poly"
(polygon) or
"PackedAgent"
(agent packed primitive).
To see a complete list of possible typename
values, run ginfo -P
on
a Houdini tools command line.
countPrimType(type_or_name)
→ long
Returns the number of primitives of the specified type in the geometry.
type_or_name
A hou.primType, or a string containing the name of a primitive type.
Typical examples of string values are "Poly"
(polygon) or
"PackedAgent"
(agent packed primitive).
To see a complete list of possible typename
values, run ginfo -P
on
a Houdini tools command line.
countUnusedPoints()
→ long
Returns the number of points in the geometry that are not part of any primitive.
primFloatAttribValues(name)
→ tuple
of float
Return a tuple of floats containing one attribute’s values for all the primitives.
This method only works on int or float attributes. If the attribute
contains more than one element, each primitive will correspond to multiple
values in the result. For example, if Cd
is a float attribute of size 3
and there are 3 primitives with values (0.1, 0.2, 0.3), (0.5, 0.5, 0.5), and
(0.8, 0.7, 0.6) then the result will be (0.1, 0.2, 0.3, 0.5, 0.5, 0.5, 0.8,
0.7, 0.6).
Calling this method is faster than looping over all the primitives and calling hou.Prim.attribValue.
If the attribute name is invalid or the attribute is not an int or float (e.g. it’s a string attribute), this method raises hou.OperationFailed.
Note that you cannot pass a hou.Attrib object to this method like you can with many methods dealing with attributes. However, you can use hou.Attrib.name to easily get the name from an Attrib object.
primFloatAttribValuesAsString(name)
→ str
for Python 2, bytes
for Python 3
Return a binary string representation of the floats of
one attribute’s value for all the primitives. This method is faster than
hou.Geometry.primFloatAttribValues, and you can use the array
module to convert the string into a Python sequence.
The returned binary string is a bytes
object in Python 3 and a str
object in Python 2. See HOM binary data for
more information.
This method provides a faster implementation of the following:
import array def primFloatAttribValuesAsString(self, name): return array.array("f", self.primFloatAttribValues(name)).tostring()
You can convert the return value from this method to an array using the following method:
import array def primFloatAttribValuesAsArray(geometry, name): a = array.array("f") a.fromstring(geometry.primFloatAttribValuesAsString(name)) return a
See hou.Geometry.primFloatAttribValues for more information.
setPrimFloatAttribValues(name, values)
For a particular attribute, set the attribute values for all primitives. You would typically call this method from the code of a Python-defined SOP.
name
The name of the primitive attribute.
values
A sequence of int or float values in the same format as that returned by hou.Geometry.primFloatAttribValues. See that method for more information.
Raises hou.OperationFailed if the attribute name is not valid, the attribute is not an int or float (i.e. it’s a string), or the array of values is not the correct size.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
Also see hou.Geometry.primFloatAttribValues.
setPrimFloatAttribValuesFromString(name, values, float_type=hou.numericData.Float32)
For a particular attribute, set the attribute values for all primitives from a string representation of a sequence of the specified float_type values. This method is faster than hou.Geometry.setPrimFloatAttribValues.
Note that this method can accept more types that just a string: it can
receive any Python object that supports the buffer interface. In
particular, arrays from the array
and numpy
Python modules are
supported, so there is no need to first construct strings from those
arrays.
float_type
A hou.numericData value to specify the float data type (either Float16, Float32 or Float64).
Raises hou.OperationFailed if the length of the string is not
len(self.iterPrims() * byte_size_of_float_type)
.
See hou.Geometry.setPrimFloatAttribValues and hou.Geometry.primFloatAttribValuesAsString for more information.
The following example function accepts an array.array("f")
and sets
the attribute values to its contents:
def setPrimFloatAttribValuesFromArray(geometry, arr): assert(arr.typecode == "f") geometry.setPrimFloatAttribValuesFromString(arr)
primIntAttribValues(name)
→ tuple
of int
Return a tuple of integers containing one attribute’s values for all the primitives.
This method only works on int or float attributes. If the attribute
contains more than one element, each primitive will correspond to multiple
values in the result. For example, if idmap
is an integer attribute of
size 2 and there are 3 primitives with values (1, 2), (2, 3), and (3,4)
then the result will be (1, 2, 2, 3, 3, 4).
Calling this method is faster than looping over all the primitives and calling hou.Prim.attribValue.
If the attribute name is invalid or the attribute is not an int or float (e.g. it’s a string attribute), this method raises hou.OperationFailed.
Note that you cannot pass a hou.Attrib object to this method like you can with many methods dealing with attributes. However, you can use hou.Attrib.name to easily get the name from an Attrib object.
primIntAttribValuesAsString(name, int_type=hou.numericData.Int32)
→ str
for Python 2, bytes
for Python 3
Return a binary string representation of the integers
of one attribute’s value for all the primitives. This method is faster
than hou.Geometry.primFloatAttribValues, and you can use the array
module to convert the string into a Python sequence.
The returned binary string is a bytes
object in Python 3 and a str
object in Python 2. See HOM binary data for
more information.
int_type
A hou.numericData value to specify the integer data type (either Int8, Int16, Int32 or Int64).
This method provides a faster implementation of the following:
import array def primIntAttribValuesAsString(self, name): return array.array("i", self.primIntAttribValues(name)).tostring()
You can convert the return value from this method to an array using the following method:
import array def primIntAttribValuesAsArray(geometry, name): a = array.array("i") a.fromstring(geometry.primIntAttribValuesAsString(name)) return a
See hou.Geometry.primIntAttribValues for more information.
setPrimIntAttribValues(name, values)
For a particular attribute, set the attribute values for all primitives. You would typically call this method from the code of a Python-defined SOP.
name
The name of the primitive attribute.
values
A sequence of int or float values in the same format as that returned by hou.Geometry.primFloatAttribValues. See that method for more information.
Raises hou.OperationFailed if the attribute name is not valid, the attribute is not an int or float (i.e. it’s a string), or the array of values is not the correct size.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
Also see hou.Geometry.primIntAttribValues.
setPrimIntAttribValuesFromString(name, values, int_type=hou.numericData.Int32)
For a particular attribute, set the attribute values for all primitives from a string representation of a sequence of the specified int_type values. This method is faster than hou.Geometry.setPrimIntAttribValues.
Note that this method can accept more types that just a string: it can
receive any Python object that supports the buffer interface. In
particular, arrays from the array
and numpy
Python modules are
supported, so there is no need to first construct strings from those
arrays.
int_type
A hou.numericData value to specify the integer data type (either Int8, Int16, Int32 or Int64).
Raises hou.OperationFailed if the length of the string is not
len(self.iterPrims() * byte_size_of_int_type)
.
See hou.Geometry.setPrimIntAttribValues and hou.Geometry.primIntAttribValuesAsString for more information.
The following example function accepts an array.array("i")
and sets
the attribute values to its contents, assuming sizeof(signed int) == 4:
def setPrimIntAttribValuesFromArray(geometry, arr): assert(arr.typecode == "i") geometry.setPrimIntAttribValuesFromString(arr)
primStringAttribValues(name)
→ tuple
of str
Return a tuple of strings containing one attribute’s values for all the primitives.
This method only works on string attributes. If the attribute contains more than one element, each primitive will correspond to multiple values in the result. For example, if “strmap” is a string attribute of size 2 and there are 3 primitives with values (“apple”, “orange”), (“red”, “blue”), and (“one”, “two”) then the result will be (“apple”, “orange”, “red”, “blue”, “one”, “two”).
Calling this method is faster than looping over all the primitives and calling hou.Prim.attribValue.
If the attribute name is invalid or the attribute is not a string attribute) then this method raises hou.OperationFailed.
Note that you cannot pass a hou.Attrib object to this method like you can with many methods dealing with attributes. However, you can use hou.Attrib.name to easily get the name from an Attrib object.
setPrimStringAttribValues(name, values)
For a particular attribute, set the attribute values for all primitives. You would typically call this method from the code of a Python-defined SOP.
name
The name of the primitive attribute.
values
A sequence of string values in the same format as that returned by hou.Geometry.primStringAttribValues. See that method for more information.
Raises hou.OperationFailed if the attribute name is not valid, the attribute is not a string, or the array of values is not the correct size.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
Also see hou.Geometry.primStringAttribValues.
intersect(ray_origin, ray_direction, position_out, normal_out, uvw_out, pattern=None, min_hit=0.01, max_hit=1E18, tolerance=0.01)
→ int
Determines the intersection point of a ray with the geometry in this object.
Note
This method is unusual in that instead of returning multiple pieces of information about the intersection, it requires that you pass it objects which it modifies in-place with the information.
# Get some geometry from a SOP node geometry = hou.node("/obj/geo1/sphere1").geometry() # Shoot a ray from high up in the "sky" straight down at the origin origin = hou.Vector3(0, 100, 0) direction = hou.Vector3(0, -1, 0) # Make objects for the intersect() method to modify position = hou.Vector3() normal = hou.Vector3() uvw = hou.Vector3() # Find the first intersection (if it exists) did_intersect = geometry.intersect(origin, direction, position, normal, uvw)
Returns the ID number of the hit primitive if the ray intersected the geometry, or -1
if the ray did not hit.
ray_origin
A hou.Vector3 object representing the starting point of the ray in world space.
ray_direction
A hou.Vector3 object representing the direction vector of the ray.
position_out
Pass a hou.Vector3 object to this argument. The method will change the object’s values to represent the intersection position in world space.
normal_out
Pass a hou.Vector3 object to this argument. The method will change the object’s values to represent the normal direction from the surface to the ray.
uvw_out
Pass a hou.Vector3 object to this argument. The method will change the object’s values to represent the UVW position within the intersecting primitive where the ray hit.
pattern
If you pass a string containing primitive group syntax, the ray can only intersect primitives that match the pattern.
min_hit
Ignore intersections closer than this distance.
You can use the min_hit
argument to iterate through all possible hits along the ray, by setting the min_hit
a tiny bit farther than the previous hit.
hit_positions = [] prev_dist = 0.01 while geometry.intersect(origin, direction, position, normal, uvw, min_hit=prev_dist): # Make sure to store a *copy* of the position, not the object # that is being modified in each iteration of the loop hit_positions.append(hou.Vector3(position)) prev_dist = origin.distanceTo(position) + 0.01
max_hit
Ignore intersections farther than this distance.
tolerance
Use this parameter to adjust the accuracy of intersections. If the ray approaches the geometry within the tolerance value, an intersection hit is assumed. A 0.01 tolerance (default) gives strict intersections while larger values produces less accurate intersections.
Vertices ¶
globVertices(pattern)
→ tuple
of hou.Vertex
Return a tuple of vertices corresponding to a pattern of vertex numbers.
The pattern format is the same one used by the group fields on SOP nodes that take vertex selections. See hou.Geometry.globPoints for more information.
vertexFloatAttribValues(name)
→ tuple
of float
Return a tuple of floats containing one attribute’s values for all the vertices.
This method only works on int or float attributes. If the attribute contains more than one element, each vertex will correspond to multiple values in the result. For example, if “attrib” is a float attribute of size 3 and there are 3 vertices with values (0.1, 0.2, 0.3), (0.5, 0.5, 0.5), and (0.8, 0.7, 0.6) then the result will be (0.1, 0.2, 0.3, 0.5, 0.5, 0.5, 0.8, 0.7, 0.6).
Calling this method is faster than looping over all the vertices and calling hou.Vertex.attribValue.
If the attribute name is invalid or the attribute is not an int or float (e.g. it’s a string attribute), this method raises hou.OperationFailed.
Note that you cannot pass a hou.Attrib object to this method like you can with many methods dealing with attributes. However, you can use hou.Attrib.name to easily get the name from an Attrib object.
vertexFloatAttribValuesAsString(name, float_type=hou.numericData.Float32)
→ str
for Python 2, bytes
for Python 3
Return a binary string representation of the floats of
one attribute’s value for all the vertices. This method is faster than
hou.Geometry.vertexFloatAttribValues, and you can use the array
module to convert the string into a Python sequence.
The returned binary string is a bytes
object in Python 3 and a str
object in Python 2. See HOM binary data for
more information.
float_type
A hou.numericData value to specify the float data type (either Float16, Float32 or Float64).
This method provides a faster implementation of the following:
import array def vertexFloatAttribValuesAsString(self, name): return array.array("f", self.vertexFloatAttribValues(name)).tostring()
You can convert the return value from this method to an array using the following method:
import array def vertexFloatAttribValuesAsArray(geometry, name): a = array.array("f") a.fromstring(geometry.vertexFloatAttribValuesAsString(name)) return a
See hou.Geometry.vertexFloatAttribValues for more information.
setVertexFloatAttribValues(name, values)
For a particular attribute, set the attribute values for all vertices. You would typically call this method from the code of a Python-defined SOP.
name
The name of the vertex attribute.
values
A sequence of int or float values in the same format as that returned by hou.Geometry.vertexFloatAttribValues. See that method for more information.
Raises hou.OperationFailed if the attribute name is not valid, the attribute is not an int or float (i.e. it’s a string), or the array of values is not the correct size.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
Also see hou.Geometry.vertexFloatAttribValues.
setVertexFloatAttribValuesFromString(name, values, float_type=hou.numericData.Float32)
For a particular attribute, set the attribute values for all vertices from a string representation of a sequence of the specified float_type values. This method is faster than hou.Geometry.setVertexFloatAttribValues.
Note that this method can accept more types that just a string: it can
receive any Python object that supports the buffer interface. In
particular, arrays from the array
and numpy
Python modules are
supported, so there is no need to first construct strings from those
arrays.
float_type
A hou.numericData value to specify the float data type (either Float16, Float32 or Float64).
Raises hou.OperationFailed if the length of the string is not
len(self.iterVertexs() * byte_size_of_float_type)
.
See hou.Geometry.setVertexFloatAttribValues and hou.Geometry.vertexFloatAttribValuesAsString for more information.
The following example function accepts an array.array("f")
and sets
the attribute values to its contents:
def setVertexFloatAttribValuesFromArray(geometry, arr): assert(arr.typecode == "f") geometry.setVertexFloatAttribValuesFromString(arr))
vertexIntAttribValues(name)
→ tuple
of int
Return a tuple of integers containing one attribute’s values for all the vertices.
This method only works on int or float attributes. If the attribute contains more than one element, each vertex will correspond to multiple values in the result. For example, if “idmap” is an integer attribute of size 2 and there are 3 vertices with values (1, 2), (2, 3), and (3, 4) then the result will be (1, 2, 2, 3, 3, 4).
Calling this method is faster than looping over all the vertices and calling hou.Vertex.attribValue.
If the attribute name is invalid or the attribute is not an int or float (e.g. it’s a string attribute), this method raises hou.OperationFailed.
Note that you cannot pass a hou.Attrib object to this method like you can with many methods dealing with attributes. However, you can use hou.Attrib.name to easily get the name from an Attrib object.
vertexIntAttribValuesAsString(name, int_type=hou.numericData.Int32)
→ str
for Python 2, bytes
for Python 3
Return a binary string representation of the integers
of one attribute’s value for all the vertices. This method is faster than
hou.Geometry.vertexIntAttribValues, and you can use the array
module to convert the string into a Python sequence.
The returned binary string is a bytes
object in Python 3 and a str
object in Python 2. See HOM binary data for
more information.
int_type
A hou.numericData value to specify the integer data type (either Int8, Int16, Int32 or Int64).
This method provides a faster implementation of the following:
import array def vertexIntAttribValuesAsString(self, name): return array.array("i", self.vertexIntAttribValues(name)).tostring()
You can convert the return value from this method to an array using the following method:
import array def vertexIntAttribValuesAsArray(geometry, name): a = array.array("i") a.fromstring(geometry.vertexIntAttribValuesAsString(name)) return a
See hou.Geometry.vertexIntAttribValues for more information.
setVertexIntAttribValues(name, values)
For a particular attribute, set the attribute values for all vertices. You would typically call this method from the code of a Python-defined SOP.
name
The name of the vertex attribute.
values
A sequence of int or float values in the same format as that returned by hou.Geometry.vertexIntAttribValues. See that method for more information.
Raises hou.OperationFailed if the attribute name is not valid, the attribute is not an int or float (i.e. it’s a string), or the array of values is not the correct size.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
Also see hou.Geometry.vertexIntAttribValues.
setVertexIntAttribValuesFromString(name, values, int_type=hou.numericData.Int32)
For a particular attribute, set the attribute values for all vertices from a string representation of a sequence of the specified int_type values. This method is faster than hou.Geometry.setVertexIntAttribValues.
Note that this method can accept more types that just a string: it can
receive any Python object that supports the buffer interface. In
particular, arrays from the array
and numpy
Python modules are
supported, so there is no need to first construct strings from those
arrays.
int_type
A hou.numericData value to specify the integer data type (either Int8, Int16, Int32 or Int64).
Raises hou.OperationFailed if the length of the string is not
len(self.iterVertexs() * byte_size_of_int_type)
.
See hou.Geometry.setVertexIntAttribValues and hou.Geometry.vertexIntAttribValuesAsString for more information.
The following example function accepts an array.array("i")
and sets
the attribute values to its contents, assuming sizeof(signed int) == 4:
def setVertexIntAttribValuesFromArray(geometry, arr): assert(arr.typecode == "i") geometry.setVertexIntAttribValuesFromString(arr))
vertexStringAttribValues(name)
→ tuple
of str
Return a tuple of strings containing one attribute’s values for all the vertices.
This method only works on string attributes. If the attribute contains more than one element, each vertex will correspond to multiple values in the result. For example, if “strmap” is a string attribute of size 2 and there are 3 vertices with values (“apple”, “orange”), (“red”, “blue”), and (“one”, “two”) then the result will be (“apple”, “orange”, “red”, “blue”, “one”, “two”).
Calling this method is faster than looping over all the vertices and calling hou.Vertex.attribValue.
If the attribute name is invalid or the attribute is not a string attribute then this method raises hou.OperationFailed.
Note that you cannot pass a hou.Attrib object to this method like you can with many methods dealing with attributes. However, you can use hou.Attrib.name to easily get the name from an Attrib object.
setVertexStringAttribValues(name, values)
For a particular attribute, set the attribute values for all vertices. You would typically call this method from the code of a Python-defined SOP.
name
The name of the vertex attribute.
values
A sequence of string values in the same format as that returned by hou.Geometry.vertexStringAttribValues. See that method for more information.
Raises hou.OperationFailed if the attribute name is not valid, the attribute is not a string, or the array of values is not the correct size.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
Also see hou.Geometry.vertexStringAttribValues.
Data ¶
data()
→ bytes
Return the geometry data in bgeo format.
For example:
geometry = hou.node("/obj/geo1/torus1").geometry() bgeo_data = geometry.data() open("/tmp/torus.bgeo", "wb").write(bgeo_data)
load(data)
Loads a bgeo bytes into this object.
For example:
torus = hou.node("/obj/geo1/torus1").geometry() bgeo_data = torus.data() geometry = hou.Geometry() geometry.load(bgeo_data)
saveToFile(file_name)
Save the contents of the geometry object to a file. The file extension determines what file format to use.
All file formats supported by Houdini (e.g. geo, bgeo, obj, etc.),
including extensions listed in GEOio
, are supported. If the file
extension is not recognized, the bgeo format is used.
Raises hou.OperationFailed if the path to the file is invalid or there were permission or other I/O errors.
loadFromFile(file_name)
Replace the contents of this geometry object with the data stored in a file. You would typically call this method from the code of a Python-defined SOP.
You may specify any type of file supported by Houdini’s File SOP. See hou.Geometry.saveToFile for more information.
Raises hou.OperationFailed if the file does not exist or otherwise cannot be loaded.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
See also hou.Geometry.merge.
clear()
Remove everything from this geometry object. The geometry will have no points or primitives after calling this method.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
merge(geometry, clone_data_ids=False, prims=None)
Merge the points and primitives from another hou.Geometry object into this one. The new points and primitives are appended to this geometry’s points and primitives. You would typically call this method from the code of a Python-defined SOP.
When merging into an empty Geometry
object, clone_data_ids
specifies
whether the resulting attributes will have the same data ids. This is
useful to enable optimizations that cache data by only looking at the
attribute data id regardless of whether it is from the same geometry object
or not. Otherwise, the copied attributes will have data ids that are unique.
The optional ‹prims› parameter is hou.Selection
that gives a more
precise subset of primitives to merge from.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
See also hou.Geometry.loadFromFile.
mergePoints(geometry, points=None)
Merge a group of points from another hou.Geometry object into this one. The new points are appended to this geometry’s points.
geometry
The hou.Geometry to merge.
points
The hou.PointGroup to merge. Raises hou.OperationFailed if
geometry
does not contain the points
group.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
See also hou.Geometry.merge.
mergePrims(geometry, prims=None)
Merge a group of primitives from another hou.Geometry object into this one. The new points and primitives are appended to this geometry’s points and primitives.
geometry
The hou.Geometry to merge.
prims
The hou.PrimGroup to merge. Raises hou.OperationFailed if
geometry
does not contain the prims
group.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
See also hou.Geometry.merge.
mergeEdges(geometry, edges=None)
Merge a group of edges from another hou.Geometry object into this one. The new points are appended to this geometry’s points. Each edge merged as a separate two-point line segment.
geometry
The hou.Geometry to merge.
edges
The hou.EdgeGroup to merge. Raises hou.OperationFailed if
geometry
does not contain the edges
group.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
See also hou.Geometry.merge.
copy(geometry, clone_data_ids=False, prims=None)
Copy the points and primitives from another hou.Geometry object into this one. This is faster than doing a clear() and a merge() as it avoid reallocating attributes and primitives. You would typically call this method from the code of a Python-defined SOP.
When merging into an empty Geometry
object, clone_data_ids
specifies
whether the resulting attributes will have the same data ids. This is
useful to enable optimizations that cache data by only looking at the
attribute data id regardless of whether it is from the same geometry object
or not. Otherwise, the copied attributes will have data ids that are unique.
The optional ‹prims› parameter is hou.Selection
that gives a more
precise subset of primitives to copy from.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
See also hou.Geometry.loadFromFile.
copyPoints(geometry, points=None)
Copy a group of points from another hou.Geometry object into this one.
geometry
The hou.Geometry to copy.
points
The hou.PointGroup to copy. Raises hou.OperationFailed if
geometry
does not contain the points
group.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
See also hou.Geometry.copy.
copyPrims(geometry, prims=None)
Copy a group of primitives from another hou.Geometry object into this one.
geometry
The hou.Geometry to copy.
prims
The hou.PrimGroup to copy. Raises hou.OperationFailed if
geometry
does not contain the prims
group.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
See also hou.Geometry.copy.
copyEdges(geometry, edges=None)
Copy a group of edges from another hou.Geometry object into this one. Each edge copied as a separate two-point line segment.
geometry
The hou.Geometry to copy.
edges
The hou.EdgeGroup to copy. Raises hou.OperationFailed if
geometry
does not contain the edges
group.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
See also hou.Geometry.copy.
execute(verb, inputs=[])
→ HOM_Geometry
Invokes verb.execute() with myself as the first input, and returns the resulting geometry. This allows one to chain a series of verbs invocations: geo.execute(subdivide).execute(subdivide).
The optional inputs will have the geometry itself prepended.
importLop(lopnode, selectionrule, purpose=None, traversal=None, path_attrib_name=None, name_attrib_name=None, strip_layers=False, frame=None)
→ hou.LopLockedStage
Imports primitives from the stage of the specified LOP as packed primitives.
Returns a hou.LopLockedStage object which should be kept in scope for as long as this geometry object contains packed primitives created by this method. Allowing this hou.LopLockedStage object to be destroyed will prevent the USD packed primitives from being displayed or unpacked.
Primitives are selected according to the hou.LopSelectionRule.
When a purpose is specified, only primitives with that purpose are imported.
When a traversal method is specified, the children of primitives specified
by the hou.LopSelectionRule will be traversed using the specified
traversal. Possible values are, for example std:component
,
std:boundables
, std:groups
.
When a path_attrib_name is given, the path of each LOP primitive is stored in an attribute of that name.
When a name_attrib_name is given, the name of each LOP primitive is stored in an attribute of that name.
If strip_layers is True
, any layers preceding a Layer Break node
connected directly or indirectly to the requested LOP node will be
stripped from the USD stage before importing the stage. This can be
useful if a Layer Break is being used to keep data that may be modified
(added after the Layer Break node) separate from primitives that should
not be modified (added to the stage before the Layer Break node).
If frame is given, the LOP will be evaluated at that specific sample. If
left at None
, the current evaluation time sample will be used instead.
importUsdStage(stage, selectionrule, purpose=None, traversal=None, path_attrib_name=None, name_attrib_name=None, frame=None)
Imports primitives from a USD Stage as packed primitives.
The USD Stage should be kept in scope for as long as this geometry object contains packed primitives created by this method. Allowing the Stage object to be destroyed may prevent the USD packed primitives from being displayed or unpacked.
Primitives are selected according to the hou.LopSelectionRule.
When a purpose is specified, only primitives with that purpose are imported.
When a traversal method is specified, the children of primitives specified
by the hou.LopSelectionRule will be traversed using the specified
traversal. Possible values are, for example std:component
,
std:boundables
, std:groups
.
When a path_attrib_name is given, the path of each LOP primitive is stored in an attribute of that name.
When a name_attrib_name is given, the name of each LOP primitive is stored in an attribute of that name.
If frame is given, time samples from the stage will be extracted for the
requested sample. If left at None
, Houdini’s current evaluation time
sample will be used instead.
Transformation ¶
transform(matrix)
Transforms (e.g. rotates, scales, translates, etc.) the geometry by a transformation matrix. You would typically call this method from the code of a Python-defined SOP.
See hou.hmath for functions that build transformation matrices.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
transformPrims(prims, matrix)
Transforms a set of primitives (e.g. rotates, scales, translates, etc.) by a transformation matrix. You would typically call this method from the code of a Python-defined SOP.
prims
A list of hou.Prim objects or hou.PrimGroup to transform.
matrix
A hou.Matrix4 to transform with. See hou.hmath functions that build transformation matrices.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
import math # This code will work from inside a Python SOP, but not from the Python # shell. def createCircle(geo, num_vertices=10): # Create a closed curve with the specified number of vertices. curve = geo.createNURBSCurve(num_vertices) curve.setIsClosed(True) # Arrange the points into a unit circle on the XZ plane, # centered about the origin. for i, vertex in enumerate(curve.vertices()): angle = i * (2.0 * math.pi) / num_vertices position = (math.cos(angle), 0, math.sin(angle)) vertex.point().setPosition(position) return curve # Create a bunch of circles on the XZ plane, tilt them slightly # about X, translate them away from the origin, and rotate each # one about the y axis by a different amount. geo = hou.pwd().geometry() num_copies = 20 for i in range(num_copies): curve = createCircle(geo) geo.transformPrims([curve], hou.hmath.buildRotateAboutAxis((1, 0, 0), 30) * hou.hmath.buildTranslate((2, 0, 0)) * hou.hmath.buildRotateAboutAxis((0, 1, 0), i * 360.0 / num_copies))
Loops ¶
primLoop(prims, loop_type)
→ tuple
of hou.Prim
Returns a tuple of hou.Prim objects that make a path connecting the primitives provided in the prims parameter. If multiple paths are being returned, they will be separated in the single returned tuple by a value of None. The paths are generated using the same algorithm used when performing loop selections in the viewport.
prims: A list of hou.Prim objects that define the path or paths of connected primitives this function should return. Must contain at least two primitives.
loop_type: Controls the type of path returned. Can be any of the hou.componentLoopType values. If using either the hou.componentLoopType.Extended or hou.componentLoopType.Closed loop types, the inputs prims cannot contain any None entries. Furthermore, each pair of primitives is used to define a separate full loop, so the number of primitives must be even. If these conditions are not met, a hou.OperationFailed exception will be thrown.
Raises a hou.OperationFailed if it was unable to construct a loop from the desired components.
pointLoop(points, full_loop)
→ tuple
of hou.Point
Returns a tuple of hou.Point objects that make a path connecting the points provided in the points parameter. If multiple paths are being returned, they will be separated in the single returned tuple by a value of None. The paths are generated using the same algorithm used when performing loop selections in the viewport.
points: A list of hou.Point objects that define the path or paths of connected points this function should return. Must contain at least two points.
loop_type: Controls the type of path returned. Can be any of the hou.componentLoopType values. If using either the hou.componentLoopType.Extended or hou.componentLoopType.Closed loop types, the inputs points cannot contain any None entries. Furthermore, each pair of points is used to define a separate full loop, so the number of points must be even. If these conditions are not met, a hou.OperationFailed exception will be thrown.
Raises a hou.OperationFailed if it was unable to construct a loop from the desired components.
edgeLoop(edges, loop_type, full_loop_per_edge, force_ring, allow_ring)
→ tuple
of hou.Edge
Returns a tuple of hou.Edge objects that make a path connecting the edges provided in the edges parameter. If multiple paths are being returned, they will be separated in the single returned tuple by a value of None. The paths are generated using the same algorithm used when performing loop selections in the viewport.
edges: A list of hou.Edge objects that define the path or paths of connected edges this function should return. Must contain at least one or two edges depending on the loop options.
loop_type: Controls the type of path returned. Can be any of the hou.componentLoopType values. If using either the hou.componentLoopType.Extended or hou.componentLoopType.Closed loop types, the inputs edges cannot contain any None entries. If these conditions are not met, a hou.OperationFailed exception will be thrown.
full_loop_per_edge: If set to True, with the loop_type set to hou.componentLoopType.Extended or hou.componentLoopType.Closed loop types, each inputs edge is used to create its own full loop or ring. If False, the edges are taken in pairs, and so the number of edges must be even.
force_ring: If set to True, this function will return edge rings instead of edge loops.
allow_ring: If set to True, this function may return an edge ring if the edges provided produce a ring more naturally than they produce a loop (for example if two perpendicular edges are provided from the same row on a polygonal grid). If set to False, only edge loops will be returned.
Raises a hou.OperationFailed if it was unable to construct a loop from the desired components.
pointNormals(points)
→ tuple
of hou.Vector3
Returns a tuple of hou.Vector3 objects representing the point normals for the supplied points.
points
A list of hou.Point objects or hou.PointGroup for which to compute point normals.
Selection ¶
selection()
→ hou.Selection
Returns the current cook component selection associated with this geometry. This is the default selection set by the SOP that created the geometry.
Packed Folders ¶
extractPackedPaths(pattern)
→ tuple
of str
Returns paths of any packed prim files that match the given pattern. See also hou.Geometry.unpackFromFolder and hou.Geometry.packToFolder.
unpackFromFolder(path)
→ hou.Geometry
Returns the unpacked geometry of the file at the given path. See also hou.Geometry.packToFolder and hou.Geometry.extractPackedPaths.
packToFolder(path, geometry, is_folder=False)
→ bool
Packs and inserts geometry
into the folder at the given path
.
If is_folder
is True, treat the inserted geometry as a folder with packed
contents. Returns True on success. Fails if the given path cannot be
created.
See also hou.Geometry.unpackFromFolder and hou.Geometry.extractPackedPaths.
packedFolderProperties(path)
→ dict
Returns a dict containing the folder properties for the given path
.
The dict contains two entries: the entry under the “visible” key specifies whether the packed primitive is in the _3d_hidden_primitives
group, and the entry under the “treat_as_folder” key specifies whether the primitive is treated as a folder with packed contents.
See also |