diff options
Diffstat (limited to 'indra/newview/lltinygltfhelper.cpp')
-rw-r--r-- | indra/newview/lltinygltfhelper.cpp | 53 |
1 files changed, 13 insertions, 40 deletions
diff --git a/indra/newview/lltinygltfhelper.cpp b/indra/newview/lltinygltfhelper.cpp index 1a8e868d11..999be07dba 100644 --- a/indra/newview/lltinygltfhelper.cpp +++ b/indra/newview/lltinygltfhelper.cpp @@ -183,19 +183,16 @@ LLImageRaw * LLTinyGLTFHelper::getTexture(const std::string & folder, const tiny return rawImage; } -S32 LLTinyGLTFHelper::getMaterialCountFromFile(const std::string& filename) +bool LLTinyGLTFHelper::loadModel(const std::string& filename, tinygltf::Model& model_in) { 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); @@ -217,57 +214,33 @@ S32 LLTinyGLTFHelper::getMaterialCountFromFile(const std::string& filename) << ", warning:" << warn_msg << " file: " << filename << LL_ENDL; - return 0; + return false; } if (model_in.materials.empty()) { // materials are missing LL_WARNS("GLTF") << "Cannot load. File has no materials " << filename << LL_ENDL; - return 0; + return false; } - materials_in_file = model_in.materials.size(); + + return true; } - return materials_in_file; + + + return false; } -bool LLTinyGLTFHelper::getMaterialFromFile( +bool LLTinyGLTFHelper::getMaterialFromModel( const std::string& filename, + const tinygltf::Model& model_in, S32 mat_index, LLFetchedGLTFMaterial* material, std::string& material_name) { llassert(material); - tinygltf::TinyGLTF loader; - std::string error_msg; - std::string warn_msg; - tinygltf::Model model_in; - std::string filename_lc = filename; - bool decode_successful = true; - - 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("GLTF") << "Cannot load Material, error: " << error_msg - << ", warning:" << warn_msg - << " file: " << filename - << LL_ENDL; - return false; - } - else if (model_in.materials.size() <= mat_index) + if (model_in.materials.size() <= mat_index) { // materials are missing LL_WARNS("GLTF") << "Cannot load Material, Material " << mat_index << " is missing, " << filename << LL_ENDL; @@ -276,7 +249,7 @@ bool LLTinyGLTFHelper::getMaterialFromFile( material->setFromModel(model_in, mat_index); - std::string folder = gDirUtilp->getDirName(filename_lc); + std::string folder = gDirUtilp->getDirName(filename); tinygltf::Material material_in = model_in.materials[mat_index]; material_name = material_in.name; |