Skip to content

Commit 9942986

Browse files
committed
#4318 Warn or log when texture gets scaled down
for material and model upload
1 parent 8df303e commit 9942986

File tree

9 files changed

+94
-17
lines changed

9 files changed

+94
-17
lines changed

indra/llprimitive/llmodelloader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ LLModelLoader::LLModelLoader(
123123
, mLod(lod)
124124
, mTrySLM(false)
125125
, mFirstTransform(true)
126-
, mNumOfFetchingTextures(0)
127126
, mLoadCallback(load_cb)
128127
, mJointLookupFunc(joint_lookup_func)
129128
, mTextureLoadFunc(texture_load_func)
@@ -134,6 +133,7 @@ LLModelLoader::LLModelLoader(
134133
, mNoNormalize(false)
135134
, mNoOptimize(false)
136135
, mCacheOnlyHitIfRigged(false)
136+
, mTexturesNeedScaling(false)
137137
, mMaxJointsPerMesh(maxJointsPerMesh)
138138
, mGeneratedModelLimit(modelLimit)
139139
, mDebugMode(debugMode)
@@ -669,7 +669,7 @@ void LLModelLoader::loadTextures()
669669

670670
if(!material.mDiffuseMapFilename.empty())
671671
{
672-
mNumOfFetchingTextures += mTextureLoadFunc(material, mOpaqueData);
672+
mTextureLoadFunc(material, mOpaqueData);
673673
}
674674
}
675675
}

indra/llprimitive/llmodelloader.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class LLModelLoader : public LLThread
109109

110110
bool mTrySLM;
111111
bool mCacheOnlyHitIfRigged; // ignore cached SLM if it does not contain rig info (and we want rig info)
112+
bool mTexturesNeedScaling;
112113

113114
model_list mModelList;
114115
// The scene is pretty much what ends up getting loaded for upload. Basically assign things to this guy if you want something uploaded.
@@ -170,9 +171,6 @@ class LLModelLoader : public LLThread
170171

171172
void stretch_extents(const LLModel* model, const LLMatrix4& mat);
172173

173-
S32 mNumOfFetchingTextures ; // updated in the main thread
174-
bool areTexturesReady() { return !mNumOfFetchingTextures; } // called in the main thread.
175-
176174
bool verifyCount( int expected, int result );
177175

178176
//Determines the viability of an asset to be used as an avatar rig (w or w/o joint upload caps)

