コード例 #1
0
        void MqttMsgReceived(object sender, MqttMsgPublishEventArgs e)
        {
            string topic = e.Topic;

            string[] topicComponents = topic.Split('/');
            string   msg             = System.Text.Encoding.UTF8.GetString(e.Message);
//            Debug.Log("Received on topic: " + e.Topic + "[" + (msgReceived++) + "] : " + System.Text.Encoding.UTF8.GetString(e.Message));

            MsgHeader msgHeader = MsgHeader.CreateFromJSON(msg);

            if (msgHeader.type != null && msgHeader.type.Equals("POSE_UPDATE"))
            {
                long pingTime = DateTimeOffset.Now.ToUnixTimeMilliseconds() - msgHeader.sendTime;
//                Debug.Log("Pose event received (ping: " + pingTime + ")");
                int       startIndex = msg.IndexOf("payload\":") + "payload\":".Length;
                PoseEvent pose       = PoseEvent.CreateFromJSON(msg.Substring(startIndex, msg.Length - (startIndex + 1)));
                pose.setAllValuesWithoutValueToNull();
                if (poseCoreEventManager != null)
                {
                    poseCoreEventManager.HandlePoseEvent(pose);
                }
            }
            else
            {
                Debug.Log("Unknown msg received: " + msg);
            }
        }
コード例 #2
0
 public override void OnPoseLost(PoseEvent e)
 {
     if (!IsInvoking("LosePhysicalPose"))
     {
         Invoke("LosePhysicalPose", 0.5f);
     }
 }
コード例 #3
0
        private PoseEffect ParseEffect(BinaryDataReader reader)
        {
            var count  = reader.ReadUInt16();
            var events = new PoseEvent[count];

            for (int i = 0; i < events.Length; i++)
            {
                var ev = new PoseEvent();
                ev.Time = reader.ReadFloat40();
                ev.Type = reader.ReadByte();
                switch (ev.Type)
                {
                case 0:
                    var resnm  = reader.ReadCString();
                    var resver = reader.ReadUInt16();
                    ev.ResRef = new ResourceRef(resnm, resver);
                    ev.Data   = reader.ReadBytes(reader.ReadByte());
                    break;

                case 1:
                    ev.Id = reader.ReadCString();
                    break;

                default:
                    throw new ResourceException("Illegal control event: " + ev.Type);
                }
                events[i] = ev;
            }
            return(new PoseEffect {
                Events = events.ToArray()
            });
        }
コード例 #4
0
    public void Log_OnPose()
    {
        PoseEvent pe = GetLogPoseData();

        // we are using world positions/rotations because the coordinate systems should be aligned
        CurrentSessionEvents.Add(pe);
    }
コード例 #5
0
 private void calculateFloorLevel(PoseEvent pose)
 {
     zeroPointAdjustment.x = lastPose.root.x;
     if (zeroPointAdjustment.y > pose.leftFoot.y)
     {
         zeroPointAdjustment.y = pose.leftFoot.y;
         Debug.Log("zeroPointAdjustment.y = " + zeroPointAdjustment.y);
     }
     if (zeroPointAdjustment.y > pose.rightFoot.y)
     {
         zeroPointAdjustment.y = pose.rightFoot.y;
         Debug.Log("zeroPointAdjustment.y = " + zeroPointAdjustment.y);
     }
 }
コード例 #6
0
 /**
  * Calculates the pelvis & middleSpine positions based on the other points, if they aren't already present
  */
 protected void calculateCalculatedNodes(ref PoseEvent newPose)
 {
     if (newPose.root == null)
     {
         newPose.root   = new PosePosition();
         newPose.root.x = (newPose.rightHip.x + newPose.leftHip.x) / 2;
         newPose.root.y = (newPose.rightHip.y + newPose.leftHip.y) / 2;
     }
     if (newPose.spine3 == null)
     {
         newPose.spine3   = new PosePosition();
         newPose.spine3.x = (newPose.rightHip.x + newPose.leftShoulder.x) / 2;
         newPose.spine3.y = (newPose.leftShoulder.y + newPose.leftHip.y) / 2;
     }
 }
コード例 #7
0
    public void Log_OnAlignment()
    {
        // grab a pose event, and then get the data and put it into a DidAlignment event
        PoseEvent pe = GetLogPoseData();

        Debug.Log("Log_OnAlignment, distDegrees = " + pe.DistDegrees + ", distMeters = " + pe.DistMeters);

        CurrentSessionEvents.Add(
            new DidAlignmentEvent()
        {
            Time             = Time.time,
            Controller       = pe.Controller,
            DistDegrees      = pe.DistDegrees,
            DistMeters       = pe.DistMeters,
            HeadPitchDegrees = pe.HeadPitchDegrees,
            Headset          = pe.Headset,
            UnusedController = pe.UnusedController,
            UnusedHeadset    = pe.UnusedHeadset,
        });
    }
コード例 #8
0
 public void set(PoseEvent poseEvent)
 {
     this.nose          = poseEvent.nose;
     this.leftFoot      = poseEvent.leftFoot;
     this.rightFoot     = poseEvent.rightFoot;
     this.leftEar       = poseEvent.leftEar;
     this.rightEar      = poseEvent.rightEar;
     this.leftElbow     = poseEvent.leftElbow;
     this.rightElbow    = poseEvent.rightElbow;
     this.leftEye       = poseEvent.leftEye;
     this.rightEye      = poseEvent.rightEye;
     this.leftHip       = poseEvent.leftHip;
     this.rightHip      = poseEvent.rightHip;
     this.leftKnee      = poseEvent.leftKnee;
     this.rightKnee     = poseEvent.rightKnee;
     this.leftShoulder  = poseEvent.leftShoulder;
     this.rightShoulder = poseEvent.rightShoulder;
     this.leftWrist     = poseEvent.leftWrist;
     this.rightWrist    = poseEvent.rightWrist;
     this.root          = poseEvent.root;
     this.spine3        = poseEvent.spine3;
 }
コード例 #9
0
    public override void OnPose(PoseEvent e, bool isNew, Vector3 position, Quaternion rotation)
    {
        // Check that the pose is within visible view
        Vector3 screenPos = Camera.main.WorldToViewportPoint(position);

        // Only detect if the OnPose object is detected where the display is
        if (screenPos.x >= -0.25f && screenPos.x <= 1.25f &&
            screenPos.y >= 0f && screenPos.y <= 1f)
        {
            CancelInvoke("LosePhysicalPose");

            if (fingerObject == null)
            {
                // New pose: create the rigidbody object for it
                fingerObject = Instantiate(fingerPrefab, Camera.main.transform);
                fingerObject.transform.position = position;
            }
            else
            {
                // Smooth the motion of the kinematic rigidbody to ensure better
                // collision with buttons
                PositionLerp positionLerp = fingerObject.GetComponent <PositionLerp>();
                if (positionLerp != null)
                {
                    positionLerp.SetTarget(position);
                }
            }
        }
        else
        {
            // Don't loose it too fast as it might come back...
            if (!IsInvoking("LosePhysicalPose"))
            {
                Invoke("LosePhysicalPose", 0.5f);
            }
        }
    }
コード例 #10
0
    void PlayNextFrame(float delta)
    {
        TryPlayEffect();
        ChangeAttack();
        ChangeWeaponTrail();

        if (PoseEvent.ContainsKey(po.Idx))
        {
            //当218发射飞轮,很快返回,还未到219动作时,下次播放219,就得立即取消循环,221 223
            if ((PoseEvent[po.Idx] & (int)PoseEvt.WeaponIsReturned) != 0)
            {
                PoseEvent[po.Idx] &= ~(int)PoseEvt.WeaponIsReturned;
                loop     = false;
                curIndex = po.LoopEnd;
            }
        }

        //有连招.
        if (TestInputLink())
        {
            return;
        }
        if (loop)
        {
            if (curIndex > po.LoopEnd)
            {
                if (curIndex > po.LoopStart)
                {
                    PlayPosEvent();
                    curIndex = po.LoopStart;
                    if (loop)
                    {
                        return;
                    }
                }
                curIndex = po.LoopStart;
            }
        }
        else
        {
            if (curIndex > po.End)
            {
                if (single)
                {
                    Pause = true;
                }
                else
                {
                    posMng.OnActionFinished();
                }
                return;
            }

            if (TheFirstFrame == curIndex)
            {
                ActionEvent.HandlerFirstActionFrame(mOwner, po.Idx);
            }
            if (TheLastFrame == curIndex)
            {
                ActionEvent.HandlerFinalActionFrame(mOwner, po.Idx);
            }
        }

        BoneStatus status = null;

        if (po.SourceIdx == 0)
        {
            status = AmbLoader.CharCommon[curIndex];
        }
        else if (po.SourceIdx == 1)
        {
            status = AmbLoader.FrameBoneAni[CharacterIdx][curIndex];
        }

        if (mOwner.Attr.IsPlayer && FightWnd.Exist)
        {
            FightWnd.Instance.UpdatePoseStatus(po.Idx, curIndex);
        }

        for (int i = 0; i < bo.Count; i++)
        {
            bo[i].localRotation = status.BoneQuat[i];
            if (i == 0)
            {
                bo[i].localPosition = status.BonePos;
            }
        }

        bool IgnoreActionMoves = IgnoreActionMove(po.Idx);

        for (int i = 0; i < dummy.Count; i++)
        {
            if (i == 0)
            {
                if (lastPosIdx == po.Idx)
                {
                    Vector3 targetPos = status.DummyPos[i];
                    Vector3 vec       = transform.rotation * (targetPos - lastDBasePos) * moveScale;
                    if (IgnoreActionMoves)
                    {
                        vec.x = 0;
                        vec.z = 0;
                        vec.y = 0;
                    }
                    else
                    {
                    }
                    moveDelta   += vec;
                    lastDBasePos = targetPos;
                }
            }
            else
            {
                dummy[i].localRotation = status.DummyQuat[i];
                dummy[i].localPosition = status.DummyPos[i];
            }
        }

        lastFrameIndex = curIndex;
        curIndex++;
        lastSource = po.SourceIdx;
        lastPosIdx = po.Idx;
    }
