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

        if (MiddleVR.VRPhysicsMgr == null)
        {
            MiddleVRTools.Log(0, "[X] No PhysicsManager found when creating a prismatic constraint.");
            enabled = false;
            return;
        }

        vrPhysicsEngine physicsEngine = MiddleVR.VRPhysicsMgr.GetPhysicsEngine();

        if (physicsEngine == null)
        {
            return;
        }

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

            if (m_PhysicsConstraint == null)
            {
                MiddleVRTools.Log(0, "[X] Could not create a prismatic 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();
            }
        }
    }
    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] 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);
    }
Exemple #4
0
    private void OnDestroy()
    {
        if (m_EventListener != null)
        {
            m_EventListener.Dispose();
            m_EventListener = null;
        }

        if (m_Node != null && !m_IsNodeGrabbed)
        {
            // Test for VRDisplayMgr existence in case VRManagerScript is destroyed before this script
            if (MiddleVR.VRDisplayMgr != null)
            {
                if (m_SyncDirection != MVRNodesMapper.ENodesSyncDirection.NoSynchronization)
                {
                    MVRNodesMapper.Instance.RemoveMapping(gameObject, false);
                }

                MiddleVR.VRDisplayMgr.DestroyNode(m_Node);
            }

            m_Node = null;
        }
    }
    protected void Start()
    {
        if (MiddleVR.VRClusterMgr.IsCluster() && !MiddleVR.VRClusterMgr.IsServer())
        {
            enabled = false;
            return;
        }

        if (MiddleVR.VRPhysicsMgr == null)
        {
            MiddleVRTools.Log(0, "[X] No PhysicsManager found when creating a planar constraint.");
            enabled = false;
            return;
        }

        vrPhysicsEngine physicsEngine = MiddleVR.VRPhysicsMgr.GetPhysicsEngine();

        if (physicsEngine == null)
        {
            return;
        }

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

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

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

                m_PhysicsConstraintName = m_PhysicsConstraint.GetName();

                AddConstraint();
            }
        }
    }
Exemple #6
0
    protected void Start()
    {
        // Retrieve the VRManager
        VRManagerScript[] foundVRManager = FindObjectsOfType(typeof(VRManagerScript)) as VRManagerScript[];
        if (foundVRManager.Length != 0)
        {
            m_VRManager = foundVRManager[0];
        }
        else
        {
            MVRTools.Log("[X] VRMenu: impossible to retrieve the VRManager.");
            return;
        }

        // Start listening to MiddleVR events
        m_Listener = new vrEventListener(EventListener);
        MiddleVR.VRInteractionMgr.AddEventListener(m_Listener);

        // Create commands

        // General
        m_ResetCurrentButtonCommand   = new vrCommand("VRMenu.ResetCurrentButtonCommand", ResetCurrentButtonHandler);
        m_ResetZeroButtonCommand      = new vrCommand("VRMenu.ResetZeroButtonCommand", ResetZeroButtonHandler);
        m_ExitButtonCommand           = new vrCommand("VRMenu.ExitButtonCommand", ExitButtonHandler);
        m_FramerateCheckboxCommand    = new vrCommand("VRMenu.FramerateCheckboxCommand", FramerateCheckboxHandler);
        m_ProxiWarningCheckboxCommand = new vrCommand("VRMenu.ProxiWarningCheckboxCommand", ProxiWarningCheckboxHandler);

        // Navigation
        m_FlyCheckboxCommand        = new vrCommand("VRMenu.FlyCheckboxCommand", FlyCheckboxHandler);
        m_CollisionsCheckboxCommand = new vrCommand("VRMenu.CollisionsCheckboxCommand", CollisionsCheckboxHandler);

        // Manipulation
        m_ReturnObjectsCheckboxCommand = new vrCommand("VRMenu.ReturnObjectsCheckboxCommand", ReturnObjectsCheckboxHandler);

        // Create GUI
        m_GUIRendererWeb = null;

        VRWebView webViewScript = GetComponent <VRWebView>();

        if (webViewScript == null)
        {
            MVRTools.Log(1, "[X] VRMenu does not have a WebView.");
            return;
        }

        m_GUIRendererWeb = new vrGUIRendererWeb("", webViewScript.webView);

        m_Menu = new vrWidgetMenu("VRMenu.VRManagerMenu", m_GUIRendererWeb);

        // Navigation
        m_NavigationOptions = new vrWidgetMenu("VRMenu.NavigationOptions", m_Menu, "Navigation");

        CreateInteractionToggleButton(MiddleVR.VRInteractionMgr.GetInteraction("InteractionNavigationWandJoystick"), "Joystick", m_NavigationOptions, NavigationJoystickHandler);
        CreateInteractionToggleButton(MiddleVR.VRInteractionMgr.GetInteraction("InteractionNavigationElastic"), "Elastic", m_NavigationOptions, NavigationElasticHandler);
        CreateInteractionToggleButton(MiddleVR.VRInteractionMgr.GetInteraction("InteractionNavigationGrabWorld"), "Grab The World", m_NavigationOptions, NavigationGrabWorldHandler);

        m_NavigationSeparator = new vrWidgetSeparator("VRMenu.NavigationSeparator", m_NavigationOptions);
        m_FlyCheckbox         = new vrWidgetToggleButton("VRMenu.FlyCheckbox", m_NavigationOptions, "Fly", m_FlyCheckboxCommand, m_VRManager.Fly);
        m_CollisionsCheckbox  = new vrWidgetToggleButton("VRMenu.CollisionsCheckbox", m_NavigationOptions, "Navigation Collisions", m_CollisionsCheckboxCommand, m_VRManager.NavigationCollisions);

        // Manipulation
        m_ManipulationOptions = new vrWidgetMenu("VRMenu.ManipulationOptions", m_Menu, "Manipulation");

        CreateInteractionToggleButton(MiddleVR.VRInteractionMgr.GetInteraction("InteractionManipulationRay"), "Ray", m_ManipulationOptions, ManipulationRayHandler);
        CreateInteractionToggleButton(MiddleVR.VRInteractionMgr.GetInteraction("InteractionManipulationHomer"), "Homer", m_ManipulationOptions, ManipulationHomerHandler);

        m_ManipulationSeparator = new vrWidgetSeparator("VRMenu.ManipulationSeparator", m_ManipulationOptions);
        m_ReturnObjectsCheckbox = new vrWidgetToggleButton("VRMenu.ReturnObjectsCheckbox", m_ManipulationOptions, "Return Objects", m_ReturnObjectsCheckboxCommand, m_VRManager.ManipulationReturnObjects);

        // Virtual Hand
        m_VirtualHandOptions = new vrWidgetMenu("VRMenu.VirtualHandOptions", m_Menu, "Virtual Hand");

        CreateInteractionToggleButton(MiddleVR.VRInteractionMgr.GetInteraction("InteractionVirtualHandGogo"), "Gogo", m_VirtualHandOptions, VirtualHandGogoButtonHandler);

        // General
        m_GeneralSeparator = new vrWidgetSeparator("VRMenu.GeneralSeparator", m_Menu);
        m_GeneralOptions   = new vrWidgetMenu("VRMenu.GeneralOptions", m_Menu, "General Options");

        m_FramerateCheckbox    = new vrWidgetToggleButton("VRMenu.FramerateCheckbox", m_GeneralOptions, "Show Frame Rate", m_FramerateCheckboxCommand, m_VRManager.ShowFPS);
        m_ProxiWarningCheckbox = new vrWidgetToggleButton("VRMenu.ProxiWarningCheckbox", m_GeneralOptions, "Show Proximity Warning", m_ProxiWarningCheckboxCommand, m_VRManager.ShowScreenProximityWarnings);

        // Reset and Exit
        m_ResetButtonMenu    = new vrWidgetMenu("VRMenu.ResetButtonMenu", m_Menu, "Reset Simulation");
        m_ResetCurrentButton = new vrWidgetButton("VRMenu.ResetCurrentButton", m_ResetButtonMenu, "Reload current level", m_ResetCurrentButtonCommand);
        m_ResetZeroButton    = new vrWidgetButton("VRMenu.ResetZeroButton", m_ResetButtonMenu, "Reload level zero", m_ResetZeroButtonCommand);

        m_ExitButtonMenu = new vrWidgetMenu("VRMenu.ExitButtonMenu", m_Menu, "Exit Simulation");
        m_ExitButton     = new vrWidgetButton("VRMenu.ExitButton", m_ExitButtonMenu, "Yes, Exit Simulation", m_ExitButtonCommand);
    }
Exemple #7
0
 public void InitializeBaseInteraction()
 {
     m_Listener = new vrEventListener(EventListener);
     MiddleVR.VRInteractionMgr.AddEventListener(m_Listener);
 }
Exemple #8
0
    protected void Start()
    {
        if (MiddleVR.VRClusterMgr.IsCluster() && !MiddleVR.VRClusterMgr.IsServer())
        {
            enabled = false;
            return;
        }

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

        vrPhysicsEngine physicsEngine = MiddleVR.VRPhysicsMgr.GetPhysicsEngine();

        if (physicsEngine == null)
        {
            MiddleVRTools.Log(0, "[X] PhysicsBody: Failed to access a physics engine for body '" + name + "'.");
            enabled = false;
            return;
        }

        if (m_PhysicsBody == null)
        {
            m_PhysicsBody = physicsEngine.CreateBodyWithUniqueName(name);

            if (m_PhysicsBody == null)
            {
                MiddleVRTools.Log(0, "[X] PhysicsBody: Failed to create a physics body for '" + name + "'.");
                enabled = false;
                return;
            }
            else
            {
                GC.SuppressFinalize(m_PhysicsBody);

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

                var nodesMapper = MVRNodesMapper.Instance;

                nodesMapper.AddMapping(
                    gameObject, m_PhysicsBody,
                    MVRNodesMapper.ENodesSyncDirection.MiddleVRToUnity,
                    MVRNodesMapper.ENodesInitValueOrigin.FromUnity);

                m_PhysicsBodyName = m_PhysicsBody.GetName();

                string geometryName = m_PhysicsBodyName + ".Geometry";

                MiddleVRTools.Log(4,
                    "[>] PhysicsBody: Creation of the physics geometry '" +
                    geometryName + "'.");

                m_Geometry = new vrPhysicsGeometry(geometryName);
                GC.SuppressFinalize(m_Geometry);

                Mesh mesh = null;

                MeshCollider meshCollider = GetComponent<MeshCollider>();

                if (meshCollider != null)
                {
                    mesh = meshCollider.sharedMesh;

                    if (mesh != null)
                    {
                        MiddleVRTools.Log(2, "[ ] PhysicsBody: the physics geometry '" + geometryName +
                            "' uses the mesh of its MeshCollider.");
                    }
                }

                // No mesh from collider was found so let's try from the mesh filter.
                if (mesh == null)
                {
                    var meshFilter = GetComponent<MeshFilter>();

                    if (meshFilter != null)
                    {
                        mesh = meshFilter.sharedMesh;

                        if (mesh != null)
                        {
                            MiddleVRTools.Log(2, "[ ] PhysicsBody: the physics geometry '" + geometryName +
                                "' uses the mesh of its MeshFilter.");
                        }
                    }
                }

                if (mesh != null)
                {
                    ConvertGeometry(mesh);
                    MiddleVRTools.Log(4, "[ ] PhysicsBody: Physics geometry created.");
                }
                else
                {
                    MiddleVRTools.Log(
                        0,
                        "[X] PhysicsBody: Failed to create the physics geometry '" +
                        geometryName + "'.");
                }

                MiddleVRTools.Log(4,
                    "[<] PhysicsBody: Creation of the physics geometry '" +
                    geometryName + "' ended.");

                m_PhysicsBody.SetGeometry(m_Geometry);

                m_PhysicsBody.SetStatic(m_Static);
                m_PhysicsBody.SetMass(m_Mass);
                m_PhysicsBody.SetRotationDamping(m_RotationDamping);
                m_PhysicsBody.SetTranslationDamping(m_TranslationDamping);

                m_PhysicsBody.SetMargin(m_Margin);

                if (physicsEngine.AddBody(m_PhysicsBody))
                {
                    MiddleVRTools.Log(3, "[ ] PhysicsBody: The physics body '" + m_PhysicsBodyName +
                        "' was added to the physics simulation.");
                }
                else
                {
                    MiddleVRTools.Log(0, "[X] PhysicsBody: Failed to add the body '" +
                         m_PhysicsBodyName + "' to the physics simulation.");
                }
            }
        }
    }
Exemple #9
0
    protected void Start()
    {
        // Retrieve the VRManager
        VRManagerScript[] foundVRManager = FindObjectsOfType(typeof(VRManagerScript)) as VRManagerScript[];
        if (foundVRManager.Length != 0)
        {
            m_VRManager = foundVRManager[0];
        }
        else
        {
            MVRTools.Log("[X] VRMenu: impossible to retrieve the VRManager.");
            return;
        }

        // Start listening to MiddleVR events
        m_Listener = new vrEventListener(EventListener);
        MiddleVR.VRInteractionMgr.AddEventListener(m_Listener);

        // Create commands

        // General
        m_ResetCurrentButtonCommand   = new vrCommand("VRMenu.ResetCurrentButtonCommand", ResetCurrentButtonHandler);
        m_ResetZeroButtonCommand      = new vrCommand("VRMenu.ResetZeroButtonCommand", ResetZeroButtonHandler);
        m_ExitButtonCommand           = new vrCommand("VRMenu.ExitButtonCommand", ExitButtonHandler);
        m_FramerateCheckboxCommand    = new vrCommand("VRMenu.FramerateCheckboxCommand", FramerateCheckboxHandler);
        m_ProxiWarningCheckboxCommand = new vrCommand("VRMenu.ProxiWarningCheckboxCommand", ProxiWarningCheckboxHandler);

        // Navigation
        m_FlyCheckboxCommand          = new vrCommand("VRMenu.FlyCheckboxCommand", FlyCheckboxHandler);
        m_CollisionsCheckboxCommand   = new vrCommand("VRMenu.CollisionsCheckboxCommand", CollisionsCheckboxHandler);

        // Manipulation
        m_ReturnObjectsCheckboxCommand = new vrCommand("VRMenu.ReturnObjectsCheckboxCommand", ReturnObjectsCheckboxHandler);

        // Create GUI
        m_GUIRendererWeb = null;

        VRWebView webViewScript = GetComponent<VRWebView>();

        if (webViewScript == null)
        {
            MVRTools.Log(1, "[X] VRMenu does not have a WebView.");
            return;
        }

        m_GUIRendererWeb = new vrGUIRendererWeb("", webViewScript.webView);

        m_Menu = new vrWidgetMenu("VRMenu.VRManagerMenu", m_GUIRendererWeb);

        // Navigation
        m_NavigationOptions = new vrWidgetMenu("VRMenu.NavigationOptions", m_Menu, "Navigation");

        CreateInteractionToggleButton(MiddleVR.VRInteractionMgr.GetInteraction("InteractionNavigationWandJoystick"), "Joystick", m_NavigationOptions, NavigationJoystickHandler);
        CreateInteractionToggleButton(MiddleVR.VRInteractionMgr.GetInteraction("InteractionNavigationElastic"), "Elastic", m_NavigationOptions, NavigationElasticHandler);
        CreateInteractionToggleButton(MiddleVR.VRInteractionMgr.GetInteraction("InteractionNavigationGrabWorld"), "Grab The World", m_NavigationOptions, NavigationGrabWorldHandler);

        m_NavigationSeparator = new vrWidgetSeparator("VRMenu.NavigationSeparator", m_NavigationOptions);
        m_FlyCheckbox         = new vrWidgetToggleButton("VRMenu.FlyCheckbox", m_NavigationOptions, "Fly", m_FlyCheckboxCommand, m_VRManager.Fly);
        m_CollisionsCheckbox  = new vrWidgetToggleButton("VRMenu.CollisionsCheckbox", m_NavigationOptions, "Navigation Collisions", m_CollisionsCheckboxCommand, m_VRManager.NavigationCollisions);

        // Manipulation
        m_ManipulationOptions = new vrWidgetMenu("VRMenu.ManipulationOptions", m_Menu, "Manipulation");

        CreateInteractionToggleButton(MiddleVR.VRInteractionMgr.GetInteraction("InteractionManipulationRay"), "Ray", m_ManipulationOptions, ManipulationRayHandler);
        CreateInteractionToggleButton(MiddleVR.VRInteractionMgr.GetInteraction("InteractionManipulationHomer"), "Homer", m_ManipulationOptions, ManipulationHomerHandler);

        m_ManipulationSeparator = new vrWidgetSeparator("VRMenu.ManipulationSeparator", m_ManipulationOptions);
        m_ReturnObjectsCheckbox = new vrWidgetToggleButton("VRMenu.ReturnObjectsCheckbox", m_ManipulationOptions, "Return Objects", m_ReturnObjectsCheckboxCommand, m_VRManager.ManipulationReturnObjects);

        // Virtual Hand
        m_VirtualHandOptions = new vrWidgetMenu("VRMenu.VirtualHandOptions", m_Menu, "Virtual Hand");

        CreateInteractionToggleButton(MiddleVR.VRInteractionMgr.GetInteraction("InteractionVirtualHandGogo"), "Gogo", m_VirtualHandOptions, VirtualHandGogoButtonHandler);

        // General
        m_GeneralSeparator = new vrWidgetSeparator("VRMenu.GeneralSeparator", m_Menu);
        m_GeneralOptions   = new vrWidgetMenu("VRMenu.GeneralOptions", m_Menu, "General Options");

        m_FramerateCheckbox    = new vrWidgetToggleButton("VRMenu.FramerateCheckbox", m_GeneralOptions, "Show Frame Rate", m_FramerateCheckboxCommand, m_VRManager.ShowFPS);
        m_ProxiWarningCheckbox = new vrWidgetToggleButton("VRMenu.ProxiWarningCheckbox", m_GeneralOptions, "Show Proximity Warning", m_ProxiWarningCheckboxCommand, m_VRManager.ShowScreenProximityWarnings);

        // Reset and Exit
        m_ResetButtonMenu    = new vrWidgetMenu("VRMenu.ResetButtonMenu", m_Menu, "Reset Simulation");
        m_ResetCurrentButton = new vrWidgetButton("VRMenu.ResetCurrentButton", m_ResetButtonMenu, "Reload current level", m_ResetCurrentButtonCommand);
        m_ResetZeroButton    = new vrWidgetButton("VRMenu.ResetZeroButton", m_ResetButtonMenu, "Reload level zero", m_ResetZeroButtonCommand);

        m_ExitButtonMenu = new vrWidgetMenu("VRMenu.ExitButtonMenu", m_Menu, "Exit Simulation");
        m_ExitButton     = new vrWidgetButton("VRMenu.ExitButton", m_ExitButtonMenu, "Yes, Exit Simulation", m_ExitButtonCommand);
    }
Exemple #10
0
 public void InitializeBaseInteraction()
 {
     m_Listener = new vrEventListener(EventListener);
     MiddleVR.VRKernel.AddEventListener(m_Listener);
 }
    protected void Start()
    {
        if (MiddleVR.VRClusterMgr.IsCluster() && !MiddleVR.VRClusterMgr.IsServer())
        {
            enabled = false;
            return;
        }

        if (MiddleVR.VRPhysicsMgr == null)
        {
            MiddleVRTools.Log(0, "[X] PhysicsBody: No PhysicsManager found.");
            enabled = false;

            return;
        }

        vrPhysicsEngine physicsEngine = MiddleVR.VRPhysicsMgr.GetPhysicsEngine();

        if (physicsEngine == null)
        {
            MiddleVRTools.Log(0, "[X] PhysicsBody: Failed to access a physics engine for body '" + name + "'.");
            enabled = false;

            return;
        }

        if (m_PhysicsBody == null)
        {
            m_PhysicsBody = physicsEngine.CreateBodyWithUniqueName(name);

            if (m_PhysicsBody == null)
            {
                MiddleVRTools.Log(0, "[X] PhysicsBody: Failed to create a physics body for '" + name + "'.");
                enabled = false;

                return;
            }
            else
            {
                GC.SuppressFinalize(m_PhysicsBody);

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

                var nodesMapper = MVRNodesMapper.Instance;

                nodesMapper.AddMapping(
                    gameObject, m_PhysicsBody,
                    MVRNodesMapper.ENodesSyncDirection.MiddleVRToUnity,
                    MVRNodesMapper.ENodesInitValueOrigin.FromUnity);

                m_PhysicsBodyName = m_PhysicsBody.GetName();

                string geometryName = m_PhysicsBodyName + ".Geometry";

                MiddleVRTools.Log(4,
                                  "[>] PhysicsBody: Creation of the physics geometry '" +
                                  geometryName + "'.");

                m_Geometry = new vrPhysicsGeometry(geometryName);
                GC.SuppressFinalize(m_Geometry);

                Mesh mesh = null;

                MeshCollider meshCollider = GetComponent <MeshCollider>();

                if (meshCollider != null)
                {
                    mesh = meshCollider.sharedMesh;

                    if (mesh != null)
                    {
                        MiddleVRTools.Log(2, "[ ] PhysicsBody: the physics geometry '" + geometryName +
                                          "' uses the mesh of its MeshCollider.");
                    }
                }

                // No mesh from collider was found so let's try from the mesh filter.
                if (mesh == null)
                {
                    var meshFilter = GetComponent <MeshFilter>();

                    if (meshFilter != null)
                    {
                        mesh = meshFilter.sharedMesh;

                        if (mesh != null)
                        {
                            MiddleVRTools.Log(2, "[ ] PhysicsBody: the physics geometry '" + geometryName +
                                              "' uses the mesh of its MeshFilter.");
                        }
                    }
                }

                if (mesh != null)
                {
                    ConvertGeometry(mesh);
                    MiddleVRTools.Log(4, "[ ] PhysicsBody: Physics geometry created.");
                }
                else
                {
                    MiddleVRTools.Log(
                        0,
                        "[X] PhysicsBody: Failed to create the physics geometry '" +
                        geometryName + "'.");
                }

                MiddleVRTools.Log(4,
                                  "[<] PhysicsBody: Creation of the physics geometry '" +
                                  geometryName + "' ended.");

                m_PhysicsBody.SetGeometry(m_Geometry);

                m_PhysicsBody.SetStatic(m_Static);
                m_PhysicsBody.SetMass(m_Mass);
                m_PhysicsBody.SetRotationDamping(m_RotationDamping);
                m_PhysicsBody.SetTranslationDamping(m_TranslationDamping);

                m_PhysicsBody.SetMargin(m_Margin);

                if (physicsEngine.AddBody(m_PhysicsBody))
                {
                    MiddleVRTools.Log(3, "[ ] PhysicsBody: The physics body '" + m_PhysicsBodyName +
                                      "' was added to the physics simulation.");
                }
                else
                {
                    MiddleVRTools.Log(3, "[X] PhysicsBody: Failed to add the body '" +
                                      m_PhysicsBodyName + "' to the physics simulation.");
                }
            }
        }
    }
Exemple #12
0
    private void _SetNode(vrNode3D iNode3D, MVRNodesMapper.ENodesSyncDirection iInitialSyncDirection, MVRNodesMapper.ENodesSyncDirection iSyncDirection)
    {
        // Check if iNode3D and m_Node3D are the same
        if (m_Node == iNode3D || (m_Node != null && iNode3D != null && m_Node.GetId() == iNode3D.GetId()))
        {
            // Same node, return.
            return;
        }

        MVRNodesMapper nodesMapper = MVRNodesMapper.Instance;

        // Cleanup old node
        if (m_Node != null && !m_IsNodeGrabbed)
        {
            if (m_EventListener != null)
            {
                m_Node.RemoveEventListener(m_EventListener);
            }

            if (m_SyncDirection != MVRNodesMapper.ENodesSyncDirection.NoSynchronization)
            {
                nodesMapper.RemoveMapping(gameObject, true);
            }
        }

        m_IsNodeGrabbed = false;
        m_Node          = iNode3D;

        // Setup new node
        if (m_Node != null)
        {
            // First mapping will copy the object's transform
            if (iInitialSyncDirection != MVRNodesMapper.ENodesSyncDirection.NoSynchronization)
            {
                nodesMapper.AddMapping(gameObject, m_Node, iInitialSyncDirection);
            }

            if (iInitialSyncDirection != iSyncDirection)
            {
                if (iInitialSyncDirection != MVRNodesMapper.ENodesSyncDirection.NoSynchronization)
                {
                    nodesMapper.RemoveMapping(gameObject, false);
                }

                if (iSyncDirection != MVRNodesMapper.ENodesSyncDirection.NoSynchronization)
                {
                    nodesMapper.AddMapping(gameObject, m_Node, iSyncDirection);
                }
            }

            m_NodeName      = m_Node.GetName();
            m_SyncDirection = iSyncDirection;

            if (m_EventListener == null)
            {
                m_EventListener = new vrEventListener(_OnNodeEvent);
            }

            m_Node.AddEventListener(m_EventListener);
        }
        else
        {
            m_NodeName = "";
        }
    }
Exemple #13
0
    void Start()
    {
        gameManager = GameObject.Find("GameManager").GetComponent <Modelisation.GameManager>();
        menuManager = GameObject.Find("Utilisateur").GetComponent <MenuManager>();

        // Retrieve the VRManager
        VRManagerScript[] foundVRManager = FindObjectsOfType(typeof(VRManagerScript)) as VRManagerScript[];
        if (foundVRManager.Length != 0)
        {
            m_VRManager = foundVRManager[0];
        }
        else
        {
            MVRTools.Log("[X] VRMenu: impossible to retrieve the VRManager.");
            return;
        }

        // Start listening to MiddleVR events
        m_Listener = new vrEventListener(EventListener);
        MiddleVR.VRKernel.AddEventListener(m_Listener);

        // Create commands

        // General
        m_ResetButtonCommand = new vrCommand("VRMenu.ResetButtonCommand", ResetButtonHandler);
        m_ExitButtonCommand  = new vrCommand("VRMenu.ExitButtonCommand", ExitButtonHandler);

        // Mode
        modeAssisteCommand = new vrCommand("VRMenu.modeAssisteCommand", ModeAssisteHandler);
        modeLibreCommand   = new vrCommand("VRMenu.modeLibreCommand", ModeLibreHandler);

        // Scenario
        scenarioAppelCommand     = new vrCommand("VRMenu.ScenarioAppelCommand", ScenarioAppelHandler);
        scenarioInfirmierCommand = new vrCommand("VRMenu.ScenarioInfirmierCommand", ScenarioInfirmierHandler);
        scenarioInconnuCommand   = new vrCommand("VRMenu.ScenarioInconnuCommand", ScenarioInconnuHandler);

        // Create GUI
        m_GUIRendererWeb = null;

        VRWebView webViewScript = GetComponent <VRWebView>();

        if (webViewScript == null)
        {
            MVRTools.Log(1, "[X] VRMenu does not have a WebView.");
            return;
        }

        m_GUIRendererWeb = new vrGUIRendererWeb("", webViewScript.webView);

        m_Menu = new vrWidgetMenu("VRMenu.VRManagerMenu", m_GUIRendererWeb);

        // Mode
        menuChoixMode = new vrWidgetMenu("VRMenu.ChoixMode", m_Menu, "Modes");

        modeAssiste = new vrWidgetButton("VRMenu.ModeAssisteButton", menuChoixMode, "Passer en mode assisté", modeAssisteCommand);
        modeLibre   = new vrWidgetButton("VRMenu.ModeLibreButton", menuChoixMode, "Passer en mode libre", modeLibreCommand);

        // Scénario
        menuChoixScenar = new vrWidgetMenu("VRMenu.ChoixScenario", m_Menu, "Scenarios");

        scenarAppel     = new vrWidgetButton("VRMenu.ScenarAppelButton", menuChoixScenar, "Appel téléphonique", scenarioAppelCommand);
        scenarInfirmier = new vrWidgetButton("VRMenu.ScenarInfirmierButton", menuChoixScenar, "Infirmier à l'entrée", scenarioInfirmierCommand);
        scenarInconnu   = new vrWidgetButton("VRMenu.ScenarInconnuButton", menuChoixScenar, "Inconnu à l'entrée", scenarioInconnuCommand);

        // Reset and Exit
        m_ResetButton = new vrWidgetButton("VRMenu.ResetCurrentButton", m_Menu, "Reload simulation", m_ResetButtonCommand);

        m_ExitButton = new vrWidgetButton("VRMenu.ExitButton", m_Menu, "Exit simulation", m_ExitButtonCommand);
    }
    protected void Start()
    {
        if (MiddleVR.VRClusterMgr.IsCluster() && !MiddleVR.VRClusterMgr.IsServer())
        {
            enabled = false;
            return;
        }

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

        vrPhysicsEngine physicsEngine = MiddleVR.VRPhysicsMgr.GetPhysicsEngine();

        if (physicsEngine == null)
        {
            MiddleVRTools.Log(0, "[X] PhysicsBody: Failed to access a physics engine for body '" + name + "'.");
            enabled = false;
            return;
        }

        if (m_PhysicsBody == null)
        {
            m_PhysicsBody = physicsEngine.CreateBodyWithUniqueName(name);

            if (m_PhysicsBody == null)
            {
                MiddleVRTools.Log(0, "[X] PhysicsBody: Failed to create a physics body for '" + name + "'.");
                enabled = false;
                return;
            }
            else
            {
                GC.SuppressFinalize(m_PhysicsBody);

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

                var nodesMapper = MVRNodesMapper.Instance;

                nodesMapper.AddMapping(
                    gameObject, m_PhysicsBody,
                    MVRNodesMapper.ENodesSyncDirection.MiddleVRToUnity,
                    MVRNodesMapper.ENodesInitValueOrigin.FromUnity);

                m_PhysicsBodyName = m_PhysicsBody.GetName();

                m_Geometry = CreateGeometry(m_MergeChildGeometries);
                if (m_Geometry != null)
                {
                    GC.SuppressFinalize(m_Geometry);
                }

                m_PhysicsBody.SetGeometry(m_Geometry);

                m_PhysicsBody.SetStatic(m_Static);
                m_PhysicsBody.SetMass(m_Mass);
                m_PhysicsBody.SetRotationDamping(m_RotationDamping);
                m_PhysicsBody.SetTranslationDamping(m_TranslationDamping);

                m_PhysicsBody.SetMargin(m_Margin);

                if (physicsEngine.AddBody(m_PhysicsBody))
                {
                    MiddleVRTools.Log(3, "[ ] PhysicsBody: The physics body '" + m_PhysicsBodyName +
                                      "' was added to the physics simulation.");
                }
                else
                {
                    MiddleVRTools.Log(0, "[X] PhysicsBody: Failed to add the body '" +
                                      m_PhysicsBodyName + "' to the physics simulation.");
                }
            }
        }
    }