Пример #1
0
    private void SetChild()
    {
        if (Child == null || Child.gameObject == null || _tracking == null || _trackedObject == null)
        {
            if (Child == null)
            {
                var nameObject = gameObject.name + "_transmittedPosition";
                Child = transform.Find(name);
                if (Child == null)
                {
                    var go = new GameObject
                    {
                        name = nameObject
                    };
                    go.transform.parent = transform;
                    Child = go.transform;
                }
            }

            _tracking = transform.parent.GetComponent <SteamVrStreamingTrackingDataUsingUdp>();

            _trackedObject        = GetComponent <SteamVR_TrackedObject>();
            _trackedObject.origin = transform.parent;
        }

        Child.localPosition = new Vector3(-PositionOffset.x, PositionOffset.z, PositionOffset.y);
        Child.localRotation = Quaternion.Euler(_tracking.TrackableRotationInitial) * Quaternion.Euler(RotationOffset);
    }
Пример #2
0
    public void TryAlter(ref List <SteamVR_TrackedObject> trackedObjects)
    {
        if (State != LogState.Playing && State != LogState.PlayingPause)
        {
            return;
        }

        TimePlaying += State == LogState.Playing ? Time.unscaledDeltaTime : 0f;
        var thisTime = TimePlaying + _data[0].TimeStamp;
        var end      = true;

        for (var i = _currentPlayIndex; i < _data.Count; i++)
        {
            if (thisTime < _data[i].TimeStamp)
            {
                _currentPlayIndex = i;
                end = false;
                break;
            }
        }
        if (end && State == LogState.Playing)
        {
            _currentPlayIndex = 0;
            TimePlaying       = 0f;
        }

        var lastPlayIndex = _currentPlayIndex == 0 ? 0 : _currentPlayIndex - 1;

        var diffTime = _data[_currentPlayIndex].TimeStamp - _data[lastPlayIndex].TimeStamp;
        var progress = diffTime > 0f ? (thisTime - _data[lastPlayIndex].TimeStamp) / diffTime : 1f;

        var currentData = SteamVrStreamingTrackingDataUsingUdp.FromByteArray <TrackedObjectData>(_data[_currentPlayIndex].TrackedObjData);
        var lastData    = SteamVrStreamingTrackingDataUsingUdp.FromByteArray <TrackedObjectData>(_data[lastPlayIndex].TrackedObjData);

        for (var t = 0; t < currentData.Length; t++)
        {
            var tod = currentData[t];
            if (!lastData.Any(x => x.id == tod.id))
            {
                continue;
            }
            string name;
            if (!_data[_currentPlayIndex].ObjIdToName.TryGetValue(tod.id, out name))
            {
                continue;
            }
            var obj = trackedObjects.FirstOrDefault(to => to.name == name);
            if (obj == null)
            {
                continue;
            }

            var todLast = lastData.First(x => x.id == tod.id);;
            obj.transform.position = Vector3.Lerp(todLast.pos, tod.pos, progress);
            obj.transform.rotation = Quaternion.Lerp(todLast.rot, tod.rot, progress);
        }
    }
Пример #3
0
 public TrackingData(TrackedObjectData[] tod, Dictionary <int, string> idToName, float time)
 {
     TrackedObjData = SteamVrStreamingTrackingDataUsingUdp.ToByteArray(tod);
     ObjIdToName    = idToName;
     TimeStamp      = time;
 }