gltfからUsdMeshを作る
ipynbFile gltf2UsdMesh__gltfからUsdMeshを作る.ipynb
In [91]:
| import trimesh
from pxr import Usd, UsdGeom, Sdf
gltf_file = r"D:\work\data_sample\susanne.glb"
gltf = trimesh.load(gltf_file)
geo_name = list(gltf.geometry.keys())[0]
geo = gltf.geometry[geo_name]
|
Success
| unable to load textures without pillow!
|
In [92]:
| # 頂点取得
vtx = []
for v in geo.vertices:
vtx.append(list(v))
|
In [93]:
| # Faceを構成するIndexとVertexCountを取得
indexes = []
vtxcount = []
for f in geo.faces:
indexes += [int(x) for x in f]
vtxcount.append(len(f))
|
In [94]:
1
2
3
4
5
6
7
8
9
10
11
12 | # to USDMesh
stage = Usd.Stage.CreateInMemory()
UsdGeom.Xform.Define(stage, f'/{geo_name}')
mesh = UsdGeom.Mesh.Define(stage, f'/{geo_name}/{geo_name}Mesh')
mesh.CreatePointsAttr(vtx)
# 1FaceあたりのVertex数
mesh.CreateFaceVertexCountsAttr(vtxcount)
# 結線情報?
mesh.CreateFaceVertexIndicesAttr(indexes)
# BoundingBoxをセット?
mesh.CreateExtentAttr(UsdGeom.PointBased(mesh).ComputeExtent(mesh.GetPointsAttr().Get()))
|
Success
| Usd.Prim(</Suzanne/SuzanneMesh>).GetAttribute('extent')
|