85 lines
1.9 KiB
C++
85 lines
1.9 KiB
C++
#include "brush.h"
|
|
#include "rendering.h"
|
|
#include "tier0/platform.h"
|
|
#include "tier1/utlvector.h"
|
|
|
|
void CBrushEntity::Precache()
|
|
{
|
|
|
|
}
|
|
|
|
void CBrushEntity::Spawn()
|
|
{
|
|
|
|
};
|
|
|
|
void CBrushEntity::Destroy()
|
|
{
|
|
|
|
}
|
|
void CBrushEntity::Think( float fDelta )
|
|
{
|
|
|
|
};
|
|
|
|
|
|
void C_BrushEntity::Precache()
|
|
{
|
|
CBrushEntity* pBrushEntity = dynamic_cast<CBrushEntity*>(pEntity);
|
|
if (!pBrushEntity)
|
|
Plat_FatalErrorFunc("pEntity is not a CBrushEntity");
|
|
}
|
|
|
|
void C_BrushEntity::Spawn()
|
|
{
|
|
struct Vertex_t
|
|
{
|
|
float position[3];
|
|
float uv[2];
|
|
};
|
|
|
|
pAlbedo = ITextureManager::LoadTexture("gfx/bricks.png");
|
|
CBrushEntity* pBrushEntity = (CBrushEntity*)pEntity;
|
|
uint32_t numVertices = 15*pBrushEntity->m_mesh.GetSize();
|
|
vertexBuffer = IBrushRenderer::CreateVertexBuffer(numVertices*4);
|
|
Vertex_t *pTriangles = (Vertex_t*)vertexBuffer->Map();
|
|
uint32_t i = 0;
|
|
for (auto &triangle: pBrushEntity->m_mesh)
|
|
{
|
|
pTriangles[i].position[0] = triangle.location[0];
|
|
pTriangles[i].position[1] = triangle.location[1];
|
|
pTriangles[i].position[2] = triangle.location[2];
|
|
pTriangles[i].uv[0] = triangle.uv[0];
|
|
pTriangles[i].uv[1] = triangle.uv[1];
|
|
pTriangles[i+1].position[0] = triangle.location[3];
|
|
pTriangles[i+1].position[1] = triangle.location[4];
|
|
pTriangles[i+1].position[2] = triangle.location[5];
|
|
pTriangles[i+1].uv[0] = triangle.uv[2];
|
|
pTriangles[i+1].uv[1] = triangle.uv[3];
|
|
pTriangles[i+2].position[0] = triangle.location[6];
|
|
pTriangles[i+2].position[1] = triangle.location[7];
|
|
pTriangles[i+2].position[2] = triangle.location[8];
|
|
pTriangles[i+2].uv[0] = triangle.uv[4];
|
|
pTriangles[i+2].uv[1] = triangle.uv[5];
|
|
i+=3;
|
|
}
|
|
vertexBuffer->Unmap();
|
|
|
|
mesh = IBrushRenderer::CreateMesh();
|
|
mesh->SetVertexBuffer(vertexBuffer);
|
|
|
|
};
|
|
|
|
void C_BrushEntity::Destroy()
|
|
{
|
|
|
|
}
|
|
void C_BrushEntity::Think( float fDelta )
|
|
{
|
|
material.m.albedo = ITextureManager::GetTexture(pAlbedo);
|
|
IBrushRenderer::SetMaterial(&material);
|
|
mesh->Draw();
|
|
};
|
|
|
|
|