summaryrefslogtreecommitdiff
path: root/indra/newview/lllocalrendermaterials.cpp
blob: aada61a056981f8ad2daec4c2d85dbe6bb9b0483 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
/** 
 * @file lllocalrendermaterials.cpp
 * @brief Local GLTF materials source
 *
 * $LicenseInfo:firstyear=2022&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2022, Linden Research, Inc.
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License only.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * 
 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 * $/LicenseInfo$
 */

/* precompiled headers */
#include "llviewerprecompiledheaders.h"

/* own header */
#include "lllocalrendermaterials.h"

/* boost: will not compile unless equivalent is undef'd, beware. */
#include "fix_macros.h"
#include <boost/filesystem.hpp>

/* time headers */
#include <time.h>
#include <ctime>

/* misc headers */
#include "llagentwearables.h"
#include "llface.h"
#include "llfilepicker.h"
#include "llgltfmateriallist.h"
#include "llimagedimensionsinfo.h"
#include "lllocaltextureobject.h"
#include "llmaterialmgr.h"
#include "llnotificationsutil.h"
#include "llscrolllistctrl.h"
#include "lltexlayerparams.h"
#include "lltinygltfhelper.h"
#include "lltrans.h"
#include "llviewercontrol.h"
#include "llviewerdisplay.h"
#include "llviewerobjectlist.h"
#include "llviewerobject.h"
#include "llviewerwearable.h"
#include "llvoavatarself.h"
#include "llvovolume.h"
#include "pipeline.h"
#include "tinygltf/tiny_gltf.h"

/*=======================================*/
/*  Formal declarations, constants, etc. */
/*=======================================*/ 

static const F32 LL_LOCAL_TIMER_HEARTBEAT   = 3.0;
static const BOOL LL_LOCAL_USE_MIPMAPS      = true;
static const S32 LL_LOCAL_DISCARD_LEVEL     = 0;
static const bool LL_LOCAL_SLAM_FOR_DEBUG   = true;
static const bool LL_LOCAL_REPLACE_ON_DEL   = true;
static const S32 LL_LOCAL_UPDATE_RETRIES    = 5;

/*=======================================*/
/*  LLLocalGLTFMaterial: unit class            */
/*=======================================*/ 
LLLocalGLTFMaterial::LLLocalGLTFMaterial(std::string filename)
	: mFilename(filename)
	, mShortName(gDirUtilp->getBaseFileName(filename, true))
	, mValid(false)
	, mLastModified()
	, mLinkStatus(LS_ON)
	, mUpdateRetries(LL_LOCAL_UPDATE_RETRIES)
{
	mTrackingID.generate();

	/* extension */
	std::string temp_exten = gDirUtilp->getExtension(mFilename);

	if (temp_exten == "gltf")
	{ 
		mExtension = ET_MATERIAL_GLTF;
	}
	else if (temp_exten == "glb")
	{
		mExtension = ET_MATERIAL_GLB;
	}
	else
	{
		LL_WARNS() << "File of no valid extension given, local material creation aborted." << "\n"
			    << "Filename: " << mFilename << LL_ENDL;
		return; // no valid extension.
	}

	/* next phase of unit creation is nearly the same as an update cycle.
	   we're running updateSelf as a special case with the optional UT_FIRSTUSE
	   which omits the parts associated with removing the outdated texture */
	mValid = updateSelf(UT_FIRSTUSE);
}

LLLocalGLTFMaterial::~LLLocalGLTFMaterial()
{
	// replace IDs with defaults, if set to do so.
	if(LL_LOCAL_REPLACE_ON_DEL && mValid && gAgentAvatarp) // fix for STORM-1837
	{
		replaceIDs(mWorldID, IMG_DEFAULT);
		LLLocalGLTFMaterialMgr::getInstance()->doRebake();
	}

	// delete self from material list
    gGLTFMaterialList.removeMaterial(mWorldID);
}

/* accessors */
std::string LLLocalGLTFMaterial::getFilename()
{
	return mFilename;
}

std::string LLLocalGLTFMaterial::getShortName()
{
	return mShortName;
}

LLUUID LLLocalGLTFMaterial::getTrackingID()
{
	return mTrackingID;
}

LLUUID LLLocalGLTFMaterial::getWorldID()
{
	return mWorldID;
}

bool LLLocalGLTFMaterial::getValid()
{
	return mValid;
}

/* update functions */
bool LLLocalGLTFMaterial::updateSelf(EUpdateType optional_firstupdate)
{
	bool updated = false;
	
	if (mLinkStatus == LS_ON)
	{
		// verifying that the file exists
		if (gDirUtilp->fileExists(mFilename))
		{
			// verifying that the file has indeed been modified

#ifndef LL_WINDOWS
			const std::time_t temp_time = boost::filesystem::last_write_time(boost::filesystem::path(mFilename));
#else
			const std::time_t temp_time = boost::filesystem::last_write_time(boost::filesystem::path(utf8str_to_utf16str(mFilename)));
#endif
			LLSD new_last_modified = asctime(localtime(&temp_time));

			if (mLastModified.asString() != new_last_modified.asString())
			{
				LLPointer<LLGLTFMaterial> raw_material = new LLGLTFMaterial();
				if (loadMaterial(raw_material))
				{
					// decode is successful, we can safely proceed.
					LLUUID old_id = LLUUID::null;
					if ((optional_firstupdate != UT_FIRSTUSE) && !mWorldID.isNull())
					{
						old_id = mWorldID;
					}
					mWorldID.generate();
					mLastModified = new_last_modified;

                    gGLTFMaterialList.addMaterial(mWorldID, raw_material);
			
					if (optional_firstupdate != UT_FIRSTUSE)
					{
						// seek out everything old_id uses and replace it with mWorldID
						replaceIDs(old_id, mWorldID);

						// remove old_id from material list
                        gGLTFMaterialList.removeMaterial(old_id);
					}

					mUpdateRetries = LL_LOCAL_UPDATE_RETRIES;
					updated = true;
				}

				// if decoding failed, we get here and it will attempt to decode it in the next cycles
				// until mUpdateRetries runs out. this is done because some software lock the material while writing to it
				else
				{
					if (mUpdateRetries)
					{
						mUpdateRetries--;
					}
					else
					{
						LL_WARNS() << "During the update process the following file was found" << "\n"
							    << "but could not be opened or decoded for " << LL_LOCAL_UPDATE_RETRIES << " attempts." << "\n"
								<< "Filename: " << mFilename << "\n"
								<< "Disabling further update attempts for this file." << LL_ENDL;

						LLSD notif_args;
						notif_args["FNAME"] = mFilename;
						notif_args["NRETRIES"] = LL_LOCAL_UPDATE_RETRIES;
						LLNotificationsUtil::add("LocalBitmapsUpdateFailedFinal", notif_args);

						mLinkStatus = LS_BROKEN;
					}
				}		
			}
			
		} // end if file exists

		else
		{
			LL_WARNS() << "During the update process, the following file was not found." << "\n" 
			        << "Filename: " << mFilename << "\n"
				    << "Disabling further update attempts for this file." << LL_ENDL;

			LLSD notif_args;
			notif_args["FNAME"] = mFilename;
			LLNotificationsUtil::add("LocalBitmapsUpdateFileNotFound", notif_args);

			mLinkStatus = LS_BROKEN;
		}
	}

	return updated;
}

