mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-25 11:52:40 +01:00
Move Atomic and Geometry out of Clump class
This commit is contained in:
parent
8e4d73fca9
commit
a0eaf5b8b0
@ -28,7 +28,7 @@ public:
|
||||
protected:
|
||||
int debugMode;
|
||||
|
||||
std::vector<Clump::GeometryVertex> lines;
|
||||
std::vector<GeometryVertex> lines;
|
||||
size_t maxlines;
|
||||
GeometryBuffer *lineBuff;
|
||||
DrawBuffer *dbuff;
|
||||
|
@ -479,7 +479,7 @@ void GameRenderer::renderGeometry(Clump* model, size_t g,
|
||||
const glm::mat4& modelMatrix, float opacity,
|
||||
GameObject* object) {
|
||||
for (size_t sg = 0; sg < model->geometries[g]->subgeom.size(); ++sg) {
|
||||
Clump::SubGeometry& subgeom = model->geometries[g]->subgeom[sg];
|
||||
SubGeometry& subgeom = model->geometries[g]->subgeom[sg];
|
||||
|
||||
Renderer::DrawParameters dp;
|
||||
|
||||
@ -489,7 +489,7 @@ void GameRenderer::renderGeometry(Clump* model, size_t g,
|
||||
dp.textures = {0};
|
||||
|
||||
if (model->geometries[g]->materials.size() > subgeom.material) {
|
||||
Clump::Material& mat =
|
||||
Geometry::Material& mat =
|
||||
model->geometries[g]->materials[subgeom.material];
|
||||
|
||||
if (mat.textures.size() > 0) {
|
||||
|
@ -37,7 +37,7 @@ void ObjectRenderer::renderGeometry(Clump* model, size_t g,
|
||||
const glm::mat4& modelMatrix, float opacity,
|
||||
GameObject* object, RenderList& outList) {
|
||||
for (size_t sg = 0; sg < model->geometries[g]->subgeom.size(); ++sg) {
|
||||
Clump::SubGeometry& subgeom = model->geometries[g]->subgeom[sg];
|
||||
SubGeometry& subgeom = model->geometries[g]->subgeom[sg];
|
||||
|
||||
bool isTransparent = false;
|
||||
|
||||
@ -56,7 +56,7 @@ void ObjectRenderer::renderGeometry(Clump* model, size_t g,
|
||||
}
|
||||
|
||||
if (model->geometries[g]->materials.size() > subgeom.material) {
|
||||
Clump::Material& mat =
|
||||
Geometry::Material& mat =
|
||||
model->geometries[g]->materials[subgeom.material];
|
||||
|
||||
if (mat.textures.size() > 0) {
|
||||
|
@ -3,10 +3,10 @@
|
||||
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
Clump::Geometry::Geometry() : flags(0) {
|
||||
Geometry::Geometry() : flags(0) {
|
||||
}
|
||||
|
||||
Clump::Geometry::~Geometry() {
|
||||
Geometry::~Geometry() {
|
||||
}
|
||||
|
||||
ModelFrame::ModelFrame(unsigned int index, ModelFrame* parent, glm::mat3 dR,
|
||||
|
@ -76,13 +76,37 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* A clump is a collection of Frames and Atomics
|
||||
* Subgeometry
|
||||
*/
|
||||
class Clump {
|
||||
public:
|
||||
enum FaceType { Triangles = 0, TriangleStrip = 1 };
|
||||
|
||||
std::uint32_t numAtomics;
|
||||
struct SubGeometry {
|
||||
GLuint start = 0;
|
||||
size_t material = 0;
|
||||
std::vector<uint32_t> indices;
|
||||
size_t numIndices = 0;
|
||||
};
|
||||
|
||||
struct GeometryVertex {
|
||||
glm::vec3 position; /* 0 */
|
||||
glm::vec3 normal; /* 24 */
|
||||
glm::vec2 texcoord; /* 48 */
|
||||
glm::u8vec4 colour; /* 64 */
|
||||
|
||||
/** @see GeometryBuffer */
|
||||
static const AttributeList vertex_attributes() {
|
||||
return {{ATRS_Position, 3, sizeof(GeometryVertex), 0ul},
|
||||
{ATRS_Normal, 3, sizeof(GeometryVertex), sizeof(float) * 3},
|
||||
{ATRS_TexCoord, 2, sizeof(GeometryVertex), sizeof(float) * 6},
|
||||
{ATRS_Colour, 4, sizeof(GeometryVertex), sizeof(float) * 8,
|
||||
GL_UNSIGNED_BYTE}};
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Geometry
|
||||
*/
|
||||
struct Geometry {
|
||||
enum FaceType { Triangles = 0, TriangleStrip = 1 };
|
||||
|
||||
struct Texture {
|
||||
std::string name;
|
||||
@ -102,31 +126,6 @@ public:
|
||||
float ambientIntensity;
|
||||
};
|
||||
|
||||
struct SubGeometry {
|
||||
GLuint start = 0;
|
||||
size_t material;
|
||||
std::vector<uint32_t> indices;
|
||||
size_t numIndices;
|
||||
};
|
||||
|
||||
struct GeometryVertex {
|
||||
glm::vec3 position; /* 0 */
|
||||
glm::vec3 normal; /* 24 */
|
||||
glm::vec2 texcoord; /* 48 */
|
||||
glm::u8vec4 colour; /* 64 */
|
||||
|
||||
/** @see GeometryBuffer */
|
||||
static const AttributeList vertex_attributes() {
|
||||
return {
|
||||
{ATRS_Position, 3, sizeof(GeometryVertex), 0ul},
|
||||
{ATRS_Normal, 3, sizeof(GeometryVertex), sizeof(float) * 3},
|
||||
{ATRS_TexCoord, 2, sizeof(GeometryVertex), sizeof(float) * 6},
|
||||
{ATRS_Colour, 4, sizeof(GeometryVertex), sizeof(float) * 8,
|
||||
GL_UNSIGNED_BYTE}};
|
||||
}
|
||||
};
|
||||
|
||||
struct Geometry {
|
||||
DrawBuffer dbuff;
|
||||
GeometryBuffer gbuff;
|
||||
|
||||
@ -147,13 +146,24 @@ public:
|
||||
~Geometry();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The Atomic struct
|
||||
*/
|
||||
struct Atomic {
|
||||
uint32_t frame;
|
||||
uint32_t geometry;
|
||||
};
|
||||
|
||||
/**
|
||||
* A clump is a collection of Frames and Atomics
|
||||
*/
|
||||
class Clump {
|
||||
public:
|
||||
std::uint32_t numAtomics;
|
||||
|
||||
// This should be gone
|
||||
std::vector<ModelFrame*> frames;
|
||||
/** @TODO clean up this mess a little */
|
||||
// This should be gone
|
||||
std::vector<std::shared_ptr<Geometry>> geometries;
|
||||
std::vector<Atomic> atomics;
|
||||
|
||||
|
@ -137,7 +137,7 @@ void LoaderDFF::readGeometry(Clump *model, const RWBStream &stream) {
|
||||
throw DFFLoaderException("Geometry missing struct chunk");
|
||||
}
|
||||
|
||||
std::shared_ptr<Clump::Geometry> geom(new Clump::Geometry);
|
||||
std::shared_ptr<Geometry> geom(new Geometry);
|
||||
|
||||
char *headerPtr = geomStream.getCursor();
|
||||
|
||||
@ -156,7 +156,7 @@ void LoaderDFF::readGeometry(Clump *model, const RWBStream &stream) {
|
||||
/*unsigned int numFrames = *(std::uint32_t*)headerPtr;*/
|
||||
headerPtr += sizeof(std::uint32_t);
|
||||
|
||||
std::vector<Clump::GeometryVertex> verts;
|
||||
std::vector<GeometryVertex> verts;
|
||||
verts.resize(numVerts);
|
||||
|
||||
if (geomStream.getChunkVersion() < 0x1003FFFF) {
|
||||
@ -235,7 +235,7 @@ void LoaderDFF::readGeometry(Clump *model, const RWBStream &stream) {
|
||||
}
|
||||
|
||||
geom->dbuff.setFaceType(
|
||||
geom->facetype == Clump::Triangles ? GL_TRIANGLES : GL_TRIANGLE_STRIP);
|
||||
geom->facetype == Geometry::Triangles ? GL_TRIANGLES : GL_TRIANGLE_STRIP);
|
||||
geom->gbuff.uploadVertices(verts);
|
||||
geom->dbuff.addGeometry(&geom->gbuff);
|
||||
|
||||
@ -244,7 +244,7 @@ void LoaderDFF::readGeometry(Clump *model, const RWBStream &stream) {
|
||||
|
||||
size_t icount = std::accumulate(
|
||||
geom->subgeom.begin(), geom->subgeom.end(), 0u,
|
||||
[](size_t a, const Clump::SubGeometry &b) { return a + b.numIndices; });
|
||||
[](size_t a, const SubGeometry &b) { return a + b.numIndices; });
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(uint32_t) * icount, 0,
|
||||
GL_STATIC_DRAW);
|
||||
for (auto &sg : geom->subgeom) {
|
||||
@ -287,7 +287,7 @@ void LoaderDFF::readMaterial(Clump *model, const RWBStream &stream) {
|
||||
|
||||
char *matData = materialStream.getCursor();
|
||||
|
||||
Clump::Material material;
|
||||
Geometry::Material material;
|
||||
|
||||
// Unkown
|
||||
matData += sizeof(std::uint32_t);
|
||||
@ -366,7 +366,7 @@ void LoaderDFF::readBinMeshPLG(Clump *model, const RWBStream &stream) {
|
||||
auto data = stream.getCursor();
|
||||
|
||||
model->geometries.back()->facetype =
|
||||
static_cast<Clump::FaceType>(*(std::uint32_t *)data);
|
||||
static_cast<Geometry::FaceType>(*(std::uint32_t *)data);
|
||||
data += sizeof(std::uint32_t);
|
||||
|
||||
unsigned int numSplits = *(std::uint32_t *)data;
|
||||
@ -380,7 +380,7 @@ void LoaderDFF::readBinMeshPLG(Clump *model, const RWBStream &stream) {
|
||||
size_t start = 0;
|
||||
|
||||
for (size_t s = 0; s < numSplits; ++s) {
|
||||
Clump::SubGeometry sg;
|
||||
SubGeometry sg;
|
||||
sg.numIndices = *(std::uint32_t *)data;
|
||||
data += sizeof(std::uint32_t);
|
||||
sg.material = *(std::uint32_t *)data;
|
||||
@ -405,7 +405,7 @@ void LoaderDFF::readAtomic(Clump *model, const RWBStream &stream) {
|
||||
throw DFFLoaderException("Atomic missing struct chunk");
|
||||
}
|
||||
|
||||
Clump::Atomic atom;
|
||||
Atomic atom;
|
||||
auto data = atomicStream.getCursor();
|
||||
atom.frame = *(std::uint32_t *)data;
|
||||
data += sizeof(std::uint32_t);
|
||||
|
@ -14,8 +14,8 @@ void ModelFramesWidget::updateInfoBox(Clump* model, ModelFrame* f) {
|
||||
for (size_t gi : f->getGeometries()) {
|
||||
auto& g = model->geometries[gi];
|
||||
// for(Model::SubGeometry& sg : g->subgeom)
|
||||
for (Clump::Material& m : g->materials) {
|
||||
for (Clump::Texture& t : m.textures) {
|
||||
for (Geometry::Material& m : g->materials) {
|
||||
for (Geometry::Texture& t : m.textures) {
|
||||
geomString += QString("\n %1 (%2)")
|
||||
.arg(t.name.c_str())
|
||||
.arg(t.alphaName.c_str());
|
||||
|
@ -27,7 +27,7 @@ BOOST_AUTO_TEST_CASE(test_load_dff) {
|
||||
|
||||
BOOST_REQUIRE(m->atomics.size() > 0);
|
||||
|
||||
for (Clump::Atomic& a : m->atomics) {
|
||||
for (auto& a : m->atomics) {
|
||||
BOOST_CHECK(a.frame < m->frames.size());
|
||||
BOOST_CHECK(a.geometry < m->geometries.size());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user