本文整理汇总了C#中MeshBuilder.AddBox方法的典型用法代码示例。如果您正苦于以下问题:C# MeshBuilder.AddBox方法的具体用法?C# MeshBuilder.AddBox怎么用?C# MeshBuilder.AddBox使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MeshBuilder
的用法示例。
在下文中一共展示了MeshBuilder.AddBox方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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 } };
}
示例3: CreatePoint
private void CreatePoint(ZonePoint zp,DisplayFlags flags)
{
Model3DGroup group = Model as Model3DGroup;
Model3DCollection collection = new Model3DCollection();
if (_mapping.ContainsKey(zp))
{
foreach (Model3D model in _mapping[zp])
{
group.Children.Remove(model);
}
}
double px, py, pz;
px = zp.X == 999999 ? 0 : zp.X;
py = zp.Y == 999999 ? 0 : zp.Y;
pz = zp.Z == 999999 ? 0 : zp.Z;
Point3D p = new Point3D(px,py,pz);
if (!Clipping.DrawPoint(p)) return;
MeshBuilder builder = new MeshBuilder();
builder.AddBox(p, 20, 20, 2);
//connect box to destination
px = zp.TargetX == 999999 ? px : zp.TargetX;
py = zp.TargetY == 999999 ? py : zp.TargetY;
pz = zp.TargetZ == 999999 ? pz : zp.TargetZ;
GeometryModel3D box;
box = new GeometryModel3D(builder.ToMesh(), Materials.Red);
collection.Add(box);
builder = new MeshBuilder();
Point3D destP = new Point3D(px, py, pz);
builder.AddArrow(p, destP, 0.5);
builder.AddBox(destP, 20, 20, 2);
if (zp.X == 999999 || zp.Y == 999999 || zp.Z == 999999 ||
zp.TargetX == 999999 || zp.TargetY == 999999 || zp.TargetZ == 999999)
{
box = new GeometryModel3D(builder.ToMesh(), Materials.Gold);
}
else
{
box = new GeometryModel3D(builder.ToMesh(), Materials.White);
}
collection.Add(box);
if (flags != DisplayFlags.None)
{
builder = new MeshBuilder();
if (flags.HasFlag(DisplayFlags.DarkGrayAura))
{
builder.AddBox(p, 25,25, 1);
builder.AddBox(destP, 25, 25, 1);
box = new GeometryModel3D(builder.ToMesh(), Materials.DarkGray);
collection.Add(box);
}
else if (flags.HasFlag(DisplayFlags.GreenAura))
{
builder.AddBox(p, 25, 25, 1);
builder.AddBox(destP, 25, 25, 1);
box = new GeometryModel3D(builder.ToMesh(), Materials.Green);
collection.Add(box);
}
}
_mapping[zp] = collection;
foreach (Model3D model in collection)
{
group.Children.Add(model);
}
}
示例4: CreateSpawn
private void CreateSpawn(EQEmu.Spawns.Spawn2 spawn,DisplayFlags flags)
{
Model3DGroup group = Model as Model3DGroup;
Model3DCollection collection = new Model3DCollection();
if (_mapping.ContainsKey(spawn))
{
foreach (Model3D model in _mapping[spawn])
{
group.Children.Remove(model);
}
}
MeshBuilder builder = new MeshBuilder();
Point3D p = new Point3D(spawn.X,spawn.Y,spawn.Z);
if( !Clipping.DrawPoint(p) ) return;
builder.AddBox(p,2,2,2);
Transform3D headingRotate = new RotateTransform3D()
{
CenterX = p.X,
CenterY = p.Y,
CenterZ = p.Z,
Rotation = new AxisAngleRotation3D(
new Vector3D(0,0,-1),spawn.HeadingDegrees)
};
GeometryModel3D box;
Material mat = Materials.White;
if (flags == DisplayFlags.None)
{
if (spawn.RoamAreaId > 0)
{
mat = Materials.Red;
}
else if (spawn.GridId > 0)
{
mat = Materials.Yellow;
}
}
else if (flags == DisplayFlags.Green)
{
mat = Materials.Green;
}
else if (flags == DisplayFlags.DarkGray)
{
mat = Materials.DarkGray;
}
else if (flags == DisplayFlags.Rainbow)
{
mat = Materials.Rainbow;
}
else if (flags == DisplayFlags.Blue)
{
mat = Materials.Blue;
}
box = new GeometryModel3D(builder.ToMesh(), mat);
box.Transform = headingRotate;
collection.Add(box);
builder = new MeshBuilder();
float radius = 3.0f;
double hx = spawn.X + Math.Cos((spawn.HeadingDegrees - 90) / 180 * Math.PI) * radius;
double hy = spawn.Y + Math.Sin((spawn.HeadingDegrees + 90) / 180 * Math.PI) * radius;
builder.AddArrow(new Point3D(spawn.X, spawn.Y, spawn.Z), new Point3D(hx, hy, spawn.Z), 0.5, 1);
collection.Add(new GeometryModel3D(builder.ToMesh(), mat));
_mapping[spawn] = collection;
foreach (Model3D model in collection)
{
group.Children.Add(model);
}
}
示例5: GetDefaultGeometry
private static Geometry3D GetDefaultGeometry()
{
// The default geometry is a box
var mb = new MeshBuilder(false, false);
mb.AddBox(new Point3D(0, 0, 0.5), 0.8, 0.8, 1);
return mb.ToMesh();
}
示例6: CreateSpawn
private void CreateSpawn(GroundSpawn spawn,DisplayFlags flags)
{
Model3DGroup group = Model as Model3DGroup;
Model3DCollection collection = new Model3DCollection();
if (_mapping.ContainsKey(spawn))
{
foreach (Model3D model in _mapping[spawn])
{
group.Children.Remove(model);
}
}
Point3D p = new Point3D(
(spawn.MaxX + spawn.MinX) / 2,
(spawn.MaxY + spawn.MinY) / 2,
spawn.MaxZ);
if (!Clipping.DrawPoint(p)) return;
var xlen = spawn.MaxX - spawn.MinX;
var ylen = spawn.MaxY - spawn.MinY;
xlen = xlen <= 0 ? 4 : xlen;
ylen = ylen <= 0 ? 4 : ylen;
MeshBuilder builder = new MeshBuilder();
builder.AddBox(p, ylen, xlen, 2);
GeometryModel3D box = new GeometryModel3D(builder.ToMesh(), Materials.Gold);
collection.Add(box);
if ( flags != DisplayFlags.None )
{
var scale = 1.25;
builder = new MeshBuilder();
if (flags.HasFlag(DisplayFlags.DarkGrayAura))
{
builder.AddBox(p, ylen * scale, xlen * scale, 1);
box = new GeometryModel3D(builder.ToMesh(), Materials.DarkGray);
collection.Add(box);
}
else if (flags.HasFlag(DisplayFlags.GreenAura))
{
builder.AddBox(p, ylen * scale, xlen * scale, 1);
box = new GeometryModel3D(builder.ToMesh(), Materials.Green);
collection.Add(box);
}
}
_mapping[spawn] = collection;
foreach (Model3D model in collection)
{
group.Children.Add(model);
}
}
示例7: 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;
}
示例8: MeshBuild
private void MeshBuild()
{
//build the box for the nodes
MeshBuilder builder = new MeshBuilder();
builder.AddBox(new Point3D(0, 0, 0), 2, 2, 2);
_nodeModel = new GeometryModel3D(builder.ToMesh(), Materials.Green);
}
示例9: 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();
}
示例10: CreateArea
private void CreateArea(LineOfSightArea area)
{
Model3DGroup group = Model as Model3DGroup;
Model3DCollection collection = new Model3DCollection();
try
{
if (_mapping[area] != null)
{
foreach (Model3D model in _mapping[area])
{
group.Children.Remove(model);
}
}
}
catch (KeyNotFoundException)
{
//nothing needs to be done
}
foreach (var vertex in area.Vertices)
{
MeshBuilder builder = new MeshBuilder();
Point3D p1 = new Point3D(vertex.X, vertex.Y, area.MaxZ);
Point3D p2 = new Point3D(vertex.X, vertex.Y, area.MinZ);
//if (Clipping != null && !Clipping.DrawPoint(p)) continue;
builder.AddBox(p1, 4, 4, 4);
builder.AddBox(p2, 4, 4, 4);
builder.AddPipe(p1, p2, 1.5, 1.5, 50);
GeometryModel3D box = new GeometryModel3D(builder.ToMesh(), Materials.Yellow);
collection.Add(box);
builder = new MeshBuilder();
Point3D next;
if (vertex == area.Vertices.Last())
{
next = area.Vertices[0];
}
else
{
next = area.Vertices.ElementAt(area.Vertices.IndexOf(vertex) + 1);
}
Point3D n1 = new Point3D(next.X, next.Y, area.MaxZ);
Point3D n2 = new Point3D(next.X, next.Y, area.MinZ);
//builder.AddPipe(p1, p2);
builder.AddPipe(p1, n1, 0.5, 0.5, 50);
builder.AddPipe(p2, n2, 0.5, 0.5, 50);
collection.Add(new GeometryModel3D(builder.ToMesh(), Materials.Yellow));
}
_mapping[area] = collection;
foreach (Model3D model in collection)
{
group.Children.Add(model);
}
}
示例11: CreateGrid
private void CreateGrid(Grid grid)
{
Model3DGroup group = Model as Model3DGroup;
Model3DCollection collection = new Model3DCollection();
if (_mapping.ContainsKey(grid))
{
foreach (Model3D model in _mapping[grid])
{
group.Children.Remove(model);
}
}
foreach (Waypoint wp in grid.Waypoints)
{
MeshBuilder builder = new MeshBuilder();
Point3D p = new Point3D(wp.X,wp.Y,wp.Z);
if (Clipping != null && !Clipping.DrawPoint(p)) continue;
builder.AddBox(p, 2, 2, 2);
Transform3D headingRotate = new RotateTransform3D()
{
CenterX = wp.X,
CenterY = wp.Y,
CenterZ = wp.Z,
Rotation = new AxisAngleRotation3D(
new Vector3D(0, 0, -1), wp.HeadingDegrees)
};
GeometryModel3D box;
Material mat;
if (wp.PauseTime > 0)
{
mat = Materials.Red;
}
else
{
mat = Materials.DarkGray;
}
box = new GeometryModel3D(builder.ToMesh(),mat);
box.Transform = headingRotate;
collection.Add(box);
builder = new MeshBuilder();
float radius = 3.0f;
double hx = wp.X + Math.Cos( (wp.HeadingDegrees-90) / 180 * Math.PI ) * radius;
double hy = wp.Y + Math.Sin( (wp.HeadingDegrees + 90) / 180 * Math.PI ) * radius;
builder.AddArrow(new Point3D(wp.X, wp.Y, wp.Z),new Point3D(hx, hy, wp.Z), 0.5,1);
collection.Add(new GeometryModel3D(builder.ToMesh(), mat));
//box = new GeometryModel3D(builder.ToMesh(), mat);
//collection.Add(box);
if(wp.Name != null && !String.IsNullOrWhiteSpace(wp.Name) )
{
GeometryModel3D text = TextCreator.CreateTextLabelModel3D(wp.Name, BrushHelper.CreateGrayBrush(50), true, 2, new Point3D(p.X, p.Y, p.Z + 5), new Vector3D(1, 0, 0), new Vector3D(0, 0, 1));
text.Transform = new ScaleTransform3D(new Vector3D(-1, 1, 1), new Point3D(p.X, p.Y, p.Z));
collection.Add(text);
}
//GeometryModel3D text = TextCreator.CreateTextLabelModel3D(wp.GridId.ToString() + "G:" + wp.Number.ToString() + "N:" + wp.PauseTime.ToString() + "P", BrushHelper.CreateGrayBrush(5), true, 2,
// new Point3D(p.X, p.Y, p.Z + 5), new Vector3D(1, 0, 0), new Vector3D(0, 0, 1));
//text.Transform = new ScaleTransform3D(new Vector3D(-1, 1, 1), new Point3D(p.X, p.Y, p.Z));
//collection.Add(text);
builder = new MeshBuilder();
if (grid.WanderType == Grid.WanderTypes.Patrol || grid.WanderType == Grid.WanderTypes.Circular)
{
IEnumerable<Waypoint> nextWaypointQuery = grid.Waypoints.Where(
x => x.Number > wp.Number).OrderBy(y => y.Number);
if (nextWaypointQuery.Count() > 0)
{
Waypoint nextWaypoint = nextWaypointQuery.ElementAt(0);
builder.AddArrow(p, new Point3D(nextWaypoint.X, nextWaypoint.Y, nextWaypoint.Z), 0.5);
collection.Add(
new GeometryModel3D(builder.ToMesh(), Materials.White));
}
}
//collection.Add( new GeometryModel3D(builder.ToMesh(), Materials.
}
//collection.Add(new GeometryModel3D(builder.ToMesh(), Materials.White));
_mapping[grid] = collection;
foreach (Model3D model in collection)
{
group.Children.Add(model);
}
}
示例12: CreateArea
private void CreateArea(RoamArea area)
{
Model3DGroup group = Model as Model3DGroup;
Model3DCollection collection = new Model3DCollection();
if (_mapping.ContainsKey(area))
{
foreach (Model3D model in _mapping[area])
{
group.Children.Remove(model);
}
}
foreach (var vertex in area.Vertices)
{
MeshBuilder builder = new MeshBuilder();
Point3D p1 = new Point3D(vertex.X, vertex.Y, area.MaxZ);
Point3D p2 = new Point3D(vertex.X, vertex.Y, area.MinZ);
//if (Clipping != null && !Clipping.DrawPoint(p)) continue;
builder.AddBox(p1, 4, 4, 4);
builder.AddBox(p2, 4, 4, 4);
builder.AddPipe(p1, p2, 1.5, 1.5, 50);
GeometryModel3D box = new GeometryModel3D(builder.ToMesh(), Materials.Yellow);
collection.Add(box);
builder = new MeshBuilder();
Point3D next = new Point3D();
if (vertex == area.Vertices.Last())
{
next.X = area.Vertices[0].X;
next.Y = area.Vertices[0].Y;
}
else
{
next.X = area.Vertices.ElementAt(area.Vertices.IndexOf(vertex) + 1).X;
next.Y = area.Vertices.ElementAt(area.Vertices.IndexOf(vertex) + 1).Y;
}
Point3D n1 = new Point3D(next.X, next.Y, area.MaxZ);
Point3D n2 = new Point3D(next.X, next.Y, area.MinZ);
//builder.AddPipe(p1, p2);
builder.AddPipe(p1, n1, 0.5, 0.5, 50);
builder.AddPipe(p2, n2, 0.5, 0.5, 50);
collection.Add(new GeometryModel3D(builder.ToMesh(), Materials.Yellow));
}
_mapping[area] = collection;
foreach (Model3D model in collection)
{
group.Children.Add(model);
}
}
示例13: UpdateAll
public void UpdateAll()
{
Model3DGroup group = Model as Model3DGroup;
Material mat = Materials.Red;
BuildDoors();
group.Children.Clear();
if (_doorObjects != null)
{
foreach (var dr in _doorObjects)
{
var builder = new MeshBuilder();
var transforms = dr.GetTransforms();
if (dr.Polygons.ElementAt(0).BitmapInfo != null)
{
var img = dr.Polygons.ElementAt(0).BitmapInfo.Image;
var brush = new System.Windows.Media.ImageBrush(img);
brush.ViewportUnits = System.Windows.Media.BrushMappingMode.Absolute;
brush.TileMode = System.Windows.Media.TileMode.Tile;
mat = HelixToolkit.Wpf.MaterialHelper.CreateMaterial(brush);
}
else
{
mat = Materials.LightGray;
}
foreach (var poly in dr.Polygons)
{
Point3D p1 = new Point3D(poly.V1.X, poly.V1.Y, poly.V1.Z);
Point3D p2 = new Point3D(poly.V2.X, poly.V2.Y, poly.V2.Z);
Point3D p3 = new Point3D(poly.V3.X, poly.V3.Y, poly.V3.Z);
foreach (var transform in transforms)
{
p1 = transform.Transform(p1);
p2 = transform.Transform(p2);
p3 = transform.Transform(p3);
}
if (!Clipping.DrawPoint(p1) || !Clipping.DrawPoint(p2) || !Clipping.DrawPoint(p3))
{
continue;
}
var t1 = new System.Windows.Point(poly.V1.U, 1 - poly.V1.V);
var t2 = new System.Windows.Point(poly.V2.U, 1 - poly.V2.V);
var t3 = new System.Windows.Point(poly.V3.U, 1 - poly.V3.V);
//builder.AddTriangle(p3, p2, p1, t3, t2, t1);
builder.AddTriangle(p1, p2, p3, t1, t2, t3);
}
group.Children.Add(new GeometryModel3D(builder.ToMesh(), mat));
}
}
var rotate = new RotateTransform3D();
rotate.Rotation = new AxisAngleRotation3D(new Vector3D(0, 0, 1), 90);
foreach (var door in _manager.Doors)
{
var bbuilder = new MeshBuilder();
Material mater = Materials.Red;
if (_selected != null && _selected.Contains(door))
{
mater = Materials.Blue;
}
var pcenter = new Point3D(door.X, door.Y, door.Z);
rotate.CenterX = pcenter.X;
rotate.CenterY = pcenter.Y;
float radius = 3.0f;
double hx = pcenter.X + Math.Cos((door.HeadingDegrees - 90) / 180 * Math.PI) * radius;
double hy = pcenter.Y + Math.Sin((door.HeadingDegrees + 90) / 180 * Math.PI) * radius;
var p = rotate.Transform(new Point3D(hx, hy, door.Z));
//bbuilder.AddArrow(pcenter, new Point3D(hx, hy, door.Z), 0.5, 1);
bbuilder.AddArrow(pcenter,p, 0.5, 1);
bbuilder.AddBox(pcenter, 0.5, 0.5, 20);
group.Children.Add(new GeometryModel3D(bbuilder.ToMesh(), mater));
}
}