-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCalcWorldBoundingBox.py
More file actions
37 lines (30 loc) · 1.14 KB
/
CalcWorldBoundingBox.py
File metadata and controls
37 lines (30 loc) · 1.14 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
from pxr import Usd, UsdGeom, Gf
import omni.usd
# Get stage.
stage = omni.usd.get_context().get_stage()
# Get selection.
selection = omni.usd.get_context().get_selection()
paths = selection.get_selected_prim_paths()
# -------------------------------------------------.
# Calculate bounding box in world coordinates.
# -------------------------------------------------.
def _calcWorldBoundingBox(prim : Usd.Prim):
# Calc world boundingBox.
bboxCache = UsdGeom.BBoxCache(Usd.TimeCode.Default(), ["default"])
bboxD = bboxCache.ComputeWorldBound(prim).ComputeAlignedRange()
bb_min = Gf.Vec3f(bboxD.GetMin())
bb_max = Gf.Vec3f(bboxD.GetMax())
return bb_min, bb_max
# -------------------------------------------------.
for path in paths:
# Get prim.
prim = stage.GetPrimAtPath(path)
if prim.IsValid() == False:
continue
print(f"[ {prim.GetName()} ] : {prim.GetTypeName()}")
bbMin, bbMax = _calcWorldBoundingBox(prim)
print(f" BoundingBox : {bbMin} - {bbMax}")
sx = bbMax[0] - bbMin[0]
sy = bbMax[1] - bbMin[1]
sz = bbMax[2] - bbMin[2]
print(f" BoundingBoxSize : {sx} x {sy} x {sz}")