Пример #1
0
 protected override void OnDisable()
 {
     if (null != group)
     {
         group.Submit();
         group = null;
     }
 }
Пример #2
0
        protected override void OnDisable()
        {
            if (null != undoGroup)
            {
                undoGroup.Submit();
                undoGroup = null;
            }

            EndCurrentPaint();
            base.OnDisable();
        }
Пример #3
0
        private void UpdateEraser()
        {
            GameObject hoveredObject = Selection.HoveredObject;

            if (null == hoveredObject && Selection.SelectedObjects.Count == 0)
            {
                return;
            }

            // If we have a hovered object, only destroy it
            if (null != hoveredObject)
            {
                // Don't delete UI handles
                if (hoveredObject.GetComponent <UIHandle>())
                {
                    return;
                }

                if (VRInput.GetValue(VRInput.primaryController, CommonUsages.triggerButton))
                {
                    CommandGroup group = new CommandGroup("Erase Hovered Object");
                    try
                    {
                        RemoveCollidedObject(hoveredObject);
                        selector.RemoveSiblingsFromSelection(hoveredObject, false);

                        new CommandRemoveGameObject(hoveredObject).Submit();
                    }
                    finally
                    {
                        group.Submit();
                    }
                }
            }

            // If we don't have any hovered object but we collided with a selection, delete the whole selection
            else if (collidedObjects.Count > 0 && Selection.IsSelected(collidedObjects[0]))
            {
                if (VRInput.GetValue(VRInput.primaryController, CommonUsages.triggerButton))
                {
                    CommandGroup group = new CommandGroup("Erase Selected Objects");
                    try
                    {
                        foreach (GameObject gobject in Selection.SelectedObjects)
                        {
                            RemoveCollidedObject(gobject);
                            selector.RemoveSiblingsFromSelection(gobject, false);

                            new CommandRemoveGameObject(gobject).Submit();
                        }
                    }
                    finally
                    {
                        group.Submit();
                    }
                }
            }
        }
Пример #4
0
        private void AddObject(GameObject gobject)
        {
            if (!items.TryGetValue(selectedItem, out AssetBankItem item))
            {
                Debug.LogWarning($"Item {gobject.name} not found in Asset Bank (id: {selectedItem})");
                return;
            }

            // Get the position of the mouthpiece into matrix
            Matrix4x4 matrix = SceneManager.RightHanded.worldToLocalMatrix * mouthpiece.localToWorldMatrix;

            Maths.DecomposeMatrix(matrix, out Vector3 t, out _, out _);
            Vector3 scale = Vector3.one;

            CommandGroup group = new CommandGroup("Instantiate Bank Object");

            try
            {
                // Add the object to scene
                ClearSelection();
                CommandAddGameObject command = new CommandAddGameObject(gobject);
                command.Submit();
                GameObject newObject = command.newObject;
                if (item.imported)
                {
                    ParametersController controller = newObject.GetComponent <ParametersController>();
                    if (null == controller)
                    {
                        controller            = newObject.AddComponent <ParametersController>();
                        controller.isImported = true;
                        controller.importPath = item.assetName;
                    }
                }

                // Set the object size to 20cm in the user space
                Bounds bounds = new Bounds();
                foreach (var subMeshFilter in newObject.GetComponentsInChildren <MeshFilter>())
                {
                    if (!useDefaultInstantiationScale)
                    {
                        bounds.Encapsulate(subMeshFilter.mesh.bounds);
                    }
                }
                if (bounds.size.magnitude > 0)
                {
                    scale *= (0.2f / bounds.size.magnitude) / GlobalState.WorldScale;  // 0.2: 20cm
                }
                AddToSelection(newObject);
                SceneManager.SetObjectMatrix(newObject, Matrix4x4.TRS(t, Quaternion.identity, scale));
                Selection.HoveredObject = newObject;
            }
            finally
            {
                group.Submit();
            }
        }
Пример #5
0
        void RemoveLookAtConstraint()
        {
            CommandGroup commandGroup = new CommandGroup();

            foreach (var selected in Selection.SelectedObjects)
            {
                CommandRemoveConstraint command = new CommandRemoveConstraint(ConstraintType.LookAt, selected);
                command.Submit();
            }
            commandGroup.Submit();
        }
