Пример #1
0
    override public void Calculate(ref KrablMesh.MeshEdges mesh, KMProcessorProgram parentProgram = null)
    {
        base.Calculate(ref mesh);

        KrablMesh.Simplify           sim = new KrablMesh.Simplify();
        KrablMesh.SimplifyParameters par = new KrablMesh.SimplifyParameters();

        sim.progressDelegate = delegate(string text, float val) {
            ReportProgress(text, val);
        };

        //	par.maximumError = maximumError;
        par.targetFaceCount = targetTriangleCount;
        if (platformID != null)
        {
            for (int i = 0; i < ttcOverridePlatform.Length; ++i)
            {
                if (platformID.Equals(ttcOverridePlatform[i]))
                {
                    par.targetFaceCount = ttcOverrideTargetTriangleCount[i];
                    break;
                }
            }
        }

        par.recalculateVertexPositions = allowVertexReposition;
        par.preventNonManifoldEdges    = preventNonManifoldEdges;

        par.borderWeight       = borders;
        par.creaseWeight       = creases;
        par.uvSeamWeight       = uvSeams;
        par.uv2SeamWeight      = uv2Seams;
        par.materialSeamWeight = materialSeams;

        // par.minTriangleShape = minTriangleShape;

        par.boneWeightProtection  = boneWeightProtection;
        par.vertexColorProtection = vertexColorProtection;
        //	par.vertexNormalProtection  = vertexNormalProtection;

        sim.Execute(ref mesh, par);
    }
Пример #2
0
    /// <summary>
    /// Simplify a mesh by collapsing edges until the target face count is reached.
    /// </summary>
    /// <param name='unityMesh'>
    /// The mesh to simplify.
    /// </param>
    /// <param name='targetFaceCount'>
    /// The number of triangles to reduce the mesh to. If this is higher than the initial
    /// number of triangles, no processing will occur.
    /// </param>
    /// <param name='highQuality'>
    /// Use slower, but more precise calculations.
    /// </param>

    public static void SimplifyMesh(Mesh unityMesh, int targetFaceCount, bool highQuality = true)
    {
        KrablMesh.MeshEdges          kmesh   = new KrablMesh.MeshEdges();
        KrablMesh.Simplify           sim     = new KrablMesh.Simplify();
        KrablMesh.SimplifyParameters simpars = new KrablMesh.SimplifyParameters();

        KrablMesh.ImportExport.UnityMeshToMeshEdges(unityMesh, kmesh);
        simpars.targetFaceCount            = targetFaceCount;
        simpars.recalculateVertexPositions = highQuality;
        simpars.checkTopology     = !highQuality;
        simpars.maxEdgesPerVertex = highQuality ? 18 : 0;
        if (highQuality == false)
        {
            simpars.preventNonManifoldEdges = false;
            simpars.boneWeightProtection    = 0.0f;
            simpars.vertexColorProtection   = 0.0f;
        }

        sim.Execute(ref kmesh, simpars);
        KrablMesh.ImportExport.MeshEdgesToUnityMesh(kmesh, unityMesh);
    }