Beispiel #1
0
        private void EndCurrentPaint()
        {
            switch (paintTool)
            {
            case PaintTools.Pencil:
            case PaintTools.FlatPencil:
            case PaintTools.ConvexHull:
            {
                // Bake line renderer into a mesh so we can raycast on it
                if (currentPaint != null)
                {
                    TranslatePaintToItsCenter();

                    GameObject paintObject = SceneManager.InstantiateUnityPrefab(currentPaint);
                    GameObject.Destroy(currentPaint.transform.parent.gameObject);
                    currentPaint = null;

                    CommandAddGameObject command = new CommandAddGameObject(paintObject);
                    command.Submit();
                    GameObject paintInstance = command.newObject;

                    PaintController controller = paintInstance.GetComponent <PaintController>();
                    controller.color               = GlobalState.CurrentColor;
                    controller.controlPoints       = freeDraw.controlPoints;
                    controller.controlPointsRadius = freeDraw.controlPointsRadius;
                }
                break;
            }

            case PaintTools.Volume:
            {
                if (currentVolume != null)
                {
                    if (volumeEditionMode == VolumeEditionMode.Create)
                    {
                        GameObject volumeObject = SceneManager.InstantiateUnityPrefab(currentVolume);
                        GameObject.Destroy(currentVolume.transform.parent.gameObject);
                        currentVolume = null;

                        CommandAddGameObject command = new CommandAddGameObject(volumeObject);
                        command.Submit();
                        GameObject volumeInstance = command.newObject;

                        VolumeController controller = volumeInstance.GetComponent <VolumeController>();
                        controller.color      = GlobalState.CurrentColor;
                        controller.origin     = volumeGenerator.origin;
                        controller.bounds     = volumeGenerator.bounds;
                        controller.field      = volumeGenerator.field;
                        controller.resolution = volumeGenerator.resolution;
                        controller.stepSize   = volumeGenerator.stepSize;
                    }
                    else         // EDIT
                    {
                        // TODO: send an update mesh command. Which is it???
                    }
                }
            }
            break;
            }
        }
Beispiel #2
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();
            }
        }
Beispiel #3
0
        private void StopPainting()
        {
            if (grass == null)
            {
                return;
            }

            // Unparent from RIGHT_HANDED so that CommandAddGameObject can RE-ADD.
            grass.transform.SetParent(null, false);
            CommandAddGameObject command = new CommandAddGameObject(grass.gameObject);

            command.Submit();

            grass = null;

            uiActiveButton.Checked = false; // may be useless, StopPainting come from clicking on that button.
        }
Beispiel #4
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();
                }
            }
        }
Beispiel #5
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();
        }