Browse Source

Have both 2D and 3D alternatives of mesh and object data in Trade.

vectorfields
Vladimír Vondruš 14 years ago
parent
commit
90a3b76e05
  1. 3
      src/CMakeLists.txt
  2. 4
      src/Primitives/Capsule.cpp
  3. 4
      src/Primitives/Capsule.h
  4. 2
      src/Primitives/Cube.cpp
  5. 4
      src/Primitives/Cube.h
  6. 2
      src/Primitives/Icosphere.cpp
  7. 4
      src/Primitives/Icosphere.h
  8. 2
      src/Primitives/Plane.cpp
  9. 4
      src/Primitives/Plane.h
  10. 87
      src/Trade/AbstractImporter.h
  11. 9
      src/Trade/CMakeLists.txt
  12. 26
      src/Trade/MeshData2D.cpp
  13. 105
      src/Trade/MeshData2D.h
  14. 6
      src/Trade/MeshData3D.cpp
  15. 22
      src/Trade/MeshData3D.h
  16. 22
      src/Trade/MeshObjectData2D.h
  17. 59
      src/Trade/MeshObjectData3D.h
  18. 103
      src/Trade/ObjectData2D.h
  19. 30
      src/Trade/ObjectData3D.h
  20. 19
      src/Trade/SceneData.h

3
src/CMakeLists.txt

