Python PolygonMesh.Set example


This simple example shows how to pass in the vertex and polygon data in Python.

Application.CreatePrim("Cube", "MeshSurface", "", "")
oCube = Application.Selection(0)

# tuple of tuples
# one tuple for the X coordinate, one for the Y, and one for the Z
verts = ((-0.5, 0.5, -0.5, 0.5, -0.5, 0.5, -0.5, 5.0), (-0.5, -0.5, 0.5, 0.5, -0.5, -0.5, 0.5, 0.0), (-0.5, -0.5, -0.5, -0.5, 0.5, 0.5, 0.5, -18.0))

# tuple of polygon data
polys = (4, 0, 2, 3, 1, 4, 0, 1, 5, 4, 4, 0, 4, 6, 2, 4, 1, 3, 7, 5, 4, 2, 6, 7, 3, 4, 4, 5, 7, 6)

Application.FreezeObj(oCube)

oCube.ActivePrimitive.Geometry.Set(verts,polys)

To help understand the vertex and polyon data, consider this simple polygon mesh:

Given the above polygon mesh, this snippet:

oCube = Application.Selection(0)

data = oCube.ActivePrimitive.Geometry.Get2()
verts = data[0]
polys = data[1]

print verts
print polys

would print this:

#  ((-3.0, 4.0, 1.0, -2.0), (0.0, -4.0, 0.0, 0.0), (1.0, -4.0, 5.0, 3.0))
# (4, 0, 1, 2, 3)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s