indra/newview/gltf/llgltfloader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ LLGLTFLoader::LLGLTFImportMaterial LLGLTFLoader::processMaterial(S32 material_in
611611
LL::GLTF::Image& image = mGLTFAsset.mImages[sourceIndex];
612612
if (image.mTexture.notNull())
613613
{
614+
mTexturesNeedScaling |= image.mHeight > LLViewerTexture::MAX_IMAGE_SIZE_DEFAULT || image.mWidth > LLViewerTexture::MAX_IMAGE_SIZE_DEFAULT;
614615
impMat.setDiffuseMap(image.mTexture->getID());
615616
LL_INFOS("GLTF_IMPORT") << "Using existing texture ID: " << image.mTexture->getID().asString() << LL_ENDL;
616617
}

indra/newview/llfloatermodelpreview.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,26 +1340,26 @@ void LLFloaterModelPreview::addStringToLog(const std::string& message, const LLS
13401340
{
13411341
std::string str;
13421342
switch (lod)
1343-
{
1343+
{
13441344
case LLModel::LOD_IMPOSTOR: str = "LOD0 "; break;
13451345
case LLModel::LOD_LOW: str = "LOD1 "; break;
13461346
case LLModel::LOD_MEDIUM: str = "LOD2 "; break;
13471347
case LLModel::LOD_PHYSICS: str = "PHYS "; break;
13481348
case LLModel::LOD_HIGH: str = "LOD3 "; break;
13491349
default: break;
1350-
}
1350+
}
13511351

13521352
LLStringUtil::format_map_t args_msg;
13531353
LLSD::map_const_iterator iter = args.beginMap();
13541354
LLSD::map_const_iterator end = args.endMap();
13551355
for (; iter != end; ++iter)
1356-
{
1356+
{
13571357
args_msg[iter->first] = iter->second.asString();
13581358
}
13591359
str += sInstance->getString(message, args_msg);
13601360
sInstance->addStringToLogTab(str, flash);
13611361
}
1362-
}
1362+
}
13631363

13641364
// static
13651365
void LLFloaterModelPreview::addStringToLog(const std::string& str, bool flash)

indra/newview/llmaterialeditor.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,6 +2479,42 @@ void LLMaterialEditor::loadMaterial(const tinygltf::Model &model_in, const std::
24792479
pack_textures(base_color_img, normal_img, mr_img, emissive_img, occlusion_img,
24802480
mBaseColorJ2C, mNormalJ2C, mMetallicRoughnessJ2C, mEmissiveJ2C);
24812481

2482+
if (open_floater)
2483+
{
2484+
bool textures_scaled = false;
2485+
if (mBaseColorFetched && mBaseColorJ2C
2486+
&& (mBaseColorFetched->getWidth() != mBaseColorJ2C->getWidth()
2487+
|| mBaseColorFetched->getHeight() != mBaseColorJ2C->getHeight()))
2488+
{
2489+
textures_scaled = true;
2490+
}
2491+
else if (mNormalFetched && mNormalJ2C
2492+
&& (mNormalFetched->getWidth() != mNormalJ2C->getWidth()
2493+
|| mNormalFetched->getHeight() != mNormalJ2C->getHeight()))
2494+
{
2495+
textures_scaled = true;
2496+
}
2497+
else if (mMetallicRoughnessFetched && mMetallicRoughnessJ2C
2498+
&& (mMetallicRoughnessFetched->getWidth() != mMetallicRoughnessJ2C->getWidth()
2499+
|| mMetallicRoughnessFetched->getHeight() != mMetallicRoughnessJ2C->getHeight()))
2500+
{
2501+
textures_scaled = true;
2502+
}
2503+
else if (mEmissiveFetched && mEmissiveJ2C
2504+
&& (mEmissiveFetched->getWidth() != mEmissiveJ2C->getWidth()
2505+
|| mEmissiveFetched->getHeight() != mEmissiveJ2C->getHeight()))
2506+
{
2507+
textures_scaled = true;
2508+
}
2509+
2510+
if (textures_scaled)
2511+
{
2512+
LLSD args;
2513+
args["MAX_SIZE"] = LLViewerTexture::MAX_IMAGE_SIZE_DEFAULT;
2514+
LLNotificationsUtil::add("MaterialImagesWereScaled", args);
2515+
}
2516+
}
2517+
24822518
LLUUID base_color_id;
24832519
if (mBaseColorFetched.notNull())
24842520
{

indra/newview/llmodelpreview.cpp

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ LLModelPreview::LLModelPreview(S32 width, S32 height, LLFloater* fmp)
169169
, mLastJointUpdate(false)
170170
, mFirstSkinUpdate(true)
171171
, mHasDegenerate(false)
172+
, mNumOfFetchingTextures(0)
173+
, mTexturesNeedScaling(false)
172174
, mImporterDebug(LLCachedControl<bool>(gSavedSettings, "ImporterDebugVerboseLogging", false))
173175
{
174176
mNeedsUpdate = true;
@@ -559,10 +561,7 @@ void LLModelPreview::rebuildUploadData()
559561
texture->setLoadedCallback(LLModelPreview::textureLoadedCallback, 0, true, false, new LLHandle<LLModelPreview>(getHandle()), &mCallbackTextureList, false);
560562
texture->forceToSaveRawImage(0, F32_MAX);
561563
texture->updateFetch();
562-
if (mModelLoader)
563-
{
564-
mModelLoader->mNumOfFetchingTextures++;
565-
}
564+
mNumOfFetchingTextures++;
566565
}
567566
}
568567
}
@@ -997,7 +996,9 @@ void LLModelPreview::loadModelCallback(S32 loaded_lod)
997996
setRigValidForJointPositionUpload(mModelLoader->isRigValidForJointPositionUpload());
998997
setLegacyRigFlags(mModelLoader->getLegacyRigFlags());
999998

999+
mTexturesNeedScaling |= mModelLoader->mTexturesNeedScaling;
10001000
mModelLoader->loadTextures();
1001+
warnTextureScaling();
10011002

10021003
if (loaded_lod == -1)
10031004
{ //populate all LoDs from model loader scene
@@ -2510,7 +2511,7 @@ void LLModelPreview::updateStatusMessages()
25102511
LLMutexLock lock(this);
25112512
if (mModelLoader)
25122513
{
2513-
if (!mModelLoader->areTexturesReady() && mFMP->childGetValue("upload_textures").asBoolean())
2514+
if (!areTexturesReady() && mFMP->childGetValue("upload_textures").asBoolean())
25142515
{
25152516
// Some textures are still loading, prevent upload until they are done
25162517
mModelNoErrors = false;
@@ -3216,6 +3217,7 @@ U32 LLModelPreview::loadTextures(LLImportMaterial& material, LLHandle<LLModelPre
32163217
tex->setLoadedCallback(LLModelPreview::textureLoadedCallback, 0, true, false, new LLHandle<LLModelPreview>(handle), &preview->mCallbackTextureList, false);
32173218
tex->forceToSaveRawImage(0, F32_MAX);
32183219
material.setDiffuseMap(tex->getID()); // record tex ID
3220+
preview->mNumOfFetchingTextures++;
32193221
return 1;
32203222
}
32213223

@@ -4060,6 +4062,18 @@ void LLModelPreview::setPreviewLOD(S32 lod)
40604062
updateStatusMessages();
40614063
}
40624064

4065+
void LLModelPreview::warnTextureScaling()
4066+
{
4067+
if (areTexturesReady() && mTexturesNeedScaling)
4068+
{
4069+
std::ostringstream out;
4070+
out << "One or more textures in this model were scaled to be within the allowed limits.";
4071+
LL_INFOS() << out.str() << LL_ENDL;
4072+
LLSD args;
4073+
LLFloaterModelPreview::addStringToLog("ModelTextureScaling", args, true, -1);
4074+
}
4075+
}
4076+
40634077
//static
40644078
void LLModelPreview::textureLoadedCallback(
40654079
bool success,
@@ -4080,11 +4094,19 @@ void LLModelPreview::textureLoadedCallback(
40804094
LLModelPreview* preview = static_cast<LLModelPreview*>(handle->get());
40814095
preview->refresh();
40824096

4083-
if (final && preview->mModelLoader)
4097+
if (final)
40844098
{
4085-
if (preview->mModelLoader->mNumOfFetchingTextures > 0)
4099+
if (src_vi
4100+
&& (src_vi->getOriginalWidth() > LLViewerFetchedTexture::MAX_IMAGE_SIZE_DEFAULT
4101+
|| src_vi->getOriginalHeight() > LLViewerFetchedTexture::MAX_IMAGE_SIZE_DEFAULT))
4102+
{
4103+
preview->mTexturesNeedScaling = true;
4104+
}
4105+
4106+
if (preview->mNumOfFetchingTextures > 0)
40864107
{
4087-
preview->mModelLoader->mNumOfFetchingTextures--;
4108+
preview->mNumOfFetchingTextures--;
4109+
preview->warnTextureScaling();
40884110
}
40894111
}
40904112
}

indra/newview/llmodelpreview.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ class LLModelPreview : public LLViewerDynamicTexture, public LLMutex, public LLH
204204
std::vector<S32> mLodsQuery;
205205
std::vector<S32> mLodsWithParsingError;
206206
bool mHasDegenerate;
207+
bool areTexturesReady() { return !mNumOfFetchingTextures; }
207208

208209
protected:
209210

@@ -213,6 +214,7 @@ class LLModelPreview : public LLViewerDynamicTexture, public LLMutex, public LLH
213214
static LLJoint* lookupJointByName(const std::string&, void* opaque);
214215
static U32 loadTextures(LLImportMaterial& material, LLHandle<LLModelPreview> handle);
215216

217+
void warnTextureScaling();
216218
void lookupLODModelFiles(S32 lod);
217219

218220
private:
@@ -242,6 +244,9 @@ class LLModelPreview : public LLViewerDynamicTexture, public LLMutex, public LLH
242244
/// Not read unless mWarnOfUnmatchedPhyicsMeshes is true.
243245
LLPointer<LLModel> mDefaultPhysicsShapeP;
244246

247+
S32 mNumOfFetchingTextures;
248+
bool mTexturesNeedScaling;
249+
245250
typedef enum
246251
{
247252
MESH_OPTIMIZER_FULL,

indra/newview/skins/default/xui/en/floater_model_preview.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
<string name="decomposing">Analyzing...</string>
4040
<string name="simplifying">Simplifying...</string>
4141
<string name="tbd">TBD</string>
42+
<string name="ModelTextureScaling">One or more textures in this model were scaled to be within the allowed limits.</string>
4243

4344
<!-- Warnings and info from model loader-->
4445
<string name="TooManyJoint">Skinning disabled due to too many joints: [JOINTS], maximum: [MAX]</string>

indra/newview/skins/default/xui/en/notifications.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7135,6 +7135,20 @@ You don&apos;t have permission to view this notecard.
71357135
<tag>fail</tag>
71367136
</notification>
71377137

7138+
<notification
7139+
icon="alertmodal.tga"
7140+
name="MaterialImagesWereScaled"
7141+
type="alertmodal">
7142+
One or more textures in this material were scaled to be within the allowed limits.
7143+
Textures must have power of two dimensions and must not exceed [MAX_SIZE]x[MAX_SIZE] pixels.
7144+
<unique/>
7145+
<tag>confirm</tag>
7146+
<usetemplate
7147+
ignoretext="Warn if textures will be scaled during upload."
7148+
name="okignore"
7149+
yestext="OK"/>
7150+
</notification>
7151+
71387152
<notification
71397153
icon="notifytip.tga"
71407154
name="RezItemNoPermissions"

0 commit comments

Comments
 (0)