public void Clone() { CompositeShape compositeShape = new CompositeShape(); for (int i = 0; i < 10; i++) { Pose pose = new Pose(new Vector3F(i, i, i)); PointShape point = new PointShape(i, i, i); GeometricObject geometry = new GeometricObject(point, pose); compositeShape.Children.Add(geometry); } CompositeShape clone = compositeShape.Clone() as CompositeShape; Assert.IsNotNull(clone); Assert.AreEqual(10, clone.Children.Count); for (int i = 0; i < 10; i++) { Assert.IsNotNull(clone.Children[i]); Assert.AreNotSame(compositeShape.Children[i], clone.Children[i]); Assert.IsTrue(clone.Children[i] is GeometricObject); Assert.AreEqual(compositeShape.Children[i].Pose, clone.Children[i].Pose); Assert.IsNotNull(clone.Children[i].Shape); Assert.AreNotSame(compositeShape.Children[i].Shape, clone.Children[i].Shape); Assert.IsTrue(clone.Children[i].Shape is PointShape); Assert.AreEqual(((PointShape)compositeShape.Children[i].Shape).Position, ((PointShape)clone.Children[i].Shape).Position); } Assert.AreEqual(compositeShape.GetAabb(Pose.Identity).Minimum, clone.GetAabb(Pose.Identity).Minimum); Assert.AreEqual(compositeShape.GetAabb(Pose.Identity).Maximum, clone.GetAabb(Pose.Identity).Maximum); }
public void Clone() { CompositeShape compositeShape = new CompositeShape(); for (int i = 0; i < 10; i++) { Pose pose = new Pose(new Vector3(i, i, i)); PointShape point = new PointShape(i, i, i); GeometricObject geometry = new GeometricObject(point, pose); compositeShape.Children.Add(geometry); } CompositeShape clone = compositeShape.Clone() as CompositeShape; Assert.IsNotNull(clone); Assert.AreEqual(10, clone.Children.Count); for (int i = 0; i < 10; i++) { Assert.IsNotNull(clone.Children[i]); Assert.AreNotSame(compositeShape.Children[i], clone.Children[i]); Assert.IsTrue(clone.Children[i] is GeometricObject); Assert.AreEqual(compositeShape.Children[i].Pose, clone.Children[i].Pose); Assert.IsNotNull(clone.Children[i].Shape); Assert.AreNotSame(compositeShape.Children[i].Shape, clone.Children[i].Shape); Assert.IsTrue(clone.Children[i].Shape is PointShape); Assert.AreEqual(((PointShape)compositeShape.Children[i].Shape).Position, ((PointShape)clone.Children[i].Shape).Position); } Assert.AreEqual(compositeShape.GetAabb(Pose.Identity).Minimum, clone.GetAabb(Pose.Identity).Minimum); Assert.AreEqual(compositeShape.GetAabb(Pose.Identity).Maximum, clone.GetAabb(Pose.Identity).Maximum); }
/// <summary> /// Does not clone textures and shapes /// </summary> /// <returns></returns> public override EntitySidedProperties Clone() { AnimationMetaData[] newAnimations = null; if (Animations != null) { newAnimations = new AnimationMetaData[Animations.Length]; for (int i = 0; i < newAnimations.Length; i++) { newAnimations[i] = Animations[i].Clone(); } } Dictionary <string, AnimationMetaData> newAnimationsByMetaData = new Dictionary <string, AnimationMetaData>(StringComparer.OrdinalIgnoreCase); Dictionary <uint, AnimationMetaData> animsByCrc32 = new Dictionary <uint, AnimationMetaData>(); foreach (var animation in AnimationsByMetaCode) { newAnimationsByMetaData[animation.Key] = animation.Value.Clone(); animsByCrc32[newAnimationsByMetaData[animation.Key].CodeCrc32] = newAnimationsByMetaData[animation.Key]; } return(new EntityClientProperties(BehaviorsAsJsonObj.Clone() as JsonObject[]) { Textures = Textures, RendererName = RendererName, GlowLevel = GlowLevel, Size = Size, Shape = Shape?.Clone(), Animations = newAnimations, AnimationsByMetaCode = newAnimationsByMetaData, AnimationsByCrc32 = animsByCrc32 }); }
public MeshData GenMesh(ICoreClientAPI capi, ItemStack contentStack, string type, string label, string lidState, CompositeShape cshape, Vec3f rotation = null) { if (lidState == "opened") { cshape = cshape.Clone(); cshape.Base.Path = cshape.Base.Path.Replace("closed", "opened"); } Shape shape = GetShape(capi, type, cshape); var tesselator = capi.Tesselator; if (shape == null) { return(new MeshData()); } curType = type; MeshData mesh; tesselator.TesselateShape("crate", shape, out mesh, this, rotation == null ? new Vec3f(Shape.rotateX, Shape.rotateY, Shape.rotateZ) : rotation); if (label != null && Props.Labels.TryGetValue(label, out var labelProps)) { var meshLabel = GenLabelMesh(capi, label, tmpTextureSource[labelProps.Texture], false, rotation); mesh.AddMeshData(meshLabel); } if (contentStack != null && lidState != "closed") { var contentMesh = genContentMesh(capi, contentStack, rotation); if (contentMesh != null) { mesh.AddMeshData(contentMesh); } } return(mesh); }
private void CloneWithPartition(CompositeShape compositeShape, ISpatialPartition <int> partition) { compositeShape.Partition = partition; CompositeShape clone = compositeShape.Clone() as CompositeShape; Assert.IsNotNull(clone); Assert.AreEqual(10, clone.Children.Count); for (int i = 0; i < 10; i++) { Assert.IsNotNull(clone.Children[i]); Assert.AreNotSame(compositeShape.Children[i], clone.Children[i]); Assert.IsTrue(clone.Children[i] is GeometricObject); Assert.AreEqual(compositeShape.Children[i].Pose, clone.Children[i].Pose); Assert.IsNotNull(clone.Children[i].Shape); Assert.AreNotSame(compositeShape.Children[i].Shape, clone.Children[i].Shape); Assert.IsTrue(clone.Children[i].Shape is PointShape); Assert.AreEqual(((PointShape)compositeShape.Children[i].Shape).Position, ((PointShape)clone.Children[i].Shape).Position); } Assert.IsNotNull(clone.Partition); Assert.IsInstanceOf(partition.GetType(), clone.Partition); Assert.AreEqual(compositeShape.Children.Count, clone.Partition.Count); Assert.AreNotSame(partition, clone.Partition); }
private void CloneWithPartition(CompositeShape compositeShape, ISpatialPartition<int> partition) { compositeShape.Partition = partition; CompositeShape clone = compositeShape.Clone() as CompositeShape; Assert.IsNotNull(clone); Assert.AreEqual(10, clone.Children.Count); for (int i = 0; i < 10; i++) { Assert.IsNotNull(clone.Children[i]); Assert.AreNotSame(compositeShape.Children[i], clone.Children[i]); Assert.IsTrue(clone.Children[i] is GeometricObject); Assert.AreEqual(compositeShape.Children[i].Pose, clone.Children[i].Pose); Assert.IsNotNull(clone.Children[i].Shape); Assert.AreNotSame(compositeShape.Children[i].Shape, clone.Children[i].Shape); Assert.IsTrue(clone.Children[i].Shape is PointShape); Assert.AreEqual(((PointShape)compositeShape.Children[i].Shape).Position, ((PointShape)clone.Children[i].Shape).Position); } Assert.IsNotNull(clone.Partition); Assert.IsInstanceOf(partition.GetType(), clone.Partition); Assert.AreEqual(compositeShape.Children.Count, clone.Partition.Count); Assert.AreNotSame(partition, clone.Partition); }