Пример #1
0
        /// <summary>
        /// compiles the <see cref="DrawAction"/> draw and returns a meshContainer.
        /// The <b>progs</b> of this is a list of <see cref="Mesh"/>.
        /// This method is called from <see cref="Entity.Compile(OpenGlDevice)"/>.
        /// </summary>
        /// <param name="Device"><see cref="OpenGlDevice"/> in which will be drawn.</param>
        /// <param name="Draw">the <see cref="DrawAction"/>, which is used to produce a <see cref="MeshContainer"/></param>
        /// <returns></returns>
        public static MeshContainer Compile(OpenGlDevice Device, DrawAction Draw)
        {
            Device.PushMatrix();
            MeshListCurrent = new MeshContainer();
            bool Compiling = Entity.Compiling;

            if (Compiling)
            {
                MeshCreator.Push();
            }
            bool SaveCompiling = Entity.Compiling;

            Entity.Compiling = true;
            RenderKind SaveRenderKind = Device.RenderKind;

            Device.RenderKind = RenderKind.Render;
            MeshIndices.Clear();

            Draw(Device);

            Renew();
            Entity.Compiling  = SaveCompiling;
            Device.RenderKind = SaveRenderKind;
            Device.PopMatrix();
            MeshContainer Result = MeshListCurrent;

            if (Compiling)
            {
                MeshCreator.Pop();
            }
            return(Result);
        }
Пример #2
0
        private void drawLetter(Font F, byte b, String s, xyz Start, int iD, OpenGlDevice Device)
        {
            if (F.Compiled[b] == null)
            {
                CompileChar = b;
                CompileFont = F;
                MeshCreator.Push();
                bool SaveRegSnap = Selector.RegisterSnap;
                Selector.RegisterSnap = false;
                F.Compiled[b]         = MeshCreator.Compile(this, Compiledraw);
                Selector.RegisterSnap = SaveRegSnap;
                MeshCreator.Pop();
            }

            if (F.Compiled[b] == null)
            {
                throw new Exception("Compile error of " + (char)(b));
            }

            if (RenderKind == RenderKind.SnapBuffer)
            {
                Object Handle = null;
                if ((RenderKind == RenderKind.SnapBuffer))
                {
                    Handle = Selector.RegisterSnapItem(new TextSnappItem(F, s, iD, Start, ModelMatrix * new xyz(0, 0, 0)));
                    if (F.GlyphInfo[b].BlackBoxY < 0.1) // blank
                    {
                        drawBox(new xyz(0, 0, 0), new xyz(F.GlyphInfo[b].Deltax, 1, 1));
                    }
                    else
                    {
                        drawBox(new xyz(0, 0, 0), new xyz(F.GlyphInfo[b].Deltax, F.GlyphInfo[b].BlackBoxY, 1));
                    }
                    if ((RenderKind == RenderKind.SnapBuffer))
                    {
                        Selector.UnRegisterSnapItem(Handle);
                    }
                }

                return;
            }
            if (Entity.Compiling)
            {
                MeshContainer M = F.Compiled[b] as MeshContainer;
                for (int i = 0; i < M.Progs.Count; i++)
                {
                    Mesh E = (M.Progs[i] as Mesh).Clone() as Mesh;
                    E.Transform(ModelMatrix);
                    MeshCreator.MeshListCurrent.Progs.Add(E);
                }

                return;
            }

            F.Compiled[b].Paint(this);
        }
Пример #3
0
 /// <summary>
 /// sets the <see cref="Mesh"/> if the entity is compiled.
 /// </summary>
 /// <param name="value">a <see cref="MeshContainer"/>, which holds the compiled informatios about the entity.</param>
 protected virtual void setMesh(MeshContainer value)   // test von Internal gwechselt auf protected virtual
 {
     if (_Mesh != value)
     {
         if (_Mesh != null)
         {
             _Mesh.Dispose();
         }
         _Mesh = value;
     }
 }
Пример #4
0
        /// <summary>
        /// is the main method of this object. See also <see cref="Entity.CompileDraw(OpenGlDevice)"/>.
        /// </summary>
        /// <param name="Device">Device in which it willl be compiled.</param>
        /// <param name="Draw">a event, which holds the drawings.</param>
        public static MeshContainer CreateMeshes(OpenGlDevice Device, DrawAction Draw)
        {
            // sollte nur von compilesnapbuffer aufgerufen werden !!!! und erstellt die triangles
            bool Compiling = Entity.Compiling;

            if (Compiling)
            {
                MeshCreator.Push();
            }
            bool SaveCompiling = Entity.Compiling;

            // Entity.Compiling = true; // Checken braucht es wegen line snap
            if (Selector.StoredSnapItems.Count == 0)
            {
                Selector.StoredSnapItems.Add(null); // braucht es nicht
            }
            MeshListCurrent = new MeshContainer();  // braucht es nicht
            MeshIndices.Clear();                    // braucht es wahrscheinlich  nicht


            RenderKind R = Device.RenderKind;// wieder heraus

            Draw(Device);

            Renew();
            Device.RenderKind = R;
            Entity.Compiling  = SaveCompiling;
            MeshContainer Result = MeshListCurrent;

            //    MeshListCurrent.MySnapItem = new MeshSnapItem(MeshListCurrent);
            Device.RenderKind = RenderKind.SnapBuffer;
            TriangleList TL = new TriangleList();

            for (int i = 0; i < MeshListCurrent.Progs.Count; i++)
            {
                if (MeshListCurrent.Progs[i] is Mesh)
                {
                    Mesh M = MeshListCurrent.Progs[i] as Mesh;
                    M.getTriangles(TL);
                }
            }
            TriangleArrays TA = TL.ToArrays();



            Device.RenderKind = R;
            if (Compiling)
            {
                MeshCreator.Pop();
            }
            return(Result);
        }
Пример #5
0
        MeshContainer DoCompile(OpenGlDevice Device)
        {
            Device.PushMatrix();
            Device.ModelMatrix = Matrix.identity;
            if (Mesh != null)
            {
                Mesh.Dispose();
            }
            MeshContainer M = MeshCreator.Compile(Device, CompileDraw);

            Device.PopMatrix();
            return(M);
        }
Пример #6
0
        /// <summary>
        /// compiliert <b>this</b>. See also <see cref="CompileEnable"/>, <see cref="MeshCreator.CreateMeshes(OpenGlDevice, DrawAction)"/>.
        /// </summary>
        /// <param name="Device"></param>
        virtual public void Compile(OpenGlDevice Device)
        {  // Sollte nur von Entity im paint aufgerufen werden
            if (!CompileEnable)
            {
                return;
            }
            MeshContainer M = DoCompile(Device);

            setMesh(M);
            //Device.PushMatrix();
            //Device.ModelMatrix = Matrix.identity;
            //if (Mesh != null) Mesh.Dispose();
            //MeshContainer M=   MeshCreator.Compile(Device,CompileDraw);
            //setMesh(M);
            //Device.PopMatrix();
        }
Пример #7
0
        /// <summary>
        /// draws a text, with a font and a n extrusion. It will be draw at the current position..
        /// </summary>
        /// <param name="F">the font, which is used.</param>
        /// <param name="s">the text, which will be drawn</param>
        /// <param name="Extrusion">the extrusion.</param>
        public void drawText(Font F, string s, double Extrusion)
        {
            PushMatrix();
            Material Save = Material;

            MulMatrix(Matrix.Scale(F.FontSize, F.FontSize, Extrusion));
            {
                xyz Start = ModelMatrix * new xyz(0, 0, 0);

                for (int i = 0; i < s.Length; i++)
                {
                    MeshContainer M = MeshCreator.MeshListCurrent;
                    byte          b = (byte)s[i];
                    drawLetter(F, b, s, Start, i, this);
                    Material = Save;
                    M        = MeshCreator.MeshListCurrent;
                    MulMatrix(Matrix.Translation(new xyz(F.GlyphInfo[b].Deltax, 0, 0)));
                }
            }
            PopMatrix();
        }
