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