mesh builder v2
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
------------ Tyra's v2.0 roadmap to publish on GitHub ------------
|
------------ Tyra's v2.0 roadmap to publish on GitHub ------------
|
||||||
|
- [General] builder2
|
||||||
|
- [General] std::vector in mesh instead of array**
|
||||||
- [General] Allow to edit all data from mesh/texture
|
- [General] Allow to edit all data from mesh/texture
|
||||||
|
- [General] manycolor -> lightmap
|
||||||
|
|
||||||
- [General] USB test
|
- [General] USB test
|
||||||
- [General] Tyra version, render it on start
|
- [General] Tyra version, render it on start
|
||||||
- [Renderer] Fog
|
- [Renderer] Fog
|
||||||
@@ -36,6 +40,7 @@ because Mesh rendering uses only core.render()
|
|||||||
- [File] Async file loading
|
- [File] Async file loading
|
||||||
- [tyrobj] Add multicolor support to tyrobj
|
- [tyrobj] Add multicolor support to tyrobj
|
||||||
- [Tyrobj] Improve obj importing for multiple usemtl with same names
|
- [Tyrobj] Improve obj importing for multiple usemtl with same names
|
||||||
|
- [tyrdata] Custom 3D data file with precalculated bboxes with support of async loading
|
||||||
- [Renderer] Interlacing
|
- [Renderer] Interlacing
|
||||||
- [General] Add cpp lint checker in GitHub
|
- [General] Add cpp lint checker in GitHub
|
||||||
- [General] Control generated id to avoid duplication. Maybe Just increment from 0? Add interface IIdentificable?
|
- [General] Control generated id to avoid duplication. Maybe Just increment from 0? Add interface IIdentificable?
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
|
||||||
|
/*
|
||||||
|
# ______ ____ ___
|
||||||
|
# | \/ ____| |___|
|
||||||
|
# | | | \ | |
|
||||||
|
#-----------------------------------------------------------------------
|
||||||
|
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||||
|
# Licenced under Apache License 2.0
|
||||||
|
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include "./mesh_builder2_material_data.hpp"
|
||||||
|
|
||||||
|
namespace Tyra {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data needed for constructing mesh class.
|
||||||
|
* All dynamic data ownership is moved to mesh class, so
|
||||||
|
* there is no any deallocation!
|
||||||
|
*/
|
||||||
|
class MeshBuilder2Data {
|
||||||
|
public:
|
||||||
|
MeshBuilder2Data();
|
||||||
|
~MeshBuilder2Data();
|
||||||
|
|
||||||
|
std::vector<MeshBuilder2MaterialData*> materials;
|
||||||
|
|
||||||
|
bool textureCoordsEnabled, normalsEnabled, lightMapEnabled;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Tyra
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
|
||||||
|
/*
|
||||||
|
# ______ ____ ___
|
||||||
|
# | \/ ____| |___|
|
||||||
|
# | | | \ | |
|
||||||
|
#-----------------------------------------------------------------------
|
||||||
|
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||||
|
# Licenced under Apache License 2.0
|
||||||
|
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include "./mesh_builder2_material_frame_data.hpp"
|
||||||
|
|
||||||
|
namespace Tyra {
|
||||||
|
|
||||||
|
class MeshBuilder2MaterialData {
|
||||||
|
public:
|
||||||
|
MeshBuilder2MaterialData();
|
||||||
|
~MeshBuilder2MaterialData();
|
||||||
|
|
||||||
|
std::vector<MeshBuilder2MaterialFrameData*> frames;
|
||||||
|
std::string name;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Tyra
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
|
||||||
|
/*
|
||||||
|
# ______ ____ ___
|
||||||
|
# | \/ ____| |___|
|
||||||
|
# | | | \ | |
|
||||||
|
#-----------------------------------------------------------------------
|
||||||
|
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||||
|
# Licenced under Apache License 2.0
|
||||||
|
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <tamtypes.h>
|
||||||
|
#include "math/vec4.hpp"
|
||||||
|
#include "renderer/models/color.hpp"
|
||||||
|
|
||||||
|
namespace Tyra {
|
||||||
|
|
||||||
|
class MeshBuilder2MaterialFrameData {
|
||||||
|
public:
|
||||||
|
MeshBuilder2MaterialFrameData();
|
||||||
|
~MeshBuilder2MaterialFrameData();
|
||||||
|
|
||||||
|
u32 count;
|
||||||
|
Vec4 *vertices, *textureCoords, *normals;
|
||||||
|
Color* colors;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Tyra
|
||||||
@@ -21,6 +21,7 @@ namespace Tyra {
|
|||||||
class DynamicMesh : public Mesh {
|
class DynamicMesh : public Mesh {
|
||||||
public:
|
public:
|
||||||
explicit DynamicMesh(const MeshBuilderData& data);
|
explicit DynamicMesh(const MeshBuilderData& data);
|
||||||
|
explicit DynamicMesh(const MeshBuilder2Data& data);
|
||||||
explicit DynamicMesh(const DynamicMesh& mesh);
|
explicit DynamicMesh(const DynamicMesh& mesh);
|
||||||
~DynamicMesh();
|
~DynamicMesh();
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ namespace Tyra {
|
|||||||
class Mesh {
|
class Mesh {
|
||||||
public:
|
public:
|
||||||
explicit Mesh(const MeshBuilderData& data);
|
explicit Mesh(const MeshBuilderData& data);
|
||||||
|
explicit Mesh(const MeshBuilder2Data& data);
|
||||||
explicit Mesh(const Mesh& mesh);
|
explicit Mesh(const Mesh& mesh);
|
||||||
~Mesh();
|
~Mesh();
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "./mesh_material.hpp"
|
#include "./mesh_material.hpp"
|
||||||
#include "loaders/3d/builder/mesh_builder_data.hpp"
|
#include "loaders/3d/builder/mesh_builder_data.hpp"
|
||||||
|
#include "loaders/3d/builder2/mesh_builder2_data.hpp"
|
||||||
#include "renderer/3d/bbox/bbox.hpp"
|
#include "renderer/3d/bbox/bbox.hpp"
|
||||||
|
|
||||||
namespace Tyra {
|
namespace Tyra {
|
||||||
@@ -19,6 +20,7 @@ namespace Tyra {
|
|||||||
class MeshFrame {
|
class MeshFrame {
|
||||||
public:
|
public:
|
||||||
explicit MeshFrame(const MeshBuilderData& data, const u32& index);
|
explicit MeshFrame(const MeshBuilderData& data, const u32& index);
|
||||||
|
explicit MeshFrame(const MeshBuilder2Data& data, const u32& index);
|
||||||
explicit MeshFrame(const MeshFrame& frame);
|
explicit MeshFrame(const MeshFrame& frame);
|
||||||
~MeshFrame();
|
~MeshFrame();
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "debug/debug.hpp"
|
#include "debug/debug.hpp"
|
||||||
#include "loaders/3d/builder/mesh_builder_data.hpp"
|
#include "loaders/3d/builder/mesh_builder_data.hpp"
|
||||||
|
#include "loaders/3d/builder2/mesh_builder2_data.hpp"
|
||||||
#include "./mesh_material_frame.hpp"
|
#include "./mesh_material_frame.hpp"
|
||||||
|
|
||||||
namespace Tyra {
|
namespace Tyra {
|
||||||
@@ -19,6 +20,7 @@ namespace Tyra {
|
|||||||
class MeshMaterial {
|
class MeshMaterial {
|
||||||
public:
|
public:
|
||||||
explicit MeshMaterial(const MeshBuilderData& data, const u32& materialIndex);
|
explicit MeshMaterial(const MeshBuilderData& data, const u32& materialIndex);
|
||||||
|
explicit MeshMaterial(const MeshBuilder2Data& data, const u32& materialIndex);
|
||||||
explicit MeshMaterial(const MeshMaterial& material);
|
explicit MeshMaterial(const MeshMaterial& material);
|
||||||
~MeshMaterial();
|
~MeshMaterial();
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "loaders/3d/builder/mesh_builder_data.hpp"
|
#include "loaders/3d/builder/mesh_builder_data.hpp"
|
||||||
|
#include "loaders/3d/builder2/mesh_builder2_data.hpp"
|
||||||
#include "./renderer/3d/bbox/bbox.hpp"
|
#include "./renderer/3d/bbox/bbox.hpp"
|
||||||
|
|
||||||
namespace Tyra {
|
namespace Tyra {
|
||||||
@@ -19,6 +20,8 @@ class MeshMaterialFrame {
|
|||||||
public:
|
public:
|
||||||
explicit MeshMaterialFrame(const MeshBuilderData& data, const u32& frameIndex,
|
explicit MeshMaterialFrame(const MeshBuilderData& data, const u32& frameIndex,
|
||||||
const u32& materialIndex);
|
const u32& materialIndex);
|
||||||
|
explicit MeshMaterialFrame(const MeshBuilder2Data& data,
|
||||||
|
const u32& frameIndex, const u32& materialIndex);
|
||||||
explicit MeshMaterialFrame(const MeshMaterialFrame& frame);
|
explicit MeshMaterialFrame(const MeshMaterialFrame& frame);
|
||||||
~MeshMaterialFrame();
|
~MeshMaterialFrame();
|
||||||
|
|
||||||
@@ -26,7 +29,7 @@ class MeshMaterialFrame {
|
|||||||
const u8& isMother() const { return _isMother; }
|
const u8& isMother() const { return _isMother; }
|
||||||
const BBox& getBBox() const { return *bbox; }
|
const BBox& getBBox() const { return *bbox; }
|
||||||
|
|
||||||
const u32& getVertexCount() const { return vertexCount; }
|
const u32& getVertexCount() const { return count; }
|
||||||
Vec4* getVertices() const { return vertices; }
|
Vec4* getVertices() const { return vertices; }
|
||||||
Vec4* getNormals() const { return normals; }
|
Vec4* getNormals() const { return normals; }
|
||||||
Vec4* getTextureCoords() const { return textureCoords; }
|
Vec4* getTextureCoords() const { return textureCoords; }
|
||||||
@@ -50,7 +53,7 @@ class MeshMaterialFrame {
|
|||||||
BBox* bbox;
|
BBox* bbox;
|
||||||
|
|
||||||
u8 _isMother;
|
u8 _isMother;
|
||||||
u32 id, vertexCount;
|
u32 id, count;
|
||||||
Vec4 *vertices, *textureCoords, *normals;
|
Vec4 *vertices, *textureCoords, *normals;
|
||||||
Color* colors;
|
Color* colors;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ namespace Tyra {
|
|||||||
class StaticMesh : public Mesh {
|
class StaticMesh : public Mesh {
|
||||||
public:
|
public:
|
||||||
StaticMesh(const MeshBuilderData& data);
|
StaticMesh(const MeshBuilderData& data);
|
||||||
|
StaticMesh(const MeshBuilder2Data& data);
|
||||||
StaticMesh(const StaticMesh& mesh);
|
StaticMesh(const StaticMesh& mesh);
|
||||||
~StaticMesh();
|
~StaticMesh();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
|
||||||
|
/*
|
||||||
|
# ______ ____ ___
|
||||||
|
# | \/ ____| |___|
|
||||||
|
# | | | \ | |
|
||||||
|
#-----------------------------------------------------------------------
|
||||||
|
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||||
|
# Licenced under Apache License 2.0
|
||||||
|
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "loaders/3d/builder2/mesh_builder2_data.hpp"
|
||||||
|
|
||||||
|
namespace Tyra {
|
||||||
|
|
||||||
|
MeshBuilder2Data::MeshBuilder2Data() {
|
||||||
|
textureCoordsEnabled = false;
|
||||||
|
normalsEnabled = false;
|
||||||
|
lightMapEnabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
MeshBuilder2Data::~MeshBuilder2Data() {}
|
||||||
|
|
||||||
|
} // namespace Tyra
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
/*
|
||||||
|
# ______ ____ ___
|
||||||
|
# | \/ ____| |___|
|
||||||
|
# | | | \ | |
|
||||||
|
#-----------------------------------------------------------------------
|
||||||
|
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||||
|
# Licenced under Apache License 2.0
|
||||||
|
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "loaders/3d/builder2/mesh_builder2_material_data.hpp"
|
||||||
|
|
||||||
|
namespace Tyra {
|
||||||
|
|
||||||
|
MeshBuilder2MaterialData::MeshBuilder2MaterialData() {}
|
||||||
|
MeshBuilder2MaterialData::~MeshBuilder2MaterialData() {}
|
||||||
|
|
||||||
|
} // namespace Tyra
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
|
||||||
|
/*
|
||||||
|
# ______ ____ ___
|
||||||
|
# | \/ ____| |___|
|
||||||
|
# | | | \ | |
|
||||||
|
#-----------------------------------------------------------------------
|
||||||
|
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||||
|
# Licenced under Apache License 2.0
|
||||||
|
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "loaders/3d/builder2/mesh_builder2_material_frame_data.hpp"
|
||||||
|
|
||||||
|
namespace Tyra {
|
||||||
|
|
||||||
|
MeshBuilder2MaterialFrameData::MeshBuilder2MaterialFrameData() {
|
||||||
|
vertices = nullptr;
|
||||||
|
textureCoords = nullptr;
|
||||||
|
normals = nullptr;
|
||||||
|
colors = nullptr;
|
||||||
|
}
|
||||||
|
MeshBuilder2MaterialFrameData::~MeshBuilder2MaterialFrameData() {}
|
||||||
|
|
||||||
|
} // namespace Tyra
|
||||||
@@ -30,6 +30,21 @@ DynamicMesh::DynamicMesh(const MeshBuilderData& data) : Mesh(data) {
|
|||||||
initAnimation();
|
initAnimation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DynamicMesh::DynamicMesh(const MeshBuilder2Data& data) : Mesh(data) {
|
||||||
|
framesCount = data.materials[0]->frames.size();
|
||||||
|
|
||||||
|
TYRA_ERROR(framesCount > 1,
|
||||||
|
"Frames count should be greater than 1 for DynamicMesh! Maybe you "
|
||||||
|
"should use StaticMesh?");
|
||||||
|
|
||||||
|
frames = new MeshFrame*[framesCount];
|
||||||
|
for (u32 i = 0; i < framesCount; i++) {
|
||||||
|
frames[i] = new MeshFrame(data, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
initAnimation();
|
||||||
|
}
|
||||||
|
|
||||||
DynamicMesh::DynamicMesh(const DynamicMesh& mesh) : Mesh(mesh) {
|
DynamicMesh::DynamicMesh(const DynamicMesh& mesh) : Mesh(mesh) {
|
||||||
framesCount = mesh.framesCount;
|
framesCount = mesh.framesCount;
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,22 @@ Mesh::Mesh(const MeshBuilderData& data) {
|
|||||||
_isMother = true;
|
_isMother = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Mesh::Mesh(const MeshBuilder2Data& data) {
|
||||||
|
init();
|
||||||
|
|
||||||
|
TYRA_ASSERT(data.materials.size() > 0,
|
||||||
|
"Materials count must be greater than 0");
|
||||||
|
|
||||||
|
materialsCount = data.materials.size();
|
||||||
|
materials = new MeshMaterial*[materialsCount];
|
||||||
|
|
||||||
|
for (u32 i = 0; i < materialsCount; i++) {
|
||||||
|
materials[i] = new MeshMaterial(data, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
_isMother = true;
|
||||||
|
}
|
||||||
|
|
||||||
Mesh::Mesh(const Mesh& mesh) {
|
Mesh::Mesh(const Mesh& mesh) {
|
||||||
init();
|
init();
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,23 @@ MeshFrame::MeshFrame(const MeshBuilderData& data, const u32& index) {
|
|||||||
_isMother = true;
|
_isMother = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MeshFrame::MeshFrame(const MeshBuilder2Data& data, const u32& index) {
|
||||||
|
id = rand() % 1000000;
|
||||||
|
|
||||||
|
auto bboxes = new CoreBBox*[data.materials.size()];
|
||||||
|
for (u32 i = 0; i < data.materials.size(); i++) {
|
||||||
|
bboxes[i] = new CoreBBox(data.materials[i]->frames[index]->vertices,
|
||||||
|
data.materials[i]->frames[index]->count);
|
||||||
|
}
|
||||||
|
|
||||||
|
bbox = new BBox(bboxes, data.materials.size());
|
||||||
|
|
||||||
|
for (u32 i = 0; i < data.materials.size(); i++) delete bboxes[i];
|
||||||
|
delete[] bboxes;
|
||||||
|
|
||||||
|
_isMother = true;
|
||||||
|
}
|
||||||
|
|
||||||
MeshFrame::MeshFrame(const MeshFrame& frame) {
|
MeshFrame::MeshFrame(const MeshFrame& frame) {
|
||||||
id = rand() % 1000000;
|
id = rand() % 1000000;
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,40 @@
|
|||||||
|
|
||||||
namespace Tyra {
|
namespace Tyra {
|
||||||
|
|
||||||
|
MeshMaterial::MeshMaterial(const MeshBuilder2Data& data,
|
||||||
|
const u32& materialIndex) {
|
||||||
|
TYRA_ASSERT(materialIndex < data.materials.size(), "Provided index \"",
|
||||||
|
materialIndex, "\" is out of range");
|
||||||
|
|
||||||
|
auto* material = data.materials[materialIndex];
|
||||||
|
|
||||||
|
TYRA_ASSERT(material->frames.size() > 0,
|
||||||
|
"Material must have at least one frame");
|
||||||
|
|
||||||
|
id = rand() % 1000000;
|
||||||
|
|
||||||
|
if (data.lightMapEnabled) {
|
||||||
|
singleColorFlag = false;
|
||||||
|
TYRA_ASSERT(material->frames[0]->colors != nullptr,
|
||||||
|
"Colors faces are required");
|
||||||
|
} else {
|
||||||
|
singleColorFlag = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
color.set(128.0F, 128.0F, 128.0F, 128.0F);
|
||||||
|
|
||||||
|
_name = material->name;
|
||||||
|
TYRA_ASSERT(_name.length() > 0, "MeshMaterial name cannot be empty");
|
||||||
|
|
||||||
|
framesCount = material->frames.size();
|
||||||
|
frames = new MeshMaterialFrame*[framesCount];
|
||||||
|
for (u32 i = 0; i < framesCount; i++) {
|
||||||
|
frames[i] = new MeshMaterialFrame(data, i, materialIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
_isMother = true;
|
||||||
|
}
|
||||||
|
|
||||||
MeshMaterial::MeshMaterial(const MeshBuilderData& data,
|
MeshMaterial::MeshMaterial(const MeshBuilderData& data,
|
||||||
const u32& materialIndex)
|
const u32& materialIndex)
|
||||||
: color(false) {
|
: color(false) {
|
||||||
|
|||||||
@@ -41,10 +41,53 @@ MeshMaterialFrame::MeshMaterialFrame(const MeshBuilderData& data,
|
|||||||
_isMother = true;
|
_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) {
|
MeshMaterialFrame::MeshMaterialFrame(const MeshMaterialFrame& frame) {
|
||||||
id = rand() % 1000000;
|
id = rand() % 1000000;
|
||||||
|
|
||||||
vertexCount = frame.vertexCount;
|
count = frame.count;
|
||||||
|
|
||||||
vertices = frame.vertices;
|
vertices = frame.vertices;
|
||||||
normals = frame.normals;
|
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::string MeshMaterialFrame::getPrint(const char* name) const {
|
||||||
std::stringstream res;
|
std::stringstream res;
|
||||||
if (name) {
|
if (name) {
|
||||||
@@ -76,31 +187,31 @@ std::string MeshMaterialFrame::getPrint(const char* name) const {
|
|||||||
res << std::fixed << std::setprecision(2);
|
res << std::fixed << std::setprecision(2);
|
||||||
|
|
||||||
res << "Id: " << id << ", " << std::endl;
|
res << "Id: " << id << ", " << std::endl;
|
||||||
res << "Vertex count: " << vertexCount << ", " << std::endl;
|
res << "Vertex count: " << count << ", " << std::endl;
|
||||||
res << "BBox: " << bbox->getPrint() << ", " << std::endl;
|
res << "BBox: " << bbox->getPrint() << ", " << std::endl;
|
||||||
|
|
||||||
res << "Vertices: ";
|
res << "Vertices: ";
|
||||||
for (u32 i = 0; i < vertexCount; i++) {
|
for (u32 i = 0; i < count; i++) {
|
||||||
res << vertices[i].getPrint() << ", " << std::endl;
|
res << vertices[i].getPrint() << ", " << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (normals) {
|
if (normals) {
|
||||||
res << "Normals: ";
|
res << "Normals: ";
|
||||||
for (u32 i = 0; i < vertexCount; i++) {
|
for (u32 i = 0; i < count; i++) {
|
||||||
res << normals[i].getPrint() << ", " << std::endl;
|
res << normals[i].getPrint() << ", " << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (textureCoords) {
|
if (textureCoords) {
|
||||||
res << "TextureCoords: ";
|
res << "TextureCoords: ";
|
||||||
for (u32 i = 0; i < vertexCount; i++) {
|
for (u32 i = 0; i < count; i++) {
|
||||||
res << textureCoords[i].getPrint() << ", " << std::endl;
|
res << textureCoords[i].getPrint() << ", " << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (colors) {
|
if (colors) {
|
||||||
res << "Colors: ";
|
res << "Colors: ";
|
||||||
for (u32 i = 0; i < vertexCount; i++) {
|
for (u32 i = 0; i < count; i++) {
|
||||||
res << colors[i].getPrint() << ", " << std::endl;
|
res << colors[i].getPrint() << ", " << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -110,72 +221,4 @@ std::string MeshMaterialFrame::getPrint(const char* name) const {
|
|||||||
return res.str();
|
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
|
} // namespace Tyra
|
||||||
|
|||||||
@@ -23,6 +23,14 @@ StaticMesh::StaticMesh(const MeshBuilderData& data) : Mesh(data) {
|
|||||||
frame = new MeshFrame(data, 0);
|
frame = new MeshFrame(data, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StaticMesh::StaticMesh(const MeshBuilder2Data& data) : Mesh(data) {
|
||||||
|
if (data.materials[0]->frames.size() > 1)
|
||||||
|
TYRA_WARN("Static meshes should have only one frame, but ",
|
||||||
|
data.materials[0]->frames.size(), " frames were found");
|
||||||
|
|
||||||
|
frame = new MeshFrame(data, 0);
|
||||||
|
}
|
||||||
|
|
||||||
StaticMesh::StaticMesh(const StaticMesh& mesh) : Mesh(mesh) {
|
StaticMesh::StaticMesh(const StaticMesh& mesh) : Mesh(mesh) {
|
||||||
frame = new MeshFrame(*mesh.frame);
|
frame = new MeshFrame(*mesh.frame);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user