コンテンツにスキップ

USDのMeshをPythonで作る

ipynbFile USDMeshTest__USDのMeshをPythonで作る.ipynb

[9]:

from pxr import Usd,UsdGeom,Sdf

[10]:

stage = Usd.Stage.CreateInMemory()
UsdGeom.Xform.Define(stage, '/hoge')
mesh = UsdGeom.Mesh.Define(stage, '/hoge/TestMesh')

[11]:

# Point設定
mesh.CreatePointsAttr([(-5, -5, 5), (5, -5, 5), (5, 5, 5), (-5, 5, 5)])
# 1FaceあたりのVertex数
mesh.CreateFaceVertexCountsAttr([3, 3])
# 結線情報?
mesh.CreateFaceVertexIndicesAttr([0, 1, 2, 0, 2, 3])
# BoundingBoxをセット?
mesh.CreateExtentAttr(UsdGeom.PointBased(mesh).ComputeExtent(mesh.GetPointsAttr().Get()))
# UV作成
uv = mesh.CreatePrimvar('st',Sdf.ValueTypeNames.TexCoord2fArray,UsdGeom.Tokens.varying)
uv.Set([(0,0),(0,1),(1,1),(1,0)])

Success

True

[12]:

# 頂点取得
print(mesh.GetPointsAttr().Get())
print(mesh.GetFaceVertexCountsAttr().Get()) # 頂点数

print(mesh.GetNormalsInterpolation())

Success

[(-5, -5, 5), (5, -5, 5), (5, 5, 5), (-5, 5, 5)]
[3, 3]
vertex

[13]:

print(stage.GetRootLayer().ExportToString())
# stage.GetRootLayer().Export("D:/work/usd_py36/usd/usdSimpleMesh.usda")

Success

#usda 1.0

def Xform "hoge"
{
    def Mesh "TestMesh"
    {
        float3[] extent = [(-5, -5, 5), (5, 5, 5)]
        int[] faceVertexCounts = [3, 3]
        int[] faceVertexIndices = [0, 1, 2, 0, 2, 3]
        point3f[] points = [(-5, -5, 5), (5, -5, 5), (5, 5, 5), (-5, 5, 5)]
        texCoord2f[] primvars:st = [(0, 0), (0, 1), (1, 1), (1, 0)] (
            interpolation = "varying"
        )
    }
}

最終更新日: 2020-01-19 03:13:27