summaryrefslogtreecommitdiff
path: root/indra/newview/lltinygltfhelper.cpp
diff options
context:
space:
mode:
authorAndrey Kleshchev <andreykproductengine@lindenlab.com>2022-12-01 21:54:49 +0200
committerakleshchev <117672381+akleshchev@users.noreply.github.com>2022-12-02 10:24:23 +0200
commit321c7895d00b0b88675c06b8f1cef063632fd686 (patch)
treec78231946ad099b8ca4bacc5007993cd97268a4e /indra/newview/lltinygltfhelper.cpp
parentc0f598c10376f12310660a729f4a763dbf46368e (diff)
SL-18741 Basic bulk upload for gltf materials #1
Diffstat (limited to 'indra/newview/lltinygltfhelper.cpp')
-rw-r--r--indra/newview/lltinygltfhelper.cpp53
1 files changed, 51 insertions, 2 deletions
diff --git a/indra/newview/lltinygltfhelper.cpp b/indra/newview/lltinygltfhelper.cpp
index 05587af9bc..838524e910 100644
--- a/indra/newview/lltinygltfhelper.cpp
+++ b/indra/newview/lltinygltfhelper.cpp
@@ -182,12 +182,62 @@ LLImageRaw * LLTinyGLTFHelper::getTexture(const std::string & folder, const tiny
return rawImage;
}
+S32 LLTinyGLTFHelper::getMaterialCountFromFile(const std::string& filename)
+{
+ std::string exten = gDirUtilp->getExtension(filename);
+ S32 materials_in_file = 0;
+
+ if (exten == "gltf" || exten == "glb")
+ {
+ tinygltf::TinyGLTF loader;
+ std::string error_msg;
+ std::string warn_msg;
+
+ tinygltf::Model model_in;
+
+ std::string filename_lc = filename;
+ 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.
+ bool decode_successful = false;
+ 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("GLTF") << "Cannot load, error: Failed to decode" << error_msg
+ << ", warning:" << warn_msg
+ << " file: " << filename
+ << LL_ENDL;
+ return 0;
+ }
+
+ if (model_in.materials.empty())
+ {
+ // materials are missing
+ LL_WARNS("GLTF") << "Cannot load. File has no materials " << filename << LL_ENDL;
+ return 0;
+ }
+ materials_in_file = model_in.materials.size();
+ }
+ return materials_in_file;
+}
+
bool LLTinyGLTFHelper::getMaterialFromFile(
const std::string& filename,
S32 mat_index,
- LLPointer < LLFetchedGLTFMaterial> material,
+ LLFetchedGLTFMaterial* material,
std::string& material_name)
{
+ llassert(material);
+
tinygltf::TinyGLTF loader;
std::string error_msg;
std::string warn_msg;
@@ -304,5 +354,4 @@ bool LLTinyGLTFHelper::getMaterialFromFile(
}
return true;
-
}