From 90a3b76e055704030bc79ef52b788b59f9ce9009 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 17 Sep 2012 02:32:28 +0200 Subject: [PATCH] Have both 2D and 3D alternatives of mesh and object data in Trade. --- src/CMakeLists.txt | 3 +- src/Primitives/Capsule.cpp | 4 +- src/Primitives/Capsule.h | 4 +- src/Primitives/Cube.cpp | 2 +- src/Primitives/Cube.h | 4 +- src/Primitives/Icosphere.cpp | 2 +- src/Primitives/Icosphere.h | 4 +- src/Primitives/Plane.cpp | 2 +- src/Primitives/Plane.h | 4 +- src/Trade/AbstractImporter.h | 87 +++++++++++---- src/Trade/CMakeLists.txt | 9 +- src/Trade/MeshData2D.cpp | 26 +++++ src/Trade/MeshData2D.h | 105 ++++++++++++++++++ src/Trade/{MeshData.cpp => MeshData3D.cpp} | 6 +- src/Trade/{MeshData.h => MeshData3D.h} | 22 ++-- .../{MeshObjectData.h => MeshObjectData2D.h} | 22 ++-- src/Trade/MeshObjectData3D.h | 59 ++++++++++ src/Trade/ObjectData2D.h | 103 +++++++++++++++++ src/Trade/{ObjectData.h => ObjectData3D.h} | 30 ++--- src/Trade/SceneData.h | 19 ++-- 20 files changed, 431 insertions(+), 86 deletions(-) create mode 100644 src/Trade/MeshData2D.cpp create mode 100644 src/Trade/MeshData2D.h rename src/Trade/{MeshData.cpp => MeshData3D.cpp} (91%) rename src/Trade/{MeshData.h => MeshData3D.h} (82%) rename src/Trade/{MeshObjectData.h => MeshObjectData2D.h} (61%) create mode 100644 src/Trade/MeshObjectData3D.h create mode 100644 src/Trade/ObjectData2D.h rename src/Trade/{ObjectData.h => ObjectData3D.h} (68%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ade850775..651eabbdb 100644 --- a/src/CMakeLists.txt +++ b/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 diff --git a/src/Primitives/Capsule.cpp b/src/Primitives/Capsule.cpp index c65c87d36..d339f04f5 100644 --- a/src/Primitives/Capsule.cpp +++ b/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, {new vector()}, {new vector()}, textureCoords == TextureCoords::Generate ? vector*>{new vector()} : vector*>()), 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, {new vector()}, {new vector()}, textureCoords == TextureCoords::Generate ? vector*>{new vector()} : vector*>()), 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, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), segments(segments), textureCoords(textureCoords) {} +Capsule::Capsule(unsigned int segments, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), segments(segments), textureCoords(textureCoords) {} void Capsule::capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV) { positions(0)->push_back({0.0f, y, 0.0f}); diff --git a/src/Primitives/Capsule.h b/src/Primitives/Capsule.h index bb496ea00..570a1ede0 100644 --- a/src/Primitives/Capsule.h +++ b/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; diff --git a/src/Primitives/Cube.cpp b/src/Primitives/Cube.cpp index ec1917c5f..48b99c491 100644 --- a/src/Primitives/Cube.cpp +++ b/src/Primitives/Cube.cpp @@ -21,7 +21,7 @@ using namespace std; namespace Magnum { namespace Primitives { -Cube::Cube(): MeshData("", Mesh::Primitive::Triangles, new vector{ +Cube::Cube(): MeshData3D("", Mesh::Primitive::Triangles, new vector{ 0, 2, 1, 2, 3, 1, 1, 3, 5, diff --git a/src/Primitives/Cube.h b/src/Primitives/Cube.h index bacc1829c..e44368f58 100644 --- a/src/Primitives/Cube.h +++ b/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(); diff --git a/src/Primitives/Icosphere.cpp b/src/Primitives/Icosphere.cpp index 100858b8f..f2ee23068 100644 --- a/src/Primitives/Icosphere.cpp +++ b/src/Primitives/Icosphere.cpp @@ -21,7 +21,7 @@ using namespace std; namespace Magnum { namespace Primitives { -Icosphere<0>::Icosphere(): MeshData("", Mesh::Primitive::Triangles, new vector{ +Icosphere<0>::Icosphere(): MeshData3D("", Mesh::Primitive::Triangles, new vector{ 1, 2, 6, 1, 7, 2, 3, 4, 5, diff --git a/src/Primitives/Icosphere.h b/src/Primitives/Icosphere.h index 22d854576..a31c887d2 100644 --- a/src/Primitives/Icosphere.h +++ b/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 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(); diff --git a/src/Primitives/Plane.cpp b/src/Primitives/Plane.cpp index 74d9a2054..99627bab1 100644 --- a/src/Primitives/Plane.cpp +++ b/src/Primitives/Plane.cpp @@ -21,7 +21,7 @@ using namespace std; namespace Magnum { namespace Primitives { -Plane::Plane(): MeshData("", Mesh::Primitive::TriangleStrip, nullptr, {new vector{ +Plane::Plane(): MeshData3D("", Mesh::Primitive::TriangleStrip, nullptr, {new vector{ {1.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}, {-1.0f, -1.0f, 0.0f}, diff --git a/src/Primitives/Plane.h b/src/Primitives/Plane.h index d21eee942..7f1693284 100644 --- a/src/Primitives/Plane.h +++ b/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(); diff --git a/src/Trade/AbstractImporter.h b/src/Trade/AbstractImporter.h index e39fada1f..43877f14d 100644 --- a/src/Trade/AbstractImporter.h +++ b/src/Trade/AbstractImporter.h @@ -30,8 +30,10 @@ class AbstractMaterialData; class CameraData; template 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; } diff --git a/src/Trade/CMakeLists.txt b/src/Trade/CMakeLists.txt index 9ef1442be..12b1fd60d 100644 --- a/src/Trade/CMakeLists.txt +++ b/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) diff --git a/src/Trade/MeshData2D.cpp b/src/Trade/MeshData2D.cpp new file mode 100644 index 000000000..8fee8177d --- /dev/null +++ b/src/Trade/MeshData2D.cpp @@ -0,0 +1,26 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + 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; +} + +}} diff --git a/src/Trade/MeshData2D.h b/src/Trade/MeshData2D.h new file mode 100644 index 000000000..3a7663e44 --- /dev/null +++ b/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š + + 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 + +#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* indices, std::vector*> positions, std::vector*> 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* indices() { return _indices; } + inline const std::vector* 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* positions(unsigned int id) { return _positions[id]; } + inline const std::vector* 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* textureCoords2D(unsigned int id) { return _textureCoords2D[id]; } + inline const std::vector* textureCoords2D(unsigned int id) const { return _textureCoords2D[id]; } /**< @overload */ + + private: + std::string _name; + Mesh::Primitive _primitive; + std::vector* _indices; + std::vector*> _positions; + std::vector*> _textureCoords2D; +}; + +}} + +#endif diff --git a/src/Trade/MeshData.cpp b/src/Trade/MeshData3D.cpp similarity index 91% rename from src/Trade/MeshData.cpp rename to src/Trade/MeshData3D.cpp index 24f2043fe..65d59fbd9 100644 --- a/src/Trade/MeshData.cpp +++ b/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; diff --git a/src/Trade/MeshData.h b/src/Trade/MeshData3D.h similarity index 82% rename from src/Trade/MeshData.h rename to src/Trade/MeshData3D.h index d3b19bb2e..371bd4a59 100644 --- a/src/Trade/MeshData.h +++ b/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š @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Trade::MeshData + * @brief Class Magnum::Trade::MeshData3D */ #include @@ -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* indices, std::vector*> positions, std::vector*> normals, std::vector*> textureCoords2D): _name(name), _primitive(primitive), _indices(indices), _positions(positions), _normals(normals), _textureCoords2D(textureCoords2D) {} + inline MeshData3D(const std::string& name, Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> normals, std::vector*> 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; } diff --git a/src/Trade/MeshObjectData.h b/src/Trade/MeshObjectData2D.h similarity index 61% rename from src/Trade/MeshObjectData.h rename to src/Trade/MeshObjectData2D.h index e8b9568e3..c733c53a4 100644 --- a/src/Trade/MeshObjectData.h +++ b/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š @@ -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& 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& 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; } diff --git a/src/Trade/MeshObjectData3D.h b/src/Trade/MeshObjectData3D.h new file mode 100644 index 000000000..4dbfef017 --- /dev/null +++ b/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š + + 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& 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 diff --git a/src/Trade/ObjectData2D.h b/src/Trade/ObjectData2D.h new file mode 100644 index 000000000..7610087eb --- /dev/null +++ b/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š + + 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& 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& 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& 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 _children; + Matrix3 _transformation; + InstanceType _instanceType; + int _instanceId; +}; + +}} + +#endif diff --git a/src/Trade/ObjectData.h b/src/Trade/ObjectData3D.h similarity index 68% rename from src/Trade/ObjectData.h rename to src/Trade/ObjectData3D.h index 53da3f783..189560254 100644 --- a/src/Trade/ObjectData.h +++ b/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š @@ -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& 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& 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& children, const Matrix4& transformation): _name(name), _children(children), _transformation(transformation), _instanceType(InstanceType::Empty), _instanceId(-1) {} + inline ObjectData3D(const std::string& name, const std::vector& 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; } diff --git a/src/Trade/SceneData.h b/src/Trade/SceneData.h index 678243208..84a5aa348 100644 --- a/src/Trade/SceneData.h +++ b/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& children): _name(name), _children(children) {} + inline SceneData(const std::string& name, const std::vector& children2D, const std::vector& 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& children() const { return _children; } + /** @brief Two-dimensional child objects */ + inline const std::vector& children2D() const { return _children2D; } + + /** @brief Three-dimensional child objects */ + inline const std::vector& children3D() const { return _children3D; } private: std::string _name; - std::vector _children; + std::vector _children2D, + _children3D; }; }}