Exemple #1
0
        public Texture2D cargarImagen(string image_name)
        {
            var name = que_tga_name(image_name);
            var tga  = tex_folder + name + ".tga";

            return(CTextureLoader.Load(device, tga));
        }
Exemple #2
0
        public void initTextures()
        {
            texture = new Texture2D[cant_subsets];
            for (var i = 0; i < cant_subsets; ++i)
            {
                // busco en que directorio puede esta la textura
                bool found = false;
                for (var j = 0; j < cant_cdmaterials && !found; ++j)
                {
                    string fname = CBspFile.tex_folder + cdmaterials[j] + subset[i].name + ".vmt";
                    if (File.Exists(fname))
                    {
                        found = true;
                        subset[i].image_name = cdmaterials[j] + subset[i].name;
                    }
                }

                if (!found)
                {
                    continue;
                }

                var name = CBspFile.que_tga_name(subset[i].image_name);
                var tga  = CBspFile.tex_folder + name + ".tga";
                texture[i] = CTextureLoader.Load(device, tga);
                // propiedades del material
                var vmt = CBspFile.tex_folder + name + ".vmt";
                if (File.Exists(vmt))
                {
                    var content = File.ReadAllText(vmt).ToLower();
                    // "$translucent" "1"
                    // "$translucent" 1
                    // "$alphatest" 1
                    // "$AlphaTestReference" "0.5"

                    string value = "";
                    if (parseTag(content, "$translucent", out value) && int.Parse(value) == 1)
                    {
                        subset[i].traslucido = true;
                    }

                    if (parseTag(content, "$alphatest", out value) && int.Parse(value) == 1)
                    {
                        subset[i].traslucido = true;
                        if (parseTag(content, "$alphatestreference", out value))
                        {
                            subset[i].alphaTestReference = atof(value);
                        }
                    }
                }
            }
        }
Exemple #3
0
        public Texture2D insert(string image_name, GraphicsDevice device)
        {
            int n = que_textura(image_name);

            if (n == -1 && cant_texturas < MAX_TEXTURAS - 1)
            {
                var name = CBspFile.que_tga_name(image_name);
                var tga  = CBspFile.tex_folder + name + ".tga";
                texturas[cant_texturas] = CTextureLoader.Load(device, tga);
                tx_name[cant_texturas]  = image_name;
                n = cant_texturas++;
            }
            return(n != -1 ? texturas[n] : null);
        }
