public SubAssetPair(SubAssetKey key, UnityEngine.Object o) { Type = key.Type.ToString(); TypeMap[Type] = key.Type; Name = key.Name; Object = o; }
public static IEnumerable <(SubAssetKey, TextureImportParam)> EnumerateSubAssetKeyValue(this MaterialImportParam param) { foreach (var kv in param.TextureSlots) { var key = new SubAssetKey(typeof(Texture2D), kv.Value.UnityObjectName); yield return(key, kv.Value); } }
public static (SubAssetKey, TextureImportParam Param) CreateSRGB(GltfParser parser, int textureIndex, Vector2 offset, Vector2 scale) { var gltfTexture = parser.GLTF.textures[textureIndex]; var gltfImage = parser.GLTF.images[gltfTexture.source]; var name = TextureImportName.GetUnityObjectName(TextureImportTypes.sRGB, gltfTexture.name, gltfImage.uri); var sampler = CreateSampler(parser.GLTF, textureIndex); GetTextureBytesAsync getTextureBytesAsync = () => Task.FromResult(ToArray(parser.GLTF.GetImageBytesFromTextureIndex(parser.Storage, textureIndex))); var key = new SubAssetKey(typeof(Texture2D), name); var param = new TextureImportParam(name, gltfImage.GetExt(), gltfImage.uri, offset, scale, sampler, TextureImportTypes.sRGB, default, default, getTextureBytesAsync, default, default, default, default, default);
/// <summary> /// Root ヒエラルキーで使っているリソース /// </summary> /// <returns></returns> public virtual void TransferOwnership(TakeResponsibilityForDestroyObjectFunc take) { foreach (var mesh in Meshes.ToArray()) { take(SubAssetKey.Create(mesh.Mesh), mesh.Mesh); Meshes.Remove(mesh); } AnimationClipFactory.TransferOwnership(take); TextureFactory.TransferOwnership(take); MaterialFactory.TransferOwnership(take); }
public static (SubAssetKey, TextureImportParam) StandardTexture(GltfParser parser, glTFMaterial src) { var metallicFactor = 1.0f; var roughnessFactor = 1.0f; if (src.pbrMetallicRoughness != null) { metallicFactor = src.pbrMetallicRoughness.metallicFactor; roughnessFactor = src.pbrMetallicRoughness.roughnessFactor; } var(offset, scale) = GltfMaterialImporter.GetTextureOffsetAndScale(src.pbrMetallicRoughness.metallicRoughnessTexture); var param = GltfTextureImporter.CreateStandard(parser, src.pbrMetallicRoughness?.metallicRoughnessTexture?.index, src.occlusionTexture?.index, offset, scale, metallicFactor, roughnessFactor); var key = new SubAssetKey(typeof(Texture2D), param.UnityObjectName); return(key, param); }
public void Extract(SubAssetKey key, TextureDescriptor texDesc) { if (Textures.ContainsKey(key)) { return; } // write converted texture if (m_subAssets.TryGetValue(key, out var texture) && texture is Texture2D tex2D) { var targetPath = m_textureDirectory.Child($"{key.Name}.png"); File.WriteAllBytes(targetPath.FullPath, tex2D.EncodeToPNG().ToArray()); targetPath.ImportAsset(); Textures.Add(key, targetPath); } else { throw new Exception($"{key} is not converted."); } }