本文整理汇总了C#中Sledge.DataStructures.MapObjects.IDGenerator类的典型用法代码示例。如果您正苦于以下问题:C# IDGenerator类的具体用法?C# IDGenerator怎么用?C# IDGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IDGenerator类属于Sledge.DataStructures.MapObjects命名空间,在下文中一共展示了IDGenerator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public IEnumerable<MapObject> Create(IDGenerator generator, Box box, ITexture texture, int roundDecimals)
{
var numSides = (int)_numSides.GetValue();
if (numSides < 3) yield break;
var width = box.Width;
var length = box.Length;
var height = box.Height;
var major = width / 2;
var minor = length / 2;
var heightRadius = height / 2;
var angleV = DMath.DegreesToRadians(180) / numSides;
var angleH = DMath.DegreesToRadians(360) / numSides;
var faces = new List<Coordinate[]>();
var bottom = new Coordinate(box.Center.X, box.Center.Y, box.Start.Z).Round(roundDecimals);
var top = new Coordinate(box.Center.X, box.Center.Y, box.End.Z).Round(roundDecimals);
for (var i = 0; i < numSides; i++)
{
// Top -> bottom
var zAngleStart = angleV * i;
var zAngleEnd = angleV * (i + 1);
var zStart = heightRadius * DMath.Cos(zAngleStart);
var zEnd = heightRadius * DMath.Cos(zAngleEnd);
var zMultStart = DMath.Sin(zAngleStart);
var zMultEnd = DMath.Sin(zAngleEnd);
for (var j = 0; j < numSides; j++)
{
// Go around the circle in X/Y
var xyAngleStart = angleH * j;
var xyAngleEnd = angleH * ((j + 1) % numSides);
var xyStartX = major * DMath.Cos(xyAngleStart);
var xyStartY = minor * DMath.Sin(xyAngleStart);
var xyEndX = major * DMath.Cos(xyAngleEnd);
var xyEndY = minor * DMath.Sin(xyAngleEnd);
var one = (new Coordinate(xyStartX * zMultStart, xyStartY * zMultStart, zStart) + box.Center).Round(roundDecimals);
var two = (new Coordinate(xyEndX * zMultStart, xyEndY * zMultStart, zStart) + box.Center).Round(roundDecimals);
var three = (new Coordinate(xyEndX * zMultEnd, xyEndY * zMultEnd, zEnd) + box.Center).Round(roundDecimals);
var four = (new Coordinate(xyStartX * zMultEnd, xyStartY * zMultEnd, zEnd) + box.Center).Round(roundDecimals);
if (i == 0)
{
// Top faces are triangles
faces.Add(new[] { top, three, four });
}
else if (i == numSides - 1)
{
// Bottom faces are also triangles
faces.Add(new[] { bottom, one, two });
}
else
{
// Inner faces are quads
faces.Add(new[] { one, two, three, four });
}
}
}
yield return MakeSolid(generator, faces, texture, Colour.GetRandomBrushColour());
}
示例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 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;
}
示例5: Paste
public override void Paste(MapObject o, IDGenerator generator)
{
PasteBase(o, generator);
var e = o as World;
if (e == null) return;
EntityData = e.EntityData.Clone();
Paths.Clear();
Paths.AddRange(e.Paths.Select(x => x.Clone()));
}
示例6: 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;
}
示例7: Copy
public override MapObject Copy(IDGenerator generator)
{
var e = new World(generator.GetNextObjectID())
{
EntityData = EntityData.Clone(),
};
e.Paths.AddRange(Paths.Select(x => x.Clone()));
CopyBase(e, generator);
return e;
}
示例8: Copy
public override MapObject Copy(IDGenerator generator)
{
var e = new Entity(generator.GetNextObjectID())
{
GameData = GameData,
EntityData = EntityData.Clone(),
Origin = Origin.Clone()
};
CopyBase(e, generator);
return e;
}
示例9: Copy
public override MapObject Copy(IDGenerator generator)
{
var e = new Solid(generator.GetNextObjectID());
foreach (var f in Faces.Select(x => x.Copy(generator)))
{
f.Parent = e;
e.Faces.Add(f);
f.UpdateBoundingBox();
}
CopyBase(e, generator);
return e;
}
示例10: 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;
}
示例11: Map
public Map()
{
Version = 1;
Visgroups = new List<Visgroup>();
Cameras = new List<Camera>();
ActiveCamera = null;
IDGenerator = new IDGenerator();
WorldSpawn = new World(IDGenerator.GetNextObjectID());
Show2DGrid = SnapToGrid = true;
TextureLock = true;
HideDisplacementSolids = true;
CordonBounds = new Box(Coordinate.One * -1024, Coordinate.One * 1024);
}
示例12: Create
public IEnumerable<MapObject> Create(IDGenerator generator, Box box, ITexture texture)
{
var wallWidth = (int) _width.GetValue();
if (wallWidth < 1) yield break;
var numsides = (int) _numSides.GetValue();
if (numsides < 3) yield break;
// Very similar to the cylinder, except we have multiple solids this time
var width = box.Width;
var length = box.Length;
var height = box.Height;
var majorOut = width / 2;
var majorIn = majorOut - wallWidth;
var minorOut = length / 2;
var minorIn = minorOut - wallWidth;
var angle = 2 * DMath.PI / numsides;
var colour = Colour.GetRandomBrushColour();
// Calculate the X and Y points for the inner and outer ellipses
var outer = new Coordinate[numsides];
var inner = new Coordinate[numsides];
for (var i = 0; i < numsides; i++)
{
var a = i * angle;
var xval = box.Center.X + majorOut * DMath.Cos(a);
var yval = box.Center.Y + minorOut * DMath.Sin(a);
var zval = box.Start.Z;
outer[i] = new Coordinate(xval, yval, zval).Round(0);
xval = box.Center.X + majorIn * DMath.Cos(a);
yval = box.Center.Y + minorIn * DMath.Sin(a);
inner[i] = new Coordinate(xval, yval, zval).Round(0);
}
// Create the solids
var z = new Coordinate(0, 0, height);
for (var i = 0; i < numsides; i++)
{
var faces = new List<Coordinate[]>();
var next = (i + 1) % numsides;
faces.Add(new[] { outer[i], outer[i] + z, outer[next] + z, outer[next] });
faces.Add(new[] { inner[next], inner[next] + z, inner[i] + z, inner[i] });
faces.Add(new[] { outer[next], outer[next] + z, inner[next] + z, inner[next] });
faces.Add(new[] { inner[i], inner[i] + z, outer[i] + z, outer[i] });
faces.Add(new[] { inner[next] + z, outer[next] + z, outer[i] + z, inner[i] + z });
faces.Add(new[] { inner[i], outer[i], outer[next], inner[next] });
yield return MakeSolid(generator, faces, texture, colour);
}
}
示例13: ExtractCopyStream
public static IEnumerable<MapObject> ExtractCopyStream(GenericStructure gs, IDGenerator generator)
{
if (gs == null || gs.Name != "clipboard") return null;
var dummyGen = new IDGenerator();
var list = new List<MapObject>();
var world = ReadWorld(gs, dummyGen);
foreach (var entity in gs.GetChildren("entity"))
{
var ent = ReadEntity(entity, dummyGen);
var groupid = entity.Children.Where(x => x.Name == "editor").Select(x => x.PropertyInteger("groupid")).FirstOrDefault();
var entParent = groupid > 0 ? world.Find(x => x.ID == groupid && x is Group).FirstOrDefault() ?? world : world;
ent.SetParent(entParent);
}
list.AddRange(world.GetChildren());
Reindex(list, generator);
return list;
}
示例14: CopyEntityTest
public void CopyEntityTest()
{
var idGen = new IDGenerator();
var box = new Box(Coordinate.One * -100, Coordinate.One * 100);
// Create an entity with children
var ent = new Entity(idGen.GetNextObjectID());
ent.EntityData.Name = "Test";
ent.EntityData.Properties.Add(new Property { Key = "key1", Value = "value1"});
ent.EntityData.Properties.Add(new Property { Key = "key2", Value = "value2"});
ent.EntityData.Flags = 12345;
var solids = new BlockBrush().Create(idGen, box, null, 0);
foreach (var mo in solids) mo.SetParent(ent);
// Copy and reconstruct
var gs = VmfProvider.CreateCopyStream(new List<MapObject> {ent});
var pasted = VmfProvider.ExtractCopyStream(gs, idGen).ToList();
// Test object
Assert.AreEqual(1, pasted.Count);
Assert.IsInstanceOfType(pasted[0], typeof(Entity));
// Test entity
var pastedEnt = (Entity) pasted[0];
Assert.AreEqual("Test", pastedEnt.EntityData.Name);
Assert.AreEqual(12345, pastedEnt.EntityData.Flags);
// Test properties
Assert.AreEqual(2, pastedEnt.EntityData.Properties.Count);
var k1 = pastedEnt.EntityData.Properties.FirstOrDefault(x => x.Key == "key1");
var k2 = pastedEnt.EntityData.Properties.FirstOrDefault(x => x.Key == "key1");
Assert.IsNotNull(k1);
Assert.IsNotNull(k2);
Assert.AreEqual(k1.Value, "value1");
Assert.AreEqual(k2.Value, "value1");
// Test child
Assert.AreEqual(1, pastedEnt.ChildCount);
Assert.IsInstanceOfType(pastedEnt.GetChildren().ToList()[0], typeof(Solid));
// Check number of sides, values of sides not so important
var pastedSolid = (Solid) pastedEnt.GetChildren().ToList()[0];
Assert.AreEqual(6, pastedSolid.Faces.Count);
}
示例15: 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;
}