diff options
author | prep <prep@lindenlab.com> | 2011-07-11 13:52:46 -0400 |
---|---|---|
committer | prep <prep@lindenlab.com> | 2011-07-11 13:52:46 -0400 |
commit | b905b231c93390fdfdccbc255fa1950a83d6eb75 (patch) | |
tree | aa673669d27d95942e349462f7c88882d947d48d /indra/newview/llfloatermodelpreview.cpp | |
parent | 572a1734a5230bb4ecbc3cc1e5ff842e582e9b49 (diff) | |
parent | 80e60371f8be32719dd19467fd2def80e994aa2d (diff) |
merge
Diffstat (limited to 'indra/newview/llfloatermodelpreview.cpp')
-rwxr-xr-x | indra/newview/llfloatermodelpreview.cpp | 180 |
1 files changed, 91 insertions, 89 deletions
diff --git a/indra/newview/llfloatermodelpreview.cpp b/indra/newview/llfloatermodelpreview.cpp index 58cf8dfd7e..80a9b8f781 100755 --- a/indra/newview/llfloatermodelpreview.cpp +++ b/indra/newview/llfloatermodelpreview.cpp @@ -103,6 +103,9 @@ #include "llanimationstates.h" #include "glod/glod.h" + +const S32 SLM_SUPPORTED_VERSION = 2; + //static S32 LLFloaterModelPreview::sUploadAmount = 10; LLFloaterModelPreview* LLFloaterModelPreview::sInstance = NULL; @@ -404,14 +407,11 @@ BOOL LLFloaterModelPreview::postBuild() childSetTextArg("status", "[STATUS]", getString("status_idle")); - //childSetLabelArg("ok_btn", "[AMOUNT]", llformat("%d",sUploadAmount)); childSetAction("ok_btn", onUpload, this); childDisable("ok_btn"); childSetAction("reset_btn", onReset, this); - childSetAction("clear_materials", onClearMaterials, this); - childSetCommitCallback("preview_lod_combo", onPreviewLODCommit, this); childSetCommitCallback("upload_skin", onUploadSkinCommit, this); @@ -779,15 +779,6 @@ void LLFloaterModelPreview::draw() childSetVisible("decompose_cancel", false); } - U32 resource_cost = mModelPreview->mResourceCost*10; - - if (childGetValue("upload_textures").asBoolean()) - { - resource_cost += mModelPreview->mTextureSet.size()*10; - } - - childSetLabelArg("ok_btn", "[AMOUNT]", llformat("%d", resource_cost)); - if (mModelPreview) { gGL.color3f(1.f, 1.f, 1.f); @@ -1945,8 +1936,11 @@ bool LLModelLoader::doLoadModel() mesh_scale *= transformation; transformation = mesh_scale; - std::vector<LLImportMaterial> materials; - materials.resize(model->getNumVolumeFaces()); + std::map<std::string, LLImportMaterial> materials; + for (U32 i = 0; i < model->mMaterialList.size(); ++i) + { + materials[model->mMaterialList[i]] = LLImportMaterial(); + } mScene[transformation].push_back(LLModelInstance(model, model->mLabel, transformation, materials)); stretch_extents(model, transformation, mExtents[0], mExtents[1], mFirstTransform); } @@ -2008,6 +2002,11 @@ bool LLModelLoader::loadFromSLM(const std::string& filename) //build model list for each LoD model_list model[LLModel::NUM_LODS]; + if (data["version"].asInteger() != SLM_SUPPORTED_VERSION) + { //unsupported version + return false; + } + LLSD& mesh = data["mesh"]; LLVolumeParams volume_params; @@ -2325,14 +2324,17 @@ void LLModelLoader::loadTextures() { for(U32 i = 0 ; i < iter->second.size(); i++) { - for(U32 j = 0 ; j < iter->second[i].mMaterial.size() ; j++) + for(std::map<std::string, LLImportMaterial>::iterator j = iter->second[i].mMaterial.begin(); + j != iter->second[i].mMaterial.end(); ++j) { - if(!iter->second[i].mMaterial[j].mDiffuseMapFilename.empty()) + LLImportMaterial& material = j->second; + + if(!material.mDiffuseMapFilename.empty()) { - iter->second[i].mMaterial[j].mDiffuseMap = - LLViewerTextureManager::getFetchedTextureFromUrl("file://" + iter->second[i].mMaterial[j].mDiffuseMapFilename, TRUE, LLViewerTexture::BOOST_PREVIEW); - iter->second[i].mMaterial[j].mDiffuseMap->setLoadedCallback(LLModelPreview::textureLoadedCallback, 0, TRUE, FALSE, mPreview, NULL, FALSE); - iter->second[i].mMaterial[j].mDiffuseMap->forceToSaveRawImage(0, F32_MAX); + material.mDiffuseMap = + LLViewerTextureManager::getFetchedTextureFromUrl("file://" + material.mDiffuseMapFilename, TRUE, LLViewerTexture::BOOST_PREVIEW); + material.mDiffuseMap->setLoadedCallback(LLModelPreview::textureLoadedCallback, 0, TRUE, FALSE, mPreview, NULL, FALSE); + material.mDiffuseMap->forceToSaveRawImage(0, F32_MAX); mNumOfFetchingTextures++ ; } } @@ -2632,7 +2634,7 @@ void LLModelLoader::processElement( daeElement* element, bool& badElement ) { LLMatrix4 transformation = mTransform; - std::vector<LLImportMaterial> materials = getMaterials(model, instance_geo); + std::map<std::string, LLImportMaterial> materials = getMaterials(model, instance_geo); // adjust the transformation to compensate for mesh normalization LLVector3 mesh_scale_vector; @@ -2688,9 +2690,9 @@ void LLModelLoader::processElement( daeElement* element, bool& badElement ) } } -std::vector<LLImportMaterial> LLModelLoader::getMaterials(LLModel* model, domInstance_geometry* instance_geo) +std::map<std::string, LLImportMaterial> LLModelLoader::getMaterials(LLModel* model, domInstance_geometry* instance_geo) { - std::vector<LLImportMaterial> materials; + std::map<std::string, LLImportMaterial> materials; for (int i = 0; i < model->mMaterialList.size(); i++) { LLImportMaterial import_material; @@ -2737,7 +2739,8 @@ std::vector<LLImportMaterial> LLModelLoader::getMaterials(LLModel* model, domIns } } - materials.push_back(import_material); + import_material.mBinding = model->mMaterialList[i]; + materials[model->mMaterialList[i]] = import_material; } return materials; @@ -2999,7 +3002,6 @@ U32 LLModelPreview::calcResourceCost() //ok_btn should not have been changed unless something was wrong with joint list } - U32 cost = 0; std::set<LLModel*> accounted; U32 num_points = 0; U32 num_hulls = 0; @@ -3047,8 +3049,7 @@ U32 LLModelPreview::calcResourceCost() mFMP->childGetValue("upload_skin").asBoolean(), mFMP->childGetValue("upload_joints").asBoolean(), TRUE); - cost += gMeshRepo.calcResourceCost(ret); - + num_hulls += decomp.mHull.size(); for (U32 i = 0; i < decomp.mHull.size(); ++i) { @@ -3080,7 +3081,7 @@ U32 LLModelPreview::calcResourceCost() updateStatusMessages(); - return cost; + return (U32) streaming_cost; } void LLFloaterModelPreview::setDetails(F32 x, F32 y, F32 z, F32 streaming_cost, F32 physics_cost) @@ -3122,6 +3123,19 @@ void LLModelPreview::rebuildUploadData() mFMP->childEnable("ok_btn"); } + //reorder materials to match mBaseModel + for (U32 i = 0; i < LLModel::NUM_LODS; i++) + { + if (mBaseModel.size() == mModel[i].size()) + { + for (U32 j = 0; j < mBaseModel.size(); ++j) + { + mModel[i][j]->matchMaterialOrder(mBaseModel[j]); + llassert(mModel[i][j]->mMaterialList == mBaseModel[j]->mMaterialList); + } + } + } + for (LLModelLoader::scene::iterator iter = mBaseScene.begin(); iter != mBaseScene.end(); ++iter) { //for each transform in scene LLMatrix4 mat = iter->first; @@ -3220,6 +3234,8 @@ void LLModelPreview::saveUploadData(const std::string& filename, bool save_skinw LLSD data; + data["version"] = SLM_SUPPORTED_VERSION; + S32 mesh_id = 0; //build list of unique models and initialize local id @@ -3595,43 +3611,6 @@ void LLModelPreview::generateNormals() updateStatusMessages(); } -void LLModelPreview::clearMaterials() -{ - for (LLModelLoader::scene::iterator iter = mScene[mPreviewLOD].begin(); iter != mScene[mPreviewLOD].end(); ++iter) - { //for each transform in current scene - for (LLModelLoader::model_instance_list::iterator model_iter = iter->second.begin(); model_iter != iter->second.end(); ++model_iter) - { //for each instance with that transform - LLModelInstance& source_instance = *model_iter; - LLModel* source = source_instance.mModel; - - for (S32 i = 0; i < source->getNumVolumeFaces(); ++i) - { //for each face in instance - LLImportMaterial& source_material = source_instance.mMaterial[i]; - - //clear material info - source_material.mDiffuseColor = LLColor4(1,1,1,1); - source_material.mDiffuseMap = NULL; - source_material.mDiffuseMapFilename.clear(); - source_material.mDiffuseMapLabel.clear(); - source_material.mFullbright = false; - } - } - } - - mVertexBuffer[mPreviewLOD].clear(); - - if (mPreviewLOD == LLModel::LOD_HIGH) - { - mBaseScene = mScene[mPreviewLOD]; - mBaseModel = mModel[mPreviewLOD]; - clearGLODGroup(); - mVertexBuffer[5].clear(); - } - - mResourceCost = calcResourceCost(); - refresh(); -} - void LLModelPreview::genLODs(S32 which_lod, U32 decimation, bool enforce_tri_limit) { if (mBaseModel.empty()) @@ -4901,6 +4880,19 @@ BOOL LLModelPreview::render() } } + //make sure material lists all match + for (U32 i = 0; i < LLModel::NUM_LODS; i++) + { + if (mBaseModel.size() == mModel[i].size()) + { + for (U32 j = 0; j < mBaseModel.size(); ++j) + { + mModel[i][j]->matchMaterialOrder(mBaseModel[j]); + llassert(mModel[i][j]->mMaterialList == mBaseModel[j]->mMaterialList); + } + } + } + if (regen) { genBuffers(mPreviewLOD, skin_weight); @@ -4932,13 +4924,18 @@ BOOL LLModelPreview::render() if (textures) { - glColor4fv(instance.mMaterial[i].mDiffuseColor.mV); - if (i < instance.mMaterial.size() && instance.mMaterial[i].mDiffuseMap.notNull()) + const std::string& binding = instance.mModel->mMaterialList[i]; + const LLImportMaterial& material = instance.mMaterial[binding]; + + llassert(binding == model->mMaterialList[i]); + + glColor4fv(material.mDiffuseColor.mV); + if (material.mDiffuseMap.notNull()) { - if (instance.mMaterial[i].mDiffuseMap->getDiscardLevel() > -1) + if (material.mDiffuseMap->getDiscardLevel() > -1) { - gGL.getTexUnit(0)->bind(instance.mMaterial[i].mDiffuseMap, true); - mTextureSet.insert(instance.mMaterial[i].mDiffuseMap.get()); + gGL.getTexUnit(0)->bind(material.mDiffuseMap, true); + mTextureSet.insert(material.mDiffuseMap.get()); } } } @@ -5238,8 +5235,10 @@ BOOL LLModelPreview::render() position[j] = v; } + const std::string& binding = instance.mModel->mMaterialList[i]; + const LLImportMaterial& material = instance.mMaterial[binding]; buffer->setBuffer(type_mask & buffer->getTypeMask()); - glColor4fv(instance.mMaterial[i].mDiffuseColor.mV); + glColor4fv(material.mDiffuseColor.mV); gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); buffer->draw(LLRender::TRIANGLES, buffer->getNumIndices(), 0); glColor3f(0.4f, 0.4f, 0.4f); @@ -5388,25 +5387,12 @@ void LLFloaterModelPreview::onUpload(void* user_data) //static -void LLFloaterModelPreview::onClearMaterials(void* user_data) -{ - LLFloaterModelPreview* mp = (LLFloaterModelPreview*) user_data; - mp->mModelPreview->clearMaterials(); -} - -//static void LLFloaterModelPreview::refresh(LLUICtrl* ctrl, void* user_data) { sInstance->toggleCalculateButton(true); sInstance->mModelPreview->mDirty = true; } -void LLFloaterModelPreview::updateResourceCost() -{ - U32 cost = mModelPreview->mResourceCost; - childSetLabelArg("ok_btn", "[AMOUNT]", llformat("%d",cost)); -} - //static void LLModelPreview::textureLoadedCallback( BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* src_aux, S32 discard_level, BOOL final, void* userdata ) { @@ -5482,18 +5468,34 @@ void LLFloaterModelPreview::toggleCalculateButton(bool visible) { std::string tbd = getString("tbd"); childSetTextArg("weights", "[EQ]", tbd); + childSetTextArg("weights", "[ST]", tbd); + childSetTextArg("weights", "[SIM]", tbd); childSetTextArg("weights", "[PH]", tbd); - childSetTextArg("weights", "[FEE]", tbd); + childSetTextArg("upload_fee", "[FEE]", tbd); + childSetTextArg("price_breakdown", "[STREAMING]", tbd); + childSetTextArg("price_breakdown", "[PHYSICS]", tbd); + childSetTextArg("price_breakdown", "[INSTANCES]", tbd); + childSetTextArg("price_breakdown", "[TEXTURES]", tbd); + childSetTextArg("price_breakdown", "[MODEL]", tbd); } } -void LLFloaterModelPreview::onModelPhysicsFeeReceived(F64 physics, S32 fee, std::string upload_url) +void LLFloaterModelPreview::onModelPhysicsFeeReceived(const LLSD& result, std::string upload_url) { mUploadModelUrl = upload_url; - childSetTextArg("weights", "[EQ]", llformat("%d", mModelPreview->mResourceCost)); - childSetTextArg("weights", "[PH]", llformat("%.3f", physics)); - childSetTextArg("weights", "[FEE]", llformat("%d", fee)); + childSetTextArg("weights", "[EQ]", llformat("%0.3f", result["resource_cost"].asReal())); + childSetTextArg("weights", "[ST]", llformat("%0.3f", result["model_streaming_cost"].asReal())); + childSetTextArg("weights", "[SIM]", llformat("%0.3f", result["simulation_cost"].asReal())); + childSetTextArg("weights", "[PH]", llformat("%0.3f", result["physics_cost"].asReal())); + childSetTextArg("upload_fee", "[FEE]", llformat("%d", result["upload_price"].asInteger())); + childSetTextArg("price_breakdown", "[STREAMING]", llformat("%d", result["upload_price_breakdown"]["mesh_streaming"].asInteger())); + childSetTextArg("price_breakdown", "[PHYSICS]", llformat("%d", result["upload_price_breakdown"]["mesh_physics"].asInteger())); + childSetTextArg("price_breakdown", "[INSTANCES]", llformat("%d", result["upload_price_breakdown"]["mesh_instance"].asInteger())); + childSetTextArg("price_breakdown", "[TEXTURES]", llformat("%d", result["upload_price_breakdown"]["texture"].asInteger())); + childSetTextArg("price_breakdown", "[MODEL]", llformat("%d", result["upload_price_breakdown"]["model"].asInteger())); childSetVisible("weights", true); + childSetVisible("upload_fee", true); + childSetVisible("price_breakdown", true); mUploadBtn->setEnabled(mHasUploadPerm && !mUploadModelUrl.empty()); } |