Example #1
0
 public TriList(TriList t)
 {
     verts.AddRange(t.verts);
     textureEnabled = t.textureEnabled;
     textureName    = t.textureName;
     GenerateIndices();
 }
Example #2
0
        //convert this abomination to a model import
        public void AddCone(string name, Color c)
        {
            TriList modl = new TriList();

            modl.textureEnabled = false;

            List <VertexPositionColorTexture> vptc = new List <VertexPositionColorTexture>();

            Color c1 = Color.Lerp(Color.LightGray, c, 0.5f);
            Color c2 = Color.Lerp(Color.Black, c, 0.5f);

            vptc.Add(new VertexPositionColorTexture(new Vector3(10, 50, -10), c1, new Vector2(0, 0)));
            vptc.Add(new VertexPositionColorTexture(new Vector3(-10, 50, -10), c1, new Vector2(0, 0)));
            vptc.Add(new VertexPositionColorTexture(new Vector3(0, 0, 0), c2, new Vector2(0, 0)));
            vptc.Add(new VertexPositionColorTexture(new Vector3(-10, 50, 10), c1, new Vector2(0, 0)));
            modl.PushQuad(vptc);

            vptc.Clear();
            vptc.Add(new VertexPositionColorTexture(new Vector3(-10, 50, 10), c1, new Vector2(0, 0)));
            vptc.Add(new VertexPositionColorTexture(new Vector3(10, 50, 10), c1, new Vector2(0, 0)));
            vptc.Add(new VertexPositionColorTexture(new Vector3(0, 0, 0), c2, new Vector2(0, 0)));
            vptc.Add(new VertexPositionColorTexture(new Vector3(10, 50, -10), c1, new Vector2(0, 0)));
            modl.PushQuad(vptc);

            vptc.Clear();
            vptc.Add(new VertexPositionColorTexture(new Vector3(10, 50, -10), c1, new Vector2(0, 0)));
            vptc.Add(new VertexPositionColorTexture(new Vector3(10, 50, 10), c1, new Vector2(0, 0)));
            vptc.Add(new VertexPositionColorTexture(new Vector3(-10, 50, -10), c1, new Vector2(0, 0)));
            vptc.Add(new VertexPositionColorTexture(new Vector3(-10, 50, 10), c1, new Vector2(0, 0)));
            modl.PushQuad(vptc);

            modl.Seal();

            ContentVault.Models.Add(name, modl);
        }
Example #3
0
        public MGLevel(SkyBox sb)
        {
            normal.textureEnabled   = false;
            normal.scrollingEnabled = false;

            for (int i = 0; i < sb.faces.Count; i++)
            {
                List <VertexPositionColorTexture> tri = new List <VertexPositionColorTexture>();
                tri.Add(MGConverter.ToVptc(sb.verts[sb.faces[i].X], new CTRFramework.Shared.Vector2b(0, 0), 0.01f));
                tri.Add(MGConverter.ToVptc(sb.verts[sb.faces[i].Y], new CTRFramework.Shared.Vector2b(0, 0), 0.01f));
                tri.Add(MGConverter.ToVptc(sb.verts[sb.faces[i].Z], new CTRFramework.Shared.Vector2b(0, 0), 0.01f));

                normal.PushTri(tri);
            }

            normal.Seal();

            wire = new TriList(normal);
            wire.SetColor(Color.Red);
        }
Example #4
0
        private void LoadLevel()
        {
            if (File.Exists("karts.lev"))
            {
                Scene karts = Scene.FromFile("karts.lev");

                foreach (LODModel m in karts.dynamics)
                {
                    if (!instTris.ContainsKey(m.name) && m.name == "selectkart")
                    {
                        List <VertexPositionColorTexture> li = new List <VertexPositionColorTexture>();

                        foreach (var x in m.lh[0].verts)
                        {
                            li.Add(MGConverter.ToVptc(x, new Vector2b(0, 0)));
                        }

                        TriList t = new TriList();
                        t.textureEnabled   = false;
                        t.textureName      = "test";
                        t.scrollingEnabled = false;
                        t.PushTri(li);
                        t.Seal();

                        instTris.Add(m.name, t);
                    }
                }
            }

            RenderEnabled = false;

            //wait for the end of frame
            while (IsDrawing)
            {
            }
            ;

            Stopwatch sw = new Stopwatch();

            sw.Start();

            Console.WriteLine("LoadLevel()");

            scn.Clear();
            levels.Clear();
            quads_low.Clear();
            instanced.Clear();

            string[] files = new string[] { };

            if (Directory.Exists(@"levels\"))
            {
                files = Directory.GetFiles(@"levels\", "*.lev");
            }

            if (files.Length == 0)
            {
                Console.WriteLine("no files");
                return;
            }

            foreach (string s in files)
            {
                scn.Add(Scene.FromFile(s));
            }

            Console.WriteLine("scenes parsed at: " + sw.Elapsed.TotalSeconds);


            foreach (Scene s in scn)
            {
                levels.Add(new MGLevel(s, Detail.Med));
                quads_low.Add(new MGLevel(s, Detail.Low));
            }

            Console.WriteLine("converted scenes to monogame render at: " + sw.Elapsed.TotalSeconds);

            //force 1st scene sky and back color
            if (scn.Count > 0)
            {
                backColor = MGConverter.ToColor(scn[0].header.backColor);
                if (scn[0].skybox != null)
                {
                    sky = new MGLevel(scn[0].skybox);
                }
            }

            foreach (Scene s in scn)
            {
                if (s.unkadv != null)
                {
                    foreach (PosAng pa in s.unkadv.smth)
                    {
                        instanced.Add(new InstancedModel("limecone", new Vector3(pa.Position.X, pa.Position.Y, pa.Position.Z), Vector3.Zero, 3));
                    }
                }

                if (s.header.ptru2 != 0)
                {
                    foreach (Vector3s v in s.posu2)
                    {
                        instanced.Add(new InstancedModel("goldcone", new Vector3(v.X, v.Y, v.Z), Vector3.Zero, 3));
                    }
                }

                if (s.header.ptrTrialData != 0)
                {
                    foreach (PosAng v in s.posu1)
                    {
                        instanced.Add(new InstancedModel("browncone", new Vector3(v.Position.X, v.Position.Y, v.Position.Z), Vector3.Zero, 30));
                    }
                }
            }


            foreach (Scene s in scn)
            {
                foreach (LODModel m in s.dynamics)
                {
                    if (!instTris.ContainsKey(m.name))
                    {
                        List <VertexPositionColorTexture> li = new List <VertexPositionColorTexture>();

                        foreach (var x in m.lh[0].verts)
                        {
                            li.Add(MGConverter.ToVptc(x, new Vector2b(0, 0)));
                        }

                        TriList t = new TriList();
                        t.textureEnabled   = false;
                        t.textureName      = "test";
                        t.scrollingEnabled = false;
                        t.PushTri(li);
                        t.Seal();

                        instTris.Add(m.name, t);
                    }
                }
            }

            karts.Add(new Kart("selectkart", MGConverter.ToVector3(scn[0].header.startGrid[0].Position), Vector3.Left, 0.5f));


            Console.WriteLine("extracted dynamics at: " + sw.Elapsed.TotalSeconds);



            foreach (Scene s in scn)
            {
                foreach (PosAng pa in s.header.startGrid)
                {
                    instanced.Add(new InstancedModel("purplecone", new Vector3(pa.Position.X, pa.Position.Y, pa.Position.Z), Vector3.Zero, 3));
                }

                foreach (PickupHeader ph in s.pickups)
                {
                    instanced.Add(new InstancedModel(
                                      ph.ModelName,
                                      new Vector3(ph.Position.X, ph.Position.Y, ph.Position.Z),
                                      new Vector3((float)(ph.Angle.X / 4094f * Math.PI * 2), (float)(ph.Angle.Y / 4094f * Math.PI * 2), (float)(ph.Angle.Z / 4094f * Math.PI * 2)),
                                      1));
                }

                foreach (PosAng n in s.restartPts)
                {
                    paths.Add(new InstancedModel("cyancone", new Vector3(n.Position.X, n.Position.Y, n.Position.Z), Vector3.Zero, 3));
                }

                if (s.nav.paths.Count == 3)
                {
                    foreach (NavFrame n in s.nav.paths[0].frames)
                    {
                        paths.Add(new InstancedModel("greencone", new Vector3(n.position.X, n.position.Y, n.position.Z), Vector3.Zero, 3));
                    }
                    foreach (NavFrame n in s.nav.paths[1].frames)
                    {
                        paths.Add(new InstancedModel("yellowcone", new Vector3(n.position.X, n.position.Y, n.position.Z), Vector3.Zero, 3));
                    }
                    foreach (NavFrame n in s.nav.paths[2].frames)
                    {
                        paths.Add(new InstancedModel("redcone", new Vector3(n.position.X, n.position.Y, n.position.Z), Vector3.Zero, 3));
                    }
                }
            }


            foreach (Scene s in scn)
            {
                s.ExportTexturesAll("levels\\tex");
            }

            Console.WriteLine("textures extracted at: " + sw.Elapsed.TotalSeconds);

            //files = Directory.GetFiles("tex", "*.png");

            foreach (MGLevel q in levels)
            {
                LoadTextures(q);
            }
            foreach (MGLevel q in quads_low)
            {
                LoadTextures(q);
            }

            sw.Stop();

            Console.WriteLine("textures loaded. level done: " + sw.Elapsed.TotalSeconds);

            RenderEnabled = true;
        }
Example #5
0
        private void LoadLevel(string[] lev)
        {
            if (lev == null)
            {
                lev = new string[] { }
            }
            ;

            Dispose();
            LoadGenericTextures(); //making sure we have default textures loaded. maybe should just allocate statically?

            if (File.Exists("karts.lev"))
            {
                Scene karts = Scene.FromFile("karts.lev");

                foreach (CtrModel m in karts.dynamics)
                {
                    if (!instTris.ContainsKey(m.Name) && m.Name == "selectkart")
                    {
                        List <VertexPositionColorTexture> li = new List <VertexPositionColorTexture>();

                        foreach (var x in m.headers[0].verts)
                        {
                            li.Add(MGConverter.ToVptc(x, new Vector2b(0, 0), 0.01f));
                        }

                        TriList t = new TriList();
                        t.textureEnabled   = false;
                        t.textureName      = "test";
                        t.scrollingEnabled = false;
                        t.PushTri(li);
                        t.Seal();

                        instTris.Add(m.Name, t);
                    }
                }
            }

            RenderEnabled = false;

            //wait for the end of frame, in case we are still rendering.
            while (IsDrawing)
            {
            }
            ;

            Stopwatch sw = new Stopwatch();

            sw.Start();

            Console.WriteLine("LoadLevel()");

            string[] files = new string[] { };

            if (lev.Length == 0)
            {
                if (Directory.Exists(@"levels\"))
                {
                    files = Directory.GetFiles(@"levels\", "*.lev");
                }
            }
            else
            {
                files = lev;
            }

            if (files.Length == 0)
            {
                Console.WriteLine("no files");
                return;
            }

            foreach (string s in files)
            {
                scn.Add(Scene.FromFile(s));
            }

            Console.WriteLine("scenes parsed at: " + sw.Elapsed.TotalSeconds);

            //loading textures between scenes and conversion to monogame for alpha textures info
            LoadTextures();

            foreach (Scene s in scn)
            {
                MeshHigh.Add(new MGLevel(s, Detail.Med));
                MeshLow.Add(new MGLevel(s, Detail.Low));
            }

            Console.WriteLine("converted scenes to monogame render at: " + sw.Elapsed.TotalSeconds);

            //force 1st scene sky and back color
            if (scn.Count > 0)
            {
                backColor = MGConverter.ToColor(scn[0].header.backColor);
                if (scn[0].skybox != null)
                {
                    sky = new MGLevel(scn[0].skybox);
                }
            }

            foreach (Scene s in scn)
            {
                if (s.unkadv != null)
                {
                    foreach (var pa in s.unkadv.smth)
                    {
                        instanced.Add(new InstancedModel("limecone", MGConverter.ToVector3(pa.Position, 0.01f), Vector3.Zero, 0.03f));
                    }
                }

                if (s.header.ptru2 != 0)
                {
                    foreach (var v in s.posu2)
                    {
                        instanced.Add(new InstancedModel("goldcone", MGConverter.ToVector3(v, 0.01f), Vector3.Zero, 0.03f));
                    }
                }

                if (s.header.ptrTrialData != 0)
                {
                    foreach (var v in s.posu1)
                    {
                        instanced.Add(new InstancedModel("browncone", MGConverter.ToVector3(v.Position, 0.01f), Vector3.Zero, 0.03f));
                    }
                }
            }


            foreach (Scene s in scn)
            {
                foreach (CtrModel m in s.dynamics)
                {
                    if (!instTris.ContainsKey(m.Name))
                    {
                        List <VertexPositionColorTexture> li = new List <VertexPositionColorTexture>();

                        foreach (var x in m.headers[0].verts)
                        {
                            li.Add(MGConverter.ToVptc(x, new Vector2b(0, 0), 0.01f));
                        }

                        TriList t = new TriList();
                        t.textureEnabled   = false;
                        t.textureName      = "test";
                        t.scrollingEnabled = false;
                        t.PushTri(li);
                        t.Seal();

                        instTris.Add(m.Name, t);
                    }
                }
            }

            //karts.Add(new Kart("selectkart", MGConverter.ToVector3(scn[0].header.startGrid[0].Position), Vector3.Left, 0.5f));


            Console.WriteLine("extracted dynamics at: " + sw.Elapsed.TotalSeconds);

            foreach (Scene s in scn)
            {
                foreach (var pa in s.header.startGrid)
                {
                    instanced.Add(new InstancedModel("purplecone", MGConverter.ToVector3(pa.Position, 0.01f), Vector3.Zero, 0.03f));
                }

                foreach (var ph in s.pickups)
                {
                    instanced.Add(new InstancedModel(
                                      ph.ModelName,
                                      MGConverter.ToVector3(ph.Position, 0.01f),
                                      Vector3.Zero,//new Vector3((float)(ph.Angle.X / 4094f * Math.PI * 2), (float)(ph.Angle.Y / 4094f * Math.PI * 2), (float)(ph.Angle.Z / 4094f * Math.PI * 2)),
                                      1f));
                }

                foreach (var n in s.restartPts)
                {
                    paths.Add(new InstancedModel("cyancone", MGConverter.ToVector3(n.Position, 0.01f), Vector3.Zero, 0.03f));
                }

                if (s.nav.paths.Count == 3)
                {
                    foreach (NavFrame n in s.nav.paths[0].frames)
                    {
                        paths.Add(new InstancedModel("greencone", MGConverter.ToVector3(n.position, 0.01f), Vector3.Zero, 0.03f));
                    }
                    foreach (NavFrame n in s.nav.paths[1].frames)
                    {
                        paths.Add(new InstancedModel("yellowcone", MGConverter.ToVector3(n.position, 0.01f), Vector3.Zero, 0.03f));
                    }
                    foreach (NavFrame n in s.nav.paths[2].frames)
                    {
                        paths.Add(new InstancedModel("redcone", MGConverter.ToVector3(n.position, 0.01f), Vector3.Zero, 0.03f));
                    }
                }
            }



            //foreach (Scene s in scn)
            //    s.ExportTexturesAll(Path.Combine(Meta.BasePath, "levels\\tex"));


            Console.WriteLine("textures extracted at: " + sw.Elapsed.TotalSeconds);

            //files = Directory.GetFiles("tex", "*.png");

            foreach (Scene s in scn)
            {
                BspDraw(s.visdata[0], s, 0);
            }

            sw.Stop();

            Console.WriteLine("textures loaded. level done: " + sw.Elapsed.TotalSeconds);

            UpdateEffects();

            RenderEnabled = true;
        }