static void SplitPolygon(List <ReducerTask> reducerTasks, MeshCache meshCache, SAMeshCollider parentMeshCollider, SAMeshCollider rootMeshCollider) { if (reducerTasks == null || meshCache == null || parentMeshCollider == null || rootMeshCollider == null) { Debug.LogError(""); return; } SplitMesh parentSplitMesh = parentMeshCollider.splitMesh; if (parentSplitMesh == null) { Debug.LogError(""); return; } SAMeshColliderEditorCommon.CleanupSelfSAMeshCollider(parentMeshCollider); SAMeshCollider[] existingMeshColliders = SAMeshColliderEditorCommon.GetChildSAMeshColliders(parentMeshCollider.gameObject); SplitMesh[] resplitMeshes = SAMeshColliderEditorCommon.MakeSplitMeshesByPolygon(meshCache, parentSplitMesh, rootMeshCollider.splitPolygonNormalAngle); if (resplitMeshes == null || resplitMeshes.Length == 0) { return; } for (int i = 0; i < resplitMeshes.Length; ++i) { SplitMesh resplitMesh = resplitMeshes[i]; SAMeshCollider existingMeshCollider = SAMeshColliderEditorCommon.FindSAMeshCollider(existingMeshColliders, resplitMesh); if (existingMeshCollider != null && existingMeshCollider.modified) { continue; } string resplitMeshColliderName = SAMeshColliderEditorCommon.GetSAMeshColliderName_Polygon(i); SAMeshCollider resplitMeshCollider = null; if (existingMeshCollider != null) { resplitMeshCollider = existingMeshCollider; SAMeshColliderEditorCommon.SetupSAMeshCollider( parentMeshCollider, resplitMeshCollider, resplitMeshColliderName); resplitMesh = resplitMeshCollider.splitMesh; } else { resplitMeshCollider = SAMeshColliderEditorCommon.CreateSAMeshCollider( parentMeshCollider, resplitMeshColliderName, resplitMesh, SplitMode.Polygon); } SAMeshColliderEditorCommon.SalvageMeshByPolygon(resplitMesh); SAMeshColliderEditorCommon.RegistReducerTask(reducerTasks, resplitMeshCollider); } }
static void ProcessPolygon( List <ReducerTask> reducerTasks, MeshCache meshCache, SAMeshColliderBuilder meshColliderBuilder, GameObject parentGameObject, SplitMesh parentSplitMesh) { if (reducerTasks == null || meshCache == null || meshColliderBuilder == null || parentGameObject == null || parentSplitMesh == null) { Debug.LogError(""); return; } if (!meshColliderBuilder.splitPolygonNormalEnabled) { return; } SplitMesh[] resplitMeshes = SAMeshColliderEditorCommon.MakeSplitMeshesByPolygon(meshCache, parentSplitMesh, meshColliderBuilder.splitPolygonNormalAngle); if (resplitMeshes == null || resplitMeshes.Length == 0) { return; } SAMeshCollider[] existingMeshColliders = SAMeshColliderEditorCommon.GetChildSAMeshColliders(parentGameObject); for (int i = 0; i < resplitMeshes.Length; ++i) { SplitMesh resplitMesh = resplitMeshes[i]; SAMeshCollider existingMeshCollider = SAMeshColliderEditorCommon.FindSAMeshCollider(existingMeshColliders, resplitMesh); if (existingMeshCollider != null && existingMeshCollider.modified) { continue; // Not overwrite modified SAMeshCollider. } string resplitMeshColliderName = SAMeshColliderEditorCommon.GetSAMeshColliderName_Polygon(i); SAMeshCollider resplitMeshCollider = null; if (existingMeshCollider != null) { resplitMeshCollider = existingMeshCollider; SAMeshColliderEditorCommon.SetupSAMeshCollider( meshColliderBuilder, resplitMeshCollider, resplitMeshColliderName); resplitMesh = resplitMeshCollider.splitMesh; } else { resplitMeshCollider = SAMeshColliderEditorCommon.CreateSAMeshCollider( meshColliderBuilder, parentGameObject, resplitMeshColliderName, resplitMesh, SplitMode.Polygon); } SAMeshColliderEditorCommon.SalvageMeshByPolygon(resplitMesh); SAMeshColliderEditorCommon.RegistReducerTask(reducerTasks, resplitMeshCollider); } }
static void Process(SAMeshCollider meshCollider) { if (meshCollider == null) { Debug.LogError(""); return; } Cleanup(meshCollider); MeshCache meshCache = null; if (meshCollider.splitMode == SplitMode.None || meshCollider.splitMode == SplitMode.Material || meshCollider.splitMode == SplitMode.Primitive) { meshCache = SAMeshColliderEditorCommon.GetParentMeshCache(meshCollider); if (meshCache == null) { Debug.LogError("Mesh not found:" + meshCollider.name); return; } } List <ReducerTask> reducerTasks = new List <ReducerTask>(); switch (meshCollider.splitMode) { case SplitMode.None: ProcessRoot(reducerTasks, meshCache, meshCollider); break; case SplitMode.Material: ProcessMaterial(reducerTasks, meshCache, meshCollider); break; case SplitMode.Primitive: ProcessPrimitive(reducerTasks, meshCache, meshCollider); break; case SplitMode.Polygon: ProcessPolygon(reducerTasks, meshCollider); break; } SAMeshColliderEditorCommon.Reduce(reducerTasks, meshCollider.isDebug); }
static void Cleanup(SAMeshCollider meshCollider) { if (meshCollider == null) { Debug.LogError(""); return; } SAMeshColliderEditorCommon.CleanupChildSAMeshColliders( meshCollider.gameObject, meshCollider.cleanupModified); SAMeshColliderEditorCommon.CleanupSelfSAMeshCollider(meshCollider); SAMeshColliderEditorCommon.MarkManualProcessingToParent(meshCollider); }
static void ProcessPolygon(List <ReducerTask> reducerTasks, SAMeshCollider meshCollider) { if (reducerTasks == null || meshCollider == null) { Debug.LogError(""); return; } SplitMesh splitMesh = meshCollider.splitMesh; if (splitMesh == null) { Debug.LogError(""); return; } SAMeshColliderEditorCommon.MarkManualProcessingToParent(meshCollider); SAMeshColliderEditorCommon.SalvageMeshByPolygon(splitMesh); SAMeshColliderEditorCommon.RegistReducerTask(reducerTasks, meshCollider); }
static void ProcessRoot(List <ReducerTask> reducerTasks, MeshCache meshCache, SAMeshCollider meshCollider) { if (reducerTasks == null || meshCache == null || meshCollider == null) { Debug.LogError(""); return; } SplitMesh splitMesh = meshCollider.splitMesh; if (splitMesh == null) { Debug.LogError(""); return; } SAMeshColliderEditorCommon.MarkManualProcessingToParent(meshCollider); if (meshCollider.splitMaterialEnabled) { SplitMaterial(reducerTasks, meshCache, meshCollider, meshCollider); } else if (meshCollider.splitPrimitiveEnabled) { SplitPrimitive(reducerTasks, meshCache, meshCollider, meshCollider); } else if (meshCollider.splitPolygonNormalEnabled) { SAMeshColliderEditorCommon.MakeSplitMeshTriangles(meshCache, splitMesh); SplitPolygon(reducerTasks, meshCache, meshCollider, meshCollider); } else { SAMeshColliderEditorCommon.MakeSplitMeshTriangles(meshCache, splitMesh); SAMeshColliderEditorCommon.RegistReducerTask(reducerTasks, meshCollider); } }
static void ProcessMaterial( List <ReducerTask> reducerTasks, MeshCache meshCache, SAMeshColliderBuilder meshColliderBuilder, GameObject parentGameObject) { if (reducerTasks == null || meshCache == null || meshColliderBuilder == null || parentGameObject == null) { Debug.LogError(""); return; } SplitMesh[] resplitMeshes = SAMeshColliderEditorCommon.MakeSplitMeshesByMaterial(meshCache); if (resplitMeshes == null || resplitMeshes.Length == 0) { return; } SAMeshCollider[] existingMeshColliders = SAMeshColliderEditorCommon.GetChildSAMeshColliders(parentGameObject); Material[] materials = meshCache.materials; for (int i = 0; i < resplitMeshes.Length; ++i) { SplitMesh resplitMesh = resplitMeshes[i]; SAMeshCollider existingMeshCollider = SAMeshColliderEditorCommon.FindSAMeshCollider(existingMeshColliders, resplitMesh); if (existingMeshCollider != null && existingMeshCollider.modified) { continue; // Not overwrite modified SAMeshCollider. } string resplitMeshColliderName = SAMeshColliderEditorCommon.GetSAMeshColliderName_Material(materials, i); SAMeshCollider resplitMeshCollider = null; if (existingMeshCollider != null) { resplitMeshCollider = existingMeshCollider; SAMeshColliderEditorCommon.SetupSAMeshCollider( meshColliderBuilder, resplitMeshCollider, resplitMeshColliderName); resplitMesh = resplitMeshCollider.splitMesh; } else { resplitMeshCollider = SAMeshColliderEditorCommon.CreateSAMeshCollider( meshColliderBuilder, parentGameObject, resplitMeshColliderName, resplitMesh, SplitMode.Material); } if (resplitMeshCollider.splitPrimitiveEnabled) { ProcessPrimitive(reducerTasks, meshCache, meshColliderBuilder, resplitMeshCollider.gameObject, resplitMeshCollider.splitMesh); } else if (resplitMeshCollider.splitPolygonNormalEnabled) { SAMeshColliderEditorCommon.MakeSplitMeshTriangles(meshCache, resplitMesh); ProcessPolygon(reducerTasks, meshCache, meshColliderBuilder, resplitMeshCollider.gameObject, resplitMeshCollider.splitMesh); } else { SAMeshColliderEditorCommon.MakeSplitMeshTriangles(meshCache, resplitMesh); SAMeshColliderEditorCommon.RegistReducerTask(reducerTasks, resplitMeshCollider); } } }
static void ProcessRoot( List <ReducerTask> reducerTasks, MeshCache meshCache, SAMeshColliderBuilder meshColliderBuilder, GameObject parentGameObject) { if (reducerTasks == null || meshCache == null || meshColliderBuilder == null || parentGameObject == null) { Debug.LogError(""); return; } SplitMesh resplitMesh = SAMeshColliderEditorCommon.MakeRootSplitMesh(meshCache); if (resplitMesh == null) { return; } if (meshColliderBuilder.splitMaterialEnabled) { ProcessMaterial(reducerTasks, meshCache, meshColliderBuilder, parentGameObject); } else if (meshColliderBuilder.splitPrimitiveEnabled) { ProcessPrimitive(reducerTasks, meshCache, meshColliderBuilder, parentGameObject, resplitMesh); } else if (meshColliderBuilder.splitPolygonNormalEnabled) { SAMeshColliderEditorCommon.MakeSplitMeshTriangles(meshCache, resplitMesh); ProcessPolygon(reducerTasks, meshCache, meshColliderBuilder, parentGameObject, resplitMesh); } else { SAMeshCollider[] existingMeshColliders = SAMeshColliderEditorCommon.GetChildSAMeshColliders(parentGameObject); SAMeshCollider existingMeshCollider = SAMeshColliderEditorCommon.FindSAMeshCollider(existingMeshColliders, resplitMesh); if (existingMeshCollider != null && existingMeshCollider.modified) { return; // Not overwrite modified SAMeshCollider. } string resplitMeshColliderName = SAMeshColliderEditorCommon.GetSAMeshColliderName_Root(parentGameObject); SAMeshCollider resplitMeshCollider = null; if (existingMeshCollider != null) { resplitMeshCollider = existingMeshCollider; SAMeshColliderEditorCommon.SetupSAMeshCollider( meshColliderBuilder, resplitMeshCollider, resplitMeshColliderName); resplitMesh = resplitMeshCollider.splitMesh; } else { resplitMeshCollider = SAMeshColliderEditorCommon.CreateSAMeshCollider( meshColliderBuilder, parentGameObject, resplitMeshColliderName, resplitMesh, SplitMode.None); } SAMeshColliderEditorCommon.MakeSplitMeshTriangles(meshCache, resplitMesh); SAMeshColliderEditorCommon.RegistReducerTask(reducerTasks, resplitMeshCollider); } }
public override void OnInspectorGUI() { SAMeshCollider meshCollider = (SAMeshCollider)target; if (meshCollider.edittingMeshCollidertProperty == null) { if (meshCollider.meshColliderProperty != null) { meshCollider.edittingMeshCollidertProperty = meshCollider.meshColliderProperty.Copy(); } } SAMeshColliderProperty meshColliderProperty = meshCollider.edittingMeshCollidertProperty; if (meshColliderProperty != null) { SplitProperty splitProperty = meshColliderProperty.splitProperty; if (splitProperty != null) { GUILayout.Label("Split", EditorStyles.boldLabel); // Split Material GUI.enabled = ((int)meshCollider.splitMode <= (int)SplitMode.None); splitProperty.splitMaterialEnabled = EditorGUILayout.Toggle("Split Material", splitProperty.splitMaterialEnabled); GUI.enabled = true; // Split Primitive GUI.enabled = ((int)meshCollider.splitMode <= (int)SplitMode.Material); splitProperty.splitPrimitiveEnabled = EditorGUILayout.Toggle("Split Primitive", splitProperty.splitPrimitiveEnabled); GUI.enabled = true; // Split Polygon Normal EditorGUILayout.BeginHorizontal(); GUI.enabled = ((int)meshCollider.splitMode <= (int)SplitMode.Primitive); splitProperty.splitPolygonNormalEnabled = EditorGUILayout.Toggle("Split Polygon Normal", splitProperty.splitPolygonNormalEnabled); GUI.enabled = GUI.enabled && meshCollider.splitPolygonNormalEnabled; splitProperty.splitPolygonNormalAngle = EditorGUILayout.Slider(splitProperty.splitPolygonNormalAngle, 0.0f, 180.0f); GUI.enabled = true; EditorGUILayout.EndHorizontal(); } EditorGUILayout.Separator(); GUILayout.Label("Reducer", EditorStyles.boldLabel); SAColliderBuilderEditorCommon.ReducerInspectorGUI(meshColliderProperty.reducerProperty, ReducerOption.Advanced); GUI.enabled = meshColliderProperty.reducerProperty.shapeType != ShapeType.None; EditorGUILayout.Separator(); GUILayout.Label("Collider", EditorStyles.boldLabel); SAColliderBuilderEditorCommon.ColliderInspectorGUI(meshColliderProperty.colliderProperty, ColliderOption.None); EditorGUILayout.Separator(); GUILayout.Label("Rigidbody", EditorStyles.boldLabel); SAColliderBuilderEditorCommon.RigidbodyInspectorGUI(meshColliderProperty.rigidbodyProperty); GUI.enabled = true; } EditorGUILayout.Separator(); meshCollider.cleanupModified = EditorGUILayout.Toggle("Cleanup Modified", meshCollider.cleanupModified); meshCollider.isDebug = EditorGUILayout.Toggle("Is Debug", meshCollider.isDebug); EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Set Default")) { if (meshCollider.defaultMeshColliderProperty != null) { float beginTime = Time.realtimeSinceStartup; meshCollider.meshColliderProperty = meshCollider.defaultMeshColliderProperty.Copy(); meshCollider.edittingMeshCollidertProperty = null; Process(meshCollider); meshCollider.cleanupModified = false; SAMeshColliderEditorCommon.UnmarkManualProcessingToParent(meshCollider); meshCollider.ResetModifyName(); float endTime = Time.realtimeSinceStartup; Debug.Log("Processed.[" + (endTime - beginTime) + " sec]"); } } GUILayout.FlexibleSpace(); if (GUILayout.Button("Revert")) { meshCollider.edittingMeshCollidertProperty = null; } if (GUILayout.Button("Cleanup")) { if (meshCollider.edittingMeshCollidertProperty != null) { meshCollider.meshColliderProperty = meshCollider.edittingMeshCollidertProperty; meshCollider.edittingMeshCollidertProperty = null; Cleanup(meshCollider); meshCollider.cleanupModified = false; meshCollider.isDebug = false; Debug.Log("Cleanuped."); } } if (GUILayout.Button("Process")) { if (meshCollider.edittingMeshCollidertProperty != null) { float beginTime = Time.realtimeSinceStartup; meshCollider.meshColliderProperty = meshCollider.edittingMeshCollidertProperty; meshCollider.edittingMeshCollidertProperty = null; Process(meshCollider); meshCollider.cleanupModified = false; meshCollider.isDebug = false; float endTime = Time.realtimeSinceStartup; Debug.Log("Processed.[" + (endTime - beginTime) + " sec]"); } } EditorGUILayout.EndHorizontal(); }