Hello World – Populate ovstage and Step#
This tutorial shows the smallest end-to-end ovphysx workflow: create an instance, populate an ovstage Stage from USD, attach it, step simulation, and clean up resources. You can use this flow as the starting point for larger integrations.
Prerequisites#
A USD stage to populate. This tutorial uses stages that ship with every package:
links_chain_sample.usdafor Python andsimple_physics_scene.usdafor C. They are underovphysx/samples/data/in the wheel,<sdk-root>/samples/data/in the C/C++ SDK, andtests/data/in a repository checkout. No hand-authoring is needed.GPU simulation (optional): prebuilt packages require a CUDA-capable NVIDIA driver compatible with CUDA 12.8, but no CUDA Toolkit installation. Refer to the Quickstart prerequisites for the versioned corresponding-driver table and source-build requirements.
Code Language#
Python#
Install ovphysx and the schema packages used by this sample:
pip install ovphysx physx-usd-schemas newton-usd-schemas
This complete sample creates a PhysX instance, populates an ovstage Stage
from links_chain_sample.usda, runs one synchronous step, and releases the
stage and the instance in lifetime-safe order:
# @implements REQ-CAPI-OVSTAGE-XFORM-001
# @covers AC-1
import ovphysx
from ovphysx.samples.python_samples.schema_support import physx_schema_paths
from ovphysx import PhysX
from pathlib import Path
print("Using ovphysx version: ", ovphysx.__version__)
_physx_schemas_registered = False
def attach_scene(physx, usd_path):
import ovstage
from ovphysx.population import physics_population_descs
if not ovstage.population.available():
raise RuntimeError("ovstage population bridge is unavailable")
# Register external PhysX and Newton schemas before the first population.
global _physx_schemas_registered
if not _physx_schemas_registered:
ovstage.population.register_usd_schemas(
[*[str(p) for p in physx_schema_paths()], str(ovphysx.newton_schema_root())]
)
_physx_schemas_registered = True
stage = ovstage.Stage("ovphysx-hello-world")
ordinal = 1
try:
ovstage.population.open_usd_with_desc(stage, str(usd_path), ordinal=ordinal, time=ovstage.population.DEFAULT_TIME, descs=physics_population_descs(rendering=True))
stage.advance_write_floor(ordinal=ordinal).wait()
physx.wait_task(physx.attach_ovstage(stage, read_ordinal=ordinal))
print("Loaded scene through ovstage")
return stage
except Exception:
if physx.is_stage_attached(stage):
physx.wait_task(physx.detach_ovstage())
stage.destroy()
raise
# Prefer package data so a copied sample works. Fall back to the checked-in
# sample's adjacent data directory when package data is absent.
usd_path = Path(ovphysx.__file__).resolve().parent / "samples" / "data" / "links_chain_sample.usda"
if not usd_path.is_file():
usd_path = Path(__file__).resolve().parent.parent / "data" / "links_chain_sample.usda"
if not usd_path.is_file():
raise FileNotFoundError(f"ovphysx sample data is missing: {usd_path}")
# Initialize PhysX
physx = PhysX()
stage = attach_scene(physx, usd_path)
try:
# Run a simulation step
dt = 1.0 / 60.0
physx.step_sync(dt)
print("Simulation step completed successfully")
finally:
if stage is not None:
physx.wait_task(physx.detach_ovstage())
stage.destroy()
physx.destroy()
print("Cleanup complete")
The attach_scene helper registers with ovstage the codeless PhysX USD schemas
from physx-usd-schemas (ovstage.population.register_usd_schemas() with
the external provider resource directories) and the separately installed Newton USD schema
(pip install newton-usd-schemas, located with ovphysx.newton_schema_root())
before it creates and populates the stage; ovphysx never registers them itself,
and registration must precede the first USD schema read in the process,
including population or export. The samples’ pyproject.toml declares both
schema packages, so uv run resolves them.
C#
Download the ovphysx SDK and matching native ovstage archive as described in the SDK Quickstart, and extract them as separate package roots.
CMakeLists.txt
Every C sample uses find_package(ovphysx) and links against ovphysx::ovphysx. Here is the CMakeLists.txt for hello_world_c:
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.16)
project(HelloWorldC C)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
find_package(ovphysx REQUIRED)
add_executable(hello_world_c main.c)
# Force the C language so the sample never compiles as C++.
set_source_files_properties(main.c PROPERTIES LANGUAGE C)
set_target_properties(hello_world_c PROPERTIES
C_STANDARD 11
C_STANDARD_REQUIRED ON
)
# Compiler-specific flags that enforce strict C compilation.
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
# An implicit declaration error catches any C++-only symbol leaking into the C sample.
target_compile_options(hello_world_c PRIVATE
-Werror=implicit-function-declaration
-pedantic
)
endif()
if(MSVC)
# /TC makes MSVC compile every source as C.
target_compile_options(hello_world_c PRIVATE /TC)
endif()
target_link_libraries(hello_world_c PRIVATE ovphysx::ovphysx ovphysx::ovstage)
target_include_directories(hello_world_c PRIVATE "${CMAKE_CURRENT_LIST_DIR}/../common")
get_filename_component(OVPHYSX_TEST_DATA_DIR "${CMAKE_CURRENT_LIST_DIR}/../../data" ABSOLUTE)
target_compile_definitions(hello_world_c PRIVATE
OVPHYSX_TEST_DATA="${OVPHYSX_TEST_DATA_DIR}"
)
if(WIN32)
ovphysx_copy_runtime_dlls(hello_world_c)
# OVStage is not copied (it loads its plugins relative to itself), so its
# directories have to reach the process through PATH.
ovphysx_set_ovstage_runtime_env(hello_world_c)
endif()
Build by pointing CMAKE_PREFIX_PATH at both package roots (refer to
SDK Quickstart for details).
Source
The C sample performs the same sequence against simple_physics_scene.usda:
#include "ovphysx/ovphysx.h"
#include "ovstage_sample.h"
#include <stdio.h>
static int run(void)
{
// Create a PhysX instance.
ovphysx_instance_handle_t handle = 0;
ovphysx_result_t result = ovphysx_create_instance(&handle);
if (result.status != OVPHYSX_API_SUCCESS) {
fprintf(stderr, "Failed to create PhysX instance\n");
ovphysx_shutdown();
return 1;
}
// Populate an ovstage instance from the USD file and attach it to ovphysx.
ovphysx_sample_stage_attachment_t stage_attachment = {0};
if (!ovphysx_sample_attach_usd_with_ovstage(
handle, OVPHYSX_TEST_DATA "/simple_physics_scene.usda", &stage_attachment)) {
fprintf(stderr, "Failed to attach ovstage scene\n");
ovphysx_destroy_instance(handle);
ovphysx_shutdown();
return 1;
}
// Enqueue one simulation step. Stepping is asynchronous.
ovphysx_enqueue_result_t step_result = ovphysx_step(handle, 0.016f);
if (step_result.status != OVPHYSX_API_SUCCESS) {
fprintf(stderr, "Failed to step simulation\n");
ovphysx_sample_destroy_stage(handle, &stage_attachment);
ovphysx_destroy_instance(handle);
ovphysx_shutdown();
return 1;
}
// Wait for the step to complete and check it reported no errors.
ovphysx_wait_task_result_t step_wait_result = {0};
ovphysx_result_t step_wait_status = ovphysx_wait_task(
handle, step_result, OVPHYSX_TIMEOUT_INFINITE, &step_wait_result);
int step_ok = (step_wait_status.status == OVPHYSX_API_SUCCESS && step_wait_result.num_errors == 0);
ovphysx_destroy_wait_task_result(&step_wait_result);
if (!step_ok) {
fprintf(stderr, "Simulation step failed\n");
ovphysx_sample_destroy_stage(handle, &stage_attachment);
ovphysx_destroy_instance(handle);
ovphysx_shutdown();
return 1;
}
printf("Simulation step completed successfully\n");
ovphysx_sample_destroy_stage(handle, &stage_attachment);
ovphysx_destroy_instance(handle);
ovphysx_shutdown();
printf("Cleanup complete\n");
return 0;
}
int main(void) {
ovphysx_result_t init_r = ovphysx_initialize();
if (init_r.status != OVPHYSX_API_SUCCESS) {
fprintf(stderr, "ovphysx_initialize() failed\n");
return 1;
}
int rc = run();
return rc;
}
The ovphysx_sample_attach_usd_with_ovstage() helper from
samples/c_samples/common/ovstage_sample.h registers the codeless PhysX USD
schemas with ovstage first, passing both provider resource directories to
ovstage_population_register_usd_schemas(), and only then creates and
populates the stage.
Result#
After this tutorial, you can step the simulation from both Python and C and release all resources cleanly.