private static StaticRenderer[] CombineStaticMeshes(Transform transform, int levelIndex, MeshRenderer[] renderers) { if (renderers.Length == 0) { return(null); } // TODO: Support to merge sub-meshes and atlas textures var newRenderers = new List <StaticRenderer>(renderers.Length); Material[] combinedMaterials; var combinedMesh = MeshCombiner.CombineMeshes(transform, renderers, out combinedMaterials); combinedMesh.name = string.Format("{0}_static{1:00}", transform.name, levelIndex); string rendererName = string.Format("{0}_combined_static", transform.name); newRenderers.Add(new StaticRenderer() { name = rendererName, isNewMesh = true, transform = null, mesh = combinedMesh, materials = combinedMaterials }); return(newRenderers.ToArray()); }
public static StaticRenderer[] CombineStaticMeshes(Transform transform, int levelIndex, MeshRenderer[] renderers, bool autoName = true, string combinedBaseName = "") { if (renderers.Length == 0) { return(null); } var newRenderers = new List <StaticRenderer>(renderers.Length); Material[] combinedMaterials; var combinedMesh = MeshCombiner.CombineMeshes(transform, renderers, out combinedMaterials); string baseName = string.IsNullOrWhiteSpace(combinedBaseName) ? transform.name : combinedBaseName; string rendererName = string.Format("{0}_combined_static", baseName); if (autoName) { if (transform != null) { combinedMesh.name = string.Format("{0}_static{1:00}", transform.name, levelIndex); } } newRenderers.Add(new StaticRenderer() { name = rendererName, isNewMesh = true, transform = null, mesh = combinedMesh, materials = combinedMaterials }); return(newRenderers.ToArray()); }
private static SkinnedRenderer[] CombineSkinnedMeshes(Transform transform, int levelIndex, SkinnedMeshRenderer[] renderers) { if (renderers.Length == 0) { return(null); } // TODO: Support to merge sub-meshes and atlas textures var newRenderers = new List <SkinnedRenderer>(renderers.Length); var blendShapeRenderers = (from renderer in renderers where renderer.sharedMesh != null && renderer.sharedMesh.blendShapeCount > 0 select renderer); var renderersWithoutMesh = (from renderer in renderers where renderer.sharedMesh == null select renderer); var combineRenderers = (from renderer in renderers where renderer.sharedMesh != null && renderer.sharedMesh.blendShapeCount == 0 select renderer).ToArray(); // Warn about renderers without a mesh foreach (var renderer in renderersWithoutMesh) { Debug.LogWarning("A renderer was missing a mesh and was ignored.", renderer); } // Don't combine meshes with blend shapes foreach (var renderer in blendShapeRenderers) { newRenderers.Add(new SkinnedRenderer() { name = renderer.name, isNewMesh = false, transform = renderer.transform, mesh = renderer.sharedMesh, materials = renderer.sharedMaterials, rootBone = renderer.rootBone, bones = renderer.bones }); } if (combineRenderers.Length > 0) { Material[] combinedMaterials; Transform[] combinedBones; var combinedMesh = MeshCombiner.CombineMeshes(transform, combineRenderers, out combinedMaterials, out combinedBones); combinedMesh.name = string.Format("{0}_skinned{1:00}", transform.name, levelIndex); var rootBone = FindBestRootBone(transform, combineRenderers); string rendererName = string.Format("{0}_combined_skinned", transform.name); newRenderers.Add(new SkinnedRenderer() { name = rendererName, isNewMesh = false, transform = null, mesh = combinedMesh, materials = combinedMaterials, rootBone = rootBone, bones = combinedBones }); } return(newRenderers.ToArray()); }
public static SkinnedRenderer[] CombineSkinnedMeshes(Transform transform, int levelIndex, SkinnedMeshRenderer[] renderers, ref SkinnedMeshRenderer[] renderersActuallyCombined, bool autoName = true, string combinedBaseName = "") { if (renderers.Length == 0) { return(null); } // TODO: Support to merge sub-meshes and atlas textures var newRenderers = new List <SkinnedRenderer>(renderers.Length); //var blendShapeRenderers = (from renderer in renderers // where renderer.sharedMesh != null && renderer.sharedMesh.blendShapeCount > 0 // select renderer); //baw did var renderersWithoutMesh = (from renderer in renderers where renderer.sharedMesh == null select renderer); var combineRenderers = (from renderer in renderers where renderer.sharedMesh != null // && renderer.sharedMesh.blendShapeCount == 0 baw did select renderer).ToArray(); renderersActuallyCombined = combineRenderers; // Warn about renderers without a mesh foreach (var renderer in renderersWithoutMesh) { Debug.LogWarning("A renderer was missing a mesh and was ignored.", renderer); } //Don't combine meshes with blend shapes //foreach (var renderer in blendShapeRenderers) //{ // newRenderers.Add(new SkinnedRenderer() // { // name = renderer.name, // isNewMesh = false, // transform = renderer.transform, // mesh = renderer.sharedMesh, // materials = renderer.sharedMaterials, // rootBone = renderer.rootBone, // bones = renderer.bones, // hasBlendShapes = true // }); //} if (combineRenderers.Length > 0) { Material[] combinedMaterials; Transform[] combinedBones; var combinedMesh = MeshCombiner.CombineMeshes(transform, combineRenderers, out combinedMaterials, out combinedBones); string baseName = string.IsNullOrWhiteSpace(combinedBaseName) ? transform.name : combinedBaseName; string rendererName = string.Format("{0}_combined_skinned", baseName); if (autoName) { combinedMesh.name = string.Format("{0}_skinned{1:00}", transform.name, levelIndex); } var rootBone = FindBestRootBone(transform, combineRenderers); newRenderers.Add(new SkinnedRenderer() { name = rendererName, isNewMesh = false, transform = null, mesh = combinedMesh, materials = combinedMaterials, rootBone = rootBone, bones = combinedBones }); } return(newRenderers.ToArray()); }