mesh -> dynamicmesh
This commit is contained in:
+21
-18
@@ -11,11 +11,11 @@
|
||||
|
||||
#include <tamtypes.h>
|
||||
#include "math/m4x4.hpp"
|
||||
#include "renderer/3d/mesh/mesh.hpp"
|
||||
#include "renderer/3d/mesh/dynamic/dynamic_mesh.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
Mesh::Mesh(const MeshBuilderData& data) {
|
||||
DynamicMesh::DynamicMesh(const MeshBuilderData& data) {
|
||||
id = rand() % 1000000;
|
||||
|
||||
framesCount = data.framesCount;
|
||||
@@ -24,14 +24,14 @@ Mesh::Mesh(const MeshBuilderData& data) {
|
||||
materialsCount = data.materialsCount;
|
||||
TYRA_ASSERT(materialsCount > 0, "Materials count must be greater than 0");
|
||||
|
||||
frames = new MeshFrame*[framesCount];
|
||||
frames = new DynamicMeshFrame*[framesCount];
|
||||
for (u32 i = 0; i < framesCount; i++) {
|
||||
frames[i] = new MeshFrame(data, i);
|
||||
frames[i] = new DynamicMeshFrame(data, i);
|
||||
}
|
||||
|
||||
materials = new MeshMaterial*[materialsCount];
|
||||
materials = new DynamicMeshMaterial*[materialsCount];
|
||||
for (u32 i = 0; i < materialsCount; i++) {
|
||||
materials[i] = new MeshMaterial(data, i);
|
||||
materials[i] = new DynamicMeshMaterial(data, i);
|
||||
}
|
||||
|
||||
translation.translate(Vec4(0.0F, 0.0F, 0.0F, 1.0F));
|
||||
@@ -41,20 +41,20 @@ Mesh::Mesh(const MeshBuilderData& data) {
|
||||
_isMother = true;
|
||||
}
|
||||
|
||||
Mesh::Mesh(const Mesh& mesh) {
|
||||
DynamicMesh::DynamicMesh(const DynamicMesh& mesh) {
|
||||
id = rand() % 1000000;
|
||||
|
||||
framesCount = mesh.framesCount;
|
||||
materialsCount = mesh.materialsCount;
|
||||
|
||||
frames = new MeshFrame*[framesCount];
|
||||
frames = new DynamicMeshFrame*[framesCount];
|
||||
for (u32 i = 0; i < framesCount; i++) {
|
||||
frames[i] = new MeshFrame(*mesh.frames[i]);
|
||||
frames[i] = new DynamicMeshFrame(*mesh.frames[i]);
|
||||
}
|
||||
|
||||
materials = new MeshMaterial*[materialsCount];
|
||||
materials = new DynamicMeshMaterial*[materialsCount];
|
||||
for (u32 i = 0; i < materialsCount; i++) {
|
||||
materials[i] = new MeshMaterial(*mesh.materials[i]);
|
||||
materials[i] = new DynamicMeshMaterial(*mesh.materials[i]);
|
||||
}
|
||||
|
||||
translation.translate(Vec4(0.0F, 0.0F, 0.0F, 1.0F));
|
||||
@@ -64,7 +64,7 @@ Mesh::Mesh(const Mesh& mesh) {
|
||||
_isMother = false;
|
||||
}
|
||||
|
||||
Mesh::~Mesh() {
|
||||
DynamicMesh::~DynamicMesh() {
|
||||
for (u32 i = 0; i < framesCount; i++) {
|
||||
delete frames[i];
|
||||
}
|
||||
@@ -77,9 +77,11 @@ Mesh::~Mesh() {
|
||||
}
|
||||
}
|
||||
|
||||
M4x4 Mesh::getModelMatrix() const { return translation * rotation * scale; }
|
||||
M4x4 DynamicMesh::getModelMatrix() const {
|
||||
return translation * rotation * scale;
|
||||
}
|
||||
|
||||
void Mesh::initMesh() {
|
||||
void DynamicMesh::initMesh() {
|
||||
animState.startFrame = 0;
|
||||
animState.endFrame = 0;
|
||||
animState.interpolation = 0.0F;
|
||||
@@ -91,7 +93,8 @@ void Mesh::initMesh() {
|
||||
animState.speed = 0.1F;
|
||||
}
|
||||
|
||||
void Mesh::playAnimation(const u32& t_startFrame, const u32& t_endFrame) {
|
||||
void DynamicMesh::playAnimation(const u32& t_startFrame,
|
||||
const u32& t_endFrame) {
|
||||
TYRA_ASSERT(framesCount > 0,
|
||||
"Cant play animation, because no mesh data was loaded!");
|
||||
TYRA_ASSERT(framesCount != 1,
|
||||
@@ -107,8 +110,8 @@ void Mesh::playAnimation(const u32& t_startFrame, const u32& t_endFrame) {
|
||||
animState.nextFrame = t_startFrame;
|
||||
}
|
||||
|
||||
void Mesh::playAnimation(const u32& t_startFrame, const u32& t_endFrame,
|
||||
const u32& t_stayFrame) {
|
||||
void DynamicMesh::playAnimation(const u32& t_startFrame, const u32& t_endFrame,
|
||||
const u32& t_stayFrame) {
|
||||
TYRA_ASSERT(framesCount > 0,
|
||||
"Cant play animation, because no mesh data was loaded!");
|
||||
TYRA_ASSERT(framesCount != 1,
|
||||
@@ -123,7 +126,7 @@ void Mesh::playAnimation(const u32& t_startFrame, const u32& t_endFrame,
|
||||
animState.nextFrame = t_startFrame;
|
||||
}
|
||||
|
||||
void Mesh::animate() {
|
||||
void DynamicMesh::animate() {
|
||||
animState.interpolation += animState.speed;
|
||||
if (animState.interpolation >= 1.0F) {
|
||||
animState.interpolation = 0.0F;
|
||||
+8
-7
@@ -14,11 +14,12 @@
|
||||
#include <string>
|
||||
#include "math/vec4.hpp"
|
||||
#include "renderer/models/color.hpp"
|
||||
#include "renderer/3d/mesh/mesh_frame.hpp"
|
||||
#include "renderer/3d/mesh/dynamic/dynamic_mesh_frame.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
MeshFrame::MeshFrame(const MeshBuilderData& data, const u32& index) {
|
||||
DynamicMeshFrame::DynamicMeshFrame(const MeshBuilderData& data,
|
||||
const u32& index) {
|
||||
TYRA_ASSERT(index < data.framesCount && index >= 0, "Provided index \"",
|
||||
index, "\" is out of range");
|
||||
|
||||
@@ -62,7 +63,7 @@ MeshFrame::MeshFrame(const MeshBuilderData& data, const u32& index) {
|
||||
_isMother = true;
|
||||
}
|
||||
|
||||
MeshFrame::MeshFrame(const MeshFrame& frame) {
|
||||
DynamicMeshFrame::DynamicMeshFrame(const DynamicMeshFrame& frame) {
|
||||
id = rand() % 1000000;
|
||||
|
||||
vertices = frame.vertices;
|
||||
@@ -80,7 +81,7 @@ MeshFrame::MeshFrame(const MeshFrame& frame) {
|
||||
_isMother = false;
|
||||
}
|
||||
|
||||
MeshFrame::~MeshFrame() {
|
||||
DynamicMeshFrame::~DynamicMeshFrame() {
|
||||
if (_isMother) {
|
||||
delete[] vertices;
|
||||
if (normals) delete[] normals;
|
||||
@@ -90,17 +91,17 @@ MeshFrame::~MeshFrame() {
|
||||
}
|
||||
}
|
||||
|
||||
void MeshFrame::print() const {
|
||||
void DynamicMeshFrame::print() const {
|
||||
auto text = getPrint(nullptr);
|
||||
printf("%s\n", text.c_str());
|
||||
}
|
||||
|
||||
void MeshFrame::print(const char* name) const {
|
||||
void DynamicMeshFrame::print(const char* name) const {
|
||||
auto text = getPrint(name);
|
||||
printf("%s\n", text.c_str());
|
||||
}
|
||||
|
||||
std::string MeshFrame::getPrint(const char* name) const {
|
||||
std::string DynamicMeshFrame::getPrint(const char* name) const {
|
||||
std::stringstream res;
|
||||
if (name) {
|
||||
res << name << "(";
|
||||
+16
-16
@@ -12,12 +12,12 @@
|
||||
#include <tamtypes.h>
|
||||
#include <string>
|
||||
#include <cstdlib>
|
||||
#include "renderer/3d/mesh/mesh_material.hpp"
|
||||
#include "renderer/3d/mesh/dynamic/dynamic_mesh_material.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
MeshMaterial::MeshMaterial(const MeshBuilderData& data,
|
||||
const u32& materialIndex)
|
||||
DynamicMeshMaterial::DynamicMeshMaterial(const MeshBuilderData& data,
|
||||
const u32& materialIndex)
|
||||
: singleColor(false) {
|
||||
TYRA_ASSERT(materialIndex < data.materialsCount && materialIndex >= 0,
|
||||
"Provided index \"", materialIndex, "\" is out of range");
|
||||
@@ -57,18 +57,18 @@ MeshMaterial::MeshMaterial(const MeshBuilderData& data,
|
||||
TYRA_ASSERT(facesCount > 0, "Faces count must be greater than 0");
|
||||
|
||||
_name = data.materials[materialIndex]->name;
|
||||
TYRA_ASSERT(_name.length() > 0, "MeshMaterial name cannot be empty");
|
||||
TYRA_ASSERT(_name.length() > 0, "DynamicMeshMaterial name cannot be empty");
|
||||
|
||||
framesCount = data.framesCount;
|
||||
frames = new MeshMaterialFrame*[framesCount];
|
||||
frames = new DynamicMeshMaterialFrame*[framesCount];
|
||||
for (u32 i = 0; i < framesCount; i++) {
|
||||
frames[i] = new MeshMaterialFrame(data, i, materialIndex);
|
||||
frames[i] = new DynamicMeshMaterialFrame(data, i, materialIndex);
|
||||
}
|
||||
|
||||
_isMother = true;
|
||||
}
|
||||
|
||||
MeshMaterial::MeshMaterial(const MeshMaterial& mesh) {
|
||||
DynamicMeshMaterial::DynamicMeshMaterial(const DynamicMeshMaterial& mesh) {
|
||||
id = rand() % 1000000;
|
||||
|
||||
vertexFaces = mesh.vertexFaces;
|
||||
@@ -82,15 +82,15 @@ MeshMaterial::MeshMaterial(const MeshMaterial& mesh) {
|
||||
|
||||
singleColor.set(128.0F, 128.0F, 128.0F, 128.0F);
|
||||
|
||||
frames = new MeshMaterialFrame*[framesCount];
|
||||
frames = new DynamicMeshMaterialFrame*[framesCount];
|
||||
for (u32 i = 0; i < framesCount; i++) {
|
||||
frames[i] = new MeshMaterialFrame(*mesh.frames[i]);
|
||||
frames[i] = new DynamicMeshMaterialFrame(*mesh.frames[i]);
|
||||
}
|
||||
|
||||
_isMother = false;
|
||||
}
|
||||
|
||||
MeshMaterial::~MeshMaterial() {
|
||||
DynamicMeshMaterial::~DynamicMeshMaterial() {
|
||||
if (_isMother) {
|
||||
delete[] vertexFaces;
|
||||
if (textureCoordFaces) delete[] textureCoordFaces;
|
||||
@@ -104,11 +104,11 @@ MeshMaterial::~MeshMaterial() {
|
||||
delete[] frames;
|
||||
}
|
||||
|
||||
const BBox& MeshMaterial::getBBox(const u32& frame) const {
|
||||
const BBox& DynamicMeshMaterial::getBBox(const u32& frame) const {
|
||||
return frames[frame]->getBBox();
|
||||
}
|
||||
|
||||
void MeshMaterial::setSingleColorFlag(const u8& flag) {
|
||||
void DynamicMeshMaterial::setSingleColorFlag(const u8& flag) {
|
||||
TYRA_ASSERT(
|
||||
colorFaces != nullptr,
|
||||
"Colors and color faces are required to use color-per-vertex mode");
|
||||
@@ -116,22 +116,22 @@ void MeshMaterial::setSingleColorFlag(const u8& flag) {
|
||||
singleColorFlag = flag;
|
||||
}
|
||||
|
||||
void MeshMaterial::print() const {
|
||||
void DynamicMeshMaterial::print() const {
|
||||
auto text = getPrint(nullptr);
|
||||
printf("%s\n", text.c_str());
|
||||
}
|
||||
|
||||
void MeshMaterial::print(const char* name) const {
|
||||
void DynamicMeshMaterial::print(const char* name) const {
|
||||
auto text = getPrint(name);
|
||||
printf("%s\n", text.c_str());
|
||||
}
|
||||
|
||||
std::string MeshMaterial::getPrint(const char* name) const {
|
||||
std::string DynamicMeshMaterial::getPrint(const char* name) const {
|
||||
std::stringstream res;
|
||||
if (name) {
|
||||
res << name << "(";
|
||||
} else {
|
||||
res << "MeshMaterial(";
|
||||
res << "DynamicMeshMaterial(";
|
||||
}
|
||||
|
||||
res << std::endl;
|
||||
+7
-6
@@ -13,13 +13,13 @@
|
||||
#include <tamtypes.h>
|
||||
#include "renderer/models/color.hpp"
|
||||
#include "loaders/3d/builder/mesh_builder_data.hpp"
|
||||
#include "renderer/3d/mesh/mesh_material_frame.hpp"
|
||||
#include "renderer/3d/mesh/dynamic/dynamic_mesh_material_frame.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
MeshMaterialFrame::MeshMaterialFrame(const MeshBuilderData& data,
|
||||
const u32& frameIndex,
|
||||
const u32& materialIndex) {
|
||||
DynamicMeshMaterialFrame::DynamicMeshMaterialFrame(const MeshBuilderData& data,
|
||||
const u32& frameIndex,
|
||||
const u32& materialIndex) {
|
||||
TYRA_ASSERT(frameIndex < data.framesCount && frameIndex >= 0,
|
||||
"Provided index \"", frameIndex, "\" is out of range");
|
||||
TYRA_ASSERT(materialIndex < data.materialsCount && materialIndex >= 0,
|
||||
@@ -34,7 +34,8 @@ MeshMaterialFrame::MeshMaterialFrame(const MeshBuilderData& data,
|
||||
_isMother = true;
|
||||
}
|
||||
|
||||
MeshMaterialFrame::MeshMaterialFrame(const MeshMaterialFrame& frame) {
|
||||
DynamicMeshMaterialFrame::DynamicMeshMaterialFrame(
|
||||
const DynamicMeshMaterialFrame& frame) {
|
||||
id = rand() % 1000000;
|
||||
|
||||
bbox = frame.bbox;
|
||||
@@ -42,7 +43,7 @@ MeshMaterialFrame::MeshMaterialFrame(const MeshMaterialFrame& frame) {
|
||||
_isMother = false;
|
||||
}
|
||||
|
||||
MeshMaterialFrame::~MeshMaterialFrame() {
|
||||
DynamicMeshMaterialFrame::~DynamicMeshMaterialFrame() {
|
||||
if (_isMother) {
|
||||
delete bbox;
|
||||
}
|
||||
@@ -23,16 +23,17 @@ void Stapipeline::init(RendererCore* t_core) {
|
||||
|
||||
void Stapipeline::onUse() { core.reinitStandardVU1Programs(); }
|
||||
|
||||
void Stapipeline::render(Mesh* mesh, const StapipOptions* options) {
|
||||
void Stapipeline::render(DynamicMesh* mesh, const StapipOptions* options) {
|
||||
auto model = mesh->getModelMatrix();
|
||||
|
||||
MeshFrame* frameFrom = mesh->getFramesCount() > 0
|
||||
? mesh->getFrame(mesh->getCurrentAnimationFrame())
|
||||
: mesh->getFrame(0);
|
||||
DynamicMeshFrame* frameFrom =
|
||||
mesh->getFramesCount() > 0
|
||||
? mesh->getFrame(mesh->getCurrentAnimationFrame())
|
||||
: mesh->getFrame(0);
|
||||
|
||||
MeshFrame* frameTo = mesh->getFramesCount() > 0
|
||||
? mesh->getFrame(mesh->getNextAnimationFrame())
|
||||
: nullptr;
|
||||
DynamicMeshFrame* frameTo =
|
||||
mesh->getFramesCount() > 0 ? mesh->getFrame(mesh->getNextAnimationFrame())
|
||||
: nullptr;
|
||||
|
||||
auto* infoBag = getInfoBag(mesh, options, &model);
|
||||
|
||||
@@ -65,9 +66,9 @@ void Stapipeline::render(Mesh* mesh, const StapipOptions* options) {
|
||||
delete infoBag;
|
||||
}
|
||||
|
||||
void Stapipeline::addVertices(Mesh* mesh, MeshMaterial* material,
|
||||
StapipBag* bag, MeshFrame* frameFrom,
|
||||
MeshFrame* frameTo) const {
|
||||
void Stapipeline::addVertices(DynamicMesh* mesh, DynamicMeshMaterial* material,
|
||||
StapipBag* bag, DynamicMeshFrame* frameFrom,
|
||||
DynamicMeshFrame* frameTo) const {
|
||||
bag->count = material->getFacesCount();
|
||||
bag->vertices = new Vec4[bag->count];
|
||||
|
||||
@@ -83,7 +84,8 @@ void Stapipeline::addVertices(Mesh* mesh, MeshMaterial* material,
|
||||
}
|
||||
}
|
||||
|
||||
StapipInfoBag* Stapipeline::getInfoBag(Mesh* mesh, const StapipOptions* options,
|
||||
StapipInfoBag* Stapipeline::getInfoBag(DynamicMesh* mesh,
|
||||
const StapipOptions* options,
|
||||
M4x4* model) const {
|
||||
auto* result = new StapipInfoBag();
|
||||
|
||||
@@ -104,9 +106,10 @@ StapipInfoBag* Stapipeline::getInfoBag(Mesh* mesh, const StapipOptions* options,
|
||||
return result;
|
||||
}
|
||||
|
||||
StapipColorBag* Stapipeline::getColorBag(Mesh* mesh, MeshMaterial* material,
|
||||
MeshFrame* frameFrom,
|
||||
MeshFrame* frameTo) const {
|
||||
StapipColorBag* Stapipeline::getColorBag(DynamicMesh* mesh,
|
||||
DynamicMeshMaterial* material,
|
||||
DynamicMeshFrame* frameFrom,
|
||||
DynamicMeshFrame* frameTo) const {
|
||||
auto* result = new StapipColorBag();
|
||||
|
||||
if (material->isSingleColorActivated()) {
|
||||
@@ -131,9 +134,10 @@ StapipColorBag* Stapipeline::getColorBag(Mesh* mesh, MeshMaterial* material,
|
||||
return result;
|
||||
}
|
||||
|
||||
StapipTextureBag* Stapipeline::getTextureBag(Mesh* mesh, MeshMaterial* material,
|
||||
MeshFrame* frameFrom,
|
||||
MeshFrame* frameTo) {
|
||||
StapipTextureBag* Stapipeline::getTextureBag(DynamicMesh* mesh,
|
||||
DynamicMeshMaterial* material,
|
||||
DynamicMeshFrame* frameFrom,
|
||||
DynamicMeshFrame* frameTo) {
|
||||
if (!material->getTextureCoordFaces()) return nullptr;
|
||||
|
||||
auto* result = new StapipTextureBag();
|
||||
@@ -161,8 +165,9 @@ StapipTextureBag* Stapipeline::getTextureBag(Mesh* mesh, MeshMaterial* material,
|
||||
}
|
||||
|
||||
StapipLightingBag* Stapipeline::getLightingBag(
|
||||
Mesh* mesh, MeshMaterial* material, M4x4* model, MeshFrame* frameFrom,
|
||||
MeshFrame* frameTo, const StapipOptions* options) const {
|
||||
DynamicMesh* mesh, DynamicMeshMaterial* material, M4x4* model,
|
||||
DynamicMeshFrame* frameFrom, DynamicMeshFrame* frameTo,
|
||||
const StapipOptions* options) const {
|
||||
if (!material->getNormalFaces() || options == nullptr ||
|
||||
options->lighting == nullptr)
|
||||
return nullptr;
|
||||
@@ -199,7 +204,7 @@ void Stapipeline::setLightingColorsCache(
|
||||
}
|
||||
|
||||
void Stapipeline::deallocDrawBags(StapipBag* bag,
|
||||
MeshMaterial* material) const {
|
||||
DynamicMeshMaterial* material) const {
|
||||
if (bag->color->many) {
|
||||
delete[] bag->color->many;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ Texture* TextureRepository::add(const char* fullpath) {
|
||||
return texture;
|
||||
}
|
||||
|
||||
void TextureRepository::addByMesh(Mesh* mesh, const char* directory,
|
||||
void TextureRepository::addByMesh(DynamicMesh* mesh, const char* directory,
|
||||
const char* extension) {
|
||||
auto& loader = texLoaderSelector.getLoaderByExtension(extension);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user