bool LLLocalGLTFMaterial::loadMaterial(LLPointer<LLGLTFMaterial> mat)
{
    bool decode_successful = false;

    switch (mExtension)
    {
    case ET_MATERIAL_GLTF:
    case ET_MATERIAL_GLB:
    {
            tinygltf::TinyGLTF loader;
            std::string        error_msg;
            std::string        warn_msg;

            tinygltf::Model model_in;

            std::string filename_lc = mFilename;
            LLStringUtil::toLower(filename_lc);

            // Load a tinygltf model fom a file. Assumes that the input filename has already been
            // been sanitized to one of (.gltf , .glb) extensions, so does a simple find to distinguish.
            if (std::string::npos == filename_lc.rfind(".gltf"))
            {  // file is binary
                decode_successful = loader.LoadBinaryFromFile(&model_in, &error_msg, &warn_msg, filename_lc);
            }
            else
            {  // file is ascii
                decode_successful = loader.LoadASCIIFromFile(&model_in, &error_msg, &warn_msg, filename_lc);
            }

            if (!decode_successful)
            {
                LL_WARNS() << "Cannot Upload Material, error: " << error_msg
                    << ", warning:" << warn_msg
                    << " file: " << mFilename
                    << LL_ENDL;
                break;
            }

            if (model_in.materials.empty())
            {
                // materials are missing
                LL_WARNS() << "Cannot Upload Material, Material missing, " << mFilename << LL_ENDL;
                decode_successful = false;
                break;
            }

            // sets everything, but textures will have inaccurate ids
            LLTinyGLTFHelper::setFromModel(mat, model_in);

            std::string folder = gDirUtilp->getDirName(filename_lc);
            tinygltf::Material material_in = model_in.materials[0];

            // get albedo texture
            LLPointer<LLImageRaw> albedo_img = LLTinyGLTFHelper::getTexture(folder, model_in, material_in.pbrMetallicRoughness.baseColorTexture.index);
            // get normal map
            LLPointer<LLImageRaw> normal_img = LLTinyGLTFHelper::getTexture(folder, model_in, material_in.normalTexture.index);
            // get metallic-roughness texture
            LLPointer<LLImageRaw> mr_img = LLTinyGLTFHelper::getTexture(folder, model_in, material_in.pbrMetallicRoughness.metallicRoughnessTexture.index);
            // get emissive texture
            LLPointer<LLImageRaw> emissive_img = LLTinyGLTFHelper::getTexture(folder, model_in, material_in.emissiveTexture.index);
            // get occlusion map if needed
            LLPointer<LLImageRaw> occlusion_img;
            if (material_in.occlusionTexture.index != material_in.pbrMetallicRoughness.metallicRoughnessTexture.index)
            {
                occlusion_img = LLTinyGLTFHelper::getTexture(folder, model_in, material_in.occlusionTexture.index);
            }

            // todo: pass it into local bitmaps?
            LLTinyGLTFHelper::initFetchedTextures(material_in,
                albedo_img, normal_img, mr_img, emissive_img, occlusion_img,
                mAlbedoFetched, mNormalFetched, mMRFetched, mEmissiveFetched);

            mat->mAlbedoId = mAlbedoFetched->getID();
            mat->mNormalId = mNormalFetched->getID();
            mat->mMetallicRoughnessId = mMRFetched->getID();
            mat->mEmissiveId = mEmissiveFetched->getID();

            break;
        }

        default:
        {
            // separating this into -several- LL_WARNS() calls because in the extremely unlikely case that this happens
            // accessing mFilename and any other object properties might very well crash the viewer.
            // getting here should be impossible, or there's been a pretty serious bug.

            LL_WARNS() << "During a decode attempt, the following local material had no properly assigned extension." << LL_ENDL;
            LL_WARNS() << "Filename: " << mFilename << LL_ENDL;
            LL_WARNS() << "Disabling further update attempts for this file." << LL_ENDL;
            mLinkStatus = LS_BROKEN;
        }
    }

    return decode_successful;
}

