NvGLModel* loadModelFromFile(const char *pFileName, float rescale )
{
    int32_t length;
    char *modelData = NvAssetLoaderRead(pFileName, length);

    NvGLModel* pModel = new NvGLModel;

    pModel->loadModelFromObjData(modelData);
    pModel->rescaleModel(rescale);
    pModel->initBuffers();

    NvAssetLoaderFree(modelData);

    return pModel;
}
NvGLModel* NormalBlendedDecal::loadModel(const char *model_filename)
{
    // Load model data for scene geometry
    int32_t length;
    char *modelData = NvAssetLoaderRead(model_filename, length);
    NvGLModel* model = new NvGLModel();
    model->loadModelFromObjData(modelData);
    model->rescaleModel(1.0f);
    model->initBuffers(true, true);

    NvAssetLoaderFree(modelData);

    CHECK_GL_ERROR();
    return model;
}
void CascadedShadowMappingRenderer::initGeometry(const unsigned int& knightCount)
{
    const float floorSize = 50.0f;
    const float halfFloorSize = floorSize / 2.0f;
    // Add floor to models.
    FloorModel* floor = new FloorModel();
    NvGLModel* floorGL = new NvGLModel(floor);
    floorGL->computeCenter();
    floorGL->initBuffers();
    nv::matrix4f floorModelMatrix;
    floorModelMatrix.set_scale(halfFloorSize);
    nv::vec3f floorMaterialColor(1.0f, 1.0f, 1.0f);
    ModelData floorData = { floorGL, floorModelMatrix, floorMaterialColor };
    m_models.push_back(floorGL);
    m_modelInstances.push_back(floorData);

    // Add knights.
    KnightNvModel* knight = new KnightNvModel();
    NvGLModel* knightGL = new NvGLModel(knight);
    knightGL->computeCenter();
    knightGL->initBuffers();
    m_models.push_back(knightGL);
    for (unsigned int row = 0; row < knightCount; ++row) {
        for (unsigned int col = 0; col < knightCount; ++col) {
            nv::matrix4f knightModelMatrix;
            nv::matrix4f scale, translate;
            scale.set_scale(5.0f);
            nv::translation(translate, -halfFloorSize + row * 5.0f + 2.5f, 1.75767496f, -halfFloorSize + col * 5.0f + 2.5f);
            knightModelMatrix = translate * scale;
            nv::vec3f knightMaterialColor(1.0f, 1.0f, 1.0f);
            ModelData knightData = { knightGL, knightModelMatrix, knightMaterialColor };
            m_modelInstances.push_back(knightData);
        }
    }

}