예제 #1
0
        /// <summary>
        /// Clone this shape.
        /// </summary>
        /// <returns>A deep copy of this object.</returns>
        public override object Clone()
        {
            Cone copy = new Cone();

            OnClone(copy);
            return(copy);
        }
예제 #2
0
 /// <summary>
 /// Destroy a persistent cone.
 /// </summary>
 /// <param name="id"></param>
 public static void ConeEnd(uint id)
 {
     if (Instance != null && id != 0)
     {
         var shape = new Tes.Shapes.Cone(id);
         Instance.Server.Destroy(shape);
     }
 }
예제 #3
0
 /// <summary>
 /// Create or update a persistent cone.
 /// </summary>
 /// <param name="id"></param>
 /// <param name="colour"></param>
 /// <param name="apex"></param>
 /// <param name="dir"></param>
 /// <param name="angle">Angle in degrees.</param>
 /// <param name="length"></param>
 public static void Cone(uint id, Color colour, Vector3 apex, Vector3 dir, float length, float angle, bool update = false)
 {
     if (Instance != null)
     {
         var shape = new Tes.Shapes.Cone(id, ToTes(apex), ToTes(dir), length, angle / 180.0f * Mathf.PI);
         shape.Colour = ToTes(colour).Value;
         if (!update || id == 0)
         {
             Instance.Server.Create(shape);
         }
         else
         {
             Instance.Server.Update(shape);
         }
     }
 }