コード例 #11
0
    public void PlayFrame(float timeRatio)
    {
        TryPlayEffect();
        ChangeAttack();
        ChangeWeaponTrail();
        ActionEvent.HandlerActionEvent(owner, po.Idx, curIndex);
        if (PoseEvent.ContainsKey(po.Idx))
        {
            //当218发射飞轮,很快返回,还未到219动作时,下次播放219,就得立即取消循环,221 223
            PoseEvent.Remove(po.Idx);
            loop     = false;
            curIndex = po.LoopEnd;
        }
        if (TestInputLink())
        {
            return;
        }
        if (loop)
        {
            if (LockCurrentFrame)
            {
                if (PoseStraight <= 0.0f)
                {
                    loop             = false;
                    curIndex         = po.LoopEnd + 1;
                    LockCurrentFrame = false;
                    return;
                }
            }

            if (curIndex >= po.LoopEnd)
            {
                LoopCount++;
                PlayPosEvent();
                if (loop)
                {
                    curIndex = po.LoopStart;
                }
                return;
            }
        }
        else
        {
            if (curIndex > po.End)
            {
                posMng.OnActionFinished();
                return;
            }
            if (TheFirstFrame <= curIndex && TheFirstFrame != -1)
            {
                ActionEvent.HandlerFirstActionFrame(mOwner, po.Idx);
                TheFirstFrame = -1;
            }
            if (TheLastFrame <= curIndex && TheLastFrame != -1)
            {
                ActionEvent.HandlerFinalActionFrame(mOwner, po.Idx);
                TheLastFrame = -1;
            }
        }
        //Debug.Log("PlayKeyFrame:" + Time.frameCount);
        //curIndex = targetIndex;
        BoneStatus status     = null;
        BoneStatus lastStatus = null;

        if (lastSource == 0 && AmbLoader.CharCommon.Count > lastFrameIndex && lastFrameIndex >= 0)
        {
            lastStatus = AmbLoader.CharCommon[lastFrameIndex];
        }
        else if (AmbLoader.PlayerAnimation.ContainsKey(owner.UnitId) && AmbLoader.PlayerAnimation[owner.UnitId].Count > lastFrameIndex && lastFrameIndex >= 0)
        {
            lastStatus = AmbLoader.PlayerAnimation[owner.UnitId][lastFrameIndex];
        }
        if (po.SourceIdx == 0)
        {
            status = AmbLoader.CharCommon[curIndex];
        }
        else if (po.SourceIdx == 1)
        {
            status = AmbLoader.PlayerAnimation[owner.UnitId][curIndex];
        }
        else
        {
            status = AmbLoader.GetBoneStatus(po.SourceIdx, owner.UnitId, curIndex);
        }

        if (status != null && lastStatus != null)
        {
            bo[0].localRotation = Quaternion.Slerp(lastStatus.BoneQuat[0], status.BoneQuat[0], timeRatio);
            bo[0].localPosition = Vector3.Lerp(lastStatus.BonePos, status.BonePos, timeRatio);
            for (int i = 1; i < bo.Count; i++)
            {
                bo[i].localRotation = Quaternion.Slerp(lastStatus.BoneQuat[i], status.BoneQuat[i], timeRatio);
            }
        }

        bool IgnoreActionMoves = PoseStatus.IgnoreActionMove(po.Idx);

        if (owner.IsDebugUnit())
        {
            if (OnAnimationFrame != null)
            {
                OnAnimationFrame(po.SourceIdx, po.Idx, curIndex, timeRatio);
            }
            //IgnoreActionMoves = false;
        }

        bool IgnoreActionXZMove = PoseStatus.IgnoreXZMove(po.Idx);

        if (lastStatus != null && status != null)
        {
            if (lastPosIdx == po.Idx)
            {
                Vector3 targetPos = Vector3.Lerp(lastStatus.DummyPos[0], status.DummyPos[0], timeRatio);
                Vector3 vec       = Target.rotation * (targetPos - lastDBasePos) * moveScale;
                if (IgnoreActionMoves)
                {
                    vec.x = 0;
                    vec.z = 0;
                    vec.y = 0;
                }
                else if (IgnoreActionXZMove)
                {
                    vec.x = vec.z = 0;
                }
                moveDelta   += vec;
                lastDBasePos = targetPos;
            }

            for (int i = 1; i < dummy.Count; i++)
            {
                dummy[i].localRotation = Quaternion.Slerp(lastStatus.DummyQuat[i], status.DummyQuat[i], timeRatio);
                dummy[i].localPosition = Vector3.Lerp(lastStatus.DummyPos[i], status.DummyPos[i], timeRatio);
            }
        }
    }