Пример #6
0
        protected override void OnDisable()
        {
            if (null != undoGroup)
            {
                undoGroup.Submit();
                undoGroup = null;
            }

            base.OnDisable();
            snapChangedEvent.RemoveListener(OnSnapChanged);
            Selection.onSelectionChanged.RemoveListener(UpdateGridFromSelection);
            if (null != grid)
            {
                grid.gameObject.SetActive(false);
            }
            if (null != boundingBox)
            {
                boundingBox.SetActive(false);
            }
        }
Пример #7
0
        public void Import(string filename)
        {
            Scene scene = Scene.Open(filename);

            CommandGroup group = new CommandGroup();

            var cameras = scene.ReadAll <CameraControllerSample>();

            foreach (var camera in cameras)
            {
                CameraControllerSample sample = camera.sample;

                GameObject cameraPrefab = ResourceManager.GetPrefab(PrefabID.Camera);
                GameObject instance     = SceneManager.InstantiateUnityPrefab(cameraPrefab);
                GameObject newObject    = SceneManager.AddObject(instance);

                newObject.name = camera.path.GetName();
                sample.CopyToCamera(newObject.GetComponent <CameraController>());
                Maths.DecomposeMatrix(sample.transform, out Vector3 position, out Quaternion rotation, out Vector3 scale);
                newObject.transform.localPosition = position;
                newObject.transform.localRotation = rotation;
                newObject.transform.localScale    = scale;
            }

            foreach (var m in scene.ReadAll <MeshSample>())
            {
                MeshSample sample = m.sample;

                GameObject gobject = new GameObject();
                gobject.name = m.path.GetName();
                Maths.DecomposeMatrix(sample.transform, out Vector3 position, out Quaternion rotation, out Vector3 scale);
                gobject.transform.localPosition = position;
                gobject.transform.localRotation = rotation;
                gobject.transform.localScale    = scale;

                Mesh mesh = new Mesh();
                mesh.SetVertices(sample.points);
                mesh.SetNormals(sample.normals);
                mesh.SetUVs(0, sample.st as Vector2[]);
                mesh.SetTriangles(sample.faceVertexIndices, 0);

                MeshFilter meshFilter = gobject.AddComponent <MeshFilter>();
                meshFilter.sharedMesh = mesh;
                MeshRenderer mr = gobject.AddComponent <MeshRenderer>();
                mr.sharedMaterial = ResourceManager.GetMaterial(MaterialID.ObjectOpaque);
                gobject.AddComponent <MeshCollider>();

                SceneManager.AddObject(gobject);
            }

            group.Submit();

            scene.Close();
        }
Пример #8
0
        private void ReleaseObject()
        {
            GlobalState.Animation.SetObjectAnimations(Target, objectData.Animation);
            CommandGroup group = new CommandGroup("Add Keyframe");

            switch (manipulationMode)
            {
            case AnimationTool.CurveEditMode.AddKeyframe:
                new CommandAddKeyframes(Target, Frame, objectData.lastPosition, objectData.lastRotation, objectData.lastScale).Submit();
                break;

            case AnimationTool.CurveEditMode.Zone:
                new CommandAddKeyframes(Target, Frame, startFrame, endFrame, objectData.lastPosition, objectData.lastRotation, objectData.lastScale).Submit();
                break;

            case AnimationTool.CurveEditMode.Segment:
                Dictionary <AnimatableProperty, List <AnimationKey> > keyframeList = new Dictionary <AnimatableProperty, List <AnimationKey> >();

                for (int prop = 0; prop < 6; prop++)
                {
                    AnimatableProperty property = (AnimatableProperty)prop;
                    keyframeList.Add(property, new List <AnimationKey>());
                    int firstKey = Mathf.Max(0, objectData.Solver.RequiredKeyframeIndices[0] - 1);
                    int lastKey  = Mathf.Min(objectData.Solver.ObjectAnimation.GetCurve(property).keys.Count - 1, objectData.Solver.RequiredKeyframeIndices[objectData.Solver.RequiredKeyframeIndices.Count - 1] + 1);
                    for (int i = firstKey; i <= lastKey; i++)
                    {
                        keyframeList[property].Add(objectData.Solver.ObjectAnimation.GetCurve(property).keys[i]);
                    }
                }
                new CommandAddKeyframes(Target, Frame, startFrame, endFrame, keyframeList).Submit();
                break;

            case AnimationTool.CurveEditMode.Tangents:
                Dictionary <AnimatableProperty, List <AnimationKey> > keyList = new Dictionary <AnimatableProperty, List <AnimationKey> >();
                for (int prop = 0; prop < 6; prop++)
                {
                    AnimatableProperty property = (AnimatableProperty)prop;
                    keyList.Add(property, new List <AnimationKey>());
                    int firstKey = objectData.Solver.RequiredKeyframeIndices[0];
                    int lastKey  = objectData.Solver.RequiredKeyframeIndices[1];
                    for (int i = firstKey; i <= lastKey; i++)
                    {
                        keyList[property].Add(objectData.Solver.ObjectAnimation.GetCurve(property).keys[i]);
                    }
                }
                new CommandAddKeyframes(Target, Frame, startFrame, endFrame, keyList).Submit();
                break;
            }
            group.Submit();
        }
Пример #9
0
        public void SelectGrassObject(GameObject grassObject)
        {
            CommandGroup command = new CommandGroup("Select Grass");

            try
            {
                SelectorBase.ClearSelection();
                SelectorBase.AddToSelection(grassObject);
            }
            finally
            {
                command.Submit();
            }
        }
Пример #10
0
        public void OnCheckEnableDepthOfField(bool value)
        {
            enableDepthOfField = value;
            CommandGroup commangGroup = new CommandGroup();

            foreach (GameObject item in Selection.SelectedObjects)
            {
                CameraController cameraController = item.GetComponent <CameraController>();
                if (null != cameraController)
                {
                    new CommandEnableDOF(item, value).Submit();
                }
            }
            commangGroup.Submit();
        }
Пример #11
0
        public void OnClearAnimations()
        {
            CommandGroup group = new CommandGroup("Clear Animations");

            try
            {
                foreach (GameObject gObject in Selection.SelectedObjects)
                {
                    new CommandClearAnimations(gObject).Submit();
                }
            }
            finally
            {
                group.Submit();
            }
        }
Пример #12
0
        public void OnAddKeyFrame()
        {
            CommandGroup group = new CommandGroup("Add Keyframe");

            try
            {
                foreach (GameObject item in Selection.SelectedObjects)
                {
                    new CommandAddKeyframes(item).Submit();
                }
            }
            finally
            {
                group.Submit();
            }
        }
Пример #13
0
        public void CreateLight(string lightType)
        {
            GameObject light = null;

            switch (lightType)
            {
            case "Sun":
                light = ResourceManager.GetPrefab(PrefabID.SunLight);
                break;

            case "Spot":
                light = ResourceManager.GetPrefab(PrefabID.SpotLight);
                break;

            case "Point":
                light = ResourceManager.GetPrefab(PrefabID.PointLight);
                break;
            }

            if (light)
            {
                Matrix4x4 matrix = parentContainer.worldToLocalMatrix * mouthpiece.localToWorldMatrix * Matrix4x4.Scale(new Vector3(10f, 10f, 10f));

                GameObject instance = SceneManager.InstantiateUnityPrefab(light);
                Vector3    position = matrix.GetColumn(3);
                Quaternion rotation = Quaternion.AngleAxis(180, Vector3.forward) * Quaternion.LookRotation(matrix.GetColumn(2), matrix.GetColumn(1));
                Vector3    scale    = new Vector3(matrix.GetColumn(0).magnitude, matrix.GetColumn(1).magnitude, matrix.GetColumn(2).magnitude);

                CommandGroup undoGroup = new CommandGroup("Instantiate Light");
                try
                {
                    ClearSelection();
                    CommandAddGameObject command = new CommandAddGameObject(instance);
                    command.Submit();
                    instance = command.newObject;
                    AddToSelection(instance);
                    SceneManager.SetObjectTransform(instance, position, rotation, scale);
                    Selection.HoveredObject = instance;
                }
                finally
                {
                    undoGroup.Submit();
                }
            }
        }
Пример #14
0
        public void OnSelectCameraItem(object sender, IndexedGameObjectArgs args)
        {
            GameObject item       = args.gobject;
            CameraItem cameraItem = item.GetComponent <CameraItem>();

            // Select camera in scene
            CommandGroup command = new CommandGroup("Select Camera");

            try
            {
                ClearSelection();
                AddToSelection(cameraItem.cameraObject);
            }
            finally
            {
                command.Submit();
            }
        }
Пример #15
0
        public void OnSelectLightItem(object sender, IndexedGameObjectArgs args)
        {
            GameObject item      = args.gobject;
            LightItem  lightItem = item.GetComponent <LightItem>();

            // Select light in scene
            CommandGroup command = new CommandGroup("Select Light");

            try
            {
                ClearSelection();
                AddToSelection(lightItem.lightObject);
            }
            finally
            {
                command.Submit();
            }
        }
Пример #16
0
        public void OnRemoveKeyFrame()
        {
            CommandGroup group = new CommandGroup("Remove Keyframe");

            try
            {
                foreach (GameObject gObject in Selection.SelectedObjects)
                {
                    if (GlobalState.Animation.ObjectHasKeyframeAt(gObject, GlobalState.Animation.CurrentFrame))
                    {
                        new CommandRemoveKeyframes(gObject).Submit();
                    }
                }
            }
            finally
            {
                group.Submit();
            }
        }
Пример #17
0
        public void StopRecording()
        {
            CommandGroup recordGroup = new CommandGroup("Record");

            foreach (var animationSet in recordingObjects.Values)
            {
                GameObject gobject = animationSet.transform.gameObject;
                foreach (Curve curve in animationSet.curves.Values)
                {
                    curve.ComputeCache();
                }
                new CommandRecordAnimations(gobject, oldAnimations[gobject], animationSet).Submit();
            }

            recordGroup.Submit();

            recordingObjects.Clear();
            oldAnimations.Clear();
            GlobalState.Settings.interpolation = preRecordInterpolation;
        }
Пример #18
0
        protected override void DoUpdateGui()
        {
            VRInput.ButtonEvent(VRInput.primaryController, CommonUsages.gripButton, () =>
            {
                if (UIObject)
                {
                    Matrix4x4 matrix        = cameraContainer.worldToLocalMatrix * mouthpiece.localToWorldMatrix * Matrix4x4.Scale(new Vector3(5f, 5f, 5f));
                    GameObject cameraPrefab = ResourceManager.GetPrefab(PrefabID.Camera);

                    GameObject instance = SceneManager.InstantiateUnityPrefab(cameraPrefab);
                    Vector3 position    = matrix.GetColumn(3);
                    Quaternion rotation = Quaternion.AngleAxis(180, Vector3.forward) * Quaternion.LookRotation(matrix.GetColumn(2), matrix.GetColumn(1));
                    Vector3 scale       = new Vector3(matrix.GetColumn(0).magnitude, matrix.GetColumn(1).magnitude, matrix.GetColumn(2).magnitude);

                    CommandGroup undoGroup = new CommandGroup("Instantiate Camera");
                    try
                    {
                        ClearSelection();
                        CommandAddGameObject command = new CommandAddGameObject(instance);
                        command.Submit();
                        GameObject newCamera = command.newObject;
                        AddToSelection(newCamera);
                        SceneManager.SetObjectTransform(instance, position, rotation, scale);
                        Selection.HoveredObject = newCamera;
                    }
                    finally
                    {
                        undoGroup.Submit();
                        UIObject = null;
                    }
                }
                OnStartGrip();
            },
                                () =>
            {
                OnEndGrip();
            });

            // called to update focal slider value
            UpdateUI();
        }
Пример #19
0
        void SetLookAtConstraint(GameObject hovered)
        {
            if (null == hovered)
            {
                return;
            }
            UIHandle uiHandle = hovered.GetComponent <UIHandle>();

            if (null != uiHandle)
            {
                return;
            }

            CommandGroup commandGroup = new CommandGroup();

            foreach (var selected in Selection.SelectedObjects)
            {
                CommandAddConstraint command = new CommandAddConstraint(ConstraintType.LookAt, selected, hovered);
                command.Submit();
            }
            commandGroup.Submit();
        }
Пример #20
0
        public void OnDeleteSelection()
        {
            if (Selection.SelectedObjects.Count == 0)
            {
                return;
            }

            CommandGroup group = new CommandGroup("Delete All Selection");

            try
            {
                HashSet <GameObject> copy = new HashSet <GameObject>(Selection.SelectedObjects);
                ClearSelection();
                foreach (GameObject selected in copy)
                {
                    new CommandRemoveGameObject(selected).Submit();
                }
            }
            finally
            {
                group.Submit();
            }
        }
Пример #21
0
        // delta = +/- 1
        public void OnUpdateKeyframe(int i, int delta)
        {
            int frame = GetKeyAtFrame(i);

            if (frame == -1)
            {
                return;
            }

            CommandGroup group = new CommandGroup("Add Keyframe");

            try
            {
                foreach (GameObject item in Selection.SelectedObjects)
                {
                    new CommandMoveKeyframes(item, frame, frame + delta).Submit();
                }
            }
            finally
            {
                group.Submit();
            }
        }
Пример #22
0
        private void ReleaseHuman()
        {
            if (manipulationMode == AnimationTool.CurveEditMode.AddKeyframe || manipulationMode == AnimationTool.CurveEditMode.Zone)
            {
                return;
            }

            List <GameObject> objectList = new List <GameObject>();
            List <Dictionary <AnimatableProperty, List <AnimationKey> > > keyframesLists = new List <Dictionary <AnimatableProperty, List <AnimationKey> > >();

            while (humanData.Solver.NextStep())
            {
            }
            humanData.Solver.ClearJob();

            int index = 0;

            for (int i = 0; i < humanData.Controller.PathToRoot.Count; i++)
            {
                if (null == humanData.Controller.AnimToRoot[i])
                {
                    continue;
                }
                keyframesLists.Add(new Dictionary <AnimatableProperty, List <AnimationKey> >());
                for (int pIndex = 0; pIndex < 6; pIndex++)
                {
                    AnimatableProperty  property = (AnimatableProperty)pIndex;
                    List <AnimationKey> keys     = new List <AnimationKey>();
                    Curve curve = humanData.Controller.AnimToRoot[i].GetCurve(property);
                    for (int k = 0; k < humanData.Solver.requiredKeyframe.Count; k++)
                    {
                        curve.GetKeyIndex(humanData.Solver.requiredKeyframe[k], out int keyIndex);
                        keys.Add(curve.keys[keyIndex]);
                    }
                    keyframesLists[keyframesLists.Count - 1].Add(property, keys);
                }
                GlobalState.Animation.SetObjectAnimations(humanData.Animations[index].transform.gameObject, humanData.Animations[index]);
                objectList.Add(humanData.Animations[index].transform.gameObject);
                index++;
            }

            keyframesLists.Add(new Dictionary <AnimatableProperty, List <AnimationKey> >());
            for (int prop = 0; prop < 6; prop++)
            {
                AnimatableProperty  property = (AnimatableProperty)prop;
                List <AnimationKey> keys     = new List <AnimationKey>();
                Curve curve = humanData.Controller.Animation.GetCurve(property);

                curve.GetKeyIndex(humanData.Solver.requiredKeyframe[0], out int beforKey);
                for (int k = 0; k < humanData.Solver.requiredKeyframe.Count; k++)
                {
                    curve.GetKeyIndex(humanData.Solver.requiredKeyframe[k], out int keyIndex);
                    keys.Add(curve.keys[keyIndex]);
                }
                curve.GetKeyIndex(humanData.Solver.requiredKeyframe[humanData.Solver.requiredKeyframe.Count - 1], out int afterKey);
                keyframesLists[keyframesLists.Count - 1].Add(property, keys);
            }
            GlobalState.Animation.SetObjectAnimations(Target, humanData.ObjectAnimation);
            objectList.Add(Target);

            GlobalState.Animation.onChangeCurve.Invoke(humanData.Animations[0].transform.gameObject, AnimatableProperty.PositionX);
            CommandGroup group = new CommandGroup("Add Keyframe");

            new CommandAddKeyframes(humanData.Controller.RootController.gameObject, objectList, Frame, startFrame, endFrame, keyframesLists).Submit();
            group.Submit();
        }