예제 #4
0
        static void CreateShapes(Ids ids, List <Shapes.Shape> shapes, List <ShapeMover> movers, List <Resource> resources, string[] args)
        {
            bool allShapes         = HaveOption("all", args);
            bool noMove            = HaveOption("nomove", args);
            int  initialShapeCount = shapes.Count;

            if (allShapes || HaveOption("arrow", args))
            {
                Shapes.Arrow arrow = new Shapes.Arrow(ids.NextShapeId++);
                arrow.Radius = 0.5f;
                arrow.Length = 1.0f;
                arrow.Colour = Colour.Colours[(int)PredefinedColour.SeaGreen].Value;
                shapes.Add(arrow);
                if (!noMove)
                {
                    movers.Add(new Oscillator(arrow, 2.0f, 2.5f));
                }
            }

            if (allShapes || HaveOption("box", args))
            {
                Shapes.Box box = new Shapes.Box(ids.NextShapeId++);
                box.Scale  = new Vector3(0.45f);
                box.Colour = Colour.Colours[(int)PredefinedColour.MediumSlateBlue].Value;
                shapes.Add(box);
                if (!noMove)
                {
                    movers.Add(new Oscillator(box, 2.0f, 2.5f));
                }
            }

            if (allShapes || HaveOption("capsule", args))
            {
                Shapes.Capsule capsule = new Shapes.Capsule(ids.NextShapeId++);
                capsule.Length = 2.0f;
                capsule.Radius = 0.3f;
                capsule.Colour = Colour.Colours[(int)PredefinedColour.LavenderBlush].Value;
                shapes.Add(capsule);
                if (!noMove)
                {
                    movers.Add(new Oscillator(capsule, 2.0f, 2.5f));
                }
            }

            if (allShapes || HaveOption("cone", args))
            {
                Shapes.Cone cone = new Shapes.Cone(ids.NextShapeId++);
                cone.Length = 2.0f;
                cone.Angle  = 15.0f / 180.0f * (float)Math.PI;
                cone.Colour = Colour.Colours[(int)PredefinedColour.SandyBrown].Value;
                shapes.Add(cone);
                if (!noMove)
                {
                    movers.Add(new Oscillator(cone, 2.0f, 2.5f));
                }
            }

            if (allShapes || HaveOption("cylinder", args))
            {
                Shapes.Cylinder cylinder = new Shapes.Cylinder(ids.NextShapeId++);
                cylinder.Scale  = new Vector3(0.45f);
                cylinder.Colour = Colour.Colours[(int)PredefinedColour.FireBrick].Value;
                shapes.Add(cylinder);
                if (!noMove)
                {
                    movers.Add(new Oscillator(cylinder, 2.0f, 2.5f));
                }
            }

            if (allShapes || HaveOption("plane", args))
            {
                Shapes.Plane plane = new Shapes.Plane(ids.NextShapeId++);
                plane.Normal       = new Vector3(1.0f, 1.0f, 0.0f).Normalised;
                plane.Scale        = 1.5f;
                plane.NormalLength = 0.5f;
                plane.Colour       = Colour.Colours[(int)PredefinedColour.LightSlateGrey].Value;
                shapes.Add(plane);
                if (!noMove)
                {
                    movers.Add(new Oscillator(plane, 2.0f, 2.5f));
                }
            }

            if (allShapes || HaveOption("pose", args))
            {
                Shapes.Pose pose = new Shapes.Pose(ids.NextShapeId++);
                shapes.Add(pose);
                if (!noMove)
                {
                    movers.Add(new Oscillator(pose, 2.0f, 2.5f));
                }
            }

            if (allShapes || HaveOption("sphere", args))
            {
                Shapes.Sphere sphere = new Shapes.Sphere(ids.NextShapeId++);
                sphere.Radius = 0.75f;
                sphere.Colour = Colour.Colours[(int)PredefinedColour.Coral].Value;
                shapes.Add(sphere);
                if (!noMove)
                {
                    movers.Add(new Oscillator(sphere, 2.0f, 2.5f));
                }
            }

            if (allShapes || HaveOption("star", args))
            {
                Shapes.Star star = new Shapes.Star(ids.NextShapeId++);
                star.Radius = 0.75f;
                star.Colour = Colour.Colours[(int)PredefinedColour.DarkGreen].Value;
                shapes.Add(star);
                if (!noMove)
                {
                    movers.Add(new Oscillator(star, 2.0f, 2.5f));
                }
            }

            if (allShapes || HaveOption("lines", args))
            {
                Vector3[] lineSet = new Vector3[]
                {
                    new Vector3(0, 0, 0), new Vector3(0, 0, 1),
                    new Vector3(0, 0, 1), new Vector3(0.25f, 0, 0.8f),
                    new Vector3(0, 0, 1), new Vector3(-0.25f, 0, 0.8f)
                };
                Shapes.MeshShape lines = new Shapes.MeshShape(MeshDrawType.Lines, lineSet, ids.NextShapeId++);
                shapes.Add(lines);
                // if (!noMove)
                // {
                //   movers.Add(new Oscillator(mesh, 2.0f, 2.5f));
                // }
            }

            if (allShapes || HaveOption("triangles", args))
            {
                Vector3[] triangleSet = new Vector3[]
                {
                    new Vector3(0, 0, 0), new Vector3(0, 0.25f, 1), new Vector3(0.25f, 0, 1),
                    new Vector3(0, 0, 0), new Vector3(-0.25f, 0, 1), new Vector3(0, 0.25f, 1),
                    new Vector3(0, 0, 0), new Vector3(0, -0.25f, 1), new Vector3(-0.25f, 0, 1),
                    new Vector3(0, 0, 0), new Vector3(0.25f, 0, 1), new Vector3(0, -0.25f, 1)
                };
                UInt32[] colours = new UInt32[]
                {
                    Colour.Colours[(int)PredefinedColour.Red].Value, Colour.Colours[(int)PredefinedColour.Red].Value, Colour.Colours[(int)PredefinedColour.Red].Value,
                    Colour.Colours[(int)PredefinedColour.Green].Value, Colour.Colours[(int)PredefinedColour.Green].Value, Colour.Colours[(int)PredefinedColour.Green].Value,
                    Colour.Colours[(int)PredefinedColour.Blue].Value, Colour.Colours[(int)PredefinedColour.Blue].Value, Colour.Colours[(int)PredefinedColour.Blue].Value,
                    Colour.Colours[(int)PredefinedColour.White].Value, Colour.Colours[(int)PredefinedColour.White].Value, Colour.Colours[(int)PredefinedColour.White].Value,
                };
                Shapes.MeshShape triangles = new Shapes.MeshShape(MeshDrawType.Triangles, triangleSet, ids.NextShapeId++);
                triangles.Colours = colours;
                shapes.Add(triangles);
                // if (!noMove)
                // {
                //   movers.Add(new Oscillator(mesh, 2.0f, 2.5f));
                // }
            }

            if (allShapes || HaveOption("mesh", args))
            {
                Shapes.MeshResource mesRes = CreateTestMesh(ids);
                resources.Add(mesRes);
                Shapes.MeshSet mesh = new Shapes.MeshSet(ids.NextShapeId++);
                mesh.AddPart(mesRes, Matrix4.Identity, Colour.Colours[(int)PredefinedColour.YellowGreen]);
                mesh.AddPart(mesRes, Matrix4.TranslationMatrix(new Vector3(0, 0, 1.5f)), Colour.Colours[(int)PredefinedColour.SkyBlue]);
                shapes.Add(mesh);
                // if (!noMove)
                // {
                //   movers.Add(new Oscillator(mesh, 2.0f, 2.5f));
                // }
            }

            if (allShapes || HaveOption("points", args))
            {
                Vector3[] pts = new Vector3[]
                {
                    new Vector3(0, 0, 0),
                    new Vector3(0, 0.25f, 1),
                    new Vector3(0.25f, 0, 1),
                    new Vector3(-0.25f, 0, 1),
                    new Vector3(0, -0.25f, 1)
                };
                UInt32[] colours = new UInt32[]
                {
                    Colour.Colours[(int)PredefinedColour.Black].Value,
                    Colour.Colours[(int)PredefinedColour.Red].Value,
                    Colour.Colours[(int)PredefinedColour.Green].Value,
                    Colour.Colours[(int)PredefinedColour.Blue].Value,
                    Colour.Colours[(int)PredefinedColour.White].Value
                };
                Shapes.MeshShape points = new Shapes.MeshShape(MeshDrawType.Points, pts, ids.NextShapeId++);
                points.Colours = colours;
                shapes.Add(points);
                // if (!noMove)
                // {
                //   movers.Add(new Oscillator(mesh, 2.0f, 2.5f));
                // }
            }

            if (allShapes || HaveOption("cloud", args) || HaveOption("cloudpart", args))
            {
                Shapes.MeshResource    cloud  = CreateTestCloud(ids);
                Shapes.PointCloudShape points = new Shapes.PointCloudShape(cloud, ids.NextShapeId++, (byte)16);
                if (HaveOption("cloudpart", args))
                {
                    // Partial indexing.
                    List <uint> partialIndices = new List <uint>();
                    uint        nextIndex      = 0;
                    for (int i = 0; i < partialIndices.Count; ++i)
                    {
                        partialIndices.Add(nextIndex);
                        nextIndex += 2;
                    }
                    points.SetIndices(partialIndices.ToArray());
                }
                shapes.Add(points);
                resources.Add(cloud);
                // if (!noMove)
                // {
                //   movers.Add(new Oscillator(points, 2.0f, 2.5f));
                // }
            }

            if (HaveOption("wire", args))
            {
                for (int i = initialShapeCount; i < shapes.Count; ++i)
                {
                    shapes[i].Wireframe = true;
                }
            }

            // Position the shapes so they aren't all on top of one another.
            if (shapes.Count > initialShapeCount)
            {
                Vector3     pos     = Vector3.Zero;
                const float spacing = 2.0f;
                pos.X -= spacing * ((shapes.Count - initialShapeCount) / 2u);

                for (int i = initialShapeCount; i < shapes.Count; ++i)
                {
                    shapes[i].Position = pos;
                    pos.X += spacing;
                }

                foreach (ShapeMover mover in movers)
                {
                    mover.Reset();
                }
            }


            // Add text after positioning and mover changes to keep fixed positions.
            if (allShapes || HaveOption("text2d", args))
            {
                Shapes.Text2D text;
                text = new Shapes.Text2D("Hello Screen", ids.NextShapeId++, new Vector3(0.25f, 0.75f, 0.0f));
                shapes.Add(text);
                text = new Shapes.Text2D("Hello World 2D", ids.NextShapeId++, new Vector3(1.0f, 1.0f, 1.0f));
                text.InWorldSpace = true;
                shapes.Add(text);
            }

            if (allShapes || HaveOption("text3d", args))
            {
                Shapes.Text3D text;
                text          = new Shapes.Text3D("Hello World 3D", ids.NextShapeId++, new Vector3(-1.0f, -1.0f, 1.0f));
                text.FontSize = 16;
                shapes.Add(text);
                text              = new Shapes.Text3D("Hello World 3D Facing", ids.NextShapeId++, new Vector3(-1.0f, -1.0f, 0.0f), 8);
                text.FontSize     = 16;
                text.ScreenFacing = true;
                shapes.Add(text);
            }

            if (HaveOption("multi", args))
            {
                int              blockSize  = 10;
                float            separation = 0.4f;
                float            posOffset  = -0.5f * blockSize * separation;
                Shapes.Capsule[] capSet     = new Shapes.Capsule[blockSize * blockSize * blockSize];
                uint             id         = ids.NextShapeId++;
                int              i          = 0;
                for (int z = 0; z < blockSize; ++z)
                {
                    for (int y = 0; y < blockSize; ++y)
                    {
                        for (int x = 0; x < blockSize; ++x)
                        {
                            Vector3 pos = Vector3.Zero;
                            pos.X = posOffset + x * separation;
                            pos.Y = posOffset + y * separation;
                            pos.Z = posOffset + z * separation;

                            Shapes.Capsule capsule = new Shapes.Capsule(id);
                            capsule.Position = pos;
                            capsule.Length   = 0.5f;
                            capsule.Radius   = 0.15f;
                            capSet[i++]      = capsule;
                        }
                    }
                }

                Shapes.MultiShape multi = new Shapes.MultiShape(capSet, new Vector3(0, 10.0f, 0), new Quaternion(Vector3.AxisZ, 1.047f));
                shapes.Add(multi);
            }

            // Did we create anything?
            if (initialShapeCount == shapes.Count)
            {
                // Nothing created. Create the default shape by providing some fake arguments.
                string[] defaultArgs = new string[]
                {
                    "sphere"
                };

                CreateShapes(ids, shapes, movers, resources, defaultArgs);
            }
        }