本文整理汇总了C#中Sledge.DataStructures.MapObjects.IDGenerator.GetNextObjectID方法的典型用法代码示例。如果您正苦于以下问题:C# IDGenerator.GetNextObjectID方法的具体用法?C# IDGenerator.GetNextObjectID怎么用?C# IDGenerator.GetNextObjectID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sledge.DataStructures.MapObjects.IDGenerator
的用法示例。
在下文中一共展示了IDGenerator.GetNextObjectID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例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: 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;
}
示例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: 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;
}
示例6: 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;
}
示例7: 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;
}
示例8: 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;
}
示例9: 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);
}
示例10: 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);
}
示例11: 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;
}
示例12: 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);
}
示例13: 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;
}
示例14: 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);
}
}
示例15: GetObjectID
private static long GetObjectID(GenericStructure gs, IDGenerator generator)
{
var id = gs.PropertyLong("id");
if (id == 0) id = generator.GetNextObjectID();
return id;
}