コード例 #12
0
    void PlayNextKeyFrame()
    {
        TryPlayEffect();
        ChangeAttack();
        ChangeWeaponTrail();
        ActionEvent.HandlerActionEvent(owner, po.Idx, curIndex);
        if (PoseEvent.ContainsKey(po.Idx))
        {
            //当218发射飞轮,很快返回,还未到219动作时,下次播放219,就得立即取消循环,221 223
            PoseEvent.Remove(po.Idx);
            loop     = false;
            curIndex = po.LoopEnd;
        }

        //有连招.
        if (TestInputLink())
        {
            return;
        }

        if (loop)
        {
            if (LockCurrentFrame)
            {
                if (PoseStraight <= 0.0f)
                {
                    loop             = false;
                    curIndex         = po.LoopEnd + 1;
                    LockCurrentFrame = false;
                    return;
                }
            }
            if (curIndex > po.LoopEnd)
            {
                if (curIndex > po.LoopStart)
                {
                    LoopCount++;
                    PlayPosEvent();
                    if (loop)
                    {
                        curIndex = po.LoopStart;
                    }
                    return;
                }
                curIndex = po.LoopStart;
            }
        }
        else
        {
            if (curIndex > po.End)
            {
                posMng.OnActionFinished();
                return;
            }

            if (TheFirstFrame <= curIndex && TheFirstFrame != -1)
            {
                ActionEvent.HandlerFirstActionFrame(mOwner, po.Idx);
                TheFirstFrame = -1;
            }
            if (TheLastFrame <= curIndex && TheLastFrame != -1)
            {
                ActionEvent.HandlerFinalActionFrame(mOwner, po.Idx);
                TheLastFrame = -1;
            }
        }
        //Debug.Log("PlayKeyFrame:" + Time.frameCount);
        BoneStatus status = null;

        if (po.SourceIdx == 0)
        {
            status = AmbLoader.CharCommon[curIndex];
        }
        else if (po.SourceIdx == 1)
        {
            status = AmbLoader.PlayerAnimation[owner.UnitId][curIndex];
        }
        else
        {
            status = AmbLoader.GetBoneStatus(po.SourceIdx, owner.UnitId, curIndex);
        }

        //Debug.LogError("play keyframe " + " idx:" + curIndex);
        if (bo.Count != 0)
        {
            bo[0].localRotation = status.BoneQuat[0];
            bo[0].localPosition = status.BonePos;
        }

        for (int i = 1; i < bo.Count; i++)
        {
            bo[i].localRotation = status.BoneQuat[i];
        }

        bool IgnoreActionMoves = PoseStatus.IgnoreActionMove(po.Idx);
        //if (owner.IsDebugUnit())
        //    IgnoreActionMoves = false;
        bool IgnoreActionXZMove = PoseStatus.IgnoreXZMove(po.Idx);

        if (lastPosIdx == po.Idx)
        {
            Vector3 targetPos = status.DummyPos[0];
            Vector3 vec       = Target.rotation * (targetPos - lastDBasePos) * moveScale;
            //如果忽略位移,或者在动作的循环帧中,即第一次从循环头开始播放后,不再计算位移.
            if (IgnoreActionMoves)
            {
                vec.x = 0;
                vec.z = 0;
                vec.y = 0;
            }
            else if (IgnoreActionXZMove)
            {
                vec.x = vec.z = 0;
            }
            moveDelta += vec;
            //if (po.Idx == 151)
            //    Debug.LogError(string.Format("pose:{0} frame:{1} move: x ={2}, y ={3} z = {4}", po.Idx, curIndex, moveDelta.x, moveDelta.y, moveDelta.z));
            lastDBasePos = targetPos;
        }

        for (int i = 1; i < dummy.Count; i++)
        {
            dummy[i].localRotation = status.DummyQuat[i];
            dummy[i].localPosition = status.DummyPos[i];
        }

        lastFrameIndex = curIndex;
        curIndex++;
        lastSource = po.SourceIdx;
        lastPosIdx = po.Idx;
    }
