file_path
stringlengths
21
224
content
stringlengths
0
80.8M
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/variant/OgnHasVariantSet.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. // // clang-format off #include "UsdPCH.h" // clang-format on #include "PrimCommon.h" #include <carb/logging/Log.h> #include <omni/usd/UsdContext.h> #include <OgnHasVariantSetDatabase.h> namespace omni::graph::nodes { class OgnHasVariantSet { public: static bool compute(OgnHasVariantSetDatabase& db) { try { pxr::UsdPrim prim = tryGetTargetPrim(db, db.inputs.prim(), "prim"); pxr::UsdVariantSets variantSets = prim.GetVariantSets(); db.outputs.exists() = variantSets.HasVariantSet(db.tokenToString(db.inputs.variantSetName())); return true; } catch (const warning& e) { db.logWarning(e.what()); } catch (const std::exception& e) { db.logError(e.what()); } db.outputs.exists() = false; return false; } }; REGISTER_OGN_NODE() } // namespace omni::graph::nodes
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/variant/OgnBlendVariants.ogn
{ "BlendVariants": { "version": 1, "categories": [ "graph:action", "sceneGraph", "variants" ], "icon": { "path": "Variant.svg" }, "scheduling": [ "usd-read" ], "description": "Add new variant by blending two variants", "uiName": "Blend Variants", "inputs": { "execIn": { "type": "execution", "description": "The input execution" }, "prim": { "type": "target", "description": "The prim with the variantSet" }, "variantSetName": { "type": "token", "description": "The variantSet name" }, "variantNameA": { "type": "token", "description": "The first variant name" }, "variantNameB": { "type": "token", "description": "The second variant name" }, "blend": { "type": "double", "description": "The blend value in [0.0, 1.0]", "default": 0.0, "minimum": 0.0, "maximum": 1.0 }, "setVariant": { "type": "bool", "default": false, "description": "Sets the variant selection when finished rather than writing to the attribute values" } }, "outputs": { "bundle": { "type": "bundle", "description": "Output bundle with blended attributes", "uiName": "Bundle" }, "execOut": { "type": "execution", "description": "The output execution" } } } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/variant/OgnGetVariantSetNames.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. // // clang-format off #include "UsdPCH.h" // clang-format on #include "PrimCommon.h" #include <carb/logging/Log.h> #include <OgnGetVariantSetNamesDatabase.h> namespace omni::graph::nodes { class OgnGetVariantSetNames { public: static bool compute(OgnGetVariantSetNamesDatabase& db) { try { pxr::UsdPrim prim = tryGetTargetPrim(db, db.inputs.prim(), "prim"); pxr::UsdVariantSets variantSets = prim.GetVariantSets(); auto variantSetNames = variantSets.GetNames(); db.outputs.variantSetNames().resize(variantSetNames.size()); for (size_t i = 0; i < variantSetNames.size(); i++) { db.outputs.variantSetNames()[i] = db.stringToToken(variantSetNames[i].c_str()); } return true; } catch (const warning& e) { db.logWarning(e.what()); } catch (const std::exception& e) { db.logError(e.what()); } db.outputs.variantSetNames().resize(0); return false; } }; REGISTER_OGN_NODE() } // namespace omni::graph::nodes
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/variant/OgnSetVariantSelection.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. // // clang-format off #include "UsdPCH.h" // clang-format on #include "PrimCommon.h" #include "VariantCommon.h" #include <carb/logging/Log.h> #include <OgnSetVariantSelectionDatabase.h> namespace omni::graph::nodes { class OgnSetVariantSelection { public: static bool compute(OgnSetVariantSelectionDatabase& db) { try { pxr::UsdPrim prim = tryGetTargetPrim(db, db.inputs.prim(), "prim"); pxr::UsdVariantSets variantSets = prim.GetVariantSets(); auto variantSetName = db.tokenToString(db.inputs.variantSetName()); pxr::UsdVariantSet variantSet = variantSets.GetVariantSet(variantSetName); auto variantName = db.tokenToString(db.inputs.variantName()); if (db.inputs.setVariant()) { removeLocalOpinion(prim, variantSetName, variantName); bool success = variantSet.SetVariantSelection(variantName); if (!success) throw warning(std::string("Failed to set variant selection for variant set ") + variantSetName + " to variant " + variantName); } else { setLocalOpinion(prim, variantSetName, variantName); } db.outputs.execOut() = kExecutionAttributeStateEnabled; return true; } catch (const warning& e) { db.logWarning(e.what()); } catch (const std::exception& e) { db.logError(e.what()); } return false; } }; REGISTER_OGN_NODE() } // namespace omni::graph::nodes
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/variant/OgnClearVariantSelection.ogn
{ "ClearVariantSelection": { "version": 2, "categories": [ "graph:action", "sceneGraph", "variants" ], "icon": { "path": "Variant.svg" }, "scheduling": [ "usd-write" ], "description": "This node will clear the variant selection of the prim on the active layer. Final variant selection will be determined by layer composition below your active layer. In a single layer stage, this will be the fallback variant defined in your variantSet.", "uiName": "Clear Variant Selection", "inputs": { "execIn": { "type": "execution", "description": "The input execution" }, "prim": { "type": "target", "description": "The prim with the variantSet" }, "variantSetName": { "type": "token", "description": "The variantSet name" }, "setVariant": { "type": "bool", "default": false, "description": "Sets the variant selection when finished rather than writing to the attribute values" } }, "outputs": { "execOut": { "type": "execution", "description": "The output execution" } } } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/variant/OgnGetVariantSelection.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. // // clang-format off #include "UsdPCH.h" // clang-format on #include "PrimCommon.h" #include <carb/logging/Log.h> #include <OgnGetVariantSelectionDatabase.h> namespace omni::graph::nodes { class OgnGetVariantSelection { public: static bool compute(OgnGetVariantSelectionDatabase& db) { try { pxr::UsdPrim prim = tryGetTargetPrim(db, db.inputs.prim(), "prim"); pxr::UsdVariantSets variantSets = prim.GetVariantSets(); auto variantSetName = db.tokenToString(db.inputs.variantSetName()); pxr::UsdVariantSet variantSet = variantSets.GetVariantSet(variantSetName); auto variantSelection = variantSet.GetVariantSelection(); db.outputs.variantName() = db.stringToToken(variantSelection.c_str()); return true; } catch (const warning& e) { db.logWarning(e.what()); } catch (const std::exception& e) { db.logError(e.what()); } db.outputs.variantName() = db.stringToToken(""); return false; } }; REGISTER_OGN_NODE() } // namespace omni::graph::nodes
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/variant/OgnBlendVariants.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. // // clang-format off #include "UsdPCH.h" // clang-format on #include "PrimCommon.h" #include "VariantCommon.h" #include <carb/logging/Log.h> #include <omni/fabric/Enums.h> #include <omni/graph/core/ogn/Types.h> #include <omni/math/linalg/SafeCast.h> #include <omni/usd/UsdContext.h> #include <pxr/usd/sdf/variantSetSpec.h> #include <pxr/usd/sdf/variantSpec.h> #include <OgnBlendVariantsDatabase.h> using omni::graph::core::ogn::eAttributeType::kOgnOutput; using omni::graph::core::ogn::eMemoryType::kCpu; using omni::math::linalg::vec3f; using DB = OgnBlendVariantsDatabase; namespace omni::graph::nodes { namespace { using LerpFunction = void (*)(const double alpha, const pxr::SdfPropertySpecHandle& propertyA, const pxr::SdfPropertySpecHandle& propertyB, pxr::UsdAttribute attribute); template <typename T> void floatLerp(const double alpha, const pxr::SdfPropertySpecHandle& propertyA, const pxr::SdfPropertySpecHandle& propertyB, pxr::UsdAttribute attribute) { T a = propertyA->GetDefaultValue().Get<T>(); T b = propertyB->GetDefaultValue().Get<T>(); T c = pxr::GfLerp(alpha, a, b); if (attribute.IsValid()) attribute.Set<T>(c); } template <typename T> void discreteLerp(const double alpha, const pxr::SdfPropertySpecHandle& propertyA, const pxr::SdfPropertySpecHandle& propertyB, pxr::UsdAttribute attribute) { T a = propertyA->GetDefaultValue().Get<T>(); T b = propertyB->GetDefaultValue().Get<T>(); if (attribute.IsValid()) { if (alpha < 0.5) attribute.Set<T>(a); else attribute.Set<T>(b); } } void lerpAttribute(const double alpha, const pxr::SdfPropertySpecHandle& propertyA, const pxr::SdfPropertySpecHandle& propertyB, const pxr::UsdAttribute& attribute) { if (propertyA->GetSpecType() != propertyB->GetSpecType()) throw warning("Property spec types do not match (attribute " + attribute.GetPath().GetString() + ")"); if (propertyA->GetTypeName() != attribute.GetTypeName()) throw warning("Attribute types do not match (attribute " + attribute.GetPath().GetString() + ")"); if (propertyA->GetValueType() != propertyB->GetValueType()) throw warning("Property value types do not match"); auto typeName = propertyA->GetValueType().GetTypeName(); auto handleType = [alpha, &propertyA, &propertyB, &attribute, &typeName](const char* type, LerpFunction lerpFunction) -> bool { if (typeName == type) { lerpFunction(alpha, propertyA, propertyB, attribute); return true; } return false; }; if (!handleType("bool", discreteLerp<bool>) && !handleType("double", floatLerp<double>) && !handleType("float", floatLerp<float>) && !handleType("pxr_half::half", floatLerp<pxr::GfHalf>) && !handleType("int", discreteLerp<int>) && !handleType("__int64", discreteLerp<int64_t>) // Windows && !handleType("long", discreteLerp<int64_t>) // Linux && !handleType("unsigned char", discreteLerp<uint8_t>) && !handleType("unsigned int", discreteLerp<uint32_t>) && !handleType("unsigned __int64", discreteLerp<uint64_t>) // Windows && !handleType("unsigned long", discreteLerp<uint64_t>) // Linux && !handleType("TfToken", discreteLerp<pxr::TfToken>) && !handleType("SdfTimeCode", floatLerp<pxr::SdfTimeCode>) && !handleType("GfVec2d", floatLerp<pxr::GfVec2d>) && !handleType("GfVec2f", floatLerp<pxr::GfVec2f>) && !handleType("GfVec2h", floatLerp<pxr::GfVec2h>) && !handleType("GfVec2i", discreteLerp<pxr::GfVec2i>) && !handleType("GfVec3d", floatLerp<pxr::GfVec3d>) && !handleType("GfVec3f", floatLerp<pxr::GfVec3f>) && !handleType("GfVec3h", floatLerp<pxr::GfVec3h>) && !handleType("GfVec3i", discreteLerp<pxr::GfVec3i>) && !handleType("GfVec4d", floatLerp<pxr::GfVec4d>) && !handleType("GfVec4f", floatLerp<pxr::GfVec4f>) && !handleType("GfVec4h", floatLerp<pxr::GfVec4h>) && !handleType("GfVec4i", discreteLerp<pxr::GfVec4i>) && !handleType("GfQuatd", floatLerp<pxr::GfQuatd>) && !handleType("GfQuatf", floatLerp<pxr::GfQuatf>) && !handleType("GfQuath", floatLerp<pxr::GfQuath>) && !handleType("GfMatrix2d", floatLerp<pxr::GfMatrix2d>) && !handleType("GfMatrix3d", floatLerp<pxr::GfMatrix3d>) && !handleType("GfMatrix4d", floatLerp<pxr::GfMatrix4d>)) throw warning("Unsupported property type " + typeName); } } class OgnBlendVariants { public: static bool compute(OgnBlendVariantsDatabase& db) { auto ok = [&db]() { db.outputs.execOut() = kExecutionAttributeStateEnabled; return true; }; try { pxr::UsdPrim prim = tryGetTargetPrim(db, db.inputs.prim(), "prim"); std::string variantSetName = db.tokenToString(db.inputs.variantSetName()); std::string variantNameA = db.tokenToString(db.inputs.variantNameA()); std::string variantNameB = db.tokenToString(db.inputs.variantNameB()); double blend = std::max(std::min(db.inputs.blend(), 1.0), 0.0); pxr::UsdVariantSets variantSets = prim.GetVariantSets(); pxr::UsdVariantSet variantSet = variantSets.GetVariantSet(variantSetName); if (!variantSet.IsValid()) throw warning("Invalid variant set " + variantSetName); bool finishing = (1.0 - blend) < 1e-6; if (finishing && db.inputs.setVariant()) variantSet.SetVariantSelection(variantNameB); VariantData a = getVariantData(prim, variantSetName, variantNameA); VariantData b = getVariantData(prim, variantSetName, variantNameB); for (const auto& [path, propertyA] : a) { if (b.find(path) == b.end()) continue; auto propertyB = b[path]; auto attribute = prim.GetStage()->GetAttributeAtPath(path); if (!attribute.IsValid()) throw warning("Invalid attribute " + path.GetString()); if (finishing && db.inputs.setVariant()) attribute.Clear(); else lerpAttribute(blend, propertyA, propertyB, attribute); } return ok(); } catch (const warning& e) { db.logWarning(e.what()); } catch (const std::exception& e) { db.logError(e.what()); } return false; } }; REGISTER_OGN_NODE() } // namespace omni::graph::nodes
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/variant/OgnHasVariantSet.ogn
{ "HasVariantSet": { "version": 2, "categories": [ "graph:action", "sceneGraph", "variants" ], "icon": { "path": "Variant.svg" }, "scheduling": [ "usd-read" ], "description": "Query the existence of a variantSet on a prim", "uiName": "Has Variant Set", "inputs": { "prim": { "type": "target", "description": "The prim with the variantSet" }, "variantSetName": { "type": "token", "description": "The variantSet name" } }, "outputs": { "exists": { "type": "bool", "description": "Variant exists" } } } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/geo/OgnLengthAlongCurve.ogn
{ "LengthAlongCurve": { "version": 1, "description": "Find the length along the curve of a set of points", "metadata": { "uiName": "Length Along Curve" }, "categories": ["geometry:analysis"], "scheduling": ["threadsafe"], "inputs": { "curveVertexStarts": { "type": "int[]", "description": "Vertex starting points", "metadata": { "uiName": "Curve Vertex Starts" } }, "curveVertexCounts": { "type": "int[]", "description": "Vertex counts for the curve points", "metadata": { "uiName": "Curve Vertex Counts" } }, "curvePoints": { "type": "float[3][]", "description": "Points on the curve to be framed", "metadata": { "uiName": "Curve Points" } }, "normalize": { "type": "bool", "description": "If true then normalize the curve length to a 0, 1 range", "metadata": { "uiName": "Normalize" } } }, "outputs": { "length": { "type": "float[]", "description": "List of lengths along the curve corresponding to the input points" } }, "tests": [ { "inputs:curveVertexStarts": [0], "inputs:curveVertexCounts": [4], "inputs:curvePoints": [[0.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 4.0, 4.0], [12.0, 13.0, 4.0]], "inputs:normalize": false, "outputs:length": [0.0, 1.0, 6.0, 21.0] }, { "inputs:curveVertexStarts": [0], "inputs:curveVertexCounts": [3], "inputs:curvePoints": [[0.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 1.0, 1.0]], "inputs:normalize": true, "outputs:length": [0.0, 0.5, 1.0] } ] } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/geo/OgnCurveFrame.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 <OgnCurveFrameDatabase.h> #include "omni/math/linalg/vec.h" #include <carb/Framework.h> #include <carb/Types.h> #include <math.h> using omni::math::linalg::vec3f; namespace omni { namespace graph { namespace nodes { static vec3f perpendicular(vec3f v) { vec3f av(abs(v[0]), abs(v[1]), abs(v[2])); // Find the smallest coordinate of v. int axis = (av[0] < av[1] && av[0] < av[2]) ? 0 : ((av[1] < av[2]) ? 1 : 2); // Start with that coordinate. vec3f p(0.0f); p[axis] = 1.0f; // Subtract the portion parallel to v. p -= (GfDot(p, v) / GfDot(v, v)) * v; // Normalize return p.GetNormalized(); } static vec3f rotateLike(vec3f v, vec3f a, vec3f aPlusb) { // To apply to another vector v, the rotation that brings tangent a to tangent b: // - reflect v through the line in direction of unit vector a // - reflect that through the line in direction of a+b vec3f temp = (2 * GfDot(a, v)) * a - v; return (2 * GfDot(aPlusb, temp) / GfDot(aPlusb, aPlusb)) * aPlusb - temp; } class OgnCurveFrame { public: static bool compute(OgnCurveFrameDatabase& db) { const auto& vertexStartIndices = db.inputs.curveVertexStarts(); const auto& vertexCounts = db.inputs.curveVertexCounts(); const auto& curvePoints = db.inputs.curvePoints(); auto& tangentArray = db.outputs.tangent(); auto& upArray = db.outputs.up(); auto &outArray = db.outputs.out(); size_t curveCount = vertexStartIndices.size(); if (vertexCounts.size() < curveCount) curveCount = vertexCounts.size(); const size_t pointCount = curvePoints.size(); if (curveCount == 0) { tangentArray.resize(0); upArray.resize(0); outArray.resize(0); return true; } tangentArray.resize(pointCount); upArray.resize(pointCount); outArray.resize(pointCount); for (size_t curve = 0; curve < curveCount; ++curve) { if (vertexCounts[curve] <= 0) continue; const size_t vertex = vertexStartIndices[curve]; if (vertex >= pointCount) break; size_t vertexCount = size_t(vertexCounts[curve]); // Limit the vertex count on this curve if it goes past the end of the points array. if (vertexCount > pointCount - vertex) { vertexCount = pointCount - vertex; } if (vertexCount == 1) { // Only one vertex: predetermined frame. tangentArray[vertex] = vec3f( 0.0f, 0.0f, 1.0f ); upArray[vertex] = vec3f( 0.0f, 1.0f, 0.0f ); outArray[vertex] = vec3f( 1.0f, 0.0f, 0.0f ); continue; } // First, compute all tangents. // The first tangent is the first edge direction. // TODO: Skip zero-length edges to get the first real edge direction. vec3f prev = curvePoints[vertex]; vec3f current = curvePoints[vertex + 1]; vec3f prevDir = (current - prev).GetNormalized(); tangentArray[vertex] = prevDir; for (size_t i = 1; i < vertexCount - 1; ++i) { vec3f next = curvePoints[vertex + i + 1]; vec3f nextDir = (next - current).GetNormalized(); // Middle tangents are averages of previous and next directions. vec3f dir = (prevDir + nextDir).GetNormalized(); tangentArray[vertex + i] = dir; prev = current; current = next; prevDir = nextDir; } // The last tangent is the last edge direction. tangentArray[vertex + vertexCount - 1] = prevDir; // Choose the first up vector as anything that's perpendicular to the first tangent. // TODO: Use a curve "normal" for more consistency. vec3f prevTangent = tangentArray[vertex]; vec3f prevUpVector = perpendicular(prevTangent); // x = cross(y, z) vec3f prevOutVector = GfCross(prevUpVector, prevTangent); upArray[vertex] = prevUpVector; outArray[vertex] = prevOutVector; for (size_t i = 1; i < vertexCount; ++i) { vec3f nextTangent = tangentArray[vertex + i]; vec3f midTangent = prevTangent + nextTangent; vec3f nextUpVector = rotateLike(prevUpVector, prevTangent, midTangent); vec3f nextOutVector = rotateLike(prevOutVector, prevTangent, midTangent); upArray[vertex + i] = nextUpVector; outArray[vertex + i] = nextOutVector; prevTangent = nextTangent; prevUpVector = nextUpVector; prevOutVector = nextOutVector; } } return true; } }; REGISTER_OGN_NODE() } } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/geo/OgnLengthAlongCurve.cpp
// Copyright (c) 2020, 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 <OgnLengthAlongCurveDatabase.h> namespace omni { namespace graph { namespace nodes { class OgnLengthAlongCurve { public: static bool compute(OgnLengthAlongCurveDatabase& db) { const auto& vertexStartIndices = db.inputs.curveVertexStarts(); const auto& vertexCounts = db.inputs.curveVertexCounts(); const auto& curvePoints = db.inputs.curvePoints(); const auto& normalize = db.inputs.normalize(); auto& lengthArray = db.outputs.length(); size_t curveCount = std::min(vertexStartIndices.size(), vertexCounts.size()); const size_t pointCount = curvePoints.size(); if (curveCount == 0) { lengthArray.resize(0); return true; } lengthArray.resize(pointCount); for (size_t curve = 0; curve < curveCount; ++curve) { if (vertexCounts[curve] <= 0) continue; const size_t vertex = vertexStartIndices[curve]; if (vertex >= pointCount) break; size_t vertexCount = size_t(vertexCounts[curve]); // Limit the vertex count on this curve if it goes past the end of the points array. if (vertexCount > pointCount - vertex) { vertexCount = pointCount - vertex; } if (vertexCount == 1) { // Only one vertex: predetermined frame. lengthArray[vertex] = 0.0f; continue; } // First, compute all lengths along the curve. auto prev = curvePoints[vertex]; lengthArray[vertex] = 0.0f; // Sum in double precision to avoid catastrophic roundoff error. double lengthSum = 0.0; for (size_t i = 1; i < vertexCount; ++i) { auto& current = curvePoints[vertex + i]; auto edge = (current - prev); lengthSum += edge.GetLength(); lengthArray[vertex + i] = float(lengthSum); prev = current; } // Don't normalize if lengthSum is zero. if (normalize && float(lengthSum) != 0) { for (size_t i = 0; i < vertexCount; ++i) { lengthArray[vertex + i] /= float(lengthSum); } } } return true; } }; REGISTER_OGN_NODE() } } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/geo/OgnCurveTubeST.ogn
{ "CurveTubeST": { "version": 1, "description" : "Compute curve tube ST values", "metadata": { "uiName": "Curve Tube ST" }, "categories": ["geometry:generator"], "scheduling": ["threadsafe"], "inputs": { "curveVertexStarts": { "type": "int[]", "description": "Vertex starting points", "metadata": { "uiName": "Curve Vertex Starts" } }, "curveVertexCounts": { "type": "int[]", "description": "Vertex counts for the curve points", "metadata": { "uiName": "Curve Vertex Counts" } }, "tubeSTStarts": { "type": "int[]", "description": "Vertex index values for the tube ST starting points", "metadata": { "uiName": "Tube ST Starts" } }, "tubeQuadStarts": { "type": "int[]", "description": "Vertex index values for the tube quad starting points", "metadata": { "uiName": "Tube Quad Starts" } }, "cols": { "type": "int[]", "description": "Columns of the tubes", "metadata": { "uiName": "Columns" } }, "t": { "type": "float[]", "description": "T values of the tubes", "metadata": { "uiName": "T Values" } }, "width": { "type": "float[]", "description": "Width of tube positions, if scaling T like S", "metadata": { "uiName": "Tube Widths" } }, "scaleTLikeS": { "type": "bool", "description": "If true then scale T the same as S", "metadata": { "uiName": "Scale T Like S" } } }, "outputs": { "primvars:st": { "type": "float[2][]", "description": "Array of computed ST values", "metadata": { "uiName": "ST Values" } }, "primvars:st:indices": { "type": "int[]", "description": "Array of computed ST indices", "metadata": { "uiName": "ST Indices" } } } } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/geo/OgnCurveFrame.ogn
{ "CurveToFrame": { "version": 1, "description": "Create a frame object based on a curve description", "metadata": { "uiName": "Crate Curve From Frame" }, "categories": ["geometry:generator"], "scheduling": ["threadsafe"], "inputs": { "curveVertexStarts": { "type": "int[]", "description": "Vertex starting points", "metadata": { "uiName": "Curve Vertex Starts" } }, "curveVertexCounts": { "type": "int[]", "description": "Vertex counts for the curve points", "metadata": { "uiName": "Curve Vertex Counts" } }, "curvePoints": { "type": "float[3][]", "description": "Points on the curve to be framed", "metadata": { "uiName": "Curve Points" } } }, "outputs": { "tangent": { "type": "float[3][]", "description": "Tangents on the curve frame", "metadata": { "uiName": "Tangents" } }, "up": { "type": "float[3][]", "description": "Up vectors on the curve frame", "metadata": { "uiName": "Up Vectors" } }, "out": { "type": "float[3][]", "description": "Out vector directions on the curve frame", "metadata": { "uiName": "Out Vectors" } } } } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/geo/OgnCreateTubeTopology.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 <OgnCreateTubeTopologyDatabase.h> namespace omni { namespace graph { namespace nodes { class OgnCreateTubeTopology { public: static bool compute(OgnCreateTubeTopologyDatabase& db) { const auto& inputRows = db.inputs.rows(); const auto& inputColumns = db.inputs.cols(); auto& faceVertexCounts = db.outputs.faceVertexCounts(); auto& faceVertexIndices = db.outputs.faceVertexIndices(); const size_t rowValueCount = inputRows.size(); const size_t colValueCount = inputColumns.size(); size_t inputTubeCount; if (colValueCount == 1 || colValueCount == rowValueCount) { inputTubeCount = rowValueCount; } else if (rowValueCount == 1) { inputTubeCount = colValueCount; } else { faceVertexCounts.resize(0); faceVertexIndices.resize(0); return true; } size_t validTubeCount = 0; size_t quadCount = 0; for (size_t inputTube = 0; inputTube < inputTubeCount; ++inputTube) { auto rows = inputRows[(rowValueCount == 1) ? 0 : inputTube]; auto cols = inputColumns[(colValueCount == 1) ? 0 : inputTube]; if (rows <= 0 || cols <= 1) { continue; } const size_t currentQuadCount = size_t(rows) * cols; quadCount += currentQuadCount; ++validTubeCount; } // Generate a faceVertexCounts array with all 4, for all quads. faceVertexCounts.resize(quadCount); for (auto& faceVertex : faceVertexCounts) { faceVertex = 4; } faceVertexIndices.resize(4 * quadCount); size_t faceVertexIndex{ 0 }; int pointIndex = 0; for (size_t inputTube = 0; inputTube < inputTubeCount; ++inputTube) { auto rows = inputRows[(rowValueCount == 1) ? 0 : inputTube]; auto cols = inputColumns[(colValueCount == 1) ? 0 : inputTube]; if (rows <= 0 || cols <= 1) { continue; } for (auto row = 0; row < rows; ++row) { // Main quads of the row for (auto col = 0; col < cols - 1; ++col) { faceVertexIndices[faceVertexIndex++] = pointIndex; faceVertexIndices[faceVertexIndex++] = pointIndex + 1; faceVertexIndices[faceVertexIndex++] = pointIndex + cols + 1; faceVertexIndices[faceVertexIndex++] = pointIndex + cols; ++pointIndex; } // Wrap around faceVertexIndices[faceVertexIndex++] = pointIndex; faceVertexIndices[faceVertexIndex++] = pointIndex - cols + 1; faceVertexIndices[faceVertexIndex++] = pointIndex + 1; faceVertexIndices[faceVertexIndex++] = pointIndex + cols; ++pointIndex; } pointIndex += cols; } return true; } }; REGISTER_OGN_NODE() } } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/geo/OgnCreateTubeTopology.ogn
{ "CreateTubeTopology":{ "version": 1, "description": [ "Creates the face vertex counts and indices describing a tube topology with the", "given number of rows and columns." ], "metadata": { "uiName": "Create Tube Topology" }, "categories": ["geometry:generator"], "scheduling": ["threadsafe"], "inputs": { "rows": { "type": "int[]", "description": "Array of rows in the topology to be generated", "metadata": { "uiName": "Row Array" } }, "cols": { "type": "int[]", "description": "Array of columns in the topology to be generated", "metadata": { "uiName": "Column Array" } } }, "outputs": { "faceVertexCounts": { "type": "int[]", "description": "Array of vertex counts for each face in the tube topology", "metadata": { "uiName": "Face Vertex Counts" } }, "faceVertexIndices": { "type": "int[]", "description" : "Array of vertex indices for each face in the tube topology", "metadata": { "uiName": "Face Vertex Indices" } } }, "tests": [ { "inputs:rows": [1, 2, 3], "inputs:cols": [2, 3, 4], "outputs:faceVertexCounts": [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4], "outputs:faceVertexIndices": [ 0, 1, 3, 2, 1, 0, 2, 3, 4, 5, 8, 7, 5, 6, 9, 8, 6, 4, 7, 9, 7, 8, 11, 10, 8, 9, 12, 11, 9, 7, 10, 12, 13, 14, 18, 17, 14, 15, 19, 18, 15, 16, 20, 19, 16, 13, 17, 20, 17, 18, 22, 21, 18, 19, 23, 22, 19, 20, 24, 23, 20, 17, 21, 24, 21, 22, 26, 25, 22, 23, 27, 26, 23, 24, 28, 27, 24, 21, 25, 28 ] } ] } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/geo/OgnCurveTubePositions.ogn
{ "CurveTubePositions": { "version": 1, "description": "Generate tube positions from a curve description", "metadata": { "uiName": "Curve Tube Positions" }, "categories": ["geometry:generator"], "scheduling": ["threadsafe"], "inputs": { "curveVertexStarts": { "type": "int[]", "description": "Vertex starting points", "metadata": { "uiName": "Curve Vertex Starts" } }, "curveVertexCounts": { "type": "int[]", "description": "Vertex counts for the curve points", "metadata": { "uiName": "Curve Vertex Counts" } }, "curvePoints": { "type": "float[3][]", "description": "Points on the curve to be framed", "metadata": { "uiName": "Curve Points" } }, "tubePointStarts": { "type": "int[]", "description": "Tube starting point index values", "metadata": { "uiName": "Tube Point Starts" } }, "cols": { "type": "int[]", "description": "Columns of the tubes", "metadata": { "uiName": "Columns" } }, "up": { "type": "float[3][]", "description": "Up vectors on the tube", "metadata": { "uiName": "Up Vectors" } }, "out": { "type": "float[3][]", "description": "Out vector directions on the tube", "metadata": { "uiName": "Out Vectors" } }, "width": { "type": "float[]", "description": "Width of tube positions", "metadata": { "uiName": "Tube Widths" } } }, "outputs": { "points": { "type": "float[3][]", "description": "Points on the tube", "metadata": { "uiName": "Points" } } } } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/geo/OgnCurveTubeST.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 <OgnCurveTubeSTDatabase.h> #include "omni/math/linalg/vec.h" #include <carb/Framework.h> #include <carb/Types.h> #include <omni/graph/core/ArrayWrapper.h> #include <omni/graph/core/NodeTypeRegistrar.h> #include <omni/graph/core/iComputeGraph.h> #include <vector> #define _USE_MATH_DEFINES #include <math.h> using omni::math::linalg::vec2f; namespace omni { namespace graph { namespace nodes { static void computeNewSs(std::vector<float>& sValues, size_t edgeCount) { if (sValues.size() == edgeCount + 1) return; sValues.resize(edgeCount + 1); sValues[0] = 0.0f; if (edgeCount == 0) return; for (size_t i = 1; i < edgeCount; ++i) { sValues[i] = float(double(i) / double(edgeCount)); } sValues[edgeCount] = 1.0f; } class OgnCurveTubeST { public: static bool compute(OgnCurveTubeSTDatabase& db) { const auto& curveStartIndices = db.inputs.curveVertexStarts(); const auto& tubeVertexCounts = db.inputs.curveVertexCounts(); const auto& tubeSTStartArray = db.inputs.tubeSTStarts(); const auto& tubeQuadStartArray = db.inputs.tubeQuadStarts(); const auto& columnsArray = db.inputs.cols(); const auto& widthArray = db.inputs.width(); const auto& tArray = db.inputs.t(); auto scaleTLikeS = db.inputs.scaleTLikeS(); // Might change, so get a copy auto& stArray = db.outputs.primvars_st(); auto& stIndicesArray = db.outputs.primvars_st_indices(); size_t curveCount = curveStartIndices.size(); if (tubeVertexCounts.size() < curveCount) curveCount = tubeVertexCounts.size(); size_t tubeCount = tubeSTStartArray.size(); if (tubeQuadStartArray.size() < tubeCount) { tubeCount = tubeQuadStartArray.size(); } const size_t colValueCount = columnsArray.size(); const int32_t tubeSTsCount = (tubeCount == 0) ? 0 : tubeSTStartArray[tubeCount - 1]; const int32_t tubeQuadsCount = (tubeCount == 0) ? 0 : tubeQuadStartArray[tubeCount - 1]; if (tubeCount != 0) --tubeCount; const size_t tCount = tArray.size(); size_t widthCount = 0; if (scaleTLikeS) { widthCount = widthArray.size(); if (widthCount == 0 || (widthCount != 1 && widthCount != tCount && widthCount != tubeCount)) { scaleTLikeS = false; } } if (tubeSTsCount <= 0 || tubeCount == 0 || (colValueCount != 1 && colValueCount != tubeCount) || (colValueCount == 1 && columnsArray[0] <= 0) || (tubeCount != curveCount)) { stArray.resize(0); stIndicesArray.resize(0); return true; } if (tCount == 0) { stArray.resize(0); stIndicesArray.resize(0); return true; } std::vector<float> sValues; size_t circleN = 0; float perimeterScale = 0.0f; if (colValueCount == 1) { circleN = columnsArray[0]; computeNewSs(sValues, circleN); perimeterScale = float(circleN * sin(M_PI / circleN)); } stArray.resize(tubeSTsCount); stIndicesArray.resize(4 * tubeQuadsCount); float width = (scaleTLikeS ? widthArray[0] : 0.0f); for (size_t tube = 0; tube < tubeCount; ++tube) { if (tubeSTStartArray[tube] < 0 || curveStartIndices[tube] < 0 || tubeQuadStartArray[tube] < 0 || tubeVertexCounts[tube] < 0) continue; size_t tubeSTStartIndex = tubeSTStartArray[tube]; size_t tubeSTEndIndex = tubeSTStartArray[tube + 1]; size_t tubeQuadStartIndex = 4 * tubeQuadStartArray[tube]; size_t tubeQuadEndIndex = 4 * tubeQuadStartArray[tube + 1]; size_t curveStartIndex = curveStartIndices[tube]; size_t curveEndIndex = curveStartIndex + tubeVertexCounts[tube]; if (colValueCount != 1) { circleN = columnsArray[tube]; if (circleN <= 0) continue; computeNewSs(sValues, circleN); perimeterScale = float(circleN * sin(M_PI / circleN)); } if ((int32_t)tubeSTEndIndex > tubeSTsCount || tubeSTEndIndex < tubeSTStartIndex) break; if (tubeSTEndIndex == tubeSTStartIndex) continue; size_t curveTCount = curveEndIndex - curveStartIndex; size_t tubeSTCount = tubeSTEndIndex - tubeSTStartIndex; if (curveTCount * (circleN + 1) != tubeSTCount) { continue; } if (scaleTLikeS) { if (widthCount == tubeCount) { width = widthArray[tube]; } else if (widthCount == tCount) { // Use the max width along the curve for the whole curve's // t scaling, just for stability for now. // Some situations need varying scale, but that's more complicated, // and not what's needed for the current use cases. width = widthArray[curveStartIndex]; for (size_t i = curveStartIndex + 1; i < curveEndIndex; ++i) { if (widthArray[i] > width) { width = widthArray[i]; } } } } // First, compute the st values. size_t circleIndex = 0; float tScale = 1.0f; if (scaleTLikeS) { // Scale t by 1/(2nr*sin(2pi/2n)), where 2r*sin(2pi/2n) is the side length, // and the full denominator is the perimeter of the tube's circle. // This is, in a sense, scaling t by the same factor that s was "scaled" // by, to make it go from 0 to 1, instead of 0 to the perimeter. // This way, t will change proportionally to s moving along the surface in 3D space. tScale = 1.0f / (width * perimeterScale); } float tValue = tScale * tArray[curveStartIndex]; for (size_t sti = tubeSTStartIndex; sti < tubeSTEndIndex; ++sti) { vec2f st( sValues[circleIndex], tValue ); stArray[sti] = st; ++circleIndex; if (circleIndex >= circleN + 1) { circleIndex = 0; ++curveStartIndex; if (curveStartIndex < curveEndIndex) { tValue = tScale * tArray[curveStartIndex]; } } } // Second, compute indices into the st values. circleIndex = 0; for (size_t indexi = tubeQuadStartIndex, sti = tubeSTStartIndex; indexi < tubeQuadEndIndex; indexi += 4, ++sti) { stIndicesArray[indexi] = int32_t(sti); stIndicesArray[indexi + 1] = int32_t(sti + 1); stIndicesArray[indexi + 2] = int32_t(sti + circleN + 1 + 1); stIndicesArray[indexi + 3] = int32_t(sti + circleN + 1); ++circleIndex; if (circleIndex >= circleN) { circleIndex = 0; ++sti; } } } return true; } }; REGISTER_OGN_NODE() } } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/geo/OgnCurveTubePositions.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 <OgnCurveTubePositionsDatabase.h> #include <carb/Framework.h> #include <carb/Types.h> #include <vector> #define _USE_MATH_DEFINES #include <math.h> using carb::Float2; using carb::Float3; namespace omni { namespace graph { namespace nodes { static void computeNewCircle(std::vector<Float2>& circle, size_t edgeCount) { if (circle.size() == edgeCount) return; circle.resize(edgeCount); circle[0] = Float2{ 1.0f, 0.0f }; for (size_t i = 1; i < edgeCount; ++i) { double theta = ((2 * M_PI) / double(edgeCount)) * double(i); float c = float(cos(theta)); float s = float(sin(theta)); circle[i] = Float2{ c, s }; } } class OgnCurveTubePositions { public: static bool compute(OgnCurveTubePositionsDatabase& db) { const auto& curveStartIndices = db.inputs.curveVertexStarts(); const auto& tubeVertexCounts = db.inputs.curveVertexCounts(); const auto& curvePointsArray = db.inputs.curvePoints(); const auto& tubeStartIndices = db.inputs.tubePointStarts(); const auto& columnsArray = db.inputs.cols(); const auto& widthArray = db.inputs.width(); const auto& upArray = db.inputs.up(); const auto& outArray = db.inputs.out(); auto& pointsArray = db.outputs.points(); size_t curveCount = curveStartIndices.size(); if (tubeVertexCounts.size() < curveCount) curveCount = tubeVertexCounts.size(); size_t tubeCount = tubeStartIndices.size(); const size_t colValueCount = columnsArray.size(); const int32_t tubePointsCount = (tubeCount == 0) ? 0 : tubeStartIndices[tubeCount - 1]; if (tubeCount != 0) --tubeCount; const size_t curvePointCount = curvePointsArray.size(); const size_t upCount = upArray.size(); const size_t outCount = outArray.size(); const size_t widthCount = widthArray.size(); size_t curvePointsCount = curvePointCount; if (upCount != 1 && upCount < curvePointsCount) curvePointsCount = upCount; if (outCount != 1 && outCount < curvePointsCount) curvePointsCount = outCount; if (widthCount != 1 && widthCount < curvePointsCount) curvePointsCount = widthCount; if (tubePointsCount <= 0 || tubeCount == 0 || (colValueCount != 1 && colValueCount != tubeCount) || (colValueCount == 1 && columnsArray[0] <= 0) || (tubeCount != curveCount)) { pointsArray.resize(0); return true; } if (curvePointsCount == 0) { pointsArray.resize(0); return true; } std::vector<Float2> circle; size_t circleN = 0; if (colValueCount == 1) { circleN = columnsArray[0]; computeNewCircle(circle, circleN); } pointsArray.resize(tubePointsCount); for (size_t tube = 0; tube < tubeCount; ++tube) { if (tubeStartIndices[tube] < 0 || curveStartIndices[tube] < 0 || tubeVertexCounts[tube] < 0) continue; size_t tubeStartIndex = tubeStartIndices[tube]; size_t tubeEndIndex = tubeStartIndices[tube + 1]; size_t curveStartIndex = curveStartIndices[tube]; size_t curveEndIndex = curveStartIndex + tubeVertexCounts[tube]; if (colValueCount != 1) { circleN = columnsArray[tube]; if (circleN <= 0) continue; computeNewCircle(circle, circleN); } if ((int32_t)tubeEndIndex > tubePointsCount || tubeEndIndex < tubeStartIndex) break; if (tubeEndIndex == tubeStartIndex) continue; size_t curvePointCount = curveEndIndex - curveStartIndex; size_t tubePointCount = tubeEndIndex - tubeStartIndex; if (curvePointCount * circleN != tubePointCount) { continue; } size_t circleIndex = 0; // Do bounds check on up and out arrays. auto center = curvePointsArray[curveStartIndex]; auto up = upArray[(upCount == 1) ? 0 : curveStartIndex]; auto out = outArray[(outCount == 1) ? 0 : curveStartIndex]; float width = 0.5f * widthArray[(widthCount == 1) ? 0 : curveStartIndex]; for (size_t point = tubeStartIndex; point < tubeEndIndex; ++point) { float x = width * circle[circleIndex].x; float y = width * circle[circleIndex].y; auto newPoint = (center + (x * out + y * up)); pointsArray[point] = newPoint; ++circleIndex; if (circleIndex >= circleN) { circleIndex = 0; ++curveStartIndex; if (curveStartIndex < curveEndIndex) { center = curvePointsArray[curveStartIndex]; up = upArray[(upCount == 1) ? 0 : curveStartIndex]; out = outArray[(outCount == 1) ? 0 : curveStartIndex]; width = 0.5f * widthArray[(widthCount == 1) ? 0 : curveStartIndex]; } } } } return true; } }; REGISTER_OGN_NODE() } } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/gpu_interop/OgnRpResourceExampleAllocator.cpp
// Copyright (c) 2021-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 "OgnRpResourceExampleAllocatorDatabase.h" #include <carb/graphics/GraphicsTypes.h> #include <carb/logging/Log.h> #include <cuda/include/cuda_runtime_api.h> #include <omni/graph/core/iComputeGraph.h> #include <omni/graph/core/NodeTypeRegistrar.h> #include <rtx/utils/GraphicsDescUtils.h> #include <rtx/resourcemanager/ResourceManager.h> #include <omni/kit/KitUtils.h> #include <omni/kit/renderer/IRenderer.h> #include <gpu/foundation/FoundationTypes.h> #include <omni/graph/core/BundlePrims.h> #include <omni/math/linalg/vec.h> using omni::math::linalg::vec3f; using omni::graph::core::BundleAttributeInfo; using omni::graph::core::BundlePrim; using omni::graph::core::BundlePrims; using omni::graph::core::ConstBundlePrim; using omni::graph::core::ConstBundlePrims; namespace omni { namespace graph { namespace core { namespace examples { class OgnRpResourceExampleAllocator { // NOTE: this node is meant only as an early example of gpu interop on a prerender graph. // Storing a pointer to an RpResource is a temporary measure that will not work in a // multi-node setting. bool previousSuccess; bool previousReload; std::vector<rtx::resourcemanager::RpResource*> resourcePointerCollection; std::vector<uint64_t> pointCountCollection; std::vector<NameToken> primPathCollection; public: static void initialize(const GraphContextObj& context, const NodeObj& nodeObj) { // std::cout << "OgnRpResourceExampleAllocator::initialize" << std::endl; } static void release(const NodeObj& nodeObj) { // std::cout << "OgnRpResourceExampleAllocator::release" << std::endl; if (auto renderer = carb::getCachedInterface<omni::kit::renderer::IRenderer>()) { if (auto gpuFoundation = renderer->getGpuFoundation()) { rtx::resourcemanager::ResourceManager* resourceManager = gpuFoundation->getResourceManager(); rtx::resourcemanager::Context* resourceManagerContext = gpuFoundation->getResourceManagerContext(); auto& internalState = OgnRpResourceExampleAllocatorDatabase::sInternalState<OgnRpResourceExampleAllocator>(nodeObj); auto& resourcePointerCollection = internalState.resourcePointerCollection; const size_t resourceCount = resourcePointerCollection.size(); for (size_t i = 0; i < resourceCount; i++) { resourceManager->releaseResource(*resourcePointerCollection[i]); } } } } static bool compute(OgnRpResourceExampleAllocatorDatabase& db) { CARB_PROFILE_ZONE(1, "OgnRpResourceExampleAllocator::compute"); rtx::resourcemanager::Context* resourceManagerContext = nullptr; rtx::resourcemanager::ResourceManager* resourceManager = nullptr; auto& internalState = db.internalState<OgnRpResourceExampleAllocator>(); const bool previousSuccess = internalState.previousSuccess; const bool previousReload = internalState.previousReload; internalState.previousSuccess = false; internalState.previousReload= false; const bool verbose = db.inputs.verbose(); if (auto renderer = carb::getCachedInterface<omni::kit::renderer::IRenderer>()) { if (auto gpuFoundation = renderer->getGpuFoundation()) { resourceManager = gpuFoundation->getResourceManager(); resourceManagerContext = gpuFoundation->getResourceManagerContext(); } } cudaStream_t stream = (cudaStream_t)db.inputs.stream(); if (verbose) { std::cout<<"OgnRpResourceExampleAllocator::compute -- cudaStream: "<<stream<<std::endl; } if (!stream) { db.outputs.resourcePointerCollection().resize(0); db.outputs.pointCountCollection().resize(0); db.outputs.primPathCollection().resize(0); return false; } if (resourceManager == nullptr || resourceManagerContext == nullptr) { db.outputs.resourcePointerCollection().resize(0); db.outputs.pointCountCollection().resize(0); db.outputs.primPathCollection().resize(0); return false; } auto& resourcePointerCollection = internalState.resourcePointerCollection; auto& pointCountCollection = internalState.pointCountCollection; auto& primPathCollection = internalState.primPathCollection; const bool reloadAttr = db.inputs.reload(); if ((reloadAttr && !previousReload) || !previousSuccess) { internalState.previousReload = true; if (resourcePointerCollection.size() != 0) { if (verbose) { std::cout << "freeing RpResource." << std::endl; } const size_t resourceCount = resourcePointerCollection.size(); for (size_t i = 0; i < resourceCount; i++) { resourceManager->releaseResource(*resourcePointerCollection[i]); } resourcePointerCollection.resize(0); pointCountCollection.resize(0); primPathCollection.resize(0); } } if (resourcePointerCollection.size() == 0) { const auto& pointsAttr = db.inputs.points(); const size_t pointsCount = pointsAttr.size(); const vec3f* points = pointsAttr.data(); const NameToken primPath = db.inputs.primPath(); if (pointsCount == 0) return false; if (points == nullptr) return false; //const uint64_t dimension = 4; const uint64_t dimension = 3; const uint64_t size = pointsCount * dimension * sizeof(float); const uint32_t deviceIndex = 0; carb::graphics::BufferUsageFlags usageFlags = carb::graphics::kBufferUsageFlagNone; usageFlags |= carb::graphics::kBufferUsageFlagShaderResourceStorage; usageFlags |= carb::graphics::kBufferUsageFlagVertexBuffer; usageFlags |= carb::graphics::kBufferUsageFlagRawOrStructuredBuffer; usageFlags |= carb::graphics::kBufferUsageFlagRaytracingBuffer; carb::graphics::BufferDesc bufferDesc = rtx::RtxBufferDesc(size, "Mesh Buffer", usageFlags); rtx::resourcemanager::ResourceDesc resourceDesc; resourceDesc.mode = rtx::resourcemanager::ResourceMode::eDefault; resourceDesc.memoryLocation = carb::graphics::MemoryLocation::eDevice; resourceDesc.category = rtx::resourcemanager::ResourceCategory::eVertexBuffer; resourceDesc.usageFlags = rtx::resourcemanager::kResourceUsageFlagCudaShared; resourceDesc.deviceMask = OMNI_ALL_DEVICES_MASK; resourceDesc.creationDeviceIndex = deviceIndex; for (size_t i = 0; i < 2; i++) { rtx::resourcemanager::RpResource* rpResource = resourceManager->getResourceFromBufferDesc(*resourceManagerContext, bufferDesc, resourceDesc); float* cpuPtr = new float[pointsCount * dimension]; for (size_t j = 0; j < pointsCount; j++) { cpuPtr[dimension * j] = points[j][0]; cpuPtr[dimension * j + 1] = points[j][1]; cpuPtr[dimension * j + 2] = points[j][2]; if (dimension == 4) cpuPtr[dimension * j + 3] = 1.f; } void* cudaPtr = resourceManager->getCudaDevicePointer(*rpResource, deviceIndex); cudaError_t err = cudaMemcpy(cudaPtr, cpuPtr, pointsCount * dimension * sizeof(float), cudaMemcpyHostToDevice); delete [] cpuPtr; if (verbose) { std::cout << "prim: " << db.tokenToString(primPath) << std::endl; std::cout << "cudaMemcpy to device error code: " << err << std::endl; std::cout << "errorName: " << cudaGetErrorName(err) << std::endl; std::cout << "errorDesc: " << cudaGetErrorString(err) << std::endl; std::cout << std::endl; } resourcePointerCollection.push_back(rpResource); } pointCountCollection.push_back((uint64_t)pointsCount); primPathCollection.push_back(primPath); db.outputs.resourcePointerCollection.resize(resourcePointerCollection.size()); memcpy(db.outputs.resourcePointerCollection().data(), resourcePointerCollection.data(), resourcePointerCollection.size() * sizeof(uint64_t)); db.outputs.pointCountCollection.resize(pointCountCollection.size()); memcpy(db.outputs.pointCountCollection().data(), pointCountCollection.data(), pointCountCollection.size() * sizeof(uint64_t)); db.outputs.primPathCollection.resize(primPathCollection.size()); memcpy(db.outputs.primPathCollection().data(), primPathCollection.data(), primPathCollection.size() * sizeof(NameToken)); } if (resourcePointerCollection.size() == 0) { return false; } db.outputs.stream() = (uint64_t)stream; internalState.previousSuccess = true; return true; } }; REGISTER_OGN_NODE() } } } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/gpu_interop/OgnRpResourceExampleHydra.cpp
// Copyright (c) 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. // // clang-format off #include "UsdPCH.h" // clang-format on #include <omni/hydra/IOmniHydra.h> #include <omni/usd/UsdContextIncludes.h> #include <omni/usd/UsdContext.h> #include <carb/graphics/GraphicsTypes.h> #include <carb/logging/Log.h> #include <cuda/include/cuda_runtime_api.h> #include <omni/graph/core/NodeTypeRegistrar.h> #include <omni/graph/core/iComputeGraph.h> #include <rtx/utils/GraphicsDescUtils.h> #include <rtx/resourcemanager/ResourceManager.h> #include <omni/kit/KitUtils.h> #include <omni/kit/renderer/IRenderer.h> #include <gpu/foundation/FoundationTypes.h> #include <omni/math/linalg/vec.h> #include "OgnRpResourceExampleHydraDatabase.h" using omni::math::linalg::vec3f; namespace omni { namespace graph { namespace core { namespace examples { class OgnRpResourceExampleHydra { public: static bool compute(OgnRpResourceExampleHydraDatabase& db) { CARB_PROFILE_ZONE(1, "OgnRpResourceExampleHydra::compute"); const bool sendToHydra = db.inputs.sendToHydra(); const bool verbose = db.inputs.verbose(); //const size_t dimension = 4; const size_t dimension = 3; const uint32_t deviceIndex = 0; rtx::resourcemanager::Context* resourceManagerContext = nullptr; rtx::resourcemanager::ResourceManager* resourceManager = nullptr; if (verbose) { if (auto renderer = carb::getCachedInterface<omni::kit::renderer::IRenderer>()) { if (auto gpuFoundation = renderer->getGpuFoundation()) { resourceManager = gpuFoundation->getResourceManager(); resourceManagerContext = gpuFoundation->getResourceManagerContext(); } } if (resourceManager == nullptr || resourceManagerContext == nullptr) { return false; } } auto& resourcePointerCollection = db.inputs.resourcePointerCollection(); auto& pointCountCollection = db.inputs.pointCountCollection(); auto& primPathCollection = db.inputs.primPathCollection(); const size_t primCount = primPathCollection.size(); if (primCount == 0 || pointCountCollection.size() != primPathCollection.size() || 2 * pointCountCollection.size() != resourcePointerCollection.size()) { return false; } rtx::resourcemanager::RpResource** rpResources = (rtx::resourcemanager::RpResource**)resourcePointerCollection.data(); const uint64_t* pointCounts = pointCountCollection.data(); const NameToken* primPaths = primPathCollection.data(); omni::usd::hydra::IOmniHydra* omniHydra = sendToHydra ? carb::getFramework()->acquireInterface<omni::usd::hydra::IOmniHydra>() : nullptr; for (size_t primIndex = 0; primIndex < primCount; primIndex++) { rtx::resourcemanager::RpResource* rpResource = rpResources[2 * primIndex + 1]; //only want deformed positions const uint64_t& pointsCount = pointCounts[primIndex]; const NameToken& primPath = primPaths[primIndex]; if (verbose) { carb::graphics::AccessFlags accessFlags = resourceManager->getResourceAccessFlags(*rpResource, deviceIndex); std::cout << "Sending to Hydra..." << std::endl; std::cout << "prim path: " << db.tokenToString(primPath) << std::endl; std::cout << "\trpResource: " << rpResource << std::endl; std::cout << "\taccessFlags: " << accessFlags << std::endl; if (accessFlags & carb::graphics::kAccessFlagUnknown) std::cout << "\t\tkAccessFlagUnknown" << std::endl; if (accessFlags & carb::graphics::kAccessFlagVertexBuffer) std::cout << "\t\tkAccessFlagVertexBuffer" << std::endl; if (accessFlags & carb::graphics::kAccessFlagIndexBuffer) std::cout << "\t\tkAccessFlagIndexBuffer" << std::endl; if (accessFlags & carb::graphics::kAccessFlagConstantBuffer) std::cout << "\t\tkAccessFlagConstantBuffer" << std::endl; if (accessFlags & carb::graphics::kAccessFlagArgumentBuffer) std::cout << "\t\tkAccessFlagArgumentBuffer" << std::endl; if (accessFlags & carb::graphics::kAccessFlagTextureRead) std::cout << "\t\tkAccessFlagTextureRead" << std::endl; if (accessFlags & carb::graphics::kAccessFlagStorageRead) std::cout << "\t\tkAccessFlagStorageRead" << std::endl; if (accessFlags & carb::graphics::kAccessFlagStorageWrite) std::cout << "\t\tkAccessFlagStorageWrite" << std::endl; if (accessFlags & carb::graphics::kAccessFlagColorAttachmentWrite) std::cout << "\t\tkAccessFlagColorAttachmentWrite" << std::endl; if (accessFlags & carb::graphics::kAccessFlagDepthStencilAttachmentWrite) std::cout << "\t\tkAccessFlagDepthStencilAttachmentWrite" << std::endl; if (accessFlags & carb::graphics::kAccessFlagDepthStencilAttachmentRead) std::cout << "\t\tkAccessFlagDepthStencilAttachmentRead" << std::endl; if (accessFlags & carb::graphics::kAccessFlagCopySource) std::cout << "\t\tkAccessFlagCopySource" << std::endl; if (accessFlags & carb::graphics::kAccessFlagCopyDestination) std::cout << "\t\tkAccessFlagCopyDestination" << std::endl; if (accessFlags & carb::graphics::kAccessFlagAccelStructRead) std::cout << "\t\tkAccessFlagAccelStructRead" << std::endl; if (accessFlags & carb::graphics::kAccessFlagAccelStructWrite) std::cout << "\t\tkAccessFlagAccelStructWrite" << std::endl; if (accessFlags & carb::graphics::kAccessFlagResolveSource) std::cout << "\t\tkAccessFlagResolveSource" << std::endl; if (accessFlags & carb::graphics::kAccessFlagResolveDestination) std::cout << "\t\tkAccessFlagResolveDestination" << std::endl; if (accessFlags & carb::graphics::kAccessFlagStorageClear) std::cout << "\t\tkAccessFlagStorageClear" << std::endl; const carb::graphics::BufferDesc* bufferDesc = resourceManager->getBufferDesc(rpResource); std::cout << "\tbufferDesc: " << bufferDesc << std::endl; if (bufferDesc != nullptr) { std::cout << "\tbuffer usage flags: " << bufferDesc->usageFlags << std::endl; if (bufferDesc->usageFlags & carb::graphics::kBufferUsageFlagNone) std::cout << "\t\tkBufferUsageFlagNone" << std::endl; if (bufferDesc->usageFlags & carb::graphics::kBufferUsageFlagShaderResource) std::cout << "\t\tkBufferUsageFlagShaderResource" << std::endl; if (bufferDesc->usageFlags & carb::graphics::kBufferUsageFlagShaderResourceStorage) std::cout << "\t\tkBufferUsageFlagShaderResourceStorage" << std::endl; if (bufferDesc->usageFlags & carb::graphics::kBufferUsageFlagVertexBuffer) std::cout << "\t\tkBufferUsageFlagVertexBuffer" << std::endl; if (bufferDesc->usageFlags & carb::graphics::kBufferUsageFlagIndexBuffer) std::cout << "\t\tkBufferUsageFlagIndexBuffer" << std::endl; if (bufferDesc->usageFlags & carb::graphics::kBufferUsageFlagConstantBuffer) std::cout << "\t\tkBufferUsageFlagConstantBuffer" << std::endl; if (bufferDesc->usageFlags & carb::graphics::kBufferUsageFlagRawOrStructuredBuffer) std::cout << "\t\tkBufferUsageFlagRawOrStructuredBuffer" << std::endl; if (bufferDesc->usageFlags & carb::graphics::kBufferUsageFlagArgumentBuffer) std::cout << "\t\tkBufferUsageFlagArgumentBuffer" << std::endl; if (bufferDesc->usageFlags & carb::graphics::kBufferUsageFlagRaytracingAccelStruct) std::cout << "\t\tkBufferUsageFlagRaytracingAccelStruct" << std::endl; if (bufferDesc->usageFlags & carb::graphics::kBufferUsageFlagRaytracingBuffer) std::cout << "\t\tkBufferUsageFlagRaytracingBuffer" << std::endl; if (bufferDesc->usageFlags & carb::graphics::kBufferUsageFlagRaytracingScratchBuffer) std::cout << "\t\tkBufferUsageFlagRaytracingScratchBuffer" << std::endl; if (bufferDesc->usageFlags & carb::graphics::kBufferUsageFlagExportShared) std::cout << "\t\tkBufferUsageFlagExportShared" << std::endl; if (bufferDesc->usageFlags & carb::graphics::kBufferUsageFlagImportShared) std::cout << "\t\tkBufferUsageFlagImportShared" << std::endl; if (bufferDesc->usageFlags & carb::graphics::kBufferUsageFlagSharedCrossAdapter) std::cout << "\t\tkBufferUsageFlagSharedCrossAdapter" << std::endl; if (bufferDesc->usageFlags & carb::graphics::kBufferUsageFlagHostMappedForeignMemory) std::cout << "\t\tkBufferUsageFlagHostMappedForeignMemory" << std::endl; if (bufferDesc->usageFlags & carb::graphics::kBufferUsageFlagConcurrentAccess) std::cout << "\t\tkBufferUsageFlagConcurrentAccess" << std::endl; if (bufferDesc->usageFlags & carb::graphics::kBufferUsageFlagVisibleCrossAdapter) std::cout << "\t\tkBufferUsageFlagVisibleCrossAdapter" << std::endl; if (bufferDesc->usageFlags & carb::graphics::kBufferUsageFlagRaytracingShaderBindingTable) std::cout << "\t\tkBufferUsageFlagRaytracingShaderBindingTable" << std::endl; std::cout << "\tbuffer size: " << bufferDesc->size << std::endl; std::cout << "\tbuffer debug name: " << bufferDesc->debugName << std::endl; std::cout << "\tbuffer ext: " << bufferDesc->ext << std::endl; } } if (sendToHydra) { omni::usd::hydra::BufferDesc desc; desc.data = (void*)rpResource; desc.elementSize = dimension * sizeof(float); desc.elementStride = dimension * sizeof(float); desc.count = pointsCount; desc.isGPUBuffer = true; desc.isDataRpResource = true; pxr::SdfPath path = pxr::SdfPath(db.tokenToString(primPath)); CARB_PROFILE_ZONE(1, "OgnRpResourceExampleHydra, sending to hydra"); omniHydra->SetPointsBuffer(pxr::SdfPath(db.tokenToString(primPath)), desc); } } return true; } }; REGISTER_OGN_NODE() } } } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/gpu_interop/OgnRpResourceExampleAllocator.ogn
{ "RpResourceExampleAllocator": { "version": 1, "description": [ "Allocate CUDA-interoperable RpResource" ], "uiName": "RpResource Example Allocator Node", "inputs": { "stream": { "type": "uint64", "description": "Pointer to the CUDA Stream", "uiName": "stream" }, "primPath": { "type": "token", "description": "Prim path input. Points and a prim path may be supplied directly as an alternative to a bundle input.", "uiName": "Prim path input" }, "points": { "type": "float[3][]", "description": "Points attribute input. Points and a prim path may be supplied directly as an alternative to a bundle input.", "uiName": "Prim Points" }, "verbose": { "type": "bool", "default": false, "description": "verbose printing", "uiName": "Verbose" }, "reload": { "type": "bool", "description": "Force RpResource reload", "default": false, "uiName": "Reload" } }, "outputs": { "resourcePointerCollection": { "type": "uint64[]", "description": [ "Pointers to RpResources ", "(two resources per prim are allocated -- one for rest positions and one for deformed positions)" ], "uiName": "Resource Pointer Collection" }, "pointCountCollection": { "type": "uint64[]", "description": [ "Point count for each prim being deformed" ], "uiName": "Point Counts" }, "primPathCollection": { "type": "token[]", "description": [ "Path for each prim being deformed" ], "uiName": "Prim Paths" }, "reload": { "type": "bool", "description": "Force RpResource reload", "default": false, "uiName": "Reload" }, "stream": { "type": "uint64", "description": "Pointer to the CUDA Stream", "uiName": "stream" } } } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/gpu_interop/OgnRpResourceExampleDeformer.cpp
// Copyright (c) 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 "OgnRpResourceExampleDeformerDatabase.h" #include <carb/graphics/GraphicsTypes.h> #include <carb/logging/Log.h> #include <cuda/include/cuda_runtime_api.h> #include <omni/graph/core/iComputeGraph.h> #include <omni/graph/core/NodeTypeRegistrar.h> #include <rtx/utils/GraphicsDescUtils.h> #include <rtx/resourcemanager/ResourceManager.h> #include <omni/kit/KitUtils.h> #include <omni/kit/renderer/IRenderer.h> #include <gpu/foundation/FoundationTypes.h> #include <omni/math/linalg/vec.h> #include <stdlib.h> #include <iostream> using omni::math::linalg::vec3f; namespace omni { namespace graph { namespace core { namespace examples { extern "C" void modifyPositions(float3* points, size_t numPoints, unsigned sequenceCounter, int displacementAxis, bool verbose, cudaStream_t stream); extern "C" void modifyPositionsSinusoidal(const float3* pointsRest, float3* pointsDeformed, size_t numPoints, unsigned sequenceCounter, float positionScale, float timeScale, float deformScale, bool verbose, cudaStream_t stream); class OgnRpResourceExampleDeformer { public: static void initialize(const GraphContextObj& context, const NodeObj& nodeObj) { // std::cout << "OgnRpResourceExampleDeformer::initialize" << std::endl; } static void release(const NodeObj& nodeObj) { // std::cout << "OgnRpResourceExampleDeformer::release" << std::endl; } static bool compute(OgnRpResourceExampleDeformerDatabase& db) { CARB_PROFILE_ZONE(1, "OgnRpResourceExampleDeformer::compute"); rtx::resourcemanager::Context* resourceManagerContext = nullptr; rtx::resourcemanager::ResourceManager* resourceManager = nullptr; const bool verbose = db.inputs.verbose(); if (auto renderer = carb::getCachedInterface<omni::kit::renderer::IRenderer>()) { if (auto gpuFoundation = renderer->getGpuFoundation()) { resourceManager = gpuFoundation->getResourceManager(); resourceManagerContext = gpuFoundation->getResourceManagerContext(); } } cudaStream_t stream = (cudaStream_t)db.inputs.stream(); if (verbose) { std::cout<<"OgnRpResourceExampleDeformer::compute -- cudaStream: "<<stream<<std::endl; } if (!stream) { db.outputs.resourcePointerCollection().resize(0); db.outputs.pointCountCollection().resize(0); db.outputs.primPathCollection().resize(0); return false; } if (resourceManager == nullptr || resourceManagerContext == nullptr) { db.outputs.resourcePointerCollection().resize(0); db.outputs.pointCountCollection().resize(0); db.outputs.primPathCollection().resize(0); return false; } auto& resourcePointerCollection = db.inputs.resourcePointerCollection(); auto& pointCountCollection = db.inputs.pointCountCollection(); auto& primPathCollection = db.inputs.primPathCollection(); const size_t primCount = primPathCollection.size(); if (primCount == 0 || pointCountCollection.size() != primPathCollection.size() || 2 * pointCountCollection.size() != resourcePointerCollection.size()) { db.outputs.resourcePointerCollection().resize(0); db.outputs.pointCountCollection().resize(0); db.outputs.primPathCollection().resize(0); return false; } bool& reloadAttr = db.outputs.reload(); auto& sequenceCounter = db.state.sequenceCounter(); if (reloadAttr) { reloadAttr = false; sequenceCounter = 0; } //const uint64_t dimension = 4; const uint64_t dimension = 3; const uint32_t deviceIndex = 0; rtx::resourcemanager::RpResource** rpResources = (rtx::resourcemanager::RpResource**)resourcePointerCollection.data(); const uint64_t* pointCounts = pointCountCollection.data(); const NameToken* primPaths = primPathCollection.data(); for (size_t primIndex = 0; primIndex < primCount; primIndex++) { rtx::resourcemanager::RpResource* rpResourceRest = rpResources[2 * primIndex]; rtx::resourcemanager::RpResource* rpResourceDeformed = rpResources[2 * primIndex + 1]; const uint64_t& pointsCount = pointCounts[primIndex]; //const NameToken& path = primPaths[primIndex]; // run some simple kernel if (verbose) { std::cout << "OgnRpResourceExampleDeformer: Modifying " << pointsCount << " positions at sequence point " << sequenceCounter << std::endl; } if (db.inputs.runDeformerKernel()) { void* cudaPtrRest = resourceManager->getCudaDevicePointer(*rpResourceRest, deviceIndex); void* cudaPtrDeformed = resourceManager->getCudaDevicePointer(*rpResourceDeformed, deviceIndex); { CARB_PROFILE_ZONE(1, "OgnRpResourceExampleDeformer::modifyPositions kernel"); modifyPositionsSinusoidal((float3*)cudaPtrRest, (float3*)cudaPtrDeformed, pointsCount, (unsigned)sequenceCounter, db.inputs.positionScale(), db.inputs.timeScale(), db.inputs.deformScale(), verbose, stream); } } } if (db.inputs.runDeformerKernel()) { sequenceCounter++; } db.outputs.resourcePointerCollection.resize(resourcePointerCollection.size()); memcpy(db.outputs.resourcePointerCollection().data(), resourcePointerCollection.data(), resourcePointerCollection.size() * sizeof(uint64_t)); db.outputs.pointCountCollection.resize(pointCountCollection.size()); memcpy(db.outputs.pointCountCollection().data(), pointCountCollection.data(), pointCountCollection.size() * sizeof(uint64_t)); db.outputs.primPathCollection.resize(primPathCollection.size()); memcpy(db.outputs.primPathCollection().data(), primPathCollection.data(), primPathCollection.size() * sizeof(NameToken)); db.outputs.stream() = (uint64_t)stream; return true; } }; REGISTER_OGN_NODE() } } } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/gpu_interop/OgnDeformedPointsToHydra.cpp
// Copyright (c) 2021-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 "OgnDeformedPointsToHydraDatabase.h" #include <carb/graphics/GraphicsTypes.h> #include <carb/logging/Log.h> #include <cuda/include/cuda_runtime_api.h> #include <omni/graph/core/iComputeGraph.h> #include <omni/graph/core/NodeTypeRegistrar.h> #include <rtx/utils/GraphicsDescUtils.h> #include <rtx/resourcemanager/ResourceManager.h> #include <omni/kit/KitUtils.h> #include <omni/kit/renderer/IRenderer.h> #include <gpu/foundation/FoundationTypes.h> #include <omni/hydra/IOmniHydra.h> #include <omni/graph/core/BundlePrims.h> #include <omni/math/linalg/vec.h> using omni::math::linalg::vec3f; using omni::graph::core::BundleAttributeInfo; using omni::graph::core::BundlePrim; using omni::graph::core::BundlePrims; using omni::graph::core::ConstBundlePrim; using omni::graph::core::ConstBundlePrims; namespace omni { namespace graph { namespace core { namespace examples { class OgnDeformedPointsToHydra { // NOTE: this node is meant only for early usage of gpu interop on a prerender graph. // Storing a pointer to an RpResource is a temporary measure that will not work in a // multi-node setting. bool previousSuccess; rtx::resourcemanager::RpResource* resourcePointer; uint64_t pointCount; NameToken primPath; public: static void initialize(const GraphContextObj& context, const NodeObj& nodeObj) { OgnDeformedPointsToHydraDatabase db(context, nodeObj); auto& internalState = db.internalState<OgnDeformedPointsToHydra>(); internalState.resourcePointer = nullptr; internalState.pointCount = 0; internalState.primPath = db.stringToToken(""); internalState.previousSuccess = false; } static void release(const NodeObj& nodeObj) { } static bool compute(OgnDeformedPointsToHydraDatabase& db) { CARB_PROFILE_ZONE(1, "OgnDeformedPointsToHydra::compute"); rtx::resourcemanager::Context* resourceManagerContext = nullptr; rtx::resourcemanager::ResourceManager* resourceManager = nullptr; auto& internalState = db.internalState<OgnDeformedPointsToHydra>(); const bool previousSuccess = internalState.previousSuccess; internalState.previousSuccess = false; const bool verbose = db.inputs.verbose(); if (db.inputs.primPath() == db.stringToToken("") || db.inputs.points.size() == 0) { return false; } bool reload = false; if (internalState.resourcePointer == nullptr || internalState.primPath != db.inputs.primPath() || internalState.pointCount != db.inputs.points.size() || !internalState.previousSuccess) { reload = true; } if (auto renderer = carb::getCachedInterface<omni::kit::renderer::IRenderer>()) { if (auto gpuFoundation = renderer->getGpuFoundation()) { resourceManager = gpuFoundation->getResourceManager(); resourceManagerContext = gpuFoundation->getResourceManagerContext(); } } cudaStream_t stream = (cudaStream_t)db.inputs.stream(); if (verbose) { std::cout<<"OgnDeformedPointsToHydra::compute -- cudaStream: "<<stream<<std::endl; } if (resourceManager == nullptr || resourceManagerContext == nullptr) { return false; } const uint32_t deviceIndex = 0; const size_t pointsCount = db.inputs.points.size(); const uint64_t dimension = 3; const uint64_t size = pointsCount * dimension * sizeof(float); if (reload) { if (internalState.resourcePointer != nullptr) { if (verbose) { std::cout << "freeing RpResource." << std::endl; } resourceManager->releaseResource(*internalState.resourcePointer); internalState.resourcePointer = nullptr; } carb::graphics::BufferUsageFlags usageFlags = carb::graphics::kBufferUsageFlagNone; usageFlags |= carb::graphics::kBufferUsageFlagShaderResourceStorage; usageFlags |= carb::graphics::kBufferUsageFlagVertexBuffer; usageFlags |= carb::graphics::kBufferUsageFlagRawOrStructuredBuffer; usageFlags |= carb::graphics::kBufferUsageFlagRaytracingBuffer; carb::graphics::BufferDesc bufferDesc = rtx::RtxBufferDesc(size, "Mesh Buffer", usageFlags); rtx::resourcemanager::ResourceDesc resourceDesc; resourceDesc.mode = rtx::resourcemanager::ResourceMode::eDefault; resourceDesc.memoryLocation = carb::graphics::MemoryLocation::eDevice; resourceDesc.category = rtx::resourcemanager::ResourceCategory::eVertexBuffer; resourceDesc.usageFlags = rtx::resourcemanager::kResourceUsageFlagCudaShared; resourceDesc.deviceMask = OMNI_ALL_DEVICES_MASK; resourceDesc.creationDeviceIndex = deviceIndex; internalState.resourcePointer = resourceManager->getResourceFromBufferDesc(*resourceManagerContext, bufferDesc, resourceDesc); internalState.pointCount = pointsCount; internalState.primPath = db.inputs.primPath(); } const float3* cudaSrc = (const float3*)(*db.inputs.points.gpu()); void* cudaDst = resourceManager->getCudaDevicePointer(*internalState.resourcePointer, deviceIndex); cudaMemcpy(cudaDst, (const void*)cudaSrc, size, cudaMemcpyDeviceToDevice); if (db.inputs.sendToHydra()) { omni::usd::hydra::IOmniHydra* omniHydra = carb::getFramework()->acquireInterface<omni::usd::hydra::IOmniHydra>(); omni::usd::hydra::BufferDesc desc; desc.data = (void*)internalState.resourcePointer; desc.elementSize = dimension * sizeof(float); desc.elementStride = dimension * sizeof(float); desc.count = pointsCount; desc.isGPUBuffer = true; desc.isDataRpResource = true; pxr::SdfPath path = pxr::SdfPath(db.tokenToString(internalState.primPath)); CARB_PROFILE_ZONE(1, "OgnRpResourceToHydra_Arrays, sending to hydra"); omniHydra->SetPointsBuffer(pxr::SdfPath(db.tokenToString(internalState.primPath)), desc); } internalState.previousSuccess = true; return true; } }; REGISTER_OGN_NODE() } } } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/gpu_interop/OgnDeformedPointsToHydra.ogn
{ "DeformedPointsToHydra": { "version": 1, "description": [ "Copy deformed points into rpresource and send to hydra" ], "uiName": "Deformed Points to Hydra", "cudaPointers": "cpu", "inputs": { "stream": { "type": "uint64", "description": "Pointer to the CUDA Stream", "uiName": "stream" }, "primPath": { "type": "token", "description": "Prim path input. Points and a prim path may be supplied directly as an alternative to a bundle input.", "uiName": "Prim path input" }, "points": { "type": "float[3][]", "memoryType": "cuda", "description": "Points attribute input. Points and a prim path may be supplied directly as an alternative to a bundle input.", "uiName": "Prim Points" }, "verbose": { "type": "bool", "default": false, "description": "verbose printing", "uiName": "Verbose" }, "sendToHydra": { "type": "bool", "default": false, "description": "send to hydra", "uiName": "Send to hydra" } }, "outputs": { "reload": { "type": "bool", "description": "Force RpResource reload", "default": false, "uiName": "Reload" } } } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/gpu_interop/OgnRpResourceExampleDeformer.ogn
{ "RpResourceExampleDeformer": { "version": 1, "description": [ "Allocate CUDA-interoperable RpResource" ], "uiName": "RpResource Example Deformer Node", "inputs": { "stream": { "type": "uint64", "description": "Pointer to the CUDA Stream", "uiName": "stream" }, "resourcePointerCollection": { "type": "uint64[]", "description": [ "Pointer to RpResource collection" ], "uiName": "Resource Pointer Collection" }, "pointCountCollection": { "type": "uint64[]", "description": [ "Pointer to point counts collection" ], "uiName": "Point Counts" }, "primPathCollection": { "type": "token[]", "description": [ "Pointer to prim path collection" ], "uiName": "Prim Paths" }, "verbose": { "type": "bool", "default": false, "description": "verbose printing", "uiName": "Verbose" }, "displacementAxis": { "type": "int", "default": 0, "description": "dimension in which mesh is translated", "uiName": "Displacement Axis" }, "runDeformerKernel": { "type": "bool", "default": true, "description": "Whether cuda kernel will be executed", "uiName": "Run Deformer" }, "timeScale": { "type": "float", "default": 0.01, "description": "Deformation control", "uiName": "Time Scale" }, "positionScale": { "type": "float", "default": 1.0, "description": "Deformation control", "uiName": "Position Scale" }, "deformScale": { "type": "float", "default": 1.0, "description": "Deformation control", "uiName": "Deform Scale" } }, "outputs": { "stream": { "type": "uint64", "description": "Pointer to the CUDA Stream", "uiName": "stream" }, "resourcePointerCollection": { "type": "uint64[]", "description": [ "Pointers to RpResources ", "(two resources per prim are assumed -- one for rest positions and one for deformed positions)" ], "uiName": "Resource Pointer Collection" }, "pointCountCollection": { "type": "uint64[]", "description": [ "Point count for each prim being deformed" ], "uiName": "Point Counts" }, "primPathCollection": { "type": "token[]", "description": [ "Path for each prim being deformed" ], "uiName": "Prim Paths" }, "reload": { "type": "bool", "description": "Force RpResource reload", "default": false, "uiName": "Reload" } }, "state": { "sequenceCounter": { "type": "uint64", "description": "tick counter for animation", "default": 0 } }, "tokens": { "points": "points", "transform": "transform", "rpResource": "rpResource", "pointCount": "pointCount", "primPath": "primPath", "testToken": "testToken", "uintData": "uintData" } } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/gpu_interop/OgnRpResourceExampleHydra.ogn
{ "RpResourceExampleHydra": { "version": 1, "description": [ "Send RpResource to Hydra" ], "uiName": "RpResource to Hydra Example Node", "inputs": { "verbose": { "type": "bool", "default": false, "description": "verbose printing", "uiName": "Verbose" }, "sendToHydra": { "type": "bool", "default": false, "description": "Send rpresource pointer to hydra using the specified prim path", "uiName": "Send to Hydra" }, "resourcePointerCollection": { "type": "uint64[]", "description": [ "Pointers to RpResources ", "(two resources per prim are assumed -- one for rest positions and one for deformed positions)" ], "uiName": "Resource Pointer Collection" }, "pointCountCollection": { "type": "uint64[]", "description": [ "Point count for each prim being deformed" ], "uiName": "Point Counts" }, "primPathCollection": { "type": "token[]", "description": [ "Path for each prim being deformed" ], "uiName": "Prim Paths" } }, "outputs": { "reload": { "type": "bool", "description": "Force RpResource reload", "default": false, "uiName": "Reload" } }, "tokens": { "points": "points", "transform": "transform", "rpResource": "rpResource", "pointCount": "pointCount", "uintData": "uintData" } } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/animation/OgnTimelineLoop.ogn
{ "LoopTimeline": { "version": 1, "description": "Controls looping playback of the main timeline", "metadata": { "uiName": "Set playback looping" }, "categories": [ "time" ], "scheduling": "compute-on-request", "inputs": { "execIn": { "type": "execution", "description": "The input that triggers the execution of this node.", "uiName": "Execute In" }, "loop": { "type": "bool", "description": "Enable or disable playback looping?", "uiName": "Loop" } }, "outputs": { "execOut": { "type": "execution", "description": "The output that is triggered when this node executed.", "uiName": "Execute Out" } } } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/animation/OgnTimelineStart.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 "TimelineCommon.h" #include <omni/timeline/ITimeline.h> #include <OgnTimelineStartDatabase.h> namespace omni { namespace graph { namespace nodes { class OgnTimelineStart { public: static bool compute(OgnTimelineStartDatabase& db) { auto handler = [](timeline::TimelinePtr const& timeline) { timeline->play(); return true; }; return timelineNodeExecute(db, handler); } }; REGISTER_OGN_NODE() } } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/animation/OgnTimer.ogn
{ "omni.graph.nodes.Timer": { "version": 2, "description": [ "Timer Node is a node that lets you create animation curve(s), plays back and samples the value(s) along its time to output values." ], "metadata": { "uiName": "Timer" }, "categories": {"animation": "Nodes dealing with Animation"}, "inputs": { "startValue": { "type": "double", "description": "Value value of the start of the duration", "uiName": "Start Value", "minimum": 0.0, "maximum": 1.0, "default": 0.0 }, "endValue": { "type": "double", "description": "Value value of the end of the duration", "uiName": "End Value", "minimum": 0.0, "maximum": 1.0, "default": 1.0 }, "duration": { "type": "double", "description": "Number of seconds to play interpolation", "uiName": "Duration", "default": 1.0 }, "play": { "type": "execution", "description": "Play the clip from current frame", "uiName": "Play" } }, "outputs": { "value": { "type": "double", "description": "Value value of the Timer node between 0.0 and 1.0", "uiName": "Value", "default": 0.0 }, "updated": { "type": "execution", "description": "The Timer node is ticked, and output value(s) resampled and updated", "uiName": "Updated" }, "finished": { "type": "execution", "description": "The Timer node has finished the playback", "uiName": "Finished" } } } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/animation/OgnTimelineGet.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 "TimelineCommon.h" #include <omni/timeline/ITimeline.h> #include <OgnTimelineGetDatabase.h> namespace omni { namespace graph { namespace nodes { class OgnTimelineGet { public: static bool compute(OgnTimelineGetDatabase& db) { auto handler = [&db](timeline::TimelinePtr const& timeline) { db.outputs.isLooping() = timeline->isLooping(); db.outputs.isPlaying() = timeline->isPlaying(); double const currentTime = timeline->getCurrentTime(); double const startTime = timeline->getStartTime(); double const endTime = timeline->getEndTime(); db.outputs.time() = currentTime; db.outputs.startTime() = startTime; db.outputs.endTime() = endTime; db.outputs.frame() = timeline->timeToTimeCode(currentTime); db.outputs.startFrame() = timeline->timeToTimeCode(startTime); db.outputs.endFrame() = timeline->timeToTimeCode(endTime); db.outputs.framesPerSecond() = timeline->getTimeCodesPerSecond(); // TODO: Should we return false when the outputs didn't change? return true; }; return timelineNodeEvaluate(db, handler); } }; REGISTER_OGN_NODE() } } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/animation/OgnInterpolator.ogn
{ "Interpolator": { "version": 1, "description": "Time sample interpolator", "metadata": { "uiName": "Interpolator" }, "categories": ["math:operator"], "scheduling": ["threadsafe"], "inputs": { "param": { "type": "float", "description": "Time sample interpolation point", "metadata": { "uiName": "Interpolation Point" } }, "knots": { "type": "float[]", "description": "Array of knots on the time sample curve", "metadata": { "uiName": "Knot Array" } }, "values": { "type": "float[]", "description": "Array of time sample values", "metadata": { "uiName": "Value Array" } } }, "outputs": { "value": { "type": "float", "description": "Value in the time samples, interpolated at the given parameter location", "metadata": { "uiName": "Interpolated Value" } } }, "tests": [ { "inputs:knots": [1.0, 2.0], "inputs:values": [3.0, 4.0], "inputs:param": 1.5, "outputs:value": 3.5 }, { "inputs:knots": [1.0, 2.0], "inputs:values": [3.0, 4.0], "inputs:param": 1.0, "outputs:value": 3.0 }, { "inputs:knots": [1.0, 2.0], "inputs:values": [3.0, 4.0], "inputs:param": 2.0, "outputs:value": 4.0 }, { "inputs:knots": [1.0, 2.0], "inputs:values": [3.0, 4.0], "inputs:param": 0.5, "outputs:value": 3.0 }, { "inputs:knots": [1.0, 2.0], "inputs:values": [3.0, 4.0], "inputs:param": 2.5, "outputs:value": 4.0 } ] } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/animation/OgnTimer.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 "PrimCommon.h" #include <OgnTimerDatabase.h> using namespace pxr; using DB = OgnTimerDatabase; namespace omni::graph::nodes { namespace { constexpr double kUninitializedStartTime = -1.; } enum TimeState : uint32_t { kTimeStateInit, kTimeStateStart, kTimeStatePlay, kTimeStateLast, kTimeStateFinish }; class OgnTimer { double m_startTime{ kUninitializedStartTime }; // The value of the context time when we started latent state TimeState m_timeState{ kTimeStateInit }; public: static bool compute(DB& db) { const auto& contextObj = db.abi_context(); auto iContext = contextObj.iContext; double now = iContext->getTimeSinceStart(contextObj); auto& state = db.internalState<OgnTimer>(); auto& timeState = state.m_timeState; auto& startTime = state.m_startTime; const double duration = std::max(db.inputs.duration(), 1.0e-6); const double startValue = db.inputs.startValue(); const double endValue = db.inputs.endValue(); switch (timeState) { case kTimeStateInit: { timeState = kTimeStateStart; db.outputs.finished() = kExecutionAttributeStateLatentPush; break; } case kTimeStateStart: { startTime = now; timeState = kTimeStatePlay; // Do not break here, we want to fall through to the next case } case kTimeStatePlay: { double deltaTime = now - startTime; double value = startValue + (endValue - startValue) * deltaTime / duration; value = std::min(value, 1.0); db.outputs.value() = value; if (deltaTime >= duration) { timeState = kTimeStateLast; } else { db.outputs.updated() = kExecutionAttributeStateEnabled; } break; } case kTimeStateLast: { timeState = kTimeStateFinish; db.outputs.value() = endValue; db.outputs.updated() = kExecutionAttributeStateEnabled; break; } case kTimeStateFinish: { startTime = kUninitializedStartTime; timeState = kTimeStateInit; db.outputs.finished() = kExecutionAttributeStateLatentFinish; break; } } return true; } }; REGISTER_OGN_NODE() }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/animation/OgnTimelineSet.ogn
{ "SetTimeline": { "version": 1, "description": "Set properties of the main timeline", "metadata": { "uiName": "Set main timeline" }, "categories": [ "time" ], "scheduling": "compute-on-request", "inputs": { "execIn": { "type": "execution", "description": "The input that triggers the execution of this node.", "uiName": "Execute In" }, "propValue": { "type": "double", "description": "The value of the property to set.", "uiName": "Property Value" }, "propName": { "type": "token", "description": "The name of the property to set.", "uiName": "Property Name", "default": "Frame", "metadata": { "displayGroup": "parameters", "literalOnly": "1", "allowedTokens": [ "Frame", "Time", "StartFrame", "StartTime", "EndFrame", "EndTime", "FramesPerSecond" ] } } }, "outputs": { "clamped": { "type": "bool", "description": "Was the input frame or time clamped to the playback range?", "uiName": "Clamp to range" }, "execOut": { "type": "execution", "description": "The output that is triggered when this node executed.", "uiName": "Execute Out" } } } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/animation/OgnInterpolator.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 <OgnInterpolatorDatabase.h> namespace omni { namespace graph { namespace nodes { inline float computeInterpolation(size_t numSamples, const float* knots, const float* values, const float& param) { // do really simple search for now for (size_t i = 0; i < numSamples - 1; i++) { float knot = knots[i]; float knotNext = knots[i + 1]; float value = values[i]; float valueNext = values[i + 1]; if (param < knot) return value; if (param <= knotNext) { float interpolant = (param - knot) / (knotNext - knot); float interpolatedValue = interpolant * valueNext + (1.0f - interpolant) * value; return interpolatedValue; } } return values[numSamples - 1]; } class OgnInterpolator { public: static bool compute(OgnInterpolatorDatabase& db) { const auto& inputKnots = db.inputs.knots(); const auto& inputValues = db.inputs.values(); size_t numSamples = inputValues.size(); if (inputKnots.size() != numSamples) { db.logWarning("Knots size %zu does not match value size %zu, skipping evaluation", inputKnots.size(), numSamples); return false; } if (numSamples > 0) { db.outputs.value() = computeInterpolation(numSamples, inputKnots.data(), inputValues.data(), db.inputs.param()); } return true; } }; REGISTER_OGN_NODE() } } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/animation/OgnTimelineStart.ogn
{ "StartTimeline": { "version": 1, "description": "Starts playback of the main timeline at the current frame", "metadata": { "uiName": "Start playback" }, "categories": [ "time" ], "scheduling": "compute-on-request", "inputs": { "execIn": { "type": "execution", "description": "The input that triggers the execution of this node.", "uiName": "Execute In" } }, "outputs": { "execOut": { "type": "execution", "description": "The output that is triggered when this node executed.", "uiName": "Execute Out" } } } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/animation/OgnTimelineStop.ogn
{ "StopTimeline": { "version": 1, "description": "Stops playback of the main timeline at the current frame", "metadata": { "uiName": "Stop playback" }, "categories": [ "time" ], "scheduling": "compute-on-request", "inputs": { "execIn": { "type": "execution", "description": "The input that triggers the execution of this node.", "uiName": "Execute In" } }, "outputs": { "execOut": { "type": "execution", "description": "The output that is triggered when this node executed.", "uiName": "Execute Out" } } } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/animation/OgnTimelineStop.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 "TimelineCommon.h" #include <omni/timeline/ITimeline.h> #include <OgnTimelineStopDatabase.h> namespace omni { namespace graph { namespace nodes { class OgnTimelineStop { public: static bool compute(OgnTimelineStopDatabase& db) { auto handler = [](timeline::TimelinePtr const& timeline) { // Pause stops at the current frame, stop resets time timeline->pause(); return true; }; return timelineNodeExecute(db, handler); } }; REGISTER_OGN_NODE() } } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/animation/OgnTimelineSet.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 "TimelineCommon.h" #include <omni/timeline/ITimeline.h> #include <OgnTimelineSetDatabase.h> namespace omni { namespace graph { namespace nodes { class OgnTimelineSet { public: static bool compute(OgnTimelineSetDatabase& db) { auto handler = [&db](timeline::TimelinePtr const& timeline) { auto const value = db.inputs.propValue(); bool clamped = false; auto setTime = [&timeline](double desiredTime) -> bool { auto const startTime = timeline->getStartTime(); auto const endTime = timeline->getEndTime(); auto const clampedTime = std::clamp(desiredTime, startTime, endTime); timeline->setCurrentTime(clampedTime); return clampedTime != desiredTime; // NOLINT(clang-diagnostic-float-equal) }; auto const propName = db.inputs.propName(); if (propName == OgnTimelineSetDatabase::tokens.Time) clamped = setTime(value); else if (propName == OgnTimelineSetDatabase::tokens.StartTime) timeline->setStartTime(value); else if (propName == OgnTimelineSetDatabase::tokens.EndTime) timeline->setEndTime(value); else if (propName == OgnTimelineSetDatabase::tokens.FramesPerSecond) timeline->setTimeCodesPerSecond(value); else { // The property to set is frame-based, convert to time in seconds. auto const time = timeline->timeCodeToTime(value); if (propName == OgnTimelineSetDatabase::tokens.Frame) clamped = setTime(time); else if (propName == OgnTimelineSetDatabase::tokens.StartFrame) timeline->setStartTime(time); else if (propName == OgnTimelineSetDatabase::tokens.EndFrame) timeline->setEndTime(time); } db.outputs.clamped() = clamped; return true; }; return timelineNodeExecute(db, handler); } }; REGISTER_OGN_NODE() } } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/animation/OgnTimelineGet.ogn
{ "GetTimeline": { "version": 1, "description": "Get the main timeline properties", "metadata": { "uiName": "Get main timeline" }, "categories": [ "time" ], "scheduling": "compute-on-request", "outputs": { "isPlaying": { "type": "bool", "uiName": "Is Playing", "description": "Is the main timeline currently playing?" }, "isLooping": { "type": "bool", "uiName": "Is Looping", "description": "Is the main timeline currently looping?" }, "time": { "type": "double", "uiName": "Current Time", "description": "The current time (in seconds) of the main timeline's playhead." }, "frame": { "type": "double", "uiName": "Current Frame", "description": "The current frame number of the main timeline's playhead." }, "framesPerSecond": { "type": "double", "uiName": "Frames Per Second", "description": "The number of frames per second of the main timeline." }, "startTime": { "type": "double", "uiName": "Start Time", "description": "The start time (in seconds) of the main timeline's play range." }, "startFrame": { "type": "double", "uiName": "Start Frame", "description": "The start frame of the main timeline's play range." }, "endTime": { "type": "double", "uiName": "End Time", "description": "The end time (in seconds) of the main timeline's play range." }, "endFrame": { "type": "double", "uiName": "End Frame", "description": "The end frame of the main timeline's play range." } } } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/animation/OgnTimelineLoop.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 "TimelineCommon.h" #include <omni/timeline/ITimeline.h> #include <OgnTimelineLoopDatabase.h> namespace omni { namespace graph { namespace nodes { class OgnTimelineLoop { public: static bool compute(OgnTimelineLoopDatabase& db) { auto handler = [&db](timeline::TimelinePtr const& timeline) { auto const loop = db.inputs.loop(); timeline->setLooping(loop); return true; }; return timelineNodeExecute(db, handler); } }; REGISTER_OGN_NODE() } } }
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnArrayResize.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): TEST_DATA = [ { 'inputs': [ ['inputs:array', {'type': 'int[]', 'value': [41, 42]}, False], ['inputs:newSize', 0, False], ], 'outputs': [ ['outputs:array', {'type': 'int[]', 'value': []}, False], ], }, { 'inputs': [ ['inputs:array', {'type': 'int64[]', 'value': []}, False], ['inputs:newSize', 1, False], ], 'outputs': [ ['outputs:array', {'type': 'int64[]', 'value': [0]}, False], ], }, { 'inputs': [ ['inputs:array', {'type': 'int[]', 'value': [41, 42]}, False], ['inputs:newSize', 1, False], ], 'outputs': [ ['outputs:array', {'type': 'int[]', 'value': [41]}, False], ], }, { 'inputs': [ ['inputs:array', {'type': 'bool[]', 'value': [True, True]}, False], ['inputs:newSize', 1, False], ], 'outputs': [ ['outputs:array', {'type': 'bool[]', 'value': [True]}, False], ], }, { 'inputs': [ ['inputs:array', {'type': 'half[2][]', 'value': [[1, 2], [3, 4]]}, False], ['inputs:newSize', 3, False], ], 'outputs': [ ['outputs:array', {'type': 'half[2][]', 'value': [[1, 2], [3, 4], [0, 0]]}, False], ], }, { 'inputs': [ ['inputs:array', {'type': 'half[2][]', 'value': []}, False], ['inputs:newSize', 1, False], ], 'outputs': [ ['outputs:array', {'type': 'half[2][]', 'value': [[0, 0]]}, False], ], }, { 'inputs': [ ['inputs:array', {'type': 'float[2][]', 'value': [[1, 2], [3, 4]]}, False], ['inputs:newSize', 3, False], ], 'outputs': [ ['outputs:array', {'type': 'float[2][]', 'value': [[1, 2], [3, 4], [0, 0]]}, False], ], }, { 'inputs': [ ['inputs:array', {'type': 'token[]', 'value': ['41', '42']}, False], ['inputs:newSize', 1, False], ], 'outputs': [ ['outputs:array', {'type': 'token[]', 'value': ['41']}, False], ], }, { 'inputs': [ ['inputs:array', {'type': 'token[]', 'value': ['41', '42']}, False], ['inputs:newSize', 2, False], ], 'outputs': [ ['outputs:array', {'type': 'token[]', 'value': ['41', '42']}, False], ], }, ] async def test_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_ArrayResize", "omni.graph.nodes.ArrayResize", test_run, test_info) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.ArrayResize User test case #{i+1}") async def test_vectorized_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_ArrayResize","omni.graph.nodes.ArrayResize", test_run, test_info, 16) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.ArrayResize User test case #{i+1}", 16) async def test_thread_safety(self): import omni.kit # Generate multiple instances of the test setup to run them concurrently instance_setup = dict() for n in range(24): instance_setup[f"/TestGraph_{n}"] = _TestGraphAndNode() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) for (key, test_info) in instance_setup.items(): test_info = await _test_setup_scene(self, og.Controller(allow_exists_prim=True), key, "TestNode_omni_graph_nodes_ArrayResize", "omni.graph.nodes.ArrayResize", test_run, test_info) self.assertEqual(len(og.get_all_graphs()), 24) # We want to evaluate all graphs concurrently. Kick them all. # Evaluate multiple times to skip 2 serial frames and increase chances for a race condition. for _ in range(10): await omni.kit.app.get_app().next_update_async() for (key, test_instance) in instance_setup.items(): _test_verify_scene(self, og.Controller(), test_run, test_info, f"omni.graph.nodes.ArrayResize User test case #{i+1}, instance{key}") async def test_data_access(self): from omni.graph.nodes.ogn.OgnArrayResizeDatabase import OgnArrayResizeDatabase test_file_name = "OgnArrayResizeTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_ArrayResize") database = OgnArrayResizeDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:newSize")) attribute = test_node.get_attribute("inputs:newSize") db_value = database.inputs.newSize expected_value = 0 actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False))
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnNand.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): TEST_DATA = [ { 'inputs': [ ['inputs:a', {'type': 'bool', 'value': False}, False], ['inputs:b', {'type': 'bool', 'value': True}, False], ], 'outputs': [ ['outputs:result', True, False], ], }, { 'inputs': [ ['inputs:a', {'type': 'bool[]', 'value': [False, False, True, True]}, False], ['inputs:b', {'type': 'bool[]', 'value': [False, True, False, True]}, False], ], 'outputs': [ ['outputs:result', [True, True, True, False], False], ], }, { 'inputs': [ ['inputs:a', {'type': 'bool', 'value': False}, False], ['inputs:b', {'type': 'bool[]', 'value': [False, True]}, False], ], 'outputs': [ ['outputs:result', [True, True], False], ], }, { 'inputs': [ ['inputs:a', {'type': 'bool[]', 'value': [False, True]}, False], ['inputs:b', {'type': 'bool', 'value': False}, False], ], 'outputs': [ ['outputs:result', [True, True], False], ], }, ] async def test_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_BooleanNand", "omni.graph.nodes.BooleanNand", test_run, test_info) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.BooleanNand User test case #{i+1}") async def test_vectorized_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_BooleanNand","omni.graph.nodes.BooleanNand", test_run, test_info, 16) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.BooleanNand User test case #{i+1}", 16) async def test_thread_safety(self): import omni.kit # Generate multiple instances of the test setup to run them concurrently instance_setup = dict() for n in range(24): instance_setup[f"/TestGraph_{n}"] = _TestGraphAndNode() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) for (key, test_info) in instance_setup.items(): test_info = await _test_setup_scene(self, og.Controller(allow_exists_prim=True), key, "TestNode_omni_graph_nodes_BooleanNand", "omni.graph.nodes.BooleanNand", test_run, test_info) self.assertEqual(len(og.get_all_graphs()), 24) # We want to evaluate all graphs concurrently. Kick them all. # Evaluate multiple times to skip 2 serial frames and increase chances for a race condition. for _ in range(10): await omni.kit.app.get_app().next_update_async() for (key, test_instance) in instance_setup.items(): _test_verify_scene(self, og.Controller(), test_run, test_info, f"omni.graph.nodes.BooleanNand User test case #{i+1}, instance{key}") async def test_data_access(self): from omni.graph.nodes.ogn.OgnNandDatabase import OgnNandDatabase test_file_name = "OgnNandTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_BooleanNand") database = OgnNandDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 2) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error"
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnStopSound.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnStopSoundDatabase import OgnStopSoundDatabase test_file_name = "OgnStopSoundTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_StopSound") database = OgnStopSoundDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:execIn")) attribute = test_node.get_attribute("inputs:execIn") db_value = database.inputs.execIn self.assertTrue(test_node.get_attribute_exists("inputs:soundId")) attribute = test_node.get_attribute("inputs:soundId") db_value = database.inputs.soundId expected_value = 0 actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("outputs:execOut")) attribute = test_node.get_attribute("outputs:execOut") db_value = database.outputs.execOut
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnExtractPrim.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnExtractPrimDatabase import OgnExtractPrimDatabase test_file_name = "OgnExtractPrimTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_ExtractPrim") database = OgnExtractPrimDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:prim")) attribute = test_node.get_attribute("inputs:prim") db_value = database.inputs.prim self.assertTrue(test_node.get_attribute_exists("inputs:primPath")) attribute = test_node.get_attribute("inputs:primPath") db_value = database.inputs.primPath expected_value = "" actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:prims")) attribute = test_node.get_attribute("inputs:prims") db_value = database.inputs.prims self.assertTrue(test_node.get_attribute_exists("outputs_primBundle")) attribute = test_node.get_attribute("outputs_primBundle") db_value = database.outputs.primBundle
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnArraySetIndex.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): TEST_DATA = [ { 'inputs': [ ['inputs:array', {'type': 'int[]', 'value': [41, 42]}, False], ['inputs:index', 0, False], ['inputs:value', {'type': 'int', 'value': 0}, False], ], 'outputs': [ ['outputs:array', {'type': 'int[]', 'value': [0, 42]}, False], ], }, { 'inputs': [ ['inputs:array', {'type': 'int64[]', 'value': [41, 42]}, False], ['inputs:index', 0, False], ['inputs:value', {'type': 'int64', 'value': 0}, False], ], 'outputs': [ ['outputs:array', {'type': 'int64[]', 'value': [0, 42]}, False], ], }, { 'inputs': [ ['inputs:array', {'type': 'uchar[]', 'value': [41, 42]}, False], ['inputs:index', 0, False], ['inputs:value', {'type': 'uchar', 'value': 0}, False], ], 'outputs': [ ['outputs:array', {'type': 'uchar[]', 'value': [0, 42]}, False], ], }, { 'inputs': [ ['inputs:array', {'type': 'uint[]', 'value': [41, 42]}, False], ['inputs:index', 0, False], ['inputs:value', {'type': 'uint', 'value': 0}, False], ], 'outputs': [ ['outputs:array', {'type': 'uint[]', 'value': [0, 42]}, False], ], }, { 'inputs': [ ['inputs:array', {'type': 'uint64[]', 'value': [41, 42]}, False], ['inputs:index', 0, False], ['inputs:value', {'type': 'uint64', 'value': 0}, False], ], 'outputs': [ ['outputs:array', {'type': 'uint64[]', 'value': [0, 42]}, False], ], }, { 'inputs': [ ['inputs:array', {'type': 'bool[]', 'value': [True, True]}, False], ['inputs:index', 0, False], ['inputs:value', {'type': 'bool', 'value': False}, False], ], 'outputs': [ ['outputs:array', {'type': 'bool[]', 'value': [False, True]}, False], ], }, { 'inputs': [ ['inputs:array', {'type': 'token[]', 'value': ['41', '42']}, False], ['inputs:index', -1, False], ['inputs:value', {'type': 'token', 'value': ''}, False], ], 'outputs': [ ['outputs:array', {'type': 'token[]', 'value': ['41', '']}, False], ], }, { 'inputs': [ ['inputs:array', {'type': 'half[2][]', 'value': [[1.0, 2.0], [3.0, 4.0]]}, False], ['inputs:index', 3, False], ['inputs:resizeToFit', True, False], ['inputs:value', {'type': 'half[2]', 'value': [5.0, 6.0]}, False], ], 'outputs': [ ['outputs:array', {'type': 'half[2][]', 'value': [[1.0, 2.0], [3.0, 4.0], [0.0, 0.0], [5.0, 6.0]]}, False], ], }, { 'inputs': [ ['inputs:array', {'type': 'float[2][]', 'value': [[1.0, 2.0], [3.0, 4.0]]}, False], ['inputs:index', 3, False], ['inputs:resizeToFit', True, False], ['inputs:value', {'type': 'float[2]', 'value': [5.0, 6.0]}, False], ], 'outputs': [ ['outputs:array', {'type': 'float[2][]', 'value': [[1.0, 2.0], [3.0, 4.0], [0.0, 0.0], [5.0, 6.0]]}, False], ], }, { 'inputs': [ ['inputs:array', {'type': 'double[3][]', 'value': [[1.0, 2.0, 3.0], [3.0, 4.0, 5.0]]}, False], ['inputs:index', 3, False], ['inputs:resizeToFit', True, False], ['inputs:value', {'type': 'double[3]', 'value': [5.0, 6.0, 7.0]}, False], ], 'outputs': [ ['outputs:array', {'type': 'double[3][]', 'value': [[1.0, 2.0, 3.0], [3.0, 4.0, 5.0], [0.0, 0.0, 0.0], [5.0, 6.0, 7.0]]}, False], ], }, { 'inputs': [ ['inputs:array', {'type': 'int[4][]', 'value': [[1, 2, 3, 4], [3, 4, 5, 6]]}, False], ['inputs:index', 3, False], ['inputs:resizeToFit', True, False], ['inputs:value', {'type': 'int[4]', 'value': [5, 6, 7, 8]}, False], ], 'outputs': [ ['outputs:array', {'type': 'int[4][]', 'value': [[1, 2, 3, 4], [3, 4, 5, 6], [0, 0, 0, 0], [5, 6, 7, 8]]}, False], ], }, { 'inputs': [ ['inputs:array', {'type': 'token[]', 'value': ['41', '42']}, False], ['inputs:index', 3, False], ['inputs:resizeToFit', True, False], ['inputs:value', {'type': 'token', 'value': '43'}, False], ], 'outputs': [ ['outputs:array', {'type': 'token[]', 'value': ['41', '42', '', '43']}, False], ], }, ] async def test_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_ArraySetIndex", "omni.graph.nodes.ArraySetIndex", test_run, test_info) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.ArraySetIndex User test case #{i+1}") async def test_vectorized_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_ArraySetIndex","omni.graph.nodes.ArraySetIndex", test_run, test_info, 16) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.ArraySetIndex User test case #{i+1}", 16) async def test_thread_safety(self): import omni.kit # Generate multiple instances of the test setup to run them concurrently instance_setup = dict() for n in range(24): instance_setup[f"/TestGraph_{n}"] = _TestGraphAndNode() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) for (key, test_info) in instance_setup.items(): test_info = await _test_setup_scene(self, og.Controller(allow_exists_prim=True), key, "TestNode_omni_graph_nodes_ArraySetIndex", "omni.graph.nodes.ArraySetIndex", test_run, test_info) self.assertEqual(len(og.get_all_graphs()), 24) # We want to evaluate all graphs concurrently. Kick them all. # Evaluate multiple times to skip 2 serial frames and increase chances for a race condition. for _ in range(10): await omni.kit.app.get_app().next_update_async() for (key, test_instance) in instance_setup.items(): _test_verify_scene(self, og.Controller(), test_run, test_info, f"omni.graph.nodes.ArraySetIndex User test case #{i+1}, instance{key}") async def test_data_access(self): from omni.graph.nodes.ogn.OgnArraySetIndexDatabase import OgnArraySetIndexDatabase test_file_name = "OgnArraySetIndexTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_ArraySetIndex") database = OgnArraySetIndexDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:index")) attribute = test_node.get_attribute("inputs:index") db_value = database.inputs.index expected_value = 0 actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:resizeToFit")) attribute = test_node.get_attribute("inputs:resizeToFit") db_value = database.inputs.resizeToFit expected_value = False actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False))
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnRound.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): TEST_DATA = [ { 'inputs': [ ['inputs:input', {'type': 'float', 'value': 1.3}, False], ['inputs:decimals', 0, False], ], 'outputs': [ ['outputs:output', {'type': 'float', 'value': 1}, False], ], }, { 'inputs': [ ['inputs:input', {'type': 'double', 'value': 1.3}, False], ['inputs:decimals', 0, False], ], 'outputs': [ ['outputs:output', {'type': 'double', 'value': 1}, False], ], }, { 'inputs': [ ['inputs:input', {'type': 'half', 'value': 1.3}, False], ['inputs:decimals', 0, False], ], 'outputs': [ ['outputs:output', {'type': 'half', 'value': 1}, False], ], }, { 'inputs': [ ['inputs:input', {'type': 'float[2]', 'value': [-3.5352, 4.341]}, False], ['inputs:decimals', 2, False], ], 'outputs': [ ['outputs:output', {'type': 'float[2]', 'value': [-3.54, 4.34]}, False], ], }, { 'inputs': [ ['inputs:input', {'type': 'double[3]', 'value': [-3.5352, 4.341, -3.5352]}, False], ['inputs:decimals', 2, False], ], 'outputs': [ ['outputs:output', {'type': 'double[3]', 'value': [-3.54, 4.34, -3.54]}, False], ], }, { 'inputs': [ ['inputs:input', {'type': 'half[4]', 'value': [-3.5352, 4.341, -3.5352, 4.341]}, False], ['inputs:decimals', 2, False], ], 'outputs': [ ['outputs:output', {'type': 'half[4]', 'value': [-3.5390625, 4.3398438, -3.5390625, 4.3398438]}, False], ], }, { 'inputs': [ ['inputs:input', {'type': 'double[]', 'value': [132, 22221.2, 5.531]}, False], ['inputs:decimals', -1, False], ], 'outputs': [ ['outputs:output', {'type': 'double[]', 'value': [130, 22220, 10]}, False], ], }, { 'inputs': [ ['inputs:input', {'type': 'float[]', 'value': [132]}, False], ['inputs:decimals', -1, False], ], 'outputs': [ ['outputs:output', {'type': 'float[]', 'value': [130]}, False], ], }, { 'inputs': [ ['inputs:input', {'type': 'half[2][]', 'value': [[132, 22221.2], [5.531, 132]]}, False], ['inputs:decimals', -1, False], ], 'outputs': [ ['outputs:output', {'type': 'half[2][]', 'value': [[130.0, 22224.0], [10.0, 130.0]]}, False], ], }, ] async def test_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_Round", "omni.graph.nodes.Round", test_run, test_info) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.Round User test case #{i+1}") async def test_vectorized_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_Round","omni.graph.nodes.Round", test_run, test_info, 16) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.Round User test case #{i+1}", 16) async def test_thread_safety(self): import omni.kit # Generate multiple instances of the test setup to run them concurrently instance_setup = dict() for n in range(24): instance_setup[f"/TestGraph_{n}"] = _TestGraphAndNode() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) for (key, test_info) in instance_setup.items(): test_info = await _test_setup_scene(self, og.Controller(allow_exists_prim=True), key, "TestNode_omni_graph_nodes_Round", "omni.graph.nodes.Round", test_run, test_info) self.assertEqual(len(og.get_all_graphs()), 24) # We want to evaluate all graphs concurrently. Kick them all. # Evaluate multiple times to skip 2 serial frames and increase chances for a race condition. for _ in range(10): await omni.kit.app.get_app().next_update_async() for (key, test_instance) in instance_setup.items(): _test_verify_scene(self, og.Controller(), test_run, test_info, f"omni.graph.nodes.Round User test case #{i+1}, instance{key}") async def test_data_access(self): from omni.graph.nodes.ogn.OgnRoundDatabase import OgnRoundDatabase test_file_name = "OgnRoundTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_Round") database = OgnRoundDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:decimals")) attribute = test_node.get_attribute("inputs:decimals") db_value = database.inputs.decimals expected_value = 0 actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False))
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnRotateToOrientation.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnRotateToOrientationDatabase import OgnRotateToOrientationDatabase test_file_name = "OgnRotateToOrientationTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_RotateToOrientation") database = OgnRotateToOrientationDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 2) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:execIn")) attribute = test_node.get_attribute("inputs:execIn") db_value = database.inputs.execIn self.assertTrue(test_node.get_attribute_exists("inputs:exponent")) attribute = test_node.get_attribute("inputs:exponent") db_value = database.inputs.exponent expected_value = 2.0 actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:speed")) attribute = test_node.get_attribute("inputs:speed") db_value = database.inputs.speed expected_value = 1.0 actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:stop")) attribute = test_node.get_attribute("inputs:stop") db_value = database.inputs.stop self.assertTrue(test_node.get_attribute_exists("inputs:target")) attribute = test_node.get_attribute("inputs:target") db_value = database.inputs.target expected_value = [0.0, 0.0, 0.0] actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:usePath")) attribute = test_node.get_attribute("inputs:usePath") db_value = database.inputs.usePath expected_value = False actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("outputs:finished")) attribute = test_node.get_attribute("outputs:finished") db_value = database.outputs.finished
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnGetPrimPath.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnGetPrimPathDatabase import OgnGetPrimPathDatabase test_file_name = "OgnGetPrimPathTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_GetPrimPath") database = OgnGetPrimPathDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 3) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:prim")) attribute = test_node.get_attribute("inputs:prim") db_value = database.inputs.prim self.assertTrue(test_node.get_attribute_exists("outputs:path")) attribute = test_node.get_attribute("outputs:path") db_value = database.outputs.path self.assertTrue(test_node.get_attribute_exists("outputs:primPath")) attribute = test_node.get_attribute("outputs:primPath") db_value = database.outputs.primPath
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnConstantUChar.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnConstantUCharDatabase import OgnConstantUCharDatabase test_file_name = "OgnConstantUCharTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_ConstantUChar") database = OgnConstantUCharDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:value")) attribute = test_node.get_attribute("inputs:value") db_value = database.inputs.value expected_value = 0 actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False))
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnGetVariantSelection.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnGetVariantSelectionDatabase import OgnGetVariantSelectionDatabase test_file_name = "OgnGetVariantSelectionTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_GetVariantSelection") database = OgnGetVariantSelectionDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 2) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:prim")) attribute = test_node.get_attribute("inputs:prim") db_value = database.inputs.prim self.assertTrue(test_node.get_attribute_exists("inputs:variantSetName")) attribute = test_node.get_attribute("inputs:variantSetName") db_value = database.inputs.variantSetName expected_value = "" actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("outputs:variantName")) attribute = test_node.get_attribute("outputs:variantName") db_value = database.outputs.variantName
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnReadGamepadState.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnReadGamepadStateDatabase import OgnReadGamepadStateDatabase test_file_name = "OgnReadGamepadStateTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_ReadGamepadState") database = OgnReadGamepadStateDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:deadzone")) attribute = test_node.get_attribute("inputs:deadzone") db_value = database.inputs.deadzone expected_value = 0.1 actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:gamepadElement")) attribute = test_node.get_attribute("inputs:gamepadElement") db_value = database.inputs.gamepadElement expected_value = "Left Stick X Axis" actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:gamepadId")) attribute = test_node.get_attribute("inputs:gamepadId") db_value = database.inputs.gamepadId expected_value = 0 actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("outputs:isPressed")) attribute = test_node.get_attribute("outputs:isPressed") db_value = database.outputs.isPressed self.assertTrue(test_node.get_attribute_exists("outputs:value")) attribute = test_node.get_attribute("outputs:value") db_value = database.outputs.value
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnGraphTarget.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnGraphTargetDatabase import OgnGraphTargetDatabase test_file_name = "OgnGraphTargetTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_GraphTarget") database = OgnGraphTargetDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:targetPath")) attribute = test_node.get_attribute("inputs:targetPath") db_value = database.inputs.targetPath expected_value = "" actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("outputs:primPath")) attribute = test_node.get_attribute("outputs:primPath") db_value = database.outputs.primPath
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnInsertAttr.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnInsertAttrDatabase import OgnInsertAttrDatabase test_file_name = "OgnInsertAttrTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_InsertAttribute") database = OgnInsertAttrDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:data")) attribute = test_node.get_attribute("inputs:data") db_value = database.inputs.data self.assertTrue(test_node.get_attribute_exists("inputs:outputAttrName")) attribute = test_node.get_attribute("inputs:outputAttrName") db_value = database.inputs.outputAttrName expected_value = "attr0" actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("outputs_data")) attribute = test_node.get_attribute("outputs_data") db_value = database.outputs.data
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnSin.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): TEST_DATA = [ { 'inputs': [ ['inputs:value', {'type': 'float', 'value': 45.0}, False], ], 'outputs': [ ['outputs:value', {'type': 'float', 'value': 0.707107}, False], ], }, { 'inputs': [ ['inputs:value', {'type': 'double', 'value': 30.0}, False], ], 'outputs': [ ['outputs:value', {'type': 'double', 'value': 0.5}, False], ], }, ] async def test_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_Sin", "omni.graph.nodes.Sin", test_run, test_info) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.Sin User test case #{i+1}") async def test_vectorized_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_Sin","omni.graph.nodes.Sin", test_run, test_info, 16) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.Sin User test case #{i+1}", 16) async def test_thread_safety(self): import omni.kit # Generate multiple instances of the test setup to run them concurrently instance_setup = dict() for n in range(24): instance_setup[f"/TestGraph_{n}"] = _TestGraphAndNode() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) for (key, test_info) in instance_setup.items(): test_info = await _test_setup_scene(self, og.Controller(allow_exists_prim=True), key, "TestNode_omni_graph_nodes_Sin", "omni.graph.nodes.Sin", test_run, test_info) self.assertEqual(len(og.get_all_graphs()), 24) # We want to evaluate all graphs concurrently. Kick them all. # Evaluate multiple times to skip 2 serial frames and increase chances for a race condition. for _ in range(10): await omni.kit.app.get_app().next_update_async() for (key, test_instance) in instance_setup.items(): _test_verify_scene(self, og.Controller(), test_run, test_info, f"omni.graph.nodes.Sin User test case #{i+1}, instance{key}") async def test_data_access(self): from omni.graph.nodes.ogn.OgnSinDatabase import OgnSinDatabase test_file_name = "OgnSinTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_Sin") database = OgnSinDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error"
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnGetPrimPaths.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnGetPrimPathsDatabase import OgnGetPrimPathsDatabase test_file_name = "OgnGetPrimPathsTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_GetPrimPaths") database = OgnGetPrimPathsDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:prims")) attribute = test_node.get_attribute("inputs:prims") db_value = database.inputs.prims self.assertTrue(test_node.get_attribute_exists("outputs:primPaths")) attribute = test_node.get_attribute("outputs:primPaths") db_value = database.outputs.primPaths
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnGetAttrNames.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnGetAttrNamesDatabase import OgnGetAttrNamesDatabase test_file_name = "OgnGetAttrNamesTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_GetAttributeNames") database = OgnGetAttrNamesDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:data")) attribute = test_node.get_attribute("inputs:data") db_value = database.inputs.data self.assertTrue(test_node.get_attribute_exists("inputs:sort")) attribute = test_node.get_attribute("inputs:sort") db_value = database.inputs.sort expected_value = True actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("outputs:output")) attribute = test_node.get_attribute("outputs:output") db_value = database.outputs.output
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnRandomBoolean.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): TEST_DATA = [ { 'inputs': [ ['inputs:useSeed', True, False], ['inputs:seed', 14092058508772706262, False], ['inputs:execIn', 1, False], ['inputs:isNoise', True, False], ], 'outputs': [ ['outputs:random', False, False], ['outputs:execOut', 1, False], ], }, { 'inputs': [ ['inputs:useSeed', True, False], ['inputs:seed', 5527295704097554033, False], ['inputs:execIn', 1, False], ['inputs:isNoise', True, False], ], 'outputs': [ ['outputs:random', False, False], ['outputs:execOut', 1, False], ], }, { 'inputs': [ ['inputs:useSeed', True, False], ['inputs:seed', 9302349107990861236, False], ['inputs:execIn', 1, False], ['inputs:isNoise', True, False], ], 'outputs': [ ['outputs:random', True, False], ['outputs:execOut', 1, False], ], }, { 'inputs': [ ['inputs:useSeed', True, False], ['inputs:seed', 1955209015103813879, False], ['inputs:execIn', 1, False], ['inputs:isNoise', True, False], ], 'outputs': [ ['outputs:random', True, False], ['outputs:execOut', 1, False], ], }, ] async def test_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_RandomBoolean", "omni.graph.nodes.RandomBoolean", test_run, test_info) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.RandomBoolean User test case #{i+1}") async def test_vectorized_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_RandomBoolean","omni.graph.nodes.RandomBoolean", test_run, test_info, 16) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.RandomBoolean User test case #{i+1}", 16) async def test_thread_safety(self): import omni.kit # Generate multiple instances of the test setup to run them concurrently instance_setup = dict() for n in range(24): instance_setup[f"/TestGraph_{n}"] = _TestGraphAndNode() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) for (key, test_info) in instance_setup.items(): test_info = await _test_setup_scene(self, og.Controller(allow_exists_prim=True), key, "TestNode_omni_graph_nodes_RandomBoolean", "omni.graph.nodes.RandomBoolean", test_run, test_info) self.assertEqual(len(og.get_all_graphs()), 24) # We want to evaluate all graphs concurrently. Kick them all. # Evaluate multiple times to skip 2 serial frames and increase chances for a race condition. for _ in range(10): await omni.kit.app.get_app().next_update_async() for (key, test_instance) in instance_setup.items(): _test_verify_scene(self, og.Controller(), test_run, test_info, f"omni.graph.nodes.RandomBoolean User test case #{i+1}, instance{key}") async def test_data_access(self): from omni.graph.nodes.ogn.OgnRandomBooleanDatabase import OgnRandomBooleanDatabase test_file_name = "OgnRandomBooleanTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_RandomBoolean") database = OgnRandomBooleanDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:execIn")) attribute = test_node.get_attribute("inputs:execIn") db_value = database.inputs.execIn self.assertTrue(test_node.get_attribute_exists("inputs:isNoise")) attribute = test_node.get_attribute("inputs:isNoise") db_value = database.inputs.isNoise expected_value = False actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:useSeed")) attribute = test_node.get_attribute("inputs:useSeed") db_value = database.inputs.useSeed expected_value = False actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("outputs:execOut")) attribute = test_node.get_attribute("outputs:execOut") db_value = database.outputs.execOut self.assertTrue(test_node.get_attribute_exists("outputs:random")) attribute = test_node.get_attribute("outputs:random") db_value = database.outputs.random self.assertTrue(test_node.get_attribute_exists("state:gen")) attribute = test_node.get_attribute("state:gen") db_value = database.state.gen
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnConstantTexCoord3h.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnConstantTexCoord3hDatabase import OgnConstantTexCoord3hDatabase test_file_name = "OgnConstantTexCoord3hTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_ConstantTexCoord3h") database = OgnConstantTexCoord3hDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:value")) attribute = test_node.get_attribute("inputs:value") db_value = database.inputs.value expected_value = [0.0, 0.0, 0.0] actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False))
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnOr.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): TEST_DATA = [ { 'inputs': [ ['inputs:a', {'type': 'bool', 'value': False}, False], ['inputs:b', {'type': 'bool', 'value': True}, False], ], 'outputs': [ ['outputs:result', True, False], ], }, { 'inputs': [ ['inputs:a', {'type': 'bool[]', 'value': [False, False, True, True]}, False], ['inputs:b', {'type': 'bool[]', 'value': [False, True, False, True]}, False], ], 'outputs': [ ['outputs:result', [False, True, True, True], False], ], }, { 'inputs': [ ['inputs:a', {'type': 'bool', 'value': False}, False], ['inputs:b', {'type': 'bool[]', 'value': [False, True]}, False], ], 'outputs': [ ['outputs:result', [False, True], False], ], }, { 'inputs': [ ['inputs:a', {'type': 'bool[]', 'value': [False, True]}, False], ['inputs:b', {'type': 'bool', 'value': False}, False], ], 'outputs': [ ['outputs:result', [False, True], False], ], }, ] async def test_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_BooleanOr", "omni.graph.nodes.BooleanOr", test_run, test_info) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.BooleanOr User test case #{i+1}") async def test_vectorized_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_BooleanOr","omni.graph.nodes.BooleanOr", test_run, test_info, 16) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.BooleanOr User test case #{i+1}", 16) async def test_thread_safety(self): import omni.kit # Generate multiple instances of the test setup to run them concurrently instance_setup = dict() for n in range(24): instance_setup[f"/TestGraph_{n}"] = _TestGraphAndNode() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) for (key, test_info) in instance_setup.items(): test_info = await _test_setup_scene(self, og.Controller(allow_exists_prim=True), key, "TestNode_omni_graph_nodes_BooleanOr", "omni.graph.nodes.BooleanOr", test_run, test_info) self.assertEqual(len(og.get_all_graphs()), 24) # We want to evaluate all graphs concurrently. Kick them all. # Evaluate multiple times to skip 2 serial frames and increase chances for a race condition. for _ in range(10): await omni.kit.app.get_app().next_update_async() for (key, test_instance) in instance_setup.items(): _test_verify_scene(self, og.Controller(), test_run, test_info, f"omni.graph.nodes.BooleanOr User test case #{i+1}, instance{key}") async def test_data_access(self): from omni.graph.nodes.ogn.OgnOrDatabase import OgnOrDatabase test_file_name = "OgnOrTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_BooleanOr") database = OgnOrDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 2) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error"
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnReadOmniGraphValue.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnReadOmniGraphValueDatabase import OgnReadOmniGraphValueDatabase test_file_name = "OgnReadOmniGraphValueTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_ReadOmniGraphValue") database = OgnReadOmniGraphValueDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:name")) attribute = test_node.get_attribute("inputs:name") db_value = database.inputs.name expected_value = "" actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:path")) attribute = test_node.get_attribute("inputs:path") db_value = database.inputs.path expected_value = "" actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False))
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnNoise.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): TEST_DATA = [ { 'inputs': [ ['inputs:seed', 5, False], ['inputs:position', {'type': 'float', 'value': 1.4}, False], ], 'outputs': [ ['outputs:result', {'type': 'float', 'value': 0.03438323736190796}, False], ], }, { 'inputs': [ ['inputs:seed', 5, False], ['inputs:position', {'type': 'float', 'value': -1.4}, False], ], 'outputs': [ ['outputs:result', {'type': 'float', 'value': -0.03764888644218445}, False], ], }, { 'inputs': [ ['inputs:seed', 23, False], ['inputs:position', {'type': 'float', 'value': 1.4}, False], ], 'outputs': [ ['outputs:result', {'type': 'float', 'value': -0.1955927014350891}, False], ], }, { 'inputs': [ ['inputs:seed', 5, False], ['inputs:position', {'type': 'float[2]', 'value': [1.7, -0.4]}, False], ], 'outputs': [ ['outputs:result', {'type': 'float', 'value': -0.10021606087684631}, False], ], }, { 'inputs': [ ['inputs:seed', 5, False], ['inputs:position', {'type': 'float[2]', 'value': [-0.4, 1.7]}, False], ], 'outputs': [ ['outputs:result', {'type': 'float', 'value': -0.4338015019893646}, False], ], }, { 'inputs': [ ['inputs:seed', 5, False], ['inputs:position', {'type': 'float[3]', 'value': [1.4, -0.8, 0.5]}, False], ], 'outputs': [ ['outputs:result', {'type': 'float', 'value': -0.14821206033229828}, False], ], }, { 'inputs': [ ['inputs:seed', 5, False], ['inputs:position', {'type': 'float[3]', 'value': [1.5, -0.8, 0.5]}, False], ], 'outputs': [ ['outputs:result', {'type': 'float', 'value': -0.11368121206760406}, False], ], }, { 'inputs': [ ['inputs:seed', 5, False], ['inputs:position', {'type': 'float[3]', 'value': [1.4, -0.9, 0.5]}, False], ], 'outputs': [ ['outputs:result', {'type': 'float', 'value': -0.16395819187164307}, False], ], }, { 'inputs': [ ['inputs:seed', 5, False], ['inputs:position', {'type': 'float[3]', 'value': [1.4, -0.8, 0.8]}, False], ], 'outputs': [ ['outputs:result', {'type': 'float', 'value': 0.00016325712203979492}, False], ], }, { 'inputs': [ ['inputs:seed', 5, False], ['inputs:position', {'type': 'float[3]', 'value': [1.5, -0.9, 0.8]}, False], ], 'outputs': [ ['outputs:result', {'type': 'float', 'value': -0.03829096257686615}, False], ], }, { 'inputs': [ ['inputs:seed', 5, False], ['inputs:position', {'type': 'float[3]', 'value': [2.5, -0.9, 0.8]}, False], ], 'outputs': [ ['outputs:result', {'type': 'float', 'value': 0.034046247601509094}, False], ], }, { 'inputs': [ ['inputs:seed', 5, False], ['inputs:position', {'type': 'float[4]', 'value': [2.5, -0.9, 0.8, 0.0]}, False], ], 'outputs': [ ['outputs:result', {'type': 'float', 'value': -0.009762797504663467}, False], ], }, { 'inputs': [ ['inputs:seed', 5, False], ['inputs:position', {'type': 'float[4]', 'value': [2.5, -0.9, 0.8, 0.1]}, False], ], 'outputs': [ ['outputs:result', {'type': 'float', 'value': -0.07352154701948166}, False], ], }, { 'inputs': [ ['inputs:seed', 6, False], ['inputs:position', {'type': 'float[4]', 'value': [2.5, -0.9, 0.8, 0.1]}, False], ], 'outputs': [ ['outputs:result', {'type': 'float', 'value': 0.2615857422351837}, False], ], }, { 'inputs': [ ['inputs:seed', 5, False], ['inputs:position', {'type': 'float[]', 'value': [-1.4]}, False], ], 'outputs': [ ['outputs:result', {'type': 'float[]', 'value': [-0.03764889]}, False], ], }, { 'inputs': [ ['inputs:seed', 5, False], ['inputs:position', {'type': 'float[]', 'value': [0.5, -1.4]}, False], ], 'outputs': [ ['outputs:result', {'type': 'float[]', 'value': [0.18699697, -0.03764889]}, False], ], }, { 'inputs': [ ['inputs:seed', 5, False], ['inputs:position', {'type': 'float[2][]', 'value': [[1.5, -0.8]]}, False], ], 'outputs': [ ['outputs:result', {'type': 'float[]', 'value': [0.16450586915016174]}, False], ], }, { 'inputs': [ ['inputs:seed', 5, False], ['inputs:position', {'type': 'float[2][]', 'value': [[1.5, -0.8], [2.5, -0.9]]}, False], ], 'outputs': [ ['outputs:result', {'type': 'float[]', 'value': [0.16450587, 0.08753645]}, False], ], }, { 'inputs': [ ['inputs:seed', 5, False], ['inputs:position', {'type': 'float[3][]', 'value': [[1.5, -0.8, 0.5]]}, False], ], 'outputs': [ ['outputs:result', {'type': 'float[]', 'value': [-0.11368121206760406]}, False], ], }, { 'inputs': [ ['inputs:seed', 5, False], ['inputs:position', {'type': 'float[3][]', 'value': [[1.5, -0.8, 0.5], [1.4, -0.8, 0.5]]}, False], ], 'outputs': [ ['outputs:result', {'type': 'float[]', 'value': [-0.11368121206760406, -0.14821206033229828]}, False], ], }, { 'inputs': [ ['inputs:seed', 5, False], ['inputs:position', {'type': 'float[3][]', 'value': [[2.5, -0.9, 0.8], [1.5, -0.8, 0.5], [1.4, -0.8, 0.5]]}, False], ], 'outputs': [ ['outputs:result', {'type': 'float[]', 'value': [0.034046247601509094, -0.11368121206760406, -0.14821206033229828]}, False], ], }, { 'inputs': [ ['inputs:seed', 5, False], ['inputs:position', {'type': 'float[4][]', 'value': [[2.5, -0.9, 0.8, 0.0], [2.5, -0.9, 0.8, 0.1]]}, False], ], 'outputs': [ ['outputs:result', {'type': 'float[]', 'value': [-0.009762797504663467, -0.07352154701948166]}, False], ], }, ] async def test_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_Noise", "omni.graph.nodes.Noise", test_run, test_info) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.Noise User test case #{i+1}") async def test_vectorized_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_Noise","omni.graph.nodes.Noise", test_run, test_info, 16) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.Noise User test case #{i+1}", 16) async def test_thread_safety(self): import omni.kit # Generate multiple instances of the test setup to run them concurrently instance_setup = dict() for n in range(24): instance_setup[f"/TestGraph_{n}"] = _TestGraphAndNode() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) for (key, test_info) in instance_setup.items(): test_info = await _test_setup_scene(self, og.Controller(allow_exists_prim=True), key, "TestNode_omni_graph_nodes_Noise", "omni.graph.nodes.Noise", test_run, test_info) self.assertEqual(len(og.get_all_graphs()), 24) # We want to evaluate all graphs concurrently. Kick them all. # Evaluate multiple times to skip 2 serial frames and increase chances for a race condition. for _ in range(10): await omni.kit.app.get_app().next_update_async() for (key, test_instance) in instance_setup.items(): _test_verify_scene(self, og.Controller(), test_run, test_info, f"omni.graph.nodes.Noise User test case #{i+1}, instance{key}") async def test_data_access(self): from omni.graph.nodes.ogn.OgnNoiseDatabase import OgnNoiseDatabase test_file_name = "OgnNoiseTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_Noise") database = OgnNoiseDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:seed")) attribute = test_node.get_attribute("inputs:seed") db_value = database.inputs.seed expected_value = 0 actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False))
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnConstructArray.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnConstructArrayDatabase import OgnConstructArrayDatabase test_file_name = "OgnConstructArrayTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_ConstructArray") database = OgnConstructArrayDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:arraySize")) attribute = test_node.get_attribute("inputs:arraySize") db_value = database.inputs.arraySize expected_value = 1 actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:arrayType")) attribute = test_node.get_attribute("inputs:arrayType") db_value = database.inputs.arrayType expected_value = "auto" actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False))
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnReadPrimsBundle.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnReadPrimsBundleDatabase import OgnReadPrimsBundleDatabase test_file_name = "OgnReadPrimsBundleTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_ReadPrimsBundle") database = OgnReadPrimsBundleDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 3) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:attrNamesToImport")) attribute = test_node.get_attribute("inputs:attrNamesToImport") db_value = database.inputs.attrNamesToImport expected_value = "*" actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:usdTimecode")) attribute = test_node.get_attribute("inputs:usdTimecode") db_value = database.inputs.usdTimecode expected_value = float("NaN") actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:usePaths")) attribute = test_node.get_attribute("inputs:usePaths") db_value = database.inputs.usePaths expected_value = False actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("outputs_primsBundle")) attribute = test_node.get_attribute("outputs_primsBundle") db_value = database.outputs.primsBundle self.assertTrue(test_node.get_attribute_exists("state:attrNamesToImport")) attribute = test_node.get_attribute("state:attrNamesToImport") db_value = database.state.attrNamesToImport self.assertTrue(test_node.get_attribute_exists("state:primPaths")) attribute = test_node.get_attribute("state:primPaths") db_value = database.state.primPaths self.assertTrue(test_node.get_attribute_exists("state:usdTimecode")) attribute = test_node.get_attribute("state:usdTimecode") db_value = database.state.usdTimecode self.assertTrue(test_node.get_attribute_exists("state:usePaths")) attribute = test_node.get_attribute("state:usePaths") db_value = database.state.usePaths
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnInvertMatrix.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): TEST_DATA = [ { 'inputs': [ ['inputs:matrix', {'type': 'matrixd[3]', 'value': [1, 0, 0, 0, 1, 0, 0, 0, 1]}, False], ], 'outputs': [ ['outputs:invertedMatrix', {'type': 'matrixd[3]', 'value': [1, 0, 0, 0, 1, 0, 0, 0, 1]}, False], ], }, { 'inputs': [ ['inputs:matrix', {'type': 'matrixd[4][]', 'value': [[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], [5, 6, 6, 8, 2, 2, 2, 8, 6, 6, 2, 8, 2, 3, 6, 7], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]]}, False], ], 'outputs': [ ['outputs:invertedMatrix', {'type': 'matrixd[4][]', 'value': [[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], [-17, -9, 12, 16, 17, 8.75, -11.75, -16, -4, -2.25, 2.75, 4, 1, 0.75, -0.75, -1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]}, False], ], }, ] async def test_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_OgnInvertMatrix", "omni.graph.nodes.OgnInvertMatrix", test_run, test_info) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.OgnInvertMatrix User test case #{i+1}") async def test_vectorized_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_OgnInvertMatrix","omni.graph.nodes.OgnInvertMatrix", test_run, test_info, 16) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.OgnInvertMatrix User test case #{i+1}", 16) async def test_thread_safety(self): import omni.kit # Generate multiple instances of the test setup to run them concurrently instance_setup = dict() for n in range(24): instance_setup[f"/TestGraph_{n}"] = _TestGraphAndNode() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) for (key, test_info) in instance_setup.items(): test_info = await _test_setup_scene(self, og.Controller(allow_exists_prim=True), key, "TestNode_omni_graph_nodes_OgnInvertMatrix", "omni.graph.nodes.OgnInvertMatrix", test_run, test_info) self.assertEqual(len(og.get_all_graphs()), 24) # We want to evaluate all graphs concurrently. Kick them all. # Evaluate multiple times to skip 2 serial frames and increase chances for a race condition. for _ in range(10): await omni.kit.app.get_app().next_update_async() for (key, test_instance) in instance_setup.items(): _test_verify_scene(self, og.Controller(), test_run, test_info, f"omni.graph.nodes.OgnInvertMatrix User test case #{i+1}, instance{key}") async def test_data_access(self): from omni.graph.nodes.ogn.OgnInvertMatrixDatabase import OgnInvertMatrixDatabase test_file_name = "OgnInvertMatrixTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_OgnInvertMatrix") database = OgnInvertMatrixDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error"
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnExponent.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): TEST_DATA = [ { 'inputs': [ ['inputs:base', {'type': 'float', 'value': 2.0}, False], ], 'outputs': [ ['outputs:result', {'type': 'float', 'value': 4.0}, False], ], }, { 'inputs': [ ['inputs:base', {'type': 'double', 'value': 0.5}, False], ['inputs:exponent', 3, False], ], 'outputs': [ ['outputs:result', {'type': 'double', 'value': 0.125}, False], ], }, { 'inputs': [ ['inputs:base', {'type': 'half[2]', 'value': [5.0, 0.5]}, False], ['inputs:exponent', 3, False], ], 'outputs': [ ['outputs:result', {'type': 'half[2]', 'value': [125.0, 0.125]}, False], ], }, { 'inputs': [ ['inputs:base', {'type': 'float[]', 'value': [1.0, 3.0]}, False], ['inputs:exponent', 3, False], ], 'outputs': [ ['outputs:result', {'type': 'float[]', 'value': [1.0, 27.0]}, False], ], }, { 'inputs': [ ['inputs:base', {'type': 'float[2][]', 'value': [[1.0, 0.3], [0.5, 3.0]]}, False], ], 'outputs': [ ['outputs:result', {'type': 'float[2][]', 'value': [[1.0, 0.09], [0.25, 9.0]]}, False], ], }, { 'inputs': [ ['inputs:base', {'type': 'int', 'value': 2147483647}, False], ['inputs:exponent', 0, False], ], 'outputs': [ ['outputs:result', {'type': 'double', 'value': 1.0}, False], ], }, { 'inputs': [ ['inputs:base', {'type': 'int64', 'value': 9223372036854775807}, False], ['inputs:exponent', 1, False], ], 'outputs': [ ['outputs:result', {'type': 'double', 'value': 9.223372036854776e+18}, False], ], }, { 'inputs': [ ['inputs:base', {'type': 'int', 'value': 5}, False], ['inputs:exponent', -1, False], ], 'outputs': [ ['outputs:result', {'type': 'double', 'value': 0.2}, False], ], }, { 'inputs': [ ['inputs:base', {'type': 'float', 'value': -2.0}, False], ], 'outputs': [ ['outputs:result', {'type': 'float', 'value': 4.0}, False], ], }, { 'inputs': [ ['inputs:base', {'type': 'float', 'value': -2.0}, False], ['inputs:exponent', 3, False], ], 'outputs': [ ['outputs:result', {'type': 'float', 'value': -8.0}, False], ], }, ] async def test_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_Exponent", "omni.graph.nodes.Exponent", test_run, test_info) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.Exponent User test case #{i+1}") async def test_vectorized_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_Exponent","omni.graph.nodes.Exponent", test_run, test_info, 16) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.Exponent User test case #{i+1}", 16) async def test_thread_safety(self): import omni.kit # Generate multiple instances of the test setup to run them concurrently instance_setup = dict() for n in range(24): instance_setup[f"/TestGraph_{n}"] = _TestGraphAndNode() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) for (key, test_info) in instance_setup.items(): test_info = await _test_setup_scene(self, og.Controller(allow_exists_prim=True), key, "TestNode_omni_graph_nodes_Exponent", "omni.graph.nodes.Exponent", test_run, test_info) self.assertEqual(len(og.get_all_graphs()), 24) # We want to evaluate all graphs concurrently. Kick them all. # Evaluate multiple times to skip 2 serial frames and increase chances for a race condition. for _ in range(10): await omni.kit.app.get_app().next_update_async() for (key, test_instance) in instance_setup.items(): _test_verify_scene(self, og.Controller(), test_run, test_info, f"omni.graph.nodes.Exponent User test case #{i+1}, instance{key}") async def test_data_access(self): from omni.graph.nodes.ogn.OgnExponentDatabase import OgnExponentDatabase test_file_name = "OgnExponentTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_Exponent") database = OgnExponentDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:exponent")) attribute = test_node.get_attribute("inputs:exponent") db_value = database.inputs.exponent expected_value = 2 actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False))
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnGetRelativePath.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): TEST_DATA = [ { 'inputs': [ ['inputs:anchor', "/World", False], ['inputs:path', {'type': 'token', 'value': '/World'}, False], ], 'outputs': [ ['outputs:relativePath', {'type': 'token', 'value': '.'}, False], ], }, { 'inputs': [ ['inputs:anchor', "/World", False], ['inputs:path', {'type': 'token', 'value': '/World/foo'}, False], ], 'outputs': [ ['outputs:relativePath', {'type': 'token', 'value': 'foo'}, False], ], }, { 'inputs': [ ['inputs:anchor', "/World", False], ['inputs:path', {'type': 'token', 'value': '/World/foo/bar'}, False], ], 'outputs': [ ['outputs:relativePath', {'type': 'token', 'value': 'foo/bar'}, False], ], }, { 'inputs': [ ['inputs:anchor', "/World", False], ['inputs:path', {'type': 'token', 'value': '/World/foo/bar.attrib'}, False], ], 'outputs': [ ['outputs:relativePath', {'type': 'token', 'value': 'foo/bar.attrib'}, False], ], }, { 'inputs': [ ['inputs:anchor', "/World", False], ['inputs:path', {'type': 'token[]', 'value': ['/World/foo', '/World/bar']}, False], ], 'outputs': [ ['outputs:relativePath', {'type': 'token[]', 'value': ['foo', 'bar']}, False], ], }, ] async def test_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_GetRelativePath", "omni.graph.nodes.GetRelativePath", test_run, test_info) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.GetRelativePath User test case #{i+1}") async def test_vectorized_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_GetRelativePath","omni.graph.nodes.GetRelativePath", test_run, test_info, 16) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.GetRelativePath User test case #{i+1}", 16) async def test_thread_safety(self): import omni.kit # Generate multiple instances of the test setup to run them concurrently instance_setup = dict() for n in range(24): instance_setup[f"/TestGraph_{n}"] = _TestGraphAndNode() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) for (key, test_info) in instance_setup.items(): test_info = await _test_setup_scene(self, og.Controller(allow_exists_prim=True), key, "TestNode_omni_graph_nodes_GetRelativePath", "omni.graph.nodes.GetRelativePath", test_run, test_info) self.assertEqual(len(og.get_all_graphs()), 24) # We want to evaluate all graphs concurrently. Kick them all. # Evaluate multiple times to skip 2 serial frames and increase chances for a race condition. for _ in range(10): await omni.kit.app.get_app().next_update_async() for (key, test_instance) in instance_setup.items(): _test_verify_scene(self, og.Controller(), test_run, test_info, f"omni.graph.nodes.GetRelativePath User test case #{i+1}, instance{key}") async def test_data_access(self): from omni.graph.nodes.ogn.OgnGetRelativePathDatabase import OgnGetRelativePathDatabase test_file_name = "OgnGetRelativePathTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_GetRelativePath") database = OgnGetRelativePathDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:anchor")) attribute = test_node.get_attribute("inputs:anchor") db_value = database.inputs.anchor expected_value = "" actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("state:anchor")) attribute = test_node.get_attribute("state:anchor") db_value = database.state.anchor self.assertTrue(test_node.get_attribute_exists("state:path")) attribute = test_node.get_attribute("state:path") db_value = database.state.path
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnGetLocationAtDistanceOnCurve.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): TEST_DATA = [ { 'inputs': [ ['inputs:curve', [[1, 2, 3]], False], ['inputs:distance', [0.5], False], ], 'outputs': [ ['outputs:location', [[1, 2, 3]], False], ], }, { 'inputs': [ ['inputs:curve', [[0, 0, 0], [0, 0, 1]], False], ['inputs:distance', [0.75, 0], False], ['inputs:forwardAxis', "X", False], ['inputs:upAxis', "Y", False], ], 'outputs': [ ['outputs:location', [[0, 0, 0.5], [0, 0, 0]], False], ['outputs:rotateXYZ', [[0, 90, 0], [0, -90, 0]], False], ], }, ] async def test_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_GetLocationAtDistanceOnCurve", "omni.graph.nodes.GetLocationAtDistanceOnCurve", test_run, test_info) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.GetLocationAtDistanceOnCurve User test case #{i+1}") async def test_vectorized_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_GetLocationAtDistanceOnCurve","omni.graph.nodes.GetLocationAtDistanceOnCurve", test_run, test_info, 16) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.GetLocationAtDistanceOnCurve User test case #{i+1}", 16) async def test_thread_safety(self): import omni.kit # Generate multiple instances of the test setup to run them concurrently instance_setup = dict() for n in range(24): instance_setup[f"/TestGraph_{n}"] = _TestGraphAndNode() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) for (key, test_info) in instance_setup.items(): test_info = await _test_setup_scene(self, og.Controller(allow_exists_prim=True), key, "TestNode_omni_graph_nodes_GetLocationAtDistanceOnCurve", "omni.graph.nodes.GetLocationAtDistanceOnCurve", test_run, test_info) self.assertEqual(len(og.get_all_graphs()), 24) # We want to evaluate all graphs concurrently. Kick them all. # Evaluate multiple times to skip 2 serial frames and increase chances for a race condition. for _ in range(10): await omni.kit.app.get_app().next_update_async() for (key, test_instance) in instance_setup.items(): _test_verify_scene(self, og.Controller(), test_run, test_info, f"omni.graph.nodes.GetLocationAtDistanceOnCurve User test case #{i+1}, instance{key}") async def test_data_access(self): from omni.graph.nodes.ogn.OgnGetLocationAtDistanceOnCurveDatabase import OgnGetLocationAtDistanceOnCurveDatabase test_file_name = "OgnGetLocationAtDistanceOnCurveTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_GetLocationAtDistanceOnCurve") database = OgnGetLocationAtDistanceOnCurveDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:curve")) attribute = test_node.get_attribute("inputs:curve") db_value = database.inputs.curve expected_value = [] actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:distance")) attribute = test_node.get_attribute("inputs:distance") db_value = database.inputs.distance expected_value = [] actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:forwardAxis")) attribute = test_node.get_attribute("inputs:forwardAxis") db_value = database.inputs.forwardAxis expected_value = "X" actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:upAxis")) attribute = test_node.get_attribute("inputs:upAxis") db_value = database.inputs.upAxis expected_value = "Y" actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("outputs:location")) attribute = test_node.get_attribute("outputs:location") db_value = database.outputs.location self.assertTrue(test_node.get_attribute_exists("outputs:orientation")) attribute = test_node.get_attribute("outputs:orientation") db_value = database.outputs.orientation self.assertTrue(test_node.get_attribute_exists("outputs:rotateXYZ")) attribute = test_node.get_attribute("outputs:rotateXYZ") db_value = database.outputs.rotateXYZ
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnToToken.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): TEST_DATA = [ { 'inputs': [ ['inputs:value', {'type': 'bool', 'value': True}, False], ], 'outputs': [ ['outputs:converted', "True", False], ], }, { 'inputs': [ ['inputs:value', {'type': 'double', 'value': 2.1}, False], ], 'outputs': [ ['outputs:converted', "2.1", False], ], }, { 'inputs': [ ['inputs:value', {'type': 'int', 'value': 42}, False], ], 'outputs': [ ['outputs:converted', "42", False], ], }, { 'inputs': [ ['inputs:value', {'type': 'double[3]', 'value': [1.8, 2.2, 3]}, False], ], 'outputs': [ ['outputs:converted', "[1.8, 2.2, 3]", False], ], }, { 'inputs': [ ['inputs:value', {'type': 'half[3]', 'value': [2, 3, 4.5]}, False], ], 'outputs': [ ['outputs:converted', "[2, 3, 4.5]", False], ], }, { 'inputs': [ ['inputs:value', {'type': 'int[2][]', 'value': [[1, 2], [3, 4]]}, False], ], 'outputs': [ ['outputs:converted', "[[1, 2], [3, 4]]", False], ], }, { 'inputs': [ ['inputs:value', {'type': 'uint64', 'value': 42}, False], ], 'outputs': [ ['outputs:converted', "42", False], ], }, { 'inputs': [ ['inputs:value', {'type': 'token', 'value': 'Foo'}, False], ], 'outputs': [ ['outputs:converted', "Foo", False], ], }, { 'inputs': [ ['inputs:value', {'type': 'string', 'value': 'Foo'}, False], ], 'outputs': [ ['outputs:converted', "Foo", False], ], }, ] async def test_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_ToToken", "omni.graph.nodes.ToToken", test_run, test_info) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.ToToken User test case #{i+1}") async def test_vectorized_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_ToToken","omni.graph.nodes.ToToken", test_run, test_info, 16) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.ToToken User test case #{i+1}", 16) async def test_thread_safety(self): import omni.kit # Generate multiple instances of the test setup to run them concurrently instance_setup = dict() for n in range(24): instance_setup[f"/TestGraph_{n}"] = _TestGraphAndNode() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) for (key, test_info) in instance_setup.items(): test_info = await _test_setup_scene(self, og.Controller(allow_exists_prim=True), key, "TestNode_omni_graph_nodes_ToToken", "omni.graph.nodes.ToToken", test_run, test_info) self.assertEqual(len(og.get_all_graphs()), 24) # We want to evaluate all graphs concurrently. Kick them all. # Evaluate multiple times to skip 2 serial frames and increase chances for a race condition. for _ in range(10): await omni.kit.app.get_app().next_update_async() for (key, test_instance) in instance_setup.items(): _test_verify_scene(self, og.Controller(), test_run, test_info, f"omni.graph.nodes.ToToken User test case #{i+1}, instance{key}") async def test_data_access(self): from omni.graph.nodes.ogn.OgnToTokenDatabase import OgnToTokenDatabase test_file_name = "OgnToTokenTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_ToToken") database = OgnToTokenDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("outputs:converted")) attribute = test_node.get_attribute("outputs:converted") db_value = database.outputs.converted
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnTranslateToLocation.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnTranslateToLocationDatabase import OgnTranslateToLocationDatabase test_file_name = "OgnTranslateToLocationTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_TranslateToLocation") database = OgnTranslateToLocationDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 2) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:execIn")) attribute = test_node.get_attribute("inputs:execIn") db_value = database.inputs.execIn self.assertTrue(test_node.get_attribute_exists("inputs:exponent")) attribute = test_node.get_attribute("inputs:exponent") db_value = database.inputs.exponent expected_value = 2.0 actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:speed")) attribute = test_node.get_attribute("inputs:speed") db_value = database.inputs.speed expected_value = 1.0 actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:stop")) attribute = test_node.get_attribute("inputs:stop") db_value = database.inputs.stop self.assertTrue(test_node.get_attribute_exists("inputs:target")) attribute = test_node.get_attribute("inputs:target") db_value = database.inputs.target expected_value = [0.0, 0.0, 0.0] actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:usePath")) attribute = test_node.get_attribute("inputs:usePath") db_value = database.inputs.usePath expected_value = False actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("outputs:finished")) attribute = test_node.get_attribute("outputs:finished") db_value = database.outputs.finished
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnMakeArray.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): TEST_DATA = [ { 'inputs': [ ['inputs:a', {'type': 'float', 'value': 1}, False], ['inputs:b', {'type': 'float', 'value': 1}, False], ['inputs:c', {'type': 'float', 'value': 1}, False], ['inputs:d', {'type': 'float', 'value': 1}, False], ['inputs:e', {'type': 'float', 'value': 1}, False], ['inputs:arraySize', 1, False], ], 'outputs': [ ['outputs:array', {'type': 'float[]', 'value': [1]}, False], ], }, { 'inputs': [ ['inputs:a', {'type': 'float[2]', 'value': [1, 2]}, False], ['inputs:b', {'type': 'float[2]', 'value': [1, 3]}, False], ['inputs:c', {'type': 'float[2]', 'value': [1, 4]}, False], ['inputs:d', {'type': 'float[2]', 'value': [1, 5]}, False], ['inputs:e', {'type': 'float[2]', 'value': [1, 6]}, False], ['inputs:arraySize', 5, False], ], 'outputs': [ ['outputs:array', {'type': 'float[2][]', 'value': [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6]]}, False], ], }, { 'inputs': [ ['inputs:a', {'type': 'token', 'value': 'foo'}, False], ['inputs:b', {'type': 'token', 'value': 'foo'}, False], ['inputs:c', {'type': 'token', 'value': 'foo'}, False], ['inputs:d', {'type': 'token', 'value': 'foo'}, False], ['inputs:e', {'type': 'token', 'value': 'foo'}, False], ['inputs:arraySize', 5, False], ], 'outputs': [ ['outputs:array', {'type': 'token[]', 'value': ['foo', 'foo', 'foo', 'foo', 'foo']}, False], ], }, { 'inputs': [ ['inputs:a', {'type': 'uchar', 'value': 42}, False], ['inputs:b', {'type': 'uchar', 'value': 42}, False], ['inputs:c', {'type': 'uchar', 'value': 42}, False], ['inputs:d', {'type': 'uchar', 'value': 42}, False], ['inputs:e', {'type': 'uchar', 'value': 42}, False], ['inputs:arraySize', 5, False], ], 'outputs': [ ['outputs:array', {'type': 'uchar[]', 'value': [42, 42, 42, 42, 42]}, False], ], }, { 'inputs': [ ['inputs:a', {'type': 'double[4]', 'value': [1, 2, 3, 4]}, False], ['inputs:b', {'type': 'double[4]', 'value': [1, 2, 3, 4]}, False], ['inputs:c', {'type': 'double[4]', 'value': [1, 2, 3, 4]}, False], ['inputs:d', {'type': 'double[4]', 'value': [1, 2, 3, 4]}, False], ['inputs:e', {'type': 'double[4]', 'value': [1, 2, 3, 5]}, False], ['inputs:arraySize', 6, False], ], 'outputs': [ ['outputs:array', {'type': 'double[4][]', 'value': [[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 5], [1, 2, 3, 5]]}, False], ], }, ] async def test_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_MakeArray", "omni.graph.nodes.MakeArray", test_run, test_info) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.MakeArray User test case #{i+1}") async def test_vectorized_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_MakeArray","omni.graph.nodes.MakeArray", test_run, test_info, 16) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.MakeArray User test case #{i+1}", 16) async def test_data_access(self): from omni.graph.nodes.ogn.OgnMakeArrayDatabase import OgnMakeArrayDatabase test_file_name = "OgnMakeArrayTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_MakeArray") database = OgnMakeArrayDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:arraySize")) attribute = test_node.get_attribute("inputs:arraySize") db_value = database.inputs.arraySize expected_value = 0 actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False))
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnNot.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): TEST_DATA = [ { 'inputs': [ ['inputs:valueIn', {'type': 'bool', 'value': True}, False], ], 'outputs': [ ['outputs:valueOut', False, False], ], }, { 'inputs': [ ['inputs:valueIn', {'type': 'bool', 'value': False}, False], ], 'outputs': [ ['outputs:valueOut', True, False], ], }, { 'inputs': [ ['inputs:valueIn', {'type': 'bool[]', 'value': [True, False, True, False]}, False], ], 'outputs': [ ['outputs:valueOut', [False, True, False, True], False], ], }, ] async def test_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_BooleanNot", "omni.graph.nodes.BooleanNot", test_run, test_info) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.BooleanNot User test case #{i+1}") async def test_vectorized_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_BooleanNot","omni.graph.nodes.BooleanNot", test_run, test_info, 16) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.BooleanNot User test case #{i+1}", 16) async def test_thread_safety(self): import omni.kit # Generate multiple instances of the test setup to run them concurrently instance_setup = dict() for n in range(24): instance_setup[f"/TestGraph_{n}"] = _TestGraphAndNode() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) for (key, test_info) in instance_setup.items(): test_info = await _test_setup_scene(self, og.Controller(allow_exists_prim=True), key, "TestNode_omni_graph_nodes_BooleanNot", "omni.graph.nodes.BooleanNot", test_run, test_info) self.assertEqual(len(og.get_all_graphs()), 24) # We want to evaluate all graphs concurrently. Kick them all. # Evaluate multiple times to skip 2 serial frames and increase chances for a race condition. for _ in range(10): await omni.kit.app.get_app().next_update_async() for (key, test_instance) in instance_setup.items(): _test_verify_scene(self, og.Controller(), test_run, test_info, f"omni.graph.nodes.BooleanNot User test case #{i+1}, instance{key}") async def test_data_access(self): from omni.graph.nodes.ogn.OgnNotDatabase import OgnNotDatabase test_file_name = "OgnNotTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_BooleanNot") database = OgnNotDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error"
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnGetPrimLocalToWorldTransform.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnGetPrimLocalToWorldTransformDatabase import OgnGetPrimLocalToWorldTransformDatabase test_file_name = "OgnGetPrimLocalToWorldTransformTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_GetPrimLocalToWorldTransform") database = OgnGetPrimLocalToWorldTransformDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 2) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:primPath")) attribute = test_node.get_attribute("inputs:primPath") db_value = database.inputs.primPath expected_value = "" actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:usePath")) attribute = test_node.get_attribute("inputs:usePath") db_value = database.inputs.usePath expected_value = True actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("outputs:localToWorldTransform")) attribute = test_node.get_attribute("outputs:localToWorldTransform") db_value = database.outputs.localToWorldTransform
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnToFloat.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): TEST_DATA = [ { 'inputs': [ ['inputs:value', {'type': 'float[]', 'value': []}, False], ], 'outputs': [ ['outputs:converted', {'type': 'float[]', 'value': []}, False], ], }, { 'inputs': [ ['inputs:value', {'type': 'double', 'value': 2.1}, False], ], 'outputs': [ ['outputs:converted', {'type': 'float', 'value': 2.1}, False], ], }, { 'inputs': [ ['inputs:value', {'type': 'int', 'value': 42}, False], ], 'outputs': [ ['outputs:converted', {'type': 'float', 'value': 42.0}, False], ], }, { 'inputs': [ ['inputs:value', {'type': 'double[2]', 'value': [2.1, 2.1]}, False], ], 'outputs': [ ['outputs:converted', {'type': 'float[2]', 'value': [2.1, 2.1]}, False], ], }, { 'inputs': [ ['inputs:value', {'type': 'half[3]', 'value': [2, 3, 4]}, False], ], 'outputs': [ ['outputs:converted', {'type': 'float[3]', 'value': [2, 3, 4]}, False], ], }, { 'inputs': [ ['inputs:value', {'type': 'half[3][]', 'value': [[2, 3, 4]]}, False], ], 'outputs': [ ['outputs:converted', {'type': 'float[3][]', 'value': [[2, 3, 4]]}, False], ], }, { 'inputs': [ ['inputs:value', {'type': 'int[2][]', 'value': [[1, 2], [3, 4]]}, False], ], 'outputs': [ ['outputs:converted', {'type': 'float[2][]', 'value': [[1.0, 2.0], [3.0, 4.0]]}, False], ], }, ] async def test_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_ToFloat", "omni.graph.nodes.ToFloat", test_run, test_info) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.ToFloat User test case #{i+1}") async def test_vectorized_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_ToFloat","omni.graph.nodes.ToFloat", test_run, test_info, 16) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.ToFloat User test case #{i+1}", 16) async def test_thread_safety(self): import omni.kit # Generate multiple instances of the test setup to run them concurrently instance_setup = dict() for n in range(24): instance_setup[f"/TestGraph_{n}"] = _TestGraphAndNode() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) for (key, test_info) in instance_setup.items(): test_info = await _test_setup_scene(self, og.Controller(allow_exists_prim=True), key, "TestNode_omni_graph_nodes_ToFloat", "omni.graph.nodes.ToFloat", test_run, test_info) self.assertEqual(len(og.get_all_graphs()), 24) # We want to evaluate all graphs concurrently. Kick them all. # Evaluate multiple times to skip 2 serial frames and increase chances for a race condition. for _ in range(10): await omni.kit.app.get_app().next_update_async() for (key, test_instance) in instance_setup.items(): _test_verify_scene(self, og.Controller(), test_run, test_info, f"omni.graph.nodes.ToFloat User test case #{i+1}, instance{key}") async def test_data_access(self): from omni.graph.nodes.ogn.OgnToFloatDatabase import OgnToFloatDatabase test_file_name = "OgnToFloatTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_ToFloat") database = OgnToFloatDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error"
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnConstantTexCoord3f.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnConstantTexCoord3fDatabase import OgnConstantTexCoord3fDatabase test_file_name = "OgnConstantTexCoord3fTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_ConstantTexCoord3f") database = OgnConstantTexCoord3fDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:value")) attribute = test_node.get_attribute("inputs:value") db_value = database.inputs.value expected_value = [0.0, 0.0, 0.0] actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False))
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnGetPrimRelationship.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnGetPrimRelationshipDatabase import OgnGetPrimRelationshipDatabase test_file_name = "OgnGetPrimRelationshipTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_GetPrimRelationship") database = OgnGetPrimRelationshipDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 3) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:name")) attribute = test_node.get_attribute("inputs:name") db_value = database.inputs.name expected_value = "" actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:usePath")) attribute = test_node.get_attribute("inputs:usePath") db_value = database.inputs.usePath expected_value = False actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("outputs:paths")) attribute = test_node.get_attribute("outputs:paths") db_value = database.outputs.paths
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnConstantTexCoord2f.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnConstantTexCoord2fDatabase import OgnConstantTexCoord2fDatabase test_file_name = "OgnConstantTexCoord2fTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_ConstantTexCoord2f") database = OgnConstantTexCoord2fDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:value")) attribute = test_node.get_attribute("inputs:value") db_value = database.inputs.value expected_value = [0.0, 0.0] actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False))
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnNthRoot.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): TEST_DATA = [ { 'inputs': [ ['inputs:value', {'type': 'float', 'value': 36.0}, False], ], 'outputs': [ ['outputs:result', {'type': 'float', 'value': 6.0}, False], ], }, { 'inputs': [ ['inputs:value', {'type': 'double', 'value': 27.0}, False], ['inputs:nthRoot', 3, False], ], 'outputs': [ ['outputs:result', {'type': 'double', 'value': 3.0}, False], ], }, { 'inputs': [ ['inputs:value', {'type': 'float[2]', 'value': [0.25, 4.0]}, False], ], 'outputs': [ ['outputs:result', {'type': 'float[2]', 'value': [0.5, 2.0]}, False], ], }, { 'inputs': [ ['inputs:value', {'type': 'float[]', 'value': [1.331, 8.0]}, False], ['inputs:nthRoot', 3, False], ], 'outputs': [ ['outputs:result', {'type': 'float[]', 'value': [1.1, 2.0]}, False], ], }, { 'inputs': [ ['inputs:value', {'type': 'float[2][]', 'value': [[4.0, 16.0], [2.25, 64.0]]}, False], ], 'outputs': [ ['outputs:result', {'type': 'float[2][]', 'value': [[2.0, 4.0], [1.5, 8.0]]}, False], ], }, { 'inputs': [ ['inputs:value', {'type': 'int64', 'value': 9223372036854775807}, False], ['inputs:nthRoot', 1, False], ], 'outputs': [ ['outputs:result', {'type': 'double', 'value': 9.223372036854776e+18}, False], ], }, { 'inputs': [ ['inputs:value', {'type': 'int', 'value': 256}, False], ['inputs:nthRoot', 4, False], ], 'outputs': [ ['outputs:result', {'type': 'double', 'value': 4.0}, False], ], }, { 'inputs': [ ['inputs:value', {'type': 'uint64', 'value': 8}, False], ['inputs:nthRoot', 3, False], ], 'outputs': [ ['outputs:result', {'type': 'double', 'value': 2.0}, False], ], }, { 'inputs': [ ['inputs:value', {'type': 'half[2]', 'value': [0.125, 1.0]}, False], ['inputs:nthRoot', 3, False], ], 'outputs': [ ['outputs:result', {'type': 'half[2]', 'value': [0.5, 1.0]}, False], ], }, { 'inputs': [ ['inputs:value', {'type': 'uchar', 'value': 25}, False], ], 'outputs': [ ['outputs:result', {'type': 'double', 'value': 5.0}, False], ], }, { 'inputs': [ ['inputs:value', {'type': 'int64', 'value': 16}, False], ['inputs:nthRoot', -2, False], ], 'outputs': [ ['outputs:result', {'type': 'double', 'value': 0.25}, False], ], }, { 'inputs': [ ['inputs:value', {'type': 'double', 'value': 0.125}, False], ['inputs:nthRoot', -3, False], ], 'outputs': [ ['outputs:result', {'type': 'double', 'value': 2}, False], ], }, ] async def test_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_NthRoot", "omni.graph.nodes.NthRoot", test_run, test_info) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.NthRoot User test case #{i+1}") async def test_vectorized_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_NthRoot","omni.graph.nodes.NthRoot", test_run, test_info, 16) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.NthRoot User test case #{i+1}", 16) async def test_thread_safety(self): import omni.kit # Generate multiple instances of the test setup to run them concurrently instance_setup = dict() for n in range(24): instance_setup[f"/TestGraph_{n}"] = _TestGraphAndNode() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) for (key, test_info) in instance_setup.items(): test_info = await _test_setup_scene(self, og.Controller(allow_exists_prim=True), key, "TestNode_omni_graph_nodes_NthRoot", "omni.graph.nodes.NthRoot", test_run, test_info) self.assertEqual(len(og.get_all_graphs()), 24) # We want to evaluate all graphs concurrently. Kick them all. # Evaluate multiple times to skip 2 serial frames and increase chances for a race condition. for _ in range(10): await omni.kit.app.get_app().next_update_async() for (key, test_instance) in instance_setup.items(): _test_verify_scene(self, og.Controller(), test_run, test_info, f"omni.graph.nodes.NthRoot User test case #{i+1}, instance{key}") async def test_data_access(self): from omni.graph.nodes.ogn.OgnNthRootDatabase import OgnNthRootDatabase test_file_name = "OgnNthRootTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_NthRoot") database = OgnNthRootDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:nthRoot")) attribute = test_node.get_attribute("inputs:nthRoot") db_value = database.inputs.nthRoot expected_value = 2 actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False))
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnDeformedPointsToHydra.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnDeformedPointsToHydraDatabase import OgnDeformedPointsToHydraDatabase test_file_name = "OgnDeformedPointsToHydraTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_DeformedPointsToHydra") database = OgnDeformedPointsToHydraDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:points")) attribute = test_node.get_attribute("inputs:points") expected_value = [] actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) self.assertTrue(test_node.get_attribute_exists("inputs:primPath")) attribute = test_node.get_attribute("inputs:primPath") db_value = database.inputs.primPath expected_value = "" actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:sendToHydra")) attribute = test_node.get_attribute("inputs:sendToHydra") db_value = database.inputs.sendToHydra expected_value = False actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:stream")) attribute = test_node.get_attribute("inputs:stream") db_value = database.inputs.stream expected_value = 0 actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:verbose")) attribute = test_node.get_attribute("inputs:verbose") db_value = database.inputs.verbose expected_value = False actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("outputs:reload")) attribute = test_node.get_attribute("outputs:reload") db_value = database.outputs.reload
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnToUint64.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): TEST_DATA = [ { 'inputs': [ ['inputs:value', {'type': 'float[]', 'value': []}, False], ], 'outputs': [ ['outputs:converted', {'type': 'uint64[]', 'value': []}, False], ], }, { 'inputs': [ ['inputs:value', {'type': 'double', 'value': 2.1}, False], ], 'outputs': [ ['outputs:converted', {'type': 'uint64', 'value': 2}, False], ], }, { 'inputs': [ ['inputs:value', {'type': 'half', 'value': 2.9}, False], ], 'outputs': [ ['outputs:converted', {'type': 'uint64', 'value': 2}, False], ], }, { 'inputs': [ ['inputs:value', {'type': 'int', 'value': 42}, False], ], 'outputs': [ ['outputs:converted', {'type': 'uint64', 'value': 42}, False], ], }, { 'inputs': [ ['inputs:value', {'type': 'int64', 'value': 42}, False], ], 'outputs': [ ['outputs:converted', {'type': 'uint64', 'value': 42}, False], ], }, { 'inputs': [ ['inputs:value', {'type': 'bool[]', 'value': [True, False]}, False], ], 'outputs': [ ['outputs:converted', {'type': 'uint64[]', 'value': [1, 0]}, False], ], }, { 'inputs': [ ['inputs:value', {'type': 'half[]', 'value': [2, 3, 4]}, False], ], 'outputs': [ ['outputs:converted', {'type': 'uint64[]', 'value': [2, 3, 4]}, False], ], }, { 'inputs': [ ['inputs:value', {'type': 'uint[]', 'value': [2, 3, 4]}, False], ], 'outputs': [ ['outputs:converted', {'type': 'uint64[]', 'value': [2, 3, 4]}, False], ], }, { 'inputs': [ ['inputs:value', {'type': 'int64[]', 'value': [2, 3, -4]}, False], ], 'outputs': [ ['outputs:converted', {'type': 'uint64[]', 'value': [2, 3, 18446744073709551612]}, False], ], }, ] async def test_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_ToUint64", "omni.graph.nodes.ToUint64", test_run, test_info) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.ToUint64 User test case #{i+1}") async def test_vectorized_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_ToUint64","omni.graph.nodes.ToUint64", test_run, test_info, 16) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.ToUint64 User test case #{i+1}", 16) async def test_thread_safety(self): import omni.kit # Generate multiple instances of the test setup to run them concurrently instance_setup = dict() for n in range(24): instance_setup[f"/TestGraph_{n}"] = _TestGraphAndNode() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) for (key, test_info) in instance_setup.items(): test_info = await _test_setup_scene(self, og.Controller(allow_exists_prim=True), key, "TestNode_omni_graph_nodes_ToUint64", "omni.graph.nodes.ToUint64", test_run, test_info) self.assertEqual(len(og.get_all_graphs()), 24) # We want to evaluate all graphs concurrently. Kick them all. # Evaluate multiple times to skip 2 serial frames and increase chances for a race condition. for _ in range(10): await omni.kit.app.get_app().next_update_async() for (key, test_instance) in instance_setup.items(): _test_verify_scene(self, og.Controller(), test_run, test_info, f"omni.graph.nodes.ToUint64 User test case #{i+1}, instance{key}") async def test_data_access(self): from omni.graph.nodes.ogn.OgnToUint64Database import OgnToUint64Database test_file_name = "OgnToUint64Template.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_ToUint64") database = OgnToUint64Database(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error"
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnEase.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): TEST_DATA = [ { 'inputs': [ ['inputs:start', {'type': 'float', 'value': 0}, False], ['inputs:end', {'type': 'float', 'value': 10}, False], ['inputs:easeFunc', "Linear", False], ['inputs:alpha', {'type': 'float', 'value': 0.5}, False], ], 'outputs': [ ['outputs:result', {'type': 'float', 'value': 5}, False], ], }, { 'inputs': [ ['inputs:start', {'type': 'float[]', 'value': [0, 1]}, False], ['inputs:end', {'type': 'float[]', 'value': [10, 11]}, False], ['inputs:easeFunc', "Linear", False], ['inputs:alpha', {'type': 'float[]', 'value': [0.5, 0.6]}, False], ], 'outputs': [ ['outputs:result', {'type': 'float[]', 'value': [5, 7]}, False], ], }, { 'inputs': [ ['inputs:start', {'type': 'float[]', 'value': [0, 0]}, False], ['inputs:end', {'type': 'float', 'value': 10}, False], ['inputs:easeFunc', "Linear", False], ['inputs:alpha', {'type': 'float[]', 'value': [0.5, 0.6]}, False], ], 'outputs': [ ['outputs:result', {'type': 'float[]', 'value': [5, 6]}, False], ], }, { 'inputs': [ ['inputs:start', {'type': 'float', 'value': 0}, False], ['inputs:end', {'type': 'float', 'value': 10}, False], ['inputs:easeFunc', "Linear", False], ['inputs:alpha', {'type': 'float[]', 'value': [0.5, 0.6]}, False], ], 'outputs': [ ['outputs:result', {'type': 'float[]', 'value': [5, 6]}, False], ], }, { 'inputs': [ ['inputs:start', {'type': 'float[2]', 'value': [0, 0]}, False], ['inputs:end', {'type': 'float[2]', 'value': [10, 10]}, False], ['inputs:easeFunc', "Linear", False], ['inputs:alpha', {'type': 'float[]', 'value': [0.5, 0.6]}, False], ], 'outputs': [ ['outputs:result', {'type': 'float[2][]', 'value': [[5, 5], [6, 6]]}, False], ], }, { 'inputs': [ ['inputs:start', {'type': 'float[2][]', 'value': [[0, 0], [10, 10]]}, False], ['inputs:end', {'type': 'float[2]', 'value': [10, 20]}, False], ['inputs:easeFunc', "Linear", False], ['inputs:alpha', {'type': 'float[]', 'value': [0.5, 0.5]}, False], ], 'outputs': [ ['outputs:result', {'type': 'float[2][]', 'value': [[5, 10], [10, 15]]}, False], ], }, { 'inputs': [ ['inputs:start', {'type': 'double', 'value': 0.0}, False], ['inputs:end', {'type': 'double', 'value': 10.0}, False], ['inputs:easeFunc', "EaseInOut", False], ['inputs:alpha', {'type': 'float', 'value': 0.25}, False], ], 'outputs': [ ['outputs:result', {'type': 'double', 'value': 1.25}, False], ], }, { 'inputs': [ ['inputs:start', {'type': 'double', 'value': 0.0}, False], ['inputs:end', {'type': 'double', 'value': 10.0}, False], ['inputs:easeFunc', "SinOut", False], ['inputs:alpha', {'type': 'float', 'value': 0.75}, False], ], 'outputs': [ ['outputs:result', {'type': 'double', 'value': 9.238795}, False], ], }, { 'inputs': [ ['inputs:start', {'type': 'float[2]', 'value': [0, 1]}, False], ['inputs:end', {'type': 'float[2]', 'value': [10.0, 11.0]}, False], ['inputs:easeFunc', "Linear", False], ['inputs:alpha', {'type': 'float', 'value': 0.5}, False], ], 'outputs': [ ['outputs:result', {'type': 'float[2]', 'value': [5.0, 6.0]}, False], ], }, { 'inputs': [ ['inputs:start', {'type': 'half[3]', 'value': [0, 1, 2]}, False], ['inputs:end', {'type': 'half[3]', 'value': [10.0, 11.0, 12.0]}, False], ['inputs:easeFunc', "Linear", False], ['inputs:alpha', {'type': 'float', 'value': 0.5}, False], ], 'outputs': [ ['outputs:result', {'type': 'half[3]', 'value': [5.0, 6.0, 7.0]}, False], ], }, { 'inputs': [ ['inputs:start', {'type': 'float', 'value': 0}, False], ['inputs:end', {'type': 'float', 'value': 10}, False], ['inputs:easeFunc', "Linear", False], ['inputs:alpha', {'type': 'float', 'value': 1.524}, False], ], 'outputs': [ ['outputs:result', {'type': 'float', 'value': 10}, False], ], }, { 'inputs': [ ['inputs:start', {'type': 'float', 'value': 0}, False], ['inputs:end', {'type': 'float', 'value': 10}, False], ['inputs:easeFunc', "Linear", False], ['inputs:alpha', {'type': 'float', 'value': -20}, False], ], 'outputs': [ ['outputs:result', {'type': 'float', 'value': 0}, False], ], }, ] async def test_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_Ease", "omni.graph.nodes.Ease", test_run, test_info) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.Ease User test case #{i+1}") async def test_vectorized_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_Ease","omni.graph.nodes.Ease", test_run, test_info, 16) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.Ease User test case #{i+1}", 16) async def test_thread_safety(self): import omni.kit # Generate multiple instances of the test setup to run them concurrently instance_setup = dict() for n in range(24): instance_setup[f"/TestGraph_{n}"] = _TestGraphAndNode() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) for (key, test_info) in instance_setup.items(): test_info = await _test_setup_scene(self, og.Controller(allow_exists_prim=True), key, "TestNode_omni_graph_nodes_Ease", "omni.graph.nodes.Ease", test_run, test_info) self.assertEqual(len(og.get_all_graphs()), 24) # We want to evaluate all graphs concurrently. Kick them all. # Evaluate multiple times to skip 2 serial frames and increase chances for a race condition. for _ in range(10): await omni.kit.app.get_app().next_update_async() for (key, test_instance) in instance_setup.items(): _test_verify_scene(self, og.Controller(), test_run, test_info, f"omni.graph.nodes.Ease User test case #{i+1}, instance{key}") async def test_data_access(self): from omni.graph.nodes.ogn.OgnEaseDatabase import OgnEaseDatabase test_file_name = "OgnEaseTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_Ease") database = OgnEaseDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 2) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:blendExponent")) attribute = test_node.get_attribute("inputs:blendExponent") db_value = database.inputs.blendExponent expected_value = 2 actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:easeFunc")) attribute = test_node.get_attribute("inputs:easeFunc") db_value = database.inputs.easeFunc expected_value = "EaseInOut" actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False))
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnConstantUInt.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnConstantUIntDatabase import OgnConstantUIntDatabase test_file_name = "OgnConstantUIntTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_ConstantUInt") database = OgnConstantUIntDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:value")) attribute = test_node.get_attribute("inputs:value") db_value = database.inputs.value expected_value = 0 actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False))
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnClearVariantSelection.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnClearVariantSelectionDatabase import OgnClearVariantSelectionDatabase test_file_name = "OgnClearVariantSelectionTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_ClearVariantSelection") database = OgnClearVariantSelectionDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 2) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:execIn")) attribute = test_node.get_attribute("inputs:execIn") db_value = database.inputs.execIn self.assertTrue(test_node.get_attribute_exists("inputs:prim")) attribute = test_node.get_attribute("inputs:prim") db_value = database.inputs.prim self.assertTrue(test_node.get_attribute_exists("inputs:setVariant")) attribute = test_node.get_attribute("inputs:setVariant") db_value = database.inputs.setVariant expected_value = False actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:variantSetName")) attribute = test_node.get_attribute("inputs:variantSetName") db_value = database.inputs.variantSetName expected_value = "" actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("outputs:execOut")) attribute = test_node.get_attribute("outputs:execOut") db_value = database.outputs.execOut
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnAsin.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): TEST_DATA = [ { 'inputs': [ ['inputs:value', {'type': 'float', 'value': 0.707107}, False], ], 'outputs': [ ['outputs:value', {'type': 'float', 'value': 45.0}, False], ], }, { 'inputs': [ ['inputs:value', {'type': 'double', 'value': 0.5}, False], ], 'outputs': [ ['outputs:value', {'type': 'double', 'value': 30.0}, False], ], }, ] async def test_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_Asin", "omni.graph.nodes.Asin", test_run, test_info) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.Asin User test case #{i+1}") async def test_vectorized_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_Asin","omni.graph.nodes.Asin", test_run, test_info, 16) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.Asin User test case #{i+1}", 16) async def test_thread_safety(self): import omni.kit # Generate multiple instances of the test setup to run them concurrently instance_setup = dict() for n in range(24): instance_setup[f"/TestGraph_{n}"] = _TestGraphAndNode() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) for (key, test_info) in instance_setup.items(): test_info = await _test_setup_scene(self, og.Controller(allow_exists_prim=True), key, "TestNode_omni_graph_nodes_Asin", "omni.graph.nodes.Asin", test_run, test_info) self.assertEqual(len(og.get_all_graphs()), 24) # We want to evaluate all graphs concurrently. Kick them all. # Evaluate multiple times to skip 2 serial frames and increase chances for a race condition. for _ in range(10): await omni.kit.app.get_app().next_update_async() for (key, test_instance) in instance_setup.items(): _test_verify_scene(self, og.Controller(), test_run, test_info, f"omni.graph.nodes.Asin User test case #{i+1}, instance{key}") async def test_data_access(self): from omni.graph.nodes.ogn.OgnAsinDatabase import OgnAsinDatabase test_file_name = "OgnAsinTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_Asin") database = OgnAsinDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error"
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnGetMatrix4Translation.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): TEST_DATA = [ { 'inputs': [ ['inputs:matrix', {'type': 'matrixd[4]', 'value': [1.0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 50, 0, 0, 1]}, False], ], 'outputs': [ ['outputs:translation', {'type': 'vectord[3]', 'value': [50, 0, 0]}, False], ], }, { 'inputs': [ ['inputs:matrix', {'type': 'matrixd[4][]', 'value': [[1.0, 0, 3, 0, 0, 1, 0, 1, 0, 0, 1, 0, 50, 0, 0, 1], [1.0, 0, 0, 3, 0, 1, 0, 1, 0, 0, 1, 0, 1, 100, 4, 1]]}, False], ], 'outputs': [ ['outputs:translation', {'type': 'vectord[3][]', 'value': [[50, 0, 0], [1, 100, 4]]}, False], ], }, ] async def test_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_GetMatrix4Translation", "omni.graph.nodes.GetMatrix4Translation", test_run, test_info) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.GetMatrix4Translation User test case #{i+1}") async def test_vectorized_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_GetMatrix4Translation","omni.graph.nodes.GetMatrix4Translation", test_run, test_info, 16) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.GetMatrix4Translation User test case #{i+1}", 16) async def test_thread_safety(self): import omni.kit # Generate multiple instances of the test setup to run them concurrently instance_setup = dict() for n in range(24): instance_setup[f"/TestGraph_{n}"] = _TestGraphAndNode() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) for (key, test_info) in instance_setup.items(): test_info = await _test_setup_scene(self, og.Controller(allow_exists_prim=True), key, "TestNode_omni_graph_nodes_GetMatrix4Translation", "omni.graph.nodes.GetMatrix4Translation", test_run, test_info) self.assertEqual(len(og.get_all_graphs()), 24) # We want to evaluate all graphs concurrently. Kick them all. # Evaluate multiple times to skip 2 serial frames and increase chances for a race condition. for _ in range(10): await omni.kit.app.get_app().next_update_async() for (key, test_instance) in instance_setup.items(): _test_verify_scene(self, og.Controller(), test_run, test_info, f"omni.graph.nodes.GetMatrix4Translation User test case #{i+1}, instance{key}") async def test_data_access(self): from omni.graph.nodes.ogn.OgnGetMatrix4TranslationDatabase import OgnGetMatrix4TranslationDatabase test_file_name = "OgnGetMatrix4TranslationTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_GetMatrix4Translation") database = OgnGetMatrix4TranslationDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error"
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnCeil.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): TEST_DATA = [ { 'inputs': [ ['inputs:a', {'type': 'float', 'value': 4.1}, False], ], 'outputs': [ ['outputs:result', 5, False], ], }, { 'inputs': [ ['inputs:a', {'type': 'half', 'value': -4.9}, False], ], 'outputs': [ ['outputs:result', -4, False], ], }, { 'inputs': [ ['inputs:a', {'type': 'double[3]', 'value': [1.3, 2.4, -3.7]}, False], ], 'outputs': [ ['outputs:result', [2, 3, -3], False], ], }, { 'inputs': [ ['inputs:a', {'type': 'double[]', 'value': [1.3, 2.4, -3.7, 4.5]}, False], ], 'outputs': [ ['outputs:result', [2, 3, -3, 5], False], ], }, ] async def test_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_Ceil", "omni.graph.nodes.Ceil", test_run, test_info) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.Ceil User test case #{i+1}") async def test_vectorized_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_Ceil","omni.graph.nodes.Ceil", test_run, test_info, 16) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.Ceil User test case #{i+1}", 16) async def test_thread_safety(self): import omni.kit # Generate multiple instances of the test setup to run them concurrently instance_setup = dict() for n in range(24): instance_setup[f"/TestGraph_{n}"] = _TestGraphAndNode() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) for (key, test_info) in instance_setup.items(): test_info = await _test_setup_scene(self, og.Controller(allow_exists_prim=True), key, "TestNode_omni_graph_nodes_Ceil", "omni.graph.nodes.Ceil", test_run, test_info) self.assertEqual(len(og.get_all_graphs()), 24) # We want to evaluate all graphs concurrently. Kick them all. # Evaluate multiple times to skip 2 serial frames and increase chances for a race condition. for _ in range(10): await omni.kit.app.get_app().next_update_async() for (key, test_instance) in instance_setup.items(): _test_verify_scene(self, og.Controller(), test_run, test_info, f"omni.graph.nodes.Ceil User test case #{i+1}, instance{key}") async def test_data_access(self): from omni.graph.nodes.ogn.OgnCeilDatabase import OgnCeilDatabase test_file_name = "OgnCeilTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_Ceil") database = OgnCeilDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error"
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnATan2.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): TEST_DATA = [ { 'inputs': [ ['inputs:a', {'type': 'float', 'value': 5.0}, False], ['inputs:b', {'type': 'float', 'value': 3.0}, False], ], 'outputs': [ ['outputs:result', {'type': 'float', 'value': 59.0362434679}, False], ], }, { 'inputs': [ ['inputs:a', {'type': 'double', 'value': 70.0}, False], ['inputs:b', {'type': 'double', 'value': 10.0}, False], ], 'outputs': [ ['outputs:result', {'type': 'double', 'value': 81.8698976458}, False], ], }, ] async def test_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_ATan2", "omni.graph.nodes.ATan2", test_run, test_info) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.ATan2 User test case #{i+1}") async def test_vectorized_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_ATan2","omni.graph.nodes.ATan2", test_run, test_info, 16) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.ATan2 User test case #{i+1}", 16) async def test_data_access(self): from omni.graph.nodes.ogn.OgnATan2Database import OgnATan2Database test_file_name = "OgnATan2Template.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_ATan2") database = OgnATan2Database(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error"
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnPartialSum.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): TEST_DATA = [ { 'inputs': [ ['inputs:array', [1, 2, 3, 4, 5], False], ], 'outputs': [ ['outputs:partialSum', [0, 1, 3, 6, 10, 15], False], ], }, ] async def test_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_PartialSum", "omni.graph.nodes.PartialSum", test_run, test_info) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.PartialSum User test case #{i+1}") async def test_vectorized_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_PartialSum","omni.graph.nodes.PartialSum", test_run, test_info, 16) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.PartialSum User test case #{i+1}", 16) async def test_thread_safety(self): import omni.kit # Generate multiple instances of the test setup to run them concurrently instance_setup = dict() for n in range(24): instance_setup[f"/TestGraph_{n}"] = _TestGraphAndNode() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) for (key, test_info) in instance_setup.items(): test_info = await _test_setup_scene(self, og.Controller(allow_exists_prim=True), key, "TestNode_omni_graph_nodes_PartialSum", "omni.graph.nodes.PartialSum", test_run, test_info) self.assertEqual(len(og.get_all_graphs()), 24) # We want to evaluate all graphs concurrently. Kick them all. # Evaluate multiple times to skip 2 serial frames and increase chances for a race condition. for _ in range(10): await omni.kit.app.get_app().next_update_async() for (key, test_instance) in instance_setup.items(): _test_verify_scene(self, og.Controller(), test_run, test_info, f"omni.graph.nodes.PartialSum User test case #{i+1}, instance{key}") async def test_data_access(self): from omni.graph.nodes.ogn.OgnPartialSumDatabase import OgnPartialSumDatabase test_file_name = "OgnPartialSumTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_PartialSum") database = OgnPartialSumDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:array")) attribute = test_node.get_attribute("inputs:array") db_value = database.inputs.array expected_value = [] actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("outputs:partialSum")) attribute = test_node.get_attribute("outputs:partialSum") db_value = database.outputs.partialSum
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnReadKeyboardState.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnReadKeyboardStateDatabase import OgnReadKeyboardStateDatabase test_file_name = "OgnReadKeyboardStateTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_ReadKeyboardState") database = OgnReadKeyboardStateDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:key")) attribute = test_node.get_attribute("inputs:key") db_value = database.inputs.key expected_value = "A" actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("outputs:altOut")) attribute = test_node.get_attribute("outputs:altOut") db_value = database.outputs.altOut self.assertTrue(test_node.get_attribute_exists("outputs:ctrlOut")) attribute = test_node.get_attribute("outputs:ctrlOut") db_value = database.outputs.ctrlOut self.assertTrue(test_node.get_attribute_exists("outputs:isPressed")) attribute = test_node.get_attribute("outputs:isPressed") db_value = database.outputs.isPressed self.assertTrue(test_node.get_attribute_exists("outputs:shiftOut")) attribute = test_node.get_attribute("outputs:shiftOut") db_value = database.outputs.shiftOut
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnTimelineStop.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnTimelineStopDatabase import OgnTimelineStopDatabase test_file_name = "OgnTimelineStopTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_StopTimeline") database = OgnTimelineStopDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:execIn")) attribute = test_node.get_attribute("inputs:execIn") db_value = database.inputs.execIn self.assertTrue(test_node.get_attribute_exists("outputs:execOut")) attribute = test_node.get_attribute("outputs:execOut") db_value = database.outputs.execOut
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnGetLocationAtDistanceOnCurve2.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): TEST_DATA = [ { 'inputs': [ ['inputs:curve', [[1, 2, 3]], False], ['inputs:distance', 0.5, False], ], 'outputs': [ ['outputs:location', [1, 2, 3], False], ], }, { 'inputs': [ ['inputs:curve', [[0, 0, 0], [0, 0, 1]], False], ['inputs:distance', 0.75, False], ['inputs:forwardAxis', "X", False], ['inputs:upAxis', "Y", False], ], 'outputs': [ ['outputs:location', [0, 0, 0.5], False], ['outputs:rotateXYZ', [0, 90, 0], False], ], }, ] async def test_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_GetLocationAtDistanceOnCurve2", "omni.graph.nodes.GetLocationAtDistanceOnCurve2", test_run, test_info) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.GetLocationAtDistanceOnCurve2 User test case #{i+1}") async def test_vectorized_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_GetLocationAtDistanceOnCurve2","omni.graph.nodes.GetLocationAtDistanceOnCurve2", test_run, test_info, 16) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.GetLocationAtDistanceOnCurve2 User test case #{i+1}", 16) async def test_thread_safety(self): import omni.kit # Generate multiple instances of the test setup to run them concurrently instance_setup = dict() for n in range(24): instance_setup[f"/TestGraph_{n}"] = _TestGraphAndNode() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) for (key, test_info) in instance_setup.items(): test_info = await _test_setup_scene(self, og.Controller(allow_exists_prim=True), key, "TestNode_omni_graph_nodes_GetLocationAtDistanceOnCurve2", "omni.graph.nodes.GetLocationAtDistanceOnCurve2", test_run, test_info) self.assertEqual(len(og.get_all_graphs()), 24) # We want to evaluate all graphs concurrently. Kick them all. # Evaluate multiple times to skip 2 serial frames and increase chances for a race condition. for _ in range(10): await omni.kit.app.get_app().next_update_async() for (key, test_instance) in instance_setup.items(): _test_verify_scene(self, og.Controller(), test_run, test_info, f"omni.graph.nodes.GetLocationAtDistanceOnCurve2 User test case #{i+1}, instance{key}") async def test_data_access(self): from omni.graph.nodes.ogn.OgnGetLocationAtDistanceOnCurve2Database import OgnGetLocationAtDistanceOnCurve2Database test_file_name = "OgnGetLocationAtDistanceOnCurve2Template.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_GetLocationAtDistanceOnCurve2") database = OgnGetLocationAtDistanceOnCurve2Database(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:curve")) attribute = test_node.get_attribute("inputs:curve") db_value = database.inputs.curve expected_value = [] actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:distance")) attribute = test_node.get_attribute("inputs:distance") db_value = database.inputs.distance expected_value = 0.0 actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:forwardAxis")) attribute = test_node.get_attribute("inputs:forwardAxis") db_value = database.inputs.forwardAxis expected_value = "X" actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:upAxis")) attribute = test_node.get_attribute("inputs:upAxis") db_value = database.inputs.upAxis expected_value = "Y" actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("outputs:location")) attribute = test_node.get_attribute("outputs:location") db_value = database.outputs.location self.assertTrue(test_node.get_attribute_exists("outputs:orientation")) attribute = test_node.get_attribute("outputs:orientation") db_value = database.outputs.orientation self.assertTrue(test_node.get_attribute_exists("outputs:rotateXYZ")) attribute = test_node.get_attribute("outputs:rotateXYZ") db_value = database.outputs.rotateXYZ
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnConstantHalf4.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnConstantHalf4Database import OgnConstantHalf4Database test_file_name = "OgnConstantHalf4Template.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_ConstantHalf4") database = OgnConstantHalf4Database(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:value")) attribute = test_node.get_attribute("inputs:value") db_value = database.inputs.value expected_value = [0.0, 0.0, 0.0, 0.0] actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False))
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnPauseSound.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnPauseSoundDatabase import OgnPauseSoundDatabase test_file_name = "OgnPauseSoundTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_PauseSound") database = OgnPauseSoundDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:execIn")) attribute = test_node.get_attribute("inputs:execIn") db_value = database.inputs.execIn self.assertTrue(test_node.get_attribute_exists("inputs:soundId")) attribute = test_node.get_attribute("inputs:soundId") db_value = database.inputs.soundId expected_value = 0 actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("outputs:execOut")) attribute = test_node.get_attribute("outputs:execOut") db_value = database.outputs.execOut
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnConstantInt64.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnConstantInt64Database import OgnConstantInt64Database test_file_name = "OgnConstantInt64Template.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_ConstantInt64") database = OgnConstantInt64Database(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:value")) attribute = test_node.get_attribute("inputs:value") db_value = database.inputs.value expected_value = 0 actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False))
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnConstantFloat.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnConstantFloatDatabase import OgnConstantFloatDatabase test_file_name = "OgnConstantFloatTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_ConstantFloat") database = OgnConstantFloatDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:value")) attribute = test_node.get_attribute("inputs:value") db_value = database.inputs.value expected_value = 0.0 actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False))
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnAtan.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): TEST_DATA = [ { 'inputs': [ ['inputs:value', {'type': 'float', 'value': 1}, False], ], 'outputs': [ ['outputs:value', {'type': 'float', 'value': 45.0}, False], ], }, ] async def test_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_Atan", "omni.graph.nodes.Atan", test_run, test_info) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.Atan User test case #{i+1}") async def test_vectorized_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_Atan","omni.graph.nodes.Atan", test_run, test_info, 16) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.Atan User test case #{i+1}", 16) async def test_thread_safety(self): import omni.kit # Generate multiple instances of the test setup to run them concurrently instance_setup = dict() for n in range(24): instance_setup[f"/TestGraph_{n}"] = _TestGraphAndNode() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) for (key, test_info) in instance_setup.items(): test_info = await _test_setup_scene(self, og.Controller(allow_exists_prim=True), key, "TestNode_omni_graph_nodes_Atan", "omni.graph.nodes.Atan", test_run, test_info) self.assertEqual(len(og.get_all_graphs()), 24) # We want to evaluate all graphs concurrently. Kick them all. # Evaluate multiple times to skip 2 serial frames and increase chances for a race condition. for _ in range(10): await omni.kit.app.get_app().next_update_async() for (key, test_instance) in instance_setup.items(): _test_verify_scene(self, og.Controller(), test_run, test_info, f"omni.graph.nodes.Atan User test case #{i+1}, instance{key}") async def test_data_access(self): from omni.graph.nodes.ogn.OgnAtanDatabase import OgnAtanDatabase test_file_name = "OgnAtanTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_Atan") database = OgnAtanDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error"
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnRpResourceExampleAllocator.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnRpResourceExampleAllocatorDatabase import OgnRpResourceExampleAllocatorDatabase test_file_name = "OgnRpResourceExampleAllocatorTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_RpResourceExampleAllocator") database = OgnRpResourceExampleAllocatorDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:points")) attribute = test_node.get_attribute("inputs:points") db_value = database.inputs.points expected_value = [] actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:primPath")) attribute = test_node.get_attribute("inputs:primPath") db_value = database.inputs.primPath expected_value = "" actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:reload")) attribute = test_node.get_attribute("inputs:reload") db_value = database.inputs.reload expected_value = False actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:stream")) attribute = test_node.get_attribute("inputs:stream") db_value = database.inputs.stream expected_value = 0 actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:verbose")) attribute = test_node.get_attribute("inputs:verbose") db_value = database.inputs.verbose expected_value = False actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("outputs:pointCountCollection")) attribute = test_node.get_attribute("outputs:pointCountCollection") db_value = database.outputs.pointCountCollection self.assertTrue(test_node.get_attribute_exists("outputs:primPathCollection")) attribute = test_node.get_attribute("outputs:primPathCollection") db_value = database.outputs.primPathCollection self.assertTrue(test_node.get_attribute_exists("outputs:reload")) attribute = test_node.get_attribute("outputs:reload") db_value = database.outputs.reload self.assertTrue(test_node.get_attribute_exists("outputs:resourcePointerCollection")) attribute = test_node.get_attribute("outputs:resourcePointerCollection") db_value = database.outputs.resourcePointerCollection self.assertTrue(test_node.get_attribute_exists("outputs:stream")) attribute = test_node.get_attribute("outputs:stream") db_value = database.outputs.stream
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnGetGraphTargetPrim.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnGetGraphTargetPrimDatabase import OgnGetGraphTargetPrimDatabase test_file_name = "OgnGetGraphTargetPrimTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_GetGraphTargetPrim") database = OgnGetGraphTargetPrimDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("outputs:prim")) attribute = test_node.get_attribute("outputs:prim") db_value = database.outputs.prim
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnNegate.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): TEST_DATA = [ { 'inputs': [ ['inputs:input', {'type': 'double', 'value': 1.0}, False], ], 'outputs': [ ['outputs:output', {'type': 'double', 'value': -1.0}, False], ], }, { 'inputs': [ ['inputs:input', {'type': 'float[2]', 'value': [0.0, 1.0]}, False], ], 'outputs': [ ['outputs:output', {'type': 'float[2]', 'value': [-0.0, -1.0]}, False], ], }, { 'inputs': [ ['inputs:input', {'type': 'half[3]', 'value': [-1.0, -0.0, 1.0]}, False], ], 'outputs': [ ['outputs:output', {'type': 'half[3]', 'value': [1.0, 0.0, -1.0]}, False], ], }, { 'inputs': [ ['inputs:input', {'type': 'int[4]', 'value': [-1, 0, 1, 2]}, False], ], 'outputs': [ ['outputs:output', {'type': 'int[4]', 'value': [1, 0, -1, -2]}, False], ], }, { 'inputs': [ ['inputs:input', {'type': 'int64[]', 'value': [-1, 0, 1, 2]}, False], ], 'outputs': [ ['outputs:output', {'type': 'int64[]', 'value': [1, 0, -1, -2]}, False], ], }, { 'inputs': [ ['inputs:input', {'type': 'double[][2]', 'value': [[-1.0, 0.0], [1.0, 2.0]]}, False], ], 'outputs': [ ['outputs:output', {'type': 'double[][2]', 'value': [[1.0, -0.0], [-1.0, -2.0]]}, False], ], }, ] async def test_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_Negate", "omni.graph.nodes.Negate", test_run, test_info) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.Negate User test case #{i+1}") async def test_vectorized_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_Negate","omni.graph.nodes.Negate", test_run, test_info, 16) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.Negate User test case #{i+1}", 16) async def test_thread_safety(self): import omni.kit # Generate multiple instances of the test setup to run them concurrently instance_setup = dict() for n in range(24): instance_setup[f"/TestGraph_{n}"] = _TestGraphAndNode() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) for (key, test_info) in instance_setup.items(): test_info = await _test_setup_scene(self, og.Controller(allow_exists_prim=True), key, "TestNode_omni_graph_nodes_Negate", "omni.graph.nodes.Negate", test_run, test_info) self.assertEqual(len(og.get_all_graphs()), 24) # We want to evaluate all graphs concurrently. Kick them all. # Evaluate multiple times to skip 2 serial frames and increase chances for a race condition. for _ in range(10): await omni.kit.app.get_app().next_update_async() for (key, test_instance) in instance_setup.items(): _test_verify_scene(self, og.Controller(), test_run, test_info, f"omni.graph.nodes.Negate User test case #{i+1}, instance{key}") async def test_data_access(self): from omni.graph.nodes.ogn.OgnNegateDatabase import OgnNegateDatabase test_file_name = "OgnNegateTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_Negate") database = OgnNegateDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error"
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnHasAttr.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): async def test_data_access(self): from omni.graph.nodes.ogn.OgnHasAttrDatabase import OgnHasAttrDatabase test_file_name = "OgnHasAttrTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_HasAttribute") database = OgnHasAttrDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:attrName")) attribute = test_node.get_attribute("inputs:attrName") db_value = database.inputs.attrName expected_value = "points" actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:data")) attribute = test_node.get_attribute("inputs:data") db_value = database.inputs.data self.assertTrue(test_node.get_attribute_exists("outputs:output")) attribute = test_node.get_attribute("outputs:output") db_value = database.outputs.output
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/tests/TestOgnGetLookAtRotation.py
import os import omni.kit.test import omni.graph.core as og import omni.graph.core.tests as ogts from omni.graph.core.tests.omnigraph_test_utils import _TestGraphAndNode from omni.graph.core.tests.omnigraph_test_utils import _test_clear_scene from omni.graph.core.tests.omnigraph_test_utils import _test_setup_scene from omni.graph.core.tests.omnigraph_test_utils import _test_verify_scene class TestOgn(ogts.OmniGraphTestCase): TEST_DATA = [ { 'inputs': [ ['inputs:start', [0.0, 0.0, 0.0], False], ['inputs:target', [100.0, 0.0, 0.0], False], ['inputs:forward', [1.0, 0.0, 0.0], False], ], 'outputs': [ ['outputs:rotateXYZ', [0.0, 0.0, 0.0], False], ['outputs:orientation', [0.0, 0.0, 0.0, 1.0], False], ], }, { 'inputs': [ ['inputs:start', [0.0, 0.0, 0.0], False], ['inputs:target', [100.0, 0.0, 0.0], False], ['inputs:forward', [0.0, 0.0, 1.0], False], ], 'outputs': [ ['outputs:rotateXYZ', [0.0, 90, 0.0], False], ['outputs:orientation', [0.0, 0.70710678, 0.0, 0.70710678], False], ], }, { 'inputs': [ ['inputs:start', [0.0, 0.0, 0.0], False], ['inputs:target', [100.0, 0.0, 100.0], False], ['inputs:forward', [1.0, 0.0, 0.0], False], ], 'outputs': [ ['outputs:rotateXYZ', [0.0, -45.0, 0.0], False], ['outputs:orientation', [0.0, -0.3826834, 0.0, 0.92387953], False], ], }, { 'inputs': [ ['inputs:start', [100.0, 0.0, 100.0], False], ['inputs:target', [200.0, 0.0, 100.0], False], ['inputs:forward', [1.0, 0.0, 0.0], False], ], 'outputs': [ ['outputs:rotateXYZ', [0.0, 0.0, 0.0], False], ['outputs:orientation', [0.0, 0.0, 0.0, 1.0], False], ], }, { 'inputs': [ ['inputs:start', [100.0, 0.0, -100.0], False], ['inputs:target', [-100.0, 200.0, -300.0], False], ['inputs:forward', [1.0, 0.0, 0.0], False], ], 'outputs': [ ['outputs:rotateXYZ', [150.0, 35.26439, 135.0], False], ['outputs:orientation', [0.27984814, 0.88047624, 0.115916896, 0.3647052], False], ], }, ] async def test_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_GetLookAtRotation", "omni.graph.nodes.GetLookAtRotation", test_run, test_info) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.GetLookAtRotation User test case #{i+1}") async def test_vectorized_generated(self): test_info = _TestGraphAndNode() controller = og.Controller() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) test_info = await _test_setup_scene(self, controller, "/TestGraph", "TestNode_omni_graph_nodes_GetLookAtRotation","omni.graph.nodes.GetLookAtRotation", test_run, test_info, 16) await controller.evaluate(test_info.graph) _test_verify_scene(self, controller, test_run, test_info, f"omni.graph.nodes.GetLookAtRotation User test case #{i+1}", 16) async def test_thread_safety(self): import omni.kit # Generate multiple instances of the test setup to run them concurrently instance_setup = dict() for n in range(24): instance_setup[f"/TestGraph_{n}"] = _TestGraphAndNode() for i, test_run in enumerate(self.TEST_DATA): await _test_clear_scene(self, test_run) for (key, test_info) in instance_setup.items(): test_info = await _test_setup_scene(self, og.Controller(allow_exists_prim=True), key, "TestNode_omni_graph_nodes_GetLookAtRotation", "omni.graph.nodes.GetLookAtRotation", test_run, test_info) self.assertEqual(len(og.get_all_graphs()), 24) # We want to evaluate all graphs concurrently. Kick them all. # Evaluate multiple times to skip 2 serial frames and increase chances for a race condition. for _ in range(10): await omni.kit.app.get_app().next_update_async() for (key, test_instance) in instance_setup.items(): _test_verify_scene(self, og.Controller(), test_run, test_info, f"omni.graph.nodes.GetLookAtRotation User test case #{i+1}, instance{key}") async def test_data_access(self): from omni.graph.nodes.ogn.OgnGetLookAtRotationDatabase import OgnGetLookAtRotationDatabase test_file_name = "OgnGetLookAtRotationTemplate.usda" usd_path = os.path.join(os.path.dirname(__file__), "usd", test_file_name) if not os.path.exists(usd_path): self.assertTrue(False, f"{usd_path} not found for loading test") (result, error) = await ogts.load_test_file(usd_path) self.assertTrue(result, f'{error} on {usd_path}') test_node = og.Controller.node("/TestGraph/Template_omni_graph_nodes_GetLookAtRotation") database = OgnGetLookAtRotationDatabase(test_node) self.assertTrue(test_node.is_valid()) node_type_name = test_node.get_type_name() self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1) def _attr_error(attribute: og.Attribute, usd_test: bool) -> str: test_type = "USD Load" if usd_test else "Database Access" return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error" self.assertTrue(test_node.get_attribute_exists("inputs:forward")) attribute = test_node.get_attribute("inputs:forward") db_value = database.inputs.forward expected_value = [0.0, 0.0, 1.0] actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:start")) attribute = test_node.get_attribute("inputs:start") db_value = database.inputs.start expected_value = [0.0, 0.0, 0.0] actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("inputs:target")) attribute = test_node.get_attribute("inputs:target") db_value = database.inputs.target expected_value = [0.0, 0.0, 0.0] actual_value = og.Controller.get(attribute) ogts.verify_values(expected_value, actual_value, _attr_error(attribute, True)) ogts.verify_values(expected_value, db_value, _attr_error(attribute, False)) self.assertTrue(test_node.get_attribute_exists("outputs:orientation")) attribute = test_node.get_attribute("outputs:orientation") db_value = database.outputs.orientation self.assertTrue(test_node.get_attribute_exists("outputs:rotateXYZ")) attribute = test_node.get_attribute("outputs:rotateXYZ") db_value = database.outputs.rotateXYZ