mesh builder v2
This commit is contained in:
@@ -41,10 +41,53 @@ MeshMaterialFrame::MeshMaterialFrame(const MeshBuilderData& data,
|
||||
_isMother = true;
|
||||
}
|
||||
|
||||
MeshMaterialFrame::MeshMaterialFrame(const MeshBuilder2Data& data,
|
||||
const u32& frameIndex,
|
||||
const u32& materialIndex) {
|
||||
TYRA_ASSERT(materialIndex < data.materials.size(), "Provided index \"",
|
||||
materialIndex, "\" is out of range");
|
||||
|
||||
TYRA_ASSERT(frameIndex < data.materials[materialIndex]->frames.size(),
|
||||
"Provided index \"", frameIndex, "\" is out of range");
|
||||
|
||||
id = rand() % 1000000;
|
||||
|
||||
auto* frame = data.materials[materialIndex]->frames[frameIndex];
|
||||
|
||||
TYRA_ASSERT(frame->count > 0, "Vertex count must be greater than 0");
|
||||
TYRA_ASSERT(frame->vertices != nullptr, "Vertex array can't be null");
|
||||
TYRA_ASSERT(frame->normals != nullptr, "Normal array can't be null");
|
||||
TYRA_ASSERT(frame->textureCoords != nullptr,
|
||||
"Texture coordinate array can't be null");
|
||||
TYRA_ASSERT(frame->colors != nullptr, "Color array can't be null");
|
||||
|
||||
bbox = new BBox(frame->vertices, frame->count);
|
||||
|
||||
count = frame->count;
|
||||
vertices = frame->vertices;
|
||||
|
||||
if (data.normalsEnabled)
|
||||
normals = frame->normals;
|
||||
else
|
||||
normals = nullptr;
|
||||
|
||||
if (data.textureCoordsEnabled)
|
||||
textureCoords = frame->textureCoords;
|
||||
else
|
||||
textureCoords = nullptr;
|
||||
|
||||
if (data.lightMapEnabled)
|
||||
colors = frame->colors;
|
||||
else
|
||||
colors = nullptr;
|
||||
|
||||
_isMother = true;
|
||||
}
|
||||
|
||||
MeshMaterialFrame::MeshMaterialFrame(const MeshMaterialFrame& frame) {
|
||||
id = rand() % 1000000;
|
||||
|
||||
vertexCount = frame.vertexCount;
|
||||
count = frame.count;
|
||||
|
||||
vertices = frame.vertices;
|
||||
normals = frame.normals;
|
||||
@@ -66,6 +109,74 @@ MeshMaterialFrame::~MeshMaterialFrame() {
|
||||
}
|
||||
}
|
||||
|
||||
void MeshMaterialFrame::allocateVertices(const MeshBuilderData& data,
|
||||
const u32& frameIndex,
|
||||
const u32& materialIndex) {
|
||||
count = data.materials[materialIndex]->count; // faces count
|
||||
vertices = new Vec4[count];
|
||||
|
||||
TYRA_ASSERT(count > 0, "Vertex count must be greater than 0");
|
||||
|
||||
auto* rolled = data.frames[frameIndex]->vertices;
|
||||
auto* faces = data.materials[materialIndex]->vertexFaces;
|
||||
|
||||
TYRA_ASSERT(rolled != nullptr, "Vertices are required");
|
||||
TYRA_ASSERT(faces != nullptr, "Vertex faces are required");
|
||||
|
||||
for (u32 i = 0; i < count; i++) vertices[i] = rolled[faces[i]];
|
||||
}
|
||||
|
||||
void MeshMaterialFrame::allocateTextureCoords(const MeshBuilderData& data,
|
||||
const u32& frameIndex,
|
||||
const u32& materialIndex) {
|
||||
textureCoords = nullptr;
|
||||
if (!data.textureCoordsEnabled) return;
|
||||
|
||||
textureCoords = new Vec4[count];
|
||||
|
||||
auto* rolled = data.frames[frameIndex]->textureCoords;
|
||||
auto* faces = data.materials[materialIndex]->textureCoordFaces;
|
||||
|
||||
TYRA_ASSERT(rolled != nullptr, "Texture coordinates are required");
|
||||
TYRA_ASSERT(faces != nullptr, "Texture coordinate faces are required");
|
||||
|
||||
for (u32 i = 0; i < count; i++) textureCoords[i] = rolled[faces[i]];
|
||||
}
|
||||
|
||||
void MeshMaterialFrame::allocateNormals(const MeshBuilderData& data,
|
||||
const u32& frameIndex,
|
||||
const u32& materialIndex) {
|
||||
normals = nullptr;
|
||||
if (!data.normalsEnabled) return;
|
||||
|
||||
normals = new Vec4[count];
|
||||
|
||||
auto* rolled = data.frames[frameIndex]->normals;
|
||||
auto* faces = data.materials[materialIndex]->normalFaces;
|
||||
|
||||
TYRA_ASSERT(rolled != nullptr, "Normals are required");
|
||||
TYRA_ASSERT(faces != nullptr, "Normal faces are required");
|
||||
|
||||
for (u32 i = 0; i < count; i++) normals[i] = rolled[faces[i]];
|
||||
}
|
||||
|
||||
void MeshMaterialFrame::allocateColors(const MeshBuilderData& data,
|
||||
const u32& frameIndex,
|
||||
const u32& materialIndex) {
|
||||
colors = nullptr;
|
||||
if (!data.manyColorsEnabled) return;
|
||||
|
||||
colors = new Color[count];
|
||||
|
||||
auto* rolled = data.frames[frameIndex]->colors;
|
||||
auto* faces = data.materials[materialIndex]->colorFaces;
|
||||
|
||||
TYRA_ASSERT(rolled != nullptr, "Colors are required");
|
||||
TYRA_ASSERT(faces != nullptr, "Color faces are required");
|
||||
|
||||
for (u32 i = 0; i < count; i++) colors[i] = rolled[faces[i]];
|
||||
}
|
||||
|
||||
std::string MeshMaterialFrame::getPrint(const char* name) const {
|
||||
std::stringstream res;
|
||||
if (name) {
|
||||
@@ -76,31 +187,31 @@ std::string MeshMaterialFrame::getPrint(const char* name) const {
|
||||
res << std::fixed << std::setprecision(2);
|
||||
|
||||
res << "Id: " << id << ", " << std::endl;
|
||||
res << "Vertex count: " << vertexCount << ", " << std::endl;
|
||||
res << "Vertex count: " << count << ", " << std::endl;
|
||||
res << "BBox: " << bbox->getPrint() << ", " << std::endl;
|
||||
|
||||
res << "Vertices: ";
|
||||
for (u32 i = 0; i < vertexCount; i++) {
|
||||
for (u32 i = 0; i < count; i++) {
|
||||
res << vertices[i].getPrint() << ", " << std::endl;
|
||||
}
|
||||
|
||||
if (normals) {
|
||||
res << "Normals: ";
|
||||
for (u32 i = 0; i < vertexCount; i++) {
|
||||
for (u32 i = 0; i < count; i++) {
|
||||
res << normals[i].getPrint() << ", " << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (textureCoords) {
|
||||
res << "TextureCoords: ";
|
||||
for (u32 i = 0; i < vertexCount; i++) {
|
||||
for (u32 i = 0; i < count; i++) {
|
||||
res << textureCoords[i].getPrint() << ", " << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (colors) {
|
||||
res << "Colors: ";
|
||||
for (u32 i = 0; i < vertexCount; i++) {
|
||||
for (u32 i = 0; i < count; i++) {
|
||||
res << colors[i].getPrint() << ", " << std::endl;
|
||||
}
|
||||
}
|
||||
@@ -110,72 +221,4 @@ std::string MeshMaterialFrame::getPrint(const char* name) const {
|
||||
return res.str();
|
||||
}
|
||||
|
||||
void MeshMaterialFrame::allocateVertices(const MeshBuilderData& data,
|
||||
const u32& frameIndex,
|
||||
const u32& materialIndex) {
|
||||
vertexCount = data.materials[materialIndex]->count; // faces count
|
||||
vertices = new Vec4[vertexCount];
|
||||
|
||||
TYRA_ASSERT(vertexCount > 0, "Vertex count must be greater than 0");
|
||||
|
||||
auto* rolled = data.frames[frameIndex]->vertices;
|
||||
auto* faces = data.materials[materialIndex]->vertexFaces;
|
||||
|
||||
TYRA_ASSERT(rolled != nullptr, "Vertices are required");
|
||||
TYRA_ASSERT(faces != nullptr, "Vertex faces are required");
|
||||
|
||||
for (u32 i = 0; i < vertexCount; i++) vertices[i] = rolled[faces[i]];
|
||||
}
|
||||
|
||||
void MeshMaterialFrame::allocateTextureCoords(const MeshBuilderData& data,
|
||||
const u32& frameIndex,
|
||||
const u32& materialIndex) {
|
||||
textureCoords = nullptr;
|
||||
if (!data.textureCoordsEnabled) return;
|
||||
|
||||
textureCoords = new Vec4[vertexCount];
|
||||
|
||||
auto* rolled = data.frames[frameIndex]->textureCoords;
|
||||
auto* faces = data.materials[materialIndex]->textureCoordFaces;
|
||||
|
||||
TYRA_ASSERT(rolled != nullptr, "Texture coordinates are required");
|
||||
TYRA_ASSERT(faces != nullptr, "Texture coordinate faces are required");
|
||||
|
||||
for (u32 i = 0; i < vertexCount; i++) textureCoords[i] = rolled[faces[i]];
|
||||
}
|
||||
|
||||
void MeshMaterialFrame::allocateNormals(const MeshBuilderData& data,
|
||||
const u32& frameIndex,
|
||||
const u32& materialIndex) {
|
||||
normals = nullptr;
|
||||
if (!data.normalsEnabled) return;
|
||||
|
||||
normals = new Vec4[vertexCount];
|
||||
|
||||
auto* rolled = data.frames[frameIndex]->normals;
|
||||
auto* faces = data.materials[materialIndex]->normalFaces;
|
||||
|
||||
TYRA_ASSERT(rolled != nullptr, "Normals are required");
|
||||
TYRA_ASSERT(faces != nullptr, "Normal faces are required");
|
||||
|
||||
for (u32 i = 0; i < vertexCount; i++) normals[i] = rolled[faces[i]];
|
||||
}
|
||||
|
||||
void MeshMaterialFrame::allocateColors(const MeshBuilderData& data,
|
||||
const u32& frameIndex,
|
||||
const u32& materialIndex) {
|
||||
colors = nullptr;
|
||||
if (!data.manyColorsEnabled) return;
|
||||
|
||||
colors = new Color[vertexCount];
|
||||
|
||||
auto* rolled = data.frames[frameIndex]->colors;
|
||||
auto* faces = data.materials[materialIndex]->colorFaces;
|
||||
|
||||
TYRA_ASSERT(rolled != nullptr, "Colors are required");
|
||||
TYRA_ASSERT(faces != nullptr, "Color faces are required");
|
||||
|
||||
for (u32 i = 0; i < vertexCount; i++) colors[i] = rolled[faces[i]];
|
||||
}
|
||||
|
||||
} // namespace Tyra
|
||||
|
||||
Reference in New Issue
Block a user