-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCreateMaterial.py
More file actions
34 lines (28 loc) · 1.33 KB
/
CreateMaterial.py
File metadata and controls
34 lines (28 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import omni.usd
from pxr import Usd, UsdGeom, UsdPhysics, UsdShade, Sdf, Gf, Tf
# Get stage.
stage = omni.usd.get_context().get_stage()
# Create sphere.
spherePath = "/World/sphere"
sphereGeom = UsdGeom.Sphere.Define(stage, spherePath)
sphereGeom.CreateRadiusAttr(20.0)
spherePrim = stage.GetPrimAtPath(spherePath)
spherePrim.CreateAttribute("refinementEnableOverride", Sdf.ValueTypeNames.Bool).Set(True)
spherePrim.CreateAttribute("refinementLevel", Sdf.ValueTypeNames.Int).Set(2)
# Create material scope.
materialScopePath = "/World/Materials"
scopePrim = stage.GetPrimAtPath(materialScopePath)
if scopePrim.IsValid() == False:
UsdGeom.Scope.Define(stage, materialScopePath)
# Create material (UsdPreviewSurface).
materialPath = "/World/Materials/mat1"
material = UsdShade.Material.Define(stage, materialPath)
pbrShader = UsdShade.Shader.Define(stage, f"{materialPath}/PBRShader")
pbrShader.CreateIdAttr("UsdPreviewSurface")
pbrShader.CreateInput("diffuseColor", Sdf.ValueTypeNames.Color3f).Set((1.0, 0.2, 0.0))
pbrShader.CreateInput("roughness", Sdf.ValueTypeNames.Float).Set(0.4)
pbrShader.CreateInput("metallic", Sdf.ValueTypeNames.Float).Set(0.0)
# Connect PBRShader to Material.
material.CreateSurfaceOutput().ConnectToSource(pbrShader.ConnectableAPI(), "surface")
# Bind material.
UsdShade.MaterialBindingAPI(spherePrim).Bind(material)