// 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
