本文整理汇总了C#中HelixToolkit.Wpf.MeshBuilder.AddBox方法的典型用法代码示例。如果您正苦于以下问题:C# MeshBuilder.AddBox方法的具体用法?C# MeshBuilder.AddBox怎么用?C# MeshBuilder.AddBox使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HelixToolkit.Wpf.MeshBuilder
的用法示例。
在下文中一共展示了MeshBuilder.AddBox方法的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: 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)
this.Model = modelGroup;
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: Cube
public Cube(Point3D center, double radius, Action action) {
Center = center;
Radius = radius;
Action = action;
Notified = false;
SolidColorBrush = new SolidColorBrush();
SolidColorBrush.Opacity = _Constants.BaseOpacity;
SolidColorBrush.Color = _Constants.DefaultCubeColour;
Material = new DiffuseMaterial(SolidColorBrush);
MeshBuilder meshBuilder = new MeshBuilder();
meshBuilder.AddBox(center, radius, radius, radius);
ModelVisual3D = Engine._3DUtil.WrapMeshAndMaterialIntoModelVisual3D(meshBuilder.ToMesh(), Material);
}
示例7: CreateDice
private ModelVisual3D CreateDice()
{
var diceMesh = new MeshBuilder();
diceMesh.AddBox(new Point3D(0, 0, 0), 1, 1, 1);
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
for (int k = 0; k < 2; k++)
{
var points = new List<Point3D>();
diceMesh.ChamferCorner(new Point3D(i - 0.5, j - 0.5, k - 0.5), 0.1, 1e-6, points);
//foreach (var p in points)
// b.ChamferCorner(p, 0.03);
}
return new ModelVisual3D { Content = new GeometryModel3D { Geometry = diceMesh.ToMesh(), Material = Materials.White } };
}
示例8: Tessellate
protected override MeshGeometry3D Tessellate()
{
double width = Columns*grid - margin*2;
double length = Rows*grid - margin*2;
double height = Height*plateThickness;
var builder = new MeshBuilder(true, true);
for (int i = 0; i < Columns; i++)
for (int j = 0; j < Rows; j++)
{
var o = new Point3D((i + 0.5)*grid, (j + 0.5)*grid, height);
builder.AddCone(o, new Vector3D(0, 0, 1), knobDiameter/2, knobDiameter/2, knobHeight, false, true,
Divisions);
builder.AddPipe(new Point3D(o.X, o.Y, o.Z - wallThickness), new Point3D(o.X, o.Y, wallThickness),
knobDiameter, outerDiameter, Divisions);
}
builder.AddBox(new Point3D(Columns * 0.5 * grid, Rows * 0.5 * grid, height - wallThickness / 2), width, length,
wallThickness,
MeshBuilder.BoxFaces.All);
builder.AddBox(new Point3D(margin + wallThickness / 2, Rows * 0.5 * grid, height / 2 - wallThickness / 2),
wallThickness, length, height - wallThickness,
MeshBuilder.BoxFaces.All ^ MeshBuilder.BoxFaces.Top);
builder.AddBox(
new Point3D(Columns * grid - margin - wallThickness / 2, Rows * 0.5 * grid, height / 2 - wallThickness / 2),
wallThickness, length, height - wallThickness,
MeshBuilder.BoxFaces.All ^ MeshBuilder.BoxFaces.Top);
builder.AddBox(new Point3D(Columns * 0.5 * grid, margin + wallThickness / 2, height / 2 - wallThickness / 2),
width, wallThickness, height - wallThickness,
MeshBuilder.BoxFaces.All ^ MeshBuilder.BoxFaces.Top);
builder.AddBox(
new Point3D(Columns * 0.5 * grid, Rows * grid - margin - wallThickness / 2, height / 2 - wallThickness / 2),
width, wallThickness, height - wallThickness,
MeshBuilder.BoxFaces.All ^ MeshBuilder.BoxFaces.Top);
return builder.ToMesh();
}
示例9: AppearanceChanged
private void AppearanceChanged()
{
var y0 = 0d;
var wallBuilder = new MeshBuilder(false, false);
for (int i = 0; i < this.Stories; i++)
{
if (i > 0 && this.FloorThickness > 0)
{
wallBuilder.AddBox(new Point3D(0, 0, y0 + this.FloorThickness / 2), this.Length + 0.2, this.Width + 0.2, this.FloorThickness);
y0 += this.FloorThickness;
}
wallBuilder.AddBox(new Point3D(0, 0, y0 + this.StoryHeight / 2), this.Length, this.Width, this.StoryHeight);
y0 += this.StoryHeight;
}
var theta = Math.PI / 180 * this.RoofAngle;
var roofBuilder = new MeshBuilder(false, false);
var y1 = y0 + Math.Tan(theta) * this.Width / 2;
var p0 = new Point(0, y1);
var p1 = new Point(this.Width / 2 + 0.2 * Math.Cos(theta), y0 - 0.2 * Math.Sin(theta));
var p2 = new Point(p1.X + this.RoofThickness * Math.Sin(theta), p1.Y + this.RoofThickness * Math.Cos(theta));
var p3 = new Point(0, y1 + this.RoofThickness / Math.Cos(theta));
var p4 = new Point(-p2.X, p2.Y);
var p5 = new Point(-p1.X, p1.Y);
var roofSection = new[] { p0, p1, p1, p2, p2, p3, p3, p4, p4, p5, p5, p0 };
roofBuilder.AddExtrudedSegments(roofSection, new Vector3D(0, -1, 0), new Point3D(-this.Length / 2, 0, 0), new Point3D(this.Length / 2, 0, 0));
var cap = new[] { p0, p1, p2, p3, p4, p5 };
roofBuilder.AddPolygon(cap, new Vector3D(0, -1, 0), new Vector3D(0, 0, 1), new Point3D(-this.Length / 2, 0, 0));
roofBuilder.AddPolygon(cap, new Vector3D(0, 1, 0), new Vector3D(0, 0, 1), new Point3D(this.Length / 2, 0, 0));
var p6 = new Point(this.Width / 2, y0);
var p7 = new Point(-this.Width / 2, y0);
wallBuilder.AddPolygon(new[] { p0, p6, p7 }, new Vector3D(0, -1, 0), new Vector3D(0, 0, 1), new Point3D(-this.Length / 2, 0, 0));
wallBuilder.AddPolygon(new[] { p0, p6, p7 }, new Vector3D(0, 1, 0), new Vector3D(0, 0, 1), new Point3D(this.Length / 2, 0, 0));
this.walls.Geometry = wallBuilder.ToMesh(true);
this.roof.Geometry = roofBuilder.ToMesh(true);
}
示例10: GetHighlightModel3D
private Model3DGroup GetHighlightModel3D(Gesture g, List<GestureFrame> fs)
{
// Create material
EmissiveMaterial material = new EmissiveMaterial(new SolidColorBrush() { Color = Colors.White, Opacity = 0.3 });
Model3DGroup modelGroup = new Model3DGroup();
foreach (GestureFrame f in fs)
{
foreach (GestureFrameCell fc in f.FrontCells.Where(fc => fc.IsHotspot == true))
{
int fcIndex = Array.IndexOf(f.FrontCells, fc);
foreach (GestureFrameCell sc in f.SideCells.Where(
sc => sc.IsHotspot == true && (int)(Array.IndexOf(f.SideCells, sc) / 20) == (int)(fcIndex / 20)))
{
// Init mesh
MeshBuilder meshBuilder = new MeshBuilder(false, false);
// Make cube and add to mesh
double y = (fc.LeftCM + fc.RightCM) / 2;
double z = (fc.TopCM + fc.BottomCM) / 2;
double x = (sc.LeftCM + sc.RightCM) / 2;
Point3D cubeCenter = new Point3D(x, y, z);
meshBuilder.AddBox(cubeCenter, 15, 15, 15);
// Create and freeze mesh
var mesh = meshBuilder.ToMesh(true);
// Create models
modelGroup.Children.Add(new GeometryModel3D(mesh, material));
}
}
}
return modelGroup;
}
示例11: CreateMazeGeometry
/// <summary>
/// Creates the maze geometry.
/// </summary>
/// <param name="themaze">
/// The maze.
/// </param>
/// <param name="height">
/// The height of the blocks.
/// </param>
/// <param name="size">
/// The size of the blocks.
/// </param>
/// <returns>
/// The geometry.
/// </returns>
private MeshGeometry3D CreateMazeGeometry(bool[,] themaze, double height = 2, double size = 0.995)
{
var builder = new MeshBuilder();
int m = themaze.GetUpperBound(0) + 1;
int n = themaze.GetUpperBound(1) + 1;
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
if (themaze[i, j])
{
builder.AddBox(this.GetPosition(i, j, height * 0.5), size, size, height);
}
}
}
return builder.ToMesh();
}
示例12: CreateBox
public void CreateBox(Point3D location, double xLen, double yLen, double zLen, string textureUri)
{
var geometryModel = new GeometryModel3D();
var meshBuilder = new MeshBuilder();
meshBuilder.AddBox(location, xLen, yLen, zLen);
geometryModel.Geometry = meshBuilder.ToMesh();
geometryModel.Material = MaterialHelper.CreateImageMaterial(textureUri);
Visual3DModel = geometryModel;
Initializer();
}
示例13: SyncEditorGrids_3D
/// <summary>
/// Sync 3D Viewport with grids
/// </summary>
private void SyncEditorGrids_3D(Gesture g) //TODO: split into smaller methods
{
// Init 3D stuff
Model3DGroup modelGroup = new Model3DGroup();
foreach (GestureFrame f in g.Frames)
{
// Create material
SolidColorBrush materialBrush = new SolidColorBrush()
{
Color = Colors.DarkSlateBlue,
Opacity = 0.1 + ((double)(g.Frames.IndexOf(f) + 1) / (double)g.Frames.Count) * 0.8
};
DiffuseMaterial material = new DiffuseMaterial(materialBrush);
foreach (GestureFrameCell fc in f.FrontCells.Where(fc => fc.IsHotspot == true))
{
int fcIndex = Array.IndexOf(f.FrontCells, fc);
foreach (GestureFrameCell sc in f.SideCells.Where(
sc => sc.IsHotspot == true && (int)(Array.IndexOf(f.SideCells, sc) / 20) == (int)(fcIndex / 20)))
{
// Init mesh
MeshBuilder meshBuilder = new MeshBuilder(false, false);
// Make cube and add to mesh
double y = (fc.LeftCM + fc.RightCM) / 2;
double z = (fc.TopCM + fc.BottomCM) / 2;
double x = (sc.LeftCM + sc.RightCM) / 2;
Point3D cubeCenter = new Point3D(x, y, z);
meshBuilder.AddBox(cubeCenter, 15, 15, 15);
// Create and freeze mesh
var mesh = meshBuilder.ToMesh(true);
// Create model
modelGroup.Children.Add(new GeometryModel3D(mesh, material));
}
}
}
// Suggest other gestures too
foreach (Gesture gg in GestureCollection)
{
foreach (GestureFrame f in gg.Frames)
{
// Create material
SolidColorBrush materialBrush = new SolidColorBrush()
{
Color = Visualizer_GestureColors[GestureCollection.IndexOf(gg) % Visualizer_GestureColors.Length].Color,
Opacity = ((double)(gg.Frames.IndexOf(f) + 1) / (double)gg.Frames.Count) * 0.09
};
DiffuseMaterial material = new DiffuseMaterial(materialBrush);
foreach (GestureFrameCell fc in f.FrontCells.Where(fc => fc.IsHotspot == true))
{
int fcIndex = Array.IndexOf(f.FrontCells, fc);
foreach (GestureFrameCell sc in f.SideCells.Where(
sc => sc.IsHotspot == true && (int)(Array.IndexOf(f.SideCells, sc) / 20) == (int)(fcIndex / 20)))
{
// Init mesh
MeshBuilder meshBuilder = new MeshBuilder(false, false);
// Make cube and add to mesh
double y = (fc.LeftCM + fc.RightCM) / 2;
double z = (fc.TopCM + fc.BottomCM) / 2;
double x = (sc.LeftCM + sc.RightCM) / 2;
Point3D cubeCenter = new Point3D(x, y, z);
meshBuilder.AddBox(cubeCenter, 15, 15, 15);
// Create and freeze mesh
var mesh = meshBuilder.ToMesh(true);
// Create model
modelGroup.Children.Add(new GeometryModel3D(mesh, material));
}
}
}
}
HotspotCellsModelVisual3D_Editor.Content = modelGroup;
}
示例14: Worker3
private void Worker3(object d)
{
var dispatcher = (Dispatcher)d;
var m = MaterialHelper.CreateMaterial(Colors.Green);
Interlocked.Increment(ref this.runningWorkers);
while (!this.source.IsCancellationRequested)
{
if (!this.AddFrozenModel || this.runningWorkers < 4)
{
Thread.Yield();
continue;
}
for (int i = 1; i <= n; i++)
{
var b = new MeshBuilder();
for (int j = 1; j <= n; j++)
{
for (int k = 1; k <= n; k++)
{
b.AddBox(new Point3D(i, j, -k), 0.8, 0.8, 0.8);
}
}
var box = new GeometryModel3D { Geometry = b.ToMesh(false), Material = m };
box.Freeze();
dispatcher.Invoke(new Action<Model3D, ModelVisual3D>(this.Add), box, this.model3);
}
dispatcher.Invoke((Action)(() => this.Count3++));
dispatcher.Invoke(new Action<ModelVisual3D>(this.Clear), model3);
}
}
示例15: CreateVoxelModel3D
private static GeometryModel3D CreateVoxelModel3D(Voxel v)
{
const double size = 0.98;
var m = new GeometryModel3D();
var mb = new MeshBuilder();
mb.AddBox(new Point3D(0, 0, 0), size, size, size);
m.Geometry = mb.ToMesh();
m.Material = MaterialHelper.CreateMaterial(v.Colour);
m.Transform = new TranslateTransform3D(v.Position.X, v.Position.Y, v.Position.Z);
return m;
}