Пример #1
0
        /// <summary>
        /// Overridden to handle component pieces.
        /// </summary>
        protected override void EncodeAttributes(ref ObjectAttributes attr, GameObject obj, ShapeComponent comp)
        {
            Transform transform = obj.transform;

            attr.X         = transform.localPosition.x;
            attr.Y         = transform.localPosition.y;
            attr.Z         = transform.localPosition.z;
            attr.RotationX = transform.localRotation.x;
            attr.RotationY = transform.localRotation.y;
            attr.RotationZ = transform.localRotation.z;
            attr.RotationW = transform.localRotation.w;
            Transform child;

            child = transform.GetChild(Tes.Tessellate.Capsule.CylinderIndex);
            if (child)
            {
                attr.ScaleX = attr.ScaleY = child.localScale.x;
                attr.ScaleZ = child.localScale.y;
            }
            if (comp != null)
            {
                attr.Colour = ShapeComponent.ConvertColour(comp.Colour);
            }
            else
            {
                attr.Colour = 0xffffffu;
            }
        }
Пример #2
0
        /// <summary>
        /// Encode transform attributes for text.
        /// </summary>
        /// <param name="attr"></param>
        /// <param name="obj"></param>
        /// <param name="comp"></param>
        protected override void EncodeAttributes(ref ObjectAttributes attr, GameObject obj, ShapeComponent comp)
        {
            Transform transform = obj.transform;
            // Convert position to Unity position.
            Vector3 pos = FrameTransform.UnityToRemote(obj.transform.position, ServerInfo.CoordinateFrame);

            attr.X         = pos.x;
            attr.Y         = pos.y;
            attr.Z         = pos.z;
            attr.RotationX = transform.localRotation.x;
            attr.RotationY = transform.localRotation.y;
            attr.RotationZ = transform.localRotation.z;
            attr.RotationW = transform.localRotation.w;
            attr.ScaleX    = 1.0f;
            attr.ScaleY    = 1.0f;
            attr.ScaleZ    = 12.0f;

            TextMesh text = obj.GetComponent <TextMesh>();

            if (text != null)
            {
                attr.ScaleZ = text.fontSize;
            }
            if (comp != null)
            {
                attr.Colour = ShapeComponent.ConvertColour(comp.Colour);
            }
            else
            {
                attr.Colour = 0xffffffu;
            }
        }
Пример #3
0
        /// <summary>
        /// Called for each mesh part in the create messages.
        /// </summary>
        /// <param name="parent">The parent object for the part object.</param>
        /// <param name="reader">Message data reader.</param>
        /// <param name="partNumber">The part number/index.</param>
        /// <returns>An error code on failure.</returns>
        protected virtual Error AddMeshPart(GameObject parent, BinaryReader reader, int partNumber)
        {
            uint             meshId     = reader.ReadUInt32();
            ObjectAttributes attributes = new ObjectAttributes();

            if (!attributes.Read(reader))
            {
                return(new Error(ErrorCode.MalformedMessage, (int)ObjectMessageID.Create));
            }

            // Add the part and a child for the part's mesh.
            // This supports the mesh having its own transform or pivot offset.
            GameObject     part  = new GameObject();
            ShapeComponent shape = part.AddComponent <ShapeComponent>();

            part.name = string.Format("part{0}", partNumber);

            shape.ObjectID    = meshId; // Use for mesh ID.
            shape.Category    = 0;
            shape.ObjectFlags = 0;
            shape.Colour      = ShapeComponent.ConvertColour(attributes.Colour);

            DecodeTransform(attributes, part.transform);
            part.transform.SetParent(parent.transform, false);

            return(new Error());
        }
Пример #4
0
        /// <summary>
        /// Handle update messages.
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="packet"></param>
        /// <param name="reader"></param>
        /// <returns></returns>
        protected virtual Error HandleMessage(UpdateMessage msg, PacketBuffer packet, BinaryReader reader)
        {
            TextEntry text = new TextEntry();

            text.ID          = msg.ObjectID;
            text.ObjectFlags = msg.Flags;
            text.Position    = new Vector3(msg.Attributes.X, msg.Attributes.Y, msg.Attributes.Z);
            text.Colour      = ShapeComponent.ConvertColour(msg.Attributes.Colour);
            text.Active      = true;

            // Read the text.
            int textLength = reader.ReadUInt16();

            if (textLength > 0)
            {
                byte[] textBytes = reader.ReadBytes(textLength);
                text.Text = System.Text.Encoding.Default.GetString(textBytes);
            }

            if (text.ID != 0)
            {
                PersistentText.UpdateEntry(text);
            }

            return(new Error());
        }
Пример #5
0
        /// <summary>
        /// Handle create messages.
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="packet"></param>
        /// <param name="reader"></param>
        /// <returns></returns>
        protected virtual Error HandleMessage(CreateMessage msg, PacketBuffer packet, BinaryReader reader)
        {
            TextEntry text = new TextEntry();

            text.ID          = msg.ObjectID;
            text.ObjectFlags = msg.Flags;
            text.Category    = msg.Category;
            text.Position    = new Vector3(msg.Attributes.X, msg.Attributes.Y, msg.Attributes.Z);
            text.Colour      = ShapeComponent.ConvertColour(msg.Attributes.Colour);
            text.Active      = CategoryCheck(text.Category);

            // Read the text.
            int textLength = reader.ReadUInt16();

            if (textLength > 0)
            {
                byte[] textBytes = reader.ReadBytes(textLength);
                text.Text = System.Text.Encoding.UTF8.GetString(textBytes);
            }

            if (msg.ObjectID == 0)
            {
                TransientText.Add(text);
            }
            else
            {
                PersistentText.Add(text);
            }

            return(new Error());
        }
