Exemplo n.º 1
0
 public ModelMesh(string _name, Mesh orig)
 {
     Original = orig;
     Name     = _name.ToLower();
     if (Name.EndsWith(".001"))
     {
         Name = Name.Substring(0, Name.Length - ".001".Length);
     }
     Faces = new List <ModelFace>();
     vbo   = new VBO();
 }
Exemplo n.º 2
0
        /// <summary>
        /// Draws the model.
        /// </summary>
        public void Draw(double aTimeHead = 0, SingleAnimation headanim = null, double aTimeTorso = 0, SingleAnimation torsoanim = null, double aTimeLegs = 0, SingleAnimation legsanim = null)
        {
            hAnim = headanim;
            tAnim = torsoanim;
            lAnim = legsanim;
            bool any = hAnim != null || tAnim != null || lAnim != null;

            if (any)
            {
                if (hAnim != null)
                {
                    Engine = hAnim.Engine;
                }
                else if (tAnim != null)
                {
                    Engine = tAnim.Engine;
                }
                else
                {
                    Engine = lAnim.Engine;
                }
                globalInverse = Root.Inverted();
                aTHead        = aTimeHead;
                aTTorso       = aTimeTorso;
                aTLegs        = aTimeLegs;
                UpdateTransforms(RootNode, Matrix4.Identity);
            }
            for (int i = 0; i < Meshes.Count; i++)
            {
                if (Meshes[i].Bones.Count > 0)
                {
                    Matrix4[] mats = new Matrix4[Meshes[i].Bones.Count];
                    for (int x = 0; x < Meshes[i].Bones.Count; x++)
                    {
                        mats[x] = Meshes[i].Bones[x].Transform;
                    }
                    SetBones(mats);
                }
                Meshes[i].Draw();
            }
            if (any)
            {
                VBO.BonesIdentity();
            }
        }
Exemplo n.º 3
0
 void GenerateBackgridVBO()
 {
     Vector3[] vecs  = new Vector3[4];
     uint[]    inds  = new uint[4];
     Vector3[] norms = new Vector3[4];
     Vector3[] texs  = new Vector3[4];
     Vector4[] cols  = new Vector4[4];
     for (uint u = 0; u < 4; u++)
     {
         inds[u] = u;
     }
     for (int n = 0; n < 4; n++)
     {
         norms[n] = new Vector3(0, 0, 1);
     }
     for (int c = 0; c < 4; c++)
     {
         cols[c] = new Vector4(1, 1, 1, 1);
     }
     Vector4[] BoneIDs     = new Vector4[4];
     Vector4[] BoneWeights = new Vector4[4];
     for (int n = 0; n < 4; n++)
     {
         BoneIDs[n]     = new Vector4(0, 0, 0, 0);
         BoneWeights[n] = new Vector4(0, 0, 0, 0);
     }
     vecs[0]              = new Vector3(10000, -10000, 0);
     texs[0]              = new Vector3(1000, -1000, 0);
     vecs[1]              = new Vector3(10000, 10000, 0);
     texs[1]              = new Vector3(1000, 1000, 0);
     vecs[2]              = new Vector3(-10000, 10000, 0);
     texs[2]              = new Vector3(-1000, 1000, 0);
     vecs[3]              = new Vector3(-10000, -10000, 0);
     texs[3]              = new Vector3(-1000, -1000, 0);
     Backgrid             = new VBO();
     Backgrid.Vertices    = vecs.ToList();
     Backgrid.Indices     = inds.ToList();
     Backgrid.Normals     = norms.ToList();
     Backgrid.TexCoords   = texs.ToList();
     Backgrid.Colors      = cols.ToList();
     Backgrid.BoneIDs     = BoneIDs.ToList();
     Backgrid.BoneWeights = BoneWeights.ToList();
     Backgrid.GenerateVBO();
 }
Exemplo n.º 4
0
 void GenerateLineVBO()
 {
     Vector3[] vecs  = new Vector3[2];
     uint[]    inds  = new uint[2];
     Vector3[] norms = new Vector3[2];
     Vector3[] texs  = new Vector3[2];
     Vector4[] cols  = new Vector4[2];
     for (uint u = 0; u < 2; u++)
     {
         inds[u] = u;
     }
     for (int n = 0; n < 2; n++)
     {
         norms[n] = new Vector3(0, 0, 1);
     }
     for (int c = 0; c < 2; c++)
     {
         cols[c] = new Vector4(1, 1, 1, 1);
     }
     Vector4[] BoneIDs     = new Vector4[2];
     Vector4[] BoneWeights = new Vector4[2];
     for (int n = 0; n < 2; n++)
     {
         BoneIDs[n]     = new Vector4(0, 0, 0, 0);
         BoneWeights[n] = new Vector4(0, 0, 0, 0);
     }
     vecs[0]          = new Vector3(0, 0, 0);
     texs[0]          = new Vector3(0, 0, 0);
     vecs[1]          = new Vector3(1, 0, 0);
     texs[1]          = new Vector3(1, 0, 0);
     Line             = new VBO();
     Line.Vertices    = vecs.ToList();
     Line.Indices     = inds.ToList();
     Line.Normals     = norms.ToList();
     Line.TexCoords   = texs.ToList();
     Line.Colors      = cols.ToList();
     Line.BoneIDs     = BoneIDs.ToList();
     Line.BoneWeights = BoneWeights.ToList();
     Line.GenerateVBO();
 }
Exemplo n.º 5
0
        /// <summary>
        /// Fully renders colorful/fancy text (unless the text is not marked as fancy, or fancy rendering is disabled)
        /// </summary>
        /// <param name="Text">The text to render</param>
        /// <param name="Position">Where to render the text at</param>
        /// <param name="MaxY">The maximum Y location to render text at.</param>
        /// <param name="transmod">Transparency modifier (EG, 0.5 = half opacity) (0.0 - 1.0)</param>
        /// <param name="extrashadow">Whether to always have a mini drop-shadow</param>
        public void DrawColoredText(string Text, Location Position, int MaxY = int.MaxValue, float transmod = 1, bool extrashadow = false)
        {
            string[] lines     = Text.Replace('\r', ' ').Replace(' ', (char)0x00A0).Replace("^q", "\"").Split('\n');
            int      color     = DefaultColor;
            int      trans     = (int)(255 * transmod);
            bool     bold      = false;
            bool     italic    = false;
            bool     underline = false;
            bool     strike    = false;
            bool     overline  = false;
            bool     highlight = false;
            bool     emphasis  = false;
            int      ucolor    = DefaultColor;
            int      scolor    = DefaultColor;
            int      ocolor    = DefaultColor;
            int      hcolor    = DefaultColor;
            int      ecolor    = DefaultColor;
            bool     super     = false;
            bool     sub       = false;
            bool     flip      = false;
            bool     pseudo    = false;
            bool     jello     = false;
            bool     obfu      = false;
            bool     random    = false;
            bool     shadow    = false;
            int      otrans    = (int)(255 * transmod);
            int      etrans    = (int)(255 * transmod);
            int      htrans    = (int)(255 * transmod);
            int      strans    = (int)(255 * transmod);
            int      utrans    = (int)(255 * transmod);
            float    X         = (float)Position.X;
            float    Y         = (float)Position.Y;
            GLFont   font      = font_default;

            for (int i = 0; i < lines.Length; i++)
            {
                string line = lines[i];
                if (line.Length == 0)
                {
                    Y += font_default.Height;
                    continue;
                }
                int start = 0;
                for (int x = 0; x < line.Length; x++)
                {
                    if ((line[x] == '^' && x + 1 < line.Length && IsColorSymbol(line[x + 1])) || (x + 1 == line.Length))
                    {
                        string drawme = line.Substring(start, (x - start) + ((x + 1 < line.Length) ? 0 : 1));
                        start = x + 2;
                        x++;
                        if (drawme.Length > 0 && Y >= -font.Height && Y - (sub ? font.Height : 0) <= MaxY)
                        {
                            float width = font.MeasureString(drawme);
                            if (highlight)
                            {
                                DrawRectangle(X, Y, width, font.Height, font, ColorFor(hcolor, htrans));
                            }
                            if (underline)
                            {
                                DrawRectangle(X, Y + ((float)font.Height * 4f / 5f), width, 1, font, ColorFor(ucolor, utrans));
                            }
                            if (overline)
                            {
                                DrawRectangle(X, Y + 2f, width, 1f, font, ColorFor(ocolor, otrans));
                            }
                            if (extrashadow)
                            {
                                foreach (Point point in ShadowPoints)
                                {
                                    RenderBaseText(X + point.X, Y + point.Y, drawme, font, 0, trans / 2, flip);
                                }
                            }
                            if (shadow)
                            {
                                foreach (Point point in ShadowPoints)
                                {
                                    RenderBaseText(X + point.X, Y + point.Y, drawme, font, 0, 255, flip);
                                }
                                foreach (Point point in BetterShadowPoints)
                                {
                                    RenderBaseText(X + point.X, Y + point.Y, drawme, font, 0, 255, flip);
                                }
                            }
                            if (emphasis)
                            {
                                foreach (Point point in EmphasisPoints)
                                {
                                    RenderBaseText(X + point.X, Y + point.Y, drawme, font, ecolor, etrans, flip);
                                }
                                foreach (Point point in BetterEmphasisPoints)
                                {
                                    RenderBaseText(X + point.X, Y + point.Y, drawme, font, ecolor, etrans, flip);
                                }
                            }
                            RenderBaseText(X, Y, drawme, font, color, trans, flip, pseudo, random, jello, obfu);
                            if (strike)
                            {
                                DrawRectangle(X, Y + (font.Height / 2), width, 1, font, ColorFor(scolor, strans));
                            }
                            X += width;
                        }
                        if (x < line.Length)
                        {
                            switch (line[x])
                            {
                            case '1': color = 1; break;

                            case '!': color = 11; break;

                            case '2': color = 2; break;

                            case '@': color = 12; break;

                            case '3': color = 3; break;

                            case '#': color = 13; break;

                            case '4': color = 4; break;

                            case '$': color = 14; break;

                            case '5': color = 5; break;

                            case '%': color = 15; break;

                            case '6': color = 6; break;

                            case '-': color = 16; break;

                            case '7': color = 7; break;

                            case '&': color = 17; break;

                            case '8': color = 8; break;

                            case '*': color = 18; break;

                            case '9': color = 9; break;

                            case '(': color = 19; break;

                            case '0': color = 0; break;

                            case ')': color = 20; break;

                            case 'a': color = 10; break;

                            case 'A': color = 21; break;

                            case 'i':
                            {
                                italic = true;
                                GLFont nfont = (super || sub) ? (bold ? font_bolditalichalf : font_italichalf) :
                                               (bold ? font_bolditalic : font_italic);
                                if (nfont != font)
                                {
                                    font = nfont;
                                }
                            }
                            break;

                            case 'b':
                            {
                                bold = true;
                                GLFont nfont = (super || sub) ? (italic ? font_bolditalichalf : font_boldhalf) :
                                               (italic ? font_bolditalic : font_bold);
                                if (nfont != font)
                                {
                                    font = nfont;
                                }
                            }
                            break;

                            case 'u': utrans = trans; underline = true; ucolor = color; break;

                            case 's': strans = trans; strike = true; scolor = color; break;

                            case 'h': htrans = trans; highlight = true; hcolor = color; break;

                            case 'e': etrans = trans; emphasis = true; ecolor = color; break;

                            case 'O': otrans = trans; overline = true; ocolor = color; break;

                            case 't': trans = (int)(128 * transmod); break;

                            case 'T': trans = (int)(64 * transmod); break;

                            case 'o': trans = (int)(255 * transmod); break;

                            case 'S':
                                if (!super)
                                {
                                    if (sub)
                                    {
                                        sub = false;
                                        Y  -= font.Height / 2;
                                    }
                                    GLFont nfont = bold && italic ? font_bolditalichalf : bold ? font_boldhalf :
                                                   italic ? font_italichalf : font_half;
                                    if (nfont != font)
                                    {
                                        font = nfont;
                                    }
                                }
                                super = true;
                                break;

                            case 'l':
                                if (!sub)
                                {
                                    if (super)
                                    {
                                        super = false;
                                    }
                                    Y += font_default.Height / 2;
                                    GLFont nfont = bold && italic ? font_bolditalichalf : bold ? font_boldhalf :
                                                   italic ? font_italichalf : font_half;
                                    if (nfont != font)
                                    {
                                        font = nfont;
                                    }
                                }
                                sub = true;
                                break;

                            case 'd': shadow = true; break;

                            case 'j': jello = true; break;

                            case 'k': obfu = true; break;

                            case 'R': random = true; break;

                            case 'p': pseudo = true; break;

                            case 'f': flip = true; break;

                            case 'n':
                                break;

                            case 'r':
                            {
                                GLFont nfont = font_default;
                                if (nfont != font)
                                {
                                    font = nfont;
                                }
                                if (sub)
                                {
                                    Y -= font_default.Height / 2;
                                }
                                sub       = false;
                                super     = false;
                                flip      = false;
                                random    = false;
                                pseudo    = false;
                                jello     = false;
                                obfu      = false;
                                shadow    = false;
                                bold      = false;
                                italic    = false;
                                underline = false;
                                strike    = false;
                                emphasis  = false;
                                highlight = false;
                                trans     = (int)(255 * transmod);
                                overline  = false;
                                break;
                            }

                            default:
                                break;
                            }
                        }
                    }
                }
                Y += font_default.Height;
                X  = (float)Position.X;
            }
            Engine.GLFonts.Shaders.TextCleanerShader.Bind();
            GL.UniformMatrix4(1, false, ref PrimaryEditor.ortho);
            Matrix4 ident = Matrix4.Identity;

            GL.UniformMatrix4(2, false, ref ident);
            Vector3 col = new Vector3(1, 1, 1);

            GL.Uniform3(3, ref col);
            VBO.Build();
            VBO.Render();
            VBO.Destroy();
            Engine.GLFonts.Shaders.ColorMultShader.Bind();
        }
Exemplo n.º 6
0
        void GenerateBoxVBO()
        {
            // TODO: Optimize?
            Vector3[] vecs  = new Vector3[24];
            uint[]    inds  = new uint[24];
            Vector3[] norms = new Vector3[24];
            Vector3[] texs  = new Vector3[24];
            Vector4[] cols  = new Vector4[24];
            for (uint u = 0; u < 24; u++)
            {
                inds[u] = u;
            }
            for (int t = 0; t < 24; t++)
            {
                texs[t] = new Vector3(0, 0, 0);
            }
            for (int n = 0; n < 24; n++)
            {
                norms[n] = new Vector3(0, 0, 1); // TODO: Accurate normals somehow? Do lines even have normals?
            }
            for (int c = 0; c < 24; c++)
            {
                cols[c] = new Vector4(1, 1, 1, 1);
            }
            Vector4[] BoneIDs     = new Vector4[24];
            Vector4[] BoneWeights = new Vector4[24];
            for (int n = 0; n < 24; n++)
            {
                BoneIDs[n]     = new Vector4(0, 0, 0, 0);
                BoneWeights[n] = new Vector4(0, 0, 0, 0);
            }
            int i    = 0;
            int zero = -1; // Ssh.

            vecs[i]         = new Vector3(zero, zero, zero); i++;
            vecs[i]         = new Vector3(1, zero, zero); i++;
            vecs[i]         = new Vector3(1, zero, zero); i++;
            vecs[i]         = new Vector3(1, 1, zero); i++;
            vecs[i]         = new Vector3(1, 1, zero); i++;
            vecs[i]         = new Vector3(zero, 1, zero); i++;
            vecs[i]         = new Vector3(zero, 1, zero); i++;
            vecs[i]         = new Vector3(zero, zero, zero); i++;
            vecs[i]         = new Vector3(zero, zero, 1); i++;
            vecs[i]         = new Vector3(1, zero, 1); i++;
            vecs[i]         = new Vector3(1, zero, 1); i++;
            vecs[i]         = new Vector3(1, 1, 1); i++;
            vecs[i]         = new Vector3(1, 1, 1); i++;
            vecs[i]         = new Vector3(zero, 1, 1); i++;
            vecs[i]         = new Vector3(zero, 1, 1); i++;
            vecs[i]         = new Vector3(zero, zero, 1); i++;
            vecs[i]         = new Vector3(zero, zero, zero); i++;
            vecs[i]         = new Vector3(zero, zero, 1); i++;
            vecs[i]         = new Vector3(1, zero, zero); i++;
            vecs[i]         = new Vector3(1, zero, 1); i++;
            vecs[i]         = new Vector3(1, 1, zero); i++;
            vecs[i]         = new Vector3(1, 1, 1); i++;
            vecs[i]         = new Vector3(zero, 1, zero); i++;
            vecs[i]         = new Vector3(zero, 1, 1); i++;
            Box             = new VBO();
            Box.Vertices    = vecs.ToList();
            Box.Indices     = inds.ToList();
            Box.Normals     = norms.ToList();
            Box.TexCoords   = texs.ToList();
            Box.Colors      = cols.ToList();
            Box.BoneIDs     = BoneIDs.ToList();
            Box.BoneWeights = BoneWeights.ToList();
            Box.GenerateVBO();
        }