-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathPointInstancer_01.py
More file actions
61 lines (48 loc) · 1.76 KB
/
PointInstancer_01.py
File metadata and controls
61 lines (48 loc) · 1.76 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from pxr import Usd, UsdGeom, UsdPhysics, UsdShade, Sdf, Gf, Tf
import random
# Get stage.
stage = omni.usd.get_context().get_stage()
# Get default prim.
defaultPrim = stage.GetDefaultPrim()
defaultPrimPath = defaultPrim.GetPath().pathString
# Create empty node(Xform).
path = defaultPrimPath + '/trees'
UsdGeom.Xform.Define(stage, path)
prim = stage.GetPrimAtPath(path)
# Create PointInstancer.
pointInstancerPath = path + '/pointInstancer'
pointInstancer = UsdGeom.PointInstancer.Define(stage, pointInstancerPath)
# Create Reference.
refPath = pointInstancerPath + '/asset'
UsdGeom.Xform.Define(stage, refPath)
prim = stage.GetPrimAtPath(refPath)
# Set Kind.
#Usd.ModelAPI(prim).SetKind(Kind.Tokens.component)
Usd.ModelAPI(prim).SetKind("component")
# Set the asset to be referenced.
pointInstancer.CreatePrototypesRel().AddTarget(refPath)
# Remove references.
prim.GetReferences().ClearReferences()
# Add a reference.
#usdPath = "./simpleTree.usda"
usdPath = "https://ft-lab.github.io/usd/omniverse/usd/simpleTree.usda"
prim.GetReferences().AddReference(usdPath)
# Points data.
positions = []
scales = []
protoIndices = []
orientations = []
areaSize = 1000.0
treesCou = 50
for i in range(treesCou):
px = random.random() * areaSize - (areaSize * 0.5)
pz = random.random() * areaSize - (areaSize * 0.5)
scale = random.random() * 0.5 + 0.8
positions.append(Gf.Vec3f(px, 0.0, pz)) # Position.
orientations.append(Gf.Quath()) # Rotation.
scales.append(Gf.Vec3f(scale, scale, scale)) # Scale.
protoIndices.append(0) # asset index.
pointInstancer.CreatePositionsAttr(positions)
pointInstancer.CreateOrientationsAttr(orientations)
pointInstancer.CreateScalesAttr(scales)
pointInstancer.CreateProtoIndicesAttr(protoIndices)