Skip to content

Commit bdd00e7

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

File tree

7 files changed

+93
-13
lines changed

7 files changed

+93
-13
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/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: 34 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,12 @@ void LLModelPreview::loadModelCallback(S32 loaded_lod)
997996
setRigValidForJointPositionUpload(mModelLoader->isRigValidForJointPositionUpload());
998997
setLegacyRigFlags(mModelLoader->getLegacyRigFlags());
999998

999+
mTexturesNeedScaling |= mModelLoader->mTexturesNeedScaling;
10001000
mModelLoader->loadTextures();
1001+
if (areTexturesReady() && mTexturesNeedScaling)
1002+
{
1003+
warnTextureScaling();
1004+
}
10011005

10021006
if (loaded_lod == -1)
10031007
{ //populate all LoDs from model loader scene
@@ -2510,7 +2514,7 @@ void LLModelPreview::updateStatusMessages()
25102514
LLMutexLock lock(this);
25112515
if (mModelLoader)
25122516
{
2513-
if (!mModelLoader->areTexturesReady() && mFMP->childGetValue("upload_textures").asBoolean())
2517+
if (!areTexturesReady() && mFMP->childGetValue("upload_textures").asBoolean())
25142518
{
25152519
// Some textures are still loading, prevent upload until they are done
25162520
mModelNoErrors = false;
@@ -3216,6 +3220,7 @@ U32 LLModelPreview::loadTextures(LLImportMaterial& material, LLHandle<LLModelPre
32163220
tex->setLoadedCallback(LLModelPreview::textureLoadedCallback, 0, true, false, new LLHandle<LLModelPreview>(handle), &preview->mCallbackTextureList, false);
32173221
tex->forceToSaveRawImage(0, F32_MAX);
32183222
material.setDiffuseMap(tex->getID()); // record tex ID
3223+
preview->mNumOfFetchingTextures++;
32193224
return 1;
32203225
}
32213226

@@ -4060,6 +4065,15 @@ void LLModelPreview::setPreviewLOD(S32 lod)
40604065
updateStatusMessages();
40614066
}
40624067

4068+
//static
4069+
void LLModelPreview::warnTextureScaling()
4070+
{
4071+
std::ostringstream out;
4072+
out << "One or more textures in this model were scaled to be within the allowed limits.";
4073+
LL_INFOS() << out.str() << LL_ENDL;
4074+
LLFloaterModelPreview::addStringToLog(out, false);
4075+
}
4076+
40634077
//static
40644078
void LLModelPreview::textureLoadedCallback(
40654079
bool success,
@@ -4080,11 +4094,23 @@ 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+
if (preview->mNumOfFetchingTextures == 0
4110+
&& preview->mTexturesNeedScaling)
4111+
{
4112+
warnTextureScaling();
4113+
}
40884114
}
40894115
}
40904116
}

indra/newview/llmodelpreview.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,11 @@ 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

211+
static void warnTextureScaling();
210212
static void loadedCallback(LLModelLoader::scene& scene, LLModelLoader::model_list& model_list, S32 lod, void* opaque);
211213
static void stateChangedCallback(U32 state, void* opaque);
212214

@@ -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/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)