diff options
Diffstat (limited to 'indra/newview/gltf')
| -rw-r--r-- | indra/newview/gltf/asset.cpp | 35 | ||||
| -rw-r--r-- | indra/newview/gltf/asset.h | 2 | ||||
| -rw-r--r-- | indra/newview/gltf/llgltfloader.cpp | 13 | ||||
| -rw-r--r-- | indra/newview/gltf/llgltfloader.h | 2 |
4 files changed, 47 insertions, 5 deletions
diff --git a/indra/newview/gltf/asset.cpp b/indra/newview/gltf/asset.cpp index f7a5a20872..a2f9cd2852 100644 --- a/indra/newview/gltf/asset.cpp +++ b/indra/newview/gltf/asset.cpp @@ -33,10 +33,11 @@ #include "../llviewertexturelist.h" #include "../pipeline.h" #include "buffer_util.h" -#include <boost/url.hpp> #include "llimagejpeg.h" #include "../llskinningutil.h" +#include <future> + using namespace LL::GLTF; using namespace boost::json; @@ -961,9 +962,41 @@ LLViewerFetchedTexture* fetch_texture(const LLUUID& id); bool Image::prep(Asset& asset, bool loadIntoVRAM) { mLoadIntoTexturePipe = loadIntoVRAM; + LLUUID id; if (mUri.size() == UUID_STR_SIZE && LLUUID::parseUUID(mUri, &id) && id.notNull()) { // loaded from an asset, fetch the texture from the asset system + LL_DEBUGS("GLTF") << "Loading image from an id" << id<< LL_ENDL; + } + else if (mUri.find("data:") == 0) + { // embedded in a data URI, load the texture from the URI + LL_WARNS("GLTF") << "Data URIs not yet supported" << LL_ENDL; + return false; + } + + // Image::prepImpl containes code that must run on the main thread + std::promise<bool> prep_promise; + std::future<bool> prep_future = prep_promise.get_future(); + + LLAppViewer::instance()->postToMainCoro([this, &asset, id, &prep_promise]() mutable { + try { + bool result = prepImpl(asset, id); + prep_promise.set_value(result); + } + catch (...) { + // Propagate exception to the waiting thread + prep_promise.set_exception(std::current_exception()); + } + }); + + // Block until prep is done on the main thread + return prep_future.get(); +} + +bool Image::prepImpl(Asset& asset, const LLUUID& id) +{ + if (id.notNull()) + { // loaded from an asset, fetch the texture from the asset system mTexture = fetch_texture(id); } else if (mUri.find("data:") == 0) diff --git a/indra/newview/gltf/asset.h b/indra/newview/gltf/asset.h index b9554d753c..2802664ed3 100644 --- a/indra/newview/gltf/asset.h +++ b/indra/newview/gltf/asset.h @@ -320,6 +320,8 @@ namespace LL void clearData(Asset& asset); bool prep(Asset& asset, bool loadIntoVRAM); + private: + bool prepImpl(Asset& asset, const LLUUID& id); }; // Render Batch -- vertex buffer and list of primitives to render using diff --git a/indra/newview/gltf/llgltfloader.cpp b/indra/newview/gltf/llgltfloader.cpp index 4f8f80129d..3a1d8079a9 100644 --- a/indra/newview/gltf/llgltfloader.cpp +++ b/indra/newview/gltf/llgltfloader.cpp @@ -602,11 +602,12 @@ LLGLTFLoader::LLGLTFImportMaterial LLGLTFLoader::processMaterial(S32 material_in if (material->mPbrMetallicRoughness.mBaseColorTexture.mIndex >= 0) { S32 texIndex = material->mPbrMetallicRoughness.mBaseColorTexture.mIndex; - std::string filename = processTexture(texIndex, "base_color", material->mName); + std::string full_path; + std::string filename = processTexture(full_path, texIndex, "base_color", material->mName); if (!filename.empty()) { - impMat.mDiffuseMapFilename = filename; + impMat.mDiffuseMapFilename = full_path; impMat.mDiffuseMapLabel = material->mName.empty() ? filename : material->mName; // Check if the texture is already loaded @@ -637,7 +638,7 @@ LLGLTFLoader::LLGLTFImportMaterial LLGLTFLoader::processMaterial(S32 material_in return cachedMat; } -std::string LLGLTFLoader::processTexture(S32 texture_index, const std::string& texture_type, const std::string& material_name) +std::string LLGLTFLoader::processTexture(std::string& full_path_out, S32 texture_index, const std::string& texture_type, const std::string& material_name) { S32 sourceIndex; if (!validateTextureIndex(texture_index, sourceIndex)) @@ -661,6 +662,12 @@ std::string LLGLTFLoader::processTexture(S32 texture_index, const std::string& t { // Uri might be escaped filename = LLURI::unescape(filename); + full_path = dir + gDirUtilp->getDirDelimiter() + filename; + } + + if (gDirUtilp->fileExists(full_path)) + { + full_path_out = full_path; } LL_INFOS("GLTF_IMPORT") << "Found texture: " << filename << " for material: " << material_name << LL_ENDL; diff --git a/indra/newview/gltf/llgltfloader.h b/indra/newview/gltf/llgltfloader.h index 7aa1a94c20..a847e567a6 100644 --- a/indra/newview/gltf/llgltfloader.h +++ b/indra/newview/gltf/llgltfloader.h @@ -149,7 +149,7 @@ private: void processNodeHierarchy(S32 node_idx, std::map<std::string, S32>& mesh_name_counts, U32 submodel_limit, const LLVolumeParams& volume_params); bool addJointToModelSkin(LLMeshSkinInfo& skin_info, S32 gltf_skin_idx, size_t gltf_joint_idx); LLGLTFImportMaterial processMaterial(S32 material_index, S32 fallback_index); - std::string processTexture(S32 texture_index, const std::string& texture_type, const std::string& material_name); + std::string processTexture(std::string& full_path_out, S32 texture_index, const std::string& texture_type, const std::string& material_name); bool validateTextureIndex(S32 texture_index, S32& source_index); std::string generateMaterialName(S32 material_index, S32 fallback_index = -1); bool populateModelFromMesh(LLModel* pModel, const std::string& base_name, const LL::GLTF::Mesh &mesh, const LL::GLTF::Node &node, material_map& mats); |
