Skip to content

Instantly share code, notes, and snippets.

@andrearastelli
Created March 5, 2017 11:42
Show Gist options
  • Save andrearastelli/fb297e6cac8cb745e90c273e7ff53a1d to your computer and use it in GitHub Desktop.
Save andrearastelli/fb297e6cac8cb745e90c273e7ff53a1d to your computer and use it in GitHub Desktop.
MAYA - unitCube using MFnMesh
import maya.api.OpenMaya as OpenMaya
mesh = OpenMaya.MFnMesh()
# Simple unitCube coordinates
vertices = []
vertices.append(OpenMaya.MPoint( 1, 1, 1)) # 0
vertices.append(OpenMaya.MPoint( 1, -1, 1)) # 1
vertices.append(OpenMaya.MPoint( 1, -1, -1)) # 2
vertices.append(OpenMaya.MPoint( 1, 1, -1)) # 3
vertices.append(OpenMaya.MPoint(-1, -1, 1)) # 4
vertices.append(OpenMaya.MPoint(-1, 1, 1)) # 5
vertices.append(OpenMaya.MPoint(-1, 1, -1)) # 6
vertices.append(OpenMaya.MPoint(-1, -1, -1)) # 7
# Number of vertices per polygon
polygonCounts = []
polygonCounts.append(4) # 0, 1, 2, 3
polygonCounts.append(4) # 0, 5, 4, 1
polygonCounts.append(4) # 5, 6, 7, 4
polygonCounts.append(4) # 6, 3, 2, 7
polygonCounts.append(4) # 0, 3, 6, 5
polygonCounts.append(4) # 1, 4, 7, 2
# How each group of N vertices per polygon is connected.
#
# Because for each vertex I have specified the list index number, I can use the
# same number to uniquely identify each face of the polygon to actually build
# the connection between each vertex.
polygonConnects = []
# First polygon
polygonConnects.append(0)
polygonConnects.append(1)
polygonConnects.append(2)
polygonConnects.append(3)
# Second polygon
polygonConnects.append(0)
polygonConnects.append(5)
polygonConnects.append(4)
polygonConnects.append(1)
# Third polygon
polygonConnects.append(5)
polygonConnects.append(6)
polygonConnects.append(7)
polygonConnects.append(4)
# Fourth polygon
polygonConnects.append(6)
polygonConnects.append(3)
polygonConnects.append(2)
polygonConnects.append(7)
# Fifth polygon
polygonConnects.append(0)
polygonConnects.append(3)
polygonConnects.append(6)
polygonConnects.append(5)
# Sixth polygon
polygonConnects.append(1)
polygonConnects.append(4)
polygonConnects.append(7)
polygonConnects.append(2)
mesh.create(vertices, polygonCounts, polygonConnects)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment