Exemplo n.º 1
0
        /// <summary>
        /// Paint a line given the 2 points
        /// </summary>
        /// <param name="points"></param>
        private void makeLine(LinkedList <Pair <double, double> > points)
        {
            NWN2Toolset.NWN2.Views.NWN2AreaViewer viewer   = getAreaViewer();
            NWN2Toolset.NWN2ToolsetMainForm       mainForm = NWN2Toolset.NWN2ToolsetMainForm.App;
            NWN2GameArea area = viewer.Area;

            TRN trn = new SFX.YATT.DAL.TRN(new System.IO.BinaryReader(area.TerrainResource.GetStream(false)), area.Name);

            Pair <Pair <double, double>, Pair <double, double> > resultPair = findUpperAndLower(points);

            Pair <double, double> upper = resultPair.X;
            Pair <double, double> lower = resultPair.Y;

            trn = ApplyLine(area, trn, upper, lower);

            System.IO.Stream       stream = area.TerrainResource.GetStream(true);
            System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);

            trn.Save(writer);
            stream.Flush();
            stream.Close();
            areaViewer.SaveContents(true, OEIShared.UI.OEIMessageBoxResult.OK);
            mainForm.WaitForPanelsToSave();

            mainForm.CloseViewer(areaViewer, true);
        }
Exemplo n.º 2
0
        private void paintTriangles(LinkedList <Triangle> triangles)
        {
            NWN2Toolset.NWN2.Views.NWN2AreaViewer viewer = getAreaViewer();
            if (viewer != null)
            {
                NWN2Toolset.NWN2ToolsetMainForm mainForm = NWN2Toolset.NWN2ToolsetMainForm.App;
                NWN2GameArea area = viewer.Area;
                TRN          trn  = new SFX.YATT.DAL.TRN(new System.IO.BinaryReader(area.TerrainResource.GetStream(false)), area.Name);

                // The random object we are going to use for all the instances
                Random ran = new Random();

                area.Demand();
                area.RefreshTerrainResource();

                System.IO.Stream       stream = area.TerrainResource.GetStream(true);
                System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);

                foreach (Triangle triangle in triangles)
                {
                    trn = ApplyTriangle(area, trn, triangle, triangle.getUpper(), triangle.getLower(), ran);
                }

                trn.Save(writer);
                stream.Flush();
                stream.Close();

                viewer.SaveContents(true, OEIShared.UI.OEIMessageBoxResult.OK);

                mainForm.WaitForPanelsToSave();
                mainForm.CloseViewer(viewer, true);
            }
        }
Exemplo n.º 3
0
        private void paintTriangles(LinkedList<Triangle> triangles)
        {
            NWN2Toolset.NWN2.Views.NWN2AreaViewer viewer = getAreaViewer();
            if (viewer != null) {
                NWN2Toolset.NWN2ToolsetMainForm mainForm = NWN2Toolset.NWN2ToolsetMainForm.App;
                NWN2GameArea area = viewer.Area;
                TRN trn = new SFX.YATT.DAL.TRN( new System.IO.BinaryReader( area.TerrainResource.GetStream( false ) ), area.Name );

                // The random object we are going to use for all the instances
                Random ran = new Random();

                area.Demand();
                area.RefreshTerrainResource();

                System.IO.Stream stream = area.TerrainResource.GetStream( true );
                System.IO.BinaryWriter writer = new System.IO.BinaryWriter( stream );

                foreach (Triangle triangle in triangles) {
                    trn = ApplyTriangle(area, trn, triangle, triangle.getUpper(), triangle.getLower(), ran);
                }

                trn.Save(writer);
                stream.Flush();
                stream.Close();

                viewer.SaveContents(true, OEIShared.UI.OEIMessageBoxResult.OK);

                mainForm.WaitForPanelsToSave();
                mainForm.CloseViewer(viewer, true);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Paint a line given the 2 points
        /// </summary>
        /// <param name="points"></param>
        private void makeLine(LinkedList<Pair<double, double>> points)
        {
            NWN2Toolset.NWN2.Views.NWN2AreaViewer viewer = getAreaViewer();
            NWN2Toolset.NWN2ToolsetMainForm mainForm = NWN2Toolset.NWN2ToolsetMainForm.App;
            NWN2GameArea area = viewer.Area;

            TRN trn = new SFX.YATT.DAL.TRN( new System.IO.BinaryReader( area.TerrainResource.GetStream( false ) ), area.Name );

            Pair<Pair<double, double>, Pair<double, double>> resultPair = findUpperAndLower(points);

            Pair<double, double> upper = resultPair.X;
            Pair<double, double> lower = resultPair.Y;

            trn = ApplyLine(area, trn, upper, lower);

            System.IO.Stream stream = area.TerrainResource.GetStream( true );
            System.IO.BinaryWriter writer = new System.IO.BinaryWriter( stream );

            trn.Save( writer );
            stream.Flush();
            stream.Close();
            areaViewer.SaveContents(true, OEIShared.UI.OEIMessageBoxResult.OK);
            mainForm.WaitForPanelsToSave();

            mainForm.CloseViewer(areaViewer, true);
        }
Exemplo n.º 5
0
        private TRN ApplyTextureLine(TRN trn, Pair<double, double> upper, Pair<double, double> lower)
        {
            int xStart = (int)Math.Floor((Math.Min(upper.X, lower.X) - this.newInner) / Constants.TextureSpacing);
            int width = (int)(4 * this.newInner * Math.Abs(upper.X - lower.X));

            int yStart = (int)Math.Floor((Math.Min(upper.Y, lower.Y) - this.newInner) / Constants.TextureSpacing);
            int height = (int)(4 * this.newInner * Math.Abs(upper.Y - lower.Y));

            Rectangle coverRectangle = new Rectangle(xStart, yStart, width, height);

            LineSegment lineSegment = new LineSegment(upper, lower);
            foreach (textureData texture in data.textures) {
                int i = 0;
                foreach (DDSGroup ddsGroup in trn.DDSGroups)
                {
                    //Check whether the DDSGroup contain parts of the rectangle that surrounds the triangle
                    int x = ( i % trn.Width ) * ddsGroup.Width;
                    int y = ( ( i - ( i % trn.Width ) ) / trn.Width ) * ddsGroup.Height;
                    i++;

                    ddsGroup.ApplyTextureAsNewChannel(x, y, texture, lineSegment, coverRectangle, this.newInner);
                }
            }

            return trn;
        }
Exemplo n.º 6
0
        private TRN ApplyLine(NWN2Toolset.NWN2.Data.NWN2GameArea area, TRN trn, Pair<double, double> upper, Pair<double, double> lower)
        {
            if (data.colourOption == colourOption.Colour) {
                trn = ApplyColourLine(trn, upper, lower);
            }

            //texturemaps
            trn = ApplyTextureLine(trn, upper, lower);

            return trn;
        }
Exemplo n.º 7
0
        private TRN ApplyColourLine(TRN trn, Pair<double, double> upper, Pair<double, double> lower)
        {
            Random ran = new Random();
            int coverage = 0;
            LineSegment linesegment = new LineSegment(upper, lower);

            foreach (Vertex vertex in trn.Vertices) {
                Pair<double, double> point = new Pair<double, double>(vertex.Position[0], vertex.Position[1]);

                if ((upper.X <= point.X && point.X <= lower.X) && (upper.Y <= point.Y && point.Y <= lower.Y)) {
                    if (linesegment.distance(point) <= Constants.VertexSpacing + newInner) {
                        coverage = ran.Next(1, 100);
                        if (coverage <= data.colourCoverage) {
                            vertex.Color = data.col;
                        }
                    }
                }
            }

            return trn;
        }
Exemplo n.º 8
0
        /// <summary>
        /// The method that calls the colour and texture methods
        /// </summary>
        /// <param name="area">The area we want to change</param>
        /// <param name="trn">The TRN data that we is going to modify</param>
        /// <param name="triangle">The Triangle we want to paint inside</param>
        /// <param name="upper">The left upper point of the rectangle that contains triangle</param>
        /// <param name="lower">The right lower point of the rectangle that contains triangle</param>
        /// <returns></returns>
        public TRN ApplyTriangle(NWN2Toolset.NWN2.Data.NWN2GameArea area, TRN trn, Triangle triangle, Pair<double, double> upper, Pair<double, double> lower, Random ran)
        {
            if (data.colourOption == colourOption.Colour) {
                trn = ApplyColourTriangle(trn, triangle, upper, lower, ran);
            }

            //texturemaps
            trn = ApplyTextureTriangle(trn, triangle, upper, lower, ran);

            return trn;
        }
Exemplo n.º 9
0
        /// <summary>
        /// The method that uses the texture the inside of the triangle
        /// </summary>
        /// <param name="trn">The TRN data that we is going to modify</param>
        /// <param name="triangle">The Triangle we want to paint inside</param>
        /// <param name="upper">The left upper point of the rectangle that contains triangle</param>
        /// <param name="lower">The right lower point of the rectangle that contains triangle</param>
        /// <returns></returns>
        public TRN ApplyTextureTriangle(TRN trn, Triangle triangle, Pair<double, double> upper, Pair<double, double> lower, Random ran)
        {
            Rectangle coverRectangle = new Rectangle((int)Math.Floor(upper.X / Constants.TextureSpacing), (int)Math.Floor(upper.Y / Constants.TextureSpacing),
                                                     (int)Math.Ceiling((lower.X - upper.X) / Constants.TextureSpacing), (int)Math.Ceiling((lower.Y - upper.Y) / Constants.TextureSpacing));

            foreach (textureData texture in data.textures) {
                int i = 0;
                foreach (DDSGroup ddsGroup in trn.DDSGroups)
                {
                    //Check whether the DDSGroup contain parts of the rectangle that surrounds the triangle
                    int x = ( i % trn.Width ) * ddsGroup.Width;
                    int y = ( ( i - ( i % trn.Width ) ) / trn.Width ) * ddsGroup.Height;
                    i++;

                    ddsGroup.ApplyTextureAsNewChannel(x, y, texture, triangle, coverRectangle, ran);
                }
            }
            return trn;
        }
Exemplo n.º 10
0
        /// <summary>
        /// The method that colours the inside of the triangle
        /// </summary>
        /// <param name="trn">The TRN data that we is going to modify</param>
        /// <param name="triangle">The Triangle we want to paint inside</param>
        /// <param name="upper">The left upper point of the rectangle that contains triangle</param>
        /// <param name="lower">The right lower point of the rectangle that contains triangle</param>
        /// <returns>The changed TRN data</returns>
        public TRN ApplyColourTriangle(TRN trn, Triangle triangle, Pair<double, double> upper, Pair<double, double> lower, Random ran)
        {
            int coverage = 0;

            foreach (Vertex vertex in trn.Vertices) {
                float x = vertex.Position[0];
                float y = vertex.Position[1];

                if ((upper.X <= x && x <= lower.X) && (upper.Y <= y && y <= lower.Y)) {
                    if (triangle.insideTriangle(new Pair<double, double>(x, y))) {
                        coverage = ran.Next(1, 100);
                        if (coverage <= data.colourCoverage) {
                            vertex.Color = data.col;
                        }
                    }
                }
            }
            return trn;
        }