예제 #1
0
 public Model(ModelPart Root)
 {
     this.Children = new List <ModelPart>
     {
         Root
     };
 }
예제 #2
0
        public static string ColourToCode(Color input)
        {
            byte R, G, B;

            R = input.R;
            G = input.G;
            B = input.B;
            return(R + ":" + G + ":" + B);
        }
예제 #3
0
 public void Append(ModelPart part, Matrix transform)
 {
     part.Dislocation = transform;
     if (this.Children == null)
     {
         this.Children = new List <ModelPart>();
     }
     this.Children.Add(part);
 }
예제 #4
0
        public Model()
        {
            this.Children = new List <ModelPart>();
            ModelPart Root = new ModelPart();

            ModelVertex[] vertices = new ModelVertex[8];
            vertices[0] = new ModelVertex(new Vector3(-1.5f, 0.5f, -0.5f), Color.DarkGray);
            vertices[1] = new ModelVertex(new Vector3(0.5f, 0.2f, 0.2f), Color.DarkGray);
            vertices[2] = new ModelVertex(new Vector3(-1.5f, 0.5f, 0.5f), Color.DarkGray);
            vertices[3] = new ModelVertex(new Vector3(0.5f, 0.2f, -0.2f), Color.DarkGray);

            vertices[4] = new ModelVertex(new Vector3(-1.5f, -0.5f, -0.5f), Color.DarkGray);
            vertices[5] = new ModelVertex(new Vector3(0.5f, -0.2f, 0.2f), Color.DarkGray);
            vertices[6] = new ModelVertex(new Vector3(-1.5f, -0.5f, 0.5f), Color.DarkGray);
            vertices[7] = new ModelVertex(new Vector3(0.5f, -0.2f, -0.2f), Color.DarkGray);
            Root.SetVertices(vertices);
            Root.SetIndices(new int[] { //--,++,-+/--,+-,++
                0, 1, 2, 0, 3, 1
                , 4, 6, 5, 4, 5, 7
                , 4, 2, 6, 4, 0, 2
                , 7, 5, 1, 7, 1, 3
                , 6, 2, 1, 6, 1, 5
                , 4, 3, 0, 4, 7, 3
            });

            ModelPart leg;
            ModelPart eye;

            leg            = new TestParts.PartBugLeg();
            eye            = new TestParts.PartLight(Color.Blue);
            eye.BoneFactor = 0.33f;

            leg.Append(eye, Matrix.CreateTranslation(new Vector3(0.2f, 0.8f, 0.0f)));
            Root.Append(leg, Matrix.CreateRotationY((float)Math.PI * 0.3f) * Matrix.CreateTranslation(new Vector3(0.4f, 0, -0.5f)));
            leg = new TestParts.PartBugLeg();
            leg.Animation.SetPhase(0.5f);
            Root.Append(leg, Matrix.CreateRotationY((float)Math.PI * 0.5f) * Matrix.CreateTranslation(new Vector3(0, 0, -0.5f)));
            leg = new TestParts.PartBugLeg();
            Root.Append(leg, Matrix.CreateRotationY((float)Math.PI * 0.8f) * Matrix.CreateTranslation(new Vector3(-0.4f, 0, -0.5f)));

            leg = new TestParts.PartBugLeg(true);
            leg.Animation.SetPhase(0.5f);
            eye            = new TestParts.PartLight(Color.Blue);
            eye.BoneFactor = 0.33f;
            leg.Append(eye, Matrix.CreateTranslation(new Vector3(0.2f, 0.8f, 0.0f)));

            Root.Append(leg, Matrix.CreateRotationY((float)Math.PI * 1.8f) * Matrix.CreateTranslation(new Vector3(0.4f, 0, 0.5f)));
            leg = new TestParts.PartBugLeg(true);
            Root.Append(leg, Matrix.CreateRotationY((float)Math.PI * 1.5f) * Matrix.CreateTranslation(new Vector3(0, 0, 0.5f)));
            leg = new TestParts.PartBugLeg(true);
            leg.Animation.SetPhase(0.5f);
            Root.Append(leg, Matrix.CreateRotationY((float)Math.PI * 1.3f) * Matrix.CreateTranslation(new Vector3(-0.4f, 0, 0.5f)));

            this.Children.Add(Root);
        }
예제 #5
0
        ModelPart ReadPart()
        {
            ModelPart result = new ModelPart();

            LineSplitter       ls       = new LineSplitter(lines[state.LineNumber]);
            List <ModelVertex> vertices = new List <ModelVertex>();

            while (ls.Next() != "#endpart")
            {
                ls.Reset();
                switch (ls.Next())
                {
                case "#beginpoints":
                {
                    state.LineNumber++;
                    result.SetVertices(this.ReadPoints());
                    break;
                }

                case "#beginmesh":
                {
                    state.LineNumber++;
                    result.SetIndices(this.ReadMesh());
                    break;
                }

                case "#texture":     //TODO: set part's tex
                {
                    result.TextureName = ls.NextQuoted();
                    if (!Textures.Contains(result.TextureName))
                    {
                        Textures.Add(result.TextureName);
                    }
                    break;
                }

                case "#billboard":     //TODO: turn into PartLight, set tex and bb type
                {
                    result = ReadBB(ls);
                    break;
                }

                default:     //throw an error or something lol
                {
                    break;
                }
                }
                state.LineNumber++;
                ls = new LineSplitter(lines[state.LineNumber]);
            }

            return(result);
        }
예제 #6
0
        ModelPart ReadBB(LineSplitter ls)
        {
            ModelPart result = new ModelPart();

            string type = ls.Next();
            int    H    = ls.NextInt();
            int    W    = ls.NextInt();
            Color  c;

            string[] rgb;
            rgb = ls.Next().Split(':');
            c   = new Microsoft.Xna.Framework.Color(int.Parse(rgb[0]), int.Parse(rgb[1]), int.Parse(rgb[2]));
            TestParts.PartLight p = new TestParts.PartLight(c);
            p.Width  = W;
            p.Height = H;
            result   = p;

            return(result);
        }
예제 #7
0
        public virtual object Clone()
        {
            ModelPart p = (ModelPart)this.MemberwiseClone();

            if (this.Animation != null)
            {
                p.Animation = (PartAnimation)this.Animation.Clone();
            }
            if (this.Children != null)
            {
                List <ModelPart> c = new List <ModelPart>();
                foreach (ModelPart part in this.Children)
                {
                    c.Add((ModelPart)part.Clone());
                }

                p.Children = c;
            }
            return(p);
        }
예제 #8
0
        void AssembleModel(Dictionary <string, ModelPart> parts)
        {
            LineSplitter      ls          = new LineSplitter(lines[state.LineNumber]);
            ModelPart         root        = new ModelPart();
            Stack <ModelPart> TreeBuilder = new Stack <ModelPart>();
            ModelPart         last;
            Model             Model;
            int depth;

            while (ls.Next() != "#endassembly")
            {
                ls.Reset();
                string name  = "";
                string first = ls.Next(); //first token

                if (first[0] == '*')      //if first character is *, count
                {
                    depth = first.Length;
                }
                else //root part
                {
                    depth = 0;
                    ls.Reset(); //rewind
                }

                name = ls.NextQuoted();           //part "name" used in animation
                string partname = ls.Next();
                if (!parts.ContainsKey(partname)) //find part by name from loaded parts
                {
                    state.LineNumber++;
                    ls = new LineSplitter(lines[state.LineNumber]);
                    continue;                  //skip if invalid part
                }
                Matrix m = ls.NextTransform(); //get whatever transforms are there

                ModelPart next = (ModelPart)parts[partname].Clone();
                //both cool with 0 as default
                next.Phase      = ls.NextFloat();
                next.BoneFactor = ls.NextFloat();
                next.Title      = name;
                //determine correct parent
                while (depth < TreeBuilder.Count)      //go back part by part until correct part is found (
                {
                    TreeBuilder.Pop();
                }
                if (depth != 0)     //the stack is not empty and its top is the last parent
                {
                    TreeBuilder.Peek().Append(next, m);
                }
                else
                {
                    root = next;
                }
                TreeBuilder.Push(next);     //put current as last parent


                state.LineNumber++;
                ls = new LineSplitter(lines[state.LineNumber]);
            }
            Model  = new Model(root);
            Output = Model;
            R      = root;
        }
예제 #9
0
        public static Dictionary <string, Dictionary <string, PartAnimation> > LoadChoreo(string input)
        {
            Dictionary <string, Dictionary <string, PartAnimation> > result = new Dictionary <string, Dictionary <string, PartAnimation> >();

            string[] filelines = SplitLines(input);
            int      pointer   = 0;
            Dictionary <string, PartAnimation> CurrentMove = new Dictionary <string, PartAnimation>();
            string        CurrentMoveName = "";
            string        CurrentPartName = "";
            PartAnimation CurrentPart     = new PartAnimation();
            LineSplitter  ls;

            while (pointer < filelines.Length)
            {
                ls = new LineSplitter(filelines[pointer]);
                string cmd = ls.Next();
                switch (cmd)
                {
                case "#beginmove":
                {
                    CurrentMove     = new Dictionary <string, PartAnimation>();
                    CurrentMoveName = ls.NextQuoted();
                    break;
                }

                case "#endmove":
                {
                    if (result.ContainsKey(CurrentMoveName))
                    {
                        break;
                    }
                    result.Add(CurrentMoveName, CurrentMove);
                    break;
                }

                case "#beginpart":
                {
                    CurrentPart     = new PartAnimation();
                    CurrentPartName = ls.NextQuoted();
                    break;
                }

                case "#endpart":
                {
                    if (CurrentMove.ContainsKey(CurrentPartName))
                    {
                        break;
                    }
                    CurrentMove.Add(CurrentPartName, CurrentPart);
                    break;
                }

                case "#beginchoreo":
                {
                    break;
                }

                case "#endchoreo":
                {
                    break;
                }

                case "#moveparam":
                {
                    break;
                }

                default:
                {
                    ls.Reset();
                    float  duration  = ls.NextFloat();
                    Matrix transform = ls.NextTransform();
                    CurrentPart.Add(transform, duration);
                    break;
                }
                }

                pointer++;
            }

            return(result);
        }