PixelLightAPI  .
SNMesh.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: SNMesh.h                                       *
00003  *
00004  *  Copyright (C) 2002-2011 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLSCENE_SCENENODE_MESH_H__
00024 #define __PLSCENE_SCENENODE_MESH_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLScene/Scene/SceneNode.h"
00032 
00033 
00034 //[-------------------------------------------------------]
00035 //[ Namespace                                             ]
00036 //[-------------------------------------------------------]
00037 namespace PLScene {
00038 
00039 
00040 //[-------------------------------------------------------]
00041 //[ Classes                                               ]
00042 //[-------------------------------------------------------]
00043 /**
00044 *  @brief
00045 *    An mesh is a special scene node that has a 3D mesh attached to it by default
00046 *
00047 *  @note
00048 *    - If 'Skin' is not empty and not a skin file, all materials are replaced through the new one
00049 *    - By default, invisible scene nodes internally don't load in their mesh at once and delay this until
00050 *      the scene node becomes visible and/or 'GetMeshHandler()' is called (use 'LoadAtOnce'-flag do force loading at once)
00051 *    - For the debug visualization of normal vectors the config setting 'EngineDebugConfig->NormalScale' is
00052 *      used to scale the length
00053 */
00054 class SNMesh : public SceneNode {
00055 
00056 
00057     //[-------------------------------------------------------]
00058     //[ Public definitions                                    ]
00059     //[-------------------------------------------------------]
00060     public:
00061         /**
00062         *  @brief
00063         *    Scene node flags (SceneNode flags extension)
00064         */
00065         enum EFlags {
00066             NoAutomaticBoundingBox = 1<<10, /**< Do not create the bounding box of the scene node automatically using the bounding box of the used mesh */
00067             LoadAtOnce             = 1<<11, /**< Load the mesh at once even if not used at the moment */
00068             DynamicMesh            = 1<<12, /**< Hint that this is a dynamic mesh, may have an impact on the performance */
00069             GenerateStrips         = 1<<13, /**< Generate triangle strips? (if possible, don't use this flag -> loading times...) */
00070             CalculateNormals       = 1<<14, /**< Calculate normal vectors? (if not already there) (if possible, don't use this flag -> loading times...) */
00071             CalculateTSVs          = 1<<15  /**< Calculate tangent space vectors? (if not already there) (if possible, don't use this flag -> loading times...) */
00072         };
00073         pl_enum(EFlags)
00074             pl_enum_base(SceneNode::EFlags)
00075             pl_enum_value(NoAutomaticBoundingBox,   "Do not create the bounding box of the scene node automatically using the bounding box of the used mesh")
00076             pl_enum_value(LoadAtOnce,               "Load the mesh at once even if not used at the moment")
00077             pl_enum_value(DynamicMesh,              "Hint that this is a dynamic mesh, may have an impact on the performance")
00078             pl_enum_value(GenerateStrips,           "Generate triangle strips? (if possible, don't use this flag -> loading times...)")
00079             pl_enum_value(CalculateNormals,         "Calculate normal vectors? (if not already there) (if possible, don't use this flag -> loading times...)")
00080             pl_enum_value(CalculateTSVs,            "Calculate tangent space vectors? (if not already there) (if possible, don't use this flag -> loading times...)")
00081         pl_enum_end
00082 
00083         /**
00084         *  @brief
00085         *    Scene node debug flags (SceneNode debug flags extension)
00086         */
00087         enum EDebugFlags {
00088             // Mesh
00089             DebugShowWireframe      = 1<<8,     /**< Draw wireframe */
00090             DebugShowVertices       = 1<<9,     /**< Draw vertices */
00091             DebugShowTangents       = 1<<10,    /**< Draw tangents (red = x/u) */
00092             DebugShowBinormals      = 1<<11,    /**< Draw binormals (green = y/v) */
00093             DebugShowNormals        = 1<<12,    /**< Draw normals (blue = z/w) */
00094             DebugShowVertexNumbers  = 1<<13,    /**< Draw vertex numbers */
00095             // Skeleton (optional) information
00096             DebugShowJoints         = 1<<14,    /**< Draw joints */
00097             DebugShowJointNames     = 1<<15,    /**< Draw joint names */
00098             DebugShowSkeleton       = 1<<16,    /**< Draw skeleton */
00099             // Misc
00100             DebugShowAnchorPoints   = 1<<17     /**< Draw anchor points */
00101         };
00102         pl_enum(EDebugFlags)
00103             pl_enum_base(SceneNode::EDebugFlags)
00104             // Mesh
00105             pl_enum_value(DebugShowWireframe,       "Draw wireframe")
00106             pl_enum_value(DebugShowVertices,        "Draw vertices")
00107             pl_enum_value(DebugShowTangents,        "Draw tangents (red = x/u)")
00108             pl_enum_value(DebugShowBinormals,       "Draw binormals (green = y/v)")
00109             pl_enum_value(DebugShowNormals,         "Draw normals (blue = z/w)")
00110             pl_enum_value(DebugShowVertexNumbers,   "Draw vertex numbers")
00111             // Skeleton (optional) information
00112             pl_enum_value(DebugShowJoints,          "Draw joints")
00113             pl_enum_value(DebugShowJointNames,      "Draw joint names")
00114             pl_enum_value(DebugShowSkeleton,        "Draw skeleton")
00115             // Misc
00116             pl_enum_value(DebugShowAnchorPoints,    "Draw anchor points")
00117         pl_enum_end
00118 
00119 
00120     //[-------------------------------------------------------]
00121     //[ RTTI interface                                        ]
00122     //[-------------------------------------------------------]
00123     pl_class(PLS_RTTI_EXPORT, SNMesh, "PLScene", PLScene::SceneNode, "An mesh is a special scene node that has a 3D mesh attached to it by default")
00124         // Properties
00125         pl_properties
00126             pl_property("Icon", "Data/Textures/IconMesh.dds")
00127         pl_properties_end
00128         // Attributes
00129         pl_attribute(Mesh,          PLCore::String,             "", ReadWrite,  GetSet, "Mesh to use",                                                  "Type='Mesh'")
00130         pl_attribute(Skin,          PLCore::String,             "", ReadWrite,  GetSet, "Skin file overwriting the default materials of the used mesh", "Type='Skin'")
00131             // Overwritten SceneNode attributes
00132         pl_attribute(Flags,         pl_flag_type(EFlags),       0,  ReadWrite,  GetSet, "Flags",                                                        "")
00133         pl_attribute(DebugFlags,    pl_flag_type(EDebugFlags),  0,  ReadWrite,  GetSet, "Debug flags",                                                  "")
00134         // Constructors
00135         pl_constructor_0(DefaultConstructor,    "Default constructor",  "")
00136     pl_class_end
00137 
00138 
00139     //[-------------------------------------------------------]
00140     //[ Public RTTI get/set functions                         ]
00141     //[-------------------------------------------------------]
00142     public:
00143         PLS_API PLCore::String GetMesh() const;
00144         PLS_API void SetMesh(const PLCore::String &sValue);
00145         PLS_API PLCore::String GetSkin() const;
00146         PLS_API void SetSkin(const PLCore::String &sValue);
00147         PLS_API virtual void SetFlags(PLCore::uint32 nValue);   // From SceneNode
00148 
00149 
00150     //[-------------------------------------------------------]
00151     //[ Public functions                                      ]
00152     //[-------------------------------------------------------]
00153     public:
00154         /**
00155         *  @brief
00156         *    Default constructor
00157         */
00158         PLS_API SNMesh();
00159 
00160         /**
00161         *  @brief
00162         *    Destructor
00163         */
00164         PLS_API virtual ~SNMesh();
00165 
00166         /**
00167         *  @brief
00168         *    Loads a mesh
00169         *
00170         *  @param[in] sFilename
00171         *    Mesh filename to load
00172         *  @param[in] sParams
00173         *    Optional load method parameters, can be an empty string
00174         *  @param[in] sMethod
00175         *    Optional name of the load method to use, can be an empty string
00176         *
00177         *  @return
00178         *    'true' if all went fine, else 'false'
00179         *
00180         *  @note
00181         *    - If this entity is initialized the mesh defined in the entity variable
00182         *      m_sMesh is loaded automatically
00183         */
00184         PLS_API bool LoadMesh(const PLCore::String &sFilename, const PLCore::String &sParams = "", const PLCore::String &sMethod = "");
00185 
00186         /**
00187         *  @brief
00188         *    Loads a skin
00189         *
00190         *  @param[in] sFilename
00191         *    Skin filename to load, if empty, the default materials of the given mesh are used
00192         *  @param[in] sParams
00193         *    Optional load method parameters, can be an empty string
00194         *  @param[in] sMethod
00195         *    Optional name of the load method to use, can be an empty string
00196         *
00197         *  @return
00198         *    'true' if all went fine, else 'false'
00199         */
00200         PLS_API bool LoadSkin(const PLCore::String &sFilename, const PLCore::String &sParams = "", const PLCore::String &sMethod = "");
00201 
00202         /**
00203         *  @brief
00204         *    Saves the skin
00205         *
00206         *  @param[in] sFilename
00207         *    Skin filename
00208         *  @param[in] sParams
00209         *    Optional save method parameters, can be an empty string
00210         *  @param[in] sMethod
00211         *    Optional name of the save method to use, can be an empty string
00212         *
00213         *  @return
00214         *    'true' if all went fine, else 'false'
00215         */
00216         PLS_API bool SaveSkin(const PLCore::String &sFilename, const PLCore::String &sParams = "", const PLCore::String &sMethod = "");
00217 
00218         /**
00219         *  @brief
00220         *    Unloads the current mesh
00221         *
00222         *  @return
00223         *    'true' if all went fine, else 'false'
00224         */
00225         PLS_API bool UnloadMesh();
00226 
00227         /*
00228         *  @brief
00229         *    Returns the world position of a skeleton joint
00230         *
00231         *  @param[in]  sJointName
00232         *    Name of the skeleton joint to return the world position from
00233         *  @param[out] vPosition
00234         *    On success this will receive the world position of the requested skeleton joint
00235         *
00236         *  @return
00237         *    'true' if all went fine, else 'false'
00238         *    (There's no mesh? There's no skeleton? There's no joint with the given name?)
00239         */
00240         PLS_API bool GetSkeletonJointWorldPosition(const PLCore::String &sJointName, PLMath::Vector3 &vPosition);
00241 
00242 
00243     //[-------------------------------------------------------]
00244     //[ Protected virtual SNMesh functions                    ]
00245     //[-------------------------------------------------------]
00246     protected:
00247         /**
00248         *  @brief
00249         *    This function is called after the mesh handler loads a mesh
00250         *
00251         *  @note
00252         *    - Use e.g. to get animation information
00253         */
00254         PLS_API virtual void MeshInitFunction();
00255 
00256         /**
00257         *  @brief
00258         *    This function is called after the mesh handler unloads a mesh
00259         *
00260         *  @note
00261         *    - The default implementation is empty
00262         *
00263         *  @see
00264         *    - MeshInitFunction()
00265         */
00266         PLS_API virtual void MeshDeInitFunction();
00267 
00268 
00269     //[-------------------------------------------------------]
00270     //[ Private data                                          ]
00271     //[-------------------------------------------------------]
00272     private:
00273         PLCore::String       m_sMesh;           /**< Mesh to use */
00274         PLCore::String       m_sSkin;           /**< Skin file overwriting the default materials of the used mesh */
00275         PLMesh::MeshHandler *m_pMeshHandler;    /**< The mesh handler, can be a null pointer */
00276 
00277 
00278     //[-------------------------------------------------------]
00279     //[ Public virtual SceneNode functions                    ]
00280     //[-------------------------------------------------------]
00281     public:
00282         PLS_API virtual PLMesh::MeshHandler *GetMeshHandler() override;
00283         PLS_API virtual void DrawDebug(PLRenderer::Renderer &cRenderer, const VisNode *pVisNode = nullptr) override;
00284 
00285 
00286     //[-------------------------------------------------------]
00287     //[ Protected virtual SceneNode functions                 ]
00288     //[-------------------------------------------------------]
00289     protected:
00290         PLS_API virtual void DeInitFunction() override;
00291 
00292 
00293 };
00294 
00295 
00296 //[-------------------------------------------------------]
00297 //[ Namespace                                             ]
00298 //[-------------------------------------------------------]
00299 } // PLScene
00300 
00301 
00302 #endif // __PLSCENE_SCENENODE_MESH_H__


PixelLight PixelLight 0.9.10-R1
Copyright (C) 2002-2011 by The PixelLight Team
Last modified Fri Dec 23 2011 15:51:02
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported