added utility functions for writing chunk data to a file, and moved the chunk identifiers (which wouldn't compile anyway, lol) to these utility functions
This commit is contained in:
parent
c1cf4d58f0
commit
6346c34f36
|
@ -80,6 +80,7 @@
|
|||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\chunks\chunks.cpp" />
|
||||
<ClCompile Include="src\main.cpp" />
|
||||
<ClCompile Include="src\md2\md2.cpp" />
|
||||
<ClCompile Include="src\ms3d\ms3d.cpp" />
|
||||
|
@ -90,6 +91,7 @@
|
|||
<ItemGroup>
|
||||
<ClInclude Include="src\assets\color.h" />
|
||||
<ClInclude Include="src\assets\material.h" />
|
||||
<ClInclude Include="src\chunks\chunks.h" />
|
||||
<ClInclude Include="src\chunks\materials.h" />
|
||||
<ClInclude Include="src\chunks\normals.h" />
|
||||
<ClInclude Include="src\chunks\texcoords.h" />
|
||||
|
|
132
MeshConverter/src/chunks/chunks.cpp
Normal file
132
MeshConverter/src/chunks/chunks.cpp
Normal file
|
@ -0,0 +1,132 @@
|
|||
#include "chunks.h"
|
||||
|
||||
void WriteFileHeader(FILE *fp)
|
||||
{
|
||||
}
|
||||
|
||||
void WriteChunk(VerticesChunk *chunk, FILE *fp)
|
||||
{
|
||||
uint32_t size = chunk->GetSize();
|
||||
if (size == 0)
|
||||
return;
|
||||
|
||||
fputs("VTX", fp);
|
||||
fwrite(&size, 4, 1, fp);
|
||||
fwrite(&chunk->count, 4, 1, fp);
|
||||
|
||||
for (uint32_t i = 0; i < chunk->count; ++i)
|
||||
{
|
||||
fwrite(&chunk->vertices[i].x, sizeof(float), 1, fp);
|
||||
fwrite(&chunk->vertices[i].y, sizeof(float), 1, fp);
|
||||
fwrite(&chunk->vertices[i].z, sizeof(float), 1, fp);
|
||||
}
|
||||
}
|
||||
|
||||
void WriteChunk(NormalsChunk *chunk, FILE *fp)
|
||||
{
|
||||
uint32_t size = chunk->GetSize();
|
||||
if (size == 0)
|
||||
return;
|
||||
|
||||
fputs("NRL", fp);
|
||||
fwrite(&size, 4, 1, fp);
|
||||
fwrite(&chunk->count, 4, 1, fp);
|
||||
|
||||
for (uint32_t i = 0; i < chunk->count; ++i)
|
||||
{
|
||||
fwrite(&chunk->normals[i].x, sizeof(float), 1, fp);
|
||||
fwrite(&chunk->normals[i].y, sizeof(float), 1, fp);
|
||||
fwrite(&chunk->normals[i].z, sizeof(float), 1, fp);
|
||||
}
|
||||
}
|
||||
|
||||
void WriteChunk(TexCoordsChunk *chunk, FILE *fp)
|
||||
{
|
||||
uint32_t size = chunk->GetSize();
|
||||
if (size == 0)
|
||||
return;
|
||||
|
||||
fputs("TXT", fp);
|
||||
fwrite(&size, 4, 1, fp);
|
||||
fwrite(&chunk->count, 4, 1, fp);
|
||||
|
||||
for (uint32_t i = 0; i < chunk->count; ++i)
|
||||
{
|
||||
fwrite(&chunk->texCoords[i].x, sizeof(float), 1, fp);
|
||||
fwrite(&chunk->texCoords[i].y, sizeof(float), 1, fp);
|
||||
}
|
||||
}
|
||||
|
||||
void WriteChunk(MaterialsChunk *chunk, FILE *fp)
|
||||
{
|
||||
uint32_t size = chunk->GetSize();
|
||||
if (size == 0)
|
||||
return;
|
||||
|
||||
fputs("MTL", fp);
|
||||
fwrite(&size, 4, 1, fp);
|
||||
fwrite(&chunk->count, 4, 1, fp);
|
||||
|
||||
for (uint32_t i = 0; i < chunk->count; ++i)
|
||||
{
|
||||
Material *m = &chunk->materials[i];
|
||||
|
||||
fwrite(m->name.c_str(), m->name.length(), 1, fp);
|
||||
char ch = '\0';
|
||||
fwrite(&ch, 1, 1, fp);
|
||||
|
||||
fwrite(&m->ambient.r, sizeof(float), 1, fp);
|
||||
fwrite(&m->ambient.g, sizeof(float), 1, fp);
|
||||
fwrite(&m->ambient.b, sizeof(float), 1, fp);
|
||||
fwrite(&m->ambient.a, sizeof(float), 1, fp);
|
||||
|
||||
fwrite(&m->diffuse.r, sizeof(float), 1, fp);
|
||||
fwrite(&m->diffuse.g, sizeof(float), 1, fp);
|
||||
fwrite(&m->diffuse.b, sizeof(float), 1, fp);
|
||||
fwrite(&m->diffuse.a, sizeof(float), 1, fp);
|
||||
|
||||
fwrite(&m->specular.r, sizeof(float), 1, fp);
|
||||
fwrite(&m->specular.g, sizeof(float), 1, fp);
|
||||
fwrite(&m->specular.b, sizeof(float), 1, fp);
|
||||
fwrite(&m->specular.a, sizeof(float), 1, fp);
|
||||
|
||||
fwrite(&m->emissive.r, sizeof(float), 1, fp);
|
||||
fwrite(&m->emissive.g, sizeof(float), 1, fp);
|
||||
fwrite(&m->emissive.b, sizeof(float), 1, fp);
|
||||
fwrite(&m->emissive.a, sizeof(float), 1, fp);
|
||||
|
||||
fwrite(&m->shininess, sizeof(float), 1, fp);
|
||||
|
||||
fwrite(&m->opacity, sizeof(float), 1, fp);
|
||||
}
|
||||
}
|
||||
|
||||
void WriteChunk(TrianglesChunk *chunk, FILE *fp)
|
||||
{
|
||||
uint32_t size = chunk->GetSize();
|
||||
if (size == 0)
|
||||
return;
|
||||
|
||||
fputs("TRI", fp);
|
||||
fwrite(&size, 4, 1, fp);
|
||||
fwrite(&chunk->count, 4, 1, fp);
|
||||
|
||||
for (uint32_t i = 0; i < chunk->count; ++i)
|
||||
{
|
||||
Triangle *t = &chunk->triangles[i];
|
||||
|
||||
fwrite(&t->vertices[0], sizeof(uint32_t), 1, fp);
|
||||
fwrite(&t->vertices[1], sizeof(uint32_t), 1, fp);
|
||||
fwrite(&t->vertices[2], sizeof(uint32_t), 1, fp);
|
||||
|
||||
fwrite(&t->normals[0], sizeof(uint32_t), 1, fp);
|
||||
fwrite(&t->normals[1], sizeof(uint32_t), 1, fp);
|
||||
fwrite(&t->normals[2], sizeof(uint32_t), 1, fp);
|
||||
|
||||
fwrite(&t->texCoords[0], sizeof(uint32_t), 1, fp);
|
||||
fwrite(&t->texCoords[1], sizeof(uint32_t), 1, fp);
|
||||
fwrite(&t->texCoords[2], sizeof(uint32_t), 1, fp);
|
||||
|
||||
fwrite(&t->materialIndex, sizeof(uint32_t), 1, fp);
|
||||
}
|
||||
}
|
23
MeshConverter/src/chunks/chunks.h
Normal file
23
MeshConverter/src/chunks/chunks.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
#ifndef __CHUNKS_CHUNKS_H_INCLUDED__
|
||||
#define __CHUNKS_CHUNKS_H_INCLUDED__
|
||||
|
||||
#include "../common.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void WriteFileHeader(FILE *fp);
|
||||
|
||||
// to be perfectly honest, i don't care to come up with a really elegant solution for this converter tool :p
|
||||
|
||||
#include "vertices.h"
|
||||
#include "normals.h"
|
||||
#include "texcoords.h"
|
||||
#include "materials.h"
|
||||
#include "triangles.h"
|
||||
|
||||
void WriteChunk(VerticesChunk *chunk, FILE *fp);
|
||||
void WriteChunk(NormalsChunk *chunk, FILE *fp);
|
||||
void WriteChunk(TexCoordsChunk *chunk, FILE *fp);
|
||||
void WriteChunk(MaterialsChunk *chunk, FILE *fp);
|
||||
void WriteChunk(TrianglesChunk *chunk, FILE *fp);
|
||||
|
||||
#endif
|
|
@ -6,8 +6,6 @@
|
|||
|
||||
struct MaterialsChunk
|
||||
{
|
||||
static const char *ident = "MTL";
|
||||
|
||||
uint32_t count;
|
||||
Material *materials;
|
||||
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
|
||||
struct NormalsChunk
|
||||
{
|
||||
static const char *ident = "NRL";
|
||||
|
||||
uint32_t count;
|
||||
Vector3 *normals;
|
||||
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
|
||||
struct TexCoordsChunk
|
||||
{
|
||||
static const char *ident = "TXT";
|
||||
|
||||
uint32_t count;
|
||||
Vector2 *texCoords;
|
||||
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
|
||||
struct TrianglesChunk
|
||||
{
|
||||
static const char *ident = "TRI";
|
||||
|
||||
uint32_t count;
|
||||
Triangle *triangles;
|
||||
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
|
||||
struct VerticesChunk
|
||||
{
|
||||
static const char *ident = "VTX";
|
||||
|
||||
uint32_t count;
|
||||
Vector3 *vertices;
|
||||
|
||||
|
|
Reference in a new issue