Exemplo n.º 1
0
        public void RemoveTextures(Predicate <LevelTexture> askIfTextureToRemove)
        {
            Parallel.ForEach(Rooms.Where(room => room != null), room =>
            {
                foreach (Block sector in room.Blocks)
                {
                    for (BlockFace face = 0; face < BlockFace.Count; ++face)
                    {
                        TextureArea currentTextureArea = sector.GetFaceTexture(face);
                        LevelTexture currentTexture    = currentTextureArea.Texture as LevelTexture;
                        if (currentTexture != null && askIfTextureToRemove(currentTexture))
                        {
                            sector.SetFaceTexture(face, TextureArea.None);
                        }
                    }
                }
                room.RoomGeometry = new RoomGeometry(room);
            });

            foreach (AnimatedTextureSet set in Settings.AnimatedTextureSets)
            {
                set.Frames.RemoveAll(frame => askIfTextureToRemove(frame.Texture));
            }

            // Clean up empty texture sets as well
            Settings.AnimatedTextureSets.RemoveAll(set => set.Frames.Count == 0);
        }
Exemplo n.º 2
0
        private static TextureArea ConvertColoredFaceToTexture(Wad2 wad, TrLevel oldLevel, ushort paletteIndex, bool isTriangle)
        {
            ColorC color;

            var sixteenBitIndex = paletteIndex >> 8;

            if (oldLevel.Palette16.Count > 0 && oldLevel.Palette16.Count == oldLevel.Palette8.Count && sixteenBitIndex < oldLevel.Palette16.Count)
            {
                var trColor = oldLevel.Palette16[sixteenBitIndex];
                color = new ColorC(trColor.Red, trColor.Green, trColor.Blue, 255);
            }
            else
            {
                var trColor = oldLevel.Palette8[paletteIndex & 0xFF];
                color = new ColorC((byte)(trColor.Red * 4), (byte)(trColor.Green * 4), (byte)(trColor.Blue * 4), 255);
            }

            const int dummyTextureSize = 4;
            var       image            = ImageC.CreateNew(dummyTextureSize, dummyTextureSize);

            image.Fill(color);

            TextureArea textureArea = new TextureArea();

            textureArea.Texture     = new WadTexture(image);
            textureArea.TexCoord0   = new Vector2(0, 0);
            textureArea.TexCoord1   = new Vector2(dummyTextureSize, 0);
            textureArea.TexCoord2   = new Vector2(dummyTextureSize, dummyTextureSize);
            textureArea.TexCoord3   = new Vector2(0, dummyTextureSize);
            textureArea.BlendMode   = BlendMode.Normal;
            textureArea.DoubleSided = false;
            return(textureArea);
        }
Exemplo n.º 3
0
        public MakeMapSDK(string directory)
        {
            #region initialize props

            ColorArea      = new ColorAreas();
            ColorMountains = new MountainsAreas();

            Items       = new ItemsAll();
            ItemsCoasts = new CoastsAll();
            Smooths     = new SmoothsAll();


            TextureArea    = new TextureArea();
            SmoothTextures = new SmoothTextures();
            Cliffs         = new Cliffs();

            #endregion

            #region initialize Factories

            Factories = new List <Factory>();

            FactoryColor = new FactoryColorArea(Path.Combine(directory, "color_area.txt"));

            Factories.Add(FactoryColor);

            FactoryCoast = new FactoryCoast(Path.Combine(directory, "color_coast.txt"));

            Factories.Add(FactoryCoast);

            FactoryMountains = new FactoryMountains(Path.Combine(directory, "color_mntn.txt"));

            Factories.Add(FactoryMountains);

            FactoryItems = new FactoryItems(Path.Combine(directory, "items.txt"));

            Factories.Add(FactoryItems);

            FactoryItemCoasts = new FactoryItemCoasts(Path.Combine(directory, "ite_tex_coast.txt"));

            Factories.Add(FactoryItemCoasts);

            FactorySmoothItems = new FactorySmoothItems(Path.Combine(directory, "items_smooth.txt"));

            Factories.Add(FactorySmoothItems);

            FactoryTextureArea = new FactoryTextureArea(Path.Combine(directory, "texture_area.txt"));

            Factories.Add(FactoryTextureArea);

            FactoryTextureSmooth = new FactoryTextureSmooth(Path.Combine(directory, "texture_smooth.txt"));

            Factories.Add(FactoryTextureSmooth);

            FactoryCliff = new FactoryCliff(Path.Combine(directory, "texture_cliff.txt"));

            Factories.Add(FactoryCliff);

            #endregion
        }
Exemplo n.º 4
0
        public void ShowTexture(TextureArea area)
        {
            if (!(area.Texture is LevelTexture))
            {
                return;
            }

            VisibleTexture  = (LevelTexture)area.Texture;
            SelectedTexture = area;

            Vector2 min = Vector2.Min(Vector2.Min(area.TexCoord0, area.TexCoord1), Vector2.Min(area.TexCoord2, area.TexCoord3));
            Vector2 max = Vector2.Max(Vector2.Max(area.TexCoord0, area.TexCoord1), Vector2.Max(area.TexCoord2, area.TexCoord3));

            ViewPosition = (min + max) * 0.5f;

            LimitPosition();
        }
Exemplo n.º 5
0
        public bool SetFaceTexture(BlockFace face, TextureArea texture)
        {
            if (texture != TextureArea.None && texture.TextureIsDegenerate)
            {
                texture = TextureArea.Invisible;
            }

            if (_faceTextures[(int)face] != texture)
            {
                _faceTextures[(int)face] = texture;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 6
0
        public MakeMapSDK()
        {
            #region initialize props

            ColorArea      = new ColorAreas();
            ColorMountains = new MountainsAreas();
            ColorCoast     = new ColorAreas();

            Items       = new ItemsAll();
            ItemsCoasts = new CoastsAll();
            Smooths     = new SmoothsAll();


            TextureArea    = new TextureArea();
            SmoothTextures = new SmoothTextures();
            Cliffs         = new Cliffs();

            #endregion
        }
Exemplo n.º 7
0
        public MakeMapSDK(string directory)
        {
            #region initialize props

            ColorArea      = new ColorAreas();
            ColorMountains = new MountainsAreas();

            Items       = new ItemsAll();
            ItemsCoasts = new CoastsAll();
            Smooths     = new SmoothsAll();


            TextureArea    = new TextureArea();
            SmoothTextures = new SmoothTextures();
            Cliffs         = new Cliffs();

            #endregion

            InitializeFactories(directory);
        }
Exemplo n.º 8
0
        private void FixWadTextureCoordinates(ref TextureArea texture)
        {
            texture.TexCoord0.X = Math.Max(0.0f, texture.TexCoord0.X);
            texture.TexCoord0.Y = Math.Max(0.0f, texture.TexCoord0.Y);
            texture.TexCoord1.X = Math.Max(0.0f, texture.TexCoord1.X);
            texture.TexCoord1.Y = Math.Max(0.0f, texture.TexCoord1.Y);
            texture.TexCoord2.X = Math.Max(0.0f, texture.TexCoord2.X);
            texture.TexCoord2.Y = Math.Max(0.0f, texture.TexCoord2.Y);
            texture.TexCoord3.X = Math.Max(0.0f, texture.TexCoord3.X);
            texture.TexCoord3.Y = Math.Max(0.0f, texture.TexCoord3.Y);

            if (!texture.TextureIsInvisible && !texture.TextureIsUnavailable)
            {
                texture.TexCoord0.X = Math.Min(texture.Texture.Image.Width, texture.TexCoord0.X);
                texture.TexCoord0.Y = Math.Min(texture.Texture.Image.Height, texture.TexCoord0.Y);
                texture.TexCoord1.X = Math.Min(texture.Texture.Image.Width, texture.TexCoord1.X);
                texture.TexCoord1.Y = Math.Min(texture.Texture.Image.Height, texture.TexCoord1.Y);
                texture.TexCoord2.X = Math.Min(texture.Texture.Image.Width, texture.TexCoord2.X);
                texture.TexCoord2.Y = Math.Min(texture.Texture.Image.Height, texture.TexCoord2.Y);
                texture.TexCoord3.X = Math.Min(texture.Texture.Image.Width, texture.TexCoord3.X);
                texture.TexCoord3.Y = Math.Min(texture.Texture.Image.Height, texture.TexCoord3.Y);
            }
        }
Exemplo n.º 9
0
        private static WadMesh LoadMesh(ChunkReader chunkIO, long chunkSize, Dictionary <long, WadTexture> textures)
        {
            var  mesh          = new WadMesh();
            long obsoleteIndex = 0;

            chunkIO.ReadChunks((id2, chunkSize2) =>
            {
                if (id2 == Wad2Chunks.MeshIndex)
                {
                    obsoleteIndex = chunkIO.ReadChunkLong(chunkSize2);
                }
                else if (id2 == Wad2Chunks.MeshName)
                {
                    mesh.Name = chunkIO.ReadChunkString(chunkSize2);
                }
                else if (id2 == Wad2Chunks.MeshSphere)
                {
                    // Read bounding sphere
                    float radius   = 0;
                    Vector3 center = Vector3.Zero;
                    chunkIO.ReadChunks((id3, chunkSize3) =>
                    {
                        if (id3 == Wad2Chunks.MeshSphereCenter)
                        {
                            center = chunkIO.ReadChunkVector3(chunkSize3);
                        }
                        else if (id3 == Wad2Chunks.MeshSphereRadius)
                        {
                            radius = chunkIO.ReadChunkFloat(chunkSize3);
                        }
                        else
                        {
                            return(false);
                        }
                        return(true);
                    });
                    mesh.BoundingSphere = new BoundingSphere(center, radius);
                }
                else if (id2 == Wad2Chunks.MeshBoundingBox)
                {
                    // Read bounding box
                    Vector3 min = Vector3.Zero;
                    Vector3 max = Vector3.Zero;
                    chunkIO.ReadChunks((id3, chunkSize3) =>
                    {
                        if (id3 == Wad2Chunks.MeshBoundingBoxMin)
                        {
                            min = chunkIO.ReadChunkVector3(chunkSize3);
                        }
                        else if (id3 == Wad2Chunks.MeshBoundingBoxMax)
                        {
                            max = chunkIO.ReadChunkVector3(chunkSize3);
                        }
                        else
                        {
                            return(false);
                        }
                        return(true);
                    });
                    mesh.BoundingBox = new BoundingBox(min, max);
                }
                else if (id2 == Wad2Chunks.MeshVertexPositions)
                {
                    chunkIO.ReadChunks((id3, chunkSize3) =>
                    {
                        if (id3 == Wad2Chunks.MeshVertexPosition)
                        {
                            mesh.VerticesPositions.Add(chunkIO.ReadChunkVector3(chunkSize3));
                        }
                        else
                        {
                            return(false);
                        }
                        return(true);
                    });
                }
                else if (id2 == Wad2Chunks.MeshVertexNormals)
                {
                    chunkIO.ReadChunks((id3, chunkSize3) =>
                    {
                        if (id3 == Wad2Chunks.MeshVertexNormal)
                        {
                            mesh.VerticesNormals.Add(chunkIO.ReadChunkVector3(chunkSize3));
                        }
                        else
                        {
                            return(false);
                        }
                        return(true);
                    });
                }
                else if (id2 == Wad2Chunks.MeshVertexShades)
                {
                    chunkIO.ReadChunks((id3, chunkSize3) =>
                    {
                        if (id3 == Wad2Chunks.MeshVertexShade)
                        {
                            mesh.VerticesShades.Add(chunkIO.ReadChunkShort(chunkSize3));
                        }
                        else
                        {
                            return(false);
                        }
                        return(true);
                    });
                }
                else if (id2 == Wad2Chunks.MeshPolygons)
                {
                    chunkIO.ReadChunks((id3, chunkSize3) =>
                    {
                        if (id3 == Wad2Chunks.MeshQuad ||
                            id3 == Wad2Chunks.MeshTriangle)
                        {
                            var polygon    = new WadPolygon();
                            polygon.Shape  = id3 == Wad2Chunks.MeshQuad ? WadPolygonShape.Quad : WadPolygonShape.Triangle;
                            polygon.Index0 = LEB128.ReadInt(chunkIO.Raw);
                            polygon.Index1 = LEB128.ReadInt(chunkIO.Raw);
                            polygon.Index2 = LEB128.ReadInt(chunkIO.Raw);
                            if (id3 == Wad2Chunks.MeshQuad)
                            {
                                polygon.Index3 = LEB128.ReadInt(chunkIO.Raw);
                            }
                            polygon.ShineStrength = LEB128.ReadByte(chunkIO.Raw);

                            TextureArea textureArea = new TextureArea();
                            textureArea.Texture     = textures[LEB128.ReadInt(chunkIO.Raw)];
                            textureArea.TexCoord0   = chunkIO.Raw.ReadVector2();
                            textureArea.TexCoord1   = chunkIO.Raw.ReadVector2();
                            textureArea.TexCoord2   = chunkIO.Raw.ReadVector2();
                            if (id3 == Wad2Chunks.MeshQuad)
                            {
                                textureArea.TexCoord3 = chunkIO.Raw.ReadVector2();
                            }
                            else
                            {
                                textureArea.TexCoord3 = textureArea.TexCoord2;
                            }
                            textureArea.BlendMode   = (BlendMode)LEB128.ReadLong(chunkIO.Raw);
                            textureArea.DoubleSided = chunkIO.Raw.ReadBoolean();
                            polygon.Texture         = textureArea;

                            chunkIO.ReadChunks((id4, chunkSize4) =>
                            {
                                return(false);
                            });

                            mesh.Polys.Add(polygon);
                        }
                        else
                        {
                            return(false);
                        }
                        return(true);
                    });
                }
                else
                {
                    return(false);
                }

                return(true);
            });

            return(mesh);
        }
Exemplo n.º 10
0
        private static TextureArea CalculateTr4UVCoordinates(Wad2 wad, Tr4Wad oldWad, wad_polygon poly, Dictionary <int, WadTexture> textures)
        {
            TextureArea textureArea = new TextureArea();

            textureArea.BlendMode   = (poly.Attributes & 0x01) != 0 ? BlendMode.Additive : BlendMode.Normal;
            textureArea.DoubleSided = false;

            int textureId = GetTr4TextureIdFromPolygon(poly);

            textureArea.Texture = textures[textureId];

            // Add the UV coordinates
            int shape   = (poly.Texture & 0x7000) >> 12;
            int flipped = (poly.Texture & 0x8000) >> 15;

            wad_object_texture texture = oldWad.Textures[textureId];

            Vector2 nw = new Vector2(0, 0);
            Vector2 ne = new Vector2(texture.Width + 1.0f, 0);
            Vector2 se = new Vector2(texture.Width + 1.0f, texture.Height + 1.0f);
            Vector2 sw = new Vector2(0, texture.Height + 1.0f);

            if (poly.Shape == 9)
            {
                if (flipped == 1)
                {
                    textureArea.TexCoord0 = ne;
                    textureArea.TexCoord1 = nw;
                    textureArea.TexCoord2 = sw;
                    textureArea.TexCoord3 = se;
                }
                else
                {
                    textureArea.TexCoord0 = nw;
                    textureArea.TexCoord1 = ne;
                    textureArea.TexCoord2 = se;
                    textureArea.TexCoord3 = sw;
                }
            }
            else
            {
                switch (shape)
                {
                case 0:
                    if (flipped == 1)
                    {
                        textureArea.TexCoord0 = ne;
                        textureArea.TexCoord1 = nw;
                        textureArea.TexCoord2 = se;
                        textureArea.TexCoord3 = textureArea.TexCoord2;
                    }
                    else
                    {
                        textureArea.TexCoord0 = nw;
                        textureArea.TexCoord1 = ne;
                        textureArea.TexCoord2 = sw;
                        textureArea.TexCoord3 = textureArea.TexCoord2;
                    }
                    break;

                case 2:
                    if (flipped == 1)
                    {
                        textureArea.TexCoord0 = nw;
                        textureArea.TexCoord1 = sw;
                        textureArea.TexCoord2 = ne;
                        textureArea.TexCoord3 = textureArea.TexCoord2;
                    }
                    else
                    {
                        textureArea.TexCoord0 = ne;
                        textureArea.TexCoord1 = se;
                        textureArea.TexCoord2 = nw;
                        textureArea.TexCoord3 = textureArea.TexCoord2;
                    }
                    break;

                case 4:
                    if (flipped == 1)
                    {
                        textureArea.TexCoord0 = sw;
                        textureArea.TexCoord1 = se;
                        textureArea.TexCoord2 = nw;
                        textureArea.TexCoord3 = textureArea.TexCoord2;
                    }
                    else
                    {
                        textureArea.TexCoord0 = se;
                        textureArea.TexCoord1 = sw;
                        textureArea.TexCoord2 = ne;
                        textureArea.TexCoord3 = textureArea.TexCoord2;
                    }
                    break;

                case 6:
                    if (flipped == 1)
                    {
                        textureArea.TexCoord0 = se;
                        textureArea.TexCoord1 = ne;
                        textureArea.TexCoord2 = sw;
                        textureArea.TexCoord3 = textureArea.TexCoord2;
                    }
                    else
                    {
                        textureArea.TexCoord0 = sw;
                        textureArea.TexCoord1 = nw;
                        textureArea.TexCoord2 = se;
                        textureArea.TexCoord3 = textureArea.TexCoord2;
                    }
                    break;

                default:
                    throw new NotImplementedException("Unknown texture shape " + shape + " found in the wad.");
                }
            }

            return(textureArea);
        }
Exemplo n.º 11
0
        private static TextureArea[] ConvertTrLevelTexturesToWadTexture(TrLevel oldLevel)
        {
            var    objectTextures = new TextureArea[oldLevel.ObjectTextures.Count];
            ImageC tiles          = ImageC.FromByteArray(oldLevel.TextureMap32, 256, oldLevel.TextureMap32.Length / 1024);

            tiles.ReplaceColor(new ColorC(255, 0, 255, 255), new ColorC(0, 0, 0, 0));

            // for (int i = 0; i < oldLevel.ObjectTextures.Count; ++i)
            Parallel.For(0, oldLevel.ObjectTextures.Count, i =>
            {
                var oldTexture = oldLevel.ObjectTextures[i];

                int textureTileIndex = oldTexture.TileAndFlags & 0x7fff;
                bool isTriangle      = (oldTexture.TileAndFlags & 0x8000) != 0; // Exists only in TR4+

                if (oldLevel.Version == TRVersion.Game.TR1 || oldLevel.Version == TRVersion.Game.TR2 || oldLevel.Version == TRVersion.Game.TR3)
                {
                    isTriangle = (oldTexture.Vertices[3].X == 0) && (oldTexture.Vertices[3].Y == 0);
                }

                // Calculate UV coordinates...
                Vector2[] coords = new Vector2[isTriangle ? 3 : 4];
                for (int j = 0; j < coords.Length; ++j)
                {
                    coords[j] = new Vector2(oldTexture.Vertices[j].X, oldTexture.Vertices[j].Y) * (1.0f / 256.0f);
                }

                // Find the corners of the texture
                Vector2 min = coords[0], max = coords[0];
                for (int j = 1; j < coords.Length; ++j)
                {
                    min = Vector2.Min(min, coords[j]);
                    max = Vector2.Max(max, coords[j]);
                }

                VectorInt2 start = VectorInt2.FromFloor(min);
                VectorInt2 end   = VectorInt2.FromCeiling(max);
                start            = VectorInt2.Min(VectorInt2.Max(start, new VectorInt2()), new VectorInt2(256, 256));
                end = VectorInt2.Min(VectorInt2.Max(end, new VectorInt2()), new VectorInt2(256, 256));

                // Create image
                ImageC image = ImageC.CreateNew(end.X - start.X, end.Y - start.Y);
                image.CopyFrom(0, 0, tiles, start.X, start.Y + textureTileIndex * 256, end.X - start.X, end.Y - start.Y);

                // Replace black with transparent color
                //image.ReplaceColor(new ColorC(0, 0, 0, 255), new ColorC(0, 0, 0, 0));

                WadTexture texture = new WadTexture(image);

                // Create texture area
                TextureArea textureArea = new TextureArea();
                textureArea.DoubleSided = false;
                textureArea.BlendMode   = (BlendMode)(oldTexture.Attributes);
                textureArea.TexCoord0   = coords[0] - start;
                textureArea.TexCoord1   = coords[1] - start;
                textureArea.TexCoord2   = coords[2] - start;
                textureArea.TexCoord3   = isTriangle ? textureArea.TexCoord2 : (coords[3] - start);
                textureArea.Texture     = texture;

                objectTextures[i] = textureArea;
            });

            return(objectTextures);
        }
Exemplo n.º 12
0
        private static WadMesh ConvertTrLevelMeshToWadMesh(Wad2 wad, TrLevel oldLevel, tr_mesh oldMesh, TextureArea[] objectTextures)
        {
            WadMesh mesh = new WadMesh();

            mesh.Name = "Mesh_" + oldLevel.Meshes.IndexOf(oldMesh);

            // Add positions
            foreach (var oldVertex in oldMesh.Vertices)
            {
                mesh.VerticesPositions.Add(new Vector3(oldVertex.X, -oldVertex.Y, oldVertex.Z));
            }

            // Create the bounding areas
            mesh.BoundingSphere = new BoundingSphere(new Vector3(oldMesh.Center.X, oldMesh.Center.Y, oldMesh.Center.Z), oldMesh.Radius);
            mesh.BoundingBox    = mesh.CalculateBoundingBox();

            // Add normals
            foreach (var oldNormal in oldMesh.Normals)
            {
                mesh.VerticesNormals.Add(new Vector3(oldNormal.X, -oldNormal.Y, oldNormal.Z));
            }

            // Add shades
            foreach (var oldShade in oldMesh.Lights)
            {
                mesh.VerticesShades.Add(oldShade);
            }

            // Add polygons
            foreach (var oldPoly in oldMesh.TexturedQuads)
            {
                TextureArea textureArea = objectTextures[oldPoly.Texture & 0x7fff];
                textureArea.DoubleSided = (oldPoly.Texture & 0x8000) != 0;

                WadPolygon poly;
                poly.Shape         = WadPolygonShape.Quad;
                poly.Index0        = oldPoly.Index0;
                poly.Index1        = oldPoly.Index1;
                poly.Index2        = oldPoly.Index2;
                poly.Index3        = oldPoly.Index3;
                poly.ShineStrength = (byte)((oldPoly.LightingEffect & 0x7c) >> 2);
                poly.Texture       = textureArea;
                mesh.Polys.Add(poly);
            }
            foreach (var oldPoly in oldMesh.TexturedTriangles)
            {
                TextureArea textureArea = objectTextures[oldPoly.Texture & 0x7fff];
                textureArea.DoubleSided = (oldPoly.Texture & 0x8000) != 0;

                WadPolygon poly = new WadPolygon();
                poly.Shape         = WadPolygonShape.Triangle;
                poly.Index0        = oldPoly.Index0;
                poly.Index1        = oldPoly.Index1;
                poly.Index2        = oldPoly.Index2;
                poly.Index3        = 0;
                poly.ShineStrength = (byte)((oldPoly.LightingEffect & 0x7c) >> 2);
                poly.Texture       = textureArea;
                mesh.Polys.Add(poly);
            }

            foreach (var oldPoly in oldMesh.ColoredRectangles)
            {
                WadPolygon poly = new WadPolygon();
                poly.Shape         = WadPolygonShape.Quad;
                poly.Index0        = oldPoly.Index0;
                poly.Index1        = oldPoly.Index1;
                poly.Index2        = oldPoly.Index2;
                poly.Index3        = oldPoly.Index3;
                poly.Texture       = ConvertColoredFaceToTexture(wad, oldLevel, oldPoly.Texture, false);
                poly.ShineStrength = 0;
                mesh.Polys.Add(poly);
            }

            foreach (var oldPoly in oldMesh.ColoredTriangles)
            {
                WadPolygon poly;
                poly.Shape         = WadPolygonShape.Triangle;
                poly.Index0        = oldPoly.Index0;
                poly.Index1        = oldPoly.Index1;
                poly.Index2        = oldPoly.Index2;
                poly.Index3        = 0;
                poly.Texture       = ConvertColoredFaceToTexture(wad, oldLevel, oldPoly.Texture, true);
                poly.ShineStrength = 0;
                mesh.Polys.Add(poly);
            }

            // Usually only for static meshes
            if (mesh.VerticesNormals.Count == 0)
            {
                mesh.CalculateNormals();
            }

            return(mesh);
        }