public static void AddMeshes(MeshFilter[] filters, SkinnedMeshRenderer[] skinnedRenderers, UnityEditor.AssetImporters.AssetImportContext ctx) { HashSet <Mesh> visitedMeshes = new HashSet <Mesh>(); for (int i = 0; i < filters.Length; i++) { Mesh mesh = filters[i].sharedMesh; if (visitedMeshes.Contains(mesh)) { continue; } ctx.AddAsset(mesh.name, mesh); visitedMeshes.Add(mesh); } for (int i = 0; i < skinnedRenderers.Length; i++) { Mesh mesh = skinnedRenderers[i].sharedMesh; if (visitedMeshes.Contains(mesh)) { continue; } ctx.AddAsset(mesh.name, mesh); visitedMeshes.Add(mesh); } }
public static void AddAnimations(GLTFAnimation.ImportResult[] animations, UnityEditor.AssetImporters.AssetImportContext ctx) { if (animations == null) { return; } HashSet <AnimationClip> visitedAnimations = new HashSet <AnimationClip>(); for (int i = 0; i < animations.Length; i++) { AnimationClip clip = animations[i].clip; if (visitedAnimations.Contains(clip)) { continue; } ctx.AddAsset(clip.name, clip); visitedAnimations.Add(clip); } }
public static void AddMaterials(MeshRenderer[] renderers, SkinnedMeshRenderer[] skinnedRenderers, UnityEditor.AssetImporters.AssetImportContext ctx) { HashSet <Material> visitedMaterials = new HashSet <Material>(); HashSet <Texture2D> visitedTextures = new HashSet <Texture2D>(); for (int i = 0; i < renderers.Length; i++) { foreach (Material mat in renderers[i].sharedMaterials) { if (mat == GLTFMaterial.defaultMaterial) { continue; } if (visitedMaterials.Contains(mat)) { continue; } if (string.IsNullOrEmpty(mat.name)) { mat.name = "material" + visitedMaterials.Count; } ctx.AddAsset(mat.name, mat); visitedMaterials.Add(mat); // Add textures foreach (Texture2D tex in mat.AllTextures()) { // Dont add asset textures //if (images[i].isAsset) continue; if (visitedTextures.Contains(tex)) { continue; } if (AssetDatabase.Contains(tex)) { continue; } if (string.IsNullOrEmpty(tex.name)) { tex.name = "texture" + visitedTextures.Count; } ctx.AddAsset(tex.name, tex); visitedTextures.Add(tex); } } } for (int i = 0; i < skinnedRenderers.Length; i++) { foreach (Material mat in skinnedRenderers[i].sharedMaterials) { if (visitedMaterials.Contains(mat)) { continue; } if (string.IsNullOrEmpty(mat.name)) { mat.name = "material" + visitedMaterials.Count; } ctx.AddAsset(mat.name, mat); visitedMaterials.Add(mat); // Add textures foreach (Texture2D tex in mat.AllTextures()) { // Dont add asset textures //if (images[i].isAsset) continue; if (visitedTextures.Contains(tex)) { continue; } if (AssetDatabase.Contains(tex)) { continue; } if (string.IsNullOrEmpty(tex.name)) { tex.name = "texture" + visitedTextures.Count; } ctx.AddAsset(tex.name, tex); visitedTextures.Add(tex); } } } }