Skip to content

Instantly share code, notes, and snippets.

@n-burk
Last active April 3, 2023 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save n-burk/c98da11b431a76f46f6ce4eb7fac1dc8 to your computer and use it in GitHub Desktop.
Save n-burk/c98da11b431a76f46f6ce4eb7fac1dc8 to your computer and use it in GitHub Desktop.
Converting blender curve geometry to UsdGeomBasisCurves
#################################################################
# This script works on a single selected hair geometry object
# modify the stagePath before using
#
################################################################
import bpy
from pxr import Usd, UsdGeom, Sdf, Gf
stagePath = r'C:\work\dumpTest.usda'
curvePrimPath = Sdf.Path('/blenderCurves')
stage = Usd.Stage.CreateNew(stagePath)
curvePrim = UsdGeom.BasisCurves.Define(stage, curvePrimPath)
vertexCountAttr = curvePrim.GetCurveVertexCountsAttr()
typeAttr = curvePrim.GetTypeAttr()
widthAttr = curvePrim.GetWidthsAttr()
pointsAttr = curvePrim.GetPointsAttr()
widths = []
vertexCounts = []
points = []
curves = bpy.context.selected_objects[0]
pointDump = [[x for x in y.points] for y in curves.data.curves]
for i in pointDump:
vertexCounts.append(len(i))
for pt in i:
widths.append(pt.radius if pt.radius > .01 else .01)
points.append(Gf.Vec3f(pt.position[0],pt.position[1],pt.position[2]))
vertexCountAttr.Set(vertexCounts)
widthAttr.Set(widths)
pointsAttr.Set(points)
typeAttr.Set(UsdGeom.Tokens.linear, Usd.TimeCode.Default())
stage.Save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment