From 1ff79683128f09baf6dbaf081092fda7e5f2fe65 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 28 Mar 2011 23:50:23 -0500 Subject: SH-1225 Add skinning info to import path of .slm files. --- indra/llprimitive/llmodel.cpp | 325 +++++++++++++++++++++++++++++------------- indra/llprimitive/llmodel.h | 38 +++-- 2 files changed, 253 insertions(+), 110 deletions(-) (limited to 'indra/llprimitive') diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp index 3669fef0dc..81420fadb7 100755 --- a/indra/llprimitive/llmodel.cpp +++ b/indra/llprimitive/llmodel.cpp @@ -775,43 +775,6 @@ BOOL LLModel::createVolumeFacesFromDomMesh(domMesh* mesh) return FALSE; } - -BOOL LLModel::createVolumeFacesFromFile(const std::string& file_name) -{ - DAE dae; - domCOLLADA* dom = dae.open(file_name); - if (dom) - { - daeDatabase* db = dae.getDatabase(); - - daeInt count = db->getElementCount(NULL, COLLADA_TYPE_MESH); - - mVolumeFaces.clear(); - mMaterialList.clear(); - - for (daeInt idx = 0; idx < count; ++idx) - { - domMesh* mesh = NULL; - - db->getElement((daeElement**) &mesh, idx, NULL, COLLADA_TYPE_MESH); - - if (mesh) - { - addVolumeFacesFromDomMesh(mesh); - } - } - - if (getNumVolumeFaces() > 0) - { - optimizeVolumeFaces(); - normalizeVolumeFaces(); - return TRUE; - } - } - - return FALSE; -} - void LLModel::offsetMesh( const LLVector3& pivotPoint ) { LLVector4a pivot( pivotPoint[VX], pivotPoint[VY], pivotPoint[VZ] ); @@ -1351,16 +1314,6 @@ std::string LLModel::getElementLabel(daeElement *element) return std::string("object"); } -//static -LLModel* LLModel::loadModelFromDae(std::string filename) -{ - LLVolumeParams volume_params; - volume_params.setType(LL_PCODE_PROFILE_SQUARE, LL_PCODE_PATH_LINE); - LLModel* ret = new LLModel(volume_params, 0.f); - ret->createVolumeFacesFromFile(filename); - return ret; -} - //static LLModel* LLModel::loadModelFromDomMesh(domMesh *mesh) { @@ -1473,49 +1426,7 @@ LLSD LLModel::writeModel( if (skinning) { //write skinning block - if (high->mJointList.size() != high->mInvBindMatrix.size()) - { - llerrs << "WTF?" << llendl; - } - - for (U32 i = 0; i < high->mJointList.size(); ++i) - { - mdl["skin"]["joint_names"][i] = high->mJointList[i]; - - for (U32 j = 0; j < 4; j++) - { - for (U32 k = 0; k < 4; k++) - { - mdl["skin"]["inverse_bind_matrix"][i][j*4+k] = high->mInvBindMatrix[i].mMatrix[j][k]; - } - } - } - - for (U32 i = 0; i < 4; i++) - { - for (U32 j = 0; j < 4; j++) - { - mdl["skin"]["bind_shape_matrix"][i*4+j] = high->mBindShapeMatrix.mMatrix[i][j]; - } - } - - - if ( upload_joints && high->mAlternateBindMatrix.size() > 0 ) - { - for (U32 i = 0; i < high->mJointList.size(); ++i) - { - for (U32 j = 0; j < 4; j++) - { - for (U32 k = 0; k < 4; k++) - { - mdl["skin"]["alt_inverse_bind_matrix"][i][j*4+k] = high->mAlternateBindMatrix[i].mMatrix[j][k]; - } - } - } - - mdl["skin"]["pelvis_offset"] = high->mPelvisOffset; - } - + mdl["skin"] = high->mSkinInfo.asLLSD(upload_joints); } if (!decomp.empty() || !base_hull.empty()) @@ -1897,12 +1808,6 @@ LLSD LLModel::writeModelToStream(std::ostream& ostr, LLSD& mdl, BOOL nowrite) return header; } -//static -LLModel* LLModel::loadModelFromAsset(std::string filename, S32 lod) -{ - return NULL; -} - LLModel::weight_list& LLModel::getJointInfluences(const LLVector3& pos) { weight_map::iterator iter = mSkinWeights.find(pos); @@ -1999,4 +1904,232 @@ void LLModel::setConvexHullDecomposition( mCenterOfHullCenters *= 1.f / mHullPoints; } +bool LLModel::loadModel(std::istream& is) +{ + mSculptLevel = -1; // default is an error occured + + LLSD header; + { + if (!LLSDSerialize::fromBinary(header, is, 1024*1024*1024)) + { + llwarns << "Mesh header parse error. Not a valid mesh asset!" << llendl; + return false; + } + } + + std::string nm[] = + { + "lowest_lod", + "low_lod", + "medium_lod", + "high_lod", + "physics_shape", + }; + + const S32 MODEL_LODS = 5; + + S32 lod = llclamp((S32) mDetail, 0, MODEL_LODS); + + if (header[nm[lod]]["offset"].asInteger() == -1 || + header[nm[lod]]["size"].asInteger() == 0 ) + { //cannot load requested LOD + return false; + } + + bool has_skin = header["skin"]["offset"].asInteger() >=0 && + header["skin"]["size"].asInteger() > 0; + + if (lod == LLModel::LOD_HIGH) + { //try to load skin info and decomp info + std::ios::pos_type cur_pos = is.tellg(); + loadSkinInfo(header, is); + is.seekg(cur_pos); + loadDecomposition(header, is); + is.seekg(cur_pos); + } + + + + is.seekg(header[nm[lod]]["offset"].asInteger(), std::ios_base::cur); + + if (unpackVolumeFaces(is, header[nm[lod]]["size"].asInteger())) + { + if (has_skin) + { + //build out mSkinWeight from face info + for (S32 i = 0; i < getNumVolumeFaces(); ++i) + { + const LLVolumeFace& face = getVolumeFace(i); + + if (face.mWeights) + { + for (S32 j = 0; j < face.mNumVertices; ++j) + { + LLVector4a& w = face.mWeights[j]; + + std::vector wght; + + for (S32 k = 0; k < 4; ++k) + { + S32 idx = (S32) w[k]; + F32 f = w[k] - idx; + if (f > 0.f) + { + wght.push_back(JointWeight(idx, f)); + } + } + + if (!wght.empty()) + { + LLVector3 pos(face.mPositions[j].getF32ptr()); + mSkinWeights[pos] = wght; + } + } + } + } + } + return true; + } + + return false; + +} + + +bool LLModel::loadSkinInfo(LLSD& header, std::istream &is) +{ + S32 offset = header["skin"]["offset"].asInteger(); + S32 size = header["skin"]["size"].asInteger(); + + if (offset >= 0 && size > 0) + { + is.seekg(offset, std::ios_base::cur); + + LLSD skin_data; + + if (unzip_llsd(skin_data, is, size)) + { + mSkinInfo.fromLLSD(skin_data); + return true; + } + } + + return false; +} + +bool LLModel::loadDecomposition(LLSD& header, std::istream& is) +{ + return true; +} + + +LLMeshSkinInfo::LLMeshSkinInfo(LLSD& skin) +{ + fromLLSD(skin); +} + +void LLMeshSkinInfo::fromLLSD(LLSD& skin) +{ + if (skin.has("joint_names")) + { + for (U32 i = 0; i < skin["joint_names"].size(); ++i) + { + mJointNames.push_back(skin["joint_names"][i]); + } + } + + if (skin.has("inverse_bind_matrix")) + { + for (U32 i = 0; i < skin["inverse_bind_matrix"].size(); ++i) + { + LLMatrix4 mat; + for (U32 j = 0; j < 4; j++) + { + for (U32 k = 0; k < 4; k++) + { + mat.mMatrix[j][k] = skin["inverse_bind_matrix"][i][j*4+k].asReal(); + } + } + + mInvBindMatrix.push_back(mat); + } + } + + if (skin.has("bind_shape_matrix")) + { + for (U32 j = 0; j < 4; j++) + { + for (U32 k = 0; k < 4; k++) + { + mBindShapeMatrix.mMatrix[j][k] = skin["bind_shape_matrix"][j*4+k].asReal(); + } + } + } + + if (skin.has("alt_inverse_bind_matrix")) + { + for (U32 i = 0; i < skin["alt_inverse_bind_matrix"].size(); ++i) + { + LLMatrix4 mat; + for (U32 j = 0; j < 4; j++) + { + for (U32 k = 0; k < 4; k++) + { + mat.mMatrix[j][k] = skin["alt_inverse_bind_matrix"][i][j*4+k].asReal(); + } + } + + mAlternateBindMatrix.push_back(mat); + } + } + + if (skin.has("pelvis_offset")) + { + mPelvisOffset = skin["pelvis_offset"].asReal(); + } +} + +LLSD LLMeshSkinInfo::asLLSD(bool include_joints) const +{ + LLSD ret; + + for (U32 i = 0; i < mJointNames.size(); ++i) + { + ret["joint_names"][i] = mJointNames[i]; + + for (U32 j = 0; j < 4; j++) + { + for (U32 k = 0; k < 4; k++) + { + ret["inverse_bind_matrix"][i][j*4+k] = mInvBindMatrix[i].mMatrix[j][k]; + } + } + } + + for (U32 i = 0; i < 4; i++) + { + for (U32 j = 0; j < 4; j++) + { + ret["bind_shape_matrix"][i*4+j] = mBindShapeMatrix.mMatrix[i][j]; + } + } + + if ( include_joints && mAlternateBindMatrix.size() > 0 ) + { + for (U32 i = 0; i < mJointNames.size(); ++i) + { + for (U32 j = 0; j < 4; j++) + { + for (U32 k = 0; k < 4; k++) + { + ret["alt_inverse_bind_matrix"][i][j*4+k] = mAlternateBindMatrix[i].mMatrix[j][k]; + } + } + } + + ret["pelvis_offset"] = mPelvisOffset; + } + + return ret; +} diff --git a/indra/llprimitive/llmodel.h b/indra/llprimitive/llmodel.h index addf527d8d..81be9d1835 100755 --- a/indra/llprimitive/llmodel.h +++ b/indra/llprimitive/llmodel.h @@ -36,6 +36,25 @@ class domMesh; #define MAX_MODEL_FACES 8 + +class LLMeshSkinInfo +{ +public: + LLUUID mMeshID; + std::vector mJointNames; + std::vector mInvBindMatrix; + std::vector mAlternateBindMatrix; + std::map mJointMap; + + LLMeshSkinInfo() { } + LLMeshSkinInfo(LLSD& data); + void fromLLSD(LLSD& data); + LLSD asLLSD(bool include_joints) const; + LLMatrix4 mBindShapeMatrix; + float mPelvisOffset; +}; + + class LLModel : public LLVolume { public: @@ -58,6 +77,9 @@ public: 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::string filename, LLModel* physics, @@ -98,8 +120,6 @@ public: LLSD& mdl, BOOL nowrite = FALSE); - static LLModel* loadModelFromAsset(std::string filename, S32 lod); - static LLModel* loadModelFromDae(std::string filename); static LLModel* loadModelFromDomMesh(domMesh* mesh); static std::string getElementLabel(daeElement* element); std::string getName() const; @@ -177,17 +197,8 @@ public: //get list of weight influences closest to given position weight_list& getJointInfluences(const LLVector3& pos); - //should always be true that mJointList[mJointMap["foo"]] == "foo" - - //map of joint names to joint index - std::map mJointMap; - - //list of joint names - std::vector mJointList; - - LLMatrix4 mBindShapeMatrix; - std::vector mInvBindMatrix; - std::vector mAlternateBindMatrix; + LLMeshSkinInfo mSkinInfo; + std::string mRequestedLabel; // name requested in UI, if any. std::string mLabel; // name computed from dae. @@ -210,7 +221,6 @@ public: protected: void addVolumeFacesFromDomMesh(domMesh* mesh); - virtual BOOL createVolumeFacesFromFile(const std::string& file_name); virtual BOOL createVolumeFacesFromDomMesh(domMesh *mesh); }; -- cgit v1.3 From 719610e68ba8275f08f51d127ab760799cb1d1c3 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 29 Mar 2011 11:50:02 -0500 Subject: SH-1225 Import convex hull data from .slm --- indra/llprimitive/llmodel.cpp | 143 +++++++++++++++-- indra/llprimitive/llmodel.h | 43 ++++- indra/llrender/llvertexbuffer.cpp | 16 ++ indra/llrender/llvertexbuffer.h | 2 + indra/newview/llfloatermodelpreview.cpp | 47 ++---- indra/newview/llfloatermodelpreview.h | 3 +- indra/newview/llfloatermodelwizard.cpp | 1 - indra/newview/llmeshrepository.cpp | 273 ++++++++++---------------------- indra/newview/llmeshrepository.h | 28 +--- indra/newview/llspatialpartition.cpp | 51 +++--- 10 files changed, 320 insertions(+), 287 deletions(-) (limited to 'indra/llprimitive') diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp index 81420fadb7..595f9aa307 100755 --- a/indra/llprimitive/llmodel.cpp +++ b/indra/llprimitive/llmodel.cpp @@ -1881,24 +1881,29 @@ LLModel::weight_list& LLModel::getJointInfluences(const LLVector3& pos) void LLModel::setConvexHullDecomposition( const LLModel::convex_hull_decomposition& decomp) { - mConvexHullDecomp = decomp; + mPhysics.mHull = decomp; + mPhysics.mMesh.clear(); + updateHullCenters(); +} - mHullCenter.resize(mConvexHullDecomp.size()); +void LLModel::updateHullCenters() +{ + mHullCenter.resize(mPhysics.mHull.size()); mHullPoints = 0; mCenterOfHullCenters.clear(); - for (U32 i = 0; i < decomp.size(); ++i) + for (U32 i = 0; i < mPhysics.mHull.size(); ++i) { LLVector3 cur_center; - for (U32 j = 0; j < decomp[i].size(); ++j) + for (U32 j = 0; j < mPhysics.mHull[i].size(); ++j) { - cur_center += decomp[i][j]; + cur_center += mPhysics.mHull[i][j]; } mCenterOfHullCenters += cur_center; - cur_center *= 1.f/decomp[i].size(); + cur_center *= 1.f/mPhysics.mHull[i].size(); mHullCenter[i] = cur_center; - mHullPoints += decomp[i].size(); + mHullPoints += mPhysics.mHull[i].size(); } mCenterOfHullCenters *= 1.f / mHullPoints; @@ -1944,12 +1949,15 @@ bool LLModel::loadModel(std::istream& is) std::ios::pos_type cur_pos = is.tellg(); loadSkinInfo(header, is); is.seekg(cur_pos); + } + + if (lod == LLModel::LOD_PHYSICS) + { + std::ios::pos_type cur_pos = is.tellg(); loadDecomposition(header, is); is.seekg(cur_pos); } - - is.seekg(header[nm[lod]]["offset"].asInteger(), std::ios_base::cur); if (unpackVolumeFaces(is, header[nm[lod]]["size"].asInteger())) @@ -2019,6 +2027,22 @@ bool LLModel::loadSkinInfo(LLSD& header, std::istream &is) bool LLModel::loadDecomposition(LLSD& header, std::istream& is) { + S32 offset = header["decomposition"]["offset"].asInteger(); + S32 size = header["decomposition"]["size"].asInteger(); + + if (offset >= 0 && size > 0) + { + is.seekg(offset, std::ios_base::cur); + + LLSD data; + + if (unzip_llsd(data, is, size)) + { + mPhysics.fromLLSD(data); + updateHullCenters(); + } + } + return true; } @@ -2133,3 +2157,104 @@ LLSD LLMeshSkinInfo::asLLSD(bool include_joints) const return ret; } +LLModel::Decomposition::Decomposition(LLSD& data) +{ + fromLLSD(data); +} + +void LLModel::Decomposition::fromLLSD(LLSD& decomp) +{ + if (decomp.has("HullList")) + { + // updated for const-correctness. gcc is picky about this type of thing - Nyx + const LLSD::Binary& hulls = decomp["HullList"].asBinary(); + const LLSD::Binary& position = decomp["Position"].asBinary(); + + U16* p = (U16*) &position[0]; + + mHull.resize(hulls.size()); + + LLVector3 min; + LLVector3 max; + LLVector3 range; + + min.setValue(decomp["Min"]); + max.setValue(decomp["Max"]); + range = max-min; + + for (U32 i = 0; i < hulls.size(); ++i) + { + U16 count = (hulls[i] == 0) ? 256 : hulls[i]; + + for (U32 j = 0; j < count; ++j) + { + mHull[i].push_back(LLVector3( + (F32) p[0]/65535.f*range.mV[0]+min.mV[0], + (F32) p[1]/65535.f*range.mV[1]+min.mV[1], + (F32) p[2]/65535.f*range.mV[2]+min.mV[2])); + p += 3; + } + + } + } + + if (decomp.has("Hull")) + { + const LLSD::Binary& position = decomp["Hull"].asBinary(); + + U16* p = (U16*) &position[0]; + + LLVector3 min; + LLVector3 max; + LLVector3 range; + + min.setValue(decomp["Min"]); + max.setValue(decomp["Max"]); + range = max-min; + + U16 count = position.size()/6; + + for (U32 j = 0; j < count; ++j) + { + mBaseHull.push_back(LLVector3( + (F32) p[0]/65535.f*range.mV[0]+min.mV[0], + (F32) p[1]/65535.f*range.mV[1]+min.mV[1], + (F32) p[2]/65535.f*range.mV[2]+min.mV[2])); + p += 3; + } + } + else + { + //empty base hull mesh to indicate decomposition has been loaded + //but contains no base hull + mBaseHullMesh.clear();; + } + +} + +void LLModel::Decomposition::merge(const LLModel::Decomposition* rhs) +{ + if (!rhs) + { + return; + } + + if (mMeshID != rhs->mMeshID) + { + llerrs << "Attempted to merge with decomposition of some other mesh." << llendl; + } + + if (mBaseHull.empty()) + { //take base hull and decomposition from rhs + mHull = rhs->mHull; + mBaseHull = rhs->mBaseHull; + mMesh = rhs->mMesh; + mBaseHullMesh = rhs->mBaseHullMesh; + } + + if (mPhysicsShapeMesh.empty()) + { //take physics shape mesh from rhs + mPhysicsShapeMesh = rhs->mPhysicsShapeMesh; + } +} + diff --git a/indra/llprimitive/llmodel.h b/indra/llprimitive/llmodel.h index 81be9d1835..e9450d2967 100755 --- a/indra/llprimitive/llmodel.h +++ b/indra/llprimitive/llmodel.h @@ -27,6 +27,7 @@ #ifndef LL_LLMODEL_H #define LL_LLMODEL_H +#include "llpointer.h" #include "llvolume.h" #include "v4math.h" #include "m4math.h" @@ -54,7 +55,6 @@ public: float mPelvisOffset; }; - class LLModel : public LLVolume { public: @@ -208,9 +208,10 @@ public: float mPelvisOffset; // convex hull decomposition S32 mDecompID; - convex_hull_decomposition mConvexHullDecomp; + void setConvexHullDecomposition( const convex_hull_decomposition& decomp); + void updateHullCenters(); LLVector3 mCenterOfHullCenters; std::vector mHullCenter; @@ -219,6 +220,44 @@ public: //ID for storing this model in a .slm file S32 mLocalID; + class PhysicsMesh + { + public: + std::vector mPositions; + std::vector mNormals; + + void clear() + { + mPositions.clear(); + mNormals.clear(); + } + + bool empty() const + { + return mPositions.empty(); + } + }; + + class Decomposition + { + public: + Decomposition() { } + Decomposition(LLSD& data); + void fromLLSD(LLSD& data); + + void merge(const Decomposition* rhs); + + LLUUID mMeshID; + LLModel::convex_hull_decomposition mHull; + LLModel::hull mBaseHull; + + std::vector mMesh; + LLModel::PhysicsMesh mBaseHullMesh; + LLModel::PhysicsMesh mPhysicsShapeMesh; + }; + + Decomposition mPhysics; + protected: void addVolumeFacesFromDomMesh(domMesh* mesh); virtual BOOL createVolumeFacesFromDomMesh(domMesh *mesh); diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 0d3f5b81bc..73efbfc999 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -236,6 +236,22 @@ void LLVertexBuffer::setupClientArrays(U32 data_mask) } } +//static +void LLVertexBuffer::drawArrays(U32 mode, const std::vector& pos, const std::vector& norm) +{ + U32 count = pos.size(); + llassert(norm.size() >= pos.size()); + + unbind(); + + setupClientArrays(MAP_VERTEX | MAP_NORMAL); + + glVertexPointer(3, GL_FLOAT, 0, pos[0].mV); + glNormalPointer(GL_FLOAT, 0, norm[0].mV); + + glDrawArrays(sGLMode[mode], 0, count); +} + void LLVertexBuffer::validateRange(U32 start, U32 end, U32 count, U32 indices_offset) const { if (start >= (U32) mRequestedNumVerts || diff --git a/indra/llrender/llvertexbuffer.h b/indra/llrender/llvertexbuffer.h index 2bbc17fb12..6c0895512e 100644 --- a/indra/llrender/llvertexbuffer.h +++ b/indra/llrender/llvertexbuffer.h @@ -97,6 +97,8 @@ public: static void initClass(bool use_vbo, bool no_vbo_mapping); static void cleanupClass(); static void setupClientArrays(U32 data_mask); + static void drawArrays(U32 mode, const std::vector& pos, const std::vector& norm); + static void clientCopy(F64 max_time = 0.005); //copy data from client to GL static void unbind(); //unbind any bound vertex buffer diff --git a/indra/newview/llfloatermodelpreview.cpp b/indra/newview/llfloatermodelpreview.cpp index d8088e2f51..541511e448 100755 --- a/indra/newview/llfloatermodelpreview.cpp +++ b/indra/newview/llfloatermodelpreview.cpp @@ -2520,8 +2520,8 @@ U32 LLModelPreview::calcResourceCost() LLModel::convex_hull_decomposition& decomp = instance.mLOD[LLModel::LOD_PHYSICS] ? - instance.mLOD[LLModel::LOD_PHYSICS]->mConvexHullDecomp : - instance.mModel->mConvexHullDecomp; + instance.mLOD[LLModel::LOD_PHYSICS]->mPhysics.mHull : + instance.mModel->mPhysics.mHull; LLSD ret = LLModel::writeModel( "", @@ -2739,8 +2739,8 @@ void LLModelPreview::saveUploadData(const std::string& filename, bool save_skinw LLModel::convex_hull_decomposition& decomp = instance.mLOD[LLModel::LOD_PHYSICS].notNull() ? - instance.mLOD[LLModel::LOD_PHYSICS]->mConvexHullDecomp : - instance.mModel->mConvexHullDecomp; + instance.mLOD[LLModel::LOD_PHYSICS]->mPhysics.mHull : + instance.mModel->mPhysics.mHull; LLModel::writeModel(str, instance.mLOD[LLModel::LOD_PHYSICS], @@ -2993,14 +2993,8 @@ void LLModelPreview::loadModelCallback(S32 lod) mScene[lod] = mModelLoader->mScene; mVertexBuffer[lod].clear(); - if (lod == LLModel::LOD_PHYSICS) - { - mPhysicsMesh.clear(); - } - setPreviewLOD(lod); - if (lod == LLModel::LOD_HIGH) { //save a copy of the highest LOD for automatic LOD manipulation if (mBaseModel.empty()) @@ -3123,11 +3117,6 @@ void LLModelPreview::genLODs(S32 which_lod, U32 decimation, bool enforce_tri_lim return; } - if (which_lod == LLModel::LOD_PHYSICS) - { //clear physics mesh map - mPhysicsMesh.clear(); - } - LLVertexBuffer::unbind(); stop_gloderror(); @@ -3676,7 +3665,7 @@ void LLModelPreview::updateStatusMessages() LLModel* model = mModel[LLModel::LOD_PHYSICS][i]; S32 cur_submeshes = model->getNumVolumeFaces(); - LLModel::convex_hull_decomposition& decomp = model->mConvexHullDecomp; + LLModel::convex_hull_decomposition& decomp = model->mPhysics.mHull; if (!decomp.empty()) { @@ -4313,12 +4302,17 @@ BOOL LLModelPreview::render() { LLMutexLock(decomp->mMutex); - std::map, std::vector > >::iterator iter = - mPhysicsMesh.find(model); - if (iter != mPhysicsMesh.end()) + LLModel::Decomposition& physics = model->mPhysics; + + if (physics.mMesh.empty()) + { //build vertex buffer for physics mesh + gMeshRepo.buildPhysicsMesh(physics); + } + + if (!physics.mMesh.empty()) { //render hull instead of mesh render_mesh = false; - for (U32 i = 0; i < iter->second.size(); ++i) + for (U32 i = 0; i < physics.mMesh.size(); ++i) { if (explode > 0.f) { @@ -4337,15 +4331,9 @@ BOOL LLModelPreview::render() hull_colors.push_back(LLColor4U(rand()%128+127, rand()%128+127, rand()%128+127, 255)); } - LLVertexBuffer* buff = iter->second[i]; - if (buff) - { - buff->setBuffer(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL); - - glColor4ubv(hull_colors[i].mV); - buff->drawArrays(LLRender::TRIANGLES, 0, buff->getNumVerts()); - } - + glColor4ubv(hull_colors[i].mV); + LLVertexBuffer::drawArrays(LLRender::TRIANGLES, physics.mMesh[i].mPositions, physics.mMesh[i].mNormals); + if (explode > 0.f) { gGL.popMatrix(); @@ -4724,7 +4712,6 @@ void LLFloaterModelPreview::DecompRequest::completed() { if (sInstance->mModelPreview) { - sInstance->mModelPreview->mPhysicsMesh[mModel] = mHullMesh; sInstance->mModelPreview->mDirty = true; LLFloaterModelPreview::sInstance->mModelPreview->refresh(); } diff --git a/indra/newview/llfloatermodelpreview.h b/indra/newview/llfloatermodelpreview.h index 68fa0fa4c1..6542ed4fbe 100644 --- a/indra/newview/llfloatermodelpreview.h +++ b/indra/newview/llfloatermodelpreview.h @@ -358,8 +358,7 @@ public: U32 mGroup; std::map, U32> mObject; U32 mMaxTriangleLimit; - std::map, std::vector > > mPhysicsMesh; - + LLMeshUploadThread::instance_list mUploadData; std::set mTextureSet; diff --git a/indra/newview/llfloatermodelwizard.cpp b/indra/newview/llfloatermodelwizard.cpp index ad6e4ebe9c..8428ddb255 100644 --- a/indra/newview/llfloatermodelwizard.cpp +++ b/indra/newview/llfloatermodelwizard.cpp @@ -485,7 +485,6 @@ void LLFloaterModelWizard::DecompRequest::completed() { if (sInstance->mModelPreview) { - sInstance->mModelPreview->mPhysicsMesh[mModel] = mHullMesh; sInstance->mModelPreview->mDirty = true; LLFloaterModelWizard::sInstance->mModelPreview->refresh(); } diff --git a/indra/newview/llmeshrepository.cpp b/indra/newview/llmeshrepository.cpp index f5fc0de0d3..752e4c8744 100755 --- a/indra/newview/llmeshrepository.cpp +++ b/indra/newview/llmeshrepository.cpp @@ -108,19 +108,13 @@ U32 get_volume_memory_size(const LLVolume* volume) return indices*2+vertices*11+sizeof(LLVolume)+sizeof(LLVolumeFace)*volume->getNumVolumeFaces(); } -LLVertexBuffer* get_vertex_buffer_from_mesh(LLCDMeshData& mesh, F32 scale = 1.f) +void get_vertex_buffer_from_mesh(LLCDMeshData& mesh, LLModel::PhysicsMesh& res, F32 scale = 1.f) { - LLVertexBuffer* buff = new LLVertexBuffer(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL, 0); - buff->allocateBuffer(mesh.mNumTriangles*3, 0, true); - - LLStrider pos; - LLStrider norm; + res.mPositions.clear(); + res.mNormals.clear(); - buff->getVertexStrider(pos); - buff->getNormalStrider(norm); - const F32* v = mesh.mVertexBase; - + if (mesh.mIndexType == LLCDMeshData::INT_16) { U16* idx = (U16*) mesh.mIndexBase; @@ -139,13 +133,13 @@ LLVertexBuffer* get_vertex_buffer_from_mesh(LLCDMeshData& mesh, F32 scale = 1.f) LLVector3 n = (v1-v0)%(v2-v0); n.normalize(); - *pos++ = v0*scale; - *pos++ = v1*scale; - *pos++ = v2*scale; + res.mPositions.push_back(v0*scale); + res.mPositions.push_back(v1*scale); + res.mPositions.push_back(v2*scale); - *norm++ = n; - *norm++ = n; - *norm++ = n; + res.mNormals.push_back(n); + res.mNormals.push_back(n); + res.mNormals.push_back(n); } } else @@ -166,17 +160,15 @@ LLVertexBuffer* get_vertex_buffer_from_mesh(LLCDMeshData& mesh, F32 scale = 1.f) LLVector3 n = (v1-v0)%(v2-v0); n.normalize(); - *(pos++) = v0*scale; - *(pos++) = v1*scale; - *(pos++) = v2*scale; + res.mPositions.push_back(v0*scale); + res.mPositions.push_back(v1*scale); + res.mPositions.push_back(v2*scale); - *(norm++) = n; - *(norm++) = n; - *(norm++) = n; + res.mNormals.push_back(n); + res.mNormals.push_back(n); + res.mNormals.push_back(n); } } - - return buff; } S32 LLMeshRepoThread::sActiveHeaderRequests = 0; @@ -1139,119 +1131,8 @@ bool LLMeshRepoThread::decompositionReceived(const LLUUID& mesh_id, U8* data, S3 } { - LLMeshDecomposition* d = new LLMeshDecomposition(); + LLModel::Decomposition* d = new LLModel::Decomposition(decomp); d->mMeshID = mesh_id; - - if (decomp.has("HullList")) - { - // updated for const-correctness. gcc is picky about this type of thing - Nyx - const LLSD::Binary& hulls = decomp["HullList"].asBinary(); - const LLSD::Binary& position = decomp["Position"].asBinary(); - - U16* p = (U16*) &position[0]; - - d->mHull.resize(hulls.size()); - - LLVector3 min; - LLVector3 max; - LLVector3 range; - - min.setValue(decomp["Min"]); - max.setValue(decomp["Max"]); - range = max-min; - - for (U32 i = 0; i < hulls.size(); ++i) - { - U16 count = (hulls[i] == 0) ? 256 : hulls[i]; - - for (U32 j = 0; j < count; ++j) - { - d->mHull[i].push_back(LLVector3( - (F32) p[0]/65535.f*range.mV[0]+min.mV[0], - (F32) p[1]/65535.f*range.mV[1]+min.mV[1], - (F32) p[2]/65535.f*range.mV[2]+min.mV[2])); - p += 3; - } - - } - - //get mesh for decomposition - for (U32 i = 0; i < d->mHull.size(); ++i) - { - LLCDHull hull; - hull.mNumVertices = d->mHull[i].size(); - hull.mVertexBase = d->mHull[i][0].mV; - hull.mVertexStrideBytes = 12; - - LLCDMeshData mesh; - LLCDResult res = LLCD_OK; - if (LLConvexDecomposition::getInstance() != NULL) - { - res = LLConvexDecomposition::getInstance()->getMeshFromHull(&hull, &mesh); - } - if (res != LLCD_OK) - { - llwarns << "could not get mesh from hull from convex decomposition lib." << llendl; - return false; - } - - - d->mMesh.push_back(get_vertex_buffer_from_mesh(mesh)); - } - } - - if (decomp.has("Hull")) - { - const LLSD::Binary& position = decomp["Hull"].asBinary(); - - U16* p = (U16*) &position[0]; - - LLVector3 min; - LLVector3 max; - LLVector3 range; - - min.setValue(decomp["Min"]); - max.setValue(decomp["Max"]); - range = max-min; - - U16 count = position.size()/6; - - for (U32 j = 0; j < count; ++j) - { - d->mBaseHull.push_back(LLVector3( - (F32) p[0]/65535.f*range.mV[0]+min.mV[0], - (F32) p[1]/65535.f*range.mV[1]+min.mV[1], - (F32) p[2]/65535.f*range.mV[2]+min.mV[2])); - p += 3; - } - - //get mesh for decomposition - LLCDHull hull; - hull.mNumVertices = d->mBaseHull.size(); - hull.mVertexBase = d->mBaseHull[0].mV; - hull.mVertexStrideBytes = 12; - - LLCDMeshData mesh; - LLCDResult res = LLCD_OK; - if (LLConvexDecomposition::getInstance() != NULL) - { - res = LLConvexDecomposition::getInstance()->getMeshFromHull(&hull, &mesh); - } - if (res != LLCD_OK) - { - llwarns << "could not get mesh from hull from convex decomposition lib." << llendl; - return false; - } - - d->mBaseHullMesh = get_vertex_buffer_from_mesh(mesh); - } - else - { - //empty vertex buffer to indicate decomposition has been fetched - //but contains no base hull - d->mBaseHullMesh = new LLVertexBuffer(0, 0); - } - mDecompositionQ.push(d); } @@ -1262,12 +1143,12 @@ bool LLMeshRepoThread::physicsShapeReceived(const LLUUID& mesh_id, U8* data, S32 { LLSD physics_shape; - LLMeshDecomposition* d = new LLMeshDecomposition(); + LLModel::Decomposition* d = new LLModel::Decomposition(); d->mMeshID = mesh_id; if (data == NULL) { //no data, no physics shape exists - d->mPhysicsShapeMesh = new LLVertexBuffer(0,0); + d->mPhysicsShapeMesh.clear(); } else { @@ -1291,33 +1172,22 @@ bool LLMeshRepoThread::physicsShapeReceived(const LLUUID& mesh_id, U8* data, S32 index_count += face.mNumIndices; } - d->mPhysicsShapeMesh = new LLVertexBuffer(LLVertexBuffer::MAP_VERTEX, 0); - - d->mPhysicsShapeMesh->allocateBuffer(vertex_count, index_count, true); + d->mPhysicsShapeMesh.clear(); - LLStrider pos; - LLStrider idx; + std::vector& pos = d->mPhysicsShapeMesh.mPositions; + std::vector& norm = d->mPhysicsShapeMesh.mNormals; - d->mPhysicsShapeMesh->getVertexStrider(pos); - d->mPhysicsShapeMesh->getIndexStrider(idx); - - S32 idx_offset = 0; for (S32 i = 0; i < volume->getNumVolumeFaces(); ++i) { const LLVolumeFace& face = volume->getVolumeFace(i); - if (idx_offset + face.mNumIndices > 65535) - { //avoid 16-bit index overflow - continue; - } - - LLVector4a::memcpyNonAliased16(pos[idx_offset].mV, face.mPositions[0].getF32ptr(), face.mNumVertices*sizeof(LLVector4a)); for (S32 i = 0; i < face.mNumIndices; ++i) { - *idx++ = face.mIndices[i] + idx_offset; - } + U16 idx = face.mIndices[i]; - idx_offset += face.mNumVertices; + pos.push_back(LLVector3(face.mPositions[idx].getF32ptr())); + norm.push_back(LLVector3(face.mNormals[idx].getF32ptr())); + } } } } @@ -2428,33 +2298,7 @@ void LLMeshRepository::notifySkinInfoReceived(LLMeshSkinInfo& info) mLoadingSkins.erase(info.mMeshID); } -void LLMeshDecomposition::merge(const LLMeshDecomposition* rhs) -{ - if (!rhs) - { - return; - } - - if (mMeshID != rhs->mMeshID) - { - llerrs << "Attempted to merge with decomposition of some other mesh." << llendl; - } - - if (mBaseHull.empty()) - { //take base hull and decomposition from rhs - mHull = rhs->mHull; - mBaseHull = rhs->mBaseHull; - mMesh = rhs->mMesh; - mBaseHullMesh = rhs->mBaseHullMesh; - } - - if (mPhysicsShapeMesh.isNull()) - { //take physics shape mesh from rhs - mPhysicsShapeMesh = rhs->mPhysicsShapeMesh; - } -} - -void LLMeshRepository::notifyDecompositionReceived(LLMeshDecomposition* decomp) +void LLMeshRepository::notifyDecompositionReceived(LLModel::Decomposition* decomp) { decomposition_map::iterator iter = mDecompositionMap.find(decomp->mMeshID); if (iter == mDecompositionMap.end()) @@ -2596,7 +2440,7 @@ void LLMeshRepository::fetchPhysicsShape(const LLUUID& mesh_id) { if (mesh_id.notNull()) { - LLMeshDecomposition* decomp = NULL; + LLModel::Decomposition* decomp = NULL; decomposition_map::iterator iter = mDecompositionMap.find(mesh_id); if (iter != mDecompositionMap.end()) { @@ -2604,7 +2448,7 @@ void LLMeshRepository::fetchPhysicsShape(const LLUUID& mesh_id) } //decomposition block hasn't been fetched yet - if (!decomp || decomp->mPhysicsShapeMesh.isNull()) + if (!decomp || decomp->mPhysicsShapeMesh.empty()) { LLMutexLock lock(mMeshMutex); //add volume to list of loading meshes @@ -2619,9 +2463,9 @@ void LLMeshRepository::fetchPhysicsShape(const LLUUID& mesh_id) } -const LLMeshDecomposition* LLMeshRepository::getDecomposition(const LLUUID& mesh_id) +LLModel::Decomposition* LLMeshRepository::getDecomposition(const LLUUID& mesh_id) { - LLMeshDecomposition* ret = NULL; + LLModel::Decomposition* ret = NULL; if (mesh_id.notNull()) { @@ -2632,7 +2476,7 @@ const LLMeshDecomposition* LLMeshRepository::getDecomposition(const LLUUID& mesh } //decomposition block hasn't been fetched yet - if (!ret || ret->mBaseHullMesh.isNull()) + if (!ret || ret->mBaseHullMesh.empty()) { LLMutexLock lock(mMeshMutex); //add volume to list of loading meshes @@ -2735,8 +2579,8 @@ void LLMeshUploadThread::sendCostRequest(LLMeshUploadData& data) LLModel::convex_hull_decomposition& decomp = data.mModel[LLModel::LOD_PHYSICS].notNull() ? - data.mModel[LLModel::LOD_PHYSICS]->mConvexHullDecomp : - data.mBaseModel->mConvexHullDecomp; + data.mModel[LLModel::LOD_PHYSICS]->mPhysics.mHull : + data.mBaseModel->mPhysics.mHull; LLModel::hull dummy_hull; @@ -2836,8 +2680,8 @@ void LLMeshUploadThread::doUploadModel(LLMeshUploadData& data) LLModel::convex_hull_decomposition& decomp = data.mModel[LLModel::LOD_PHYSICS].notNull() ? - data.mModel[LLModel::LOD_PHYSICS]->mConvexHullDecomp : - data.mBaseModel->mConvexHullDecomp; + data.mModel[LLModel::LOD_PHYSICS]->mPhysics.mHull : + data.mBaseModel->mPhysics.mHull; LLModel::writeModel( ostr, @@ -3355,7 +3199,7 @@ void LLPhysicsDecomp::doDecomposition() // if LLConvexDecomposition is a stub, num_hulls should have been set to 0 above, and we should not reach this code LLConvexDecomposition::getInstance()->getMeshFromStage(stage, i, &mesh); - mCurRequest->mHullMesh[i] = get_vertex_buffer_from_mesh(mesh); + get_vertex_buffer_from_mesh(mesh, mCurRequest->mHullMesh[i]); mMutex->lock(); mCurRequest->mHull[i] = p; @@ -3628,3 +3472,46 @@ LLSD LLImportMaterial::asLLSD() return ret; } + +void LLMeshRepository::buildPhysicsMesh(LLModel::Decomposition& decomp) +{ + decomp.mMesh.resize(decomp.mHull.size()); + + for (U32 i = 0; i < decomp.mHull.size(); ++i) + { + LLCDHull hull; + hull.mNumVertices = decomp.mHull[i].size(); + hull.mVertexBase = decomp.mHull[i][0].mV; + hull.mVertexStrideBytes = 12; + + LLCDMeshData mesh; + LLCDResult res = LLCD_OK; + if (LLConvexDecomposition::getInstance() != NULL) + { + res = LLConvexDecomposition::getInstance()->getMeshFromHull(&hull, &mesh); + } + if (res == LLCD_OK) + { + get_vertex_buffer_from_mesh(mesh, decomp.mMesh[i]); + } + } + + if (!decomp.mBaseHull.empty() && decomp.mBaseHullMesh.empty()) + { //get mesh for base hull + LLCDHull hull; + hull.mNumVertices = decomp.mBaseHull.size(); + hull.mVertexBase = decomp.mBaseHull[0].mV; + hull.mVertexStrideBytes = 12; + + LLCDMeshData mesh; + LLCDResult res = LLCD_OK; + if (LLConvexDecomposition::getInstance() != NULL) + { + res = LLConvexDecomposition::getInstance()->getMeshFromHull(&hull, &mesh); + } + if (res == LLCD_OK) + { + get_vertex_buffer_from_mesh(mesh, decomp.mBaseHullMesh); + } + } +} diff --git a/indra/newview/llmeshrepository.h b/indra/newview/llmeshrepository.h index 5960fe2949..31c2049c32 100644 --- a/indra/newview/llmeshrepository.h +++ b/indra/newview/llmeshrepository.h @@ -132,22 +132,6 @@ public: LLSD asLLSD(); }; -class LLMeshDecomposition -{ -public: - LLMeshDecomposition() { } - - void merge(const LLMeshDecomposition* rhs); - - LLUUID mMeshID; - LLModel::convex_hull_decomposition mHull; - LLModel::hull mBaseHull; - - std::vector > mMesh; - LLPointer mBaseHullMesh; - LLPointer mPhysicsShapeMesh; -}; - class LLPhysicsDecomp : public LLThread { public: @@ -166,7 +150,7 @@ public: //output state std::string mStatusMessage; - std::vector > mHullMesh; + std::vector mHullMesh; LLModel::convex_hull_decomposition mHull; //status message callback, called from decomposition thread @@ -301,7 +285,7 @@ public: std::set mPhysicsShapeRequests; //queue of completed Decomposition info requests - std::queue mDecompositionQ; + std::queue mDecompositionQ; //queue of requested headers std::queue mHeaderReqQ; @@ -465,17 +449,19 @@ public: void notifyMeshLoaded(const LLVolumeParams& mesh_params, LLVolume* volume); void notifyMeshUnavailable(const LLVolumeParams& mesh_params, S32 lod); void notifySkinInfoReceived(LLMeshSkinInfo& info); - void notifyDecompositionReceived(LLMeshDecomposition* info); + void notifyDecompositionReceived(LLModel::Decomposition* info); S32 getActualMeshLOD(const LLVolumeParams& mesh_params, S32 lod); U32 calcResourceCost(LLSD& header); U32 getResourceCost(const LLUUID& mesh_params); const LLMeshSkinInfo* getSkinInfo(const LLUUID& mesh_id); - const LLMeshDecomposition* getDecomposition(const LLUUID& mesh_id); + LLModel::Decomposition* getDecomposition(const LLUUID& mesh_id); void fetchPhysicsShape(const LLUUID& mesh_id); bool hasPhysicsShape(const LLUUID& mesh_id); void buildHull(const LLVolumeParams& params, S32 detail); + void buildPhysicsMesh(LLModel::Decomposition& decomp); + const LLSD& getMeshHeader(const LLUUID& mesh_id); void uploadModel(std::vector& data, LLVector3& scale, bool upload_textures, @@ -489,7 +475,7 @@ public: typedef std::map skin_map; skin_map mSkinMap; - typedef std::map decomposition_map; + typedef std::map decomposition_map; decomposition_map mDecompositionMap; LLMutex* mMeshMutex; diff --git a/indra/newview/llspatialpartition.cpp b/indra/newview/llspatialpartition.cpp index 5e7af6bbb3..65f7d299bc 100644 --- a/indra/newview/llspatialpartition.cpp +++ b/indra/newview/llspatialpartition.cpp @@ -2961,31 +2961,21 @@ S32 get_physics_detail(const LLVolumeParams& volume_params, const LLVector3& sca void renderMeshBaseHull(LLVOVolume* volume, U32 data_mask, LLColor4& color, LLColor4& line_color) { LLUUID mesh_id = volume->getVolume()->getParams().getSculptID(); - const LLMeshDecomposition* decomp = gMeshRepo.getDecomposition(mesh_id); + LLModel::Decomposition* decomp = gMeshRepo.getDecomposition(mesh_id); const LLVector3 center(0,0,0); const LLVector3 size(0.25f,0.25f,0.25f); if (decomp) { - LLVertexBuffer* buff = decomp->mBaseHullMesh; - - if (buff && buff->getNumVerts() > 0) + if (!decomp->mBaseHullMesh.empty()) { - buff->setBuffer(data_mask); - - /* glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - glColor4fv(line_color.mV); - buff->drawArrays(LLRender::TRIANGLES, 0, buff->getNumVerts()); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);*/ - - { - glColor4fv(color.mV); - buff->drawArrays(LLRender::TRIANGLES, 0, buff->getNumVerts()); - } + glColor4fv(color.mV); + LLVertexBuffer::drawArrays(LLRender::TRIANGLES, decomp->mBaseHullMesh.mPositions, decomp->mBaseHullMesh.mNormals); } else { + gMeshRepo.buildPhysicsMesh(*decomp); gGL.color3f(0,1,1); drawBoxOutline(center, size); } @@ -2998,19 +2988,16 @@ void renderMeshBaseHull(LLVOVolume* volume, U32 data_mask, LLColor4& color, LLCo } } -void render_hull(LLVertexBuffer* buff, U32 data_mask, const LLColor4& color, const LLColor4& line_color) +void render_hull(LLModel::PhysicsMesh& mesh, const LLColor4& color, const LLColor4& line_color) { - buff->setBuffer(data_mask); - glColor4fv(color.mV); - buff->drawArrays(LLRender::TRIANGLES, 0, buff->getNumVerts()); - + LLVertexBuffer::drawArrays(LLRender::TRIANGLES, mesh.mPositions, mesh.mNormals); LLGLEnable offset(GL_POLYGON_OFFSET_LINE); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glPolygonOffset(3.f, 3.f); glLineWidth(3.f); glColor4fv(line_color.mV); - buff->drawArrays(LLRender::TRIANGLES, 0, buff->getNumVerts()); + LLVertexBuffer::drawArrays(LLRender::TRIANGLES, mesh.mPositions, mesh.mNormals); glLineWidth(1.f); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } @@ -3075,7 +3062,7 @@ void renderPhysicsShape(LLDrawable* drawable, LLVOVolume* volume) if (type == LLPhysicsShapeBuilderUtil::PhysicsShapeSpecification::USER_MESH) { LLUUID mesh_id = volume->getVolume()->getParams().getSculptID(); - const LLMeshDecomposition* decomp = gMeshRepo.getDecomposition(mesh_id); + LLModel::Decomposition* decomp = gMeshRepo.getDecomposition(mesh_id); if (decomp) { //render a physics based mesh @@ -3084,27 +3071,33 @@ void renderPhysicsShape(LLDrawable* drawable, LLVOVolume* volume) if (!decomp->mHull.empty()) { //decomposition exists, use that - for (U32 i = 0; i < decomp->mHull.size(); ++i) + + if (decomp->mMesh.empty()) + { + gMeshRepo.buildPhysicsMesh(*decomp); + } + + for (U32 i = 0; i < decomp->mMesh.size(); ++i) { - render_hull(decomp->mMesh[i], data_mask, color, line_color); + render_hull(decomp->mMesh[i], color, line_color); } } - else if (decomp->mPhysicsShapeMesh.notNull() && decomp->mPhysicsShapeMesh->getNumVerts() > 0) + else if (!decomp->mPhysicsShapeMesh.empty()) { //decomp has physics mesh, render that mesh glColor4fv(color.mV); - pushBufferVerts(decomp->mPhysicsShapeMesh, data_mask); - + LLVertexBuffer::drawArrays(LLRender::TRIANGLES, decomp->mPhysicsShapeMesh.mPositions, decomp->mPhysicsShapeMesh.mNormals); + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glColor4fv(line_color.mV); - pushBufferVerts(decomp->mPhysicsShapeMesh, data_mask); + LLVertexBuffer::drawArrays(LLRender::TRIANGLES, decomp->mPhysicsShapeMesh.mPositions, decomp->mPhysicsShapeMesh.mNormals); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } else { //no mesh or decomposition, render base hull renderMeshBaseHull(volume, data_mask, color, line_color); - if (decomp->mPhysicsShapeMesh.isNull()) + if (decomp->mPhysicsShapeMesh.empty()) { //attempt to fetch physics shape mesh if available gMeshRepo.fetchPhysicsShape(mesh_id); -- cgit v1.3 From 73bf43b5933846e786d7e97310488fc72b06d645 Mon Sep 17 00:00:00 2001 From: "Brad Payne (Vir Linden)" Date: Wed, 30 Mar 2011 10:49:14 -0400 Subject: line ending fixes --- indra/llprimitive/llmodel.cpp | 186 ++++++++++++++++++------------------- indra/newview/llmeshrepository.cpp | 12 +-- 2 files changed, 99 insertions(+), 99 deletions(-) (limited to 'indra/llprimitive') diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp index 595f9aa307..4574100f32 100755 --- a/indra/llprimitive/llmodel.cpp +++ b/indra/llprimitive/llmodel.cpp @@ -1909,99 +1909,99 @@ void LLModel::updateHullCenters() mCenterOfHullCenters *= 1.f / mHullPoints; } -bool LLModel::loadModel(std::istream& is) -{ - mSculptLevel = -1; // default is an error occured - - LLSD header; - { - if (!LLSDSerialize::fromBinary(header, is, 1024*1024*1024)) - { - llwarns << "Mesh header parse error. Not a valid mesh asset!" << llendl; - return false; - } - } - - std::string nm[] = - { - "lowest_lod", - "low_lod", - "medium_lod", - "high_lod", - "physics_shape", - }; - - const S32 MODEL_LODS = 5; - - S32 lod = llclamp((S32) mDetail, 0, MODEL_LODS); - - if (header[nm[lod]]["offset"].asInteger() == -1 || - header[nm[lod]]["size"].asInteger() == 0 ) - { //cannot load requested LOD - return false; - } - - bool has_skin = header["skin"]["offset"].asInteger() >=0 && - header["skin"]["size"].asInteger() > 0; - - if (lod == LLModel::LOD_HIGH) - { //try to load skin info and decomp info - std::ios::pos_type cur_pos = is.tellg(); - loadSkinInfo(header, is); - is.seekg(cur_pos); - } - - if (lod == LLModel::LOD_PHYSICS) - { - std::ios::pos_type cur_pos = is.tellg(); - loadDecomposition(header, is); - is.seekg(cur_pos); - } - - is.seekg(header[nm[lod]]["offset"].asInteger(), std::ios_base::cur); - - if (unpackVolumeFaces(is, header[nm[lod]]["size"].asInteger())) - { - if (has_skin) - { - //build out mSkinWeight from face info - for (S32 i = 0; i < getNumVolumeFaces(); ++i) - { - const LLVolumeFace& face = getVolumeFace(i); - - if (face.mWeights) - { - for (S32 j = 0; j < face.mNumVertices; ++j) - { - LLVector4a& w = face.mWeights[j]; - - std::vector wght; - - for (S32 k = 0; k < 4; ++k) - { - S32 idx = (S32) w[k]; - F32 f = w[k] - idx; - if (f > 0.f) - { - wght.push_back(JointWeight(idx, f)); - } - } - - if (!wght.empty()) - { - LLVector3 pos(face.mPositions[j].getF32ptr()); - mSkinWeights[pos] = wght; - } - } - } - } - } - return true; - } - - return false; - -} +bool LLModel::loadModel(std::istream& is) +{ + mSculptLevel = -1; // default is an error occured + + LLSD header; + { + if (!LLSDSerialize::fromBinary(header, is, 1024*1024*1024)) + { + llwarns << "Mesh header parse error. Not a valid mesh asset!" << llendl; + return false; + } + } + + std::string nm[] = + { + "lowest_lod", + "low_lod", + "medium_lod", + "high_lod", + "physics_shape", + }; + + const S32 MODEL_LODS = 5; + + S32 lod = llclamp((S32) mDetail, 0, MODEL_LODS); + + if (header[nm[lod]]["offset"].asInteger() == -1 || + header[nm[lod]]["size"].asInteger() == 0 ) + { //cannot load requested LOD + return false; + } + + bool has_skin = header["skin"]["offset"].asInteger() >=0 && + header["skin"]["size"].asInteger() > 0; + + if (lod == LLModel::LOD_HIGH) + { //try to load skin info and decomp info + std::ios::pos_type cur_pos = is.tellg(); + loadSkinInfo(header, is); + is.seekg(cur_pos); + } + + if (lod == LLModel::LOD_PHYSICS) + { + std::ios::pos_type cur_pos = is.tellg(); + loadDecomposition(header, is); + is.seekg(cur_pos); + } + + is.seekg(header[nm[lod]]["offset"].asInteger(), std::ios_base::cur); + + if (unpackVolumeFaces(is, header[nm[lod]]["size"].asInteger())) + { + if (has_skin) + { + //build out mSkinWeight from face info + for (S32 i = 0; i < getNumVolumeFaces(); ++i) + { + const LLVolumeFace& face = getVolumeFace(i); + + if (face.mWeights) + { + for (S32 j = 0; j < face.mNumVertices; ++j) + { + LLVector4a& w = face.mWeights[j]; + + std::vector wght; + + for (S32 k = 0; k < 4; ++k) + { + S32 idx = (S32) w[k]; + F32 f = w[k] - idx; + if (f > 0.f) + { + wght.push_back(JointWeight(idx, f)); + } + } + + if (!wght.empty()) + { + LLVector3 pos(face.mPositions[j].getF32ptr()); + mSkinWeights[pos] = wght; + } + } + } + } + } + return true; + } + + return false; + +} bool LLModel::loadSkinInfo(LLSD& header, std::istream &is) diff --git a/indra/newview/llmeshrepository.cpp b/indra/newview/llmeshrepository.cpp index 752e4c8744..cfb0609111 100755 --- a/indra/newview/llmeshrepository.cpp +++ b/indra/newview/llmeshrepository.cpp @@ -3475,10 +3475,10 @@ LLSD LLImportMaterial::asLLSD() void LLMeshRepository::buildPhysicsMesh(LLModel::Decomposition& decomp) { - decomp.mMesh.resize(decomp.mHull.size()); - - for (U32 i = 0; i < decomp.mHull.size(); ++i) - { + decomp.mMesh.resize(decomp.mHull.size()); + + for (U32 i = 0; i < decomp.mHull.size(); ++i) + { LLCDHull hull; hull.mNumVertices = decomp.mHull[i].size(); hull.mVertexBase = decomp.mHull[i][0].mV; @@ -3492,8 +3492,8 @@ void LLMeshRepository::buildPhysicsMesh(LLModel::Decomposition& decomp) } if (res == LLCD_OK) { - get_vertex_buffer_from_mesh(mesh, decomp.mMesh[i]); - } + get_vertex_buffer_from_mesh(mesh, decomp.mMesh[i]); + } } if (!decomp.mBaseHull.empty() && decomp.mBaseHullMesh.empty()) -- cgit v1.3 From 6b9a2d24cce8efaa72c2fd60655998844394312d Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 30 Mar 2011 18:38:22 -0500 Subject: SH-477 Better mesh streaming cost estimation. --- indra/llcommon/llsdserialize.cpp | 5 - indra/llprimitive/llmodel.cpp | 360 ++++++++++++++++---------------- indra/llprimitive/llmodel.h | 103 ++++----- indra/newview/app_settings/settings.xml | 2 +- indra/newview/llfloatermodelpreview.cpp | 34 +-- indra/newview/llmeshrepository.cpp | 109 ++++++---- indra/newview/llmeshrepository.h | 7 +- indra/newview/llselectmgr.cpp | 18 +- indra/newview/llselectmgr.h | 4 +- indra/newview/llviewerobject.cpp | 2 +- indra/newview/llviewerobject.h | 2 +- indra/newview/llviewerwindow.cpp | 21 +- indra/newview/llvovolume.cpp | 6 +- indra/newview/llvovolume.h | 2 +- 14 files changed, 351 insertions(+), 324 deletions(-) (limited to 'indra/llprimitive') diff --git a/indra/llcommon/llsdserialize.cpp b/indra/llcommon/llsdserialize.cpp index f3cbfab77a..5be5ecc492 100644 --- a/indra/llcommon/llsdserialize.cpp +++ b/indra/llcommon/llsdserialize.cpp @@ -2095,11 +2095,6 @@ bool unzip_llsd(LLSD& data, std::istream& is, S32 size) S32 ret = inflateInit(&strm); - if (ret != Z_OK) - { - llerrs << "WTF?" << llendl; - } - do { strm.avail_out = CHUNK; diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp index 595f9aa307..049cf6b71f 100755 --- a/indra/llprimitive/llmodel.cpp +++ b/indra/llprimitive/llmodel.cpp @@ -1333,70 +1333,6 @@ std::string LLModel::getName() const return mLabel; } -//static -LLSD LLModel::writeModel( - std::string filename, - LLModel* physics, - LLModel* high, - LLModel* medium, - LLModel* low, - LLModel* impostor, - const convex_hull_decomposition& decomp, - BOOL upload_skin, - BOOL upload_joints, - BOOL nowrite) -{ - LLModel::hull dummy_hull; - return writeModel( - filename, - physics, - high, - medium, - low, - impostor, - decomp, - dummy_hull, - upload_skin, - upload_joints, - nowrite); -} - -//static -LLSD LLModel::writeModel( - std::string filename, - LLModel* physics, - LLModel* high, - LLModel* medium, - LLModel* low, - LLModel* impostor, - const convex_hull_decomposition& decomp, - const hull& base_hull, - BOOL upload_skin, - BOOL upload_joints, - BOOL nowrite) -{ - std::ofstream os( - filename.c_str(), - std::ofstream::out | std::ofstream::binary); - - LLSD header = writeModel( - os, - physics, - high, - medium, - low, - impostor, - decomp, - base_hull, - upload_skin, - upload_joints, - nowrite); - - os.close(); - - return header; -} - //static LLSD LLModel::writeModel( std::ostream& ostr, @@ -1405,8 +1341,7 @@ LLSD LLModel::writeModel( LLModel* medium, LLModel* low, LLModel* impostor, - const convex_hull_decomposition& decomp, - const hull& base_hull, + const LLModel::Decomposition& decomp, BOOL upload_skin, BOOL upload_joints, BOOL nowrite) @@ -1429,119 +1364,10 @@ LLSD LLModel::writeModel( mdl["skin"] = high->mSkinInfo.asLLSD(upload_joints); } - if (!decomp.empty() || !base_hull.empty()) + if (!decomp.mBaseHull.empty() || + !decomp.mHull.empty()) { - //write decomposition block - // ["decomposition"]["HullList"] -- list of 8 bit integers, each entry represents a hull with specified number of points - // ["decomposition"]["PositionDomain"]["Min"/"Max"] - // ["decomposition"]["Position"] -- list of 16-bit integers to be decoded to given domain, encoded 3D points - // ["decomposition"]["Hull"] -- list of 16-bit integers to be decoded to given domain, encoded 3D points representing a single hull approximation of given shape - - - //get minimum and maximum - LLVector3 min; - - if (decomp.empty()) - { - min = base_hull[0]; - } - else - { - min = decomp[0][0]; - } - - LLVector3 max = min; - - LLSD::Binary hulls(decomp.size()); - - U32 total = 0; - - for (U32 i = 0; i < decomp.size(); ++i) - { - U32 size = decomp[i].size(); - total += size; - hulls[i] = (U8) (size); - - for (U32 j = 0; j < decomp[i].size(); ++j) - { - update_min_max(min, max, decomp[i][j]); - } - - } - - for (U32 i = 0; i < base_hull.size(); ++i) - { - update_min_max(min, max, base_hull[i]); - } - - mdl["decomposition"]["Min"] = min.getValue(); - mdl["decomposition"]["Max"] = max.getValue(); - - if (!hulls.empty()) - { - mdl["decomposition"]["HullList"] = hulls; - } - - if (total > 0) - { - LLSD::Binary p(total*3*2); - - LLVector3 range = max-min; - - U32 vert_idx = 0; - for (U32 i = 0; i < decomp.size(); ++i) - { - for (U32 j = 0; j < decomp[i].size(); ++j) - { - for (U32 k = 0; k < 3; k++) - { - //convert to 16-bit normalized across domain - U16 val = (U16) (((decomp[i][j].mV[k]-min.mV[k])/range.mV[k])*65535); - - U8* buff = (U8*) &val; - //write to binary buffer - p[vert_idx++] = buff[0]; - p[vert_idx++] = buff[1]; - - if (vert_idx > p.size()) - { - llerrs << "WTF?" << llendl; - } - } - } - } - - mdl["decomposition"]["Position"] = p; - } - - if (!base_hull.empty()) - { - LLSD::Binary p(base_hull.size()*3*2); - - LLVector3 range = max-min; - - U32 vert_idx = 0; - for (U32 j = 0; j < base_hull.size(); ++j) - { - for (U32 k = 0; k < 3; k++) - { - //convert to 16-bit normalized across domain - U16 val = (U16) (((base_hull[j].mV[k]-min.mV[k])/range.mV[k])*65535); - - U8* buff = (U8*) &val; - //write to binary buffer - p[vert_idx++] = buff[0]; - p[vert_idx++] = buff[1]; - - if (vert_idx > p.size()) - { - llerrs << "WTF?" << llendl; - } - } - } - - mdl["decomposition"]["Hull"] = p; - } + mdl["decomposition"] = decomp.asLLSD(); } for (U32 idx = 0; idx < MODEL_NAMES_LENGTH; ++idx) @@ -1906,7 +1732,11 @@ void LLModel::updateHullCenters() mHullPoints += mPhysics.mHull[i].size(); } - mCenterOfHullCenters *= 1.f / mHullPoints; + if (mHullPoints > 0) + { + mCenterOfHullCenters *= 1.f / mHullPoints; + llassert(mPhysics.asLLSD().has("HullList")); + } } bool LLModel::loadModel(std::istream& is) @@ -2182,19 +2012,33 @@ void LLModel::Decomposition::fromLLSD(LLSD& decomp) max.setValue(decomp["Max"]); range = max-min; + for (U32 i = 0; i < hulls.size(); ++i) { U16 count = (hulls[i] == 0) ? 256 : hulls[i]; + std::set valid; + + //must have at least 4 points + llassert(count > 3); + for (U32 j = 0; j < count; ++j) { + U64 test = (U64) p[0] | ((U64) p[1] << 16) | ((U64) p[2] << 32); + //point must be unique + //llassert(valid.find(test) == valid.end()); + valid.insert(test); mHull[i].push_back(LLVector3( (F32) p[0]/65535.f*range.mV[0]+min.mV[0], (F32) p[1]/65535.f*range.mV[1]+min.mV[1], (F32) p[2]/65535.f*range.mV[2]+min.mV[2])); p += 3; - } + + } + + //each hull must contain at least 4 unique points + llassert(valid.size() > 3); } } @@ -2208,8 +2052,17 @@ void LLModel::Decomposition::fromLLSD(LLSD& decomp) LLVector3 max; LLVector3 range; - min.setValue(decomp["Min"]); - max.setValue(decomp["Max"]); + if (decomp.has("Min")) + { + min.setValue(decomp["Min"]); + max.setValue(decomp["Max"]); + } + else + { + min.set(-0.5f, -0.5f, -0.5f); + max.set(0.5f, 0.5f, 0.5f); + } + range = max-min; U16 count = position.size()/6; @@ -2229,7 +2082,145 @@ void LLModel::Decomposition::fromLLSD(LLSD& decomp) //but contains no base hull mBaseHullMesh.clear();; } +} + +LLSD LLModel::Decomposition::asLLSD() const +{ + LLSD ret; + + if (mBaseHull.empty() && mHull.empty()) + { //nothing to write + return ret; + } + + //write decomposition block + // ["decomposition"]["HullList"] -- list of 8 bit integers, each entry represents a hull with specified number of points + // ["decomposition"]["PositionDomain"]["Min"/"Max"] + // ["decomposition"]["Position"] -- list of 16-bit integers to be decoded to given domain, encoded 3D points + // ["decomposition"]["Hull"] -- list of 16-bit integers to be decoded to given domain, encoded 3D points representing a single hull approximation of given shape + + + //get minimum and maximum + LLVector3 min; + + if (mHull.empty()) + { + min = mBaseHull[0]; + } + else + { + min = mHull[0][0]; + } + + LLVector3 max = min; + + LLSD::Binary hulls(mHull.size()); + + U32 total = 0; + + for (U32 i = 0; i < mHull.size(); ++i) + { + U32 size = mHull[i].size(); + total += size; + hulls[i] = (U8) (size); + + for (U32 j = 0; j < mHull[i].size(); ++j) + { + update_min_max(min, max, mHull[i][j]); + } + } + + for (U32 i = 0; i < mBaseHull.size(); ++i) + { + update_min_max(min, max, mBaseHull[i]); + } + ret["Min"] = min.getValue(); + ret["Max"] = max.getValue(); + + if (!hulls.empty()) + { + ret["HullList"] = hulls; + } + + if (total > 0) + { + LLSD::Binary p(total*3*2); + + LLVector3 range = max-min; + + U32 vert_idx = 0; + + for (U32 i = 0; i < mHull.size(); ++i) + { + std::set valid; + + llassert(!mHull[i].empty()); + + for (U32 j = 0; j < mHull[i].size(); ++j) + { + U64 test = 0; + for (U32 k = 0; k < 3; k++) + { + //convert to 16-bit normalized across domain + U16 val = (U16) (((mHull[i][j].mV[k]-min.mV[k])/range.mV[k])*65535); + + switch (k) + { + case 0: test = test | (U64) val; break; + case 1: test = test | ((U64) val << 16); break; + case 2: test = test | ((U64) val << 32); break; + }; + + valid.insert(test); + + U8* buff = (U8*) &val; + //write to binary buffer + p[vert_idx++] = buff[0]; + p[vert_idx++] = buff[1]; + + //makes sure we haven't run off the end of the array + llassert(vert_idx <= p.size()); + } + } + + //must have at least 4 unique points + llassert(valid.size() > 3); + } + + ret["Position"] = p; + } + + if (!mBaseHull.empty()) + { + LLSD::Binary p(mBaseHull.size()*3*2); + + LLVector3 range = max-min; + + U32 vert_idx = 0; + for (U32 j = 0; j < mBaseHull.size(); ++j) + { + for (U32 k = 0; k < 3; k++) + { + //convert to 16-bit normalized across domain + U16 val = (U16) (((mBaseHull[j].mV[k]-min.mV[k])/range.mV[k])*65535); + + U8* buff = (U8*) &val; + //write to binary buffer + p[vert_idx++] = buff[0]; + p[vert_idx++] = buff[1]; + + if (vert_idx > p.size()) + { + llerrs << "WTF?" << llendl; + } + } + } + + ret["Hull"] = p; + } + + return ret; } void LLModel::Decomposition::merge(const LLModel::Decomposition* rhs) @@ -2256,5 +2247,10 @@ void LLModel::Decomposition::merge(const LLModel::Decomposition* rhs) { //take physics shape mesh from rhs mPhysicsShapeMesh = rhs->mPhysicsShapeMesh; } + + if (!mHull.empty()) + { //verify + llassert(asLLSD().has("HullList")); + } } diff --git a/indra/llprimitive/llmodel.h b/indra/llprimitive/llmodel.h index e9450d2967..962e422a26 100755 --- a/indra/llprimitive/llmodel.h +++ b/indra/llprimitive/llmodel.h @@ -71,38 +71,53 @@ public: //convex_hull_decomposition is a vector of convex hulls //each convex hull is a set of points - typedef std::vector > convex_hull_decomposition; + typedef std::vector > convex_hull_decomposition; typedef std::vector hull; + class PhysicsMesh + { + public: + std::vector mPositions; + std::vector 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; + + void merge(const Decomposition* rhs); + + LLUUID mMeshID; + LLModel::convex_hull_decomposition mHull; + LLModel::hull mBaseHull; + + std::vector 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::string filename, - LLModel* physics, - LLModel* high, - LLModel* medium, - LLModel* low, - LLModel* imposotr, - const LLModel::convex_hull_decomposition& convex_hull_decomposition, - const LLModel::hull& base_hull, - BOOL upload_skin, - BOOL upload_joints, - BOOL nowrite = FALSE); - static LLSD writeModel( - std::string filename, - LLModel* physics, - LLModel* high, - LLModel* medium, - LLModel* low, - LLModel* imposotr, - const LLModel::convex_hull_decomposition& convex_hull_decomposition, - BOOL upload_skin, - BOOL upload_joints, - BOOL nowrite = FALSE); + static LLSD writeModel( std::ostream& ostr, LLModel* physics, @@ -110,11 +125,11 @@ public: LLModel* medium, LLModel* low, LLModel* imposotr, - const LLModel::convex_hull_decomposition& convex_hull_decomposition, - const LLModel::hull& base_hull, + const LLModel::Decomposition& decomp, BOOL upload_skin, BOOL upload_joints, BOOL nowrite = FALSE); + static LLSD writeModelToStream( std::ostream& ostr, LLSD& mdl, @@ -220,42 +235,6 @@ public: //ID for storing this model in a .slm file S32 mLocalID; - class PhysicsMesh - { - public: - std::vector mPositions; - std::vector mNormals; - - void clear() - { - mPositions.clear(); - mNormals.clear(); - } - - bool empty() const - { - return mPositions.empty(); - } - }; - - class Decomposition - { - public: - Decomposition() { } - Decomposition(LLSD& data); - void fromLLSD(LLSD& data); - - void merge(const Decomposition* rhs); - - LLUUID mMeshID; - LLModel::convex_hull_decomposition mHull; - LLModel::hull mBaseHull; - - std::vector mMesh; - LLModel::PhysicsMesh mBaseHullMesh; - LLModel::PhysicsMesh mPhysicsShapeMesh; - }; - Decomposition mPhysics; protected: diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index c11de57c42..4c042435f2 100755 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -8974,7 +8974,7 @@ Type F32 Value - 2.0 + 3.0 MeshThreadCount diff --git a/indra/newview/llfloatermodelpreview.cpp b/indra/newview/llfloatermodelpreview.cpp index 541511e448..243f301e9d 100755 --- a/indra/newview/llfloatermodelpreview.cpp +++ b/indra/newview/llfloatermodelpreview.cpp @@ -1093,7 +1093,7 @@ LLModelLoader::LLModelLoader(std::string filename, S32 lod, LLModelPreview* prev { //only try to load from slm if viewer is configured to do so and this is the //initial model load (not an LoD or physics shape) - mTrySLM = gSavedSettings.getBOOL("MeshImportUseSLM") && mPreview->mBaseModel.empty(); + mTrySLM = gSavedSettings.getBOOL("MeshImportUseSLM") && mPreview->mUploadData.empty(); mPreview->setLoadState(STARTING); } else @@ -1889,6 +1889,14 @@ void LLModelLoader::loadModelCallback() { //wait until this thread is stopped before deleting self apr_sleep(100); } + + //cleanup model loader + if (mPreview) + { + mPreview->mModelLoader = NULL; + } + + delete this; } void LLModelLoader::handlePivotPoint( daeElement* pRoot ) @@ -2518,13 +2526,13 @@ U32 LLModelPreview::calcResourceCost() { accounted.insert(instance.mModel); - LLModel::convex_hull_decomposition& decomp = + LLModel::Decomposition& decomp = instance.mLOD[LLModel::LOD_PHYSICS] ? - instance.mLOD[LLModel::LOD_PHYSICS]->mPhysics.mHull : - instance.mModel->mPhysics.mHull; + instance.mLOD[LLModel::LOD_PHYSICS]->mPhysics : + instance.mModel->mPhysics; - LLSD ret = LLModel::writeModel( - "", + std::stringstream ostr; + LLSD ret = LLModel::writeModel(ostr, instance.mLOD[4], instance.mLOD[3], instance.mLOD[2], @@ -2536,10 +2544,10 @@ U32 LLModelPreview::calcResourceCost() TRUE); cost += gMeshRepo.calcResourceCost(ret); - num_hulls += decomp.size(); - for (U32 i = 0; i < decomp.size(); ++i) + num_hulls += decomp.mHull.size(); + for (U32 i = 0; i < decomp.mHull.size(); ++i) { - num_points += decomp[i].size(); + num_points += decomp.mHull[i].size(); } //calculate streaming cost @@ -2737,10 +2745,10 @@ void LLModelPreview::saveUploadData(const std::string& filename, bool save_skinw std::stringstream str; - LLModel::convex_hull_decomposition& decomp = + LLModel::Decomposition& decomp = instance.mLOD[LLModel::LOD_PHYSICS].notNull() ? - instance.mLOD[LLModel::LOD_PHYSICS]->mPhysics.mHull : - instance.mModel->mPhysics.mHull; + instance.mLOD[LLModel::LOD_PHYSICS]->mPhysics : + instance.mModel->mPhysics; LLModel::writeModel(str, instance.mLOD[LLModel::LOD_PHYSICS], @@ -2749,7 +2757,7 @@ void LLModelPreview::saveUploadData(const std::string& filename, bool save_skinw instance.mLOD[LLModel::LOD_LOW], instance.mLOD[LLModel::LOD_IMPOSTOR], decomp, - empty_hull, save_skinweights, save_joint_positions); + save_skinweights, save_joint_positions); data["mesh"][instance.mModel->mLocalID] = str.str(); diff --git a/indra/newview/llmeshrepository.cpp b/indra/newview/llmeshrepository.cpp index 752e4c8744..78943ef1b6 100755 --- a/indra/newview/llmeshrepository.cpp +++ b/indra/newview/llmeshrepository.cpp @@ -1535,8 +1535,6 @@ void LLMeshRepoThread::notifyLoadedMeshes() S32 LLMeshRepoThread::getActualMeshLOD(const LLVolumeParams& mesh_params, S32 lod) { //only ever called from main thread - lod = llclamp(lod, 0, 3); - LLMutexLock lock(mHeaderMutex); mesh_header_map::iterator iter = mMeshHeader.find(mesh_params.getSculptID()); @@ -1544,40 +1542,48 @@ S32 LLMeshRepoThread::getActualMeshLOD(const LLVolumeParams& mesh_params, S32 lo { LLSD& header = iter->second; - if (header.has("404")) - { - return -1; - } + return LLMeshRepository::getActualMeshLOD(header, lod); + } - if (header[header_lod[lod]]["size"].asInteger() > 0) - { - return lod; - } + return lod; +} + +//static +S32 LLMeshRepository::getActualMeshLOD(LLSD& header, S32 lod) +{ + lod = llclamp(lod, 0, 3); + + if (header.has("404")) + { + return -1; + } - //search down to find the next available lower lod - for (S32 i = lod-1; i >= 0; --i) + if (header[header_lod[lod]]["size"].asInteger() > 0) + { + return lod; + } + + //search down to find the next available lower lod + for (S32 i = lod-1; i >= 0; --i) + { + if (header[header_lod[i]]["size"].asInteger() > 0) { - if (header[header_lod[i]]["size"].asInteger() > 0) - { - return i; - } + return i; } + } - //search up to find then ext available higher lod - for (S32 i = lod+1; i < 4; ++i) + //search up to find then ext available higher lod + for (S32 i = lod+1; i < 4; ++i) + { + if (header[header_lod[i]]["size"].asInteger() > 0) { - if (header[header_lod[i]]["size"].asInteger() > 0) - { - return i; - } + return i; } - - //header exists and no good lod found, treat as 404 - header["404"] = 1; - return -1; } - return lod; + //header exists and no good lod found, treat as 404 + header["404"] = 1; + return -1; } U32 LLMeshRepoThread::getResourceCost(const LLUUID& mesh_id) @@ -2514,12 +2520,12 @@ bool LLMeshRepository::hasPhysicsShape(const LLUUID& mesh_id) return mesh.has("physics_shape") && mesh["physics_shape"].has("size") && (mesh["physics_shape"]["size"].asInteger() > 0); } -const LLSD& LLMeshRepository::getMeshHeader(const LLUUID& mesh_id) +LLSD& LLMeshRepository::getMeshHeader(const LLUUID& mesh_id) { return mThread->getMeshHeader(mesh_id); } -const LLSD& LLMeshRepoThread::getMeshHeader(const LLUUID& mesh_id) +LLSD& LLMeshRepoThread::getMeshHeader(const LLUUID& mesh_id) { static LLSD dummy_ret; if (mesh_id.notNull()) @@ -2577,12 +2583,10 @@ void LLMeshUploadThread::sendCostRequest(LLMeshUploadData& data) //write model file to memory buffer std::stringstream ostr; - LLModel::convex_hull_decomposition& decomp = + LLModel::Decomposition& decomp = data.mModel[LLModel::LOD_PHYSICS].notNull() ? - data.mModel[LLModel::LOD_PHYSICS]->mPhysics.mHull : - data.mBaseModel->mPhysics.mHull; - - LLModel::hull dummy_hull; + data.mModel[LLModel::LOD_PHYSICS]->mPhysics : + data.mBaseModel->mPhysics; LLSD header = LLModel::writeModel( ostr, @@ -2592,7 +2596,6 @@ void LLMeshUploadThread::sendCostRequest(LLMeshUploadData& data) data.mModel[LLModel::LOD_LOW], data.mModel[LLModel::LOD_IMPOSTOR], decomp, - dummy_hull, mUploadSkin, mUploadJoints, true); @@ -2678,10 +2681,12 @@ void LLMeshUploadThread::doUploadModel(LLMeshUploadData& data) { std::stringstream ostr; - LLModel::convex_hull_decomposition& decomp = + LLModel::Decomposition& decomp = data.mModel[LLModel::LOD_PHYSICS].notNull() ? - data.mModel[LLModel::LOD_PHYSICS]->mPhysics.mHull : - data.mBaseModel->mPhysics.mHull; + data.mModel[LLModel::LOD_PHYSICS]->mPhysics : + data.mBaseModel->mPhysics; + + decomp.mBaseHull = mHullMap[data.mBaseModel]; LLModel::writeModel( ostr, @@ -2691,7 +2696,6 @@ void LLMeshUploadThread::doUploadModel(LLMeshUploadData& data) data.mModel[LLModel::LOD_LOW], data.mModel[LLModel::LOD_IMPOSTOR], decomp, - mHullMap[data.mBaseModel], mUploadSkin, mUploadJoints); @@ -2939,17 +2943,36 @@ void LLMeshRepository::uploadError(LLSD& args) } //static -F32 LLMeshRepository::getStreamingCost(const LLSD& header, F32 radius) +F32 LLMeshRepository::getStreamingCost(LLSD& header, F32 radius, S32* bytes, S32* bytes_visible, S32 lod) { - F32 dlowest = llmin(radius/0.06f, 256.f); - F32 dlow = llmin(radius/0.24f, 256.f); - F32 dmid = llmin(radius/1.0f, 256.f); + F32 dlowest = llmin(radius/0.03f, 256.f); + F32 dlow = llmin(radius/0.06f, 256.f); + F32 dmid = llmin(radius/0.24f, 256.f); F32 bytes_lowest = header["lowest_lod"]["size"].asReal()/1024.f; F32 bytes_low = header["low_lod"]["size"].asReal()/1024.f; F32 bytes_mid = header["medium_lod"]["size"].asReal()/1024.f; F32 bytes_high = header["high_lod"]["size"].asReal()/1024.f; + if (bytes) + { + *bytes = 0; + *bytes += header["lowest_lod"]["size"].asInteger(); + *bytes += header["low_lod"]["size"].asInteger(); + *bytes += header["medium_lod"]["size"].asInteger(); + *bytes += header["high_lod"]["size"].asInteger(); + } + + + if (bytes_visible) + { + lod = LLMeshRepository::getActualMeshLOD(header, lod); + if (lod >= 0 && lod <= 3) + { + *bytes_visible = header[header_lod[lod]]["size"].asInteger(); + } + } + if (bytes_high == 0.f) { return 0.f; diff --git a/indra/newview/llmeshrepository.h b/indra/newview/llmeshrepository.h index 31c2049c32..5983a282a2 100644 --- a/indra/newview/llmeshrepository.h +++ b/indra/newview/llmeshrepository.h @@ -318,7 +318,7 @@ public: bool skinInfoReceived(const LLUUID& mesh_id, U8* data, S32 data_size); bool decompositionReceived(const LLUUID& mesh_id, U8* data, S32 data_size); bool physicsShapeReceived(const LLUUID& mesh_id, U8* data, S32 data_size); - const LLSD& getMeshHeader(const LLUUID& mesh_id); + LLSD& getMeshHeader(const LLUUID& mesh_id); void notifyLoadedMeshes(); S32 getActualMeshLOD(const LLVolumeParams& mesh_params, S32 lod); @@ -434,7 +434,7 @@ public: static U32 sCacheBytesWritten; static U32 sPeakKbps; - static F32 getStreamingCost(const LLSD& header, F32 radius); + static F32 getStreamingCost(LLSD& header, F32 radius, S32* bytes = NULL, S32* visible_bytes = NULL, S32 detail = -1); LLMeshRepository(); @@ -452,6 +452,7 @@ public: void notifyDecompositionReceived(LLModel::Decomposition* info); S32 getActualMeshLOD(const LLVolumeParams& mesh_params, S32 lod); + static S32 getActualMeshLOD(LLSD& header, S32 lod); U32 calcResourceCost(LLSD& header); U32 getResourceCost(const LLUUID& mesh_params); const LLMeshSkinInfo* getSkinInfo(const LLUUID& mesh_id); @@ -462,7 +463,7 @@ public: void buildHull(const LLVolumeParams& params, S32 detail); void buildPhysicsMesh(LLModel::Decomposition& decomp); - const LLSD& getMeshHeader(const LLUUID& mesh_id); + LLSD& getMeshHeader(const LLUUID& mesh_id); void uploadModel(std::vector& data, LLVector3& scale, bool upload_textures, bool upload_skin, bool upload_joints); diff --git a/indra/newview/llselectmgr.cpp b/indra/newview/llselectmgr.cpp index b139ba361e..78ffc7908d 100644 --- a/indra/newview/llselectmgr.cpp +++ b/indra/newview/llselectmgr.cpp @@ -6374,7 +6374,7 @@ BOOL LLObjectSelection::isEmpty() const //----------------------------------------------------------------------------- // getObjectCount() - returns number of non null objects //----------------------------------------------------------------------------- -S32 LLObjectSelection::getObjectCount(BOOL mesh_adjust) +S32 LLObjectSelection::getObjectCount() { cleanupNodes(); S32 count = mList.size(); @@ -6478,7 +6478,7 @@ F32 LLObjectSelection::getSelectedLinksetPhysicsCost() return cost; } -F32 LLObjectSelection::getSelectedObjectStreamingCost() +F32 LLObjectSelection::getSelectedObjectStreamingCost(S32* total_bytes, S32* visible_bytes) { F32 cost = 0.f; for (list_t::iterator iter = mList.begin(); iter != mList.end(); ++iter) @@ -6488,7 +6488,19 @@ F32 LLObjectSelection::getSelectedObjectStreamingCost() if (object) { - cost += object->getStreamingCost(); + S32 bytes = 0; + S32 visible = 0; + cost += object->getStreamingCost(&bytes, &visible); + + if (total_bytes) + { + *total_bytes += bytes; + } + + if (visible_bytes) + { + *visible_bytes += visible; + } } } diff --git a/indra/newview/llselectmgr.h b/indra/newview/llselectmgr.h index 031898d7c5..166616e13e 100644 --- a/indra/newview/llselectmgr.h +++ b/indra/newview/llselectmgr.h @@ -278,14 +278,14 @@ public: LLSelectNode* findNode(LLViewerObject* objectp); // count members - S32 getObjectCount(BOOL mesh_adjust = FALSE); + S32 getObjectCount(); F32 getSelectedObjectCost(); F32 getSelectedLinksetCost(); F32 getSelectedPhysicsCost(); F32 getSelectedLinksetPhysicsCost(); S32 getSelectedObjectRenderCost(); - F32 getSelectedObjectStreamingCost(); + F32 getSelectedObjectStreamingCost(S32* total_bytes = NULL, S32* visible_bytes = NULL); U32 getSelectedObjectTriangleCount(); S32 getTECount(); diff --git a/indra/newview/llviewerobject.cpp b/indra/newview/llviewerobject.cpp index bcdc774c5e..70b1809033 100644 --- a/indra/newview/llviewerobject.cpp +++ b/indra/newview/llviewerobject.cpp @@ -3134,7 +3134,7 @@ F32 LLViewerObject::getLinksetPhysicsCost() return mLinksetPhysicsCost; } -F32 LLViewerObject::getStreamingCost() +F32 LLViewerObject::getStreamingCost(S32* bytes, S32* visible_bytes) { return 0.f; } diff --git a/indra/newview/llviewerobject.h b/indra/newview/llviewerobject.h index 2b2b7bd59d..44f46b8c0f 100644 --- a/indra/newview/llviewerobject.h +++ b/indra/newview/llviewerobject.h @@ -326,7 +326,7 @@ public: virtual void setScale(const LLVector3 &scale, BOOL damped = FALSE); - virtual F32 getStreamingCost(); + virtual F32 getStreamingCost(S32* bytes = NULL, S32* visible_bytes = NULL); virtual U32 getTriangleCount(); void setObjectCost(F32 cost); diff --git a/indra/newview/llviewerwindow.cpp b/indra/newview/llviewerwindow.cpp index 39ef56d156..141ade8079 100644 --- a/indra/newview/llviewerwindow.cpp +++ b/indra/newview/llviewerwindow.cpp @@ -493,6 +493,10 @@ public: { F32 cost = 0.f; S32 count = 0; + S32 object_count = 0; + S32 total_bytes = 0; + S32 visible_bytes = 0; + const char* label = "Region"; if (LLSelectMgr::getInstance()->getSelection()->getObjectCount() == 0) { //region @@ -506,8 +510,13 @@ public: object->getRegion() == region && object->getVolume()) { - cost += object->getStreamingCost(); + object_count++; + S32 bytes = 0; + S32 visible = 0; + cost += object->getStreamingCost(&bytes, &visible); count += object->getTriangleCount(); + total_bytes += bytes; + visible_bytes += visible; } } } @@ -515,12 +524,16 @@ public: else { label = "Selection"; - cost = LLSelectMgr::getInstance()->getSelection()->getSelectedObjectStreamingCost(); + cost = LLSelectMgr::getInstance()->getSelection()->getSelectedObjectStreamingCost(&total_bytes, &visible_bytes); count = LLSelectMgr::getInstance()->getSelection()->getSelectedObjectTriangleCount(); + object_count = LLSelectMgr::getInstance()->getSelection()->getObjectCount(); } - addText(xpos,ypos, llformat("%s streaming cost: %.1f (%.1f KTris)", - label, cost, count/1000.f)); + addText(xpos,ypos, llformat("%s streaming cost: %.1f", label, cost)); + ypos += y_inc; + + addText(xpos, ypos, llformat(" %.1f KTris, %.1f/%.1f KB, %d objects", + count/1024.f, visible_bytes/1024.f, total_bytes/1024.f, object_count)); ypos += y_inc; } diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp index 98e5e4c6de..7c4a4c13ba 100644 --- a/indra/newview/llvovolume.cpp +++ b/indra/newview/llvovolume.cpp @@ -3082,15 +3082,15 @@ U32 LLVOVolume::getRenderCost(std::set &textures) const } -F32 LLVOVolume::getStreamingCost() +F32 LLVOVolume::getStreamingCost(S32* bytes, S32* visible_bytes) { if (isMesh()) { - const LLSD& header = gMeshRepo.getMeshHeader(getVolume()->getParams().getSculptID()); + LLSD& header = gMeshRepo.getMeshHeader(getVolume()->getParams().getSculptID()); F32 radius = getScale().length(); - return LLMeshRepository::getStreamingCost(header, radius); + return LLMeshRepository::getStreamingCost(header, radius, bytes, visible_bytes, mLOD); } return 0.f; diff --git a/indra/newview/llvovolume.h b/indra/newview/llvovolume.h index b09243055c..029811886d 100644 --- a/indra/newview/llvovolume.h +++ b/indra/newview/llvovolume.h @@ -130,7 +130,7 @@ public: const LLMatrix3& getRelativeXformInvTrans() const { return mRelativeXformInvTrans; } /*virtual*/ const LLMatrix4 getRenderMatrix() const; U32 getRenderCost(std::set &textures) const; - /*virtual*/ F32 getStreamingCost(); + /*virtual*/ F32 getStreamingCost(S32* bytes = NULL, S32* visible_bytes = NULL); /*virtual*/ U32 getTriangleCount(); /*virtual*/ BOOL lineSegmentIntersect(const LLVector3& start, const LLVector3& end, S32 face = -1, // which face to check, -1 = ALL_SIDES -- cgit v1.3 From f0c70a4ee3739c34b1da2ce384bfcf420f8c6c72 Mon Sep 17 00:00:00 2001 From: Xiaohong Bao Date: Fri, 1 Apr 2011 10:58:34 -0600 Subject: fix for SH-1176: A Mesh That Crashes Client on Upload Attempt (due to triangle number overflowing) --- indra/llprimitive/llmodel.cpp | 71 ++++++++++++++++++---- indra/llprimitive/llmodel.h | 10 +++ indra/newview/llfloatermodelpreview.cpp | 27 ++++++-- indra/newview/llfloatermodelpreview.h | 2 +- .../skins/default/xui/en/floater_model_preview.xml | 1 + .../skins/default/xui/en/floater_model_wizard.xml | 1 + 6 files changed, 95 insertions(+), 17 deletions(-) (limited to 'indra/llprimitive') diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp index 0a4ed6b638..03b893de29 100755 --- a/indra/llprimitive/llmodel.cpp +++ b/indra/llprimitive/llmodel.cpp @@ -57,7 +57,7 @@ const int MODEL_NAMES_LENGTH = sizeof(model_names) / sizeof(std::string); LLModel::LLModel(LLVolumeParams& params, F32 detail) : LLVolume(params, detail), mNormalizedScale(1,1,1), mNormalizedTranslation(0,0,0) - , mPelvisOffset( 0.0f ) + , mPelvisOffset( 0.0f ), mStatus(NO_ERRORS) { mDecompID = -1; mLocalID = -1; @@ -209,7 +209,7 @@ void get_dom_sources(const domInputLocalOffset_Array& inputs, S32& pos_offset, S idx_stride += 1; } -void load_face_from_dom_triangles(std::vector& face_list, std::vector& materials, domTrianglesRef& tri) +LLModel::EModelStatus load_face_from_dom_triangles(std::vector& face_list, std::vector& materials, domTrianglesRef& tri) { LLVolumeFace face; std::vector verts; @@ -304,7 +304,8 @@ void load_face_from_dom_triangles(std::vector& face_list, std::vec verts.push_back(cv); if (verts.size() >= 65535) { - llerrs << "Attempted to write model exceeding 16-bit index buffer limitation." << llendl; + //llerrs << "Attempted to write model exceeding 16-bit index buffer limitation." << llendl; + return LLModel::VERTEX_NUMBER_OVERFLOW ; } U16 index = (U16) (verts.size()-1); indices.push_back(index); @@ -349,16 +350,17 @@ void load_face_from_dom_triangles(std::vector& face_list, std::vec face_list.rbegin()->fillFromLegacyData(verts, indices); } + return LLModel::NO_ERRORS ; } -void load_face_from_dom_polylist(std::vector& face_list, std::vector& materials, domPolylistRef& poly) +LLModel::EModelStatus load_face_from_dom_polylist(std::vector& face_list, std::vector& materials, domPolylistRef& poly) { domPRef p = poly->getP(); domListOfUInts& idx = p->getValue(); if (idx.getCount() == 0) { - return; + return LLModel::NO_ERRORS ; } const domInputLocalOffset_Array& inputs = poly->getInput_array(); @@ -479,7 +481,8 @@ void load_face_from_dom_polylist(std::vector& face_list, std::vect verts.push_back(cv); if (verts.size() >= 65535) { - llerrs << "Attempted to write model exceeding 16-bit index buffer limitation." << llendl; + //llerrs << "Attempted to write model exceeding 16-bit index buffer limitation." << llendl; + return LLModel::VERTEX_NUMBER_OVERFLOW ; } U16 index = (U16) (verts.size()-1); @@ -539,9 +542,11 @@ void load_face_from_dom_polylist(std::vector& face_list, std::vect face_list.push_back(face); face_list.rbegin()->fillFromLegacyData(verts, indices); } + + return LLModel::NO_ERRORS ; } -void load_face_from_dom_polygons(std::vector& face_list, std::vector& materials, domPolygonsRef& poly) +LLModel::EModelStatus load_face_from_dom_polygons(std::vector& face_list, std::vector& materials, domPolygonsRef& poly) { LLVolumeFace face; std::vector indices; @@ -654,7 +659,7 @@ void load_face_from_dom_polygons(std::vector& face_list, std::vect if (verts.empty()) { - return; + return LLModel::NO_ERRORS; } face.mExtents[0] = verts[0].getPosition(); @@ -716,6 +721,27 @@ void load_face_from_dom_polygons(std::vector& face_list, std::vect face_list.push_back(face); face_list.rbegin()->fillFromLegacyData(new_verts, indices); } + + return LLModel::NO_ERRORS ; +} + +//static +std::string LLModel::getStatusString(U32 status) +{ + const static std::string status_strings[(S32)INVALID_STATUS] = {"status_no_error", "status_vertex_number_overflow"}; + + if(status < INVALID_STATUS) + { + if(status_strings[status] == std::string()) + { + llerrs << "No valid status string for this status: " << (U32)status << llendl ; + } + return status_strings[status] ; + } + + llerrs << "Invalid model status: " << (U32)status << llendl ; + + return std::string() ; } void LLModel::addVolumeFacesFromDomMesh(domMesh* mesh) @@ -726,7 +752,14 @@ void LLModel::addVolumeFacesFromDomMesh(domMesh* mesh) { domTrianglesRef& tri = tris.get(i); - load_face_from_dom_triangles(mVolumeFaces, mMaterialList, tri); + mStatus = load_face_from_dom_triangles(mVolumeFaces, mMaterialList, tri); + + if(mStatus != NO_ERRORS) + { + mVolumeFaces.clear() ; + mMaterialList.clear() ; + return ; //abort + } } domPolylist_Array& polys = mesh->getPolylist_array(); @@ -734,7 +767,14 @@ void LLModel::addVolumeFacesFromDomMesh(domMesh* mesh) { domPolylistRef& poly = polys.get(i); - load_face_from_dom_polylist(mVolumeFaces, mMaterialList, poly); + mStatus = load_face_from_dom_polylist(mVolumeFaces, mMaterialList, poly); + + if(mStatus != NO_ERRORS) + { + mVolumeFaces.clear() ; + mMaterialList.clear() ; + return ; //abort + } } domPolygons_Array& polygons = mesh->getPolygons_array(); @@ -742,7 +782,14 @@ void LLModel::addVolumeFacesFromDomMesh(domMesh* mesh) { domPolygonsRef& poly = polygons.get(i); - load_face_from_dom_polygons(mVolumeFaces, mMaterialList, poly); + mStatus = load_face_from_dom_polygons(mVolumeFaces, mMaterialList, poly); + + if(mStatus != NO_ERRORS) + { + mVolumeFaces.clear() ; + mMaterialList.clear() ; + return ; //abort + } } } @@ -755,7 +802,7 @@ BOOL LLModel::createVolumeFacesFromDomMesh(domMesh* mesh) mMaterialList.clear(); addVolumeFacesFromDomMesh(mesh); - + if (getNumVolumeFaces() > 0) { optimizeVolumeFaces(); diff --git a/indra/llprimitive/llmodel.h b/indra/llprimitive/llmodel.h index 962e422a26..23f4b5cb42 100755 --- a/indra/llprimitive/llmodel.h +++ b/indra/llprimitive/llmodel.h @@ -69,6 +69,13 @@ public: NUM_LODS }; + enum EModelStatus + { + NO_ERRORS = 0, + VERTEX_NUMBER_OVERFLOW, //vertex number is >= 65535. + INVALID_STATUS + } ; + //convex_hull_decomposition is a vector of convex hulls //each convex hull is a set of points typedef std::vector > convex_hull_decomposition; @@ -138,6 +145,8 @@ public: static LLModel* loadModelFromDomMesh(domMesh* mesh); static std::string getElementLabel(daeElement* element); std::string getName() const; + 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); @@ -237,6 +246,7 @@ public: Decomposition mPhysics; + EModelStatus mStatus ; protected: void addVolumeFacesFromDomMesh(domMesh* mesh); virtual BOOL createVolumeFacesFromDomMesh(domMesh *mesh); diff --git a/indra/newview/llfloatermodelpreview.cpp b/indra/newview/llfloatermodelpreview.cpp index 21c9fca164..f2fa891bca 100755 --- a/indra/newview/llfloatermodelpreview.cpp +++ b/indra/newview/llfloatermodelpreview.cpp @@ -579,7 +579,14 @@ void LLFloaterModelPreview::draw() if (!mModelPreview->mLoading) { - childSetTextArg("status", "[STATUS]", getString("status_idle")); + if ( mModelPreview->getLoadState() > LLModelLoader::ERROR_PARSING ) + { + childSetTextArg("status", "[STATUS]", getString(LLModel::getStatusString(mModelPreview->getLoadState() - LLModelLoader::ERROR_PARSING))); + } + else + { + childSetTextArg("status", "[STATUS]", getString("status_idle")); + } } childSetTextArg("prim_cost", "[PRIM_COST]", llformat("%d", mModelPreview->mResourceCost)); @@ -1285,6 +1292,12 @@ bool LLModelLoader::doLoadModel() { LLPointer model = LLModel::loadModelFromDomMesh(mesh); + if(model->getStatus() != LLModel::NO_ERRORS) + { + setLoadState(ERROR_PARSING + model->getStatus()) ; + return true ; //abort + } + if (model.notNull() && validate_model(model)) { mModelList.push_back(model); @@ -2502,7 +2515,7 @@ U32 LLModelPreview::calcResourceCost() if (mFMP && mModelLoader) { - if ( getLoadState() != LLModelLoader::ERROR_PARSING ) + if ( getLoadState() < LLModelLoader::ERROR_PARSING ) { mFMP->childEnable("ok_btn"); } @@ -2856,7 +2869,7 @@ void LLModelPreview::loadModel(std::string filename, S32 lod) setPreviewLOD(lod); - if ( getLoadState() == LLModelLoader::ERROR_PARSING ) + if ( getLoadState() >= LLModelLoader::ERROR_PARSING ) { mFMP->childDisable("ok_btn"); } @@ -2938,8 +2951,14 @@ void LLModelPreview::loadModelCallback(S32 lod) LLMutexLock lock(this); if (!mModelLoader) { + mLoading = false ; return; } + if(getLoadState() >= LLModelLoader::ERROR_PARSING) + { + mLoading = false ; + return ; + } mModelLoader->loadTextures() ; @@ -3675,7 +3694,7 @@ void LLModelPreview::updateStatusMessages() } } - bool errorStateFromLoader = getLoadState() == LLModelLoader::ERROR_PARSING ? true : false; + bool errorStateFromLoader = getLoadState() >= LLModelLoader::ERROR_PARSING ? true : false; bool skinAndRigOk = true; bool uploadingSkin = mFMP->childGetValue("upload_skin").asBoolean(); diff --git a/indra/newview/llfloatermodelpreview.h b/indra/newview/llfloatermodelpreview.h index 3fcc1b3e57..dabe3c613d 100644 --- a/indra/newview/llfloatermodelpreview.h +++ b/indra/newview/llfloatermodelpreview.h @@ -66,7 +66,7 @@ public: GENERATING_VERTEX_BUFFERS, GENERATING_LOD, DONE, - ERROR_PARSING, //basically loading failed + ERROR_PARSING //basically loading failed } eLoadState; U32 mState; diff --git a/indra/newview/skins/default/xui/en/floater_model_preview.xml b/indra/newview/skins/default/xui/en/floater_model_preview.xml index 0053be4f67..7be6165a0d 100644 --- a/indra/newview/skins/default/xui/en/floater_model_preview.xml +++ b/indra/newview/skins/default/xui/en/floater_model_preview.xml @@ -6,6 +6,7 @@ Idle Loading... Generating Meshes... + Error: Vertex number is more than 65534, aborted! High Medium Low diff --git a/indra/newview/skins/default/xui/en/floater_model_wizard.xml b/indra/newview/skins/default/xui/en/floater_model_wizard.xml index 93740007ee..54ef4695f0 100644 --- a/indra/newview/skins/default/xui/en/floater_model_wizard.xml +++ b/indra/newview/skins/default/xui/en/floater_model_wizard.xml @@ -1026,6 +1026,7 @@ Advanced users familiar with 3d content creation tools may prefer to use the [se Idle Loading... Generating Meshes... + Error: Vertex number is more than 65534, aborted! High Medium Low -- cgit v1.3