// Update is called once per frame
    void Update()
    {
        if (deviceData != null)
        {
            foreach (var item in deviceData)
            {
                Tracker tracker = null;
                if (!trackDic.TryGetValue(item.id, out tracker))
                {
                    var ob = GameObject.Instantiate(this.trackerPrefab);
                    ob.name = item.id.ToString();

                    tracker    = ob.GetComponent <Tracker>();
                    tracker.ID = item.id;
                    trackDic.Add(item.id, tracker);
                }

                tracker.trackPos = AliceDataReader.FlipLRHandedPosition(item.data[0], item.data[1], item.data[2]);
                tracker.trackRot = AliceDataReader.FlipLRHandedRotation(item.data[3], item.data[4], item.data[5], item.data[6]);
            }
        }

        if (pwrData != null)
        {
            foreach (var item in pwrData)
            {
                Tracker tracker = null;
                if (!trackDic.TryGetValue(item.id, out tracker))
                {
                    var ob = GameObject.Instantiate(this.trackerPrefab);
                    ob.name = item.id.ToString();

                    tracker    = ob.GetComponent <Tracker>();
                    tracker.ID = item.id;
                    trackDic.Add(item.id, tracker);
                }

                tracker.trackPos = AliceDataReader.FlipLRHandedPosition(item.data[0], item.data[1], item.data[2]);
                tracker.trackRot = AliceDataReader.FlipLRHandedRotation(item.data[3], item.data[4], item.data[5], item.data[6]);
            }
        }

        foreach (var item in sikDataDic)
        {
            Avatar avatar = null;
            if (!avatarDic.TryGetValue(item.Key, out avatar))
            {
                var ob = GameObject.Instantiate(this.avatarPrefab);
                ob.name = "Avatar" + item.Key.ToString();

                avatar    = ob.GetComponent <Avatar>();
                avatar.ID = item.Key;
                avatarDic.Add(item.Key, avatar);
            }

            avatar.sikBVHData = item.Value;
        }
    }
    private void FrameDataReceivedHandle(IntPtr customObject, IntPtr sockRef, IntPtr header, IntPtr data, int len)
    {
        // parsering header
        RTDHeader ver = Marshal.PtrToStructure <RTDHeader>(header);

        //Debug.Log("Received data," + " frameIndex=" + ver.frameIndex + " dataType=" + ver.dataType + " timecode=" + ver.timecode + " payloadLen=" + ver.payloadLen);

        switch (ver.dataType)
        {
        case AliceDataType.ADT_TrackerData:
            break;

        case AliceDataType.ADT_Bvh:
            break;

        case AliceDataType.ADT_RigidBody_Base:      // PWR data in base coordinate
            AliceDataReader.GetTrackingData <TrackingData>(data, len, out pwrData);
            break;

        case AliceDataType.ADT_Glove_Sensor:        // Glove sensor data
            //AliceDataReader.GetTrackingData<GloveSensorData>(data, len, out gloveData);
            break;

        case AliceDataType.ADT_RigidBody:           // device data in model coordinate.
            AliceDataReader.GetTrackingData <TrackingData>(data, len, out deviceData);
            break;

        case AliceDataType.ADT_DeviceData:
            break;

        case AliceDataType.ADT_DeviceCmd:
            break;

        case AliceDataType.ADT_Agent_Delays:
            break;

        case AliceDataType.ADT_AgentRecvFrameRate:
            break;

        case AliceDataType.ADT_CloudHeartBeat:
        case AliceDataType.ADT_DataHeartBeat:
            break;

        case AliceDataType.ADT_SikBvhData:
        {
            int id = AliceDataReader.ReadAvatarID(data);
            sikDataDic[id] = AliceDataReader.ReadAvatarData(data, len);
        }
        break;

        default:
            break;
        }

        //Debug.Log("<color=green>Info: </color>Received data, type:" + dtype.ToString());
    }
    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("<color=green>Info: </color> Connect to remote: " + remoteIP + ", send port:" + sendPort + ", recv port:" + recvPort);
        AliceDataReader.BRConnectRemote(remoteIP, sendPort, recvPort);

        Debug.Log("<color=green>Info: </color> Register callback handler");
        fn = new RealtimeDataCallback(FrameDataReceivedHandle);
        AliceDataReader.BRRegisterRealtimeDataCallback(IntPtr.Zero, fn);

        Debug.Log("<color=green>Info: </color>Initialized");
    }
示例#4
0
    // Update is called once per frame
    void Update()
    {
        boneMaps[0].localRotation = AliceDataReader.FlipBVHHipRotation(sikBVHData.rootData[0], sikBVHData.rootData[1], sikBVHData.rootData[2], sikBVHData.rootData[3]);
        boneMaps[0].localPosition = AliceDataReader.FlipBVHHipPosition(sikBVHData.rootData[4], sikBVHData.rootData[5], sikBVHData.rootData[6]);

        int boneDataCnt = sikBVHData.bWithDisp == 1 ? 7 : 4;
        int boneCnt     = (int)SIKHelper.SikBones.MaxBone - 1;

        for (int i = 0; i < boneCnt; i++)
        {
            int offset = boneDataCnt * i;
            if (sikBVHData.bWithDisp == 1)
            {
                boneMaps[i + 1].localRotation = AliceDataReader.FlipBVHRotation(sikBVHData.data[offset], sikBVHData.data[offset + 1], sikBVHData.data[offset + 2], sikBVHData.data[offset + 3]);
                boneMaps[i + 1].localPosition = AliceDataReader.FlipBVHPosition(sikBVHData.data[offset + 4], sikBVHData.data[offset + 5], sikBVHData.data[offset + 6]);
            }
            else
            {
                boneMaps[i + 1].localRotation = AliceDataReader.FlipBVHRotation(sikBVHData.data[offset], sikBVHData.data[offset + 1], sikBVHData.data[offset + 2], sikBVHData.data[offset + 3]);
            }
        }
    }