Example #1
0
        public bool Renderiza(ref SharpGL.SceneControl scene_GLControl, bool Grid = false, bool Modelo = false, double CotaZ = double.NaN, bool BBox = false)
        {
            bool Res = true;

            scene_GLControl.Scene.RenderBoundingVolumes = BBox;

            for (int i = 0; i < scene_GLControl.Scene.SceneContainer.Children.Count(); i++)
            {
                switch (scene_GLControl.Scene.SceneContainer.Children[i].Name)
                {
                case constPlanoSLT:
                    if (CotaZ != double.NaN)
                    {
                        scene_GLControl.Scene.SceneContainer.RemoveChild(scene_GLControl.Scene.SceneContainer.Children[i]);
                        i--;
                    }
                    break;

                case constModeloSLT:
                    if (Modelo)
                    {
                        scene_GLControl.Scene.SceneContainer.RemoveChild(scene_GLControl.Scene.SceneContainer.Children[i]);
                        i--;
                    }
                    break;

                case constDesignPrimitives:
                    if (Grid)
                    {
                        if (scene_GLControl.Scene.SceneContainer.Children[i] is SharpGL.SceneGraph.Primitives.Folder)
                        {
                            SharpGL.SceneGraph.Primitives.Folder Foldr = scene_GLControl.Scene.SceneContainer.Children[i] as SharpGL.SceneGraph.Primitives.Folder;
                            for (int j = 0; j < Foldr.Children.Count(); j++)
                            {
                                if (Foldr.Children[j] is SharpGL.SceneGraph.Primitives.Grid)
                                {
                                    SharpGL.SceneGraph.Primitives.Grid Grd = Foldr.Children[j] as SharpGL.SceneGraph.Primitives.Grid;

                                    if (Grd.Name == constDesignGrid)
                                    {
                                        Foldr.RemoveChild(Grd);
                                        j--;
                                    }
                                }
                                else if (Foldr.Children[j] is SharpGL.SceneGraph.Primitives.Axies)
                                {
                                    SharpGL.SceneGraph.Primitives.Axies Ax = Foldr.Children[j] as SharpGL.SceneGraph.Primitives.Axies;

                                    if (Ax.Name == constDesignAxie)
                                    {
                                        Foldr.RemoveChild(Ax);
                                        j--;
                                    }
                                }
                            }
                        }
                    }
                    break;

                default:
                    break;
                }
            }

            if (Grid)
            {
                SharpGL.SceneGraph.Primitives.Folder Foldr = null;

                for (int i = 0; i < scene_GLControl.Scene.SceneContainer.Children.Count(); i++)
                {
                    if (scene_GLControl.Scene.SceneContainer.Children[i].Name == constDesignPrimitives)
                    {
                        if (scene_GLControl.Scene.SceneContainer.Children[i] is SharpGL.SceneGraph.Primitives.Folder)
                        {
                            Foldr = scene_GLControl.Scene.SceneContainer.Children[i] as SharpGL.SceneGraph.Primitives.Folder;
                            break;
                        }
                    }
                }

                if (Foldr != null)
                {
                    SharpGL.SceneGraph.Primitives.Grid grid = new SharpGL.SceneGraph.Primitives.Grid();
                    grid.Name = constDesignGrid;

                    SharpGL.SceneGraph.Primitives.Axies axie = new SharpGL.SceneGraph.Primitives.Axies();
                    axie.Name = constDesignAxie;

                    if (_Facets.Count > 0)
                    {
                        //printer Axies
                        SharpGL.SceneGraph.Transformations.LinearTransformation linearAxiesTransformation = new SharpGL.SceneGraph.Transformations.LinearTransformation();

                        linearAxiesTransformation.ScaleX = 10;
                        linearAxiesTransformation.ScaleY = 10;
                        linearAxiesTransformation.ScaleZ = 10;

                        SharpGL.SceneGraph.Effects.LinearTransformationEffect linearAxiesTransformationEffect = new SharpGL.SceneGraph.Effects.LinearTransformationEffect();
                        linearAxiesTransformationEffect.LinearTransformation = linearAxiesTransformation;

                        axie.AddEffect(linearAxiesTransformationEffect);

                        //Printer Grid
                        SharpGL.SceneGraph.Transformations.LinearTransformation linearGridTransformation = new SharpGL.SceneGraph.Transformations.LinearTransformation();

                        linearGridTransformation.TranslateX = 200;
                        linearGridTransformation.TranslateY = 200;
                        linearGridTransformation.ScaleX     = 20;
                        linearGridTransformation.ScaleY     = 20;

                        SharpGL.SceneGraph.Effects.LinearTransformationEffect linearGridTransformationEffect = new SharpGL.SceneGraph.Effects.LinearTransformationEffect();
                        linearGridTransformationEffect.LinearTransformation = linearGridTransformation;

                        grid.AddEffect(linearGridTransformationEffect);
                    }

                    Foldr.AddChild(axie);
                    Foldr.AddChild(grid);
                }
            }

            if (!double.IsNaN(CotaZ))
            {
                //Dibuja el plano Z.
                SharpGL.SceneGraph.Primitives.Polygon Polig = new SharpGL.SceneGraph.Primitives.Polygon();
                Polig.Name        = constPlanoSLT;
                Polig.DrawNormals = false;

                SharpGL.SceneGraph.Vertex[] Vertices = new SharpGL.SceneGraph.Vertex[4];

                float MargenX = (float)this.Ancho * 0.1f;
                float MargenY = (float)this.Alto * 0.1f;

                Vertices[0] = new SharpGL.SceneGraph.Vertex(_IzqFrontInf.Xf - MargenX, _IzqFrontInf.Yf - MargenY, (float)CotaZ);
                Vertices[1] = new SharpGL.SceneGraph.Vertex(_IzqFrontInf.Xf - MargenX, _DerPostSup.Yf + MargenY, (float)CotaZ);
                Vertices[2] = new SharpGL.SceneGraph.Vertex(_DerPostSup.Xf + MargenX, _DerPostSup.Yf + MargenY, (float)CotaZ);
                Vertices[3] = new SharpGL.SceneGraph.Vertex(_DerPostSup.Xf + MargenX, _IzqFrontInf.Yf - MargenY, (float)CotaZ);

                Polig.AddFaceFromVertexData(Vertices);

                Polig.Validate(true);

                scene_GLControl.Scene.SceneContainer.AddChild(Polig);
            }

            if (Modelo && _Facets.Count > 0)
            {
                SharpGL.SceneGraph.Primitives.Polygon Polig = new SharpGL.SceneGraph.Primitives.Polygon();
                Polig.Name        = constModeloSLT;
                Polig.DrawNormals = false;

                foreach (FacetSLT F in _Facets)
                {
                    foreach (LoopSLT L in F._Loops)
                    {
                        bool Representar = true;

                        if (!double.IsNaN(CotaZ))
                        {
                            //Evalua si se tiene que mostrar o no por encontrarse bajo el plano
                            foreach (VertexSLT V in L.Vertices)
                            {
                                if (V.Z <= CotaZ)
                                {
                                    Representar = true;
                                    break;
                                }
                                else
                                {
                                    Representar = false;
                                }
                            }
                        }

                        if (Representar)
                        {
                            SharpGL.SceneGraph.Vertex[] Vertices = new SharpGL.SceneGraph.Vertex[L.Vertices.Count()];
                            for (int i = 0; i < L.Vertices.Count(); i++)
                            {
                                //Polig.Vertices.Add(new SharpGL.SceneGraph.Vertex(V._X, V._Y, V._Z));
                                Vertices[i] = new SharpGL.SceneGraph.Vertex(L.Vertices[i].Xf + (float)_Tx, L.Vertices[i].Yf + (float)_Ty, L.Vertices[i].Zf + (float)_Tz);
                            }

                            Polig.AddFaceFromVertexData(Vertices);
                        }
                    }
                }

                Polig.Validate(true);

                scene_GLControl.Scene.SceneContainer.AddChild(Polig);
            }

            return(Res);
        }