コード例 #1
0
    private void OnGetInitPoseCallback(string errorJson, string resultJson)
    {
        if (errorJson != null)
        {
            Debug.LogWarning("[vlUnitySDK] OnGetInitPoseCallback: Failed to get init pose");
            return;
        }

        VLModelTrackerCommands.GetInitPoseResult result =
            VLJsonUtility.FromJson <VLModelTrackerCommands.GetInitPoseResult>(
                resultJson);

        Vector3    position;
        Quaternion orientation;

        VLUnityCameraHelper.VLPoseToCamera(
            new Vector3(result.t[0], result.t[1], result.t[2]),
            new Quaternion(result.q[0], result.q[1], result.q[2], result.q[3]),
            out position, out orientation,
            this.workerBehaviour.flipCoordinateSystemHandedness);

        if (this.initCamera != null)
        {
            this.initCamera.transform.position = position;
            this.initCamera.transform.rotation = orientation;
            this.originalPosition    = position;
            this.originalOrientation = orientation;
            this.ready = true;
        }
        else
        {
            Debug.LogWarning("[vlUnitySDK] OnGetInitPoseCallback: initCamera is null");
        }
    }
コード例 #2
0
    private void OnGetInitPoseCallback(string errorJson, string resultJson)
    {
        if (errorJson != null)
        {
            Debug.LogWarning("[vlUnitySDK] OnGetInitPoseCallback: Failed to get init pose");
            return;
        }

        VLModelTrackerCommands.GetInitPoseResult result =
            VLJsonUtility.FromJson <VLModelTrackerCommands.GetInitPoseResult>(
                resultJson);

        Vector3    position;
        Quaternion orientation;

        VLUnityCameraHelper.VLPoseToCamera(
            new Vector3(result.t[0], result.t[1], result.t[2]),
            new Quaternion(result.q[0], result.q[1], result.q[2], result.q[3]),
            out position, out orientation);

        this.originalPosition    = position;
        this.originalOrientation = orientation;
        this.initPoseReady       = true;
        this.reset = true; // This will set the new pose during the next Update
                           // call
    }
コード例 #3
0
    /// <summary>
    ///  Retrieves the device info object from the AbstractApplication.
    /// </summary>
    /// <returns>
    ///  <c>VLDeviceInfo</c>, if the device info was acquired successfully;
    ///  <c>null</c> otherwise.
    /// </returns>
    public VLDeviceInfo GetDeviceInfo()
    {
        if (this.disposed)
        {
            throw new ObjectDisposedException("VLAbstractApplicationWrapper");
        }

        string        deviceInfo;
        StringBuilder sb = new StringBuilder(65536);

        if (!vlAbstractApplicationWrapper_GetDeviceInfo(this.handle, sb,
                                                        Convert.ToUInt32(sb.Capacity + 1)))
        {
            Debug.LogError("No valid device info returned...");
            return(null);
        }

        deviceInfo = sb.ToString();
        Debug.Log("[vlUnitySDK] DeviceInfoJson: " + deviceInfo);

        VLDeviceInfo devInfo =
            VLJsonUtility.FromJson <VLDeviceInfo>(deviceInfo);

        return(devInfo);
    }
コード例 #4
0
    private void PerformanceInfoHandler(string performanceInfoJson)
    {
        VLPerformanceInfo performanceInfo =
            VLJsonUtility.FromJson <VLPerformanceInfo>(performanceInfoJson);

        if (OnPerformanceInfo != null)
        {
            OnPerformanceInfo(performanceInfo);
        }
    }
コード例 #5
0
    private void TrackingStateHandler(string trackingStateJson)
    {
        VLTrackingState state =
            VLJsonUtility.FromJson <VLTrackingState>(trackingStateJson);

        if (state != null && OnTrackingStates != null)
        {
            OnTrackingStates(state);
        }
    }
