本文整理汇总了C#中Sledge.DataStructures.MapObjects.IDGenerator.GetNextFaceID方法的典型用法代码示例。如果您正苦于以下问题:C# IDGenerator.GetNextFaceID方法的具体用法?C# IDGenerator.GetNextFaceID怎么用?C# IDGenerator.GetNextFaceID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sledge.DataStructures.MapObjects.IDGenerator
的用法示例。
在下文中一共展示了IDGenerator.GetNextFaceID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public IEnumerable<MapObject> Create(IDGenerator generator, Box box, ITexture texture, int roundDecimals)
{
var solid = new Solid(generator.GetNextObjectID()) { Colour = Colour.GetRandomBrushColour() };
// The higher Z plane will be triangle, with the lower X value getting the two corners
var c1 = new Coordinate(box.Start.X, box.Start.Y, box.End.Z).Round(roundDecimals);
var c2 = new Coordinate(box.End.X, box.Start.Y, box.End.Z).Round(roundDecimals);
var c3 = new Coordinate(box.Center.X, box.End.Y, box.End.Z).Round(roundDecimals);
var c4 = new Coordinate(box.Center.X, box.Center.Y, box.Start.Z).Round(roundDecimals);
var faces = new[]
{
new[] { c3, c2, c1 },
new[] { c3, c1, c4 },
new[] { c2, c3, c4 },
new[] { c1, c2, c4 }
};
foreach (var arr in faces)
{
var face = new Face(generator.GetNextFaceID())
{
Parent = solid,
Plane = new Plane(arr[0], arr[1], arr[2]),
Colour = solid.Colour,
Texture = { Texture = texture }
};
face.Vertices.AddRange(arr.Select(x => new Vertex(x, face)));
face.UpdateBoundingBox();
face.AlignTextureToFace();
solid.Faces.Add(face);
}
solid.UpdateBoundingBox();
yield return solid;
}
示例2: Create
public IEnumerable<MapObject> Create(IDGenerator generator, Box box, ITexture texture)
{
var solid = new Solid(generator.GetNextObjectID()) { Colour = Colour.GetRandomBrushColour() };
// The lower Z plane will be base, the x planes will be triangles
var c1 = new Coordinate(box.Start.X, box.Start.Y, box.Start.Z);
var c2 = new Coordinate(box.End.X, box.Start.Y, box.Start.Z);
var c3 = new Coordinate(box.End.X, box.End.Y, box.Start.Z);
var c4 = new Coordinate(box.Start.X, box.End.Y, box.Start.Z);
var c5 = new Coordinate(box.Center.X, box.Start.Y, box.End.Z);
var c6 = new Coordinate(box.Center.X, box.End.Y, box.End.Z);
var faces = new[]
{
new[] { c1, c2, c3, c4 },
new[] { c2, c1, c5 },
new[] { c5, c6, c3, c2 },
new[] { c4, c3, c6 },
new[] { c6, c5, c1, c4 }
};
foreach (var arr in faces)
{
var face = new Face(generator.GetNextFaceID())
{
Parent = solid,
Plane = new Plane(arr[0], arr[1], arr[2]),
Colour = solid.Colour,
Texture = { Texture = texture }
};
face.Vertices.AddRange(arr.Select(x => new Vertex(x, face)));
face.UpdateBoundingBox();
face.AlignTextureToFace();
solid.Faces.Add(face);
}
solid.UpdateBoundingBox();
yield return solid;
}
示例3: CreateFromIntersectingPlanes
public static Solid CreateFromIntersectingPlanes(IEnumerable<Plane> planes, IDGenerator generator)
{
var solid = new Solid(generator.GetNextObjectID());
var list = planes.ToList();
for (var i = 0; i < list.Count; i++)
{
// Split the polygon by all the other planes
var poly = new Polygon(list[i]);
for (var j = 0; j < list.Count; j++)
{
if (i != j) poly.Split(list[j]);
}
// The final polygon is the face
var face = new Face(generator.GetNextFaceID()) { Plane = poly.Plane , Parent = solid };
face.Vertices.AddRange(poly.Vertices.Select(x => new Vertex(x, face)));
face.UpdateBoundingBox();
face.AlignTextureToWorld();
solid.Faces.Add(face);
}
// Ensure all the faces point outwards
var origin = solid.GetOrigin();
foreach (var face in solid.Faces)
{
if (face.Plane.OnPlane(origin) >= 0) face.Flip();
}
solid.UpdateBoundingBox();
return solid;
}
示例4: Create
public IEnumerable<MapObject> Create(IDGenerator generator, Box box, ITexture texture, int roundDecimals)
{
var numsides = (int) _numSides.GetValue();
if (numsides < 3) yield break;
// Cylinders can be elliptical so use both major and minor rather than just the radius
// NOTE: when a low number (< 10ish) of faces are selected this will cause the cylinder to not touch all the edges of the box.
var width = box.Width;
var length = box.Length;
var height = box.Height;
var major = width / 2;
var minor = length / 2;
var angle = 2 * DMath.PI / numsides;
// Calculate the X and Y points for the ellipse
var points = new Coordinate[numsides];
for (var i = 0; i < numsides; i++)
{
var a = i * angle;
var xval = box.Center.X + major * DMath.Cos(a);
var yval = box.Center.Y + minor * DMath.Sin(a);
var zval = box.Start.Z;
points[i] = new Coordinate(xval, yval, zval).Round(roundDecimals);
}
var faces = new List<Coordinate[]>();
// Add the vertical faces
var z = new Coordinate(0, 0, height).Round(roundDecimals);
for (var i = 0; i < numsides; i++)
{
var next = (i + 1) % numsides;
faces.Add(new[] {points[i], points[i] + z, points[next] + z, points[next]});
}
// Add the elliptical top and bottom faces
faces.Add(points.ToArray());
faces.Add(points.Select(x => x + z).Reverse().ToArray());
// Nothing new here, move along
var solid = new Solid(generator.GetNextObjectID()) { Colour = Colour.GetRandomBrushColour() };
foreach (var arr in faces)
{
var face = new Face(generator.GetNextFaceID())
{
Parent = solid,
Plane = new Plane(arr[0], arr[1], arr[2]),
Colour = solid.Colour,
Texture = { Texture = texture }
};
face.Vertices.AddRange(arr.Select(x => new Vertex(x, face)));
face.UpdateBoundingBox();
face.AlignTextureToFace();
solid.Faces.Add(face);
}
solid.UpdateBoundingBox();
yield return solid;
}
示例5: Create
public IEnumerable<MapObject> Create(IDGenerator generator, Box box, ITexture texture)
{
var numsides = (int) _numSides.GetValue();
if (numsides < 3) yield break;
// This is all very similar to the cylinder brush.
var width = box.Width;
var length = box.Length;
var major = width / 2;
var minor = length / 2;
var angle = 2 * DMath.PI / numsides;
var points = new Coordinate[numsides];
for (var i = 0; i < numsides; i++)
{
var a = i * angle;
var xval = box.Center.X + major * DMath.Cos(a);
var yval = box.Center.Y + minor * DMath.Sin(a);
var zval = box.Start.Z;
points[i] = new Coordinate(xval, yval, zval).Round(0);
}
var faces = new List<Coordinate[]>();
var point = new Coordinate(box.Center.X, box.Center.Y, box.End.Z);
for (var i = 0; i < numsides; i++)
{
var next = (i + 1) % numsides;
faces.Add(new[] {points[i], point, points[next]});
}
faces.Add(points.ToArray());
var solid = new Solid(generator.GetNextObjectID()) { Colour = Colour.GetRandomBrushColour() };
foreach (var arr in faces)
{
var face = new Face(generator.GetNextFaceID())
{
Parent = solid,
Plane = new Plane(arr[0], arr[1], arr[2]),
Colour = solid.Colour,
Texture = { Texture = texture }
};
face.Vertices.AddRange(arr.Select(x => new Vertex(x, face)));
face.UpdateBoundingBox();
face.AlignTextureToFace();
solid.Faces.Add(face);
}
solid.UpdateBoundingBox();
yield return solid;
}
示例6: Create
public IEnumerable<MapObject> Create(IDGenerator generator, Box box, ITexture texture, int roundDecimals)
{
var solid = new Solid(generator.GetNextObjectID()) { Colour = Colour.GetRandomBrushColour() };
foreach (var arr in box.GetBoxFaces())
{
var face = new Face(generator.GetNextFaceID())
{
Parent = solid,
Plane = new Plane(arr[0], arr[1], arr[2]),
Colour = solid.Colour,
Texture = { Texture = texture }
};
face.Vertices.AddRange(arr.Select(x => new Vertex(x.Round(roundDecimals), face)));
face.UpdateBoundingBox();
face.AlignTextureToFace();
solid.Faces.Add(face);
}
solid.UpdateBoundingBox();
yield return solid;
}
示例7: BenchmarkSolidConstruction
public void BenchmarkSolidConstruction()
{
var idg = new IDGenerator();
var box = new Box(Coordinate.One * -100, Coordinate.One * 100);
var planes = new CylinderBrush().Create(idg, box, null, 2).OfType<Solid>().SelectMany(x => x.Faces).Select(x => x.Plane).ToList();
var stopwatch = new Stopwatch();
stopwatch.Start();
for (var b = 0; b < 1000; b++)
{
Solid.CreateFromIntersectingPlanes(planes, idg);
}
stopwatch.Stop();
Debug.WriteLine(stopwatch.Elapsed);
stopwatch.Restart();
for (var b = 0; b < 1000; b++)
{
var polys = new List<Polygon>();
for (var i = 0; i < planes.Count; i++)
{
var poly = new Polygon(planes[i]);
for (var j = 0; j < planes.Count; j++)
{
if (i != j) poly.Split(planes[j]);
}
polys.Add(poly);
}
var solid = new Solid(idg.GetNextObjectID());
foreach (var polygon in polys)
{
var face = new Face(idg.GetNextFaceID()) {Plane = polygon.Plane};
face.Vertices.AddRange(polygon.Vertices.Select(x => new Vertex(x, face)));
face.UpdateBoundingBox();
face.AlignTextureToWorld();
solid.Faces.Add(face);
}
solid.UpdateBoundingBox();
}
stopwatch.Stop();
Debug.WriteLine(stopwatch.Elapsed);
}
示例8: ReadFace
private Face ReadFace(string line, IDGenerator generator)
{
const NumberStyles ns = NumberStyles.Float;
var parts = line.Split(' ').Where(x => !String.IsNullOrWhiteSpace(x)).ToArray();
Assert(parts[0] == "(");
Assert(parts[4] == ")");
Assert(parts[5] == "(");
Assert(parts[9] == ")");
Assert(parts[10] == "(");
Assert(parts[14] == ")");
Assert(parts[16] == "[");
Assert(parts[21] == "]");
Assert(parts[22] == "[");
Assert(parts[27] == "]");
return new Face(generator.GetNextFaceID())
{
Plane = new Plane(Coordinate.Parse(parts[1], parts[2], parts[3]),
Coordinate.Parse(parts[6], parts[7], parts[8]),
Coordinate.Parse(parts[11], parts[12], parts[13])),
Texture =
{
Name = parts[15],
UAxis = Coordinate.Parse(parts[17], parts[18], parts[19]),
XShift = decimal.Parse(parts[20], ns,CultureInfo.InvariantCulture),
VAxis = Coordinate.Parse(parts[23], parts[24], parts[25]),
YShift = decimal.Parse(parts[26], ns, CultureInfo.InvariantCulture),
Rotation = decimal.Parse(parts[28], ns, CultureInfo.InvariantCulture),
XScale = decimal.Parse(parts[29], ns, CultureInfo.InvariantCulture),
YScale = decimal.Parse(parts[30], ns, CultureInfo.InvariantCulture)
}
};
}
示例9: MakeSolid
private Solid MakeSolid(IDGenerator generator, IEnumerable<Coordinate[]> faces, ITexture texture, Color col)
{
var solid = new Solid(generator.GetNextObjectID()) { Colour = col };
foreach (var arr in faces)
{
var face = new Face(generator.GetNextFaceID())
{
Parent = solid,
Plane = new Plane(arr[0], arr[1], arr[2]),
Colour = solid.Colour,
Texture = { Texture = texture }
};
face.Vertices.AddRange(arr.Select(x => new Vertex(x, face)));
face.UpdateBoundingBox();
face.AlignTextureToWorld();
solid.Faces.Add(face);
}
solid.UpdateBoundingBox();
return solid;
}
示例10: Copy
public virtual Face Copy(IDGenerator generator)
{
var f = new Face(generator.GetNextFaceID())
{
Plane = Plane.Clone(),
Colour = Colour,
IsSelected = IsSelected,
IsHidden = IsHidden,
Opacity = Opacity,
Texture = Texture.Clone(),
Parent = Parent,
BoundingBox = BoundingBox.Clone()
};
foreach (var v in Vertices.Select(x => x.Clone()))
{
v.Parent = f;
f.Vertices.Add(v);
}
return f;
}
示例11: Create
//.........这里部分代码省略.........
var gp = new GraphicsPath();
gp.AddString(c.ToString(CultureInfo.InvariantCulture), family, (int)style, length, new PointF(0, 0), StringFormat.GenericTypographic);
gp.Flatten(new System.Drawing.Drawing2D.Matrix(), flatten);
var polygons = new List<Polygon>();
var poly = new List<PolygonPoint>();
for (var i = 0; i < gp.PointCount; i++)
{
var type = gp.PathTypes[i];
var point = gp.PathPoints[i];
poly.Add(new PolygonPoint(point.X + xOffset, -point.Y + yOffset));
if ((type & 0x80) == 0x80)
{
polygons.Add(new Polygon(poly));
poly.Clear();
}
}
var tri = new List<Polygon>();
Polygon polygon = null;
foreach (var p in polygons)
{
if (polygon == null)
{
polygon = p;
tri.Add(p);
}
else if (p.CalculateWindingOrder() != polygon.CalculateWindingOrder())
{
polygon.AddHole(p);
}
else
{
polygon = null;
tri.Add(p);
}
}
foreach (var pp in tri)
{
try
{
P2T.Triangulate(pp);
set.Add(pp);
}
catch
{
// Ignore
}
}
xOffset += size.Width;
}
var zOffset = box.Start.Z;
foreach (var polygon in set.Polygons)
{
foreach (var t in polygon.Triangles)
{
var points = t.Points.Select(x => new Coordinate((decimal) x.X, (decimal) x.Y, zOffset).Round(roundDecimals)).ToList();
var faces = new List<Coordinate[]>();
// Add the vertical faces
var z = new Coordinate(0, 0, height).Round(roundDecimals);
for (var j = 0; j < points.Count; j++)
{
var next = (j + 1) % points.Count;
faces.Add(new[] {points[j], points[j] + z, points[next] + z, points[next]});
}
// Add the top and bottom faces
faces.Add(points.ToArray());
faces.Add(points.Select(x => x + z).Reverse().ToArray());
// Nothing new here, move along
var solid = new Solid(generator.GetNextObjectID()) {Colour = Colour.GetRandomBrushColour()};
foreach (var arr in faces)
{
var face = new Face(generator.GetNextFaceID())
{
Parent = solid,
Plane = new Plane(arr[0], arr[1], arr[2]),
Colour = solid.Colour,
Texture = {Texture = texture}
};
face.Vertices.AddRange(arr.Select(x => new Vertex(x, face)));
face.UpdateBoundingBox();
face.AlignTextureToFace();
solid.Faces.Add(face);
}
solid.UpdateBoundingBox();
yield return solid;
}
}
}
示例12: ReadFace
private static Face ReadFace(BinaryReader br, IDGenerator generator)
{
var face = new Face(generator.GetNextFaceID());
var textureName = br.ReadFixedLengthString(Encoding.UTF8, 256);
br.ReadBytes(4); // Unused
face.Texture.Name = textureName;
face.Texture.UAxis = br.ReadCoordinate();
face.Texture.XShift = br.ReadSingleAsDecimal();
face.Texture.VAxis = br.ReadCoordinate();
face.Texture.YShift = br.ReadSingleAsDecimal();
face.Texture.Rotation = br.ReadSingleAsDecimal();
face.Texture.XScale = br.ReadSingleAsDecimal();
face.Texture.YScale = br.ReadSingleAsDecimal();
br.ReadBytes(16); // Unused
var numVerts = br.ReadInt32();
for (var i = 0; i < numVerts; i++)
{
face.Vertices.Add(new Vertex(br.ReadCoordinate(), face));
}
face.Plane = br.ReadPlane();
face.UpdateBoundingBox();
return face;
}
示例13: CalculateDecalGeometry
public void CalculateDecalGeometry()
{
_decalGeometry = new List<Face>();
if (Decal == null) return; // Texture not found
var boxRadius = Coordinate.One * 4;
// Decals apply to all faces that intersect within an 8x8x8 bounding box
// centered at the origin of the decal
var box = new Box(Origin - boxRadius, Origin + boxRadius);
var root = GetRoot(Parent);
// Get the faces that intersect with the decal's radius
var faces = root.GetAllNodesIntersectingWith(box).OfType<Solid>()
.SelectMany(x => x.Faces).Where(x => x.IntersectsWithBox(box));
var idg = new IDGenerator(); // Dummy generator
foreach (var face in faces)
{
// Project the decal onto the face
var center = face.Plane.Project(Origin);
var texture = face.Texture.Clone();
texture.Name = Decal.Name;
texture.Texture = Decal;
texture.XShift = -Decal.Width / 2m;
texture.YShift = -Decal.Height / 2m;
var decalFace = new Face(idg.GetNextFaceID())
{
Colour = Colour,
IsSelected = IsSelected,
IsHidden = IsCodeHidden,
Plane = face.Plane,
Texture = texture
};
// Re-project the vertices in case the texture axes are not on the face plane
var xShift = face.Texture.UAxis * face.Texture.XScale * Decal.Width / 2;
var yShift = face.Texture.VAxis * face.Texture.YScale * Decal.Height / 2;
var verts = new[]
{
new Vertex(face.Plane.Project(center + xShift - yShift), decalFace), // Bottom Right
new Vertex(face.Plane.Project(center + xShift + yShift), decalFace), // Top Right
new Vertex(face.Plane.Project(center - xShift + yShift), decalFace), // Top Left
new Vertex(face.Plane.Project(center - xShift - yShift), decalFace) // Bottom Left
};
// Because the texture axes don't have to align to the face, we might have a reversed face here
// If so, reverse the points to get a valid face for the plane.
// TODO: Is there a better way to do this?
var vertPlane = new Plane(verts[0].Location, verts[1].Location, verts[2].Location);
if (!face.Plane.Normal.EquivalentTo(vertPlane.Normal))
{
Array.Reverse(verts);
}
decalFace.Vertices.AddRange(verts);
decalFace.UpdateBoundingBox();
// Calculate the X and Y shift bases on the first vertex location (assuming U/V of first vertex is zero) - we dont want these to change
var vtx = decalFace.Vertices[0];
decalFace.Texture.XShift = -(vtx.Location.Dot(decalFace.Texture.UAxis)) / decalFace.Texture.XScale;
decalFace.Texture.YShift = -(vtx.Location.Dot(decalFace.Texture.VAxis)) / decalFace.Texture.YScale;
decalFace.CalculateTextureCoordinates();
// Next, the decal geometry needs to be clipped to the face so it doesn't spill into the void
// Create a fake solid out of the decal geometry and clip it against all the brush planes
var fake = CreateFakeDecalSolid(decalFace);
foreach (var f in face.Parent.Faces.Except(new[] { face }))
{
Solid back, front;
fake.Split(f.Plane, out back, out front, idg);
fake = back ?? fake;
}
// Extract out the original face
decalFace = fake.Faces.First(x => x.Plane.EquivalentTo(face.Plane, 0.05m));
// Add a tiny bit to the normal axis to ensure the decal is rendered in front of the face
var normalAdd = face.Plane.Normal * 0.2m;
decalFace.Transform(new UnitTranslate(normalAdd), TransformFlags.TextureLock);
_decalGeometry.Add(decalFace);
}
}
示例14: ReadFace
private Face ReadFace(string line, IDGenerator generator)
{
const NumberStyles ns = NumberStyles.Float;
var parts = line.Split(' ').Where(x => !String.IsNullOrWhiteSpace(x)).ToList();
Assert(parts[0] == "(");
Assert(parts[4] == ")");
Assert(parts[5] == "(");
Assert(parts[9] == ")");
Assert(parts[10] == "(");
Assert(parts[14] == ")");
var face = new Face(generator.GetNextFaceID())
{
Plane = new Plane(Coordinate.Parse(parts[1], parts[2], parts[3]),
Coordinate.Parse(parts[6], parts[7], parts[8]),
Coordinate.Parse(parts[11], parts[12], parts[13])),
Texture = {Name = parts[15]}
};
// Cater for older-style map formats
if (parts.Count == 21)
{
face.AlignTextureToFace();
face.Texture.XShift = decimal.Parse(parts[16], ns, CultureInfo.InvariantCulture);
face.Texture.YShift = decimal.Parse(parts[17], ns, CultureInfo.InvariantCulture);
face.Texture.Rotation = decimal.Parse(parts[18], ns, CultureInfo.InvariantCulture);
face.Texture.XScale = decimal.Parse(parts[19], ns, CultureInfo.InvariantCulture);
face.Texture.YScale = decimal.Parse(parts[20], ns, CultureInfo.InvariantCulture);
}
else
{
Assert(parts[16] == "[");
Assert(parts[21] == "]");
Assert(parts[22] == "[");
Assert(parts[27] == "]");
face.Texture.UAxis = Coordinate.Parse(parts[17], parts[18], parts[19]);
face.Texture.XShift = decimal.Parse(parts[20], ns, CultureInfo.InvariantCulture);
face.Texture.VAxis = Coordinate.Parse(parts[23], parts[24], parts[25]);
face.Texture.YShift = decimal.Parse(parts[26], ns, CultureInfo.InvariantCulture);
face.Texture.Rotation = decimal.Parse(parts[28], ns, CultureInfo.InvariantCulture);
face.Texture.XScale = decimal.Parse(parts[29], ns, CultureInfo.InvariantCulture);
face.Texture.YScale = decimal.Parse(parts[30], ns, CultureInfo.InvariantCulture);
}
return face;
}
示例15: Reindex
private static void Reindex(IEnumerable<MapObject> objs, IDGenerator generator)
{
foreach (var o in objs)
{
if (o is Solid) ((Solid) o).Faces.ForEach(x => x.ID = generator.GetNextFaceID());
o.ID = generator.GetNextObjectID();
if (o.Children.Count == 0) o.UpdateBoundingBox();
Reindex(o.Children, generator);
}
}