PageRenderTime 129ms CodeModel.GetById 7ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llpolymesh.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 438 lines | 235 code | 88 blank | 115 comment | 2 complexity | 511b513a626010c555b28426d09b5e71 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llpolymesh.h
  3. * @brief Implementation of LLPolyMesh class
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLPOLYMESH_H
  27. #define LL_LLPOLYMESH_H
  28. #include <string>
  29. #include <map>
  30. #include "llstl.h"
  31. #include "v3math.h"
  32. #include "v2math.h"
  33. #include "llquaternion.h"
  34. #include "llpolymorph.h"
  35. #include "lljoint.h"
  36. //#include "lldarray.h"
  37. class LLSkinJoint;
  38. class LLVOAvatar;
  39. class LLWearable;
  40. //#define USE_STRIPS // Use tri-strips for rendering.
  41. //-----------------------------------------------------------------------------
  42. // LLPolyFace
  43. // A set of 4 vertex indices.
  44. // An LLPolyFace can represent either a triangle or quad.
  45. // If the last index is -1, it's a triangle.
  46. //-----------------------------------------------------------------------------
  47. typedef S32 LLPolyFace[3];
  48. //struct PrimitiveGroup;
  49. //-----------------------------------------------------------------------------
  50. // LLPolyMesh
  51. // A polyhedra consisting of any number of triangles and quads.
  52. // All instances contain a set of faces, and optionally may include
  53. // faces grouped into named face sets.
  54. //-----------------------------------------------------------------------------
  55. class LLPolyMorphTarget;
  56. class LLPolyMeshSharedData
  57. {
  58. friend class LLPolyMesh;
  59. private:
  60. // transform data
  61. LLVector3 mPosition;
  62. LLQuaternion mRotation;
  63. LLVector3 mScale;
  64. // vertex data
  65. S32 mNumVertices;
  66. LLVector3 *mBaseCoords;
  67. LLVector3 *mBaseNormals;
  68. LLVector3 *mBaseBinormals;
  69. LLVector2 *mTexCoords;
  70. LLVector2 *mDetailTexCoords;
  71. F32 *mWeights;
  72. BOOL mHasWeights;
  73. BOOL mHasDetailTexCoords;
  74. // face data
  75. S32 mNumFaces;
  76. LLPolyFace *mFaces;
  77. // face set data
  78. U32 mNumJointNames;
  79. std::string* mJointNames;
  80. // morph targets
  81. typedef std::set<LLPolyMorphData*> morphdata_list_t;
  82. morphdata_list_t mMorphData;
  83. std::map<S32, S32> mSharedVerts;
  84. LLPolyMeshSharedData* mReferenceData;
  85. S32 mLastIndexOffset;
  86. public:
  87. // Temporarily...
  88. // Triangle indices
  89. U32 mNumTriangleIndices;
  90. U32 *mTriangleIndices;
  91. public:
  92. LLPolyMeshSharedData();
  93. ~LLPolyMeshSharedData();
  94. private:
  95. void setupLOD(LLPolyMeshSharedData* reference_data);
  96. // Frees all mesh memory resources
  97. void freeMeshData();
  98. void setPosition( const LLVector3 &pos ) { mPosition = pos; }
  99. void setRotation( const LLQuaternion &rot ) { mRotation = rot; }
  100. void setScale( const LLVector3 &scale ) { mScale = scale; }
  101. BOOL allocateVertexData( U32 numVertices );
  102. BOOL allocateFaceData( U32 numFaces );
  103. BOOL allocateJointNames( U32 numJointNames );
  104. // Retrieve the number of KB of memory used by this instance
  105. U32 getNumKB();
  106. // Load mesh data from file
  107. BOOL loadMesh( const std::string& fileName );
  108. public:
  109. void genIndices(S32 offset);
  110. const LLVector2 &getUVs(U32 index);
  111. const S32 *getSharedVert(S32 vert);
  112. BOOL isLOD() { return (mReferenceData != NULL); }
  113. };
  114. class LLJointRenderData
  115. {
  116. public:
  117. LLJointRenderData(const LLMatrix4* world_matrix, LLSkinJoint* skin_joint) : mWorldMatrix(world_matrix), mSkinJoint(skin_joint) {}
  118. ~LLJointRenderData(){}
  119. const LLMatrix4* mWorldMatrix;
  120. LLSkinJoint* mSkinJoint;
  121. };
  122. class LLPolyMesh
  123. {
  124. public:
  125. // Constructor
  126. LLPolyMesh(LLPolyMeshSharedData *shared_data, LLPolyMesh *reference_mesh);
  127. // Destructor
  128. ~LLPolyMesh();
  129. // Requests a mesh by name.
  130. // If the mesh already exists in the global mesh table, it is returned,
  131. // otherwise it is loaded from file, added to the table, and returned.
  132. static LLPolyMesh *getMesh( const std::string &name, LLPolyMesh* reference_mesh = NULL);
  133. // Frees all loaded meshes.
  134. // This should only be called once you know there are no outstanding
  135. // references to these objects. Generally, upon exit of the application.
  136. static void freeAllMeshes();
  137. //--------------------------------------------------------------------
  138. // Transform Data Access
  139. //--------------------------------------------------------------------
  140. // Get position
  141. const LLVector3 &getPosition() {
  142. llassert (mSharedData);
  143. return mSharedData->mPosition;
  144. }
  145. // Get rotation
  146. const LLQuaternion &getRotation() {
  147. llassert (mSharedData);
  148. return mSharedData->mRotation;
  149. }
  150. // Get scale
  151. const LLVector3 &getScale() {
  152. llassert (mSharedData);
  153. return mSharedData->mScale;
  154. }
  155. //--------------------------------------------------------------------
  156. // Vertex Data Access
  157. //--------------------------------------------------------------------
  158. // Get number of vertices
  159. U32 getNumVertices() {
  160. llassert (mSharedData);
  161. return mSharedData->mNumVertices;
  162. }
  163. // Returns whether or not the mesh has detail texture coords
  164. BOOL hasDetailTexCoords() {
  165. llassert (mSharedData);
  166. return mSharedData->mHasDetailTexCoords;
  167. }
  168. // Returns whether or not the mesh has vertex weights
  169. BOOL hasWeights() const{
  170. llassert (mSharedData);
  171. return mSharedData->mHasWeights;
  172. }
  173. // Get coords
  174. const LLVector4 *getCoords() const{
  175. return mCoords;
  176. }
  177. // non const version
  178. LLVector4 *getWritableCoords();
  179. // Get normals
  180. const LLVector4 *getNormals() const{
  181. return mNormals;
  182. }
  183. // Get normals
  184. const LLVector3 *getBinormals() const{
  185. return mBinormals;
  186. }
  187. // Get base mesh normals
  188. const LLVector3 *getBaseNormals() const{
  189. llassert(mSharedData);
  190. return mSharedData->mBaseNormals;
  191. }
  192. // Get base mesh normals
  193. const LLVector3 *getBaseBinormals() const{
  194. llassert(mSharedData);
  195. return mSharedData->mBaseBinormals;
  196. }
  197. // intermediate morphed normals and output normals
  198. LLVector4 *getWritableNormals();
  199. LLVector3 *getScaledNormals();
  200. LLVector3 *getWritableBinormals();
  201. LLVector3 *getScaledBinormals();
  202. // Get texCoords
  203. const LLVector2 *getTexCoords() const {
  204. return mTexCoords;
  205. }
  206. // non const version
  207. LLVector2 *getWritableTexCoords();
  208. // Get detailTexCoords
  209. const LLVector2 *getDetailTexCoords() const {
  210. llassert (mSharedData);
  211. return mSharedData->mDetailTexCoords;
  212. }
  213. // Get weights
  214. const F32 *getWeights() const {
  215. llassert (mSharedData);
  216. return mSharedData->mWeights;
  217. }
  218. F32 *getWritableWeights() const;
  219. LLVector4 *getWritableClothingWeights();
  220. const LLVector4 *getClothingWeights()
  221. {
  222. return mClothingWeights;
  223. }
  224. //--------------------------------------------------------------------
  225. // Face Data Access
  226. //--------------------------------------------------------------------
  227. // Get number of faces
  228. S32 getNumFaces() {
  229. llassert (mSharedData);
  230. return mSharedData->mNumFaces;
  231. }
  232. // Get faces
  233. LLPolyFace *getFaces() {
  234. llassert (mSharedData);
  235. return mSharedData->mFaces;
  236. }
  237. U32 getNumJointNames() {
  238. llassert (mSharedData);
  239. return mSharedData->mNumJointNames;
  240. }
  241. std::string *getJointNames() {
  242. llassert (mSharedData);
  243. return mSharedData->mJointNames;
  244. }
  245. LLPolyMorphData* getMorphData(const std::string& morph_name);
  246. // void removeMorphData(LLPolyMorphData *morph_target);
  247. // void deleteAllMorphData();
  248. LLPolyMeshSharedData *getSharedData() const;
  249. LLPolyMesh *getReferenceMesh() { return mReferenceMesh ? mReferenceMesh : this; }
  250. // Get indices
  251. U32* getIndices() { return mSharedData ? mSharedData->mTriangleIndices : NULL; }
  252. BOOL isLOD() { return mSharedData && mSharedData->isLOD(); }
  253. void setAvatar(LLVOAvatar* avatarp) { mAvatarp = avatarp; }
  254. LLVOAvatar* getAvatar() { return mAvatarp; }
  255. LLDynamicArray<LLJointRenderData*> mJointRenderData;
  256. U32 mFaceVertexOffset;
  257. U32 mFaceVertexCount;
  258. U32 mFaceIndexOffset;
  259. U32 mFaceIndexCount;
  260. U32 mCurVertexCount;
  261. private:
  262. void initializeForMorph();
  263. // Dumps diagnostic information about the global mesh table
  264. static void dumpDiagInfo();
  265. protected:
  266. // mesh data shared across all instances of a given mesh
  267. LLPolyMeshSharedData *mSharedData;
  268. // Single array of floats for allocation / deletion
  269. F32 *mVertexData;
  270. // deformed vertices (resulting from application of morph targets)
  271. LLVector4 *mCoords;
  272. // deformed normals (resulting from application of morph targets)
  273. LLVector3 *mScaledNormals;
  274. // output normals (after normalization)
  275. LLVector4 *mNormals;
  276. // deformed binormals (resulting from application of morph targets)
  277. LLVector3 *mScaledBinormals;
  278. // output binormals (after normalization)
  279. LLVector3 *mBinormals;
  280. // weight values that mark verts as clothing/skin
  281. LLVector4 *mClothingWeights;
  282. // output texture coordinates
  283. LLVector2 *mTexCoords;
  284. LLPolyMesh *mReferenceMesh;
  285. // global mesh list
  286. typedef std::map<std::string, LLPolyMeshSharedData*> LLPolyMeshSharedDataTable;
  287. static LLPolyMeshSharedDataTable sGlobalSharedMeshList;
  288. // Backlink only; don't make this an LLPointer.
  289. LLVOAvatar* mAvatarp;
  290. };
  291. //-----------------------------------------------------------------------------
  292. // LLPolySkeletalDeformationInfo
  293. // Shared information for LLPolySkeletalDeformations
  294. //-----------------------------------------------------------------------------
  295. struct LLPolySkeletalBoneInfo
  296. {
  297. LLPolySkeletalBoneInfo(std::string &name, LLVector3 &scale, LLVector3 &pos, BOOL haspos)
  298. : mBoneName(name),
  299. mScaleDeformation(scale),
  300. mPositionDeformation(pos),
  301. mHasPositionDeformation(haspos) {}
  302. std::string mBoneName;
  303. LLVector3 mScaleDeformation;
  304. LLVector3 mPositionDeformation;
  305. BOOL mHasPositionDeformation;
  306. };
  307. class LLPolySkeletalDistortionInfo : public LLViewerVisualParamInfo
  308. {
  309. friend class LLPolySkeletalDistortion;
  310. public:
  311. LLPolySkeletalDistortionInfo();
  312. /*virtual*/ ~LLPolySkeletalDistortionInfo() {};
  313. /*virtual*/ BOOL parseXml(LLXmlTreeNode* node);
  314. protected:
  315. typedef std::vector<LLPolySkeletalBoneInfo> bone_info_list_t;
  316. bone_info_list_t mBoneInfoList;
  317. };
  318. //-----------------------------------------------------------------------------
  319. // LLPolySkeletalDeformation
  320. // A set of joint scale data for deforming the avatar mesh
  321. //-----------------------------------------------------------------------------
  322. class LLPolySkeletalDistortion : public LLViewerVisualParam
  323. {
  324. public:
  325. LLPolySkeletalDistortion(LLVOAvatar *avatarp);
  326. ~LLPolySkeletalDistortion();
  327. // Special: These functions are overridden by child classes
  328. LLPolySkeletalDistortionInfo* getInfo() const { return (LLPolySkeletalDistortionInfo*)mInfo; }
  329. // This sets mInfo and calls initialization functions
  330. BOOL setInfo(LLPolySkeletalDistortionInfo *info);
  331. /*virtual*/ LLViewerVisualParam* cloneParam(LLWearable* wearable) const;
  332. // LLVisualParam Virtual functions
  333. ///*virtual*/ BOOL parseData(LLXmlTreeNode* node);
  334. /*virtual*/ void apply( ESex sex );
  335. // LLViewerVisualParam Virtual functions
  336. /*virtual*/ F32 getTotalDistortion() { return 0.1f; }
  337. /*virtual*/ const LLVector3& getAvgDistortion() { return mDefaultVec; }
  338. /*virtual*/ F32 getMaxDistortion() { return 0.1f; }
  339. /*virtual*/ LLVector3 getVertexDistortion(S32 index, LLPolyMesh *poly_mesh){return LLVector3(0.001f, 0.001f, 0.001f);}
  340. /*virtual*/ const LLVector3* getFirstDistortion(U32 *index, LLPolyMesh **poly_mesh){index = 0; poly_mesh = NULL; return &mDefaultVec;};
  341. /*virtual*/ const LLVector3* getNextDistortion(U32 *index, LLPolyMesh **poly_mesh){index = 0; poly_mesh = NULL; return NULL;};
  342. protected:
  343. typedef std::map<LLJoint*, LLVector3> joint_vec_map_t;
  344. joint_vec_map_t mJointScales;
  345. joint_vec_map_t mJointOffsets;
  346. LLVector3 mDefaultVec;
  347. // Backlink only; don't make this an LLPointer.
  348. LLVOAvatar *mAvatar;
  349. };
  350. #endif // LL_LLPOLYMESH_H