Editing with GeoPython Node
The GeoPython node allows you to directly edit the Python code in your stage. If you have some knowledge of USD and Python then this node can be very powerful in creating new schemas and editing your USD stage.
| 1. | Connect the GeoPython node downstream of your stage in the node graph. |
| 2. | You can then inspect and edit the code in the GeoPython node Properties panel. |
| 3. | If you make changes to your stage and want to view the updates in the GeoPython node, you’ll need to select Reload. This refreshes the code. |
Example Code
For example, this would make a 3D sphere of points:
from pxr import Usd, Sdf, Gf
import math
stage = geo_python.stage()
node = geo_python.node()
sphere = node['sphere'].getValue()
from pxr import UsdGeom
prim = UsdGeom.Points.Define(stage, "/Points")
golden_angle = 2.399963
for time in geo_python.times():
radius = node['radius'].getValueAt(time)
n = int(node['count'].getValueAt(time))
size = node['size'].getValueAt(time)
points = []
for i in range(0, n):
k = i + 0.5
theta = golden_angle * k;
if sphere:
phi = math.acos(1.0 - 2.0 * k / n)
sinPhi = math.sin(phi)
p = Gf.Vec3f(math.cos(theta) * sinPhi, math.cos(phi), math.sin(theta) * sinPhi) * radius
else:
p = Gf.Vec3f(math.cos(theta), math.sin(theta), 0.0) * radius * math.sqrt(k / n)
points.append(p)
prim.CreatePointsAttr().Set(points, time)
prim.CreateWidthsAttr().Set([size] * len(points), time)
e = Gf.Vec3f(radius, radius, radius)
prim.GetExtentAttr().Set([-e, e])
Learn more about Python in the Nuke Python Developer's Guide.