コード例 #6
0
    private void OnGetAttributeCallback(string errorJson, string resultJson)
    {
        this.getting = false;

        // The callback might occur after the behaviour was disabled
        if (!this.enabled)
        {
            return;
        }

        if (errorJson != null)
        {
            CommandError error =
                VLJsonUtility.FromJson <CommandError>(errorJson);
            Debug.LogWarning("[vlUnitySDK] OnGetAttributeCallback: " +
                             error.message);
            return;
        }

        GetAttributeResult result =
            VLJsonUtility.FromJson <GetAttributeResult>(resultJson);

        if (this.parameterValue != result.value)
        {
            this.parameterValue = result.value;
            switch (this.internalParameterType)
            {
            case ParameterType.String:
                this.stringValueChangedEvent.Invoke(result.value);
                break;

            case ParameterType.Int:
                this.intValueChangedEvent.Invoke(
                    Convert.ToInt32(result.value, CultureInfo.InvariantCulture));
                this.floatValueChangedEvent.Invoke(
                    Convert.ToSingle(result.value, CultureInfo.InvariantCulture));
                break;

            case ParameterType.Float:
                this.floatValueChangedEvent.Invoke(
                    Convert.ToSingle(result.value, CultureInfo.InvariantCulture));
                break;

            case ParameterType.Bool:
                this.boolValueChangedEvent.Invoke(
                    VLRuntimeParameterBehaviour.ToBoolean(result.value));
                break;

            default:
                Debug.LogWarning("[vlUnitySDK] OnGetAttributeCallback: Unknown parameter type");
                break;
            }
        }
    }
コード例 #7
0
 private void CameraCalibrationDataHandler(string errorJson, string resultJson)
 {
     if (OnCameraCalibrationData != null)
     {
         VLCameraCalibrationAnswer calib =
             VLJsonUtility.FromJson <VLCameraCalibrationAnswer>(resultJson);
         if (calib != null &&
             calib.calibration != null &&
             calib.stateChange.command == "getResults")
         {
             OnCameraCalibrationData(calib.calibration);
         }
     }
 }
コード例 #8
0
 private void GetModelPropertiesHandler(string errorJson, string resultJson)
 {
     if (OnGetModelProperties != null)
     {
         VLModelPropertiesStructure modelProperties = null;
         if (resultJson != null)
         {
             modelProperties =
                 VLJsonUtility.FromJson <VLModelPropertiesStructure>(resultJson);
             OnGetModelProperties(modelProperties.info);
         }
         else
         {
             OnGetModelProperties(null);
         }
     }
 }
コード例 #9
0
    private void CreateTrackerHandler(string errorJson, string resultJson)
    {
        bool hasError = (errorJson != null);

        if (OnTrackerInitializedWithIssues != null)
        {
            VLTrackingIssues errorIssues   = null;
            VLTrackingIssues warningIssues = null;
            if (errorJson != null)
            {
                errorIssues =
                    VLJsonUtility.FromJson <VLTrackingIssues>(errorJson);
            }
            if (resultJson != null)
            {
                warningIssues =
                    VLJsonUtility.FromJson <VLTrackingIssues>(resultJson);
            }

            OnTrackerInitializedWithIssues(errorIssues, warningIssues);
        }

        if (OnTrackerInitialized != null)
        {
            OnTrackerInitialized(errorJson == null);
        }

        // Push the RunTracking command after calling the OnTrackerInitialized
        // event in order to give the user the chance to push commands which
        // will then be executed before the tracking is running.
        // only run if no error has occured...
        if (!hasError)
        {
            this.worker.PushCommand(
                new RunTrackingCmd(),
                DispatchRunTrackingCallback,
                GCHandle.ToIntPtr(this.gcHandle));
        }
        else
        {
            StopTracking();
        }
    }
コード例 #10
0
    private static void DispatchAddModelCallback(
        string description,
        string data,
        System.UInt32 dataSize,
        IntPtr clientData)
    {
        if (description == null)
        {
            return;
        }

        try
        {
            VLModelDeserializationStructure answerStructure =
                VLJsonUtility.FromJson <VLModelDeserializationStructure>(description);

            VLModelTrackableBehaviour trackable =
                (VLModelTrackableBehaviour)GCHandle.FromIntPtr(clientData).Target;

            // free data previously allocated/pinned
            trackable.FreeNextBinaryMemoryBlock();

            if (!String.IsNullOrEmpty(answerStructure.error))
            {
                Debug.Log("[vlUnitySDK] VLModelTrackableBehaviour.DispatchAddModelCallback: Error occurred while adding a model to the tracking system: "
                          + answerStructure.error);
            }

            if (answerStructure.result != null)
            {
                trackable.OnUpdateDeserializationResult(answerStructure.result);
            }
        }
        catch (Exception e) // Catch all exceptions, because this is a callback
                            // invoked from native code
        {
            Debug.LogError("[vlUnitySDK] " + e.GetType().Name + ": " +
                           e.Message);
        }
    }