diff options
Diffstat (limited to 'indra/newview/llmodelpreview.cpp')
-rw-r--r-- | indra/newview/llmodelpreview.cpp | 154 |
1 files changed, 107 insertions, 47 deletions
diff --git a/indra/newview/llmodelpreview.cpp b/indra/newview/llmodelpreview.cpp index 26f1206c85..9af9f7fd53 100644 --- a/indra/newview/llmodelpreview.cpp +++ b/indra/newview/llmodelpreview.cpp @@ -68,6 +68,8 @@ #include "lltabcontainer.h" #include "lltextbox.h" +#include <filesystem> + #include <boost/algorithm/string.hpp> bool LLModelPreview::sIgnoreLoadedCallback = false; @@ -93,7 +95,7 @@ const F32 SKIN_WEIGHT_CAMERA_DISTANCE = 16.f; LLViewerFetchedTexture* bindMaterialDiffuseTexture(const LLImportMaterial& material) { - LLViewerFetchedTexture *texture = LLViewerTextureManager::getFetchedTexture(material.getDiffuseMap(), FTT_DEFAULT, TRUE, LLGLTexture::BOOST_PREVIEW); + LLViewerFetchedTexture *texture = LLViewerTextureManager::getFetchedTexture(material.getDiffuseMap(), FTT_DEFAULT, true, LLGLTexture::BOOST_PREVIEW); if (texture) { @@ -151,7 +153,7 @@ void FindModel(LLModelLoader::scene& scene, const std::string& name_to_match, LL //----------------------------------------------------------------------------- LLModelPreview::LLModelPreview(S32 width, S32 height, LLFloater* fmp) - : LLViewerDynamicTexture(width, height, 3, ORDER_MIDDLE, FALSE), LLMutex() + : LLViewerDynamicTexture(width, height, 3, ORDER_MIDDLE, false), LLMutex() , mLodsQuery() , mLodsWithParsingError() , mPelvisZOffset(0.0f) @@ -165,7 +167,7 @@ LLModelPreview::LLModelPreview(S32 width, S32 height, LLFloater* fmp) , mHasDegenerate(false) , mImporterDebug(LLCachedControl<bool>(gSavedSettings, "ImporterDebug", false)) { - mNeedsUpdate = TRUE; + mNeedsUpdate = true; mCameraDistance = 0.f; mCameraYaw = 0.f; mCameraPitch = 0.f; @@ -293,7 +295,7 @@ void LLModelPreview::rebuildUploadData() F32 max_scale = 0.f; - BOOL legacyMatching = gSavedSettings.getBOOL("ImporterLegacyMatching"); + bool legacyMatching = gSavedSettings.getBOOL("ImporterLegacyMatching"); U32 load_state = 0; for (auto iter = mBaseScene.begin(); iter != mBaseScene.end(); ++iter) @@ -536,6 +538,32 @@ void LLModelPreview::rebuildUploadData() } instance.mTransform = mat; mUploadData.push_back(instance); + + // if uploading textures, make sure textures are present + if (mFMP->childGetValue("upload_textures").asBoolean()) // too early to cheack if still loading + { + for (auto& mat_pair : instance.mMaterial) + { + LLImportMaterial& material = mat_pair.second; + + if (material.mDiffuseMapFilename.size()) + { + LLViewerFetchedTexture* texture = LLMeshUploadThread::FindViewerTexture(material); + if (texture && texture->isMissingAsset()) + { + // in case user provided a missing file later + texture->setIsMissingAsset(false); + texture->setLoadedCallback(LLModelPreview::textureLoadedCallback, 0, true, false, this, NULL, false); + texture->forceToSaveRawImage(0, F32_MAX); + texture->updateFetch(); + if (mModelLoader) + { + mModelLoader->mNumOfFetchingTextures++; + } + } + } + } + } } } @@ -662,7 +690,7 @@ void LLModelPreview::saveUploadData(const std::string& filename, save_skinweights, save_joint_positions, lock_scale_if_joint_position, - FALSE, TRUE, instance.mModel->mSubmodelID); + false, true, instance.mModel->mSubmodelID); data["mesh"][instance.mModel->mLocalID] = str.str(); } @@ -1062,6 +1090,29 @@ void LLModelPreview::loadModelCallback(S32 loaded_lod) { //only replace given LoD mModel[loaded_lod] = mModelLoader->mModelList; mScene[loaded_lod] = mModelLoader->mScene; + + // Duplicate the model if it is an internal bounding box model + if (loaded_lod == LLModel::LOD_PHYSICS && + mBaseModel.size() > 1 && // This makes sense for multiple models only + mModelLoader->mModelList.size() == 1 && // Just on the off-chance + mModelLoader->mScene.size() == 1 && // Just on the off-chance + std::filesystem::path(mModelLoader->mFilename).filename() == "cube.dae") + { + // Create a copy of the just loaded model for each model in mBaseModel + const LLModel* origin = mModelLoader->mModelList.front(); + const LLModelInstance& mi = mModelLoader->mScene.begin()->second.front(); + for (U32 i = 1; i < mBaseModel.size(); ++i) + { + LLPointer<LLModel> copy(new LLModel(origin->getParams(), origin->getDetail())); + copy->mLabel = origin->mLabel; + copy->copyVolumeFaces(origin); + copy->mPosition = origin->mPosition; + copy->mMaterialList = origin->mMaterialList; + mModel[loaded_lod].push_back(copy); + mScene[loaded_lod][mi.mTransform].push_back(LLModelInstance(copy, copy->mLabel, mi.mTransform, mi.mMaterial)); + } + } + mVertexBuffer[loaded_lod].clear(); setPreviewLOD(loaded_lod); @@ -1088,18 +1139,18 @@ void LLModelPreview::loadModelCallback(S32 loaded_lod) mDefaultPhysicsShapeP = out_model; mWarnOfUnmatchedPhyicsMeshes = true; } - BOOL legacyMatching = gSavedSettings.getBOOL("ImporterLegacyMatching"); + bool legacyMatching = gSavedSettings.getBOOL("ImporterLegacyMatching"); if (!legacyMatching) { if (!mBaseModel.empty()) { - BOOL name_based = FALSE; - BOOL has_submodels = FALSE; + bool name_based = false; + bool has_submodels = false; for (U32 idx = 0; idx < mBaseModel.size(); ++idx) { if (mBaseModel[idx]->mSubmodelID) { // don't do index-based renaming when the base model has submodels - has_submodels = TRUE; + has_submodels = true; if (mImporterDebug) { std::ostringstream out; @@ -1120,12 +1171,12 @@ void LLModelPreview::loadModelCallback(S32 loaded_lod) FindModel(mBaseScene, loaded_name, found_model, transform); if (found_model) { // don't rename correctly named models (even if they are placed in a wrong order) - name_based = TRUE; + name_based = true; } if (mModel[loaded_lod][idx]->mSubmodelID) { // don't rename the models when loaded LOD model has submodels - has_submodels = TRUE; + has_submodels = true; } } @@ -1159,6 +1210,17 @@ void LLModelPreview::loadModelCallback(S32 loaded_lod) LLFloaterModelPreview::addStringToLog(out, false); } mModel[loaded_lod][idx]->mLabel = name; + // Rename the correspondent instance as well + [&]() + { + for (auto& p : mScene[loaded_lod]) + for (auto& i : p.second) + if (i.mModel == mModel[loaded_lod][idx]) + { + i.mLabel = name; + return; + } + }(); } } } @@ -1323,7 +1385,7 @@ F32 LLModelPreview::genMeshOptimizerPerModel(LLModel *base_model, LLModel *targe S32 size_indices = 0; S32 size_vertices = 0; - for (U32 face_idx = 0; face_idx < base_model->getNumVolumeFaces(); ++face_idx) + for (S32 face_idx = 0; face_idx < base_model->getNumVolumeFaces(); ++face_idx) { const LLVolumeFace &face = base_model->getVolumeFace(face_idx); size_indices += face.mNumIndices; @@ -1349,7 +1411,7 @@ F32 LLModelPreview::genMeshOptimizerPerModel(LLModel *base_model, LLModel *targe S32 combined_positions_shift = 0; S32 indices_idx_shift = 0; S32 combined_indices_shift = 0; - for (U32 face_idx = 0; face_idx < base_model->getNumVolumeFaces(); ++face_idx) + for (S32 face_idx = 0; face_idx < base_model->getNumVolumeFaces(); ++face_idx) { const LLVolumeFace &face = base_model->getVolumeFace(face_idx); @@ -1474,7 +1536,7 @@ F32 LLModelPreview::genMeshOptimizerPerModel(LLModel *base_model, LLModel *targe S32 valid_faces = 0; // Crude method to copy indices back into face - for (U32 face_idx = 0; face_idx < base_model->getNumVolumeFaces(); ++face_idx) + for (S32 face_idx = 0; face_idx < base_model->getNumVolumeFaces(); ++face_idx) { const LLVolumeFace &face = base_model->getVolumeFace(face_idx); @@ -1492,7 +1554,7 @@ F32 LLModelPreview::genMeshOptimizerPerModel(LLModel *base_model, LLModel *targe // Copy relevant indices and vertices for (S32 i = 0; i < size_new_indices; ++i) { - U32 idx = output_indices[i]; + S32 idx = (S32)output_indices[i]; if ((i % 3) == 0) { @@ -1521,7 +1583,7 @@ F32 LLModelPreview::genMeshOptimizerPerModel(LLModel *base_model, LLModel *targe // U16 vertices overflow shouldn't happen, but just in case size_new_indices = 0; valid_faces = 0; - for (U32 face_idx = 0; face_idx < base_model->getNumVolumeFaces(); ++face_idx) + for (S32 face_idx = 0; face_idx < base_model->getNumVolumeFaces(); ++face_idx) { genMeshOptimizerPerFace(base_model, target_model, face_idx, indices_decimator, error_threshold, simplification_mode); const LLVolumeFace &face = target_model->getVolumeFace(face_idx); @@ -1867,7 +1929,7 @@ void LLModelPreview::genMeshOptimizerLODs(S32 which_lod, S32 meshopt_mode, U32 d LLModel* target_model = mModel[lod][mdl_idx]; // carry over normalized transform into simplified model - for (int i = 0; i < base->getNumVolumeFaces(); ++i) + for (S32 i = 0; i < base->getNumVolumeFaces(); ++i) { LLVolumeFace& src = base->getVolumeFace(i); LLVolumeFace& dst = target_model->getVolumeFace(i); @@ -1881,7 +1943,7 @@ void LLModelPreview::genMeshOptimizerLODs(S32 which_lod, S32 meshopt_mode, U32 d if (model_meshopt_mode == MESH_OPTIMIZER_PRECISE) { // Run meshoptimizer for each face - for (U32 face_idx = 0; face_idx < base->getNumVolumeFaces(); ++face_idx) + for (S32 face_idx = 0; face_idx < base->getNumVolumeFaces(); ++face_idx) { F32 res = genMeshOptimizerPerFace(base, target_model, face_idx, indices_decimator, lod_error_threshold, MESH_OPTIMIZER_FULL); if (res < 0) @@ -1897,7 +1959,7 @@ void LLModelPreview::genMeshOptimizerLODs(S32 which_lod, S32 meshopt_mode, U32 d if (model_meshopt_mode == MESH_OPTIMIZER_SLOPPY) { // Run meshoptimizer for each face - for (U32 face_idx = 0; face_idx < base->getNumVolumeFaces(); ++face_idx) + for (S32 face_idx = 0; face_idx < base->getNumVolumeFaces(); ++face_idx) { if (genMeshOptimizerPerFace(base, target_model, face_idx, indices_decimator, lod_error_threshold, MESH_OPTIMIZER_NO_TOPOLOGY) < 0) { @@ -2244,7 +2306,7 @@ void LLModelPreview::updateStatusMessages() mModelNoErrors = true; const U32 lod_high = LLModel::LOD_HIGH; - U32 high_submodel_count = mModel[lod_high].size() - countRootModels(mModel[lod_high]); + U32 high_submodel_count = static_cast<U32>(mModel[lod_high].size()) - countRootModels(mModel[lod_high]); for (S32 lod = 0; lod <= lod_high; ++lod) { @@ -2341,7 +2403,7 @@ void LLModelPreview::updateStatusMessages() //warn if hulls have more than 256 points in them - BOOL physExceededVertexLimit = FALSE; + bool physExceededVertexLimit = false; for (U32 i = 0; mModelNoErrors && i < mModel[LLModel::LOD_PHYSICS].size(); ++i) { LLModel* mdl = mModel[LLModel::LOD_PHYSICS][i]; @@ -2352,7 +2414,7 @@ void LLModelPreview::updateStatusMessages() { if (mdl->mPhysics.mHull[j].size() > 256) { - physExceededVertexLimit = TRUE; + physExceededVertexLimit = true; LL_INFOS() << "Physical model " << mdl->mLabel << " exceeds vertex per hull limitations." << LL_ENDL; break; } @@ -2447,10 +2509,10 @@ void LLModelPreview::updateStatusMessages() if (!decomp.empty()) { - phys_hulls += decomp.size(); + phys_hulls += static_cast<S32>(decomp.size()); for (U32 i = 0; i < decomp.size(); ++i) { - phys_points += decomp[i].size(); + phys_points += static_cast<S32>(decomp[i].size()); } } else @@ -3075,8 +3137,8 @@ U32 LLModelPreview::loadTextures(LLImportMaterial& material, void* opaque) material.mOpaqueData = new LLPointer< LLViewerFetchedTexture >; LLPointer< LLViewerFetchedTexture >& tex = (*reinterpret_cast< LLPointer< LLViewerFetchedTexture > * >(material.mOpaqueData)); - tex = LLViewerTextureManager::getFetchedTextureFromUrl("file://" + LLURI::unescape(material.mDiffuseMapFilename), FTT_LOCAL_FILE, TRUE, LLGLTexture::BOOST_PREVIEW); - tex->setLoadedCallback(LLModelPreview::textureLoadedCallback, 0, TRUE, FALSE, opaque, NULL, FALSE); + tex = LLViewerTextureManager::getFetchedTextureFromUrl("file://" + LLURI::unescape(material.mDiffuseMapFilename), FTT_LOCAL_FILE, true, LLGLTexture::BOOST_PREVIEW); + tex->setLoadedCallback(LLModelPreview::textureLoadedCallback, 0, true, false, opaque, NULL, false); tex->forceToSaveRawImage(0, F32_MAX); material.setDiffuseMap(tex->getID()); // record tex ID return 1; @@ -3128,12 +3190,12 @@ void LLModelPreview::addEmptyFace(LLModel* pTarget) //----------------------------------------------------------------------------- // Todo: we shouldn't be setting all those UI elements on render. // Note: Render happens each frame with skinned avatars -BOOL LLModelPreview::render() +bool LLModelPreview::render() { assert_main_thread(); LLMutexLock lock(this); - mNeedsUpdate = FALSE; + mNeedsUpdate = false; bool show_edges = mViewOption["show_edges"]; bool show_joint_overrides = mViewOption["show_joint_overrides"]; @@ -3344,7 +3406,7 @@ BOOL LLModelPreview::render() z_near = llclamp(z_far * 0.001f, 0.001f, 0.1f); - LLViewerCamera::getInstance()->setPerspective(FALSE, mOrigin.mX, mOrigin.mY, width, height, FALSE, z_near, z_far); + LLViewerCamera::getInstance()->setPerspective(false, mOrigin.mX, mOrigin.mY, width, height, false, z_near, z_far); stop_glerror(); @@ -3373,7 +3435,7 @@ BOOL LLModelPreview::render() else { LL_INFOS() << "Vertex Buffer[" << mPreviewLOD << "]" << " is EMPTY!!!" << LL_ENDL; - regen = TRUE; + regen = true; } } @@ -3406,12 +3468,12 @@ BOOL LLModelPreview::render() gGL.multMatrix((GLfloat*)mat.mMatrix); - U32 num_models = mVertexBuffer[mPreviewLOD][model].size(); - for (U32 i = 0; i < num_models; ++i) + auto num_models = mVertexBuffer[mPreviewLOD][model].size(); + for (size_t i = 0; i < num_models; ++i) { if (show_textures) { - int materialCnt = instance.mModel->mMaterialList.size(); + auto materialCnt = instance.mModel->mMaterialList.size(); if (i < materialCnt) { const std::string& binding = instance.mModel->mMaterialList[i]; @@ -3559,10 +3621,9 @@ BOOL LLModelPreview::render() if (render_mesh) { - U32 num_models = mVertexBuffer[LLModel::LOD_PHYSICS][model].size(); - if (pass > 0) - { - for (U32 i = 0; i < num_models; ++i) + auto num_models = mVertexBuffer[LLModel::LOD_PHYSICS][model].size(); + if (pass > 0){ + for (size_t i = 0; i < num_models; ++i) { gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); gGL.diffuseColor4fv(PREVIEW_PSYH_FILL_COL.mV); @@ -3633,8 +3694,8 @@ BOOL LLModelPreview::render() if (physics.mHull.empty()) { - U32 num_models = mVertexBuffer[LLModel::LOD_PHYSICS][model].size(); - for (U32 v = 0; v < num_models; ++v) + auto num_models = mVertexBuffer[LLModel::LOD_PHYSICS][model].size(); + for (size_t v = 0; v < num_models; ++v) { // Zero this variable for an obligatory buffer initialization // See https://github.com/secondlife/viewer/issues/912 @@ -3704,7 +3765,7 @@ BOOL LLModelPreview::render() const LLMeshSkinInfo *skin = &model->mSkinInfo; LLSkinningUtil::initJointNums(&model->mSkinInfo, getPreviewAvatar());// inits skin->mJointNums if nessesary U32 joint_count = LLSkinningUtil::getMeshJointCount(skin); - U32 bind_count = skin->mAlternateBindMatrix.size(); + auto bind_count = skin->mAlternateBindMatrix.size(); if (show_joint_overrides && bind_count > 0 @@ -3749,8 +3810,7 @@ BOOL LLModelPreview::render() } } - std::size_t size = mVertexBuffer[mPreviewLOD][model].size(); - for (U32 i = 0; i < size; ++i) + for (U32 i = 0, e = static_cast<U32>(mVertexBuffer[mPreviewLOD][model].size()); i < e; ++i) { model->mSkinInfo.updateHash(); LLRenderPass::uploadMatrixPalette(mPreviewAvatar, &model->mSkinInfo); @@ -3759,7 +3819,7 @@ BOOL LLModelPreview::render() if (show_textures) { - int materialCnt = instance.mModel->mMaterialList.size(); + auto materialCnt = instance.mModel->mMaterialList.size(); if (i < materialCnt) { const std::string& binding = instance.mModel->mMaterialList[i]; @@ -3842,7 +3902,7 @@ BOOL LLModelPreview::render() gGL.popMatrix(); - return TRUE; + return true; } void LLModelPreview::renderGroundPlane(float z_offset) @@ -3872,7 +3932,7 @@ void LLModelPreview::renderGroundPlane(float z_offset) //----------------------------------------------------------------------------- void LLModelPreview::refresh() { - mNeedsUpdate = TRUE; + mNeedsUpdate = true; } //----------------------------------------------------------------------------- @@ -3941,12 +4001,12 @@ void LLModelPreview::setPreviewLOD(S32 lod) //static void LLModelPreview::textureLoadedCallback( - BOOL success, + bool success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* src_aux, S32 discard_level, - BOOL final, + bool final, void* userdata) { LLModelPreview* preview = (LLModelPreview*)userdata; |