/// <summary> /// Converts "Necessary" textures textures found in the gltf file. /// Coroutine must be fully consumed before generating materials. /// </summary> /// <seealso cref="GltfMaterialConverter.NecessaryTextures" /> /// <param name="root">The root of the GLTF file.</param> /// <param name="loader">The loader to use to load resources (textures, etc).</param> /// <param name="loaded">Mutated to add any textures that were loaded.</param> public static IEnumerable LoadTexturesCoroutine( GltfRootBase root, IUriLoader loader, List <Texture2D> loaded) { foreach (GltfTextureBase gltfTexture in NecessaryTextures(root)) { if (IsTiltBrushHostedUri(gltfTexture.SourcePtr.uri)) { Debug.LogWarningFormat("Texture {0} uri {1} was considered necessary", gltfTexture.GltfId, gltfTexture.SourcePtr.uri); continue; } foreach (var unused in ConvertTextureCoroutine(gltfTexture, loader)) { yield return(null); } if (gltfTexture.unityTexture != null) { loaded.Add(gltfTexture.unityTexture); } } // After textures are converted, we don't need the cached RawImage data any more. // "Deallocate" it. foreach (GltfImageBase image in root.Images) { image.data = null; } }
/// <summary> /// Enumerates those Textures associated with local materials, as distinguished /// from well-known, global materials like BlocksPaper and Tilt Brush Light. /// Textures associated with those latter materials will not be enumerated. /// /// These are the textures that need UnityEngine.Textures created for them. /// </summary> public static IEnumerable <GltfTextureBase> NecessaryTextures(GltfRootBase root) { foreach (var mat in root.Materials) { if (!IsGlobalMaterial(mat)) { foreach (var tex in mat.ReferencedTextures) { yield return(tex); } } } }