file_path
stringlengths 21
224
| content
stringlengths 0
80.8M
|
---|---|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/constants/OgnConstantDouble4.ogn | {
"ConstantDouble4": {
"description": [
"Holds a 4-component double constant."
],
"categories": ["constants"],
"scheduling": ["pure"],
"version": 1,
"inputs": {
"value": {
"type": "double[4]",
"description": "The constant value",
"uiName": "Value",
"metadata": {
"outputOnly": "1"
}
}
}
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/constants/OgnConstantPoint3f.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 <OgnConstantPoint3fDatabase.h>
namespace omni
{
namespace graph
{
namespace nodes
{
class OgnConstantPoint3f
{
public:
static size_t computeVectorized(OgnConstantPoint3fDatabase&, size_t count)
{
return count;
}
};
REGISTER_OGN_NODE()
}
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/constants/OgnConstantFloat3.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 <OgnConstantFloat3Database.h>
namespace omni
{
namespace graph
{
namespace nodes
{
class OgnConstantFloat3
{
public:
static size_t computeVectorized(OgnConstantFloat3Database&, size_t count)
{
return count;
}
};
REGISTER_OGN_NODE()
}
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/constants/OgnConstantInt.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 <OgnConstantIntDatabase.h>
namespace omni
{
namespace graph
{
namespace nodes
{
class OgnConstantInt
{
public:
static size_t computeVectorized(OgnConstantIntDatabase&, size_t count)
{
return count;
}
};
REGISTER_OGN_NODE()
}
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnMakeVector3.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 <OgnMakeVector3Database.h>
#include <omni/graph/core/ogn/ComputeHelpers.h>
#include <omni/graph/core/ogn/UsdTypes.h>
#include <fstream>
#include <iomanip>
namespace omni
{
namespace graph
{
namespace nodes
{
namespace
{
template <typename Type>
bool tryMakeVector(OgnMakeVector3Database& db, size_t count = 1)
{
const auto x = db.inputs.x().template get<Type>();
const auto y = db.inputs.y().template get<Type>();
const auto z = db.inputs.z().template get<Type>();
const auto vector = db.outputs.tuple().template get<Type[3]>();
if (x && y && z && vector)
{
const auto px = x.vectorized(count);
const auto py = y.vectorized(count);
const auto pz = z.vectorized(count);
const auto pvector = vector.vectorized(count);
if (not(pvector.empty() || px.empty() || py.empty() || pz.empty()))
{
for (size_t i = 0; i < count; i++)
{
pvector[i][0] = px[i];
pvector[i][1] = py[i];
pvector[i][2] = pz[i];
}
return true;
}
return false;
}
for(size_t i = 0; i < count ; ++i)
{
const auto xArray = db.inputs.x(i).template get<Type[]>();
const auto yArray = db.inputs.y(i).template get<Type[]>();
const auto zArray = db.inputs.z(i).template get<Type[]>();
auto vectorArray = db.outputs.tuple(i).template get<Type[][3]>();
if (!vectorArray || !xArray || !yArray || !zArray){
return false;
}
if (xArray->size() != yArray->size() || xArray->size() != zArray->size())
{
throw ogn::compute::InputError("Input arrays of different lengths x:" + std::to_string(xArray->size()) +
", y:" + std::to_string(yArray->size()) +
", z:" + std::to_string(zArray->size()));
}
vectorArray->resize(xArray->size());
for (size_t i = 0; i < vectorArray->size(); i++)
{
(*vectorArray)[i][0] = (*xArray)[i];
(*vectorArray)[i][1] = (*yArray)[i];
(*vectorArray)[i][2] = (*zArray)[i];
}
}
return true;
}
} // namespace
// Node to merge 3 scalers together to make 3-vector
class OgnMakeVector3
{
public:
static size_t computeVectorized(OgnMakeVector3Database& db, size_t count)
{
// Compute the components, if the types are all resolved.
try
{
if (tryMakeVector<double>(db, count))
return count;
else if (tryMakeVector<float>(db, count))
return count;
else if (tryMakeVector<pxr::GfHalf>(db, count))
return count;
else if (tryMakeVector<int32_t>(db, count))
return count;
else
{
db.logError("Failed to resolve input types");
return 0;
}
}
catch (const std::exception& e)
{
db.logError("Vector could not be made: %s", e.what());
return 0;
}
return 0;
}
static void onConnectionTypeResolve(const NodeObj& nodeObj)
{
auto x = nodeObj.iNode->getAttributeByToken(nodeObj, inputs::x.token());
auto y = nodeObj.iNode->getAttributeByToken(nodeObj, inputs::y.token());
auto z = nodeObj.iNode->getAttributeByToken(nodeObj, inputs::z.token());
auto vector = nodeObj.iNode->getAttributeByToken(nodeObj, outputs::tuple.token());
auto xType = vector.iAttribute->getResolvedType(x);
auto yType = vector.iAttribute->getResolvedType(y);
auto zType = vector.iAttribute->getResolvedType(z);
// If one of the inputs is resolved we can resolve the other because they should match
std::array<AttributeObj, 3> attrs { x, y, z };
if (nodeObj.iNode->resolveCoupledAttributes(nodeObj, attrs.data(), attrs.size()))
{
xType = vector.iAttribute->getResolvedType(x);
yType = vector.iAttribute->getResolvedType(y);
zType = vector.iAttribute->getResolvedType(z);
}
// Require inputs to be resolved before determining outputs' type
if (xType.baseType != BaseDataType::eUnknown &&
yType.baseType != BaseDataType::eUnknown &&
zType.baseType != BaseDataType::eUnknown )
{
std::array<AttributeObj, 4> attrs{ x, y, z, vector };
std::array<uint8_t, 4> tuples{ 1, 1, 1, 3 };
std::array<uint8_t, 4> arrays{
xType.arrayDepth,
yType.arrayDepth,
zType.arrayDepth,
xType.arrayDepth,
};
std::array<AttributeRole, 4> roles{ xType.role, yType.role, zType.role, AttributeRole::eNone };
nodeObj.iNode->resolvePartiallyCoupledAttributes(
nodeObj, attrs.data(), tuples.data(), arrays.data(), roles.data(), attrs.size());
}
}
};
REGISTER_OGN_NODE();
}
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnConstantPrims.cpp | // Copyright (c) 2020-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 <OgnConstantPrimsDatabase.h>
namespace omni
{
namespace graph
{
namespace nodes
{
class OgnConstantPrims
{
public:
static size_t computeVectorized(OgnConstantPrimsDatabase& db, size_t count)
{
return count;
}
};
REGISTER_OGN_NODE();
} // nodes
} // graph
} // omni
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnGetParentPrims.ogn | {
"GetParentPrims": {
"version": 1,
"description": ["Generates parent paths from one or more targeted paths (ex. /World/Cube -> /World)"],
"uiName": "Get Parent Prims",
"categories": ["sceneGraph"],
"scheduling": [ "threadsafe" ],
"inputs": {
"prims": {
"type": "target",
"description": "Input prim paths (ex. /World/Cube)",
"metadata": {
"allowMultiInputs": "1"
}
}
},
"outputs": {
"parentPrims": {
"type": "target",
"description": "Computed parent paths (ex. /World)"
}
}
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnConstructArray.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 <OgnConstructArrayDatabase.h>
#include <carb/logging/Log.h>
#include <omni/graph/core/Type.h>
#include <omni/graph/core/StringUtils.h>
#include <omni/graph/core/ogn/ComputeHelpers.h>
#include <array>
#include <unordered_map>
#include <vector>
namespace omni {
namespace graph {
namespace nodes {
// unnamed namespace to avoid multiple declaration when linking
namespace {
static constexpr size_t kMaxAttrNameLen{ 32 };
void formatAttrName(size_t n, std::array<char, kMaxAttrNameLen>& outName)
{
snprintf(outName.data(), kMaxAttrNameLen, "inputs:input%zu", n);
}
template<typename BaseType>
bool tryComputeAssumingType(OgnConstructArrayDatabase& db)
{
NodeObj nodeObj = db.abi_node();
auto iNode = nodeObj.iNode;
GraphObj graphObj = iNode->getGraph(nodeObj);
GraphContextObj context = graphObj.iGraph->getDefaultGraphContext(graphObj);
auto const outputArrayAttr = iNode->getAttributeByToken(nodeObj, outputs::array.token());
auto const outputArrayType = outputArrayAttr.iAttribute->getResolvedType(outputArrayAttr);
if (outputArrayType.baseType == BaseDataType::eUnknown)
{
return false;
}
auto outputArray = db.outputs.array().template get<BaseType[]>();
if (!outputArray)
return false;
size_t const arraySize = static_cast<size_t>(std::max(0, db.inputs.arraySize()));
(*outputArray).resize(arraySize);
memset(outputArray->data(), 0, sizeof(BaseType) * arraySize);
// read dynamic inputs
size_t i = 0;
std::array<char, kMaxAttrNameLen> outName;
formatAttrName(i, outName);
while (iNode->getAttributeExists(nodeObj, outName.data()) && i < arraySize) {
auto inAttrib = iNode->getAttribute(nodeObj, outName.data());
auto inputAttribType = inAttrib.iAttribute->getResolvedType(inAttrib);
if (inputAttribType.baseType != BaseDataType::eUnknown)
{
ConstAttributeDataHandle handle = inAttrib.iAttribute->getConstAttributeDataHandle(inAttrib, db.getInstanceIndex());
auto const dataPtr = getDataR<BaseType>(context, handle);
if (dataPtr)
(*outputArray)[i] = *dataPtr;
}
++i;
formatAttrName(i, outName);
}
// fill the rest of the array using the last input value if necessary
if (0 < i && i < arraySize)
{
for (size_t j = i; j < arraySize; ++j)
{
(*outputArray)[j] = (*outputArray)[i - 1];
}
}
return true;
}
template<typename BaseType, size_t TupleSize>
bool tryComputeAssumingType(OgnConstructArrayDatabase& db)
{
NodeObj nodeObj = db.abi_node();
auto iNode = nodeObj.iNode;
GraphObj graphObj = iNode->getGraph(nodeObj);
GraphContextObj context = graphObj.iGraph->getDefaultGraphContext(graphObj);
auto const outputArrayAttr = iNode->getAttributeByToken(nodeObj, outputs::array.token());
auto const outputArrayType = outputArrayAttr.iAttribute->getResolvedType(outputArrayAttr);
if (outputArrayType.baseType == BaseDataType::eUnknown)
{
return false;
}
auto outputArray = db.outputs.array().template get<BaseType[][TupleSize]>();
if (!outputArray)
return false;
size_t const arraySize = static_cast<size_t>(std::max(0, db.inputs.arraySize()));
(*outputArray).resize(arraySize);
memset(outputArray->data(), 0, sizeof(BaseType) * arraySize * TupleSize);
// read dynamic inputs
size_t i = 0;
std::array<char, kMaxAttrNameLen> outName;
formatAttrName(i, outName);
while (iNode->getAttributeExists(nodeObj, outName.data()) && i < arraySize) {
auto inAttrib = iNode->getAttribute(nodeObj, outName.data());
auto inputAttribType = inAttrib.iAttribute->getResolvedType(inAttrib);
if (inputAttribType.baseType != BaseDataType::eUnknown)
{
ConstAttributeDataHandle handle = inAttrib.iAttribute->getConstAttributeDataHandle(inAttrib, db.getInstanceIndex());
auto const dataPtr = getDataR<BaseType[TupleSize]>(context, handle);
if (dataPtr)
memcpy(&((*outputArray)[i]), dataPtr, sizeof(BaseType) * TupleSize);
}
++i;
formatAttrName(i, outName);
}
// fill the rest of the array using the last input value if necessary
if (0 < i && i < arraySize)
{
for (size_t j = i; j < arraySize; ++j)
{
memcpy(&((*outputArray)[j]), &((*outputArray)[i - 1]), sizeof(BaseType) * TupleSize);
}
}
return true;
}
} // namespace
class OgnConstructArray
{
static void tryResolveAttribute(omni::graph::core::NodeObj const& nodeObj,
omni::graph::core::AttributeObj attrib,
omni::graph::core::Type attribType)
{
Type valueType{ attrib.iAttribute->getResolvedType(attrib) };
bool attribIsValid = (attribType.baseType != BaseDataType::eUnknown);
if (valueType.baseType != BaseDataType::eUnknown)
{
// Resolved
// Case 1: We didn't find a valid source attribute => unresolve
// Case 2: We found an attribute but it is not compatible with our current resolution => unresolve
// Else: All good
if (!attribIsValid or (attribType != valueType))
{
// Not compatible! Request that the attribute be un-resolved. Note that this could fail if there are
// connections that result in a contradiction during type propagation
attrib.iAttribute->setResolvedType(attrib, Type(BaseDataType::eUnknown));
}
}
// If it's unresolved (and we have a valid attribute) we can request a resolution
if (attribIsValid and (attrib.iAttribute->getResolvedType(attrib).baseType == BaseDataType::eUnknown))
{
attrib.iAttribute->setResolvedType(attrib, attribType);
}
}
static void tryResolveArrayAttributes(omni::graph::core::NodeObj const& nodeObj, bool reconnectInputs)
{
auto& state = OgnConstructArrayDatabase::sInternalState<OgnConstructArray>(nodeObj);
// Get the input attributes
std::vector<AttributeObj> inputAttributes;
size_t i = 0;
std::array<char, kMaxAttrNameLen> outName;
formatAttrName(i, outName);
while (nodeObj.iNode->getAttributeExists(nodeObj, outName.data()))
{
inputAttributes.push_back(nodeObj.iNode->getAttribute(nodeObj, outName.data()));
++i;
formatAttrName(i, outName);
}
// Determine the output array type from the specified array type and connected inputs
Type outputType = state.m_inputArrayType; // Initialize to the specified array type ('eUnknown' if unspecified, i.e. 'inputs:arrayType' is set to 'auto')
for (auto const& inAttrib : inputAttributes)
{
// Check if input is an array
if (inAttrib.iAttribute->getResolvedType(inAttrib).arrayDepth != 0)
{
OgnConstructArrayDatabase::logError(nodeObj, "Nested arrays not supported: The input array element at attribute '%s' is an array",
inAttrib.iAttribute->getName(inAttrib));
// Unresolve output and return
auto outputArrayAttrib = nodeObj.iNode->getAttributeByToken(nodeObj, outputs::array.token());
tryResolveAttribute(nodeObj, outputArrayAttrib, Type(BaseDataType::eUnknown));
return;
}
// Skip unconnected inputs
size_t upstreamConnectionCount = inAttrib.iAttribute->getUpstreamConnectionCount(inAttrib);
if (upstreamConnectionCount != 1)
continue;
// Get the type of the current input from the upstream connection
ConnectionInfo upstreamConnection;
inAttrib.iAttribute->getUpstreamConnectionsInfo(inAttrib, &upstreamConnection, 1);
Type const upstreamType = upstreamConnection.attrObj.iAttribute->getResolvedType(upstreamConnection.attrObj);
// The array type is not specified, so infer from the first connected and resolved input
if (upstreamType.baseType != BaseDataType::eUnknown)
{
if (outputType.baseType == BaseDataType::eUnknown)
{
outputType = upstreamType;
}
else
{
// Check if the specified or inferred array type matches the type of the current input
if (!outputType.compatibleRawData(upstreamType))
{
OgnConstructArrayDatabase::logError(
nodeObj, "Mismatched array element type on input attribute '%s': expected '%s', got '%s'",
inAttrib.iAttribute->getName(inAttrib), getOgnTypeName(outputType).c_str(),
getOgnTypeName(upstreamType).c_str());
outputType = Type(BaseDataType::eUnknown);
break;
}
}
}
}
// Resolve inputs
for (auto& inAttrib : inputAttributes)
{
size_t upstreamConnectionCount = inAttrib.iAttribute->getUpstreamConnectionCount(inAttrib);
if (upstreamConnectionCount == 0)
{
// Resolve unconnected inputs to the specified array type, or the inferred array type if the array type is unspecified
if (state.m_inputArrayType.baseType != BaseDataType::eUnknown)
{
if (inAttrib.iAttribute->getResolvedType(inAttrib) != state.m_inputArrayType)
{
// Case: The current input is disconnected and the array type is specified
// Action: Resolve the current input to the specified array type
tryResolveAttribute(nodeObj, inAttrib, state.m_inputArrayType);
}
}
else
{
if (inAttrib.iAttribute->getResolvedType(inAttrib) != outputType)
{
// Case: The current input is disconnected and the array type is unspecified (auto)
// Action: Resolve the current input to the inferred array type if any input is connected.
// If no inputs are connected, then outputType will be 'eUnknown', unresolving the current input.
tryResolveAttribute(nodeObj, inAttrib, outputType);
}
}
}
else if (upstreamConnectionCount == 1 && reconnectInputs) // reconnectInputs avoids an infinite loop
{
// Resolve connected inputs to the specified array type, or their upstream types if the array type is unspecified
if (state.m_inputArrayType.baseType != BaseDataType::eUnknown)
{
// Check if already resolved to the specified array type
if (inAttrib.iAttribute->getResolvedType(inAttrib) != state.m_inputArrayType)
{
// Disconnect before re-resolving
ConnectionInfo upstreamConnection;
inAttrib.iAttribute->getUpstreamConnectionsInfo(inAttrib, &upstreamConnection, 1);
inAttrib.iAttribute->disconnectAttrs(upstreamConnection.attrObj, inAttrib, true);
// Case: The current input is connected and the array type is specified
// Action: Resolve the current input to the specified array type
tryResolveAttribute(nodeObj, inAttrib, state.m_inputArrayType);
// Reconnect
ConnectionInfo destConnection {inAttrib, upstreamConnection.connectionType};
inAttrib.iAttribute->connectAttrsEx(upstreamConnection.attrObj, destConnection, true);
}
}
else
{
ConnectionInfo upstreamConnection;
inAttrib.iAttribute->getUpstreamConnectionsInfo(inAttrib, &upstreamConnection, 1);
Type const upstreamType = upstreamConnection.attrObj.iAttribute->getResolvedType(upstreamConnection.attrObj);
// Check if already resolved to the upstream type
if (inAttrib.iAttribute->getResolvedType(inAttrib) != upstreamType)
{
// Disconnect before re-resolving
inAttrib.iAttribute->disconnectAttrs(upstreamConnection.attrObj, inAttrib, true);
// Case: The current input is connected and the array type is unspecified (auto)
// Action: Resolve the current input to its upstream type (not the inferred array type 'outputType',
// which could be a different but compatible type or 'eUnknown')
tryResolveAttribute(nodeObj, inAttrib, Type(BaseDataType::eUnknown)); // Must be resolved to 'eUnknown', not 'upstreamType'
// Reconnect
ConnectionInfo destConnection {inAttrib, upstreamConnection.connectionType};
inAttrib.iAttribute->connectAttrsEx(upstreamConnection.attrObj, destConnection, true);
}
}
}
}
// Resolve the output
// If there is a type mismatch (regardless of whether the array type was specified), then 'outputType' gets set to 'eUnknown', so 'outputs:array' gets unresolved.
// If the array type is unspecified (auto) and no inputs are connected (i.e. no type is inferred), then 'outputType' gets set to 'eUnknown' as well (but the node does not error).
// Otherwise, 'outputs:array' gets resolved to the specified or inferred array type 'outputType'.
outputType.arrayDepth = 1;
auto outputArrayAttrib = nodeObj.iNode->getAttributeByToken(nodeObj, outputs::array.token());
tryResolveAttribute(nodeObj, outputArrayAttrib, outputType);
}
static void onValueChanged(AttributeObj const& attrObj, void const* userData)
{
NodeObj nodeObj{ attrObj.iAttribute->getNode(attrObj) };
if (nodeObj.nodeHandle == kInvalidNodeHandle)
return;
GraphObj graphObj{ nodeObj.iNode->getGraph(nodeObj) };
if (graphObj.graphHandle == kInvalidGraphHandle)
return;
GraphContextObj context{ graphObj.iGraph->getDefaultGraphContext(graphObj) };
if (context.contextHandle == kInvalidGraphContextHandle)
return;
ConstAttributeDataHandle handle =
attrObj.iAttribute->getConstAttributeDataHandle(attrObj, kAccordingToContextIndex);
auto const dataPtr = getDataR<NameToken>(context, handle);
if (dataPtr)
{
auto& state = OgnConstructArrayDatabase::sInternalState<OgnConstructArray>(nodeObj);
state.m_inputArrayType = state.m_arrayTypes[*dataPtr];
}
tryResolveArrayAttributes(nodeObj, true);
}
static void onConnected(AttributeObj const& otherAttrib, AttributeObj const& inAttrib, void* userData)
{
NodeObj nodeObj{ inAttrib.iAttribute->getNode(inAttrib) };
if (nodeObj.nodeHandle == kInvalidNodeHandle)
return;
NodeObj* thisNodeObj = reinterpret_cast<NodeObj*>(userData);
if (nodeObj.nodeHandle != thisNodeObj->nodeHandle)
return;
auto& state = OgnConstructArrayDatabase::sInternalState<OgnConstructArray>(nodeObj);
// Deregister onConnected callback to avoid infinite loop
struct ConnectionCallback connectedCallback = {onConnected, &state.m_nodeObj};
nodeObj.iNode->deregisterConnectedCallback(nodeObj, connectedCallback);
tryResolveArrayAttributes(nodeObj, true);
// Re-register onConnected callback
nodeObj.iNode->registerConnectedCallback(nodeObj, connectedCallback);
}
public:
omni::graph::core::NodeObj m_nodeObj;
std::unordered_map<NameToken, omni::graph::core::Type> m_arrayTypes;
omni::graph::core::Type m_inputArrayType;
static void initialize(GraphContextObj const& context, NodeObj const& nodeObj)
{
auto& state = OgnConstructArrayDatabase::sInternalState<OgnConstructArray>(nodeObj);
state.m_nodeObj = nodeObj;
state.m_arrayTypes = {
{OgnConstructArrayDatabase::tokens.Bool, Type(BaseDataType::eBool)},
{OgnConstructArrayDatabase::tokens.Double, Type(BaseDataType::eDouble)},
{OgnConstructArrayDatabase::tokens.Float, Type(BaseDataType::eFloat)},
{OgnConstructArrayDatabase::tokens.Half, Type(BaseDataType::eHalf)},
{OgnConstructArrayDatabase::tokens.Int, Type(BaseDataType::eInt)},
{OgnConstructArrayDatabase::tokens.Int64, Type(BaseDataType::eInt64)},
{OgnConstructArrayDatabase::tokens.Token, Type(BaseDataType::eToken)},
{OgnConstructArrayDatabase::tokens.UChar, Type(BaseDataType::eUChar)},
{OgnConstructArrayDatabase::tokens.UInt, Type(BaseDataType::eUInt)},
{OgnConstructArrayDatabase::tokens.UInt64, Type(BaseDataType::eUInt64)},
{OgnConstructArrayDatabase::tokens.Double_2, Type(BaseDataType::eDouble, 2)},
{OgnConstructArrayDatabase::tokens.Double_3, Type(BaseDataType::eDouble, 3)},
{OgnConstructArrayDatabase::tokens.Double_4, Type(BaseDataType::eDouble, 4)},
{OgnConstructArrayDatabase::tokens.Double_9, Type(BaseDataType::eDouble, 9, 0, AttributeRole::eMatrix)},
{OgnConstructArrayDatabase::tokens.Double_16, Type(BaseDataType::eDouble, 16, 0, AttributeRole::eMatrix)},
{OgnConstructArrayDatabase::tokens.Float_2, Type(BaseDataType::eFloat, 2)},
{OgnConstructArrayDatabase::tokens.Float_3, Type(BaseDataType::eFloat, 3)},
{OgnConstructArrayDatabase::tokens.Float_4, Type(BaseDataType::eFloat, 4)},
{OgnConstructArrayDatabase::tokens.Half_2, Type(BaseDataType::eHalf, 2)},
{OgnConstructArrayDatabase::tokens.Half_3, Type(BaseDataType::eHalf, 3)},
{OgnConstructArrayDatabase::tokens.Half_4, Type(BaseDataType::eHalf, 4)},
{OgnConstructArrayDatabase::tokens.Int_2, Type(BaseDataType::eInt, 2)},
{OgnConstructArrayDatabase::tokens.Int_3, Type(BaseDataType::eInt, 3)},
{OgnConstructArrayDatabase::tokens.Int_4, Type(BaseDataType::eInt, 4)},
};
AttributeObj arrayTypeAttrib = nodeObj.iNode->getAttributeByToken(nodeObj, inputs::arrayType.m_token);
arrayTypeAttrib.iAttribute->registerValueChangedCallback(arrayTypeAttrib, onValueChanged, true);
struct ConnectionCallback connectedCallback = {onConnected, &state.m_nodeObj};
nodeObj.iNode->registerConnectedCallback(nodeObj, connectedCallback);
onValueChanged(arrayTypeAttrib, nullptr);
}
static bool compute(OgnConstructArrayDatabase& db)
{
NodeObj nodeObj = db.abi_node();
auto const outputArrayAttr = nodeObj.iNode->getAttributeByToken(nodeObj, outputs::array.token());
auto const outputArrayType = outputArrayAttr.iAttribute->getResolvedType(outputArrayAttr);
try
{
switch (outputArrayType.baseType)
{
case BaseDataType::eBool:
if (outputArrayType.componentCount == 1)
if (tryComputeAssumingType<bool>(db)) return true;
break;
case BaseDataType::eDouble:
switch (outputArrayType.componentCount)
{
case 1:
if (tryComputeAssumingType<double>(db)) return true;
break;
case 2:
if (tryComputeAssumingType<double, 2>(db)) return true;
break;
case 3:
if (tryComputeAssumingType<double, 3>(db)) return true;
break;
case 4:
if (tryComputeAssumingType<double, 4>(db)) return true;
break;
case 9:
if (tryComputeAssumingType<double, 9>(db)) return true;
break;
case 16:
if (tryComputeAssumingType<double, 16>(db)) return true;
break;
}
break;
case BaseDataType::eFloat:
switch (outputArrayType.componentCount)
{
case 1:
if (tryComputeAssumingType<float>(db)) return true;
break;
case 2:
if (tryComputeAssumingType<float, 2>(db)) return true;
break;
case 3:
if (tryComputeAssumingType<float, 3>(db)) return true;
break;
case 4:
if (tryComputeAssumingType<float, 4>(db)) return true;
break;
}
break;
case BaseDataType::eHalf:
switch (outputArrayType.componentCount)
{
case 1:
if (tryComputeAssumingType<pxr::GfHalf>(db)) return true;
break;
case 2:
if (tryComputeAssumingType<pxr::GfHalf, 2>(db)) return true;
break;
case 3:
if (tryComputeAssumingType<pxr::GfHalf, 3>(db)) return true;
break;
case 4:
if (tryComputeAssumingType<pxr::GfHalf, 4>(db)) return true;
break;
}
break;
case BaseDataType::eInt:
switch (outputArrayType.componentCount)
{
case 1:
if (tryComputeAssumingType<int32_t>(db)) return true;
break;
case 2:
if (tryComputeAssumingType<int32_t, 2>(db)) return true;
break;
case 3:
if (tryComputeAssumingType<int32_t, 3>(db)) return true;
break;
case 4:
if (tryComputeAssumingType<int32_t, 4>(db)) return true;
break;
}
break;
case BaseDataType::eInt64:
if (outputArrayType.componentCount == 1)
if (tryComputeAssumingType<int64_t>(db)) return true;
break;
case BaseDataType::eToken:
if (outputArrayType.componentCount == 1)
if (tryComputeAssumingType<OgnToken>(db)) return true;
break;
case BaseDataType::eUChar:
if (outputArrayType.componentCount == 1)
if (tryComputeAssumingType<uint8_t>(db)) return true;
break;
case BaseDataType::eUInt:
if (outputArrayType.componentCount == 1)
if (tryComputeAssumingType<uint32_t>(db)) return true;
break;
case BaseDataType::eUInt64:
if (outputArrayType.componentCount == 1)
if (tryComputeAssumingType<uint64_t>(db)) return true;
break;
default:
break;
}
db.logError("Failed to resolve input types");
}
catch (ogn::compute::InputError const &error)
{
db.logError(error.what());
}
return false;
}
static void onConnectionTypeResolve(const NodeObj& nodeObj)
{
tryResolveArrayAttributes(nodeObj, false);
}
};
REGISTER_OGN_NODE()
} // namespace nodes
} // namespace graph
} // namespace omni
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnAppendString.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 <OgnAppendStringDatabase.h>
namespace omni
{
namespace graph
{
namespace nodes
{
class OgnAppendString
{
public:
static bool compute(OgnAppendStringDatabase& db)
{
auto const& suffix = db.inputs.suffix();
if (suffix.type().baseType == BaseDataType::eToken)
return computeForToken(db);
return computeForString(db);
}
static bool computeForString(OgnAppendStringDatabase& db)
{
auto const inputValue = db.inputs.value();
auto const suffixIn = db.inputs.suffix();
auto const suffixData = suffixIn.get<uint8_t[]>();
auto& outValue = db.outputs.value();
// No suffix? Just copy in to out
if (suffixData->empty())
{
db.outputs.value().copyData(inputValue);
return true;
}
auto const inputValueData = inputValue.get<uint8_t[]>();
std::string outVal;
outVal.reserve(inputValueData.size() + suffixData.size());
outVal.append(reinterpret_cast<char const*>(inputValueData->data()), inputValueData.size());
outVal.append(reinterpret_cast<char const*>(suffixData->data()), suffixData.size());
auto outData = outValue.get<uint8_t[]>();
size_t outBufferSize = outVal.size();
outData->resize(outBufferSize);
memcpy(outData->data(), reinterpret_cast<uint8_t const*>(outVal.data()), outBufferSize);
return true;
}
static bool computeForToken(OgnAppendStringDatabase& db)
{
auto const& inputValue = db.inputs.value();
auto const& suffix = db.inputs.suffix();
std::vector<char const*> suffixes;
if (suffix.type().arrayDepth == 0)
{
NameToken suffixToken = *suffix.get<OgnToken>();
if (suffixToken != omni::fabric::kUninitializedToken)
suffixes.push_back(db.tokenToString(suffixToken));
}
else
{
const auto suffixTokens = *suffix.get<OgnToken[]>();
suffixes.resize(suffixTokens.size());
std::transform(suffixTokens.begin(), suffixTokens.end(), suffixes.begin(),
[&db](auto t) { return db.tokenToString(t); });
}
// No suffix? Just copy in to out
if (suffixes.empty())
{
db.outputs.value().copyData(inputValue);
return true;
}
if (inputValue.type().arrayDepth > 0)
{
const auto inputValueArray = *inputValue.get<OgnToken[]>();
auto outputPathArray = *db.outputs.value().get<OgnToken[]>();
outputPathArray.resize(inputValueArray.size());
if (suffixes.size() == 1)
{
const char* suffixStr = suffixes[0];
std::transform(inputValueArray.begin(), inputValueArray.end(), outputPathArray.begin(),
[&](const auto& p)
{
std::string s = db.tokenToString(p);
s += suffixStr;
return db.stringToToken(s.c_str());
});
}
else
{
if (inputValueArray.size() != suffixes.size())
{
CARB_LOG_ERROR("inputs:value and inputs:suffix arrays are not the same size (%zu and %zu)",
inputValueArray.size(), suffixes.size());
return false;
}
for (size_t i = 0; i < inputValueArray.size(); ++i)
{
std::string s = db.tokenToString(inputValueArray[i]);
s += suffixes[i];
outputPathArray[i] = db.stringToToken(s.c_str());
}
}
return true;
}
else
{
NameToken inValue = *inputValue.get<OgnToken>();
std::string s;
if (inValue != omni::fabric::kUninitializedToken)
{
s = db.tokenToString(inValue);
}
s += suffixes[0];
*db.outputs.value().get<OgnToken>() = db.stringToToken(s.c_str());
}
return true;
}
static void onConnectionTypeResolve(const NodeObj& node)
{
auto inputVal = node.iNode->getAttributeByToken(node, OgnAppendStringAttributes::inputs::value.m_token);
auto outputVal = node.iNode->getAttributeByToken(node, OgnAppendStringAttributes::outputs::value.m_token);
auto suffixVal = node.iNode->getAttributeByToken(node, OgnAppendStringAttributes::inputs::suffix.m_token);
//in type
auto type = inputVal.iAttribute->getResolvedType(inputVal);
//if input is an array of token, suffix is allowed to be either a simple or an array of token(s)
if (type.baseType == BaseDataType::eToken && type.arrayDepth != 0)
{
// both in and out needs to be the same
std::array<AttributeObj, 2> attrs{ inputVal, outputVal };
node.iNode->resolveCoupledAttributes(node, attrs.data(), attrs.size());
//change suffix if necessary
auto suffixType = suffixVal.iAttribute->getResolvedType(suffixVal);
if (suffixType.baseType == BaseDataType::eUChar)//string not compatible with tokens
suffixVal.iAttribute->setResolvedType(suffixVal, type);
}
else
{
// else, the 3 needs to have the same type
std::array<AttributeObj, 3> attrs{ inputVal, suffixVal, outputVal };
node.iNode->resolveCoupledAttributes(node, attrs.data(), attrs.size());
}
}
};
REGISTER_OGN_NODE();
} // nodes
} // graph
} // omni
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnToHalf.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 <OgnToHalfDatabase.h>
#include <omni/graph/core/ogn/ComputeHelpers.h>
#include <omni/graph/core/ogn/UsdTypes.h>
namespace omni
{
namespace graph
{
namespace nodes
{
namespace
{
template<typename T>
bool tryComputeAssumingType(OgnToHalfDatabase& db, size_t count)
{
auto functor = [](auto const& value, auto& converted) { converted = pxr::GfHalf(float(value)); };
return ogn::compute::tryComputeWithArrayBroadcasting<T, pxr::GfHalf>(db.inputs.value(), db.outputs.converted(), functor, count);
}
template<typename T, size_t tupleSize>
bool tryComputeAssumingType(OgnToHalfDatabase& db, size_t count)
{
auto functor = [](auto const& value, auto& converted) { converted = pxr::GfHalf(float(value)); };
return ogn::compute::tryComputeWithTupleBroadcasting<tupleSize, T, pxr::GfHalf>(
db.inputs.value(), db.outputs.converted(), functor, count);
}
} // namespace
class OgnToHalf
{
public:
// Node to convert numeric inputs to halfs
static bool computeVectorized(OgnToHalfDatabase& db, size_t count)
{
const auto& inputsValue = db.inputs.value();
auto& type = inputsValue.type();
bool result = false;
switch (type.baseType)
{
case BaseDataType::eBool:
{
result = tryComputeAssumingType<bool>(db, count);
break;
}
case BaseDataType::eDouble:
{
switch (type.componentCount)
{
case 1:
result = tryComputeAssumingType<double>(db, count);
break;
case 2:
result = tryComputeAssumingType<double, 2>(db, count);
break;
case 3:
result = tryComputeAssumingType<double, 3>(db, count);
break;
case 4:
result = tryComputeAssumingType<double, 4>(db, count);
break;
case 9:
result = tryComputeAssumingType<double, 9>(db, count);
break;
case 16:
result = tryComputeAssumingType<double, 16>(db, count);
break;
default:
result = false;
}
break;
}
case BaseDataType::eFloat:
{
switch (type.componentCount)
{
case 1:
result = tryComputeAssumingType<float>(db, count);
break;
case 2:
result = tryComputeAssumingType<float, 2>(db, count);
break;
case 3:
result = tryComputeAssumingType<float, 3>(db, count);
break;
case 4:
result = tryComputeAssumingType<float, 4>(db, count);
break;
default:
result = false;
}
break;
}
case BaseDataType::eHalf:
{
switch (type.componentCount)
{
case 1:
result = tryComputeAssumingType<pxr::GfHalf>(db, count);
break;
case 2:
result = tryComputeAssumingType<pxr::GfHalf, 2>(db, count);
break;
case 3:
result = tryComputeAssumingType<pxr::GfHalf, 3>(db, count);
break;
case 4:
result = tryComputeAssumingType<pxr::GfHalf, 4>(db, count);
break;
default:
result = false;
}
break;
}
case BaseDataType::eInt:
{
switch (type.componentCount)
{
case 1:
result = tryComputeAssumingType<int32_t>(db, count);
break;
case 2:
result = tryComputeAssumingType<int32_t, 2>(db, count);
break;
case 3:
result = tryComputeAssumingType<int32_t, 3>(db, count);
break;
case 4:
result = tryComputeAssumingType<int32_t, 4>(db, count);
break;
default:
result = false;
}
break;
}
case BaseDataType::eInt64:
{
result = tryComputeAssumingType<int64_t>(db, count);
break;
}
case BaseDataType::eUChar:
{
result = tryComputeAssumingType<unsigned char>(db, count);
break;
}
case BaseDataType::eUInt:
{
result = tryComputeAssumingType<uint32_t>(db, count);
break;
}
case BaseDataType::eUInt64:
{
result = tryComputeAssumingType<uint64_t>(db, count);
break;
}
default:
{
result = false;
}
}
if (!result)
{
db.logError("Input could not be converted to half");
return false;
}
return true;
}
static void onConnectionTypeResolve(const NodeObj& nodeObj)
{
auto valueAttr = nodeObj.iNode->getAttributeByToken(nodeObj, inputs::value.token());
auto outAttr = nodeObj.iNode->getAttributeByToken(nodeObj, outputs::converted.token());
auto valueType = valueAttr.iAttribute->getResolvedType(valueAttr);
// The output shape must match the input shape and visa-versa, however we can't say anything
// about the input base type until it's connected
if (valueType.baseType != BaseDataType::eUnknown)
{
Type resultType(BaseDataType::eHalf, valueType.componentCount, valueType.arrayDepth);
outAttr.iAttribute->setResolvedType(outAttr, resultType);
}
}
};
REGISTER_OGN_NODE();
}
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnArrayIndex.ogn | {
"ArrayIndex": {
"version": 1,
"description": [
"Copies an element of an input array into an output"
],
"uiName": "Array Index",
"categories": ["math:array"],
"scheduling": ["threadsafe"],
"inputs": {
"array": {
"type": ["arrays", "bool[]"],
"description": "The array to be indexed",
"uiName": "Array"
},
"index": {
"type": "int",
"description": "The index into the array, a negative value indexes from the end of the array",
"uiName": "Index"
}
},
"outputs": {
"value": {
"type": ["array_elements", "bool"],
"description": "The value from the array"
}
},
"tests": [
{
"inputs:array": {"type": "int[]", "value": [42]}, "inputs:index": 0,
"outputs:value": {"type": "int", "value":42}
},
{
"inputs:array": {"type": "float[2][]", "value":[[1.0, 2.0]]}, "inputs:index": 0,
"outputs:value": {"type": "float[2]", "value":[1.0, 2.0]}
},
{
"inputs:array": {"type": "int[]", "value": [1, 2, 3]}, "inputs:index": 1,
"outputs:value": {"type": "int", "value":2}
},
{
"inputs:array": {"type": "int[]", "value": [1, 2, 3]}, "inputs:index": -1,
"outputs:value": {"type": "int", "value":3}
},
{
"inputs:array": {"type": "int[]", "value": [1, 2, 3]}, "inputs:index": -2,
"outputs:value": {"type": "int", "value":2}
},
{
"inputs:array": {"type": "int[]", "value": [1, 2, 3]}, "inputs:index": 2,
"outputs:value": {"type": "int", "value":3}
},
{
"inputs:array": {"type": "token[]", "value": ["foo", "bar"]}, "inputs:index": 1,
"outputs:value": {"type": "token", "value":"bar"}
},
{
"inputs:array": {"type": "bool[]", "value": [true, false, false]}, "inputs:index": 1,
"outputs:value": {"type": "bool", "value":false}
},
{
"inputs:array": {"type": "pointd[3][]", "value": [[1,2,3],[4,5,6]]}, "inputs:index": 1,
"outputs:value": {"type": "pointd[3]", "value":[4,5,6]}
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnGetPrimsAtPath.ogn | {
"GetPrimsAtPath": {
"version": 1,
"description": ["This node computes a prim path from either a single or an array of pth tokens."],
"uiName": "Get Prims At Path",
"categories": ["sceneGraph"],
"scheduling": [ "threadsafe" ],
"inputs": {
"path": {
"type": ["token", "token[]"],
"description": "A token or token array to compute representing a path."
}
},
"outputs": {
"prims": {
"type": "target",
"description": "The output prim paths"
}
},
"state": {
"path": {
"type": "token",
"description": "Snapshot of previously seen path"
}
}
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnMakeArray.ogn | {
"MakeArray": {
"version": 1,
"description": [
"Makes an output array attribute from input values, in the order of the inputs. If ",
"'arraySize' is less than 5, the top 'arraySize' elements will be taken. If 'arraySize' is greater than 5",
"element e will be repeated to fill the remaining space"
],
"language": "Python",
"categories": ["math:array"],
"uiName": "Make Array",
"metadata": {"hidden": "true"},
"inputs": {
"a": {
"type": ["array_elements"],
"description": "Element 1"
},
"b": {
"type": ["array_elements"],
"description": "Element 2"
},
"c": {
"type": ["array_elements"],
"description": "Element 3"
},
"d": {
"type": ["array_elements"],
"description": "Element 4"
},
"e": {
"type": ["array_elements"],
"description": "Element 5"
},
"arraySize": {
"type": "int",
"description": "The size of the array to create",
"minimum": 0
}
},
"outputs": {
"array": {
"type": ["arrays"],
"description": "The array of copied values of inputs in the given order"
}
},
"tests": [
{
"inputs:a": {"type": "float", "value": 1},
"inputs:b": {"type": "float", "value": 1},
"inputs:c": {"type": "float", "value": 1},
"inputs:d": {"type": "float", "value": 1},
"inputs:e": {"type": "float", "value": 1},
"inputs:arraySize": 1,
"outputs:array": {"type": "float[]", "value":[1]}
},
{
"inputs:a": {"type": "float[2]", "value": [1,2]},
"inputs:b": {"type": "float[2]", "value": [1,3]},
"inputs:c": {"type": "float[2]", "value": [1,4]},
"inputs:d": {"type": "float[2]", "value": [1,5]},
"inputs:e": {"type": "float[2]", "value": [1,6]},
"inputs:arraySize": 5,
"outputs:array": {"type": "float[2][]", "value":[
[1,2],
[1,3],
[1,4],
[1,5],
[1,6]
]}
},
{
"inputs:a": {"type": "token", "value": "foo"},
"inputs:b": {"type": "token", "value": "foo"},
"inputs:c": {"type": "token", "value": "foo"},
"inputs:d": {"type": "token", "value": "foo"},
"inputs:e": {"type": "token", "value": "foo"},
"inputs:arraySize": 5,
"outputs:array": {"type": "token[]", "value":["foo","foo","foo","foo","foo"]}
},
{
"inputs:a": {"type": "uchar", "value": 42},
"inputs:b": {"type": "uchar", "value": 42},
"inputs:c": {"type": "uchar", "value": 42},
"inputs:d": {"type": "uchar", "value": 42},
"inputs:e": {"type": "uchar", "value": 42},
"inputs:arraySize": 5,
"outputs:array": {"type": "uchar[]", "value":[42,42,42,42,42]}
},
{
"inputs:a": {"type": "double[4]", "value": [1, 2, 3, 4]},
"inputs:b": {"type": "double[4]", "value": [1, 2, 3, 4]},
"inputs:c": {"type": "double[4]", "value": [1, 2, 3, 4]},
"inputs:d": {"type": "double[4]", "value": [1, 2, 3, 4]},
"inputs:e": {"type": "double[4]", "value": [1, 2, 3, 5]},
"inputs:arraySize": 6,
"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]
]}
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnIsEmpty.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 <OgnIsEmptyDatabase.h>
#include <omni/graph/core/ogn/ComputeHelpers.h>
#include <omni/graph/core/ogn/Types.h>
#include <string>
#include "PrimCommon.h"
namespace omni
{
namespace graph
{
namespace nodes
{
class OgnIsEmpty
{
public:
static bool compute(OgnIsEmptyDatabase& db)
{
const auto& variable = db.inputs.input();
auto& type = variable.type();
switch (type.baseType)
{
case BaseDataType::eBool:
case BaseDataType::eUChar:
case BaseDataType::eInt:
case BaseDataType::eUInt:
case BaseDataType::eInt64:
case BaseDataType::eUInt64:
case BaseDataType::eHalf:
case BaseDataType::eFloat:
case BaseDataType::eDouble:
{
db.outputs.isEmpty() = variable.size() == 0;
return true;
}
case BaseDataType::eToken:
{
std::string converted = tryConvertToString<ogn::Token>(db, variable);
db.outputs.isEmpty() = converted.length() == 0;
return true;
}
default:
{
db.logError("Type %s not supported", getOgnTypeName(type).c_str());
}
}
return false;
}
};
REGISTER_OGN_NODE()
} // nodes
} // graph
} // omni
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnToToken.cpp | // Copyright (c) 2022-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 <OgnToTokenDatabase.h>
#include <omni/graph/core/ogn/UsdTypes.h>
#include <fstream>
#include <iomanip>
#include <sstream>
#include "PrimCommon.h"
namespace omni
{
namespace graph
{
namespace nodes
{
namespace
{
template <typename T>
bool tryComputeAssumingType(OgnToTokenDatabase& db)
{
std::string converted = tryConvertToString<T>(db, db.inputs.value());
if (converted.empty())
{
return false;
}
db.outputs.converted() = db.stringToToken(converted.c_str());
return true;
}
template <typename T, size_t tupleSize>
bool tryComputeAssumingType(OgnToTokenDatabase& db)
{
std::string converted = tryConvertToString<T, tupleSize>(db, db.inputs.value());
if (converted.empty())
{
return false;
}
db.outputs.converted() = db.stringToToken(converted.c_str());
return true;
}
} // namespace
class OgnToToken
{
public:
// Node to convert any input to a token
static bool compute(OgnToTokenDatabase& db)
{
NodeObj nodeObj = db.abi_node();
const AttributeObj attr = nodeObj.iNode->getAttributeByToken(nodeObj, inputs::value.token());
const Type attrType = attr.iAttribute->getResolvedType(attr);
auto value = db.inputs.value();
if (attrType.baseType == BaseDataType::eUnknown)
{
db.logError("Unknown input data type");
return false;
}
// Compute the components, if the types are all resolved.
// This handles char and string case (get<ogn::string>() will return invalid result)
if (attrType.baseType == BaseDataType::eUChar)
{
if ((attrType.arrayDepth == 1) &&
((attrType.role == AttributeRole::eText) || (attrType.role == AttributeRole::ePath)))
{
auto val = db.inputs.value().template get<uint8_t[]>();
if (!val)
{
db.logError("Unable to resolve input type");
return false;
}
auto charData = val->data();
std::string str(charData, charData + val->size());
db.outputs.converted() = db.stringToToken(str.c_str());
return true;
}
else if (attrType.arrayDepth == 0)
{
uchar val = *db.inputs.value().template get<uchar>();
db.outputs.converted() = db.stringToToken(std::string(1, static_cast<char>(val)).c_str());
}
return true;
}
try
{
auto& inputType = db.inputs.value().type();
switch (inputType.baseType)
{
case BaseDataType::eToken:
return tryComputeAssumingType<ogn::Token>(db);
case BaseDataType::eBool:
return tryComputeAssumingType<bool>(db);
case BaseDataType::eDouble:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<double>(db);
case 2: return tryComputeAssumingType<double, 2>(db);
case 3: return tryComputeAssumingType<double, 3>(db);
case 4: return tryComputeAssumingType<double, 4>(db);
case 9: return tryComputeAssumingType<double, 9>(db);
case 16: return tryComputeAssumingType<double, 16>(db);
default: break;
}
case BaseDataType::eFloat:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<float>(db);
case 2: return tryComputeAssumingType<float, 2>(db);
case 3: return tryComputeAssumingType<float, 3>(db);
case 4: return tryComputeAssumingType<float, 4>(db);
default: break;
}
case BaseDataType::eHalf:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<pxr::GfHalf>(db);
case 2: return tryComputeAssumingType<pxr::GfHalf, 2>(db);
case 3: return tryComputeAssumingType<pxr::GfHalf, 3>(db);
case 4: return tryComputeAssumingType<pxr::GfHalf, 4>(db);
default: break;
}
case BaseDataType::eInt:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<int32_t>(db);
case 2: return tryComputeAssumingType<int32_t, 2>(db);
case 3: return tryComputeAssumingType<int32_t, 3>(db);
case 4: return tryComputeAssumingType<int32_t, 4>(db);
default: break;
}
;
case BaseDataType::eInt64:
return tryComputeAssumingType<int64_t>(db);
case BaseDataType::eUInt:
return tryComputeAssumingType<uint32_t>(db);
case BaseDataType::eUInt64:
return tryComputeAssumingType<uint64_t>(db);
default: break;
}
db.logWarning("Failed to resolve input types");
}
catch (const std::exception& e)
{
db.logError("Input could not be converted to a token: %s", e.what());
return false;
}
return true;
}
};
REGISTER_OGN_NODE();
}
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnArrayFindValue.ogn | {
"ArrayFindValue": {
"version": 1,
"description": [
"Searches for a value in an array, returns the index of the first occurrence of the value, or -1 if not found."
],
"uiName": "Array Find Value",
"categories": ["math:array"],
"scheduling": ["threadsafe"],
"inputs": {
"array": {
"type": ["arrays", "bool[]"],
"description": "The array to be searched",
"uiName": "Array"
},
"value": {
"type": ["array_elements", "bool"],
"description": "The value to be found"
}
},
"outputs": {
"index": {
"type": "int",
"description": "The index of the first occurrence of value, or -1 if not found",
"uiName": "Index"
}
},
"tests": [
{
"inputs:array": {"type": "int[]", "value": [41, 42]}, "outputs:index": 1,
"inputs:value": {"type": "int", "value": 42}
},
{
"inputs:array": {"type": "token[]", "value": ["FOOD", "BARFOOD", "BAZ"]}, "outputs:index": -1,
"inputs:value": {"type": "token", "value":"FOO"}
},
{
"inputs:array": {"type": "token[]", "value": ["FOOD", "BARFOOD", "BAZ"]}, "outputs:index": 0,
"inputs:value": {"type": "token", "value":"FOOD"}
},
{
"inputs:array": {"type": "int64[]", "value": [41, 42]}, "outputs:index": 0,
"inputs:value": {"type": "int64", "value":41}
},
{
"inputs:array": {"type": "uchar[]", "value": [41, 42]}, "outputs:index": 0,
"inputs:value": {"type": "uchar", "value":41}
},
{
"inputs:array": {"type": "uint[]", "value": [41, 42]}, "outputs:index": 1,
"inputs:value": {"type": "uint", "value":42}
},
{
"inputs:array": {"type": "uint64[]", "value": [41, 42]}, "outputs:index": 1,
"inputs:value": {"type": "uint64", "value":42}
},
{
"inputs:array": {"type": "bool[]", "value": [false, true]}, "outputs:index": 0,
"inputs:value": {"type": "bool", "value":false}
},
{
"inputs:array": {"type": "half[2][]", "value": [[1, 2], [3, 4]]}, "outputs:index": 0,
"inputs:value": {"type": "half[2]", "value":[1, 2]}
},
{
"inputs:array": {"type": "double[2][]", "value": [[1, 2], [3, 4]]}, "outputs:index": 0,
"inputs:value": {"type": "double[2]", "value":[1, 2]}
},
{
"inputs:array": {"type": "double[3][]", "value": [[1.1, 2.1, 1.0], [3, 4, 5]]}, "outputs:index": 1,
"inputs:value": {"type": "double[3]", "value":[3, 4, 5]}
},
{
"inputs:array": {"type": "int[4][]", "value": [[1, 2, 3, 4], [3, 4, 5, 6]]}, "outputs:index": 0,
"inputs:value": {"type": "int[4]", "value":[1, 2, 3, 4]}
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnCompare.ogn | {
"Compare": {
"version": 1,
"description": ["Outputs the truth value of a comparison operation. Tuples are compared in lexicographic order.",
"If one input is an array and the other is a scaler, the scaler will ",
"be broadcast to the size of the array"],
"uiName": "Compare",
"categories": ["math:condition"],
"scheduling": ["threadsafe"],
"inputs": {
"a": {
"type": "any",
"description": "Input A"
},
"b": {
"type": "any",
"description": "Input B"
},
"operation": {
"type": "token",
"description": "The comparison operation to perform (>,<,>=,<=,==,!=))",
"uiName": "Operation",
"default": ">",
"metadata": {
"allowedTokens": {
"gt": ">",
"lt": "<",
"ge": ">=",
"le": "<=",
"eq": "==",
"ne": "!="
}
}
}
},
"outputs": {
"result": {
"type": ["bool","bool[]"],
"description": "The result of the comparison operation",
"uiName": "Result"
}
},
"tests" : [
{
"inputs:a": {"type": "float", "value": 42.0}, "inputs:b": {"type": "float", "value": 1.0},
"inputs:operation": ">",
"outputs:result": {"type": "bool", "value": true}
},
{
"inputs:a": {"type": "float", "value": 42.0}, "inputs:b": {"type": "float", "value": 1.0},
"inputs:operation": "<=",
"outputs:result": {"type": "bool", "value": false}
},
{
"inputs:a": {"type": "int64", "value": 9223372036854775807}, "inputs:b": {"type": "int64", "value": 9223372036854775807},
"inputs:operation": "==",
"outputs:result": {"type": "bool", "value": true}
},
{
"inputs:a": {"type": "float[]", "value": [1.0, 2.0]}, "inputs:b": {"type": "float[]", "value": [1.0, 2.01]},
"inputs:operation": "==",
"outputs:result": {"type": "bool[]", "value": [true, false]}
},
{
"inputs:a": {"type": "double[]", "value": [2.0, 3.0]}, "inputs:b": {"type": "double[]", "value": [2.0, 3.1]},
"inputs:operation": "<=",
"outputs:result": {"type": "bool[]", "value": [true, true]}
},
{
"inputs:a": {"type": "double[3][]", "value": [[2.0, 3.0, 1.0], [1.0, 2.0, 5.0]]},
"inputs:b": {"type": "double[3][]", "value": [[2.0, 1.0, 4.0], [2.0, 2.0, 2.0]]},
"inputs:operation": "<=",
"outputs:result": {"type": "bool[]", "value": [false, true]}
},
{
"inputs:a": {"type": "token", "value": ""}, "inputs:b": {"type": "token", "value": ""},
"inputs:operation": "==",
"outputs:result": {"type": "bool", "value": true}
},
{
"inputs:a": {"type": "token", "value": "abc"}, "inputs:b": {"type": "token", "value": "abc"},
"inputs:operation": "!=",
"outputs:result": {"type": "bool", "value": false}
},
{
"inputs:a": {"type": "token", "value": "abc"}, "inputs:b": {"type": "token", "value": "d"},
"inputs:operation": "==",
"outputs:result": {"type": "bool", "value": false}
},
{
"inputs:a": {"type": "token", "value": "abc"}, "inputs:b": {"type": "token", "value": ""},
"inputs:operation": "!=",
"outputs:result": {"type": "bool", "value": true}
},
{
"inputs:a": {"type": "string", "value": ""}, "inputs:b": {"type": "string", "value": ""},
"inputs:operation": "==",
"outputs:result": {"type": "bool", "value": true}
},
{
"inputs:a": {"type": "string", "value": "abc"}, "inputs:b": {"type": "string", "value": "abc"},
"inputs:operation": "!=",
"outputs:result": {"type": "bool", "value": false}
},
{
"inputs:a": {"type": "string", "value": "abc"}, "inputs:b": {"type": "string", "value": "d"},
"inputs:operation": "==",
"outputs:result": {"type": "bool", "value": false}
},
{
"inputs:a": {"type": "string", "value": "abc"}, "inputs:b": {"type": "string", "value": ""},
"inputs:operation": "!=",
"outputs:result": {"type": "bool", "value": true}
},
{
"inputs:a": {"type": "string", "value": ""}, "inputs:b": {"type": "string", "value": ""},
"inputs:operation": "<",
"outputs:result": {"type": "bool", "value": false}
},
{
"inputs:a": {"type": "string", "value": "abc"}, "inputs:b": {"type": "string", "value": "ad"},
"inputs:operation": "<=",
"outputs:result": {"type": "bool", "value": true}
},
{
"inputs:a": {"type": "string", "value": "abc"}, "inputs:b": {"type": "string", "value": ""},
"inputs:operation": ">",
"outputs:result": {"type": "bool", "value": true}
},
{
"inputs:a": {"type": "string", "value": "abc"}, "inputs:b": {"type": "string", "value": "abc"},
"inputs:operation": ">=",
"outputs:result": {"type": "bool", "value": true}
},
{
"inputs:a": {"type": "uchar[]", "value": []}, "inputs:b": {"type": "uchar[]", "value": []},
"inputs:operation": "==",
"outputs:result": {"type": "bool[]", "value": []}
},
{
"inputs:a": {"type": "string", "value": "abc"}, "inputs:b": {"type": "uchar[]", "value": [97, 98, 99]},
"inputs:operation": "!=",
"outputs:result": {"type": "bool[]", "value": [false, false, false]}
},
{
"inputs:a": {"type": "uchar[]", "value": [97, 98, 99]}, "inputs:b": {"type": "uchar", "value": 98},
"inputs:operation": ">",
"outputs:result": {"type": "bool[]", "value": [false, false, true]}
},
{
"inputs:a": {"type": "uchar", "value": 98}, "inputs:b": {"type": "string", "value": "abc"},
"inputs:operation": "<=",
"outputs:result": {"type": "bool[]", "value": [false, true, true]}
},
{
"inputs:a": {"type": "token[]", "value": ["abcd", "a", "foo"]}, "inputs:b": {"type": "token[]", "value": ["abc", "a", "food"]},
"inputs:operation": "!=",
"outputs:result": {"type": "bool[]", "value": [true, false, true]}
},
{
"inputs:a": {"type": "token", "value": ""}, "inputs:b": {"type": "token[]", "value": ["abc", "a", ""]},
"inputs:operation": "==",
"outputs:result": {"type": "bool[]", "value": [false, false, true]}
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnArrayRotate.ogn | {
"ArrayRotate": {
"version": 1,
"description": [
"Shifts the elements of an array by the specified number of steps to the right and wraps elements",
"from one end to the other. A negative step will shift to the left."
],
"uiName": "Array Rotate",
"categories": ["math:array"],
"scheduling": ["threadsafe"],
"inputs": {
"array": {
"type": ["arrays", "bool[]"],
"description": "The array to be modified"
},
"steps": {
"type": "int",
"description": "The number of steps to shift, negative means shift left instead of right"
}
},
"outputs": {
"array": {
"type": ["arrays", "bool[]"],
"description": "The modified array"
}
},
"tests": [
{
"inputs:array": {"type": "int[]", "value": [41, 42]}, "inputs:steps": 0,
"outputs:array": {"type": "int[]", "value": [41, 42]}
},
{
"inputs:array": {"type": "int[]", "value": [41, 42, 43]}, "inputs:steps": 1,
"outputs:array": {"type": "int[]", "value": [43, 41, 42]}
},
{
"inputs:array": {"type": "float[2][]", "value": [[1,2],[3,4],[5,6]]}, "inputs:steps": 1,
"outputs:array": {"type": "float[2][]", "value": [[5,6],[1,2],[3,4]]}
},
{
"inputs:array": {"type": "int[]", "value": [41, 42, 43]}, "inputs:steps": -1,
"outputs:array": {"type": "int[]", "value": [42, 43, 41]}
},
{
"inputs:array": {"type": "bool[]", "value": [true, false, true]}, "inputs:steps": -1,
"outputs:array": {"type": "bool[]", "value": [false, true, true]}
},
{
"inputs:array": {"type": "int[]", "value": [41, 42, 43]}, "inputs:steps": -2,
"outputs:array": {"type": "int[]", "value": [43, 41, 42]}
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnBreakVector2.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 <OgnBreakVector2Database.h>
#include <omni/graph/core/ogn/ComputeHelpers.h>
#include <omni/graph/core/ogn/UsdTypes.h>
#include <fstream>
#include <iomanip>
namespace omni
{
namespace graph
{
namespace nodes
{
namespace
{
template <typename Type>
bool tryBreakVector(OgnBreakVector2Database& db)
{
const auto vector = db.inputs.tuple().template get<Type[2]>();
auto x = db.outputs.x().template get<Type>();
auto y = db.outputs.y().template get<Type>();
if (!vector || !x || !y){
return false;
}
*x = (*vector)[0];
*y = (*vector)[1];
return true;
}
} // namespace
// Node to break a 2-vector into it's component scalers
class OgnBreakVector2
{
public:
static bool compute(OgnBreakVector2Database& db)
{
// Compute the components, if the types are all resolved.
try
{
if (tryBreakVector<double>(db))
return true;
else if (tryBreakVector<float>(db))
return true;
else if (tryBreakVector<pxr::GfHalf>(db))
return true;
else if (tryBreakVector<int32_t>(db))
return true;
else
{
db.logWarning("Failed to resolve input types");
}
}
catch (const std::exception& e)
{
db.logError("Vector could not be broken: %s", e.what());
return false;
}
return true;
}
static void onConnectionTypeResolve(const NodeObj& nodeObj)
{
auto vector = nodeObj.iNode->getAttributeByToken(nodeObj, inputs::tuple.token());
auto x = nodeObj.iNode->getAttributeByToken(nodeObj, outputs::x.token());
auto y = nodeObj.iNode->getAttributeByToken(nodeObj, outputs::y.token());
auto vectorType = vector.iAttribute->getResolvedType(vector);
// Require inputs to be resolved before determining outputs' type
if (vectorType.baseType != BaseDataType::eUnknown)
{
std::array<AttributeObj, 3> attrs{ vector, x, y };
std::array<uint8_t, 3> tuples{ 2, 1, 1 };
std::array<uint8_t, 3> arrays{ 0, 0, 0 };
std::array<AttributeRole, 3> roles{ vectorType.role, AttributeRole::eNone, AttributeRole::eNone };
nodeObj.iNode->resolvePartiallyCoupledAttributes(nodeObj, attrs.data(), tuples.data(), arrays.data(), roles.data(), attrs.size());
}
}
};
REGISTER_OGN_NODE();
}
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnToFloat.cpp | // Copyright (c) 2022-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 <OgnToFloatDatabase.h>
#include <omni/graph/core/ogn/ComputeHelpers.h>
#include <omni/graph/core/ogn/UsdTypes.h>
namespace omni
{
namespace graph
{
namespace nodes
{
namespace
{
template<typename T>
bool tryComputeAssumingType(OgnToFloatDatabase& db, size_t count)
{
auto functor = [](auto const& value, auto& converted) { converted = static_cast<float>(value); };
return ogn::compute::tryComputeWithArrayBroadcasting<T, float>(db.inputs.value(), db.outputs.converted(), functor, count);
}
template<typename T, size_t tupleSize>
bool tryComputeAssumingType(OgnToFloatDatabase& db, size_t count)
{
auto functor = [](auto const& value, auto& converted) { converted = static_cast<float>(value); };
return ogn::compute::tryComputeWithTupleBroadcasting<tupleSize, T, float>(
db.inputs.value(), db.outputs.converted(), functor, count);
}
} // namespace
class OgnToFloat
{
public:
// Node to convert numeric inputs to floats
static bool computeVectorized(OgnToFloatDatabase& db, size_t count)
{
auto& inputType = db.inputs.value().type();
// Compute the components, if the types are all resolved.
try
{
switch (inputType.baseType)
{
case BaseDataType::eBool:
return tryComputeAssumingType<bool>(db, count);
case BaseDataType::eDouble:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<double>(db, count);
case 2: return tryComputeAssumingType<double, 2>(db, count);
case 3: return tryComputeAssumingType<double, 3>(db, count);
case 4: return tryComputeAssumingType<double, 4>(db, count);
case 9: return tryComputeAssumingType<double, 9>(db, count);
case 16: return tryComputeAssumingType<double, 16>(db, count);
default: break;
}
case BaseDataType::eFloat:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<float>(db, count);
case 2: return tryComputeAssumingType<float, 2>(db, count);
case 3: return tryComputeAssumingType<float, 3>(db, count);
case 4: return tryComputeAssumingType<float, 4>(db, count);
default: break;
}
case BaseDataType::eHalf:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<pxr::GfHalf>(db, count);
case 2: return tryComputeAssumingType<pxr::GfHalf, 2>(db, count);
case 3: return tryComputeAssumingType<pxr::GfHalf, 3>(db, count);
case 4: return tryComputeAssumingType<pxr::GfHalf, 4>(db, count);
default: break;
}
case BaseDataType::eInt:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<int32_t>(db, count);
case 2: return tryComputeAssumingType<int32_t, 2>(db, count);
case 3: return tryComputeAssumingType<int32_t, 3>(db, count);
case 4: return tryComputeAssumingType<int32_t, 4>(db, count);
default: break;
}
;
case BaseDataType::eInt64:
return tryComputeAssumingType<int64_t>(db, count);
case BaseDataType::eUChar:
return tryComputeAssumingType<unsigned char>(db, count);
case BaseDataType::eUInt:
return tryComputeAssumingType<uint32_t>(db, count);
case BaseDataType::eUInt64:
return tryComputeAssumingType<uint64_t>(db, count);
default: break;
}
db.logWarning("Failed to resolve input types");
}
catch (const std::exception& e)
{
db.logError("Input could not be converted to float: %s", e.what());
return false;
}
return true;
}
static void onConnectionTypeResolve(const NodeObj& nodeObj)
{
auto valueAttr = nodeObj.iNode->getAttributeByToken(nodeObj, inputs::value.token());
auto outAttr = nodeObj.iNode->getAttributeByToken(nodeObj, outputs::converted.token());
auto valueType = valueAttr.iAttribute->getResolvedType(valueAttr);
// The output shape must match the input shape and visa-versa, however we can't say anything
// about the input base type until it's connected
if (valueType.baseType != BaseDataType::eUnknown)
{
Type resultType(BaseDataType::eFloat, valueType.componentCount, valueType.arrayDepth);
outAttr.iAttribute->setResolvedType(outAttr, resultType);
}
}
};
REGISTER_OGN_NODE();
}
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnArrayRotate.cpp | // Copyright (c) 2021-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 <OgnArrayRotateDatabase.h>
#include <omni/graph/core/ogn/ComputeHelpers.h>
#include <omni/graph/core/ogn/string.h>
#include <omni/graph/core/ogn/Types.h>
#include <algorithm>
namespace omni
{
namespace graph
{
namespace nodes
{
namespace
{
// Custom implementation of std::rotate.
// Using std::rotate fails to build on Linux when the underlying type is a tuple (eg int[3])
template<class ForwardIt>
constexpr
ForwardIt
rotateArray(ForwardIt first, ForwardIt n_first, ForwardIt last)
{
if(first == n_first) return last;
if(n_first == last) return first;
ForwardIt read = n_first;
ForwardIt write = first;
ForwardIt next_read = first; // read position for when "read" hits "last"
while(read != last) {
if(write == next_read) next_read = read; // track where "first" went
std::iter_swap(write++, read++);
}
// rotate the remaining sequence into place
(rotateArray)(write, next_read, last);
return write;
}
template<typename T>
bool tryComputeAssumingType(OgnArrayRotateDatabase& db)
{
const auto& steps = db.inputs.steps();
if (auto array = db.inputs.array().template get<T[]>())
{
if (auto result = db.outputs.array().template get<T[]>())
{
*result = *array;
if (!result->empty())
{
if (steps < 0)
{
rotateArray(result->begin(), result->begin() - steps, result->end());
}
else if (steps > 0)
{
rotateArray(result->rbegin(), result->rbegin() + steps, result->rend());
}
}
return true;
}
}
return false;
}
} // namespace
class OgnArrayRotate
{
public:
static bool compute(OgnArrayRotateDatabase& db)
{
auto& inputType = db.inputs.array().type();
try
{
switch (inputType.baseType)
{
case BaseDataType::eBool:
return tryComputeAssumingType<bool>(db);
case BaseDataType::eToken:
return tryComputeAssumingType<ogn::Token>(db);
case BaseDataType::eDouble:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<double>(db);
case 2: return tryComputeAssumingType<double[2]>(db);
case 3: return tryComputeAssumingType<double[3]>(db);
case 4: return tryComputeAssumingType<double[4]>(db);
case 9: return tryComputeAssumingType<double[9]>(db);
case 16: return tryComputeAssumingType<double[16]>(db);
default: break;
}
case BaseDataType::eFloat:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<float>(db);
case 2: return tryComputeAssumingType<float[2]>(db);
case 3: return tryComputeAssumingType<float[3]>(db);
case 4: return tryComputeAssumingType<float[4]>(db);
default: break;
}
case BaseDataType::eHalf:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<pxr::GfHalf>(db);
case 2: return tryComputeAssumingType<pxr::GfHalf[2]>(db);
case 3: return tryComputeAssumingType<pxr::GfHalf[3]>(db);
case 4: return tryComputeAssumingType<pxr::GfHalf[4]>(db);
default: break;
}
case BaseDataType::eInt:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<int32_t>(db);
case 2: return tryComputeAssumingType<int32_t[2]>(db);
case 3: return tryComputeAssumingType<int32_t[3]>(db);
case 4: return tryComputeAssumingType<int32_t[4]>(db);
default: break;
}
;
case BaseDataType::eInt64:
return tryComputeAssumingType<int64_t>(db);
case BaseDataType::eUChar:
return tryComputeAssumingType<unsigned char>(db);
case BaseDataType::eUInt:
return tryComputeAssumingType<uint32_t>(db);
case BaseDataType::eUInt64:
return tryComputeAssumingType<uint64_t>(db);
default: break;
}
db.logWarning("Failed to resolve input types");
}
catch (ogn::compute::InputError &error)
{
db.logWarning("OgnArrayRotate: %s", error.what());
}
return false;
}
static void onConnectionTypeResolve(const NodeObj& node){
std::array<AttributeObj, 2> attrs {
node.iNode->getAttributeByToken(node, inputs::array.token()),
node.iNode->getAttributeByToken(node, outputs::array.token())
};
node.iNode->resolveCoupledAttributes(node, attrs.data(), attrs.size());
}
};
REGISTER_OGN_NODE()
} // namespace nodes
} // namespace graph
} // namespace omni
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnArraySetIndex.ogn | {
"ArraySetIndex": {
"version": 1,
"description": [
"Sets an element of an array. If the given index is negative it will be an offset from the end of the array."
],
"uiName": "Array Set Index",
"categories": ["math:array"],
"scheduling": ["threadsafe"],
"inputs": {
"array": {
"type": ["arrays", "bool[]"],
"description": "The array to be modified",
"uiName": "Array"
},
"index": {
"type": "int",
"description": "The index into the array, a negative value indexes from the end of the array",
"uiName": "Index"
},
"resizeToFit": {
"type": "bool",
"description": ["When true, and the given positive index is larger than the highest index in the array",
"resize the output array to length 1 + index, and fill the new spaces with zeros"]
},
"value": {
"type": ["array_elements", "bool"],
"description": "The value to set at the given index"
}
},
"outputs": {
"array": {
"type": ["arrays", "bool[]"],
"description": "The modified array",
"uiName": "Array"
}
},
"tests": [
{
"inputs:array": {"type": "int[]", "value": [41, 42]}, "inputs:index": 0,
"inputs:value": {"type": "int", "value":0}, "outputs:array": {"type": "int[]", "value": [0, 42]}
},
{
"inputs:array": {"type": "int64[]", "value": [41, 42]}, "inputs:index": 0,
"inputs:value": {"type": "int64", "value":0}, "outputs:array": {"type": "int64[]", "value": [0, 42]}
},
{
"inputs:array": {"type": "uchar[]", "value": [41, 42]}, "inputs:index": 0,
"inputs:value": {"type": "uchar", "value":0}, "outputs:array": {"type": "uchar[]", "value": [0, 42]}
},
{
"inputs:array": {"type": "uint[]", "value": [41, 42]}, "inputs:index": 0,
"inputs:value": {"type": "uint", "value":0}, "outputs:array": {"type": "uint[]", "value": [0, 42]}
},
{
"inputs:array": {"type": "uint64[]", "value": [41, 42]}, "inputs:index": 0,
"inputs:value": {"type": "uint64", "value":0}, "outputs:array": {"type": "uint64[]", "value": [0, 42]}
},
{
"inputs:array": {"type": "bool[]", "value": [true, true]}, "inputs:index": 0,
"inputs:value": {"type": "bool", "value":false}, "outputs:array": {"type": "bool[]", "value": [false, true]}
},
{
"inputs:array": {"type": "token[]", "value": ["41", "42"]}, "inputs:index": -1,
"inputs:value": {"type": "token", "value":""}, "outputs:array": {"type": "token[]", "value": ["41", ""]}
},
{
"inputs:array": {"type": "half[2][]", "value": [[1.0, 2.0], [3.0, 4.0]]}, "inputs:index": 3, "inputs:resizeToFit": true,
"inputs:value": {"type": "half[2]", "value":[5.0, 6.0]},
"outputs:array": {"type": "half[2][]", "value": [[1.0, 2.0], [3.0, 4.0], [0.0, 0.0], [5.0, 6.0]]}
},
{
"inputs:array": {"type": "float[2][]", "value": [[1.0, 2.0], [3.0, 4.0]]}, "inputs:index": 3, "inputs:resizeToFit": true,
"inputs:value": {"type": "float[2]", "value":[5.0, 6.0]},
"outputs:array": {"type": "float[2][]", "value": [[1.0, 2.0], [3.0, 4.0], [0.0, 0.0], [5.0, 6.0]]}
},
{
"inputs:array": {"type": "double[3][]", "value": [[1.0, 2.0, 3.0], [3.0, 4.0, 5.0]]}, "inputs:index": 3, "inputs:resizeToFit": true,
"inputs:value": {"type": "double[3]", "value":[5.0, 6.0, 7.0]},
"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]]}
},
{
"inputs:array": {"type": "int[4][]", "value": [[1, 2, 3, 4], [3, 4, 5, 6]]}, "inputs:index": 3, "inputs:resizeToFit": true,
"inputs:value": {"type": "int[4]", "value":[5, 6, 7, 8]},
"outputs:array": {"type": "int[4][]", "value": [[1, 2, 3, 4], [3, 4, 5, 6], [0, 0, 0, 0], [5, 6, 7, 8]]}
},
{
"inputs:array": {"type": "token[]", "value": ["41", "42"]}, "inputs:index": 3, "inputs:resizeToFit": true,
"inputs:value": {"type": "token", "value":"43"},
"outputs:array": {"type": "token[]", "value": ["41", "42", "", "43"]}
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnAppendPath.ogn | {
"AppendPath": {
"version": 1,
"description": [
"Generates a path token by appending the given relative path token to the given root or prim path token"
],
"uiName": "Append Path",
"tags": [ "paths" ],
"categories": [ "sceneGraph" ],
"scheduling": [ "threadsafe" ],
"inputs": {
"path": {
"type": [ "token", "token[]" ],
"description": "The path token(s) to be appended to. Must be a base or prim path (ex. /World)"
},
"suffix": {
"type": "token",
"description": "The prim or prim-property path to append (ex. Cube or Cube.attr)"
}
},
"outputs": {
"path": {
"type": [ "token", "token[]" ],
"description": "The new path token(s) (ex. /World/Cube or /World/Cube.attr)"
}
},
"state": {
"path": {
"type": "token",
"description": "Snapshot of previously seen path"
},
"suffix": {
"type": "token",
"description": "Snapshot of previously seen suffix"
}
},
"tests": [
{
"inputs:path": {
"type": "token",
"value": "/"
},
"inputs:suffix": "foo",
"outputs:path": {
"type": "token",
"value": "/foo"
}
},
{
"inputs:path": {
"type": "token",
"value": "/World"
},
"inputs:suffix": "foo",
"outputs:path": {
"type": "token",
"value": "/World/foo"
}
},
{
"inputs:path": {
"type": "token",
"value": "/World"
},
"inputs:suffix": "foo/bar",
"outputs:path": {
"type": "token",
"value": "/World/foo/bar"
}
},
{
"inputs:path": {
"type": "token",
"value": "/World"
},
"inputs:suffix": "foo/bar.attrib",
"outputs:path": {
"type": "token",
"value": "/World/foo/bar.attrib"
}
},
{
"inputs:path": {
"type": "token[]",
"value": [ "/World", "/World2" ]
},
"inputs:suffix": "foo",
"outputs:path": {
"type": "token[]",
"value": [ "/World/foo", "/World2/foo" ]
}
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnStartsWith.ogn | {
"StartsWith": {
"version": 1,
"description": [
"Determines if a string starts with a given string value"
],
"uiName": "Starts With",
"categories": ["function"],
"scheduling": ["threadsafe"],
"inputs": {
"prefix": {
"type": "string",
"description": "The prefix to test"
},
"value": {
"type": "string",
"description": "The string to check"
}
},
"outputs": {
"isPrefix": {
"type": "bool",
"description": "True if 'value' starts with 'prefix'"
}
},
"tests": [
{
"inputs:value": "", "inputs:prefix": "", "outputs:isPrefix": true
},
{
"inputs:value": "a", "inputs:prefix": "", "outputs:isPrefix": true
},
{
"inputs:value": "", "inputs:prefix": "a", "outputs:isPrefix": false
},
{
"inputs:value": "aa", "inputs:prefix": "a", "outputs:isPrefix": true
},
{
"inputs:value": "aa", "inputs:prefix": "aa", "outputs:isPrefix": true
},
{
"inputs:value": "aa", "inputs:prefix": "aaa", "outputs:isPrefix": false
},
{
"inputs:value": "aaa", "inputs:prefix": "aa", "outputs:isPrefix": true
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnIsEmpty.ogn | {
"IsEmpty": {
"version": 1,
"description": [
"Checks if the given input is empty.",
"An input is considered empty if there is no data.",
"A string or array of size 0 is considered empty whereas a blank string ' ' is not empty.",
"A float with value 0.0 and int[2] with value [0, 0] are not empty."
],
"uiName": "Is Empty",
"categories": ["function"],
"scheduling": ["threadsafe"],
"inputs": {
"input": {
"type": "any",
"uiName": "Input",
"description": "The input to check if empty"
}
},
"outputs": {
"isEmpty": {
"type": "bool",
"uiName": "Is Empty",
"description": "True if the input is empty, false otherwise"
}
},
"tests": [
{ "inputs:input": { "type": "bool", "value": false }, "outputs:isEmpty": false },
{ "inputs:input": { "type": "int", "value": 0 }, "outputs:isEmpty": false },
{ "inputs:input": { "type": "double", "value": 0.0 }, "outputs:isEmpty": false },
{ "inputs:input": { "type": "uchar", "value": 0 }, "outputs:isEmpty": false },
{ "inputs:input": { "type": "float[2]", "value": [0.0, 0.0] }, "outputs:isEmpty": false },
{ "inputs:input": { "type": "float[]", "value": [0.0] }, "outputs:isEmpty": false },
{ "inputs:input": { "type": "float[]", "value": [] }, "outputs:isEmpty": true },
{ "inputs:input": { "type": "int[]", "value": [] }, "outputs:isEmpty": true },
{ "inputs:input": { "type": "float[2][]", "value": [] }, "outputs:isEmpty": true },
{ "inputs:input": { "type": "token", "value": "hello" }, "outputs:isEmpty": false },
{ "inputs:input": { "type": "string", "value": "hello" }, "outputs:isEmpty": false },
{ "inputs:input": { "type": "token", "value": " " }, "outputs:isEmpty": false },
{ "inputs:input": { "type": "string", "value": " " }, "outputs:isEmpty": false },
{ "inputs:input": { "type": "string", "value": "" }, "outputs:isEmpty": true },
{ "inputs:input": { "type": "token", "value": "" }, "outputs:isEmpty": true }
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnSelectIf.cpp | // Copyright (c) 2022-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 <OgnSelectIfDatabase.h>
#include <omni/graph/core/ogn/ComputeHelpers.h>
#include <omni/graph/core/ogn/string.h>
#include <omni/graph/core/ogn/Types.h>
#include <carb/logging/Log.h>
namespace omni
{
namespace graph
{
namespace nodes
{
namespace
{
template<typename T>
bool tryComputeAssumingType(OgnSelectIfDatabase& db, size_t count)
{
auto functor = [](auto const& a, auto const& b, auto const& condition, auto& result)
{
result = condition ? a : b;
};
return ogn::compute::tryComputeWithArrayBroadcasting<T, T, bool, T>(
db.inputs.ifTrue(), db.inputs.ifFalse(), db.inputs.condition(), db.outputs.result(), functor, count);
}
template<typename T, size_t N>
bool tryComputeAssumingType(OgnSelectIfDatabase& db, size_t count)
{
auto functor = [](auto const& a, auto const& b, auto const& condition, auto& result)
{
if (condition)
{
memcpy(result, a, sizeof(T) * N);
}
else
{
memcpy(result, b, sizeof(T) * N);
}
};
return ogn::compute::tryComputeWithArrayBroadcasting<T[N], T[N], bool, T[N]>(
db.inputs.ifTrue(), db.inputs.ifFalse(), db.inputs.condition(), db.outputs.result(), functor, count);
}
} // namespace
class OgnSelectIf
{
public:
static bool computeVectorized(OgnSelectIfDatabase& db, size_t count)
{
NodeObj nodeObj = db.abi_node();
const AttributeObj ifTrueAttr = nodeObj.iNode->getAttributeByToken(nodeObj, inputs::ifTrue.token());
const Type ifTrueType = ifTrueAttr.iAttribute->getResolvedType(ifTrueAttr);
const AttributeObj ifFalseAttr = nodeObj.iNode->getAttributeByToken(nodeObj, inputs::ifFalse.token());
const Type ifFalseType = ifFalseAttr.iAttribute->getResolvedType(ifFalseAttr);
const AttributeObj conditionAttr = nodeObj.iNode->getAttributeByToken(nodeObj, inputs::condition.token());
const Type conditionType = conditionAttr.iAttribute->getResolvedType(conditionAttr);
// This handles string case (arrays of strings are not supported)
if (ifTrueType.baseType == BaseDataType::eUChar && ifTrueType.arrayDepth == 1
&& ifFalseType.baseType == BaseDataType::eUChar && ifFalseType.arrayDepth == 1
&& conditionType.arrayDepth == 0)
{
for (size_t idx = 0; idx < count; ++idx)
{
const bool condition = *db.inputs.condition(idx).template get<bool>();
auto ifTrue = db.inputs.ifTrue(idx).template get<uint8_t[]>();
auto ifFalse = db.inputs.ifFalse(idx).template get<uint8_t[]>();
auto result = db.outputs.result(idx).template get<uint8_t[]>();
if (condition)
{
result->resize(ifTrue->size());
memcpy(&((*result)[0]), &((*ifTrue)[0]), result->size());
}
else
{
result->resize(ifFalse->size());
memcpy(&((*result)[0]), &((*ifFalse)[0]), result->size());
}
}
return true;
}
try
{
switch (ifTrueType.baseType)
{
case BaseDataType::eBool:
return tryComputeAssumingType<bool>(db, count);
case BaseDataType::eToken:
return tryComputeAssumingType<ogn::Token>(db, count);
case BaseDataType::eDouble:
switch (ifTrueType.componentCount)
{
case 1: return tryComputeAssumingType<double>(db, count);
case 2: return tryComputeAssumingType<double, 2>(db, count);
case 3: return tryComputeAssumingType<double, 3>(db, count);
case 4: return tryComputeAssumingType<double, 4>(db, count);
case 9: return tryComputeAssumingType<double, 9>(db, count);
case 16: return tryComputeAssumingType<double, 16>(db, count);
default: break;
}
case BaseDataType::eFloat:
switch (ifTrueType.componentCount)
{
case 1: return tryComputeAssumingType<float>(db, count);
case 2: return tryComputeAssumingType<float, 2>(db, count);
case 3: return tryComputeAssumingType<float, 3>(db, count);
case 4: return tryComputeAssumingType<float, 4>(db, count);
default: break;
}
case BaseDataType::eHalf:
switch (ifTrueType.componentCount)
{
case 1: return tryComputeAssumingType<pxr::GfHalf>(db, count);
case 2: return tryComputeAssumingType<pxr::GfHalf, 2>(db, count);
case 3: return tryComputeAssumingType<pxr::GfHalf, 3>(db, count);
case 4: return tryComputeAssumingType<pxr::GfHalf, 4>(db, count);
default: break;
}
case BaseDataType::eInt:
switch (ifTrueType.componentCount)
{
case 1: return tryComputeAssumingType<int32_t>(db, count);
case 2: return tryComputeAssumingType<int32_t, 2>(db, count);
case 3: return tryComputeAssumingType<int32_t, 3>(db, count);
case 4: return tryComputeAssumingType<int32_t, 4>(db, count);
default: break;
}
;
case BaseDataType::eInt64:
return tryComputeAssumingType<int64_t>(db, count);
case BaseDataType::eUChar:
return tryComputeAssumingType<unsigned char>(db, count);
case BaseDataType::eUInt:
return tryComputeAssumingType<uint32_t>(db, count);
case BaseDataType::eUInt64:
return tryComputeAssumingType<uint64_t>(db, count);
default: break;
}
db.logWarning("Failed to resolve input types");
}
catch (ogn::compute::InputError &error)
{
db.logError(error.what());
}
return false;
}
static void onConnectionTypeResolve(const NodeObj& node){
auto ifTrue = node.iNode->getAttributeByToken(node, inputs::ifTrue.token());
auto ifFalse = node.iNode->getAttributeByToken(node, inputs::ifFalse.token());
auto condition = node.iNode->getAttributeByToken(node, inputs::condition.token());
auto result = node.iNode->getAttributeByToken(node, outputs::result.token());
auto ifTrueType = ifTrue.iAttribute->getResolvedType(ifTrue);
auto ifFalseType = ifFalse.iAttribute->getResolvedType(ifFalse);
auto conditionType = condition.iAttribute->getResolvedType(condition);
// Require ifTrue, ifFalse, and condition to be resolved before determining result's type
if (ifTrueType.baseType != BaseDataType::eUnknown && ifFalseType.baseType != BaseDataType::eUnknown
&& conditionType.baseType != BaseDataType::eUnknown)
{
std::array<AttributeObj, 3> attrs { ifTrue, ifFalse, result };
std::array<uint8_t, 3> tupleCounts {
ifTrueType.componentCount,
ifFalseType.componentCount,
std::max(ifTrueType.componentCount, ifFalseType.componentCount)
};
std::array<uint8_t, 3> arrayDepths {
ifTrueType.arrayDepth,
ifFalseType.arrayDepth,
std::max(conditionType.arrayDepth, std::max(ifTrueType.arrayDepth, ifFalseType.arrayDepth))
};
const bool isStringInput = (ifTrueType.baseType == BaseDataType::eUChar
&& ifTrueType.arrayDepth == 1
&& ifFalseType.baseType == BaseDataType::eUChar
&& ifFalseType.arrayDepth == 1
&& conditionType.arrayDepth == 0
&& ifTrueType.role == AttributeRole::eText
&& ifFalseType.role == AttributeRole::eText);
std::array<AttributeRole, 3> rolesBuf {
ifTrueType.role,
ifFalseType.role,
isStringInput ? AttributeRole::eText : AttributeRole::eUnknown
};
node.iNode->resolvePartiallyCoupledAttributes(node, attrs.data(), tupleCounts.data(),
arrayDepths.data(), rolesBuf.data(), attrs.size());
}
}
};
REGISTER_OGN_NODE()
} // namespace nodes
} // namespace graph
} // namespace omni
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnArrayGetSize.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 <OgnArrayGetSizeDatabase.h>
#include <omni/graph/core/ogn/ComputeHelpers.h>
#include <omni/graph/core/ogn/string.h>
#include <omni/graph/core/ogn/Types.h>
#include <algorithm>
namespace omni {
namespace graph {
namespace nodes {
class OgnArrayGetSize
{
public:
static bool compute(OgnArrayGetSizeDatabase& db)
{
try
{
db.outputs.size() = int(db.inputs.array().size());
return true;
}
catch (ogn::compute::InputError const &error)
{
db.logError(error.what());
}
return false;
}
static void onConnectionTypeResolve(const NodeObj& node){
auto const inputArray = node.iNode->getAttributeByToken(node, inputs::array.token());
auto const inputArrayType = inputArray.iAttribute->getResolvedType(inputArray);
if (inputArrayType.baseType != BaseDataType::eUnknown)
{
std::array<AttributeObj, 1> attrs { inputArray };
// all should have the same tuple count
std::array<uint8_t, 1> tupleCounts {
inputArrayType.componentCount
};
// value type can not be an array because we don't support arrays-of-arrays
std::array<uint8_t, 1> arrayDepths {
1
};
std::array<AttributeRole, 1> rolesBuf {
inputArrayType.role
};
node.iNode->resolvePartiallyCoupledAttributes(node, attrs.data(), tupleCounts.data(),
arrayDepths.data(), rolesBuf.data(), attrs.size());
}
}
};
REGISTER_OGN_NODE()
} // namespace nodes
} // namespace graph
} // namespace omni |
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnEndsWith.ogn | {
"EndsWith": {
"version": 1,
"description": [
"Determines if a string ends with a given string value"
],
"uiName": "Ends With",
"categories": ["function"],
"scheduling": ["threadsafe"],
"inputs": {
"suffix": {
"type": "string",
"description": "The suffix to test"
},
"value": {
"type": "string",
"description": "The string to check"
}
},
"outputs": {
"isSuffix": {
"type": "bool",
"description": "True if 'value' ends with 'suffix'"
}
},
"tests": [
{
"inputs:value": "", "inputs:suffix": "", "outputs:isSuffix": true
},
{
"inputs:value": "a", "inputs:suffix": "", "outputs:isSuffix": true
},
{
"inputs:value": "", "inputs:suffix": "a", "outputs:isSuffix": false
},
{
"inputs:value": "aa", "inputs:suffix": "a", "outputs:isSuffix": true
},
{
"inputs:value": "ab", "inputs:suffix": "ab", "outputs:isSuffix": true
},
{
"inputs:value": "aa", "inputs:suffix": "aaa", "outputs:isSuffix": false
},
{
"inputs:value": "aba", "inputs:suffix": "ba", "outputs:isSuffix": true
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnMakeVector2.ogn | {
"MakeVector2": {
"version": 1,
"description": [
"Merge 2 input values into a single output vector.",
"If the inputs are arrays, the output will be an array of vectors."
],
"uiName": "Make 2-Vector",
"categories": ["math:conversion"],
"tags": ["compose", "combine", "join"],
"scheduling": ["threadsafe"],
"inputs": {
"x": {
"type": ["double", "float", "half", "int", "double[]", "float[]", "half[]", "int[]"],
"uiName": "X",
"description": "The first component of the vector"
},
"y": {
"type": ["double", "float", "half", "int", "double[]", "float[]", "half[]", "int[]"],
"uiName": "Y",
"description": "The second component of the vector"
}
},
"outputs": {
"tuple": {
"type": ["double[2]", "float[2]", "half[2]", "int[2]", "double[2][]", "float[2][]", "half[2][]", "int[2][]"],
"uiName": "Vector",
"description": "Output vector(s)"
}
},
"tests" : [
{
"inputs:x": {"type": "float", "value": 42.0}, "inputs:y": {"type": "float", "value": 1.0},
"outputs:tuple": {"type": "float[2]", "value": [42.0, 1.0]}
},
{
"inputs:x": {"type": "float", "value": 42.0},
"outputs:tuple": {"type": "float[2]", "value": [42.0, 0.0]}
},
{
"inputs:x": {"type": "float[]", "value": [42,1,0]},
"inputs:y": {"type": "float[]", "value": [0,1,2]},
"outputs:tuple": {"type": "float[2][]", "value": [[42,0],[1,1],[0,2]]}
},
{
"inputs:x": {"type": "int", "value": 42}, "inputs:y": {"type": "int", "value": -42},
"outputs:tuple": {"type": "int[2]", "value": [42, -42]}
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnToToken.ogn | {
"ToToken": {
"version": 1,
"description": [
"Converts the given input to a string equivalent and provides the Token value"
],
"uiName": "To Token",
"categories": ["function"],
"scheduling": ["threadsafe"],
"inputs": {
"value": {
"type": "any",
"uiName": "value",
"description": "The value to be converted to a token"
}
},
"outputs": {
"converted": {
"type": "token",
"uiName": "Token",
"description": "Stringified output as a Token"
}
},
"tests" : [
{
"inputs:value": {"type": "bool", "value": true}, "outputs:converted": "True"
},
{
"inputs:value": {"type": "double", "value": 2.1}, "outputs:converted": "2.1"
},
{
"inputs:value": {"type": "int", "value": 42}, "outputs:converted": "42"
},
{
"inputs:value": {"type": "double[3]", "value": [1.8, 2.2, 3] }, "outputs:converted": "[1.8, 2.2, 3]"
},
{
"inputs:value": {"type": "half[3]", "value": [2, 3, 4.5] }, "outputs:converted": "[2, 3, 4.5]"
},
{
"inputs:value": {"type": "int[2][]", "value": [[1, 2],[3, 4]] }, "outputs:converted": "[[1, 2], [3, 4]]"
},
{
"inputs:value": {"type": "uint64", "value": 42 }, "outputs:converted": "42"
},
{
"inputs:value": {"type": "token", "value": "Foo" }, "outputs:converted": "Foo"
},
{
"inputs:value": {"type": "string", "value": "Foo" }, "outputs:converted": "Foo"
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnBuildString.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 <OgnBuildStringDatabase.h>
namespace omni
{
namespace graph
{
namespace nodes
{
class OgnBuildString
{
public:
static bool compute(OgnBuildStringDatabase& db)
{
auto const& inputValue = db.inputs.a();
auto const& suffixIn = db.inputs.b();
auto& outValue = db.outputs.value();
bool result = true;
if (inputValue.type().baseType == BaseDataType::eToken)
result = result && computeForToken(db, inputValue, suffixIn, outValue);
else
result = result && computeForString(db, inputValue, suffixIn, outValue);
auto const& dynamicInputs = db.getDynamicInputs();
if (!result || dynamicInputs.empty())
return result;
auto accumulatingValue = omni::graph::core::ogn::constructInputFromOutput(db, db.outputs.value(), outputs::value.token());
for (auto const& input : dynamicInputs)
{
if (input().type().baseType == BaseDataType::eToken)
result = result && computeForToken(db, accumulatingValue, input(), outValue);
else
result = result && computeForString(db, accumulatingValue, input(), outValue);
}
return result;
}
static bool computeForString(OgnBuildStringDatabase& db,
ogn::RuntimeAttribute<ogn::kOgnInput, ogn::kCpu> const& inputValue,
ogn::RuntimeAttribute<ogn::kOgnInput, ogn::kCpu> const& suffixIn,
ogn::RuntimeAttribute<ogn::kOgnOutput, ogn::kCpu>& outValue)
{
auto const suffixData = suffixIn.get<uint8_t[]>();
// No suffix? Just copy in to out
if (suffixData->empty())
{
// the inputValue may be an alias for the outValue
if (inputValue.name() != outValue.name())
db.outputs.value().copyData(inputValue);
return true;
}
auto const inputValueData = inputValue.get<uint8_t[]>();
std::string outVal;
outVal.reserve(inputValueData.size() + suffixData.size());
outVal.append(reinterpret_cast<char const*>(inputValueData->data()), inputValueData.size());
outVal.append(reinterpret_cast<char const*>(suffixData->data()), suffixData.size());
auto outData = outValue.get<uint8_t[]>();
size_t outBufferSize = outVal.size();
outData->resize(outBufferSize);
memcpy(outData->data(), reinterpret_cast<uint8_t const*>(outVal.data()), outBufferSize);
return true;
}
static bool computeForToken(OgnBuildStringDatabase& db,
ogn::RuntimeAttribute<ogn::kOgnInput, ogn::kCpu> const& inputValue,
ogn::RuntimeAttribute<ogn::kOgnInput, ogn::kCpu> const& suffix,
ogn::RuntimeAttribute<ogn::kOgnOutput, ogn::kCpu>& outValue)
{
std::vector<char const*> suffixes;
if (suffix.type().arrayDepth == 0)
{
NameToken suffixToken = *suffix.get<OgnToken>();
if (suffixToken != omni::fabric::kUninitializedToken)
suffixes.push_back(db.tokenToString(suffixToken));
}
else
{
const auto suffixTokens = *suffix.get<OgnToken[]>();
suffixes.resize(suffixTokens.size());
std::transform(suffixTokens.begin(), suffixTokens.end(), suffixes.begin(),
[&db](auto t) { return db.tokenToString(t); });
}
// No suffix? Just copy in to out
if (suffixes.empty())
{
// the input value may be an alias for the output value
if (inputValue.name() != outValue.name())
db.outputs.value().copyData(inputValue);
return true;
}
if (inputValue.type().arrayDepth > 0)
{
const auto inputValueArray = *inputValue.get<OgnToken[]>();
auto outputPathArray = *db.outputs.value().get<OgnToken[]>();
outputPathArray.resize(inputValueArray.size());
if (suffixes.size() == 1)
{
const char* suffixStr = suffixes[0];
std::transform(inputValueArray.begin(), inputValueArray.end(), outputPathArray.begin(),
[&](const auto& p)
{
std::string s = db.tokenToString(p);
s += suffixStr;
return db.stringToToken(s.c_str());
});
}
else
{
if (inputValueArray.size() != suffixes.size())
{
CARB_LOG_ERROR("inputs:value and inputs:suffix arrays are not the same size (%zu and %zu)",
inputValueArray.size(), suffixes.size());
return false;
}
for (size_t i = 0; i < inputValueArray.size(); ++i)
{
std::string s = db.tokenToString(inputValueArray[i]);
s += suffixes[i];
outputPathArray[i] = db.stringToToken(s.c_str());
}
}
return true;
}
else
{
NameToken inValue = *inputValue.get<OgnToken>();
std::string s;
if (inValue != omni::fabric::kUninitializedToken)
{
s = db.tokenToString(inValue);
}
s += suffixes[0];
*db.outputs.value().get<OgnToken>() = db.stringToToken(s.c_str());
}
return true;
}
static void onConnectionTypeResolve(const NodeObj& node)
{
auto inputVal = node.iNode->getAttributeByToken(node, OgnBuildStringAttributes::inputs::a.m_token);
auto outputVal = node.iNode->getAttributeByToken(node, OgnBuildStringAttributes::outputs::value.m_token);
// in and out needs to be the same
std::array<AttributeObj, 2> io{ inputVal, outputVal };
node.iNode->resolveCoupledAttributes(node, io.data(), io.size());
//retrieve all other input attributes
auto totalCount = node.iNode->getAttributeCount(node);
std::vector<AttributeObj> attrs(totalCount);
node.iNode->getAttributes(node, attrs.data(), totalCount);
size_t idx = 0;
size_t count = totalCount;
while (idx != count)
{
if (attrs[idx].iAttribute->getPortType(attrs[idx]) != AttributePortType::kAttributePortType_Input ||
attrs[idx].attributeHandle == inputVal.attributeHandle)
{
count--;
std::swap(attrs[idx], attrs[count]);
}
else
{
idx++;
}
}
auto type = inputVal.iAttribute->getResolvedType(inputVal);
// if input is an array of token, suffixes are allowed to be either a simple or an array of token(s)
if (type.baseType == BaseDataType::eToken && type.arrayDepth != 0)
{
for (auto const& attr : attrs)
{
auto suffixType = attr.iAttribute->getResolvedType(attr);
if (suffixType.baseType == BaseDataType::eUChar) // string not compatible with tokens
attr.iAttribute->setResolvedType(attr, type);
}
}
else if (type.baseType != BaseDataType::eUnknown)
{
// else, they all needs to have the same type
for (auto const& attr : attrs)
attr.iAttribute->setResolvedType(attr, type);
}
}
};
REGISTER_OGN_NODE();
} // nodes
} // graph
} // omni
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnBreakVector3.ogn | {
"BreakVector3": {
"version": 1,
"description": ["Split vector into 3 component values."],
"uiName": "Break 3-Vector",
"categories": ["math:conversion"],
"tags": ["decompose", "separate", "isolate"],
"scheduling": ["threadsafe"],
"inputs": {
"tuple": {
"type": ["double[3]", "float[3]", "half[3]", "int[3]"],
"uiName": "Vector",
"description": "3-vector to be broken"
}
},
"outputs": {
"x": {
"type": ["double", "float", "half", "int"],
"uiName": "X",
"description": "The first component of the vector"
},
"y": {
"type": ["double", "float", "half", "int"],
"uiName": "Y",
"description": "The second component of the vector"
},
"z": {
"type": ["double", "float", "half", "int"],
"uiName": "Z",
"description": "The third component of the vector"
}
},
"tests" : [
{
"inputs:tuple": {"type": "float[3]", "value": [42.0, 1.0, 0.0]},
"outputs:x": {"type": "float", "value": 42.0}, "outputs:y": {"type": "float", "value": 1.0},
"outputs:z": {"type": "float", "value": 0.0}
},
{
"inputs:tuple": {"type": "int[3]", "value": [42, -42, 5]},
"outputs:x": {"type": "int", "value": 42}, "outputs:y": {"type": "int", "value": -42},
"outputs:z": {"type": "int", "value": 5}
},
{
"inputs:tuple": {"type": "colorf[3]", "value": [42.0, 1.0, 0.0]},
"outputs:x": {"type": "float", "value": 42.0}, "outputs:y": {"type": "float", "value": 1.0},
"outputs:z": {"type": "float", "value": 0.0}
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnGetPrimRelationship.ogn | {
"GetPrimRelationship": {
"version": 3,
"description": ["DEPRECATED - Use ReadPrimRelationship!"],
"uiName": "Get Prim Relationship",
"categories": ["sceneGraph"],
"scheduling": ["usd-read", "threadsafe"],
"inputs": {
"prim": {
"type": "target",
"description": "The prim with the relationship",
"optional": true
},
"name": {
"type": "token",
"description": "Name of the relationship property",
"uiName": "Relationship Name"
},
"usePath": {
"type": "bool",
"default": false,
"description": "When true, the 'path' attribute is used, otherwise it will read the connection at the 'prim' attribute.",
"deprecated": "Use prim input with a GetPrimsAtPath node instead"
},
"path": {
"type": "token",
"description": "Path of the prim with the relationship property",
"uiName": "Prim Path",
"optional": true,
"deprecated": "Use prim input with a GetPrimsAtPath node instead"
}
},
"outputs": {
"paths": {
"type": "token[]",
"description": "The prim paths for the given relationship",
"uiName": "Paths"
}
}
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnArrayInsertValue.ogn | {
"ArrayInsertValue": {
"version": 1,
"description": [
"Inserts an element at the given index. The indexing is zero-based, so 0 adds an element to the front of the",
"array and index = Length inserts at the end of the array. The index will be clamped to the range (0, Length),",
"so an index of -1 will add to the front, and an index larger than the array size will append to the end."
],
"uiName": "Array Insert Value",
"categories": ["math:array"],
"scheduling": ["threadsafe"],
"inputs": {
"array": {
"type": ["arrays", "bool[]"],
"description": "The array to be modified",
"uiName": "Array"
},
"value": {
"type": ["array_elements", "bool"],
"description": "The value to be inserted"
},
"index": {
"type": "int",
"description": "The array index to insert the value, which is clamped to the valid range",
"uiName": "Index"
}
},
"outputs": {
"array": {
"type": ["arrays", "bool[]"],
"description": "The modified array",
"uiName": "Array"
}
},
"tests": [
{
"inputs:array": {"type": "int[]", "value": [41, 42]}, "inputs:index": 0,
"inputs:value": {"type": "int", "value": 1}, "outputs:array": {"type": "int[]", "value": [1, 41, 42]}
},
{
"inputs:array": {"type": "int[]", "value": [41, 42]}, "inputs:index": 1,
"inputs:value": {"type": "int", "value": 1}, "outputs:array": {"type": "int[]", "value": [41, 1, 42]}
},
{
"inputs:array": {"type": "int[]", "value": [41, 42]}, "inputs:index": 2,
"inputs:value": {"type": "int", "value": 1}, "outputs:array": {"type": "int[]", "value": [41, 42, 1]}
},
{
"inputs:array": {"type": "token[]", "value": ["FOO", "BAR"]}, "inputs:index": 1,
"inputs:value": {"type": "token", "value": "BAZ"},
"outputs:array": {"type": "token[]", "value": ["FOO", "BAZ", "BAR"]}
},
{
"inputs:array": {"type": "half[]", "value": [41, 42]}, "inputs:index": 1,
"inputs:value": {"type": "half", "value": 1}, "outputs:array": {"type": "half[]", "value": [41, 1, 42]}
},
{
"inputs:array": {"type": "half[2][]", "value": [[41, 1], [42, 2]]}, "inputs:index": 1,
"inputs:value": {"type": "half[2]", "value": [1, 2]},
"outputs:array": {"type": "half[2][]", "value": [[41, 1], [1, 2], [42, 2]]}
},
{
"inputs:array": {"type": "double[2][]", "value": [[41, 1], [42, 2]]}, "inputs:index": 1,
"inputs:value": {"type": "double[2]", "value": [1, 2]},
"outputs:array": {"type": "double[2][]", "value": [[41, 1], [1, 2], [42, 2]]}
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnToDouble.cpp | // Copyright (c) 2022-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 <OgnToDoubleDatabase.h>
#include <omni/graph/core/ogn/ComputeHelpers.h>
#include <omni/graph/core/ogn/UsdTypes.h>
namespace omni
{
namespace graph
{
namespace nodes
{
namespace
{
template<typename T>
bool tryComputeAssumingType(OgnToDoubleDatabase& db, size_t count)
{
auto functor = [](auto const& value, auto& converted) { converted = static_cast<double>(value); };
return ogn::compute::tryComputeWithArrayBroadcasting<T, double>(db.inputs.value(), db.outputs.converted(), functor, count);
}
template<typename T, size_t tupleSize>
bool tryComputeAssumingType(OgnToDoubleDatabase& db, size_t count)
{
auto functor = [](auto const& value, auto& converted) { converted = static_cast<double>(value); };
return ogn::compute::tryComputeWithTupleBroadcasting<tupleSize, T, double>(
db.inputs.value(), db.outputs.converted(), functor, count);
}
} // namespace
class OgnToDouble
{
public:
// Node to convert numeric inputs to floats
static bool computeVectorized(OgnToDoubleDatabase& db, size_t count)
{
auto& inputType = db.inputs.value().type();
// Compute the components, if the types are all resolved.
try
{
switch (inputType.baseType)
{
case BaseDataType::eBool:
return tryComputeAssumingType<bool>(db, count);
case BaseDataType::eDouble:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<double>(db, count);
case 2: return tryComputeAssumingType<double, 2>(db, count);
case 3: return tryComputeAssumingType<double, 3>(db, count);
case 4: return tryComputeAssumingType<double, 4>(db, count);
case 9: return tryComputeAssumingType<double, 9>(db, count);
case 16: return tryComputeAssumingType<double, 16>(db, count);
default: break;
}
case BaseDataType::eFloat:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<float>(db, count);
case 2: return tryComputeAssumingType<float, 2>(db, count);
case 3: return tryComputeAssumingType<float, 3>(db, count);
case 4: return tryComputeAssumingType<float, 4>(db, count);
default: break;
}
case BaseDataType::eHalf:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<pxr::GfHalf>(db, count);
case 2: return tryComputeAssumingType<pxr::GfHalf, 2>(db, count);
case 3: return tryComputeAssumingType<pxr::GfHalf, 3>(db, count);
case 4: return tryComputeAssumingType<pxr::GfHalf, 4>(db, count);
default: break;
}
case BaseDataType::eInt:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<int32_t>(db, count);
case 2: return tryComputeAssumingType<int32_t, 2>(db, count);
case 3: return tryComputeAssumingType<int32_t, 3>(db, count);
case 4: return tryComputeAssumingType<int32_t, 4>(db, count);
default: break;
}
;
case BaseDataType::eInt64:
return tryComputeAssumingType<int64_t>(db, count);
case BaseDataType::eUChar:
return tryComputeAssumingType<unsigned char>(db, count);
case BaseDataType::eUInt:
return tryComputeAssumingType<uint32_t>(db, count);
case BaseDataType::eUInt64:
return tryComputeAssumingType<uint64_t>(db, count);
default: break;
}
db.logWarning("Failed to resolve input types");
}
catch (const std::exception& e)
{
db.logError("Input could not be converted to float: %s", e.what());
return false;
}
return true;
}
static void onConnectionTypeResolve(const NodeObj& nodeObj)
{
auto valueAttr = nodeObj.iNode->getAttributeByToken(nodeObj, inputs::value.token());
auto outAttr = nodeObj.iNode->getAttributeByToken(nodeObj, outputs::converted.token());
auto valueType = valueAttr.iAttribute->getResolvedType(valueAttr);
// The output shape must match the input shape and visa-versa, however we can't say anything
// about the input base type until it's connected
if (valueType.baseType != BaseDataType::eUnknown)
{
Type resultType(BaseDataType::eDouble, valueType.componentCount, valueType.arrayDepth);
outAttr.iAttribute->setResolvedType(outAttr, resultType);
}
}
};
REGISTER_OGN_NODE();
} // nodes
} // graph
} // omni
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnToUint64.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 <OgnToUint64Database.h>
#include <omni/graph/core/ogn/ComputeHelpers.h>
#include <omni/graph/core/ogn/UsdTypes.h>
namespace omni
{
namespace graph
{
namespace nodes
{
namespace
{
template<typename T>
bool tryComputeAssumingType(OgnToUint64Database& db)
{
auto functor = [](auto const& value, auto& converted) { converted = static_cast<uint64_t>(value); };
return ogn::compute::tryComputeWithArrayBroadcasting<T, uint64_t>(db.inputs.value(), db.outputs.converted(), functor);
}
} // namespace
class OgnToUint64
{
public:
// Node to convert numeric inputs to floats
static bool compute(OgnToUint64Database& db)
{
auto& valueType = db.inputs.value().type();
switch (valueType.baseType)
{
case BaseDataType::eBool:
return tryComputeAssumingType<bool>(db);
case BaseDataType::eUChar:
return tryComputeAssumingType<uint8_t>(db);
case BaseDataType::eInt:
return tryComputeAssumingType<int32_t>(db);
case BaseDataType::eUInt:
return tryComputeAssumingType<uint32_t>(db);
case BaseDataType::eInt64:
return tryComputeAssumingType<int64_t>(db);
case BaseDataType::eHalf:
return tryComputeAssumingType<pxr::GfHalf>(db);
case BaseDataType::eFloat:
return tryComputeAssumingType<float>(db);
case BaseDataType::eDouble:
return tryComputeAssumingType<double>(db);
default:
db.logError("Failed to resolve input types");
}
return false;
}
static void onConnectionTypeResolve(const NodeObj& nodeObj)
{
auto valueAttr = nodeObj.iNode->getAttributeByToken(nodeObj, inputs::value.token());
auto outAttr = nodeObj.iNode->getAttributeByToken(nodeObj, outputs::converted.token());
auto valueType = valueAttr.iAttribute->getResolvedType(valueAttr);
// The output shape must match the input shape and visa-versa, however we can't say anything
// about the input base type until it's connected
if (valueType.baseType != BaseDataType::eUnknown)
{
Type resultType(BaseDataType::eUInt64, 1, valueType.arrayDepth);
outAttr.iAttribute->setResolvedType(outAttr, resultType);
}
}
};
REGISTER_OGN_NODE();
} // nodes
} // graph
} // omni
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnStartsWith.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 <OgnStartsWithDatabase.h>
#include <algorithm>
namespace omni
{
namespace graph
{
namespace nodes
{
class OgnStartsWith
{
public:
static bool compute(OgnStartsWithDatabase& db)
{
auto const& prefix = db.inputs.prefix();
auto const& value = db.inputs.value();
auto iters = std::mismatch(prefix.begin(), prefix.end(), value.begin(), value.end());
db.outputs.isPrefix() = (iters.first == prefix.end());
return true;
}
};
REGISTER_OGN_NODE();
} // nodes
} // graph
} // omni
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnBuildString.ogn | {
"BuildString": {
"$comment": "Replaces the v1 AppendString node as it renames the input attributes",
"version": 2,
"description": [
"Creates a new token or string by concatenating the inputs.",
"token[] inputs will be appended element-wise."
],
"uiName": "Append String",
"categories": ["function"],
"scheduling": ["threadsafe"],
"inputs": {
"a": {
"type": ["token", "token[]", "string"],
"description": "The string(s) to be appended to"
},
"b": {
"type": ["token", "token[]", "string"],
"description": "The string to be appended"
}
},
"outputs": {
"value": {
"type": ["token","token[]", "string"],
"description": "The new string(s)"
}
},
"tests": [
{
"inputs:a": {"type":"token", "value": "/"}, "inputs:b": {"type":"token", "value": "foo"}, "outputs:value": {"type":"token", "value": "/foo"}
},
{
"inputs:a": {"type":"token[]", "value": ["/World","/World2"]}, "inputs:b": {"type":"token", "value": "/foo"}, "outputs:value": {"type":"token[]", "value": ["/World/foo","/World2/foo"]}
},
{
"inputs:a": {"type":"token[]", "value": ["/World","/World2"]}, "inputs:b": {"type":"token[]", "value": ["/foo", "/bar"]}, "outputs:value": {"type":"token[]", "value": ["/World/foo","/World2/bar"]}
},
{
"inputs:a": {"type":"string", "value": "/"}, "inputs:b": {"type":"string", "value": "foo"}, "outputs:value": {"type":"string", "value": "/foo"}
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnSetGatheredAttribute.cpp | // Copyright (c) 2021-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 <OgnSetGatheredAttributeDatabase.h>
#include <omni/graph/core/IGatherPrototype.h>
#include <carb/flatcache/FlatCache.h>
using namespace carb::flatcache;
namespace omni
{
namespace graph
{
namespace core
{
// WARNING!
// The following code uses low-level ABI functionality and should not be copied for other purposes when such
// low level access is not required. Please use the OGN-generated API whenever possible.
#define RETURN_TRUE_EXEC \
{\
db.outputs.execOut() = kExecutionAttributeStateEnabled;\
return true;\
}
class OgnSetGatheredAttribute
{
public:
static bool compute(OgnSetGatheredAttributeDatabase& db)
{
auto& nodeObj = db.abi_node();
const INode& iNode = *nodeObj.iNode;
const IGraphContext& iContext = *db.abi_context().iContext;
const omni::graph::core::IGatherPrototype* iGatherPrototype =
carb::getCachedInterface<omni::graph::core::IGatherPrototype>();
const auto& value = db.inputs.value();
const auto& mask = db.inputs.mask();
NameToken attributeName = db.inputs.name();
const char* attributeNameStr = db.tokenToString(attributeName);
if (!attributeNameStr || strlen(attributeNameStr) == 0)
RETURN_TRUE_EXEC
GatherId gatherId = static_cast<GatherId>(db.inputs.gatherId());
if (gatherId == kInvalidGatherId)
RETURN_TRUE_EXEC
if (!mask.empty() && value.size() > 1 && mask.size() != value.size())
{
db.logError("The length of the write mask (%zd) does not match the length of the value (%zd)",
mask.size(), value.size());
return false;
}
BucketId const* buckets{ nullptr };
size_t numBuckets{ 0 };
if (!iGatherPrototype->getGatheredBuckets(db.abi_context(), gatherId, buckets, numBuckets))
{
db.logError("Could not get gathered bucket list for Gather %zd", gatherId);
return false;
}
if (numBuckets == 0)
{
db.logError("Gathered bucket list is empty for Gather %zd", gatherId);
return false;
}
Type elementType;
size_t elementSize{ 0 };
if (!iGatherPrototype->getGatheredType(db.abi_context(), gatherId, attributeName, elementType, elementSize))
{
db.logError("Could not determine gathered type");
return false;
}
if (elementType.arrayDepth > 0)
{
db.logError("Gathering Array Type %s is not yet supported", elementType.getOgnTypeName().c_str());
return false;
}
if (elementSize == 0)
{
db.logError("The element type %s has zero size", elementType.getOgnTypeName().c_str());
return false;
}
Type srcDataType = db.inputs.value().type();
bool srcIsScaler = srcDataType.arrayDepth == 0;
if (!srcIsScaler)
{
// A scaler value will be broadcast
--srcDataType.arrayDepth;
}
if (!srcDataType.compatibleRawData(elementType))
{
db.logWarning("Attribute %s is not compatible with type '%s'", elementType.getTypeName().c_str(),
srcDataType.getTypeName().c_str());
RETURN_TRUE_EXEC
}
// determine the length of the content
size_t totalPrimCount{ 0 };
size_t inputArraySize = value.size();
for (size_t i = 0; i < numBuckets; ++i)
{
BucketId bucketId = buckets[i];
size_t primCount = 0;
(void)db.abi_context().iContext->getBucketArray(db.abi_context(), bucketId, attributeName, primCount);
totalPrimCount += primCount;
}
PathBucketIndex const* repeatedPaths{ nullptr };
size_t numRepeatedPaths{ 0 };
if (!iGatherPrototype->getGatheredRepeatedPaths(db.abi_context(), gatherId, repeatedPaths, numRepeatedPaths))
{
db.logError("Could not get repeated paths list for Gather %zd", gatherId);
return false;
}
if (inputArraySize > 1 && totalPrimCount + numRepeatedPaths != inputArraySize)
{
db.logError(
"Given value of length %zd is not equal to the number of gathered attributes (%zd)", inputArraySize, totalPrimCount + numRepeatedPaths);
return false;
}
//printf("Setting %zd prims worth (%zd bytes) to %s\n", totalPrimCount, totalPrimCount * elementSize,
// attributeNameStr);
// Finally, we copy the data from the attribute to the buckets
const IAttributeData& iAttributeData = *db.abi_context().iAttributeData;
AttributeObj inputAttr =
nodeObj.iNode->getAttributeByToken(nodeObj, OgnSetGatheredAttributeAttributes::inputs::value.m_token);
ConstAttributeDataHandle inputHandle = inputAttr.iAttribute->getConstAttributeDataHandle(inputAttr);
ConstRawPtr srcPtr{ nullptr };
{
const void** out = nullptr;
void** outPtr = reinterpret_cast<void**>(&out);
iAttributeData.getDataR((const void**)outPtr, db.abi_context(), &inputHandle, 1);
if (srcIsScaler)
srcPtr = reinterpret_cast<ConstRawPtr>(out);
else
srcPtr = reinterpret_cast<ConstRawPtr>(*out);
}
if (!srcPtr)
{
// No data to read
RETURN_TRUE_EXEC
}
size_t maskIndex = 0;
for (size_t i = 0; i < numBuckets; ++i)
{
BucketId bucketId = buckets[i];
size_t primCount{ 0 };
uint8_t* destPtr = (uint8_t*)db.abi_context().iContext->getBucketArray(
db.abi_context(), bucketId, attributeName, primCount);
if (primCount == 0 || !destPtr)
{
db.logWarning("Bucket %zd has no entries for the given attribute", bucketId);
continue;
}
if (mask.empty())
{
size_t totalBytes = elementSize * primCount;
memcpy(destPtr, srcPtr, totalBytes);
if (!srcIsScaler)
srcPtr += totalBytes;
}
else
{
for (size_t j = 0; j < primCount; ++j)
{
if (mask[maskIndex++])
memcpy(destPtr, srcPtr, elementSize);
destPtr += elementSize;
if (!srcIsScaler)
srcPtr += elementSize;
}
}
}
// Set attribute for repeated paths
if (numRepeatedPaths > 0)
{
// If there are repeated paths, the set behaviour might be unexpected. Warn the user.
db.logWarning("Trying to set attribute when there are repeated prims in the gather. The first %zd values might be overwritten", totalPrimCount);
}
for (size_t i = 0; i < numRepeatedPaths; ++i)
{
PathBucketIndex pathBucketIndex = repeatedPaths[i];
BucketId bucketId = std::get<1>(pathBucketIndex);
ArrayIndex index = std::get<2>(pathBucketIndex);
size_t primCount{ 0 };
uint8_t* destPtr = (uint8_t*)db.abi_context().iContext->getBucketArray(
db.abi_context(), bucketId, attributeName, primCount);
if (primCount == 0 || !destPtr)
{
db.logWarning("Bucket %zd has no entries for the given attribute", bucketId);
continue;
}
if (index >= primCount)
{
db.logWarning("Bucket %zd has less entries than required", bucketId);
return false;
}
if (mask.empty() || mask[maskIndex++])
{
size_t byteCount = elementSize * index;
memcpy(destPtr + byteCount, srcPtr, elementSize);
if (!srcIsScaler)
srcPtr += elementSize;
}
}
RETURN_TRUE_EXEC
}
};
REGISTER_OGN_NODE()
}
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnArrayFindValue.cpp | // Copyright (c) 2022-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 <OgnArrayFindValueDatabase.h>
#include <omni/graph/core/ogn/ComputeHelpers.h>
#include <omni/graph/core/ogn/string.h>
#include <omni/graph/core/ogn/Types.h>
#include <algorithm>
namespace omni {
namespace graph {
namespace nodes {
// unnamed namespace to avoid multiple declaration when linking
namespace {
template<typename BaseType>
bool tryComputeAssumingType(OgnArrayFindValueDatabase& db)
{
auto const inputArray = db.inputs.array().template get<BaseType[]>();
size_t const inputArraySize = db.inputs.array().size();
auto const value = db.inputs.value().template get<BaseType>();
if (!value || !inputArray)
return false;
for (size_t i = 0; i < inputArraySize; ++i)
{
if (memcmp(&((*inputArray)[i]), &*value, sizeof(BaseType)) == 0)
{
db.outputs.index() = int(i);
return true;
}
}
db.outputs.index() = -1;
return true;
}
} // namespace
class OgnArrayFindValue
{
public:
static bool compute(OgnArrayFindValueDatabase& db)
{
auto& inputType = db.inputs.value().type();
try
{
switch (inputType.baseType)
{
case BaseDataType::eBool:
return tryComputeAssumingType<bool>(db);
case BaseDataType::eToken:
return tryComputeAssumingType<ogn::Token>(db);
case BaseDataType::eDouble:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<double>(db);
case 2: return tryComputeAssumingType<double[2]>(db);
case 3: return tryComputeAssumingType<double[3]>(db);
case 4: return tryComputeAssumingType<double[4]>(db);
case 9: return tryComputeAssumingType<double[9]>(db);
case 16: return tryComputeAssumingType<double[16]>(db);
default: break;
}
case BaseDataType::eFloat:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<float>(db);
case 2: return tryComputeAssumingType<float[2]>(db);
case 3: return tryComputeAssumingType<float[3]>(db);
case 4: return tryComputeAssumingType<float[4]>(db);
default: break;
}
case BaseDataType::eHalf:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<pxr::GfHalf>(db);
case 2: return tryComputeAssumingType<pxr::GfHalf[2]>(db);
case 3: return tryComputeAssumingType<pxr::GfHalf[3]>(db);
case 4: return tryComputeAssumingType<pxr::GfHalf[4]>(db);
default: break;
}
case BaseDataType::eInt:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<int32_t>(db);
case 2: return tryComputeAssumingType<int32_t[2]>(db);
case 3: return tryComputeAssumingType<int32_t[3]>(db);
case 4: return tryComputeAssumingType<int32_t[4]>(db);
default: break;
}
;
case BaseDataType::eInt64:
return tryComputeAssumingType<int64_t>(db);
case BaseDataType::eUChar:
return tryComputeAssumingType<unsigned char>(db);
case BaseDataType::eUInt:
return tryComputeAssumingType<uint32_t>(db);
case BaseDataType::eUInt64:
return tryComputeAssumingType<uint64_t>(db);
default: break;
}
db.logWarning("Failed to resolve input types");
}
catch (ogn::compute::InputError const &error)
{
db.logError(error.what());
}
return false;
}
static void onConnectionTypeResolve(const NodeObj& node){
auto const inputArray = node.iNode->getAttributeByToken(node, inputs::array.token());
auto const inputValue = node.iNode->getAttributeByToken(node, inputs::value.token());
auto const inputArrayType = inputArray.iAttribute->getResolvedType(inputArray);
if (inputArrayType.baseType != BaseDataType::eUnknown)
{
std::array<AttributeObj, 2> attrs { inputArray, inputValue };
// all should have the same tuple count
std::array<uint8_t, 2> tupleCounts {
inputArrayType.componentCount,
inputArrayType.componentCount
};
// value type can not be an array because we don't support arrays-of-arrays
std::array<uint8_t, 2> arrayDepths {
1,
0,
};
std::array<AttributeRole, 2> rolesBuf {
inputArrayType.role,
AttributeRole::eUnknown
};
node.iNode->resolvePartiallyCoupledAttributes(node, attrs.data(), tupleCounts.data(),
arrayDepths.data(), rolesBuf.data(), attrs.size());
}
}
};
REGISTER_OGN_NODE()
} // namespace nodes
} // namespace graph
} // namespace omni |
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnGetParentPath.ogn | {
"GetParentPath": {
"version": 1,
"description": ["Generates a parent path token from another path token. (ex. /World/Cube -> /World)"],
"uiName": "Get Parent Path",
"categories": ["sceneGraph"],
"scheduling": [ "threadsafe" ],
"inputs": {
"path": {
"type": ["token", "token[]"],
"description": "One or more path tokens to compute a parent path from. (ex. /World/Cube)"
}
},
"outputs": {
"parentPath": {
"type": ["token", "token[]"],
"description": "Parent path token (ex. /World)"
}
},
"state": {
"path": {
"type": "token",
"description": "Snapshot of previously seen path"
}
},
"tests": [
{
"inputs:path": {
"type": "token",
"value": "/"
},
"outputs:parentPath": {
"type": "token",
"value": ""
}
},
{
"inputs:path": {
"type": "token",
"value": "/World"
},
"outputs:parentPath": {
"type": "token",
"value": "/"
}
},
{
"inputs:path": {
"type": "token",
"value": "/World/foo"
},
"outputs:parentPath": {
"type": "token",
"value": "/World"
}
},
{
"inputs:path": {
"type": "token",
"value": "/World/foo/bar"
},
"outputs:parentPath": {
"type": "token",
"value": "/World/foo"
}
},
{
"inputs:path": {
"type": "token",
"value": "/World/foo/bar.attrib"
},
"outputs:parentPath": {
"type": "token",
"value": "/World/foo/bar"
}
},
{
"inputs:path": {
"type": "token[]",
"value": [ "/World1/foo", "/World2/bar" ]
},
"outputs:parentPath": {
"type": "token[]",
"value": [ "/World1", "/World2" ]
}
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnBundleInspector.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 <OgnBundleInspectorDatabase.h>
#include <omni/graph/core/ogn/UsdTypes.h>
#include <fstream>
#include <iomanip>
namespace omni
{
namespace graph
{
namespace nodes
{
template <typename CppType>
std::string valueToString(const CppType& value)
{
return std::to_string(value);
}
template <>
std::string valueToString(const pxr::GfHalf& value)
{
return std::to_string((float) value);
}
template <>
std::string valueToString(const bool& value)
{
return value ? "True" : "False";
}
// TODO: This string conversion code is better suited to the BundledAttribute where it is accessible to all
// Since there are only three matrix dimensions a lookup is faster than a sqrt() call.
const int matrixDimensionMap[17]{ 1, 1, 1, 1, 2, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 4 };
// Helper template to output a convertible simple value as a string. Used when std::to_string works on the type.
template <typename CppType>
bool simpleValueToString(const ogn::RuntimeAttribute<core::ogn::kOgnInput, core::ogn::kCpu>& runtimeInput, std::string& valueToSet)
{
if (const auto value = runtimeInput.get<CppType>() )
{
valueToSet = valueToString(*value);
return true;
}
return false;
}
// Helper template to output a convertible simple tuple value as a string.
// The output format is parenthesized "(X, Y, Z)"
template <typename CppType>
bool tupleValueToString(const ogn::RuntimeAttribute<core::ogn::kOgnInput, core::ogn::kCpu>& runtimeInput, std::string& valueToSet)
{
if (const auto value = runtimeInput.get<CppType>() )
{
auto inputType = runtimeInput.type();
valueToSet = "(";
if (inputType.isMatrixType())
{
uint8_t dimension = inputType.dimension();
uint8_t index{ 0 };
for (uint8_t row=0; row<dimension; ++row)
{
if (row > 0)
{
valueToSet += ", ";
}
valueToSet += "(";
for (int col=0; col<dimension; ++col)
{
if (col > 0)
{
valueToSet += ", ";
}
valueToSet += valueToString(value[index++]);
}
valueToSet += ")";
}
}
else
{
for (uint8_t tupleIndex=0; tupleIndex<value.tupleSize(); ++tupleIndex )
{
if (tupleIndex > 0)
{
valueToSet += ", ";
}
valueToSet += valueToString(value[tupleIndex]);
}
}
valueToSet += ")";
return true;
}
return false;
}
// Helper template to output a convertible simple array value as a string.
// The output format has square brackets "[X, Y, Z]"
template <typename CppType>
bool arrayValueToString(const ogn::RuntimeAttribute<core::ogn::kOgnInput, core::ogn::kCpu>& runtimeInput, std::string& valueToSet)
{
if (const auto arrayValue = runtimeInput.get<CppType>() )
{
auto role = runtimeInput.type().role;
auto baseType = runtimeInput.type().baseType;
const bool isString = (baseType == BaseDataType::eUChar) && ((role == AttributeRole::eText) || (role == AttributeRole::ePath));
if (isString)
{
std::string rawString(reinterpret_cast<const char*>(arrayValue->data()), arrayValue->size());
valueToSet = "'";
valueToSet += rawString;
valueToSet += "'";
}
else
{
valueToSet = "[";
size_t index{ 0 };
for (const auto& value : *arrayValue)
{
if (index++ > 0)
{
valueToSet += ", ";
}
valueToSet += valueToString(value);
}
valueToSet += "]";
}
return true;
}
return false;
}
// Helper template to output a convertible tuple array value as a string.
// The output format has square brackets "[(X1, Y1), (X2, Y2), (X3, Y3))]"
template <typename CppType>
bool tupleArrayValueToString(const ogn::RuntimeAttribute<core::ogn::kOgnInput, core::ogn::kCpu>& runtimeInput, std::string& valueToSet)
{
if (const auto tupleArrayValue = runtimeInput.get<CppType>() )
{
auto inputType = runtimeInput.type();
const bool isMatrix = inputType.isMatrixType();
auto tupleSize = inputType.dimension();
valueToSet = "[";
size_t index{ 0 };
for (const auto& value : *tupleArrayValue)
{
if (index++ > 0)
{
valueToSet += ", ";
}
valueToSet += "(";
if (isMatrix)
{
int tupleIndex{ 0 };
for (int row=0; row<tupleSize; ++row)
{
if (row > 0)
{
valueToSet += ", ";
}
valueToSet += "(";
for (int col=0; col<tupleSize; ++col)
{
if (col > 0)
{
valueToSet += ", ";
}
valueToSet += valueToString(value[tupleIndex++]);
}
valueToSet += ")";
}
}
else
{
for (int tupleIndex=0; tupleIndex<tupleSize; ++tupleIndex )
{
if (tupleIndex > 0)
{
valueToSet += ", ";
}
valueToSet += valueToString(value[tupleIndex]);
}
}
valueToSet += ")";
}
valueToSet += "]";
return true;
}
return false;
}
// Node whose responsibility is to analyze the contents of an input bundle attribute
// and create outputs describing them.
class OgnBundleInspector
{
private:
static void inspectRecursive
(
const int currentDepth,
const int inspectDepth,
const bool printContents,
OgnBundleInspectorDatabase& db,
const ogn::BundleContents<ogn::kOgnInput, ogn::kCpu> &inputBundle,
std::ostream &output,
ogn::array<NameToken> &names,
ogn::array<NameToken> &types,
ogn::array<NameToken> &roles,
ogn::array<int> &arrayDepths,
ogn::array<int> &tupleCounts,
ogn::array<NameToken> &values
)
{
IToken const* iToken = carb::getCachedInterface<omni::fabric::IToken>();
auto bundleName = inputBundle.abi_bundleInterface()->getName();
std::string indent{" "};
auto attributeCount = inputBundle.attributeCount();
auto childCount = inputBundle.childCount();
output << "Bundle '" << iToken->getText(bundleName) << "' from " << db.abi_node().iNode->getPrimPath(db.abi_node())
<< " (attributes = " << attributeCount << " children = " << childCount << ")" << std::endl;
// Walk the contents of the input bundle, extracting the attribute information along the way
size_t index = 0;
for (const auto& bundledAttribute : inputBundle)
{
if (bundledAttribute.isValid())
{
// The attribute names and etc apply only to top level bundle passed to the BundleInspector
if (currentDepth == 0) names[index] = bundledAttribute.name();
for (int numIndent = 0; numIndent < currentDepth; numIndent++) output << indent;
output << indent << "[" << index << "] " << db.tokenToString(bundledAttribute.name());
const Type& attributeType = bundledAttribute.type();
output << "(" << attributeType << ")";
if (currentDepth == 0)
{
{
std::ostringstream nameStream;
nameStream << attributeType.baseType;
types[index] = db.stringToToken(nameStream.str().c_str());
}
{
std::ostringstream nameStream;
nameStream << getOgnRoleName(attributeType.role);
roles[index] = db.stringToToken(nameStream.str().c_str());
}
arrayDepths[index] = attributeType.arrayDepth;
tupleCounts[index] = attributeType.componentCount;
}
// Convert the value into a string, using an empty string for unknown types
std::string valueAsString{"__unsupported__"};
bool noOutput = !simpleValueToString<bool>(bundledAttribute, valueAsString)
&& !arrayValueToString<bool[]>(bundledAttribute, valueAsString)
&& !simpleValueToString<int64_t>(bundledAttribute, valueAsString)
&& !arrayValueToString<int64_t[]>(bundledAttribute, valueAsString)
&& !simpleValueToString<uint8_t>(bundledAttribute, valueAsString)
&& !arrayValueToString<uint8_t[]>(bundledAttribute, valueAsString)
&& !simpleValueToString<uint32_t>(bundledAttribute, valueAsString)
&& !arrayValueToString<uint32_t[]>(bundledAttribute, valueAsString)
&& !simpleValueToString<uint64_t>(bundledAttribute, valueAsString)
&& !arrayValueToString<uint64_t[]>(bundledAttribute, valueAsString)
&& !simpleValueToString<double>(bundledAttribute, valueAsString)
&& !arrayValueToString<double[]>(bundledAttribute, valueAsString)
&& !tupleValueToString<double[2]>(bundledAttribute, valueAsString)
&& !tupleArrayValueToString<double[][2]>(bundledAttribute, valueAsString)
&& !tupleValueToString<double[3]>(bundledAttribute, valueAsString)
&& !tupleArrayValueToString<double[][3]>(bundledAttribute, valueAsString)
&& !tupleValueToString<double[4]>(bundledAttribute, valueAsString)
&& !tupleArrayValueToString<double[][4]>(bundledAttribute, valueAsString)
&& !tupleValueToString<double[9]>(bundledAttribute, valueAsString)
&& !tupleArrayValueToString<double[][9]>(bundledAttribute, valueAsString)
&& !tupleValueToString<double[16]>(bundledAttribute, valueAsString)
&& !tupleArrayValueToString<double[][16]>(bundledAttribute, valueAsString)
&& !simpleValueToString<float>(bundledAttribute, valueAsString)
&& !arrayValueToString<float[]>(bundledAttribute, valueAsString)
&& !tupleValueToString<float[2]>(bundledAttribute, valueAsString)
&& !tupleArrayValueToString<float[][2]>(bundledAttribute, valueAsString)
&& !tupleValueToString<float[3]>(bundledAttribute, valueAsString)
&& !tupleArrayValueToString<float[][3]>(bundledAttribute, valueAsString)
&& !tupleValueToString<float[4]>(bundledAttribute, valueAsString)
&& !tupleArrayValueToString<float[][4]>(bundledAttribute, valueAsString)
&& !simpleValueToString<int>(bundledAttribute, valueAsString)
&& !arrayValueToString<int[]>(bundledAttribute, valueAsString)
&& !tupleValueToString<int[2]>(bundledAttribute, valueAsString)
&& !tupleArrayValueToString<int[][2]>(bundledAttribute, valueAsString)
&& !tupleValueToString<int[3]>(bundledAttribute, valueAsString)
&& !tupleArrayValueToString<int[][3]>(bundledAttribute, valueAsString)
&& !tupleValueToString<int[4]>(bundledAttribute, valueAsString)
&& !tupleArrayValueToString<int[][4]>(bundledAttribute, valueAsString)
&& !simpleValueToString<pxr::GfHalf>(bundledAttribute, valueAsString)
&& !arrayValueToString<pxr::GfHalf[]>(bundledAttribute, valueAsString)
&& !tupleValueToString<pxr::GfHalf[2]>(bundledAttribute, valueAsString)
&& !tupleArrayValueToString<pxr::GfHalf[][2]>(bundledAttribute, valueAsString)
&& !tupleValueToString<pxr::GfHalf[3]>(bundledAttribute, valueAsString)
&& !tupleArrayValueToString<pxr::GfHalf[][3]>(bundledAttribute, valueAsString)
&& !tupleValueToString<pxr::GfHalf[4]>(bundledAttribute, valueAsString)
&& !tupleArrayValueToString<pxr::GfHalf[][4]>(bundledAttribute, valueAsString)
;
if (noOutput)
{
if (const auto tokenValue = bundledAttribute.get<OgnToken>() )
{
std::ostringstream tokenValueStream;
tokenValueStream << std::quoted(db.tokenToString(*tokenValue));
valueAsString = tokenValueStream.str();
noOutput = false;
}
}
if (noOutput)
{
if (const auto tokenArrayValue = bundledAttribute.get<OgnToken[]>() )
{
std::ostringstream tokenArrayValueStream;
tokenArrayValueStream << "[";
size_t index{ 0 };
for (const auto& value : *tokenArrayValue)
{
if (index++ > 0)
{
tokenArrayValueStream << ", ";
}
tokenArrayValueStream << std::quoted(db.tokenToString(value));
}
tokenArrayValueStream << "]";
valueAsString = tokenArrayValueStream.str();
noOutput = false;
}
}
output << " = " << valueAsString << std::endl;
if (currentDepth == 0) values[index] = db.stringToToken(valueAsString.c_str());
if (noOutput)
{
std::ostringstream nameStream;
nameStream << attributeType;
db.logWarning("No value output known for attribute %zu (%s), defaulting to '__unsupported__'", index, nameStream.str().c_str());
}
index++;
}
else
{
output << indent << "Bundle is invalid" << std::endl;
db.logWarning("Ignoring invalid bundle member '%s'", db.tokenToString(bundledAttribute.name()));
}
}
// Walk through its children, if any
if (printContents && childCount && ((currentDepth < inspectDepth) || (inspectDepth <= -1)))
{
IConstBundle2* inputBundleIFace = inputBundle.abi_bundleInterface();
// context is for building the child BundleContents
const auto context = inputBundleIFace->getContext();
std::vector<ConstBundleHandle> childBundleHandles(childCount);
inputBundleIFace->getConstChildBundles(childBundleHandles.data(), childCount);
for (const auto& childHandle : childBundleHandles)
{
if (childHandle.isValid())
{
ogn::BundleContents<ogn::kOgnInput, ogn::kCpu> childBundle(context, childHandle);
for (int numIndent = 0; numIndent < currentDepth + 1; numIndent++) output << indent;
output << "Has Child "; // No std::endl -> "Has Child Bundle from ..."
inspectRecursive(currentDepth+1, inspectDepth, printContents, db, childBundle, output, names, types, roles, arrayDepths, tupleCounts, values);
}
else
{
for (int numIndent = 0; numIndent < currentDepth; numIndent++) output << indent;
output << "One child is invalid." << std::endl;
}
}
}
}
public:
static bool compute(OgnBundleInspectorDatabase& db)
{
const auto& inputBundle = db.inputs.bundle();
auto attributeCount = inputBundle.attributeCount();
auto childCount = inputBundle.childCount();
db.outputs.bundle() = inputBundle;
const auto& printContents = db.inputs.print();
const auto& inspectDepth = db.inputs.inspectDepth();
// Rather than pollute the file with a bunch of "if (printContents)" setting up a file stream with a
// bad bit causes the output to be thrown away without parsing.
std::ofstream ofs;
ofs.setstate(std::ios_base::badbit);
auto& output = printContents ? std::cout : ofs;
db.outputs.count() = attributeCount;
db.outputs.attributeCount() = attributeCount;
db.outputs.childCount() = childCount;
// Extract the output interfaces to nicer names
auto& names = db.outputs.names();
auto& types = db.outputs.types();
auto& roles = db.outputs.roles();
auto& arrayDepths = db.outputs.arrayDepths();
auto& tupleCounts = db.outputs.tupleCounts();
auto& values = db.outputs.values();
// All outputs except the count are arrays of that size - preallocate them here
names.resize(attributeCount);
types.resize(attributeCount);
roles.resize(attributeCount);
arrayDepths.resize(attributeCount);
tupleCounts.resize(attributeCount);
values.resize(attributeCount);
inspectRecursive(0, inspectDepth, printContents, db, inputBundle, output, names, types, roles, arrayDepths, tupleCounts, values);
return true;
}
};
REGISTER_OGN_NODE();
}
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnArrayInsertValue.cpp |
// Copyright (c) 2022-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 <OgnArrayInsertValueDatabase.h>
#include <omni/graph/core/ogn/ComputeHelpers.h>
#include <omni/graph/core/ogn/string.h>
#include <omni/graph/core/ogn/Types.h>
#include <algorithm>
namespace omni {
namespace graph {
namespace nodes {
// unnamed namespace to avoid multiple declaration when linking
namespace {
// helper to clamp a given index to [0:arrayLength]
size_t tryWrapIndex(int index, size_t arraySize)
{
if (index < 0)
index = 0;
if (index > static_cast<int>(arraySize))
index = static_cast<int>(arraySize);
return static_cast<size_t>(index);
}
template<typename BaseType>
bool tryComputeAssumingType(OgnArrayInsertValueDatabase& db)
{
auto const inputArray = db.inputs.array().template get<BaseType[]>();
size_t const inputArraySize = db.inputs.array().size();
size_t const index = tryWrapIndex(db.inputs.index(), inputArraySize);
auto const value = db.inputs.value().template get<BaseType>();
auto outputArray = db.outputs.array().template get<BaseType[]>();
if (!value || !inputArray)
return false;
(*outputArray).resize(inputArraySize+1);
memcpy(outputArray->data(), inputArray->data(), sizeof(BaseType) * index);
memcpy(&((*outputArray)[index]), &*value, sizeof(BaseType));
memcpy(outputArray->data() + index + 1, inputArray->data() + index, sizeof(BaseType) * (inputArraySize - index));
return true;
}
} // namespace
class OgnArrayInsertValue
{
public:
static bool compute(OgnArrayInsertValueDatabase& db)
{
auto& inputType = db.inputs.value().type();
try
{
switch (inputType.baseType)
{
case BaseDataType::eBool:
return tryComputeAssumingType<bool>(db);
case BaseDataType::eToken:
return tryComputeAssumingType<ogn::Token>(db);
case BaseDataType::eDouble:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<double>(db);
case 2: return tryComputeAssumingType<double[2]>(db);
case 3: return tryComputeAssumingType<double[3]>(db);
case 4: return tryComputeAssumingType<double[4]>(db);
case 9: return tryComputeAssumingType<double[9]>(db);
case 16: return tryComputeAssumingType<double[16]>(db);
default: break;
}
case BaseDataType::eFloat:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<float>(db);
case 2: return tryComputeAssumingType<float[2]>(db);
case 3: return tryComputeAssumingType<float[3]>(db);
case 4: return tryComputeAssumingType<float[4]>(db);
default: break;
}
case BaseDataType::eHalf:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<pxr::GfHalf>(db);
case 2: return tryComputeAssumingType<pxr::GfHalf[2]>(db);
case 3: return tryComputeAssumingType<pxr::GfHalf[3]>(db);
case 4: return tryComputeAssumingType<pxr::GfHalf[4]>(db);
default: break;
}
case BaseDataType::eInt:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<int32_t>(db);
case 2: return tryComputeAssumingType<int32_t[2]>(db);
case 3: return tryComputeAssumingType<int32_t[3]>(db);
case 4: return tryComputeAssumingType<int32_t[4]>(db);
default: break;
}
;
case BaseDataType::eInt64:
return tryComputeAssumingType<int64_t>(db);
case BaseDataType::eUChar:
return tryComputeAssumingType<unsigned char>(db);
case BaseDataType::eUInt:
return tryComputeAssumingType<uint32_t>(db);
case BaseDataType::eUInt64:
return tryComputeAssumingType<uint64_t>(db);
default: break;
}
db.logWarning("Failed to resolve input types");
}
catch (ogn::compute::InputError const &error)
{
db.logError(error.what());
}
return false;
}
static void onConnectionTypeResolve(const NodeObj& node){
auto const inputArray = node.iNode->getAttributeByToken(node, inputs::array.token());
auto const inputValue = node.iNode->getAttributeByToken(node, inputs::value.token());
auto const outputArray = node.iNode->getAttributeByToken(node, outputs::array.token());
auto const inputArrayType = inputArray.iAttribute->getResolvedType(inputArray);
if (inputArrayType.baseType != BaseDataType::eUnknown)
{
std::array<AttributeObj, 3> attrs { inputArray, inputValue, outputArray };
// all should have the same tuple count
std::array<uint8_t, 3> tupleCounts {
inputArrayType.componentCount,
inputArrayType.componentCount,
inputArrayType.componentCount
};
// value type can not be an array because we don't support arrays-of-arrays
std::array<uint8_t, 3> arrayDepths {
1,
0,
1
};
std::array<AttributeRole, 3> rolesBuf {
inputArrayType.role,
AttributeRole::eUnknown,
AttributeRole::eUnknown
};
node.iNode->resolvePartiallyCoupledAttributes(node, attrs.data(), tupleCounts.data(),
arrayDepths.data(), rolesBuf.data(), attrs.size());
}
}
};
REGISTER_OGN_NODE()
} // namespace nodes
} // namespace graph
} // namespace omni |
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnMakeVector2.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 <OgnMakeVector2Database.h>
#include <omni/graph/core/ogn/ComputeHelpers.h>
#include <omni/graph/core/ogn/UsdTypes.h>
#include <fstream>
#include <iomanip>
namespace omni
{
namespace graph
{
namespace nodes
{
namespace
{
template <typename Type>
bool tryMakeVector(OgnMakeVector2Database& db)
{
const auto x = db.inputs.x().template get<Type>();
const auto y = db.inputs.y().template get<Type>();
auto vector = db.outputs.tuple().template get<Type[2]>();
if (vector && x && y){
(*vector)[0] = *x;
(*vector)[1] = *y;
return true;
}
const auto xArray = db.inputs.x().template get<Type[]>();
const auto yArray = db.inputs.y().template get<Type[]>();
auto vectorArray = db.outputs.tuple().template get<Type[][2]>();
if (!vectorArray || !xArray || !yArray){
return false;
}
if (xArray->size() != yArray->size())
{
throw ogn::compute::InputError("Input arrays of different lengths x:" +
std::to_string(xArray->size()) + ", y:" + std::to_string(yArray->size()));
}
vectorArray->resize(xArray->size());
for (size_t i = 0; i < vectorArray->size(); i++)
{
(*vectorArray)[i][0] = (*xArray)[i];
(*vectorArray)[i][1] = (*yArray)[i];
}
return true;
}
} // namespace
// Node to merge 2 scalers together to make 2-vector
class OgnMakeVector2
{
public:
static bool compute(OgnMakeVector2Database& db)
{
// Compute the components, if the types are all resolved.
try
{
if (tryMakeVector<double>(db))
return true;
else if (tryMakeVector<float>(db))
return true;
else if (tryMakeVector<pxr::GfHalf>(db))
return true;
else if (tryMakeVector<int32_t>(db))
return true;
else
{
db.logError("Failed to resolve input types");
return false;
}
}
catch (const std::exception& e)
{
db.logError("Vector could not be made: %s", e.what());
return false;
}
return true;
}
static void onConnectionTypeResolve(const NodeObj& nodeObj)
{
auto x = nodeObj.iNode->getAttributeByToken(nodeObj, inputs::x.token());
auto y = nodeObj.iNode->getAttributeByToken(nodeObj, inputs::y.token());
auto vector = nodeObj.iNode->getAttributeByToken(nodeObj, outputs::tuple.token());
auto xType = vector.iAttribute->getResolvedType(x);
auto yType = vector.iAttribute->getResolvedType(y);
// If one of the inputs is resolved we can resolve the other because they should match
std::array<AttributeObj, 2> attrs { x, y };
if (nodeObj.iNode->resolveCoupledAttributes(nodeObj, attrs.data(), attrs.size()))
{
xType = vector.iAttribute->getResolvedType(x);
yType = vector.iAttribute->getResolvedType(y);
}
// Require inputs to be resolved before determining outputs' type
if (xType.baseType != BaseDataType::eUnknown && yType.baseType != BaseDataType::eUnknown)
{
std::array<AttributeObj, 3> attrs{ x, y, vector };
std::array<uint8_t, 3> tuples{ 1, 1, 2 };
std::array<uint8_t, 3> arrays{
xType.arrayDepth,
yType.arrayDepth,
xType.arrayDepth,
};
std::array<AttributeRole, 3> roles{ xType.role, yType.role, AttributeRole::eNone };
nodeObj.iNode->resolvePartiallyCoupledAttributes(nodeObj, attrs.data(), tuples.data(), arrays.data(), roles.data(), attrs.size());
}
}
};
REGISTER_OGN_NODE();
}
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnArrayIndex.cpp | // Copyright (c) 2022-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 <OgnArrayIndexDatabase.h>
#include <omni/graph/core/StringUtils.h>
#include <omni/graph/core/ogn/ComputeHelpers.h>
#include <carb/logging/Log.h>
namespace omni {
namespace graph {
namespace nodes {
using core::ogn::array;
// unnamed namespace to avoid multiple declaration when linking
namespace {
// helper to wrap a given index from legal range [-arrayLength, arrayLength) to [0:arrayLength).
// values outside of the legal range with throw
size_t tryWrapIndex(int index, size_t arraySize)
{
int wrappedIndex = index;
if (index < 0)
wrappedIndex = (int)arraySize + index;
if ((wrappedIndex >= (int)arraySize) or (wrappedIndex < 0))
throw ogn::compute::InputError(formatString("inputs:index %d is out of range for inputs:array of size %zu", wrappedIndex, arraySize));
return size_t(wrappedIndex);
}
template<typename BaseType>
bool tryComputeAssumingType(OgnArrayIndexDatabase& db)
{
auto const inputArray = db.inputs.array().template get<BaseType[]>();
size_t const index = tryWrapIndex(db.inputs.index(), db.inputs.array().size());
auto outputValue = db.outputs.value().template get<BaseType>();
if (!outputValue || !inputArray)
return false;
memcpy(&*outputValue, &((*inputArray)[index]), sizeof(BaseType));
return true;
}
} // namespace
class OgnArrayIndex
{
public:
static bool compute(OgnArrayIndexDatabase& db)
{
auto& inputType = db.inputs.array().type();
try
{
switch (inputType.baseType)
{
case BaseDataType::eBool:
return tryComputeAssumingType<bool>(db);
case BaseDataType::eToken:
return tryComputeAssumingType<ogn::Token>(db);
case BaseDataType::eDouble:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<double>(db);
case 2: return tryComputeAssumingType<double[2]>(db);
case 3: return tryComputeAssumingType<double[3]>(db);
case 4: return tryComputeAssumingType<double[4]>(db);
case 9: return tryComputeAssumingType<double[9]>(db);
case 16: return tryComputeAssumingType<double[16]>(db);
default: break;
}
case BaseDataType::eFloat:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<float>(db);
case 2: return tryComputeAssumingType<float[2]>(db);
case 3: return tryComputeAssumingType<float[3]>(db);
case 4: return tryComputeAssumingType<float[4]>(db);
default: break;
}
case BaseDataType::eHalf:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<pxr::GfHalf>(db);
case 2: return tryComputeAssumingType<pxr::GfHalf[2]>(db);
case 3: return tryComputeAssumingType<pxr::GfHalf[3]>(db);
case 4: return tryComputeAssumingType<pxr::GfHalf[4]>(db);
default: break;
}
case BaseDataType::eInt:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<int32_t>(db);
case 2: return tryComputeAssumingType<int32_t[2]>(db);
case 3: return tryComputeAssumingType<int32_t[3]>(db);
case 4: return tryComputeAssumingType<int32_t[4]>(db);
default: break;
}
;
case BaseDataType::eInt64:
return tryComputeAssumingType<int64_t>(db);
case BaseDataType::eUChar:
return tryComputeAssumingType<unsigned char>(db);
case BaseDataType::eUInt:
return tryComputeAssumingType<uint32_t>(db);
case BaseDataType::eUInt64:
return tryComputeAssumingType<uint64_t>(db);
default: break;
}
db.logWarning("Failed to resolve input types");
}
catch (ogn::compute::InputError const &error)
{
db.logError(error.what());
}
return false;
}
static void onConnectionTypeResolve(const NodeObj& node){
auto const array = node.iNode->getAttributeByToken(node, inputs::array.token());
auto const value = node.iNode->getAttributeByToken(node, outputs::value.token());
auto const arrayType = array.iAttribute->getResolvedType(array);
auto const valueType = value.iAttribute->getResolvedType(value);
if ((arrayType.baseType == BaseDataType::eUnknown) != (valueType.baseType == BaseDataType::eUnknown))
{
std::array<AttributeObj, 2> attrs { array, value };
// array and value should have the same tuple count
std::array<uint8_t, 2> tupleCounts {
std::max(arrayType.componentCount, valueType.componentCount),
std::max(arrayType.componentCount, valueType.componentCount)
};
// value type can not be an array because we don't support arrays-of-arrays
std::array<uint8_t, 2> arrayDepths {
1,
0
};
std::array<AttributeRole, 2> rolesBuf {
arrayType.role,
// Copy the attribute role from the array type to the value type
AttributeRole::eUnknown
};
node.iNode->resolvePartiallyCoupledAttributes(node, attrs.data(), tupleCounts.data(),
arrayDepths.data(), rolesBuf.data(), attrs.size());
}
}
};
REGISTER_OGN_NODE()
} // namespace nodes
} // namespace graph
} // namespace omni
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnGetPrimPath.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 <OgnGetPrimPathDatabase.h>
namespace omni
{
namespace graph
{
namespace nodes
{
class OgnGetPrimPath
{
public:
static size_t computeVectorized(OgnGetPrimPathDatabase& db, size_t count)
{
auto pathInterface = carb::getCachedInterface<omni::fabric::IPath>();
auto tokenInterface = carb::getCachedInterface<omni::fabric::IToken>();
if (!pathInterface || !tokenInterface)
{
CARB_LOG_ERROR("Failed to initialize path or token interface");
return 0;
}
auto primPaths = db.outputs.primPath.vectorized(count);
for (size_t i = 0; i < count; i++)
{
const auto& prims = db.inputs.prim(i);
if (prims.size() > 0)
{
auto text = pathInterface->getText(prims[0]);
db.outputs.path(i) = text;
primPaths[i] = tokenInterface->getHandle(text);
}
else
{
db.outputs.path(i) = "";
primPaths[i] = Token();
}
}
return count;
}
};
REGISTER_OGN_NODE();
} // nodes
} // graph
} // omni
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnFindPrims.ogn | {
"FindPrims": {
"version": 2,
"description": ["Finds Prims on the stage which match the given criteria"],
"uiName": "Find Prims",
"categories": ["sceneGraph"],
"scheduling": ["usd-read", "threadsafe"],
"inputs": {
"type": {
"uiName": "Prim Type Pattern",
"type": "token",
"default": "*",
"description": [
"A list of wildcard patterns used to match the prim types that are to be imported",
"",
"Supported syntax of wildcard pattern:",
" '*' - match an arbitrary number of any characters",
" '?' - match any single character",
" '^' - (caret) is used to define a pattern that is to be excluded",
"",
"Example of wildcard patterns, input: ['Mesh', 'Cone', 'Cube']",
" '*' - match any",
" '* ^Mesh' - match any, but exclude 'Mesh'",
" '* ^Cone ^Cube' - match any, but exclude 'Cone' and 'Cube'"
]
},
"pathPattern": {
"uiName": "Prim Path Pattern",
"type": "token",
"description": [
"A list of wildcard patterns used to match the prim paths",
"",
"Supported syntax of wildcard pattern:",
" '*' - match an arbitrary number of any characters",
" '?' - match any single character",
" '^' - (caret) is used to define a pattern that is to be excluded",
"",
"Example of wildcard patterns, input: ['/Cube0', '/Cube1', '/Box']",
" '*' - match any",
" '* ^/Box' - match any, but exclude '/Box'",
" '* ^/Cube*' - match any, but exclude '/Cube0' and '/Cube1'"
]
},
"rootPrimPath": {
"uiName": "Root Prim Path",
"type": "token",
"description": "Only children of the given prim will be considered. Empty will search the whole stage.",
"deprecated": "Use rootPrim input attribute instead"
},
"rootPrim": {
"uiName": "Root Prim",
"type": "target",
"description": "Only children of the given prim will be considered. If rootPrim is specified, rootPrimPath will be ignored."
},
"namePrefix": {
"uiName": "Prim Name Prefix",
"type": "token",
"description": "Only prims with a name starting with the given prefix will be returned."
},
"requiredAttributes": {
"uiName": "Attribute Names",
"type": "string",
"description": "A space-separated list of attribute names that are required to be present on matched prims"
},
"requiredRelationship": {
"uiName": "Relationship Name",
"type": "token",
"description": "The name of a relationship which must have a target specified by requiredRelationshipTarget or requiredTarget"
},
"requiredRelationshipTarget": {
"uiName": "Relationship Prim Path",
"type": "path",
"description": "The path that must be a target of the requiredRelationship",
"deprecated": "Use requiredTarget instead"
},
"requiredTarget": {
"uiName": "Relationship Prim",
"type": "target",
"description": "The target of the requiredRelationship"
},
"recursive": {
"type": "bool",
"description": "False means only consider children of the root prim, True means all prims in the hierarchy"
},
"ignoreSystemPrims": {
"type": "bool",
"description": "Ignore system prims such as omni graph nodes that shouldn't be considered during the import.",
"default": false
}
},
"outputs": {
"prims": {
"type": "target",
"description": "A list of Prim paths which match the given type"
},
"primPaths": {
"type": "token[]",
"description": "A list of Prim paths as tokens which match the given type"
}
},
"state": {
"inputType": { "type": "token" , "description": "last corresponding input seen"},
"rootPrimPath": { "type": "token" , "description": "last corresponding input seen"},
"rootPrim": { "type": "target", "description": "last corresponding input seen"},
"namePrefix": { "type": "token" , "description": "last corresponding input seen"},
"requiredRelationship": { "type": "token" , "description": "last corresponding input seen"},
"pathPattern": { "type": "token" , "description": "last corresponding input seen"},
"requiredAttributes": { "type": "string" , "description": "last corresponding input seen"},
"requiredRelationshipTarget": { "type": "string" , "description": "last corresponding input seen"},
"requiredTarget": { "type": "target", "description": "last corresponding input seen"},
"recursive": { "type": "bool" , "description": "last corresponding input seen"},
"ignoreSystemPrims": { "type": "bool", "description": "last corresponding input seen" }
},
"tests": [
{
"setup": {
"create_nodes": [
["TestNode", "omni.graph.nodes.FindPrims"]
],
"create_prims": [
["Empty", {}],
["Xform1", {"_translate": ["pointd[3][]", [[1, 2, 3]]]}],
["Xform2", {"_translate": ["pointd[3][]", [[4, 5, 6]]]}],
["XformTagged1", {"foo": ["token", ""], "_translate": ["pointd[3][]", [[1, 2, 3]]]}],
["Tagged1", {"foo": ["token", ""]}]
]
},
"inputs": {
"namePrefix": "Xform"
},
"outputs": {
"primPaths": ["/Xform1", "/Xform2", "/XformTagged1"]
}
},
{
"setup": {},
"inputs": {
"namePrefix": "",
"requiredAttributes": "foo _translate"
},
"outputs": {
"primPaths": ["/XformTagged1"]
}
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnGetRelativePath.cpp | // Copyright (c) 2020-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 <OgnGetRelativePathDatabase.h>
#include <omni/fabric/FabricUSD.h>
using omni::fabric::asInt;
using omni::fabric::toTfToken;
static NameToken const& getRelativePath(const NameToken& pathAsToken, const pxr::SdfPath& anchor)
{
auto pathToken = toTfToken(pathAsToken);
if (pathAsToken != omni::fabric::kUninitializedToken && pxr::SdfPath::IsValidPathString(pathToken))
{
auto relPath = pxr::SdfPath(pathToken).MakeRelativePath(anchor);
return *asInt(&relPath.GetToken());
}
return pathAsToken;
}
namespace omni
{
namespace graph
{
namespace nodes
{
class OgnGetRelativePath
{
public:
static size_t computeVectorized(OgnGetRelativePathDatabase& db, size_t count)
{
auto anchor = db.inputs.anchor.vectorized(count);
if (db.inputs.path().type().arrayDepth > 0)
{
for (size_t idx = 0; idx < count; ++idx)
{
if (anchor[idx] == omni::fabric::kUninitializedToken)
{
db.outputs.relativePath(idx).copyData(db.inputs.path(idx));
}
else
{
const auto anchorPath = pxr::SdfPath(toTfToken(anchor[idx]));
const auto inputPathArray = *db.inputs.path(idx).get<OgnToken[]>();
auto outputPathArray = *db.outputs.relativePath(idx).get<OgnToken[]>();
outputPathArray.resize(inputPathArray.size());
std::transform(inputPathArray.begin(), inputPathArray.end(), outputPathArray.begin(),
[&](const auto& p) { return getRelativePath(p, anchorPath); });
}
}
}
else
{
auto ipt = db.inputs.path().get<OgnToken>();
auto inputPath = ipt.vectorized(count);
auto oldInputs = db.state.path.vectorized(count);
auto oldAnchor = db.state.anchor.vectorized(count);
auto op = db.outputs.relativePath().get<OgnToken>();
auto outputs = op.vectorized(count);
for (size_t idx = 0; idx < count; ++idx)
{
if (oldAnchor[idx] != anchor[idx] || oldInputs[idx] != inputPath[idx])
{
if (anchor[idx] == omni::fabric::kUninitializedToken)
{
outputs[idx] = inputPath[idx];
}
else
{
const auto anchorPath = pxr::SdfPath(toTfToken(anchor[idx]));
outputs[idx] = getRelativePath(inputPath[idx], anchorPath);
}
oldAnchor[idx] = anchor[idx];
oldInputs[idx] = inputPath[idx];
}
}
}
return count;
}
static void onConnectionTypeResolve(const NodeObj& node)
{
// Resolve fully-coupled types for the 2 attributes
std::array<AttributeObj, 2> attrs{ node.iNode->getAttribute(node, OgnGetRelativePathAttributes::inputs::path.m_name),
node.iNode->getAttribute(node, OgnGetRelativePathAttributes::outputs::relativePath.m_name) };
node.iNode->resolveCoupledAttributes(node, attrs.data(), attrs.size());
}
};
REGISTER_OGN_NODE();
} // nodes
} // graph
} // omni
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnToDouble.ogn | {
"ToDouble": {
"version": 1,
"description": ["Converts the given input to 64 bit double. The node will attempt to convert",
" array and tuple inputs to doubles of the same shape"
],
"uiName": "To Double",
"categories": ["math:conversion"],
"scheduling": ["threadsafe"],
"inputs": {
"value": {
"type": ["numerics", "bool", "bool[]"],
"uiName": "value",
"description": "The numeric value to convert to double"
}
},
"outputs": {
"converted": {
"type": ["double", "double[2]", "double[3]", "double[4]", "double[]", "double[2][]", "double[3][]", "double[4][]"],
"uiName": "Double",
"description": "Output double-based value"
}
},
"tests" : [
{
"inputs:value": {"type": "float[]", "value": [] }, "outputs:converted": {"type": "double[]", "value": []}
},
{
"inputs:value": {"type": "double", "value": 2.1}, "outputs:converted": {"type": "double", "value": 2.1}
},
{
"inputs:value": {"type": "int", "value": 42}, "outputs:converted": {"type": "double", "value": 42.0}
},
{
"inputs:value": {"type": "bool[]", "value": [true, false]}, "outputs:converted": {"type": "double[]", "value": [1.0, 0.0]}
},
{
"inputs:value": {"type": "float[2]", "value": [2.1, 2.1] }, "outputs:converted": {"type": "double[2]", "value": [2.1, 2.1]}
},
{
"inputs:value": {"type": "half[3]", "value": [2, 3, 4] }, "outputs:converted": {"type": "double[3]", "value": [2, 3, 4] }
},
{
"inputs:value": {"type": "half[3][]", "value": [[2, 3, 4]] }, "outputs:converted": {"type": "double[3][]", "value": [[2, 3, 4]] }
},
{
"inputs:value": {"type": "int[2][]", "value": [[1, 2],[3, 4]] }, "outputs:converted": {"type": "double[2][]", "value": [[1.0, 2.0],[3.0, 4.0]] }
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnSetGatheredAttribute.ogn | {
"SetGatheredAttribute": {
"version": 1,
"description": ["Writes a value into the given Gathered attribute. If the number elements of the value is less",
"than the gathered attribute, the value will be broadcast to all prims. If the given value has",
"more elements than the gathered attribute, an error will be produced.",
"PROTOTYPE DO NOT USE, Requires GatherPrototype"
],
"uiName": "Set Gathered Attribute (Prototype)",
"categories": ["internal"],
"inputs": {
"gatherId": {
"type": "uint64",
"description": "The GatherId of the gathered prims"
},
"name": {
"type": "token",
"description": "The name of the attribute to set in the given Gather"
},
"execIn": {
"type": "execution",
"description": "Input execution state"
},
"value": {
"type": "any",
"description": "The new value to be written to the gathered attributes"
},
"mask": {
"type": "bool[]",
"optional": true,
"description": "Only writes values to the indexes which are true."
}
},
"outputs": {
"execOut": {
"type": "execution",
"description": "Output execution"
}
}
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnAppendPath.cpp | // Copyright (c) 2020-2021, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#include <omni/graph/core/PreUsdInclude.h>
#include <pxr/usd/usd/common.h>
#include <pxr/usd/sdf/valueTypeName.h>
#include <omni/graph/core/PostUsdInclude.h>
#include <omni/fabric/FabricUSD.h>
#include <OgnAppendPathDatabase.h>
using omni::fabric::asInt;
using omni::fabric::toTfToken;
static NameToken const& appendPath(const NameToken& pathAsToken, const pxr::SdfPath& suffix)
{
auto pathToken = toTfToken(pathAsToken);
if (pathAsToken != omni::fabric::kUninitializedToken && pxr::SdfPath::IsValidPathString(pathToken))
{
auto newPath = pxr::SdfPath(pathToken).AppendPath(suffix);
return *asInt(&newPath.GetToken());
}
return pathAsToken;
}
namespace omni
{
namespace graph
{
namespace nodes
{
class OgnAppendPath
{
public:
static size_t computeVectorized(OgnAppendPathDatabase& db, size_t count)
{
auto suffix = db.inputs.suffix.vectorized(count);
if (db.inputs.path().type().arrayDepth > 0)
{
for (size_t idx = 0; idx < count; ++idx)
{
if (suffix[idx] == omni::fabric::kUninitializedToken)
{
db.outputs.path(idx).copyData(db.inputs.path(idx));
}
else
{
const auto suffixPath = pxr::SdfPath(toTfToken(suffix[idx]));
const auto inputPathArray = *db.inputs.path(idx).get<OgnToken[]>();
auto outputPathArray = *db.outputs.path(idx).get<OgnToken[]>();
outputPathArray.resize(inputPathArray.size());
std::transform(inputPathArray.begin(), inputPathArray.end(), outputPathArray.begin(),
[&](const auto& p) { return appendPath(p, suffixPath); });
}
}
}
else
{
auto ipt = db.inputs.path().get<OgnToken>();
auto inputPath = ipt.vectorized(count);
auto oldInputs = db.state.path.vectorized(count);
auto oldSuffix = db.state.suffix.vectorized(count);
auto op = db.outputs.path().get<OgnToken>();
auto outputs = op.vectorized(count);
for (size_t idx = 0; idx < count; ++idx)
{
if (oldSuffix[idx] != suffix[idx] || oldInputs[idx] != inputPath[idx])
{
if (suffix[idx] == omni::fabric::kUninitializedToken)
{
outputs[idx] = inputPath[idx];
}
else
{
const auto suffixPath = pxr::SdfPath(toTfToken(suffix[idx]));
outputs[idx] = appendPath(inputPath[idx], suffixPath);
}
oldSuffix[idx] = suffix[idx];
oldInputs[idx] = inputPath[idx];
}
}
}
return count;
}
static void onConnectionTypeResolve(const NodeObj& node)
{
// Resolve fully-coupled types for the 2 attributes
std::array<AttributeObj, 2> attrs{ node.iNode->getAttribute(node, OgnAppendPathAttributes::inputs::path.m_name),
node.iNode->getAttribute(node, OgnAppendPathAttributes::outputs::path.m_name) };
node.iNode->resolveCoupledAttributes(node, attrs.data(), attrs.size());
}
};
REGISTER_OGN_NODE();
} // nodes
} // graph
} // omni
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnFindPrims.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.
//
// clang-format off
#include "UsdPCH.h"
// clang-format on
#include <OgnFindPrimsDatabase.h>
#include <omni/fabric/FabricUSD.h>
#include "ReadPrimCommon.h"
#include "PrimCommon.h"
namespace omni
{
namespace graph
{
namespace nodes
{
class OgnFindPrims
{
struct Listener
{
UsdStageChangeListenerRefPtr changeListener; // Lets us know when the USD stage changes
};
public:
// ----------------------------------------------------------------------------
static void initialize(const GraphContextObj& context, const NodeObj& nodeObj)
{
auto& ls = OgnFindPrimsDatabase::sSharedState<Listener>(nodeObj);
ls.changeListener = UsdStageChangeListener::New(context, UsdStageChangeListener::ListenMode::eResync);
}
// ----------------------------------------------------------------------------
static void release(const NodeObj& nodeObj)
{
auto& ls = OgnFindPrimsDatabase::sSharedState<Listener>(nodeObj);
ls.changeListener.Reset();
}
// ----------------------------------------------------------------------------
static bool compute(OgnFindPrimsDatabase& db)
{
auto& ls = db.sharedState<Listener>();
auto inputType = db.inputs.type();
auto rootPrimPath = db.inputs.rootPrimPath();
auto rootPrim = db.inputs.rootPrim();
auto recursive = db.inputs.recursive();
auto namePrefix = db.inputs.namePrefix();
auto requiredAttributesStr = db.inputs.requiredAttributes();
auto requiredRelationship = db.inputs.requiredRelationship();
auto requiredRelationshipTargetStr = db.inputs.requiredRelationshipTarget();
auto requiredTarget = db.inputs.requiredTarget();
auto pathPattern = db.inputs.pathPattern();
auto ignoreSystemPrims = db.inputs.ignoreSystemPrims();
// We can skip compute if our state isn't dirty, and our inputs haven't changed
if (not ls.changeListener->checkDirty())
{
if (db.state.inputType() == inputType &&
db.state.rootPrim().size() == rootPrim.size() &&
(db.state.rootPrim().size() == 0 ? db.state.rootPrimPath() == rootPrimPath
: db.state.rootPrim()[0] == rootPrim[0]) &&
db.state.recursive() == recursive &&
db.state.namePrefix() == namePrefix &&
requiredAttributesStr == db.state.requiredAttributes() &&
db.state.requiredRelationship() == requiredRelationship &&
(db.state.requiredTarget.size() == 0 ? requiredRelationshipTargetStr == db.state.requiredRelationshipTarget()
: db.state.requiredTarget()[0] == requiredTarget[0]) &&
pathPattern == db.state.pathPattern() &&
ignoreSystemPrims == db.state.ignoreSystemPrims())
{
// Not dirty and inputs didn't change
return true;
}
}
db.state.inputType() = inputType;
db.state.rootPrimPath() = rootPrimPath;
db.state.rootPrim() = rootPrim;
db.state.recursive() = recursive;
db.state.namePrefix() = namePrefix;
db.state.requiredAttributes() = requiredAttributesStr;
db.state.requiredRelationship() = requiredRelationship;
db.state.requiredRelationshipTarget() = requiredRelationshipTargetStr;
db.state.requiredTarget() = requiredTarget;
db.state.pathPattern() = pathPattern;
db.state.ignoreSystemPrims() = ignoreSystemPrims;
long stageId = db.abi_context().iContext->getStageId(db.abi_context());
auto stage = pxr::UsdUtilsStageCache::Get().Find(pxr::UsdStageCache::Id::FromLongInt(stageId));
if (!stage)
{
db.logError("Could not find USD stage %ld", stageId);
return false;
}
pxr::UsdPrim startPrim;
if(rootPrim.size() == 0)
{
if (rootPrimPath == omni::fabric::kUninitializedToken)
startPrim = stage->GetPseudoRoot();
else
{
if (const char* primPathStr = db.tokenToString(rootPrimPath))
{
startPrim = stage->GetPrimAtPath(pxr::SdfPath(primPathStr));
if (!startPrim)
{
db.logError("Could not find rootPrim \"%s\"", primPathStr);
return false;
}
}
}
}
else
{
if(rootPrim.size() > 1)
db.logWarning("Only one rootPrim target is supported, the rest will be ignored");
startPrim = stage->GetPrimAtPath(omni::fabric::toSdfPath(rootPrim[0]));
if (!startPrim)
{
db.logError("Could not find rootPrim \"%s\"", db.pathToString(rootPrim[0]));
return false;
}
}
// Figure out the required type if any
pxr::TfToken requiredTypeName;
if (inputType != omni::fabric::kUninitializedToken)
{
if (char const* typeStr = db.tokenToString(inputType))
requiredTypeName = pxr::TfToken(typeStr);
}
char const* requiredNamePrefix{ db.tokenToString(namePrefix) };
// Figure out require relationship target if any
pxr::SdfPath requiredRelationshipTarget;
pxr::TfToken requiredRelName;
if (requiredRelationship != omni::fabric::kUninitializedToken)
{
requiredRelName = pxr::TfToken(db.tokenToString(requiredRelationship));
if (!requiredRelName.IsEmpty())
{
bool validTarget = (requiredTarget.size() == 0 && !requiredRelationshipTargetStr.empty());
if(requiredTarget.size() == 0)
{
if(!requiredRelationshipTargetStr.empty())
requiredRelationshipTarget = pxr::SdfPath{ requiredRelationshipTargetStr };
}
else
{
if(requiredTarget.size() > 1)
db.logWarning("Only one requiredTarget is supported, the rest will be ignored");
requiredRelationshipTarget = omni::fabric::toSdfPath(requiredTarget[0]);
}
if (validTarget && !requiredRelationshipTarget.IsPrimPath())
{
db.logError("Required relationship target \"%s\" is not valid", requiredRelationshipTarget.GetText());
}
}
}
// now find matching prims
pxr::TfToken requiredAttribs{ std::string{ requiredAttributesStr.data(), requiredAttributesStr.size() } };
PathVector matchedPaths;
findPrims_findMatching(matchedPaths, startPrim, recursive, requiredNamePrefix, requiredTypeName,
requiredAttribs, requiredRelName, requiredRelationshipTarget,
omni::fabric::intToToken(pathPattern), ignoreSystemPrims);
// output PathC
auto outputPrims = db.outputs.prims();
outputPrims.resize(matchedPaths.size());
std::transform(matchedPaths.begin(), matchedPaths.end(), outputPrims.begin(),
[&db](auto path) {return path;});
// convert PathC to TokenC
auto outputPaths = db.outputs.primPaths();
outputPaths.resize(matchedPaths.size());
std::transform(matchedPaths.begin(), matchedPaths.end(), outputPaths.begin(),
[&db](auto path)
{
const char* pathStr = omni::fabric::intToPath(path).GetText();
return db.stringToToken(pathStr);
});
return true;
}
static bool updateNodeVersion(GraphContextObj const& context, NodeObj const& nodeObj, int oldVersion, int newVersion)
{
if (oldVersion < newVersion)
{
if (oldVersion < 2)
{
// backward compatibility: `inputs:type`
// Prior to this version `inputs:type` attribute did not support wild cards.
// The meaning of an empty string was to include all types. With the introduction of the wild cards
// we need to convert an empty string to "*" in order to include all types.
static Token const value{ "*" };
if (nodeObj.iNode->getAttributeExists(nodeObj, OgnFindPrimsAttributes::inputs::type.m_name))
{
AttributeObj attr = nodeObj.iNode->getAttribute(nodeObj, OgnFindPrimsAttributes::inputs::type.m_name);
auto roHandle = attr.iAttribute->getAttributeDataHandle(attr, kAccordingToContextIndex);
Token const* roValue = getDataR<Token const>(context, roHandle);
if (roValue && roValue->getString().empty())
{
Token* rwValue = getDataW<Token>(
context, attr.iAttribute->getAttributeDataHandle(attr, kAccordingToContextIndex));
*rwValue = value;
}
}
else
{
nodeObj.iNode->createAttribute(nodeObj, OgnFindPrimsAttributes::inputs::type.m_name, Type(BaseDataType::eToken), &value, nullptr,
kAttributePortType_Input, kExtendedAttributeType_Regular, nullptr);
}
return true;
}
}
return false;
}
};
REGISTER_OGN_NODE();
} // nodes
} // graph
} // omni
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnSelectIf.ogn | {
"SelectIf": {
"version": 1,
"description": [
"Selects an output from the given inputs based on a boolean condition.",
"If the condition is an array, and the inputs are arrays of equal length, and values will be selected",
"from ifTrue, ifFalse depending on the bool at the same index. If one input is an array and the other is",
"a scaler of the same base type, the scaler will be extended to the length of the other input."
],
"uiName": "Select If",
"categories": ["flowControl"],
"scheduling": ["threadsafe"],
"inputs": {
"ifTrue": {
"type": "any",
"uiName": "If True",
"description": "Value if condition is True"
},
"ifFalse": {
"type": "any",
"uiName": "If False",
"description": "Value if condition is False"
},
"condition": {
"type": ["bool", "bool[]"],
"description": "The selection variable"
}
},
"outputs": {
"result": {
"type": "any",
"description": "The selected value from ifTrue and ifFalse",
"uiName": "Result"
}
},
"tests" : [
{
"inputs:ifTrue": {"type": "float", "value": 1.0}, "inputs:ifFalse": {"type": "float", "value": 3.0},
"inputs:condition": {"type":"bool", "value":true}, "outputs:result": {"type": "float", "value": 1.0}
},
{
"inputs:ifTrue": {"type": "float", "value": 1.0}, "inputs:ifFalse": {"type": "float", "value": 3.0},
"inputs:condition": {"type":"bool", "value":false}, "outputs:result": {"type": "float", "value": 3.0}
},
{
"inputs:ifTrue": {"type": "float[]", "value": [10.0, 20.0]}, "inputs:ifFalse": {"type": "float[]", "value": [1.0, 2.0]},
"inputs:condition": {"type":"bool[]", "value":[true, false]}, "outputs:result": {"type": "float[]", "value": [10.0, 2.0]}
},
{
"inputs:ifTrue": {"type": "float[]", "value": [10.0, 20.0]}, "inputs:ifFalse": {"type": "float", "value": 99},
"inputs:condition": {"type":"bool[]", "value":[true, false]}, "outputs:result": {"type": "float[]", "value": [10.0, 99]}
},
{
"inputs:ifTrue": {"type": "float", "value": 99}, "inputs:ifFalse": {"type": "float[]", "value": [1.0, 2.0]},
"inputs:condition": {"type":"bool[]", "value":[true, false]}, "outputs:result": {"type": "float[]", "value": [99, 2.0]}
},
{
"inputs:ifTrue": {"type": "float[2][]", "value": [[1,1], [2,2]]}, "inputs:ifFalse": {"type": "float[2][]", "value": [[3,3], [4,4]]},
"inputs:condition": {"type":"bool[]", "value":[true, false]}, "outputs:result": {"type": "float[2][]", "value": [[1,1], [4,4]]}
},
{
"inputs:ifTrue": {"type": "string", "value": "abc"}, "inputs:ifFalse": {"type": "string", "value": "efghi"},
"inputs:condition": {"type":"bool", "value":true}, "outputs:result": {"type": "string", "value": "abc"}
},
{
"inputs:ifTrue": {"type": "string", "value": "abc"}, "inputs:ifFalse": {"type": "string", "value": "efg"},
"inputs:condition": {"type":"bool", "value":false}, "outputs:result": {"type": "string", "value": "efg"}
},
{
"inputs:ifTrue": {"type": "uchar[]", "value": [61, 62, 63]}, "inputs:ifFalse": {"type": "uchar[]", "value": [65, 66, 67]},
"inputs:condition": {"type":"bool", "value":false}, "outputs:result": {"type": "uchar[]", "value": [65, 66, 67]}
},
{
"inputs:ifTrue": {"type": "uchar[]", "value": [61, 62, 63]}, "inputs:ifFalse": {"type": "uchar[]", "value": [65, 66, 67]},
"inputs:condition": {"type":"bool[]", "value":[true, false, true]}, "outputs:result": {"type": "uchar[]", "value": [61, 66, 63]}
},
{
"inputs:ifTrue": {"type": "token", "value": "abc"}, "inputs:ifFalse": {"type": "token", "value": "efghi"},
"inputs:condition": {"type":"bool", "value":true}, "outputs:result": {"type": "token", "value": "abc"}
},
{
"inputs:ifTrue": {"type": "token", "value": "abc"}, "inputs:ifFalse": {"type": "token", "value": "efghi"},
"inputs:condition": {"type":"bool", "value":false}, "outputs:result": {"type": "token", "value": "efghi"}
},
{
"inputs:ifTrue": {"type": "token[]", "value": ["ab", "cd"]}, "inputs:ifFalse": {"type": "token[]", "value": ["ef", "gh"]},
"inputs:condition": {"type":"bool[]", "value":[true, false]}, "outputs:result": {"type": "token[]", "value": ["ab", "gh"]}
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnAppendString.ogn | {
"AppendString": {
"version": 1,
"$comment": "This node is replaced by OgnBuildString",
"description": [
"Creates a new token or string by appending the given token or string.",
"token[] inputs will be appended element-wise."
],
"uiName": "Append String (Deprecated)",
"categories": ["function"],
"scheduling": ["threadsafe"],
"metadata": {"hidden": "true"},
"inputs": {
"value": {
"type": ["token", "token[]", "string"],
"description": "The string(s) to be appended to"
},
"suffix": {
"type": ["token", "token[]", "string"],
"description": "The string to be appended"
}
},
"outputs": {
"value": {
"type": ["token","token[]", "string"],
"description": "The new string(s)"
}
},
"tests": [
{
"inputs:value": {"type":"token", "value": "/"}, "inputs:suffix": {"type":"token", "value": "foo"}, "outputs:value": {"type":"token", "value": "/foo"}
},
{
"inputs:value": {"type":"token[]", "value": ["/World","/World2"]}, "inputs:suffix": {"type":"token", "value": "/foo"}, "outputs:value": {"type":"token[]", "value": ["/World/foo","/World2/foo"]}
},
{
"inputs:value": {"type":"token[]", "value": ["/World","/World2"]}, "inputs:suffix": {"type":"token[]", "value": ["/foo", "/bar"]}, "outputs:value": {"type":"token[]", "value": ["/World/foo","/World2/bar"]}
},
{
"inputs:value": {"type":"string", "value": "/"}, "inputs:suffix": {"type":"string", "value": "foo"}, "outputs:value": {"type":"string", "value": "/foo"}
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnToString.cpp | // Copyright (c) 2022-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 <OgnToStringDatabase.h>
#include <omni/graph/core/ogn/UsdTypes.h>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <string>
#include "PrimCommon.h"
namespace omni
{
namespace graph
{
namespace nodes
{
namespace
{
template<typename T>
bool tryComputeAssumingType(OgnToStringDatabase& db)
{
std::string converted = tryConvertToString<T>(db, db.inputs.value());
if (converted.empty())
{
return false;
}
db.outputs.converted() = converted.c_str();
return true;
}
template<>
bool tryComputeAssumingType<ogn::Token>(OgnToStringDatabase& db)
{
std::string converted = tryConvertToString<ogn::Token>(db, db.inputs.value());
db.outputs.converted() = converted.c_str();
return true;
}
template<typename T, size_t tupleSize>
bool tryComputeAssumingType(OgnToStringDatabase& db)
{
std::string converted = tryConvertToString<T, tupleSize>(db, db.inputs.value());
if (converted.empty())
{
return false;
}
db.outputs.converted() = converted.c_str();
return true;
}
} // namespace
class OgnToString
{
public:
// Node to convert any input to a string
static bool compute(OgnToStringDatabase& db)
{
NodeObj nodeObj = db.abi_node();
const AttributeObj attr = nodeObj.iNode->getAttributeByToken(nodeObj, inputs::value.token());
const Type attrType = attr.iAttribute->getResolvedType(attr);
auto value = db.inputs.value();
if (attrType.baseType == BaseDataType::eUnknown)
{
db.logError("Unknown input data type");
return false;
}
// Compute the components, if the types are all resolved.
// This handles char and string case (get<ogn::string>() will return invalid result)
if (attrType.baseType == BaseDataType::eUChar)
{
if ((attrType.arrayDepth == 1) &&
((attrType.role == AttributeRole::eText) || (attrType.role == AttributeRole::ePath)))
{
auto val = db.inputs.value().template get<uint8_t[]>();
if (!val)
{
db.logError("Unable to resolve input type");
return false;
}
auto charData = val->data();
std::string str = std::string(charData, charData + val->size());
db.outputs.converted() = str.c_str();
return true;
}
else if (attrType.arrayDepth == 0)
{
uchar val = *db.inputs.value().template get<uchar>();
db.outputs.converted() = std::string(1, static_cast<char>(val)).c_str();
return true;
}
}
try
{
auto& inputType = db.inputs.value().type();
switch (inputType.baseType)
{
case BaseDataType::eToken:
return tryComputeAssumingType<ogn::Token>(db);
case BaseDataType::eBool:
return tryComputeAssumingType<bool>(db);
case BaseDataType::eDouble:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<double>(db);
case 2: return tryComputeAssumingType<double, 2>(db);
case 3: return tryComputeAssumingType<double, 3>(db);
case 4: return tryComputeAssumingType<double, 4>(db);
case 9: return tryComputeAssumingType<double, 9>(db);
case 16: return tryComputeAssumingType<double, 16>(db);
default: break;
}
case BaseDataType::eFloat:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<float>(db);
case 2: return tryComputeAssumingType<float, 2>(db);
case 3: return tryComputeAssumingType<float, 3>(db);
case 4: return tryComputeAssumingType<float, 4>(db);
default: break;
}
case BaseDataType::eHalf:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<pxr::GfHalf>(db);
case 2: return tryComputeAssumingType<pxr::GfHalf, 2>(db);
case 3: return tryComputeAssumingType<pxr::GfHalf, 3>(db);
case 4: return tryComputeAssumingType<pxr::GfHalf, 4>(db);
default: break;
}
case BaseDataType::eInt:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<int32_t>(db);
case 2: return tryComputeAssumingType<int32_t, 2>(db);
case 3: return tryComputeAssumingType<int32_t, 3>(db);
case 4: return tryComputeAssumingType<int32_t, 4>(db);
default: break;
}
;
case BaseDataType::eInt64:
return tryComputeAssumingType<int64_t>(db);
case BaseDataType::eUChar:
return tryComputeAssumingType<unsigned char>(db);
case BaseDataType::eUInt:
return tryComputeAssumingType<uint32_t>(db);
case BaseDataType::eUInt64:
return tryComputeAssumingType<uint64_t>(db);
default: break;
}
db.logWarning("Failed to resolve input types");
}
catch (const std::exception& e)
{
db.logError("Input could not be converted to string: %s", e.what());
return false;
}
return true;
}
};
REGISTER_OGN_NODE();
}
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnConstructArray.ogn | {
"ConstructArray": {
"version": 1,
"description": [
"Makes an output array attribute from input values, in the order of the inputs.",
"If 'arraySize' is less than the number of input elements, the top 'arraySize' elements will be used.",
"If 'arraySize' is greater than the number of input elements, the last input element will be repeated",
"to fill the remaining space."
],
"categories": ["math:array"],
"uiName": "Make Array",
"scheduling": ["threadsafe"],
"inputs": {
"input0": {
"type": "any",
"description": "Input array element"
},
"arraySize": {
"type": "int",
"description": "The size of the array to create",
"default": 1,
"minimum": 0,
"metadata": { "literalOnly": "1" }
},
"arrayType": {
"type": "token",
"description": "The type of the array ('auto' infers the type from the first connected and resolved input)",
"uiName": "Array Type",
"default": "auto",
"metadata": {
"literalOnly": "1",
"allowedTokens": {
"Auto": "auto",
"Bool": "bool[]",
"Double": "double[]",
"Float": "float[]",
"Half": "half[]",
"Int": "int[]",
"Int64": "int64[]",
"Token": "token[]",
"UChar": "uchar[]",
"UInt": "uint[]",
"UInt64": "uint64[]",
"Double_2": "double[2][]",
"Double_3": "double[3][]",
"Double_4": "double[4][]",
"Double_9": "matrixd[3][]",
"Double_16": "matrixd[4][]",
"Float_2": "float[2][]",
"Float_3": "float[3][]",
"Float_4": "float[4][]",
"Half_2": "half[2][]",
"Half_3": "half[3][]",
"Half_4": "half[4][]",
"Int_2": "int[2][]",
"Int_3": "int[3][]",
"Int_4": "int[4][]"
}
}
}
},
"outputs": {
"array": {
"type": "any",
"description": "The array of copied values of inputs in the given order"
}
},
"tests": [
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnBreakVector2.ogn | {
"BreakVector2": {
"version": 1,
"description": ["Split vector into 2 component values."],
"uiName": "Break 2-Vector",
"categories": ["math:conversion"],
"tags": ["decompose", "separate", "isolate"],
"scheduling": ["threadsafe"],
"inputs": {
"tuple": {
"type": ["double[2]", "float[2]", "half[2]", "int[2]"],
"uiName": "Vector",
"description": "2-vector to be broken"
}
},
"outputs": {
"x": {
"type": ["double", "float", "half", "int"],
"uiName": "X",
"description": "The first component of the vector"
},
"y": {
"type": ["double", "float", "half", "int"],
"uiName": "Y",
"description": "The second component of the vector"
}
},
"tests" : [
{
"inputs:tuple": {"type": "float[2]", "value": [42.0, 1.0]},
"outputs:x": {"type": "float", "value": 42.0}, "outputs:y": {"type": "float", "value": 1.0}
},
{
"inputs:tuple": {"type": "int[2]", "value": [42, -42]},
"outputs:x": {"type": "int", "value": 42}, "outputs:y": {"type": "int", "value": -42}
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnGetGatheredAttribute.cpp | // Copyright (c) 2021-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 <OgnGetGatheredAttributeDatabase.h>
#include <omni/graph/core/IGatherPrototype.h>
#include <carb/flatcache/FlatCache.h>
using namespace carb::flatcache;
namespace omni
{
namespace graph
{
namespace core
{
class OgnGetGatheredAttribute
{
public:
static bool compute(OgnGetGatheredAttributeDatabase& db)
{
auto& nodeObj = db.abi_node();
const INode& iNode = *nodeObj.iNode;
const IGraphContext& iContext = *db.abi_context().iContext;
const omni::graph::core::IGatherPrototype* iGatherPrototype =
carb::getCachedInterface<omni::graph::core::IGatherPrototype>();
NameToken attributeName = db.inputs.name();
const char* attributeNameStr = db.tokenToString(attributeName);
if (!attributeNameStr || strlen(attributeNameStr) == 0)
return true;
GatherId gatherId = static_cast<GatherId>(db.inputs.gatherId());
BucketId const* buckets{ nullptr };
size_t numBuckets{ 0 };
if (!iGatherPrototype->getGatheredBuckets(db.abi_context(), gatherId, buckets, numBuckets))
{
db.logError("Could not get gathered bucket list for Gather %zd", gatherId);
return false;
}
if (numBuckets == 0)
{
db.logError("Gathered bucket list is empty for Gather %zd", gatherId);
return false;
}
Type elementType;
size_t elementSize{ 0 };
if (!iGatherPrototype->getGatheredType(db.abi_context(), gatherId, attributeName, elementType, elementSize))
{
db.logError("Could not determine gathered type");
return false;
}
if (elementType.arrayDepth > 0)
{
db.logError("Gathering Array Type %s is not yet supported", elementType.getOgnTypeName().c_str());
return false;
}
Type outputType(elementType);
++outputType.arrayDepth;
// Determine if the output attribute has already been resolved to an incompatible type
if (db.outputs.value().resolved())
{
Type outType = db.outputs.value().type();
if (!outputType.compatibleRawData(outType))
{
db.logWarning("Resolved type %s of outputs:value is not compatible with type %s",
outType.getOgnTypeName().c_str(), db.outputs.value().type().getOgnTypeName().c_str());
return false;
}
}
// If it's resolved, we already know that it is compatible from the above check
if (!db.outputs.value().resolved())
{
// Not resolved, so we have to resolve it now. This node is strange in that the resolved output type
// depends on external state instead of other attributes.
AttributeObj out = nodeObj.iNode->getAttributeByToken(nodeObj, outputs::value.m_token);
out.iAttribute->setResolvedType(out, outputType);
db.outputs.value().reset(db.abi_context(), out.iAttribute->getAttributeDataHandle(out), out);
}
AttributeObj outputAttr = nodeObj.iNode->getAttributeByToken(
nodeObj, OgnGetGatheredAttributeAttributes::outputs::value.m_token);
AttributeDataHandle outputHandle = outputAttr.iAttribute->getAttributeDataHandle(outputAttr);
// determine the length of the output
size_t totalPrimCount{ 0 };
for (size_t i = 0; i < numBuckets; ++i)
{
BucketId bucketId = buckets[i];
size_t primCount = 0;
void* ptr = db.abi_context().iContext->getBucketArray(db.abi_context(), bucketId, attributeName, primCount);
if (!ptr)
{
CARB_LOG_WARN("Attribute %s not found in Gather %zd, bucket %zd", attributeNameStr, gatherId, size_t(bucketId));
return true;
}
totalPrimCount += primCount;
}
PathBucketIndex const* repeatedPaths{ nullptr };
size_t numRepeatedPaths{ 0 };
if (!iGatherPrototype->getGatheredRepeatedPaths(db.abi_context(), gatherId, repeatedPaths, numRepeatedPaths))
{
db.logError("Could not get repeated paths list for Gather %zd", gatherId);
return false;
}
//printf("Getting %zd prims worth of %s\n", totalPrimCount, attributeNameStr);
// Set the required length of output array
db.abi_context().iAttributeData->setElementCount(db.abi_context(), outputHandle, totalPrimCount + numRepeatedPaths);
// Get pointer to target data
uint8_t* destPtr = nullptr;
{
void** out = nullptr;
void** outPtr = reinterpret_cast<void**>(&out);
db.abi_context().iAttributeData->getDataW(outPtr, db.abi_context(), &outputHandle, 1);
destPtr = (uint8_t*)(*out);
}
CARB_ASSERT(destPtr);
// Finally, we copy the data into the output, bucket by bucket
for (size_t i = 0; i < numBuckets; ++i)
{
BucketId bucketId = buckets[i];
size_t primCount{ 0 };
const uint8_t* srcPtr = (const uint8_t*)db.abi_context().iContext->getBucketArray(
db.abi_context(), bucketId, attributeName, primCount);
if (primCount == 0 || !srcPtr)
{
db.logWarning("Bucket %zd has no entries for the given attribute", bucketId);
return false;
}
size_t byteCount = elementSize * primCount;
{
// Copy the data
memcpy(destPtr, srcPtr, byteCount);
// Move the write pointer
destPtr += byteCount;
}
}
// Copy the data for repeated paths
for (size_t i = 0; i < numRepeatedPaths; ++i)
{
BucketId bucketId = std::get<1>(repeatedPaths[i]);
size_t primCount{ 0 };
const uint8_t* srcPtr = (const uint8_t*)db.abi_context().iContext->getBucketArray(
db.abi_context(), bucketId, attributeName, primCount);
if (primCount == 0 || !srcPtr)
{
db.logWarning("Bucket %zd has no entries for the given attribute", bucketId);
return false;
}
ArrayIndex index = std::get<2>(repeatedPaths[i]);
if (index >= primCount)
{
db.logWarning("Bucket %zd has less entries than required", bucketId);
return false;
}
size_t byteCount = elementSize * index;
{
// Copy the data
memcpy(destPtr, srcPtr + byteCount, elementSize);
// Move the write pointer
destPtr += elementSize;
}
}
return true;
}
};
REGISTER_OGN_NODE()
}
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnBundleConstructor.ogn | {
"BundleConstructor": {
"version": 1,
"language": "python",
"description": [
"This node creates a bundle mirroring all of the dynamic input attributes that have been added to it.",
"If no dynamic attributes exist then the bundle will be empty. See the 'InsertAttribute' node for",
"something that can construct a bundle from existing connected attributes."
],
"metadata": {
"uiName": "Bundle Constructor"
},
"categories": ["bundle"],
"outputs": {
"bundle": {
"type": "bundle",
"description": "The bundle consisting of copies of all of the dynamic input attributes.",
"metadata": {
"uiName": "Constructed Bundle"
}
}
}
}
} |
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnGetPrimPath.ogn |
{
"GetPrimPath": {
"version": 3,
"description": ["Generates a path from the specified relationship. This is useful when an absolute prim path may change."],
"uiName": "Get Prim Path",
"categories": ["sceneGraph"],
"scheduling": ["threadsafe"],
"inputs": {
"prim": {
"type": "target",
"description": "The prim to determine the path of"
}
},
"outputs": {
"primPath": {
"type": "token",
"description": "The absolute path of the given prim as a token"
},
"path": {
"type": "path",
"description": "The absolute path of the given prim as a string",
"deprecated": "Path is deprecated. Use primPath output instead."
}
}
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnGetGatheredAttribute.ogn | {
"GetGatheredAttribute": {
"version": 1,
"description": [
"Copies gathered scaler/vector attribute values from the Gather buckets into an array attribute",
"PROTOTYPE DO NOT USE, Requires GatherPrototype"
],
"uiName": "Get Gathered Attribute (Prototype)",
"categories": ["internal"],
"inputs": {
"gatherId": {
"type": "uint64",
"description": "The GatherId of the Gather containing the attribute values"
},
"name": {
"type": "token",
"description": "The name of the gathered attribute to join"
}
},
"outputs": {
"value": {
"type": "any",
"description": "The gathered attribute values as an array",
"unvalidated": true
}
},
"tests": [
{
"setup": {
"create_nodes": [
["TestNode", "omni.graph.nodes.GetGatheredAttribute"],
["GatherByPath", "omni.graph.nodes.GatherByPath"]
],
"create_prims": [
["Empty", {}],
["Xform1", {"_translate": ["pointd[3]", [1, 2, 3]]}],
["Xform2", {"_translate": ["pointd[3]", [4, 5, 6]]}],
["XformTagged1", {"foo": ["token", ""], "_translate": ["pointd[3]", [1, 2, 3]]}],
["Tagged1", {"foo": ["token", ""]}]
],
"connect": [
["GatherByPath.outputs:gatherId", "TestNode.inputs:gatherId"]
],
"set_values": [
["GatherByPath.inputs:primPaths", ["/Xform1", "/Xform2"] ],
["GatherByPath.inputs:attributes", "_translate" ],
["GatherByPath.inputs:allAttributes", false]
]
},
"inputs": {
"name": "_translate"
},
"outputs": {
"value": {"type": "pointd[3][]", "value": [[1,2,3],[4,5,6]]}
}
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnMakeArray.py | """
This is the implementation of the OGN node defined in OgnMakeArrayDouble3.ogn
"""
import omni.graph.core as og
class OgnMakeArray:
"""
Makes an output array attribute from input values
"""
@staticmethod
def compute(db) -> bool:
"""Compute the outputs from the current input"""
if db.inputs.a.type.base_type == og.BaseDataType.UNKNOWN:
return False
array_size = db.inputs.arraySize
out_array = []
if array_size > 0:
out_array.append(db.inputs.a.value)
if array_size > 1:
out_array.append(db.inputs.b.value)
if array_size > 2:
out_array.append(db.inputs.c.value)
if array_size > 3:
out_array.append(db.inputs.d.value)
if array_size > 4:
out_array.append(db.inputs.e.value)
out_array.extend([db.inputs.e.value] * (array_size - 5))
db.outputs.array.value = out_array
return True
@staticmethod
def on_connection_type_resolve(node) -> None:
attribs = [(node.get_attribute("inputs:" + a), None, 0, None) for a in ("a", "b", "c", "d", "e")]
attribs.append((node.get_attribute("outputs:array"), None, 1, None))
og.resolve_base_coupled(attribs)
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnGetParentPath.cpp | // Copyright (c) 2020-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 <OgnGetParentPathDatabase.h>
#include <omni/fabric/FabricUSD.h>
using omni::fabric::asInt;
using omni::fabric::toTfToken;
static NameToken const& getParentPath(const NameToken& pathAsToken)
{
auto pathToken = toTfToken(pathAsToken);
if (pathAsToken != omni::fabric::kUninitializedToken && pxr::SdfPath::IsValidPathString(pathToken))
{
auto parentPath = pxr::SdfPath(pathToken).GetParentPath();
return *asInt(&parentPath.GetToken());
}
return pathAsToken;
}
namespace omni
{
namespace graph
{
namespace nodes
{
class OgnGetParentPath
{
public:
static bool computeVectorized(OgnGetParentPathDatabase& db, size_t count)
{
if (db.inputs.path().type().arrayDepth > 0)
{
for (size_t idx = 0; idx < count; ++idx)
{
const auto inputPathArray = *db.inputs.path(idx).get<OgnToken[]>();
auto outputPathArray = *db.outputs.parentPath(idx).get<OgnToken[]>();
outputPathArray.resize(inputPathArray.size());
std::transform(inputPathArray.begin(), inputPathArray.end(), outputPathArray.begin(),
[&](const auto& p) { return getParentPath(p); });
}
}
else
{
auto ipt = db.inputs.path().get<OgnToken>();
auto inputPath = ipt.vectorized(count);
auto oldInputs = db.state.path.vectorized(count);
auto op = db.outputs.parentPath().get<OgnToken>();
auto outputs = op.vectorized(count);
for (size_t idx = 0; idx < count; ++idx)
{
if (oldInputs[idx] != inputPath[idx])
{
outputs[idx] = getParentPath(inputPath[idx]);
oldInputs[idx] = inputPath[idx];
}
}
}
return count;
}
static void onConnectionTypeResolve(const NodeObj& node)
{
// Resolve fully-coupled types for the 2 attributes
std::array<AttributeObj, 2> attrs{ node.iNode->getAttribute(node, OgnGetParentPathAttributes::inputs::path.m_name),
node.iNode->getAttribute(node, OgnGetParentPathAttributes::outputs::parentPath.m_name) };
node.iNode->resolveCoupledAttributes(node, attrs.data(), attrs.size());
}
};
REGISTER_OGN_NODE();
} // nodes
} // graph
} // omni
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnMakeVector3.ogn | {
"MakeVector3": {
"version": 1,
"description": [
"Merge 3 input values into a single output vector.",
"If the inputs are arrays, the output will be an array of vectors."
],
"uiName": "Make 3-Vector",
"categories": ["math:conversion"],
"tags": ["compose", "combine", "join"],
"scheduling": ["threadsafe"],
"inputs": {
"x": {
"type": ["double", "float", "half", "int", "double[]", "float[]", "half[]", "int[]"],
"uiName": "X",
"description": "The first component of the vector"
},
"y": {
"type": ["double", "float", "half", "int", "double[]", "float[]", "half[]", "int[]"],
"uiName": "Y",
"description": "The second component of the vector"
},
"z": {
"type": ["double", "float", "half", "int", "double[]", "float[]", "half[]", "int[]"],
"uiName": "Z",
"description": "The third component of the vector"
}
},
"outputs": {
"tuple": {
"type": ["double[3]", "float[3]", "half[3]", "int[3]", "double[3][]", "float[3][]", "half[3][]", "int[3][]"],
"uiName": "Vector",
"description": "Output 3-vector(s)"
}
},
"tests" : [
{
"inputs:x": {"type": "float", "value": 42.0}, "inputs:y": {"type": "float", "value": 1.0},
"inputs:z": {"type": "float", "value": 0.0},
"outputs:tuple": {"type": "float[3]", "value": [42.0, 1.0, 0.0]}
},
{
"inputs:x": {"type": "float", "value": 42.0},
"outputs:tuple": {"type": "float[3]", "value": [42.0, 0.0, 0.0]}
},
{
"inputs:x": {"type": "float[]", "value": [42,1,0]},
"inputs:y": {"type": "float[]", "value": [0,1,2]},
"inputs:z": {"type": "float[]", "value": [0,2,4]},
"outputs:tuple": {"type": "float[3][]", "value": [[42,0,0],[1,1,2],[0,2,4]]}
},
{
"inputs:x": {"type": "int", "value": 42}, "inputs:y": {"type": "int", "value": -42},
"inputs:z": {"type": "int", "value": 5},
"outputs:tuple": {"type": "int[3]", "value": [42, -42, 5]}
},
{
"setup": {
"create_nodes": [
["TestNode", "omni.graph.nodes.MakeVector3"],
["ConstPoint3d", "omni.graph.nodes.ConstantPoint3d"]
],
"connect": [
["TestNode.outputs:tuple", "ConstPoint3d.inputs:value"]
]
},
"inputs": {
"x": {"type": "double", "value": 42.0}, "y": {"type": "double", "value": 1.0},
"z": {"type": "double", "value": 0.0}
},
"outputs": {
"tuple": {"type": "pointd[3]", "value": [42.0, 1.0, 0.0]}
}
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnBundleInspector.ogn | {
"BundleInspector": {
"version": 3,
"description": [
"This node creates independent outputs containing information about the contents",
"of a bundle attribute. It can be used for testing or debugging what is inside a",
"bundle as it flows through the graph. The bundle is inspected recursively, so",
"any bundles inside of the main bundle have their contents added to the output as well.",
"The bundle contents can be printed when the node evaluates, and it passes the input straight",
"through unchanged so you can insert this node between two nodes to inspect the data flowing",
"through the graph."
],
"metadata": {
"uiName": "Bundle Inspector"
},
"categories": ["bundle"],
"inputs": {
"bundle": {
"type": "bundle",
"description": "The attribute bundle to be inspected",
"metadata": {
"uiName": "Bundle To Analyze"
}
},
"print": {
"type": "bool",
"description": "Setting to true prints the contents of the bundle when the node evaluates",
"metadata": {
"uiName" : "Print Contents"
}
},
"inspectDepth": {
"type": "int",
"default": 1,
"description": [
"The depth that the inspector is going to traverse and print.",
"0 means just attributes on the input bundles. 1 means its immediate children. -1 means infinity."
],
"metadata": {
"uiName" : "Inspect Depth"
}
}
},
"outputs": {
"count": {
"type": "uint64",
"description": [
"Number of attributes present in the bundle. Every other output is an array that",
"should have this number of elements in it."
],
"metadata": {
"uiName": "Attribute Count",
"hidden": "true"
}
},
"attributeCount": {
"type": "uint64",
"description": [
"Number of attributes present in the bundle. Every other output is an array that",
"should have this number of elements in it."
],
"metadata": {
"uiName": "Attribute Count"
}
},
"names": {
"type": "token[]",
"description": "List of the names of attributes present in the bundle",
"metadata": {
"uiName": "Attribute Names"
}
},
"types": {
"type": "token[]",
"description": "List of the types of attributes present in the bundle",
"metadata": {
"uiName": "Attribute Base Types"
}
},
"roles": {
"type": "token[]",
"description": "List of the names of the roles of attributes present in the bundle",
"metadata": {
"uiName": "Attribute Roles"
}
},
"arrayDepths": {
"type": "int[]",
"description": "List of the array depths of attributes present in the bundle",
"metadata": {
"uiName": "Array Depths"
}
},
"tupleCounts": {
"type": "int[]",
"description": "List of the tuple counts of attributes present in the bundle",
"metadata": {
"uiName": "Tuple Counts"
}
},
"values": {
"type": "token[]",
"description": "List of the bundled attribute values, converted to token format",
"metadata": {
"uiName": "Attribute Values"
}
},
"childCount": {
"type": "uint64",
"description": [
"Number of child bundles present in the bundle."
],
"metadata": {
"uiName": "Child Count"
}
},
"bundle": {
"type": "bundle",
"description": "The attribute bundle passed through as-is from the input bundle",
"metadata": {
"uiName": "Bundle Passthrough"
}
}
},
"tests": [
{
"outputs:count": 0,
"outputs:names": [],
"outputs:types": [],
"outputs:roles": [],
"outputs:arrayDepths": [],
"outputs:tupleCounts": [],
"outputs:values": []
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnToString.ogn | {
"ToString": {
"version": 1,
"description": [
"Converts the given input to a string equivalent."
],
"uiName": "To String",
"categories": ["function"],
"scheduling": ["threadsafe"],
"inputs": {
"value": {
"type": "any",
"uiName": "value",
"description": [
"The value to be converted to a string.\n",
"Numeric values are converted using C++'s std::ostringstream << operator. This can result in the values",
"being converted to exponential form. E.g: 1.234e+06",
"Arrays of numeric values are converted to Python list syntax. E.g: [1.5, -0.03]",
"A uchar value is converted to a single, unquoted character.",
"An array of uchar values is converted to an unquoted string. Avoid zero values (i.e. null chars) in the",
"array as the behavior is undefined and may vary over time.",
"A single token is converted to its unquoted string equivalent.",
"An array of tokens is converted to Python list syntax with each token enclosed in double quotes. E.g. [\"first\", \"second\"]"
]
}
},
"outputs": {
"converted": {
"type": "string",
"uiName": "String",
"description": "Output string"
}
},
"tests" : [
{
"inputs:value": {"type": "bool", "value": true}, "outputs:converted": "True"
},
{
"inputs:value": {"type": "double", "value": 2.1}, "outputs:converted": "2.1"
},
{
"inputs:value": {"type": "int", "value": 42}, "outputs:converted": "42"
},
{
"inputs:value": {"type": "double[3]", "value": [1.5, 2, 3] }, "outputs:converted": "[1.5, 2, 3]"
},
{
"inputs:value": {"type": "half[3]", "value": [2, 3.5, 4] }, "outputs:converted": "[2, 3.5, 4]"
},
{
"inputs:value": {"type": "int[2][]", "value": [[1, 2],[3, 4]] }, "outputs:converted": "[[1, 2], [3, 4]]"
},
{
"inputs:value": {"type": "uint64", "value": 42 }, "outputs:converted": "42"
},
{
"inputs:value": {"type": "uchar", "value": 65 }, "outputs:converted": "A"
},
{
"inputs:value": {"type": "uchar[]", "value": [ 65, 66, 67] }, "outputs:converted": "[A, B, C]"
},
{
"inputs:value": {"type": "string", "value": "ABC" }, "outputs:converted": "ABC"
},
{
"inputs:value": {"type": "token", "value": "Foo" }, "outputs:converted": "Foo"
},
{
"inputs:value": {"type": "token", "value": "" }, "outputs:converted": ""
},
{
"inputs:value": {"type": "token[]", "value": ["Foo","Bar"]}, "outputs:converted": "[\"Foo\", \"Bar\"]"
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnBreakVector3.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 <OgnBreakVector3Database.h>
#include <omni/graph/core/ogn/ComputeHelpers.h>
#include <omni/graph/core/ogn/UsdTypes.h>
#include <fstream>
#include <iomanip>
namespace omni
{
namespace graph
{
namespace nodes
{
namespace
{
template <typename Type>
bool tryBreakVector(OgnBreakVector3Database& db, size_t count = 1)
{
const auto vector = db.inputs.tuple().template get<Type[3]>();
const auto x = db.outputs.x().template get<Type>();
const auto y = db.outputs.y().template get<Type>();
const auto z = db.outputs.z().template get<Type>();
if (!vector || !x || !y || !z)
return false;
const auto pVector = vector.vectorized(count);
const auto px = x.vectorized(count);
const auto py = y.vectorized(count);
const auto pz = z.vectorized(count);
if (pVector.empty() || px.empty() || py.empty() || pz.empty())
return false;
for (size_t i = 0; i < count; i++)
{
px[i] = pVector[i][0];
py[i] = pVector[i][1];
pz[i] = pVector[i][2];
}
return true;
}
} // namespace
// Node to break a 3-vector into it's component scalers
class OgnBreakVector3
{
public:
static size_t computeVectorized(OgnBreakVector3Database& db, size_t count)
{
// Compute the components, if the types are all resolved.
try
{
if (tryBreakVector<double>(db, count))
return count;
else if (tryBreakVector<float>(db, count))
return true;
else if (tryBreakVector<pxr::GfHalf>(db, count))
return count;
else if (tryBreakVector<int32_t>(db, count))
return count;
else
{
db.logWarning("Failed to resolve input types");
}
}
catch (const std::exception& e)
{
db.logError("Vector could not be broken: %s", e.what());
return 0;
}
return 0;
}
static void onConnectionTypeResolve(const NodeObj& nodeObj)
{
auto vector = nodeObj.iNode->getAttributeByToken(nodeObj, inputs::tuple.token());
auto x = nodeObj.iNode->getAttributeByToken(nodeObj, outputs::x.token());
auto y = nodeObj.iNode->getAttributeByToken(nodeObj, outputs::y.token());
auto z = nodeObj.iNode->getAttributeByToken(nodeObj, outputs::z.token());
auto vectorType = vector.iAttribute->getResolvedType(vector);
// Require inputs to be resolved before determining outputs' type
if (vectorType.baseType != BaseDataType::eUnknown)
{
std::array<AttributeObj, 4> attrs{ vector, x, y, z };
std::array<uint8_t, 4> tuples{ 3, 1, 1, 1};
std::array<uint8_t, 4> arrays{ 0, 0, 0, 0 };
std::array<AttributeRole, 4> roles{ vectorType.role, AttributeRole::eNone, AttributeRole::eNone, AttributeRole::eNone };
nodeObj.iNode->resolvePartiallyCoupledAttributes(nodeObj, attrs.data(), tuples.data(), arrays.data(), roles.data(), attrs.size());
}
}
};
REGISTER_OGN_NODE();
}
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnArrayRemoveValue.ogn | {
"ArrayRemoveValue": {
"version": 1,
"description": [
"Removes the first occurrence of the given value from an array. If removeAll is true, removes all occurrences"
],
"uiName": "Array Remove Value",
"categories": ["math:array"],
"scheduling": ["threadsafe"],
"inputs": {
"array": {
"type": ["arrays", "bool[]"],
"description": "The array to be modified",
"uiName": "Array"
},
"value": {
"type": ["array_elements", "bool"],
"description": "The value to be removed"
},
"removeAll": {
"type": "bool",
"description": "If true, removes all occurences of the value.",
"default": false
}
},
"outputs": {
"array": {
"type": ["arrays", "bool[]"],
"description": "The modified array",
"uiName": "Array"
},
"found": {
"type": "bool",
"description": "true if a value was removed, false otherwise"
}
},
"tests": [
{
"inputs:array": {"type": "int[]", "value": []}, "outputs:found": false,
"inputs:removeAll": false, "inputs:value": {"type": "int", "value": 41},
"outputs:array": {"type": "int[]", "value": []}
},
{
"inputs:array": {"type": "int[]", "value": [41, 42, 41]}, "outputs:found": true,
"inputs:removeAll": false, "inputs:value": {"type": "int", "value": 41},
"outputs:array": {"type": "int[]", "value": [42, 41]}
},
{
"inputs:array": {"type": "int[]", "value": [41, 42, 43, 41]}, "outputs:found": true,
"inputs:removeAll": true, "inputs:value": {"type": "int", "value": 41},
"outputs:array": {"type": "int[]", "value": [42, 43]}
},
{
"inputs:array": {"type": "int[]", "value": [41, 41, 41, 41]}, "outputs:found": true,
"inputs:removeAll": true, "inputs:value": {"type": "int", "value": 41},
"outputs:array": {"type": "int[]", "value": []}
},
{
"inputs:array": {"type": "token[]", "value": ["FOOD", "BARFOOD", "BAZ"]}, "outputs:found": false,
"inputs:value": {"type": "token", "value":"FOO"}, "inputs:removeAll": false,
"outputs:array": {"type": "token[]", "value": ["FOOD", "BARFOOD", "BAZ"]}
},
{
"inputs:array": {"type": "token[]", "value": ["FOOD", "BARFOOD", "BAZ"]}, "outputs:found": true,
"inputs:value": {"type": "token", "value":"FOOD"}, "inputs:removeAll": false,
"outputs:array": {"type": "token[]", "value": ["BARFOOD", "BAZ"]}
},
{
"inputs:array": {"type": "int64[]", "value": [41, 42]}, "outputs:found": true,
"inputs:value": {"type": "int64", "value":41}, "inputs:removeAll": false,
"outputs:array": {"type": "int64[]", "value": [42]}
},
{
"inputs:array": {"type": "uchar[]", "value": [41, 42]}, "outputs:found": true,
"inputs:value": {"type": "uchar", "value":41}, "inputs:removeAll": false,
"outputs:array": {"type": "uchar[]", "value": [42]}
},
{
"inputs:array": {"type": "uint[]", "value": [41, 42]}, "outputs:found": true,
"inputs:value": {"type": "uint", "value":42}, "inputs:removeAll": false,
"outputs:array": {"type": "uint[]", "value": [41]}
},
{
"inputs:array": {"type": "uint64[]", "value": [41, 42]}, "outputs:found": true,
"inputs:value": {"type": "uint64", "value":42}, "inputs:removeAll": false,
"outputs:array": {"type": "uint64[]", "value": [41]}
},
{
"inputs:array": {"type": "bool[]", "value": [false, true]}, "outputs:found": true,
"inputs:value": {"type": "bool", "value":false}, "inputs:removeAll": false,
"outputs:array": {"type": "bool[]", "value": [true]}
},
{
"inputs:array": {"type": "half[2][]", "value": [[1, 2], [3, 4]]}, "outputs:found": true,
"inputs:value": {"type": "half[2]", "value":[1, 2]}, "inputs:removeAll": false,
"outputs:array": {"type": "half[2][]", "value": [[3, 4]]}
},
{
"inputs:array": {"type": "double[2][]", "value": [[1, 2], [3, 4], [5, 6]]}, "outputs:found": true,
"inputs:value": {"type": "double[2]", "value":[1, 2]}, "inputs:removeAll": false,
"outputs:array": {"type": "double[2][]", "value": [[3, 4], [5, 6]]}
},
{
"inputs:array": {"type": "double[2][]", "value": [[1, 2], [3, 4], [5, 6], [1, 2]]}, "outputs:found": true,
"inputs:value": {"type": "double[2]", "value":[1, 2]}, "inputs:removeAll": true,
"outputs:array": {"type": "double[2][]", "value": [[3, 4], [5, 6]]}
},
{
"inputs:array": {"type": "double[3][]", "value": [[1.1, 2.1, 1.0], [3, 4, 5]]}, "outputs:found": true,
"inputs:value": {"type": "double[3]", "value":[3, 4, 5]}, "inputs:removeAll": false,
"outputs:array": {"type": "double[3][]", "value": [[1.1, 2.1, 1.0]]}
},
{
"inputs:array": {"type": "double[3][]", "value": [[1.1, 2.1, 1.0], [3, 4, 5]]}, "outputs:found": false,
"inputs:value": {"type": "double[3]", "value":[3.1, 4, 5]}, "inputs:removeAll": false,
"outputs:array": {"type": "double[3][]", "value": [[1.1, 2.1, 1.0], [3, 4, 5]]}
},
{
"inputs:array": {"type": "int[4][]", "value": [[1, 2, 3, 4], [3, 4, 5, 6]]}, "outputs:found": true,
"inputs:value": {"type": "int[4]", "value":[1, 2, 3, 4]}, "inputs:removeAll": false,
"outputs:array": {"type": "int[4][]", "value": [[3, 4, 5, 6]]}
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnArraySetIndex.cpp | // Copyright (c) 2022-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 <OgnArraySetIndexDatabase.h>
#include <omni/graph/core/StringUtils.h>
#include <omni/graph/core/ogn/ComputeHelpers.h>
#include <carb/logging/Log.h>
#include <algorithm>
namespace omni {
namespace graph {
namespace nodes {
using core::ogn::array;
// unnamed namespace to avoid multiple declaration when linking
namespace {
// helper to wrap a given index from legal range [-arrayLength, arrayLength) to [0:arrayLength)
// This will throw if the wrapped index is greater than arraySize when resizeToFit is false,
// or if the wrapped index is negative.
size_t tryWrapIndex(int index, size_t arraySize, bool resizeToFit)
{
int wrappedIndex = index;
if (index < 0)
wrappedIndex = static_cast<int>(arraySize) + index;
if ((wrappedIndex >= static_cast<int>(arraySize) && !resizeToFit) || wrappedIndex < 0)
throw ogn::compute::InputError(formatString("inputs:index %d is out of range for inputs:array of size %zu", wrappedIndex, arraySize));
return static_cast<size_t>(wrappedIndex);
}
template<typename BaseType>
bool tryComputeAssumingType(OgnArraySetIndexDatabase& db)
{
auto inputArray = db.inputs.array().template get<BaseType[]>();
size_t const inputArraySize = db.inputs.array().size();
size_t const index = tryWrapIndex(db.inputs.index(), inputArraySize, db.inputs.resizeToFit());
auto const value = db.inputs.value().template get<BaseType>();
auto outputArray = db.outputs.array().template get<BaseType[]>();
if (!value || !inputArray)
return false;
// tryWrapIndex would have thrown already if index >= inputArraySize and resizeToFit is false
size_t outputArraySize = std::max(inputArraySize, index + 1);
(*outputArray).resize(outputArraySize);
memcpy(outputArray->data(), inputArray->data(), sizeof(BaseType) * inputArraySize);
if (outputArraySize > inputArraySize)
memset(&((*outputArray)[inputArraySize]), 0, sizeof(BaseType) * (outputArraySize - inputArraySize));
memcpy(&((*outputArray)[index]), &*value, sizeof(BaseType));
return true;
}
} // namespace
class OgnArraySetIndex
{
public:
static bool compute(OgnArraySetIndexDatabase& db)
{
auto& inputType = db.inputs.value().type();
try
{
switch (inputType.baseType)
{
case BaseDataType::eBool:
return tryComputeAssumingType<bool>(db);
case BaseDataType::eToken:
return tryComputeAssumingType<ogn::Token>(db);
case BaseDataType::eDouble:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<double>(db);
case 2: return tryComputeAssumingType<double[2]>(db);
case 3: return tryComputeAssumingType<double[3]>(db);
case 4: return tryComputeAssumingType<double[4]>(db);
case 9: return tryComputeAssumingType<double[9]>(db);
case 16: return tryComputeAssumingType<double[16]>(db);
default: break;
}
case BaseDataType::eFloat:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<float>(db);
case 2: return tryComputeAssumingType<float[2]>(db);
case 3: return tryComputeAssumingType<float[3]>(db);
case 4: return tryComputeAssumingType<float[4]>(db);
default: break;
}
case BaseDataType::eHalf:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<pxr::GfHalf>(db);
case 2: return tryComputeAssumingType<pxr::GfHalf[2]>(db);
case 3: return tryComputeAssumingType<pxr::GfHalf[3]>(db);
case 4: return tryComputeAssumingType<pxr::GfHalf[4]>(db);
default: break;
}
case BaseDataType::eInt:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<int32_t>(db);
case 2: return tryComputeAssumingType<int32_t[2]>(db);
case 3: return tryComputeAssumingType<int32_t[3]>(db);
case 4: return tryComputeAssumingType<int32_t[4]>(db);
default: break;
}
;
case BaseDataType::eInt64:
return tryComputeAssumingType<int64_t>(db);
case BaseDataType::eUChar:
return tryComputeAssumingType<unsigned char>(db);
case BaseDataType::eUInt:
return tryComputeAssumingType<uint32_t>(db);
case BaseDataType::eUInt64:
return tryComputeAssumingType<uint64_t>(db);
default: break;
}
db.logWarning("Failed to resolve input types");
}
catch (ogn::compute::InputError const &error)
{
db.logError(error.what());
}
return false;
}
static void onConnectionTypeResolve(const NodeObj& node){
auto const inputArray = node.iNode->getAttributeByToken(node, inputs::array.token());
auto const inputValue = node.iNode->getAttributeByToken(node, inputs::value.token());
auto const outputArray = node.iNode->getAttributeByToken(node, outputs::array.token());
auto const inputArrayType = inputArray.iAttribute->getResolvedType(inputArray);
if (inputArrayType.baseType != BaseDataType::eUnknown)
{
std::array<AttributeObj, 3> attrs { inputArray, inputValue, outputArray };
// all should have the same tuple count
std::array<uint8_t, 3> tupleCounts {
inputArrayType.componentCount,
inputArrayType.componentCount,
inputArrayType.componentCount
};
// value type can not be an array because we don't support arrays-of-arrays
std::array<uint8_t, 3> arrayDepths {
1,
0,
1
};
std::array<AttributeRole, 3> rolesBuf {
inputArrayType.role,
AttributeRole::eUnknown,
AttributeRole::eUnknown
};
node.iNode->resolvePartiallyCoupledAttributes(node, attrs.data(), tupleCounts.data(),
arrayDepths.data(), rolesBuf.data(), attrs.size());
}
}
};
REGISTER_OGN_NODE()
} // namespace nodes
} // namespace graph
} // namespace omni
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnGetRelativePath.ogn | {
"GetRelativePath": {
"version": 1,
"description": ["Generates a path token relative to anchor from path.(ex. (/World, /World/Cube) -> /Cube)"],
"uiName": "Get Relative Path",
"categories": ["sceneGraph"],
"scheduling": [ "threadsafe" ],
"inputs": {
"anchor": {
"type": "token",
"description": "Path token to compute relative to (ex. /World)"
},
"path": {
"type": ["token", "token[]"],
"description": "Path token to convert to a relative path (ex. /World/Cube)"
}
},
"outputs": {
"relativePath": {
"type": ["token", "token[]"],
"description": "Relative path token (ex. /Cube)"
}
},
"state": {
"anchor": {
"type": "token",
"description": "Snapshot of previously seen rootPath"
},
"path": {
"type": "token",
"description": "Snapshot of previously seen path"
}
},
"tests": [
{
"inputs:anchor": "/World",
"inputs:path": {
"type": "token",
"value": "/World"
},
"outputs:relativePath": {
"type": "token",
"value": "."
}
},
{
"inputs:anchor": "/World",
"inputs:path": {
"type": "token",
"value": "/World/foo"
},
"outputs:relativePath": {
"type": "token",
"value": "foo"
}
},
{
"inputs:anchor": "/World",
"inputs:path": {
"type": "token",
"value": "/World/foo/bar"
},
"outputs:relativePath": {
"type": "token",
"value": "foo/bar"
}
},
{
"inputs:anchor": "/World",
"inputs:path": {
"type": "token",
"value": "/World/foo/bar.attrib"
},
"outputs:relativePath": {
"type": "token",
"value": "foo/bar.attrib"
}
},
{
"inputs:anchor": "/World",
"inputs:path": {
"type": "token[]",
"value": [ "/World/foo", "/World/bar" ]
},
"outputs:relativePath": {
"type": "token[]",
"value": [ "foo", "bar" ]
}
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnMakeVector4.ogn | {
"MakeVector4": {
"version": 1,
"description": [
"Merge 4 input values into a single output vector.",
"If the inputs are arrays, the output will be an array of vectors."
],
"uiName": "Make 4-Vector",
"categories": ["math:conversion"],
"tags": ["compose", "combine", "join"],
"scheduling": ["threadsafe"],
"inputs": {
"x": {
"type": ["double", "float", "half", "int", "double[]", "float[]", "half[]", "int[]"],
"uiName": "X",
"description": "The first component of the vector"
},
"y": {
"type": ["double", "float", "half", "int", "double[]", "float[]", "half[]", "int[]"],
"uiName": "Y",
"description": "The second component of the vector"
},
"z": {
"type": ["double", "float", "half", "int", "double[]", "float[]", "half[]", "int[]"],
"uiName": "Z",
"description": "The third component of the vector"
},
"w": {
"type": ["double", "float", "half", "int", "double[]", "float[]", "half[]", "int[]"],
"uiName": "W",
"description": "The fourth component of the vector"
}
},
"outputs": {
"tuple": {
"type": ["double[4]", "float[4]", "half[4]", "int[4]", "double[4][]", "float[4][]", "half[4][]", "int[4][]"],
"uiName": "Vector",
"description": "Output 4-vector"
}
},
"tests" : [
{
"inputs:x": {"type": "float", "value": 42.0}, "inputs:y": {"type": "float", "value": 1.0},
"inputs:z": {"type": "float", "value": 0}, "inputs:w": {"type": "float", "value": 0},
"outputs:tuple": {"type": "float[4]", "value": [42.0, 1.0, 0.0, 0.0]}
},
{
"inputs:x": {"type": "float", "value": 42.0},
"outputs:tuple": {"type": "float[4]", "value": [42.0, 0.0, 0.0, 0.0]}
},
{
"inputs:x": {"type": "float[]", "value": [42,1,0]},
"inputs:y": {"type": "float[]", "value": [0,1,2]},
"inputs:z": {"type": "float[]", "value": [0,2,4]},
"inputs:w": {"type": "float[]", "value": [5,6,7]},
"outputs:tuple": {"type": "float[4][]", "value": [[42,0,0,5],[1,1,2,6],[0,2,4,7]]}
},
{
"inputs:x": {"type": "int", "value": 42}, "inputs:y": {"type": "int", "value": -42},
"inputs:z": {"type": "int", "value": 5}, "inputs:w": {"type": "int", "value": 6},
"outputs:tuple": {"type": "int[4]", "value": [42, -42, 5, 6]}
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnArrayRemoveIndex.cpp | // Copyright (c) 2022-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 <OgnArrayRemoveIndexDatabase.h>
#include <omni/graph/core/StringUtils.h>
#include <omni/graph/core/ogn/ComputeHelpers.h>
#include <carb/logging/Log.h>
#include <algorithm>
namespace omni {
namespace graph {
namespace nodes {
using core::ogn::array;
// unnamed namespace to avoid multiple declaration when linking
namespace {
// helper to wrap a given index from legal range [-arrayLength, arrayLength) to [0:arrayLength)
// This will throw if the wrapped index is out of bounds
size_t tryWrapIndex(int index, size_t arraySize)
{
int wrappedIndex = index;
if (index < 0)
wrappedIndex = static_cast<int>(arraySize) + index;
if (wrappedIndex < 0 || wrappedIndex >= static_cast<int>(arraySize))
throw ogn::compute::InputError(formatString("inputs:index %d is out of range for inputs:array of size %zu", wrappedIndex, arraySize));
return static_cast<size_t>(wrappedIndex);
}
template<typename BaseType>
bool tryComputeAssumingType(OgnArrayRemoveIndexDatabase& db)
{
auto const inputArray = db.inputs.array().template get<BaseType[]>();
size_t const inputArraySize = db.inputs.array().size();
size_t const index = tryWrapIndex(db.inputs.index(), inputArraySize);
if (!inputArray)
return false;
// make sure the types match before copying input into output
if (db.inputs.array().type() != db.outputs.array().type())
{
auto attribute = db.abi_node().iNode->getAttributeByToken(db.abi_node(), outputs::array.m_token);
auto handle = db.outputs.array().abi_handle();
attribute.iAttribute->setResolvedType(attribute, db.inputs.array().type());
db.outputs.array().reset(db.abi_context(), handle, attribute);
}
db.outputs.array().copyData(db.inputs.array());
auto outputArray = db.outputs.array().template get<BaseType[]>();
memcpy(outputArray->data() + index, outputArray->data() + index + 1, sizeof(BaseType) * (inputArraySize - index - 1));
(*outputArray).resize(inputArraySize - 1);
return true;
}
} // namespace
class OgnArrayRemoveIndex
{
public:
static bool compute(OgnArrayRemoveIndexDatabase& db)
{
auto& inputType = db.inputs.array().type();
try
{
switch (inputType.baseType)
{
case BaseDataType::eBool:
return tryComputeAssumingType<bool>(db);
case BaseDataType::eToken:
return tryComputeAssumingType<ogn::Token>(db);
case BaseDataType::eDouble:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<double>(db);
case 2: return tryComputeAssumingType<double[2]>(db);
case 3: return tryComputeAssumingType<double[3]>(db);
case 4: return tryComputeAssumingType<double[4]>(db);
case 9: return tryComputeAssumingType<double[9]>(db);
case 16: return tryComputeAssumingType<double[16]>(db);
}
case BaseDataType::eFloat:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<float>(db);
case 2: return tryComputeAssumingType<float[2]>(db);
case 3: return tryComputeAssumingType<float[3]>(db);
case 4: return tryComputeAssumingType<float[4]>(db);
}
case BaseDataType::eHalf:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<pxr::GfHalf>(db);
case 2: return tryComputeAssumingType<pxr::GfHalf[2]>(db);
case 3: return tryComputeAssumingType<pxr::GfHalf[3]>(db);
case 4: return tryComputeAssumingType<pxr::GfHalf[4]>(db);
}
case BaseDataType::eInt:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<int32_t>(db);
case 2: return tryComputeAssumingType<int32_t[2]>(db);
case 3: return tryComputeAssumingType<int32_t[3]>(db);
case 4: return tryComputeAssumingType<int32_t[4]>(db);
}
;
case BaseDataType::eInt64:
return tryComputeAssumingType<int64_t>(db);
case BaseDataType::eUChar:
return tryComputeAssumingType<unsigned char>(db);
case BaseDataType::eUInt:
return tryComputeAssumingType<uint32_t>(db);
case BaseDataType::eUInt64:
return tryComputeAssumingType<uint64_t>(db);
default: break;
}
db.logWarning("Failed to resolve input types");
}
catch (ogn::compute::InputError const &error)
{
db.logError(error.what());
}
return false;
}
static void onConnectionTypeResolve(const NodeObj& node){
auto const inputArray = node.iNode->getAttributeByToken(node, inputs::array.token());
auto const outputArray = node.iNode->getAttributeByToken(node, outputs::array.token());
auto const inputArrayType = inputArray.iAttribute->getResolvedType(inputArray);
if (inputArrayType.baseType != BaseDataType::eUnknown)
{
std::array<AttributeObj, 2> attrs { inputArray, outputArray };
// all should have the same tuple count
std::array<uint8_t, 2> tupleCounts {
inputArrayType.componentCount,
inputArrayType.componentCount
};
// value type can not be an array because we don't support arrays-of-arrays
std::array<uint8_t, 2> arrayDepths {
1,
1
};
std::array<AttributeRole, 2> rolesBuf {
inputArrayType.role,
AttributeRole::eUnknown
};
node.iNode->resolvePartiallyCoupledAttributes(node, attrs.data(), tupleCounts.data(),
arrayDepths.data(), rolesBuf.data(), attrs.size());
}
}
};
REGISTER_OGN_NODE()
} // namespace nodes
} // namespace graph
} // namespace omni |
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnGetPrimRelationship.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 "OgnGetPrimRelationshipDatabase.h"
#include <omni/graph/core/PreUsdInclude.h>
#include <pxr/usd/sdf/path.h>
#include <pxr/usd/usd/common.h>
#include <pxr/usd/usd/prim.h>
#include <pxr/usd/usd/relationship.h>
#include <pxr/usd/usdUtils/stageCache.h>
#include <omni/graph/core/PostUsdInclude.h>
#include <algorithm>
#include "PrimCommon.h"
namespace omni
{
namespace graph
{
namespace nodes
{
class OgnGetPrimRelationship
{
public:
// Queries relationship data on a prim
static bool compute(OgnGetPrimRelationshipDatabase& db)
{
auto& nodeObj = db.abi_node();
const auto& contextObj = db.abi_context();
auto iContext = contextObj.iContext;
try {
auto primPath = getPrimOrPath(contextObj, nodeObj, inputs::prim.token(), inputs::path.token(),
inputs::usePath.token(), db.getInstanceIndex());
const char* relName = db.tokenToString(db.inputs.name());
if (!relName)
return false;
long int stageId = iContext->getStageId(contextObj);
pxr::UsdStageRefPtr stage = pxr::UsdUtilsStageCache::Get().Find(pxr::UsdStageCache::Id::FromLongInt(stageId));
pxr::UsdPrim prim = stage->GetPrimAtPath(primPath);
if (!prim)
return false;
pxr::UsdRelationship relationship = prim.GetRelationship(pxr::TfToken(relName));
pxr::SdfPathVector targets;
if (relationship.GetTargets(&targets))
{
auto& outputPaths = db.outputs.paths();
outputPaths.resize(targets.size());
std::transform(targets.begin(), targets.end(), outputPaths.begin(),
[&db](const pxr::SdfPath& path) { return db.stringToToken(path.GetText()); });
}
return true;
}
catch(const std::exception& e)
{
db.logError(e.what());
return false;
}
}
static bool updateNodeVersion(const GraphContextObj& context, const NodeObj& nodeObj, int oldVersion, int newVersion)
{
if (oldVersion < newVersion)
{
if (oldVersion < 2)
{
// for older nodes, inputs:usePath must equal true so the prim path method is on by default
const bool val{ true };
nodeObj.iNode->createAttribute(nodeObj, "inputs:usePath", Type(BaseDataType::eBool), &val, nullptr,
kAttributePortType_Input, kExtendedAttributeType_Regular, nullptr);
}
return true;
}
return false;
}
};
REGISTER_OGN_NODE()
}
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnArrayResize.ogn | {
"ArrayResize": {
"version": 1,
"description": [
"Resizes an array. If the new size is larger, zeroed values will be added to the end."
],
"uiName": "Array Resize",
"categories": ["math:array"],
"scheduling": ["threadsafe"],
"inputs": {
"array": {
"type": ["arrays", "bool[]"],
"description": "The array to be modified",
"uiName": "Array"
},
"newSize": {
"type": "int",
"description": "The new size of the array, negative values are treated as size of 0",
"minimum": 0
}
},
"outputs": {
"array": {
"type": ["arrays", "bool[]"],
"description": "The modified array",
"uiName": "Array"
}
},
"tests": [
{
"inputs:array": {"type": "int[]", "value": [41, 42]}, "inputs:newSize": 0,
"outputs:array": {"type": "int[]", "value": []}
},
{
"inputs:array": {"type": "int64[]", "value": []}, "inputs:newSize": 1,
"outputs:array": {"type": "int64[]", "value": [0]}
},
{
"inputs:array": {"type": "int[]", "value": [41, 42]}, "inputs:newSize": 1,
"outputs:array": {"type": "int[]", "value": [41]}
},
{
"inputs:array": {"type": "bool[]", "value": [true, true]}, "inputs:newSize": 1,
"outputs:array": {"type": "bool[]", "value": [true]}
},
{
"inputs:array": {"type": "half[2][]", "value": [[1, 2], [3, 4]]}, "inputs:newSize": 3,
"outputs:array": {"type": "half[2][]", "value": [[1, 2], [3, 4], [0, 0]]}
},
{
"inputs:array": {"type": "half[2][]", "value": []}, "inputs:newSize": 1,
"outputs:array": {"type": "half[2][]", "value": [[0, 0]]}
},
{
"inputs:array": {"type": "float[2][]", "value": [[1, 2], [3, 4]]}, "inputs:newSize": 3,
"outputs:array": {"type": "float[2][]", "value": [[1, 2], [3, 4], [0, 0]]}
},
{
"inputs:array": {"type": "token[]", "value": ["41", "42"]}, "inputs:newSize": 1,
"outputs:array": {"type": "token[]", "value": ["41"]}
},
{
"inputs:array": {"type": "token[]", "value": ["41", "42"]}, "inputs:newSize": 2,
"outputs:array": {"type": "token[]", "value": ["41", "42"]}
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnGetPrimsAtPath.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 <OgnGetPrimsAtPathDatabase.h>
namespace omni
{
namespace graph
{
namespace nodes
{
class OgnGetPrimsAtPath
{
public:
static bool computeVectorized(OgnGetPrimsAtPathDatabase& db, size_t count)
{
if (db.inputs.path().type().arrayDepth > 0)
{
for (size_t idx = 0; idx < count; ++idx)
{
auto& outPrims = db.outputs.prims(idx);
const auto paths = *db.inputs.path(idx).template get<OgnToken[]>();
outPrims.resize(paths.size());
std::transform(paths.begin(), paths.end(), outPrims.begin(),
[&](const auto& p) {
return (p != omni::fabric::kUninitializedToken) ? db.tokenToPath(p) : omni::fabric::kUninitializedPath;
});
}
}
else
{
const auto pathPtr = db.inputs.path().template get<OgnToken>();
if (pathPtr)
{
auto path = pathPtr.vectorized(count);
auto oldPath = db.state.path.vectorized(count);
for (size_t idx = 0; idx < count; ++idx)
{
auto outPrims = db.outputs.prims(idx);
if (oldPath[idx] != path[idx])
{
if (path[idx] != omni::fabric::kUninitializedToken)
{
outPrims.resize(1);
outPrims[0] = db.tokenToPath(path[idx]);
}
else
{
outPrims.resize(0);
}
}
}
}
}
return count;
}
};
REGISTER_OGN_NODE();
} // nodes
} // graph
} // omni
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnMakeVector4.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 <OgnMakeVector4Database.h>
#include <omni/graph/core/ogn/ComputeHelpers.h>
#include <omni/graph/core/ogn/UsdTypes.h>
#include <fstream>
#include <iomanip>
namespace omni
{
namespace graph
{
namespace nodes
{
namespace
{
template <typename Type>
bool tryMakeVector(OgnMakeVector4Database& db)
{
const auto x = db.inputs.x().template get<Type>();
const auto y = db.inputs.y().template get<Type>();
const auto z = db.inputs.z().template get<Type>();
const auto w = db.inputs.w().template get<Type>();
auto vector = db.outputs.tuple().template get<Type[4]>();
if (vector && x && y && z && w)
{
(*vector)[0] = *x;
(*vector)[1] = *y;
(*vector)[2] = *z;
(*vector)[3] = *w;
return true;
}
const auto xArray = db.inputs.x().template get<Type[]>();
const auto yArray = db.inputs.y().template get<Type[]>();
const auto zArray = db.inputs.z().template get<Type[]>();
const auto wArray = db.inputs.w().template get<Type[]>();
auto vectorArray = db.outputs.tuple().template get<Type[][4]>();
if (!vectorArray || !xArray || !yArray || !zArray || !wArray)
{
return false;
}
if (xArray->size() != yArray->size() || xArray->size() != zArray->size() || xArray->size() != wArray->size())
{
throw ogn::compute::InputError("Input arrays of different lengths x:" +
std::to_string(xArray->size()) + ", y:" +
std::to_string(yArray->size()) + ", z:" +
std::to_string(zArray->size()) + ", w:" +
std::to_string(wArray->size()));
}
vectorArray->resize(xArray->size());
for (size_t i = 0; i < vectorArray->size(); i++)
{
(*vectorArray)[i][0] = (*xArray)[i];
(*vectorArray)[i][1] = (*yArray)[i];
(*vectorArray)[i][2] = (*zArray)[i];
(*vectorArray)[i][3] = (*wArray)[i];
}
return true;
}
} // namespace
// Node to merge 4 scalers together to make 4-vector
class OgnMakeVector4
{
public:
static bool compute(OgnMakeVector4Database& db)
{
// Compute the components, if the types are all resolved.
try
{
if (tryMakeVector<double>(db))
return true;
else if (tryMakeVector<float>(db))
return true;
else if (tryMakeVector<pxr::GfHalf>(db))
return true;
else if (tryMakeVector<int32_t>(db))
return true;
else
{
db.logError("Failed to resolve input types");
return false;
}
}
catch (const std::exception& e)
{
db.logError("Vector could not be made: %s", e.what());
return false;
}
return true;
}
static void onConnectionTypeResolve(const NodeObj& nodeObj)
{
auto x = nodeObj.iNode->getAttributeByToken(nodeObj, inputs::x.token());
auto y = nodeObj.iNode->getAttributeByToken(nodeObj, inputs::y.token());
auto z = nodeObj.iNode->getAttributeByToken(nodeObj, inputs::z.token());
auto w = nodeObj.iNode->getAttributeByToken(nodeObj, inputs::w.token());
auto vector = nodeObj.iNode->getAttributeByToken(nodeObj, outputs::tuple.token());
auto xType = vector.iAttribute->getResolvedType(x);
auto yType = vector.iAttribute->getResolvedType(y);
auto zType = vector.iAttribute->getResolvedType(z);
auto wType = vector.iAttribute->getResolvedType(w);
std::array<AttributeObj, 4> attrs{ x, y, z, w };
if (nodeObj.iNode->resolveCoupledAttributes(nodeObj, attrs.data(), attrs.size()))
{
xType = vector.iAttribute->getResolvedType(x);
yType = vector.iAttribute->getResolvedType(y);
zType = vector.iAttribute->getResolvedType(z);
wType = vector.iAttribute->getResolvedType(w);
}
// Require inputs to be resolved before determining outputs' type
if (xType.baseType != BaseDataType::eUnknown && yType.baseType != BaseDataType::eUnknown &&
zType.baseType != BaseDataType::eUnknown && wType.baseType != BaseDataType::eUnknown)
{
std::array<AttributeObj, 5> attrs{ x, y, z, w, vector };
std::array<uint8_t, 5> tuples{ 1, 1, 1, 1, 4 };
std::array<uint8_t, 5> arrays{
xType.arrayDepth,
yType.arrayDepth,
zType.arrayDepth,
wType.arrayDepth,
xType.arrayDepth
};
std::array<AttributeRole, 5> roles{ xType.role, yType.role, zType.role, wType.role, AttributeRole::eNone };
nodeObj.iNode->resolvePartiallyCoupledAttributes(
nodeObj, attrs.data(), tuples.data(), arrays.data(), roles.data(), attrs.size());
}
}
};
REGISTER_OGN_NODE();
}
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnArrayGetSize.ogn | {
"ArrayGetSize": {
"version": 1,
"description": [
"Returns the number of elements in an array"
],
"uiName": "Array Get Size",
"categories": ["math:array"],
"scheduling": ["threadsafe"],
"inputs": {
"array": {
"type": ["arrays", "bool[]"],
"description": "The array in question",
"uiName": "Array"
}
},
"outputs": {
"size": {
"type": "int",
"description": "The size of the array"
}
},
"tests": [
{
"inputs:array": {"type": "int[]", "value": [41, 42]}, "outputs:size": 2
},
{
"inputs:array": {"type": "half[]", "value": [41, 42]}, "outputs:size": 2
},
{
"inputs:array": {"type": "token[]", "value": []}, "outputs:size": 0
},
{
"inputs:array": {"type": "int64[]", "value": [41]}, "outputs:size": 1
},
{
"inputs:array": {"type": "uchar[]", "value": [41, 42]}, "outputs:size": 2
},
{
"inputs:array": {"type": "uint[]", "value": [41, 42]}, "outputs:size": 2
},
{
"inputs:array": {"type": "uint64[]", "value": [41, 42]}, "outputs:size": 2
},
{
"inputs:array": {"type": "bool[]", "value": [false, true]}, "outputs:size": 2
},
{
"inputs:array": {"type": "half[2][]", "value": [[41, 42], [43, 44]]}, "outputs:size": 2
},
{
"inputs:array": {"type": "double[3][]", "value": [[41, 42, 43], [43, 44, 56]]}, "outputs:size": 2
},
{
"inputs:array": {"type": "int[4][]", "value": [[1, 2, 3, 4], [3, 4, 5, 6]]}, "outputs:size": 2
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnGetPrimPaths.ogn | {
"GetPrimPaths": {
"version": 1,
"description": ["Generates a path array from the specified relationship. This is useful when absolute prim paths may change."],
"uiName": "Get Prim Paths",
"categories": ["sceneGraph"],
"scheduling": [ "threadsafe" ],
"inputs": {
"prims": {
"type": "target",
"description": "Relationship to prims on the stage",
"metadata": {
"allowMultiInputs" : 1
}
}
},
"outputs": {
"primPaths": {
"type": "token[]",
"description": "The absolute paths of the given prims as a token array"
}
}
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnArrayFill.ogn | {
"ArrayFill": {
"version": 1,
"description": [
"Creates a copy of the input array, filled with the given value"
],
"uiName": "Array Fill",
"categories": ["math:array"],
"scheduling": ["threadsafe"],
"inputs": {
"array": {
"type": ["arrays", "bool[]"],
"description": "The array to be modified"
},
"fillValue": {
"type": ["array_elements", "bool"],
"description": "The value to be repeated in the new array"
}
},
"outputs": {
"array": {
"type": ["arrays", "bool[]"],
"description": "The modified array"
}
},
"tests": [
{
"inputs:array": {"type": "int[]", "value": [41, 42]}, "inputs:fillValue": {"type": "int", "value": 0},
"outputs:array": {"type": "int[]", "value": [0, 0]}
},
{
"inputs:array": {"type": "int[2][]", "value": [[41, 42], [43,44]]}, "inputs:fillValue": {"type": "int[2]", "value": [1,2]},
"outputs:array": {"type": "int[2][]", "value": [[1, 2], [1,2]]}
},
{
"inputs:array": {"type": "int64[]", "value": [41, 42]}, "inputs:fillValue": {"type": "int64", "value":0},
"outputs:array": {"type": "int64[]", "value": [0, 0]}
},
{
"inputs:array": {"type": "uchar[]", "value": [41, 42]}, "inputs:fillValue": {"type": "uchar", "value":0},
"outputs:array": {"type": "uchar[]", "value": [0, 0]}
},
{
"inputs:array": {"type": "uint[]", "value": [41, 42]}, "inputs:fillValue": {"type": "uint", "value":0},
"outputs:array": {"type": "uint[]", "value": [0, 0]}
},
{
"inputs:array": {"type": "uint64[]", "value": [41, 42]}, "inputs:fillValue": {"type": "uint64", "value":0},
"outputs:array": {"type": "uint64[]", "value": [0, 0]}
},
{
"inputs:array": {"type": "bool[]", "value": [true, true]}, "inputs:fillValue": {"type": "bool", "value":false},
"outputs:array": {"type": "bool[]", "value": [false, false]}
},
{
"inputs:array": {"type": "token[]", "value": ["41", "42"]}, "inputs:fillValue": {"type": "token", "value":""},
"outputs:array": {"type": "token[]", "value": ["", ""]}
},
{
"inputs:array": {"type": "half[2][]", "value": [[1.0, 2.0], [3.0, 4.0]]}, "inputs:fillValue": {"type": "half[2]", "value":[5.0, 6.0]},
"outputs:array": {"type": "half[2][]", "value": [[5.0, 6.0], [5.0, 6.0]]}
},
{
"inputs:array": {"type": "double[3][]", "value": [[1.0, 2.0, 3.0], [3.0, 4.0, 5.0]]}, "inputs:fillValue": {"type": "double[3]", "value":[5.0, 6.0, 7.0]},
"outputs:array": {"type": "double[3][]", "value": [[5.0, 6.0, 7.0], [5.0, 6.0, 7.0]]}
},
{
"inputs:array": {"type": "int[4][]", "value": [[1, 2, 3, 4], [3, 4, 5, 6]]}, "inputs:fillValue": {"type": "int[4]", "value":[5, 6, 7, 8]},
"outputs:array": {"type": "int[4][]", "value": [[5, 6, 7, 8], [5, 6, 7, 8]]}
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnToHalf.ogn | {
"ToHalf": {
"version": 1,
"description": ["Converts the given input to 16 bit float. The node will attempt to convert",
" array and tuple inputs to halfs of the same shape"
],
"uiName": "To Half",
"categories": ["math:conversion"],
"scheduling": ["threadsafe"],
"inputs": {
"value": {
"type": ["numerics", "bool", "bool[]"],
"uiName": "value",
"description": "The numeric value to convert to half"
}
},
"outputs": {
"converted": {
"type": ["half", "half[2]", "half[3]", "half[4]", "half[]", "half[2][]", "half[3][]", "half[4][]"],
"uiName": "Half",
"description": "Output half scaler or array"
}
},
"tests" : [
{
"inputs:value": {"type": "float[]", "value": [] }, "outputs:converted": {"type": "half[]", "value": []}
},
{
"inputs:value": {"type": "double", "value": 2.5}, "outputs:converted": {"type": "half", "value": 2.5}
},
{
"inputs:value": {"type": "int", "value": 42}, "outputs:converted": {"type": "half", "value": 42.0}
},
{
"inputs:value": {"type": "double[2]", "value": [2.5, 2.5] }, "outputs:converted": {"type": "half[2]", "value": [2.5, 2.5]}
},
{
"inputs:value": {"type": "half[3]", "value": [2, 3, 4] }, "outputs:converted": {"type": "half[3]", "value": [2, 3, 4] }
},
{
"inputs:value": {"type": "half[3][]", "value": [[2, 3, 4]] }, "outputs:converted": {"type": "half[3][]", "value": [[2, 3, 4]] }
},
{
"inputs:value": {"type": "int[2][]", "value": [[1, 2],[3, 4]] }, "outputs:converted": {"type": "half[2][]", "value": [[1.0, 2.0],[3.0, 4.0]] }
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnArrayFill.cpp | // Copyright (c) 2022-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 <OgnArrayFillDatabase.h>
#include <omni/graph/core/ogn/ComputeHelpers.h>
#include <omni/graph/core/ogn/string.h>
#include <omni/graph/core/ogn/Types.h>
#include <algorithm>
namespace omni {
namespace graph {
namespace nodes {
// unnamed namespace to avoid multiple declaration when linking
namespace {
// Custom implementation of std::rotate.
// Using std::fill fails to build on Linux when the underlying type is a tuple (eg int[3])
template< class ForwardIt, class T >
void fillArray(ForwardIt first, ForwardIt last, const T& value)
{
for (; first != last; ++first) {
memcpy(&*first, &value, sizeof(*first));
}
}
template<typename BaseType>
bool tryComputeAssumingType(OgnArrayFillDatabase& db)
{
auto const inputArray = db.inputs.array().template get<BaseType[]>();
size_t const inputArraySize = db.inputs.array().size();
auto const fillValue = db.inputs.fillValue().template get<BaseType>();
auto outputArray = db.outputs.array().template get<BaseType[]>();
if (!fillValue || !inputArray)
return false;
(*outputArray).resize(inputArraySize);
fillArray(outputArray->begin(), outputArray->end(), *fillValue);
return true;
}
} // namespace
class OgnArrayFill
{
public:
static bool compute(OgnArrayFillDatabase& db)
{
auto& inputType = db.inputs.fillValue().type();
try
{
switch (inputType.baseType)
{
case BaseDataType::eBool:
return tryComputeAssumingType<bool>(db);
case BaseDataType::eToken:
return tryComputeAssumingType<ogn::Token>(db);
case BaseDataType::eDouble:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<double>(db);
case 2: return tryComputeAssumingType<double[2]>(db);
case 3: return tryComputeAssumingType<double[3]>(db);
case 4: return tryComputeAssumingType<double[4]>(db);
case 9: return tryComputeAssumingType<double[9]>(db);
case 16: return tryComputeAssumingType<double[16]>(db);
default: break;
}
case BaseDataType::eFloat:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<float>(db);
case 2: return tryComputeAssumingType<float[2]>(db);
case 3: return tryComputeAssumingType<float[3]>(db);
case 4: return tryComputeAssumingType<float[4]>(db);
default: break;
}
case BaseDataType::eHalf:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<pxr::GfHalf>(db);
case 2: return tryComputeAssumingType<pxr::GfHalf[2]>(db);
case 3: return tryComputeAssumingType<pxr::GfHalf[3]>(db);
case 4: return tryComputeAssumingType<pxr::GfHalf[4]>(db);
default: break;
}
case BaseDataType::eInt:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<int32_t>(db);
case 2: return tryComputeAssumingType<int32_t[2]>(db);
case 3: return tryComputeAssumingType<int32_t[3]>(db);
case 4: return tryComputeAssumingType<int32_t[4]>(db);
default: break;
}
;
case BaseDataType::eInt64:
return tryComputeAssumingType<int64_t>(db);
case BaseDataType::eUChar:
return tryComputeAssumingType<unsigned char>(db);
case BaseDataType::eUInt:
return tryComputeAssumingType<uint32_t>(db);
case BaseDataType::eUInt64:
return tryComputeAssumingType<uint64_t>(db);
default: break;
}
db.logWarning("Failed to resolve input types");
}
catch (ogn::compute::InputError const &error)
{
db.logError(error.what());
}
return false;
}
static void onConnectionTypeResolve(const NodeObj& node){
auto const inputArray = node.iNode->getAttributeByToken(node, inputs::array.token());
auto const inputFillValue = node.iNode->getAttributeByToken(node, inputs::fillValue.token());
auto const outputArray = node.iNode->getAttributeByToken(node, outputs::array.token());
auto const inputArrayType = inputArray.iAttribute->getResolvedType(inputArray);
if (inputArrayType.baseType != BaseDataType::eUnknown)
{
std::array<AttributeObj, 3> attrs { inputArray, inputFillValue, outputArray };
// all should have the same tuple count
std::array<uint8_t, 3> tupleCounts {
inputArrayType.componentCount,
inputArrayType.componentCount,
inputArrayType.componentCount
};
// value type can not be an array because we don't support arrays-of-arrays
std::array<uint8_t, 3> arrayDepths {
1,
0,
1
};
std::array<AttributeRole, 3> rolesBuf {
inputArrayType.role,
AttributeRole::eUnknown,
AttributeRole::eUnknown
};
node.iNode->resolvePartiallyCoupledAttributes(node, attrs.data(), tupleCounts.data(),
arrayDepths.data(), rolesBuf.data(), attrs.size());
}
}
};
REGISTER_OGN_NODE()
} // namespace nodes
} // namespace graph
} // namespace omni |
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnArrayRemoveValue.cpp | // Copyright (c) 2022-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 <OgnArrayRemoveValueDatabase.h>
#include <omni/graph/core/ogn/ComputeHelpers.h>
#include <omni/graph/core/ogn/string.h>
#include <omni/graph/core/ogn/Types.h>
#include <algorithm>
namespace omni {
namespace graph {
namespace nodes {
// unnamed namespace to avoid multiple declaration when linking
namespace {
// Custom implementation of std::remove_if.
// Using std::remove_if fails to build when the underlying type is a tuple (eg int[3])
template<class ForwardIt, class UnaryPredicate>
int removeArray(ForwardIt first, ForwardIt last, UnaryPredicate p)
{
int outputArraySize = 0;
first = std::find_if(first, last, p);
if (first != last) {
for(ForwardIt i = first; ++i != last; ) {
if (!p(*i)) {
memcpy(&*first++, &*i, sizeof(*first));
outputArraySize++;
}
}
}
return outputArraySize;
}
template<typename BaseType>
bool tryComputeAssumingType(OgnArrayRemoveValueDatabase& db)
{
auto const inputArray = db.inputs.array().template get<BaseType[]>();
auto const value = db.inputs.value().template get<BaseType>();
bool const removeAll = db.inputs.removeAll();
size_t const inputArraySize = db.inputs.array().size();
size_t const stride = sizeof(BaseType);
db.outputs.found() = false;
if (!value || !inputArray)
return false;
// make sure the types match before copying input into output
if (db.inputs.array().type() != db.outputs.array().type())
{
auto attribute = db.abi_node().iNode->getAttributeByToken(db.abi_node(), outputs::array.m_token);
auto handle = db.outputs.array().abi_handle();
attribute.iAttribute->setResolvedType(attribute, db.inputs.array().type());
db.outputs.array().reset(db.abi_context(), handle, attribute);
}
db.outputs.array().copyData(db.inputs.array());
auto equalsValue = [&value, &stride](auto &i) { return memcmp(&i, &*value, stride) == 0; };
auto const it = std::find_if(inputArray->begin(), inputArray->end(), equalsValue);
if (it == inputArray->end()){
return true;
}
auto outputArray = db.outputs.array().template get<BaseType[]>();
if (removeAll) {
const int outputArraySize = removeArray(outputArray->begin(), outputArray->end(), equalsValue);
(*outputArray).resize(outputArraySize);
}
else {
const int index = static_cast<int>(it - inputArray->begin());
memcpy(outputArray->data() + index, outputArray->data() + index + 1, stride * (inputArraySize - index - 1));
(*outputArray).resize(inputArraySize - 1);
}
db.outputs.found() = true;
return true;
}
} // namespace
class OgnArrayRemoveValue
{
public:
static bool compute(OgnArrayRemoveValueDatabase& db)
{
auto& inputType = db.inputs.value().type();
try
{
switch (inputType.baseType)
{
case BaseDataType::eBool:
return tryComputeAssumingType<bool>(db);
case BaseDataType::eToken:
return tryComputeAssumingType<ogn::Token>(db);
case BaseDataType::eDouble:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<double>(db);
case 2: return tryComputeAssumingType<double[2]>(db);
case 3: return tryComputeAssumingType<double[3]>(db);
case 4: return tryComputeAssumingType<double[4]>(db);
case 9: return tryComputeAssumingType<double[9]>(db);
case 16: return tryComputeAssumingType<double[16]>(db);
default: break;
}
case BaseDataType::eFloat:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<float>(db);
case 2: return tryComputeAssumingType<float[2]>(db);
case 3: return tryComputeAssumingType<float[3]>(db);
case 4: return tryComputeAssumingType<float[4]>(db);
default: break;
}
case BaseDataType::eHalf:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<pxr::GfHalf>(db);
case 2: return tryComputeAssumingType<pxr::GfHalf[2]>(db);
case 3: return tryComputeAssumingType<pxr::GfHalf[3]>(db);
case 4: return tryComputeAssumingType<pxr::GfHalf[4]>(db);
default: break;
}
case BaseDataType::eInt:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<int32_t>(db);
case 2: return tryComputeAssumingType<int32_t[2]>(db);
case 3: return tryComputeAssumingType<int32_t[3]>(db);
case 4: return tryComputeAssumingType<int32_t[4]>(db);
default: break;
}
;
case BaseDataType::eInt64:
return tryComputeAssumingType<int64_t>(db);
case BaseDataType::eUChar:
return tryComputeAssumingType<unsigned char>(db);
case BaseDataType::eUInt:
return tryComputeAssumingType<uint32_t>(db);
case BaseDataType::eUInt64:
return tryComputeAssumingType<uint64_t>(db);
default: break;
}
db.logWarning("Failed to resolve input types");
}
catch (ogn::compute::InputError const &error)
{
db.logError(error.what());
}
return false;
}
static void onConnectionTypeResolve(const NodeObj& node){
auto const inputArray = node.iNode->getAttributeByToken(node, inputs::array.token());
auto const inputValue = node.iNode->getAttributeByToken(node, inputs::value.token());
auto const outputArray = node.iNode->getAttributeByToken(node, outputs::array.token());
auto const inputArrayType = inputArray.iAttribute->getResolvedType(inputArray);
if (inputArrayType.baseType != BaseDataType::eUnknown)
{
std::array<AttributeObj, 3> attrs { inputArray, inputValue, outputArray };
// all should have the same tuple count
std::array<uint8_t, 3> tupleCounts {
inputArrayType.componentCount,
inputArrayType.componentCount,
inputArrayType.componentCount
};
// value type can not be an array because we don't support arrays-of-arrays
std::array<uint8_t, 3> arrayDepths {
1,
0,
1
};
std::array<AttributeRole, 3> rolesBuf {
inputArrayType.role,
AttributeRole::eUnknown,
AttributeRole::eUnknown
};
node.iNode->resolvePartiallyCoupledAttributes(node, attrs.data(), tupleCounts.data(),
arrayDepths.data(), rolesBuf.data(), attrs.size());
}
}
};
REGISTER_OGN_NODE()
} // namespace nodes
} // namespace graph
} // namespace omni |
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnCompare.cpp | // Copyright (c) 2021-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 <OgnCompareDatabase.h>
#include <functional>
#include <omni/graph/core/ogn/ComputeHelpers.h>
#include <omni/graph/core/ogn/string.h>
#include <omni/graph/core/ogn/Types.h>
#include <carb/logging/Log.h>
namespace omni
{
namespace graph
{
namespace nodes
{
namespace
{
template<typename T>
std::function<bool(const T&, const T&)> getOperation(OgnCompareDatabase& db, NameToken operation)
{
// Find the desired comparison
std::function<bool(const T&, const T&)> fn;
if (operation == db.tokens.gt) fn = [](const T& a, const T& b){ return a > b; };
else if (operation == db.tokens.lt) fn =[](const T& a, const T& b){ return a < b; };
else if (operation == db.tokens.ge) fn = [](const T& a, const T& b){ return a >= b; };
else if (operation == db.tokens.le) fn = [](const T& a, const T& b){ return a <= b; };
else if (operation == db.tokens.eq) fn = [](const T& a, const T& b){ return a == b; };
else if (operation == db.tokens.ne) fn = [](const T& a, const T& b){ return a != b; };
else
{
throw ogn::compute::InputError("Failed to resolve token " + std::string(db.tokenToString(operation)) +
", expected one of (>,<,>=,<=,==,!=)");
}
return fn;
}
template<>
std::function<bool(const OgnToken&, const OgnToken&)> getOperation(OgnCompareDatabase& db, NameToken operation)
{
std::function<bool(const OgnToken&, const OgnToken&)> fn;
if (operation == db.tokens.eq)
fn = [](const OgnToken& a, const OgnToken& b) { return a == b; };
else if (operation == db.tokens.ne)
fn = [](const OgnToken& a, const OgnToken& b) { return a != b; };
else if (operation == db.tokens.gt || operation == db.tokens.lt || operation == db.tokens.ge || operation == db.tokens.le)
throw ogn::compute::InputError("Operation " + std::string(db.tokenToString(operation)) +
" not supported for Tokens, expected one of (==,!=)");
else
throw ogn::compute::InputError("Failed to resolve token " + std::string(db.tokenToString(operation)) +
", expected one of (>,<,>=,<=,==,!=)");
return fn;
}
template<typename T>
bool tryComputeAssumingType(OgnCompareDatabase& db, NameToken operation, size_t count)
{
auto op = getOperation<T>(db, operation);
auto functor = [&](auto const& a, auto const& b, auto& result)
{
result = op(a, b);
};
return ogn::compute::tryComputeWithArrayBroadcasting<T, T, bool>(db.inputs.a(), db.inputs.b(), db.outputs.result(), functor, count);
}
template<typename T, size_t N>
bool tryComputeAssumingType(OgnCompareDatabase& db, NameToken operation, size_t count)
{
auto op = getOperation<T>(db, operation);
auto functor = [&](auto const& a, auto const& b, auto& result)
{
// Lexicographical comparison of tuples
result = true;
for (size_t i = 0; i < N; i++)
{
if (i < (N - 1) && (a[i] == b[i]))
continue;
else if (op(a[i], b[i]))
{
result = true;
break;
}
else
{
result = false;
break;
}
}
};
return ogn::compute::tryComputeWithArrayBroadcasting<T[N], T[N], bool>(db.inputs.a(), db.inputs.b(), db.outputs.result(), functor, count);
}
bool tryComputeAssumingString(OgnCompareDatabase& db, NameToken operation, size_t count)
{
auto op = getOperation<ogn::const_string>(db, operation);
for (size_t idx = 0; idx < count; ++idx)
{
auto stringA = db.inputs.a(idx).get<const char[]>();
auto stringB = db.inputs.b(idx).get<const char[]>();
*(db.outputs.result(idx).get<bool>()) = op(stringA(), stringB());
}
return true;
}
} // namespace
class OgnCompare
{
public:
static bool computeVectorized(OgnCompareDatabase& db, size_t count)
{
try
{
auto& aType = db.inputs.a().type();
auto& bType = db.inputs.b().type();
if (aType.baseType != bType.baseType || aType.componentCount != bType.componentCount)
throw ogn::compute::InputError("Failed to resolve input types");
const auto& operation = db.inputs.operation();
if ((operation != db.tokens.gt) and (operation != db.tokens.lt) and (operation != db.tokens.ge) and
(operation != db.tokens.le) and (operation != db.tokens.eq) and (operation != db.tokens.ne))
{
std::string op{ "Unknown" };
char const* opStr = db.tokenToString(operation);
if (opStr)
op = opStr;
throw ogn::compute::InputError("Unrecognized operation '" + op + std::string("'"));
}
auto node = db.abi_node();
auto opAttrib = node.iNode->getAttributeByToken(node, inputs::operation.m_token);
bool isOpConstant = opAttrib.iAttribute->isRuntimeConstant(opAttrib);
using FUNC_SIG = bool (*)(OgnCompareDatabase& db, NameToken operation, size_t count);
auto repeatWork = [&](FUNC_SIG const& func)
{
if (isOpConstant)
{
return func(db, operation, count);
}
bool ret = true;
while (count)
{
ret = func(db, operation, 1) && ret;
db.moveToNextInstance();
--count;
}
return ret;
};
switch (aType.baseType)
{
case BaseDataType::eBool:
return repeatWork(tryComputeAssumingType<bool>);
case BaseDataType::eDouble:
switch (aType.componentCount)
{
case 1: return repeatWork(tryComputeAssumingType<double>);
case 2: return repeatWork(tryComputeAssumingType<double, 2>);
case 3: return repeatWork(tryComputeAssumingType<double, 3>);
case 4: return repeatWork(tryComputeAssumingType<double, 4>);
case 9: return repeatWork(tryComputeAssumingType<double, 9>);
case 16: return repeatWork(tryComputeAssumingType<double, 16>);
}
case BaseDataType::eFloat:
switch (aType.componentCount)
{
case 1: return repeatWork(tryComputeAssumingType<float>);
case 2: return repeatWork(tryComputeAssumingType<float, 2>);
case 3: return repeatWork(tryComputeAssumingType<float, 3>);
case 4: return repeatWork(tryComputeAssumingType<float, 4>);
}
case BaseDataType::eInt:
switch (aType.componentCount)
{
case 1: return repeatWork(tryComputeAssumingType<int32_t>);
case 2: return repeatWork(tryComputeAssumingType<int32_t, 2>);
case 3: return repeatWork(tryComputeAssumingType<int32_t, 3>);
case 4: return repeatWork(tryComputeAssumingType<int32_t, 4>);
}
case BaseDataType::eHalf:
return repeatWork(tryComputeAssumingType<pxr::GfHalf>);
case BaseDataType::eInt64:
return repeatWork(tryComputeAssumingType<int64_t>);
case BaseDataType::eUChar:
if (aType.role == AttributeRole::eText && bType.role == AttributeRole::eText &&
aType.arrayDepth == 1 && bType.arrayDepth == 1 && aType.componentCount == 1 &&
bType.componentCount == 1)
{
return repeatWork(tryComputeAssumingString);
}
return repeatWork(tryComputeAssumingType<unsigned char>);
case BaseDataType::eUInt:
return repeatWork(tryComputeAssumingType<uint32_t>);
case BaseDataType::eToken:
return repeatWork(tryComputeAssumingType<OgnToken>);
case BaseDataType::eUInt64:
return repeatWork(tryComputeAssumingType<uint64_t>);
default:
break;
}
throw ogn::compute::InputError("Failed to resolve input types");
}
catch (ogn::compute::InputError &error)
{
db.logError("%s", error.what());
}
return false;
}
static void onConnectionTypeResolve(const NodeObj& node){
auto a = node.iNode->getAttributeByToken(node, inputs::a.token());
auto b = node.iNode->getAttributeByToken(node, inputs::b.token());
auto result = node.iNode->getAttributeByToken(node, outputs::result.token());
auto aType = a.iAttribute->getResolvedType(a);
auto bType = b.iAttribute->getResolvedType(b);
// Require inputs to be resolved before determining result's type
if (aType.baseType != BaseDataType::eUnknown && bType.baseType != BaseDataType::eUnknown)
{
const bool isStringInput = (aType.baseType == BaseDataType::eUChar && bType.baseType == BaseDataType::eUChar
&& aType.role == AttributeRole::eText && bType.role == AttributeRole::eText
&& aType.arrayDepth == 1 && bType.arrayDepth == 1
&& aType.componentCount == 1 && bType.componentCount == 1);
const uint8_t resultArrayDepth = isStringInput ? 0 : std::max(aType.arrayDepth, bType.arrayDepth);
Type resultType(BaseDataType::eBool, 1, resultArrayDepth);
result.iAttribute->setResolvedType(result, resultType);
}
}
};
REGISTER_OGN_NODE()
} // namespace nodes
} // namespace graph
} // namespace omni
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnBundleConstructor.py | """
Module contains the OmniGraph node implementation of BundleConstructor
"""
import omni.graph.core as og
class OgnBundleConstructor:
"""Node to create a bundle out of dynamic attributes"""
@staticmethod
def compute(db) -> bool:
"""Compute the bundle from the dynamic input attributes"""
# Start with an empty output bundle.
output_bundle = db.outputs.bundle
output_bundle.clear()
# Walk the list of node attribute, looking for dynamic inputs
for attribute in db.abi_node.get_attributes():
if attribute.is_dynamic():
if attribute.get_port_type() != og.AttributePortType.ATTRIBUTE_PORT_TYPE_INPUT:
continue
if attribute.get_extended_type() != og.ExtendedAttributeType.EXTENDED_ATTR_TYPE_REGULAR:
db.log_warn(f"Cannot add extended attribute types like '{attribute.get_name()}' to a bundle")
continue
if attribute.get_resolved_type().base_type in [og.BaseDataType.RELATIONSHIP]:
db.log_warn(f"Cannot add bundle attribute types like '{attribute.get_name()}' to a bundle")
continue
# The bundled name does not need the port namespace
new_name = attribute.get_name().replace("inputs:", "")
output_bundle.insert((attribute.get_resolved_type(), new_name))
return True
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnArrayRemoveIndex.ogn | {
"ArrayRemoveIndex": {
"version": 1,
"description": [
"Removes an element of an array by index. If the given index is negative it will be an offset from the end of the array."
],
"uiName": "Array Remove Index",
"categories": ["math:array"],
"scheduling": ["threadsafe"],
"inputs": {
"array": {
"type": ["arrays", "bool[]"],
"description": "The array to be modified",
"uiName": "Array"
},
"index": {
"type": "int",
"description": "The index into the array, a negative value indexes from the end of the array",
"uiName": "Index"
}
},
"outputs": {
"array": {
"type": ["arrays", "bool[]"],
"description": "The modified array",
"uiName": "Array"
}
},
"tests": [
{
"inputs:array": {"type": "int[]", "value": [41, 42]}, "inputs:index": 0,
"outputs:array": {"type": "int[]", "value": [42]}
},
{
"inputs:array": {"type": "bool[]", "value": [true, false]}, "inputs:index": 0,
"outputs:array": {"type": "bool[]", "value": [false]}
},
{
"inputs:array": {"type": "half[2][]", "value": [[1, 2], [3, 4]]}, "inputs:index": 1,
"outputs:array": {"type": "half[2][]", "value": [[1, 2]]}
},
{
"inputs:array": {"type": "token[]", "value": ["41", "42"]}, "inputs:index": -2,
"outputs:array": {"type": "token[]", "value": ["42"]}
},
{
"inputs:array": {"type": "int[]", "value": [41, 42, 43, 41]}, "inputs:index": 1,
"outputs:array": {"type": "int[]", "value": [41, 43, 41]}
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnGetPrimPaths.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 <OgnGetPrimPathsDatabase.h>
namespace omni
{
namespace graph
{
namespace nodes
{
class OgnGetPrimPaths
{
public:
static size_t computeVectorized(OgnGetPrimPathsDatabase& db, size_t count)
{
auto pathInterface = carb::getCachedInterface<omni::fabric::IPath>();
auto tokenInterface = carb::getCachedInterface<omni::fabric::IToken>();
if (!pathInterface || !tokenInterface)
{
CARB_LOG_ERROR("Failed to initialize path or token interface");
return 0;
}
for (size_t p = 0; p < count; p++)
{
const auto& prims = db.inputs.prims(p);
auto& primPaths = db.outputs.primPaths(p);
primPaths.resize(prims.size());
for (size_t i = 0; i < prims.size(); i++)
{
primPaths[i] = tokenInterface->getHandle(pathInterface->getText(prims[i]));
}
}
return count;
}
};
REGISTER_OGN_NODE();
} // nodes
} // graph
} // omni
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnToUint64.ogn | {
"ToUint64": {
"version": 1,
"description": [
"Converts the given input to a 64 bit unsigned integer of the same shape.",
"Negative integers are converted by adding them to 2**64, decimal numbers are truncated."
],
"uiName": "To Uint64",
"categories": ["math:conversion"],
"scheduling": ["threadsafe"],
"inputs": {
"value": {
"type": ["bool", "int", "uint", "int64", "float", "double", "half", "uchar",
"bool[]", "int[]", "uint[]", "int64[]", "float[]", "double[]", "half[]", "uchar[]"],
"uiName": "value",
"description": "The numeric value to convert to uint64"
}
},
"outputs": {
"converted": {
"type": ["uint64","uint64[]"],
"uiName": "Uint64",
"description": "Converted output"
}
},
"tests" : [
{
"inputs:value": {"type": "float[]", "value": [] }, "outputs:converted": {"type": "uint64[]", "value": []}
},
{
"inputs:value": {"type": "double", "value": 2.1}, "outputs:converted": {"type": "uint64", "value": 2}
},
{
"inputs:value": {"type": "half", "value": 2.9}, "outputs:converted": {"type": "uint64", "value": 2}
},
{
"inputs:value": {"type": "int", "value": 42}, "outputs:converted": {"type": "uint64", "value": 42}
},
{
"inputs:value": {"type": "int64", "value": 42}, "outputs:converted": {"type": "uint64", "value": 42}
},
{
"inputs:value": {"type": "bool[]", "value": [true, false]}, "outputs:converted": {"type": "uint64[]", "value": [1, 0]}
},
{
"inputs:value": {"type": "half[]", "value": [2, 3, 4] }, "outputs:converted": {"type": "uint64[]", "value": [2, 3, 4] }
},
{
"inputs:value": {"type": "uint[]", "value": [2, 3, 4] }, "outputs:converted": {"type": "uint64[]", "value": [2, 3, 4] }
},
{
"inputs:value": {"type": "int64[]", "value": [2, 3, -4] }, "outputs:converted": {"type": "uint64[]", "value": [2, 3, 18446744073709551612] }
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnToFloat.ogn | {
"ToFloat": {
"version": 1,
"description": ["Converts the given input to 32 bit float. The node will attempt to convert",
" array and tuple inputs to floats of the same shape"
],
"uiName": "To Float",
"categories": ["math:conversion"],
"scheduling": ["threadsafe"],
"inputs": {
"value": {
"type": ["numerics", "bool", "bool[]"],
"uiName": "value",
"description": "The numeric value to convert to float"
}
},
"outputs": {
"converted": {
"type": ["float", "float[2]", "float[3]", "float[4]", "float[]", "float[2][]", "float[3][]", "float[4][]"],
"uiName": "Float",
"description": "Output float scaler or array"
}
},
"tests" : [
{
"inputs:value": {"type": "float[]", "value": [] }, "outputs:converted": {"type": "float[]", "value": []}
},
{
"inputs:value": {"type": "double", "value": 2.1}, "outputs:converted": {"type": "float", "value": 2.1}
},
{
"inputs:value": {"type": "int", "value": 42}, "outputs:converted": {"type": "float", "value": 42.0}
},
{
"inputs:value": {"type": "double[2]", "value": [2.1, 2.1] }, "outputs:converted": {"type": "float[2]", "value": [2.1, 2.1]}
},
{
"inputs:value": {"type": "half[3]", "value": [2, 3, 4] }, "outputs:converted": {"type": "float[3]", "value": [2, 3, 4] }
},
{
"inputs:value": {"type": "half[3][]", "value": [[2, 3, 4]] }, "outputs:converted": {"type": "float[3][]", "value": [[2, 3, 4]] }
},
{
"inputs:value": {"type": "int[2][]", "value": [[1, 2],[3, 4]] }, "outputs:converted": {"type": "float[2][]", "value": [[1.0, 2.0],[3.0, 4.0]] }
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnBreakVector4.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 <OgnBreakVector4Database.h>
#include <omni/graph/core/ogn/ComputeHelpers.h>
#include <omni/graph/core/ogn/UsdTypes.h>
#include <fstream>
#include <iomanip>
namespace omni
{
namespace graph
{
namespace nodes
{
namespace
{
template <typename Type>
bool tryBreakVector(OgnBreakVector4Database& db)
{
const auto vector = db.inputs.tuple().template get<Type[4]>();
auto x = db.outputs.x().template get<Type>();
auto y = db.outputs.y().template get<Type>();
auto z = db.outputs.z().template get<Type>();
auto w = db.outputs.w().template get<Type>();
if (!vector || !x || !y || !z || !w){
return false;
}
*x = (*vector)[0];
*y = (*vector)[1];
*z = (*vector)[2];
*w = (*vector)[3];
return true;
}
} // namespace
// Node to break a 4-vector into it's component scalers
class OgnBreakVector4
{
public:
static bool compute(OgnBreakVector4Database& db)
{
// Compute the components, if the types are all resolved.
try
{
if (tryBreakVector<double>(db))
return true;
else if (tryBreakVector<float>(db))
return true;
else if (tryBreakVector<pxr::GfHalf>(db))
return true;
else if (tryBreakVector<int32_t>(db))
return true;
else
{
db.logWarning("Failed to resolve input types");
}
}
catch (const std::exception& e)
{
db.logError("Vector could not be broken: %s", e.what());
return false;
}
return true;
}
static void onConnectionTypeResolve(const NodeObj& nodeObj)
{
auto vector = nodeObj.iNode->getAttributeByToken(nodeObj, inputs::tuple.token());
auto x = nodeObj.iNode->getAttributeByToken(nodeObj, outputs::x.token());
auto y = nodeObj.iNode->getAttributeByToken(nodeObj, outputs::y.token());
auto z = nodeObj.iNode->getAttributeByToken(nodeObj, outputs::z.token());
auto w = nodeObj.iNode->getAttributeByToken(nodeObj, outputs::w.token());
auto vectorType = vector.iAttribute->getResolvedType(vector);
// Require inputs to be resolved before determining outputs' type
if (vectorType.baseType != BaseDataType::eUnknown)
{
std::array<AttributeObj, 5> attrs{ vector, x, y, z, w };
std::array<uint8_t, 5> tuples{ 4, 1, 1, 1, 1};
std::array<uint8_t, 5> arrays{ 0, 0, 0, 0, 0 };
std::array<AttributeRole, 5> roles{ vectorType.role, AttributeRole::eNone, AttributeRole::eNone, AttributeRole::eNone, AttributeRole::eNone};
nodeObj.iNode->resolvePartiallyCoupledAttributes(nodeObj, attrs.data(), tuples.data(), arrays.data(), roles.data(), attrs.size());
}
}
};
REGISTER_OGN_NODE();
}
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnGetParentPrims.cpp | // Copyright (c) 2020-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 <OgnGetParentPrimsDatabase.h>
namespace omni
{
namespace graph
{
namespace nodes
{
class OgnGetParentPrims
{
public:
static size_t computeVectorized(OgnGetParentPrimsDatabase& db, size_t count)
{
auto pathInterface = carb::getCachedInterface<omni::fabric::IPath>();
if (!pathInterface)
{
CARB_LOG_ERROR("Failed to initialize path or token interface");
return 0;
}
for (size_t i = 0; i < count; i++)
{
const auto& prims = db.inputs.prims(i);
auto& parentPaths = db.outputs.parentPrims(i);
parentPaths.resize(prims.size());
std::transform(prims.begin(), prims.end(), parentPaths.begin(),
[&](const auto& p) { return pathInterface->getParent(p); });
}
return count;
}
};
REGISTER_OGN_NODE();
} // nodes
} // graph
} // omni
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnEndsWith.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 <OgnEndsWithDatabase.h>
#include <algorithm>
namespace omni
{
namespace graph
{
namespace nodes
{
class OgnEndsWith
{
public:
static bool compute(OgnEndsWithDatabase& db)
{
auto const& suffix = db.inputs.suffix();
auto const& value = db.inputs.value();
auto iters = std::mismatch(suffix.rbegin(), suffix.rend(), value.rbegin(), value.rend());
db.outputs.isSuffix() = (iters.first == suffix.rend());
return true;
}
};
REGISTER_OGN_NODE();
} // nodes
} // graph
} // omni
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnArrayResize.cpp | // Copyright (c) 2022-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 <OgnArrayResizeDatabase.h>
#include <omni/graph/core/StringUtils.h>
#include <omni/graph/core/ogn/ComputeHelpers.h>
#include <carb/logging/Log.h>
#include <algorithm>
namespace omni {
namespace graph {
namespace nodes {
using core::ogn::array;
// unnamed namespace to avoid multiple declaration when linking
namespace {
template<typename BaseType>
bool tryComputeAssumingType(OgnArrayResizeDatabase& db)
{
auto const inputArray = db.inputs.array().template get<BaseType[]>();
size_t const inputArraySize = db.inputs.array().size();
size_t newSize = db.inputs.newSize();
auto outputArray = db.outputs.array().template get<BaseType[]>();
if (!inputArray)
return false;
if (newSize < 0)
newSize = 0;
(*outputArray).resize(newSize);
memcpy(outputArray->data(), inputArray->data(), sizeof(BaseType) * (std::min(inputArraySize, newSize)));
if (newSize > inputArraySize)
memset(outputArray->data() + inputArraySize, 0, sizeof(BaseType) * (newSize - inputArraySize));
return true;
}
} // namespace
class OgnArrayResize
{
public:
static bool compute(OgnArrayResizeDatabase& db)
{
auto& inputType = db.inputs.array().type();
try
{
switch (inputType.baseType)
{
case BaseDataType::eBool:
return tryComputeAssumingType<bool>(db);
case BaseDataType::eToken:
return tryComputeAssumingType<ogn::Token>(db);
case BaseDataType::eDouble:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<double>(db);
case 2: return tryComputeAssumingType<double[2]>(db);
case 3: return tryComputeAssumingType<double[3]>(db);
case 4: return tryComputeAssumingType<double[4]>(db);
case 9: return tryComputeAssumingType<double[9]>(db);
case 16: return tryComputeAssumingType<double[16]>(db);
default: break;
}
case BaseDataType::eFloat:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<float>(db);
case 2: return tryComputeAssumingType<float[2]>(db);
case 3: return tryComputeAssumingType<float[3]>(db);
case 4: return tryComputeAssumingType<float[4]>(db);
default: break;
}
case BaseDataType::eHalf:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<pxr::GfHalf>(db);
case 2: return tryComputeAssumingType<pxr::GfHalf[2]>(db);
case 3: return tryComputeAssumingType<pxr::GfHalf[3]>(db);
case 4: return tryComputeAssumingType<pxr::GfHalf[4]>(db);
default: break;
}
case BaseDataType::eInt:
switch (inputType.componentCount)
{
case 1: return tryComputeAssumingType<int32_t>(db);
case 2: return tryComputeAssumingType<int32_t[2]>(db);
case 3: return tryComputeAssumingType<int32_t[3]>(db);
case 4: return tryComputeAssumingType<int32_t[4]>(db);
default: break;
}
;
case BaseDataType::eInt64:
return tryComputeAssumingType<int64_t>(db);
case BaseDataType::eUChar:
return tryComputeAssumingType<unsigned char>(db);
case BaseDataType::eUInt:
return tryComputeAssumingType<uint32_t>(db);
case BaseDataType::eUInt64:
return tryComputeAssumingType<uint64_t>(db);
default: break;
}
db.logWarning("Failed to resolve input types");
}
catch (ogn::compute::InputError const &error)
{
db.logError(error.what());
}
return false;
}
static void onConnectionTypeResolve(const NodeObj& node){
auto const inputArray = node.iNode->getAttributeByToken(node, inputs::array.token());
auto const outputArray = node.iNode->getAttributeByToken(node, outputs::array.token());
auto const inputArrayType = inputArray.iAttribute->getResolvedType(inputArray);
if (inputArrayType.baseType != BaseDataType::eUnknown)
{
std::array<AttributeObj, 2> attrs { inputArray, outputArray };
// all should have the same tuple count
std::array<uint8_t, 3> tupleCounts {
inputArrayType.componentCount,
inputArrayType.componentCount
};
// value type can not be an array because we don't support arrays-of-arrays
std::array<uint8_t, 2> arrayDepths {
1,
1
};
std::array<AttributeRole, 2> rolesBuf {
inputArrayType.role,
AttributeRole::eUnknown
};
node.iNode->resolvePartiallyCoupledAttributes(node, attrs.data(), tupleCounts.data(),
arrayDepths.data(), rolesBuf.data(), attrs.size());
}
}
};
REGISTER_OGN_NODE()
} // namespace nodes
} // namespace graph
} // namespace omni |
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnBreakVector4.ogn | {
"BreakVector4": {
"version": 1,
"description": ["Split vector into 4 component values."],
"uiName": "Break 4-Vector",
"categories": ["math:conversion"],
"tags": ["decompose", "separate", "isolate"],
"scheduling": ["threadsafe"],
"inputs": {
"tuple": {
"type": ["double[4]", "float[4]", "half[4]", "int[4]"],
"uiName": "Vector",
"description": "4-vector to be broken"
}
},
"outputs": {
"x": {
"type": ["double", "float", "half", "int"],
"uiName": "X",
"description": "The first component of the vector"
},
"y": {
"type": ["double", "float", "half", "int"],
"uiName": "Y",
"description": "The second component of the vector"
},
"z": {
"type": ["double", "float", "half", "int"],
"uiName": "Z",
"description": "The third component of the vector"
},
"w": {
"type": ["double", "float", "half", "int"],
"uiName": "W",
"description": "The fourth component of the vector"
}
},
"tests" : [
{
"inputs:tuple": {"type": "float[4]", "value": [42.0, 1.0, 2.0, 3.0]},
"outputs:x": {"type": "float", "value": 42.0}, "outputs:y": {"type": "float", "value": 1.0},
"outputs:z": {"type": "float", "value": 2.0}, "outputs:w": {"type": "float", "value": 3.0}
},
{
"inputs:tuple": {"type": "int[4]", "value": [42, -42, 5, -5]},
"outputs:x": {"type": "int", "value": 42}, "outputs:y": {"type": "int", "value": -42},
"outputs:z": {"type": "int", "value": 5}, "outputs:w": {"type": "int", "value": -5}
},
{
"inputs:tuple": {"type": "quatd[4]", "value": [42.0, 1.0, 2.0, 3.0]},
"outputs:x": {"type": "double", "value": 42.0}, "outputs:y": {"type": "double", "value": 1.0},
"outputs:z": {"type": "double", "value": 2.0}, "outputs:w": {"type": "double", "value": 3.0}
}
]
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/utility/OgnConstantPrims.ogn | {
"ConstantPrims": {
"version": 2,
"description": ["Returns the paths of one or more targetd prims"],
"uiName": "Constant Prims",
"categories": ["sceneGraph"],
"scheduling": [ "threadsafe" ],
"inputs": {
"value": {
"type": "target",
"description": "The input prim paths",
"metadata": {
"outputOnly": "1",
"allowMultiInputs": "1"
}
}
}
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/variant/OgnGetVariantNames.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 <OgnGetVariantNamesDatabase.h>
namespace omni::graph::nodes
{
class OgnGetVariantNames
{
public:
static bool compute(OgnGetVariantNamesDatabase& 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 variantNames = variantSet.GetVariantNames();
db.outputs.variantNames().resize(variantNames.size());
for (size_t i = 0; i < variantNames.size(); i++)
{
db.outputs.variantNames()[i] = db.stringToToken(variantNames[i].c_str());
}
return true;
}
catch (const warning& e)
{
db.logWarning(e.what());
}
catch (const std::exception& e)
{
db.logError(e.what());
}
db.outputs.variantNames().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.ogn | {
"SetVariantSelection": {
"version": 2,
"categories": [
"graph:action",
"sceneGraph",
"variants"
],
"icon": {
"path": "Variant.svg"
},
"scheduling": [
"usd-write"
],
"description": "Set the variant selection on a prim",
"uiName": "Set Variant Selection",
"inputs": {
"execIn": {
"type": "execution",
"description": "The input execution"
},
"prim": {
"type": "target",
"description": "The prim with the variantSet"
},
"variantName": {
"type": "token",
"description": "The variant name"
},
"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/OgnClearVariantSelection.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 <OgnClearVariantSelectionDatabase.h>
namespace omni::graph::nodes
{
class OgnClearVariantSelection
{
public:
static bool compute(OgnClearVariantSelectionDatabase& 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);
if (db.inputs.setVariant())
{
bool success = variantSet.SetVariantSelection("");
if (!success)
throw warning(std::string("Failed to clear variant selection for variant set ") + variantSetName);
}
else
{
removeLocalOpinion(prim, variantSetName);
}
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/OgnGetVariantNames.ogn | {
"GetVariantNames": {
"version": 2,
"categories": [
"graph:action",
"sceneGraph",
"variants"
],
"icon": {
"path": "Variant.svg"
},
"scheduling": [
"usd-read"
],
"description": "Get variant names from a variantSet on a prim",
"uiName": "Get Variant Names",
"inputs": {
"prim": {
"type": "target",
"description": "The prim with the variantSet"
},
"variantSetName": {
"type": "token",
"description": "The variantSet name"
}
},
"outputs": {
"variantNames": {
"type": "token[]",
"description": "List of variant names"
}
}
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/variant/OgnGetVariantSelection.ogn | {
"GetVariantSelection": {
"version": 2,
"categories": [
"graph:action",
"sceneGraph",
"variants"
],
"icon": {
"path": "Variant.svg"
},
"scheduling": [
"usd-read"
],
"description": "Get the variant selection on a prim",
"uiName": "Get Variant Selection",
"inputs": {
"prim": {
"type": "target",
"description": "The prim with the variantSet"
},
"variantSetName": {
"type": "token",
"description": "The variantSet name"
}
},
"outputs": {
"variantName": {
"type": "token",
"description": "The variant name"
}
}
}
}
|
omniverse-code/kit/exts/omni.graph.nodes/omni/graph/nodes/ogn/nodes/variant/OgnGetVariantSetNames.ogn | {
"GetVariantSetNames": {
"version": 2,
"categories": [
"graph:action",
"sceneGraph",
"variants"
],
"icon": {
"path": "Variant.svg"
},
"scheduling": [
"usd-read"
],
"description": "Get variantSet names on a prim",
"uiName": "Get Variant Set Names",
"inputs": {
"prim": {
"type": "target",
"description": "The prim with the variantSet"
}
},
"outputs": {
"variantSetNames": {
"type": "token[]",
"description": "List of variantSet names"
}
}
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.