meshgeometry module

The meshgeometry module allows to edit components of a mesh such as points, polygons, faces and their corresponding map values.

MeshGeometry

class modo.meshgeometry.MeshGeometry[source]

A class wrapped around lx.object.Mesh that provides access to geometry of a given Mesh Item

There have been new changes to this class in Modo 10.2, please read Mesh editing change in Modo 10.2

Parameters:
  • item (type lx.object.Item) – Input item
  • mode (string. Note: References are always read only.) – Mode in which to access the mesh. Possible values: “write”, “read”, “deformed”
Returns:

Instance of MeshGeometry

Raises:
  • LookupError – If item was passed as string and could not be found in the scene
  • TypeError – If the passed item is not of type lx.object.Item
  • TypeError – If the passed item is not compatible with the mesh type

example:

scene = modo.scene.current()

# Get the selected mesh
for mesh in scene.selectedByType("mesh")[:1]:

    # Print the number of vertices
    print len(mesh.geometry.vertices)

    # Print point position by index
    print mesh.geometry.vertices[4]

    # Set point position by index
    mesh.geometry.vertices[4] = (1,2,3)

    # Iterate all vertices and move them by 0.1 in x
    for point in mesh.geometry.vertices:
        point += (0.1, 0, 0)

    # Update to see mesh changes
    mesh.geometry.setMeshEdits()
vertices
Return type:MeshVertices
edges
Return type:MeshEdges
polygons
Return type:MeshPolygons
vmaps
Return type:MeshMaps
boundingBox

Get the bounding box of this mesh

Getter:Returns a tuple representing the two corners of the bounding box
getMeshCenter()[source]
Returns:Center position of the bounding box
internalMesh
Getter:Returns the wrapped lx.object.Mesh object
numEdges
Getter:returns the vertex count of this mesh
numPolygons
Getter:returns the polygon count of this mesh
numVertices
Getter:returns the vertex count of this mesh
setAccessMode(value='write', time=None)[source]

possible values: ‘read’, ‘write’ or ‘deformed’

setMeshEdits(editType=None)[source]

Updates mesh edits applying previous changes.

Parameters:editType (lx.symbol.f_MESHEDIT_*) – The type of change to set. Defaults to all.

MeshVertices

class modo.meshgeometry.MeshVertices(mesh, geometry, function_keyword='Point')[source]

Bases: modo.meshgeometry.MeshComponentContainer

Extension class of the point accessor that adds iteration methods.

The individual vertex objects can be accessed through the built-in iterator function or angular brackets

example:

# Get the vertex count
print "Number of vertices: %i" % len(mesh.geometry.vertices)

# Access first vertex
print mesh.geometry.vertices[0]

# Iterates all vertices through a generator object
for vertex in mesh.geometry.vertices:
    print vertex
Parameters:
  • mesh – Input mesh to obtain PointAccessor from
  • parent – MeshGeometry parent object
__getitem__(index)[source]

Quick read access to a point position via angular brackets.

example:

# Print point position by index
print mesh.geometry.vertices[4]
__iter__()[source]

Iterate over all vertices.

Returns:Iterable MeshVertices generator object

example:

# Iterate all vertices and move them by 0.1 in x
for point in mesh.geometry.vertices:
    pos = list(point.Pos())
    pos[0] += 0.1
    point.SetPos(pos)

# Update to see mesh changes
mesh.geometry.setMeshEdits()
__setitem__(index, in_vertex)[source]

Quick write access to a point position via angular brackets.

example:

mesh.geometry.vertices[0] = (1, 2, 3)
enumerate(mode, visitor, monitor=0)[source]

Enumerate vertices using a visitor

Parameters:
  • mode (int) – lx.symbol.iMARK_ANY
  • visitor (lxifc.Visitor) – Visitor class instance to use
  • monitor – Optional monitor (progress bar) to display
iterByList(vertex_list=None)[source]

Iterate over vertices of a given list of point indices.

Returns:Iterable MeshVertices generator object
Parameters:vertex_list – List of point indices to visit

example:

# Iterate all vertices and move them by 0.1 in x
for point in mesh.geometry.vertices.iterByList([1,3,6,7]):
    pos = list(point.Pos())
    pos[0] += 0.1
    point.SetPos(pos)

# Update to see mesh changes
mesh.geometry.setMeshEdits()
new(position)[source]

Adds a new vertex

Parameters:tuple – Position
Returns MeshVertex:
 New vertex object
remove(vertices)[source]

Removes a single vertex or a list of vertices

Parameters:or list/tuple vertices (int) – Vertices to remove
select(vertices=None, replace=False)[source]

Selects one or multiple vertices of this mesh