Пример #6
0
        /// <summary>
        /// Overridden to read information about mesh parts.
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="packet"></param>
        /// <param name="reader"></param>
        /// <returns></returns>
        protected override Error HandleMessage(CreateMessage msg, PacketBuffer packet, BinaryReader reader)
        {
            GameObject obj = null;

            if (msg.ObjectID == 0)
            {
                // Cannot support transient objects: we need to get point data through additional
                // messages which requires a valid object id.
                return(new Error(ErrorCode.InvalidObjectID, 0));
            }
            else
            {
                obj = CreateObject(msg.ObjectID);
                if (!obj)
                {
                    // Object already exists.
                    return(new Error(ErrorCode.DuplicateShape, msg.ObjectID));
                }
            }

            ShapeComponent shapeComp = obj.GetComponent <ShapeComponent>();

            if (shapeComp)
            {
                shapeComp.Category    = msg.Category;
                shapeComp.ObjectFlags = msg.Flags;
                shapeComp.Colour      = ShapeComponent.ConvertColour(msg.Attributes.Colour);
            }

            obj.transform.SetParent(Root.transform, false);
            DecodeTransform(msg.Attributes, obj.transform);

            // Read additional attributes.
            PointsComponent pointsComp = obj.AddComponent <PointsComponent>();

            // Read the mesh ID to render points from.
            pointsComp.MeshID = reader.ReadUInt32();
            // Read the number of indices (zero implies show entire mesh).
            pointsComp.IndexCount = reader.ReadUInt32();
            pointsComp.PointSize  = reader.ReadByte();

            if (pointsComp.IndexCount == 0)
            {
                // Not expecting any index data messages.
                // Register the mesh now.
                RegisterForMesh(pointsComp);
            }

            return(new Error());
        }
Пример #7
0
        /// <summary>
        /// Overridden to handle component pieces.
        /// </summary>
        protected override void EncodeAttributes(ref ObjectAttributes attr, GameObject obj, ShapeComponent comp)
        {
            Transform transform = obj.transform;

            attr.Colour    = ShapeComponent.ConvertColour(comp.Colour);
            attr.X         = transform.localPosition.x;
            attr.Y         = transform.localPosition.y;
            attr.Z         = transform.localPosition.z;
            attr.RotationX = transform.localRotation.x;
            attr.RotationY = transform.localRotation.y;
            attr.RotationZ = transform.localRotation.z;
            attr.RotationW = transform.localRotation.w;
            attr.ScaleX    = transform.localScale.x;
            attr.ScaleY    = attr.ScaleZ = transform.localScale.z;
        }
Пример #8
0
        /// <summary>
        /// Overridden to read information about mesh parts.
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="packet"></param>
        /// <param name="reader"></param>
        /// <returns></returns>
        protected override Error HandleMessage(CreateMessage msg, PacketBuffer packet, BinaryReader reader)
        {
            GameObject obj = null;

            if (msg.ObjectID == 0)
            {
                // Transient object.
                obj = CreateTransient();
            }
            else
            {
                obj = CreateObject(msg.ObjectID);
                if (!obj)
                {
                    // Object already exists.
                    return(new Error(ErrorCode.DuplicateShape, msg.ObjectID));
                }
            }

            ShapeComponent shapeComp = obj.GetComponent <ShapeComponent>();

            if (shapeComp)
            {
                shapeComp.Category    = msg.Category;
                shapeComp.ObjectFlags = msg.Flags;
                shapeComp.Colour      = ShapeComponent.ConvertColour(msg.Attributes.Colour);
            }

            obj.transform.SetParent(Root.transform, false);
            DecodeTransform(msg.Attributes, obj.transform);

            // Read mesh parts.
            ushort meshPartCount = reader.ReadUInt16();

            // Read part IDs
            for (ushort i = 0; i < meshPartCount; ++i)
            {
                Error err = AddMeshPart(obj, reader, i);
                if (err.Failed)
                {
                    return(err);
                }
            }

            foreach (ShapeComponent part in obj.GetComponentsInChildren <ShapeComponent>())
            {
                if (part.gameObject != obj)
                {
                    List <ShapeComponent> parts = null;
                    if (!_registeredParts.TryGetValue(part.ObjectID, out parts))
                    {
                        // Add new list.
                        parts = new List <ShapeComponent>();
                        _registeredParts.Add(part.ObjectID, parts);
                    }

                    parts.Add(part);

                    // Try resolve the mesh part.
                    if (_meshCache != null)
                    {
                        MeshCache.MeshDetails meshDetails = _meshCache.GetEntry(part.ObjectID);
                        if (meshDetails != null && meshDetails.Finalised)
                        {
                            part.Dirty = true;
                            _awaitingFinalisation.Add(part);
                            //SetMesh(part, meshDetails);
                        }
                    }
                }
            }

            return(new Error());
        }