Пример #8
0
        /// <summary>
        /// returns a list of <see cref="Mesh"/>es. You can paint this list to obtain the hole entity.
        /// </summary>
        /// <param name="Device">the <see cref="OpenGlDevice"/> in which the entity will be played.</param>
        /// <returns>a list of <see cref="Mesh"/></returns>
        public List <Mesh> getMeshes(OpenGlDevice Device)
        {
            MeshContainer M      = DoCompile(Device);
            List <Mesh>   Result = new List <Drawing3d.Mesh>();

            for (int i = 0; i < M.Progs.Count; i++)
            {
                if (M.Progs[i] is Mesh)
                {
                    Result.Add(M.Progs[i] as Mesh);
                }
            }
            return(Result);
            //Device.BeginMeshMode();
            //bool SaveCompileEnable = CompileEnable;
            //CompileEnable = false;
            //setMesh(null);
            //Paint(Device);
            //CompileEnable = SaveCompileEnable;
            //return Device.EndMeshMode();
        }
Пример #9
0
            public MeshCreatorItem(
                List <xyzf> MeshVertices,
                List <xyzf> MeshNormals,
                List <xyf> MeshTextureCoords,
                List <IndexType> MeshIndices,
                MeshContainer MeshListCurrent,

                float PenWidth,
                SnappItem SnapItem,
                PolygonMode _MeshMode,
                List <SnappItem> StoredSnapItems)
            {
                this.MeshVertices      = MeshVertices;
                this.MeshNormals       = MeshNormals;
                this.MeshTextureCoords = MeshTextureCoords;
                this.MeshIndices       = MeshIndices;
                this.MeshListCurrent   = MeshListCurrent;

                this.PenWidth = PenWidth;

                this._MeshMode = PolygonMode.Fill;
            }