void LLLocalGLTFMaterial::replaceIDs(LLUUID old_id, LLUUID new_id)
{
    // checking for misuse.
    if (old_id == new_id)
    {
        LL_INFOS() << "An attempt was made to replace a texture with itself. (matching UUIDs)" << "\n"
            << "Texture UUID: " << old_id.asString() << LL_ENDL;
        return;
    }

    // processing updates per channel; makes the process scalable.
    // the only actual difference is in SetTE* call i.e. SetTETexture, SetTENormal, etc.
    updateUserPrims(old_id, new_id, LLRender::DIFFUSE_MAP);
    updateUserPrims(old_id, new_id, LLRender::NORMAL_MAP);
    updateUserPrims(old_id, new_id, LLRender::SPECULAR_MAP);

    // default safeguard image for layers
    if (new_id == IMG_DEFAULT)
    {
        new_id = IMG_DEFAULT_AVATAR;
    }
}

// this function sorts the faces from a getFaceList[getNumFaces] into a list of objects
// in order to prevent multiple sendTEUpdate calls per object during updateUserPrims
std::vector<LLViewerObject*> LLLocalGLTFMaterial::prepUpdateObjects(LLUUID old_id, U32 channel)
{
    std::vector<LLViewerObject*> obj_list;
    // todo: find a way to update materials
    /*
    LLGLTFMaterial* old_material = gGLTFMaterialList.getMaterial(old_id);

    for(U32 face_iterator = 0; face_iterator < old_texture->getNumFaces(channel); face_iterator++)
    {
        // getting an object from a face
        LLFace* face_to_object = (*old_texture->getFaceList(channel))[face_iterator];

        if(face_to_object)
        {
            LLViewerObject* affected_object = face_to_object->getViewerObject();

            if(affected_object)
            {

                // we have an object, we'll take it's UUID and compare it to
                // whatever we already have in the returnable object list.
                // if there is a match - we do not add (to prevent duplicates)
                LLUUID mainlist_obj_id = affected_object->getID();
                bool add_object = true;

                // begin looking for duplicates
                std::vector<LLViewerObject*>::iterator objlist_iter = obj_list.begin();
                for(; (objlist_iter != obj_list.end()) && add_object; objlist_iter++)
                {
                    LLViewerObject* obj = *objlist_iter;
                    if (obj->getID() == mainlist_obj_id)
                    {
                        add_object = false; // duplicate found.
                    }
                }
                // end looking for duplicates

                if(add_object)
                {
                    obj_list.push_back(affected_object);
                }

            }

        }

    } // end of face-iterating for()

    */
    return obj_list;
}

void LLLocalGLTFMaterial::updateUserPrims(LLUUID old_id, LLUUID new_id, U32 channel)
{
    /*std::vector<LLViewerObject*> objectlist = prepUpdateObjects(old_id, channel);
    for(std::vector<LLViewerObject*>::iterator object_iterator = objectlist.begin();
        object_iterator != objectlist.end(); object_iterator++)
    {
        LLViewerObject* object = *object_iterator;

        if(object)
        {
            bool update_tex = false;
            bool update_mat = false;
            S32 num_faces = object->getNumFaces();

            for (U8 face_iter = 0; face_iter < num_faces; face_iter++)
            {
                if (object->mDrawable)
                {
                    LLFace* face = object->mDrawable->getFace(face_iter);
                    if (face && face->getTexture(channel) && face->getTexture(channel)->getID() == old_id)
                    {
                        // these things differ per channel, unless there already is a universal
                        // texture setting function to setTE that takes channel as a param?
                        // p.s.: switch for now, might become if - if an extra test is needed to verify before touching normalmap/specmap
                        switch(channel)
                        {
                            case LLRender::DIFFUSE_MAP:
                    {
                                object->setTETexture(face_iter, new_id);
                                update_tex = true;
                                break;
                            }

                            case LLRender::NORMAL_MAP:
                            {
                                object->setTENormalMap(face_iter, new_id);
                                update_mat = true;
                                update_tex = true;
                                break;
                            }

                            case LLRender::SPECULAR_MAP:
                            {
                                object->setTESpecularMap(face_iter, new_id);
                                update_mat = true;
                                update_tex = true;
                                break;
                            }
                        }
                        // end switch

                    }
                }
            }

            if (update_tex)
            {
                object->sendTEUpdate();
            }

            if (update_mat)
            {
                object->mDrawable->getVOVolume()->faceMappingChanged();
            }
        }
    }
    */
}

