本文整理汇总了C#中HelixToolkit.Wpf.MeshBuilder类的典型用法代码示例。如果您正苦于以下问题:C# MeshBuilder类的具体用法?C# MeshBuilder怎么用?C# MeshBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MeshBuilder类属于HelixToolkit.Wpf命名空间,在下文中一共展示了MeshBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MainViewModel
public MainViewModel()
{
var gm = new MeshBuilder();
gm.AddBox(new Point3D(0, 0, 0.5), 1, 1, 1);
gm.AddCylinder(new Point3D(5, 0, 0), new Point3D(5, 0, 5), 1, 36);
this.Model = new GeometryModel3D(gm.ToMesh(true), Materials.Blue);
this.Model.Freeze();
}
示例2: buildTri
private static object buildTri()
{
var mb = new MeshBuilder(true, false);
var p0 = new Point3D(0, 0, 0);
var p1 = new Point3D(1, 0, 0);
var p2 = new Point3D(1, 1, 0);
mb.AddTriangle(p0, p1, p2);
mb.Normals.ToList().ForEach(x => System.Diagnostics.Trace.WriteLine(x.ToString()));
return mb.ToMesh();
}
示例3: MainViewModel
/// <summary>
/// Initializes a new instance of the <see cref="MainViewModel"/> class.
/// </summary>
public MainViewModel()
{
// Create a model group
var modelGroup = new Model3DGroup();
// Create a mesh builder and add a box to it
var meshBuilder = new MeshBuilder(false, false);
meshBuilder.AddBox(new Point3D(0, 0, 1), 1, 2, 0.5);
meshBuilder.AddBox(new Rect3D(0, 0, 1.2, 0.5, 1, 0.4));
// Create a mesh from the builder (and freeze it)
var mesh = meshBuilder.ToMesh(true);
// Create some materials
var greenMaterial = MaterialHelper.CreateMaterial(Colors.Green);
var redMaterial = MaterialHelper.CreateMaterial(Colors.Red);
var blueMaterial = MaterialHelper.CreateMaterial(Colors.Blue);
var insideMaterial = MaterialHelper.CreateMaterial(Colors.Yellow);
// Add 3 models to the group (using the same mesh, that's why we had to freeze it)
modelGroup.Children.Add(new GeometryModel3D { Geometry = mesh, Material = greenMaterial, BackMaterial = insideMaterial });
modelGroup.Children.Add(new GeometryModel3D { Geometry = mesh, Transform = new TranslateTransform3D(-2, 0, 0), Material = redMaterial, BackMaterial = insideMaterial });
modelGroup.Children.Add(new GeometryModel3D { Geometry = mesh, Transform = new TranslateTransform3D(2, 0, 0), Material = blueMaterial, BackMaterial = insideMaterial });
//// Set the property, which will be bound to the Content property of the ModelVisual3D (see MainWindow.xaml)
//AxisAngleRotation3D rotateAxis = new AxisAngleRotation3D(new Vector3D(0, 1, 0), 180/*or 360*/);
//Rotation3DAnimation rotateAnimation = new Rotation3DAnimation(rotateAxis, TimeSpan.FromSeconds(2));
//var rotateTransform = new RotateTransform3D();
//rotateTransform.BeginAnimation(RotateTransform3D.RotationProperty, rotateAnimation);
//modelGroup.Transform = rotateTransform;
this.Model = modelGroup;
}
示例4: Initializer
private void Initializer(Point3D location)
{
var geometryModel = new GeometryModel3D();
var meshBuilder = new MeshBuilder();
meshBuilder.AddBox(new Point3D(location.X, location.Y, location.Z + 3.5), 1.5, 1.5, 0.25);
meshBuilder.AddBox(new Point3D(location.X, location.Y + 1, location.Z + 3.5), 0.25, 1.25, 0.25);
meshBuilder.AddBox(new Point3D(location.X, location.Y - 1, location.Z + 3.5), 0.25, 1.25, 0.25);
meshBuilder.AddBox(new Point3D(location.X + 1, location.Y , location.Z + 3.5), 1.25, 0.25, 0.25);
meshBuilder.AddBox(new Point3D(location.X - 1, location.Y, location.Z + 3.5), 1.25, 0.25, 0.25);
meshBuilder.AddBox(new Point3D(location.X, location.Y + 1.5, location.Z + 3), 0.25, 0.25, 0.75);
meshBuilder.AddBox(new Point3D(location.X, location.Y - 1.5, location.Z + 3), 0.25, 0.25, 0.75);
meshBuilder.AddBox(new Point3D(location.X + 1.5, location.Y, location.Z + 3), 0.25, 0.25, 0.75);
meshBuilder.AddBox(new Point3D(location.X - 1.5, location.Y, location.Z + 3), 0.25, 0.25, 0.75);
meshBuilder.AddBox(new Point3D(location.X, location.Y, location.Z + 4), 0.5, 0.5, 1);
geometryModel.Geometry = meshBuilder.ToMesh();
geometryModel.Material = Materials.Gold;
Visual3DModel = geometryModel;
}
示例5: ModelVisual3D
// Add all cubes to a ModelVisual3D, reuse geometry but create new visual for each cube - this is slow
/* GeometryModel3D AddGeometrySeparate(IEnumerable<Point3D> centers, double L)
{
var mv = new ModelVisual3D();
var cubit = new CubeVisual3D { SideLength = L * 0.95, Fill = Brushes.Gold };
var cuboidGeometry = cubit.Model.Geometry as MeshGeometry3D;
var r = new Random();
foreach (var center in centers)
{
var tg = new Transform3DGroup();
tg.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), (r.NextDouble() - 0.5) * 10)));
tg.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), (r.NextDouble() - 0.5) * 10)));
tg.Children.Add(new TranslateTransform3D(center.ToVector3D()));
var c = new ModelVisual3D
{
Content =
new GeometryModel3D
{
Geometry = cuboidGeometry,
Material = cubit.Material,
Transform = tg
}
};
mv.Children.Add(c);
}
return mv;
}*/
// All cubes in one GeometryModel - much faster
GeometryModel3D AddGeometry(IEnumerable<Point3D> centers, double L)
{
var w = new Stopwatch();
w.Start();
/* var geometry = new MeshGeometry3D();
foreach (var center in centers)
{
MeshGeometryHelper.AddBox(geometry,center, L, L, L);
}
*/
var builder = new MeshBuilder();
foreach (var center in centers)
{
builder.AddBox(center, L, L, L);
}
var geometry = builder.ToMesh();
geometry.Freeze();
Trace.WriteLine(Level + ": " + w.ElapsedMilliseconds + " ms");
var mv = new GeometryModel3D
{
Geometry = geometry,
Material = MaterialHelper.CreateMaterial(Brushes.Gold)
};
TriangleCount = geometry.TriangleIndices.Count / 3;
return mv;
}
示例6: AddCircleInZCross
private static void AddCircleInZCross(MeshBuilder mb, Point3D centre, double radius, int div)
{
var points = MeshBuilder.GetCircle(div);
var vectors = new Point3DCollection();
var normals = new Vector3DCollection();
var textures = new PointCollection();
vectors.Add(new Point3D(centre.X, centre.Y, 0));
normals.Add(new Vector3D(0, 0, 1));
textures.Add(new Point(0.5, 0.5));
for (int i = 0; i < points.Count - 1; i++)
{
vectors.Add(new Point3D(points[i].X * radius + centre.X, points[i].Y * radius + centre.Y, centre.Z));
normals.Add(new Vector3D(0, 0, -1));
textures.Add(new Point(points[i].X * 0.5 + 0.5, points[i].Y * 0.5 + 0.5));
vectors.Add(new Point3D(points[i + 1].X * radius + centre.X, points[i + 1].Y * radius + centre.Y, centre.Z));
normals.Add(new Vector3D(0, 0, 01));
textures.Add(new Point(points[i + 1].X * 0.5 + 0.5, points[i + 1].Y * 0.5 + 0.5));
}
mb.AddTriangleFan(vectors, normals, textures);
}
示例7: CreateModel
private void CreateModel()
{
const double dt = 0.1;
const int nSteps = 100;
var mb = new MeshBuilder(true, true);
for (double y0 = -5; y0 <= 5; y0 += 0.25)
{
var p0 = new Point(-3, y0);
Point[] pts = Solve(Velocity, p0, dt, nSteps);
var vel = new double[pts.Length];
var diam = new double[pts.Length];
int i = 0;
var pts3d = new Point3D[pts.Length];
double vmax = 0;
foreach (Point pt in pts)
{
pts3d[i] = new Point3D(pt.X, pt.Y, 0);
double v = Velocity(pt.X, pt.Y).Length;
if (v > vmax) vmax = v;
vel[i++] = v;
}
for (int j = 0; j < vel.Length; j++)
vel[j] /= vmax;
for (int j = 0; j < vel.Length; j++)
diam[j] = 0.075;
mb.AddTube(pts3d, vel, diam, 12, false);
}
this.StreamLinesModel = new GeometryModel3D();
this.StreamLinesModel.Geometry = mb.ToMesh();
this.StreamLinesModel.Material = Materials.Hue;
this.StreamLinesModel.BackMaterial = Materials.Hue;
}
示例8: AppearanceChanged
private void AppearanceChanged()
{
var builder = new MeshBuilder(false, true);
// hard code a kerb section
var section = new PointCollection();
int m = 41;
double n = 4;
double a = this.Width / 2;
double b = this.Height;
for (int i = 0; i < m; i++)
{
double t = Math.PI * i / (m - 1);
section.Add(new Point(
a * Math.Sign(Math.Cos(t)) * Math.Pow(Math.Abs(Math.Cos(t)), 2 / n),
-b * Math.Sign(Math.Sin(t)) * Math.Pow(Math.Abs(Math.Sin(t)), 2 / n)));
}
// calculate the texture coordinates
var values = new List<double> { 0 };
for (int i = 1; i < this.Positions.Count; i++)
{
var d = this.Positions[i - 1].DistanceTo(this.Positions[i]);
values.Add(values[values.Count - 1] + (d / this.Length));
}
// create the extruded geometry
builder.AddTube(this.Positions, null, values, null, section, new Vector3D(1, 0, 0), false, false);
this.kerbModel.Geometry = builder.ToMesh();
}
示例9: MainViewModel
public MainViewModel()
{
// Create a model group
var modelGroup = new Model3DGroup();
points = new List<Point3D>();
// Create a mesh builder and add a box to it
var meshBuilder = new MeshBuilder(false, false);
// -1 -1 -1
//1 -1 -1
//1 1 -1
//-1 1 -1
//-1 -1 1
//1 -1 1
//1 1 1
//-1 1 1
string path = @"teapot.ply";
PLYReader reader = new PLYReader();
using (var s = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
{
mg=reader.Read(s);
}
this.points = reader.Vertices;
this.faces = reader.Faces;
// meshBuilder.Positions.Add(new Point3D(-1, -1, -1));//, 1, 2, 0.5);
// meshBuilder.Positions.Add(new Point3D(1, -1, -1));
// meshBuilder.Positions.Add(new Point3D(1, 1, -1));
// meshBuilder.Positions.Add(new Point3D(-1, 1, -1));
// meshBuilder.Positions.Add(new Point3D(-1, -1, 1));
// meshBuilder.Positions.Add(new Point3D(1, -1, 1));
// meshBuilder.Positions.Add(new Point3D(1, 1, 1));
// meshBuilder.Positions.Add(new Point3D(-1, 1, 1));
// meshBuilder.AddPolygon(new int[4] {0,1,2,3 });
// meshBuilder.AddPolygon(new int[4] { 5,4,7,6 });
// meshBuilder.AddPolygon(new int[4] { 6,2,1,5 });
// meshBuilder.AddPolygon(new int[4] { 3,7,4,0 });
// meshBuilder.AddPolygon(new int[4] { 7,3,2,6 });
// meshBuilder.AddPolygon(new int[4] { 5,1,0,4 });
// // Create a mesh from the builder (and freeze it)
// var mesh = meshBuilder.ToMesh(true);
// // Create some materials
// var greenMaterial = MaterialHelper.CreateMaterial(Colors.Green);
// var redMaterial = MaterialHelper.CreateMaterial(Colors.Red);
// var blueMaterial = MaterialHelper.CreateMaterial(Colors.Blue);
// var insideMaterial = MaterialHelper.CreateMaterial(Colors.Yellow);
// // Add 3 models to the group (using the same mesh, that's why we had to freeze it)
// modelGroup.Children.Add(new GeometryModel3D { Geometry = mesh, Material = greenMaterial, BackMaterial = insideMaterial });
//// modelGroup.Children.Add(new GeometryModel3D { Geometry = mesh, Transform = new TranslateTransform3D(-2, 0, 0), Material = redMaterial, BackMaterial = insideMaterial });
//// modelGroup.Children.Add(new GeometryModel3D { Geometry = mesh, Transform = new TranslateTransform3D(2, 0, 0), Material = blueMaterial, BackMaterial = insideMaterial });
// // Set the property, which will be bound to the Content property of the ModelVisual3D (see MainWindow.xaml)
this.Model = mg;
}
示例10: MoveTo
/// <summary>
/// Move the center of this point to here
/// </summary>
/// <param name="point"></param>
public void MoveTo(Point3D point) {
Center = point;
GeometryModel3D g = (GeometryModel3D)ModelVisual3D.Content;
MeshGeometry3D m = (MeshGeometry3D)g.Geometry;
MeshBuilder meshBuilder = new MeshBuilder();
meshBuilder.AddBox(Center, Radius, Radius, Radius);
m.Positions = meshBuilder.Positions;
}
示例11: LineSegment
public LineSegment(Point3D startPoint, Point3D endPoint)
{
StartPoint = startPoint;
EndPoint = endPoint;
var meshBuilder = new MeshBuilder(false, false);
meshBuilder.AddCylinder(startPoint, endPoint, 0.2, 10);
Model = meshBuilder.ToMesh();
}
示例12: DemoElement3D
public DemoElement3D()
{
var gm = new GeometryModel3D();
var mb = new MeshBuilder();
mb.AddSphere(new Point3D(0, 0, 0), 2, 100, 50);
gm.Geometry = mb.ToMesh();
gm.Material = Materials.Blue;
Visual3DModel = gm;
}
示例13: AddTube
void AddTube(List<Point3D> path, Color color)
{
var mb = new MeshBuilder();
mb.AddTube(path, 0.1, 3, false);
var geom = new GeometryModel3D { Geometry = mb.ToMesh(true), Material = MaterialHelper.CreateMaterial(color) }; // create a model
var model = new ModelVisual3D();
model.Content = geom;
_Helix.Children.Add(model);
}
示例14: AddGroup
public void AddGroup(List<int> selectedVertex)
{
MeshBuilder mesh = new MeshBuilder(false, false);
foreach (int index in selectedVertex)
mesh.AddSphere(this.Points[index], pointRaduis);
var mesh1 = mesh.ToMesh(true);
var redMaterial = MaterialHelper.CreateMaterial(Colors.Red);
var insideMaterial = MaterialHelper.CreateMaterial(Colors.Yellow);
// Add 3 models to the group (using the same mesh, that's why we had to freeze it)
mg.Children.Add(new GeometryModel3D { Geometry = mesh1, Material = redMaterial, BackMaterial = insideMaterial });
}
示例15: MainWindow
public MainWindow()
{
InitializeComponent();
var material = MaterialHelper.CreateMaterial(Colors.Aqua);
var builder = new MeshBuilder();
builder.AddTriangle(new Point3D(0, 0, 0), new Point3D(0, 10, 100), new Point3D(100, 0, 0));
var mesh = builder.ToMesh();
var geo = new GeometryModel3D { Geometry = mesh, Material = material , Transform = null};
var model = new ModelVisual3D { Content = geo, Transform = null };
_visual.Children.Add(model);
}