Parameters:
  • list or tuple vertices (int,) – index, MeshVertex, or sequence of indices or MeshVertex objects. If None, the selection is cleared.
  • replace (bool) – Clears the selection first
selected
Getter:Returns the currently selected vertices (tuple)

MeshVertex

class modo.meshgeometry.MeshVertex(index, geometry)[source]

Bases: object

Class representing a single vertex

example:

#Supports operators

v1 = mesh.geometry.vertices[1]
v2 = mesh.geometry.vertices[2]

v1 += v2
v1 = v1 - v2
deselect()[source]

Deselects this vertex

classmethod fromId(id, geometry)[source]

Initializes a vertex from a given MeshGeometry object

Parameters:
  • or long vertex (int) – The index of the vertex to be obtained. If vertex is of type long, it will be looked up as pointer ID.
  • geometry – The geometry to obtain the vertex from
Type:

int

Type:

MeshGeometry

Returns:

An instance of MeshVertex

id
Getter:Returns the pointer ID of this vertex
index
Getter:Returns the index of this vertex as integer.

Note that indices do not exist immediately after adding a vertex, the edits need to be applied with setMeshEdits to produce indices.

nextPointByVector(direction, minAlign=-1.0)[source]
Parameters:
  • direction (Vector3) – A start vector
  • minAlign (float) – A threshold between -1.0 and 1.0. The smaller the value, the bigger the angle range that is considered.
Returns MeshVertex:
 

The vertex closest to the given vector direction

polygons
Getter:Returns the connected polygons
position

Get or set the local position vector as tuple

Getter:Returns position as a tuple
Setter:Takes an Iterable as input to set the position from
remove()[source]

Removes this vertex from the mesh

select(polygon=None, replace=False)[source]

Selects this vertex

Parameters:
  • polygon (MeshPolygon) – Selects the vertex specific to this polygon, needed for UV selections
  • replace (bool) – Clears the selection before selecting
vertices
Getter:Returns the connected vertices
x
Getter:Returns the x position
Setter:Takes a float value to set the x position from
y
Getter:Returns the y position
Setter:Takes a float value to set the y position from
z
Getter:Returns the z position
Setter:Takes a float value to set the z position from

MeshEdges

class modo.meshgeometry.MeshEdges(mesh, parent)[source]

Bases: modo.meshgeometry.MeshComponentContainer

Extension class of the Edge accessor lx.object.Edge that adds iteration methods.

Note: Modo does not store edges by index, therefore they cannot be accessed by such. You can use the built-in python iterator however.

Parameters:
  • mesh – Input mesh to obtain PointAccessor from
  • parent – MeshGeometry parent object
enumerate(mode, visitor, monitor=0)[source]

Enumerate edges using a visitor

Parameters:
  • mode (int) – lx.symbol.iMARK_ANY
  • visitor (lxifc.Visitor) – Visitor class instance to use
  • monitor – Optional monitor (progress bar) to display
select(edges=None, replace=False)[source]

Selects one or multiple edges of this mesh

Parameters:
  • or tuple edges (list) – index, MeshEdge, or sequence of indices or MeshEdge objects. If None, the selection is cleared.
  • replace (bool) – Clears the selection first
selected
Getter:Returns the currently selected edges as tuple

MeshEdge

class modo.meshgeometry.MeshEdge(vertices, geometry)[source]

Bases: object

Class representing an edge

accessor
Getter:Returns the internal shared EdgeAccessor object of the core SDK (lx.object.Edge)
id
Getter:Returns the pointer ID of this edge
polygons
Getter:Returns the polygons connected to this edge
vertex_indices
Getter:Returns the connected vertex indices as tuple

Note that indices do not exist immediately after adding a vertex, the edits need to be applied with setMeshEdits to produce indices.

vertices
Getter:Returns the connected vertices as tuple

MeshPolygons

class modo.meshgeometry.MeshPolygons(mesh, geometry, function_keyword='Point')[source]

Bases: modo.meshgeometry.MeshComponentContainer

Extension class of the Polygon accessor that adds iteration methods.

The vertices of of individual vertices can be accessed through the built-in iterator function or angular brackets

example:

mesh, = modo.scene.current().selectedByType("mesh")

# Get the number of polygon
print "Number of polygons: %i" % len(mesh.geometry.polygons)

# Access the first polygon and print it's normal
polygon = mesh.geometry.polygons[0]
print polygon.normal

# Iterates all polygons through a generator object and print it's vertices
for polygon in mesh.geometry.polygons:
    print polygon.vertices
__getitem__(index)[source]

Quick read access to a point position via index and angular brackets.

__iter__()[source]

Iterate over all polygons.

Returns:Iterable MeshPolygon generator object

