/// <summary> /// Destroy a persistent sphere. /// </summary> /// <param name="id"></param> public static void SphereEnd(uint id) { if (Instance != null && id != 0) { var shape = new Tes.Shapes.Sphere(id); Instance.Server.Destroy(shape); } }
/// <summary> /// Create or update a persistent sphere. /// </summary> /// <param name="id"></param> /// <param name="colour"></param> /// <param name="centre"></param> /// <param name="radius"></param> /// <param name="update"></param> public static void Sphere(uint id, Color colour, Vector3 centre, float radius, bool update = false) { if (Instance != null) { var shape = new Tes.Shapes.Sphere(id, ToTes(centre), radius); shape.Colour = ToTes(colour).Value; if (!update || id == 0) { Instance.Server.Create(shape); } else { Instance.Server.Update(shape); } } }
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); } }
void Start() { Dynamic = false; if (Shape == null) { // Resolve the appropriate shape. Collider collider = GetComponent <Collider>(); UpdatePosition = UpdateRotation = UpdateScale = false; if (collider != null) { BoxCollider box = null; CapsuleCollider capsule = null; MeshCollider mesh = null; SphereCollider sphere = null; TerrainCollider terrain = null; WheelCollider wheel = null; // Note: colour is set using LookupColour() in TesServer.Add() // FIXME: isStatic doesn't do well to highlight static collision geometry. // Mark everything as dynamic for now. //if (!collider.gameObject.isStatic) //{ UpdatePosition = UpdateRotation = UpdateScale = true; //} Tes.Maths.Vector3 scale = ToTes(transform.lossyScale); Tes.Maths.Vector3 pos = ToTes(transform.position); if ((box = collider as BoxCollider) != null) { pos += ToTes(PositionOffset); scale.X *= box.size.x; scale.Y *= box.size.y; scale.Z *= box.size.z; Shape = new Tes.Shapes.Box(NextId(), pos, scale, ToTes(transform.rotation)); } else if ((capsule = collider as CapsuleCollider) != null) { UpdateScale = false; Shape = new Tes.Shapes.Capsule(NextId(), ToTes(transform.position), Tes.Maths.Vector3.AxisY, scale.Y * capsule.height, scale.X * capsule.radius); _shapeRotation = FromTes(Shape.Rotation); Shape.Rotation = ToTes(transform.rotation * _shapeRotation); } else if ((mesh = collider as MeshCollider) != null) { var meshShape = new Tes.Shapes.MeshSet(NextId()); Shape = meshShape; meshShape.AddPart(new TesMeshWrapper(mesh.sharedMesh)); meshShape.Position = ToTes(transform.position); meshShape.Rotation = ToTes(transform.rotation); meshShape.Scale = scale; } else if ((sphere = collider as SphereCollider) != null) { UpdateRotation = false; UpdateScale = false; Shape = new Tes.Shapes.Sphere(NextId(), ToTes(transform.localPosition), transform.lossyScale.x * sphere.radius); } else if ((terrain = collider as TerrainCollider) != null) { Debug.LogWarning(string.Format("TerrainCollider not yet supported ({0}).", gameObject.name)); } else if ((wheel = collider as WheelCollider) != null) { Debug.LogWarning(string.Format("WheelCollider not yet supported ({0}).", gameObject.name)); } else { Debug.LogError(string.Format("Unsupported collider type for object {0}: {1}.", gameObject.name, collider.GetType().Name)); } } } Dynamic = UpdatePosition || UpdateRotation || UpdateScale; }