예제 #1
0
        public virtual void DoReduce()
        {
            if (mesh.TriangleCount == 0)    // badness if we don't catch this...
            {
                return;
            }

            begin_pass();

            begin_setup();
            Precompute();
            InitializeVertexQuadrics();
            InitializeQueue();
            end_setup();

            begin_ops();

            begin_collapse();
            while (EdgeQueue.Count > 0)
            {
                // termination criteria
                if (ReduceMode == TargetModes.VertexCount)
                {
                    if (mesh.VertexCount <= TargetCount)
                    {
                        break;
                    }
                }
                else
                {
                    if (mesh.TriangleCount <= TargetCount)
                    {
                        break;
                    }
                }

                COUNT_ITERATIONS++;
                int eid = EdgeQueue.Dequeue();
                if (!mesh.IsEdge(eid))
                {
                    continue;
                }

                int           vKept;
                ProcessResult result = CollapseEdge(eid, EdgeQuadrics[eid].collapse_pt, out vKept);
                if (result == ProcessResult.Ok_Collapsed)
                {
                    vertQuadrics[vKept] = EdgeQuadrics[eid].q;
                    UpdateNeighbours(vKept);
                }
            }
            end_collapse();
            end_ops();

            Reproject();

            end_pass();
        }
        public virtual IEnumerable <int> ReduceToTriangleCount_Interactive(int nCount)
        {
            ReduceMode    = TargetModes.TriangleCount;
            TargetCount   = Math.Max(1, nCount);
            MinEdgeLength = double.MaxValue;


            if (mesh.TriangleCount == 0)    // badness if we don't catch this...
            {
                yield break;
            }

            begin_pass();

            begin_setup();
            Precompute();
            InitializeVertexQuadrics();
            InitializeQueue();
            end_setup();

            begin_ops();

            begin_collapse();
            int count = PerFrameCount;

            while (EdgeQueue.Count > 0)
            {
                // termination criteria
                if (ReduceMode == TargetModes.VertexCount)
                {
                    if (mesh.VertexCount <= TargetCount)
                    {
                        break;
                    }
                }
                else
                {
                    if (mesh.TriangleCount <= TargetCount)
                    {
                        break;
                    }
                }

                int eid = EdgeQueue.Dequeue();
                if (!mesh.IsEdge(eid))
                {
                    continue;
                }

                int           vKept;
                ProcessResult result = CollapseEdge(eid, EdgeQuadrics[eid].collapse_pt, out vKept);
                if (result == ProcessResult.Ok_Collapsed)
                {
                    vertQuadrics[vKept] = EdgeQuadrics[eid].q;
                    UpdateNeighbours(vKept);
                }
                if (count-- == 0)
                {
                    count = PerFrameCount;
                    yield return(0);
                }
            }
            end_collapse();
            end_ops();

            Reproject();

            end_pass();
        }