/*=======================================*/
/*  LLLocalGLTFMaterialTimer: timer class      */
/*=======================================*/
LLLocalGLTFMaterialTimer::LLLocalGLTFMaterialTimer() : LLEventTimer(LL_LOCAL_TIMER_HEARTBEAT)
{
}

LLLocalGLTFMaterialTimer::~LLLocalGLTFMaterialTimer()
{
}

void LLLocalGLTFMaterialTimer::startTimer()
{
    mEventTimer.start();
}

void LLLocalGLTFMaterialTimer::stopTimer()
{
    mEventTimer.stop();
}

bool LLLocalGLTFMaterialTimer::isRunning()
{
    return mEventTimer.getStarted();
}

BOOL LLLocalGLTFMaterialTimer::tick()
{
    // todo: do on idle? No point in timer 
    LLLocalGLTFMaterialMgr::getInstance()->doUpdates();
    return FALSE;
}

/*=======================================*/
/*  LLLocalGLTFMaterialMgr: manager class      */
/*=======================================*/
LLLocalGLTFMaterialMgr::LLLocalGLTFMaterialMgr()
{
}

LLLocalGLTFMaterialMgr::~LLLocalGLTFMaterialMgr()
{
    std::for_each(mMaterialList.begin(), mMaterialList.end(), DeletePointer());
    mMaterialList.clear();
}

bool LLLocalGLTFMaterialMgr::addUnit()
{
    bool add_successful = false;

    LLFilePicker& picker = LLFilePicker::instance();
    if (picker.getMultipleOpenFiles(LLFilePicker::FFLOAD_IMAGE))
    {
        mTimer.stopTimer();

        std::string filename = picker.getFirstFile();
        while (!filename.empty())
        {
            if (!checkTextureDimensions(filename))
            {
                filename = picker.getNextFile();
                continue;
            }

            LLLocalGLTFMaterial* unit = new LLLocalGLTFMaterial(filename);

            if (unit->getValid())
            {
                mMaterialList.push_back(unit);
                add_successful = true;
            }
            else
            {
                LL_WARNS() << "Attempted to add invalid or unreadable image file, attempt cancelled.\n"
                    << "Filename: " << filename << LL_ENDL;

                LLSD notif_args;
                notif_args["FNAME"] = filename;
                LLNotificationsUtil::add("LocalBitmapsVerifyFail", notif_args);

                delete unit;
                unit = NULL;
            }

            filename = picker.getNextFile();
        }

        mTimer.startTimer();
    }

    return add_successful;
}

bool LLLocalGLTFMaterialMgr::checkTextureDimensions(std::string filename)
{
    std::string exten = gDirUtilp->getExtension(filename);
    U32 codec = LLImageBase::getCodecFromExtension(exten);
    std::string mImageLoadError;
    LLImageDimensionsInfo image_info;
    if (!image_info.load(filename, codec))
    {
        return false;
    }

    S32 max_width = gSavedSettings.getS32("max_texture_dimension_X");
    S32 max_height = gSavedSettings.getS32("max_texture_dimension_Y");

    if ((image_info.getWidth() > max_width) || (image_info.getHeight() > max_height))
    {
        LLStringUtil::format_map_t args;
        args["WIDTH"] = llformat("%d", max_width);
        args["HEIGHT"] = llformat("%d", max_height);
        mImageLoadError = LLTrans::getString("texture_load_dimensions_error", args);

        LLSD notif_args;
        notif_args["REASON"] = mImageLoadError;
        LLNotificationsUtil::add("CannotUploadTexture", notif_args);

        return false;
    }

    return true;
}