Пример #10
0
        /// <summary>
        /// overrides the draw nethod and paints the axis.
        /// </summary>
        /// <param name="Device"></param>
        protected override void OnDraw(OpenGlDevice Device)
        {
            if (FullSize)
            {
                xy WE = Device.WorldExtensions;
                if (WE.dist(Size.toXY()) > 0.2)
                {
                    SetInvalid(true);
                }
                Size = new xyz(WE.x, WE.y, WE.x);
            }
            if (Font == null)
            {
                Font = new Drawing3d.Font(FontName);
            }
            SaveFontSize  = Font.FontSize;
            Font.FontSize = TextHeight;
            base.OnDraw(Device);
            Device.PushMatrix();
            Device.MulMatrix(AxesBase.ToMatrix());
            bool SaveLighting = Device.LightEnabled;

            Device.LightEnabled = false;
            Color Save = Device.Emission;

            Device.Emission = Color;

            if (LeftAndRight)
            {
                Device.drawLine(new xyz(-Size.x, 0, 0), new xyz(Size.x, 0, 0));
                Device.drawLine(new xyz(0, -Size.y, 0), new xyz(0, Size.y, 0));
                if (Dim3d)
                {
                    Device.drawLine(new xyz(0, 0, -Size.z), new xyz(0, 0, Size.z));
                }
            }

            {
                Device.drawLine(new xyz(0, 0, 0), new xyz(Size.x, 0, 0));
                Device.drawLine(new xyz(0, 0, 0), new xyz(0, Size.y, 0));
                if (Dim3d)
                {
                    Device.drawLine(new xyz(0, 0, 0), new xyz(0, 0, Size.z));
                }
            }

            xyz n1   = new xyz(0, DeviderLineLength, 0);
            int from = (int)(-Size.x / Devider.x);

            if (!LeftAndRight)
            {
                from = 0;
            }

            if (Device.RenderKind == RenderKind.Render)
            {
                for (int i = from; i <= Size.x / Devider.x; i++)
                {
                    if (ShowDevider)
                    {
                        Device.drawLine(new xyz(Devider.x * i, 0, 0) - n1, new xyz(Devider.x * i, 0, 0) + n1);
                    }
                    if (ShowText)
                    {
                        double Pos = Devider.x * i - ((float)Device.getEnvText(Font, i.ToString()).x / 2f);

                        Device.drawText(Font, Matrix.Translation(new xyz(Pos, DeviderLineLength, 0)), i.ToString(), 0);
                    }
                }


                from = (int)(-Size.y / Devider.y);
                if (!LeftAndRight)
                {
                    from = 0;
                }
                n1 = new xyz(DeviderLineLength, 0, 0);
                for (int i = from; i <= Size.y / Devider.y; i++)
                {
                    if (i != 0)
                    {
                        if (ShowDevider)
                        {
                            Device.drawLine(new xyz(0, Devider.y * i, 0) - n1, new xyz(0, Devider.y * i, 0) + n1);
                        }
                        if (ShowText)
                        {
                            double Pos = Devider.x * i - ((float)Device.getEnvText(Font, i.ToString()).y / 2f);

                            Device.drawText(Font, Matrix.Translation(new xyz(DeviderLineLength, Pos, 0)), i.ToString(), 0);
                        }
                    }
                }
                if (Dim3d)
                {
                    for (int i = from; i <= Size.z / Devider.z; i++)
                    {
                        if (i != 0)
                        {
                            if (ShowDevider)
                            {
                                Device.drawLine(new xyz(0, 0, Devider.z * i) - n1, new xyz(0, 0, Devider.z * i) + n1);
                            }
                            if (ShowText)
                            {
                                double Pos = Devider.z * i - ((float)Device.getEnvText(Font, i.ToString()).y / 2f);

                                Device.drawText(Font, Matrix.Translation(new xyz(DeviderLineLength, 0, Pos)), i.ToString(), 0);
                            }
                        }
                    }
                }
            }
            if (Device.RenderKind == RenderKind.SnapBuffer)
            {
                if (LeftAndRight)
                {
                    Device.drawLine(new xyz(-Size.x, 0, 0), new xyz(Size.x, 0, 0));
                    Device.drawLine(new xyz(0, -Size.y, 0), new xyz(0, Size.y, 0));
                    if (Dim3d)
                    {
                        Device.drawLine(new xyz(0, 0, -Size.z), new xyz(0, 0, Size.z));
                    }
                }
                else
                if (LeftAndRight)
                {
                    Device.drawLine(new xyz(0, 0, 0), new xyz(Size.x, 0, 0));
                    Device.drawLine(new xyz(0, 0, 0), new xyz(0, Size.y, 0));
                    if (Dim3d)
                    {
                        Device.drawLine(new xyz(0, 0, 0), new xyz(0, 0, Size.z));
                    }
                }
                for (int i = from; i <= Size.x / Devider.x; i++)
                {
                    Device.drawPoint(new xyz(Devider.x * i, 0, 0), Devider.x / 4);
                    if (ShowText)
                    {
                        double        Pos = Devider.x * i - ((float)Device.getEnvText(Font, i.ToString()).x / 2f);
                        MeshContainer M   = MeshCreator.MeshListCurrent;
                        Device.drawText(Font, Matrix.Translation(new xyz(Pos, DeviderLineLength, 0)), i.ToString(), 0);
                        M = MeshCreator.MeshListCurrent;
                    }
                }


                from = (int)(-Size.y / Devider.y);
                if (!LeftAndRight)
                {
                    from = 0;
                }
                n1 = new xyz(DeviderLineLength, 0, 0);
                for (int i = from; i <= Size.y / Devider.y; i++)
                {
                    if (i != 0)
                    {
                        Device.drawPoint(new xyz(0, Devider.y * i, 0), Devider.x / 4);
                        if (ShowText)
                        {
                            double Pos = Devider.x * i - ((float)Device.getEnvText(Font, i.ToString()).y / 2f);

                            Device.drawText(Font, Matrix.Translation(new xyz(DeviderLineLength, Pos, 0)), i.ToString(), 0);
                        }
                    }
                }
                if (Dim3d)
                {
                    for (int i = from; i <= Size.z / Devider.z; i++)
                    {
                        if (i != 0)
                        {
                            Device.drawPoint(new xyz(0, 0, Devider.z * i), Devider.x / 4);

                            if (ShowText)
                            {
                                double Pos = Devider.z * i - ((float)Device.getEnvText(Font, i.ToString()).y / 2f);

                                Device.drawText(Font, Matrix.Translation(new xyz(DeviderLineLength, 0, Pos)), i.ToString(), 0);
                            }
                        }
                    }
                }
            }

            Device.Emission     = Save;
            Device.LightEnabled = SaveLighting;
            Font.FontSize       = SaveFontSize;
            Device.PopMatrix();
        }