mirror of https://github.com/mosra/magnum.git
20 changed files with 431 additions and 86 deletions
@ -0,0 +1,26 @@ |
|||||||
|
/*
|
||||||
|
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz> |
||||||
|
|
||||||
|
This file is part of Magnum. |
||||||
|
|
||||||
|
Magnum is free software: you can redistribute it and/or modify |
||||||
|
it under the terms of the GNU Lesser General Public License version 3 |
||||||
|
only, as published by the Free Software Foundation. |
||||||
|
|
||||||
|
Magnum is distributed in the hope that it will be useful, |
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
GNU Lesser General Public License version 3 for more details. |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "MeshData2D.h" |
||||||
|
|
||||||
|
namespace Magnum { namespace Trade { |
||||||
|
|
||||||
|
MeshData2D::~MeshData2D() { |
||||||
|
delete _indices; |
||||||
|
for(auto i: _positions) delete i; |
||||||
|
for(auto i: _textureCoords2D) delete i; |
||||||
|
} |
||||||
|
|
||||||
|
}} |
||||||
@ -0,0 +1,105 @@ |
|||||||
|
#ifndef Magnum_Trade_MeshData2D_h |
||||||
|
#define Magnum_Trade_MeshData2D_h |
||||||
|
/*
|
||||||
|
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz> |
||||||
|
|
||||||
|
This file is part of Magnum. |
||||||
|
|
||||||
|
Magnum is free software: you can redistribute it and/or modify |
||||||
|
it under the terms of the GNU Lesser General Public License version 3 |
||||||
|
only, as published by the Free Software Foundation. |
||||||
|
|
||||||
|
Magnum is distributed in the hope that it will be useful, |
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
GNU Lesser General Public License version 3 for more details. |
||||||
|
*/ |
||||||
|
|
||||||
|
/** @file
|
||||||
|
* @brief Class Magnum::Trade::MeshData2D |
||||||
|
*/ |
||||||
|
|
||||||
|
#include <string> |
||||||
|
|
||||||
|
#include "Math/Point2D.h" |
||||||
|
#include "Mesh.h" |
||||||
|
|
||||||
|
namespace Magnum { namespace Trade { |
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Two-dimensional mesh data |
||||||
|
|
||||||
|
Provides access to mesh data and additional information, such as primitive |
||||||
|
type. |
||||||
|
*/ |
||||||
|
class MAGNUM_EXPORT MeshData2D { |
||||||
|
MeshData2D(const MeshData2D& other) = delete; |
||||||
|
MeshData2D(MeshData2D&& other) = delete; |
||||||
|
MeshData2D& operator=(const MeshData2D& other) = delete; |
||||||
|
MeshData2D& operator=(MeshData2D&& other) = delete; |
||||||
|
|
||||||
|
public: |
||||||
|
/**
|
||||||
|
* @brief Constructor |
||||||
|
* @param name %Mesh name |
||||||
|
* @param primitive Primitive |
||||||
|
* @param indices Array with indices or 0, if this is not |
||||||
|
* indexed mesh |
||||||
|
* @param positions Array with vertex positions. At least one |
||||||
|
* position array should be present. |
||||||
|
* @param textureCoords2D Array with two-dimensional texture |
||||||
|
* coordinate arrays or empty array |
||||||
|
*/ |
||||||
|
inline MeshData2D(const std::string& name, Mesh::Primitive primitive, std::vector<unsigned int>* indices, std::vector<std::vector<Point2D>*> positions, std::vector<std::vector<Vector2>*> textureCoords2D): _name(name), _primitive(primitive), _indices(indices), _positions(positions), _textureCoords2D(textureCoords2D) {} |
||||||
|
|
||||||
|
/** @brief Destructor */ |
||||||
|
~MeshData2D(); |
||||||
|
|
||||||
|
/** @brief %Mesh name */ |
||||||
|
inline std::string name() const { return _name; } |
||||||
|
|
||||||
|
/** @brief Primitive */ |
||||||
|
inline Mesh::Primitive primitive() const { return _primitive; } |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Indices |
||||||
|
* @return Indices or nullptr if the mesh is not indexed. |
||||||
|
*/ |
||||||
|
inline std::vector<unsigned int>* indices() { return _indices; } |
||||||
|
inline const std::vector<unsigned int>* indices() const { return _indices; } /**< @overload */ |
||||||
|
|
||||||
|
/** @brief Count of vertex position arrays */ |
||||||
|
inline unsigned int positionArrayCount() const { return _positions.size(); } |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Positions |
||||||
|
* @param id ID of position data array |
||||||
|
* @return Positions or nullptr if there is no vertex array with given |
||||||
|
* ID. |
||||||
|
*/ |
||||||
|
inline std::vector<Point2D>* positions(unsigned int id) { return _positions[id]; } |
||||||
|
inline const std::vector<Point2D>* positions(unsigned int id) const { return _positions[id]; } /**< @overload */ |
||||||
|
|
||||||
|
/** @brief Count of 2D texture coordinate arrays */ |
||||||
|
inline unsigned int textureCoords2DArrayCount() const { return _textureCoords2D.size(); } |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 2D texture coordinates |
||||||
|
* @param id ID of texture coordinates array |
||||||
|
* @return %Texture coordinates or nullptr if there is no texture |
||||||
|
* coordinates array with given ID. |
||||||
|
*/ |
||||||
|
inline std::vector<Vector2>* textureCoords2D(unsigned int id) { return _textureCoords2D[id]; } |
||||||
|
inline const std::vector<Vector2>* textureCoords2D(unsigned int id) const { return _textureCoords2D[id]; } /**< @overload */ |
||||||
|
|
||||||
|
private: |
||||||
|
std::string _name; |
||||||
|
Mesh::Primitive _primitive; |
||||||
|
std::vector<unsigned int>* _indices; |
||||||
|
std::vector<std::vector<Point2D>*> _positions; |
||||||
|
std::vector<std::vector<Vector2>*> _textureCoords2D; |
||||||
|
}; |
||||||
|
|
||||||
|
}} |
||||||
|
|
||||||
|
#endif |
||||||
@ -0,0 +1,59 @@ |
|||||||
|
#ifndef Magnum_Trade_MeshObjectData3D_h |
||||||
|
#define Magnum_Trade_MeshObjectData3D_h |
||||||
|
/*
|
||||||
|
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz> |
||||||
|
|
||||||
|
This file is part of Magnum. |
||||||
|
|
||||||
|
Magnum is free software: you can redistribute it and/or modify |
||||||
|
it under the terms of the GNU Lesser General Public License version 3 |
||||||
|
only, as published by the Free Software Foundation. |
||||||
|
|
||||||
|
Magnum is distributed in the hope that it will be useful, |
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
GNU Lesser General Public License version 3 for more details. |
||||||
|
*/ |
||||||
|
|
||||||
|
/** @file
|
||||||
|
* @brief Class Magnum::Trade::MeshObjectData3D |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "ObjectData3D.h" |
||||||
|
|
||||||
|
namespace Magnum { namespace Trade { |
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Three-dimensional mesh object data |
||||||
|
|
||||||
|
Provides access to material information for given mesh instance. |
||||||
|
*/ |
||||||
|
class MeshObjectData3D: public ObjectData3D { |
||||||
|
MeshObjectData3D(const MeshObjectData3D& other) = delete; |
||||||
|
MeshObjectData3D(MeshObjectData3D&& other) = delete; |
||||||
|
MeshObjectData3D& operator=(const MeshObjectData3D& other) = delete; |
||||||
|
MeshObjectData3D& operator=(MeshObjectData3D&& other) = delete; |
||||||
|
|
||||||
|
public: |
||||||
|
/**
|
||||||
|
* @brief Constructor |
||||||
|
* @param name %Mesh object name |
||||||
|
* @param children Child objects |
||||||
|
* @param transformation Transformation (relative to parent) |
||||||
|
* @param instance Instance ID |
||||||
|
* @param material Material ID |
||||||
|
* |
||||||
|
* Creates object with mesh instance type. |
||||||
|
*/ |
||||||
|
inline MeshObjectData3D(const std::string& name, const std::vector<unsigned int>& children, const Matrix4& transformation, unsigned int instance, unsigned int material): ObjectData3D(name, children, transformation, InstanceType::Mesh, instance), _material(material) {} |
||||||
|
|
||||||
|
/** @brief Material ID */ |
||||||
|
inline unsigned int material() const { return _material; } |
||||||
|
|
||||||
|
private: |
||||||
|
unsigned int _material; |
||||||
|
}; |
||||||
|
|
||||||
|
}} |
||||||
|
|
||||||
|
#endif |
||||||
@ -0,0 +1,103 @@ |
|||||||
|
#ifndef Magnum_Trade_ObjectData2D_h |
||||||
|
#define Magnum_Trade_ObjectData2D_h |
||||||
|
/*
|
||||||
|
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz> |
||||||
|
|
||||||
|
This file is part of Magnum. |
||||||
|
|
||||||
|
Magnum is free software: you can redistribute it and/or modify |
||||||
|
it under the terms of the GNU Lesser General Public License version 3 |
||||||
|
only, as published by the Free Software Foundation. |
||||||
|
|
||||||
|
Magnum is distributed in the hope that it will be useful, |
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
GNU Lesser General Public License version 3 for more details. |
||||||
|
*/ |
||||||
|
|
||||||
|
/** @file
|
||||||
|
* @brief Class Magnum::Trade::ObjectData2D |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "Math/Matrix4.h" |
||||||
|
#include "Magnum.h" |
||||||
|
|
||||||
|
namespace Magnum { namespace Trade { |
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Two-dimensional object data |
||||||
|
|
||||||
|
Provides access to object transformation and hierarchy. See also |
||||||
|
MeshObjectData2D, which is specialized for objects with mesh instance type. |
||||||
|
*/ |
||||||
|
class ObjectData2D { |
||||||
|
ObjectData2D(const ObjectData2D& other) = delete; |
||||||
|
ObjectData2D(ObjectData2D&& other) = delete; |
||||||
|
ObjectData2D& operator=(const ObjectData2D& other) = delete; |
||||||
|
ObjectData2D& operator=(ObjectData2D&& other) = delete; |
||||||
|
|
||||||
|
public: |
||||||
|
/** @brief Instance type */ |
||||||
|
enum class InstanceType { |
||||||
|
Camera, /**< Camera instance (see CameraData) */ |
||||||
|
Mesh, /**< Three-dimensional mesh instance (see MeshData2D) */ |
||||||
|
Empty /**< Empty */ |
||||||
|
}; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Constructor |
||||||
|
* @param name Object name |
||||||
|
* @param children Child objects |
||||||
|
* @param transformation Transformation (relative to parent) |
||||||
|
* @param instanceType Instance type |
||||||
|
* @param instanceId Instance ID |
||||||
|
*/ |
||||||
|
inline ObjectData2D(const std::string& name, const std::vector<unsigned int>& children, const Matrix3& transformation, InstanceType instanceType, unsigned int instanceId): _name(name), _children(children), _transformation(transformation), _instanceType(instanceType), _instanceId(instanceId) {} |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Constructor for empty instance |
||||||
|
* @param name Object name |
||||||
|
* @param children Child objects |
||||||
|
* @param transformation Transformation (relative to parent) |
||||||
|
*/ |
||||||
|
inline ObjectData2D(const std::string& name, const std::vector<unsigned int>& children, const Matrix3& transformation): _name(name), _children(children), _transformation(transformation), _instanceType(InstanceType::Empty), _instanceId(-1) {} |
||||||
|
|
||||||
|
/** @brief Destructor */ |
||||||
|
inline virtual ~ObjectData2D() {} |
||||||
|
|
||||||
|
/** @brief %Object name */ |
||||||
|
inline std::string name() const { return _name; } |
||||||
|
|
||||||
|
/** @brief Child objects */ |
||||||
|
inline std::vector<unsigned int>& children() { return _children; } |
||||||
|
|
||||||
|
/** @brief Transformation (relative to parent) */ |
||||||
|
inline Matrix3 transformation() const { return _transformation; } |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Instance type |
||||||
|
* @return Type of instance held by this object |
||||||
|
* |
||||||
|
* If the instance is of type InstanceType::Mesh, the instance can be |
||||||
|
* casted to MeshObjectData2D and provide more information. |
||||||
|
*/ |
||||||
|
inline InstanceType instanceType() const { return _instanceType; } |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Instance ID |
||||||
|
* @return ID of given camera / light / mesh etc., specified by |
||||||
|
* instanceType() |
||||||
|
*/ |
||||||
|
inline int instanceId() const { return _instanceId; } |
||||||
|
|
||||||
|
private: |
||||||
|
std::string _name; |
||||||
|
std::vector<unsigned int> _children; |
||||||
|
Matrix3 _transformation; |
||||||
|
InstanceType _instanceType; |
||||||
|
int _instanceId; |
||||||
|
}; |
||||||
|
|
||||||
|
}} |
||||||
|
|
||||||
|
#endif |
||||||
Loading…
Reference in new issue