mirror of
https://github.com/rwengine/openrw.git
synced 2024-09-18 16:32:32 +02:00
clang-format files in rwlib/source/data
This commit is contained in:
parent
1219075e1a
commit
4308a55ee8
@ -3,51 +3,44 @@
|
||||
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
|
||||
Model::Geometry::Geometry()
|
||||
: flags(0)
|
||||
{
|
||||
|
||||
Model::Geometry::Geometry() : flags(0) {
|
||||
}
|
||||
|
||||
Model::Geometry::~Geometry()
|
||||
{
|
||||
|
||||
Model::Geometry::~Geometry() {
|
||||
}
|
||||
|
||||
ModelFrame::ModelFrame(unsigned int index, ModelFrame* parent, glm::mat3 dR, glm::vec3 dT)
|
||||
: index(index), defaultRotation(dR), defaultTranslation(dT), parentFrame(parent)
|
||||
{
|
||||
if(parent != nullptr) {
|
||||
parent->childs.push_back(this);
|
||||
}
|
||||
reset();
|
||||
ModelFrame::ModelFrame(unsigned int index, ModelFrame* parent, glm::mat3 dR,
|
||||
glm::vec3 dT)
|
||||
: index(index)
|
||||
, defaultRotation(dR)
|
||||
, defaultTranslation(dT)
|
||||
, parentFrame(parent) {
|
||||
if (parent != nullptr) {
|
||||
parent->childs.push_back(this);
|
||||
}
|
||||
reset();
|
||||
}
|
||||
|
||||
void ModelFrame::reset()
|
||||
{
|
||||
matrix = glm::translate(glm::mat4(), defaultTranslation) * glm::mat4(defaultRotation);
|
||||
void ModelFrame::reset() {
|
||||
matrix = glm::translate(glm::mat4(), defaultTranslation) *
|
||||
glm::mat4(defaultRotation);
|
||||
}
|
||||
|
||||
void ModelFrame::addGeometry(size_t idx)
|
||||
{
|
||||
geometries.push_back(idx);
|
||||
void ModelFrame::addGeometry(size_t idx) {
|
||||
geometries.push_back(idx);
|
||||
}
|
||||
|
||||
|
||||
Model::~Model()
|
||||
{
|
||||
for(auto mf : frames) {
|
||||
delete mf;
|
||||
}
|
||||
Model::~Model() {
|
||||
for (auto mf : frames) {
|
||||
delete mf;
|
||||
}
|
||||
}
|
||||
|
||||
void Model::recalculateMetrics()
|
||||
{
|
||||
boundingRadius = std::numeric_limits<float>::min();
|
||||
for (size_t g = 0; g < geometries.size(); g++)
|
||||
{
|
||||
RW::BSGeometryBounds& bounds = geometries[g]->geometryBounds;
|
||||
boundingRadius = std::max(boundingRadius, glm::length(bounds.center) + bounds.radius);
|
||||
}
|
||||
void Model::recalculateMetrics() {
|
||||
boundingRadius = std::numeric_limits<float>::min();
|
||||
for (size_t g = 0; g < geometries.size(); g++) {
|
||||
RW::BSGeometryBounds& bounds = geometries[g]->geometryBounds;
|
||||
boundingRadius = std::max(boundingRadius,
|
||||
glm::length(bounds.center) + bounds.radius);
|
||||
}
|
||||
}
|
||||
|
@ -1,176 +1,183 @@
|
||||
#pragma once
|
||||
#ifndef _MODEL_HPP_
|
||||
#define _MODEL_HPP_
|
||||
#include <glm/glm.hpp>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <algorithm>
|
||||
#include <glm/glm.hpp>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <data/ResourceHandle.hpp>
|
||||
#include <loaders/RWBinaryStream.hpp>
|
||||
#include <gl/DrawBuffer.hpp>
|
||||
#include <gl/GeometryBuffer.hpp>
|
||||
#include <gl/TextureData.hpp>
|
||||
#include <loaders/RWBinaryStream.hpp>
|
||||
|
||||
/**
|
||||
* ModelFrame stores the hierarchy of a model's geometry as well as default
|
||||
* transformations.
|
||||
* transformations.
|
||||
*/
|
||||
class ModelFrame {
|
||||
unsigned int index;
|
||||
glm::mat3 defaultRotation;
|
||||
glm::vec3 defaultTranslation;
|
||||
glm::mat4 matrix;
|
||||
ModelFrame* parentFrame;
|
||||
std::string name;
|
||||
std::vector<size_t> geometries;
|
||||
std::vector<ModelFrame*> childs;
|
||||
unsigned int index;
|
||||
glm::mat3 defaultRotation;
|
||||
glm::vec3 defaultTranslation;
|
||||
glm::mat4 matrix;
|
||||
ModelFrame* parentFrame;
|
||||
std::string name;
|
||||
std::vector<size_t> geometries;
|
||||
std::vector<ModelFrame*> childs;
|
||||
|
||||
public:
|
||||
|
||||
ModelFrame(unsigned int index, ModelFrame* parent, glm::mat3 dR, glm::vec3 dT);
|
||||
ModelFrame(unsigned int index, ModelFrame* parent, glm::mat3 dR,
|
||||
glm::vec3 dT);
|
||||
|
||||
void reset();
|
||||
void setTransform(const glm::mat4& m);
|
||||
const glm::mat4& getTransform() const { return matrix; }
|
||||
void reset();
|
||||
void setTransform(const glm::mat4& m);
|
||||
const glm::mat4& getTransform() const {
|
||||
return matrix;
|
||||
}
|
||||
|
||||
void setName(const std::string& fname)
|
||||
{ name = fname; }
|
||||
void setName(const std::string& fname) {
|
||||
name = fname;
|
||||
}
|
||||
|
||||
void addGeometry(size_t idx);
|
||||
|
||||
unsigned int getIndex() const
|
||||
{ return index; }
|
||||
void addGeometry(size_t idx);
|
||||
|
||||
glm::vec3 getDefaultTranslation() const
|
||||
{ return defaultTranslation; }
|
||||
unsigned int getIndex() const {
|
||||
return index;
|
||||
}
|
||||
|
||||
glm::mat3 getDefaultRotation() const
|
||||
{ return defaultRotation; }
|
||||
glm::vec3 getDefaultTranslation() const {
|
||||
return defaultTranslation;
|
||||
}
|
||||
|
||||
glm::mat4 getMatrix() const
|
||||
{ return (parentFrame? parentFrame->getMatrix() : glm::mat4()) * matrix; }
|
||||
|
||||
ModelFrame* getParent() const
|
||||
{ return parentFrame; }
|
||||
glm::mat3 getDefaultRotation() const {
|
||||
return defaultRotation;
|
||||
}
|
||||
|
||||
const std::vector<ModelFrame*>& getChildren() const
|
||||
{ return childs; }
|
||||
glm::mat4 getMatrix() const {
|
||||
return (parentFrame ? parentFrame->getMatrix() : glm::mat4()) * matrix;
|
||||
}
|
||||
|
||||
const std::string& getName() const
|
||||
{ return name; }
|
||||
ModelFrame* getParent() const {
|
||||
return parentFrame;
|
||||
}
|
||||
|
||||
const std::vector<size_t>& getGeometries() const
|
||||
{ return geometries; }
|
||||
const std::vector<ModelFrame*>& getChildren() const {
|
||||
return childs;
|
||||
}
|
||||
|
||||
const std::string& getName() const {
|
||||
return name;
|
||||
}
|
||||
|
||||
const std::vector<size_t>& getGeometries() const {
|
||||
return geometries;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Model stores all the data contained within a DFF, as well as data required
|
||||
* to render them.
|
||||
*/
|
||||
class Model
|
||||
{
|
||||
class Model {
|
||||
public:
|
||||
enum FaceType {
|
||||
Triangles = 0,
|
||||
TriangleStrip = 1
|
||||
enum FaceType { Triangles = 0, TriangleStrip = 1 };
|
||||
|
||||
std::uint32_t numAtomics;
|
||||
|
||||
struct Texture {
|
||||
std::string name;
|
||||
std::string alphaName;
|
||||
TextureData::Handle texture;
|
||||
};
|
||||
|
||||
std::uint32_t numAtomics;
|
||||
enum { MTF_PrimaryColour = 1 << 0, MTF_SecondaryColour = 1 << 1 };
|
||||
|
||||
struct Texture {
|
||||
std::string name;
|
||||
std::string alphaName;
|
||||
TextureData::Handle texture;
|
||||
};
|
||||
|
||||
enum {
|
||||
MTF_PrimaryColour = 1 << 0,
|
||||
MTF_SecondaryColour = 1 << 1
|
||||
};
|
||||
|
||||
struct Material {
|
||||
std::vector<Texture> textures;
|
||||
glm::u8vec4 colour;
|
||||
|
||||
uint8_t flags;
|
||||
|
||||
float diffuseIntensity;
|
||||
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;
|
||||
|
||||
GLuint EBO;
|
||||
|
||||
RW::BSGeometryBounds geometryBounds;
|
||||
|
||||
uint32_t clumpNum;
|
||||
struct Material {
|
||||
std::vector<Texture> textures;
|
||||
glm::u8vec4 colour;
|
||||
|
||||
uint8_t flags;
|
||||
|
||||
float diffuseIntensity;
|
||||
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;
|
||||
|
||||
GLuint EBO;
|
||||
|
||||
RW::BSGeometryBounds geometryBounds;
|
||||
|
||||
uint32_t clumpNum;
|
||||
|
||||
FaceType facetype;
|
||||
|
||||
uint32_t flags;
|
||||
uint32_t flags;
|
||||
|
||||
std::vector<Material> materials;
|
||||
std::vector<SubGeometry> subgeom;
|
||||
|
||||
Geometry();
|
||||
~Geometry();
|
||||
};
|
||||
|
||||
struct Atomic {
|
||||
uint32_t frame;
|
||||
uint32_t geometry;
|
||||
};
|
||||
|
||||
std::vector<ModelFrame*> frames;
|
||||
/** @TODO clean up this mess a little */
|
||||
std::vector<std::shared_ptr<Geometry>> geometries;
|
||||
std::vector<Atomic> atomics;
|
||||
std::vector<Material> materials;
|
||||
std::vector<SubGeometry> subgeom;
|
||||
|
||||
int32_t rootFrameIdx;
|
||||
Geometry();
|
||||
~Geometry();
|
||||
};
|
||||
|
||||
ModelFrame* findFrame(const std::string& name) const {
|
||||
auto fit = std::find_if(
|
||||
frames.begin(), frames.end(),
|
||||
[&](ModelFrame* f) { return f->getName() == name; });
|
||||
return fit != frames.end() ? *fit : nullptr;
|
||||
}
|
||||
struct Atomic {
|
||||
uint32_t frame;
|
||||
uint32_t geometry;
|
||||
};
|
||||
|
||||
~Model();
|
||||
std::vector<ModelFrame*> frames;
|
||||
/** @TODO clean up this mess a little */
|
||||
std::vector<std::shared_ptr<Geometry>> geometries;
|
||||
std::vector<Atomic> atomics;
|
||||
|
||||
void recalculateMetrics();
|
||||
int32_t rootFrameIdx;
|
||||
|
||||
float getBoundingRadius() const { return boundingRadius; }
|
||||
ModelFrame* findFrame(const std::string& name) const {
|
||||
auto fit =
|
||||
std::find_if(frames.begin(), frames.end(),
|
||||
[&](ModelFrame* f) { return f->getName() == name; });
|
||||
return fit != frames.end() ? *fit : nullptr;
|
||||
}
|
||||
|
||||
~Model();
|
||||
|
||||
void recalculateMetrics();
|
||||
|
||||
float getBoundingRadius() const {
|
||||
return boundingRadius;
|
||||
}
|
||||
|
||||
private:
|
||||
float boundingRadius;
|
||||
float boundingRadius;
|
||||
};
|
||||
|
||||
typedef ResourceHandle<Model>::Ref ModelRef;
|
||||
|
@ -3,32 +3,30 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace RW
|
||||
{
|
||||
/**
|
||||
* Possible states for ResourceHandle
|
||||
*/
|
||||
enum ResourceState
|
||||
{
|
||||
/// Resource has been declared but not loaded
|
||||
Loading = 0,
|
||||
/// Resource has been loaded and is available
|
||||
Loaded = 1,
|
||||
/// Loading the resource failed
|
||||
Failed = 2
|
||||
};
|
||||
namespace RW {
|
||||
/**
|
||||
* Possible states for ResourceHandle
|
||||
*/
|
||||
enum ResourceState {
|
||||
/// Resource has been declared but not loaded
|
||||
Loading = 0,
|
||||
/// Resource has been loaded and is available
|
||||
Loaded = 1,
|
||||
/// Loading the resource failed
|
||||
Failed = 2
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
template<class T> class ResourceHandle
|
||||
{
|
||||
template <class T>
|
||||
class ResourceHandle {
|
||||
public:
|
||||
T* resource;
|
||||
RW::ResourceState state;
|
||||
std::string name;
|
||||
|
||||
typedef std::shared_ptr<ResourceHandle<T>> Ref;
|
||||
|
||||
ResourceHandle(const std::string& name)
|
||||
: resource(nullptr), state(RW::Loading), name(name) { }
|
||||
T* resource;
|
||||
RW::ResourceState state;
|
||||
std::string name;
|
||||
|
||||
typedef std::shared_ptr<ResourceHandle<T>> Ref;
|
||||
|
||||
ResourceHandle(const std::string& name)
|
||||
: resource(nullptr), state(RW::Loading), name(name) {
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user