PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: MeshMorphTarget.h * 00003 * 00004 * Copyright (C) 2002-2012 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 __PLMESH_MESH_MORPHTARGET_H__ 00024 #define __PLMESH_MESH_MORPHTARGET_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include <PLCore/Container/Array.h> 00032 #include <PLMath/Plane.h> 00033 #include "PLMesh/PLMesh.h" 00034 00035 00036 //[-------------------------------------------------------] 00037 //[ Forward declarations ] 00038 //[-------------------------------------------------------] 00039 namespace PLRenderer { 00040 class VertexBuffer; 00041 } 00042 namespace PLMesh { 00043 class Mesh; 00044 } 00045 00046 00047 //[-------------------------------------------------------] 00048 //[ Namespace ] 00049 //[-------------------------------------------------------] 00050 namespace PLMesh { 00051 00052 00053 //[-------------------------------------------------------] 00054 //[ Classes ] 00055 //[-------------------------------------------------------] 00056 /** 00057 * @brief 00058 * A morph target alters the vertex data for each frame 00059 */ 00060 class MeshMorphTarget { 00061 00062 00063 //[-------------------------------------------------------] 00064 //[ Friends ] 00065 //[-------------------------------------------------------] 00066 friend class Mesh; 00067 00068 00069 //[-------------------------------------------------------] 00070 //[ Public functions ] 00071 //[-------------------------------------------------------] 00072 public: 00073 //[-------------------------------------------------------] 00074 //[ Main functions ] 00075 //[-------------------------------------------------------] 00076 /** 00077 * @brief 00078 * Constructor 00079 * 00080 * @param[in] pMesh 00081 * Pointer to the owner mesh, can be a null pointer 00082 */ 00083 PLMESH_API MeshMorphTarget(Mesh *pMesh = nullptr); 00084 00085 /** 00086 * @brief 00087 * Destructor 00088 */ 00089 PLMESH_API ~MeshMorphTarget(); 00090 00091 /** 00092 * @brief 00093 * Returns the mesh the morph target belongs to 00094 * 00095 * @return 00096 * Pointer to the owner mesh, can be a null pointer 00097 */ 00098 PLMESH_API Mesh *GetMesh() const; 00099 00100 /** 00101 * @brief 00102 * Sets the mesh the morph target belongs to 00103 * 00104 * @param[in] pMesh 00105 * Pointer to the owner mesh, can be a null pointer 00106 */ 00107 PLMESH_API void SetMesh(Mesh *pMesh = nullptr); 00108 00109 /** 00110 * @brief 00111 * Returns the name of this morph target 00112 * 00113 * @return 00114 * Name of this morph target 00115 */ 00116 PLMESH_API PLCore::String GetName() const; 00117 00118 /** 00119 * @brief 00120 * Sets the name of this morph target 00121 * 00122 * @param[in] sName 00123 * Name of this morph target 00124 * 00125 * @note 00126 * - The name muse be unique, if the owner mesh has already a morph target 00127 * with this name, the given name is changed automatically 00128 */ 00129 PLMESH_API void SetName(const PLCore::String &sName); 00130 00131 /** 00132 * @brief 00133 * Returns whether this morph target is relative to the basis morph target or not 00134 * 00135 * @return 00136 * 'true' if it's relative, else 'false' 00137 */ 00138 PLMESH_API bool IsRelative() const; 00139 00140 /** 00141 * @brief 00142 * Sets whether this morph target is relative to the basis morph target or not 00143 * 00144 * @param[in] bRelative 00145 * 'true' if it's relative, else 'false' 00146 */ 00147 PLMESH_API void SetRelative(bool bRelative = false); 00148 00149 /** 00150 * @brief 00151 * Returns the vertex ID's 00152 * 00153 * @return 00154 * Vertex ID's 00155 * 00156 * @note 00157 * - Only used if the morph target is relative to the base morph target 00158 * - If there are vertex ID's they will be used for the vertex buffer to skip 00159 * null deltas 00160 */ 00161 PLMESH_API PLCore::Array<PLCore::uint32> &GetVertexIDs(); 00162 00163 /** 00164 * @brief 00165 * Returns the vertex buffer 00166 * 00167 * @return 00168 * Vertex buffer, can be a null pointer 00169 */ 00170 PLMESH_API PLRenderer::VertexBuffer *GetVertexBuffer() const; 00171 00172 /** 00173 * @brief 00174 * Copy operator 00175 * 00176 * @param[in] cSource 00177 * Source to copy from 00178 * 00179 * @return 00180 * This class instance 00181 */ 00182 PLMESH_API MeshMorphTarget &operator =(const MeshMorphTarget &cSource); 00183 00184 //[-------------------------------------------------------] 00185 //[ Tool functions ] 00186 //[-------------------------------------------------------] 00187 /** 00188 * @brief 00189 * Builds the current triangle planes 00190 * 00191 * @note 00192 * - The triangle planes must be updated after manipulating 00193 * geometries or vertices! 00194 * - If the triangle list is available (MeshLODLevel::GetTriangleList()) 00195 * it will be used for faster triangle plane calculation, else the slower 00196 * GetTriangle() is used instead. 00197 * If there are vertex ID's, we CAN'T build triangle planes because only a few vertices are 00198 * influenced by this morph target! 00199 */ 00200 PLMESH_API void BuildTrianglePlaneList(); 00201 00202 /** 00203 * @brief 00204 * Gets the triangle plane list 00205 * 00206 * @return 00207 * Triangle plane list 00208 * 00209 * @see 00210 * - BuildTrianglePlaneList() 00211 */ 00212 PLMESH_API PLCore::Array<PLMath::Plane> &GetTrianglePlaneList(); 00213 00214 /** 00215 * @brief 00216 * Calculate the vertex normals of the morph target 00217 * 00218 * @return 00219 * 'true' if all went fine, else 'false' 00220 * 00221 * @note 00222 * - This function will add normals to the vertex buffer if there are no one 00223 * allocated yet 00224 * - If there are vertex ID's, we CAN'T calculate normals because only a few vertices are 00225 * influenced by this morph target! 00226 */ 00227 PLMESH_API bool CalculateNormals(); 00228 00229 /** 00230 * @brief 00231 * Calculates all tangent space vectors of the morph target 00232 * 00233 * @param[in] bTangent 00234 * Create tangent vectors? 00235 * @param[in] bBinormal 00236 * Create binormal vectors? 00237 * 00238 * @return 00239 * 'true' if all went fine, else 'false' (maybe the mesh has no texture coordinates...) 00240 * 00241 * @note 00242 * - This function will add tangents and binormals to the vertex buffer if 00243 * there are no one allocated yet 00244 * - If there are no normals available they will be computed (see CalculateNormals()) 00245 * - To save memory one can only hold tangent vectors and compute the binormal for 00246 * instance within a vertex shader using a cross product of the normal and 00247 * tangent vector 00248 * - If there are vertex ID's, we CAN'T calculate normals because only a few vertices are 00249 * influenced by this morph target! 00250 */ 00251 PLMESH_API bool CalculateTangentSpaceVectors(bool bTangent = true, bool bBinormal = true); 00252 00253 /** 00254 * @brief 00255 * Calculates the morph target bounding box 00256 * 00257 * @param[out] vMinPos 00258 * Will receive the minimum bounding box position 00259 * @param[out] vMaxPos 00260 * Will receive the maximum bounding box position 00261 * 00262 * @return 00263 * 'true' if all went fine, else 'false' 00264 */ 00265 PLMESH_API bool CalculateBoundingBox(PLMath::Vector3 &vMinPos, PLMath::Vector3 &vMaxPos) const; 00266 00267 /** 00268 * @brief 00269 * Calculates the morph target bounding sphere 00270 * 00271 * @param[out] vPos 00272 * Will receive the bounding sphere position 00273 * @param[out] fRadius 00274 * Will receive the bounding sphere radius 00275 * 00276 * @return 00277 * 'true' if all went fine, else 'false' 00278 */ 00279 PLMESH_API bool CalculateBoundingSphere(PLMath::Vector3 &vPos, float &fRadius) const; 00280 00281 00282 //[-------------------------------------------------------] 00283 //[ Private data ] 00284 //[-------------------------------------------------------] 00285 private: 00286 // Internal data 00287 PLCore::String m_sName; /**< Name of the morph target */ 00288 bool m_bRelative; /**< Is this morph target relative to the basis morph target? */ 00289 Mesh *m_pMesh; /**< Owner mesh, can be a null pointer */ 00290 00291 // Only used if relative 00292 PLCore::Array<PLCore::uint32> m_lstVertexIDs; /**< Vertex ID's */ 00293 00294 // Vertex data 00295 PLRenderer::VertexBuffer *m_pVertexBuffer; /**< A vertex buffer, can be a null pointer */ 00296 00297 // Precalculated data 00298 PLCore::Array<PLMath::Plane> m_lstTrianglePlanes; /**< List of triangle planes */ 00299 00300 00301 }; 00302 00303 00304 //[-------------------------------------------------------] 00305 //[ Namespace ] 00306 //[-------------------------------------------------------] 00307 } // PLMesh 00308 00309 00310 #endif // __PLMESH_MESH_MORPHTARGET_H__
|