Beispiel #1
0
    protected void Start()
    {
        if (MiddleVR.VRClusterMgr.IsCluster() && !MiddleVR.VRClusterMgr.IsServer())
        {
            enabled = false;
            return;
        }

        if (MiddleVR.VRPhysicsMgr == null)
        {
            MiddleVRTools.Log(0, "No PhysicsManager found when creating a cylindrical constraint.");
            return;
        }

        vrPhysicsEngine physicsEngine = MiddleVR.VRPhysicsMgr.GetPhysicsEngine();

        if (physicsEngine == null)
        {
            return;
        }

        if (m_PhysicsConstraint == null)
        {
            m_PhysicsConstraint = physicsEngine.CreateConstraintCylindricalWithUniqueName(name);

            if (m_PhysicsConstraint == null)
            {
                MiddleVRTools.Log(0, "[X] Could not create a cylindrical physics constraint for '"
                                  + name + "'.");
            }
            else
            {
                GC.SuppressFinalize(m_PhysicsConstraint);

                m_MVREventListener = new vrEventListener(OnMVRNodeDestroy);
                m_PhysicsConstraint.AddEventListener(m_MVREventListener);

                m_PhysicsConstraintName = m_PhysicsConstraint.GetName();

                AddConstraint();
            }
        }
    }
    void Start()
    {
        MiddleVRTools.Log(4, "[>] VR Manager Start.");

        InitializeVR();

        // Reset Manager's position so text display is correct.
        transform.position   = new UnityEngine.Vector3(0, 0, 0);
        transform.rotation   = new Quaternion();
        transform.localScale = new UnityEngine.Vector3(1, 1, 1);

        m_Wand = GameObject.Find("VRWand");

        if (ShowFPS)
        {
            guiText.enabled = true;
        }
        else
        {
            guiText.enabled = false;
        }

        if (ShowWand)
        {
            ShowWandGeometry(true);
        }
        else
        {
            ShowWandGeometry(false);
        }

        if (ForceQuality)
        {
#if UNITY_3_4
            QualitySettings.currentLevel = (QualityLevel)ForceQualityIndex;
#else
            QualitySettings.SetQualityLevel(ForceQualityIndex);
#endif
        }

        MiddleVRTools.Log(4, "[<] End of VR Manager Start.");
    }
Beispiel #3
0
    // Update is called once per frame
    void Update()
    {
        if (!attached)
        {
            GameObject node = GameObject.Find(VRParentNode);

            if (VRParentNode.Length == 0)
            {
                MiddleVRTools.Log(0, "[X] AttachToNode: Please specify a valid VRParentNode name.");
            }

            if (node != null)
            {
                Vector3    oldPos = transform.localPosition;
                Quaternion oldRot = transform.localRotation;

                transform.parent = node.transform;

                if (ResetTransformation)
                {
                    transform.localPosition = new Vector3(0, 0, 0);
                    transform.localRotation = new Quaternion(0, 0, 0, 1);
                }
                else
                {
                    transform.localPosition = oldPos;
                    transform.localRotation = oldRot;
                }

                MiddleVRTools.Log(2, "[+] AttachToNode: " + this.name + " attached to : " + node.name);
                attached = true;
            }
            else
            {
                if (m_Searched == false)
                {
                    MiddleVRTools.Log(0, "[X] AttachToNode: Failed to find Game object '" + VRParentNode + "'");
                    m_Searched = true;
                }
            }
        }
    }
Beispiel #4
0
    void TestDisplay()
    {
        // 3D nodes
        vrNode3D       node   = null;
        vrCamera       camera = null;
        vrCameraStereo scam   = null;
        vrScreen       screen = null;
        vrViewport     vp     = null;

        if (MiddleVR.VRDisplayMgr != null)
        {
            node = MiddleVR.VRDisplayMgr.GetNode("HeadNode");
            if (node != null)
            {
                MiddleVRTools.Log("Found HeadNode");
            }

            camera = MiddleVR.VRDisplayMgr.GetCamera("Camera0");
            if (camera != null)
            {
                MiddleVRTools.Log("Found Camera0");
            }

            scam = MiddleVR.VRDisplayMgr.GetCameraStereo("CameraStereo0");
            if (scam != null)
            {
                MiddleVRTools.Log("Found CameraStereo0");
            }

            screen = MiddleVR.VRDisplayMgr.GetScreen("Screen0");
            if (screen != null)
            {
                MiddleVRTools.Log("Found Screen0");
            }

            vp = MiddleVR.VRDisplayMgr.GetViewport("Viewport0");
            if (vp != null)
            {
                MiddleVRTools.Log("Found Viewport0");
            }
        }
    }
Beispiel #5
0
    public override void OnInspectorGUI()
    {
        GUILayout.BeginVertical();

        if (GUILayout.Button("Re-apply VR player settings"))
        {
            ApplyVRSettings();
        }

        if (GUILayout.Button("Pick configuration file"))
        {
            string path = EditorUtility.OpenFilePanel("Please choose MiddleVR configuration file", "", "vrx");
            MiddleVRTools.Log("[+] Picked " + path);
            mgr.ConfigFile = path;
            EditorUtility.SetDirty(mgr);
        }

        DrawDefaultInspector();
        GUILayout.EndVertical();
    }
 // Update is called once per frame
 public void Update()
 {
     if (m_ShareEventScript != null)
     {
         if (m_EventButton == null && MiddleVR.VRDeviceMgr != null)
         {
             m_EventButton = MiddleVR.VRDeviceMgr.GetButtons(m_ShareEventScript.ShareName);
             MiddleVRTools.Log("[+] Acquired shared event button " + m_EventButton.GetName());
         }
         else if (m_EventButton != null)
         {
             if (m_EventButton.IsPressed(0))
             {
                 // Every node receive the event VRCallbackName
                 // this.SendMessage("FinalFunction");
                 m_EventButton.SetPressedState(0, false);
             }
         }
     }
 }
 void DumpOptions()
 {
     MiddleVRTools.Log(3, "[ ] Dumping VRManager's options:");
     MiddleVRTools.Log(3, "[ ] - Config File : " + ConfigFile);
     MiddleVRTools.Log(3, "[ ] - Root Node : " + RootNode);
     MiddleVRTools.Log(3, "[ ] - Template Camera : " + TemplateCamera);
     MiddleVRTools.Log(3, "[ ] - Show Wand : " + ShowWand);
     MiddleVRTools.Log(3, "[ ] - Show FPS  : " + ShowFPS);
     MiddleVRTools.Log(3, "[ ] - Disable Existing Cameras : " + DisableExistingCameras);
     MiddleVRTools.Log(3, "[ ] - Grab Existing Nodes : " + GrabExistingNodes);
     MiddleVRTools.Log(3, "[ ] - Debug Nodes : " + DebugNodes);
     MiddleVRTools.Log(3, "[ ] - Debug Screens : " + DebugScreens);
     MiddleVRTools.Log(3, "[ ] - Quit On Esc : " + QuitOnEsc);
     MiddleVRTools.Log(3, "[ ] - Dont Change Window Geometry : " + DontChangeWindowGeometry);
     MiddleVRTools.Log(3, "[ ] - Simple Cluster : " + SimpleCluster);
     MiddleVRTools.Log(3, "[ ] - Force Quality : " + ForceQuality);
     MiddleVRTools.Log(3, "[ ] - Force QualityIndex : " + ForceQualityIndex);
     MiddleVRTools.Log(3, "[ ] - Change World Scale : " + ChangeWorldScale);
     MiddleVRTools.Log(3, "[ ] - World Scale : " + WorldScale);
 }
Beispiel #8
0
    protected void Update()
    {
        int haptionDeviceId = 0;

        string haptionDeviceNameBase = "Haption" + haptionDeviceId;

        vrButtons buttons = MiddleVR.VRDeviceMgr.GetButtons(haptionDeviceNameBase + ".Buttons");

        for (uint i = 0, iEnd = buttons.GetButtonsNb(); i < iEnd; ++i)
        {
            if (buttons.IsToggled(i, true))
            {
                MiddleVRTools.Log(1, "[+] Haption button '" + i + "' is pressed.");
            }
            else if (buttons.IsToggled(i, false))
            {
                MiddleVRTools.Log(1, "[+] Haption button '" + i + "' is released.");
            }
        }
    }
    // Start
    void Start()
    {
        // Retrieve trackers by name
        m_SourceTracker             = MiddleVR.VRDeviceMgr.GetTracker(m_SourceTrackerName);
        m_DestinationVirtualTracker = MiddleVR.VRDeviceMgr.GetTracker(m_DestinationVirtualTrackerName);

        if (m_SourceTracker == null)
        {
            MiddleVRTools.Log("[X] VirtualTrackerMapping: Error : Can't find tracker '" + m_SourceTrackerName + "'.");
        }
        if (m_DestinationVirtualTracker == null)
        {
            MiddleVRTools.Log("[X] VirtualTrackerMapping: Error : Can't find tracker '" + m_DestinationVirtualTrackerName + "'.");
        }

        if (m_SourceTracker != null && m_DestinationVirtualTracker != null)
        {
            m_Init = true;
        }
    }
    protected void Update()
    {
        var deviceMgr = MiddleVR.VRDeviceMgr;

        if (deviceMgr != null &&
            deviceMgr.IsKeyPressed(MiddleVR.VRK_H))
        {
            if (deviceMgr.IsKeyToggled(MiddleVR.VRK_F))
            {
                Vector3 force = m_Force;

                if (deviceMgr.IsKeyPressed(MiddleVR.VRK_LSHIFT) ||
                    deviceMgr.IsKeyPressed(MiddleVR.VRK_RSHIFT))
                {
                    force = -force;
                }

                m_RigidBody.AddForce(MiddleVRTools.FromUnity(force));

                MiddleVRTools.Log(2, "[ ] ApplyForceTorqueSample: applied force " +
                                  force + " on '" + m_RigidBody.GetName() + "'.");
            }

            if (deviceMgr.IsKeyToggled(MiddleVR.VRK_T))
            {
                Vector3 torque = m_Torque;

                if (deviceMgr.IsKeyPressed(MiddleVR.VRK_LSHIFT) ||
                    deviceMgr.IsKeyPressed(MiddleVR.VRK_RSHIFT))
                {
                    torque = -torque;
                }

                m_RigidBody.AddTorque(MiddleVRTools.FromUnity(torque));

                MiddleVRTools.Log(2, "[ ] ApplyForceTorqueSample: applied torque " +
                                  m_Torque + " on '" + m_RigidBody.GetName() + "'.");
            }
        }
    }
Beispiel #11
0
    void TestWand()
    {
        if (MiddleVR.VRDeviceMgr != null)
        {
            // Getting wand horizontal axis
            float x = MiddleVR.VRDeviceMgr.GetWandHorizontalAxisValue();
            // Getting wand vertical axis
            float y = MiddleVR.VRDeviceMgr.GetWandVerticalAxisValue();

            // Getting state of primary wand button
            bool b0 = MiddleVR.VRDeviceMgr.IsWandButtonPressed(0);

            // Getting toggled state of primary wand button
            // bool t0 = MiddleVR.VRDeviceMgr.IsWandButtonToggled(0);

            if (b0 == true)
            {
                // If primary button is pressed, display wand horizontal axis value
                MiddleVRTools.Log("WandButton 0 pressed! HAxis value: " + x + ", VAxis value: " + y);
            }
        }
    }
Beispiel #12
0
    // Start
    void Start()
    {
        // Retrieve trackers by name
        m_Tracker = MiddleVR.VRDeviceMgr.GetTracker(m_VirtualTrackerName);

        m_Wiimote = MiddleVR.VRDeviceMgr.GetAxis("VRPNAxis0.Axis");

        if (m_Tracker == null)
        {
            MiddleVRTools.Log("[X] VirtualTrackerMapping: Error : Can't find tracker '" + m_VirtualTrackerName + "'.");
        }

        if (m_Wiimote == null)
        {
            MiddleVRTools.Log("[X] Wiimote not found.");
        }

        if (m_Tracker != null && m_Wiimote != null)
        {
            m_Init = true;
        }
    }
Beispiel #13
0
    protected void Start()
    {
        m_ScriptStarted = true;

        if (MiddleVR.VRClusterMgr.IsCluster() && !MiddleVR.VRClusterMgr.IsServer())
        {
            enabled = false;
            return;
        }

        vrPhysicsBody physicsBody = GetComponent <VRPhysicsBody>().PhysicsBody;

        if (physicsBody == null)
        {
            MiddleVRTools.Log(0, "[X] PhysicsBodyManipulator: No PhysicsBody found in '"
                              + name + "'.");

            enabled = false;

            return;
        }

        // Fix incoherent settings.
        if (physicsBody.IsStatic())
        {
            MiddleVRTools.Log(0, "[X] PhysicsBodyManipulator: The body '" +
                              physicsBody.GetName() + "' cannot be manipulated because it is static.");

            // And so we stop to use this script.
            enabled = false;

            return;
        }

        m_PhysicsBodyName = physicsBody.GetName();

        m_DidFirstAttachment = false;
    }
    protected void Start()
    {
        if (MiddleVR.VRPhysicsMgr == null)
        {
            MiddleVRTools.Log(0, "[X] ApplyForceTorqueSample: No PhysicsManager found.");
            enabled = false;
            return;
        }

        VRPhysicsBody body = GetComponent <VRPhysicsBody>();

        m_RigidBody = body.PhysicsBody;

        if (m_RigidBody == null)
        {
            MiddleVRTools.Log(0, "[X] ApplyForceTorqueSample: No rigid body given.");
            enabled = false;
            return;
        }

        m_MVREventListener = new vrEventListener(OnMVRNodeDestroy);
        m_RigidBody.AddEventListener(m_MVREventListener);
    }
    protected void Start()
    {
        if (MiddleVR.VRPhysicsMgr == null)
        {
            MiddleVRTools.Log(0, "[X] PhysicsDeactivateAllContacts: No PhysicsManager found.");
            enabled = false;

            return;
        }

        vrPhysicsEngine physicsEngine = MiddleVR.VRPhysicsMgr.GetPhysicsEngine();

        if (physicsEngine == null)
        {
            MiddleVRTools.Log(0, "[X] PhysicsDeactivateAllContacts: No PhysicsEngine found.");
            enabled = false;

            return;
        }

        physicsEngine.SetActivateContactInfos(false);

        MiddleVRTools.Log(2, "[ ] PhysicsDisableAllContacts: all contacts disabled.");
    }
    // Update is called once per frame
    void Update()
    {
        // Nothing to do for this interaction, everything is done in the kernel

        if (!m_Initialized)
        {
            if (GameObject.Find("VRManager").GetComponent <VRManagerScript>().RootNode != null)
            {
                m_VRRootNode = GameObject.Find("VRManager").GetComponent <VRManagerScript>().RootNode.transform;
            }

            m_Initialized = true;
        }

        if (ElasticRepresentationPrefab == null)
        {
            MiddleVRTools.Log("[X] VRInteractionNavigationElastic error: bad elastic prefab reference");
            return;
        }

        if (m_it.HasNavigationStarted())
        {
            m_ElasticRepresentationObject = (GameObject)GameObject.Instantiate(ElasticRepresentationPrefab);
            m_ElasticRepresentationObject.transform.parent = m_VRRootNode;
            m_ElasticRepresentation = m_ElasticRepresentationObject.GetComponent <VRElasticRepresentation>();
            UpdateElasticRepresentation();
        }
        else if (m_it.IsNavigationRunning())
        {
            UpdateElasticRepresentation();
        }
        else if (m_it.IsNavigationStopped() && m_ElasticRepresentation != null)
        {
            GameObject.Destroy(m_ElasticRepresentationObject);
        }
    }
    // Update is called once per frame
    public void Update()
    {
        if (m_tracker == null && MiddleVR.VRDeviceMgr != null)
        {
            ShareName = "S_" + m_ShareID.ToString();
            m_tracker = MiddleVR.VRDeviceMgr.CreateTracker(ShareName);
            MiddleVRTools.Log("[+] Created shared tracker " + ShareName);
            MiddleVR.VRClusterMgr.AddSynchronizedObject(m_tracker, 1);
        }

        if (MiddleVR.VRClusterMgr.IsServer() && m_tracker != null)
        {
            Vector3    p = transform.position;
            Quaternion q = transform.rotation;

            vrVec3 pos = new vrVec3(p.x, p.y, p.z);
            vrQuat or  = new vrQuat(q.x, q.y, q.z, q.w);

            m_tracker.SetPosition(pos);
            m_tracker.SetOrientation(or);

            //MiddleVRTools.Log("Server pushing data : " + p.z );
        }
    }
Beispiel #18
0
    protected void Init()
    {
        if (RenderMaterial == null)
        {
            RenderMaterial = Resources.Load("OVRLensCorrectionMat", typeof(Material)) as Material;

            if (RenderMaterial == null)
            {
                MiddleVRTools.Log(-1, "[RiftCamera] Failed to load OVRLensCorrectionMat.");
            }
        }

        vrObject oculusDriver = MiddleVR.VRKernel.GetObject("OculusRift Tracker Driver");

        if (oculusDriver == null)
        {
            MiddleVRTools.Log(0, "[RiftCamera] No Oculus Rift driver found!");
            return;
        }

        float DistortionScale = oculusDriver.GetProperty("DistortionScale").GetFloat();
        float AR = oculusDriver.GetProperty("AspectRatio").GetFloat();
        float K0 = oculusDriver.GetProperty("K0").GetFloat();
        float K1 = oculusDriver.GetProperty("K1").GetFloat();
        float K2 = oculusDriver.GetProperty("K2").GetFloat();
        float K3 = oculusDriver.GetProperty("K3").GetFloat();

        float OffsetLensLeft  = oculusDriver.GetProperty("OffsetLensLeft").GetFloat();
        float OffsetLensRight = oculusDriver.GetProperty("OffsetLensRight").GetFloat();

        //print("DistortionScale: " + DistortionScale);
        //print("AspectRatio: " + AR);

        //float LensSeparationDistance = oculusDriver.GetProperty("LensSeparationDistance").GetFloat();

        // Get the distortion scale and aspect ratio to use when calculating distortion shader
        float distortionScale = 1.0f / DistortionScale;
        float aspectRatio     = AR;

        float LensOffsetLeft  = OffsetLensLeft;
        float LensOffsetRight = OffsetLensRight;

        // These values are different in the SDK World Demo; Unity renders each camera to a buffer
        // that is normalized, so we will respect this rule when calculating the distortion inputs
        float NormalizedWidth  = 1.0f;
        float NormalizedHeight = 1.0f;

        _Scale.x        = (NormalizedWidth / 2.0f) * distortionScale;
        _Scale.y        = (NormalizedHeight / 2.0f) * distortionScale * aspectRatio;
        _ScaleIn.x      = (2.0f / NormalizedWidth);
        _ScaleIn.y      = (2.0f / NormalizedHeight) / aspectRatio;
        _HmdWarpParam.x = K0;
        _HmdWarpParam.y = K1;
        _HmdWarpParam.z = K2;
        _HmdWarpParam.w = K3;

        if (name.Contains("Left"))
        {
            float lensOffset = 0.5f + (LensOffsetLeft * 0.5f);
            _Center.x = lensOffset;
        }

        if (name.Contains("Right"))
        {
            float lensOffset = 0.5f + (LensOffsetRight * 0.5f);
            _Center.x = lensOffset;
        }

        _Center.y = 0.5f;

        if (RenderMaterial != null)
        {
            SetMaterialProperties();
        }
        else
        {
            print("NOMAT");
        }

        IsInit = true;
    }
Beispiel #19
0
    // Public methods

    public void Log(string text)
    {
        MiddleVRTools.Log(text);
    }
    protected void Update()
    {
        var deviceMgr = MiddleVR.VRDeviceMgr;

        if (deviceMgr != null &&
            deviceMgr.IsKeyPressed(MiddleVR.VRK_H) &&
            deviceMgr.IsKeyToggled(MiddleVR.VRK_C))
        {
            var physicsMgr = MiddleVR.VRPhysicsMgr;

            if (physicsMgr == null)
            {
                MiddleVRTools.Log(0, "[X] VRChangeAttachedPhysicsBodyIPSISample: No PhysicsManager found.");
                enabled = false;
                return;
            }

            vrPhysicsEngine physicsEngine = physicsMgr.GetPhysicsEngine();

            if (physicsEngine == null)
            {
                return;
            }

            if (!physicsEngine.IsStarted())
            {
                // We have to wait...
                return;
            }

            uint bodiesNb = physicsEngine.GetBodiesNb();

            if (bodiesNb == 0)
            {
                MiddleVRTools.Log(0, "[X] VRChangeAttachedPhysicsBodyIPSISample: No physics body found!");
                return;
            }

            vrPhysicsBody physicsBody = physicsEngine.GetBody(m_PhysicsBodyId);

            MiddleVRTools.Log(2, "[+] VRChangeAttachedPhysicsBodyIPSISample: proposed body id: " +
                              m_PhysicsBodyId + " ('" + (physicsBody != null ? physicsBody.GetName() : "Null") + "').");

            if (physicsBody != null && physicsBody.IsA("PhysicsBodyIPSI"))
            {
                var objId = physicsBody.GetId();

                // As a reminder: static or frozen physics bodies cannot be manipulated.
                MiddleVRTools.Log(2, "[+] VRChangeAttachedPhysicsBodyIPSISample: Is the physics body '" +
                                  objId + "' static? " + (physicsBody.IsStatic() ? "Yes" : "No") + ".");
                MiddleVRTools.Log(2, "[+] VRChangeAttachedPhysicsBodyIPSISample: Is the physics body '" +
                                  objId + "' frozen? " + (physicsBody.IsFrozen() ? "Yes" : "No") + ".");

                var kernel = MiddleVR.VRKernel;


                // Use of "Haption.IPSI.GetManipulationDevicesNb".
                // Param with one vrValue:
                //  + None, so vrValue.NULL_VALUE can be used.
                // Return:
                //  A vrValue that contains a uint.
                //  In case of problem, the vrValue is invalid.

                var getManipDeviceNbRetValue = kernel.ExecuteCommand(
                    "Haption.IPSI.GetManipulationDevicesNb",
                    vrValue.NULL_VALUE);

                if (getManipDeviceNbRetValue.IsNumber())
                {
                    MiddleVRTools.Log(2, "[+] VRChangeAttachedPhysicsBodyIPSISample: " +
                                      getManipDeviceNbRetValue.GetUInt() + " Haption device(s) are connected.");
                }
                else
                {
                    MiddleVRTools.Log(0,
                                      "[X] VRChangeAttachedPhysicsBodyIPSISample: Failed to detect how many Haption devices are connected.");
                }


                // Use of "Haption.IPSI.GetManipulationDeviceName".
                // Param with one vrValue:
                //  + the id of an Haption device (as uint).
                // Return:
                //  A vrValue that contains a string (the name).
                //  In case of problem, the vrValue is invalid.

                var getManipDeviceNamePrmsValue = new vrValue(m_ManipulationDeviceId);

                var getManipDeviceNameRetValue = kernel.ExecuteCommand(
                    "Haption.IPSI.GetManipulationDeviceName",
                    getManipDeviceNamePrmsValue);

                if (getManipDeviceNameRetValue.IsString())
                {
                    MiddleVRTools.Log(2, "[+] VRChangeAttachedPhysicsBodyIPSISample: The name of the Haption device '" +
                                      m_ManipulationDeviceId + "' is '" + getManipDeviceNameRetValue.GetString() + "'.");
                }
                else
                {
                    MiddleVRTools.Log(0, "[X] VRChangeAttachedPhysicsBodyIPSISample: Failed to the find the name of the Haption device '" +
                                      m_ManipulationDeviceId + "'.");
                }


                // Use of "Haption.IPSI.AttachManipulationDeviceToBody".
                // Params with one vrValue:
                //  + 1st arg: the id of an Haption device (as uint),
                //  + 2st arg: the id of a physics body (returned by GetId() on this object).
                // Return:
                //  A vrValue that contains a boolean: True if successfully attached, False otherwise.
                //  In case of problem, the vrValue is invalid.
                //
                // If the attachment failed, the previous attached physics body
                // will remain attached, otherwise it will be detached.
                //
                // It is also possible to add arguments in order to select how
                // the manipulated object will be attached:
                // + 3rd arg: the type of attachment (as uint),
                // + 4th arg: a translation offset for an arbitrary point of attachment (as vrVec3),
                // + 5th arg: a rotation for offset of an arbitrary point of attachment (as vrQuat).
                //
                // The type of attachment can take the following values:
                // + 0: unknown attach point so no attachment will occur,
                // + 1: attachment at the geometric center,
                // + 2: attachment at the center of the axis-aligned bounding box (AABB),
                // + 3: attachment at an arbitrary point that is an offset in
                //      the object coordinate frame.
                //
                // So the 4th and the 5th arguments will be used with type 3
                // (i.e. arbitrary point) but ignored otherwise.
                // If the type 3 is used but the 4th and the 5th arguments are
                // not given, translation will equal to 0 and rotation to identity.
                // If the type 3 is used but the 5th argument is not given,
                // rotation will equal to identity.

                var attachManipDeviceToBodyPrmsValue = vrValue.CreateList();
                attachManipDeviceToBodyPrmsValue.AddListItem(m_ManipulationDeviceId);
                attachManipDeviceToBodyPrmsValue.AddListItem(objId);

                // The previous manipulated physics body (if any), will be
                // automatically detached.
                var attachManipDeviceToBodyRetValue = kernel.ExecuteCommand(
                    "Haption.IPSI.AttachManipulationDeviceToBody",
                    attachManipDeviceToBodyPrmsValue);

                if (attachManipDeviceToBodyRetValue.IsBool())
                {
                    MiddleVRTools.Log(2, "[+] VRChangeAttachedPhysicsBodyIPSISample: Did attachment of the Haption device '" +
                                      m_ManipulationDeviceId + "' to the physics body '" + objId + "' succeeded? " +
                                      (attachManipDeviceToBodyRetValue.GetBool() == true ? "Yes" : "No") + ".");
                }
                else
                {
                    MiddleVRTools.Log(0, "[X] VRChangeAttachedPhysicsBodyIPSISample: Failed to attach the Haption device '" +
                                      m_ManipulationDeviceId + "' to the physics body '" + objId + "'.");
                }

                // Use of "Haption.IPSI.IsManipulationDeviceAttachedToABody".
                // Params with one vrValue:
                //  + the id of an Haption device (as uint).
                // Return:
                //  A vrValue that contains a boolean: True means that the device is attached to a body, False otherwise.
                //  In case of problem, the vrValue is invalid.

                var isManipDeviceAttachedToABodyPrmsValue = new vrValue(m_ManipulationDeviceId);

                var isManipDeviceAttachedToABodyRetValue = kernel.ExecuteCommand(
                    "Haption.IPSI.IsManipulationDeviceAttachedToABody",
                    isManipDeviceAttachedToABodyPrmsValue);

                if (isManipDeviceAttachedToABodyRetValue.IsBool())
                {
                    MiddleVRTools.Log(2, "[+] VRChangeAttachedPhysicsBodyIPSISample: Is the Haption device '" +
                                      m_ManipulationDeviceId + "' attached to a physics body? " +
                                      (isManipDeviceAttachedToABodyRetValue.GetBool() == true ? "Yes" : "No") + ".");
                }
                else
                {
                    MiddleVRTools.Log(0, "[X] VRChangeAttachedPhysicsBodyIPSISample: Failed to check whether the Haption device '" +
                                      m_ManipulationDeviceId + "' is attached to a physics body.");
                }


                // Use of "Haption.IPSI.IsBodyAttachedToAManipulationDevice".
                // Params with one vrValue:
                //  + the id of a physics body (returned by GetId() on this object).
                // Return:
                //  A vrValue that contains a boolean: True means that the body is attached to a manipulation device, False otherwise.
                //  In case of problem, the vrValue is invalid.

                var isBodyAttachedToAManipDevicePrmsValue = new vrValue(objId);

                var isBodyAttachedToAManipDeviceRetValue = kernel.ExecuteCommand(
                    "Haption.IPSI.IsBodyAttachedToAManipulationDevice",
                    isBodyAttachedToAManipDevicePrmsValue);

                if (isBodyAttachedToAManipDeviceRetValue.IsBool())
                {
                    MiddleVRTools.Log(2, "[+] VRChangeAttachedPhysicsBodyIPSISample: Is the physics body '" +
                                      objId + "' attached to a Haption device? " +
                                      (isBodyAttachedToAManipDeviceRetValue.GetBool() == true ? "Yes" : "No") + ".");
                }
                else
                {
                    MiddleVRTools.Log(0, "[X] VRChangeAttachedPhysicsBodyIPSISample: Failed to check whether the physics body " +
                                      objId + " is attached to a Haption device.");
                }


                // Use of "Haption.IPSI.GetIdOfManipulationDeviceAttachedToBody".
                // Params with one vrValue:
                //  + the id of a physics body (returned by GetId() on this object).
                // Return:
                //  A vrValue that contains the id (a uint) of the attached manipulation device.
                //  In case of problem or if the physics body was not attached, the vrValue is invalid.

                var getIdOfManipDeviceAttachedToBodyPrmsValue = new vrValue(objId);

                var getIdOfManipDeviceAttachedToBodyRetValue = kernel.ExecuteCommand(
                    "Haption.IPSI.GetIdOfManipulationDeviceAttachedToBody",
                    getIdOfManipDeviceAttachedToBodyPrmsValue);

                if (getIdOfManipDeviceAttachedToBodyRetValue.IsNumber())
                {
                    MiddleVRTools.Log(2, "[+] VRChangeAttachedPhysicsBodyIPSISample: The physics body '" +
                                      objId + "' is attached to the Haption device '" +
                                      getIdOfManipDeviceAttachedToBodyRetValue.GetNumber() + "'.");
                }
                else
                {
                    MiddleVRTools.Log(0, "[X] VRChangeAttachedPhysicsBodyIPSISample: The physics body '" +
                                      objId + "' does not seem to be attached to a Haption device.");
                }


                // Use of "Haption.IPSI.GetIdOfBodyAttachedToManipulationDevice".
                // Params with one vrValue:
                //  + the id of an Haption device (as uint).
                // Return:
                //  A vrValue that contains the id (returned by vrObject.GetId()) of the attached physics body.
                //  In case of problem or if the device was not attached, the vrValue is invalid.

                var getIdOfBodyAttachedToManipDevicePrmsValue = new vrValue(m_ManipulationDeviceId);

                var getIdOfBodyAttachedToManipDeviceRetValue = kernel.ExecuteCommand(
                    "Haption.IPSI.GetIdOfBodyAttachedToManipulationDevice",
                    getIdOfBodyAttachedToManipDevicePrmsValue);

                if (getIdOfBodyAttachedToManipDeviceRetValue.IsNumber())
                {
                    MiddleVRTools.Log(2, "[+] VRChangeAttachedPhysicsBodyIPSISample: The Haption device '" +
                                      m_ManipulationDeviceId + "' is attached to the physics body '" +
                                      getIdOfBodyAttachedToManipDeviceRetValue.GetNumber() + "'.");
                }
                else
                {
                    MiddleVRTools.Log(0, "[X] VRChangeAttachedPhysicsBodyIPSISample: The Haption device '" +
                                      m_ManipulationDeviceId + "' does not seem to be attached to a physics body.");
                }


                // Use of "Haption.IPSI.DetachManipulationDevice".
                // Params with one vrValue:
                //  + the id of an Haption device (as uint).
                // Return:
                //  A vrValue that contains a boolean: True if successfully detached, False otherwise.
                //  In case of problem, the vrValue is invalid.

                // Please uncomment the code following to try...

                /*
                 * var detachManipDevicePrmsValue = new vrValue(m_ManipulationDeviceId);
                 *
                 * var detachManipDeviceRetValue = kernel.ExecuteCommand(
                 *  "Haption.IPSI.DetachManipulationDevice",
                 *  detachManipDevicePrmsValue);
                 *
                 * if (detachManipDeviceRetValue.IsBool())
                 * {
                 *  MiddleVRTools.Log(2, "[+] VRChangeAttachedPhysicsBodyIPSISample: Did detachment of the Haption device '" +
                 *      m_ManipulationDeviceId + "' succeeded? " +
                 *      (detachManipDeviceRetValue.GetBool() == true ? "Yes" : "No") + ".");
                 * }
                 * else
                 * {
                 *  MiddleVRTools.Log(0, "[X] VRChangeAttachedPhysicsBodyIPSISample: Failed to detach the Haption device '" +
                 *      m_ManipulationDeviceId + "'.");
                 * }
                 */


                // Use of "Haption.IPSI.DetachBodyFromAManipulationDevice".
                // Params with one vrValue:
                //  + the id of a physics body (returned by GetId() on this object).
                // Return:
                //  A vrValue that contains a boolean: True if successfully detached, False otherwise.
                //  In case of problem, the vrValue is invalid.

                // Please uncomment the code following to try...

                /*
                 * var detachBodyFromAManipDevicePrmsValue = new vrValue(objId);
                 *
                 * var detachBodyFromAManipDeviceRetValue = kernel.ExecuteCommand(
                 *  "Haption.IPSI.DetachBodyFromAManipulationDevice",
                 *  detachBodyFromAManipDevicePrmsValue);
                 *
                 * if (detachBodyFromAManipDeviceRetValue.IsBool())
                 * {
                 *  MiddleVRTools.Log(2, "[+] VRChangeAttachedPhysicsBodyIPSISample: Did detachment of the physics body '" +
                 *      objId + "' succeeded? " +
                 *      (detachBodyFromAManipDeviceRetValue.GetBool() == true ? "Yes" : "No") + ".");
                 * }
                 * else
                 * {
                 *  MiddleVRTools.Log(0, "[X] VRChangeAttachedPhysicsBodyIPSISample: Failed to detach the physics body '" +
                 *      objId + "'.");
                 * }
                 */
            }

            m_PhysicsBodyId = (m_PhysicsBodyId + 1) % (bodiesNb);
        }
    }
    protected void Update()
    {
        var deviceMgr = MiddleVR.VRDeviceMgr;

        if (deviceMgr != null)
        {
            var headTracker   = deviceMgr.GetTracker("zSpace.Head.Tracker");
            var stylusTracker = deviceMgr.GetTracker("zSpace.Stylus.Tracker");

            if (headTracker == null || stylusTracker == null)
            {
                MiddleVRTools.Log(0, "[X] No head or stylus tracker found for zSpace. Did you load the driver?");
                enabled = false;
                return;
            }

            bool headTargetIsVisible = headTracker.IsTracked();
            if (headTargetWasVisible != headTargetIsVisible)
            {
                MiddleVRTools.Log(2, "[+] Head is " + (headTargetIsVisible ? "visible" : "invisible") +
                                  " by the zSpace device.");

                headTargetWasVisible = headTargetIsVisible;
            }

            bool stylusTargetIsVisible = stylusTracker.IsTracked();
            if (stylusTargetWasVisible != stylusTargetIsVisible)
            {
                MiddleVRTools.Log(2, "[+] Stylus is " + (stylusTargetIsVisible ? "visible" : "invisible") +
                                  " by the zSpace device.");

                stylusTargetWasVisible = stylusTargetIsVisible;
            }
        }

        var kernel = MiddleVR.VRKernel;

        if (kernel != null && deviceMgr != null)
        {
            if (deviceMgr.IsKeyToggled(MiddleVR.VRK_C))
            {
                Color c = m_UsingLEDColor0 ? m_LEDColor0 : m_LEDColor1;

                vrVec3 proposedColor = new vrVec3(c.r, c.g, c.b);

                MiddleVRTools.Log(2, "[+] Proposed stylus LED color sent to zSpace: ("
                                  + proposedColor.x() + ", " + proposedColor.y() + ", " + proposedColor.z() + ").");

                kernel.ExecuteCommand(
                    "zSpace.SetStylusLEDColor", proposedColor);

                m_UsingLEDColor0 = !m_UsingLEDColor0;

                vrVec3 usedColorAsRGB = GetStylusLEDColor();

                MiddleVRTools.Log(2, "[+] Current zSpace stylus LED color is: ("
                                  + usedColorAsRGB.x() + ", " + usedColorAsRGB.y() + ", " + usedColorAsRGB.z() + ").");
            }

            if (deviceMgr.IsKeyToggled(MiddleVR.VRK_L))
            {
                bool turnOnLight = true;

                if (deviceMgr.IsKeyPressed(MiddleVR.VRK_LSHIFT) || deviceMgr.IsKeyPressed(MiddleVR.VRK_RSHIFT))
                {
                    turnOnLight = false;
                }

                MiddleVRTools.Log(2, "[+] Trying to turn " +
                                  (turnOnLight ? "on" : "off") + " the zSpace stylus LED.");

                kernel.ExecuteCommand(
                    "zSpace.SetStylusLEDAsTurnedOn", turnOnLight);

                vrValue isLEDTurnedOnValue = kernel.ExecuteCommand(
                    "zSpace.IsStylusLEDTurnedOn", null);

                bool isLEDTurnedOn = isLEDTurnedOnValue.GetBool();

                MiddleVRTools.Log(2, "[+] zSpace stylus LED turned on? " +
                                  (isLEDTurnedOn ? "Yes" : "No") + ".");

                if (isLEDTurnedOn)
                {
                    vrVec3 usedColorAsRGB = GetStylusLEDColor();

                    MiddleVRTools.Log(2, "[+] Current zSpace stylus LED color is: ("
                                      + usedColorAsRGB.x() + ", " + usedColorAsRGB.y() + ", " + usedColorAsRGB.z() + "). If set to black, no light will appear!");
                }
            }

            if (deviceMgr.IsKeyToggled(MiddleVR.VRK_V))
            {
                if (deviceMgr.IsKeyPressed(MiddleVR.VRK_LSHIFT) || deviceMgr.IsKeyPressed(MiddleVR.VRK_RSHIFT))
                {
                    // Stop vibration (nothing will happen if the stylus
                    // is not vibrating).

                    MiddleVRTools.Log(2, "[+] Trying to stop zSpace stylus vibration.");

                    kernel.ExecuteCommand(
                        "zSpace.StopStylusVibration", null);
                }
                else
                {
                    // Start vibration.

                    MiddleVRTools.Log(2, "[+] Trying to start zSpace stylus vibration with parameters:\n" +
                                      "- duration vibration: " + m_DurationVibration + " s,\n" +
                                      "- duration between two vibrations: " + m_DurationBetween + " s,\n" +
                                      "- number of vibrations: " + m_NumberOfVibrations + ".");

                    vrValue vibrationValueList = vrValue.CreateList();
                    vibrationValueList.AddListItem(m_DurationVibration);
                    vibrationValueList.AddListItem(m_DurationBetween);
                    vibrationValueList.AddListItem(m_NumberOfVibrations);
                    // It is also possible to set the intensity of the vibration:
                    // pass then a 4th argument with a float between 0.0 and 1.0.
                    //vibrationValueList.AddListItem(1.0f);

                    kernel.ExecuteCommand(
                        "zSpace.StartStylusVibration", vibrationValueList);
                }
            }

            if (deviceMgr.IsKeyToggled(MiddleVR.VRK_T))
            {
                MiddleVRTools.Log(2, "[+] Trying to trigger a default zSpace stylus vibration.");

                kernel.ExecuteCommand(
                    "zSpace.TriggerDefaultStylusVibration",
                    true);  // or false to stop the vibration (if any).
            }
        }
    }
    protected bool AddConstraint()
    {
        vrPhysicsEngine physicsEngine = MiddleVR.VRPhysicsMgr.GetPhysicsEngine();

        if (physicsEngine == null)
        {
            return(false);
        }

        if (m_PhysicsConstraint == null)
        {
            return(false);
        }

        bool addedToSimulation = false;

        // Cannot fail since we require this component.
        VRPhysicsBody body0 = GetComponent <VRPhysicsBody>();

        VRPhysicsBody body1 = null;

        if (m_ConnectedBody != null)
        {
            body1 = m_ConnectedBody.GetComponent <VRPhysicsBody>();
        }

        if (body0.PhysicsBody != null)
        {
            var scaleShearMatrix = MVRTools.ComputeScaleShearMatrixWorld(transform);
            m_PhysicsConstraint.SetPosition(MiddleVRTools.FromUnity(scaleShearMatrix * Anchor));
            m_PhysicsConstraint.SetAxis(MiddleVRTools.FromUnity(Axis));

            m_PhysicsConstraint.SetAngularLowerLimit(m_AngularLimits.Min);
            m_PhysicsConstraint.SetAngularUpperLimit(m_AngularLimits.Max);

            m_PhysicsConstraint.SetAngularReferencePosition(m_AngularZeroPosition);

            m_PhysicsConstraint.SetLinearLowerLimit(m_LinearLimits.Min);
            m_PhysicsConstraint.SetLinearUpperLimit(m_LinearLimits.Max);

            m_PhysicsConstraint.SetLinearReferencePosition(m_LinearZeroPosition);

            m_PhysicsConstraint.SetBody(0, body0.PhysicsBody);
            m_PhysicsConstraint.SetBody(1, body1 != null ? body1.PhysicsBody : null);

            addedToSimulation = physicsEngine.AddConstraint(m_PhysicsConstraint);

            if (addedToSimulation)
            {
                MiddleVRTools.Log(3, "[ ] The constraint '" + m_PhysicsConstraintName +
                                  "' was added to the physics simulation.");
            }
            else
            {
                MiddleVRTools.Log(0, "[X] Failed to add the constraint '" +
                                  m_PhysicsConstraintName + "' to the physics simulation.");
            }
        }
        else
        {
            MiddleVRTools.Log(0, "[X] The PhysicsBody of '" + name +
                              "' for the cylindrical physics constraint '" + m_PhysicsConstraintName +
                              "' is null.");
        }

        return(addedToSimulation);
    }
    // Update is called once per frame
    void Update()
    {
        GameObject directionRefNode = null;
        GameObject nodeToMove       = null;
        GameObject turnNode         = null;

        directionRefNode = GameObject.Find(DirectionReferenceNode);
        nodeToMove       = GameObject.Find(NodeToMove);
        turnNode         = GameObject.Find(TurnAroundNode);

        if (m_SearchedRefNode == false && directionRefNode == null)
        {
            MiddleVRTools.Log("[X] VRWandNavigation: Couldn't find '" + DirectionReferenceNode + "'");
            m_SearchedRefNode = true;
        }

        if (m_SearchedNodeToMove == false && nodeToMove == null)
        {
            MiddleVRTools.Log("[X] VRWandNavigation: Couldn't find '" + NodeToMove + "'");
            m_SearchedNodeToMove = true;
        }

        if (m_SearchedRotationNode == false && TurnAroundNode.Length > 0 && turnNode == null)
        {
            MiddleVRTools.Log("[X] VRWandNavigation: Couldn't find '" + TurnAroundNode + "'");
            m_SearchedRotationNode = true;
        }

        if (directionRefNode != null && nodeToMove != null)
        {
            float speed  = 0.0f;
            float speedR = 0.0f;

            GameObject vrmgr = GameObject.Find("VRManager");
            if (vrmgr != null)
            {
                VRManagerScript script = vrmgr.GetComponent <VRManagerScript>();

                if (script != null)
                {
                    /// FORWARD
                    float forward = script.WandAxisVertical;

                    //MiddleVRTools.Log("Forward: " + forward);

                    float deltaTime = (float)MiddleVR.VRKernel.GetDeltaTime();

                    if (Math.Abs(forward) > 0.1)
                    {
                        speed = forward * NavigationSpeed * deltaTime;
                    }

                    /// ROTATION
                    float rotation = script.WandAxisHorizontal;

                    if (Math.Abs(rotation) > 0.1)
                    {
                        speedR = rotation * RotationSpeed * deltaTime;
                    }

                    /// Computing direction
                    Vector3 translationVector = new Vector3(0, 0, 1);
                    Vector3 tVec = translationVector;
                    Vector3 nVec = new Vector3(tVec.x * speed, tVec.y * speed, tVec.z * speed);

                    Vector3 mVec = directionRefNode.transform.TransformDirection(nVec);

                    if (Fly == false)
                    {
                        mVec.y = 0.0f;
                    }

                    nodeToMove.transform.Translate(mVec, Space.World);

                    if (turnNode != null)
                    {
                        nodeToMove.transform.RotateAround(turnNode.transform.position, new Vector3(0, 1, 0), speedR);
                    }
                    else
                    {
                        nodeToMove.transform.Rotate(new Vector3(0, 1, 0), speedR);
                    }
                }
            }
        }
    }
Beispiel #24
0
 public void Warning(string message)
 {
     MiddleVRTools.Log("[-] " + message);
 }
Beispiel #25
0
 public void Error(string message)
 {
     MiddleVRTools.Log("[X] " + message);
 }
Beispiel #26
0
 public void Info(string message)
 {
     MiddleVRTools.Log("[ ] " + message);
 }
    protected void EnableCollisions(vrPhysicsBody physicsBody0, bool iEnabled)
    {
        bool operationDone = false;

        vrPhysicsBody physicsBody1 = null;

        if (m_ConnectedBody != null)
        {
            if (MiddleVR.VRPhysicsMgr == null)
            {
                return;
            }

            vrPhysicsEngine physicsEngine = MiddleVR.VRPhysicsMgr.GetPhysicsEngine();

            if (physicsEngine == null)
            {
                return;
            }

            physicsBody1 = physicsEngine.GetBody(m_ConnectedBody.GetComponent <VRPhysicsBody>().PhysicsBodyName);

            if (physicsBody1 == null)
            {
                MiddleVRTools.Log(0, "[X] PhysicsEnableCollisions: No PhysicsBody found in the connected body.");
                return;
            }

            operationDone = physicsBody0.EnableCollisionsWith(physicsBody1, iEnabled);
        }
        else
        {
            operationDone = physicsBody0.EnableAllCollisions(iEnabled);
        }

        if (operationDone)
        {
            string againstTxt = (physicsBody1 != null ?
                                 " against object '" + physicsBody1.GetName() + "'" :
                                 " against the world scene"
                                 );

            if (iEnabled)
            {
                MiddleVRTools.Log(2, "[ ] PhysicsEnableCollisions: Enabled collisions for '" +
                                  physicsBody0.GetName() + "'" + againstTxt + ".");
            }
            else
            {
                MiddleVRTools.Log(2, "[ ] PhysicsEnableCollisions: Disabled collisions for '" +
                                  physicsBody0.GetName() + "'" + againstTxt + ".");
            }
        }
        else
        {
            if (iEnabled)
            {
                MiddleVRTools.Log(0, "[X] PhysicsEnableCollisions: Failed to enable collisions for '" +
                                  physicsBody0.GetName() + "'.");
            }
            else
            {
                MiddleVRTools.Log(0, "[X] PhysicsEnableCollisions: Failed to disable collisions for '" +
                                  physicsBody0.GetName() + "'.");
            }
        }
    }
    // Private methods

    void InitializeVR()
    {
        mouseButtons[0] = mouseButtons[1] = mouseButtons[2] = false;

        if (m_displayLog)
        {
            GameObject gui = new GameObject();
            m_GUI = gui.AddComponent("GUIText") as GUIText;
            gui.transform.localPosition = new UnityEngine.Vector3(0.5f, 0.0f, 0.0f);
            m_GUI.pixelOffset           = new UnityEngine.Vector2(15, 0);
            m_GUI.anchor = TextAnchor.LowerCenter;
        }

        MiddleVRTools.IsEditor = Application.isEditor;

        m_isInit = MiddleVRTools.VRInitialize(ConfigFile);

        DumpOptions();

        kernel     = MiddleVR.VRKernel;
        displayMgr = MiddleVR.VRDisplayMgr;

        if (!m_isInit)
        {
            GameObject gui = new GameObject();
            m_GUI = gui.AddComponent("GUIText") as GUIText;
            gui.transform.localPosition = new UnityEngine.Vector3(0.2f, 0.0f, 0.0f);
            m_GUI.pixelOffset           = new UnityEngine.Vector2(0, 0);
            m_GUI.anchor = TextAnchor.LowerLeft;

            string txt = kernel.GetLogString(true);
            print(txt);
            m_GUI.text = txt;

            return;
        }

        if (SimpleCluster)
        {
            SetupSimpleCluster();
        }

        if (ChangeWorldScale)
        {
            displayMgr.SetChangeWorldScale(true);
            displayMgr.SetWorldScale(WorldScale);
        }

        if (DisableExistingCameras)
        {
            Camera[] cameras = GameObject.FindObjectsOfType(typeof(Camera)) as Camera[];

            foreach (Camera cam in cameras)
            {
                if (cam.targetTexture == null)
                {
                    cam.enabled = false;
                }
            }
        }

        MiddleVRTools.CreateNodes(RootNode, DebugNodes, DebugScreens, GrabExistingNodes, TemplateCamera);
        MiddleVRTools.CreateViewportsAndCameras(DontChangeWindowGeometry);

        //AttachCameraCB();

        MiddleVRTools.Log(4, "[<] End of VR initialization script");
    }
Beispiel #29
0
    // Private methods

    void InitializeVR()
    {
        mouseButtons[0] = mouseButtons[1] = mouseButtons[2] = false;

        if (m_displayLog)
        {
            GameObject gui = new GameObject();
            m_GUI = gui.AddComponent("GUIText") as GUIText;
            gui.transform.localPosition = new UnityEngine.Vector3(0.5f, 0.0f, 0.0f);
            m_GUI.pixelOffset           = new UnityEngine.Vector2(15, 0);
            m_GUI.anchor = TextAnchor.LowerCenter;
        }

        MiddleVRTools.IsEditor = Application.isEditor;

        if (MiddleVR.VRKernel != null)
        {
            MiddleVRTools.Log(3, "[ ] VRKernel already alive, reset Unity Manager.");
            MiddleVRTools.VRReset();
            m_isInit = true;
            // Not needed because this is the first execution of this script instance
            // m_isGeometrySet = false;
            m_FirstFrameAfterReset = MiddleVR.VRKernel.GetFrame();
        }
        else
        {
            m_isInit = MiddleVRTools.VRInitialize(ConfigFile);
        }

        // Get AA from vrx configuration file
        //m_AntiAliasingLevel = (int)MiddleVR.VRDisplayMgr.GetAntiAliasing();

        DumpOptions();

        kernel     = MiddleVR.VRKernel;
        displayMgr = MiddleVR.VRDisplayMgr;

        if (!m_isInit)
        {
            GameObject gui = new GameObject();
            m_GUI = gui.AddComponent("GUIText") as GUIText;
            gui.transform.localPosition = new UnityEngine.Vector3(0.2f, 0.0f, 0.0f);
            m_GUI.pixelOffset           = new UnityEngine.Vector2(0, 0);
            m_GUI.anchor = TextAnchor.LowerLeft;

            string txt = kernel.GetLogString(true);
            print(txt);
            m_GUI.text = txt;

            return;
        }

        if (SimpleCluster)
        {
            SetupSimpleCluster();
        }

        if (ChangeWorldScale)
        {
            displayMgr.SetChangeWorldScale(true);
            displayMgr.SetWorldScale(WorldScale);
        }

        if (DisableExistingCameras)
        {
            Camera[] cameras = GameObject.FindObjectsOfType(typeof(Camera)) as Camera[];

            foreach (Camera cam in cameras)
            {
                if (cam.targetTexture == null)
                {
                    cam.enabled = false;
                }
            }
        }

        MiddleVRTools.CreateNodes(RootNode, DebugNodes, DebugScreens, GrabExistingNodes, TemplateCamera);
        MiddleVRTools.CreateViewportsAndCameras(DontChangeWindowGeometry, m_AllowRenderTargetAA);

        //AttachCameraCB();

        MiddleVRTools.Log(4, "[<] End of VR initialization script");
    }
Beispiel #30
0
    // Update is called once per frame
    void Update()
    {
        //MiddleVRTools.Log("VRManagerUpdate");

        if (m_isInit)
        {
            MiddleVRTools.Log(4, "[>] Unity Update - Start");

            if (kernel.GetFrame() >= m_FirstFrameAfterReset + 1 && !m_isGeometrySet && !Application.isEditor)
            {
                if (!DontChangeWindowGeometry)
                {
                    displayMgr.SetUnityWindowGeometry();
                }
                m_isGeometrySet = true;
            }

            kernel.Update();
            UpdateInput();

            if (ShowFPS)
            {
                guiText.text = kernel.GetFPS().ToString("f2");
            }

            MiddleVRTools.UpdateNodes();

            if (m_displayLog)
            {
                string txt = kernel.GetLogString(true);
                print(txt);
                m_GUI.text = txt;
            }

            vrKeyboard keyb = MiddleVR.VRDeviceMgr.GetKeyboard();

            if (keyb != null && keyb.IsKeyToggled(MiddleVR.VRK_F) && (keyb.IsKeyPressed(MiddleVR.VRK_LSHIFT) || keyb.IsKeyPressed(MiddleVR.VRK_RSHIFT)))
            {
                ShowFPS         = !ShowFPS;
                guiText.enabled = ShowFPS;
            }

            if (keyb != null && (keyb.IsKeyToggled(MiddleVR.VRK_W) || keyb.IsKeyToggled(MiddleVR.VRK_Z)) && (keyb.IsKeyPressed(MiddleVR.VRK_LSHIFT) || keyb.IsKeyPressed(MiddleVR.VRK_RSHIFT)))
            {
                ShowWand = !ShowWand;
                ShowWandGeometry(ShowWand);
            }

            DeltaTime = kernel.GetDeltaTime();

            MiddleVRTools.Log(4, "[<] Unity Update - End");
        }
        else
        {
            //Debug.LogWarning("[ ] If you have an error mentionning 'DLLNotFoundException: MiddleVR_CSharp', please restart Unity. If this does not fix the problem, please make sure MiddleVR is in the PATH environment variable.");
        }

        // If QualityLevel changed, we have to reset the Unity Manager
        if (m_NeedDelayedRenderingReset)
        {
            if (m_RenderingResetDelay == 0)
            {
                MiddleVRTools.Log(3, "[ ] Graphic quality forced, reset Unity Manager.");
                MiddleVRTools.VRReset();
                MiddleVRTools.CreateViewportsAndCameras(DontChangeWindowGeometry, m_AllowRenderTargetAA);
                m_isGeometrySet             = false;
                m_NeedDelayedRenderingReset = false;
            }
            else
            {
                --m_RenderingResetDelay;
            }
        }
    }