void LLLocalGLTFMaterialMgr::delUnit(LLUUID tracking_id)
{
    if (!mMaterialList.empty())
    {
        std::vector<LLLocalGLTFMaterial*> to_delete;
        for (local_list_iter iter = mMaterialList.begin(); iter != mMaterialList.end(); iter++)
        {   /* finding which ones we want deleted and making a separate list */
            LLLocalGLTFMaterial* unit = *iter;
            if (unit->getTrackingID() == tracking_id)
            {
                to_delete.push_back(unit);
            }
        }

        for (std::vector<LLLocalGLTFMaterial*>::iterator del_iter = to_delete.begin();
            del_iter != to_delete.end(); del_iter++)
        {   /* iterating over a temporary list, hence preserving the iterator validity while deleting. */
            LLLocalGLTFMaterial* unit = *del_iter;
            mMaterialList.remove(unit);
            delete unit;
            unit = NULL;
        }
    }
}

LLUUID LLLocalGLTFMaterialMgr::getWorldID(LLUUID tracking_id)
{
    LLUUID world_id = LLUUID::null;

    for (local_list_iter iter = mMaterialList.begin(); iter != mMaterialList.end(); iter++)
    {
        LLLocalGLTFMaterial* unit = *iter;
        if (unit->getTrackingID() == tracking_id)
        {
            world_id = unit->getWorldID();
        }
    }

    return world_id;
}

bool LLLocalGLTFMaterialMgr::isLocal(const LLUUID world_id)
{
    for (local_list_iter iter = mMaterialList.begin(); iter != mMaterialList.end(); iter++)
    {
        LLLocalGLTFMaterial* unit = *iter;
        if (unit->getWorldID() == world_id)
        {
            return true;
        }
    }
    return false;
}

std::string LLLocalGLTFMaterialMgr::getFilename(LLUUID tracking_id)
{
    std::string filename = "";

    for (local_list_iter iter = mMaterialList.begin(); iter != mMaterialList.end(); iter++)
    {
        LLLocalGLTFMaterial* unit = *iter;
        if (unit->getTrackingID() == tracking_id)
        {
            filename = unit->getFilename();
        }
    }

    return filename;
}

void LLLocalGLTFMaterialMgr::feedScrollList(LLScrollListCtrl* ctrl)
{
    if (ctrl)
    {
        ctrl->clearRows();

        if (!mMaterialList.empty())
        {
            for (local_list_iter iter = mMaterialList.begin();
                iter != mMaterialList.end(); iter++)
            {
                LLSD element;
                element["columns"][0]["column"] = "unit_name";
                element["columns"][0]["type"] = "text";
                element["columns"][0]["value"] = (*iter)->getShortName();

                element["columns"][1]["column"] = "unit_id_HIDDEN";
                element["columns"][1]["type"] = "text";
                element["columns"][1]["value"] = (*iter)->getTrackingID();

                ctrl->addElement(element);
            }
        }
    }

}

void LLLocalGLTFMaterialMgr::doUpdates()
{
    // preventing theoretical overlap in cases with huge number of loaded images.
    mTimer.stopTimer();
    mNeedsRebake = false;

    for (local_list_iter iter = mMaterialList.begin(); iter != mMaterialList.end(); iter++)
    {
        (*iter)->updateSelf();
    }

    doRebake();
    mTimer.startTimer();
}

void LLLocalGLTFMaterialMgr::setNeedsRebake()
{
    mNeedsRebake = true;
}

void LLLocalGLTFMaterialMgr::doRebake()
{ /* separated that from doUpdates to insure a rebake can be called separately during deletion */
    if (mNeedsRebake)
    {
        gAgentAvatarp->forceBakeAllTextures(LL_LOCAL_SLAM_FOR_DEBUG);
        mNeedsRebake = false;
    }
}