Hello devs,
After 20++ years in CG I was able to create a poly plane!
I am playing with USD Python API trying to understand the lowest level of this beast.
This is a quite messy process for me but, as usual, when I learn new exciting stuff, I record my findings in the form of an article or tutorial. Here is the USD Python API exploration which I would like to share.
Here is the code for the procedural plane:
def plane(row_points, column_points):
"""
Create polygonal grid (size 2x2 units)
int[] faceVertexCounts = [4]
int[] faceVertexIndices = [0, 1, 2, 3]
point3f[] points = [(-5, 0, -5), (5, 0, -5), (5, 0, 5), (-5, 0, 5)]
"""
points = [] # List of point positions
face_vertex_counts = [] # List of vertex count per face
face_vertex_indices = [] # List of vertex indices
# Spacing between points
width = 2
height = 2
row_spacing = height / (row_points - 1)
col_spacing = width / (column_points - 1)
# Generate points for the grid
for row_point in range(row_points):
for column_point in range(column_points):
x = column_point * col_spacing - width / 2
z = row_point * row_spacing - height / 2
points.append((x, 0, z))
# Define faces using the indices of the grid points
for row_point in range(row_points - 1):
for column_point in range(column_points - 1):
# Calculate the indices of the corners of the cell
top_left = row_point * column_points + column_point
top_right = top_left + 1
bottom_left = top_left + column_points
bottom_right = bottom_left + 1
# Define the face using the indices of the 4 corners
face_vertex_indices.extend([top_left, top_right, bottom_right, bottom_left])
face_vertex_counts.append(4)
geometry_data = {'points': points,
'face_vertex_counts': face_vertex_counts,
'face_vertex_indices': face_vertex_indices}
return geometry_data
I started with the creation of a USD file, then I tried to export existing geometry to this USD file from Maya and Houdini and now I am reinventing the wheel, understanding how to create geometry with code. The latest milestone is a sphere:
And I hope to continue the exploration