#include "PolygonNode.h"

#include "Polygon.h"
#include "SceneInfo.h"
#include "SceneModel.h"

PolygonNode::PolygonNode(const Transform& t)
	: GeometryNode(t)
{

}

PolygonNode::~PolygonNode()
{

}

PolygonNode::Type PolygonNode::getType()
{
	return Type::Polygon;
}

void PolygonNode::setPoints(const std::vector<Point>& points)
{
	mPoints = points;
	mGeometryIsDirty = true;
}

void PolygonNode::createOrUpdateGeometry(SceneInfo* sceneInfo)
{
    if (!mBackgroundItem)
    {
        if (sceneInfo->mSupportsGeometryPrimitives)
        {
            auto polygon = std::make_unique<ntk::Polygon>(mPoints);
            mBackgroundItem = std::make_unique<SceneModel>(std::move(polygon));
        }
        else
        {
            //auto mesh = MeshPrimitives::buildRectangleAsTriMesh();
            //mBackgroundItem = std::make_unique<SceneModel>(std::move(mesh));
        }
        mBackgroundItem->setName(mName + "_Model");
    }
    else
    {
        if (sceneInfo->mSupportsGeometryPrimitives)
        {
            auto polygon = std::make_unique<ntk::Polygon>(mPoints);
            mBackgroundItem->updateGeometry(std::move(polygon));
        }
    }
}