Esempio n. 1
0
 public void Dispose()
 {
     foreach (var kv in _runtimeClips)
     {
         UnityObjectDestoyer.DestroyRuntimeOrEditor(kv.Value);
     }
     _runtimeClips.Clear();
 }
Esempio n. 2
0
        public void Dispose()
        {
            foreach (var x in m_materials)
            {
                if (!x.UseExternal)
                {
                    // 外部の '.asset' からロードしていない
#if VRM_DEVELOP
                    // Debug.Log($"Destroy {x.Asset}");
#endif
                    UnityObjectDestoyer.DestroyRuntimeOrEditor(x.Asset);
                }
            }
        }
Esempio n. 3
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();
            }
        }