From 265da569764348a2c3259d653c9da984acb92273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 11 Mar 2012 04:13:15 +0100 Subject: [PATCH] Added class Trade::MeshObjectData, specialized for mesh instance types. --- src/Trade/MeshObjectData.h | 58 ++++++++++++++++++++++++++++++++++++++ src/Trade/ObjectData.h | 11 ++++++-- 2 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 src/Trade/MeshObjectData.h diff --git a/src/Trade/MeshObjectData.h b/src/Trade/MeshObjectData.h new file mode 100644 index 000000000..e1f53b81d --- /dev/null +++ b/src/Trade/MeshObjectData.h @@ -0,0 +1,58 @@ +#ifndef Magnum_Trade_MeshObjectData_h +#define Magnum_Trade_MeshObjectData_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::MeshObjectData + */ + +#include "ObjectData.h" + +namespace Magnum { namespace Trade { + +/** +@brief %Mesh object data + +Provides access to material information for given mesh instance. +*/ +class MAGNUM_EXPORT MeshObjectData: public ObjectData { + MeshObjectData(const MeshObjectData& other) = delete; + MeshObjectData(MeshObjectData&& other) = delete; + MeshObjectData& operator=(const MeshObjectData& other) = delete; + MeshObjectData& operator=(MeshObjectData&& other) = delete; + + public: + /** + * @brief Constructor + * @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 MeshObjectData(std::vector children, const Matrix4& transformation, size_t instance, size_t material): ObjectData(children, transformation, InstanceType::Mesh, instance), _material(material) {} + + /** @brief Material ID */ + inline size_t material() { return _material; } + + private: + size_t _material; +}; + +}} + +#endif diff --git a/src/Trade/ObjectData.h b/src/Trade/ObjectData.h index 1ea3e1fbb..34df5378f 100644 --- a/src/Trade/ObjectData.h +++ b/src/Trade/ObjectData.h @@ -26,7 +26,8 @@ namespace Magnum { namespace Trade { /** @brief %Object data -Provides access to object transformation and hierarchy. +Provides access to object transformation and hierarchy. See also +MeshObjectData, which is specialized for objects with mesh instance type. */ class MAGNUM_EXPORT ObjectData { ObjectData(const ObjectData& other) = delete; @@ -51,6 +52,9 @@ class MAGNUM_EXPORT ObjectData { */ inline ObjectData(std::vector children, const Matrix4& transformation, InstanceType instanceType, size_t instanceId): _children(children), _transformation(transformation), _instanceType(instanceType), _instanceId(instanceId) {} + /** @brief Destructor */ + inline virtual ~ObjectData() {} + /** @brief Child objects */ inline std::vector& children() { return _children; } @@ -60,13 +64,16 @@ class MAGNUM_EXPORT ObjectData { /** * @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 MeshObjectData and provide more information. */ inline InstanceType instanceType() const { return _instanceType; } /** * @brief Instance ID * @return ID of given camera / light / mesh etc., specified by - * instance() + * instanceType() */ inline size_t instanceId() const { return _instanceId; }