Esempio n. 1
0
    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 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);
        }
    }
Esempio n. 3
0
    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);
            }
        }
    }
Esempio n. 4
0
    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);
        }
    }