file_path
stringlengths 21
207
| content
stringlengths 5
1.02M
| size
int64 5
1.02M
| lang
stringclasses 9
values | avg_line_length
float64 2.5
98.5
| max_line_length
int64 5
993
| alphanum_fraction
float64 0.27
0.91
|
---|---|---|---|---|---|---|
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.python.hello_world/omni/example/python/hello_world/hello_world_extension.py | ## Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
import omni.ext
# Functions and variables are available to other extensions which import this module.
def hello_from(caller: str):
print(f"[omni.example.python.hello_world] hello_from was called from {caller}.")
return "Hello back from omni.example.python.hello_world!"
def hello_squared(x: int):
print(f"[omni.example.python.hello_world] hello_squared was called with {x}.")
return x**x
# When this extension is enabled, any class that derives from 'omni.ext.IExt'
# declared in the top level module (see 'python.modules' of 'extension.toml')
# will be instantiated and 'on_startup(ext_id)' called. When the extension is
# later disabled, a matching 'on_shutdown()' call will be made on the object.
class ExamplePythonHelloWorldExtension(omni.ext.IExt):
# ext_id can be used to query the extension manager for additional information about
# this extension, for example the location of this extension in the local filesystem.
def on_startup(self, ext_id):
print(f"ExamplePythonHelloWorldExtension starting up (ext_id: {ext_id}).")
def on_shutdown(self):
print(f"ExamplePythonHelloWorldExtension shutting down.")
| 1,604 | Python | 43.583332 | 89 | 0.754364 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.python.hello_world/omni/example/python/hello_world/tests/__init__.py | ## Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
from .test_hello_world import *
| 468 | Python | 45.899995 | 77 | 0.790598 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.python.hello_world/omni/example/python/hello_world/tests/test_hello_world.py | ## Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
# omni.kit.test is primarily Python's standard unittest module
# with additional wrapping to add suport for async/await tests.
# Please see: https://docs.python.org/3/library/unittest.html
import omni.kit.test
# The Python module we are testing, imported with an absolute
# path to simulate using it from a different Python extension.
import omni.example.python.hello_world
# Any class that dervives from 'omni.kit.test.AsyncTestCase'
# declared at the root of the module will be auto-discovered,
class ExamplePythonHelloWorldTest(omni.kit.test.AsyncTestCase):
# Called before running each test.
async def setUp(self):
pass
# Called after running each test.
async def tearDown(self):
pass
# Example test case (notice it is an 'async' function, so 'await' can be used if needed).
async def test_hello_from(self):
result = omni.example.python.hello_world.hello_from("test_hello_world")
self.assertEqual(result, "Hello back from omni.example.python.hello_world!")
# Example test case (notice it is an 'async' function, so 'await' can be used if needed).
async def test_hello_squared(self):
result = omni.example.python.hello_world.hello_squared(4)
self.assertEqual(result, 256)
| 1,698 | Python | 41.474999 | 93 | 0.743227 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.python.hello_world/docs/CHANGELOG.md | # Changelog
## [1.0.0] - 2022-06-30
### Added
- Initial implementation.
| 73 | Markdown | 11.333331 | 25 | 0.630137 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.python.hello_world/docs/Overview.md | # Overview
An example Python extension that can be used as a reference/template for creating new extensions.
Demonstrates how to create a Python module that will startup / shutdown along with the extension.
Also demonstrates how to expose Python functions so that they can be called from other extensions.
# Python Usage Examples
## Defining Extensions
```
# When this extension is enabled, any class that derives from 'omni.ext.IExt'
# declared in the top level module (see 'python.modules' of 'extension.toml')
# will be instantiated and 'on_startup(ext_id)' called. When the extension is
# later disabled, a matching 'on_shutdown()' call will be made on the object.
class ExamplePythonHelloWorldExtension(omni.ext.IExt):
# ext_id can be used to query the extension manager for additional information about
# this extension, for example the location of this extension in the local filesystem.
def on_startup(self, ext_id):
print(f"ExamplePythonHelloWorldExtension starting up (ext_id: {ext_id}).")
def on_shutdown(self):
print(f"ExamplePythonHelloWorldExtension shutting down.")
```
| 1,129 | Markdown | 34.312499 | 98 | 0.756422 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.usd/python/tests/__init__.py | ## Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
from .test_usd_example import *
| 468 | Python | 45.899995 | 77 | 0.790598 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.usd/python/tests/test_usd_example.py | ## Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
import omni.kit.test
import omni.kit.app
import omni.usd
import omni.example.cpp.usd
class TestUsdExample(omni.kit.test.AsyncTestCase):
async def setUp(self):
# Cache the example usd interface.
self.example_usd_interface = omni.example.cpp.usd.get_example_usd_interface()
# Open a new USD stage.
omni.usd.get_context().new_stage()
self.usd_stage = omni.usd.get_context().get_stage()
async def tearDown(self):
# Close the USD stage.
await omni.usd.get_context().close_stage_async()
self.usd_stage = None
# Clear the example usd interface.
self.example_usd_interface = None
async def test_create_prims(self):
self.example_usd_interface.create_prims()
self.assertTrue(self.usd_stage.GetPrimAtPath("/World/example_prim_0"))
self.assertTrue(self.usd_stage.GetPrimAtPath("/World/example_prim_1"))
self.assertTrue(self.usd_stage.GetPrimAtPath("/World/example_prim_2"))
self.assertTrue(self.usd_stage.GetPrimAtPath("/World/example_prim_3"))
self.assertTrue(self.usd_stage.GetPrimAtPath("/World/example_prim_4"))
self.assertTrue(self.usd_stage.GetPrimAtPath("/World/example_prim_5"))
self.assertTrue(self.usd_stage.GetPrimAtPath("/World/example_prim_6"))
self.assertTrue(self.usd_stage.GetPrimAtPath("/World/example_prim_7"))
self.assertTrue(self.usd_stage.GetPrimAtPath("/World/example_prim_8"))
self.assertFalse(self.usd_stage.GetPrimAtPath("/World/a_random_prim"))
| 1,982 | Python | 43.066666 | 85 | 0.709384 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.usd/python/impl/__init__.py | ## Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
from .example_usd_extension import *
| 473 | Python | 46.399995 | 77 | 0.792812 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.usd/python/impl/example_usd_extension.py | ## Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
import omni.ext
import omni.usd
from .._example_usd_bindings import *
# Global public interface object.
_example_usd_interface = None
# Public API.
def get_example_usd_interface() -> IExampleUsdInterface:
return _example_usd_interface
# Use the extension entry points to acquire and release the interface,
# and to subscribe to usd stage events.
class ExampleUsdExtension(omni.ext.IExt):
def on_startup(self):
# Acquire the example USD interface.
global _example_usd_interface
_example_usd_interface = acquire_example_usd_interface()
# Inform the C++ plugin if a USD stage is already open.
usd_context = omni.usd.get_context()
if usd_context.get_stage_state() == omni.usd.StageState.OPENED:
_example_usd_interface.on_default_usd_stage_changed(usd_context.get_stage_id())
# Subscribe to omni.usd stage events so we can inform the C++ plugin when a new stage opens.
self._stage_event_sub = usd_context.get_stage_event_stream().create_subscription_to_pop(
self._on_stage_event, name="omni.example.cpp.usd"
)
# Print some info about the stage from C++.
_example_usd_interface.print_stage_info()
# Create some example prims from C++.
_example_usd_interface.create_prims()
# Print some info about the stage from C++.
_example_usd_interface.print_stage_info()
# Animate the example prims from C++.
_example_usd_interface.start_timeline_animation()
def on_shutdown(self):
global _example_usd_interface
# Stop animating the example prims from C++.
_example_usd_interface.stop_timeline_animation()
# Remove the example prims from C++.
_example_usd_interface.remove_prims()
# Unsubscribe from omni.usd stage events.
self._stage_event_sub = None
# Release the example USD interface.
release_example_usd_interface(_example_usd_interface)
_example_usd_interface = None
def _on_stage_event(self, event):
if event.type == int(omni.usd.StageEventType.OPENED):
_example_usd_interface.on_default_usd_stage_changed(omni.usd.get_context().get_stage_id())
elif event.type == int(omni.usd.StageEventType.CLOSED):
_example_usd_interface.on_default_usd_stage_changed(0)
| 2,793 | Python | 37.805555 | 102 | 0.686359 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.usd/bindings/python/omni.example.cpp.usd/__init__.py | ## Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
# Necessary so we can link to the Python source instead of copying it.
__all__ = ['IExampleUsdInterface', 'acquire_example_usd_interface', 'release_example_usd_interface']
from .impl import *
| 629 | Python | 47.461535 | 100 | 0.779014 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.usd/bindings/python/omni.example.cpp.usd/ExampleUsdBindings.cpp | // Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#include <carb/BindingsPythonUtils.h>
#include <omni/example/cpp/usd/IExampleUsdInterface.h>
CARB_BINDINGS("omni.example.cpp.usd.python")
DISABLE_PYBIND11_DYNAMIC_CAST(omni::example::cpp::usd::IExampleUsdInterface)
namespace
{
// Define the pybind11 module using the same name specified in premake5.lua
PYBIND11_MODULE(_example_usd_bindings, m)
{
using namespace omni::example::cpp::usd;
m.doc() = "pybind11 omni.example.cpp.usd bindings";
carb::defineInterfaceClass<IExampleUsdInterface>(
m, "IExampleUsdInterface", "acquire_example_usd_interface", "release_example_usd_interface")
.def("create_prims", &IExampleUsdInterface::createPrims)
.def("remove_prims", &IExampleUsdInterface::removePrims)
.def("print_stage_info", &IExampleUsdInterface::printStageInfo)
.def("start_timeline_animation", &IExampleUsdInterface::startTimelineAnimation)
.def("stop_timeline_animation", &IExampleUsdInterface::stopTimelineAnimation)
.def("on_default_usd_stage_changed", &IExampleUsdInterface::onDefaultUsdStageChanged)
/**/;
}
}
| 1,530 | C++ | 38.256409 | 100 | 0.752941 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.usd/include/omni/example/cpp/usd/IExampleUsdInterface.h | // Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#pragma once
#include <carb/Interface.h>
namespace omni
{
namespace example
{
namespace cpp
{
namespace usd
{
/**
* Interface used to interact with the example C++ USD plugin from Python.
*/
class IExampleUsdInterface
{
public:
/// @private
CARB_PLUGIN_INTERFACE("omni::example::cpp::usd::IExampleUsdInterface", 1, 0);
/**
* Creates some example prims using C++.
*/
virtual void createPrims() = 0;
/**
* Remove the example prims using C++.
*/
virtual void removePrims() = 0;
/**
* Print some info about the currently open USD stage from C++.
*/
virtual void printStageInfo() const = 0;
/**
* Start animating the example prims using the timeline.
*/
virtual void startTimelineAnimation() = 0;
/**
* Stop animating the example prims using the timeline.
*/
virtual void stopTimelineAnimation() = 0;
/**
* Called when the default USD stage (ie. the one open in the main viewport) changes.
* Necessary for now until the omni.usd C++ API becomes ready for public consumption.
*
* @param stageId The id of the new default USD stage.
*/
virtual void onDefaultUsdStageChanged(long stageId) = 0;
};
}
}
}
}
| 1,675 | C | 23.289855 | 89 | 0.678209 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.usd/config/extension.toml | [package]
version = "1.0.1" # Semantic Versioning is used: https://semver.org/
# These fields are used primarily for display in the extension browser UI.
title = "Example C++ Extension: USD"
description = "Demonstrates how to create a C++ plugin that can interact with the current USD stage."
category = "Example"
keywords = ["example", "C++", "cpp", "USD"]
icon = "data/icon.png"
preview_image = "data/preview.png"
changelog = "docs/CHANGELOG.md"
readme = "docs/README.md"
authors = ["David Bosnich <[email protected]>"]
repository = "https://github.com/NVIDIA-Omniverse/kit-extension-template-cpp"
[dependencies]
"omni.usd" = {}
# Define the Python modules that this extension provides.
# C++ only extensions need this just so tests don't fail.
[[python.module]]
name = "omni.example.cpp.usd"
# Define the C++ plugins that this extension provides.
[[native.plugin]]
path = "bin/*.plugin"
# Define the documentation that will be generated for this extension.
[documentation]
pages = [
"docs/Overview.md",
"docs/CHANGELOG.md",
]
cpp_api = [
"include/omni/example/cpp/usd/IExampleUsdInterface.h",
]
| 1,119 | TOML | 29.270269 | 101 | 0.714924 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.usd/plugins/omni.example.cpp.usd/ExampleUsdExtension.cpp | // Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#define CARB_EXPORTS
#include <carb/PluginUtils.h>
#include <omni/example/cpp/usd/IExampleUsdInterface.h>
#include <omni/ext/ExtensionsUtils.h>
#include <omni/ext/IExt.h>
#include <omni/kit/IApp.h>
#include <omni/timeline/ITimeline.h>
#include <omni/timeline/TimelineTypes.h>
#include <pxr/usd/usd/notice.h>
#include <pxr/usd/usd/stage.h>
#include <pxr/usd/usd/stageCache.h>
#include <pxr/usd/usd/primRange.h>
#include <pxr/usd/usdGeom/metrics.h>
#include <pxr/usd/usdGeom/xform.h>
#include <pxr/usd/usdUtils/stageCache.h>
#include <vector>
const struct carb::PluginImplDesc pluginImplDesc = { "omni.example.cpp.usd.plugin",
"An example C++ extension.", "NVIDIA",
carb::PluginHotReload::eEnabled, "dev" };
namespace omni
{
namespace example
{
namespace cpp
{
namespace usd
{
class ExampleCppUsdExtension : public IExampleUsdInterface
, public PXR_NS::TfWeakBase
{
protected:
void createPrims() override
{
// It is important that all USD stage reads/writes happen from the main thread:
// https ://graphics.pixar.com/usd/release/api/_usd__page__multi_threading.html
if (!m_stage)
{
return;
}
constexpr int numPrimsToCreate = 9;
const float rotationIncrement = 360.0f / (numPrimsToCreate - 1);
for (int i = 0; i < numPrimsToCreate; ++i)
{
// Create a cube prim.
const PXR_NS::SdfPath primPath("/World/example_prim_" + std::to_string(i));
if (m_stage->GetPrimAtPath(primPath))
{
// A prim already exists at this path.
continue;
}
PXR_NS::UsdPrim prim = m_stage->DefinePrim(primPath, PXR_NS::TfToken("Cube"));
// Set the size of the cube prim.
const double cubeSize = 0.5 / PXR_NS::UsdGeomGetStageMetersPerUnit(m_stage);
prim.CreateAttribute(PXR_NS::TfToken("size"), PXR_NS::SdfValueTypeNames->Double).Set(cubeSize);
// Leave the first prim at the origin and position the rest in a circle surrounding it.
if (i == 0)
{
m_primsWithRotationOps.push_back({ prim });
}
else
{
PXR_NS::UsdGeomXformable xformable = PXR_NS::UsdGeomXformable(prim);
// Setup the global rotation operation.
const float initialRotation = rotationIncrement * static_cast<float>(i);
PXR_NS::UsdGeomXformOp globalRotationOp = xformable.AddRotateYOp(PXR_NS::UsdGeomXformOp::PrecisionFloat);
globalRotationOp.Set(initialRotation);
// Setup the translation operation.
const PXR_NS::GfVec3f translation(0.0f, 0.0f, cubeSize * 4.0f);
xformable.AddTranslateOp(PXR_NS::UsdGeomXformOp::PrecisionFloat).Set(translation);
// Setup the local rotation operation.
PXR_NS::UsdGeomXformOp localRotationOp = xformable.AddRotateXOp(PXR_NS::UsdGeomXformOp::PrecisionFloat);
localRotationOp.Set(initialRotation);
// Store the prim and rotation ops so we can update them later in animatePrims().
m_primsWithRotationOps.push_back({ prim, localRotationOp, globalRotationOp });
}
}
// Subscribe to timeline events so we know when to start or stop animating the prims.
if (auto timeline = omni::timeline::getTimeline())
{
m_timelineEventsSubscription = carb::events::createSubscriptionToPop(
timeline->getTimelineEventStream(),
[this](carb::events::IEvent* timelineEvent) {
onTimelineEvent(static_cast<omni::timeline::TimelineEventType>(timelineEvent->type));
});
}
}
void removePrims() override
{
if (!m_stage)
{
return;
}
// Release all event subscriptions.
PXR_NS::TfNotice::Revoke(m_usdNoticeListenerKey);
m_timelineEventsSubscription = nullptr;
m_updateEventsSubscription = nullptr;
// Remove all prims.
for (auto& primWithRotationOps : m_primsWithRotationOps)
{
m_stage->RemovePrim(primWithRotationOps.m_prim.GetPath());
}
m_primsWithRotationOps.clear();
}
void printStageInfo() const override
{
if (!m_stage)
{
return;
}
printf("---Stage Info Begin---\n");
// Print the USD stage's up-axis.
const PXR_NS::TfToken stageUpAxis = PXR_NS::UsdGeomGetStageUpAxis(m_stage);
printf("Stage up-axis is: %s.\n", stageUpAxis.GetText());
// Print the USD stage's meters per unit.
const double metersPerUnit = PXR_NS::UsdGeomGetStageMetersPerUnit(m_stage);
printf("Stage meters per unit: %f.\n", metersPerUnit);
// Print the USD stage's prims.
const PXR_NS::UsdPrimRange primRange = m_stage->Traverse();
for (const PXR_NS::UsdPrim& prim : primRange)
{
printf("Stage contains prim: %s.\n", prim.GetPath().GetString().c_str());
}
printf("---Stage Info End---\n\n");
}
void startTimelineAnimation() override
{
if (auto timeline = omni::timeline::getTimeline())
{
timeline->play();
}
}
void stopTimelineAnimation() override
{
if (auto timeline = omni::timeline::getTimeline())
{
timeline->stop();
}
}
void onDefaultUsdStageChanged(long stageId) override
{
PXR_NS::TfNotice::Revoke(m_usdNoticeListenerKey);
m_timelineEventsSubscription = nullptr;
m_updateEventsSubscription = nullptr;
m_primsWithRotationOps.clear();
m_stage.Reset();
if (stageId)
{
m_stage = PXR_NS::UsdUtilsStageCache::Get().Find(PXR_NS::UsdStageCache::Id::FromLongInt(stageId));
m_usdNoticeListenerKey = PXR_NS::TfNotice::Register(PXR_NS::TfCreateWeakPtr(this), &ExampleCppUsdExtension::onObjectsChanged);
}
}
void onObjectsChanged(const PXR_NS::UsdNotice::ObjectsChanged& objectsChanged)
{
// Check whether any of the prims we created have been (potentially) invalidated.
// This may be too broad a check, but handles prims being removed from the stage.
for (auto& primWithRotationOps : m_primsWithRotationOps)
{
if (!primWithRotationOps.m_invalid &&
objectsChanged.ResyncedObject(primWithRotationOps.m_prim))
{
primWithRotationOps.m_invalid = true;
}
}
}
void onTimelineEvent(omni::timeline::TimelineEventType timelineEventType)
{
switch (timelineEventType)
{
case omni::timeline::TimelineEventType::ePlay:
{
startAnimatingPrims();
}
break;
case omni::timeline::TimelineEventType::eStop:
{
stopAnimatingPrims();
}
break;
default:
{
}
break;
}
}
void startAnimatingPrims()
{
if (m_updateEventsSubscription)
{
// We're already animating the prims.
return;
}
// Subscribe to update events so we can animate the prims.
if (omni::kit::IApp* app = carb::getCachedInterface<omni::kit::IApp>())
{
m_updateEventsSubscription = carb::events::createSubscriptionToPop(app->getUpdateEventStream(), [this](carb::events::IEvent*)
{
onUpdateEvent();
});
}
}
void stopAnimatingPrims()
{
m_updateEventsSubscription = nullptr;
onUpdateEvent(); // Reset positions.
}
void onUpdateEvent()
{
// It is important that all USD stage reads/writes happen from the main thread:
// https ://graphics.pixar.com/usd/release/api/_usd__page__multi_threading.html
if (!m_stage)
{
return;
}
// Update the value of each local and global rotation operation to (crudely) animate the prims around the origin.
const size_t numPrims = m_primsWithRotationOps.size();
const float initialLocalRotationIncrement = 360.0f / (numPrims - 1); // Ignore the first prim at the origin.
const float initialGlobalRotationIncrement = 360.0f / (numPrims - 1); // Ignore the first prim at the origin.
const float currentAnimTime = omni::timeline::getTimeline()->getCurrentTime() * m_stage->GetTimeCodesPerSecond();
for (size_t i = 1; i < numPrims; ++i) // Ignore the first prim at the origin.
{
if (m_primsWithRotationOps[i].m_invalid)
{
continue;
}
PXR_NS::UsdGeomXformOp& localRotationOp = m_primsWithRotationOps[i].m_localRotationOp;
const float initialLocalRotation = initialLocalRotationIncrement * static_cast<float>(i);
const float currentLocalRotation = initialLocalRotation + (360.0f * (currentAnimTime / 100.0f));
localRotationOp.Set(currentLocalRotation);
PXR_NS::UsdGeomXformOp& globalRotationOp = m_primsWithRotationOps[i].m_globalRotationOp;
const float initialGlobalRotation = initialGlobalRotationIncrement * static_cast<float>(i);
const float currentGlobalRotation = initialGlobalRotation - (360.0f * (currentAnimTime / 100.0f));
globalRotationOp.Set(currentGlobalRotation);
}
}
private:
struct PrimWithRotationOps
{
PXR_NS::UsdPrim m_prim;
PXR_NS::UsdGeomXformOp m_localRotationOp;
PXR_NS::UsdGeomXformOp m_globalRotationOp;
bool m_invalid = false;
};
PXR_NS::UsdStageRefPtr m_stage;
PXR_NS::TfNotice::Key m_usdNoticeListenerKey;
std::vector<PrimWithRotationOps> m_primsWithRotationOps;
carb::events::ISubscriptionPtr m_updateEventsSubscription;
carb::events::ISubscriptionPtr m_timelineEventsSubscription;
};
}
}
}
}
CARB_PLUGIN_IMPL(pluginImplDesc, omni::example::cpp::usd::ExampleCppUsdExtension)
void fillInterface(omni::example::cpp::usd::ExampleCppUsdExtension& iface)
{
}
| 10,791 | C++ | 33.925566 | 138 | 0.61505 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.usd/docs/CHANGELOG.md | # Changelog
## [1.0.1] - 2023-04-27
### Updated
- Build against Kit 105.0
## [1.0.0] - 2022-07-07
### Added
- Initial implementation.
| 136 | Markdown | 12.699999 | 25 | 0.610294 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.usd/docs/Overview.md | # Overview
An example C++ extension that can be used as a reference/template for creating new extensions.
Demonstrates how to create a C++ plugin that can interact with the current USD stage by:
- Subscribing to USD stage events from Python.
- Sending the current USD stage id to C++.
- Storing a reference to the USD stage in C++.
- Adding some prims to the USD stage from C++.
- Animating the USD prims each update from C++.
- Printing information about the USD stage from C++.
Note: It is important that all USD stage reads/writes happen from the main thread:
[https://graphics.pixar.com/usd/release/api/_usd__page__multi_threading.html](https://graphics.pixar.com/usd/release/api/_usd__page__multi_threading.html)
# Example

| 775 | Markdown | 32.739129 | 154 | 0.750968 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.hello_world/config/extension.toml | [package]
version = "1.0.0" # Semantic Versioning is used: https://semver.org/
# These fields are used primarily for display in the extension browser UI.
title = "Example C++ Extension: Hello World"
description = "Demonstrates how to create a C++ object that will startup / shutdown along with the extension."
category = "Example"
keywords = ["example", "C++", "cpp"]
icon = "data/icon.png"
preview_image = "data/preview.png"
changelog = "docs/CHANGELOG.md"
readme = "docs/README.md"
authors = ["Anton Novoselov <[email protected]>", "David Bosnich <[email protected]>"]
repository = "https://github.com/NVIDIA-Omniverse/kit-extension-template-cpp"
# Define the Python modules that this extension provides.
# C++ only extensions need this just so tests don't fail.
[[python.module]]
name = "omni.example.cpp.hello_world"
# Define the C++ plugins that this extension provides.
[[native.plugin]]
path = "bin/*.plugin"
# Define the documentation that will be generated for this extension.
[documentation]
pages = [
"docs/Overview.md",
"docs/CHANGELOG.md",
]
| 1,074 | TOML | 33.677418 | 110 | 0.727188 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.hello_world/plugins/omni.example.cpp.hello_world/HelloWorldExtension.cpp | // Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#define CARB_EXPORTS
#include <carb/PluginUtils.h>
#include <omni/ext/IExt.h>
#include <omni/kit/IApp.h>
const struct carb::PluginImplDesc pluginImplDesc = { "omni.example.cpp.hello_world.plugin",
"An example C++ extension.", "NVIDIA",
carb::PluginHotReload::eEnabled, "dev" };
CARB_PLUGIN_IMPL_DEPS(omni::kit::IApp)
namespace omni
{
namespace example
{
namespace cpp
{
namespace hello_world
{
// When this extension is enabled, any class that derives from omni.ext.IExt
// will be instantiated and 'onStartup(extId)' called. When the extension is
// later disabled, a matching 'onShutdown()' call will be made on the object.
class ExampleCppHelloWorldExtension : public omni::ext::IExt
{
public:
void onStartup(const char* extId) override
{
printf("ExampleCppHelloWorldExtension starting up (ext_id: %s).\n", extId);
// Get the app interface from the Carbonite Framework.
if (omni::kit::IApp* app = carb::getFramework()->acquireInterface<omni::kit::IApp>())
{
// Subscribe to update events.
m_updateEventsSubscription =
carb::events::createSubscriptionToPop(app->getUpdateEventStream(), [this](carb::events::IEvent*) {
onUpdate();
});
}
}
void onShutdown() override
{
printf("ExampleCppHelloWorldExtension shutting down.\n");
// Unsubscribe from update events.
m_updateEventsSubscription = nullptr;
}
void onUpdate()
{
if (m_updateCounter % 1000 == 0)
{
printf("Hello from the omni.example.cpp.hello_world extension! %d updates counted.\n", m_updateCounter);
}
m_updateCounter++;
}
private:
carb::events::ISubscriptionPtr m_updateEventsSubscription;
int m_updateCounter = 0;
};
}
}
}
}
CARB_PLUGIN_IMPL(pluginImplDesc, omni::example::cpp::hello_world::ExampleCppHelloWorldExtension)
void fillInterface(omni::example::cpp::hello_world::ExampleCppHelloWorldExtension& iface)
{
}
| 2,554 | C++ | 29.058823 | 116 | 0.661316 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.hello_world/omni/example/cpp/hello_world/__init__.py | ## Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
# This file is needed so tests don't fail.
| 480 | Python | 42.727269 | 77 | 0.785417 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.hello_world/docs/CHANGELOG.md | # Changelog
## [1.0.0] - 2022-06-30
### Added
- Initial implementation.
| 73 | Markdown | 11.333331 | 25 | 0.630137 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.hello_world/docs/Overview.md | # Overview
An example C++ extension that can be used as a reference/template for creating new extensions.
Demonstrates how to create a C++ object that will startup / shutdown along with the extension.
# C++ Usage Examples
## Defining Extensions
```
// When this extension is enabled, any class that derives from omni.ext.IExt
// will be instantiated and 'onStartup(extId)' called. When the extension is
// later disabled, a matching 'onShutdown()' call will be made on the object.
class ExampleCppHelloWorldExtension : public omni::ext::IExt
{
public:
void onStartup(const char* extId) override
{
printf("ExampleCppHelloWorldExtension starting up (ext_id: %s).\n", extId);
if (omni::kit::IApp* app = carb::getFramework()->acquireInterface<omni::kit::IApp>())
{
// Subscribe to update events.
m_updateEventsSubscription =
carb::events::createSubscriptionToPop(app->getUpdateEventStream(), [this](carb::events::IEvent*) {
onUpdate();
});
}
}
void onShutdown() override
{
printf("ExampleCppHelloWorldExtension shutting down.\n");
// Unsubscribe from update events.
m_updateEventsSubscription = nullptr;
}
void onUpdate()
{
if (m_updateCounter % 1000 == 0)
{
printf("Hello from the omni.example.cpp.hello_world extension! %d updates counted.\n", m_updateCounter);
}
m_updateCounter++;
}
private:
carb::events::ISubscriptionPtr m_updateEventsSubscription;
int m_updateCounter = 0;
};
```
| 1,609 | Markdown | 26.75862 | 116 | 0.646364 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.python.usdrt/config/extension.toml | [package]
# Semantic Versioning is used: https://semver.org/
version = "1.0.1"
# Lists people or organizations that are considered the "authors" of the package.
authors = ["Alan Blevins <[email protected]>"]
# The title and description fields are primarily for displaying extension info in UI
title = "Example Python Extension: USDRT"
description="Example Kit extension using the USDRT Scenegraph API."
# Path (relative to the root) or content of readme markdown file for UI.
readme = "docs/README.md"
# URL of the extension source repository.
repository = "https://github.com/NVIDIA-Omniverse/kit-extension-template-cpp"
# One of categories for UI.
category = "Example"
# Keywords for the extension
keywords = ["kit", "example", "usdrt", "scenegraph", "fabric"]
# Location of change log file in target (final) folder of extension, relative to the root.
# More info on writing changelog: https://keepachangelog.com/en/1.0.0/
changelog="docs/CHANGELOG.md"
# Preview image and icon. Folder named "data" automatically goes in git lfs (see .gitattributes file).
# Preview image is shown in "Overview" of Extensions window. Screenshot of an extension might be a good preview image.
preview_image = "data/preview.png"
# Icon is shown in Extensions window, it is recommended to be square, of size 256x256.
icon = "data/icon.png"
# Extension dependencies
[dependencies]
"omni.kit.uiapp" = {}
"usdrt.scenegraph" = {}
"omni.usd" = {}
"omni.kit.primitive.mesh" = {}
"omni.warp" = { optional = true }
# Main python module this extension provides
[[python.module]]
name = "omni.example.python.usdrt"
[[test]]
waiver = "Just example code, not for production"
#TODO
# Define the documentation that will be generated for this extension.
[documentation]
pages = [
"docs/Overview.md",
"docs/CHANGELOG.md",
] | 1,813 | TOML | 31.392857 | 118 | 0.737452 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.python.usdrt/omni/example/python/usdrt/example_python_usdrt_extension.py | ## Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
import math
import random
from ctypes import alignment
import omni.ext
import omni.ui as ui
import omni.usd
from usdrt import Gf, Rt, Sdf, Usd, Vt
try:
wp = None
import warp as wp
wp.init()
@wp.kernel
def deform(positions: wp.array(dtype=wp.vec3), t: float):
tid = wp.tid()
x = positions[tid]
offset = -wp.sin(x[0])
scale = wp.sin(t) * 10.0
x = x + wp.vec3(0.0, offset * scale, 0.0)
positions[tid] = x
except ImportError:
pass
def get_selected_prim_path():
"""Return the path of the first selected prim"""
context = omni.usd.get_context()
selection = context.get_selection()
paths = selection.get_selected_prim_paths()
return None if not paths else paths[0]
def get_stage_id():
"""Return the stage Id of the current stage"""
context = omni.usd.get_context()
return context.get_stage_id()
def is_vtarray(obj):
"""Check if this is a VtArray type
In Python, each data type gets its own
VtArray class i.e. Vt.Float3Array etc.
so this helper identifies any of them.
"""
return hasattr(obj, "IsFabricData")
def condensed_vtarray_str(data):
"""Return a string representing VtArray data
Include at most 6 values, and the total items
in the array
"""
size = len(data)
if size > 6:
datastr = "[{}, {}, {}, .. {}, {}, {}] (size: {})".format(
data[0], data[1], data[2], data[-3], data[-2], data[-1], size
)
else:
datastr = "["
for i in range(size - 1):
datastr += str(data[i]) + ", "
datastr += str(data[-1]) + "]"
return datastr
def get_fabric_data_for_prim(stage_id, path):
"""Get the Fabric data for a path as a string"""
if path is None:
return "Nothing selected"
stage = Usd.Stage.Attach(stage_id)
# If a prim does not already exist in Fabric,
# it will be fetched from USD by simply creating the
# Usd.Prim object. At this time, only the attributes that have
# authored opinions will be fetch into Fabric.
prim = stage.GetPrimAtPath(Sdf.Path(path))
if not prim:
return f"Prim at path {path} is not in Fabric"
# This diverges a bit from USD - only attributes
# that exist in Fabric are returned by this API
attrs = prim.GetAttributes()
result = f"Fabric data for prim at path {path}\n\n\n"
for attr in attrs:
try:
data = attr.Get()
datastr = str(data)
if data is None:
datastr = "<no value>"
elif is_vtarray(data):
datastr = condensed_vtarray_str(data)
except TypeError:
# Some data types not yet supported in Python
datastr = "<no Python conversion>"
result += "{} ({}): {}\n".format(attr.GetName(), str(attr.GetTypeName().GetAsToken()), datastr)
return result
def apply_random_rotation(stage_id, path):
"""Apply a random world space rotation to a prim in Fabric"""
if path is None:
return "Nothing selected"
stage = Usd.Stage.Attach(stage_id)
prim = stage.GetPrimAtPath(Sdf.Path(path))
if not prim:
return f"Prim at path {path} is not in Fabric"
rtxformable = Rt.Xformable(prim)
if not rtxformable.HasWorldXform():
rtxformable.SetWorldXformFromUsd()
angle = random.random() * math.pi * 2
axis = Gf.Vec3f(random.random(), random.random(), random.random()).GetNormalized()
halfangle = angle / 2.0
shalfangle = math.sin(halfangle)
rotation = Gf.Quatf(math.cos(halfangle), axis[0] * shalfangle, axis[1] * shalfangle, axis[2] * shalfangle)
rtxformable.GetWorldOrientationAttr().Set(rotation)
return f"Set new world orientation on {path} to {rotation}"
def deform_mesh_with_warp(stage_id, path, time):
"""Use Warp to deform a Mesh prim"""
if path is None:
return "Nothing selected"
stage = Usd.Stage.Attach(stage_id)
prim = stage.GetPrimAtPath(Sdf.Path(path))
if not prim:
return f"Prim at path {path} is not in Fabric"
if not prim.HasAttribute("points"):
return f"Prim at path {path} does not have points attribute"
if not wp:
return "Warp failed to initialize. Install/Load the warp extension."
# Tell OmniHydra to render points from Fabric
if not prim.HasAttribute("Deformable"):
prim.CreateAttribute("Deformable", Sdf.ValueTypeNames.PrimTypeTag, True)
points = prim.GetAttribute("points")
pointsarray = points.Get()
warparray = wp.array(pointsarray, dtype=wp.vec3, device="cuda")
wp.launch(kernel=deform, dim=len(pointsarray), inputs=[warparray, time], device="cuda")
points.Set(Vt.Vec3fArray(warparray.numpy()))
return f"Deformed points on prim {path}"
# Any class derived from `omni.ext.IExt` in top level module (defined in `python.modules` of `extension.toml`) will be
# instantiated when extension gets enabled and `on_startup(ext_id)` will be called. Later when extension gets disabled
# on_shutdown() is called.
class UsdrtExamplePythonExtension(omni.ext.IExt):
# ext_id is current extension id. It can be used with extension manager to query additional information, like where
# this extension is located on filesystem.
def on_startup(self, ext_id):
print("[omni.example.python.usdrt] startup")
self._window = ui.Window(
"What's in Fabric?", width=300, height=300, dockPreference=ui.DockPreference.RIGHT_BOTTOM
)
self._t = 0
with self._window.frame:
with ui.VStack():
frame = ui.ScrollingFrame()
with frame:
label = ui.Label("Select a prim and push a button", alignment=ui.Alignment.LEFT_TOP)
def get_fabric_data():
label.text = get_fabric_data_for_prim(get_stage_id(), get_selected_prim_path())
def rotate_prim():
label.text = apply_random_rotation(get_stage_id(), get_selected_prim_path())
def deform_prim():
label.text = deform_mesh_with_warp(get_stage_id(), get_selected_prim_path(), self._t)
self._t += 1
ui.Button("What's in Fabric?", clicked_fn=get_fabric_data, height=0)
ui.Button("Rotate it in Fabric!", clicked_fn=rotate_prim, height=0)
ui.Button("Deform it with Warp!", clicked_fn=deform_prim, height=0)
def on_shutdown(self):
print("[omni.example.python.usdrt] shutdown")
| 6,999 | Python | 31.71028 | 119 | 0.632519 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.python.usdrt/omni/example/python/usdrt/__init__.py | from .example_python_usdrt_extension import *
| 46 | Python | 22.499989 | 45 | 0.804348 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.python.usdrt/omni/example/python/usdrt/tests/__init__.py | ## Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
from .test_whats_in_fabric import *
| 472 | Python | 46.299995 | 77 | 0.790254 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.python.usdrt/omni/example/python/usdrt/tests/test_whats_in_fabric.py | ## Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
import omni.example.python.usdrt
# omni.kit.test is primarily Python's standard unittest module
# with additional wrapping to add suport for async/await tests.
# Please see: https://docs.python.org/3/library/unittest.html
import omni.kit.test
# The Python module we are testing, imported with an absolute
# path to simulate using it from a different Python extension.
import omni.usd
import usdrt
# Any class that dervives from 'omni.kit.test.AsyncTestCase'
# declared at the root of the module will be auto-discovered,
class ExamplePythonUsdrtTest(omni.kit.test.AsyncTestCase):
async def setUp(self):
# Open a new USD stage.
omni.usd.get_context().new_stage()
self.usd_stage = omni.usd.get_context().get_stage()
self.stage_id = omni.usd.get_context().get_stage_id()
# create a torus
(success, pathString) = omni.kit.commands.execute("CreateMeshPrimWithDefaultXformCommand", prim_type="Torus")
self.assertTrue(success)
self.prim_path = pathString
async def tearDown(self):
# Close the USD stage.
await omni.usd.get_context().close_stage_async()
self.usd_stage = None
async def test_get_fabric_data_for_prim(self):
result = omni.example.python.usdrt.get_fabric_data_for_prim(self.stage_id, self.prim_path)
self.assertTrue("Fabric data for prim at path %s\n\n\n" % self.prim_path in result)
for attr in ["points", "normals", "primvars:st", "extent"]:
self.assertTrue(attr in result)
# test invalid prim
result = omni.example.python.usdrt.get_fabric_data_for_prim(self.stage_id, "/invalidPrim")
self.assertTrue(result == "Prim at path /invalidPrim is not in Fabric")
# test empty path
result = omni.example.python.usdrt.get_fabric_data_for_prim(self.stage_id, None)
self.assertTrue(result == "Nothing selected")
async def test_apply_random_rotation(self):
result = omni.example.python.usdrt.apply_random_rotation(self.stage_id, self.prim_path)
self.assertTrue("Set new world orientation on %s to (" % self.prim_path in result)
# test invalid prim
result = omni.example.python.usdrt.apply_random_rotation(self.stage_id, "/invalidPrim")
self.assertTrue(result == "Prim at path /invalidPrim is not in Fabric")
# test empty path
result = omni.example.python.usdrt.apply_random_rotation(self.stage_id, None)
self.assertTrue(result == "Nothing selected")
async def test_deform_mesh_with_warp(self):
try:
import warp
t = 0
result = omni.example.python.usdrt.deform_mesh_with_warp(self.stage_id, self.prim_path, t)
self.assertTrue(result == f"Deformed points on prim {self.prim_path}")
# test invalid prim
result = omni.example.python.usdrt.deform_mesh_with_warp(self.stage_id, "/invalidPrim", t)
self.assertTrue(result == "Prim at path /invalidPrim is not in Fabric")
# test empty path
result = omni.example.python.usdrt.deform_mesh_with_warp(self.stage_id, None, t)
self.assertTrue(result == "Nothing selected")
except ImportError:
pass
| 3,687 | Python | 41.390804 | 117 | 0.681584 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.python.usdrt/docs/CHANGELOG.md | # Changelog
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [1.0.1] - 2022-10-07
- More cleanup for publish retry
## [1.0.0] - 2022-10-06
- Cleanup and publish for documentation example
## [0.1.0] - 2022-05-31
- Initial version
| 271 | Markdown | 15.999999 | 80 | 0.667897 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.python.usdrt/docs/Overview.md | # What's in Fabric? USDRT Scenegraph API example [omni.example.python.usdrt]
This is an example Kit extension using the USDRT Scenegraph API. This Python
extension demonstrates the following:
- Inspecting Fabric data using the USDRT Scenegraph API
- Manipulating prim transforms in Fabric using the RtXformable schema
- Deforming Mesh geometry on the GPU with USDRT and Warp
| 377 | Markdown | 40.999995 | 76 | 0.811671 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.omnigraph_node/config/extension.toml | [package]
version = "1.0.1" # Semantic Versioning is used: https://semver.org/
# These fields are used primarily for display in the extension browser UI.
title = "Example C++ Extension: OmniGraph Node"
description = "Demonstrates how to create a C++ node for OmniGraph"
category = "Example"
keywords = ["example", "C++", "cpp", "Graph", "Node", "OmniGraph"]
icon = "data/icon.png"
preview_image = "data/preview.png"
changelog = "docs/CHANGELOG.md"
readme = "docs/README.md"
authors = ["Kevin Picott <[email protected]>", "David Bosnich <[email protected]>"]
repository = "https://github.com/NVIDIA-Omniverse/kit-extension-template-cpp"
[dependencies]
"omni.graph.core" = {}
"omni.graph.tools" = {}
[[python.module]]
name = "omni.example.cpp.omnigraph_node"
[[native.plugin]]
path = "bin/*.plugin"
[documentation]
pages = [
"docs/Overview.md",
"docs/CHANGELOG.md",
]
| 883 | TOML | 27.516128 | 86 | 0.697622 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.omnigraph_node/plugins/omni.example.cpp.omnigraph_node/ExampleOmniGraphNodeExtension.cpp | // Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#define CARB_EXPORTS
#include <carb/PluginUtils.h>
#include <omni/ext/IExt.h>
#include <omni/graph/core/IGraphRegistry.h>
#include <omni/graph/core/ogn/Database.h>
#include <omni/graph/core/ogn/Registration.h>
// Standard plugin definitions required by Carbonite.
const struct carb::PluginImplDesc pluginImplDesc = { "omni.example.cpp.omnigraph_node.plugin",
"An example C++ extension.", "NVIDIA",
carb::PluginHotReload::eEnabled, "dev" };
// These interface dependencies are required by all OmniGraph node types
CARB_PLUGIN_IMPL_DEPS(omni::graph::core::IGraphRegistry,
omni::fabric::IPath,
omni::fabric::IToken)
// This macro sets up the information required to register your node type definitions with OmniGraph
DECLARE_OGN_NODES()
namespace omni
{
namespace example
{
namespace cpp
{
namespace omnigraph_node
{
class ExampleOmniGraphNodeExtension : public omni::ext::IExt
{
public:
void onStartup(const char* extId) override
{
printf("ExampleOmniGraphNodeExtension starting up (ext_id: %s).\n", extId);
// This macro walks the list of pending node type definitions and registers them with OmniGraph
INITIALIZE_OGN_NODES()
}
void onShutdown() override
{
printf("ExampleOmniGraphNodeExtension shutting down.\n");
// This macro walks the list of registered node type definitions and deregisters all of them. This is required
// for hot reload to work.
RELEASE_OGN_NODES()
}
private:
};
}
}
}
}
CARB_PLUGIN_IMPL(pluginImplDesc, omni::example::cpp::omnigraph_node::ExampleOmniGraphNodeExtension)
void fillInterface(omni::example::cpp::omnigraph_node::ExampleOmniGraphNodeExtension& iface)
{
}
| 2,269 | C++ | 30.527777 | 118 | 0.698986 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.omnigraph_node/plugins/nodes/OgnExampleNode.cpp | // Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#include <OgnExampleNodeDatabase.h>
// Helpers to explicit shorten names you know you will use
using omni::graph::core::Type;
using omni::graph::core::BaseDataType;
namespace omni {
namespace example {
namespace cpp {
namespace omnigraph_node {
class OgnExampleNode
{
public:
static bool compute(OgnExampleNodeDatabase& db)
{
// The database has a few useful utilities that simplify common operations such as converting strings to tokens
static auto pointsToken = db.stringToToken("points");
// This is how to extract a single-valued attribute. The return values for db.inputs.XXX() are
// const-ref accessors that provide an interface to the actual data. For simple values it can be
// considered to be the POD type so this line would be equivalent to:
// const bool& disableOffset = db.inputs.disable();
const auto& disableOffset = db.inputs.disable();
// This is how to extract an output array attribute. It returns an accessor that behaves basically the same as
// the std::array type, except that the data is managed by Fabric. It further adds the ability to set the array
// size explicitly, required to ensure that Fabric has enough space allocated for the attribute data.
// Since this is an output the reference is no longer a const, enabling modification of the data to which it
// provides access.
auto& points = db.outputs.points();
// Attributes with well-defined types, like float/float[3], cast by default to the USD data types, however you
// can use any binary compatible types you have. See the .ogn documentation on type configurations to see how
// to change types. For bundle members and extended types whose type is determined at runtime the types are all
// POD types (though they can also be cast to other types at runtime if they are easier to use)
pxr::GfVec3f pointOffset{ 0.0f, 0.0f, 0.0f };
// This is how to extract a variable-typed input attribute. By default if the type has not been resolved to
// one of the legal types, in this case float[3] or float, the compute() will not be called. You can
// add "unvalidated":true to the attribute definition and handle the case of unresolved types here.
// The return value is an accessor that provides type information and the cast operators to get the
// resolved data types.
const auto& offsetValue = db.inputs.offset();
if (auto floatOffset = offsetValue.get<float>())
{
// The data received back from the "get<>()" method is an accessor that provides a boolean operator,
// which did the type compatibility test that got us into this section of the "if", and an indirection
// operator that returns a reference to data of the type that was matched (float in this case).
pointOffset = pxr::GfVec3f{*floatOffset, *floatOffset, *floatOffset};
std::cout << "Got a float value of " << *floatOffset << std::endl;
}
// Repeat the same process of checking and applying for the other accepted value type of float[3]
else if (auto float3Offset = offsetValue.get<float[3]>())
{
pointOffset = pxr::GfVec3f{*float3Offset};
std::cout << "Got a float[3] value of " << pointOffset[0] << ", " << pointOffset[1] << ", " << pointOffset[2] << std::endl;
}
else
{
// If the resolved type was not one of the recognized one then something went wrong and the node is
// incapable of computing so log an error and return false.
db.logError("Unrecognized offset type %s", offsetValue.typeName().c_str());
return false;
}
// -------------------------------------------------------------------------------------------------------------
// With only a few accepted data types you can use the cascading "if" cast method above. If you have a lot of
// types being accepted then you should use a switch statement on the attribute type like this, as it has much
// better performance.
// const auto& type = offsetValue.type();
// switch (type.baseDataType)
// {
// case BaseDataType::eFloat:
// if ((type.componentCount == 1) and (type.arrayDepth == 0))
// {
// return handleFloatValue();
// }
// if ((type.componentCount == 3) and (type.arrayDepth == 0))
// {
// return handleFloat3Value();
// }
// }
// db.logError("Unrecognized offset type %s", offsetValue.typeName().c_str());
// return false;
// -------------------------------------------------------------------------------------------------------------
// This is how to extract an input bundle attribute. It returns an accessor that lets you inspect the bundle
// contents and the values of the attributes in the bundle.
const auto& bundleWithGeometry = db.inputs.geometry();
// The accessor supports a range-based for-loop for iterating over members. Since the output has to have a
// fixed size there is a first pass here just to count the matching members.
size_t numPointsToOffset{ 0 };
for (auto const& bundleMember : bundleWithGeometry)
{
auto inputPoint = bundleMember.get<float[3]>();
// The member accessor supports a boolean operator indicating if it is valid, meaning the type is
// compatible with the templated type with which it was extracted (float[3]).
if (inputPoint)
{
numPointsToOffset++;
}
}
// Now that all values are accessible the actual computation can happen.
//
// Output arrays must always be first resized to be the total number of entries they will eventually
// contain. Repeated resizing can be expensive so it's best to do it once up front.
points.resize(numPointsToOffset);
// The array accessor provides the common definitions that allow range-based for loops
size_t pointIndex{ 0 };
for (auto const& bundleMember : bundleWithGeometry)
{
auto inputPoint = bundleMember.get<float[3]>();
if (! inputPoint)
{
continue;
}
auto& point = points[pointIndex++];
point = pxr::GfVec3f(inputPoint);
if (! disableOffset)
{
point += pointOffset;
}
pointIndex++;
}
// Returning true tells Omnigraph that the compute was successful and the output value is now valid.
return true;
}
};
// This macro provides the information necessary to OmniGraph that lets it automatically register and deregister
// your node type definition.
REGISTER_OGN_NODE()
} // omnigraph_node
} // cpp
} // example
} // omni
| 7,538 | C++ | 49.26 | 135 | 0.620854 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.omnigraph_node/omni/example/cpp/omnigraph_node/__init__.py | ## Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
# This file is needed so tests don't fail.
| 480 | Python | 42.727269 | 77 | 0.785417 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.omnigraph_node/docs/CHANGELOG.md | (changelog_omni_example_cpp_omnigraph_node)=
# Changelog
## [1.0.1] - 2023-04-27
### Updated
- Build against Kit 105.0
## [1.0.0] - 2022-08-15
### Added
- Initial implementation.
| 182 | Markdown | 14.249999 | 44 | 0.653846 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.omnigraph_node/docs/Overview.md | ```{csv-table}
**Extension**: {{ extension_version }},**Documentation Generated**: {sub-ref}`today`,{ref}`changelog_omni_example_cpp_omnigraph_node`
```
(ext_omni_example_cpp_omnigraph_node)=
# Overview
An example C++ extension that can be used as a reference/template for creating new extensions.
Demonstrates how to create a C++ node for omni.graph
| 356 | Markdown | 26.461536 | 133 | 0.730337 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.pybind/python/tests/__init__.py | ## Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
from .test_pybind_example import *
| 471 | Python | 46.199995 | 77 | 0.791932 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.pybind/python/tests/test_pybind_example.py | ## Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
import omni.kit.test
import omni.example.cpp.pybind
class TestPybindExample(omni.kit.test.AsyncTestCase):
async def setUp(self):
# Cache the pybind interface.
self.bound_interface = omni.example.cpp.pybind.get_bound_interface()
# Create and register a bound object.
self.bound_object = omni.example.cpp.pybind.BoundObject("test_bound_object")
self.bound_object.property_int = 9
self.bound_object.property_bool = True
self.bound_object.property_string = "Ninety-Nine"
self.bound_interface.register_bound_object(self.bound_object)
async def tearDown(self):
# Deregister and clear the bound object.
self.bound_interface.deregister_bound_object(self.bound_object)
self.bound_object = None
# Clear the pybind interface.
self.bound_interface = None
async def test_find_bound_object(self):
found_object = self.bound_interface.find_bound_object("test_bound_object")
self.assertIsNotNone(found_object)
async def test_find_unregistered_bound_object(self):
found_object = self.bound_interface.find_bound_object("unregistered_object")
self.assertIsNone(found_object)
async def test_access_bound_object_properties(self):
self.assertEqual(self.bound_object.id, "test_bound_object")
self.assertEqual(self.bound_object.property_int, 9)
self.assertEqual(self.bound_object.property_bool, True)
self.assertEqual(self.bound_object.property_string, "Ninety-Nine")
async def test_call_bound_object_functions(self):
# Test calling a bound function that accepts an argument.
self.bound_object.multiply_int_property(9)
self.assertEqual(self.bound_object.property_int, 81)
# Test calling a bound function that returns a value.
result = self.bound_object.toggle_bool_property()
self.assertEqual(result, False)
self.assertEqual(self.bound_object.property_bool, False)
# Test calling a bound function that accepts an argument and returns a value.
result = self.bound_object.append_string_property(" Red Balloons")
self.assertEqual(result, "Ninety-Nine Red Balloons")
self.assertEqual(self.bound_object.property_string, "Ninety-Nine Red Balloons")
| 2,746 | Python | 43.306451 | 87 | 0.714494 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.pybind/python/impl/example_pybind_extension.py | ## Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
import omni.ext
from .._example_pybind_bindings import *
# Global public interface object.
_bound_interface = None
# Public API.
def get_bound_interface() -> IExampleBoundInterface:
return _bound_interface
# Use the extension entry points to acquire and release the interface.
class ExamplePybindExtension(omni.ext.IExt):
def __init__(self):
super().__init__()
global _bound_interface
_bound_interface = acquire_bound_interface()
def on_shutdown(self):
global _bound_interface
release_bound_interface(_bound_interface)
_bound_interface = None
| 1,045 | Python | 31.687499 | 77 | 0.733014 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.pybind/python/impl/__init__.py | ## Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
from .example_pybind_extension import *
| 476 | Python | 46.699995 | 77 | 0.794118 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.pybind/bindings/python/omni.example.cpp.pybind/__init__.py | ## Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
# Necessary so we can link to the Python source instead of copying it.
__all__ = ['BoundObject', 'IExampleBoundInterface', 'IExampleBoundObject', 'acquire_bound_interface', 'release_bound_interface']
from .impl import *
| 657 | Python | 49.615381 | 128 | 0.7793 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.pybind/bindings/python/omni.example.cpp.pybind/ExamplePybindBindings.cpp | // Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#include <carb/BindingsPythonUtils.h>
#include <omni/example/cpp/pybind/ExampleBoundObject.h>
#include <omni/example/cpp/pybind/IExampleBoundInterface.h>
#include <string>
CARB_BINDINGS("omni.example.cpp.pybind.python")
DISABLE_PYBIND11_DYNAMIC_CAST(omni::example::cpp::pybind::IExampleBoundInterface)
DISABLE_PYBIND11_DYNAMIC_CAST(omni::example::cpp::pybind::IExampleBoundObject)
namespace
{
/**
* Concrete bound object class that will be reflected to Python.
*/
class PythonBoundObject : public omni::example::cpp::pybind::ExampleBoundObject
{
public:
/**
* Factory.
*
* @param id Id of the bound action.
*
* @return The bound object that was created.
*/
static carb::ObjectPtr<PythonBoundObject> create(const char* id)
{
// Note: It is important to construct the handler using ObjectPtr<T>::InitPolicy::eSteal,
// otherwise we end up incresing the reference count by one too many during construction,
// resulting in carb::ObjectPtr<T> instance whose wrapped object will never be destroyed.
return carb::stealObject<PythonBoundObject>(new PythonBoundObject(id));
}
/**
* Constructor.
*
* @param id Id of the bound object.
*/
PythonBoundObject(const char* id)
: ExampleBoundObject(id)
, m_memberInt(0)
, m_memberBool(false)
, m_memberString()
{
}
// To deomnstrate binding a fuction that accepts an argument.
void multiplyIntProperty(int value)
{
m_memberInt *= value;
}
// To deomnstrate binding a fuction that returns a value.
bool toggleBoolProperty()
{
m_memberBool = !m_memberBool;
return m_memberBool;
}
// To deomnstrate binding a fuction that accepts an argument and returns a value.
const char* appendStringProperty(const char* value)
{
m_memberString += value;
return m_memberString.c_str();
}
// To deomnstrate binding properties using accessors.
const char* getMemberString() const
{
return m_memberString.c_str();
}
// To deomnstrate binding properties using accessors.
void setMemberString(const char* value)
{
m_memberString = value;
}
// To deomnstrate binding properties directly.
int m_memberInt;
bool m_memberBool;
private:
// To deomnstrate binding properties using accessors.
std::string m_memberString;
};
// Define the pybind11 module using the same name specified in premake5.lua
PYBIND11_MODULE(_example_pybind_bindings, m)
{
using namespace omni::example::cpp::pybind;
m.doc() = "pybind11 omni.example.cpp.pybind bindings";
carb::defineInterfaceClass<IExampleBoundInterface>(
m, "IExampleBoundInterface", "acquire_bound_interface", "release_bound_interface")
.def("register_bound_object", &IExampleBoundInterface::registerBoundObject,
R"(
Register a bound object.
Args:
object: The bound object to register.
)",
py::arg("object"))
.def("deregister_bound_object", &IExampleBoundInterface::deregisterBoundObject,
R"(
Deregister a bound object.
Args:
object: The bound object to deregister.
)",
py::arg("object"))
.def("find_bound_object", &IExampleBoundInterface::findBoundObject, py::return_value_policy::reference,
R"(
Find a bound object.
Args:
id: Id of the bound object.
Return:
The bound object if it exists, an empty object otherwise.
)",
py::arg("id"))
/**/;
py::class_<IExampleBoundObject, carb::ObjectPtr<IExampleBoundObject>>(m, "IExampleBoundObject")
.def_property_readonly("id", &IExampleBoundObject::getId, py::return_value_policy::reference,
R"(
Get the id of this bound object.
Return:
The id of this bound object.
)")
/**/;
py::class_<PythonBoundObject, IExampleBoundObject, carb::ObjectPtr<PythonBoundObject>>(m, "BoundObject")
.def(py::init([](const char* id) { return PythonBoundObject::create(id); }),
R"(
Create a bound object.
Args:
id: Id of the bound object.
Return:
The bound object that was created.
)",
py::arg("id"))
.def_readwrite("property_int", &PythonBoundObject::m_memberInt,
R"(
Int property bound directly.
)")
.def_readwrite("property_bool", &PythonBoundObject::m_memberBool,
R"(
Bool property bound directly.
)")
.def_property("property_string", &PythonBoundObject::getMemberString, &PythonBoundObject::setMemberString, py::return_value_policy::reference,
R"(
String property bound using accessors.
)")
.def("multiply_int_property", &PythonBoundObject::multiplyIntProperty,
R"(
Bound fuction that accepts an argument.
Args:
value_to_multiply: The value to multiply by.
)",
py::arg("value_to_multiply"))
.def("toggle_bool_property", &PythonBoundObject::toggleBoolProperty,
R"(
Bound fuction that returns a value.
Return:
The toggled bool value.
)")
.def("append_string_property", &PythonBoundObject::appendStringProperty, py::return_value_policy::reference,
R"(
Bound fuction that accepts an argument and returns a value.
Args:
value_to_append: The value to append.
Return:
The new string value.
)",
py::arg("value_to_append"))
/**/;
}
}
| 6,447 | C++ | 31.079602 | 150 | 0.607725 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.pybind/include/omni/example/cpp/pybind/IExampleBoundInterface.h | // Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#pragma once
#include <omni/example/cpp/pybind/IExampleBoundObject.h>
#include <carb/Interface.h>
namespace omni
{
namespace example
{
namespace cpp
{
namespace pybind
{
/**
* An example interface to demonstrate reflection using pybind.
*/
class IExampleBoundInterface
{
public:
/// @private
CARB_PLUGIN_INTERFACE("omni::example::cpp::pybind::IExampleBoundInterface", 1, 0);
/**
* Register a bound object.
*
* @param object The bound object to register.
*/
virtual void registerBoundObject(carb::ObjectPtr<IExampleBoundObject>& object) = 0;
/**
* Deregister a bound object.
*
* @param object The bound object to deregister.
*/
virtual void deregisterBoundObject(carb::ObjectPtr<IExampleBoundObject>& object) = 0;
/**
* Find a bound object.
*
* @param id Id of the bound object.
*
* @return The bound object if it exists, an empty ObjectPtr otherwise.
*/
virtual carb::ObjectPtr<IExampleBoundObject> findBoundObject(const char* id) const = 0;
};
}
}
}
}
| 1,500 | C | 23.606557 | 91 | 0.704 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.pybind/include/omni/example/cpp/pybind/ExampleBoundObject.h | // Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#pragma once
#include <omni/example/cpp/pybind/IExampleBoundObject.h>
#include <carb/ObjectUtils.h>
#include <omni/String.h>
namespace omni
{
namespace example
{
namespace cpp
{
namespace pybind
{
/**
* Helper base class for bound object implementations.
*/
class ExampleBoundObject : public IExampleBoundObject
{
CARB_IOBJECT_IMPL
public:
/**
* Constructor.
*
* @param id Id of the bound object.
*/
ExampleBoundObject(const char* id)
: m_id(id ? id : "")
{
}
/**
* @ref IExampleBoundObject::getId
*/
const char* getId() const override
{
return m_id.c_str();
}
protected:
const omni::string m_id; //!< Id of the bound object.
};
}
}
}
}
| 1,169 | C | 18.5 | 77 | 0.681779 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.pybind/include/omni/example/cpp/pybind/IExampleBoundObject.h | // Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#pragma once
#include <carb/IObject.h>
namespace omni
{
namespace example
{
namespace cpp
{
namespace pybind
{
/**
* Pure virtual bound object interface.
*/
class IExampleBoundObject : public carb::IObject
{
public:
/**
* Get the id of this object.
*
* @return Id of this object.
*/
virtual const char* getId() const = 0;
};
/**
* Implement the equality operator so these can be used in std containers.
*/
inline bool operator==(const carb::ObjectPtr<IExampleBoundObject>& left,
const carb::ObjectPtr<IExampleBoundObject>& right) noexcept
{
return (left.get() == right.get());
}
}
}
}
}
| 1,086 | C | 21.183673 | 82 | 0.70442 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.pybind/config/extension.toml | [package]
version = "1.0.1" # Semantic Versioning is used: https://semver.org/
# These fields are used primarily for display in the extension browser UI.
title = "Example C++ Extension: pybind"
description = "Demonstrates how to reflect C++ code using pybind11 so that it can be called from Python code."
category = "Example"
keywords = ["example", "C++", "cpp", "pybind"]
icon = "data/icon.png"
preview_image = "data/preview.png"
changelog = "docs/CHANGELOG.md"
readme = "docs/README.md"
authors = ["David Bosnich <[email protected]>"]
repository = "https://github.com/NVIDIA-Omniverse/kit-extension-template-cpp"
# Define the Python modules that this extension provides.
[[python.module]]
name = "omni.example.cpp.pybind"
# Define the C++ plugins that this extension provides.
[[native.plugin]]
path = "bin/*.plugin"
# Define any test specific properties of this extension.
[[test]]
cppTests.libraries = [
"bin/${lib_prefix}omni.example.cpp.pybind.tests${lib_ext}"
]
# Define the documentation that will be generated for this extension.
[documentation]
pages = [
"docs/Overview.md",
"docs/CHANGELOG.md",
]
cpp_api = [
"include/omni/example/cpp/pybind/IExampleBoundInterface.h",
"include/omni/example/cpp/pybind/IExampleBoundObject.h",
"include/omni/example/cpp/pybind/ExampleBoundObject.h",
]
| 1,330 | TOML | 31.463414 | 110 | 0.72406 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.pybind/plugins/omni.example.cpp.pybind.tests/ExamplePybindTests.cpp | // Copyright (c) 2020-2021, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#include <omni/example/cpp/pybind/IExampleBoundInterface.h>
#include <omni/example/cpp/pybind/ExampleBoundObject.h>
#include <doctest/doctest.h>
#include <carb/BindingsUtils.h>
CARB_BINDINGS("omni.example.cpp.pybind.tests")
namespace omni
{
namespace example
{
namespace cpp
{
namespace pybind
{
class ExampleCppObject : public ExampleBoundObject
{
public:
static carb::ObjectPtr<IExampleBoundObject> create(const char* id)
{
return carb::stealObject<IExampleBoundObject>(new ExampleCppObject(id));
}
ExampleCppObject(const char* id)
: ExampleBoundObject(id)
{
}
};
class ExamplePybindTestFixture
{
public:
static constexpr const char* k_registeredObjectId = "example_bound_object";
ExamplePybindTestFixture()
: m_exampleBoundInterface(carb::getCachedInterface<omni::example::cpp::pybind::IExampleBoundInterface>())
, m_exampleBoundObject(ExampleCppObject::create(k_registeredObjectId))
{
m_exampleBoundInterface->registerBoundObject(m_exampleBoundObject);
}
~ExamplePybindTestFixture()
{
m_exampleBoundInterface->deregisterBoundObject(m_exampleBoundObject);
}
protected:
IExampleBoundInterface* getExampleBoundInterface()
{
return m_exampleBoundInterface;
}
carb::ObjectPtr<IExampleBoundObject> getExampleBoundObject()
{
return m_exampleBoundObject;
}
private:
IExampleBoundInterface* m_exampleBoundInterface = nullptr;
carb::ObjectPtr<IExampleBoundObject> m_exampleBoundObject;
};
}
}
}
}
TEST_SUITE("omni.example.cpp.pybind.tests")
{
using namespace omni::example::cpp::pybind;
TEST_CASE_FIXTURE(ExamplePybindTestFixture, "Get Example Bound Interface")
{
CHECK(getExampleBoundInterface() != nullptr);
}
TEST_CASE_FIXTURE(ExamplePybindTestFixture, "Get Example Bound Object")
{
CHECK(getExampleBoundObject().get() != nullptr);
}
TEST_CASE_FIXTURE(ExamplePybindTestFixture, "Find Example Bound Object")
{
SUBCASE("Registered")
{
carb::ObjectPtr<IExampleBoundObject> foundObject = getExampleBoundInterface()->findBoundObject(k_registeredObjectId);
CHECK(foundObject.get() == getExampleBoundObject().get());
CHECK(foundObject.get() != nullptr);
}
SUBCASE("Unregistered")
{
carb::ObjectPtr<IExampleBoundObject> foundObject = getExampleBoundInterface()->findBoundObject("unregistered_object_id");
CHECK(foundObject.get() != getExampleBoundObject().get());
CHECK(foundObject.get() == nullptr);
}
}
}
| 3,079 | C++ | 26.747748 | 133 | 0.708996 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.pybind/plugins/omni.example.cpp.pybind/ExamplePybindExtension.cpp | // Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#define CARB_EXPORTS
#include <carb/PluginUtils.h>
#include <omni/ext/IExt.h>
#include <omni/example/cpp/pybind/IExampleBoundInterface.h>
#include <unordered_map>
const struct carb::PluginImplDesc pluginImplDesc = { "omni.example.cpp.pybind.plugin",
"An example C++ extension.", "NVIDIA",
carb::PluginHotReload::eEnabled, "dev" };
namespace omni
{
namespace example
{
namespace cpp
{
namespace pybind
{
class ExampleBoundImplementation : public IExampleBoundInterface
{
public:
void registerBoundObject(carb::ObjectPtr<IExampleBoundObject>& object) override
{
if (object)
{
m_registeredObjectsById[object->getId()] = object;
}
}
void deregisterBoundObject(carb::ObjectPtr<IExampleBoundObject>& object) override
{
if (object)
{
const auto& it = m_registeredObjectsById.find(object->getId());
if (it != m_registeredObjectsById.end())
{
m_registeredObjectsById.erase(it);
}
}
}
carb::ObjectPtr<IExampleBoundObject> findBoundObject(const char* id) const override
{
const auto& it = m_registeredObjectsById.find(id);
if (it != m_registeredObjectsById.end())
{
return it->second;
}
return carb::ObjectPtr<IExampleBoundObject>();
}
private:
std::unordered_map<std::string, carb::ObjectPtr<IExampleBoundObject>> m_registeredObjectsById;
};
}
}
}
}
CARB_PLUGIN_IMPL(pluginImplDesc, omni::example::cpp::pybind::ExampleBoundImplementation)
void fillInterface(omni::example::cpp::pybind::ExampleBoundImplementation& iface)
{
}
| 2,187 | C++ | 26.012345 | 98 | 0.657522 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.pybind/docs/CHANGELOG.md | # Changelog
## [1.0.1] - 2023-04-27
### Updated
- Build against Kit 105.0
## [1.0.0] - 2022-06-30
### Added
- Initial implementation.
| 136 | Markdown | 12.699999 | 25 | 0.610294 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.pybind/docs/Overview.md | # Overview
An example C++ extension that can be used as a reference/template for creating new extensions.
Demonstrates how to reflect C++ code using pybind11 so that it can be called from Python code.
The IExampleBoundInterface located in `include/omni/example/cpp/pybind/IExampleBoundInterface.h` is:
- Implemented in `plugins/omni.example.cpp.pybind/ExamplePybindExtension.cpp`.
- Reflected in `bindings/python/omni.example.cpp.pybind/ExamplePybindBindings.cpp`.
- Accessed from Python in `python/tests/test_pybind_example.py` via `python/impl/example_pybind_extension.py`.
# C++ Usage Examples
## Defining Pybind Module
```
PYBIND11_MODULE(_example_pybind_bindings, m)
{
using namespace omni::example::cpp::pybind;
m.doc() = "pybind11 omni.example.cpp.pybind bindings";
carb::defineInterfaceClass<IExampleBoundInterface>(
m, "IExampleBoundInterface", "acquire_bound_interface", "release_bound_interface")
.def("register_bound_object", &IExampleBoundInterface::registerBoundObject,
R"(
Register a bound object.
Args:
object: The bound object to register.
)",
py::arg("object"))
.def("deregister_bound_object", &IExampleBoundInterface::deregisterBoundObject,
R"(
Deregister a bound object.
Args:
object: The bound object to deregister.
)",
py::arg("object"))
.def("find_bound_object", &IExampleBoundInterface::findBoundObject, py::return_value_policy::reference,
R"(
Find a bound object.
Args:
id: Id of the bound object.
Return:
The bound object if it exists, an empty object otherwise.
)",
py::arg("id"))
/**/;
py::class_<IExampleBoundObject, carb::ObjectPtr<IExampleBoundObject>>(m, "IExampleBoundObject")
.def_property_readonly("id", &IExampleBoundObject::getId, py::return_value_policy::reference,
R"(
Get the id of this bound object.
Return:
The id of this bound object.
)")
/**/;
py::class_<PythonBoundObject, IExampleBoundObject, carb::ObjectPtr<PythonBoundObject>>(m, "BoundObject")
.def(py::init([](const char* id) { return PythonBoundObject::create(id); }),
R"(
Create a bound object.
Args:
id: Id of the bound object.
Return:
The bound object that was created.
)",
py::arg("id"))
.def_readwrite("property_int", &PythonBoundObject::m_memberInt,
R"(
Int property bound directly.
)")
.def_readwrite("property_bool", &PythonBoundObject::m_memberBool,
R"(
Bool property bound directly.
)")
.def_property("property_string", &PythonBoundObject::getMemberString, &PythonBoundObject::setMemberString, py::return_value_policy::reference,
R"(
String property bound using accessors.
)")
.def("multiply_int_property", &PythonBoundObject::multiplyIntProperty,
R"(
Bound fuction that accepts an argument.
Args:
value_to_multiply: The value to multiply by.
)",
py::arg("value_to_multiply"))
.def("toggle_bool_property", &PythonBoundObject::toggleBoolProperty,
R"(
Bound fuction that returns a value.
Return:
The toggled bool value.
)")
.def("append_string_property", &PythonBoundObject::appendStringProperty, py::return_value_policy::reference,
R"(
Bound fuction that accepts an argument and returns a value.
Args:
value_to_append: The value to append.
Return:
The new string value.
)",
py::arg("value_to_append"))
/**/;
}
```
| 4,125 | Markdown | 33.099173 | 150 | 0.575273 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.usd_physics/config/extension.toml | [package]
version = "1.0.1" # Semantic Versioning is used: https://semver.org/
# These fields are used primarily for display in the extension browser UI.
title = "Example C++ Extension: USD Physics"
description = "Demonstrates how to create a C++ plugin that can add physics to the current USD stage."
category = "Example"
keywords = ["example", "C++", "cpp", "USD", "Physics"]
icon = "data/icon.png"
preview_image = "data/preview.png"
changelog = "docs/CHANGELOG.md"
readme = "docs/README.md"
authors = ["David Bosnich <[email protected]>"]
repository = "https://github.com/NVIDIA-Omniverse/kit-extension-template-cpp"
[dependencies]
"omni.physx" = {}
# Define the Python modules that this extension provides.
# C++ only extensions need this just so tests don't fail.
[[python.module]]
name = "omni.example.cpp.usd_physics"
# Define the C++ plugins that this extension provides.
[[native.plugin]]
path = "bin/*.plugin"
# Define the documentation that will be generated for this extension.
[documentation]
pages = [
"docs/Overview.md",
"docs/CHANGELOG.md",
]
| 1,075 | TOML | 30.647058 | 102 | 0.71814 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.usd_physics/plugins/omni.example.cpp.usd_physics/ExampleUsdPhysicsExtension.cpp | // Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#define CARB_EXPORTS
#include <carb/PluginUtils.h>
#include <omni/ext/IExt.h>
#include <pxr/usd/usd/stage.h>
#include <pxr/usd/usdGeom/cube.h>
#include <pxr/usd/usdGeom/metrics.h>
#include <pxr/usd/usdPhysics/collisionAPI.h>
#include <pxr/usd/usdPhysics/massAPI.h>
#include <pxr/usd/usdPhysics/rigidBodyAPI.h>
#include <pxr/usd/usdPhysics/scene.h>
#include <pxr/usd/usdUtils/stageCache.h>
const struct carb::PluginImplDesc pluginImplDesc = { "omni.example.cpp.usd_physics.plugin",
"An example C++ extension.", "NVIDIA",
carb::PluginHotReload::eEnabled, "dev" };
namespace omni
{
namespace example
{
namespace cpp
{
namespace usd_physics
{
class ExampleUsdPhysicsExtension : public omni::ext::IExt
{
protected:
void onStartup(const char* extId) override
{
// Get the 'active' USD stage from the USD stage cache.
const std::vector<PXR_NS::UsdStageRefPtr> allStages = PXR_NS::UsdUtilsStageCache::Get().GetAllStages();
if (allStages.size() != 1)
{
CARB_LOG_WARN("Cannot determine the 'active' USD stage (%zu stages present in the USD stage cache).", allStages.size());
return;
}
// Get the meters per unit and up axis of the 'active' USD stage.
PXR_NS::UsdStageRefPtr activeStage = allStages[0];
const double activeStageMetersPerUnit = PXR_NS::UsdGeomGetStageMetersPerUnit(activeStage);
if (PXR_NS::UsdGeomGetStageUpAxis(activeStage) != PXR_NS::UsdGeomTokens->y)
{
// Handling this is possible, but it would complicate the example,
// that is only designed to work in an empty stage with Y-axis up.
CARB_LOG_WARN("The up axis of the 'active' USD stage is not Y.");
return;
}
// Create and setup the USD physics scene.
static const PXR_NS::SdfPath kPhysicsScenePath("/World/PhysicsScene");
if (!activeStage->GetPrimAtPath(kPhysicsScenePath))
{
static constexpr PXR_NS::GfVec3f kGravityDirection = { 0.0f, -1.0f, 0.0f };
static constexpr float kGravityMagnitude = 981.0f;
PXR_NS::UsdPhysicsScene physicsScene = PXR_NS::UsdPhysicsScene::Define(activeStage, kPhysicsScenePath);
physicsScene.CreateGravityDirectionAttr().Set(kGravityDirection);
physicsScene.CreateGravityMagnitudeAttr().Set(kGravityMagnitude);
}
// Create and setup a static ground plane (box for now, should use UsdGeomPlane instead).
static const PXR_NS::SdfPath kGroundPlanePath("/World/StaticGroundPlane");
if (!activeStage->GetPrimAtPath(kGroundPlanePath))
{
const double kSize = 5.0 / activeStageMetersPerUnit;
const PXR_NS::GfVec3f kColour = { 1.0f, 1.0f, 1.0f };
const PXR_NS::GfVec3f kPosition = { 0.0f, -(float)kSize * 0.5f, 0.0f };
PXR_NS::UsdGeomCube geomPrim = PXR_NS::UsdGeomCube::Define(activeStage, kGroundPlanePath);
geomPrim.CreateSizeAttr().Set(kSize);
geomPrim.AddTranslateOp(PXR_NS::UsdGeomXformOp::PrecisionFloat).Set(kPosition);
geomPrim.CreateDisplayColorAttr().Set(PXR_NS::VtArray<PXR_NS::GfVec3f>({ kColour }));
PXR_NS::UsdPhysicsCollisionAPI::Apply(geomPrim.GetPrim());
}
// Create and setup a rigid body box.
const PXR_NS::SdfPath kRigidBodyPath("/World/RigidBodyBox");
if (!activeStage->GetPrimAtPath(kRigidBodyPath))
{
const double kSize = 0.5 / activeStageMetersPerUnit;
const PXR_NS::GfVec3f kColour = { 0.0f, 0.0f, 1.0f };
const PXR_NS::GfVec3f kPosition = { 0.0f, (float)kSize * 5.0f, 0.0f };
PXR_NS::UsdGeomCube geomPrim = PXR_NS::UsdGeomCube::Define(activeStage, kRigidBodyPath);
geomPrim.CreateSizeAttr().Set(kSize);
geomPrim.AddTranslateOp(PXR_NS::UsdGeomXformOp::PrecisionFloat).Set(kPosition);
geomPrim.CreateDisplayColorAttr().Set(PXR_NS::VtArray<PXR_NS::GfVec3f>({ kColour }));
static constexpr PXR_NS::GfVec3f kVelocity = { 2.0f, 1.0f, 2.0f };
static constexpr PXR_NS::GfVec3f kAngularVelocity = { 180.0f, 0.0f, 0.0f };
PXR_NS::UsdPhysicsCollisionAPI::Apply(geomPrim.GetPrim());
PXR_NS::UsdPhysicsMassAPI::Apply(geomPrim.GetPrim());
auto rigidBodyAPI = PXR_NS::UsdPhysicsRigidBodyAPI::Apply(geomPrim.GetPrim());
rigidBodyAPI.CreateVelocityAttr().Set(kVelocity);
rigidBodyAPI.CreateAngularVelocityAttr().Set(kAngularVelocity);
}
}
void onShutdown() override
{
}
};
}
}
}
}
CARB_PLUGIN_IMPL(pluginImplDesc, omni::example::cpp::usd_physics::ExampleUsdPhysicsExtension)
void fillInterface(omni::example::cpp::usd_physics::ExampleUsdPhysicsExtension& iface)
{
}
| 5,348 | C++ | 40.465116 | 132 | 0.658377 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.usd_physics/omni/example/cpp/usd_physics/__init__.py | ## Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
# This file is needed so tests don't fail.
| 480 | Python | 42.727269 | 77 | 0.785417 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.usd_physics/docs/CHANGELOG.md | # Changelog
## [1.0.1] - 2023-04-27
### Updated
- Build against Kit 105.0
## [1.0.0] - 2022-11-14
### Added
- Initial implementation.
| 136 | Markdown | 12.699999 | 25 | 0.610294 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.usd_physics/docs/Overview.md | # Overview
An example C++ extension that can be used as a reference/template for creating new extensions.
Demonstrates how to create a C++ plugin that can add physics to the current USD stage by:
- Using the UsdStageCache to get a USD stage from C++.
- Adding a UsdPhysicsScene to the USD stage from C++.
- Adding a static body box to the USD stage from C++.
- Adding a rigid body box to the USD stage from C++.
Note: It is important that all USD stage reads/writes happen from the main thread:
[https://graphics.pixar.com/usd/release/api/_usd__page__multi_threading.html](https://graphics.pixar.com/usd/release/api/_usd__page__multi_threading.html)
# Example

| 715 | Markdown | 33.095237 | 154 | 0.748252 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.commands/config/extension.toml | [package]
version = "1.0.1" # Semantic Versioning is used: https://semver.org/
# These fields are used primarily for display in the extension browser UI.
title = "Example C++ Extension: commands"
description = "Demonstrates how to create commands in C++ that can then be executed from either C++ or Python."
category = "Example"
keywords = ["example", "C++", "cpp", "commands"]
icon = "data/icon.png"
preview_image = "data/preview.png"
changelog = "docs/CHANGELOG.md"
readme = "docs/README.md"
authors = ["David Bosnich <[email protected]>"]
repository = "https://github.com/NVIDIA-Omniverse/kit-extension-template-cpp"
[dependencies]
"omni.kit.commands" = {}
# Define the Python modules that this extension provides.
[[python.module]]
name = "omni.example.cpp.commands"
# Define the C++ plugins that this extension provides.
[[native.plugin]]
path = "bin/*.plugin"
# Define any test specific properties of this extension.
[[test]]
cppTests.libraries = [
"bin/${lib_prefix}omni.example.cpp.commands.tests${lib_ext}"
]
# Define the documentation that will be generated for this extension.
[documentation]
pages = [
"docs/Overview.md",
"docs/CHANGELOG.md",
]
| 1,178 | TOML | 29.230768 | 111 | 0.719864 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.commands/plugins/omni.example.cpp.commands/ExampleCommandsExtension.cpp | // Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#define CARB_EXPORTS
#include <carb/PluginUtils.h>
#include <omni/ext/IExt.h>
#include <omni/kit/commands/Command.h>
#include <omni/kit/commands/ICommandBridge.h>
const struct carb::PluginImplDesc pluginImplDesc = { "omni.example.cpp.commands.plugin",
"An example C++ extension.", "NVIDIA",
carb::PluginHotReload::eEnabled, "dev" };
namespace omni
{
namespace example
{
namespace cpp
{
namespace commands
{
using namespace omni::kit::commands;
class ExampleCppCommand : public Command
{
public:
static carb::ObjectPtr<ICommand> create(const char* extensionId,
const char* commandName,
const carb::dictionary::Item* kwargs)
{
// Note: It is important to construct the handler using ObjectPtr<T>::InitPolicy::eSteal,
// otherwise we end up incresing the reference count by one too many during construction,
// resulting in a carb::ObjectPtr<IAction> whose object instance will never be destroyed.
return carb::stealObject<ICommand>(new ExampleCppCommand(extensionId, commandName, kwargs));
}
static void populateKeywordArgs(carb::dictionary::Item* defaultKwargs,
carb::dictionary::Item* optionalKwargs,
carb::dictionary::Item* requiredKwargs)
{
if (carb::dictionary::IDictionary* iDictionary = carb::getCachedInterface<carb::dictionary::IDictionary>())
{
iDictionary->makeAtPath(defaultKwargs, "x", 9);
iDictionary->makeAtPath(defaultKwargs, "y", -1);
}
}
ExampleCppCommand(const char* extensionId, const char* commandName, const carb::dictionary::Item* kwargs)
: Command(extensionId, commandName)
{
if (carb::dictionary::IDictionary* iDictionary = carb::getCachedInterface<carb::dictionary::IDictionary>())
{
m_x = iDictionary->get<int32_t>(kwargs, "x");
m_y = iDictionary->get<int32_t>(kwargs, "y");
}
}
void doCommand() override
{
printf("Executing command '%s' with params 'x=%d' and 'y=%d'.\n", getName(), m_x, m_y);
}
void undoCommand() override
{
printf("Undoing command '%s' with params 'x=%d' and 'y=%d'.\n", getName(), m_x, m_y);
}
private:
int32_t m_x = 0;
int32_t m_y = 0;
};
class ExampleCommandsExtension : public omni::ext::IExt
{
public:
void onStartup(const char* extId) override
{
auto commandBridge = carb::getCachedInterface<ICommandBridge>();
if (!commandBridge)
{
CARB_LOG_WARN("Could not get cached ICommandBridge interface.");
return;
}
// Example of registering a command from C++.
commandBridge->registerCommand(
"omni.example.cpp.commands", "ExampleCppCommand", ExampleCppCommand::create, ExampleCppCommand::populateKeywordArgs);
}
void onShutdown() override
{
if (auto commandBridge = carb::getCachedInterface<ICommandBridge>())
{
commandBridge->deregisterCommand("omni.example.cpp.commands", "ExampleCppCommand");
}
else
{
CARB_LOG_WARN("Could not get cached ICommandBridge interface.");
}
}
};
}
}
}
}
CARB_PLUGIN_IMPL(pluginImplDesc, omni::example::cpp::commands::ExampleCommandsExtension)
void fillInterface(omni::example::cpp::commands::ExampleCommandsExtension& iface)
{
}
| 4,025 | C++ | 31.731707 | 129 | 0.631304 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.commands/plugins/omni.example.cpp.commands.tests/ExampleCommandsTests.cpp | // Copyright (c) 2020-2021, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#include <doctest/doctest.h>
#include <carb/BindingsUtils.h>
#include <omni/kit/commands/ICommandBridge.h>
CARB_BINDINGS("omni.example.cpp.commands.tests")
TEST_SUITE("omni.example.cpp.commands.tests")
{
using namespace omni::kit::commands;
TEST_CASE("Execute Example C++ Command")
{
auto commandBridge = carb::getCachedInterface<ICommandBridge>();
REQUIRE(commandBridge != nullptr);
// Execute
bool result = commandBridge->executeCommand("ExampleCpp");
CHECK(result);
// Undo
result = commandBridge->undoCommand();
CHECK(result);
// Redo
result = commandBridge->redoCommand();
CHECK(result);
// Undo
result = commandBridge->undoCommand();
CHECK(result);
// Execute with args
carb::dictionary::IDictionary* iDictionary = carb::getCachedInterface<carb::dictionary::IDictionary>();
REQUIRE(iDictionary != nullptr);
carb::dictionary::Item* kwargs = iDictionary->createItem(nullptr, "", carb::dictionary::ItemType::eDictionary);
REQUIRE(kwargs != nullptr);
iDictionary->makeAtPath(kwargs, "x", -9);
iDictionary->makeAtPath(kwargs, "y", 99);
result = commandBridge->executeCommand("ExampleCpp", kwargs);
iDictionary->destroyItem(kwargs);
CHECK(result);
// Repeat
result = commandBridge->repeatCommand();
CHECK(result);
// Undo
result = commandBridge->undoCommand();
CHECK(result);
// Undo
result = commandBridge->undoCommand();
CHECK(result);
// Undo (empty command stack)
result = commandBridge->undoCommand();
CHECK(!result);
}
}
| 2,186 | C++ | 29.802816 | 119 | 0.651418 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.commands/omni/example/cpp/commands/tests/test_commands_example.py | ## Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
import omni.kit.test
import omni.kit.commands
import omni.kit.undo
class TestCommandsExample(omni.kit.test.AsyncTestCase):
async def setUp(self):
omni.kit.undo.clear_stack()
async def tearDown(self):
omni.kit.undo.clear_stack()
async def test_cpp_commands(self):
# Execute
res = omni.kit.commands.execute("ExampleCpp")
self.assertEqual(res, (True, None))
# Undo
res = omni.kit.undo.undo()
self.assertTrue(res)
# Redo
res = omni.kit.undo.redo()
self.assertTrue(res)
# Repeat
res = omni.kit.undo.repeat()
self.assertTrue(res)
# Undo
res = omni.kit.undo.undo()
self.assertTrue(res)
# Undo
res = omni.kit.undo.undo()
self.assertTrue(res)
# Undo (empty command stack)
res = omni.kit.undo.undo()
self.assertFalse(res)
| 1,355 | Python | 26.119999 | 77 | 0.648708 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.commands/omni/example/cpp/commands/tests/__init__.py | ## Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
from .test_commands_example import *
| 473 | Python | 46.399995 | 77 | 0.792812 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.commands/docs/CHANGELOG.md | # Changelog
## [1.0.1] - 2023-04-27
### Updated
- Build against Kit 105.0
## [1.0.0] - 2022-11-04
### Added
- Initial implementation.
| 136 | Markdown | 12.699999 | 25 | 0.610294 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.commands/docs/Overview.md | # Overview
An example C++ extension that can be used as a reference/template for creating new extensions.
Demonstrates how to create commands in C++ that can then be executed from either C++ or Python.
See the omni.kit.commands extension for extensive documentation about commands themselves.
# C++ Usage Examples
## Defining Commands
```
using namespace omni::kit::commands;
class ExampleCppCommand : public Command
{
public:
static carb::ObjectPtr<ICommand> create(const char* extensionId,
const char* commandName,
const carb::dictionary::Item* kwargs)
{
return carb::stealObject<ICommand>(new ExampleCppCommand(extensionId, commandName, kwargs));
}
static void populateKeywordArgs(carb::dictionary::Item* defaultKwargs,
carb::dictionary::Item* optionalKwargs,
carb::dictionary::Item* requiredKwargs)
{
if (carb::dictionary::IDictionary* iDictionary = carb::getCachedInterface<carb::dictionary::IDictionary>())
{
iDictionary->makeAtPath(defaultKwargs, "x", 9);
iDictionary->makeAtPath(defaultKwargs, "y", -1);
}
}
ExampleCppCommand(const char* extensionId, const char* commandName, const carb::dictionary::Item* kwargs)
: Command(extensionId, commandName)
{
if (carb::dictionary::IDictionary* iDictionary = carb::getCachedInterface<carb::dictionary::IDictionary>())
{
m_x = iDictionary->get<int32_t>(kwargs, "x");
m_y = iDictionary->get<int32_t>(kwargs, "y");
}
}
void doCommand() override
{
printf("Executing command '%s' with params 'x=%d' and 'y=%d'.\n", getName(), m_x, m_y);
}
void undoCommand() override
{
printf("Undoing command '%s' with params 'x=%d' and 'y=%d'.\n", getName(), m_x, m_y);
}
private:
int32_t m_x = 0;
int32_t m_y = 0;
};
```
## Registering Commands
```
auto commandBridge = carb::getCachedInterface<omni::kit::commands::ICommandBridge>());
commandBridge->registerCommand(
"omni.example.cpp.commands", "ExampleCppCommand", ExampleCppCommand::create, ExampleCppCommand::populateKeywordArgs);
// Note that the command name (in this case "ExampleCppCommand") is arbitrary and does not need to match the C++ class
```
## Executing Commands
```
auto commandBridge = carb::getCachedInterface<omni::kit::commands::ICommandBridge>());
// Create the kwargs dictionary.
auto iDictionary = carb::getCachedInterface<carb::dictionary::IDictionary>();
carb::dictionary::Item* kwargs = iDictionary->createItem(nullptr, "", carb::dictionary::ItemType::eDictionary);
iDictionary->makeIntAtPath(kwargs, "x", 7);
iDictionary->makeIntAtPath(kwargs, "y", 9);
// Execute the command using its name...
commandBridge->executeCommand("ExampleCppCommand", kwargs);
// or without the 'Command' postfix just like Python commands...
commandBridge->executeCommand("ExampleCpp", kwargs);
// or fully qualified if needed to disambiguate (works with or without the 'Command)' postfix.
commandBridge->executeCommand("omni.example.cpp.commands", "ExampleCppCommand", kwargs);
// Destroy the kwargs dictionary.
iDictionary->destroyItem(kwargs);
// The C++ command can be executed from Python exactly like any Python command,
// and we can also execute Python commands from C++ in the same ways as above:
commandBridge->executeCommand("SomePythonCommand", kwargs);
// etc.
```
## Undo/Redo/Repeat Commands
```
auto commandBridge = carb::getCachedInterface<omni::kit::commands::ICommandBridge>());
// It doesn't matter whether the command stack contains Python commands, C++ commands,
// or a mix of both, and the same stands for when undoing/redoing commands from Python.
commandBridge->undoCommand();
commandBridge->redoCommand();
commandBridge->repeatCommand();
```
## Deregistering Commands
```
auto commandBridge = carb::getCachedInterface<omni::kit::commands::ICommandBridge>());
commandBridge->deregisterCommand("omni.example.cpp.commands", "ExampleCppCommand");
```
| 4,154 | Markdown | 32.508064 | 121 | 0.685123 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.ui_widget/python/tests/__init__.py | # Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA CORPORATION is strictly prohibited.
#
from .test_cpp_widget import TestCppWidget
| 471 | Python | 46.199995 | 76 | 0.81104 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.ui_widget/python/tests/test_cpp_widget.py | ## Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
__all__ = ["TestCppWidget"]
from omni.example.cpp.ui_widget import CppWidget
from omni.ui.tests.test_base import OmniUiTest
from pathlib import Path
import omni.kit.app
import omni.ui as ui
EXTENSION_PATH = Path(omni.kit.app.get_app().get_extension_manager().get_extension_path_by_module(__name__))
GOLDEN_PATH = EXTENSION_PATH.joinpath("data/golden")
STYLE = {"CppWidget": {"color": ui.color.red}}
class TestCppWidget(OmniUiTest):
async def test_general(self):
"""Testing general look of CppWidget"""
window = await self.create_test_window()
with window.frame:
CppWidget(thickness=2, style=STYLE)
await self.finalize_test(golden_img_dir=GOLDEN_PATH, golden_img_name=f"test_general.png")
| 1,180 | Python | 34.787878 | 108 | 0.738136 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.ui_widget/bindings/python/omni.example.cpp.ui_widget/BindCppWidget.cpp | // Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#include <omni/ui/bind/BindUtils.h>
#include <pybind11/functional.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <CppWidget.h>
#include <BindCppWidget.h>
using namespace pybind11;
OMNIUI_NAMESPACE_USING_DIRECTIVE
OMNIUI_CPPWIDGET_NAMESPACE_USING_DIRECTIVE
void wrapCppWidget(module& m)
{
const char* cppWidgetDoc = OMNIUI_PYBIND_CLASS_DOC(CppWidget);
const char* cppWidgetConstructorDoc = OMNIUI_PYBIND_CONSTRUCTOR_DOC(CppWidget, CppWidget);
class_<CppWidget, omni::ui::Widget, std::shared_ptr<CppWidget>>(m, "CppWidget", cppWidgetDoc)
.def(init([](kwargs kwargs) { OMNIUI_PYBIND_INIT(CppWidget) }), cppWidgetConstructorDoc)
.def_property(
"thickness", &CppWidget::getThickness, &CppWidget::setThickness, OMNIUI_PYBIND_DOC_CppWidget_thickness)
/* */;
}
| 1,263 | C++ | 36.17647 | 115 | 0.752177 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.ui_widget/bindings/python/omni.example.cpp.ui_widget/__init__.py | ## Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
"""
omni.example.cpp.ui_widget
---------------------------
"""
__all__ = ["CppWidget"]
from ._example_cpp_widget import *
| 559 | Python | 33.999998 | 77 | 0.726297 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.ui_widget/bindings/python/omni.example.cpp.ui_widget/Module.cpp | // Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#include <carb/BindingsUtils.h>
#include <omni/ui/bind/BindUtils.h>
#include <pybind11/pybind11.h>
// We need to be registered as Carbonite plugin because we need to use CARB_LOG_ERROR
CARB_BINDINGS("omni.example.cpp.ui_widget.python")
PYBIND11_MODULE(_example_cpp_widget, m)
{
pybind11::module::import("omni.ui");
OMNIUI_BIND(CppWidget);
}
| 787 | C++ | 33.260868 | 85 | 0.768742 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.ui_widget/bindings/python/omni.example.cpp.ui_widget/DocCppWidget.h | // Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#pragma once
#define OMNIUI_PYBIND_DOC_CppWidget \
"A simple C++ omni.ui widget that draws a rectangle.\n" \
"\n"
#define OMNIUI_PYBIND_DOC_CppWidget_thickness "This property holds the thickness of the rectangle line.\n"
#define OMNIUI_PYBIND_DOC_CppWidget_CppWidget "Constructor.\n"
| 873 | C | 47.555553 | 120 | 0.647194 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.ui_widget/bindings/python/omni.example.cpp.ui_widget/BindCppWidget.h | // Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#pragma once
#include <DocCppWidget.h>
#include <omni/ui/bind/BindWidget.h>
// clang-format off
#define OMNIUI_PYBIND_INIT_CppWidget \
OMNIUI_PYBIND_INIT_CAST(thickness, setThickness, float) \
OMNIUI_PYBIND_INIT_Widget
#define OMNIUI_PYBIND_KWARGS_DOC_CppWidget \
"\n `thickness : float`\n " \
OMNIUI_PYBIND_DOC_CppWidget_thickness \
OMNIUI_PYBIND_KWARGS_DOC_Widget
// clang-format on
| 1,224 | C | 47.999998 | 120 | 0.52451 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.ui_widget/include/CppWidget.h | // Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#pragma once
#include "Api.h"
#include <string>
#include <omni/ui/Widget.h>
OMNIUI_CPPWIDGET_NAMESPACE_OPEN_SCOPE
/**
* @brief A simple C++ omni.ui widget that draws a rectangle.
*/
class OMNIUI_CPPWIDGET_CLASS_API CppWidget : public OMNIUI_NS::Widget
{
OMNIUI_OBJECT(CppWidget)
public:
OMNIUI_CPPWIDGET_API
~CppWidget() override;
/**
* @brief This property holds the thickness of the rectangle line.
*/
/// @private (suppress doc generation error)
OMNIUI_PROPERTY(float, thickness, DEFAULT, 1.0f, READ, getThickness, WRITE, setThickness);
protected:
/**
* Constructor.
*/
OMNIUI_CPPWIDGET_API
CppWidget();
/**
* @brief Reimplemented the rendering code of the widget.
*
* @see Widget::_drawContent
*/
OMNIUI_CPPWIDGET_API
void _drawContent(float elapsedTime) override;
private:
};
OMNIUI_CPPWIDGET_NAMESPACE_CLOSE_SCOPE
| 1,354 | C | 24.092592 | 94 | 0.710487 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.ui_widget/include/Api.h | // Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#pragma once
#ifdef _WIN32
// When we build DLL, we need the __declspec(dllexport) keyword to export class
// member functions from a DLL. __declspec(dllexport) adds the export directive
// to the object file, so you do not need to use a .def file.
# define OMNIUI_CPPWIDGET_EXPORT __declspec(dllexport)
// When we build a third-party library that uses public symbols defined by this
// DLL, the symbols must be imported. We need to use __declspec(dllimport) on
// the declarations of the public symbols.
# define OMNIUI_CPPWIDGET_IMPORT __declspec(dllimport)
# define OMNIUI_CPPWIDGET_CLASS_EXPORT
#else
// It works similarly in Linux. The symbols must be visible in DSO because we
// build with the compiler option -fvisibility=hidden.
# define OMNIUI_CPPWIDGET_EXPORT __attribute__((visibility("default")))
// But to use them we don't need to use any dirrective.
# define OMNIUI_CPPWIDGET_IMPORT
// typeinfo of the class should be visible in DSO as well.
# define OMNIUI_CPPWIDGET_CLASS_EXPORT __attribute__((visibility("default")))
#endif
#if defined(OMNIUI_CPPWIDGET_STATIC)
# define OMNIUI_CPPWIDGET_API
# define OMNIUI_CPPWIDGET_CLASS_API
#else
# if defined(OMNIUI_CPPWIDGET_EXPORTS)
# define OMNIUI_CPPWIDGET_API OMNIUI_CPPWIDGET_EXPORT
# define OMNIUI_CPPWIDGET_CLASS_API OMNIUI_CPPWIDGET_CLASS_EXPORT
# else
# define OMNIUI_CPPWIDGET_API OMNIUI_CPPWIDGET_IMPORT
# define OMNIUI_CPPWIDGET_CLASS_API
# endif
#endif
#define OMNIUI_CPPWIDGET_NS omni::ui::example_cpp_widget
#define OMNIUI_CPPWIDGET_NAMESPACE_USING_DIRECTIVE using namespace OMNIUI_CPPWIDGET_NS;
#define OMNIUI_CPPWIDGET_NAMESPACE_OPEN_SCOPE \
namespace omni \
{ \
namespace ui \
{ \
namespace example_cpp_widget \
{
#define OMNIUI_CPPWIDGET_NAMESPACE_CLOSE_SCOPE \
} \
} \
}
| 3,167 | C | 54.578946 | 120 | 0.533944 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.ui_widget/config/extension.toml | [package]
version = "1.0.1" # Semantic Versioning is used: https://semver.org/
# These fields are used primarily for display in the extension browser UI.
title = "Example C++ Extension: UI Widget"
description = "Demonstrates how to create a C++ widget for omni.ui"
category = "Example"
keywords = ["example", "C++", "cpp", "UI"]
icon = "data/icon.png"
preview_image = "data/preview.png"
changelog = "docs/CHANGELOG.md"
readme = "docs/README.md"
authors = ["Victor Yudin <[email protected]>", "David Bosnich <[email protected]>"]
repository = "https://github.com/NVIDIA-Omniverse/kit-extension-template-cpp"
[dependencies]
"omni.ui" = {}
[[python.module]]
name = "omni.example.cpp.ui_widget"
[[native.library]]
path = "bin/${lib_prefix}omni.example.cpp.ui_widget${lib_ext}"
[[test]]
dependencies = [
"omni.kit.renderer.capture",
"omni.kit.ui_test",
]
args = [
"--/app/window/dpiScaleOverride=1.0",
"--/app/window/scaleToMonitor=false",
"--no-window"
]
stdoutFailPatterns.exclude = [
"*omniclient: Initialization failed*",
]
[documentation]
pages = [
"docs/Overview.md",
"docs/CHANGELOG.md",
]
cpp_api = [
"include/CppWidget.h",
]
| 1,177 | TOML | 23.040816 | 85 | 0.675446 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.ui_widget/plugins/omni.example.cpp.ui_widget/ExampleUIExtension.cpp | // Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#include <carb/BindingsUtils.h>
#include <omni/ui/Api.h>
#ifdef _WIN32
# include <Windows.h>
#endif
// We need to be registered as Carbonite client because we need to use Carbonite interfaces.
CARB_BINDINGS("omni.example.cpp.ui_widget")
| 677 | C++ | 34.684209 | 92 | 0.776957 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.ui_widget/plugins/omni.example.cpp.ui_widget/CppWidget.cpp | // Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#include <imgui/imgui.h>
#include <imgui/imgui_internal.h>
#include <CppWidget.h>
OMNIUI_CPPWIDGET_NAMESPACE_OPEN_SCOPE
CppWidget::CppWidget() : Widget{}
{
}
CppWidget::~CppWidget()
{
}
void CppWidget::_drawContent(float elapsedTime)
{
ImVec2 start = ImGui::GetCursorScreenPos();
float computedWidth = this->getComputedContentWidth();
float computedHeight = this->getComputedContentHeight();
// Draw a rect
ImVec2 rectMax{ start.x + computedWidth, start.y + computedHeight };
// We need to scale the thickness to look similar on all the monitors.
float scaledThickness = this->getThickness() * this->getDpiScale();
// Determine which color we need from the style. The style should look like
// this to set red color:
// {"CppWidget": {"color": ui.color.red}}
uint32_t color = 0xff000000;
this->_resolveStyleProperty(StyleColorProperty::eColor, &color);
ImGui::GetWindowDrawList()->AddRect(start, rectMax, 0xff0000ff, 0.0f, 0, scaledThickness);
}
OMNIUI_CPPWIDGET_NAMESPACE_CLOSE_SCOPE
| 1,481 | C++ | 31.217391 | 94 | 0.738015 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.ui_widget/docs/CHANGELOG.md | # Changelog
## [1.0.1] - 2023-04-27
### Updated
- Build against Kit 105.0
## [1.0.0] - 2022-07-01
### Added
- Initial implementation.
| 136 | Markdown | 12.699999 | 25 | 0.610294 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.ui_widget/docs/Overview.md | # Overview
An example C++ extension that can be used as a reference/template for creating new extensions.
Demonstrates how to create a C++ widget for omni.ui that has a property and draws a simple rectangle.
| 211 | Markdown | 29.28571 | 101 | 0.777251 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.usdrt/python/tests/__init__.py | ## Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
from .test_usdrt_example import *
| 470 | Python | 46.099995 | 77 | 0.791489 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.usdrt/python/tests/test_usdrt_example.py | ## Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
import omni.example.cpp.usdrt
import omni.kit.app
import omni.kit.test
import omni.usd
from usdrt import Sdf
class TestUsdrtExample(omni.kit.test.AsyncTestCase):
async def setUp(self):
# Cache the example usdrt interface.
self.example_usdrt_interface = omni.example.cpp.usdrt.get_example_usdrt_interface()
# Open a new USD stage.
omni.usd.get_context().new_stage()
self.usd_stage = omni.usd.get_context().get_stage()
self.stage_id = omni.usd.get_context().get_stage_id()
# Create a torus
(success, pathString) = omni.kit.commands.execute("CreateMeshPrimWithDefaultXformCommand", prim_type="Torus")
self.assertTrue(success)
self.prim_path = Sdf.Path(pathString)
async def tearDown(self):
# Close the USD stage.
await omni.usd.get_context().close_stage_async()
self.usd_stage = None
# Clear the example usdrt interface.
self.example_usdrt_interface = None
async def test_get_attributes_for_prim(self):
(err, attrs) = self.example_usdrt_interface.get_attributes_for_prim(self.stage_id, self.prim_path)
self.assertTrue(err == "")
self.assertTrue(attrs)
# test invalid prim
(err, attrs) = self.example_usdrt_interface.get_attributes_for_prim(self.stage_id, Sdf.Path("/invalidPrim"))
self.assertTrue(err == "Prim at path /invalidPrim is not in Fabric")
self.assertFalse(attrs)
# test empty path
(err, attrs) = self.example_usdrt_interface.get_attributes_for_prim(self.stage_id, Sdf.Path(""))
self.assertTrue(err == "Nothing selected")
self.assertFalse(attrs)
async def test_apply_random_rotation(self):
(err, rotation) = self.example_usdrt_interface.apply_random_rotation(self.stage_id, self.prim_path)
self.assertTrue(err == "")
self.assertTrue(rotation)
# test invalid prim
(err, rotation) = self.example_usdrt_interface.apply_random_rotation(self.stage_id, Sdf.Path("/invalidPrim"))
self.assertTrue(err == "Prim at path /invalidPrim is not in Fabric")
# test empty path
(err, rotation) = self.example_usdrt_interface.apply_random_rotation(self.stage_id, Sdf.Path(""))
self.assertTrue(err == "Nothing selected")
async def test_deform_mesh(self):
t = 0
result = self.example_usdrt_interface.deform_mesh(self.stage_id, self.prim_path, t)
self.assertTrue(result == f"Deformed points on prim {self.prim_path}")
# test invalid prim
result = self.example_usdrt_interface.deform_mesh(self.stage_id, Sdf.Path("/invalidPrim"), t)
self.assertTrue(result == "Prim at path /invalidPrim is not in Fabric")
# test empty path
result =self.example_usdrt_interface.deform_mesh(self.stage_id, Sdf.Path(""), t)
self.assertTrue(result == "Nothing selected")
| 3,357 | Python | 39.951219 | 117 | 0.677391 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.usdrt/python/impl/__init__.py | ## Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
from .example_usdrt_extension import *
| 475 | Python | 46.599995 | 77 | 0.793684 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.usdrt/python/impl/example_usdrt_extension.py | ## Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
import math
import random
from ctypes import alignment
import omni.ext
import omni.ui as ui
import omni.usd
from usdrt import Gf, Rt, Sdf, Usd, Vt
from .._example_usdrt_bindings import *
# Global public interface object.
_example_usdrt_interface = None
# Public API.
def get_example_usdrt_interface() -> IExampleUsdrtInterface:
return _example_usdrt_interface
def get_selected_prim_path():
"""Return the path of the first selected prim"""
context = omni.usd.get_context()
selection = context.get_selection()
paths = selection.get_selected_prim_paths()
return None if not paths else paths[0]
def get_stage_id():
"""Return the stage Id of the current stage"""
context = omni.usd.get_context()
return context.get_stage_id()
# Any class derived from `omni.ext.IExt` in top level module (defined in `python.modules` of `extension.toml`) will be
# instantiated when extension gets enabled and `on_startup(ext_id)` will be called. Later when extension gets disabled
# on_shutdown() is called.
class ExampleUsdrtExtension(omni.ext.IExt):
# ext_id is current extension id. It can be used with extension manager to query additional information, like where
# this extension is located on filesystem.
def on_startup(self, ext_id):
# Acquire the example USDRT interface.
global _example_usdrt_interface
_example_usdrt_interface = acquire_example_usdrt_interface()
print("[omni.example.cpp.usdrt] startup")
self._window = ui.Window(
"What's in Fabric?", width=300, height=300, dockPreference=ui.DockPreference.RIGHT_BOTTOM
)
self._t = 0
with self._window.frame:
with ui.VStack():
frame = ui.ScrollingFrame()
with frame:
label = ui.Label("Select a prim and push a button", alignment=ui.Alignment.LEFT_TOP)
def get_fabric_data():
selected_prim_path = get_selected_prim_path()
(err, data) = _example_usdrt_interface.get_attributes_for_prim(
get_stage_id(), selected_prim_path
)
if err:
label.text = err
else:
result = f"Fabric data for prim at path {selected_prim_path}\n\n\n"
for attr in data:
try:
data = attr.Get()
datastr = str(data)
if data is None:
datastr = "<no value>"
except TypeError:
# Some data types not yet supported in Python
datastr = "<no Python conversion>"
result += "{} ({}): {}\n".format(
attr.GetName(), str(attr.GetTypeName().GetAsToken()), datastr
)
label.text = result
def rotate_prim():
selected_prim_path = get_selected_prim_path()
(err, rotation) = _example_usdrt_interface.apply_random_rotation(
get_stage_id(), selected_prim_path
)
label.text = err if err else f"Set new world orientation on {selected_prim_path} to {rotation}"
def deform_prim():
label.text = _example_usdrt_interface.deform_mesh(
get_stage_id(), get_selected_prim_path(), self._t
)
self._t += 1
ui.Button("What's in Fabric?", clicked_fn=get_fabric_data, height=0)
ui.Button("Rotate it in Fabric!", clicked_fn=rotate_prim, height=0)
ui.Button("Deform it!", clicked_fn=deform_prim, height=0)
def on_shutdown(self):
global _example_usdrt_interface
# Release the example USDRT interface.
release_example_usdrt_interface(_example_usdrt_interface)
_example_usdrt_interface = None
print("[omni.example.cpp.usdrt] shutdown")
| 4,631 | Python | 39.631579 | 119 | 0.57547 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.usdrt/bindings/python/omni.example.cpp.usdrt/__init__.py | ## Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
# Necessary so we can link to the Python source instead of copying it.
__all__ = ["IExampleUsdrtInterface", "acquire_example_usdrt_interface", "release_example_usdrt_interface"]
from .impl import *
| 635 | Python | 47.923073 | 106 | 0.781102 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.usdrt/bindings/python/omni.example.cpp.usdrt/ExampleUsdrtBindings.cpp | // Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#include <carb/BindingsPythonUtils.h>
#include <omni/example/cpp/usdrt/IExampleUsdrtInterface.h>
#include <usdrt/scenegraph/base/gf/quatf.h>
#include <usdrt/scenegraph/usd/sdf/path.h>
#include <usdrt/scenegraph/usd/usd/attribute.h>
CARB_BINDINGS("omni.example.cpp.usdrt.python")
DISABLE_PYBIND11_DYNAMIC_CAST(
omni::example::cpp::usdruntime::IExampleUsdrtInterface)
namespace {
// Define the pybind11 module using the same name specified in premake5.lua
PYBIND11_MODULE(_example_usdrt_bindings, m) {
using namespace omni::example::cpp::usdruntime;
m.doc() = "pybind11 omni.example.cpp.usdrt bindings";
carb::defineInterfaceClass<IExampleUsdrtInterface>(
m, "IExampleUsdrtInterface", "acquire_example_usdrt_interface",
"release_example_usdrt_interface")
.def("get_attributes_for_prim",
[](IExampleUsdrtInterface &self, long int id,
usdrt::SdfPath* path) {
std::vector<usdrt::UsdAttribute> data;
std::string err = self.get_attributes_for_prim(id, path, &data);
return std::make_tuple(err, data);
},
py::arg("stageId"), py::arg("primPath"))
.def("apply_random_rotation",
[](IExampleUsdrtInterface &self,long int id,
usdrt::SdfPath* path) {
usdrt::GfQuatf rot;
std::string err = self.apply_random_rotation(id, path, &rot);
return std::make_tuple(err, rot);
},
py::arg("stageId"), py::arg("primPath"))
.def("deform_mesh",
&IExampleUsdrtInterface::deform_mesh, py::arg("stageId"),
py::arg("primPath"), py::arg("time"));
}
} // namespace
| 2,108 | C++ | 37.345454 | 77 | 0.671727 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.usdrt/include/omni/example/cpp/usdrt/IExampleUsdrtInterface.h | // Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#pragma once
#include <carb/Interface.h>
#include <usdrt/scenegraph/usd/usd/attribute.h>
#include <usdrt/scenegraph/usd/sdf/path.h>
#include <usdrt/scenegraph/base/gf/quatf.h>
namespace omni
{
namespace example
{
namespace cpp
{
namespace usdruntime
{
/**
* Interface used to interact with the example C++ USDRT plugin from Python.
*/
class IExampleUsdrtInterface
{
public:
/// @private
CARB_PLUGIN_INTERFACE("omni::example::cpp::usdruntime::IExampleUsdrtInterface", 1, 0);
/*
Get the Fabric data for a path.
*/
virtual std::string get_attributes_for_prim(long int stageId, usdrt::SdfPath* path, std::vector<usdrt::UsdAttribute>* data) = 0;
/*
Apply a random world space rotation to a prim in Fabric.
*/
virtual std::string apply_random_rotation(long int stageId, usdrt::SdfPath* path, usdrt::GfQuatf* rot) = 0;
/*
Deform a Mesh prim
*/
virtual std::string deform_mesh(long int stageId, usdrt::SdfPath* path, int time) = 0;
};
}
}
}
}
| 1,445 | C | 25.290909 | 132 | 0.715571 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.usdrt/config/extension.toml | [package]
version = "1.0.1" # Semantic Versioning is used: https://semver.org/
# These fields are used primarily for display in the extension browser UI.
title = "Example C++ Extension: USDRT"
description = "Demonstrates how to create a C++ plugin that can interact with the current USDRT stage."
category = "Example"
keywords = ["example", "C++", "cpp", "fabric", "usdrt", "runtime"]
icon = "data/icon.png"
preview_image = "data/preview.png"
changelog = "docs/CHANGELOG.md"
readme = "docs/README.md"
authors = ["Jessica Jamieson <[email protected]>"]
repository = "https://github.com/NVIDIA-Omniverse/kit-extension-template-cpp"
[dependencies]
"omni.kit.uiapp" = {}
"usdrt.scenegraph" = {}
"omni.kit.primitive.mesh" = {}
# Define the Python modules that this extension provides.
# C++ only extensions need this just so tests don't fail.
[[python.module]]
name = "omni.example.cpp.usdrt"
[[test]]
waiver = "Just example code, not for production"
# Define the C++ plugins that this extension provides.
[[native.plugin]]
path = "bin/*.plugin"
# Define the documentation that will be generated for this extension.
[documentation]
pages = [
"docs/Overview.md",
"docs/CHANGELOG.md",
]
cpp_api = [
"include/omni/example/cpp/usdrt/IExampleUsdrtInterface.h",
]
| 1,276 | TOML | 29.404761 | 103 | 0.713166 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.usdrt/plugins/omni.example.cpp.usdrt/ExampleUsdrtExtension.cpp | // Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#define CARB_EXPORTS
#include <carb/PluginUtils.h>
#include <omni/example/cpp/usdrt/IExampleUsdrtInterface.h>
#include <omni/ext/ExtensionsUtils.h>
#include <omni/ext/IExt.h>
#include <omni/kit/IApp.h>
#include <usdrt/scenegraph/usd/usd/stage.h>
#include <usdrt/scenegraph/usd/usd/prim.h>
#include <usdrt/scenegraph/usd/rt/xformable.h>
#include <usdrt/scenegraph/usd/sdf/path.h>
#include <usdrt/scenegraph/base/gf/vec3f.h>
#include <usdrt/scenegraph/base/gf/quatf.h>
#include <usdrt/scenegraph/base/vt/array.h>
#include <usdrt/scenegraph/usd/usd/attribute.h>
#include <omni/fabric/IFabric.h>
#include <vector>
#include <random>
const struct carb::PluginImplDesc pluginImplDesc = { "omni.example.cpp.usdrt.plugin",
"An example C++ USDRT extension.", "NVIDIA",
carb::PluginHotReload::eEnabled, "dev" };
namespace omni
{
namespace example
{
namespace cpp
{
namespace usdruntime
{
class ExampleCppUsdrtExtension : public IExampleUsdrtInterface
{
protected:
/*
Get the Fabric data for a path.
*/
std::string get_attributes_for_prim(long int stageId, usdrt::SdfPath* path, std::vector<usdrt::UsdAttribute>* data) override;
/*
Apply a random world space rotation to a prim in Fabric.
*/
std::string apply_random_rotation(long int stageId, usdrt::SdfPath* path, usdrt::GfQuatf* rot) override;
/*
Deform a Mesh prim
*/
std::string deform_mesh(long int stageId, usdrt::SdfPath* path, int time) override;
private:
};
inline std::string ExampleCppUsdrtExtension::get_attributes_for_prim(long int stageId, usdrt::SdfPath* path, std::vector<usdrt::UsdAttribute>* data)
{
if (!path || path->IsEmpty()) {
return "Nothing selected";
}
if (data == nullptr) {
return "Invalid data";
}
usdrt::UsdStageRefPtr stage = usdrt::UsdStage::Attach(omni::fabric::UsdStageId(stageId));
// If a prim does not already exist in Fabric,
// it will be fetched from USD by simply creating the
// Usd.Prim object. At this time, only the attributes that have
// authored opinions will be fetch into Fabric.
usdrt::UsdPrim prim = stage->GetPrimAtPath(*path);
if (!prim) {
return "Prim at path " + path->GetString() + " is not in Fabric";
}
// This diverges a bit from USD - only attributes
// that exist in Fabric are returned by this API
std::vector<usdrt::UsdAttribute> attrs = prim.GetAttributes();
*data = attrs;
return "";
}
inline std::string ExampleCppUsdrtExtension::apply_random_rotation(long int stageId, usdrt::SdfPath* path, usdrt::GfQuatf* rot) {
//Apply a random world space rotation to a prim in Fabric
if (!path || path->IsEmpty()) {
return "Nothing selected";
}
if (rot == nullptr) {
return "Invalid data";
}
usdrt::UsdStageRefPtr stage = usdrt::UsdStage::Attach(omni::fabric::UsdStageId(stageId));
usdrt::UsdPrim prim = stage->GetPrimAtPath(*path);
if (!prim) {
return "Prim at path " + path->GetString() + " is not in Fabric";
}
usdrt::RtXformable rtxformable = usdrt::RtXformable(prim);
if (!rtxformable.HasWorldXform()) {
rtxformable.SetWorldXformFromUsd();
}
std::random_device rd; // Will be used to obtain a seed for the random number engine
std::mt19937 gen(rd()); // Standard mersenne_twister_engine seeded with rd()
std::uniform_real_distribution<float> dist(0.0f, 1.0f);
float angle = dist(gen) * M_PI * 2;
usdrt::GfVec3f axis = usdrt::GfVec3f(dist(gen), dist(gen), dist(gen)).GetNormalized();
float halfangle = angle / 2.0;
float shalfangle = sin(halfangle);
usdrt::GfQuatf rotation = usdrt::GfQuatf(cos(halfangle), axis[0] * shalfangle, axis[1] * shalfangle, axis[2] * shalfangle);
rtxformable.GetWorldOrientationAttr().Set(rotation);
*rot = rotation;
return "";
}
inline std::string ExampleCppUsdrtExtension::deform_mesh(long int stageId, usdrt::SdfPath* path, int time) {
// Deform a Mesh prim
if (!path || path->IsEmpty()) {
return "Nothing selected";
}
usdrt::UsdStageRefPtr stage = usdrt::UsdStage::Attach(omni::fabric::UsdStageId(stageId));
usdrt::UsdPrim prim = stage->GetPrimAtPath(*path);
if (!prim) {
return "Prim at path " + path->GetString() + " is not in Fabric";
}
if (!prim.HasAttribute("points")) {
return "Prim at path " + path->GetString() + " does not have points attribute";
}
// Tell OmniHydra to render points from Fabric
if (!prim.HasAttribute("Deformable")) {
prim.CreateAttribute("Deformable", usdrt::SdfValueTypeNames->PrimTypeTag, true);
}
usdrt::UsdAttribute points = prim.GetAttribute("points");
usdrt::VtArray<usdrt::GfVec3f> pointsarray;
points.Get(&pointsarray);
// Deform points
// In the python example, this uses warp to run the deformation on GPU
// The more correct C++ equivalent would be to write a CUDA kernel for this
// but for simplicity of this example, do the deformation here on CPU.
for (usdrt::GfVec3f& point : pointsarray) {
float offset = -sin(point[0]);
float scale = sin(time) * 10.0;
point = point + usdrt::GfVec3f(0.0, offset * scale, 0.0);
}
points.Set(pointsarray);
return "Deformed points on prim " + path->GetString();
}
}
}
}
}
CARB_PLUGIN_IMPL(pluginImplDesc, omni::example::cpp::usdruntime::ExampleCppUsdrtExtension)
void fillInterface(omni::example::cpp::usdruntime::ExampleCppUsdrtExtension& iface)
{
}
| 6,075 | C++ | 31.666666 | 148 | 0.670123 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.usdrt/docs/CHANGELOG.md | # Changelog
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [1.0.1] - 2023-11-13
- Updated USDRT example
## [1.0.0] - 2023-10-17
- Initial version
| 186 | Markdown | 17.699998 | 80 | 0.66129 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.usdrt/docs/Overview.md | # Overview
# What's in Fabric? USDRT Scenegraph API example [omni.example.cpp.usdrt]
This is an example Kit extension using the USDRT Scenegraph API. This C++
extension demonstrates the following:
- Inspecting Fabric data using the USDRT Scenegraph API
- Manipulating prim transforms in Fabric using the RtXformable schema
- Deforming Mesh geometry | 351 | Markdown | 34.199997 | 73 | 0.803419 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.python.ui/config/extension.toml | [package]
version = "1.0.0" # Semantic Versioning is used: https://semver.org/
# These fields are used primarily for display in the extension browser UI.
title = "Example Python Extension: UI"
description = "Demonstrates how to create simple UI elements (eg. buttons and labels) from Python."
category = "Example"
keywords = ["example"]
icon = "data/icon.png"
preview_image = "data/preview.png"
changelog = "docs/CHANGELOG.md"
readme = "docs/README.md"
authors = ["Anton Novoselov <[email protected]>", "David Bosnich <[email protected]>"]
repository = "https://github.com/NVIDIA-Omniverse/kit-extension-template-cpp"
# List all dependencies of this extension.
[dependencies]
"omni.kit.uiapp" = {}
"omni.example.cpp.ui_widget" = {} # To demonstrate using widgets defined in C++
# Define the Python modules that this extension provides.
[[python.module]]
name = "omni.example.python.ui"
# Define any test specific properties of this extension.
[[test]]
dependencies = [
"omni.kit.ui_test"
]
# Define the documentation that will be generated for this extension.
[documentation]
pages = [
"docs/Overview.md",
"docs/CHANGELOG.md",
]
| 1,153 | TOML | 30.189188 | 99 | 0.730269 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.python.ui/omni/example/python/ui/example_python_ui_extension.py | ## Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
import omni.ext
import omni.ui as ui
from omni.example.cpp.ui_widget import CppWidget
class ExamplePythonUIExtension(omni.ext.IExt):
def on_startup(self, ext_id):
print(f"ExamplePythonUIExtension starting up (ext_id: {ext_id}).")
self._count = 0
self._window = ui.Window("Example Window", width=300, height=300)
with self._window.frame:
with ui.VStack():
label = ui.Label("")
def on_click():
self._count += 1
label.text = f"count: {self._count}"
def on_reset():
self._count = 0
label.text = "empty"
on_reset()
with ui.HStack():
ui.Button("Add", clicked_fn=on_click)
ui.Button("Reset", clicked_fn=on_reset)
# Use a widget that was defined in C++
STYLE = {"CppWidget": {"color": ui.color.red}}
CppWidget(thickness=2, style=STYLE)
def on_shutdown(self):
print(f"ExamplePythonUIExtension shutting down.")
self._count = 0
| 1,579 | Python | 33.347825 | 77 | 0.592147 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.python.ui/omni/example/python/ui/__init__.py | ## Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
__all__ = ["ExamplePythonUIExtension", "CppWidget"]
from .example_python_ui_extension import *
| 531 | Python | 47.363632 | 77 | 0.783427 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.python.ui/omni/example/python/ui/tests/test_example_python_ui.py | ## Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
# omni.kit.test is primarily Python's standard unittest module
# with additional wrapping to add suport for async/await tests.
# Please see: https://docs.python.org/3/library/unittest.html
import omni.kit.test
# omni.kit.ui_test is for simulating UI interactions in tests.
import omni.kit.ui_test as ui_test
# The Python module we are testing, imported with an absolute
# path to simulate using it from a different Python extension.
import omni.example.python.ui
# Any class that dervives from 'omni.kit.test.AsyncTestCase'
# declared at the root of the module will be auto-discovered,
class Test(omni.kit.test.AsyncTestCase):
# Called before running each test.
async def setUp(self):
pass
# Called after running each test.
async def tearDown(self):
pass
# Example test case that simulates UI interactions.
async def test_window_button(self):
# Find a label in the window.
label = ui_test.find("Example Window//Frame/**/Label[*]")
# Find buttons in the window.
add_button = ui_test.find("Example Window//Frame/**/Button[*].text=='Add'")
reset_button = ui_test.find("Example Window//Frame/**/Button[*].text=='Reset'")
# Click the add button.
await add_button.click()
self.assertEqual(label.widget.text, "count: 1")
# Click the add button.
await add_button.click()
self.assertEqual(label.widget.text, "count: 2")
# Click the reset button.
await reset_button.click()
self.assertEqual(label.widget.text, "empty")
| 2,009 | Python | 35.545454 | 87 | 0.703335 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.python.ui/omni/example/python/ui/tests/__init__.py | ## Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
from .test_example_python_ui import *
| 474 | Python | 46.499995 | 77 | 0.791139 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.python.ui/docs/CHANGELOG.md | # Changelog
## [1.0.0] - 2022-07-01
### Added
- Initial implementation.
| 73 | Markdown | 11.333331 | 25 | 0.630137 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.python.ui/docs/Overview.md | # Overview
An example Python extension that can be used as a template for creating new extensions.
Demonstrates how to create simple UI elements (eg. buttons and labels) from Python, and also how to use UI widgets that were created in C++.
| 243 | Markdown | 33.857138 | 140 | 0.777778 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.actions/config/extension.toml | [package]
version = "1.0.1" # Semantic Versioning is used: https://semver.org/
# These fields are used primarily for display in the extension browser UI.
title = "Example C++ Extension: actions"
description = "Demonstrates how to create actions in C++ that can then be executed from either C++ or Python."
category = "Example"
keywords = ["example", "C++", "cpp", "actions"]
icon = "data/icon.png"
preview_image = "data/preview.png"
changelog = "docs/CHANGELOG.md"
readme = "docs/README.md"
authors = ["David Bosnich <[email protected]>"]
repository = "https://github.com/NVIDIA-Omniverse/kit-extension-template-cpp"
[dependencies]
"omni.kit.actions.core" = {}
# Define the Python modules that this extension provides.
[[python.module]]
name = "omni.example.cpp.actions"
# Define the C++ plugins that this extension provides.
[[native.plugin]]
path = "bin/*.plugin"
# Define any test specific properties of this extension.
[[test]]
cppTests.libraries = [
"bin/${lib_prefix}omni.example.cpp.actions.tests${lib_ext}"
]
# Define the documentation that will be generated for this extension.
[documentation]
pages = [
"docs/Overview.md",
"docs/CHANGELOG.md",
]
| 1,177 | TOML | 29.205127 | 110 | 0.718777 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.actions/plugins/omni.example.cpp.actions.tests/ExampleActionsTests.cpp | // Copyright (c) 2020-2021, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#include <omni/kit/actions/core/IActionRegistry.h>
#include <doctest/doctest.h>
#include <carb/BindingsUtils.h>
CARB_BINDINGS("omni.example.cpp.actions.tests")
TEST_SUITE("omni.example.cpp.actions.tests")
{
using namespace omni::kit::actions::core;
TEST_CASE("Execute Example C++ Action")
{
auto actionRegistry = carb::getCachedInterface<IActionRegistry>();
REQUIRE(actionRegistry != nullptr);
carb::ObjectPtr<IAction> action;
SUBCASE("Custom")
{
action = actionRegistry->getAction("omni.example.cpp.actions", "example_custom_action_id");
REQUIRE(action.get() != nullptr);
auto result = action->execute();
CHECK(result.hasValue());
CHECK(result.getValue<uint32_t>() == 1);
result = action->execute();
CHECK(result.hasValue());
CHECK(result.getValue<uint32_t>() == 2);
}
SUBCASE("Lambda")
{
action = actionRegistry->getAction("omni.example.cpp.actions", "example_lambda_action_id");
REQUIRE(action.get() != nullptr);
auto result = action->execute();
CHECK(!result.hasValue());
}
}
}
| 1,665 | C++ | 31.038461 | 103 | 0.643243 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.actions/plugins/omni.example.cpp.actions/ExampleActionsExtension.cpp | // Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#define CARB_EXPORTS
#include <carb/PluginUtils.h>
#include <omni/ext/IExt.h>
#include <omni/kit/actions/core/IActionRegistry.h>
#include <omni/kit/actions/core/LambdaAction.h>
const struct carb::PluginImplDesc pluginImplDesc = { "omni.example.cpp.actions.plugin",
"An example C++ extension.", "NVIDIA",
carb::PluginHotReload::eEnabled, "dev" };
namespace omni
{
namespace example
{
namespace cpp
{
namespace actions
{
using namespace omni::kit::actions::core;
class ExampleCustomAction : public Action
{
public:
static carb::ObjectPtr<IAction> create(const char* extensionId,
const char* actionId,
const MetaData* metaData)
{
// Note: It is important to construct the handler using ObjectPtr<T>::InitPolicy::eSteal,
// otherwise we end up incresing the reference count by one too many during construction,
// resulting in a carb::ObjectPtr<IAction> whose object instance will never be destroyed.
return carb::stealObject<IAction>(new ExampleCustomAction(extensionId, actionId, metaData));
}
ExampleCustomAction(const char* extensionId, const char* actionId, const MetaData* metaData)
: Action(extensionId, actionId, metaData), m_executionCount(0)
{
}
carb::variant::Variant execute(const carb::variant::Variant& args = {},
const carb::dictionary::Item* kwargs = nullptr) override
{
++m_executionCount;
printf("Executing %s (execution count = %d).\n", getActionId(), m_executionCount);
return carb::variant::Variant(m_executionCount);
}
void invalidate() override
{
resetExecutionCount();
}
uint32_t getExecutionCount() const
{
return m_executionCount;
}
protected:
void resetExecutionCount()
{
m_executionCount = 0;
}
private:
uint32_t m_executionCount = 0;
};
class ExampleActionsExtension : public omni::ext::IExt
{
public:
void onStartup(const char* extId) override
{
auto actionRegistry = carb::getCachedInterface<IActionRegistry>();
if (!actionRegistry)
{
CARB_LOG_WARN("Could not get cached IActionRegistry interface.");
return;
}
// Example of registering a custom action from C++.
Action::MetaData metaData;
metaData.displayName = "Example Custom Action Display Name";
metaData.description = "Example Custom Action Description.";
m_exampleCustomAction = ExampleCustomAction::create("omni.example.cpp.actions", "example_custom_action_id", &metaData);
actionRegistry->registerAction(m_exampleCustomAction);
// Example of registering a lambda action from C++.
m_exampleLambdaAction = actionRegistry->registerAction(
"omni.example.cpp.actions", "example_lambda_action_id",
[](const carb::variant::Variant& args = {}, const carb::dictionary::Item* kwargs = nullptr) {
printf("Executing example_lambda_action_id.\n");
return carb::variant::Variant();
},
"Example Lambda Action Display Name",
"Example Lambda Action Description.");
}
void onShutdown() override
{
if (auto actionRegistry = carb::getCachedInterface<IActionRegistry>())
{
actionRegistry->deregisterAction(m_exampleLambdaAction);
m_exampleLambdaAction = nullptr;
actionRegistry->deregisterAction(m_exampleCustomAction);
m_exampleCustomAction = nullptr;
}
else
{
CARB_LOG_WARN("Could not get cached IActionRegistry interface.");
}
}
private:
carb::ObjectPtr<IAction> m_exampleCustomAction;
carb::ObjectPtr<IAction> m_exampleLambdaAction;
};
}
}
}
}
CARB_PLUGIN_IMPL(pluginImplDesc, omni::example::cpp::actions::ExampleActionsExtension)
void fillInterface(omni::example::cpp::actions::ExampleActionsExtension& iface)
{
}
| 4,585 | C++ | 31.524822 | 127 | 0.646456 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.actions/omni/example/cpp/actions/tests/test_actions_example.py | ## Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
import omni.kit.test
import omni.kit.actions.core
class TestActionsExample(omni.kit.test.AsyncTestCase):
async def setUp(self):
self.action_registry = omni.kit.actions.core.get_action_registry()
self.extension_id = "omni.example.cpp.actions"
async def tearDown(self):
self.extension_id = None
self.action_registry = None
async def test_find_and_execute_custom_action(self):
action = self.action_registry.get_action(self.extension_id, "example_custom_action_id")
self.assertIsNotNone(action)
result = action.execute()
self.assertEqual(result, 3) # 3 because this was already executed twice in the C++ tests
result = action.execute()
self.assertEqual(result, 4)
async def test_find_and_execute_lambda_action(self):
action = self.action_registry.get_action(self.extension_id, "example_lambda_action_id")
self.assertIsNotNone(action)
result = action.execute()
self.assertIsNone(result)
| 1,455 | Python | 36.333332 | 96 | 0.716151 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.actions/omni/example/cpp/actions/tests/__init__.py | ## Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto. Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
from .test_actions_example import *
| 472 | Python | 46.299995 | 77 | 0.792373 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.actions/docs/CHANGELOG.md | # Changelog
## [1.0.1] - 2023-04-27
### Updated
- Build against Kit 105.0
## [1.0.0] - 2022-11-04
### Added
- Initial implementation.
| 136 | Markdown | 12.699999 | 25 | 0.610294 |
NVIDIA-Omniverse/kit-extension-template-cpp/source/extensions/omni.example.cpp.actions/docs/Overview.md | # Overview
An example C++ extension that can be used as a reference/template for creating new extensions.
Demonstrates how to create actions in C++ that can then be executed from either C++ or Python.
See the omni.kit.actions.core extension for extensive documentation about actions themselves.
# C++ Usage Examples
## Defining Custom Actions
```
using namespace omni::kit::actions::core;
class ExampleCustomAction : public Action
{
public:
static carb::ObjectPtr<IAction> create(const char* extensionId,
const char* actionId,
const MetaData* metaData)
{
return carb::stealObject<IAction>(new ExampleCustomAction(extensionId, actionId, metaData));
}
ExampleCustomAction(const char* extensionId, const char* actionId, const MetaData* metaData)
: Action(extensionId, actionId, metaData), m_executionCount(0)
{
}
carb::variant::Variant execute(const carb::variant::Variant& args = {},
const carb::dictionary::Item* kwargs = nullptr) override
{
++m_executionCount;
printf("Executing %s (execution count = %d).\n", getActionId(), m_executionCount);
return carb::variant::Variant(m_executionCount);
}
void invalidate() override
{
resetExecutionCount();
}
uint32_t getExecutionCount() const
{
return m_executionCount;
}
protected:
void resetExecutionCount()
{
m_executionCount = 0;
}
private:
uint32_t m_executionCount = 0;
};
```
## Creating and Registering Custom Actions
```
// Example of creating and registering a custom action from C++.
Action::MetaData metaData;
metaData.displayName = "Example Custom Action Display Name";
metaData.description = "Example Custom Action Description.";
carb::ObjectPtr<IAction> exampleCustomAction =
ExampleCustomAction::create("omni.example.cpp.actions", "example_custom_action_id", &metaData);
carb::getCachedInterface<omni::kit::actions::core::IActionRegistry>()->registerAction(exampleCustomAction);
```
## Creating and Registering Lambda Actions
```
auto actionRegistry = carb::getCachedInterface<omni::kit::actions::core::IActionRegistry>();
// Example of creating and registering a lambda action from C++.
omni::kit::actions::core::IAction::MetaData metaData;
metaData.displayName = "Example Lambda Action Display Name";
metaData.description = "Example Lambda Action Description.";
carb::ObjectPtr<IAction> exampleLambdaAction =
omni::kit::actions::core::LambdaAction::create(
"omni.example.cpp.actions", "example_lambda_action_id", &metaData,
[this](const carb::variant::Variant& args = {}, const carb::dictionary::Item* kwargs = nullptr) {
printf("Executing example_lambda_action_id.\n");
return carb::variant::Variant();
}));
carb::getCachedInterface<omni::kit::actions::core::IActionRegistry>()->registerAction(exampleLambdaAction);
```
```
// Example of creating and registering (at the same time) a lambda action from C++.
carb::getCachedInterface<omni::kit::actions::core::IActionRegistry>()->registerAction(
"omni.example.cpp.actions", "example_lambda_action_id",
[](const carb::variant::Variant& args = {}, const carb::dictionary::Item* kwargs = nullptr) {
printf("Executing example_lambda_action_id.\n");
return carb::variant::Variant();
},
"Example Lambda Action Display Name",
"Example Lambda Action Description.");
```
## Discovering Actions
```
auto registry = carb::getCachedInterface<omni::kit::actions::core::IActionRegistry>();
// Retrieve an action that has been registered using the registering extension id and the action id.
carb::ObjectPtr<IAction> action = registry->getAction("omni.example.cpp.actions", "example_custom_action_id");
// Retrieve all actions that have been registered by a specific extension id.
std::vector<carb::ObjectPtr<IAction>> actions = registry->getAllActionsForExtension("example");
// Retrieve all actions that have been registered by any extension.
std::vector<carb::ObjectPtr<IAction>> actions = registry->getAllActions();
```
## Deregistering Actions
```
auto actionRegistry = carb::getCachedInterface<omni::kit::actions::core::IActionRegistry>();
// Deregister an action directly...
actionRegistry->deregisterAction(exampleCustomAction);
// or using the registering extension id and the action id...
actionRegistry->deregisterAction("omni.example.cpp.actions", "example_custom_action_id");
// or deregister all actions that were registered by an extension.
actionRegistry->deregisterAllActionsForExtension("omni.example.cpp.actions");
```
## Executing Actions
```
auto actionRegistry = carb::getCachedInterface<omni::kit::actions::core::IActionRegistry>();
// Execute an action after retrieving it from the action registry.
auto action = actionRegistry->getAction("omni.example.cpp.actions", "example_custom_action_id");
action->execute();
// Execute an action indirectly (retrieves it internally).
actionRegistry->executeAction("omni.example.cpp.actions", "example_custom_action_id");
// Execute an action that was stored previously.
exampleCustomAction->execute();
```
Note: All of the above will find any actions that have been registered from either Python or C++,
and you can interact with them without needing to know anything about where they were registered.
| 5,460 | Markdown | 32.503067 | 110 | 0.712088 |
NVIDIA-Omniverse/kit-extension-sample-ui-scene/README.md | # omni.ui.scene Kit Extension Samples
## [Object Info (omni.example.ui_scene.object_info)](exts/omni.example.ui_scene.object_info)
[](exts/omni.example.ui_scene.object_info)
### About
This extension uses the omni.ui.scene API to add simple graphics and labels in the viewport above your selected prim. The labels provide the prim path of the selected prim and the prim path of its assigned material.
### [README](exts/omni.example.ui_scene.object_info)
See the [README for this extension](exts/omni.example.ui_scene.object_info) to learn more about it including how to use it.
### [Tutorial](exts/omni.example.ui_scene.object_info/Tutorial/object_info.tutorial.md)
Follow a [step-by-step tutorial](exts/omni.example.ui_scene.object_info/Tutorial/object_info.tutorial.md) that walks you through how to use omni.ui.scene to build this extension.
## [Widget Info (omni.example.ui_scene.widget_info)](exts/omni.example.ui_scene.object_info)
[](exts/omni.example.ui_scene.widget_info)
### About
This extension uses the omni.ui.scene API to add a widget in the viewport, just above your selected prim. The widget provides the prim path of your selection and a scale slider.
### [README](exts/omni.example.ui_scene.widget_info)
See the [README for this extension](exts/omni.example.ui_scene.widget_info) to learn more about it including how to use it.
### [Tutorial](exts/omni.example.ui_scene.widget_info/Tutorial/object.info.widget.tutorial.md)
Follow a [step-by-step tutorial](exts/omni.example.ui_scene.widget_info/Tutorial/object.info.widget.tutorial.md) that walks you through how to use omni.ui.scene to build this extension.
## [Light Manipulator (omni.example.ui_scene.light_manipulator)](exts/omni.example.ui_scene.light_manipulator)
[](exts/omni.example.ui_scene.light_manipulator)
### About
This extension add a custom manipulator for RectLights that allows you to control the width, height, and intensity of RectLights by clicking and dragging in the viewport.
### [README](exts/omni.example.ui_scene.light_manipulator)
See the [README for this extension](exts/omni.example.ui_scene.light_manipulator) to learn more about it including how to use it.
### [Tutorial](exts/omni.example.ui_scene.light_manipulator/tutorial/tutorial.md)
Follow a [step-by-step tutorial](exts/omni.example.ui_scene.light_manipulator/tutorial/tutorial.md) that walks you through how to use omni.ui.scene to build this extension.
## [Slider Manipulator (omni.example.ui_scene.slider_manipulator)](exts/omni.example.ui_scene.slider_manipulator)
[](exts/omni.example.ui_scene.slider_manipulator)
### About
This extension add a custom slider manipulator above you selected prim that controls the scale of the prim when you click and drag the slider.
### [README](exts/omni.example.ui_scene.slider_manipulator)
See the [README for this extension](exts/omni.example.ui_scene.slider_manipulator) to learn more about it including how to use it.
### [Tutorial](exts/omni.example.ui_scene.slider_manipulator/Tutorial/slider_Manipulator_Tutorial.md)
Follow a [step-by-step tutorial](exts/omni.example.ui_scene.slider_manipulator/Tutorial/slider_Manipulator_Tutorial.md) that walks you through how to use omni.ui.scene to build this extension.
# Adding These Extensions
To add these extensions to your Omniverse app:
1. Go into: Extension Manager -> Gear Icon -> Extension Search Path
2. Add this as a search path: `git://github.com/NVIDIA-Omniverse/kit-extension-sample-ui-scene?branch=main&dir=exts`
## Linking with an Omniverse app
For a better developer experience, it is recommended to create a folder link named `app` to the *Omniverse Kit* app installed from *Omniverse Launcher*. A convenience script to use is included.
Run:
```bash
> link_app.bat
```
There is also an analogous `link_app.sh` for Linux. If successful you should see `app` folder link in the root of this repo.
If multiple Omniverse apps is installed script will select recommended one. Or you can explicitly pass an app:
```bash
> link_app.bat --app code
```
You can also just pass a path to create link to:
```bash
> link_app.bat --path "C:/Users/bob/AppData/Local/ov/pkg/create-2022.1.3"
```
Running this command adds a symlink to Omniverse Code. This makes intellisense work and lets you easily run the app from the terminal.
## Contributing
The source code for this repository is provided as-is and we are not accepting outside contributions.
| 4,736 | Markdown | 52.224719 | 215 | 0.776394 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.