Replacing KRMesh submeshes with GLTF style primitives with completely independent vertex layouts and topologies.
Some checks failed
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, macos-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Has been cancelled
Some checks failed
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, macos-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Has been cancelled
This commit is contained in:
@@ -1275,7 +1275,7 @@ void LoadMaterial(KRContext& context, FbxSurfaceMaterial* pMaterial)
|
|||||||
|
|
||||||
void LoadMesh(KRContext& context, FbxScene* pFbxScene, FbxGeometryConverter* pGeometryConverter, FbxMesh* pMesh)
|
void LoadMesh(KRContext& context, FbxScene* pFbxScene, FbxGeometryConverter* pGeometryConverter, FbxMesh* pMesh)
|
||||||
{
|
{
|
||||||
KRMesh::mesh_info mi;
|
KRMesh::MeshDesc mi;
|
||||||
mi.format = Topology::Triangles;
|
mi.format = Topology::Triangles;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
@@ -1554,7 +1554,7 @@ void LoadMesh(KRContext& context, FbxScene* pFbxScene, FbxGeometryConverter* pGe
|
|||||||
delete control_point_weights;
|
delete control_point_weights;
|
||||||
|
|
||||||
KRMesh* new_mesh = new KRMesh(context, pMesh->GetNode()->GetName());
|
KRMesh* new_mesh = new KRMesh(context, pMesh->GetNode()->GetName());
|
||||||
new_mesh->LoadData(mi, true, need_tangents);
|
new_mesh->LoadDesc(mi, true, need_tangents);
|
||||||
|
|
||||||
context.getMeshManager()->addMesh(new_mesh);
|
context.getMeshManager()->addMesh(new_mesh);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ KRMesh* KRResource::LoadObj(KRContext& context, const std::string& path)
|
|||||||
{
|
{
|
||||||
KRMesh* new_mesh = new KRMesh(context, util::GetFileBase(path));
|
KRMesh* new_mesh = new KRMesh(context, util::GetFileBase(path));
|
||||||
|
|
||||||
KRMesh::mesh_info mi;
|
KRMesh::MeshDesc md{};
|
||||||
|
|
||||||
std::vector<std::string> material_names_t;
|
std::vector<std::string> material_names_t;
|
||||||
|
|
||||||
@@ -53,8 +53,6 @@ KRMesh* KRResource::LoadObj(KRContext& context, const std::string& path)
|
|||||||
|
|
||||||
int* pFaces = NULL;
|
int* pFaces = NULL;
|
||||||
|
|
||||||
vector<KRMesh::pack_material*> m_materials;
|
|
||||||
|
|
||||||
if (data.load(path)) {
|
if (data.load(path)) {
|
||||||
// -----=====----- Get counts -----=====-----
|
// -----=====----- Get counts -----=====-----
|
||||||
|
|
||||||
@@ -134,9 +132,6 @@ KRMesh* KRResource::LoadObj(KRContext& context, const std::string& path)
|
|||||||
int* pMaterialFaces = pFace++;
|
int* pMaterialFaces = pFace++;
|
||||||
*pMaterialFaces = 0;
|
*pMaterialFaces = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// --------
|
// --------
|
||||||
|
|
||||||
pScan = (char*)data.getStart();
|
pScan = (char*)data.getStart();
|
||||||
@@ -254,23 +249,13 @@ KRMesh* KRResource::LoadObj(KRContext& context, const std::string& path)
|
|||||||
|
|
||||||
|
|
||||||
int iVertex = 0;
|
int iVertex = 0;
|
||||||
|
int iMaterialStartVertex = 0;
|
||||||
|
|
||||||
std::vector<std::string>::iterator material_itr = material_names_t.begin();
|
std::vector<std::string>::iterator material_itr = material_names_t.begin();
|
||||||
KRMesh::pack_material* pMaterial = new KRMesh::pack_material();
|
|
||||||
pMaterial->start_vertex = iVertex;
|
|
||||||
pMaterial->vertex_count = 0;
|
|
||||||
memset(pMaterial->szName, 0, 256);
|
|
||||||
if (material_itr < material_names_t.end()) {
|
|
||||||
strncpy(pMaterial->szName, (*material_itr++).c_str(), 256);
|
|
||||||
}
|
|
||||||
m_materials.push_back(pMaterial);
|
|
||||||
|
|
||||||
|
|
||||||
pFace = pFaces;
|
pFace = pFaces;
|
||||||
while (*pFace != 0 && iVertex < cVertexData) {
|
while (*pFace != 0 && iVertex < cVertexData) {
|
||||||
pMaterial->start_vertex = iVertex;
|
KRMesh::PrimitiveDesc pd{};
|
||||||
|
|
||||||
int* pMaterialEndFace = pFace + *pFace;
|
int* pMaterialEndFace = pFace + *pFace;
|
||||||
++pFace;
|
++pFace;
|
||||||
while (pFace < pMaterialEndFace && iVertex < cVertexData) {
|
while (pFace < pMaterialEndFace && iVertex < cVertexData) {
|
||||||
@@ -286,13 +271,13 @@ KRMesh* KRResource::LoadObj(KRContext& context, const std::string& path)
|
|||||||
// There have already been 3 vertices. Now we need to split the quad into a second triangle composed of the 1st, 3rd, and 4th vertices
|
// There have already been 3 vertices. Now we need to split the quad into a second triangle composed of the 1st, 3rd, and 4th vertices
|
||||||
iVertex += 2;
|
iVertex += 2;
|
||||||
|
|
||||||
mi.vertices.push_back(firstFaceVertex);
|
pd.vertices.push_back(firstFaceVertex);
|
||||||
mi.texcoord[0].push_back(firstFaceUva);
|
pd.texcoord[0].push_back(firstFaceUva);
|
||||||
mi.normals.push_back(firstFaceNormal);
|
pd.normals.push_back(firstFaceNormal);
|
||||||
|
|
||||||
mi.vertices.push_back(prevFaceVertex);
|
pd.vertices.push_back(prevFaceVertex);
|
||||||
mi.texcoord[0].push_back(prevFaceUva);
|
pd.texcoord[0].push_back(prevFaceUva);
|
||||||
mi.normals.push_back(prevFaceNormal);
|
pd.normals.push_back(prevFaceNormal);
|
||||||
}
|
}
|
||||||
Vector3 vertex = indexed_vertices[pFace[iFaceVertex * 3 + 1]];
|
Vector3 vertex = indexed_vertices[pFace[iFaceVertex * 3 + 1]];
|
||||||
Vector2 new_uva;
|
Vector2 new_uva;
|
||||||
@@ -304,9 +289,9 @@ KRMesh* KRResource::LoadObj(KRContext& context, const std::string& path)
|
|||||||
Vector3 normal = indexed_normals[pFace[iFaceVertex * 3 + 3]];
|
Vector3 normal = indexed_normals[pFace[iFaceVertex * 3 + 3]];
|
||||||
}
|
}
|
||||||
|
|
||||||
mi.vertices.push_back(vertex);
|
pd.vertices.push_back(vertex);
|
||||||
mi.texcoord[0].push_back(new_uva);
|
pd.texcoord[0].push_back(new_uva);
|
||||||
mi.normals.push_back(normal);
|
pd.normals.push_back(normal);
|
||||||
|
|
||||||
if (iFaceVertex == 0) {
|
if (iFaceVertex == 0) {
|
||||||
firstFaceVertex = vertex;
|
firstFaceVertex = vertex;
|
||||||
@@ -321,41 +306,16 @@ KRMesh* KRResource::LoadObj(KRContext& context, const std::string& path)
|
|||||||
}
|
}
|
||||||
pFace += cFaceVertexes * 3 + 1;
|
pFace += cFaceVertexes * 3 + 1;
|
||||||
}
|
}
|
||||||
pMaterial->vertex_count = iVertex - pMaterial->start_vertex;
|
|
||||||
if (*pFace != 0) {
|
|
||||||
pMaterial = new KRMesh::pack_material();
|
|
||||||
pMaterial->start_vertex = iVertex;
|
|
||||||
pMaterial->vertex_count = 0;
|
|
||||||
memset(pMaterial->szName, 0, 256);
|
|
||||||
|
|
||||||
if (material_itr < material_names_t.end()) {
|
pd.format = Topology::Triangles;
|
||||||
strncpy(pMaterial->szName, (*material_itr++).c_str(), 256);
|
pd.materialName = *material_itr++;
|
||||||
}
|
md.primitives.push_back(pd);
|
||||||
m_materials.push_back(pMaterial);
|
iMaterialStartVertex = iVertex;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int iMaterial = 0; iMaterial < m_materials.size(); iMaterial++) {
|
|
||||||
KRMesh::pack_material* pNewMaterial = m_materials[iMaterial];
|
|
||||||
if (pNewMaterial->vertex_count > 0) {
|
|
||||||
mi.material_names.push_back(std::string(pNewMaterial->szName));
|
|
||||||
mi.submesh_starts.push_back(pNewMaterial->start_vertex);
|
|
||||||
mi.submesh_lengths.push_back(pNewMaterial->vertex_count);
|
|
||||||
}
|
|
||||||
delete pNewMaterial;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Bones not yet supported for OBJ
|
// TODO: Bones not yet supported for OBJ
|
||||||
// std::vector<std::string> bone_names;
|
|
||||||
// std::vector<Matrix4> bone_bind_poses;
|
|
||||||
// std::vector<std::vector<int> > bone_indexes;
|
|
||||||
// std::vector<std::vector<float> > bone_weights;
|
|
||||||
//
|
|
||||||
// std::vector<__uint16_t> vertex_indexes;
|
|
||||||
// std::vector<std::pair<int, int> > vertex_index_bases;
|
|
||||||
|
|
||||||
mi.format = Topology::Triangles;
|
new_mesh->LoadDesc(md, true, false);
|
||||||
new_mesh->LoadData(mi, true, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pFaces) {
|
if (pFaces) {
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -76,28 +76,33 @@ public:
|
|||||||
|
|
||||||
struct PrimitiveInfo
|
struct PrimitiveInfo
|
||||||
{
|
{
|
||||||
|
char szMaterialName[KRENGINE_MAX_NAME_LENGTH];
|
||||||
VertexBufferLayout layout;
|
VertexBufferLayout layout;
|
||||||
|
int64_t vertexOffset;
|
||||||
int64_t vertexCount;
|
int64_t vertexCount;
|
||||||
|
int64_t indexOffset;
|
||||||
int64_t indexCount;
|
int64_t indexCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mesh_info
|
struct PrimitiveDesc
|
||||||
{
|
{
|
||||||
|
std::string materialName;
|
||||||
Topology format;
|
Topology format;
|
||||||
std::vector<hydra::Vector3> vertices;
|
std::vector<hydra::Vector3> vertices;
|
||||||
std::vector<__uint16_t> vertex_indexes;
|
std::vector<int> indexes;
|
||||||
std::vector<std::pair<int, int> > vertex_index_bases;
|
|
||||||
std::vector<hydra::Vector2> texcoord[8];
|
std::vector<hydra::Vector2> texcoord[8];
|
||||||
std::vector<hydra::Vector4> color[8];
|
std::vector<hydra::Vector4> color[8];
|
||||||
std::vector<hydra::Vector3> normals;
|
std::vector<hydra::Vector3> normals;
|
||||||
std::vector<hydra::Vector3> tangents;
|
std::vector<hydra::Vector3> 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<hydra::Matrix4> bone_bind_poses;
|
|
||||||
std::vector<std::vector<float> > bone_weights;
|
std::vector<std::vector<float> > bone_weights;
|
||||||
|
std::vector<std::vector<int> > bone_indexes;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MeshDesc
|
||||||
|
{
|
||||||
|
std::vector<PrimitiveDesc> primitives;
|
||||||
|
std::vector<std::string> bone_names;
|
||||||
|
std::vector<hydra::Matrix4> bone_bind_poses;
|
||||||
};
|
};
|
||||||
|
|
||||||
void render(KRNode::RenderInfo& ri, const std::string& object_name, const hydra::Matrix4& matModel, KRTexture* pLightMap, const std::vector<KRBone*>& bones, float lod_coverage = 0.0f);
|
void render(KRNode::RenderInfo& ri, const std::string& object_name, const hydra::Matrix4& matModel, KRTexture* pLightMap, const std::vector<KRBone*>& bones, float lod_coverage = 0.0f);
|
||||||
@@ -108,7 +113,7 @@ public:
|
|||||||
virtual bool save(const std::string& path) override;
|
virtual bool save(const std::string& path) override;
|
||||||
virtual bool save(mimir::Block& data) override;
|
virtual bool save(mimir::Block& data) override;
|
||||||
|
|
||||||
void LoadData(const mesh_info& mi, bool calculate_normals, bool calculate_tangents);
|
void LoadDesc(const MeshDesc& mi, bool calculate_normals, bool calculate_tangents);
|
||||||
void loadPack(mimir::Block* data);
|
void loadPack(mimir::Block* data);
|
||||||
|
|
||||||
void convertToIndexed();
|
void convertToIndexed();
|
||||||
@@ -116,54 +121,11 @@ public:
|
|||||||
void optimizeIndexes();
|
void optimizeIndexes();
|
||||||
|
|
||||||
void renderNoMaterials(VkCommandBuffer& commandBuffer, const KRRenderPass* renderPass, const std::string& object_name, const std::string& material_name, float lodCoverage);
|
void renderNoMaterials(VkCommandBuffer& commandBuffer, const KRRenderPass* renderPass, const std::string& object_name, const std::string& material_name, float lodCoverage);
|
||||||
bool isReady() const;
|
|
||||||
|
|
||||||
float getMaxDimension();
|
float getMaxDimension();
|
||||||
|
|
||||||
const hydra::AABB& getExtents() const;
|
const hydra::AABB& getExtents() const;
|
||||||
|
|
||||||
class Submesh
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Submesh()
|
|
||||||
{};
|
|
||||||
~Submesh()
|
|
||||||
{
|
|
||||||
vbo_data_blocks.clear();
|
|
||||||
for (auto itr = vertex_data_blocks.begin(); itr != vertex_data_blocks.end(); itr++) {
|
|
||||||
delete (*itr);
|
|
||||||
}
|
|
||||||
for (auto itr = index_data_blocks.begin(); itr != index_data_blocks.end(); itr++) {
|
|
||||||
delete (*itr);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
int start_vertex;
|
|
||||||
int vertex_count;
|
|
||||||
char szMaterialName[KRENGINE_MAX_NAME_LENGTH];
|
|
||||||
vector<mimir::Block*> vertex_data_blocks;
|
|
||||||
vector<mimir::Block*> index_data_blocks;
|
|
||||||
// KRMeshManager depends on the address of KRVBOData's being constant
|
|
||||||
// after allocation, enforced by deleted copy constructors.
|
|
||||||
// As std::vector requires copy constuctors, we wrap these in shared_ptr.
|
|
||||||
vector<shared_ptr<KRMeshManager::KRVBOData>> vbo_data_blocks;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
union
|
|
||||||
{
|
|
||||||
struct
|
|
||||||
{ // For Indexed triangles / strips
|
|
||||||
uint16_t index_group;
|
|
||||||
uint16_t index_group_offset;
|
|
||||||
};
|
|
||||||
int32_t start_vertex; // For non-indexed trigangles / strips
|
|
||||||
};
|
|
||||||
int32_t vertex_count;
|
|
||||||
char szName[KRENGINE_MAX_NAME_LENGTH];
|
|
||||||
} pack_material;
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
char szName[KRENGINE_MAX_NAME_LENGTH];
|
char szName[KRENGINE_MAX_NAME_LENGTH];
|
||||||
@@ -182,37 +144,38 @@ public:
|
|||||||
const VertexBufferLayout* getLayout(int submesh) const;
|
const VertexBufferLayout* getLayout(int submesh) const;
|
||||||
|
|
||||||
int getVertexIndex(int submesh, int index) const;
|
int getVertexIndex(int submesh, int index) const;
|
||||||
hydra::Vector3 getVertexPosition(int index) const;
|
void setVertexIndex(int submesh, int index, int indexVal);
|
||||||
hydra::Vector3 getVertexNormal(int index) const;
|
hydra::Vector3 getVertexPosition(int submesh, int index) const;
|
||||||
hydra::Vector3 getVertexTangent(int index) const;
|
hydra::Vector3 getVertexNormal(int submesh, int index) const;
|
||||||
hydra::Vector2 getVertexTexCoord(int set, int index) const;
|
hydra::Vector3 getVertexTangent(int submesh, int index) const;
|
||||||
hydra::Vector4 getVertexColor(int set, int index) const;
|
hydra::Vector2 getVertexTexCoord(int submesh, int set, int index) const;
|
||||||
|
hydra::Vector4 getVertexColor(int submesh, int set, int index) const;
|
||||||
|
|
||||||
static int getAttributeIndex(const PrimitiveInfo& primitive, VertexAttribute attribute, int index);
|
static int getAttributeIndex(const PrimitiveInfo& primitive, VertexAttribute attribute, int index);
|
||||||
void setVertexAttribute(int vertexIndex, int attributeIndex, float val);
|
void setVertexAttribute(int submesh, int vertexIndex, int attributeIndex, float val);
|
||||||
void setVertexAttribute(int vertexIndex, int attributeIndex, hydra::Vector2 val);
|
void setVertexAttribute(int submesh, int vertexIndex, int attributeIndex, hydra::Vector2 val);
|
||||||
void setVertexAttribute(int vertexIndex, int attributeIndex, hydra::Vector3 val);
|
void setVertexAttribute(int submesh, int vertexIndex, int attributeIndex, hydra::Vector3 val);
|
||||||
void setVertexAttribute(int vertexIndex, int attributeIndex, hydra::Vector4 val);
|
void setVertexAttribute(int submesh, int vertexIndex, int attributeIndex, hydra::Vector4 val);
|
||||||
void setVertexAttribute(int vertexIndex, int attributeIndex, hydra::Matrix2 val);
|
void setVertexAttribute(int submesh, int vertexIndex, int attributeIndex, hydra::Matrix2 val);
|
||||||
void setVertexAttribute(int vertexIndex, int attributeIndex, hydra::Matrix4 val);
|
void setVertexAttribute(int submesh, int vertexIndex, int attributeIndex, hydra::Matrix4 val);
|
||||||
void getVertexAttribute(int vertexIndex, int attributeIndex, float* val) const;
|
void getVertexAttribute(int submesh, int vertexIndex, int attributeIndex, float* val) const;
|
||||||
void getVertexAttribute(int vertexIndex, int attributeIndex, hydra::Vector2* val) const;
|
void getVertexAttribute(int submesh, int vertexIndex, int attributeIndex, hydra::Vector2* val) const;
|
||||||
void getVertexAttribute(int vertexIndex, int attributeIndex, hydra::Vector3* val) const;
|
void getVertexAttribute(int submesh, int vertexIndex, int attributeIndex, hydra::Vector3* val) const;
|
||||||
void getVertexAttribute(int vertexIndex, int attributeIndex, hydra::Vector4* val) const;
|
void getVertexAttribute(int submesh, int vertexIndex, int attributeIndex, hydra::Vector4* val) const;
|
||||||
void getVertexAttribute(int vertexIndex, int attributeIndex, hydra::Matrix2* val) const;
|
void getVertexAttribute(int submesh, int vertexIndex, int attributeIndex, hydra::Matrix2* val) const;
|
||||||
void getVertexAttribute(int vertexIndex, int attributeIndex, hydra::Matrix4* val) const;
|
void getVertexAttribute(int submesh, int vertexIndex, int attributeIndex, hydra::Matrix4* val) const;
|
||||||
|
|
||||||
void setVertexPosition(int index, const hydra::Vector3& v);
|
void setVertexPosition(int submesh, int index, const hydra::Vector3& v);
|
||||||
void setVertexNormal(int index, const hydra::Vector3& v);
|
void setVertexNormal(int submesh, int index, const hydra::Vector3& v);
|
||||||
void setVertexTangent(int index, const hydra::Vector3& v);
|
void setVertexTangent(int submesh, int index, const hydra::Vector3& v);
|
||||||
void setVertexTexCoord(int index, int set, const hydra::Vector2& v);
|
void setVertexTexCoord(int submesh, int index, int set, const hydra::Vector2& v);
|
||||||
void setVertexColor(int index, int set, const hydra::Vector4& v);
|
void setVertexColor(int submesh, int index, int set, const hydra::Vector4& v);
|
||||||
|
|
||||||
int getBoneIndex(int index, int weight_index) const;
|
int getBoneIndex(int submesh, int index, int weight_index) const;
|
||||||
void setBoneIndex(int index, int weight_index, int bone_index);
|
void setBoneIndex(int submesh, int index, int weight_index, int bone_index);
|
||||||
|
|
||||||
float getBoneWeight(int index, int weight_index) const;
|
float getBoneWeight(int submesh, int index, int weight_index) const;
|
||||||
void setBoneWeight(int index, int weight_index, float weight);
|
void setBoneWeight(int submesh, int index, int weight_index, float weight);
|
||||||
|
|
||||||
static VkFormat AttributeVulkanFormat(const VertexAttributeInfo& attribute);
|
static VkFormat AttributeVulkanFormat(const VertexAttributeInfo& attribute);
|
||||||
|
|
||||||
@@ -220,9 +183,6 @@ public:
|
|||||||
char* getBoneName(int bone_index);
|
char* getBoneName(int bone_index);
|
||||||
hydra::Matrix4 getBoneBindPose(int bone_index);
|
hydra::Matrix4 getBoneBindPose(int bone_index);
|
||||||
|
|
||||||
|
|
||||||
Topology getTopology() const;
|
|
||||||
|
|
||||||
bool lineCast(const hydra::Vector3& v0, const hydra::Vector3& v1, hydra::HitInfo& hitinfo) const;
|
bool lineCast(const hydra::Vector3& v0, const hydra::Vector3& v1, hydra::HitInfo& hitinfo) const;
|
||||||
bool rayCast(const hydra::Vector3& v0, const hydra::Vector3& dir, hydra::HitInfo& hitinfo) const;
|
bool rayCast(const hydra::Vector3& v0, const hydra::Vector3& dir, hydra::HitInfo& hitinfo) const;
|
||||||
bool sphereCast(const hydra::Matrix4& model_to_world, const hydra::Vector3& v0, const hydra::Vector3& v1, float radius, hydra::HitInfo& hitinfo) const;
|
bool sphereCast(const hydra::Matrix4& model_to_world, const hydra::Vector3& v0, const hydra::Vector3& v1, float radius, hydra::HitInfo& hitinfo) const;
|
||||||
@@ -234,10 +194,19 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
mimir::Block* m_pData;
|
mimir::Block* m_pData;
|
||||||
mimir::Block* m_pMetaData;
|
|
||||||
mimir::Block* m_pIndexBaseData;
|
|
||||||
|
|
||||||
void getSubmeshes();
|
// Sub-blocks
|
||||||
|
mimir::Block* m_pMetaData;
|
||||||
|
vector<mimir::Block*> m_vertexBlocks;
|
||||||
|
vector<mimir::Block*> m_indexBlocks;
|
||||||
|
|
||||||
|
// KRMeshManager depends on the address of KRVBOData's being constant
|
||||||
|
// after allocation, enforced by deleted copy constructors.
|
||||||
|
// As std::vector requires copy constuctors, we wrap these in shared_ptr.
|
||||||
|
vector<shared_ptr<KRMeshManager::KRVBOData>> vbo_data_blocks;
|
||||||
|
|
||||||
|
void initSubBlocks();
|
||||||
|
void getPrimitives();
|
||||||
void getMaterials();
|
void getMaterials();
|
||||||
void renderSubmesh(VkCommandBuffer& commandBuffer, int iSubmesh, const KRRenderPass* renderPass, const std::string& object_name, const std::string& material_name, float lodCoverage);
|
void renderSubmesh(VkCommandBuffer& commandBuffer, int iSubmesh, const KRRenderPass* renderPass, const std::string& object_name, const std::string& material_name, float lodCoverage);
|
||||||
|
|
||||||
@@ -250,41 +219,23 @@ private:
|
|||||||
|
|
||||||
bool m_hasTransparency;
|
bool m_hasTransparency;
|
||||||
|
|
||||||
hydra::AABB m_extents;
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
char szTag[16];
|
char szTag[16];
|
||||||
PrimitiveInfo primitive;
|
|
||||||
int32_t submesh_count;
|
int32_t submesh_count;
|
||||||
int32_t bone_count;
|
int32_t bone_count;
|
||||||
hydra::AABB extents; // Axis aligned bounding box, in model's coordinate space
|
hydra::AABB extents; // Axis aligned bounding box, in model's coordinate space
|
||||||
int32_t index_base_count;
|
unsigned char reserved[464]; // Pad out to 512 bytes
|
||||||
unsigned char reserved[456 - sizeof(PrimitiveInfo)]; // Pad out to 512 bytes
|
|
||||||
} pack_header;
|
} pack_header;
|
||||||
|
|
||||||
static_assert(sizeof(pack_header) == 512);
|
static_assert(sizeof(pack_header) == 512);
|
||||||
|
|
||||||
vector<Submesh> m_submeshes;
|
|
||||||
|
|
||||||
void setName(const std::string name);
|
void setName(const std::string name);
|
||||||
|
|
||||||
pack_material* getSubmesh(int mesh_index) const;
|
std::byte* getVertexData(int submesh, int index) const;
|
||||||
unsigned char* getVertexData() const;
|
|
||||||
size_t getVertexDataOffset() const;
|
|
||||||
unsigned char* getVertexData(int index) const;
|
|
||||||
__uint16_t* getIndexData() const;
|
|
||||||
size_t getIndexDataOffset() const;
|
|
||||||
__uint32_t* getIndexBaseData() const;
|
|
||||||
pack_header* getHeader() const;
|
pack_header* getHeader() const;
|
||||||
|
PrimitiveInfo* getPrimitive(int index) const;
|
||||||
pack_bone* getBone(int index);
|
pack_bone* getBone(int index);
|
||||||
|
|
||||||
|
|
||||||
void getIndexedRange(int index_group, int& start_index_offset, int& start_vertex_offset, int& index_count, int& vertex_count) const;
|
|
||||||
|
|
||||||
void releaseData(bool includeMainDatablock = true);
|
void releaseData(bool includeMainDatablock = true);
|
||||||
|
|
||||||
void createDataBlocks(KRMeshManager::KRVBOData::vbo_type t);
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -37,144 +37,143 @@ KRMeshCube::KRMeshCube(KRContext& context) : KRMesh(context, "__cube")
|
|||||||
{
|
{
|
||||||
m_constant = true;
|
m_constant = true;
|
||||||
|
|
||||||
KRMesh::mesh_info mi;
|
KRMesh::PrimitiveDesc pd{};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// Cube without normals
|
// Cube without normals
|
||||||
mi.vertices.push_back(Vector3::Create(1.0, 1.0, 1.0));
|
pd.vertices.push_back(Vector3::Create(1.0, 1.0, 1.0));
|
||||||
mi.vertices.push_back(Vector3::Create(-1.0, 1.0, 1.0));
|
pd.vertices.push_back(Vector3::Create(-1.0, 1.0, 1.0));
|
||||||
mi.vertices.push_back(Vector3::Create(1.0, -1.0, 1.0));
|
pd.vertices.push_back(Vector3::Create(1.0, -1.0, 1.0));
|
||||||
mi.vertices.push_back(Vector3::Create(-1.0, -1.0, 1.0));
|
pd.vertices.push_back(Vector3::Create(-1.0, -1.0, 1.0));
|
||||||
mi.vertices.push_back(Vector3::Create(-1.0, -1.0, -1.0));
|
pd.vertices.push_back(Vector3::Create(-1.0, -1.0, -1.0));
|
||||||
mi.vertices.push_back(Vector3::Create(-1.0, 1.0, 1.0));
|
pd.vertices.push_back(Vector3::Create(-1.0, 1.0, 1.0));
|
||||||
mi.vertices.push_back(Vector3::Create(-1.0, 1.0, -1.0));
|
pd.vertices.push_back(Vector3::Create(-1.0, 1.0, -1.0));
|
||||||
mi.vertices.push_back(Vector3::Create(1.0, 1.0, 1.0));
|
pd.vertices.push_back(Vector3::Create(1.0, 1.0, 1.0));
|
||||||
mi.vertices.push_back(Vector3::Create(1.0, 1.0, -1.0));
|
pd.vertices.push_back(Vector3::Create(1.0, 1.0, -1.0));
|
||||||
mi.vertices.push_back(Vector3::Create(1.0, -1.0, 1.0));
|
pd.vertices.push_back(Vector3::Create(1.0, -1.0, 1.0));
|
||||||
mi.vertices.push_back(Vector3::Create(1.0, -1.0, -1.0));
|
pd.vertices.push_back(Vector3::Create(1.0, -1.0, -1.0));
|
||||||
mi.vertices.push_back(Vector3::Create(-1.0, -1.0, -1.0));
|
pd.vertices.push_back(Vector3::Create(-1.0, -1.0, -1.0));
|
||||||
mi.vertices.push_back(Vector3::Create(1.0, 1.0, -1.0));
|
pd.vertices.push_back(Vector3::Create(1.0, 1.0, -1.0));
|
||||||
mi.vertices.push_back(Vector3::Create(-1.0, 1.0, -1.0));
|
pd.vertices.push_back(Vector3::Create(-1.0, 1.0, -1.0));
|
||||||
|
|
||||||
|
|
||||||
mi.submesh_starts.push_back(0);
|
pd.submesh_starts.push_back(0);
|
||||||
mi.submesh_lengths.push_back((int)mi.vertices.size());
|
pd.submesh_lengths.push_back((int)pd.vertices.size());
|
||||||
mi.material_names.push_back("__white");
|
pd.material_names.push_back("__white");
|
||||||
mi.format = Topology::TriangleStrips;
|
pd.format = Topology::TriangleStrips;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Cube with normals
|
// Cube with normals
|
||||||
int b = 0;
|
int b = 0;
|
||||||
mi.vertices.push_back(Vector3::Create(1.0, 1.0, 1.0));
|
pd.vertices.push_back(Vector3::Create(1.0, 1.0, 1.0));
|
||||||
mi.vertices.push_back(Vector3::Create(-1.0, 1.0, 1.0));
|
pd.vertices.push_back(Vector3::Create(-1.0, 1.0, 1.0));
|
||||||
mi.vertices.push_back(Vector3::Create(1.0, -1.0, 1.0));
|
pd.vertices.push_back(Vector3::Create(1.0, -1.0, 1.0));
|
||||||
mi.vertices.push_back(Vector3::Create(-1.0, -1.0, 1.0));
|
pd.vertices.push_back(Vector3::Create(-1.0, -1.0, 1.0));
|
||||||
mi.normals.push_back(Vector3::Create(0.0, 0.0, 1.0));
|
pd.normals.push_back(Vector3::Create(0.0, 0.0, 1.0));
|
||||||
mi.normals.push_back(Vector3::Create(0.0, 0.0, 1.0));
|
pd.normals.push_back(Vector3::Create(0.0, 0.0, 1.0));
|
||||||
mi.normals.push_back(Vector3::Create(0.0, 0.0, 1.0));
|
pd.normals.push_back(Vector3::Create(0.0, 0.0, 1.0));
|
||||||
mi.normals.push_back(Vector3::Create(0.0, 0.0, 1.0));
|
pd.normals.push_back(Vector3::Create(0.0, 0.0, 1.0));
|
||||||
|
|
||||||
mi.vertex_indexes.push_back(b+0);
|
pd.indexes.push_back(b+0);
|
||||||
mi.vertex_indexes.push_back(b+1);
|
pd.indexes.push_back(b+1);
|
||||||
mi.vertex_indexes.push_back(b+2);
|
pd.indexes.push_back(b+2);
|
||||||
mi.vertex_indexes.push_back(b+2);
|
pd.indexes.push_back(b+2);
|
||||||
mi.vertex_indexes.push_back(b+1);
|
pd.indexes.push_back(b+1);
|
||||||
mi.vertex_indexes.push_back(b+3);
|
pd.indexes.push_back(b+3);
|
||||||
b += 4;
|
b += 4;
|
||||||
|
|
||||||
mi.vertices.push_back(Vector3::Create(1.0, 1.0, 1.0));
|
pd.vertices.push_back(Vector3::Create(1.0, 1.0, 1.0));
|
||||||
mi.vertices.push_back(Vector3::Create(-1.0, 1.0, 1.0));
|
pd.vertices.push_back(Vector3::Create(-1.0, 1.0, 1.0));
|
||||||
mi.vertices.push_back(Vector3::Create(1.0, 1.0, -1.0));
|
pd.vertices.push_back(Vector3::Create(1.0, 1.0, -1.0));
|
||||||
mi.vertices.push_back(Vector3::Create(-1.0, 1.0, -1.0));
|
pd.vertices.push_back(Vector3::Create(-1.0, 1.0, -1.0));
|
||||||
mi.normals.push_back(Vector3::Create(0.0, 1.0, 0.0));
|
pd.normals.push_back(Vector3::Create(0.0, 1.0, 0.0));
|
||||||
mi.normals.push_back(Vector3::Create(0.0, 1.0, 0.0));
|
pd.normals.push_back(Vector3::Create(0.0, 1.0, 0.0));
|
||||||
mi.normals.push_back(Vector3::Create(0.0, 1.0, 0.0));
|
pd.normals.push_back(Vector3::Create(0.0, 1.0, 0.0));
|
||||||
mi.normals.push_back(Vector3::Create(0.0, 1.0, 0.0));
|
pd.normals.push_back(Vector3::Create(0.0, 1.0, 0.0));
|
||||||
|
|
||||||
mi.vertex_indexes.push_back(b + 3);
|
pd.indexes.push_back(b + 3);
|
||||||
mi.vertex_indexes.push_back(b + 1);
|
pd.indexes.push_back(b + 1);
|
||||||
mi.vertex_indexes.push_back(b + 2);
|
pd.indexes.push_back(b + 2);
|
||||||
mi.vertex_indexes.push_back(b + 2);
|
pd.indexes.push_back(b + 2);
|
||||||
mi.vertex_indexes.push_back(b + 1);
|
pd.indexes.push_back(b + 1);
|
||||||
mi.vertex_indexes.push_back(b + 0);
|
pd.indexes.push_back(b + 0);
|
||||||
b += 4;
|
b += 4;
|
||||||
|
|
||||||
mi.vertices.push_back(Vector3::Create(1.0, 1.0, 1.0));
|
pd.vertices.push_back(Vector3::Create(1.0, 1.0, 1.0));
|
||||||
mi.vertices.push_back(Vector3::Create(1.0, -1.0, 1.0));
|
pd.vertices.push_back(Vector3::Create(1.0, -1.0, 1.0));
|
||||||
mi.vertices.push_back(Vector3::Create(1.0, 1.0, -1.0));
|
pd.vertices.push_back(Vector3::Create(1.0, 1.0, -1.0));
|
||||||
mi.vertices.push_back(Vector3::Create(1.0, -1.0, -1.0));
|
pd.vertices.push_back(Vector3::Create(1.0, -1.0, -1.0));
|
||||||
mi.normals.push_back(Vector3::Create(1.0, 0.0, 0.0));
|
pd.normals.push_back(Vector3::Create(1.0, 0.0, 0.0));
|
||||||
mi.normals.push_back(Vector3::Create(1.0, 0.0, 0.0));
|
pd.normals.push_back(Vector3::Create(1.0, 0.0, 0.0));
|
||||||
mi.normals.push_back(Vector3::Create(1.0, 0.0, 0.0));
|
pd.normals.push_back(Vector3::Create(1.0, 0.0, 0.0));
|
||||||
mi.normals.push_back(Vector3::Create(1.0, 0.0, 0.0));
|
pd.normals.push_back(Vector3::Create(1.0, 0.0, 0.0));
|
||||||
|
|
||||||
mi.vertex_indexes.push_back(b + 0);
|
pd.indexes.push_back(b + 0);
|
||||||
mi.vertex_indexes.push_back(b + 1);
|
pd.indexes.push_back(b + 1);
|
||||||
mi.vertex_indexes.push_back(b + 2);
|
pd.indexes.push_back(b + 2);
|
||||||
mi.vertex_indexes.push_back(b + 2);
|
pd.indexes.push_back(b + 2);
|
||||||
mi.vertex_indexes.push_back(b + 1);
|
pd.indexes.push_back(b + 1);
|
||||||
mi.vertex_indexes.push_back(b + 3);
|
pd.indexes.push_back(b + 3);
|
||||||
b += 4;
|
b += 4;
|
||||||
|
|
||||||
mi.vertices.push_back(Vector3::Create(1.0, 1.0, -1.0));
|
pd.vertices.push_back(Vector3::Create(1.0, 1.0, -1.0));
|
||||||
mi.vertices.push_back(Vector3::Create(-1.0, 1.0, -1.0));
|
pd.vertices.push_back(Vector3::Create(-1.0, 1.0, -1.0));
|
||||||
mi.vertices.push_back(Vector3::Create(1.0, -1.0, -1.0));
|
pd.vertices.push_back(Vector3::Create(1.0, -1.0, -1.0));
|
||||||
mi.vertices.push_back(Vector3::Create(-1.0, -1.0, -1.0));
|
pd.vertices.push_back(Vector3::Create(-1.0, -1.0, -1.0));
|
||||||
mi.normals.push_back(Vector3::Create(0.0, 0.0, -1.0));
|
pd.normals.push_back(Vector3::Create(0.0, 0.0, -1.0));
|
||||||
mi.normals.push_back(Vector3::Create(0.0, 0.0, -1.0));
|
pd.normals.push_back(Vector3::Create(0.0, 0.0, -1.0));
|
||||||
mi.normals.push_back(Vector3::Create(0.0, 0.0, -1.0));
|
pd.normals.push_back(Vector3::Create(0.0, 0.0, -1.0));
|
||||||
mi.normals.push_back(Vector3::Create(0.0, 0.0, -1.0));
|
pd.normals.push_back(Vector3::Create(0.0, 0.0, -1.0));
|
||||||
|
|
||||||
mi.vertex_indexes.push_back(b + 3);
|
pd.indexes.push_back(b + 3);
|
||||||
mi.vertex_indexes.push_back(b + 1);
|
pd.indexes.push_back(b + 1);
|
||||||
mi.vertex_indexes.push_back(b + 2);
|
pd.indexes.push_back(b + 2);
|
||||||
mi.vertex_indexes.push_back(b + 2);
|
pd.indexes.push_back(b + 2);
|
||||||
mi.vertex_indexes.push_back(b + 1);
|
pd.indexes.push_back(b + 1);
|
||||||
mi.vertex_indexes.push_back(b + 0);
|
pd.indexes.push_back(b + 0);
|
||||||
b += 4;
|
b += 4;
|
||||||
|
|
||||||
mi.vertices.push_back(Vector3::Create(1.0, -1.0, 1.0));
|
pd.vertices.push_back(Vector3::Create(1.0, -1.0, 1.0));
|
||||||
mi.vertices.push_back(Vector3::Create(-1.0, -1.0, 1.0));
|
pd.vertices.push_back(Vector3::Create(-1.0, -1.0, 1.0));
|
||||||
mi.vertices.push_back(Vector3::Create(1.0, -1.0, -1.0));
|
pd.vertices.push_back(Vector3::Create(1.0, -1.0, -1.0));
|
||||||
mi.vertices.push_back(Vector3::Create(-1.0, -1.0, -1.0));
|
pd.vertices.push_back(Vector3::Create(-1.0, -1.0, -1.0));
|
||||||
mi.normals.push_back(Vector3::Create(0.0, -1.0, 0.0));
|
pd.normals.push_back(Vector3::Create(0.0, -1.0, 0.0));
|
||||||
mi.normals.push_back(Vector3::Create(0.0, -1.0, 0.0));
|
pd.normals.push_back(Vector3::Create(0.0, -1.0, 0.0));
|
||||||
mi.normals.push_back(Vector3::Create(0.0, -1.0, 0.0));
|
pd.normals.push_back(Vector3::Create(0.0, -1.0, 0.0));
|
||||||
mi.normals.push_back(Vector3::Create(0.0, -1.0, 0.0));
|
pd.normals.push_back(Vector3::Create(0.0, -1.0, 0.0));
|
||||||
|
|
||||||
mi.vertex_indexes.push_back(b + 0);
|
pd.indexes.push_back(b + 0);
|
||||||
mi.vertex_indexes.push_back(b + 1);
|
pd.indexes.push_back(b + 1);
|
||||||
mi.vertex_indexes.push_back(b + 2);
|
pd.indexes.push_back(b + 2);
|
||||||
mi.vertex_indexes.push_back(b + 2);
|
pd.indexes.push_back(b + 2);
|
||||||
mi.vertex_indexes.push_back(b + 1);
|
pd.indexes.push_back(b + 1);
|
||||||
mi.vertex_indexes.push_back(b + 3);
|
pd.indexes.push_back(b + 3);
|
||||||
b += 4;
|
b += 4;
|
||||||
|
|
||||||
mi.vertices.push_back(Vector3::Create(-1.0, 1.0, 1.0));
|
pd.vertices.push_back(Vector3::Create(-1.0, 1.0, 1.0));
|
||||||
mi.vertices.push_back(Vector3::Create(-1.0, -1.0, 1.0));
|
pd.vertices.push_back(Vector3::Create(-1.0, -1.0, 1.0));
|
||||||
mi.vertices.push_back(Vector3::Create(-1.0, 1.0, -1.0));
|
pd.vertices.push_back(Vector3::Create(-1.0, 1.0, -1.0));
|
||||||
mi.vertices.push_back(Vector3::Create(-1.0, -1.0, -1.0));
|
pd.vertices.push_back(Vector3::Create(-1.0, -1.0, -1.0));
|
||||||
mi.normals.push_back(Vector3::Create(-1.0, 0.0, 0.0));
|
pd.normals.push_back(Vector3::Create(-1.0, 0.0, 0.0));
|
||||||
mi.normals.push_back(Vector3::Create(-1.0, 0.0, 0.0));
|
pd.normals.push_back(Vector3::Create(-1.0, 0.0, 0.0));
|
||||||
mi.normals.push_back(Vector3::Create(-1.0, 0.0, 0.0));
|
pd.normals.push_back(Vector3::Create(-1.0, 0.0, 0.0));
|
||||||
mi.normals.push_back(Vector3::Create(-1.0, 0.0, 0.0));
|
pd.normals.push_back(Vector3::Create(-1.0, 0.0, 0.0));
|
||||||
|
|
||||||
mi.vertex_indexes.push_back(b + 3);
|
pd.indexes.push_back(b + 3);
|
||||||
mi.vertex_indexes.push_back(b + 1);
|
pd.indexes.push_back(b + 1);
|
||||||
mi.vertex_indexes.push_back(b + 2);
|
pd.indexes.push_back(b + 2);
|
||||||
mi.vertex_indexes.push_back(b + 2);
|
pd.indexes.push_back(b + 2);
|
||||||
mi.vertex_indexes.push_back(b + 1);
|
pd.indexes.push_back(b + 1);
|
||||||
mi.vertex_indexes.push_back(b + 0);
|
pd.indexes.push_back(b + 0);
|
||||||
b += 4;
|
b += 4;
|
||||||
|
|
||||||
|
|
||||||
mi.submesh_starts.push_back(0);
|
pd.materialName = "__white";
|
||||||
mi.submesh_lengths.push_back((int)mi.vertex_indexes.size());
|
pd.format = Topology::Triangles;
|
||||||
mi.vertex_index_bases.push_back(std::make_pair<int, int>(0, 0));
|
|
||||||
mi.material_names.push_back("__white");
|
|
||||||
mi.format = Topology::Triangles;
|
|
||||||
|
|
||||||
LoadData(mi, true, true);
|
MeshDesc md{};
|
||||||
|
md.primitives.push_back(pd);
|
||||||
|
LoadDesc(md, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
KRMeshCube::~KRMeshCube()
|
KRMeshCube::~KRMeshCube()
|
||||||
|
|||||||
@@ -37,25 +37,24 @@ KRMeshQuad::KRMeshQuad(KRContext& context) : KRMesh(context, "__quad")
|
|||||||
{
|
{
|
||||||
m_constant = true;
|
m_constant = true;
|
||||||
|
|
||||||
KRMesh::mesh_info mi;
|
KRMesh::MeshDesc md{};
|
||||||
|
KRMesh::PrimitiveDesc pd{};
|
||||||
|
pd.vertices.push_back(Vector3::Create(-1.0f, -1.0f, 0.0f));
|
||||||
|
pd.vertices.push_back(Vector3::Create(1.0f, -1.0f, 0.0f));
|
||||||
|
pd.vertices.push_back(Vector3::Create(-1.0f, 1.0f, 0.0f));
|
||||||
|
pd.vertices.push_back(Vector3::Create(1.0f, 1.0f, 0.0f));
|
||||||
|
|
||||||
mi.vertices.push_back(Vector3::Create(-1.0f, -1.0f, 0.0f));
|
pd.texcoord[0].push_back(Vector2::Create(0.0f, 0.0f));
|
||||||
mi.vertices.push_back(Vector3::Create(1.0f, -1.0f, 0.0f));
|
pd.texcoord[0].push_back(Vector2::Create(1.0f, 0.0f));
|
||||||
mi.vertices.push_back(Vector3::Create(-1.0f, 1.0f, 0.0f));
|
pd.texcoord[0].push_back(Vector2::Create(0.0f, 1.0f));
|
||||||
mi.vertices.push_back(Vector3::Create(1.0f, 1.0f, 0.0f));
|
pd.texcoord[0].push_back(Vector2::Create(1.0f, 1.0f));
|
||||||
|
|
||||||
mi.texcoord[0].push_back(Vector2::Create(0.0f, 0.0f));
|
pd.materialName = "__white";
|
||||||
mi.texcoord[0].push_back(Vector2::Create(1.0f, 0.0f));
|
pd.format = Topology::TriangleStrips;
|
||||||
mi.texcoord[0].push_back(Vector2::Create(0.0f, 1.0f));
|
|
||||||
mi.texcoord[0].push_back(Vector2::Create(1.0f, 1.0f));
|
|
||||||
|
|
||||||
|
md.primitives.push_back(pd);
|
||||||
|
|
||||||
mi.submesh_starts.push_back(0);
|
LoadDesc(md, true, true);
|
||||||
mi.submesh_lengths.push_back((int)mi.vertices.size());
|
|
||||||
mi.material_names.push_back("__white");
|
|
||||||
mi.format = Topology::TriangleStrips;
|
|
||||||
|
|
||||||
LoadData(mi, true, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
KRMeshQuad::~KRMeshQuad()
|
KRMeshQuad::~KRMeshQuad()
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ KRMeshSphere::KRMeshSphere(KRContext& context) : KRMesh(context, "__sphere")
|
|||||||
{
|
{
|
||||||
m_constant = true;
|
m_constant = true;
|
||||||
|
|
||||||
KRMesh::mesh_info mi;
|
KRMesh::PrimitiveDesc primitive{};
|
||||||
|
|
||||||
// Create a triangular facet approximation to a sphere
|
// Create a triangular facet approximation to a sphere
|
||||||
// Based on algorithm from Paul Bourke: http://paulbourke.net/miscellaneous/sphere_cylinder/
|
// Based on algorithm from Paul Bourke: http://paulbourke.net/miscellaneous/sphere_cylinder/
|
||||||
@@ -103,23 +103,23 @@ KRMeshSphere::KRMeshSphere(KRContext& context) : KRMesh(context, "__sphere")
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int facet_index = 0; facet_index < facet_count; facet_index++) {
|
for (int facet_index = 0; facet_index < facet_count; facet_index++) {
|
||||||
mi.vertices.push_back(f[facet_index][0]);
|
primitive.vertices.push_back(f[facet_index][0]);
|
||||||
mi.vertices.push_back(f[facet_index][1]);
|
primitive.vertices.push_back(f[facet_index][1]);
|
||||||
mi.vertices.push_back(f[facet_index][2]);
|
primitive.vertices.push_back(f[facet_index][2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
mi.submesh_starts.push_back(0);
|
primitive.materialName = "__white";
|
||||||
mi.submesh_lengths.push_back((int)mi.vertices.size());
|
primitive.format = Topology::Triangles;
|
||||||
mi.material_names.push_back("__white");
|
|
||||||
|
|
||||||
mi.format = Topology::Triangles;
|
|
||||||
|
|
||||||
// Generate normals pointing away from center of sphere.
|
// Generate normals pointing away from center of sphere.
|
||||||
for (int vertex_index = 0; vertex_index < mi.vertices.size(); vertex_index++) {
|
for (int vertex_index = 0; vertex_index < primitive.vertices.size(); vertex_index++) {
|
||||||
mi.normals.push_back(Vector3::Normalize(mi.vertices[vertex_index] - Vector3::Zero()));
|
primitive.normals.push_back(Vector3::Normalize(primitive.vertices[vertex_index] - Vector3::Zero()));
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadData(mi, true, true);
|
MeshDesc md{};
|
||||||
|
md.primitives.push_back(primitive);
|
||||||
|
|
||||||
|
LoadDesc(md, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
KRMeshSphere::~KRMeshSphere()
|
KRMeshSphere::~KRMeshSphere()
|
||||||
|
|||||||
Reference in New Issue
Block a user