Esempio n. 1
0
        /// <summary>
        /// Splits the triangles and Vertices in red/yellow/blue sections considering angularTol.
        /// </summary>
        private void SplitTrianglesByNormal(Mesh originalEntity, Vector3D direction, MyIndexTriangle[] originalT,
                                            Mesh redSection, Mesh yellowSection, Mesh blueSection, int[] redPoints, int[] yellowPoints, int[] bluePoints,
                                            ref int redT, ref int yellowT, ref int blueT)
        {
            for (int i = 0; i < originalT.Length; i++)
            {
                MyIndexTriangle it = originalT[i];
                Triangle        t  = new Triangle(originalEntity.Vertices[it.V1], originalEntity.Vertices[it.V2],
                                                  originalEntity.Vertices[it.V3]);
                t.Regen(0.1);
                double angle = Vector3D.AngleBetween(direction, t.Normal);

                // red section
                if (Math.PI / 2 - Math.Abs(angle) > _angularTol)
                {
                    originalT[i].Found   = true;
                    originalT[i].Visited = true;
                    //sets to yellow group
                    originalT[i].Group = 1;
                    // if is yellow isn't blue/red
                    blueSection.Triangles[i]   = null;
                    yellowSection.Triangles[i] = null;
                    //found a new red triangle
                    redT++;

                    redPoints[it.V3] = redPoints[it.V2] = redPoints[it.V1] = 1;
                }
                // yellow section
                else if (Math.Abs(angle - Math.PI / 2) <= _angularTol)
                {
                    //sets to yellow group
                    originalT[i].Group = 0;
                    // if is yellow isn't blue/red
                    blueSection.Triangles[i] = null;
                    redSection.Triangles[i]  = null;
                    //found a new yellow triangle
                    yellowT++;

                    yellowPoints[it.V3] = yellowPoints[it.V2] = yellowPoints[it.V1] = 1;
                }
                // blue section
                else
                {
                    originalT[i].Found = true;
                    //originalT[i].Visited = true;
                    //sets to blue group
                    originalT[i].Group = -1;
                    // if is blue isn't red/yellow
                    redSection.Triangles[i]    = null;
                    yellowSection.Triangles[i] = null;
                    //found a new blue triangle
                    blueT++;

                    bluePoints[it.V3] = bluePoints[it.V2] = bluePoints[it.V1] = 1;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Splits original Entity in three sections (red, blue, yellow) using direction vector.
        /// </summary>
        public void QuickSplit(Mesh originalEntity, Vector3D direction)
        {
            int redT    = 0;
            int blueT   = 0;
            int yellowT = 0;

            Mesh redSection    = (Mesh)originalEntity.Clone();
            Mesh blueSection   = (Mesh)originalEntity.Clone();
            Mesh yellowSection = (Mesh)originalEntity.Clone();

            blueSection.Visible   = true;
            redSection.Visible    = true;
            yellowSection.Visible = true;

            int[] redPoints    = new int[originalEntity.Vertices.Length];
            int[] yellowPoints = new int[originalEntity.Vertices.Length];
            int[] bluePoints   = new int[originalEntity.Vertices.Length];

            // gets graph of originalEntity's edges
            LinkedList <SharedEdge>[] sell;
            int res = Utility.GetEdgesWithoutDuplicates(originalEntity.Triangles, originalEntity.Vertices.Count(), out sell);

            //convert original IndexTriangles to MyIndexTriangle
            MyIndexTriangle[] originalT = new MyIndexTriangle[originalEntity.Triangles.Length];
            for (int i = 0; i < originalEntity.Triangles.Length; i++)
            {
                originalT[i] = new MyIndexTriangle(originalEntity.Triangles[i].V1, originalEntity.Triangles[i].V2, originalEntity.Triangles[i].V3, false, 0, originalEntity.Vertices);
            }

            // gets a first list of triangles
            SplitTrianglesByNormal(originalEntity, direction, originalT, redSection, yellowSection, blueSection, redPoints, yellowPoints, bluePoints,
                                   ref redT, ref yellowT, ref blueT);

            // checks yellow triangles
            ReassingYellowTriangles(originalEntity, direction, originalT, sell, redSection, yellowSection, blueSection, redPoints, yellowPoints, bluePoints,
                                    ref redT, ref yellowT, ref blueT);

            // updates triangle section arrays
            IndexTriangle[] blue            = new IndexTriangle[blueT];
            IndexTriangle[] red             = new IndexTriangle[redT];
            IndexTriangle[] yellow          = new IndexTriangle[yellowT];
            int             redDestCount    = 0;
            int             blueDestCount   = 0;
            int             yellowDestCount = 0;

            for (int i = 0; i < originalEntity.Triangles.Length; i++)
            {
                if (redSection.Triangles[i] != null)
                {
                    red[redDestCount] = (IndexTriangle)redSection.Triangles[i].Clone();
                    redDestCount++;
                }
                if (blueSection.Triangles[i] != null)
                {
                    blue[blueDestCount] = (IndexTriangle)blueSection.Triangles[i].Clone();
                    blueDestCount++;
                }
                if (yellowSection.Triangles[i] != null)
                {
                    yellow[yellowDestCount] = (IndexTriangle)yellowSection.Triangles[i].Clone();
                    yellowDestCount++;
                }
            }
            redSection.Triangles    = red;
            blueSection.Triangles   = blue;
            yellowSection.Triangles = yellow;

            //Deletes and reorders Vertices lists
            yellowSection = DeleteUnusedVertices(yellowSection);
            redSection    = DeleteUnusedVertices(redSection);
            blueSection   = DeleteUnusedVertices(blueSection);

            SetBlockDefinition(blueSection, redSection, yellowSection);
            DrawNormalDirection(Point3D.Origin, originalEntity.BoxSize.Diagonal);

            _model1.Entities.Regen();
            _model1.Invalidate();
        }