예제 #1
0
 /// <summary>
 /// Creates an event from an action.
 /// </summary>
 /// <param name="action">The action.</param>
 /// <returns></returns>
 private UpdateElementEvent ToEvent(ElementActionData action)
 {
     switch (action.SchemaType)
     {
         case ElementActionSchemaTypes.BOOL:
         {
             return new UpdateElementBoolEvent
             {
                 ElementHash = _handler.Map.ElementHash(action.ElementId),
                 PropHash = _handler.Map.PropHash(action.Key),
                 Value = (bool)action.Value
             };
         }
         case ElementActionSchemaTypes.COL4:
         {
             return new UpdateElementCol4Event
             {
                 ElementHash = _handler.Map.ElementHash(action.ElementId),
                 PropHash = _handler.Map.PropHash(action.Key),
                 Value = (Col4)action.Value
             };
         }
         case ElementActionSchemaTypes.FLOAT:
         {
             return new UpdateElementFloatEvent
             {
                 ElementHash = _handler.Map.ElementHash(action.ElementId),
                 PropHash = _handler.Map.PropHash(action.Key),
                 Value = (float)action.Value
             };
         }
         case ElementActionSchemaTypes.INT:
         {
             return new UpdateElementIntEvent
             {
                 ElementHash = _handler.Map.ElementHash(action.ElementId),
                 PropHash = _handler.Map.PropHash(action.Key),
                 Value = (int)action.Value
             };
         }
         case ElementActionSchemaTypes.STRING:
         {
             return new UpdateElementStringEvent
             {
                 ElementHash = _handler.Map.ElementHash(action.ElementId),
                 PropHash = _handler.Map.PropHash(action.Key),
                 Value = (string)action.Value
             };
         }
         case ElementActionSchemaTypes.VEC3:
         {
             return new UpdateElementVec3Event
             {
                 ElementHash = _handler.Map.ElementHash(action.ElementId),
                 PropHash = _handler.Map.PropHash(action.Key),
                 Value = (Vec3)action.Value
             };
         }
         default:
         {
             throw new Exception(
                 $"Could not creaate update event for unknown schema type '{action.SchemaType}'.");
         }
     }
 }
예제 #2
0
        /// <summary>
        /// Called when BodyCapture has updated data for a body.
        /// </summary>
        /// <param name="id">Unique ID of the body.</param>
        /// <param name="data">Current data for the body.</param>
        private void Body_OnUpdated(ulong id, BodyCapture.SensorData data)
        {
            if (!_bodyElements.TryGetValue(id, out var bodyElements))
            {
                Log.Error("Body updated, but was never tracked.");
                return;
            }

            if (bodyElements == null)
            {
                return; // This is okay, Elements are in flight.
            }

            if ((DateTime.Now - bodyElements.LastUpdate).TotalMilliseconds < _config.SendIntervalMs)
            {
                return; // Time throttling
            }

            const int stride  = 2;
            var       updates = new ElementActionData[_trackList.Length * stride];

            for (int i = 0, len = _trackList.Length; i < len; i++)
            {
                var jointType = _trackList[i];

                if (!data.JointPositions.ContainsKey(jointType))
                {
                    // If there's invalid data and the body is visible, hide it!
                    if (bodyElements.Visible)
                    {
                        _network.Update(new [] { new ElementActionData
                                                 {
                                                     ElementId  = bodyElements.RootElement.Id,
                                                     Type       = "update",
                                                     SchemaType = "bool",
                                                     Key        = PropVisible,
                                                     Value      = false
                                                 } });
                        bodyElements.Visible = false;
                    }
                    return;
                }

                updates[i * stride] = new ElementActionData
                {
                    ElementId  = bodyElements.JointElements[jointType].Id,
                    Type       = "update",
                    SchemaType = "vec3",
                    Key        = PropPosition,
                    Value      = data.JointPositions[jointType]
                };

                updates[i * stride + 1] = new ElementActionData
                {
                    ElementId  = bodyElements.JointElements[jointType].Id,
                    Type       = "update",
                    SchemaType = "vec3",
                    Key        = PropRotation,
                    Value      = data.JointRotations[jointType]
                };
            }

            // If previously hidden, unhide!
            if (!bodyElements.Visible)
            {
                var tmp = new ElementActionData[updates.Length + 1];
                Array.Copy(updates, tmp, updates.Length);
                updates = tmp;
                updates[updates.Length] = new ElementActionData
                {
                    ElementId  = bodyElements.RootElement.Id,
                    Type       = "update",
                    SchemaType = "bool",
                    Key        = PropVisible,
                    Value      = true
                };
            }

            _network.Update(updates);
            bodyElements.LastUpdate = DateTime.Now;
        }
예제 #3
0
        /// <summary>
        /// Creates an event from an action.
        /// </summary>
        /// <param name="elementHash">The id of the element.</param>
        /// <param name="propHash">The id of the hash.</param>
        /// <param name="action">The action.</param>
        /// <returns></returns>
        private static UpdateElementEvent ToEvent(ushort elementHash, ushort propHash, ElementActionData action)
        {
            switch (action.SchemaType)
            {
            case ElementActionSchemaTypes.BOOL:
            {
                return(new UpdateElementBoolEvent
                    {
                        ElementHash = elementHash,
                        PropHash = propHash,
                        Value = (bool)action.Value
                    });
            }

            case ElementActionSchemaTypes.COL4:
            {
                return(new UpdateElementCol4Event
                    {
                        ElementHash = elementHash,
                        PropHash = propHash,
                        Value = (Col4)action.Value
                    });
            }

            case ElementActionSchemaTypes.FLOAT:
            {
                return(new UpdateElementFloatEvent
                    {
                        ElementHash = elementHash,
                        PropHash = propHash,
                        Value = (float)action.Value
                    });
            }

            case ElementActionSchemaTypes.INT:
            {
                return(new UpdateElementIntEvent
                    {
                        ElementHash = elementHash,
                        PropHash = propHash,
                        Value = (int)action.Value
                    });
            }

            case ElementActionSchemaTypes.STRING:
            {
                return(new UpdateElementStringEvent
                    {
                        ElementHash = elementHash,
                        PropHash = propHash,
                        Value = (string)action.Value
                    });
            }

            case ElementActionSchemaTypes.VEC3:
            {
                return(new UpdateElementVec3Event
                    {
                        ElementHash = elementHash,
                        PropHash = propHash,
                        Value = (Vec3)action.Value
                    });
            }

            default:
            {
                throw new Exception(
                          $"Could not creaate update event for unknown schema type '{action.SchemaType}'.");
            }
            }
        }