
#include <WFX/scene/GeometryFactory.h>
#include <WFX/scene/TextureManager.h>

using namespace WFX::scene;
using namespace WFX::math;

TriMesh* GeometryFactory::getTriangleTriMesh(const Color& c1,
                                             const Color& c2,
                                             const Color& c3) {
    TriMesh* r = new TriMesh();
    r->VertexCount = 3;
    r->Vertices = new Vector3[r->VertexCount];
    r->Vertices[0] = Vector3(-1.0f, -1.0f, 0.0f);
    r->Vertices[1] = Vector3( 1.0f, -1.0f, 0.0f);
    r->Vertices[2] = Vector3( 0.0f,  1.0f, 0.0f);
    
    r->Colors = new Color[r->VertexCount];
    r->Colors[0] = c1;
    r->Colors[1] = c2;
    r->Colors[2] = c3;

    r->FaceCount = 1;
    r->Connectivity = new UInt[r->FaceCount*3];
    r->Connectivity[0] = 0;
    r->Connectivity[1] = 1;
    r->Connectivity[2] = 2;

    r->calcNormals();
    return r;
}

TriMesh* GeometryFactory::getTexTriangle(const std::string& fn) {
    TriMesh* r = new TriMesh();
    r->VertexCount = 3;
    r->Vertices = new Vector3[r->VertexCount];
    r->Vertices[0] = Vector3(-1.0f, -1.0f, 0.0f);
    r->Vertices[1] = Vector3( 1.0f, -1.0f, 0.0f);
    r->Vertices[2] = Vector3( 0.0f,  1.0f, 0.0f);
   
    r->TexCoords = new Vector2[r->VertexCount];
    r->TexCoords[0] = Vector2(0, 0);
    r->TexCoords[1] = Vector2(1, 0);
    r->TexCoords[2] = Vector2(1, 1);
   
    r->FaceCount = 1;
    r->Connectivity = new UInt[r->FaceCount*3];
    r->Connectivity[0] = 0;
    r->Connectivity[1] = 1;
    r->Connectivity[2] = 2;

    //r->getMaterial()->setTexture(TextureManager::getInstance().regTexture(WFX::io::File(fn)));
    r->getMaterial()->setTexture(TextureManager::getInstance().regTexture(fn));
    r->calcNormals();
    return r;
}


