I want to use usdrt to create material and bind the material to Mesh.but I can not find the api.
here is the code w replace pxr to usdrt ,but it does not work.
import omni.usd
from usdrt import Usd ,UsdGeom ,Sdf,UsdShade,Rt,Gf
stage_id = omni.usd.get_context().get_stage_id()
stage = Usd.Stage.Attach(stage_id)
modelRoot = UsdGeom.Xform.Define(stage, “/TexModel”)
x_billboard = UsdGeom.Mesh.Define(stage, “/TexModel/card”)
attr=x_billboard.CreatePointsAttr()
attr.Set([(-430, -145, 0), (430, -145, 0), (430, 145, 0), (-430, 145, 0)])
attr=x_billboard.CreateFaceVertexCountsAttr()
attr.Set([3,3])
attr=x_billboard.CreateFaceVertexIndicesAttr()
attr.Set([0,1,2,0,2,3])
texCoords = UsdGeom.PrimvarsAPI(x_billboard).CreatePrimvar(“st”,
Sdf.ValueTypeNames.TexCoord2fArray,
UsdGeom.Tokens.varying)
texCoords.Set([(0, 0), (1, 0), (1,1), (0, 1)])
pbrShader = UsdShade.Shader.Define(stage, ‘/TexModel/boardMat/PBRShader’)
attr=pbrShader.CreateIdAttr()
attr.Set(“UsdPreviewSurface”)
pbrShader.CreateInput(“roughness”, Sdf.ValueTypeNames.Float).Set(0.4)
pbrShader.CreateInput(“metallic”, Sdf.ValueTypeNames.Float).Set(0.0)
material = UsdShade.Material.Define(stage, ‘/TexModel/boardMat’)
material.CreateSurfaceOutput().ConnectToSource(pbrShader.ConnectableAPI(), “surface”)
stReader = UsdShade.Shader.Define(stage, ‘/TexModel/boardMat/stReader’)
attr=stReader.CreateIdAttr()
attr.Set(‘UsdPrimvarReader_float2’)
diffuseTextureSampler = UsdShade.Shader.Define(stage,‘/TexModel/boardMat/diffuseTexture’)
attr=diffuseTextureSampler.CreateIdAttr()
attr.Set(‘UsdUVTexture’)
diffuseTextureSampler.CreateInput(‘file’, Sdf.ValueTypeNames.Asset).Set(r"C:\Technical_schoolv_vcurrent_m2a177\resource\img\19bcd6ebdfbe6c19ae10f763cc9f0221.png")
diffuseTextureSampler.CreateInput(“st”, Sdf.ValueTypeNames.Float2).ConnectToSource(stReader.ConnectableAPI(), ‘result’)
diffuseTextureSampler.CreateOutput(‘rgb’, Sdf.ValueTypeNames.Float3)
pbrShader.CreateInput(“diffuseColor”, Sdf.ValueTypeNames.Color3f).ConnectToSource(diffuseTextureSampler.ConnectableAPI(), ‘rgb’)
stInput = material.CreateInput(‘frame:stPrimvarName’, Sdf.ValueTypeNames.Token)
stInput.Set(‘st’)
stReader.CreateInput(‘varname’,Sdf.ValueTypeNames.Token).ConnectToSource(stInput)
x_billboard.GetPrim().ApplyAPI(UsdShade.MaterialBindingAPI)
UsdShade.MaterialBindingAPI(x_billboard).Bind(material)
pts_boundable = Rt.Boundable(x_billboard.GetPrim())
pts_world_ext = pts_boundable.CreateWorldExtentAttr()
pts_world_ext.Set(
Gf.Range3d(Gf.Vec3d(-430, -145, 0), Gf.Vec3d(430, 145, 0))
)
pts_boundable.CreateFabricHierarchyLocalMatrixAttr()
pts_boundable.CreateFabricHierarchyWorldMatrixAttr()
billboard.GetPrim().CreateAttribute(“_worldVisibility”, Sdf.ValueTypeNames.Bool, True).Set(True)
billboard.GetPrim().CreateAttribute(“purpose”, Sdf.ValueTypeNames.Token, False).Set(“default”)