@ -35,7 +35,8 @@ set(Magnum_SRCS
TypeTraits.cpp
Trade/AbstractImporter.cpp
Trade/MeshData.cpp)
Trade/MeshData2D.cpp
Trade/MeshData3D.cpp)
set(Magnum_HEADERS
AbstractImage.h
AbstractShaderProgram.h

4
src/Primitives/Capsule.cpp

@ -22,7 +22,7 @@ using namespace std;
namespace Magnum { namespace Primitives {
Capsule::Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsigned int segments, GLfloat length, TextureCoords textureCoords): MeshData("", Mesh::Primitive::Triangles, new vector<unsigned int>, {new vector<Point3D>()}, {new vector<Vector3>()}, textureCoords == TextureCoords::Generate ? vector<vector<Vector2>*>{new vector<Vector2>()} : vector<vector<Vector2>*>()), segments(segments), textureCoords(textureCoords) {
Capsule::Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsigned int segments, GLfloat length, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new vector<unsigned int>, {new vector<Point3D>()}, {new vector<Vector3>()}, textureCoords == TextureCoords::Generate ? vector<vector<Vector2>*>{new vector<Vector2>()} : vector<vector<Vector2>*>()), segments(segments), textureCoords(textureCoords) {
CORRADE_ASSERT(hemisphereRings >= 1 && cylinderRings >= 1 && segments >= 3, "Capsule must have at least one hemisphere ring, one cylinder ring and three segments", );
GLfloat height = 2.0f+length;
@ -50,7 +50,7 @@ Capsule::Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsig
topFaceRing();
}
Capsule::Capsule(unsigned int segments, TextureCoords textureCoords): MeshData("", Mesh::Primitive::Triangles, new std::vector<unsigned int>, {new std::vector<Point3D>()}, {new std::vector<Vector3>()}, textureCoords == TextureCoords::Generate ? std::vector<std::vector<Vector2>*>{new std::vector<Vector2>()} : std::vector<std::vector<Vector2>*>()), segments(segments), textureCoords(textureCoords) {}
Capsule::Capsule(unsigned int segments, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new std::vector<unsigned int>, {new std::vector<Point3D>()}, {new std::vector<Vector3>()}, textureCoords == TextureCoords::Generate ? std::vector<std::vector<Vector2>*>{new std::vector<Vector2>()} : std::vector<std::vector<Vector2>*>()), segments(segments), textureCoords(textureCoords) {}
void Capsule::capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV) {
positions(0)->push_back({0.0f, y, 0.0f});

4
src/Primitives/Capsule.h

@ -19,7 +19,7 @@
* @brief Class Magnum::Primitives::Capsule
*/
#include "Trade/MeshData.h"
#include "Trade/MeshData3D.h"
namespace Magnum { namespace Primitives {
@ -28,7 +28,7 @@ namespace Magnum { namespace Primitives {
Cylinder along Y axis with hemispheres instead of caps.
*/
class Capsule: public Trade::MeshData {
class Capsule: public Trade::MeshData3D {
friend class UVSphere;
friend class Cylinder;

2
src/Primitives/Cube.cpp

@ -21,7 +21,7 @@ using namespace std;
namespace Magnum { namespace Primitives {
Cube::Cube(): MeshData("", Mesh::Primitive::Triangles, new vector<unsigned int>{
Cube::Cube(): MeshData3D("", Mesh::Primitive::Triangles, new vector<unsigned int>{
0, 2, 1,
2, 3, 1,
1, 3, 5,

4
src/Primitives/Cube.h

@ -19,12 +19,12 @@
* @brief Class Magnum::Primitives::Cube
*/
#include "Trade/MeshData.h"
#include "Trade/MeshData3D.h"
namespace Magnum { namespace Primitives {
/** @brief %Cube primitive */
class Cube: public Trade::MeshData {
class Cube: public Trade::MeshData3D {
public:
/** @brief Constructor */
Cube();

2
src/Primitives/Icosphere.cpp

@ -21,7 +21,7 @@ using namespace std;
namespace Magnum { namespace Primitives {
Icosphere<0>::Icosphere(): MeshData("", Mesh::Primitive::Triangles, new vector<unsigned int>{
Icosphere<0>::Icosphere(): MeshData3D("", Mesh::Primitive::Triangles, new vector<unsigned int>{
1, 2, 6,
1, 7, 2,
3, 4, 5,

4
src/Primitives/Icosphere.h

@ -22,7 +22,7 @@
#include "Math/Vector3.h"
#include "MeshTools/Subdivide.h"
#include "MeshTools/Clean.h"
#include "Trade/MeshData.h"
#include "Trade/MeshData3D.h"
namespace Magnum { namespace Primitives {
@ -34,7 +34,7 @@ template<size_t subdivisions> class Icosphere;
@todo Use own computed (and more precise) icosahedron data, not these stolen
from Blender.
*/
template<> class Icosphere<0>: public Trade::MeshData {
template<> class Icosphere<0>: public Trade::MeshData3D {
public:
/** @brief Constructor */
Icosphere();

2
src/Primitives/Plane.cpp

@ -21,7 +21,7 @@ using namespace std;
namespace Magnum { namespace Primitives {
Plane::Plane(): MeshData("", Mesh::Primitive::TriangleStrip, nullptr, {new vector<Point3D>{
Plane::Plane(): MeshData3D("", Mesh::Primitive::TriangleStrip, nullptr, {new vector<Point3D>{
{1.0f, -1.0f, 0.0f},
{1.0f, 1.0f, 0.0f},
{-1.0f, -1.0f, 0.0f},

4
src/Primitives/Plane.h

@ -19,7 +19,7 @@
* @brief Class Magnum::Primitives::Plane
*/
#include "Trade/MeshData.h"
#include "Trade/MeshData3D.h"
namespace Magnum { namespace Primitives {
@ -28,7 +28,7 @@ namespace Magnum { namespace Primitives {
2x2 plane with normals in positive Z direction.
*/
class Plane: public Trade::MeshData {
class Plane: public Trade::MeshData3D {
public:
/** @brief Constructor */
Plane();

87
src/Trade/AbstractImporter.h

@ -30,8 +30,10 @@ class AbstractMaterialData;
class CameraData;
template<size_t> class ImageData;
class LightData;
class MeshData;
class ObjectData;
class MeshData2D;
class MeshData3D;
class ObjectData2D;
class ObjectData3D;
class SceneData;
class TextureData;
@ -176,44 +178,83 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin {
*/
virtual CameraData* camera(unsigned int id);
/** @brief %Object count */
virtual inline unsigned int objectCount() const { return 0; }
/** @brief Two-dimensional object count */
virtual inline unsigned int object2DCount() const { return 0; }
/**
* @brief %Object ID for given name
* @brief Two-dimensional object ID for given name
*
* If no scene for given name exists, returns -1.
* @see ObjectData::name()
* @see ObjectData2D::name()
*/
virtual int objectForName(const std::string& name);
virtual int object2DForName(const std::string& name);
/**
* @brief %Object
* @param id %Object ID, from range [0, objectCount()).
* @brief Two-dimensional object
* @param id %Object ID, from range [0, object2DCount()).
*
* Returns pointer to given object or nullptr, if no such object
* exists.
*/
virtual ObjectData* object(unsigned int id);
virtual ObjectData2D* object2D(unsigned int id);
/** @brief %Mesh count */
virtual inline unsigned int meshCount() const { return 0; }
/** @brief Three-dimensional object count */
virtual inline unsigned int object3DCount() const { return 0; }
/**
* @brief %Mesh ID for given name
* @brief Three-dimensional object ID for given name
*
* If no scene for given name exists, returns -1.
* @see ObjectData3D::name()
*/
virtual int object3DForName(const std::string& name);
/**
* @brief Three-dimensional object
* @param id %Object ID, from range [0, object3DCount()).
*
* Returns pointer to given object or nullptr, if no such object
* exists.
*/
virtual ObjectData3D* object3D(unsigned int id);
/** @brief Two-dimensional mesh count */
virtual inline unsigned int mesh2DCount() const { return 0; }
/**
* @brief Two-dimensional mesh ID for given name
*
* If no mesh for given name exists, returns -1.
* @see MeshData2D::name()
*/
virtual int mesh2DForName(const std::string& name);
/**
* @brief Two-dimensional mesh
* @param id %Mesh ID, from range [0, meshCount()).
*
* Returns pointer to given mesh or nullptr, if no such mesh exists.
*/
virtual MeshData2D* mesh2D(unsigned int id);
/** @brief Three-dimensional mesh count */
virtual inline unsigned int mesh3DCount() const { return 0; }
/**
* @brief Three-dimensional mesh ID for given name
*
* If no mesh for given name exists, returns -1.
* @see MeshData::name()
* @see MeshData3D::name()
*/
virtual int meshForName(const std::string& name);
virtual int mesh3DForName(const std::string& name);
/**
* @brief %Mesh
* @brief Three-dimensional mesh
* @param id %Mesh ID, from range [0, meshCount()).
*
* Returns pointer to given mesh or nullptr, if no such mesh exists.
*/
virtual MeshData* mesh(unsigned int id);
virtual MeshData3D* mesh3D(unsigned int id);
/** @brief Material count */
virtual inline unsigned int materialCount() const { return 0; }
@ -324,10 +365,14 @@ inline int AbstractImporter::lightForName(const std::string&) { return -1; }
inline LightData* AbstractImporter::light(unsigned int) { return nullptr; }
inline int AbstractImporter::cameraForName(const std::string&) { return -1; }
inline CameraData* AbstractImporter::camera(unsigned int) { return nullptr; }
inline int AbstractImporter::objectForName(const std::string&) { return -1; }
inline ObjectData* AbstractImporter::object(unsigned int) { return nullptr; }
inline int AbstractImporter::meshForName(const std::string&) { return -1; }
inline MeshData* AbstractImporter::mesh(unsigned int) { return nullptr; }
inline int AbstractImporter::object2DForName(const std::string&) { return -1; }
inline ObjectData2D* AbstractImporter::object2D(unsigned int) { return nullptr; }
inline int AbstractImporter::object3DForName(const std::string&) { return -1; }
inline ObjectData3D* AbstractImporter::object3D(unsigned int) { return nullptr; }
inline int AbstractImporter::mesh2DForName(const std::string&) { return -1; }
inline MeshData2D* AbstractImporter::mesh2D(unsigned int) { return nullptr; }
inline int AbstractImporter::mesh3DForName(const std::string&) { return -1; }
inline MeshData3D* AbstractImporter::mesh3D(unsigned int) { return nullptr; }
inline int AbstractImporter::materialForName(const std::string&) { return -1; }
inline AbstractMaterialData* AbstractImporter::material(unsigned int) { return nullptr; }
inline int AbstractImporter::textureForName(const std::string&) { return -1; }

9
src/Trade/CMakeLists.txt

@ -4,9 +4,12 @@ set(MagnumTrade_HEADERS
CameraData.h
ImageData.h
LightData.h
MeshData.h
MeshObjectData.h
ObjectData.h
MeshData2D.h
MeshData3D.h
MeshObjectData2D.h
MeshObjectData3D.h
ObjectData2D.h
ObjectData3D.h
PhongMaterialData.h
SceneData.h
TextureData.h)

26
src/Trade/MeshData2D.cpp

@ -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;
}
}}

105
src/Trade/MeshData2D.h

@ -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

6
src/Trade/MeshData.cpp → src/Trade/MeshData3D.cpp

@ -13,13 +13,11 @@
GNU Lesser General Public License version 3 for more details.
*/
#include "MeshData.h"
#include "Math/Vector4.h"
#include "MeshData3D.h"
namespace Magnum { namespace Trade {
MeshData::~MeshData() {
MeshData3D::~MeshData3D() {
delete _indices;
for(auto i: _positions) delete i;
for(auto i: _normals) delete i;

22
src/Trade/MeshData.h → src/Trade/MeshData3D.h

@ -1,5 +1,5 @@
#ifndef Magnum_Trade_MeshData_h
#define Magnum_Trade_MeshData_h
#ifndef Magnum_Trade_MeshData3D_h
#define Magnum_Trade_MeshData3D_h
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
@ -16,7 +16,7 @@
*/
/** @file
* @brief Class Magnum::Trade::MeshData
* @brief Class Magnum::Trade::MeshData3D
*/
#include <string>
@ -27,16 +27,16 @@
namespace Magnum { namespace Trade {
/**
@brief %Mesh data
@brief Three-dimensional mesh data
Provides access to mesh data and additional information, such as primitive
type.
*/
class MAGNUM_EXPORT MeshData {
MeshData(const MeshData& other) = delete;
MeshData(MeshData&& other) = delete;
MeshData& operator=(const MeshData& other) = delete;
MeshData& operator=(MeshData&& other) = delete;
class MAGNUM_EXPORT MeshData3D {
MeshData3D(const MeshData3D& other) = delete;
MeshData3D(MeshData3D&& other) = delete;
MeshData3D& operator=(const MeshData3D& other) = delete;
MeshData3D& operator=(MeshData3D&& other) = delete;
public:
/**
@ -51,10 +51,10 @@ class MAGNUM_EXPORT MeshData {
* @param textureCoords2D Array with two-dimensional texture
* coordinate arrays or empty array
*/
inline MeshData(const std::string& name, Mesh::Primitive primitive, std::vector<unsigned int>* indices, std::vector<std::vector<Point3D>*> positions, std::vector<std::vector<Vector3>*> normals, std::vector<std::vector<Vector2>*> textureCoords2D): _name(name), _primitive(primitive), _indices(indices), _positions(positions), _normals(normals), _textureCoords2D(textureCoords2D) {}
inline MeshData3D(const std::string& name, Mesh::Primitive primitive, std::vector<unsigned int>* indices, std::vector<std::vector<Point3D>*> positions, std::vector<std::vector<Vector3>*> normals, std::vector<std::vector<Vector2>*> textureCoords2D): _name(name), _primitive(primitive), _indices(indices), _positions(positions), _normals(normals), _textureCoords2D(textureCoords2D) {}
/** @brief Destructor */
~MeshData();
~MeshData3D();
/** @brief %Mesh name */
inline std::string name() const { return _name; }

22
src/Trade/MeshObjectData.h → src/Trade/MeshObjectData2D.h

@ -1,5 +1,5 @@
#ifndef Magnum_Trade_MeshObjectData_h
#define Magnum_Trade_MeshObjectData_h
#ifndef Magnum_Trade_MeshObjectData2D_h
#define Magnum_Trade_MeshObjectData2D_h
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
@ -16,23 +16,23 @@
*/
/** @file
* @brief Class Magnum::Trade::MeshObjectData
* @brief Class Magnum::Trade::MeshObjectData2D
*/
#include "ObjectData.h"
#include "ObjectData2D.h"
namespace Magnum { namespace Trade {
/**
@brief %Mesh object data
@brief Two-dimensional mesh object data
Provides access to material information for given mesh instance.
*/
class MeshObjectData: public ObjectData {
MeshObjectData(const MeshObjectData& other) = delete;
MeshObjectData(MeshObjectData&& other) = delete;
MeshObjectData& operator=(const MeshObjectData& other) = delete;
MeshObjectData& operator=(MeshObjectData&& other) = delete;
class MeshObjectData2D: public ObjectData2D {
MeshObjectData2D(const MeshObjectData2D& other) = delete;
MeshObjectData2D(MeshObjectData2D&& other) = delete;
MeshObjectData2D& operator=(const MeshObjectData2D& other) = delete;
MeshObjectData2D& operator=(MeshObjectData2D&& other) = delete;
public:
/**
@ -45,7 +45,7 @@ class MeshObjectData: public ObjectData {
*
* Creates object with mesh instance type.
*/
inline MeshObjectData(const std::string& name, const std::vector<unsigned int>& children, const Matrix4& transformation, unsigned int instance, unsigned int material): ObjectData(name, children, transformation, InstanceType::Mesh, instance), _material(material) {}
inline MeshObjectData2D(const std::string& name, const std::vector<unsigned int>& children, const Matrix4& transformation, unsigned int instance, unsigned int material): ObjectData2D(name, children, transformation, InstanceType::Mesh, instance), _material(material) {}
/** @brief Material ID */
inline unsigned int material() const { return _material; }

59
src/Trade/MeshObjectData3D.h

@ -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

103
src/Trade/ObjectData2D.h

@ -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

30
src/Trade/ObjectData.h → src/Trade/ObjectData3D.h

@ -1,5 +1,5 @@
#ifndef Magnum_Trade_ObjectData_h
#define Magnum_Trade_ObjectData_h
#ifndef Magnum_Trade_ObjectData3D_h
#define Magnum_Trade_ObjectData3D_h
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
@ -16,7 +16,7 @@
*/
/** @file
* @brief Class Magnum::Trade::ObjectData
* @brief Class Magnum::Trade::ObjectData3D
*/
#include "Math/Matrix4.h"
@ -25,23 +25,23 @@
namespace Magnum { namespace Trade {
/**
@brief %Object data
@brief Three-dimensional object data
Provides access to object transformation and hierarchy. See also
MeshObjectData, which is specialized for objects with mesh instance type.
MeshObjectData3D, which is specialized for objects with mesh instance type.
*/
class ObjectData {
ObjectData(const ObjectData& other) = delete;
ObjectData(ObjectData&& other) = delete;
ObjectData& operator=(const ObjectData& other) = delete;
ObjectData& operator=(ObjectData&& other) = delete;
class ObjectData3D {
ObjectData3D(const ObjectData3D& other) = delete;
ObjectData3D(ObjectData3D&& other) = delete;
ObjectData3D& operator=(const ObjectData3D& other) = delete;
ObjectData3D& operator=(ObjectData3D&& other) = delete;
public:
/** @brief Instance type */
enum class InstanceType {
Camera, /**< Camera instance (see CameraData) */
Light, /**< Light instance (see LightData) */
Mesh, /**< Mesh instance (see MeshData) */
Mesh, /**< Three-dimensional mesh instance (see MeshData3D) */
Empty /**< Empty */
};
@ -53,7 +53,7 @@ class ObjectData {
* @param instanceType Instance type
* @param instanceId Instance ID
*/
inline ObjectData(const std::string& name, const std::vector<unsigned int>& children, const Matrix4& transformation, InstanceType instanceType, unsigned int instanceId): _name(name), _children(children), _transformation(transformation), _instanceType(instanceType), _instanceId(instanceId) {}
inline ObjectData3D(const std::string& name, const std::vector<unsigned int>& children, const Matrix4& transformation, InstanceType instanceType, unsigned int instanceId): _name(name), _children(children), _transformation(transformation), _instanceType(instanceType), _instanceId(instanceId) {}
/**
* @brief Constructor for empty instance
@ -61,10 +61,10 @@ class ObjectData {
* @param children Child objects
* @param transformation Transformation (relative to parent)
*/
inline ObjectData(const std::string& name, const std::vector<unsigned int>& children, const Matrix4& transformation): _name(name), _children(children), _transformation(transformation), _instanceType(InstanceType::Empty), _instanceId(-1) {}
inline ObjectData3D(const std::string& name, const std::vector<unsigned int>& children, const Matrix4& transformation): _name(name), _children(children), _transformation(transformation), _instanceType(InstanceType::Empty), _instanceId(-1) {}
/** @brief Destructor */
inline virtual ~ObjectData() {}
inline virtual ~ObjectData3D() {}
/** @brief %Object name */
inline std::string name() const { return _name; }
@ -80,7 +80,7 @@ class ObjectData {
* @return Type of instance held by this object
*
* If the instance is of type InstanceType::Mesh, the instance can be
* casted to MeshObjectData and provide more information.
* casted to MeshObjectData3D and provide more information.
*/
inline InstanceType instanceType() const { return _instanceType; }

19
src/Trade/SceneData.h

@ -36,20 +36,25 @@ class MAGNUM_EXPORT SceneData {
public:
/**
* @brief Constructor
* @param name %Scene name
* @param children Child objects
* @param name Scene name
* @param children2D Two-dimensional child objects
* @param children3D Three-dimensional child objects
*/
inline SceneData(const std::string& name, const std::vector<unsigned int>& children): _name(name), _children(children) {}
inline SceneData(const std::string& name, const std::vector<unsigned int>& children2D, const std::vector<unsigned int>& children3D): _name(name), _children2D(children2D), _children3D(children3D) {}
/** @brief %Scene name */
/** @brief Scene name */
inline std::string name() const { return _name; }
/** @brief Child objects */
inline const std::vector<unsigned int>& children() const { return _children; }
/** @brief Two-dimensional child objects */
inline const std::vector<unsigned int>& children2D() const { return _children2D; }
/** @brief Three-dimensional child objects */
inline const std::vector<unsigned int>& children3D() const { return _children3D; }
private:
std::string _name;
std::vector<unsigned int> _children;
std::vector<unsigned int> _children2D,
_children3D;
};
}}

Loading…
Cancel
Save