I am using the Helixtoolkit.WPF in my C# program. I have imported the NuGet package and it is working perfectly. However, I am wanting to edit one of the files, specifically GridLinesVisual.cs. I want to change how one of the functions in that file operates, but can’t seem to get it working.
The function I need to change begins on line 247 protected override MeshGeometry3D Tessellate()
Here is a link to the file I need to update/change https://searchcode.com/codesearch/view/10564811/
The calling code from my program is 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 am thinking that an override is the proper way to do this, but I can’t get that working. I created a new file RectGrid.cs 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 showing up. Is using an override the proper way to modify how Tessellate functions or is there a better/easier way to edit it?
For what it is worth, the Tessellate function is creating grid lines in the X and Y directions. I only want grid lines in the Y direction, not the X. So basically I don’t want a grid, I just want lines…
Your changes only apply to the RectGrid
class. you aren't modifying the behavior of the original class, that isn't how overrides work.
You need to make sure that you add using Axcro.Helix_Toolkit_Extentions;
to the top of your file where you instantiate your class. If the RectGrid
class is in a different DLL that where it is being used. Make sure to add a reference.
Then you will instantiate your class instance of the GridLinesVisual3D
with
grid = new RectGrid();