diff options
Diffstat (limited to 'indra/newview/llfloatermodelpreview.cpp')
-rwxr-xr-x | indra/newview/llfloatermodelpreview.cpp | 149 |
1 files changed, 143 insertions, 6 deletions
diff --git a/indra/newview/llfloatermodelpreview.cpp b/indra/newview/llfloatermodelpreview.cpp index 20760001fd..fea4e57d13 100755 --- a/indra/newview/llfloatermodelpreview.cpp +++ b/indra/newview/llfloatermodelpreview.cpp @@ -751,6 +751,8 @@ void LLFloaterModelPreview::onExplodeCommit(LLUICtrl* ctrl, void* userdata) void LLFloaterModelPreview::onAutoFillCommit(LLUICtrl* ctrl, void* userdata) { LLFloaterModelPreview* fp = (LLFloaterModelPreview*) userdata; + if (fp->mModelPreview->mHasBrokenModel) + return; fp->mModelPreview->genLODs(); } @@ -1635,6 +1637,10 @@ bool LLModelLoader::doLoadModel() mModelList.push_back(model); mModel[mesh] = model; } + else + { + mPreview->mHasBrokenModel = true; + } } } @@ -2289,6 +2295,12 @@ void LLModelLoader::loadModelCallback() return ; } + //generate BBox here if non-valide model in scene was detected + if (mPreview->mHasBrokenModel) + { + mPreview->genModelBBox(); + } + //cleanup model loader if (mPreview) { @@ -3133,6 +3145,7 @@ LLModelPreview::LLModelPreview(S32 width, S32 height, LLFloater* fmp) , mResetJoints( false ) , mRigParityWithScene( false ) , mLastJointUpdate( false ) +, mHasBrokenModel( false ) { mNeedsUpdate = TRUE; mCameraDistance = 0.f; @@ -4295,6 +4308,114 @@ void LLModelPreview::genLODs(S32 which_lod, U32 decimation, bool enforce_tri_lim }*/ } +void LLModelPreview::genModelBBox() +{ + LLVector3 min, max; + min = this->mModelLoader->mExtents[0]; + max = this->mModelLoader->mExtents[1]; + + std::vector<LLVector3> v_list; + v_list.resize(4); + std::map<U8, std::vector<LLVector3> > face_list; + + // Face 0 + v_list[0] = LLVector3(min.mV[VX], max.mV[VY], max.mV[VZ]); + v_list[1] = LLVector3(min.mV[VX], min.mV[VY], max.mV[VZ]); + v_list[2] = LLVector3(max.mV[VX], min.mV[VY], max.mV[VZ]); + v_list[3] = LLVector3(max.mV[VX], max.mV[VY], max.mV[VZ]); + face_list.insert(std::pair<U8, std::vector<LLVector3> >(0, v_list)); + + // Face 1 + v_list[0] = LLVector3(max.mV[VX], min.mV[VY], max.mV[VZ]); + v_list[1] = LLVector3(max.mV[VX], min.mV[VY], min.mV[VZ]); + v_list[2] = LLVector3(max.mV[VX], max.mV[VY], min.mV[VZ]); + v_list[3] = LLVector3(max.mV[VX], max.mV[VY], max.mV[VZ]); + face_list.insert(std::pair<U8, std::vector<LLVector3> >(1, v_list)); + + // Face 2 + v_list[0] = LLVector3(min.mV[VX], max.mV[VY], min.mV[VZ]); + v_list[1] = LLVector3(min.mV[VX], max.mV[VY], max.mV[VZ]); + v_list[2] = LLVector3(max.mV[VX], max.mV[VY], max.mV[VZ]); + v_list[3] = LLVector3(max.mV[VX], max.mV[VY], min.mV[VZ]); + face_list.insert(std::pair<U8, std::vector<LLVector3> >(2, v_list)); + + // Face 3 + v_list[0] = LLVector3(min.mV[VX], max.mV[VY], max.mV[VZ]); + v_list[1] = LLVector3(min.mV[VX], max.mV[VY], min.mV[VZ]); + v_list[2] = LLVector3(min.mV[VX], min.mV[VY], min.mV[VZ]); + v_list[3] = LLVector3(min.mV[VX], min.mV[VY], max.mV[VZ]); + face_list.insert(std::pair<U8, std::vector<LLVector3> >(3, v_list)); + + // Face 4 + v_list[0] = LLVector3(min.mV[VX], min.mV[VY], max.mV[VZ]); + v_list[1] = LLVector3(min.mV[VX], min.mV[VY], min.mV[VZ]); + v_list[2] = LLVector3(max.mV[VX], min.mV[VY], min.mV[VZ]); + v_list[3] = LLVector3(max.mV[VX], min.mV[VY], max.mV[VZ]); + face_list.insert(std::pair<U8, std::vector<LLVector3> >(4, v_list)); + + // Face 5 + v_list[0] = LLVector3(min.mV[VX], min.mV[VY], min.mV[VZ]); + v_list[1] = LLVector3(min.mV[VX], max.mV[VY], min.mV[VZ]); + v_list[2] = LLVector3(max.mV[VX], max.mV[VY], min.mV[VZ]); + v_list[3] = LLVector3(max.mV[VX], min.mV[VY], min.mV[VZ]); + face_list.insert(std::pair<U8, std::vector<LLVector3> >(5, v_list)); + + U16 Idx[] = { 0, 1, 2, 3, 0, 2, }; + + U32 type_mask = LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_TEXCOORD0; + LLPointer<LLVertexBuffer> buff = new LLVertexBuffer(type_mask, 0); + buff->allocateBuffer(4, 6, true); + + LLStrider<LLVector3> pos; + LLStrider<U16> idx; + LLStrider<LLVector3> norm; + LLStrider<LLVector2> tc; + + buff->getVertexStrider(pos); + buff->getIndexStrider(idx); + + buff->getNormalStrider(norm); + buff->getTexCoord0Strider(tc); + + for (U32 i = 0; i < 6; ++i) + { + idx[i] = Idx[i]; + } + + LLVolumeParams volume_params; + volume_params.setType(LL_PCODE_PROFILE_SQUARE, LL_PCODE_PATH_LINE); + LLModel* mdl = new LLModel(volume_params, 0.f); + mdl->mLabel = "BBOX"; + + mdl->setNumVolumeFaces(6); + for (U8 i = 0; i < 6; ++i) + { + for (U8 j = 0; j < 4; ++j) + { + pos[j] = face_list[i][j]; + } + + mdl->setVolumeFaceData(i, pos, norm, tc, idx, buff->getNumVerts(), buff->getNumIndices()); + } + + if (validate_model(mdl)) + { + LLMatrix4 mat; + std::map<std::string, LLImportMaterial> materials; + std::vector<LLModelInstance> instance_list; + instance_list.push_back(LLModelInstance(mdl, mdl->mLabel, mat, materials)); + + for (S32 i = LLModel::LOD_HIGH - 1; i >= 0; i--) + { + mModel[i].clear(); + mModel[i].push_back(mdl); + + mScene[i].clear(); + mScene[i].insert(std::pair<LLMatrix4, std::vector<LLModelInstance> >(mat, instance_list)); + } + } +} + void LLModelPreview::updateStatusMessages() { assert_main_thread(); @@ -4961,12 +5082,14 @@ void LLModelPreview::update() if (mGenLOD) { - mGenLOD = false; - genLODs(); - refresh(); - updateStatusMessages(); + if (!this->mHasBrokenModel) + { + mGenLOD = false; + genLODs(); + refresh(); + updateStatusMessages(); + } } - } //----------------------------------------------------------------------------- // getTranslationForJointOffset() @@ -5292,7 +5415,11 @@ BOOL LLModelPreview::render() } gGL.pushMatrix(); - LLMatrix4 mat = instance.mTransform; + LLMatrix4 mat; + if (model->getName() != "BBOX") + { + mat = instance.mTransform; + } gGL.multMatrix((GLfloat*) mat.mMatrix); @@ -5825,6 +5952,16 @@ void LLModelPreview::onLODParamCommit(S32 lod, bool enforce_tri_limit) { if (!mLODFrozen) { + S32 lod_mode = 0; + LLCtrlSelectionInterface* iface = this->mFMP->childGetSelectionInterface("lod_mode_" + lod_name[lod]); + if (iface) + { + lod_mode = iface->getFirstSelectedIndex(); + } + + if (lod_mode == 0 && this->mHasBrokenModel) + return; + genLODs(lod, 3, enforce_tri_limit); refresh(); } |