diff options
Diffstat (limited to 'indra/newview/lltinygltfhelper.cpp')
-rw-r--r-- | indra/newview/lltinygltfhelper.cpp | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/indra/newview/lltinygltfhelper.cpp b/indra/newview/lltinygltfhelper.cpp index 58ce23a23a..7b4f47e567 100644 --- a/indra/newview/lltinygltfhelper.cpp +++ b/indra/newview/lltinygltfhelper.cpp @@ -91,14 +91,14 @@ void LLTinyGLTFHelper::initFetchedTextures(tinygltf::Material& material, { if (material.pbrMetallicRoughness.metallicRoughnessTexture.index != material.occlusionTexture.index) { + LLImageDataLock lockIn(occlusion_img); + LLImageDataLock lockOut(mr_img); // occlusion is a distinct texture from pbrMetallicRoughness // pack into mr red channel int occlusion_idx = material.occlusionTexture.index; int mr_idx = material.pbrMetallicRoughness.metallicRoughnessTexture.index; if (occlusion_idx != mr_idx) { - LLImageDataLock lockIn(occlusion_img); - LLImageDataLock lockOut(mr_img); //scale occlusion image to match resolution of mr image occlusion_img->scale(mr_img->getWidth(), mr_img->getHeight()); @@ -206,7 +206,7 @@ LLImageRaw * LLTinyGLTFHelper::getTexture(const std::string & folder, const tiny bool LLTinyGLTFHelper::loadModel(const std::string& filename, tinygltf::Model& model_in) { std::string exten = gDirUtilp->getExtension(filename); - + if (exten == "gltf" || exten == "glb") { tinygltf::TinyGLTF loader; @@ -243,7 +243,7 @@ bool LLTinyGLTFHelper::loadModel(const std::string& filename, tinygltf::Model& m LL_WARNS("GLTF") << "Cannot load. File has no materials " << filename << LL_ENDL; return false; } - + return true; } @@ -251,6 +251,43 @@ bool LLTinyGLTFHelper::loadModel(const std::string& filename, tinygltf::Model& m return false; } +bool LLTinyGLTFHelper::saveModel(const std::string& filename, tinygltf::Model& model_in) +{ + std::string exten = gDirUtilp->getExtension(filename); + + bool success = false; + + if (exten == "gltf" || exten == "glb") + { + tinygltf::TinyGLTF writer; + + std::string filename_lc = filename; + LLStringUtil::toLower(filename_lc); + + + bool embed_images = false; + bool embed_buffers = false; + bool pretty_print = true; + bool write_binary = false; + + + if (std::string::npos == filename_lc.rfind(".gltf")) + { // file is binary + embed_images = embed_buffers = write_binary = true; + } + + success = writer.WriteGltfSceneToFile(&model_in, filename, embed_images, embed_buffers, pretty_print, write_binary); + + if (!success) + { + LL_WARNS("GLTF") << "Failed to save" << LL_ENDL; + return false; + } + } + + return success; +} + bool LLTinyGLTFHelper::getMaterialFromModel( const std::string& filename, const tinygltf::Model& model_in, |