Esempio n. 1
0
#pragma warning restore 649

        public override bool CreateGameObject(out GameObject createdObj, Transform parentTransform)
        {
            if (m_Prefab == null)
            {
                createdObj = null;
                return(false);
            }

            MARSSession.EnsureRuntimeState();

            var objName = GameObjectUtility.GetUniqueNameForSibling(null, m_ObjectName);

            createdObj = Instantiate(m_Prefab);
            MarsWorldScaleModule.ScaleChildren(createdObj.transform);

            foreach (var colorComponent in createdObj.GetComponentsInChildren <IHasEditorColor>())
            {
                colorComponent.SetNewColor(true, true);
            }

            createdObj.name = objName;
            Undo.RegisterCreatedObjectUndo(createdObj, $"Create {objName}");
            Selection.activeGameObject = createdObj;
            return(true);
        }
Esempio n. 2
0
        public void Setup()
        {
            MARSSession.TestMode           = true;
            QuerySimulationModule.TestMode = true;
            m_TestSimulationUser           = ScriptableObject.CreateInstance <TestSimulationUser>();
            MARSSession.EnsureSessionInActiveScene();

            var moduleLoader = ModuleLoaderCore.instance;

            moduleLoader.GetModule <SimulationSceneModule>().RegisterSimulationUser(m_TestSimulationUser);
            moduleLoader.GetModule <SceneWatchdogModule>().ScenePoll();

            EditorWindow.GetWindow <SimulationView>(); // Tests will fail if a Simulation isn't open.

            m_EnvironmentManager            = moduleLoader.GetModule <MARSEnvironmentManager>();
            m_CachedEnvironmentModeSettings = m_EnvironmentManager.CustomModeSettings;
            m_CachedEnvironmentMode         = SimulationSettings.instance.EnvironmentMode;

            m_TestModeSettings.Clear();
            var testModeA = ScriptableObject.CreateInstance <TestSimulationEnvironmentModeSettings>();

            testModeA.TestDefaultSimulationMode = SimulationModeSelection.TemporalMode;
            testModeA.TestIsFramingEnabled      = false;
            testModeA.TestEnvironmentModeName   = "TestSimulationEnvironmentModeSettings_testModeA";
            m_TestModeSettings.Add(testModeA.EnvironmentModeName, testModeA);

            var testModeB = ScriptableObject.CreateInstance <TestSimulationEnvironmentModeSettings>();

            testModeB.TestDefaultSimulationMode = SimulationModeSelection.SingleFrameMode;
            testModeA.TestIsFramingEnabled      = true;
            testModeB.TestEnvironmentModeName   = "TestSimulationEnvironmentModeSettings_testModeB";
            m_TestModeSettings.Add(testModeB.EnvironmentModeName, testModeB);

            ResetScene();
        }
        /// <summary>
        /// Sets the default camera settings based on the current scene view camera
        /// </summary>
        /// <param name="sceneView">Scene view that we are getting the camera from</param>
        /// <param name="isSimView">Is the scene view a simulation view</param>
        public void SetDefaultEnvironmentCamera(SceneView sceneView, bool isSimView)
        {
            MARSSession.EnsureRuntimeState();
            var simCamera       = sceneView.camera;
            var cameraTransform = simCamera.transform;

            using (var undoBlock = new UndoBlock("Set Default Environment Camera"))
            {
                undoBlock.RecordObject(this);
                if (isSimView)
                {
                    var cameraScale = MARSSession.GetWorldScale();
                    var camPose     = new Pose(cameraTransform.position / cameraScale, cameraTransform.rotation);

                    m_EnvironmentInfo.DefaultCameraWorldPose = camPose;
                    m_EnvironmentInfo.DefaultCameraPivot     = sceneView.pivot / cameraScale;
                    m_EnvironmentInfo.DefaultCameraSize      = sceneView.size / cameraScale;
                }
                else
                {
                    m_EnvironmentInfo.DefaultCameraWorldPose = cameraTransform.GetWorldPose();
                    m_EnvironmentInfo.DefaultCameraPivot     = sceneView.pivot;
                    m_EnvironmentInfo.DefaultCameraSize      = sceneView.size;
                }
            }
        }
        public override bool CreateGameObject(out GameObject createdObj, Transform parentTransform = null)
        {
            MARSSession.EnsureRuntimeState();

            createdObj = GenerateInitialGameObject(m_ObjectName, parentTransform);

            createdObj.AddComponent <ProxyGroup>();

            var child1 = new GameObject("Child 1");

            child1.AddComponent <Proxy>();
            child1.AddComponent <ShowChildrenOnTrackingAction>();
            child1.AddComponent <SetPoseAction>();
            child1.transform.parent = createdObj.transform;

            var child2 = new GameObject("Child 2");

            child2.AddComponent <Proxy>();
            child2.AddComponent <ShowChildrenOnTrackingAction>();
            child2.AddComponent <SetPoseAction>();
            child2.transform.parent = createdObj.transform;

            Undo.RegisterCreatedObjectUndo(createdObj, $"Create {createdObj.name}");
            Selection.activeGameObject = createdObj;

            var simObjectsManager = ModuleLoaderCore.instance.GetModule <SimulatedObjectsManager>();

            simObjectsManager?.DirtySimulatableScene();

            return(true);
        }
        /// <summary>
        /// Returns the first MarsSession found in the given scene
        /// </summary>
        /// <param name="scene">The scene to search</param>
        /// <returns>The first MarsSession found in the given scene, or null if none exists</returns>
        public static MARSSession GetMarsSessionInScene(Scene scene)
        {
            if (s_CachedScene == scene && s_CachedSession != null)
            {
                return(s_CachedSession);
            }

            if (s_CachedScene != scene || s_CachedSession == null)
            {
                foreach (var root in scene.GetRootGameObjects())
                {
                    var session = root.GetComponentInChildren <MARSSession>();
                    if (session != null)
                    {
                        s_CachedScene   = scene;
                        s_CachedSession = session;
                        return(session);
                    }
                }
            }

            s_CachedScene   = default;
            s_CachedSession = null;
            return(null);
        }
Esempio n. 6
0
        /// <summary>
        /// Create a Body preset object
        /// </summary>
        /// <param name="createdObj">The created object</param>
        /// <param name="parentTransform">A parent transform to use for object creation (can be null)</param>
        /// <returns>True if the object was created successfully</returns>
        public override bool CreateGameObject(out GameObject createdObj, Transform parentTransform)
        {
            MARSSession.EnsureRuntimeState();

            createdObj = GenerateInitialGameObject(m_ObjectName, parentTransform);

            createdObj.AddComponent <Proxy>();
            createdObj.AddComponent <IsBodyCondition>();
            var bodyAction = createdObj.AddComponent <MatchBodyPoseAction>();

            var defaultBodyRig = Instantiate(
                MarsBodySettings.instance.DefaultLandmarksBodyRig.gameObject, createdObj.transform).GetComponent <Animator>();

            defaultBodyRig.gameObject.name = "Default Body Rig";

            var bodyActionSerializedObj = new SerializedObject(bodyAction);
            var animatorProperty        = bodyActionSerializedObj.FindProperty("m_Animator");

            animatorProperty.objectReferenceValue = defaultBodyRig;
            bodyActionSerializedObj.ApplyModifiedProperties();

            Undo.RegisterCreatedObjectUndo(createdObj, $"Create {createdObj.name}");
            Selection.activeGameObject = createdObj;

            var simObjectsManager = ModuleLoaderCore.instance.GetModule <SimulatedObjectsManager>();

            if (simObjectsManager != null)
            {
                simObjectsManager.DirtySimulatableScene();
            }

            SceneView.RepaintAll();

            return(true);
        }
        protected virtual void OnEnable()
        {
            var sceneModule = MARSSceneModule.instance;

            m_WasBlockingEnsureSession     = sceneModule.BlockEnsureSession;
            m_WasSimulatingInPlayMode      = sceneModule.simulateInPlaymode;
            m_WasSimulatingDiscovery       = sceneModule.simulateDiscovery;
            sceneModule.BlockEnsureSession = false;
            sceneModule.simulateInPlaymode = true;
            sceneModule.simulateDiscovery  = false;

            MARSSession.TestMode = true;
            MARSSession.EnsureRuntimeState();
            m_MARSSession = MARSSession.Instance;

            m_Proxy = new GameObject("QueryRegistrationTest_Proxy");
            m_Proxy.SetActive(false);
            m_Proxy.AddComponent <Proxy>();
            m_Proxy.AddComponent <ShowChildrenOnTrackingAction>();
            m_Proxy.AddComponent <SetPoseAction>();
            m_Proxy.AddComponent <IsPlaneCondition>();
            m_Proxy.SetActive(true);

            var synthPlane = GameObject.CreatePrimitive(PrimitiveType.Plane);

            synthPlane.SetActive(false);
            synthPlane.AddComponent <SynthesizedObject>();
            synthPlane.AddComponent <SynthesizedPlane>();
            synthPlane.SetActive(true);
        }
        void IModule.UnloadModule()
        {
            SceneView.duringSceneGui -= OnSceneGUI;

            s_CachedSession       = null;
            s_SerializedTransform = null;

            ClearEnvironmentRangeScaledComponents();

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

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

            m_ScaleReferenceRenderer    = null;
            m_ScaleReferenceOrigin      = default(Vector3);
            m_CurrentScaleReferenceIcon = 0;
            m_MinScale         = 0;
            m_MaxScale         = 0;
            m_VisualsZeroIndex = 0;
        }
 static void CheckMARSBehaviors(Scene scene)
 {
     // TODO: shut down MARS entirely if there are no MARS behaviors--the issue is starting it back up when adding them
     if (MarsRuntimeUtils.HasMarsBehaviors(scene))
     {
         MARSSession.EnsureRuntimeState();
     }
 }
Esempio n. 10
0
 public void OnEnable()
 {
     titleContent.text = WindowTitle;
     SwitchRatio();
     m_OriginalSkybox             = RenderSettings.skybox;
     m_Session                    = MarsRuntimeUtils.GetMarsSessionInActiveScene();
     EditorApplication.delayCall += SetupTextures;
     EditorSceneManager.activeSceneChangedInEditMode += OnActiveSceneChange;
 }
        #pragma warning restore 649

        public override bool CreateGameObject(out GameObject createdObj, Transform parentTransform = null)
        {
            MARSSession.EnsureRuntimeState();

            createdObj = GenerateInitialGameObject(m_ObjectName, parentTransform);

            createdObj.AddComponent <Proxy>();
            createdObj.AddComponent <ShowChildrenOnTrackingAction>();

            createdObj.AddComponent <IsFaceCondition>();
            var landmarksAction = createdObj.AddComponent <FaceLandmarksAction>();

            var allLandmarkDefinitions = landmarksAction.AvailableLandmarkDefinitions;

            foreach (var def in allLandmarkDefinitions)
            {
                landmarksAction.CreateLandmarkAsChild(def, def.outputTypes[0]);
            }

            var entityVisualsModule = ModuleLoaderCore.instance.GetModule <EntityVisualsModule>();
            var marsEntity          = landmarksAction.GetComponentInParent <MARSEntity>();

            if (entityVisualsModule != null && marsEntity != null)
            {
                entityVisualsModule.InvalidateVisual(marsEntity);
            }

            var depthMaskGO = new GameObject(k_DepthMaskGameObjName);

            depthMaskGO.AddComponent <MeshFilter>().sharedMesh = m_DepthMaskMesh;

            var depthFaceMaskRenderer = depthMaskGO.AddComponent <MeshRenderer>();

            depthFaceMaskRenderer.sharedMaterial     = m_DepthMaskMaterial;
            depthFaceMaskRenderer.renderingLayerMask = uint.MaxValue; //All layers

            depthMaskGO.transform.parent = createdObj.transform;

            var faceAction = createdObj.AddComponent <FaceAction>();
            var serializedFaceActionObj = new SerializedObject(faceAction);
            var faceMeshProperty        = serializedFaceActionObj.FindProperty(k_FaceMeshPropertyName);

            faceMeshProperty.objectReferenceValue = depthMaskGO;
            serializedFaceActionObj.ApplyModifiedPropertiesWithoutUndo();

            createdObj.AddComponent <FaceExpressionAction>();

            Undo.RegisterCreatedObjectUndo(createdObj, $"Create {createdObj.name}");
            Selection.activeGameObject = createdObj;

            var simObjectsManager = ModuleLoaderCore.instance.GetModule <SimulatedObjectsManager>();

            simObjectsManager?.DirtySimulatableScene();

            return(true);
        }
        void IModule.LoadModule()
        {
#if UNITY_EDITOR
            // Make sure we have a MARS Session because we skip OnSceneOpened during builds
            if (MARSSession.Instance == null)
            {
                MARSSession.FindExistingInstance();
            }
#endif
        }
        internal bool Update(MARSSession marsSession, List <IFunctionalitySubscriber> subscribers, bool temporal)
        {
            k_SubscriberTypes.Clear();
            k_TraitRequirements.Clear();

            var moduleLoader = ModuleLoaderCore.instance;

            foreach (var module in moduleLoader.modules)
            {
                k_SubscriberTypes.Add(module.GetType());
            }

            foreach (var subscriber in subscribers)
            {
                k_SubscriberTypes.Add(subscriber.GetType());
            }

            k_TraitRequirements.UnionWith(marsSession.requirements.TraitRequirements);

            var simulationSettings   = SimulationSettings.instance;
            var environmentMode      = simulationSettings.EnvironmentMode;
            var environmentPrefab    = simulationSettings.EnvironmentPrefab;
            var independentRecording = simulationSettings.IndependentRecording;
            var syntheticRecording   = simulationSettings.UseSyntheticRecording ?
                                       simulationSettings.GetRecordingForCurrentSyntheticEnvironment() : null;

            var recordingPlaybackModule  = moduleLoader.GetModule <MarsRecordingPlaybackModule>();
            var disableRecordingPlayback = recordingPlaybackModule != null && recordingPlaybackModule.DisableRecordingPlayback;

            var changed = !SceneSubscriberTypes.SetEquals(k_SubscriberTypes) ||
                          !SceneRequirements.SetEquals(k_TraitRequirements) ||
                          m_EnvironmentMode != environmentMode ||
                          m_EnvironmentPrefab != environmentPrefab ||
                          m_SyntheticRecording != syntheticRecording ||
                          m_IndependentRecording != independentRecording ||
                          m_Temporal != temporal ||
                          m_DisableRecordingPlayback != disableRecordingPlayback;

            SceneSubscriberTypes.Clear();
            SceneSubscriberTypes.UnionWith(k_SubscriberTypes);
            SceneRequirements.Clear();
            SceneRequirements.UnionWith(k_TraitRequirements);
            m_EnvironmentMode          = environmentMode;
            m_EnvironmentPrefab        = environmentPrefab;
            m_SyntheticRecording       = syntheticRecording;
            m_IndependentRecording     = independentRecording;
            m_Temporal                 = temporal;
            m_DisableRecordingPlayback = disableRecordingPlayback;

            k_SubscriberTypes.Clear();
            k_TraitRequirements.Clear();
            return(changed);
        }
#pragma warning restore 649

        public override bool CreateGameObject(out GameObject createdObj, Transform parentTransform = null)
        {
            MARSSession.EnsureRuntimeState();

            createdObj = null;

            SimulationView activeView = SimulationView.ActiveSimulationView as SimulationView;

            if (activeView != null)
            {
                activeView.EnvironmentSceneActive = true;
            }

            Tools.current = Tool.Move;

            GameObject markerGO;

            using (var undoBlock = new UndoBlock("Synthetic Marker Creation"))
            {
                var imageMarkerParent = GetOrGenerateUniqueParent(k_SimulatedMarkersParentName);
                if (imageMarkerParent == null)
                {
                    Debug.LogWarning("Unable to create synthetic marker.");
                    return(false);
                }

                var syntheticMarker = CreateSyntheticMarker();
                var markerTransform = syntheticMarker.transform;
                markerTransform.parent = imageMarkerParent;

                // Zero out position and rotation, leave scale in case the user is working with other scale.
                markerTransform.localPosition = Vector3.zero;
                markerTransform.localRotation = Quaternion.identity;

                markerTransform.name = GameObjectUtility.GetUniqueNameForSibling(imageMarkerParent, m_ObjectName);

                markerGO = markerTransform.gameObject;
                undoBlock.RegisterCreatedObject(markerGO);

                Selection.activeTransform = markerTransform;

                var initialScale = Vector2.one * MarsWorldScaleModule.GetWorldScale();
                syntheticMarker.UpdateMarkerSize(initialScale);

                markerTransform.localScale = new Vector3(1, 0.01f, 1);
                createdObj = markerTransform.gameObject;
            }

            return(true);
        }
        /// <summary>
        /// Draw a hint box with a button to add a MARS Session
        /// </summary>
        /// <param name="shouldShowHint">Whether the hint box should currently be displayed</param>
        /// <param name="hintMessage">The primary message to show in the hint box</param>
        /// <param name="messageType">What type of message box to show (info / warning)</param>
        /// /// <returns>True, unless the user presses the 'close' button</returns>
        public static bool NoActiveSessionHintBox(bool shouldShowHint, string hintMessage, MessageType messageType)
        {
            if (shouldShowHint)
            {
                EditorGUILayout.HelpBox(hintMessage, messageType);
                if (GUILayout.Button(k_AddSessionContent))
                {
                    MARSSession.EnsureRuntimeState();
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 16
0
        public override bool CreateGameObject(out GameObject createdObj, Transform parentTransform)
        {
            //Early out if we already have a MARSLightEstimationVisualizer
            var lightEstimationVisualizer = GameObject.FindObjectOfType <MARSLightEstimationVisualizer>();

            if (lightEstimationVisualizer)
            {
                createdObj             = null;
                Selection.activeObject = lightEstimationVisualizer.gameObject;
                return(false);
            }

            MARSSession.EnsureRuntimeState();

            Light existingDirectionalLight = null;

            Light[] existingLights = GameObject.FindObjectsOfType <Light>();
            for (int i = 0; i < existingLights.Length; i++)
            {
                if (existingLights[i].type == LightType.Directional)
                {
                    existingDirectionalLight = existingLights[i];
                    break;
                }
            }

            if (existingDirectionalLight != null)
            {
                createdObj = existingDirectionalLight.gameObject;
                var lightEstimate = Undo.AddComponent <MARSLightEstimationVisualizer>(createdObj);
                lightEstimate.Light = existingDirectionalLight;
            }
            else
            {
                //no light exists, lets create one and add the component
                createdObj = GenerateInitialGameObject(m_ObjectName, parentTransform);
                createdObj.AddComponent <Light>().type = LightType.Directional;
                createdObj.AddComponent <MARSLightEstimationVisualizer>();
                Undo.RegisterCreatedObjectUndo(createdObj, $"Create {createdObj.name}");
            }

            Selection.activeObject = createdObj;

            var simObjectsManager = ModuleLoaderCore.instance.GetModule <SimulatedObjectsManager>();

            simObjectsManager?.DirtySimulatableScene();

            return(true);
        }
        /// <summary>
        /// Sets the simulated device starting pose based on the current scene view camera
        /// </summary>
        /// <param name="cameraPose">Camera pose we using</param>
        /// <param name="isSimView">Is this camera from a simulation view</param>
        public void SetSimulationStartingPose(Pose cameraPose, bool isSimView)
        {
            MARSSession.EnsureRuntimeState();
            using (var undoBlock = new UndoBlock("Set Simulation Starting Pose"))
            {
                undoBlock.RecordObject(this);
                if (isSimView)
                {
                    var cameraScale = MARSSession.GetWorldScale();
                    cameraPose.position /= cameraScale;
                }

                m_EnvironmentInfo.SimulationStartingPose = cameraPose;
            }
        }
        void EnableMARSSession(bool activate)
        {
            Debug.Log($"Enable MARSSession: {activate}");

            if (m_MarsSession == null)
            {
                m_MarsSession = FindObjectOfType <MARSSession>();
                if (m_MarsSession == null)
                {
                    return;
                }
            }

            m_MarsSession.enabled = activate;
        }
Esempio n. 19
0
        public override bool CreateGameObject(out GameObject createdObj, Transform parentTransform = null)
        {
            MARSSession.EnsureRuntimeState();

            createdObj = GenerateInitialGameObject(m_ObjectName, parentTransform);

            createdObj.AddComponent <MRFaceLandmarkVisualizer>();

            Undo.RegisterCreatedObjectUndo(createdObj, $"Create {createdObj.name}");
            Selection.activeGameObject = createdObj;

            var simObjectsManager = ModuleLoaderCore.instance.GetModule <SimulatedObjectsManager>();

            simObjectsManager?.DirtySimulatableScene();

            return(true);
        }
#pragma warning restore 649

        /// <summary>
        /// Create a Synthetic Body preset object
        /// </summary>
        /// <param name="createdObj">The created object</param>
        /// <param name="parentTransform">A parent transform to use for object creation (can be null)</param>
        /// <returns>True if the object was created successfully</returns>
        public override bool CreateGameObject(out GameObject createdObj, Transform parentTransform)
        {
            MARSSession.EnsureRuntimeState();

            createdObj = null;

            var activeView = SimulationView.ActiveSimulationView as SimulationView;

            if (activeView != null)
            {
                activeView.EnvironmentSceneActive = true;
            }

            Tools.current = Tool.Move;

            var syntheticBodyParentTransform = GetOrGenerateUniqueParent(k_SimulatedBodiesParentName);

            if (syntheticBodyParentTransform == null)
            {
                Debug.LogWarning("Unable to create synthetic body parent");
                return(false);
            }

            createdObj = CreateSyntheticBody();
            var createdBodyTransform = createdObj.transform;

            createdBodyTransform.parent = syntheticBodyParentTransform;

            createdBodyTransform.localPosition = Vector3.zero;
            createdBodyTransform.localRotation = Quaternion.identity;
            createdBodyTransform.localScale    = Vector3.one;

            createdObj.name = GameObjectUtility.GetUniqueNameForSibling(syntheticBodyParentTransform, k_CreatedBodyObjName);

            Undo.RegisterCreatedObjectUndo(createdObj, $"Create {createdObj.name}");
            Selection.activeGameObject = createdObj;

            var simObjectsManager = ModuleLoaderCore.instance.GetModule <SimulatedObjectsManager>();

            if (simObjectsManager != null)
            {
                simObjectsManager.DirtySimulatableScene();
            }

            return(true);
        }
        void OnEntityComponentsChanged(List <Component> changed)
        {
            if (anyEntitiesInScene)
            {
                MARSSession.EnsureRuntimeState();
            }

#if UNITY_EDITOR
            var marsSession = MARSSession.Instance;
            if (marsSession)
            {
                marsSession.CheckCapabilities();
            }
#endif

            m_SimulatedObjectsManager.DirtySimulatableScene();
            CheckIfFaceScene();
        }
        static SerializedProperty GetWorldScaleProperty()
        {
            var session = MarsRuntimeUtils.GetMarsSessionInActiveScene();

            if (session == null || session.transform == null)
            {
                return(null);
            }

            if (s_CachedSession != session || s_SerializedTransform == null)
            {
                s_CachedSession       = session;
                s_SerializedTransform = new SerializedObject(session.transform);
            }

            s_SerializedTransform.UpdateIfRequiredOrScript();
            return(s_SerializedTransform.FindProperty("m_LocalScale"));
        }
Esempio n. 23
0
        public override bool CreateGameObject(out GameObject createdObj, Transform parentTransform = null)
        {
            MARSSession.EnsureRuntimeState();

            createdObj = GenerateInitialGameObject(m_ObjectName, parentTransform);

            createdObj.AddComponent <Proxy>();
            createdObj.AddComponent <SetPoseAction>().AlignWithWorldUp = SetPoseAction.AlignMode.None;
            createdObj.AddComponent <ShowChildrenOnTrackingAction>();
            createdObj.AddComponent <MarkerCondition>();

            Undo.RegisterCreatedObjectUndo(createdObj, $"Create {createdObj.name}");
            Selection.activeGameObject = createdObj;

            var simObjectsManager = ModuleLoaderCore.instance.GetModule <SimulatedObjectsManager>();

            simObjectsManager?.DirtySimulatableScene();

            return(true);
        }
Esempio n. 24
0
        static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
        {
            // List is cleared by GetInstances
            SubsystemManager.GetInstances(k_MarsXRSubsystems);
            var anyMarsSubsystemsRunning = false;

            foreach (var subsystem in k_MarsXRSubsystems)
            {
                if (subsystem.running)
                {
                    anyMarsSubsystemsRunning = true;
                    break;
                }
            }

            if (anyMarsSubsystemsRunning)
            {
                MARSSession.EnsureSessionInActiveScene();
            }
        }
Esempio n. 25
0
        public void SetupLandmark(ILandmarkController landmark)
        {
            var faceLandmark = landmark.landmarkDefinition.GetEnumName <MRFaceLandmark>();

            if (m_FallbackLandmarkPoses == null)
            {
                m_FallbackLandmarkPoses = MARSFallbackFaceLandmarks.instance.GetFallbackFaceLandmarkPoses();
            }

            var initialPose = m_FallbackLandmarkPoses[faceLandmark];

            initialPose.position *= MARSSession.GetWorldScale();
            var landmarkTransform = ((Component)(landmark)).transform;

            landmarkTransform.SetLocalPose(initialPose);
            var landmarkPose = landmark.output as LandmarkOutputPose;

            if (landmarkPose != null)
            {
                landmarkPose.currentPose = landmarkTransform.GetWorldPose();
            }
        }
        #pragma warning restore 649

        public override bool CreateGameObject(out GameObject createdObj, Transform parentTransform = null)
        {
            MARSSession.EnsureRuntimeState();

            createdObj = GenerateInitialGameObject(m_ObjectName, parentTransform);

            createdObj.AddComponent <MARSPointCloudVisualizer>();
            //MeshFilter and MeshRenderer get added by default by (MARSPointCloudVisualizer)
            var createdVisualizerMeshRenderer = createdObj.GetComponent <MeshRenderer>();

            createdVisualizerMeshRenderer.sharedMaterial     = m_PointCloudMaterial;
            createdVisualizerMeshRenderer.renderingLayerMask = uint.MaxValue; // All layers

            Undo.RegisterCreatedObjectUndo(createdObj, $"Create {createdObj.name}");
            Selection.activeGameObject = createdObj;

            var simObjectsManager = ModuleLoaderCore.instance.GetModule <SimulatedObjectsManager>();

            simObjectsManager?.DirtySimulatableScene();

            return(true);
        }
        #pragma warning restore 649

        public override bool CreateGameObject(out GameObject createdObj, Transform parentTransform = null)
        {
            MARSSession.EnsureRuntimeState();

            createdObj = GenerateInitialGameObject(m_ObjectName, parentTransform);

            var planeVisualizer = createdObj.AddComponent <MARSPlaneVisualizer>();
            var planeVisualizerSerializedObj = new SerializedObject(planeVisualizer);
            var planePrefabProperty          = planeVisualizerSerializedObj.FindProperty(k_PlanePrefabPropertyName);

            planePrefabProperty.objectReferenceValue = m_PlanePrefab;
            planeVisualizerSerializedObj.ApplyModifiedPropertiesWithoutUndo();

            Undo.RegisterCreatedObjectUndo(createdObj, $"Create {createdObj.name}");
            Selection.activeGameObject = createdObj;

            var simObjectsManager = ModuleLoaderCore.instance.GetModule <SimulatedObjectsManager>();

            simObjectsManager?.DirtySimulatableScene();

            return(true);
        }
        public static Proxy EditorEnsureProxyOnThisOrParents(GameObject gm)
        {
            ProxyForcesFieldSolverModule session = null;

            ProxyForcesFieldSolverModule.EnsureInstance(gm, ref session);

            MARSSession.EnsureRuntimeState();

            var ans = gm.GetComponent <Proxy>();

            if (ans)
            {
                return(ans);
            }
            ans = gm.GetComponentInParent <Proxy>();
            if (ans)
            {
                return(ans);
            }

            return(Undo.AddComponent <Proxy>(gm));
        }
Esempio n. 29
0
        public override bool CreateGameObject()
        {
            if (m_Prefab == null)
            {
                return(false);
            }

            MARSSession.EnsureRuntimeState();

            var objName = GameObjectUtility.GetUniqueNameForSibling(null, m_ButtonName);
            var go      = Instantiate(m_Prefab);

            MarsWorldScaleModule.ScaleChildren(go.transform);

            foreach (var colorComponent in go.GetComponentsInChildren <IHasEditorColor>())
            {
                colorComponent.SetNewColor(true, true);
            }

            go.name = objName;
            Undo.RegisterCreatedObjectUndo(go, $"Create {objName}");
            Selection.activeGameObject = go;
            return(true);
        }
Esempio n. 30
0
        void OnDrawGizmosSelected()
        {
            if (!m_ShowPoseAxes)
            {
                return;
            }

            Gizmos.color = m_PoseAxesColor;
            var position = transform.position;
            var rotation = transform.rotation;

            var worldScale = MARSSession.GetWorldScale();

            Gizmos.DrawWireSphere(position, m_PoseAxesSize * 0.5f * worldScale);

            Gizmos.color = Color.red;
            Gizmos.DrawLine(position, position + rotation * Vector3.right * m_PoseAxesSize * worldScale);

            Gizmos.color = Color.green;
            Gizmos.DrawLine(position, position + rotation * Vector3.up * m_PoseAxesSize * worldScale);

            Gizmos.color = Color.blue;
            Gizmos.DrawLine(position, position + rotation * Vector3.forward * m_PoseAxesSize * worldScale);
        }