예제 #1
0
 private static void ConfigureSampler(TextureDescriptor texDesc, TextureImporter textureImporter)
 {
     textureImporter.mipmapEnabled = texDesc.Sampler.EnableMipMap;
     textureImporter.filterMode    = texDesc.Sampler.FilterMode;
     textureImporter.wrapModeU     = texDesc.Sampler.WrapModesU;
     textureImporter.wrapModeV     = texDesc.Sampler.WrapModesV;
 }
예제 #2
0
        public void Add(TextureDescriptor texDesc)
        {
            if (_texDescDict.ContainsKey(texDesc.SubAssetKey))
            {
                return;
            }

            _texDescDict.Add(texDesc.SubAssetKey, texDesc);
        }
예제 #3
0
 public static void Configure(TextureDescriptor texDesc, IReadOnlyDictionary <SubAssetKey, Texture> ExternalMap)
 {
     if (ExternalMap.TryGetValue(texDesc.SubAssetKey, out Texture external))
     {
         if (ImporterGetter.TryGetImporter(external, out ImporterGetter getter))
         {
             using (getter)
             {
                 Configure(texDesc, external, getter.Importer);
             }
         }
     }
 }
예제 #4
0
        public static void Configure(TextureDescriptor texDesc, IReadOnlyDictionary <SubAssetKey, Texture> externalMap)
        {
            if (!externalMap.TryGetValue(texDesc.SubAssetKey, out var externalTexture))
            {
                return;
            }
            if (!EditorTextureUtility.TryGetAsEditorTexture2DAsset(externalTexture, out var texture2D, out var importer))
            {
                return;
            }

            Configure(texDesc, importer);
            importer.SaveAndReimport();
        }
예제 #5
0
        private static void Configure(TextureDescriptor texDesc, TextureImporter importer)
        {
            switch (texDesc.TextureType)
            {
            case TextureImportTypes.NormalMap:
            {
                ConfigureSize(importer);
                ConfigureNormalMap(importer);
            }
            break;

            case TextureImportTypes.StandardMap:
            {
                ConfigureSize(importer);
                ConfigureLinear(importer);
            }
            break;

            case TextureImportTypes.sRGB:
            {
                ConfigureSize(importer);
            }
            break;

            case TextureImportTypes.Linear:
            {
                ConfigureSize(importer);
                ConfigureLinear(importer);
            }
            break;

            default:
                throw new NotImplementedException();
            }

            ConfigureSampler(texDesc, importer);
        }
예제 #6
0
        /// <summary>
        /// テクスチャ生成情報を基に、テクスチャ生成を行う。
        /// SubAssetKey が同じ場合はキャッシュを返す。
        /// </summary>
        public async Task <Texture> GetTextureAsync(TextureDescriptor texDesc, IAwaitCaller awaitCaller)
        {
            var subAssetKey = texDesc.SubAssetKey;

            if (_externalMap != null && _externalMap.TryGetValue(subAssetKey, out var externalTexture))
            {
                return(externalTexture);
            }

            if (_textureCache.TryGetValue(subAssetKey, out var cachedTexture))
            {
                return(cachedTexture);
            }

            switch (texDesc.TextureType)
            {
            case TextureImportTypes.NormalMap:
            {
                // no conversion. Unity's normal map is same with glTF's.
                //
                // > contrary to Unity’s usual convention of using Y as “up”
                // https://docs.unity3d.com/2018.4/Documentation/Manual/StandardShaderMaterialParameterNormalMap.html
                var data0 = await texDesc.Index0();

                var rawTexture = await TextureDeserializer.LoadTextureAsync(data0, texDesc.Sampler.EnableMipMap, ColorSpace.Linear, awaitCaller);

                rawTexture.name = subAssetKey.Name;
                rawTexture.SetSampler(texDesc.Sampler);
                _textureCache.Add(subAssetKey, rawTexture);
                return(rawTexture);
            }

            case TextureImportTypes.StandardMap:
            {
                Texture2D metallicRoughnessTexture = default;
                Texture2D occlusionTexture         = default;

                if (texDesc.Index0 != null)
                {
                    var data0 = await texDesc.Index0();

                    metallicRoughnessTexture = await TextureDeserializer.LoadTextureAsync(data0, texDesc.Sampler.EnableMipMap, ColorSpace.Linear, awaitCaller);
                }
                if (texDesc.Index1 != null)
                {
                    var data1 = await texDesc.Index1();

                    occlusionTexture = await TextureDeserializer.LoadTextureAsync(data1, texDesc.Sampler.EnableMipMap, ColorSpace.Linear, awaitCaller);
                }

                var combinedTexture = OcclusionMetallicRoughnessConverter.Import(metallicRoughnessTexture,
                                                                                 texDesc.MetallicFactor, texDesc.RoughnessFactor, occlusionTexture, _isLegacySquaredRoughness);
                combinedTexture.name = subAssetKey.Name;
                combinedTexture.SetSampler(texDesc.Sampler);
                _textureCache.Add(subAssetKey, combinedTexture);
                UnityObjectDestoyer.DestroyRuntimeOrEditor(metallicRoughnessTexture);
                UnityObjectDestoyer.DestroyRuntimeOrEditor(occlusionTexture);
                return(combinedTexture);
            }

            case TextureImportTypes.sRGB:
            {
                var data0 = await texDesc.Index0();

                var rawTexture = await TextureDeserializer.LoadTextureAsync(data0, texDesc.Sampler.EnableMipMap, ColorSpace.sRGB, awaitCaller);

                rawTexture.name = subAssetKey.Name;
                rawTexture.SetSampler(texDesc.Sampler);
                _textureCache.Add(subAssetKey, rawTexture);
                return(rawTexture);
            }

            case TextureImportTypes.Linear:
            {
                var data0 = await texDesc.Index0();

                var rawTexture = await TextureDeserializer.LoadTextureAsync(data0, texDesc.Sampler.EnableMipMap, ColorSpace.Linear, awaitCaller);

                rawTexture.name = subAssetKey.Name;
                rawTexture.SetSampler(texDesc.Sampler);
                _textureCache.Add(subAssetKey, rawTexture);
                return(rawTexture);
            }

            default:
                throw new ArgumentOutOfRangeException();
            }
        }