file_path
stringlengths 21
207
| content
stringlengths 5
1.02M
| size
int64 5
1.02M
| lang
stringclasses 9
values | avg_line_length
float64 1.33
100
| max_line_length
int64 4
993
| alphanum_fraction
float64 0.27
0.93
|
---|---|---|---|---|---|---|
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/prims/check-prim-exists/py_usd.md | ``` {literalinclude} py_usd.py
:language: py
```
Alternatively, `Usd.Object` overrides the boolean operator so you can check with a simple boolean expression.
``` {literalinclude} py_usd_var1.py
:language: py
``` | 214 | Markdown | 22.888886 | 109 | 0.728972 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/prims/check-prim-exists/config.toml | [core]
title = "Check if a Prim Exists"
[metadata]
description = "Universal Scene Description (OpenUSD) code samples for checking if a Prim exists on a Stage."
keywords = ["OpenUSD", "USD", "Python", "snippet", "code sample", "prim", "exists", "IsValid", "valid"] | 264 | TOML | 43.166659 | 108 | 0.69697 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/prims/check-prim-exists/py_usd_var1.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from pxr import Usd
def check_prim_exists(prim: Usd.Prim) -> bool:
if prim:
return True
return False
#############
# Full Usage
#############
from pxr import Sdf, UsdGeom
# Create an in-memory Stage with /World Xform prim as the default prim
stage: Usd.Stage = Usd.Stage.CreateInMemory()
default_prim: Usd.Prim = UsdGeom.Xform.Define(stage, Sdf.Path("/World")).GetPrim()
stage.SetDefaultPrim(default_prim)
# Create one prim and
cube: Usd.Prim = UsdGeom.Cube.Define(stage, Sdf.Path("/World/Cube")).GetPrim()
empty_prim = Usd.Prim()
usda = stage.GetRootLayer().ExportToString()
print(usda)
# Check if prims exist
assert check_prim_exists(default_prim)
assert check_prim_exists(cube)
assert not check_prim_exists(None) | 877 | Python | 26.437499 | 98 | 0.718358 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/prims/get-prim/py_usd.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from typing import Union
from pxr import Usd, Sdf
def get_prim_by_path(stage: Usd.Stage, prim_path: Union[str, Sdf.Path]) -> Usd.Prim:
return stage.GetPrimAtPath(prim_path)
##############
# Full Usage
##############
from pxr import UsdGeom
# Create an in-memory Stage with /World Xform prim as the default prim
stage: Usd.Stage = Usd.Stage.CreateInMemory()
default_prim = UsdGeom.Xform.Define(stage, Sdf.Path("/World"))
stage.SetDefaultPrim(default_prim.GetPrim())
# Create some prims
UsdGeom.Xform.Define(stage, "/World/Group")
UsdGeom.Cube.Define(stage, "/World/Group/Foo")
# Get a prim using a str object
group_prim_path = "/World/Group"
group_prim = get_prim_by_path(stage, group_prim_path)
# Get a prim using an Sdf.Path object
foo_prim_path = Sdf.Path("/World/Group/Foo")
foo_prim = get_prim_by_path(stage, foo_prim_path)
# Print the prim objects that were retrieved
print(group_prim)
print(foo_prim)
# Check that the prims retrieve match the paths provided
assert group_prim.GetPath() == Sdf.Path(group_prim_path)
assert foo_prim.GetPath() == foo_prim_path | 1,214 | Python | 30.973683 | 98 | 0.729819 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/prims/get-prim/py_usd.md | Get a prim by using the prim’s path:
``` {literalinclude} py_usd.py
:language: py
``` | 86 | Markdown | 16.399997 | 36 | 0.674419 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/prims/get-prim/config.toml | [core]
title = "Get a Prim"
[metadata]
description = "Universal Scene Description (OpenUSD) code samples for accessing or getting a Prim on the Stage."
keywords = ["OpenUSD", "USD", "Python", "code sample", "prim", "get prim", "accessing", "IsValid", "valid"] | 260 | TOML | 42.499993 | 112 | 0.696154 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/prims/get-current-selected-prims/py_usdview.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from typing import List
from pxr import Usd
prims: List[Usd.Prim] = usdviewApi.selectedPrims | 231 | Python | 32.142853 | 98 | 0.792208 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/prims/get-current-selected-prims/py_omni_usd.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
import omni.usd
prim_path = "/World/My/Prim"
ctx = omni.usd.get_context()
# returns a list of prim path strings
selection = ctx.get_selection().get_selected_prim_paths() | 308 | Python | 33.33333 | 98 | 0.756494 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/prims/get-current-selected-prims/py_usdview.md | *usdview* Python interpreter has a built-in object called `usdviewApi` that gives you access to the currently selected prims.
``` {literalinclude} py_usdview.py
:language: py
``` | 178 | Markdown | 43.749989 | 125 | 0.769663 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/prims/get-current-selected-prims/config.toml | [core]
title = "Get the Currently Selected Prims"
[metadata]
description = "Universal Scene Description (OpenUSD) code samples for getting the currently selected prim(s)."
keywords = ["OpenUSD", "USD", "Python", "code sample", "prim", "selection", "selected", "prims", "usdview"] | 281 | TOML | 45.999992 | 110 | 0.715302 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/prims/get-current-selected-prims/py_omni_usd.md | ``` {literalinclude} py_omni_usd.py
:language: py
``` | 53 | Markdown | 16.999994 | 35 | 0.660377 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/inherits/add-inherit/py_usd.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from pxr import Usd
def add_inherit(stage: Usd.Stage, prim: Usd.Prim, class_prim: Usd.Prim):
inherits: Usd.Inherits = prim.GetInherits()
inherits.AddInherit(class_prim.GetPath())
#############
# Full Usage
#############
from pxr import Sdf, UsdGeom
# Create an in-memory Stage with /World Xform prim as the default prim
stage: Usd.Stage = Usd.Stage.CreateInMemory()
default_prim: Usd.Prim = UsdGeom.Xform.Define(stage, Sdf.Path("/World")).GetPrim()
stage.SetDefaultPrim(default_prim)
# The base prim typically uses the "class" Specifier to designate that it
# is meant to be inherited and skipped in standard stage traversals
tree_class: Usd.Prim = stage.CreateClassPrim("/_class_Tree")
tree_prim: Usd.Prim = UsdGeom.Mesh.Define(stage, default_prim.GetPath().AppendPath("TreeA")).GetPrim()
add_inherit(stage, tree_prim, tree_class)
usda = stage.GetRootLayer().ExportToString()
print(usda)
# Check to see if the inherit was added
inherits_list = tree_prim.GetInherits().GetAllDirectInherits()
assert tree_class.GetPath() in inherits_list | 1,190 | Python | 35.090908 | 102 | 0.743697 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/inherits/add-inherit/py_usd.md | This code sample shows how to add an Inherit arc to a prim. A single prim can have multiple Inherits.
``` {literalinclude} py_usd.py
:language: py
```
| 152 | Markdown | 24.499996 | 101 | 0.730263 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/inherits/add-inherit/usda.md | This is an example USDA result adding an Inherit Arc to a prim.
``` {literalinclude} usda.usda
:language: usd
``` | 114 | Markdown | 27.749993 | 63 | 0.72807 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/inherits/add-inherit/config.toml | [core]
title = "Add an Inherit"
[metadata]
description = "Universal Scene Description (OpenUSD) code samples for adding an Inherit composition arc to a prim."
keywords = ["OpenUSD", "USD", "Python", "snippet", "code sample", "inherit", "AddInherit", "composition", "composition arc"] | 284 | TOML | 46.499992 | 124 | 0.721831 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/data-types/convert-vtarray-numpy/py_usd.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
import numpy
from pxr import Vt
def convert_vt_to_np(my_array: Vt.Vec3fArray) -> numpy.ndarray:
return numpy.array(my_vec3_array)
#############
# Full Usage
#############
# Create a Vt.Vec3fArray and convert it to a numpy array
my_vec3_array = Vt.Vec3fArray([(1,2,3),(4,5,6),(7,8,9)])
np_array: numpy.ndarray = convert_vt_to_np(my_vec3_array)
# print the numpy array to check the values
print(np_array)
# check the size and length of the numpy array
assert np_array.size == 9
assert len(np_array) == 3
| 651 | Python | 24.076922 | 98 | 0.695853 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/data-types/convert-vtarray-numpy/py_usd.md | **Convert to Numpy Array**
To convert a VtArray to a Numpy Array, simply pass the VtArray object to `numpy.array` constructor.
``` {literalinclude} py_usd.py
:language: py
```
**Convert from Numpy Array**
To convert a Numpy Array to a VtArray, you can use `FromNumpy()` from the VtArray class you want to convert to.
``` {literalinclude} py_usd_var1.py
:language: py
``` | 377 | Markdown | 24.199998 | 111 | 0.71618 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/data-types/convert-vtarray-numpy/config.toml | [core]
title = "Convert Between VtArray and Numpy Array"
[metadata]
description = "Universal Scene Description (OpenUSD) code samples for converting between VtArray classes and Numpy."
keywords = ["OpenUSD", "USD", "Python", "snippet", "code sample", "types", "array", "numpy", "VtArray"] | 289 | TOML | 47.333325 | 116 | 0.726644 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/data-types/convert-vtarray-numpy/py_usd_var1.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
import numpy
from pxr import Vt
def convert_np_to_vt(my_array: numpy.ndarray) -> Vt.Vec3fArray:
return Vt.Vec3fArray.FromNumpy(my_array)
#############
# Full Usage
#############
# Create a numpy array and convert it into a Vt.Vec3fArray
np_array = numpy.array([(1,2,3),(4,5,6),(7,8,9)])
from_numpy: Vt.Vec3fArray = convert_np_to_vt(np_array)
# Print the Vt.Vec3fArray to check the values
print(from_numpy)
# Check the length of the numpy array
assert len(np_array) == 3 | 618 | Python | 24.791666 | 98 | 0.700647 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/data-types/convert-vtarray-numpy/header.md | Some Attributes store array type data which are accessed using the VtArray classes. You can find a list of the VtArray classes in our [USD Data Types documentation](https://docs.omniverse.nvidia.com/dev-guide/latest/dev_usd/quick-start/usd-types.html)
If you need to manipulate the arrays using Python, it is advantageous to use Numpy to benefit from it's speed and efficiency. These code samples show how you can convert between the VtArray objects and Numpy Array objects.
```{note}
These examples show how to convert using only the Vt.Vec3fArray class, but the same can be applied to any VtArray class. See what other VtArray classes exist in the [USD Data Types documentation](https://docs.omniverse.nvidia.com/dev-guide/latest/dev_usd/quick-start/usd-types.html).
```
| 778 | Markdown | 76.899992 | 283 | 0.790488 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/paths/concatenate-property-with-prim-path/py_usd.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from pxr import Sdf
def concat_property_with_prim_path(prim_path: Sdf.Path, prop) -> Sdf.Path:
prop_path = prim_path.AppendProperty(prop)
return prop_path
#############
# Full Usage
#############
# e.g., get path to "points" attribute on a mesh prim
from pxr import UsdGeom, Usd
stage: Usd.Stage = Usd.Stage.CreateInMemory()
default_prim: Usd.Prim = UsdGeom.Xform.Define(stage, Sdf.Path("/World")).GetPrim()
stage.SetDefaultPrim(default_prim)
mesh_prim: Usd.Prim = UsdGeom.Xform.Define(stage, Sdf.Path("/World/Mesh")).GetPrim()
prop_path: Sdf.Path = concat_property_with_prim_path(mesh_prim.GetPrimPath(), UsdGeom.Tokens.points) #nothing happend so did it get added?
usda = stage.GetRootLayer().ExportToString()
print(usda)
assert Sdf.Path.IsValidPathString(prop_path.pathString) | 932 | Python | 33.555554 | 138 | 0.73176 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/paths/concatenate-property-with-prim-path/py_usd.md | ``` {literalinclude} py_usd.py
:language: py
```
| 49 | Markdown | 11.499997 | 30 | 0.632653 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/paths/concatenate-property-with-prim-path/config.toml | [core]
title = "Concatenate a Property Name with a Prim Path"
[metadata]
description = "Universal Scene Description (OpenUSD) code samples showing how to concatenate a property name with a prim path."
keywords = ["OpenUSD", "USD", "Python", "snippet", "code sample", "prim", "property", "path", "AppendProperty"] | 313 | TOML | 51.333325 | 127 | 0.728435 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/paths/get-parent-path/py_usd.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from pxr import Sdf
def get_parent_path(prim_path: Sdf.Path) -> Sdf.Path:
parent_path = prim_path.GetParentPath()
return parent_path
#############
# Full Usage
#############
from pxr import Usd, UsdGeom
# Create an in-memory Stage with /World Xform prim as the default prim
stage: Usd.Stage = Usd.Stage.CreateInMemory()
default_prim: Usd.Prim = UsdGeom.Xform.Define(stage, Sdf.Path("/World")).GetPrim()
stage.SetDefaultPrim(default_prim)
cone_prim = UsdGeom.Cone.Define(stage, Sdf.Path("/World/Cone")).GetPrim()
# Given Sdf.Path('/World/Cone') for my_prim_path, parent_path will contain Sdf.Path('/World')
parent_path = get_parent_path(cone_prim.GetPrimPath())
usda = stage.GetRootLayer().ExportToString()
print(usda)
assert parent_path == default_prim.GetPrimPath() | 918 | Python | 33.037036 | 98 | 0.724401 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/paths/get-parent-path/py_usd.md | ``` {literalinclude} py_usd.py
:language: py
```
| 49 | Markdown | 11.499997 | 30 | 0.632653 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/paths/get-parent-path/usda.md | This is an example USDA result from adding a Cone to the a World Prim.
``` {literalinclude} usda.usda
:language: usd
``` | 121 | Markdown | 29.499993 | 70 | 0.727273 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/paths/get-parent-path/config.toml | [core]
title = "Get the Parent Path for a Prim Path"
[metadata]
description = "Universal Scene Description (OpenUSD) code samples for getting the parent path from a prim path."
keywords = ["OpenUSD", "USD", "Python", "snippet", "code sample", "prim", "path", "GetParentPath"] | 276 | TOML | 45.166659 | 112 | 0.713768 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/paths/concatenate-prim-path/py_usd.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from pxr import Sdf
def concat_prim_path(prim_path: Sdf.Path, path_to_add: str) -> Sdf.Path:
concat_path = prim_path.AppendPath(path_to_add)
return concat_path
#############
# Full Usage
#############
from pxr import Usd, UsdGeom
# Create an in-memory Stage with /World Xform prim as the default prim
stage: Usd.Stage = Usd.Stage.CreateInMemory()
default_prim: Usd.Prim = UsdGeom.Xform.Define(stage, Sdf.Path("/World")).GetPrim()
stage.SetDefaultPrim(default_prim)
# Concatenate the Paths
concatenated_prim_path: Sdf.Path = concat_prim_path(default_prim.GetPrimPath(), "Kitchen_set/Props_grp/North_grp/NorthWall_grp/MeasuringSpoon_1")
usda = stage.GetRootLayer().ExportToString()
print(usda)
assert concatenated_prim_path.pathString == "/World/Kitchen_set/Props_grp/North_grp/NorthWall_grp/MeasuringSpoon_1" | 960 | Python | 34.592591 | 145 | 0.742708 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/paths/concatenate-prim-path/py_usd.md | ``` {literalinclude} py_usd.py
:language: py
```
| 49 | Markdown | 11.499997 | 30 | 0.632653 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/paths/concatenate-prim-path/config.toml | [core]
title = "Concatenate a Prim Path"
[metadata]
description = "Universal Scene Description (OpenUSD) code samples for concatenating prim paths."
keywords = ["OpenUSD", "USD", "Python", "snippet", "code sample", "concatenate", "prim", "path", "AppendPath"] | 261 | TOML | 42.66666 | 111 | 0.712644 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/get-relationship-targets/py_usd.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from pxr import Usd, UsdGeom
# For example, getting the proxy prim on an Imageable
proxy_prim_rel: Usd.Relationship = UsdGeom.Imageable(myprim).GetProxyPrimRel()
proxyPrimTargets = proxy_prim_rel.GetForwardedTargets() | 356 | Python | 43.624995 | 98 | 0.797753 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/get-relationship-targets/py_usd.md | ``` {literalinclude} py_usd.py
:language: py
``` | 48 | Markdown | 15.333328 | 30 | 0.645833 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/get-relationship-targets/config.toml | [core]
# The title for this code sample. Used to name the page.
title = "Get the Targets of a Relationship"
[metadata]
#A concise description of the code sample for SEO.
description = "Universal Scene Description (OpenUSD) code samples for getting the targets of a Relationship taking into account relationship forwarding."
# Put in SEO keywords relevant to this code sample.
keywords = ["OpenUSD", "USD", "code sample", "snippet", "Python", "C++", "relationship", "targets", "relationship forwarding"] | 503 | TOML | 54.999994 | 153 | 0.751491 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/check-property-exists/py_usd.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from pxr import Usd
pts_attr: Usd.Attribute = mesh_prim.GetAttribute("points")
if pts_attr.IsValid():
print("Attribute exists!") | 271 | Python | 32.999996 | 98 | 0.756458 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/check-property-exists/py_usd.md | ``` {literalinclude} py_usd.py
:language: py
```
Alternatively, `Usd.Object` overrides the boolean operator so you can check with a simple boolean expression.
``` {literalinclude} py_usd_var1.py
:language: py
``` | 214 | Markdown | 22.888886 | 109 | 0.728972 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/check-property-exists/config.toml | [core]
# The title for this code sample. Used to name the page.
title = "Check if a Property Exists"
[metadata]
#A concise description of the code sample for SEO.
description = "Universal Scene Description (OpenUSD) code samples for checking if a Property exists."
# Put in SEO keywords relevant to this code sample.
keywords = ["OpenUSD", "USD", "code sample", "snippet", "Python", "C++", "property", "relationship", "attribute", "IsValid", "exists", "valid"] | 461 | TOML | 50.333328 | 143 | 0.720174 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/check-property-exists/py_usd_var1.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from pxr import Usd
pts_attr: Usd.Attribute = mesh_prim.GetAttribute("points")
if pts_attr:
print("Attribute exists!") | 261 | Python | 31.749996 | 98 | 0.758621 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/check-property-exists/header.md | Certain functions may return a `Usd.Property` object, but the Property may not exist due to an incorrect path or because of changes on the Stage. You can use [Usd.Object.IsValid()](https://openusd.org/release/api/class_usd_object.html#ac532c4b500b1a85ea22217f2c65a70ed) to check if the Property is valid or exists.
```{note}
Remember, that Properties consist of `Usd.Attribute` and `Usd.Relationship`. You can perform this check on both types of objects.
```
| 464 | Markdown | 76.499987 | 314 | 0.773707 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/create-relationship/py_usd.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from pxr import Usd
prim: Usd.Prim = stage.GetPrimAtPath("/World/MyPrim")
custom_relationship: Usd.Relationship = prim.CreateRelationship("myCustomRelationship")
# You can also use Usd.Relationship.AddTarget() to add targets to an existing Relationship.
custom_relationship.SetTargets(["/World/TargetA", "/World/TargetB"]) | 461 | Python | 50.333328 | 98 | 0.789588 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/create-relationship/py_usd.md | ``` {literalinclude} py_usd.py
:language: py
``` | 48 | Markdown | 15.333328 | 30 | 0.645833 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/create-relationship/config.toml | [core]
# The title for this code sample. Used to name the page.
title = "Create a Relationship"
[metadata]
#A concise description of the code sample for SEO.
description = "Universal Scene Description (OpenUSD) code samples for creating a Relationship."
# Put in SEO keywords relevant to this code sample.
keywords = ["OpenUSD", "USD", "code sample", "snippet", "Python", "C++", "property", "relationship", "create", "create relationship"] | 440 | TOML | 47.999995 | 133 | 0.731818 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/create-attribute/py_kit_cmds.md | The `CreateUsdAttributeCommand` command in Kit can create an Attribute on a prim. The Attribute name and type are required.
``` {literalinclude} py_kit_cmds.py
:language: py
``` | 180 | Markdown | 35.199993 | 125 | 0.755556 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/create-attribute/py_usd.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from pxr import Gf, Sdf, Usd, UsdGeom
"""
Find all relevant data types at: https://openusd.org/release/api/_usd__page__datatypes.html
"""
def create_float_attribute(prim: Usd.Prim, attribute_name: str) -> Usd.Attribute:
"""Creates attribute for a prim that holds a float.
See: https://openusd.org/release/api/class_usd_prim.html
Args:
prim (Usd.Prim): A Prim for holding the attribute.
attribute_name (str): The name of the attribute to create.
Returns:
Usd.Attribute: An attribute created at specific prim.
"""
attr: Usd.Attribute = prim.CreateAttribute(attribute_name, Sdf.ValueTypeNames.Float)
return attr
def create_vector_attribute(prim: Usd.Prim, attribute_name: str) -> Usd.Attribute:
"""Creates attribute for a prim that holds a vector.
See: https://openusd.org/release/api/class_usd_prim.html
Args:
prim (Usd.Prim): A Prim for holding the attribute.
attribute_name (str): The name of the attribute to create.
Returns:
Usd.Attribute: An attribute created at specific prim.
"""
attr: Usd.Attribute = prim.CreateAttribute(
attribute_name, Sdf.ValueTypeNames.Float3
)
return attr
#############
# Full Usage
#############
# Create an in-memory Stage
stage: Usd.Stage = Usd.Stage.CreateInMemory()
# Create a prim named /World (type Xform) and make it the default prim.
prim_path = "/World"
xform: UsdGeom.Xform = UsdGeom.Xform.Define(stage, prim_path)
prim: Usd.Prim = xform.GetPrim()
stage.SetDefaultPrim(prim)
# Create a float attribute on /World
float_attr: Usd.Attribute = create_float_attribute(prim, "my_float_attr")
# Create a vector attribute on /World
vector_attr: Usd.Attribute = create_vector_attribute(prim, "my_vector_attr")
# Set and query values
print(float_attr.Get())
float_attr.Set(0.1)
print(float_attr.Get())
vector_value: Gf.Vec3f = Gf.Vec3f(0.1, 0.2, 0.3)
print(vector_attr.Get())
vector_attr.Set(vector_value)
print(vector_attr.Get())
# Optionally preview the usd
# print(stage.GetRootLayer().ExportToString())
| 2,205 | Python | 30.514285 | 98 | 0.702041 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/create-attribute/py_usd.md | With the USD API, you can use `Usd.Prim.CreateAttribute()` to create `attributes` on `Usd.Prim` objects.
You can set the value using `Usd.Attribute.Set()` and query the value using `Usd.Attribute.Get()`
``` {literalinclude} py_usd.py
:language: py
```
| 253 | Markdown | 35.285709 | 104 | 0.719368 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/create-attribute/py_kit_cmds.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
import omni.kit.commands
import omni.usd
from pxr import Gf, Sdf, Usd, UsdGeom
def create_float_attribute(prim: Usd.Prim, attribute_name: str) -> Usd.Attribute:
"""Creates attribute for a prim that holds a float.
See: https://openusd.org/release/api/class_usd_prim.html
See: https://docs.omniverse.nvidia.com/kit/docs/omni.usd/latest/omni.usd.commands/omni.usd.commands.CreateUsdAttributeCommand.html
Args:
prim (Usd.Prim): A Prim for holding the attribute.
attribute_name (str): The name of the attribute to create.
Returns:
Usd.Attribute: An attribute created at specific prim.
"""
omni.kit.commands.execute(
"CreateUsdAttributeCommand",
prim=prim,
attr_name=attribute_name,
attr_type=Sdf.ValueTypeNames.Float,
)
attr: Usd.Attribute = prim.GetAttribute(attribute_name)
return attr
def create_vector_attribute(prim: Usd.Prim, attribute_name: str) -> Usd.Attribute:
"""Creates attribute for a prim that holds a vector.
See: https://openusd.org/release/api/class_usd_prim.html
See: https://docs.omniverse.nvidia.com/kit/docs/omni.usd/latest/omni.usd.commands/omni.usd.commands.CreateUsdAttributeCommand.html
Args:
prim (Usd.Prim): A Prim for holding the attribute.
attribute_name (str): The name of the attribute to create.
Returns:
Usd.Attribute: An attribute created at specific prim.
"""
omni.kit.commands.execute(
"CreateUsdAttributeCommand",
prim=prim,
attr_name=attribute_name,
attr_type=Sdf.ValueTypeNames.Float3,
)
attr: Usd.Attribute = prim.GetAttribute(attribute_name)
return attr
#############
# Full Usage
#############
# Get the current stage
stage: Usd.Stage = omni.usd.get_context().get_stage()
# Get the default prim
prim: Usd.Prim = stage.GetDefaultPrim()
# Create a float attribute on /World
float_attr: Usd.Attribute = create_float_attribute(prim, "my_float_attr")
# Create a vector attribute on /World
vector_attr: Usd.Attribute = create_vector_attribute(prim, "my_vector_attr")
# Set and query values
print(float_attr.Get())
float_attr.Set(0.1)
print(float_attr.Get())
vector_value: Gf.Vec3f = Gf.Vec3f(0.1, 0.2, 0.3)
print(vector_attr.Get())
vector_attr.Set(vector_value)
print(vector_attr.Get())
# Optionally preview the usd
# print(stage.GetRootLayer().ExportToString())
| 2,539 | Python | 31.151898 | 134 | 0.700276 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/create-attribute/usda.md | This is an example USDA result from creating an Xform and Cube prim. Where the Cube prim is a child of the Xform and the Xform has it's own Translation Ops.
``` {literalinclude} usda.usda
:language: usd
``` | 207 | Markdown | 50.999987 | 156 | 0.753623 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/create-attribute/config.toml | [core]
# The title for this code sample. Used to name the page.
title = "Create an Attribute"
[metadata]
description = "Universal Scene Description (OpenUSD) code samples to create an attribute."
keywords = ["OpenUSD", "USD", "Python", "snippet", "code sample", "attribute", "property", "create"] | 297 | TOML | 41.571423 | 100 | 0.717172 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/create-attribute/header.md | Creating an Attribute on a layer ensures that it is concretely defined on the Stage. It will always return a value `Usd.Attribute` object.
| 139 | Markdown | 68.999966 | 138 | 0.798561 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/set-attribute/py_kit_cmds.md | The `ChangeProperty` command allows users to undo the operation, but you must provide the value to use during the undo operation as the `prev` parameter.
``` {literalinclude} py_kit_cmds.py
:language: py
```
You can also set a timesample value at a particular time:
``` {literalinclude} py_kit_cmds_var1.py
:language: py
``` | 327 | Markdown | 28.818179 | 153 | 0.743119 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/set-attribute/py_usd.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from pxr import Usd, Sdf, Gf
def set_float_attribute(attr: Usd.Attribute, value: float) -> None:
"""
See: https://openusd.org/release/api/class_usd_attribute.html
Args:
attr: The attribute to set.
value: A floating point value, i.e. `3.141516`.
"""
attr.Set(value)
def set_vector_attribute(attr: Usd.Attribute, value: Gf.Vec3f) -> None:
"""
Args:
attr: The attribute to set.
value: A floating point vector, i.e. `(1., 2., 3.)`.
"""
attr.Set(value) | 655 | Python | 30.238094 | 98 | 0.638168 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/set-attribute/py_usd.md | ``` {literalinclude} py_usd.py
:language: py
```
You can also set a timesample value at a particular time:
``` {literalinclude} py_usd_var1.py
:language: py
``` | 162 | Markdown | 17.111109 | 57 | 0.691358 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/set-attribute/py_kit_cmds_var1.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
import omni.kit.commands
from pxr import Gf, Sdf, Usd
prim_path = Sdf.Path("/World/defaultLight")
prim: Usd.Prim = stage.GetPrimAtPath(prim_path)
prop_name = "xformOp:rotateXYZ"
rotation = prim.GetAttribute(prop_name)
omni.kit.commands.execute("ChangeProperty",
prop_path=Sdf.Path(prim_path.AppendProperty(prop_name)),
value=Gf.Vec3d(180.0, 0.0, 0.0),
prev=rotation.Get(10.0),
timecode=Usd.TimeCode(10.0)
) | 561 | Python | 34.124998 | 98 | 0.741533 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/set-attribute/py_kit_cmds.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
import omni.kit.commands
from pxr import Gf, Sdf, Usd
prim_path = Sdf.Path("/World/defaultLight")
prim: Usd.Prim = stage.GetPrimAtPath(prim_path)
prop_name = "xformOp:rotateXYZ"
rotation = prim.GetAttribute(prop_name)
omni.kit.commands.execute("ChangeProperty",
prop_path=Sdf.Path(prim_path.AppendProperty(prop_name)),
value=Gf.Vec3d(180.0, 0.0, 0.0),
prev=rotation.Get()
) | 524 | Python | 33.999998 | 98 | 0.746183 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/set-attribute/config.toml | [core]
# The title for this code sample. Used to name the page.
title = "Set the Value of an Attribute"
[metadata]
#A concise description of the code sample for SEO.
description = "Universal Scene Description (OpenUSD) code samples for setting the value of an Attribute."
# Put in SEO keywords relevant to this code sample.
keywords = ["OpenUSD", "USD", "code sample", "snippet", "Python", "C++", "attribute", "set", "value", "ChangeProperty", "Omniverse Kit", "Kit Commands"] | 477 | TOML | 52.111105 | 152 | 0.721174 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/set-attribute/py_usd_var1.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from pxr import Usd, Sdf, Gf
def set_float_attribute_at_time(attr: Usd.Attribute, value: float, time_value: float) -> None:
"""
See: https://openusd.org/release/api/class_usd_attribute.html
Args:
attr: The attribute to set.
value: A floating point value, i.e. `3.141516`.
time_value: Set a timesample at a particular time.
"""
attr.Set(value, time_value)
def set_vector_attribute_at_time(attr: Usd.Attribute, value: Gf.Vec3f, time_value: float) -> None:
"""
Args:
attr: The attribute to set.
value: A floating point vector, i.e. `(1., 2., 3.)`.
time_value: Set a timesample at a particular time.
"""
attr.Set(value, time_value) | 851 | Python | 36.043477 | 98 | 0.653349 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/get-attribute-value/py_usd.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from pxr import Usd, Sdf
def get_attribute_value(prim: Usd.Prim, attribute_name: str):
"""
See: https://openusd.org/release/api/class_usd_attribute.html
Args:
prim: The prim owner of the attribute.
attribute_name: The name of the attribute to retrieve.
Return:
The value of the attribute, see https://openusd.org/release/api/_usd__page__datatypes.html
for the return types.
For example, for `float3`, the return type will be `Gf.Vec3f`.
"""
attr = prim.GetAttribute(attribute_name)
return attr.Get() | 706 | Python | 38.277776 | 98 | 0.686969 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/get-attribute-value/py_usd.md | ``` {literalinclude} py_usd.py
:language: py
```
You can also get the value at a particular time:
``` {literalinclude} py_usd_var1.py
:language: py
``` | 153 | Markdown | 16.111109 | 48 | 0.679739 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/get-attribute-value/config.toml | [core]
# The title for this code sample. Used to name the page.
title = "Get the Value of an Attribute"
[metadata]
#A concise description of the code sample for SEO.
description = "Universal Scene Description (OpenUSD) code samples for getting the value of an Attribute."
# Put in SEO keywords relevant to this code sample.
keywords = ["OpenUSD", "USD", "code sample", "snippet", "Python", "C++", "attribute", "get", "value", "value resolution", "GetAttribute"] | 462 | TOML | 50.444439 | 137 | 0.722944 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/get-attribute-value/py_usd_var1.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from pxr import Usd, Sdf
def get_attribute_value_at_time(prim: Usd.Prim, attribute_name: str, time_value: float):
"""
See: https://openusd.org/release/api/class_usd_attribute.html
Args:
prim: The prim owner of the attribute.
attribute_name: The name of the attribute to retrieve.
time_value: Get the value authored or interpolated at a particular time.
Return:
The value of the attribute, see https://openusd.org/release/api/_usd__page__datatypes.html
for the return types.
For example, for `float3`, the return type will be `Gf.Vec3f`.
"""
attr = prim.GetAttribute(attribute_name)
return attr.Get(time_value) | 824 | Python | 42.42105 | 98 | 0.695388 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/add-relationship-target/py_usd.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from pxr import Usd, UsdGeom
# For example, adding a proxy prim target on an Imageable
proxy_prim_rel: Usd.Relationship = UsdGeom.Imageable(myprim).GetProxyPrimRel()
proxy_prim_rel.AddTarget("/World/MyProxy")
| 348 | Python | 37.777774 | 98 | 0.784483 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/add-relationship-target/py_usd.md |
``` {literalinclude} py_usd.py
:language: py
``` | 49 | Markdown | 11.499997 | 30 | 0.632653 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/properties/add-relationship-target/config.toml | [core]
# The title for this code sample. Used to name the page.
title = "Add a Relationship Target"
[metadata]
#A concise description of the code sample for SEO.
description = "Universal Scene Description (OpenUSD) code samples for adding a target to a Relationship."
# Put in SEO keywords relevant to this code sample.
keywords = ["OpenUSD", "USD", "code sample", "snippet", "Python", "C++", "relationship", "targets", "property"] | 432 | TOML | 47.111106 | 111 | 0.729167 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/materials/create-usdpreviewsurface-material/py_kit_cmds.md | This version creates just the material prim and UsdPreviewSurface Shader.
``` {literalinclude} py_kit_cmds.py
:language: py
```
This version also creates UsdUVTexture Shader prims for the diffuse, roughness, metallic, and normal properties and connects them to the UsdPreviewSurface.
``` {literalinclude} py_kit_cmds_var1.py
:language: py
``` | 345 | Markdown | 30.454543 | 155 | 0.776812 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/materials/create-usdpreviewsurface-material/py_usd.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from pxr import Sdf, UsdShade
mtl_path = Sdf.Path("/World/Looks/PreviewSurface")
mtl = UsdShade.Material.Define(stage, mtl_path)
shader = UsdShade.Shader.Define(stage, mtl_path.AppendPath("Shader"))
shader.CreateIdAttr("UsdPreviewSurface")
shader.CreateInput("diffuseColor", Sdf.ValueTypeNames.Color3f).Set([1.0, 0.0, 0.0])
shader.CreateInput("roughness", Sdf.ValueTypeNames.Float).Set(0.5)
shader.CreateInput("metallic", Sdf.ValueTypeNames.Float).Set(0.0)
mtl.CreateSurfaceOutput().ConnectToSource(shader.ConnectableAPI(), "surface") | 673 | Python | 50.84615 | 98 | 0.783061 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/materials/create-usdpreviewsurface-material/py_usd.md | This version creates just the Material prim and UsdPreviewSurface Shader.
``` {literalinclude} py_usd.py
:language: py
```
This version also creates UsdUVTexture Shader prim and connects it to the diffuse property of the UsdPreviewSurface.
``` {literalinclude} py_usd_var1.py
:language: py
``` | 296 | Markdown | 25.999998 | 116 | 0.77027 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/materials/create-usdpreviewsurface-material/py_kit_cmds_var1.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
import omni.kit.commands
omni.kit.commands.execute("CreatePreviewSurfaceTextureMaterialPrim",
mtl_path="/World/Looks/PreviewSurfaceWithTextures",
select_new_prim=True)
| 316 | Python | 30.699997 | 98 | 0.791139 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/materials/create-usdpreviewsurface-material/py_kit_cmds.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
import omni.kit.commands
omni.kit.commands.execute("CreatePreviewSurfaceMaterialPrim",
mtl_path="/World/Looks/PreviewSurface",
select_new_prim=True)
| 297 | Python | 28.799997 | 98 | 0.777778 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/materials/create-usdpreviewsurface-material/config.toml | [core]
title = "Create a UsdPreviewSurface Material"
[metadata]
description = "Universal Scene Description (OpenUSD) code samples for creating a UsdPreviewSurface material including UsdUVTexture Shader for loading data from textures."
keywords = ["OpenUSD", "USD", "Python", "snippet", "code sample", "Omniverse Kit", "Kit Commands", "UsdPreviewSurface", "material", "CreatePreviewSurfaceMaterialPrim", "UsdUVTexture"]
| 420 | TOML | 59.142849 | 183 | 0.77619 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/materials/create-usdpreviewsurface-material/py_usd_var1.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from pxr import Sdf, UsdShade
mtl_path = Sdf.Path("/World/Looks/PreviewSurface")
mtl = UsdShade.Material.Define(stage, mtl_path)
shader = UsdShade.Shader.Define(stage, mtl_path.AppendPath("Shader"))
shader.CreateIdAttr("UsdPreviewSurface")
shader.CreateInput("diffuseColor", Sdf.ValueTypeNames.Color3f).Set((1.0, 0.0, 0.0))
shader.CreateInput("roughness", Sdf.ValueTypeNames.Float).Set(0.5)
shader.CreateInput("metallic", Sdf.ValueTypeNames.Float).Set(0.0)
diffuse_tx = UsdShade.Shader.Define(stage,mtl_path.AppendPath("DiffuseColorTx"))
diffuse_tx.CreateIdAttr('UsdUVTexture')
diffuse_tx.CreateInput('file', Sdf.ValueTypeNames.Asset).Set("C:/path/to/texture.png")
diffuse_tx.CreateOutput('rgb', Sdf.ValueTypeNames.Float3)
shader.CreateInput("diffuseColor", Sdf.ValueTypeNames.Color3f).ConnectToSource(diffuse_tx.ConnectableAPI(), 'rgb')
mtl.CreateSurfaceOutput().ConnectToSource(shader.ConnectableAPI(), "surface") | 1,055 | Python | 54.578944 | 114 | 0.788626 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/materials/create-mdl-material/py_kit_cmds.md | ``` {literalinclude} py_kit_cmds.py
:language: py
``` | 53 | Markdown | 16.999994 | 35 | 0.660377 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/materials/create-mdl-material/py_usd.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from pxr import Sdf, UsdShade
mtl_path = Sdf.Path("/World/Looks/OmniPBR")
mtl = UsdShade.Material.Define(stage, mtl_path)
shader = UsdShade.Shader.Define(stage, mtl_path.AppendPath("Shader"))
shader.CreateImplementationSourceAttr(UsdShade.Tokens.sourceAsset)
# MDL shaders should use "mdl" sourceType
shader.SetSourceAsset("OmniPBR.mdl", "mdl")
shader.SetSourceAssetSubIdentifier("OmniPBR", "mdl")
# MDL materials should use "mdl" renderContext
mtl.CreateSurfaceOutput("mdl").ConnectToSource(shader.ConnectableAPI(), "out")
mtl.CreateDisplacementOutput("mdl").ConnectToSource(shader.ConnectableAPI(), "out")
mtl.CreateVolumeOutput("mdl").ConnectToSource(shader.ConnectableAPI(), "out") | 824 | Python | 50.562497 | 98 | 0.792476 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/materials/create-mdl-material/py_usd.md | ``` {literalinclude} py_usd.py
:language: py
``` | 48 | Markdown | 15.333328 | 30 | 0.645833 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/materials/create-mdl-material/py_kit_cmds.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
import omni.kit.commands
success, result = omni.kit.commands.execute('CreateMdlMaterialPrimCommand',
mtl_url='OmniPBR.mdl', # This can be path to local or remote MDL
mtl_name='OmniPBR', # sourceAsset:subIdentifier (i.e. the name of the material within the MDL)
mtl_path="/World/Looks/OmniPBR" # Prim path for the Material to create.
)
| 486 | Python | 43.272723 | 98 | 0.751029 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/materials/create-mdl-material/config.toml | [core]
title = "Create an MDL Material"
[metadata]
description = "Universal Scene Description (OpenUSD) code samples for creating an MDL material with a Shader prim with an MDL source asset."
keywords = ["OpenUSD", "USD", "Python", "snippet", "code sample", "Omniverse Kit", "Kit Commands", "shader", "material", "CreateMdlMaterialPrimCommand"]
| 346 | TOML | 48.571422 | 152 | 0.736994 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/stage/set-default-prim/py_usd.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from pxr import Usd
def set_default_prim(stage: Usd.Stage, prim: Usd.Prim):
stage.SetDefaultPrim(prim)
#############
# Full Usage
#############
from pxr import UsdGeom, Sdf
# Create new USD stage for this sample
stage: Usd.Stage = Usd.Stage.CreateInMemory()
# Create an xform which should be set as the default prim
default_prim: Usd.Prim = UsdGeom.Xform.Define(stage, Sdf.Path("/World")).GetPrim()
# Make the xform the default prim
set_default_prim(stage, default_prim)
usda = stage.GetRootLayer().ExportToString()
print(usda)
# Check that the expected default prim was set
assert stage.GetDefaultPrim() == default_prim
| 773 | Python | 24.799999 | 98 | 0.728331 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/stage/set-default-prim/py_usd.md | ``` {literalinclude} py_usd.py
:language: py
``` | 48 | Markdown | 15.333328 | 30 | 0.645833 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/stage/set-default-prim/usda.md | This is an example USDA result from setting the `defaultPrim` metadata in an empty layer.
``` {literalinclude} usda.usda
:language: usd
``` | 140 | Markdown | 34.249991 | 89 | 0.75 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/stage/set-default-prim/config.toml | [core]
title = "Set the Default Prim on a Stage"
[metadata]
description = "Universal Scene Description (OpenUSD) code samples for setting the default prim on a Stage."
keywords = ["OpenUSD", "USD", "Python", "snippet", "code sample", "stage", "metadata", "default prim"] | 271 | TOML | 44.333326 | 107 | 0.712177 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/stage/set-stage-linear-units/py_usd.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from pxr import Usd, UsdGeom
def set_meters_per_unit(stage: Usd.Stage, unit: UsdGeom.LinearUnits = UsdGeom.LinearUnits.centimeters):
UsdGeom.SetStageMetersPerUnit(stage, unit) # Any double-precision float can be used for metersPerUnit.
#############
# Full Usage
#############
unit: UsdGeom.LinearUnits = UsdGeom.LinearUnits.centimeters
stage: Usd.Stage = Usd.Stage.CreateInMemory()
set_meters_per_unit(stage, unit)
usda = stage.GetRootLayer().ExportToString()
print(usda)
# Check that the expected meterPerUnit were set
assert UsdGeom.GetStageMetersPerUnit(stage) == unit
| 721 | Python | 30.391303 | 106 | 0.755895 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/stage/set-stage-linear-units/py_usd.md | You can set the `metersPerUnit` metadata on the stage using `UsdGeom.SetStageMetersPerUnit` to define the linear units of the stage. Convenience shortcuts for units are scoped in `UsdGeom.LinearUnits` (e.g. `UsdGeom.LinearUnits.meters` is `1.0 metersPerUnit`)
``` {literalinclude} py_usd.py
:language: py
``` | 308 | Markdown | 76.249981 | 259 | 0.775974 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/stage/set-stage-linear-units/usda.md | This is an example USDA result from setting the `metersPerUnit` metadata in an empty layer.
``` {literalinclude} usda.usda
:language: usd
``` | 142 | Markdown | 34.749991 | 91 | 0.753521 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/stage/set-stage-linear-units/config.toml | [core]
title = "Set the Stage Linear Units"
[metadata]
description = "Universal Scene Description (OpenUSD) code samples for defining the linear units of a Stage (i.e. metersPerUnit metadata)."
keywords = ["OpenUSD", "USD", "Python", "snippet", "code sample", "stage", "metadata", "metersPerUnit", "units", "linear units"] | 323 | TOML | 52.999991 | 138 | 0.718266 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/stage/set-stage-linear-units/header.md | You can set the `metersPerUnit` metadata on the stage using `UsdGeom.SetStageMetersPerUnit`. Convenience shortcuts for units are scoped in `UsdGeom.LinearUnits` (e.g. `UsdGeom.LinearUnits.meters` is `1.0 metersPerUnit`)
```{note}
Fallback stage linear units are centimeters (0.01).
```
```{warning}
Existing objects will not be automatically scaled to adapt to the stage linear units. Learn more about [stage linear units](https://openusd.org/release/api/group___usd_geom_linear_units__group.html).
```
| 511 | Markdown | 41.666663 | 219 | 0.755382 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/stage/set-stage-up-axis/py_usd.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from pxr import Usd, UsdGeom
def set_up_axis(stage: Usd.Stage, axis: UsdGeom.Tokens):
UsdGeom.SetStageUpAxis(stage, axis)
#############
# Full Usage
#############
axis: UsdGeom.Tokens = UsdGeom.Tokens.z
stage: Usd.Stage = Usd.Stage.CreateInMemory()
set_up_axis(stage, axis)
usda = stage.GetRootLayer().ExportToString()
print(usda)
# Check that the expected upAxis was set
assert UsdGeom.GetStageUpAxis(stage) == axis
| 564 | Python | 24.681817 | 98 | 0.723404 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/stage/set-stage-up-axis/py_usd.md | You can set the `upAxis` metadata on the stage using `UsdGeom.SetStageUpAxis` to define which world axis points up. The tokens for the different axes are scoped in `UsdGeom.Tokens`.
``` {literalinclude} py_usd.py
:language: py
``` | 230 | Markdown | 56.749986 | 181 | 0.76087 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/stage/set-stage-up-axis/usda.md | This is an example USDA result from setting the `upAxis` metadata in an empty layer.
``` {literalinclude} usda.usda
:language: usd
``` | 135 | Markdown | 32.999992 | 84 | 0.740741 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/stage/set-stage-up-axis/config.toml | [core]
title = "Set the Stage Up Axis"
[metadata]
description = "Universal Scene Description (OpenUSD) code samples for defining the up axis of a Stage."
keywords = ["OpenUSD", "USD", "Python", "snippet", "code sample", "stage", "metadata", "upAxis", "axis", "coordinate system"] | 280 | TOML | 45.833326 | 125 | 0.7 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/stage/set-stage-up-axis/header.md | You can set the `upAxis` metadata on the stage using `UsdGeom.SetStageUpAxis` to define which world axis points up. The tokens for the different axes are scoped in `UsdGeom.Tokens`.
```{note}
Fallback stage upAxis is Y.
```
```{warning}
Existing objects will not be automatically rotated to adapt to the stage `upAxis`. Learn more about [stage up axis](https://openusd.org/release/api/group___usd_geom_up_axis__group.html).
```
| 437 | Markdown | 32.692305 | 186 | 0.734554 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/stage/get-current-stage/py_usdview.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from pxr import Usd
stage: Usd.Stage = usdviewApi.stage | 194 | Python | 31.499995 | 98 | 0.783505 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/stage/get-current-stage/py_omni_usd.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from pxr import Usd
import omni.usd
def get_current_stage() -> Usd.Stage:
return omni.usd.get_context().get_stage()
#############
# Full Usage
#############
# Create a new USD stage through the UsdContext
success: bool = omni.usd.get_context().new_stage()
# Get the the current stage from the UsdContext
current_stage: Usd.Stage = get_current_stage()
# Check if the a new stage was created and a valid stage was returned
assert success
assert current_stage
| 604 | Python | 25.304347 | 98 | 0.720199 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/stage/get-current-stage/py_usdview.md | *usdview* Python interpreter has a built-in object called `usdviewApi` that gives you access to the currently loaded Stage.
``` {literalinclude} py_usdview.py
:language: py
``` | 176 | Markdown | 43.249989 | 123 | 0.767045 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/stage/get-current-stage/config.toml | [core]
title = "Get the Current Stage"
[metadata]
description = "Universal Scene Description (OpenUSD) code samples for getting the current Stage in Omniverse Kit and usdview."
keywords = ["OpenUSD", "USD", "Python", "snippet", "code sample", "stage", "Omniverse Kit", "usdview", "USD View"] | 292 | TOML | 47.833325 | 126 | 0.719178 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/stage/get-current-stage/py_omni_usd.md | ``` {literalinclude} py_omni_usd.py
:language: py
``` | 53 | Markdown | 16.999994 | 35 | 0.660377 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/transforms/get-local-transforms/py_usd.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
import typing
from pxr import Gf, Usd, UsdGeom
def get_local_transform_xform(prim: Usd.Prim) -> typing.Tuple[Gf.Vec3d, Gf.Rotation, Gf.Vec3d]:
"""
Get the local transformation of a prim using Xformable.
See https://openusd.org/release/api/class_usd_geom_xformable.html
Args:
prim: The prim to calculate the local transformation.
Returns:
A tuple of:
- Translation vector.
- Rotation quaternion, i.e. 3d vector plus angle.
- Scale vector.
"""
xform = UsdGeom.Xformable(prim)
local_transformation: Gf.Matrix4d = xform.GetLocalTransformation()
translation: Gf.Vec3d = local_transformation.ExtractTranslation()
rotation: Gf.Rotation = local_transformation.ExtractRotation()
scale: Gf.Vec3d = Gf.Vec3d(*(v.GetLength() for v in local_transformation.ExtractRotationMatrix()))
return translation, rotation, scale
#############
# Full Usage
#############
from pxr import Sdf
# Create an in-memory Stage with /World Xform prim as the default prim
stage: Usd.Stage = Usd.Stage.CreateInMemory()
default_prim: Usd.Prim = UsdGeom.Xform.Define(stage, Sdf.Path("/World")).GetPrim()
stage.SetDefaultPrim(default_prim)
xform: Usd.Prim = UsdGeom.Xform.Define(stage, default_prim.GetPath().AppendPath("Xform"))
xform.AddTranslateOp().Set(value=(100,10,0))
xform.AddRotateXYZOp().Set(value=(0,50,0))
xform.AddScaleOp().Set(value=(5,5,5))
cube = UsdGeom.Cube.Define(stage, xform.GetPath().AppendPath("Cube"))
cube.AddTranslateOp().Set(value=(4,0,0))
cube.AddRotateXYZOp().Set(value=(100,0,0))
cube.AddScaleOp().Set(value=(2,2,2))
transform = get_local_transform_xform(cube)
usda = stage.GetRootLayer().ExportToString()
print(usda)
cube_prim = cube.GetPrim()
assert transform[0] == cube_prim.GetAttribute('xformOp:translate').Get()
assert (100,0,0) == cube_prim.GetAttribute('xformOp:rotateXYZ').Get()
assert transform[2] == cube_prim.GetAttribute('xformOp:scale').Get() | 2,084 | Python | 35.578947 | 102 | 0.714971 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/transforms/get-local-transforms/py_omni_usd.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
import typing
import omni.usd
from pxr import Usd, Gf
def get_local_transform_omni(prim: Usd.Prim) -> typing.Tuple[Gf.Vec3d, Gf.Rotation, Gf.Vec3d]:
"""
Get the local transformation of a prim using omni.usd.get_local_transform_SRT.
See https://docs.omniverse.nvidia.com/kit/docs/omni.usd/latest/omni.usd/omni.usd.get_local_transform_SRT.html
Args:
prim: The prim to calculate the local transformation.
Returns:
A tuple of:
- Translation vector.
- Rotation quaternion, i.e. 3d vector plus angle.
- Scale vector.
"""
local_transform = omni.usd.get_local_transform_SRT(prim)
scale: Gf.Vec3d = local_transform[0]
rotation: Gf.Vec3d = local_transform[1]
rotation_order: float = local_transform[2]
translation: Gf.Vec3d = local_transform[3]
return translation, Gf.Rotation(rotation, rotation_order), scale
#############
# Full Usage
#############
import omni.kit.commands
# Create an Xform with a Cube Prim as it's Child
omni.kit.commands.execute('CreatePrimWithDefaultXform',
prim_type='Xform',
attributes={},
select_new_prim=True)
omni.kit.commands.execute('TransformMultiPrimsSRTCpp',
count=1,
paths=['/World/Xform'],
new_translations=[100, 0, 0],
new_rotation_eulers=[0, 50 ,0],
new_rotation_orders=[0, 1, 2],
new_scales=[5, 5, 5],
old_translations=[0.0, 0.0, 0.0],
old_rotation_eulers=[0.0, 0.0, 0.0],
old_rotation_orders=[0, 1, 2],
old_scales=[1.0, 1.0, 1.0],
usd_context_name='',
time_code=0.0)
omni.kit.commands.execute('CreateMeshPrimWithDefaultXform',
prim_type='Cube',
prim_path='/World/Xform/Cube',
select_new_prim=True,
prepend_default_prim=False)
omni.kit.commands.execute('TransformMultiPrimsSRTCpp',
count=1,
paths=['/World/Xform/Cube'],
new_translations=[4, 0, 0],
new_rotation_eulers=[100, 0 ,0],
new_rotation_orders=[0, 1, 2],
new_scales=[2, 2, 2],
old_translations=[0.0, 0.0, 0.0],
old_rotation_eulers=[0.0, 0.0, 0.0],
old_rotation_orders=[0, 1, 2],
old_scales=[1.0, 1.0, 1.0],
usd_context_name='',
time_code=0.0)
stage = omni.usd.get_context().get_stage()
cube_prim = stage.GetPrimAtPath("/World/Xform/Cube")
transform = get_local_transform_omni(cube_prim)
assert transform[0] == cube_prim.GetAttribute('xformOp:translate').Get()
assert (100,0,0) == cube_prim.GetAttribute('xformOp:rotateXYZ').Get()
assert transform[2] == cube_prim.GetAttribute('xformOp:scale').Get() | 2,549 | Python | 31.278481 | 113 | 0.68929 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/transforms/get-local-transforms/py_usd.md | ``` {literalinclude} py_usd.py
:language: py
```
| 50 | Markdown | 11.749997 | 30 | 0.62 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/transforms/get-local-transforms/usda.md | This is an example USDA result from creating (and setting) `float` and `float3` Attributes on the default Prim.
``` {literalinclude} usda.usda
:language: usd
``` | 162 | Markdown | 39.74999 | 111 | 0.740741 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/transforms/get-local-transforms/config.toml | [core]
title = "Get the Local Space Transforms for a Prim"
[metadata]
description = "Universal Scene Description (OpenUSD) code samples showing how to get the local transform for a prim."
keywords = ["OpenUSD", "USD", "Python", "omni.usd", "code sample", "local space", "local", "transforms", "get_local_transform_SRT", "GetLocalTransformation"] | 346 | TOML | 56.833324 | 157 | 0.731214 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/transforms/get-local-transforms/py_omni_usd.md | ``` {literalinclude} py_omni_usd.py
:language: py
``` | 53 | Markdown | 16.999994 | 35 | 0.660377 |
NVIDIA-Omniverse/OpenUSD-Code-Samples/source/transforms/get-world-transforms/py_usd.py | # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.transform
# SPDX-License-Identifier: Apache-2.0
import typing
from pxr import Usd, UsdGeom, Gf
def get_world_transform_xform(prim: Usd.Prim) -> typing.Tuple[Gf.Vec3d, Gf.Rotation, Gf.Vec3d]:
"""
Get the local transformation of a prim using Xformable.
See https://openusd.org/release/api/class_usd_geom_xformable.html
Args:
prim: The prim to calculate the world transformation.
Returns:
A tuple of:
- Translation vector.
- Rotation quaternion, i.e. 3d vector plus angle.
- Scale vector.
"""
xform = UsdGeom.Xformable(prim)
time = Usd.TimeCode.Default() # The time at which we compute the bounding box
world_transform: Gf.Matrix4d = xform.ComputeLocalToWorldTransform(time)
translation: Gf.Vec3d = world_transform.ExtractTranslation()
rotation: Gf.Rotation = world_transform.ExtractRotation()
scale: Gf.Vec3d = Gf.Vec3d(*(v.GetLength() for v in world_transform.ExtractRotationMatrix()))
return translation, rotation, scale
#############
# Full Usage
#############
from pxr import Sdf
# Create an in-memory Stage with /World Xform prim as the default prim
stage: Usd.Stage = Usd.Stage.CreateInMemory()
default_prim: Usd.Prim = UsdGeom.Xform.Define(stage, Sdf.Path("/World")).GetPrim()
stage.SetDefaultPrim(default_prim)
xform: Usd.Prim = UsdGeom.Xform.Define(stage, default_prim.GetPath().AppendPath("Xform"))
xform.AddTranslateOp().Set(value=(100,10,0))
xform.AddRotateXYZOp().Set(value=(0,50,0))
xform.AddScaleOp().Set(value=(5,5,5))
cube = UsdGeom.Cube.Define(stage, xform.GetPath().AppendPath("Cube"))
cube.AddTranslateOp().Set(value=(4,0,0))
cube.AddRotateXYZOp().Set(value=(100,0,0))
cube.AddScaleOp().Set(value=(2,2,2))
transform = get_world_transform_xform(cube)
usda = stage.GetRootLayer().ExportToString()
print(usda)
| 1,924 | Python | 36.01923 | 107 | 0.713617 |
Subsets and Splits