summaryrefslogtreecommitdiff
path: root/indra/newview/lltinygltfhelper.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/lltinygltfhelper.cpp')
-rw-r--r--indra/newview/lltinygltfhelper.cpp69
1 files changed, 21 insertions, 48 deletions
diff --git a/indra/newview/lltinygltfhelper.cpp b/indra/newview/lltinygltfhelper.cpp
index 611911014a..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;
@@ -309,48 +282,48 @@ bool LLTinyGLTFHelper::getMaterialFromFile(
if (base_color_tex)
{
base_color_tex->addTextureStats(64.f * 64.f, TRUE);
- material->mBaseColorId = base_color_tex->getID();
+ material->mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_BASE_COLOR] = base_color_tex->getID();
material->mBaseColorTexture = base_color_tex;
}
else
{
- material->mBaseColorId = LLUUID::null;
+ material->mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_BASE_COLOR] = LLUUID::null;
material->mBaseColorTexture = nullptr;
}
if (normal_tex)
{
normal_tex->addTextureStats(64.f * 64.f, TRUE);
- material->mNormalId = normal_tex->getID();
+ material->mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_NORMAL] = normal_tex->getID();
material->mNormalTexture = normal_tex;
}
else
{
- material->mNormalId = LLUUID::null;
+ material->mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_NORMAL] = LLUUID::null;
material->mNormalTexture = nullptr;
}
if (mr_tex)
{
mr_tex->addTextureStats(64.f * 64.f, TRUE);
- material->mMetallicRoughnessId = mr_tex->getID();
+ material->mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_METALLIC_ROUGHNESS] = mr_tex->getID();
material->mMetallicRoughnessTexture = mr_tex;
}
else
{
- material->mMetallicRoughnessId = LLUUID::null;
+ material->mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_METALLIC_ROUGHNESS] = LLUUID::null;
material->mMetallicRoughnessTexture = nullptr;
}
if (emissive_tex)
{
emissive_tex->addTextureStats(64.f * 64.f, TRUE);
- material->mEmissiveId = emissive_tex->getID();
+ material->mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_EMISSIVE] = emissive_tex->getID();
material->mEmissiveTexture = emissive_tex;
}
else
{
- material->mEmissiveId = LLUUID::null;
+ material->mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_EMISSIVE] = LLUUID::null;
material->mEmissiveTexture = nullptr;
}