Exemple #4
0
        public void initMeshFromData(byte[] arrayByte)
        {
            var   t      = 0;
            int   cant_v = (int)BitConverter.ToInt32(arrayByte, t); t += 4;
            float min_x  = 1000000;
            float min_y  = 1000000;
            float min_z  = 1000000;
            float max_x  = -1000000;
            float max_y  = -1000000;
            float max_z  = -1000000;


            ValveVertex[] vertices = new ValveVertex[cant_v];
            for (var i = 0; i < cant_v; ++i)
            {
                var x = BitConverter.ToSingle(arrayByte, t); t += 4;
                var z = BitConverter.ToSingle(arrayByte, t); t += 4;
                var y = BitConverter.ToSingle(arrayByte, t); t += 4;

                vertices[i].Position.X = x;
                vertices[i].Position.Y = y;
                vertices[i].Position.Z = z;

                if (x < min_x)
                {
                    min_x = x;
                }
                if (y < min_y)
                {
                    min_y = y;
                }
                if (z < min_z)
                {
                    min_z = z;
                }
                if (x > max_x)
                {
                    max_x = x;
                }
                if (y > max_y)
                {
                    max_y = y;
                }
                if (z > max_z)
                {
                    max_z = z;
                }

                vertices[i].TextureCoordinate.X = BitConverter.ToSingle(arrayByte, t); t += 4;
                vertices[i].TextureCoordinate.Y = BitConverter.ToSingle(arrayByte, t); t += 4;

                vertices[i].LightmapCoordinate.X = -BitConverter.ToSingle(arrayByte, t); t += 4;
                vertices[i].LightmapCoordinate.Y = BitConverter.ToSingle(arrayByte, t); t += 4;
            }

            // actualizo el bounding box
            p_min = new Vector3(min_x, min_y, min_z);
            p_max = new Vector3(max_x, max_y, max_z);
            size  = new Vector3(max_x - min_x, max_y - min_y, max_z - min_z);
            cg    = p_min + size * 0.5f;


            // computo la normal y de paso actualizo la geoemtria
            int cant_tri = cant_v / 3;



            for (int i = 0; i < cant_tri; ++i)
            {
                Vector3 v0 = vertices[3 * i].Position;
                Vector3 v1 = vertices[3 * i + 1].Position;
                Vector3 v2 = vertices[3 * i + 2].Position;

                Vector3 N = Vector3.Cross(v1 - v0, v2 - v0);
                N.Normalize();
                vertices[3 * i].Normal = vertices[3 * i + 1].Normal = vertices[3 * i + 2].Normal = N;
            }


            VertexBuffer = new VertexBuffer(device, ValveVertex.VertexDeclaration, cant_v, BufferUsage.WriteOnly);
            VertexBuffer.SetData(vertices);


            // estructura de subsets
            cant_subsets = (int)BitConverter.ToInt32(arrayByte, t); t += 4;
            subset       = new bsp_subset[cant_subsets];
            texture      = new Texture2D[cant_subsets];

            for (int i = 0; i < cant_subsets; ++i)
            {
                subset[i]            = new bsp_subset();
                subset[i].cant_items = (int)BitConverter.ToInt32(arrayByte, t); t += 4;
                string name = getString(arrayByte, t, 256); t += 256;
                name = name.ToUpper();
                subset[i].image_name = name = que_tga_name(name);
                var tga = tex_folder + name + ".tga";
                texture[i] = null;
                if (File.Exists(tga))
                {
                    texture[i] = CTextureLoader.Load(device, tga);
                }

                if (texture[i] == null)
                {
                    Debug.WriteLine(i + "-" + subset[i].image_name);
                }
            }

            // como mucho hay cant_tri faces a los efectos de colision, anulo las que son TOOLS
            faces      = new bsp_face[cant_tri];
            cant_faces = 0;
            var pos = 0;

            for (var i = 0; i < cant_subsets; i++)
            {
                if (!subset[i].image_name.StartsWith("TOOLS"))
                {
                    for (int j = 0; j < subset[i].cant_items; ++j)
                    {
                        var     k  = pos + 3 * j;
                        Vector3 v0 = vertices[k].Position;
                        Vector3 v1 = vertices[k + 1].Position;
                        Vector3 v2 = vertices[k + 2].Position;
                        faces[cant_faces]            = new bsp_face();
                        faces[cant_faces].v[0]       = v0;
                        faces[cant_faces].v[1]       = v1;
                        faces[cant_faces].v[2]       = v2;
                        faces[cant_faces].nro_modelo = -1 - i;                                  // escenario
                        cant_faces++;
                    }
                }
                pos += subset[i].cant_items * 3;
            }


            // leo el lightmap
            lightmap = new Texture2D(device, 2048, 2048);
            int lm_size = 2048 * 2048;

            Color[] data = new Color[lm_size];
            for (int pixel = 0; pixel < lm_size; pixel++)
            {
                data[pixel].R = arrayByte[t++];
                data[pixel].G = arrayByte[t++];
                data[pixel].B = arrayByte[t++];
                data[pixel].A = (byte)(arrayByte[t++] + 128);
            }
            lightmap.SetData(data);
        }
Exemple #5
0
        public CSkybox(GraphicsDevice p_device)
        {
            device = p_device;
            Vector3 p_min = new Vector3(-1, -1, -1);
            Vector3 p_max = new Vector3(1, 1, 1);


            VertexPositionTexture[] vertices = new VertexPositionTexture[36];

            // abajo
            vertices[0].Position          = new Vector3(p_min.X, p_min.Y, p_min.Z);
            vertices[0].TextureCoordinate = new Vector2(0, 0);
            vertices[1].Position          = new Vector3(p_max.X, p_min.Y, p_min.Z);
            vertices[1].TextureCoordinate = new Vector2(0, 1);
            vertices[2].Position          = new Vector3(p_max.X, p_min.Y, p_max.Z);
            vertices[2].TextureCoordinate = new Vector2(1, 1);
            vertices[3].Position          = new Vector3(p_min.X, p_min.Y, p_min.Z);
            vertices[3].TextureCoordinate = new Vector2(0, 0);
            vertices[4].Position          = new Vector3(p_max.X, p_min.Y, p_max.Z);
            vertices[4].TextureCoordinate = new Vector2(1, 1);
            vertices[5].Position          = new Vector3(p_min.X, p_min.Y, p_max.Z);
            vertices[5].TextureCoordinate = new Vector2(1, 0);

            // arriba
            for (int i = 0; i < 6; ++i)
            {
                vertices[6 + i].Position          = vertices[i].Position;
                vertices[6 + i].Position.Y        = p_max.Y;
                vertices[6 + i].TextureCoordinate = vertices[i].TextureCoordinate;
            }


            //izquierda
            vertices[12].Position          = new Vector3(p_min.X, p_min.Y, p_min.Z);
            vertices[12].TextureCoordinate = new Vector2(1, 1);
            vertices[13].Position          = new Vector3(p_min.X, p_min.Y, p_max.Z);
            vertices[13].TextureCoordinate = new Vector2(0, 1);
            vertices[14].Position          = new Vector3(p_min.X, p_max.Y, p_max.Z);
            vertices[14].TextureCoordinate = new Vector2(0, 0);
            vertices[15].Position          = new Vector3(p_min.X, p_min.Y, p_min.Z);
            vertices[15].TextureCoordinate = new Vector2(1, 1);
            vertices[16].Position          = new Vector3(p_min.X, p_max.Y, p_max.Z);
            vertices[16].TextureCoordinate = new Vector2(0, 0);
            vertices[17].Position          = new Vector3(p_min.X, p_max.Y, p_min.Z);
            vertices[17].TextureCoordinate = new Vector2(1, 0);

            //derecha
            for (int i = 0; i < 6; ++i)
            {
                vertices[18 + i].Position            = vertices[12 + i].Position;
                vertices[18 + i].Position.X          = p_max.X;
                vertices[18 + i].TextureCoordinate   = vertices[12 + i].TextureCoordinate;
                vertices[18 + i].TextureCoordinate.X = 1 - vertices[18 + i].TextureCoordinate.X;
            }

            //adelante
            vertices[24].Position          = new Vector3(p_min.X, p_min.Y, p_max.Z);
            vertices[24].TextureCoordinate = new Vector2(1, 1);
            vertices[25].Position          = new Vector3(p_max.X, p_min.Y, p_max.Z);
            vertices[25].TextureCoordinate = new Vector2(0, 1);
            vertices[26].Position          = new Vector3(p_min.X, p_max.Y, p_max.Z);
            vertices[26].TextureCoordinate = new Vector2(1, 0);
            vertices[27].Position          = new Vector3(p_max.X, p_min.Y, p_max.Z);
            vertices[27].TextureCoordinate = new Vector2(0, 1);
            vertices[28].Position          = new Vector3(p_min.X, p_max.Y, p_max.Z);
            vertices[28].TextureCoordinate = new Vector2(1, 0);
            vertices[29].Position          = new Vector3(p_max.X, p_max.Y, p_max.Z);
            vertices[29].TextureCoordinate = new Vector2(0, 0);

            //atras
            for (int i = 0; i < 6; ++i)
            {
                vertices[30 + i].Position            = vertices[24 + i].Position;
                vertices[30 + i].Position.Z          = p_min.Z;
                vertices[30 + i].TextureCoordinate   = vertices[24 + i].TextureCoordinate;
                vertices[30 + i].TextureCoordinate.X = 1 - vertices[24 + i].TextureCoordinate.X;
            }

            VertexBuffer = new VertexBuffer(device, VertexPositionTexture.VertexDeclaration, 36, BufferUsage.WriteOnly);
            VertexBuffer.SetData(vertices);

            texture[0] = CTextureLoader.Load(device, CBspFile.tex_folder + "skybox\\assaultdn.tga");
            texture[1] = CTextureLoader.Load(device, CBspFile.tex_folder + "skybox\\assaultup.tga");
            texture[2] = CTextureLoader.Load(device, CBspFile.tex_folder + "skybox\\assaultlf.tga");
            texture[3] = CTextureLoader.Load(device, CBspFile.tex_folder + "skybox\\assaultrt.tga");
            texture[4] = CTextureLoader.Load(device, CBspFile.tex_folder + "skybox\\assaultft.tga");
            texture[5] = CTextureLoader.Load(device, CBspFile.tex_folder + "skybox\\assaultbk.tga");
        }