void Start()
    {
        moviemode = GetComponent <MovieMode>();
        if (ControlledObjectList == null)
        {
            ControlledObjectList = new List <List <GameObject> >();
        }

        ControlledObjectList.Clear();
        ControlledObjectList.Add(group0);
        ControlledObjectList.Add(group1);
        ControlledObjectList.Add(group2);
        ControlledObjectList.Add(group3);
        ControlledObjectList.Add(group4);
        ControlledObjectList.Add(group5);

        controlledObjectIndex = Mathf.Clamp(controlledObjectIndex, 0, ControlledObjectList.Count - 1);
        for (int i = 0; i < ControlledObjectList.Count; i++)
        {
            SetControlledObjectActive(ControlledObjectList[i], false);
        }
        SetControlledObjectActive(ControlledObjectList[controlledObjectIndex], true);

        render = WaveVR_Render.Instance;
    }
Esempio n. 2
0
    public void stopCamera()
    {
        if (!mStarted)
        {
            return;
        }

        if (syncPose)
        {
            WaveVR_Utils.Event.Remove("DrawCameraCompleted", OnUpdateCameraCompleted);
            Log.i(LOG_TAG, "Reset WaveVR_Render submit pose");
            WaveVR_Render.ResetPoseUsedOnSubmit();
            Interop.WVR_StopCamera();
            if (mframeBuffer != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(mframeBuffer);
                mframeBuffer = IntPtr.Zero;
            }
            mStarted = false;
        }
        else
        {
            if (mthread != null && mthread.IsAlive)
            {
                toThreadStop = true;
                Log.i(LOG_TAG, "to thread stop");
            }
        }

        Log.i(LOG_TAG, "Release native texture resources");
        WaveVR_Utils.SendRenderEvent(WaveVR_Utils.RENDEREVENTID_ReleaseTexture);
    }
Esempio n. 3
0
    public static void Expand(WaveVR_Render head)
    {
        Log.d(LOG_TAG, "Expand()+");

        if (head.isExpanded)
        {
            //Debug.Log("Expanded");
        }
        head.righteye = head.CreateEye(WVR_Eye.WVR_Eye_Right);
        head.lefteye  = head.CreateEye(WVR_Eye.WVR_Eye_Left);
        head.createDistortion();

        var found = head.GetComponentFromChildren <AudioListener>(OBJ_NAME_EAR);

        if (found == null)
        {
            var earObj = new GameObject(OBJ_NAME_EAR);
            earObj.transform.SetParent(head.transform, false);
            earObj.transform.localPosition = new Vector3(0, 0, -0.01f);  // TODO if 6DOF should be around -0.025f
            earObj.AddComponent <AudioListener>();
            head.ear = earObj;
        }

        head.AddRaycaster();

        head.createLoadingBlack();
        Log.d(LOG_TAG, "Expand()-");
    }
Esempio n. 4
0
    IEnumerator Initialization()
    {
        WaveVR_Render render = null;

        // Check first.  OnConfigurationChanged may already passed.
        while (!isCameraReady || !isGraphicReady)
        {
            //Log.d(TAG, "Coroutine check: isCameraReady=" + isCameraReady + " isGraphicReady" + isGraphicReady, true);

            render = WaveVR_Render.Instance;
            if (render == null)
            {
                yield return(null);

                continue;
            }

            PrepareCameras(render);

            isGraphicReady = render.IsGraphicReady;

            if (!isCameraReady || !isGraphicReady)
            {
                yield return(null);
            }
        }

        Camera.onPreCull              += MyPreCull;
        Camera.onPreRender            += MyPreRender;
        render.onConfigurationChanged += OnConfigurationChanged;

        Log.d(TAG, "RenderMask initialization finished");
    }
Esempio n. 5
0
    void Awake()
    {
        Log.d(LOG_TAG, "Awake()+");
        if (instance == null)
        {
            instance = this;
        }
        else
        {
            Log.w(LOG_TAG, "Render already Awaked");
        }
        synchronizer = new RenderThreadSynchronizer();

        if (globalOrigin >= 0 && globalOrigin <= 3)
        {
            _origin = (WVR_PoseOriginModel)globalOrigin;
            Log.d(LOG_TAG, "Has global tracking space " + _origin);
        }

#if UNITY_EDITOR
        if (!Application.isEditor)
#endif
        {
            if (WaveVR_Init.Instance == null || WaveVR.Instance == null)
            {
                Log.e(LOG_TAG, "Fail to initialize");
            }

            // This command can make sure native's render code are initialized in render thread.
            InitializeGraphic(synchronizer);

            // Setup render values
            uint w = 0, h = 0;
            Interop.WVR_GetRenderTargetSize(ref w, ref h);
            sceneWidth  = (float)w;
            sceneHeight = (float)h;

            projRawL = new float[4] {
                0.0f, 0.0f, 0.0f, 0.0f
            };
            projRawR = new float[4] {
                0.0f, 0.0f, 0.0f, 0.0f
            };

            OnIpdChanged(null);
        }

        // May call eglMakeCurrent inside TextureManager()
        if (textureManager == null)
        {
            textureManager = new TextureManager();
        }

        WaveVR_Utils.IssueEngineEvent(WaveVR_Utils.EngineEventID.HMD_INITIAILZED);

        Screen.sleepTimeout         = SleepTimeout.NeverSleep;
        Application.targetFrameRate = targetFPS;
        Log.d(LOG_TAG, "Awake()-");
    }
Esempio n. 6
0
 void OnDestroy()
 {
     Log.d(LOG_TAG, "OnDestroy()+");
     textureManager = null;
     instance       = null;
     WaveVR_Utils.IssueEngineEvent(WaveVR_Utils.EngineEventID.UNITY_DESTROY);
     Log.d(LOG_TAG, "OnDestroy()-");
 }
Esempio n. 7
0
    void UpdatePose(params object[] args)
    {
        if (lockHMDPosition && needUpdatePose)
        {
            needUpdatePose = false;
            StillPoses[0]  = WaveVR.Instance.hmd.pose.pose;
            WaveVR_Render.SetPoseUsedOnSubmit(StillPoses[0]);
        }

        if (lockHMDPosition && needSmoothMove)
        {
            if (smoothMoveFrame >= smoothMoveFrameCount || smSpline == null)
            {
                smoothMoveFrame = 0;

                // Copy old value
                MovePoses[0] = StillPoses[0];

                SmoothMovePosesFrom = new WVRMatrix(MovePoses[0].PoseMatrix);
                SmoothMovePosesTo   = new WVRMatrix(WaveVR.Instance.hmd.pose.pose.PoseMatrix);

                smSpline = new MatrixSpline(SmoothMovePosesFrom.GetMatrix(), SmoothMovePosesTo.GetMatrix());

                // save a new one
                StillPoses[0] = WaveVR.Instance.hmd.pose.pose;
            }

            smoothMoveFrame++;
            //Log.d("MovieMode", "smoothMoveFrame=" + smoothMoveFrame);

            if (smoothMoveFrame < smoothMoveNoActionFrameCount)
            {
                return;
            }

            int total = smoothMoveFrameCount - smoothMoveNoActionFrameCount;
            int time  = smoothMoveFrame - smoothMoveNoActionFrameCount;

            // This will accelerate the speed.
            if (needSmoothMoveAccelerate && smCurrent != null)
            {
                SmoothMovePosesTo = new WVRMatrix(WaveVR.Instance.hmd.pose.pose.PoseMatrix);
                smSpline.UpdateFromTo(smCurrent, SmoothMovePosesTo.GetMatrix());
            }

            smCurrent = smSpline.Spline(time / (float)total);

            //Log.d("MovieMode", "From=" + SmoothMovePosesFrom.rot + ", To=" + SmoothMovePosesTo.rot + ", lerp=" + rot);

            WVRMatrix wvrMatrix = new WVRMatrix(smCurrent.pos, smCurrent.rot, false);
            MovePoses[0].PoseMatrix       = wvrMatrix.GetWVRMatrix();
            MovePoses[0].RawPose.position = wvrMatrix.GetWVRPosition();
            MovePoses[0].RawPose.rotation = wvrMatrix.GetWVRRotation();

            WaveVR_Render.SetPoseUsedOnSubmit(MovePoses[0]);
        }
    }
Esempio n. 8
0
    public void DisableMovieMode()
    {
        if (!enabled || !lockHMDPosition)
        {
            return;
        }

        lockHMDPosition = false;
        WaveVR_Render.ResetPoseUsedOnSubmit();
    }
Esempio n. 9
0
    private void processVREvent(WVR_Event_t vrEvent)
    {
        // Process events used by plugin
        switch ((WVR_EventType)vrEvent.common.type)
        {
        case WVR_EventType.WVR_EventType_IpdChanged:
        {
            WaveVR_Utils.Event.Send("IpdChanged");
            if (WaveVR_Render.Instance != null)
            {
                WaveVR_Render.Expand(WaveVR_Render.Instance);
            }
        }
        break;

        case WVR_EventType.WVR_EventType_DeviceStatusUpdate:
        {
            WaveVR_Utils.Event.Send("TrackedDeviceUpdated", vrEvent.device.common.type);
        }
        break;

        case WVR_EventType.WVR_EventType_BatteryStatusUpdate:
        {
            WaveVR_Utils.Event.Send("BatteryStatusUpdate");
        }
        break;

        case WVR_EventType.WVR_EventType_LeftToRightSwipe:
        case WVR_EventType.WVR_EventType_RightToLeftSwipe:
        case WVR_EventType.WVR_EventType_DownToUpSwipe:
        case WVR_EventType.WVR_EventType_UpToDownSwipe:
            WaveVR_Utils.Event.Send("SWIPE_EVENT", vrEvent.common.type);
            break;

        case WVR_EventType.WVR_EventType_DeviceRoleChanged:
            if (WaveVR.Instance != null)
            {
                SetLeftHandedMode();
                ResetButtonStates();

                Log.i(LOG_TAG, "processVREvent() Resend connection notification after switching hand.");
                WaveVR.Instance.OnControllerRoleChange();
            }
            break;

        default:
            break;
        }

        // Send event to developer for all kind of event if developer don't want to add callbacks for every event.
        WaveVR_Utils.Event.Send(WaveVR_Utils.Event.ALL_VREVENT, vrEvent);

        // Send event to developer by name.
        WaveVR_Utils.Event.Send(vrEvent.common.type.ToString(), vrEvent);
    }
Esempio n. 10
0
    void MyRenderEye(WaveVR_Render render, WVR_Eye eye, WaveVR_Camera wvrCamera)
    {
        if (eye == WVR_Eye.WVR_Eye_Both)
        {
            return;
        }
        var camera = wvrCamera.GetCamera();

        canvas.worldCamera = camera;
        canvas.renderMode  = RenderMode.ScreenSpaceCamera;
    }
Esempio n. 11
0
    public void updateTexture(IntPtr textureId)
    {
        if (!mStarted)
        {
            Log.w(LOG_TAG, "Camera not start yet");
            return;
        }

        //PrintDebugLog("updateTexture start, syncPose = " + syncPose.ToString() + " updateFramebuffer = " + updateFramebuffer.ToString());

        nativeTextureId = textureId;
        if (WaveVR_Render.Instance != null)
        {
            origin = WaveVR_Render.Instance.origin;
        }

        if (syncPose)
        {
            if (mframeBuffer != IntPtr.Zero)
            {
                uint predictInMs = 0;
                PrintDebugLog("updateTexture frameBuffer and PoseState, predict time:" + predictInMs);

                Interop.WVR_GetFrameBufferWithPoseState(mframeBuffer, camerainfo.size, origin, predictInMs, ref mPoseState);

                PrintDebugLog("Sync camera frame buffer with poseState, timeStamp: " + mPoseState.PoseTimestamp_ns);
                WaveVR_Render.SetPoseUsedOnSubmit(mPoseState);

                PrintDebugLog("send event to draw OpenGL");
                WaveVR_Utils.SendRenderEvent(WaveVR_Utils.RENDEREVENTID_DrawTextureWithBuffer);
            }
        }
        else
        {
            if (updateFramebuffer && (threadframeBuffer != IntPtr.Zero))
            {
                PrintDebugLog("updateFramebuffer camera frame buffer");
                nativeTextureId = textureId;
                PrintDebugLog("send event to draw OpenGL");
                WaveVR_Utils.SendRenderEvent(WaveVR_Utils.RENDEREVENTID_DrawTextureWithBuffer);
                updateFramebuffer = false;
            }
            else
            {
                // thread frame buffer is not updated and native texture is not updated, send complete delegate back
                if (UpdateCameraCompletedDelegate != null)
                {
                    UpdateCameraCompletedDelegate(nativeTextureId);
                }
            }
        }
    }
Esempio n. 12
0
    private void processVREvent(WVR_Event_t vrEvent)
    {
        // Process events used by plugin
        switch ((WVR_EventType)vrEvent.common.type)
        {
        case WVR_EventType.WVR_EventType_IpdUpdate:
        {
            WaveVR_Utils.Event.Send("IpdChanged");
            if (WaveVR_Render.Instance != null)
            {
                WaveVR_Render.Expand(WaveVR_Render.Instance);
            }
        }
        break;

        case WVR_EventType.WVR_EventType_DeviceStatusUpdate:
        {
            WaveVR_Utils.Event.Send("TrackedDeviceUpdated", vrEvent.device.common.type);
        }
        break;

        case WVR_EventType.WVR_EventType_BatteryStatus_Update:
        {
            WaveVR_Utils.Event.Send("BatteryStatus_Update");
        }
        break;

        case WVR_EventType.WVR_EventType_TouchpadSwipe_LeftToRight:
        case WVR_EventType.WVR_EventType_TouchpadSwipe_RightToLeft:
        case WVR_EventType.WVR_EventType_TouchpadSwipe_DownToUp:
        case WVR_EventType.WVR_EventType_TouchpadSwipe_UpToDown:
            WaveVR_Utils.Event.Send("SWIPE_EVENT", vrEvent.common.type);
            break;

        case WVR_EventType.WVR_EventType_Settings_Controller:
            if (WaveVR.Instance != null)
            {
                WaveVR_Controller.SetLeftHandedMode();
                Log.i(LOG_TAG, "Set left-handed mode to " + WaveVR_Controller.IsLeftHanded);
            }
            break;

        default:
            break;
        }

        // Send event to developer for all kind of event if developer don't want to add callbacks for every event.
        WaveVR_Utils.Event.Send(WaveVR_Utils.Event.ALL_VREVENT, vrEvent);

        // Send event to developer by name.
        WaveVR_Utils.Event.Send(vrEvent.common.type.ToString(), vrEvent);
    }
Esempio n. 13
0
    void OnEnable()
    {
        render = (WaveVR_Render)target;

        var resourcePath = GetResourcePath();

#if UNITY_5_0
        logo = Resources.LoadAssetAtPath <Texture2D>(resourcePath + "vivewave_logo_flat.png");
#else
        logo = AssetDatabase.LoadAssetAtPath <Texture2D>(resourcePath + "vivewave_logo_flat.png");
#endif
        Validate();
    }
Esempio n. 14
0
        public override void Uninstall()
        {
            this.Remove <WaveVR_DevicePoseTracker>();
            var render = GetComponent <WaveVR_Render>();

            if (render != null && render.isExpanded)
            {
                WaveVR_Render.Collapse(render);
                render.Destroy();
            }

            base.Uninstall();
        }
Esempio n. 15
0
    void UpdatePose2(object[] args)
    {
        if (lockHMDPosition && needUpdatePose)
        {
            needUpdatePose = false;
            WaveVR_Render.SetPoseUsedOnSubmit(WaveVR.Instance.hmd.pose.pose);
        }

        if (lockHMDPosition && needSmoothMove)
        {
            if (smoothMoveFrame >= smoothMoveFrameCount)
            {
                smoothMoveFrame = 0;

                // Copy old value
                MovePoses[0] = StillPoses[0];

                SmoothMovePosesFrom = new WVRMatrix(MovePoses[0].PoseMatrix);
                SmoothMovePosesTo   = new WVRMatrix(WaveVR.Instance.hmd.pose.pose.PoseMatrix);

                // Record a new one
                StillPoses[0] = WaveVR.Instance.hmd.pose.pose;
            }

            smoothMoveFrame++;
            //Log.d("MovieMode", "smoothMoveFrame=" + smoothMoveFrame);

            if (smoothMoveFrame < smoothMoveNoActionFrameCount)
            {
                return;
            }

            int total = smoothMoveFrameCount - smoothMoveNoActionFrameCount;
            int time  = smoothMoveFrame - smoothMoveNoActionFrameCount;

            var from = SmoothMovePosesFrom.GetMatrix();
            var to   = SmoothMovePosesTo.GetMatrix();
            var pos  = Vector3.Lerp(from.GetPosition(), to.GetPosition(), time / (float)total);
            var rot  = Quaternion.Lerp(from.GetRotation(), to.GetRotation(), time / (float)total);

            //Log.d("MovieMode", "From=" + SmoothMovePosesFrom.rot + ", To=" + SmoothMovePosesTo.rot + ", lerp=" + rot);

            WVRMatrix wvrMatrix = new WVRMatrix(pos, rot, false);
            MovePoses[0].PoseMatrix       = wvrMatrix.GetWVRMatrix();
            MovePoses[0].RawPose.position = wvrMatrix.GetWVRPosition();
            MovePoses[0].RawPose.rotation = wvrMatrix.GetWVRRotation();

            WaveVR_Render.SetPoseUsedOnSubmit(MovePoses[0]);
        }
    }
Esempio n. 16
0
        private static void SetFoveatedRenderingParameterCheck(WVR_Eye eye, float ndcFocalPointX, float ndcFocalPointY, float clearVisionFOV, WVR_PeripheralQuality quality)
        {
            if (eye == WVR_Eye.WVR_Eye_Both || eye == WVR_Eye.WVR_Eye_None)
            {
                throw new System.ArgumentException("Invalid argument: eye (" + eye + ") should be WVR_Eye_Left or WVR_Eye_Right.");
            }

            if (quality < WVR_PeripheralQuality.Low || quality > WVR_PeripheralQuality.High)
            {
                throw new System.ArgumentException("Invalid argument: level (" + quality + ") should be in WVR_PeripheralQuality range.");
            }

            //Log.d(TAG, "eye " + eye + " XY = (" + ndcFocalPointX + ", " + ndcFocalPointY + ", " + clearVisionFOV + ", " + level + ")");
            WaveVR_Render.SetFoveatedRenderingParameter(eye, ndcFocalPointX, ndcFocalPointY, clearVisionFOV, quality);
        }
Esempio n. 17
0
    void PrepareCameras(WaveVR_Render render)
    {
        if (isCameraReady)
        {
            return;
        }

        data.Clear();

        if (render.IsSinglePass)
        {
            if (render.botheyes == null)
            {
                return;
            }

            Data d = new Data();
            // both
            d.wvrCamera = WaveVR_Render.Instance.botheyes;
            d.eye       = WVR_Eye.WVR_Eye_Both;
            d.camera    = d.wvrCamera.GetCamera();
            data.Add(d);
        }
        else
        {
            if (render.lefteye == null || render.righteye == null)
            {
                return;
            }

            Data d = new Data();
            // left
            d.wvrCamera = WaveVR_Render.Instance.lefteye;
            d.eye       = WVR_Eye.WVR_Eye_Left;
            d.camera    = d.wvrCamera.GetCamera();
            data.Add(d);

            // right
            d           = new Data();
            d.eye       = WVR_Eye.WVR_Eye_Right;
            d.wvrCamera = WaveVR_Render.Instance.righteye;
            d.camera    = d.wvrCamera.GetCamera();
            data.Add(d);
        }

        isCameraReady = true;
    }
Esempio n. 18
0
    private WaveVR()
    {
        PrintInfoLog("WaveVR()+ commit: " + WaveVR_COMMITINFO.wavevr_version);
        {
            WVR_InitError error = Interop.WVR_Init(WVR_AppType.WVR_AppType_VRContent);
            if (error != WVR_InitError.WVR_InitError_None)
            {
                ReportError(error);
                Interop.WVR_Quit();
                this.Initialized = false;
                PrintErrorLog("WaveVR() initialize simulator failed, WVR_Quit()");
                return;
            }
            WaveVR_Utils.notifyActivityUnityStarted();
        }

        this.Initialized = true;
        PrintInfoLog("WaveVR() initialization succeeded.");
#if !UNITY_EDITOR
        UnityPlayerSettingsStereoRenderingPath = WaveVR_Render.IsVRSinglePassBuildTimeSupported()? WaveVR_Render.StereoRenderingPath.SinglePass: WaveVR_Render.StereoRenderingPath.MultiPass;
#else
        UnityPlayerSettingsStereoRenderingPath = (WaveVR_Render.StereoRenderingPath)PlayerSettings.stereoRenderingPath;
#endif
        PrintInfoLog("UnityPlayerSettingsStereoRenderingPath = " + UnityPlayerSettingsStereoRenderingPath);


        for (int i = 0; i < 3; i++)
        {
            poses[i]          = new WVR_DevicePosePair_t();
            isValidPose[i]    = false;          // force update connection status to all listener.
            deviceIndexMap[i] = 0;              // use hmd's id as default.
        }

        hmd             = new Device(WVR_DeviceType.WVR_DeviceType_HMD);
        controllerLeft  = new Device(WVR_DeviceType.WVR_DeviceType_Controller_Left);
        controllerRight = new Device(WVR_DeviceType.WVR_DeviceType_Controller_Right);

        // Check left-handed mode first, then set connection status according to left-handed mode.
        SetLeftHandedMode();
        UpdateAllConnection();
        SetDefaultButtons();

        supportedFeatures = Interop.WVR_GetSupportedFeatures();
        PrintInfoLog("WaveVR() supportedFeatures: " + supportedFeatures);

        PrintInfoLog("WaveVR()-");
    }
Esempio n. 19
0
    void Start()
    {
        Log.d(LOG_TAG, "Start()+");
        var camera = GetComponent <Camera>();

        camera.cullingMask     = CameraGaze ? camera.cullingMask : 0;
        camera.backgroundColor = Color.black;
        camera.clearFlags      = CameraClearFlags.Nothing;
        // Camera.main need this camera to enabled
        camera.enabled = true;
        camera.rect    = new Rect(0.5f - 0.01f, 0.5f - 0.01f, 0.02f, 0.02f);
        camera.tag     = "MainCamera";

        WaveVR_Render.Expand(this);
        configurationChanged = false;
        Log.d(LOG_TAG, "Start()-");
    }
Esempio n. 20
0
    public static void Collapse(WaveVR_Render head)
    {
        if (head.lefteye != null)
        {
            DestroyImmediate(head.lefteye.gameObject);
        }
        head.lefteye = null;

        if (head.righteye != null)
        {
            DestroyImmediate(head.righteye.gameObject);
        }
        head.righteye = null;

        if (head.distortion != null)
        {
            DestroyImmediate(head.distortion.gameObject);
        }
        head.distortion = null;

        Transform ear = head.transform.Find(OBJ_NAME_EAR);

        if (ear != null)
        {
            DestroyImmediate(ear.gameObject);
        }
        ear = null;

        var raycast = head.GetComponent <PhysicsRaycaster>();

        if (raycast != null)
        {
            DestroyImmediate(raycast);
        }
        raycast = null;

        if (head.loadingCanvas != null)
        {
            var loading = head.loadingCanvas.gameObject;
            head.loadingCanvas = null;
            DestroyImmediate(loading);
        }
    }
Esempio n. 21
0
        public override void Install(bool reset)
        {
            base.Install(reset);

            this.WithLock(() =>
            {
                var rend = this.Ensure <WaveVR_Render>();
                if (rend.IsNew)
                {
                    if (!rend.Value.isExpanded)
                    {
                        WaveVR_Render.Expand(rend);
                    }
                    rend.Value.cpuPerfLevel = WaveVR_Utils.WVR_PerfLevel.Maximum;
                    rend.Value.gpuPerfLevel = WaveVR_Utils.WVR_PerfLevel.Maximum;
                }

                rend.Value.origin = WVR_PoseOriginModel.WVR_PoseOriginModel_OriginOnHead;

                var tracker             = this.Ensure <WaveVR_DevicePoseTracker>().Value;
                tracker.type            = WVR_DeviceType.WVR_DeviceType_HMD;
                tracker.trackPosition   = true;
                tracker.EnableNeckModel = true;
                tracker.trackRotation   = true;
                tracker.timing          = WVR_TrackTiming.WhenNewPoses;

#if UNITY_MODULES_AUDIO
#if UNITY_GOOGLE_RESONANCE_AUDIO
                var wasStereo = goog.stereoSpeakerModeEnabled;
                this.Remove <ResonanceAudioListener>();
#endif

                this.Remove <AudioListener>();
                Find.Any(out listener);

#if UNITY_GOOGLE_RESONANCE_AUDIO
                goog = listener.Ensure <ResonanceAudioListener>();
                goog.stereoSpeakerModeEnabled = wasStereo;
#endif
#endif
            });
        }
Esempio n. 22
0
        void CreateTrackedObject(WaveVR_Render render)
        {
            Transform t;

            if (staticTrackedObject != null)
            {
                t = staticTrackedObject.transform;
            }
            else
            {
                t = render.centerWVRCamera.transform.Find(StaticTrackedObjectName);
            }

            if (t == null)
            {
                var obj = new GameObject(StaticTrackedObjectName);
                t = obj.transform;
                t.localPosition = staticFocalPoint;
                t.SetParent(render.centerWVRCamera.transform, false);
            }

            trackedObject = t.gameObject;
        }
Esempio n. 23
0
        protected override void OnSystemSwitch(XRSystem system)
        {
            if (system == XRSystem.Standalone && standaloneCameraGoal)
            {
                this.transform.localPosition = standaloneCameraGoal.localPosition;
                this.transform.localRotation = standaloneCameraGoal.localRotation;
            }
            else if (System == XRSystem.GearVR && gearVRCameraGoal)
            {
                this.transform.localPosition = gearVRCameraGoal.localPosition;
                this.transform.localRotation = gearVRCameraGoal.localRotation;
            }
            else
            {
                this.transform.localPosition = Vector3.zero;
                this.transform.localRotation = Quaternion.identity;
            }

            //if (sensorFusion = GetComponent<XRSensorFusion>())
            //  sensorFusion.enabled = system == XRSystem.GearVR;
            if (mouseLook = GetComponent <XRMouseLook>())
            {
                mouseLook.enabled = system == XRSystem.Standalone;
            }
#if WAVE
            WaveVR_Render waveRender = GetComponentInChildren <WaveVR_Render>();
            if (waveRender)
            {
                waveRender.enabled = system == XRSystem.ViveFocus;
            }
            WaveVR_DevicePoseTracker waveTracker = GetComponentInChildren <WaveVR_DevicePoseTracker>();
            if (waveTracker)
            {
                waveTracker.enabled = system == XRSystem.ViveFocus;
            }
#endif
        }
Esempio n. 24
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        if (logo)
        {
            // Logo need have aspect rate 2:1
            int bannerWidth, bannerHeight;
            bannerWidth  = Screen.width - 35;
            bannerHeight = (int)(bannerWidth / (float)2);
            if (bannerHeight > bannerHeightMax)
            {
                bannerHeight = bannerHeightMax;
                bannerWidth  = bannerHeight * 2;
            }
            var rect = GUILayoutUtility.GetRect(bannerWidth, bannerHeight, GUI.skin.box);
            GUI.DrawTexture(rect, logo, ScaleMode.ScaleToFit);
        }
        EditorGUILayout.PropertyField(script);

        EditorGUILayout.PropertyField(CameraGaze);

        //EditorGUILayout.PropertyField(useSingleBuffer);
        //EditorGUILayout.PropertyField(useCompositor);
        //EditorGUILayout.PropertyField(prediction);
        //EditorGUILayout.PropertyField(textureExpand);
        //EditorGUILayout.PropertyField(targetFPS);
        EditorGUILayout.PropertyField(_origin);
        EditorGUILayout.PropertyField(needTimeControl);
        //EditorGUILayout.PropertyField(useATW);

        if (!Application.isPlaying)
        {
            var expand   = false;
            var collapse = false;

            foreach (WaveVR_Render target in targets)
            {
                if (AssetDatabase.Contains(target))
                {
                    continue;
                }
                if (target.isExpanded)
                {
                    collapse = true;
                }
                else
                {
                    expand = true;
                }
            }

            if (expand)
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Expand"))
                {
                    foreach (WaveVR_Render target in targets)
                    {
                        if (AssetDatabase.Contains(target))
                        {
                            continue;
                        }
                        if (!target.isExpanded)
                        {
                            WaveVR_Render.Expand(target);
                            EditorUtility.SetDirty(target);
                        }
                    }
                }
                GUILayout.Space(18);
                GUILayout.EndHorizontal();
            }

            if (collapse)
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Collapse"))
                {
                    foreach (WaveVR_Render target in targets)
                    {
                        if (AssetDatabase.Contains(target))
                        {
                            continue;
                        }
                        if (target.isExpanded)
                        {
                            WaveVR_Render.Collapse(target);
                            EditorUtility.SetDirty(target);
                        }
                    }
                }
                GUILayout.Space(18);
                GUILayout.EndHorizontal();
            }
        }
        serializedObject.ApplyModifiedProperties();
    }
Esempio n. 25
0
 void signalSurfaceState(string msg)
 {
     WaveVR_Render.signalSurfaceState(msg);
 }
    private void processVREvent(WVR_Event_t vrEvent)
    {
        WVR_DeviceType _type = vrEvent.device.type;
        WVR_InputId    _btn  = vrEvent.input.inputId;

        // Process events used by plugin
        switch ((WVR_EventType)vrEvent.common.type)
        {
        case WVR_EventType.WVR_EventType_IpdChanged:
            WaveVR_Utils.Event.Send(WaveVR_Utils.Event.IPD_CHANGED);
            if (WaveVR_Render.Instance != null)
            {
                WaveVR_Render.Expand(WaveVR_Render.Instance);
            }
            break;

        case WVR_EventType.WVR_EventType_DeviceStatusUpdate:
            WaveVR_Utils.Event.Send(WaveVR_Utils.Event.DEVICE_STATUS_UPDATE, vrEvent.device.common.type);
            break;

        case WVR_EventType.WVR_EventType_BatteryStatusUpdate:
            WaveVR_Utils.Event.Send(WaveVR_Utils.Event.BATTERY_STATUS_UPDATE);
            break;

        case WVR_EventType.WVR_EventType_LeftToRightSwipe:
        case WVR_EventType.WVR_EventType_RightToLeftSwipe:
        case WVR_EventType.WVR_EventType_DownToUpSwipe:
        case WVR_EventType.WVR_EventType_UpToDownSwipe:
            PrintDebugLog("Swipe event: " + (WVR_EventType)vrEvent.common.type);
            WaveVR_Utils.Event.Send(WaveVR_Utils.Event.SWIPE_EVENT, vrEvent.common.type, _type);
            break;

        case WVR_EventType.WVR_EventType_DeviceRoleChanged:
            PrintDebugLog("WVR_EventType_DeviceRoleChanged() " + _type + ", " + _btn + ", Resend connection notification after switching hand.");
            WaveVR.Instance.UpdateAllConnection();
            if (WaveVR.Instance.SetLeftHandedMode())
            {
                // Due to connected, valid pose and role change are not synchronized, DEVICE_ROLE_CHANGED will be obseleted.
                WaveVR_Utils.Event.Send(WaveVR_Utils.Event.DEVICE_ROLE_CHANGED);
                WaveVR.Instance.ResetAllButtonStates();
            }
            break;

        case WVR_EventType.WVR_EventType_ButtonPressed:
            PrintDebugLog("WVR_EventType_ButtonPressed() " + _type + ", " + _btn + ", left-handed? " + WaveVR_Controller.IsLeftHanded);
            if (_type != WVR_DeviceType.WVR_DeviceType_Invalid && WaveVR.Instance.Initialized)
            {
                _type = WaveVR.Instance.getDeviceByType(_type).type;
            }
            WaveVR_Controller.Input(_type).SetEventState_Press(_btn, true);
            break;

        case WVR_EventType.WVR_EventType_ButtonUnpressed:
            PrintDebugLog("WVR_EventType_ButtonUnpressed() " + _type + ", " + _btn + ", left-handed? " + WaveVR_Controller.IsLeftHanded);
            if (_type != WVR_DeviceType.WVR_DeviceType_Invalid && WaveVR.Instance.Initialized)
            {
                _type = WaveVR.Instance.getDeviceByType(_type).type;
            }
            WaveVR_Controller.Input(_type).SetEventState_Press(_btn, false);
            break;

        case WVR_EventType.WVR_EventType_TouchTapped:
            PrintDebugLog("WVR_EventType_TouchTapped() " + _type + ", " + _btn + ", left-handed? " + WaveVR_Controller.IsLeftHanded);
            if (_type != WVR_DeviceType.WVR_DeviceType_Invalid && WaveVR.Instance.Initialized)
            {
                _type = WaveVR.Instance.getDeviceByType(_type).type;
            }
            WaveVR_Controller.Input(_type).SetEventState_Touch(_btn, true);
            break;

        case WVR_EventType.WVR_EventType_TouchUntapped:
            PrintDebugLog("WVR_EventType_TouchUntapped() " + _type + ", " + _btn + ", left-handed? " + WaveVR_Controller.IsLeftHanded);
            if (_type != WVR_DeviceType.WVR_DeviceType_Invalid && WaveVR.Instance.Initialized)
            {
                _type = WaveVR.Instance.getDeviceByType(_type).type;
            }
            WaveVR_Controller.Input(_type).SetEventState_Touch(_btn, false);
            break;

        case WVR_EventType.WVR_EventType_DeviceConnected:
            PrintDebugLog("WVR_EventType_DeviceConnected() " + _type + ", left-handed? " + WaveVR_Controller.IsLeftHanded);
            WaveVR.Instance.SetConnectionStatus(_type, true);
            break;

        case WVR_EventType.WVR_EventType_DeviceDisconnected:
            PrintDebugLog("WVR_EventType_DeviceDisconnected() " + _type + ", left-handed? " + WaveVR_Controller.IsLeftHanded);
            WaveVR.Instance.SetConnectionStatus(_type, false);
            if (_type != WVR_DeviceType.WVR_DeviceType_Invalid)
            {
                _type = WaveVR_Controller.Input(_type).DeviceType;
                WaveVR_Controller.Input(_type).ResetButtonEvents();
            }
            break;

        default:
            break;
        }

        // Send event to developer for all kind of event if developer don't want to add callbacks for every event.
        WaveVR_Utils.Event.Send(WaveVR_Utils.Event.ALL_VREVENT, vrEvent);

        // Send event to developer by name.
        WaveVR_Utils.Event.Send(vrEvent.common.type.ToString(), vrEvent);
    }
Esempio n. 27
0
    private IEnumerator RenderLoop()
    {
        var wait = new WaitForEndOfFrame();

        yield return(wait);

        Log.d(LOG_TAG, "RenderLoop() is started");
        var tim = Time.time;

#if UNITY_EDITOR
        if (!Application.isEditor)
#endif
        {
            // Restart ATW thread before rendering.
            while (!WaveVR_Utils.WVR_IsATWActive())
            {
                yield return(wait);

                if (surfaceChanged && isNeedTimeout == false)
                {
                    break;
                }
                if (Time.time - tim > 1.0f)
                {
                    Log.w(LOG_TAG, "Waiting for surface change is timeout.");
                    break;
                }
            }
            // Reset isNeedTimeout flag
            isNeedTimeout = false;

            if (textureManager != null)
            {
                if (!textureManager.validate())
                {
                    textureManager.reset();
                }
            }
        }
        Log.d(LOG_TAG, "First frame");
        WaveVR_Utils.IssueEngineEvent(WaveVR_Utils.EngineEventID.FIRST_FRAME);

        setLoadingCanvas(false);
        Log.d(LOG_TAG, "RenderLoop() is running");

        while (true)
        {
            Log.gpl.d(LOG_TAG, "RenderLoop() is still running");
            WaveVR_Utils.Trace.BeginSection("RenderLoop", false);
#if UNITY_EDITOR
            if (Application.isEditor)
            {
                WaveVR_Utils.Event.Send(WaveVR_Utils.Event.NEW_POSES, new WVR_DevicePosePair_t[0], new WaveVR_Utils.RigidTransform[0]);
                WaveVR_Utils.Event.Send(WaveVR_Utils.Event.AFTER_NEW_POSES);
                textureManager.Next();
            }
            else
#endif
            {
                WaveVR.Instance.UpdatePoses(origin);
                // Set next texture before running any graphic command.
                textureManager.Next();
            }

            if (configurationChanged)
            {
                WaveVR_Render.Expand(this);
                configurationChanged = false;
            }

            RenderEye(lefteye.getCamera(), WVR_Eye.WVR_Eye_Left);
            RenderEye(righteye.getCamera(), WVR_Eye.WVR_Eye_Right);
            WaveVR_Utils.Trace.EndSection(false);

            // Put here to control the time of next frame.
            TimeControl();

            Log.gpl.d(LOG_TAG, "End of frame");
            yield return(wait);
        }
    }
 private void InitDynamicResolution(WaveVR_Render waveVR_Render)
 {
     DefineLowerBound();
     SetListLowerBound();
     isInitialized = true;
 }
Esempio n. 29
0
    private void processVREvent(WVR_Event_t vrEvent)
    {
        WVR_DeviceType _type = vrEvent.device.type;
        WVR_InputId    _btn  = vrEvent.input.inputId;

        // Process events used by plugin
        switch ((WVR_EventType)vrEvent.common.type)
        {
        case WVR_EventType.WVR_EventType_IpdChanged:
        {
            WaveVR_Utils.Event.Send("IpdChanged");
            if (WaveVR_Render.Instance != null)
            {
                WaveVR_Render.Expand(WaveVR_Render.Instance);
            }
        }
        break;

        case WVR_EventType.WVR_EventType_DeviceStatusUpdate:
        {
            WaveVR_Utils.Event.Send("TrackedDeviceUpdated", vrEvent.device.common.type);
        }
        break;

        case WVR_EventType.WVR_EventType_BatteryStatusUpdate:
        {
            WaveVR_Utils.Event.Send("BatteryStatusUpdate");
        }
        break;

        case WVR_EventType.WVR_EventType_LeftToRightSwipe:
        case WVR_EventType.WVR_EventType_RightToLeftSwipe:
        case WVR_EventType.WVR_EventType_DownToUpSwipe:
        case WVR_EventType.WVR_EventType_UpToDownSwipe:
            Log.i(LOG_TAG, "Swipe event: " + (WVR_EventType)vrEvent.common.type);
            WaveVR_Utils.Event.Send(WaveVR_Utils.Event.SWIPE_EVENT, vrEvent.common.type, _type);
            break;

        case WVR_EventType.WVR_EventType_DeviceRoleChanged:
            Log.i(LOG_TAG, "WVR_EventType_DeviceRoleChanged() " + _type + ", " + _btn + ", Resend connection notification after switching hand.");
            WaveVR.Instance.SetConnectionStatus();
            if (WaveVR.Instance.SetLeftHandedMode())
            {
                WaveVR_Utils.Event.Send(WaveVR_Utils.Event.DEVICE_ROLE_CHANGED);
                WaveVR.Instance.ResetAllButtonStates();
            }
            break;

        case WVR_EventType.WVR_EventType_ButtonPressed:
            Log.d(LOG_TAG, "WVR_EventType_ButtonPressed() " + _type + ", " + _btn + ", left-handed? " + WaveVR_Controller.IsLeftHanded);
            if (_type != WVR_DeviceType.WVR_DeviceType_Invalid && WaveVR.Instance != null)
            {
                _type = WaveVR.Instance.getDeviceByType(_type).type;
            }
            WaveVR_Controller.Input(_type).SetEventState_Press(_btn, true);
            break;

        case WVR_EventType.WVR_EventType_ButtonUnpressed:
            Log.d(LOG_TAG, "WVR_EventType_ButtonUnpressed() " + _type + ", " + _btn + ", left-handed? " + WaveVR_Controller.IsLeftHanded);
            if (_type != WVR_DeviceType.WVR_DeviceType_Invalid && WaveVR.Instance != null)
            {
                _type = WaveVR.Instance.getDeviceByType(_type).type;
            }
            WaveVR_Controller.Input(_type).SetEventState_Press(_btn, false);
            break;

        case WVR_EventType.WVR_EventType_TouchTapped:
            Log.d(LOG_TAG, "WVR_EventType_TouchTapped() " + _type + ", " + _btn + ", left-handed? " + WaveVR_Controller.IsLeftHanded);
            if (_type != WVR_DeviceType.WVR_DeviceType_Invalid && WaveVR.Instance != null)
            {
                _type = WaveVR.Instance.getDeviceByType(_type).type;
            }
            WaveVR_Controller.Input(_type).SetEventState_Touch(_btn, true);
            break;

        case WVR_EventType.WVR_EventType_TouchUntapped:
            Log.d(LOG_TAG, "WVR_EventType_TouchUntapped() " + _type + ", " + _btn + ", left-handed? " + WaveVR_Controller.IsLeftHanded);
            if (_type != WVR_DeviceType.WVR_DeviceType_Invalid && WaveVR.Instance != null)
            {
                _type = WaveVR.Instance.getDeviceByType(_type).type;
            }
            WaveVR_Controller.Input(_type).SetEventState_Touch(_btn, false);
            break;

        case WVR_EventType.WVR_EventType_DeviceConnected:
            Log.d(LOG_TAG, "WVR_EventType_DeviceConnected() " + _type + ", left-handed? " + WaveVR_Controller.IsLeftHanded);
            WaveVR.Instance.SetConnectionStatus(_type, true);
            break;

        case WVR_EventType.WVR_EventType_DeviceDisconnected:
            Log.d(LOG_TAG, "WVR_EventType_DeviceDisconnected() " + _type + ", left-handed? " + WaveVR_Controller.IsLeftHanded);
            WaveVR.Instance.SetConnectionStatus(_type, false);
            break;

        default:
            break;
        }

        // Send event to developer for all kind of event if developer don't want to add callbacks for every event.
        WaveVR_Utils.Event.Send(WaveVR_Utils.Event.ALL_VREVENT, vrEvent);

        // Send event to developer by name.
        WaveVR_Utils.Event.Send(vrEvent.common.type.ToString(), vrEvent);
    }
Esempio n. 30
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        if (logo)
        {
            // Logo need have aspect rate 2:1
            int bannerWidth, bannerHeight;
            bannerWidth  = Screen.width - 35;
            bannerHeight = (int)(bannerWidth / (float)2);
            if (bannerHeight > bannerHeightMax)
            {
                bannerHeight = bannerHeightMax;
                bannerWidth  = bannerHeight * 2;
            }
            var rect = GUILayoutUtility.GetRect(bannerWidth, bannerHeight, GUI.skin.box);
            GUI.DrawTexture(rect, logo, ScaleMode.ScaleToFit);
        }

        if (!Application.isPlaying)
        {
            var expand   = false;
            var collapse = false;

            if (render.isExpanded)
            {
                collapse = true;
            }
            else
            {
                expand = true;
            }

            if (expand)
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Expand"))
                {
                    if (!render.isExpanded)
                    {
                        WaveVR_Render.Expand(render);
                        EditorUtility.SetDirty(render);
                    }
                }
                GUILayout.EndHorizontal();
            }

            if (collapse)
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Collapse"))
                {
                    if (render.isExpanded)
                    {
                        WaveVR_Render.Collapse(render);
                        EditorUtility.SetDirty(render);
                    }
                }
                GUILayout.EndHorizontal();
            }
        }
        serializedObject.ApplyModifiedProperties();

        EditorGUI.BeginChangeCheck();
        DrawDefaultInspector();
        if (EditorGUI.EndChangeCheck())
        {
            Validate();
        }
    }