example:

for polygon in mesh.geometry.polygons:
    print polygon
accessor
Getter:Returns the internal shared PolygonAccessor object of the core SDK (lx.object.Polygon)
enumerate(mode, visitor, monitor=0)[source]

Enumerate polygons using a visitor

Parameters:
  • mode (int) – lx.symbol.iMARK_ANY
  • visitor (lxifc.Visitor) – Visitor class instance to use
  • monitor – Optional monitor (progress bar) to display
iterByIndices(poly_list=None)[source]

Iterate over polygons of a given list of indices.

Use this if you want to save memory for large meshes.

Parameters:poly_list – List of point indices to visit
Returns:Iterable MeshPolygon generator object

example:

for polygon in mesh.geometry.polygons.iterByIndices([1,4,2]):
    print polygon
iterByType(polyType)[source]
Parameters:polyType (string) – Value in FACE, CURV, BEZR, SUBD, SPCH, TEXT, PSUB, LINE
Returns:Generator object for polygons of specified type
iterCurves()[source]

This method currently broken, please use iterByType(‘CURV’) instead

Returns:Iterable for curve polygons
iterFaces()[source]
Returns:Iterable for curve polygons
iterLines()[source]
Returns:Iterable for line polygons
iterPixarSubdivs()[source]
Returns:Iterable for pixar subdiv polygons
iterSplinePatches()[source]
Returns:Iterable for spline patch polygons
iterSubdivs()[source]
Returns:Iterable for subdiv polygons
iterTexts()[source]
Returns:Iterable for text polygons
new(vertices=None, reversed=False, polyType=None)[source]

Adds a polygon to the mesh

Parameters:
  • vertices (list) – List containing or either MeshVertex objects or vertex indices
  • reversed (bool) – Winding order is reversed when True. (Clockwise is the default)
select(polygons=None, replace=False)[source]

Selects one or multiple polygons of this mesh

Parameters:
  • list or tuple polygons (int,) – index, MeshPolygon, or sequence of indices or MeshPolygon objects. If None, the selection is cleared.
  • replace (bool) – Clears the selection first
selected
Getter:Returns the selected polygons as tuple

Note that indices do not exist immediately after adding a vertex, the edits need to be applied with setMeshEdits to produce indices.


MeshPolygon

class modo.meshgeometry.MeshPolygon(index, geometry)[source]

Bases: object

Class wrapped around lx.object.Polygon for polygon access.

accessor
Getter:Returns the internal shared PolygonAccessor object of the core SDK (lx.object.Polygon)
area
Getter:Returns the area of this polygon
deselect()[source]

Deselects this polygon

edges
Getter:Returns the edges connected to this polygon
classmethod fromMesh(index, geometry)[source]

Initializes a polygon from a given MeshGeometry object

Parameters:
  • index – The polygon index to be obtained
  • geometry – The geometry to obtain the polygon from
Type:

int

Type:

MeshGeometry

Returns:

An instance of MeshPolygon

getIsland()[source]

Returns the all connected neighbour polygons found.

getTag(tagType)[source]

Gets a polygon tag

Parameters:tagType (basestring) – Any out of lx.symbol.i_POLYTAG_*
Returns:Value of the tag
getUV(vertex, uvmap=None)[source]

Get a UV value pair from a vertex specific to this polygon.

Parameters:uvmap (UVMap) – The UVMap to read the value from
Vertex int or MeshVertex:
 Vertex to read the uv value pair for. Can be a vertex index or a MeshVertex object.
id
Getter:Returns the pointer ID of this polygon
index
Getter:Returns the index of this polygon

Note that indices do not exist immediately after adding a polygon, the edits need to be applied with setMeshEdits to produce indices.

iterTriangles(asIndices=True)[source]
Parameters:asIndices (bool) – Indices are returned if True, MeshVertex instances if False
Returns generator object:
 Tuples consisting of 3 vertices each
iterVertexNormals()[source]

Iterator for vertex normals :return: Generator object that returns a vertex normal per polygon vertex

materialTag
Getter:Get the value of the material tag
Setter:Set the value of the material tag, taking a string argument
neighbours
Getter:Returns the neighbour polygons as tuple
normal
Getter:Returns the normal of this polygon face
numTriangles(keepTriangles=False)[source]
Returns:The number of triangles on the polygon
numVertices
Getter:Returns the number of vertices of this polygon
select(replace=False)[source]

Selects this polygon

Parameters:replace (bool) – Deselects all polygons of this mesh before selecting
setTag(tagType, value)[source]

Sets a polygon tag

Parameters:
  • tagType (basestring) – Any out of lx.symbol.i_POLYTAG_*
  • value – Value to set
