Moves some constants out of llavatarconstants.h 8ebf8f4608bd: Change various const constants to constexpr e07d5d43ba30: CID-143595 30b6935fc66d: CID-143595 acc96f9051cb: Fix a memory leak in viewer side baking initial wearable setup Sync llmodel.* Changesets assimilated: f8f7706c2902: CID-143554 - fix out of bounds access 223eb65adce4: CID-143554 - Chase 2ceb49aaa133: CID-42838, CID-42930, CID-42933, CID-42938, CID-42940, CID-42945, CID-42948, CID-56111, CID-83907 d220005d9f23: Missing null check before deref 31dbb0f3b6ee: CID-42571 CID-42576 CID-42578 49caf082e65c: change unordered_map to flat_map Doesn't cause as many problems as a hashmap when it comes to assumptions in the LLUI system. f93f5e881484: "update" linux cef downgrade to fix javascript problems cba818dd9269: Various null checks and etc. 1b4c6bc483bb: CID-42847, CID-42854, CID-42886, CID-42921, CID-42922, CID-42923, CID-42924, CID-42925, CID-42927, CID-42928, CID-83871, CID-83876, CID-83878, CID-83880, CID-83900, CID-143573 0fe90cd9ec24: Various file size related things a79f6f653dca: CID-42918 - Initialize member pointers in LLFloaterGodTools 0b70d600d978: Tweak LLFloaterBuyLand initializations e8b173ffe813: CID-42854 - Additional fix to LLDrawInfo b5d745cf3fde: Fix signage 4f2e2f384781: Initialize and cleanup various class member variables. CID-42899, CID-42900, CID-42902, CID-42903, CID-42904, CID-42905, CID-42909, CID-42910, CID-42911, CID-42912, CID-42913, CID-42967, CID-83853, CID-83898, CID-83890, CID-143584 9851a3e39b4c: Fix platform specific include directories 5c074e84f1be: Initialize and clenaup various more class member variables. CID-42885, CID-42853, CID-42894, CID-42895, CID-42896, CID-83908, CID-143574, CID-143575, CID-143576, CID-143576, CID-143578 ac262854ac92: Brace sub-object in initialization to make our intentions clear to clang 358da477d4c1: More double brace init c3850119314a: Initialize various member pointers in panels CID-83902, CID-83903, CID-83905, CID-83909, CID-83911, CID-83912, CID-143572
289 lines
7.0 KiB
C++
289 lines
7.0 KiB
C++
/**
|
|
* @file llmodel.h
|
|
* @brief Model handling class definitions
|
|
*
|
|
* $LicenseInfo:firstyear=2001&license=viewerlgpl$
|
|
* Second Life Viewer Source Code
|
|
* Copyright (C) 2010, Linden Research, Inc.
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation;
|
|
* version 2.1 of the License only.
|
|
*
|
|
* This library 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 for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*
|
|
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
|
|
* $/LicenseInfo$
|
|
*/
|
|
|
|
#ifndef LL_LLMODEL_H
|
|
#define LL_LLMODEL_H
|
|
|
|
#include "llpointer.h"
|
|
#include "llvolume.h"
|
|
#include "v4math.h"
|
|
#include "m4math.h"
|
|
|
|
class daeElement;
|
|
class domMesh;
|
|
|
|
#define MAX_MODEL_FACES 8
|
|
|
|
|
|
class LLMeshSkinInfo
|
|
{
|
|
public:
|
|
LLUUID mMeshID;
|
|
std::vector<std::string> mJointNames;
|
|
std::vector<LLMatrix4> mInvBindMatrix;
|
|
std::vector<LLMatrix4> mAlternateBindMatrix;
|
|
std::map<std::string, U32> mJointMap;
|
|
|
|
LLMeshSkinInfo() { }
|
|
LLMeshSkinInfo(LLSD& data);
|
|
void fromLLSD(LLSD& data);
|
|
LLSD asLLSD(bool include_joints) const;
|
|
LLMatrix4 mBindShapeMatrix;
|
|
float mPelvisOffset;
|
|
};
|
|
|
|
class LLModel : public LLVolume
|
|
{
|
|
public:
|
|
|
|
enum
|
|
{
|
|
LOD_IMPOSTOR = 0,
|
|
LOD_LOW,
|
|
LOD_MEDIUM,
|
|
LOD_HIGH,
|
|
LOD_PHYSICS,
|
|
NUM_LODS
|
|
};
|
|
|
|
enum EModelStatus
|
|
{
|
|
NO_ERRORS = 0,
|
|
VERTEX_NUMBER_OVERFLOW, //vertex number is >= 65535.
|
|
BAD_ELEMENT,
|
|
INVALID_STATUS
|
|
} ;
|
|
|
|
//convex_hull_decomposition is a vector of convex hulls
|
|
//each convex hull is a set of points
|
|
typedef std::vector<std::vector<LLVector3> > convex_hull_decomposition;
|
|
typedef std::vector<LLVector3> hull;
|
|
|
|
class PhysicsMesh
|
|
{
|
|
public:
|
|
std::vector<LLVector3> mPositions;
|
|
std::vector<LLVector3> mNormals;
|
|
|
|
void clear()
|
|
{
|
|
mPositions.clear();
|
|
mNormals.clear();
|
|
}
|
|
|
|
bool empty() const
|
|
{
|
|
return mPositions.empty();
|
|
}
|
|
};
|
|
|
|
class Decomposition
|
|
{
|
|
public:
|
|
Decomposition() { }
|
|
Decomposition(LLSD& data);
|
|
void fromLLSD(LLSD& data);
|
|
LLSD asLLSD() const;
|
|
bool hasHullList() const;
|
|
|
|
void merge(const Decomposition* rhs);
|
|
|
|
LLUUID mMeshID;
|
|
LLModel::convex_hull_decomposition mHull;
|
|
LLModel::hull mBaseHull;
|
|
|
|
std::vector<LLModel::PhysicsMesh> mMesh;
|
|
LLModel::PhysicsMesh mBaseHullMesh;
|
|
LLModel::PhysicsMesh mPhysicsShapeMesh;
|
|
};
|
|
|
|
LLModel(LLVolumeParams& params, F32 detail);
|
|
~LLModel();
|
|
|
|
bool loadModel(std::istream& is);
|
|
bool loadSkinInfo(LLSD& header, std::istream& is);
|
|
bool loadDecomposition(LLSD& header, std::istream& is);
|
|
|
|
static LLSD writeModel(
|
|
std::ostream& ostr,
|
|
LLModel* physics,
|
|
LLModel* high,
|
|
LLModel* medium,
|
|
LLModel* low,
|
|
LLModel* imposotr,
|
|
const LLModel::Decomposition& decomp,
|
|
BOOL upload_skin,
|
|
BOOL upload_joints,
|
|
BOOL nowrite = FALSE,
|
|
BOOL as_slm = FALSE);
|
|
|
|
static LLSD writeModelToStream(
|
|
std::ostream& ostr,
|
|
LLSD& mdl,
|
|
BOOL nowrite = FALSE, BOOL as_slm = FALSE);
|
|
|
|
static LLModel* loadModelFromDomMesh(domMesh* mesh);
|
|
static std::string getElementLabel(daeElement* element);
|
|
std::string getName() const;
|
|
std::string getMetric() const {return mMetric;}
|
|
EModelStatus getStatus() const {return mStatus;}
|
|
static std::string getStatusString(U32 status) ;
|
|
|
|
void appendFaces(LLModel* model, LLMatrix4& transform, LLMatrix4& normal_transform);
|
|
void appendFace(const LLVolumeFace& src_face, std::string src_material, LLMatrix4& mat, LLMatrix4& norm_mat);
|
|
|
|
void setNumVolumeFaces(S32 count);
|
|
void setVolumeFaceData(
|
|
S32 f,
|
|
LLStrider<LLVector3> pos,
|
|
LLStrider<LLVector3> norm,
|
|
LLStrider<LLVector2> tc,
|
|
LLStrider<U16> ind,
|
|
U32 num_verts,
|
|
U32 num_indices);
|
|
|
|
void generateNormals(F32 angle_cutoff);
|
|
|
|
void addFace(const LLVolumeFace& face);
|
|
|
|
void normalizeVolumeFaces();
|
|
void optimizeVolumeFaces();
|
|
void offsetMesh( const LLVector3& pivotPoint );
|
|
void getNormalizedScaleTranslation(LLVector3& scale_out, LLVector3& translation_out);
|
|
LLVector3 getTransformedCenter(const LLMatrix4& mat);
|
|
|
|
//reorder face list based on mMaterialList in this and reference so
|
|
//order matches that of reference (material ordering touchup)
|
|
bool matchMaterialOrder(LLModel* ref, int& refFaceCnt, int& modelFaceCnt );
|
|
bool isMaterialListSubset( LLModel* ref );
|
|
bool needToAddFaces( LLModel* ref, int& refFaceCnt, int& modelFaceCnt );
|
|
|
|
typedef std::vector<std::string> material_list;
|
|
|
|
material_list mMaterialList;
|
|
|
|
material_list& getMaterialList() { return mMaterialList; }
|
|
|
|
//data used for skin weights
|
|
class JointWeight
|
|
{
|
|
public:
|
|
S32 mJointIdx;
|
|
F32 mWeight;
|
|
|
|
JointWeight()
|
|
{
|
|
mJointIdx = 0;
|
|
mWeight = 0.f;
|
|
}
|
|
|
|
JointWeight(S32 idx, F32 weight)
|
|
: mJointIdx(idx), mWeight(weight)
|
|
{
|
|
}
|
|
|
|
bool operator<(const JointWeight& rhs) const
|
|
{
|
|
if (mWeight == rhs.mWeight)
|
|
{
|
|
return mJointIdx < rhs.mJointIdx;
|
|
}
|
|
|
|
return mWeight < rhs.mWeight;
|
|
}
|
|
|
|
};
|
|
|
|
struct CompareWeightGreater
|
|
{
|
|
bool operator()(const JointWeight& lhs, const JointWeight& rhs)
|
|
{
|
|
return rhs < lhs; // strongest = first
|
|
}
|
|
};
|
|
|
|
|
|
//Are the doubles the same w/in epsilon specified tolerance
|
|
bool areEqual( double a, double b )
|
|
{
|
|
const float epsilon = 1e-5f;
|
|
return (fabs((a - b)) < epsilon) ? true : false ;
|
|
}
|
|
//Make sure that we return false for any values that are within the tolerance for equivalence
|
|
bool jointPositionalLookup( const LLVector3& a, const LLVector3& b )
|
|
{
|
|
return ( areEqual( a[0],b[0]) && areEqual( a[1],b[1] ) && areEqual( a[2],b[2]) ) ? true : false;
|
|
}
|
|
|
|
//copy of position array for this model -- mPosition[idx].mV[X,Y,Z]
|
|
std::vector<LLVector3> mPosition;
|
|
|
|
//map of positions to skin weights --- mSkinWeights[pos].mV[0..4] == <joint_index>.<weight>
|
|
//joint_index corresponds to mJointList
|
|
typedef std::vector<JointWeight> weight_list;
|
|
typedef std::map<LLVector3, weight_list > weight_map;
|
|
weight_map mSkinWeights;
|
|
|
|
//get list of weight influences closest to given position
|
|
weight_list& getJointInfluences(const LLVector3& pos);
|
|
|
|
LLMeshSkinInfo mSkinInfo;
|
|
|
|
std::string mRequestedLabel; // name requested in UI, if any.
|
|
std::string mLabel; // name computed from dae.
|
|
|
|
std::string mMetric; // user-supplied metric data for upload
|
|
|
|
LLVector3 mNormalizedScale;
|
|
LLVector3 mNormalizedTranslation;
|
|
|
|
float mPelvisOffset;
|
|
// convex hull decomposition
|
|
S32 mDecompID;
|
|
|
|
void setConvexHullDecomposition(
|
|
const convex_hull_decomposition& decomp);
|
|
void updateHullCenters();
|
|
|
|
LLVector3 mCenterOfHullCenters;
|
|
std::vector<LLVector3> mHullCenter;
|
|
U32 mHullPoints;
|
|
|
|
//ID for storing this model in a .slm file
|
|
S32 mLocalID;
|
|
|
|
Decomposition mPhysics;
|
|
|
|
EModelStatus mStatus ;
|
|
|
|
int mSubmodelID;
|
|
protected:
|
|
void addVolumeFacesFromDomMesh(domMesh* mesh);
|
|
virtual BOOL createVolumeFacesFromDomMesh(domMesh *mesh);
|
|
};
|
|
|
|
#endif //LL_LLMODEL_H
|