Created
March 3, 2020 13:30
-
-
Save rondreas/a40dfc7d5edc75b7faa5488a2093315f to your computer and use it in GitHub Desktop.
Script to create a mesh cube using Modo TD SDK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# python | |
# -*- coding: utf-8 -*- | |
import modo | |
def create(): | |
""" Modo TD SDK example of creating a cube item, | |
Not recommended but one can run this as a fire-and-forget like.. | |
@cube.py | |
in modo command prompt. | |
Or one can import it and run like.. | |
>>> import cube | |
>>> cube.create() | |
ASCII Figure, Cube vertex positions and coordinate | |
directions. | |
+Y | |
-X | |
4 -Z | |
5. ´|`~. | |
|`~. | `6 | |
| `7|´ ´| | |
| .~|0 | | |
1´ | `~. | | |
`~. | .`2 | |
+Z `3´ | |
+X | |
-Y | |
""" | |
mesh = modo.Scene().addItem('mesh', name="Cube") | |
vertices = [ # List of vertex positions for a cube, | |
(-0.5, -0.5, -0.5), # 0 <- indices, | |
(-0.5, -0.5, 0.5), # 1 | |
( 0.5, -0.5, -0.5), # 2 | |
( 0.5, -0.5, 0.5), # 3 | |
(-0.5, 0.5, -0.5), # 4 | |
(-0.5, 0.5, 0.5), # 5 | |
( 0.5, 0.5, -0.5), # 6 | |
( 0.5, 0.5, 0.5), # 7 | |
] | |
polygons = [ # Polygons takes a list of vert indices, | |
(0, 2, 3, 1), # -Y | |
(4, 5, 7, 6), # +Y | |
(2, 6, 7, 3), # +X | |
(0, 1, 5, 4), # -X | |
(1, 3, 7, 5), # +Z | |
(0, 4, 6, 2) # -Z | |
] # index order is important to make the polygon face | |
# the right direction. | |
# enter the context so it's safe to edit meshes, | |
with mesh.geometry as geo: | |
for vertex in vertices: | |
geo.vertices.new(vertex) | |
for polygon in polygons: | |
geo.polygons.new(polygon) | |
return mesh | |
if __name__ == '__main__': | |
create() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment