Editing a Nuget C # Helixtoolkit.WPF Package

I am using Helixtoolkit.WPF in my C # program. I imported the NuGet package and it works fine. However, I want to edit one of the files, in particular GridLinesVisual.cs. I want to change how one of the functions in this file works, but it doesn't seem to work.

The function I need to change starts on line 247 protected override MeshGeometry3D Tessellate()

Here is the link to the file I need to update / change https://searchcode.com/codesearch/view/10564811/

The calling code from my program grid = new GridLinesVisual3D();

I am not as familiar with C # as I am with C ++, but I know that I cannot create a child class to edit this function. I think overriding is the right way to do this, but I can't get it to work. I created a new RectGrid.cs file, and this is what I have in the code:

using HelixToolkit.Wpf;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Media3D;

namespace Axcro.Helix_Toolkit_Extentions
{
    class RectGrid : GridLinesVisual3D
    {
        protected override MeshGeometry3D Tessellate()
        {
        this.lengthDirection = this.LengthDirection;
        this.lengthDirection.Normalize();
        this.widthDirection = Vector3D.CrossProduct(this.Normal, this.lengthDirection);
        this.widthDirection.Normalize();

        var mesh = new MeshBuilder(true, false);
        double minX = -this.Width / 2;
        double minY = -this.Length / 2;
        double maxX = this.Width / 2;
        double maxY = this.Length / 2;

        double x = minX;
        double eps = this.MinorDistance / 10;
        while (x <= maxX + eps)
        {
            double t = this.Thickness;
            if (IsMultipleOf(x, this.MajorDistance))
            {
                t *= 2;
            }

            this.AddLineX(mesh, x, minY, maxY, t);
            x += this.MinorDistance;
        }

        var m = mesh.ToMesh();
        m.Freeze();
        return m;
        }
    }
} 

This code compiles just fine, but my changes to Tessellate are not displayed. Is using override the correct way to change the Tessellate function or is there a better / easier way to edit it?

For what it's worth, the Tessellate function creates grid lines in the X and Y directions. I only need grid lines in the Y direction, not X. So basically I don't want the grid, I just need the lines ...

+4
source share
2 answers

RectGrid. , , .

, using Axcro.Helix_Toolkit_Extentions; , . RectGrid DLL, . .

GridLinesVisual3D

grid = new RectGrid();
+1

I, RectGrid.cs

using HelixToolkit.Wpf;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Media3D;

namespace Axcro.Helix_Toolkit_Extentions
   {
   class RectGrid : GridLinesVisual3D
{
    private Vector3D lengthDirection;
    private Vector3D widthDirection;
    private void AddLineY(MeshBuilder mesh, double y, double minX,     double maxX, double thickness)
    {
        int i0 = mesh.Positions.Count;
        mesh.Positions.Add(this.GetPoint(minX, y + thickness / 2));
        mesh.Positions.Add(this.GetPoint(maxX, y + thickness / 2));
        mesh.Positions.Add(this.GetPoint(maxX, y - thickness / 2));
        mesh.Positions.Add(this.GetPoint(minX, y - thickness / 2));
        mesh.Normals.Add(this.Normal);
        mesh.Normals.Add(this.Normal);
        mesh.Normals.Add(this.Normal);
        mesh.Normals.Add(this.Normal);
        mesh.TriangleIndices.Add(i0);
        mesh.TriangleIndices.Add(i0 + 1);
        mesh.TriangleIndices.Add(i0 + 2);
        mesh.TriangleIndices.Add(i0 + 2);
        mesh.TriangleIndices.Add(i0 + 3);
        mesh.TriangleIndices.Add(i0);
    }
        private Point3D GetPoint(double x, double y)
    {
        return this.Center + this.widthDirection * x +     this.lengthDirection * y;
    }
        private static bool IsMultipleOf(double y, double d)
    {
        double y2 = d * (int)(y / d);
        return (y - y2) < 1e-3;
        }

        protected override MeshGeometry3D Tessellate()
        {
            this.lengthDirection = this.LengthDirection;
            this.lengthDirection.Normalize();
            this.widthDirection = Vector3D.CrossProduct(this.Normal,     this.lengthDirection);
            this.widthDirection.Normalize();

            var mesh = new MeshBuilder(true, false);
            double minX = -this.Width / 2;
            double minY = -this.Length / 2;
            double maxX = this.Width / 2;
            double maxY = this.Length / 2;
            double eps = this.MinorDistance / 10;
            double y = minY;
            while (y <= maxY + eps)
            {
                double t = this.Thickness;
                if (IsMultipleOf(y, this.MajorDistance))
                {
                    t *= 2;
                }

                this.AddLineY(mesh, y, minX, maxX, t);
                y += this.MinorDistance;
            }


            var m = mesh.ToMesh();
            m.Freeze();
            return m;
        }
    }
}

, , using Axcro.Helix_Toolkit_Extentions;

grid = new RectGrid();

, , , . !

0

Source: https://habr.com/ru/post/1589001/


All Articles