Exemple #1
0
        private void model1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                int selEntityIndex = model1.GetEntityUnderMouseCursor(devDept.Graphics.RenderContextUtility.ConvertPoint(model1.GetMousePosition(e)));

                if (selEntityIndex != -1)
                {
                    Entity  entity = model1.Entities[selEntityIndex];
                    Point3D pt;
                    int     tri;
                    try
                    {
                        if (model1.FindClosestTriangle((IFace)entity, devDept.Graphics.RenderContextUtility.ConvertPoint(model1.GetMousePosition(e)), out pt, out tri) > 0)
                        {
                            IndexTriangle it = ((Mesh)entity).Triangles[tri];

                            // calculates normal direction of selected triangle
                            Point3D[] pointEnt = ((Mesh)entity).Vertices;
                            Triangle  selT     = new Triangle(pointEnt[it.V1], pointEnt[it.V2], pointEnt[it.V3]);
                            selT.Regen(0.1);
                            Sh.Direction = selT.Normal;

                            // shows the normal's direction like an arrow
                            Sh.DrawNormalDirection(pt, _readFile.Entities[_originalIndex].BoxSize.Diagonal);

                            model1.Entities.Regen();
                            model1.Invalidate();
                        }
                    }
                    catch { }
                }
            }
        }
Exemple #2
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;
                }
            }
        }
Exemple #3
0
        public MyIndexTriangle(int v1, int v2, int v3, bool visited, int group, Point3D[] vertices)
            : base(v1, v2, v3)
        {
            Visited = visited;
            Group   = group;
            Found   = false;
            ReVisit = false;

            Triangle t = new Triangle(vertices[V1], vertices[V2], vertices[V3]);

            t.Regen(0.1);
            Normal = t.Normal;
        }