public void getSidedefs() { if (side1Index != -1) { side1 = map.sidedefs[side1Index]; } if (side2Index != -1) { side2 = map.sidedefs[side2Index]; } }
public static SubMesh CreateWall(SECTORS sector, LINEDEFS line, Material texture, float startHeight, float endHeight, bool flipped, WallType wallType) { List <Vector3> tmpVerts = new List <Vector3>(); List <Vector2> tmpUv = new List <Vector2>(); SubMesh sMesh = new SubMesh(); sMesh.mesh = new Mesh(); sMesh.mesh.vertices = new Vector3[4]; sMesh.mesh.uv = new Vector2[4]; // create the vertices tmpVerts.Add(new Vector3(line.firstVert.x, startHeight, line.firstVert.z)); tmpVerts.Add(new Vector3(line.firstVert.x, endHeight, line.firstVert.z)); tmpVerts.Add(new Vector3(line.lastVert.x, endHeight, line.lastVert.z)); tmpVerts.Add(new Vector3(line.lastVert.x, startHeight, line.lastVert.z)); // remember things for uv generation SIDEDEFS side = flipped ? line.side2 : line.side1; float xOffset = side.xOfs; float yOffset = side.yOfs; float textureWidth = texture.mainTexture.width; float textureHeight = texture.mainTexture.height; float wallHeight = endHeight - startHeight; float wallWidth = line.getLength(); // check upper and lower unpegged flags bool lowerUnpegged = (wallType == WallType.Upper) ? ((line.flags & 0x0008) == 0) : ((line.flags & 0x0010) != 0); // generate UVs if (lowerUnpegged) { if (wallType == WallType.Lower) { float sectorHeight = sector.ceilingHeight - sector.floorHeight; tmpUv.Add(new Vector2(xOffset / textureWidth, (sectorHeight + yOffset) / textureHeight)); tmpUv.Add(new Vector2(xOffset / textureWidth, (sectorHeight - wallHeight + yOffset) / textureHeight)); tmpUv.Add(new Vector2((wallWidth + xOffset) / textureWidth, (sectorHeight - wallHeight + yOffset) / textureHeight)); tmpUv.Add(new Vector2((wallWidth + xOffset) / textureWidth, (sectorHeight + yOffset) / textureHeight)); } else { tmpUv.Add(new Vector2(xOffset / textureWidth, (textureHeight + yOffset) / textureHeight)); tmpUv.Add(new Vector2(xOffset / textureWidth, (textureHeight - wallHeight + yOffset) / textureHeight)); tmpUv.Add(new Vector2((wallWidth + xOffset) / textureWidth, (textureHeight - wallHeight + yOffset) / textureHeight)); tmpUv.Add(new Vector2((wallWidth + xOffset) / textureWidth, (textureHeight + yOffset) / textureHeight)); } } else { tmpUv.Add(new Vector2(xOffset / textureWidth, (wallHeight + yOffset) / textureHeight)); tmpUv.Add(new Vector2(xOffset / textureWidth, yOffset / textureHeight)); tmpUv.Add(new Vector2((wallWidth + xOffset) / textureWidth, yOffset / textureHeight)); tmpUv.Add(new Vector2((wallWidth + xOffset) / textureWidth, (wallHeight + yOffset) / textureHeight)); } // set mesh data sMesh.mesh.uv = tmpUv.ToArray(); sMesh.mesh.vertices = tmpVerts.ToArray(); sMesh.material = texture; if (flipped) { sMesh.mesh.triangles = new int[6] { 2, 1, 0, 0, 3, 2 }; sMesh.mesh.normals = new Vector3[4] { -line.frontVector(), -line.frontVector(), -line.frontVector(), -line.frontVector() }; } else { sMesh.mesh.triangles = new int[6] { 0, 1, 2, 2, 3, 0 }; sMesh.mesh.normals = new Vector3[4] { line.frontVector(), line.frontVector(), line.frontVector(), line.frontVector() }; } return(sMesh); }
void ReadMAPEntries() { for (int i = 0; i < newWad.directory.Count - 1; i++) { if (newWad.directory[i + 1].name.Contains("THINGS") && newWad.directory[i].size == 0) { DoomMap newMap = new DoomMap(); DrctEntry dirEntry = newWad.directory[i]; newMap.name = dirEntry.name; //THINGS lump if (newWad.directory[i + 1].name.Contains("THINGS")) { byte[] thingBytes = new byte[newWad.directory[i + 1].size]; wadOpener.Position = newWad.directory[i + 1].filepos; wadOpener.Read(thingBytes, 0, thingBytes.Length); for (int j = 0; j < newWad.directory[i + 1].size; j += 10) { THINGS newThing = new THINGS(); newThing.xPos = BitConverter.ToInt16(thingBytes, j + 0); newThing.yPos = BitConverter.ToInt16(thingBytes, j + 2); newThing.angle = BitConverter.ToInt16(thingBytes, j + 4); newThing.thingType = BitConverter.ToInt16(thingBytes, j + 6); newThing.thingOptions = BitConverter.ToInt16(thingBytes, j + 8); newMap.things.Add(newThing); } } //LINEDEEFS lump if (newWad.directory[i + 2].name.Contains("LINEDEFS")) { byte[] lineDefBytes = new byte[newWad.directory[i + 2].size]; wadOpener.Position = newWad.directory[i + 2].filepos; wadOpener.Read(lineDefBytes, 0, lineDefBytes.Length); for (int j = 0; j < newWad.directory[i + 2].size; j += 14) { LINEDEFS newLineDef = new LINEDEFS(); newLineDef.firstVertIndex = BitConverter.ToInt16(lineDefBytes, j + 0); newLineDef.lastVertIndex = BitConverter.ToInt16(lineDefBytes, j + 2); newLineDef.flags = BitConverter.ToInt16(lineDefBytes, j + 4); newLineDef.types = BitConverter.ToInt16(lineDefBytes, j + 6); newLineDef.tag = BitConverter.ToInt16(lineDefBytes, j + 8); newLineDef.side1Index = BitConverter.ToInt16(lineDefBytes, j + 10); newLineDef.side2Index = BitConverter.ToInt16(lineDefBytes, j + 12); newMap.linedefs.Add(newLineDef); } } //SIDEDEFS lump if (newWad.directory[i + 3].name.Contains("SIDEDEFS")) { byte[] sideDefBytes = new byte[newWad.directory[i + 3].size]; wadOpener.Position = newWad.directory[i + 3].filepos; wadOpener.Read(sideDefBytes, 0, sideDefBytes.Length); for (int j = 0; j < newWad.directory[i + 3].size; j += 30) { SIDEDEFS newSideDef = new SIDEDEFS(); newSideDef.xOfs = BitConverter.ToInt16(sideDefBytes, j + 0); newSideDef.yOfs = BitConverter.ToInt16(sideDefBytes, j + 2); newSideDef.upTex = new String(System.Text.Encoding.ASCII.GetChars(sideDefBytes, j + 4, 8)).ToUpper(); newSideDef.lowTex = new String(System.Text.Encoding.ASCII.GetChars(sideDefBytes, j + 12, 8)).ToUpper(); newSideDef.midTex = new String(System.Text.Encoding.ASCII.GetChars(sideDefBytes, j + 20, 8)).ToUpper(); newSideDef.secNum = BitConverter.ToInt16(sideDefBytes, j + 28); newSideDef.upTex = newSideDef.upTex.Replace("\0", ""); newSideDef.lowTex = newSideDef.lowTex.Replace("\0", ""); newSideDef.midTex = newSideDef.midTex.Replace("\0", ""); newMap.sidedefs.Add(newSideDef); } } //VERTEXES lump if (newWad.directory[i + 4].name.Contains("VERTEXES")) { byte[] vertexBytes = new byte[newWad.directory[i + 4].size]; wadOpener.Position = newWad.directory[i + 4].filepos; wadOpener.Read(vertexBytes, 0, vertexBytes.Length); for (int j = 0; j < newWad.directory[i + 4].size; j += 4) { Vector3 newVertex = new Vector3(0, 0, 0); newVertex.x = BitConverter.ToInt16(vertexBytes, j + 0); newVertex.z = BitConverter.ToInt16(vertexBytes, j + 2); newMap.vertexes.Add(newVertex); } } //SECTORS lump if (newWad.directory[i + 8].name.Contains("SECTORS")) { byte[] secBytes = new byte[newWad.directory[i + 8].size]; wadOpener.Position = newWad.directory[i + 8].filepos; wadOpener.Read(secBytes, 0, secBytes.Length); for (int j = 0; j < newWad.directory[i + 8].size; j += 26) { SECTORS newSec = new SECTORS(); newSec.floorHeight = BitConverter.ToInt16(secBytes, j + 0); newSec.ceilingHeight = BitConverter.ToInt16(secBytes, j + 2); newSec.floorFlat = new String(System.Text.Encoding.ASCII.GetChars(secBytes, j + 4, 8)); newSec.ceilingFlat = new String(System.Text.Encoding.ASCII.GetChars(secBytes, j + 12, 8)); newSec.lightLevel = BitConverter.ToInt16(secBytes, j + 20); newSec.specialSec = BitConverter.ToInt16(secBytes, j + 22); newSec.sectorTag = BitConverter.ToInt16(secBytes, j + 24); newSec.floorFlat = newSec.floorFlat.Replace("\0", ""); newSec.ceilingFlat = newSec.ceilingFlat.Replace("\0", ""); newMap.sectors.Add(newSec); } } //BLOCKMAPS lump if (newWad.directory[i + 10].name.Contains("BLOCKMAP")) { byte[] blockBytes = new byte[newWad.directory[i + 10].size]; wadOpener.Position = newWad.directory[i + 10].filepos; wadOpener.Read(blockBytes, 0, blockBytes.Length); BLOCKMAP newBlockmap = new BLOCKMAP(); newBlockmap.xcoord = BitConverter.ToInt16(blockBytes, 0); newBlockmap.ycoord = BitConverter.ToInt16(blockBytes, 2); newBlockmap.numColumns = BitConverter.ToInt16(blockBytes, 4); newBlockmap.numRows = BitConverter.ToInt16(blockBytes, 6); int N = newBlockmap.numColumns * newBlockmap.numRows; //Offsets for (int j = 8; j < (8 + (2 * (N - 1))); j += 2) // (8 + (2 * (N - 1))) IS DEFINITELY RIGHT { newBlockmap.Offsets.Add(BitConverter.ToUInt16(blockBytes, j) * 2); //multiply this times 2 so its right } foreach (int offset in newBlockmap.Offsets) { int line = 0; int blockOffset = offset; // List<int> newBlock = new List<int>(); Block blk = new Block(); do { line = BitConverter.ToUInt16(blockBytes, blockOffset + 2); //newBlock.Add(line); if (line == 0xFFFF) { continue; } blk.lines.Add(newMap.linedefs[line]); blockOffset += 2; } while (line != 0xFFFF); newBlockmap.blocks.Add(blk); } newMap.blockmap = newBlockmap; } newWad.maps.Add(newMap); //Store the map in newWad } } }