setUV(values, vertex, uvmap=None)[source]

Set a UV value pair for a vertex specific to this polygon. Splitting UVs off their surrounding connections can be done this way.

Parameters:
  • values (tuple) – A tuple containing the two uv floats to be set
  • uvmap (UVMap) – The UVMap to write the value to. Will look for the first found UV map if None
Vertex int or MeshVertex:
 

Vertex to write the uv value pair for. Can be a vertex index or a MeshVertex object.

tags()[source]

List tags of this polygon

triangles

:getter : Returns all triangle vertices as tuple

vertexNormal(index)[source]
Parameters:index (int) – Vertex index on the polygon
Returns tuple:The normal of the vertex
vertices
Getter:Returns the connected vertices of the polygon

Note that indices do not exist immediately after adding a vertex, the edits need to be applied with setMeshEdits to produce indices.


MeshMaps

class modo.meshgeometry.MeshMaps(mesh, geometry, function_keyword='Point')[source]

Bases: modo.meshgeometry.MeshComponentContainer

This module provides access to the various map types that a mesh holds.

example:

# By index
myMap = geo.vmaps[0]

# From string
myMap = geo.vmaps['MyMap']

# From string with wildcard
myMap = geo.vmaps['MyMap*']

# Get the first morph map if any and change vertex 36
for morph in geo.vmaps.morphMaps[0:1]:
    morph[36] = (0, 0, 0)

# Update changes on the mesh
geo.setMeshEdits()

Note: to remove a vertex map, use the Remove method of the accessor for now:

myMap.accessor.Remove()
accessor
Getter:Returns the internal shared MeshMapAccessor object of the core SDK (lx.object.MeshMap)
addMap(mapType=None, name='WeightMap')[source]

Add a new map

Parameters:name (string) – Name
Returns:New map
addMorphMap(name='Morph', static=False)[source]

Add a morph map

Parameters:
  • name (string) – Name
  • static (bool) – Creates a static (absolute) morph map if true and relative one if false
Returns MorphMap:
 
getMapsByType(types_list=None)[source]
Parameters:types_list (list) – List of lx.symbol types. If it is None, all map types will be retrieved
Returns:tuple containing the requested map objects of this mesh
morphMaps
Getter:Returns a list of morph maps
pickMaps
Getter:Returns a list of pick maps (aka selection sets)
rgbMaps
Getter:Returns a list of RGB maps
rgbaMaps
Getter:Returns a list of RGBA maps
uvMaps
Getter:Returns a list of uv maps
weightMaps
Getter:Returns a list of weight maps

VertexMap

class modo.meshgeometry.VertexMap[source]

A class representing a vertex map, accessible by point indices through angular brackets.

Base class for other maps.

accessor
Getter:Returns the internal shared MeshMapAccessor object of the core SDK (lx.object.MeshMap)
clear(index=None)[source]
Parameters:index (int) – If not None, the vertex of this index is deallocated from the map. Otherwise all values of the map are deallocated.
name

Get or set the name of this mesh map

Getter:Returns name as string
Setter:Sets name from string

WeightMap

class modo.meshgeometry.WeightMap[source]

Bases: modo.meshgeometry.VertexMap

Provides access to weight map values.

example:

scene = modo.scene.current()

# Get the first selected Mesh
mesh = scene.selectedByType("mesh")[0]

# Get the weight maps object
vmaps = mesh.geometry.vmaps.weight_maps

if vmaps:

    # Get the first weight map found
    weightMap = vmaps[0]

    # Set and get values
    weightMap[0] = 0.333
    print weightMap[0]

    # Iterate and print all weight values
    if weightMap:
        for index, weight in enumerate(weightMap):
            print index, weight

MorphMap

class modo.meshgeometry.MorphMap[source]

Bases: modo.meshgeometry.VertexMap

example:

# Get first morph map if exists
for morph in geo.vmaps.morphMaps[:1]:

    # Set position for vertex 10
    morph[10] = (1,2,3)

# Update mesh
geo.setMeshEdits()
getAbsolutePosition(index)[source]

Gets the absolute position instead of the relative position

Parameters:index (int) – Vertex index to read
Returns tuple:position values
setAbsolutePosition(index, value)[source]

Sets the absolute position instead of the relative position

Parameters:
  • index (int) – Vertex index to change
  • tuple – xyz values

UVMap

class modo.meshgeometry.UVMap[source]

Bases: modo.meshgeometry.VertexMap

Access for UV-Map values


RGBMap

class modo.meshgeometry.RGBMap[source]

Bases: modo.meshgeometry.VertexMap


RGBAMap

class modo.meshgeometry.RGBAMap[source]

Bases: modo.meshgeometry.VertexMap