public static void UpdateSkinnedMeshApproximateBoundsFromBoundsStatic(List <GameObject> objectsInCombined, SkinnedMeshRenderer smr) { Bounds b = new Bounds(); Bounds bigB = new Bounds(); if (MeshBakerUtility.GetBounds(objectsInCombined[0], out b)) { bigB = b; } else { Debug.LogError("Could not get bounds. Not updating skinned mesh bounds"); return; } for (int i = 1; i < objectsInCombined.Count; i++) { if (MeshBakerUtility.GetBounds(objectsInCombined[i], out b)) { bigB.Encapsulate(b); } else { Debug.LogError("Could not get bounds. Not updating skinned mesh bounds"); return; } } smr.localBounds = bigB; }
public override void DestroyMesh() { for (int i = 0; i < meshCombiners.Count; i++) { if (meshCombiners[i].combinedMesh.targetRenderer != null) { MeshBakerUtility.Destroy(meshCombiners[i].combinedMesh.targetRenderer.gameObject); } meshCombiners[i].combinedMesh.ClearMesh(); } obj2MeshCombinerMap.Clear(); meshCombiners.Clear(); }
void _distributeAmongBakers(GameObject[] gos, int[] deleteGOinstanceIDs) { if (gos == null) { gos = empty; } if (deleteGOinstanceIDs == null) { deleteGOinstanceIDs = emptyIDs; } if (resultSceneObject == null) { resultSceneObject = new GameObject("CombinedMesh-" + name); } //PART 2 ==== calculate which bakers to add objects to for (int i = 0; i < meshCombiners.Count; i++) { meshCombiners[i].extraSpace = _maxVertsInMesh - meshCombiners[i].combinedMesh.GetMesh().vertexCount; } //Profile.End//Profile("MB2_MultiMeshCombiner.AddDeleteGameObjects1"); //Profile.Start//Profile("MB2_MultiMeshCombiner.AddDeleteGameObjects2.1"); //first delete game objects from the existing combinedMeshes keep track of free space for (int i = 0; i < deleteGOinstanceIDs.Length; i++) { CombinedMesh c = null; if (obj2MeshCombinerMap.TryGetValue(deleteGOinstanceIDs[i], out c)) { if (LOG_LEVEL >= MBLogLevel.debug) { MBLog.LogDebug("MB2_MultiMeshCombiner.Removing " + deleteGOinstanceIDs[i] + " from meshCombiner " + meshCombiners.IndexOf(c)); } c.numVertsInListToDelete += c.combinedMesh.GetNumVerticesFor(deleteGOinstanceIDs[i]); //m.vertexCount; c.gosToDelete.Add(deleteGOinstanceIDs[i]); } else { Debug.LogWarning("Object " + deleteGOinstanceIDs[i] + " in the list of objects to delete is not in the combined mesh."); } } for (int i = 0; i < gos.Length; i++) { GameObject go = gos[i]; int numVerts = MeshBakerUtility.GetMesh(go).vertexCount; CombinedMesh cm = null; for (int j = 0; j < meshCombiners.Count; j++) { if (meshCombiners[j].extraSpace + meshCombiners[j].numVertsInListToDelete - meshCombiners[j].numVertsInListToAdd > numVerts) { cm = meshCombiners[j]; if (LOG_LEVEL >= MBLogLevel.debug) { MBLog.LogDebug("MB2_MultiMeshCombiner.Added " + gos[i] + " to combinedMesh " + j, LOG_LEVEL); } break; } } if (cm == null) { cm = new CombinedMesh(maxVertsInMesh, _resultSceneObject, _LOG_LEVEL); _setMBValues(cm.combinedMesh); meshCombiners.Add(cm); if (LOG_LEVEL >= MBLogLevel.debug) { MBLog.LogDebug("MB2_MultiMeshCombiner.Created new combinedMesh"); } } cm.gosToAdd.Add(go); cm.numVertsInListToAdd += numVerts; // obj2MeshCombinerMap.Add(go,cm); } }