Merge branch 'DRTVWR-559' of https://bitbucket.org/lindenlab/viewer
commit
7f961f1c16
|
|
@ -40,6 +40,7 @@
|
|||
#include "llviewertexture.h"
|
||||
#include "llsdutil.h"
|
||||
#include "llselectmgr.h"
|
||||
#include "llstatusbar.h" // can_afford_transaction()
|
||||
#include "llviewerinventory.h"
|
||||
#include "llviewerregion.h"
|
||||
#include "llvovolume.h"
|
||||
|
|
@ -56,6 +57,11 @@
|
|||
#include <strstream>
|
||||
|
||||
|
||||
const std::string MATERIAL_ALBEDO_DEFAULT_NAME = "Albedo";
|
||||
const std::string MATERIAL_NORMAL_DEFAULT_NAME = "Normal";
|
||||
const std::string MATERIAL_METALLIC_DEFAULT_NAME = "Metallic Roughness";
|
||||
const std::string MATERIAL_EMISSIVE_DEFAULT_NAME = "Emissive";
|
||||
|
||||
class LLMaterialEditorCopiedCallback : public LLInventoryCallback
|
||||
{
|
||||
public:
|
||||
|
|
@ -79,6 +85,8 @@ private:
|
|||
LLMaterialEditor::LLMaterialEditor(const LLSD& key)
|
||||
: LLPreview(key)
|
||||
, mHasUnsavedChanges(false)
|
||||
, mExpectedUploadCost(0)
|
||||
, mUploadingTexturesCount(0)
|
||||
{
|
||||
const LLInventoryItem* item = getItem();
|
||||
if (item)
|
||||
|
|
@ -366,8 +374,8 @@ void LLMaterialEditor::setHasUnsavedChanges(bool value)
|
|||
upload_texture_count++;
|
||||
}
|
||||
|
||||
S32 upload_cost = upload_texture_count * LLAgentBenefitsMgr::current().getTextureUploadCost();
|
||||
getChild<LLUICtrl>("total_upload_fee")->setTextArg("[FEE]", llformat("%d", upload_cost));
|
||||
mExpectedUploadCost = upload_texture_count * LLAgentBenefitsMgr::current().getTextureUploadCost();
|
||||
getChild<LLUICtrl>("total_upload_fee")->setTextArg("[FEE]", llformat("%d", mExpectedUploadCost));
|
||||
}
|
||||
|
||||
void LLMaterialEditor::setCanSaveAs(BOOL value)
|
||||
|
|
@ -474,6 +482,14 @@ static U32 write_texture(const LLUUID& id, tinygltf::Model& model)
|
|||
|
||||
void LLMaterialEditor::onClickSave()
|
||||
{
|
||||
if (!can_afford_transaction(mExpectedUploadCost))
|
||||
{
|
||||
LLSD args;
|
||||
args["COST"] = llformat("%d", mExpectedUploadCost);
|
||||
LLNotificationsUtil::add("ErrorCannotAffordUpload", args);
|
||||
return;
|
||||
}
|
||||
|
||||
applyToSelection();
|
||||
saveIfNeeded();
|
||||
}
|
||||
|
|
@ -634,9 +650,22 @@ bool LLMaterialEditor::decodeAsset(const std::vector<char>& buffer)
|
|||
|
||||
bool LLMaterialEditor::saveIfNeeded()
|
||||
{
|
||||
if (mUploadingTexturesCount > 0)
|
||||
{
|
||||
// upload already in progress
|
||||
// wait until textures upload
|
||||
// will retry saving on callback
|
||||
return true;
|
||||
}
|
||||
|
||||
if (saveTextures() > 0)
|
||||
{
|
||||
// started texture upload
|
||||
setEnabled(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string buffer = getEncodedAsset();
|
||||
|
||||
saveTextures();
|
||||
|
||||
const LLInventoryItem* item = getItem();
|
||||
// save it out to database
|
||||
|
|
@ -839,6 +868,14 @@ void LLMaterialEditor::refreshFromInventory(const LLUUID& new_item_id)
|
|||
|
||||
void LLMaterialEditor::onClickSaveAs()
|
||||
{
|
||||
if (!can_afford_transaction(mExpectedUploadCost))
|
||||
{
|
||||
LLSD args;
|
||||
args["COST"] = llformat("%d", mExpectedUploadCost);
|
||||
LLNotificationsUtil::add("ErrorCannotAffordUpload", args);
|
||||
return;
|
||||
}
|
||||
|
||||
LLSD args;
|
||||
args["DESC"] = mMaterialName;
|
||||
|
||||
|
|
@ -1161,6 +1198,11 @@ void LLMaterialFilePicker::loadMaterial(const std::string& filename)
|
|||
{
|
||||
mME->mAlbedoFetched->forceToSaveRawImage(0, F32_MAX);
|
||||
albedo_id = mME->mAlbedoFetched->getID();
|
||||
|
||||
if (mME->mAlbedoName.empty())
|
||||
{
|
||||
mME->mAlbedoName = MATERIAL_ALBEDO_DEFAULT_NAME;
|
||||
}
|
||||
}
|
||||
|
||||
LLUUID normal_id;
|
||||
|
|
@ -1168,6 +1210,11 @@ void LLMaterialFilePicker::loadMaterial(const std::string& filename)
|
|||
{
|
||||
mME->mNormalFetched->forceToSaveRawImage(0, F32_MAX);
|
||||
normal_id = mME->mNormalFetched->getID();
|
||||
|
||||
if (mME->mNormalName.empty())
|
||||
{
|
||||
mME->mNormalName = MATERIAL_NORMAL_DEFAULT_NAME;
|
||||
}
|
||||
}
|
||||
|
||||
LLUUID mr_id;
|
||||
|
|
@ -1175,6 +1222,11 @@ void LLMaterialFilePicker::loadMaterial(const std::string& filename)
|
|||
{
|
||||
mME->mMetallicRoughnessFetched->forceToSaveRawImage(0, F32_MAX);
|
||||
mr_id = mME->mMetallicRoughnessFetched->getID();
|
||||
|
||||
if (mME->mMetallicRoughnessName.empty())
|
||||
{
|
||||
mME->mMetallicRoughnessName = MATERIAL_METALLIC_DEFAULT_NAME;
|
||||
}
|
||||
}
|
||||
|
||||
LLUUID emissive_id;
|
||||
|
|
@ -1182,6 +1234,11 @@ void LLMaterialFilePicker::loadMaterial(const std::string& filename)
|
|||
{
|
||||
mME->mEmissiveFetched->forceToSaveRawImage(0, F32_MAX);
|
||||
emissive_id = mME->mEmissiveFetched->getID();
|
||||
|
||||
if (mME->mEmissiveName.empty())
|
||||
{
|
||||
mME->mEmissiveName = MATERIAL_EMISSIVE_DEFAULT_NAME;
|
||||
}
|
||||
}
|
||||
|
||||
mME->setAlbedoId(albedo_id);
|
||||
|
|
@ -1508,7 +1565,7 @@ void LLMaterialEditor::inventoryChanged(LLViewerObject* object,
|
|||
}
|
||||
|
||||
|
||||
void LLMaterialEditor::saveTexture(LLImageJ2C* img, const std::string& name, const LLUUID& asset_id)
|
||||
void LLMaterialEditor::saveTexture(LLImageJ2C* img, const std::string& name, const LLUUID& asset_id, upload_callback_f cb)
|
||||
{
|
||||
if (asset_id.isNull()
|
||||
|| img == nullptr
|
||||
|
|
@ -1523,7 +1580,6 @@ void LLMaterialEditor::saveTexture(LLImageJ2C* img, const std::string& name, con
|
|||
|
||||
U32 expected_upload_cost = LLAgentBenefitsMgr::current().getTextureUploadCost();
|
||||
|
||||
LLAssetStorage::LLStoreAssetCallback callback;
|
||||
|
||||
LLResourceUploadInfo::ptr_t uploadInfo(std::make_shared<LLNewBufferedResourceUploadInfo>(
|
||||
buffer,
|
||||
|
|
@ -1538,28 +1594,114 @@ void LLMaterialEditor::saveTexture(LLImageJ2C* img, const std::string& name, con
|
|||
LLFloaterPerms::getGroupPerms("Uploads"),
|
||||
LLFloaterPerms::getEveryonePerms("Uploads"),
|
||||
expected_upload_cost,
|
||||
false));
|
||||
false,
|
||||
cb));
|
||||
|
||||
upload_new_resource(uploadInfo, callback, nullptr);
|
||||
upload_new_resource(uploadInfo);
|
||||
}
|
||||
|
||||
void LLMaterialEditor::saveTextures()
|
||||
S32 LLMaterialEditor::saveTextures()
|
||||
{
|
||||
if (mAlbedoTextureUploadId == getAlbedoId())
|
||||
S32 work_count = 0;
|
||||
LLSD key = getKey(); // must be locally declared for lambda's capture to work
|
||||
if (mAlbedoTextureUploadId == getAlbedoId() && mAlbedoTextureUploadId.notNull())
|
||||
{
|
||||
saveTexture(mAlbedoJ2C, mAlbedoName, mAlbedoTextureUploadId);
|
||||
mUploadingTexturesCount++;
|
||||
work_count++;
|
||||
saveTexture(mAlbedoJ2C, mAlbedoName, mAlbedoTextureUploadId, [key](LLUUID newAssetId, LLSD response)
|
||||
{
|
||||
LLMaterialEditor* me = LLFloaterReg::findTypedInstance<LLMaterialEditor>("material_editor", key);
|
||||
if (me)
|
||||
{
|
||||
if (response["success"].asBoolean())
|
||||
{
|
||||
me->setAlbedoId(newAssetId);
|
||||
}
|
||||
else
|
||||
{
|
||||
// To make sure that we won't retry (some failures can cb immediately)
|
||||
me->setAlbedoId(LLUUID::null);
|
||||
}
|
||||
me->mUploadingTexturesCount--;
|
||||
|
||||
// try saving
|
||||
me->saveIfNeeded();
|
||||
}
|
||||
});
|
||||
}
|
||||
if (mNormalTextureUploadId == getNormalId())
|
||||
if (mNormalTextureUploadId == getNormalId() && mNormalTextureUploadId.notNull())
|
||||
{
|
||||
saveTexture(mNormalJ2C, mNormalName, mNormalTextureUploadId);
|
||||
mUploadingTexturesCount++;
|
||||
work_count++;
|
||||
saveTexture(mNormalJ2C, mNormalName, mNormalTextureUploadId, [key](LLUUID newAssetId, LLSD response)
|
||||
{
|
||||
LLMaterialEditor* me = LLFloaterReg::findTypedInstance<LLMaterialEditor>("material_editor", key);
|
||||
if (me)
|
||||
{
|
||||
if (response["success"].asBoolean())
|
||||
{
|
||||
me->setNormalId(newAssetId);
|
||||
}
|
||||
else
|
||||
{
|
||||
me->setNormalId(LLUUID::null);
|
||||
}
|
||||
me->setNormalId(newAssetId);
|
||||
me->mUploadingTexturesCount--;
|
||||
|
||||
// try saving
|
||||
me->saveIfNeeded();
|
||||
}
|
||||
});
|
||||
}
|
||||
if (mMetallicTextureUploadId == getMetallicRoughnessId())
|
||||
if (mMetallicTextureUploadId == getMetallicRoughnessId() && mMetallicTextureUploadId.notNull())
|
||||
{
|
||||
saveTexture(mMetallicRoughnessJ2C, mMetallicRoughnessName, mMetallicTextureUploadId);
|
||||
mUploadingTexturesCount++;
|
||||
work_count++;
|
||||
saveTexture(mMetallicRoughnessJ2C, mMetallicRoughnessName, mMetallicTextureUploadId, [key](LLUUID newAssetId, LLSD response)
|
||||
{
|
||||
LLMaterialEditor* me = LLFloaterReg::findTypedInstance<LLMaterialEditor>("material_editor", key);
|
||||
if (me)
|
||||
{
|
||||
if (response["success"].asBoolean())
|
||||
{
|
||||
me->setMetallicRoughnessId(newAssetId);
|
||||
}
|
||||
else
|
||||
{
|
||||
me->setMetallicRoughnessId(LLUUID::null);
|
||||
}
|
||||
me->mUploadingTexturesCount--;
|
||||
|
||||
// try saving
|
||||
me->saveIfNeeded();
|
||||
}
|
||||
});
|
||||
}
|
||||
if (mEmissiveTextureUploadId == getEmissiveId())
|
||||
|
||||
if (mEmissiveTextureUploadId == getEmissiveId() && mEmissiveTextureUploadId.notNull())
|
||||
{
|
||||
saveTexture(mEmissiveJ2C, mEmissiveName, mEmissiveTextureUploadId);
|
||||
mUploadingTexturesCount++;
|
||||
work_count++;
|
||||
saveTexture(mEmissiveJ2C, mEmissiveName, mEmissiveTextureUploadId, [key](LLUUID newAssetId, LLSD response)
|
||||
{
|
||||
LLMaterialEditor* me = LLFloaterReg::findTypedInstance<LLMaterialEditor>("material_editor", LLSD(key));
|
||||
if (me)
|
||||
{
|
||||
if (response["success"].asBoolean())
|
||||
{
|
||||
me->setEmissiveId(newAssetId);
|
||||
}
|
||||
else
|
||||
{
|
||||
me->setEmissiveId(LLUUID::null);
|
||||
}
|
||||
me->mUploadingTexturesCount--;
|
||||
|
||||
// try saving
|
||||
me->saveIfNeeded();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// discard upload buffers once textures have been saved
|
||||
|
|
@ -1577,5 +1719,10 @@ void LLMaterialEditor::saveTextures()
|
|||
mNormalTextureUploadId.setNull();
|
||||
mMetallicTextureUploadId.setNull();
|
||||
mEmissiveTextureUploadId.setNull();
|
||||
|
||||
// asset storage can callback immediately, causing a decrease
|
||||
// of mUploadingTexturesCount, report amount of work scheduled
|
||||
// not amount of work remaining
|
||||
return work_count;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -63,10 +63,12 @@ public:
|
|||
|
||||
void inventoryChanged(LLViewerObject* object, LLInventoryObject::object_list_t* inventory, S32 serial_num, void* user_data) override;
|
||||
|
||||
void saveTexture(LLImageJ2C* img, const std::string& name, const LLUUID& asset_id);
|
||||
typedef std::function<void(LLUUID newAssetId, LLSD response)> upload_callback_f;
|
||||
void saveTexture(LLImageJ2C* img, const std::string& name, const LLUUID& asset_id, upload_callback_f cb);
|
||||
|
||||
// save textures to inventory if needed
|
||||
void saveTextures();
|
||||
// returns amount of scheduled uploads
|
||||
S32 saveTextures();
|
||||
|
||||
void onClickSave();
|
||||
|
||||
|
|
@ -191,6 +193,8 @@ private:
|
|||
LLPointer<LLImageJ2C> mEmissiveJ2C;
|
||||
|
||||
bool mHasUnsavedChanges;
|
||||
S32 mUploadingTexturesCount;
|
||||
S32 mExpectedUploadCost;
|
||||
std::string mMaterialName;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -535,11 +535,13 @@ LLNewBufferedResourceUploadInfo::LLNewBufferedResourceUploadInfo(
|
|||
U32 groupPerms,
|
||||
U32 everyonePerms,
|
||||
S32 expectedCost,
|
||||
bool show_inventory) :
|
||||
LLResourceUploadInfo(name, description, compressionInfo,
|
||||
bool show_inventory,
|
||||
uploadFinish_f finish)
|
||||
: LLResourceUploadInfo(name, description, compressionInfo,
|
||||
destinationType, inventoryType,
|
||||
nextOWnerPerms, groupPerms, everyonePerms, expectedCost, show_inventory),
|
||||
mBuffer(buffer)
|
||||
nextOWnerPerms, groupPerms, everyonePerms, expectedCost, show_inventory)
|
||||
, mBuffer(buffer)
|
||||
, mFinishFn(finish)
|
||||
{
|
||||
setAssetType(assetType);
|
||||
setAssetId(asset_id);
|
||||
|
|
@ -568,6 +570,18 @@ LLSD LLNewBufferedResourceUploadInfo::exportTempFile()
|
|||
return LLSD();
|
||||
}
|
||||
|
||||
LLUUID LLNewBufferedResourceUploadInfo::finishUpload(LLSD &result)
|
||||
{
|
||||
LLUUID newItemId = LLResourceUploadInfo::finishUpload(result);
|
||||
|
||||
if (mFinishFn)
|
||||
{
|
||||
mFinishFn(result["new_asset"].asUUID(), result);
|
||||
}
|
||||
|
||||
return newItemId;
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
LLBufferedAssetUploadInfo::LLBufferedAssetUploadInfo(LLUUID itemId, LLAssetType::EType assetType, std::string buffer, invnUploadFinish_f finish) :
|
||||
LLResourceUploadInfo(std::string(), std::string(), 0, LLFolderType::FT_NONE, LLInventoryType::IT_NONE,
|
||||
|
|
|
|||
|
|
@ -172,6 +172,8 @@ private:
|
|||
class LLNewBufferedResourceUploadInfo : public LLResourceUploadInfo
|
||||
{
|
||||
public:
|
||||
typedef std::function<void(LLUUID newAssetId, LLSD response)> uploadFinish_f;
|
||||
|
||||
LLNewBufferedResourceUploadInfo(
|
||||
const std::string& buffer,
|
||||
const LLAssetID& asset_id,
|
||||
|
|
@ -185,15 +187,18 @@ public:
|
|||
U32 groupPerms,
|
||||
U32 everyonePerms,
|
||||
S32 expectedCost,
|
||||
bool show_inventory = true);
|
||||
bool show_inventory,
|
||||
uploadFinish_f finish);
|
||||
|
||||
virtual LLSD prepareUpload();
|
||||
|
||||
protected:
|
||||
|
||||
virtual LLSD exportTempFile();
|
||||
virtual LLUUID finishUpload(LLSD &result);
|
||||
|
||||
private:
|
||||
uploadFinish_f mFinishFn;
|
||||
std::string mBuffer;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue