예제 #1
0
 public void BuildData(ref List <Model3D.MeshData> meshes)
 {
     finalMesh = newFinalMesh();
     for (int t = 0; t < TempMeshes.Count; t++)
     {
         uint             indexCount = 0;
         Model3D.MeshData md         = new Model3D.MeshData();
         Bitmap           bmp        = textureImages[t];
         md.texture = ContentPipe.LoadTexture(ref bmp);
         md.texture.TextureParamS = textureInfo[t].wrapS;
         md.texture.TextureParamT = textureInfo[t].wrapT;
         TempMesh temp = TempMeshes[t];
         for (int i = 0; i < temp.vertices.Count; i++)
         {
             int vExists = doesVertexAlreadyExist(t, temp.vertices[i], temp.texCoords[i], temp.colors[i]);
             if (vExists < 0)
             {
                 Vector2 texCoord = temp.texCoords[i];
                 texCoord.X /= (float)bmp.Width * 32.0f;
                 texCoord.Y /= (float)bmp.Height * 32.0f;
                 temp.final.vertices.Add(temp.vertices[i]);
                 temp.final.texCoords.Add(texCoord);
                 temp.final.colors.Add(temp.colors[i]);
                 temp.final.indices.Add(indexCount);
                 indexCount++;
             }
             else
             {
                 temp.final.indices.Add((uint)vExists);
             }
         }
         meshes.Add(md);
     }
 }
예제 #2
0
파일: Player.cs 프로젝트: 29942016/opengl
 public Player(Vector2 startPos)
 {
     Position      = startPos;
     Velocity      = Vector2.Zero;
     _Climbing     = false;
     _FacingRight  = false;
     _OnLadder     = false;
     _Grounded     = false;
     _Size         = new Vector2(40, 80);
     _PlayerSprite = ContentPipe.LoadTexture("player.png");
 }
예제 #3
0
 public CollisionTriangleList(int ID)
 {
     id           = ID;
     indicesList  = new List <uint>();
     textureColor = new Bitmap(1, 1);
     textureColor.SetPixel(0, 0,
                           Color.FromArgb(
                               random.Next(0, 255),
                               random.Next(0, 255),
                               random.Next(0, 255)
                               )
                           );
     texture = ContentPipe.LoadTexture(ref textureColor);
 }
예제 #4
0
        private void glControl1_Load(object sender, EventArgs e)
        {
            OpenTK.Graphics.OpenGL.GL.Enable(EnableCap.Texture2D);
            Application.Idle += Application_Idle;
            loaded            = true;
            GL.ClearColor(Color.SkyBlue);

            //GL.Enable(EnableCap.Texture2D);

            tileset = ContentPipe.LoadTexture("Tiles.png");
            view    = new ViewGame(Vector2.Zero, 0.5f, 0);
            level   = new Level("../../../GameLogic/Content/LevelOneNew.json");
            //var mouse = Mouse.GetState();
            // Input.Initialize(this);


            glControl1.MouseDown += GlControl1_MouseDown;
        }
예제 #5
0
        public void BuildData(List <Model3D.MeshData> meshes)
        {
            //TextureAtlasBuilder.TextureAtlas atlas = new TextureAtlasBuilder.TextureAtlas(textureImages);
            //atlas.outputToPNG("TestAtlas.png");

            finalMesh = newFinalMesh();
            for (int t = 0; t < TempMeshes.Count; t++)
            {
                uint indexCount = 0;
                meshes.Add(new Model3D.MeshData());
                //if (t != 0) continue;
                //TextureAtlasBuilder.TextureAtlas.AtlasEntry atlasEntry = atlas.getEntryFromID((uint)t);
                Model3D.MeshData md = meshes[t];
                md.texture = ContentPipe.LoadTexture(textureImages[t]);
                md.texture.TextureParamS = textureInfo[t].wrapS;
                md.texture.TextureParamT = textureInfo[t].wrapT;
                //Console.WriteLine("[Building]: " + (OpenTK.Graphics.OpenGL.All)md.texture.TextureParamS + "," +(OpenTK.Graphics.OpenGL.All)md.texture.TextureParamT);
                TempMesh temp = TempMeshes[t];
                for (int i = 0; i < temp.vertices.Count; i++)
                {
                    int vExists = doesVertexAlreadyExist(t, temp.vertices[i], temp.texCoords[i], temp.colors[i]);
                    if (vExists < 0)
                    {
                        Vector2 texCoord = temp.texCoords[i];
                        texCoord.X /= (float)textureImages[t].Width * 32.0f;
                        texCoord.Y /= (float)textureImages[t].Height * 32.0f;
                        temp.final.vertices.Add(temp.vertices[i]);
                        temp.final.texCoords.Add(texCoord);
                        temp.final.colors.Add(temp.colors[i]);
                        temp.final.indices.Add(indexCount);
                        indexCount++;
                    }
                    else
                    {
                        temp.final.indices.Add((uint)vExists);
                    }
                }
            }
        }
예제 #6
0
 public void LoadActorTexture(string path)
 {
     texture = ContentPipe.LoadTexture(path);
 }
예제 #7
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            texture = ContentPipe.LoadTexture("il_fullxfull.1152887108_9y04.jpg");
        }
예제 #8
0
        public Model(string filepath)
        {
            path = filepath;
            name = Path.GetFileNameWithoutExtension(filepath).Replace('_', ' ');
            Obj tobj = new Obj();

            tobj.LoadObj(filepath);
            Mtl tmtl = new Mtl();

            tmtl.LoadMtl(Path.GetDirectoryName(filepath) + filepathSlash + tobj.Mtl);

            List <Vector3> Vertices = new List <Vector3>();

            foreach (ObjParser.Types.Vertex v in tobj.VertexList)
            {
                Vertices.Add(new Vector3((float)v.X, (float)v.Y, (float)v.Z));
            }
            List <Vector3> Normals = new List <Vector3>();

            foreach (ObjParser.Types.Normal vn in tobj.NormalList)
            {
                Normals.Add(new Vector3((float)vn.X, (float)vn.Y, (float)vn.Z));
            }
            List <Vector2> UVs = new List <Vector2>();

            foreach (ObjParser.Types.TextureVertex vt in tobj.TextureList)
            {
                UVs.Add(new Vector2((float)vt.X, (float)vt.Y));
            }
            foreach (ObjParser.Types.Material mat in tmtl.MaterialList)
            {
                List <int[]> faces = new List <int[]>();
                List <int[]> fnmls = new List <int[]>();
                List <int[]> fuvs  = new List <int[]>();
                int          texture;
                Console.WriteLine("{0}: {1}", mat.DiffuseTexture, Path.IsPathRooted(mat.DiffuseTexture));
                if (Path.IsPathRooted(mat.DiffuseTexture))
                {
                    texture = ContentPipe.Load_and_AddTexture(mat.DiffuseTexture);
                }
                else
                {
                    texture = ContentPipe.Load_and_AddTexture(Path.GetDirectoryName(filepath) + filepathSlash + mat.DiffuseTexture);
                }

                foreach (ObjParser.Types.Face f in tobj.FaceList)
                {
                    if (f.UseMtl == mat.Name)
                    {
                        faces.Add(f.VertexIndexList);
                        fnmls.Add(f.NormalIndexList);
                        fuvs.Add(f.TextureVertexIndexList);
                    }
                }
                List <Vector3> cverts = new List <Vector3>();
                List <Vector3> cnorms = new List <Vector3>();
                List <Vector2> cuvs   = new List <Vector2>();
                foreach (Vector3 v in Vertices)
                {
                    cverts.Add(v);
                }
                foreach (Vector3 n in Normals)
                {
                    cnorms.Add(n);
                }
                foreach (Vector2 t in UVs)
                {
                    cuvs.Add(t);
                }
                meshes.Add(new Mesh(cverts, cnorms, cuvs, faces, fnmls, fuvs, Vector3.One, texture));
            }
            Obj tobjkcl = new Obj();

            tobjkcl.LoadObj(Path.GetDirectoryName(filepath) + filepathSlash + Path.GetFileNameWithoutExtension(filepath) + "_KCL.obj");

            List <Vector3> CVerts = new List <Vector3>();

            foreach (ObjParser.Types.Vertex v in tobjkcl.VertexList)
            {
                CVerts.Add(new Vector3((float)v.X, (float)v.Y, (float)v.Z));
            }
            foreach (string name in tobjkcl.objects)
            {
                Collision_Mesh.CollisionType coll;
                if (name == "ROAD")
                {
                    coll = Collision_Mesh.CollisionType.road;
                }
                else if (name == "WALL")
                {
                    coll = Collision_Mesh.CollisionType.wall;
                }
                else if (name == "OFFROAD")
                {
                    coll = Collision_Mesh.CollisionType.off_road;
                }
                else if (name == "WAYOFFROAD")
                {
                    coll = Collision_Mesh.CollisionType.way_off_road;
                }
                else if (name == "OUTOFBOUNDS")
                {
                    coll = Collision_Mesh.CollisionType.out_of_bounds;
                }
                else if (name == "BOOST")
                {
                    coll = Collision_Mesh.CollisionType.boost;
                }
                else if (name == "RAMP")
                {
                    coll = Collision_Mesh.CollisionType.ramp;
                }
                else if (name == "ENGAGEGLIDER")
                {
                    coll = Collision_Mesh.CollisionType.engage_glider;
                }
                else if (name == "SIDERAMP")
                {
                    coll = Collision_Mesh.CollisionType.side_ramp;
                }
                else if (name == "CANNON")
                {
                    coll = Collision_Mesh.CollisionType.cannon;
                }
                else if (name == "WATER")
                {
                    coll = Collision_Mesh.CollisionType.water;
                }
                else if (name == "LAVA")
                {
                    coll = Collision_Mesh.CollisionType.lava;
                }
                else if (name == "SPINOUT")
                {
                    coll = Collision_Mesh.CollisionType.spin_out;
                }
                else if (name == "KNOCKOUT")
                {
                    coll = Collision_Mesh.CollisionType.knock_out;
                }
                else
                {
                    continue;
                }

                List <int[]> faces = new List <int[]>();
                foreach (ObjParser.Types.Face f in tobjkcl.FaceList)
                {
                    if (f.objectName == name)
                    {
                        faces.Add(f.VertexIndexList);
                    }
                }
                List <Vector3> cverts = new List <Vector3>();
                foreach (Vector3 v in CVerts)
                {
                    cverts.Add(v);
                }
                KCLs.Add(new Collision_Mesh(cverts, faces, coll));
            }
            CalculateBounds();
            ImportAttachments(Path.GetDirectoryName(filepath) + filepathSlash + Path.GetFileNameWithoutExtension(filepath) + "_Atch.txt");
        }
예제 #9
0
 public void LoadToOpenGL()
 {
     textureID = ContentPipe.LoadTexture(bitmap);
 }
예제 #10
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            texture = ContentPipe.LoadTexture("tiles.jpg");
        }
예제 #11
0
        public void BuildData(List <Model3D.MeshData> meshes)
        {
            if (meshes.Count != 0)
            {
                System.Console.WriteLine("duplicate");
            }

            {
                int target_c = (int)TempMeshes.count + meshes.Count;
                if (meshes.Capacity < target_c)
                {
                    meshes.Capacity = target_c;
                }
            }

            Dictionary <TempVertex, TempVertex> vert_temp = null;

            Model3D.MeshData md;
            TempMesh         mesh_iter;
            TempVertex       vert_iter;
            uint             mesh_iter_n, vert_iter_n, next_ind, u_pos; int v_count;
            float            fw, fh;

            for (mesh_iter = TempMeshes.first,
                 mesh_iter_n = TempMeshes.count;
                 0 != mesh_iter_n;
                 mesh_iter = mesh_iter.next,
                 --mesh_iter_n)
            {
                v_count = null == (object)(
                    vert_temp = TempVertex.Process(ref mesh_iter.references.list, utilize: vert_temp)
                    ) ? 0 : vert_temp.Count;
                md = new Model3D.MeshData()
                {
                    vertices = new Vector3[v_count],
                    normals  = new Vector3[v_count],
                    colors   = new Vector4[v_count],
                    texCoord = new Vector2[v_count],
                    indices  = new uint[mesh_iter.references.list.count],
                    texture  = ContentPipe.LoadTexture(
                        mesh_iter.references.bmp,
                        mesh_iter.value.info.wrapS,
                        mesh_iter.value.info.wrapT),
                    material = mesh_iter.value.getMaterial(),
                };
                fw = ((uint)mesh_iter.references.bmp.Width << 5);
                fh = ((uint)mesh_iter.references.bmp.Height << 5);
                for (
                    u_pos = 0, next_ind = 0,
                    vert_iter = mesh_iter.references.list.first,
                    vert_iter_n = mesh_iter.references.list.count;
                    0 != vert_iter_n;
                    vert_iter = vert_iter.next,
                    u_pos++,
                    --vert_iter_n)
                {
                    md.indices[u_pos] = vert_iter.index;
                    if (vert_iter.index != next_ind)
                    {
                        continue;
                    }
                    md.vertices[next_ind]   = vert_iter.value.position;
                    md.texCoord[next_ind].X = vert_iter.value.texCoord.X / fw;
                    md.texCoord[next_ind].Y = vert_iter.value.texCoord.Y / fh;
                    md.normals[next_ind]    = vert_iter.value.normal;
                    md.colors[next_ind]     = vert_iter.value.color;
                    next_ind++;
                }
                meshes.Add(md);
            }
        }