Example #1
0
    public BSPMipTexture ReadInTexture(long Texoffset, BinaryReader stream, string wadname)
    {
        long textureOffset = Texoffset;                         // need this below to locate colour array of this texture

        stream.BaseStream.Position = textureOffset;

        BSPMipTexture miptex = new BSPMipTexture(stream.LoadCleanString(16), stream.ReadUInt32(), stream.ReadUInt32(), stream.ReadUInt32Array(4));

        //check to see if texture is in a wad file
        if (miptex.offset [0] == 0)                        //if its zero then the texture is in a wad file, So skip this texture
        {
            Debug.Log("Error Error");

            miptex.texture = null;
            return(miptex);
        }


        miptex.texture = new Texture2D(miptex.width, miptex.height);                         //set size of texture
        //color palette is 2 bytes after the end of mipmap[4]

        stream.BaseStream.Position = ((miptex.width * miptex.height / 64) + miptex.offset [3] + textureOffset + 2);                         //Move stream to start of  Palette.


        byte[] colourArray = stream.ReadBytes(256 * 3);

        //move stream to start of the texture array
        stream.BaseStream.Position = (textureOffset + miptex.offset [0]);
        int NumberOfPixels = (int)(miptex.height * miptex.width);

        byte[] pixelArray = stream.ReadBytes(NumberOfPixels);
        miptex.texture = MakeTexture2D(miptex.height, miptex.width, colourArray, pixelArray);


        return(miptex);
    }
Example #2
0
		private void ReadTextures ()
		{
				//(Half-life textures can be in wad file or the bsp)
		
				BSPfile.BaseStream.Position = header.directory [2].offset;//move to start of texture lump
				int numberOfTextures = (int)BSPfile.ReadUInt32 (); //get the amount of stored / referenced textures in this lump
		
		
		
				miptexLump = new BSPMipTexture[numberOfTextures];
		
				//get offsets of each texture
				Int32[] BSPMIPTEXOFFSET = new  Int32[numberOfTextures]; // Array to store the start position of each texture
				for (int i = 0; i < numberOfTextures; i++)
				{
					
						BSPMIPTEXOFFSET [i] = (header.directory [2].offset + BSPfile.ReadInt32 ());

			
				}

	
				//now load in textures(in half-life each texture has its own palette)
				for (int indexOfTex = 0; indexOfTex < numberOfTextures; indexOfTex++)
				{
			
			
						int textureOffset = BSPMIPTEXOFFSET [indexOfTex]; // need this below to locate colour array of this texture
						BSPfile.BaseStream.Position = textureOffset;
						miptexLump [indexOfTex] = new BSPMipTexture (BSPfile.LoadCleanString (16), BSPfile.ReadUInt32 (), BSPfile.ReadUInt32 (), BSPfile.ReadUInt32Array (4));

						//check to see if texture is in a wad file
						if (miptexLump [indexOfTex].offset [0] == 0)//if its zero then the texture is in a wad file, So skip this texture
						{
				
								
								NumTexLoadFromWad++;
								miptexLump [indexOfTex].texture = null;
								continue;
				
						}
						Debug.Log ("starting to read in texture " + miptexLump [indexOfTex].name.ToString ());
						miptexLump [indexOfTex].texture = new Texture2D (miptexLump [indexOfTex].width, miptexLump [indexOfTex].height);//set size of texture
						//color palette is 2 bytes after the end of mipmap[4]
						Debug.Log ((miptexLump [indexOfTex].width * miptexLump [indexOfTex].height / 64) + (miptexLump [indexOfTex].offset [3] + textureOffset + 2).ToString ());
						BSPfile.BaseStream.Position = ((miptexLump [indexOfTex].width * miptexLump [indexOfTex].height / 64) + miptexLump [indexOfTex].offset [3] + textureOffset + 2); //Move stream to start of  Palette.
		

						Color[] colourPalette = new Color[256];//used to hold colour palette array
						for (int j = 0; j < 256; j++)
						{
								//read in texture colour palette (Unlike quake each texture has its own palette)
								colourPalette [j] = new Color32 (BSPfile.ReadByte (), BSPfile.ReadByte (), BSPfile.ReadByte (), 0);
						}
						//move stream to start of the texture array
						BSPfile.BaseStream.Position = (textureOffset + miptexLump [indexOfTex].offset [0]);
						int NumberOfPixels = (int)(miptexLump [indexOfTex].height * miptexLump [indexOfTex].width);
						Color[] colour = new Color[NumberOfPixels];
						int indexInToColourPalette;
						for (int currentPixel = 0; currentPixel < NumberOfPixels; currentPixel++)
						{
				
								colour [currentPixel] = new Color ();
								indexInToColourPalette = (int)BSPfile.ReadByte ();
								if (indexInToColourPalette < 0 || indexInToColourPalette > 255)
								{
										Debug.LogError ("something wrong here chap!!!");
								}
								//Debug.Log (indexInToPalette.ToString ());
								colour [currentPixel] = colourPalette [indexInToColourPalette];
						}
						miptexLump [indexOfTex].texture.SetPixels (colour);
						miptexLump [indexOfTex].texture.filterMode = FilterMode.Bilinear;
						miptexLump [indexOfTex].texture.Apply ();
			
			
				}	
				Debug.Log ("finished reading textures");
		}
Example #3
0
		public BSPMipTexture ReadInTexture (long Texoffset, BinaryReader stream, string wadname)
		{

				long textureOffset = Texoffset; // need this below to locate colour array of this texture
				stream.BaseStream.Position = textureOffset;

				BSPMipTexture miptex = new BSPMipTexture (stream.LoadCleanString (16), stream.ReadUInt32 (), stream.ReadUInt32 (), stream.ReadUInt32Array (4));
	
				//check to see if texture is in a wad file
				if (miptex.offset [0] == 0)//if its zero then the texture is in a wad file, So skip this texture
				{
			
						Debug.Log ("Error Error");

						miptex.texture = null;
						return miptex;
			
				}
				

				miptex.texture = new Texture2D (miptex.width, miptex.height);//set size of texture
				//color palette is 2 bytes after the end of mipmap[4]

				stream.BaseStream.Position = ((miptex.width * miptex.height / 64) + miptex.offset [3] + textureOffset + 2); //Move stream to start of  Palette.
		
		
				byte[] colourArray = stream.ReadBytes (256 * 3);

				//move stream to start of the texture array
				stream.BaseStream.Position = (textureOffset + miptex.offset [0]);
				int NumberOfPixels = (int)(miptex.height * miptex.width);
				byte[] pixelArray = stream.ReadBytes (NumberOfPixels);
				miptex.texture = MakeTexture2D (miptex.height, miptex.width, colourArray, pixelArray);
	

				return miptex;

		}
Example #4
0
    private void ReadTextures()
    {
        //(Half-life textures can be in wad file or the bsp)

        BSPfile.BaseStream.Position = header.directory [2].offset;                 //move to start of texture lump
        int numberOfTextures = (int)BSPfile.ReadUInt32();                          //get the amount of stored / referenced textures in this lump



        miptexLump = new BSPMipTexture[numberOfTextures];

        //get offsets of each texture
        Int32[] BSPMIPTEXOFFSET = new  Int32[numberOfTextures];                         // Array to store the start position of each texture
        for (int i = 0; i < numberOfTextures; i++)
        {
            BSPMIPTEXOFFSET [i] = (header.directory [2].offset + BSPfile.ReadInt32());
        }


        //now load in textures(in half-life each texture has its own palette)
        for (int indexOfTex = 0; indexOfTex < numberOfTextures; indexOfTex++)
        {
            int textureOffset = BSPMIPTEXOFFSET [indexOfTex];                                     // need this below to locate colour array of this texture
            BSPfile.BaseStream.Position = textureOffset;
            miptexLump [indexOfTex]     = new BSPMipTexture(BSPfile.LoadCleanString(16), BSPfile.ReadUInt32(), BSPfile.ReadUInt32(), BSPfile.ReadUInt32Array(4));

            //check to see if texture is in a wad file
            if (miptexLump [indexOfTex].offset [0] == 0)                                    //if its zero then the texture is in a wad file, So skip this texture
            {
                NumTexLoadFromWad++;
                miptexLump [indexOfTex].texture = null;
                continue;
            }
            Debug.Log("starting to read in texture " + miptexLump [indexOfTex].name.ToString());
            miptexLump [indexOfTex].texture = new Texture2D(miptexLump [indexOfTex].width, miptexLump [indexOfTex].height);                                     //set size of texture
            //color palette is 2 bytes after the end of mipmap[4]
            Debug.Log((miptexLump [indexOfTex].width * miptexLump [indexOfTex].height / 64) + (miptexLump [indexOfTex].offset [3] + textureOffset + 2).ToString());
            BSPfile.BaseStream.Position = ((miptexLump [indexOfTex].width * miptexLump [indexOfTex].height / 64) + miptexLump [indexOfTex].offset [3] + textureOffset + 2);                                     //Move stream to start of  Palette.


            Color[] colourPalette = new Color[256];                                    //used to hold colour palette array
            for (int j = 0; j < 256; j++)
            {
                //read in texture colour palette (Unlike quake each texture has its own palette)
                colourPalette [j] = new Color32(BSPfile.ReadByte(), BSPfile.ReadByte(), BSPfile.ReadByte(), 0);
            }
            //move stream to start of the texture array
            BSPfile.BaseStream.Position = (textureOffset + miptexLump [indexOfTex].offset [0]);
            int     NumberOfPixels = (int)(miptexLump [indexOfTex].height * miptexLump [indexOfTex].width);
            Color[] colour         = new Color[NumberOfPixels];
            int     indexInToColourPalette;
            for (int currentPixel = 0; currentPixel < NumberOfPixels; currentPixel++)
            {
                colour [currentPixel]  = new Color();
                indexInToColourPalette = (int)BSPfile.ReadByte();
                if (indexInToColourPalette < 0 || indexInToColourPalette > 255)
                {
                    Debug.LogError("something wrong here chap!!!");
                }
                //Debug.Log (indexInToPalette.ToString ());
                colour [currentPixel] = colourPalette [indexInToColourPalette];
            }
            miptexLump [indexOfTex].texture.SetPixels(colour);
            miptexLump [indexOfTex].texture.filterMode = FilterMode.Bilinear;
            miptexLump [indexOfTex].texture.Apply();
        }
        Debug.Log("finished reading textures");
    }