コード例 #13
0
 protected void baseHandlingOfPoseEvent(PoseEvent pose)
 {
     calculateCalculatedNodes(ref pose);
 }
コード例 #14
0
    /**
     * A new posenet event was received
     */
    public void HandlePoseEvent(PoseEvent pose)
    {
//        Debug.Log("PoseEvent handled by PoseCoreEventManager: " + pose);
        baseHandlingOfPoseEvent(pose);
        BodyPositionState currentPose = new BodyPositionState(pose);

        if (onPoseEventReceived != null)
        {
            // Inform all handlers of this event
            onPoseEventReceived(lastPose);
        }

        if (onNosePoseEventReceived != null)
        {
            onNosePoseEventReceived(pose.nose);
        }
        if (onLeftEyePoseEventReceived != null)
        {
            onLeftEyePoseEventReceived(pose.leftEye);
        }
        if (onRightEyePoseEventReceived != null)
        {
            onRightEyePoseEventReceived(pose.rightEye);
        }

        if (onLeftEarPoseEventReceived != null)
        {
            onLeftEarPoseEventReceived(pose.leftEar);
        }
        if (onRightEarPoseEventReceived != null)
        {
            onRightEarPoseEventReceived(pose.rightEar);
        }
        if (onLeftShoulderPoseEventReceived != null)
        {
            onLeftShoulderPoseEventReceived(pose.leftShoulder);
        }
        if (onRightShoulderPoseEventReceived != null)
        {
            onRightShoulderPoseEventReceived(pose.rightShoulder);
        }
        if (onLeftElbowPoseEventReceived != null)
        {
            onLeftElbowPoseEventReceived(pose.leftElbow);
        }
        if (onRightElbowPoseEventReceived != null)
        {
            onRightElbowPoseEventReceived(pose.rightElbow);
        }
        if (onLeftWristPoseEventReceived != null)
        {
            onLeftWristPoseEventReceived(pose.leftWrist);
        }
        if (onRightWristPoseEventReceived != null)
        {
            onRightWristPoseEventReceived(pose.rightWrist);
        }
        if (onLeftHipPoseEventReceived != null)
        {
            onLeftHipPoseEventReceived(pose.leftHip);
        }
        if (onRightHipPoseEventReceived != null)
        {
            onRightHipPoseEventReceived(pose.rightHip);
        }
        if (onLeftKneePoseEventReceived != null)
        {
            onLeftKneePoseEventReceived(pose.leftKnee);
        }
        if (onRightKneePoseEventReceived != null)
        {
            onRightKneePoseEventReceived(pose.rightKnee);
        }
        if (onLeftFootPoseEventReceived != null)
        {
            onLeftFootPoseEventReceived(pose.leftFoot);
        }
        if (onRightFootPoseEventReceived != null)
        {
            onRightFootPoseEventReceived(pose.rightFoot);
        }

        if (onRootPoseEventReceived != null)
        {
            onRootPoseEventReceived(pose.root);
        }
        if (onMiddleSpinePoseEventReceived != null)
        {
            onMiddleSpinePoseEventReceived(pose.spine3);
        }

        processCalcState(currentPose);
        lastPose = currentPose;
    }