-
-
Save satishgoda/18cacefd3ed6b2c3542710245a3becc3 to your computer and use it in GitHub Desktop.
Converting blender curve geometry to UsdGeomBasisCurves
This file contains hidden or 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
################################################################# | |
# 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