Indexed vertex meshes in progress
This commit is contained in:
@@ -119,6 +119,7 @@ fprintf(stderr, "Error at line number %d, in file %s. alGetError() returned %i f
|
||||
|
||||
#define KRMIN(x,y) ((x) < (y) ? (x) : (y))
|
||||
#define KRMAX(x,y) ((x) > (y) ? (x) : (y))
|
||||
#define KRALIGN(x) ((x + 3) & ~0x03)
|
||||
|
||||
#include "KRVector3.h"
|
||||
#include "KRVector2.h"
|
||||
@@ -346,11 +346,11 @@ void KRMesh::LoadData(std::vector<KRVector3> vertices, std::vector<KRVector2> uv
|
||||
vertex_attrib_flags += (1 << KRENGINE_ATTRIB_BONEINDEXES) + (1 << KRENGINE_ATTRIB_BONEWEIGHTS);
|
||||
}
|
||||
size_t vertex_size = VertexSizeForAttributes(vertex_attrib_flags);
|
||||
|
||||
size_t index_count = 0;
|
||||
size_t submesh_count = submesh_lengths.size();
|
||||
size_t vertex_count = vertices.size();
|
||||
size_t bone_count = bone_names.size();
|
||||
size_t new_file_size = sizeof(pack_header) + sizeof(pack_material) * submesh_count + sizeof(pack_bone) * bone_count + vertex_size * vertex_count;
|
||||
size_t new_file_size = sizeof(pack_header) + sizeof(pack_material) * submesh_count + sizeof(pack_bone) * bone_count + KRALIGN(2 * index_count) + vertex_size * vertex_count;
|
||||
m_pData->expand(new_file_size);
|
||||
|
||||
pack_header *pHeader = getHeader();
|
||||
@@ -359,6 +359,7 @@ void KRMesh::LoadData(std::vector<KRVector3> vertices, std::vector<KRVector2> uv
|
||||
pHeader->submesh_count = (__int32_t)submesh_count;
|
||||
pHeader->vertex_count = (__int32_t)vertex_count;
|
||||
pHeader->bone_count = (__int32_t)bone_count;
|
||||
pHeader->index_count = (__int32_t)index_count;
|
||||
pHeader->model_format = model_format;
|
||||
strcpy(pHeader->szTag, "KROBJPACK1.1 ");
|
||||
updateAttributeOffsets();
|
||||
@@ -530,9 +531,15 @@ KRMesh::pack_bone *KRMesh::getBone(int index)
|
||||
|
||||
unsigned char *KRMesh::getVertexData() const {
|
||||
pack_header *pHeader = getHeader();
|
||||
return ((unsigned char *)m_pData->getStart()) + sizeof(pack_header) + sizeof(pack_material) * pHeader->submesh_count + sizeof(pack_bone) * pHeader->bone_count;
|
||||
return ((unsigned char *)m_pData->getStart()) + sizeof(pack_header) + sizeof(pack_material) * pHeader->submesh_count + sizeof(pack_bone) * pHeader->bone_count + KRALIGN(2 * pHeader->index_count);
|
||||
}
|
||||
|
||||
__uint16_t *KRMesh::getIndexData() const {
|
||||
pack_header *pHeader = getHeader();
|
||||
return (__uint16_t *)((unsigned char *)m_pData->getStart()) + sizeof(pack_header) + sizeof(pack_material) * pHeader->submesh_count + sizeof(pack_bone) * pHeader->bone_count;
|
||||
}
|
||||
|
||||
|
||||
KRMesh::pack_material *KRMesh::getSubmesh(int mesh_index) const
|
||||
{
|
||||
return (pack_material *)((unsigned char *)m_pData->getStart() + sizeof(pack_header)) + mesh_index;
|
||||
@@ -726,11 +733,6 @@ char *KRMesh::getBoneName(int bone_index)
|
||||
return getBone(bone_index)->szName;
|
||||
}
|
||||
|
||||
void KRMesh::optimize()
|
||||
{
|
||||
// TODO - Add algorithm to convert model to indexed vertices, identying vertexes with identical attributes and optimizing order of trianges for best usage post-vertex-transform cache on GPU
|
||||
}
|
||||
|
||||
KRMesh::model_format_t KRMesh::getModelFormat() const
|
||||
{
|
||||
return (model_format_t)getHeader()->model_format;
|
||||
@@ -852,3 +854,15 @@ bool KRMesh::lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitin
|
||||
}
|
||||
return false; // Either no hit, or the hit was beyond v1
|
||||
}
|
||||
|
||||
void KRMesh::convert(model_format_t model_format)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void KRMesh::optimize()
|
||||
{
|
||||
convert(KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES);
|
||||
// TODO - Add algorithm to convert model to indexed vertices, identying vertexes with identical attributes and optimizing order of trianges for best usage post-vertex-transform cache on GPU
|
||||
}
|
||||
|
||||
|
||||
@@ -94,6 +94,8 @@ public:
|
||||
void LoadData(std::vector<KRVector3> vertices, std::vector<KRVector2> uva, std::vector<KRVector2> uvb, std::vector<KRVector3> normals, std::vector<KRVector3> tangents, std::vector<int> submesh_starts, std::vector<int> submesh_lengths, std::vector<std::string> material_names, std::vector<std::string> bone_names, std::vector<std::vector<int> > bone_indexes, std::vector<std::vector<float> > bone_weights, model_format_t model_format);
|
||||
void loadPack(KRDataBlock *data);
|
||||
|
||||
void convert(model_format_t model_format);
|
||||
void optimize();
|
||||
|
||||
void renderSubmesh(int iSubmesh);
|
||||
|
||||
@@ -204,7 +206,8 @@ private:
|
||||
int32_t submesh_count;
|
||||
int32_t bone_count;
|
||||
float minx, miny, minz, maxx, maxy, maxz; // Axis aligned bounding box, in model's coordinate space
|
||||
unsigned char reserved[452]; // Pad out to 512 bytes
|
||||
int32_t index_count;
|
||||
unsigned char reserved[448]; // Pad out to 512 bytes
|
||||
} pack_header;
|
||||
|
||||
vector<Submesh *> m_submeshes;
|
||||
@@ -217,13 +220,13 @@ private:
|
||||
void clearBuffers();
|
||||
|
||||
void setName(const std::string name);
|
||||
void optimize();
|
||||
|
||||
|
||||
|
||||
pack_material *getSubmesh(int mesh_index) const;
|
||||
unsigned char *getVertexData() const;
|
||||
unsigned char *getVertexData(int index) const;
|
||||
__uint16_t *getIndexData() const;
|
||||
pack_header *getHeader() const;
|
||||
pack_bone *getBone(int index);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user