Beispiel #1
0
        private void GetAllHandleMatrixes(Vector3[] positions, Quaternion rotation, Vector3 scale, List <Matrix4x4> cubeMatrixes, List <Matrix4x4> sphereMatrixes, int targetIndex)
        {
            BoundingBoxManipulate manipulate = boundingBox.GetComponent <BoundingBoxManipulate>();

            // Get all our handle positions for cubes
            if ((manipulate.PermittedOperations & BoundingBoxManipulate.OperationEnum.ScaleUniform) == BoundingBoxManipulate.OperationEnum.ScaleUniform)
            {
                for (int i = BoundsExtentions.LBF; i <= BoundsExtentions.RTB; i++)
                {
                    if (i == targetIndex)
                    {
                        continue;
                    }

                    cubeMatrixes.Add(Matrix4x4.TRS(handlePositions[i], rotation, scale));
                }
            }
            // Get all our handle positions for rotation
            if ((manipulate.PermittedOperations & BoundingBoxManipulate.OperationEnum.RotateX) == BoundingBoxManipulate.OperationEnum.RotateX)
            {
                for (int i = BoundsExtentions.LTF_RTF; i <= BoundsExtentions.RBB_LBB; i++)
                {
                    if (i == targetIndex)
                    {
                        continue;
                    }

                    sphereMatrixes.Add(Matrix4x4.TRS(handlePositions[i], rotation, scale));
                }
            }

            if ((manipulate.PermittedOperations & BoundingBoxManipulate.OperationEnum.RotateY) == BoundingBoxManipulate.OperationEnum.RotateY)
            {
                for (int i = BoundsExtentions.LTF_LBF; i <= BoundsExtentions.RTF_RBF; i++)
                {
                    if (i == targetIndex)
                    {
                        continue;
                    }

                    sphereMatrixes.Add(Matrix4x4.TRS(handlePositions[i], rotation, scale));
                }
            }

            if ((manipulate.PermittedOperations & BoundingBoxManipulate.OperationEnum.RotateZ) == BoundingBoxManipulate.OperationEnum.RotateZ)
            {
                for (int i = BoundsExtentions.RBF_RBB; i <= BoundsExtentions.LTF_LTB; i++)
                {
                    if (i == targetIndex)
                    {
                        continue;
                    }

                    sphereMatrixes.Add(Matrix4x4.TRS(handlePositions[i], rotation, scale));
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// On Start spawn in the active bounding box and app bar for manipulation
        /// </summary>
        protected void Start()
        {
            // Spawn in the bounding box and assign internally
            GameObject boundBoxGO = Instantiate(BoundingBoxPrefab) as GameObject;

            m_boundingBox = boundBoxGO.GetComponent <BoundingBoxManipulate>();

            // Spawn in the app bar and assign internally
            GameObject appBarGO = Instantiate(AppBarPrefab) as GameObject;

            m_appBar = appBarGO.GetComponent <AppBar>();
        }
Beispiel #3
0
        protected override void OnTapped(GameObject obj, InteractionManager.InteractionEventArgs eventArgs)
        {
            if (Time.time < lastTimeTapped + coolDownTime)
            {
                return;
            }

            lastTimeTapped = Time.time;

            base.OnTapped(obj, eventArgs);

            switch (obj.name)
            {
            case "Remove":
                // Destroy the target object
                GameObject.Destroy(boundingBox.Target);
                // Set our bounding box to null so we'll disappear
                boundingBox = null;
                break;

            case "Adjust":
                // Make the bounding box active so users can manipulate it
                State = AppBarStateEnum.Manipulation;
                break;

            case "Hide":
                // Make the bounding box inactive and invisible
                State = AppBarStateEnum.Hidden;
                break;

            case "Show":
                State = AppBarStateEnum.Default;
                break;

            case "Done":
                State = AppBarStateEnum.Default;
                break;

            // Customization
            case "Ready":
                Debug.Log("Ready");
                Destroy(this.gameObject);
                Destroy(GameObject.Find("Drag"));
                Destroy(GameObject.Find("BoundingBoxShell(Clone)"));
                Destroy(GameObject.Find("BoundingBoxTransformHelper"));
                game.ChangeStateTo(Game.State.SearchingCube);
                break;

            default:
                break;
            }
        }
Beispiel #4
0
        public void Tapped()
        {
            // If we've already got a bounding box and it's pointing to us, do nothing
            if (boundingBox != null && boundingBox.Target == this.gameObject)
            {
                return;
            }

            // Try to find our bounding box
            if (boundingBox == null)
            {
                boundingBox = GameObject.FindObjectOfType <BoundingBoxManipulate>();
                if (boundingBox == null)
                {
                    Debug.LogError("Couldn't find bounding box for object " + name);
                    return;
                }
            }

            // Try to find our toolbar
            if (toolbar == null)
            {
                toolbar = GameObject.FindObjectOfType <ManipulationToolbar>();
                if (toolbar == null)
                {
                    // This is only a problem if we want to display one
                    if (ManipulationDisplay != ManipulationToolbar.DisplayEnum.None)
                    {
                        Debug.LogError("Couldn't find toolbar for object " + name);
                        return;
                    }
                }
            }

            // Set the bounding box's target and permitted operations
            boundingBox.PermittedOperations = PermittedOperations;
            boundingBox.Target = gameObject;

            if (ManipulationDisplay != ManipulationToolbar.DisplayEnum.None)
            {
                // Show it and set its bounding box object
                toolbar.BoundingBox = boundingBox;
                toolbar.Reset();
            }
            else if (toolbar != null)
            {
                // Set its bounding box to null to hide it
                toolbar.BoundingBox = null;
                // Set to accept input immediately
                boundingBox.AcceptInput = true;
            }
        }
Beispiel #5
0
        public void Tapped()
        {
            // Return if there isn't a Manipulation Manager
            if (ManipulationManager.Instance == null)
            {
                Debug.LogError("No manipulation manager for " + name);
                return;
            }

            // Try to find our bounding box
            if (boundingBox == null)
            {
                boundingBox = ManipulationManager.Instance.ActiveBoundingBox;
            }

            // Try to find our toolbar
            if (toolbar == null)
            {
                toolbar = ManipulationManager.Instance.ActiveAppBar;
            }

            // If we've already got a bounding box and it's pointing to us, do nothing
            if (boundingBox != null && boundingBox.gameObject.activeSelf && boundingBox.Target == this.gameObject)
            {
                return;
            }

            // Set the bounding box's target and permitted operations
            boundingBox.PermittedOperations = PermittedOperations;
            boundingBox.FlattenPreference   = FlattenPreference;
            boundingBox.Target = gameObject;
            boundingBox.BoundsMethodOverride = BoundsCalculationMethod;
            boundingBox.gameObject.SetActive(true);

            if (ShowAppBar)
            {
                // Show it and set its bounding box object
                toolbar.BoundingBox = boundingBox;
                toolbar.Reset();
                toolbar.gameObject.SetActive(true);
            }
            else if (toolbar != null)
            {
                // Set its bounding box to null to hide it
                toolbar.BoundingBox = null;
                // Set to accept input immediately
                boundingBox.AcceptInput = true;
            }
        }
Beispiel #6
0
        protected override void OnTapped(GameObject obj, InteractionManager.InteractionEventArgs eventArgs)
        {
            if (Time.time < lastTimeTapped + coolDownTime)
            {
                return;
            }

            lastTimeTapped = Time.time;
            lastFocusExit  = Time.time;

            base.OnTapped(obj, eventArgs);

            switch (obj.name)
            {
            case "Remove":
                // Destroy the target object
                GameObject.Destroy(boundingBox.Target);
                // Set our bounding box to null so we'll disappear
                boundingBox = null;
                break;

            case "Adjust":
                // Make the bounding box active so users can manipulate it
                State = AppBarStateEnum.Manipulation;
                break;

            case "Hide":
                // Make the bounding box inactive and invisible
                State = AppBarStateEnum.Hidden;
                break;

            case "Show":
                State = AppBarStateEnum.Default;
                break;

            case "Done":
                State = AppBarStateEnum.Default;
                break;

            default:
                break;
            }
        }
        protected override void DrawGizmoObjects()
        {
            if (boundingBox.Target == null)
            {
                edgeRenderer.enabled = false;
                return;
            }

            // Get our manipulate bb
            BoundingBoxManipulate manipulate = boundingBox.GetComponent <BoundingBoxManipulate>();

            // Reset our scale - only scaleTransform can be changed
            transform.localScale = Vector3.one;

            // Get the positions of our handles
            localBounds.size   = scaleTransform.localScale;
            localBounds.center = Vector3.zero;
            cubeHandleMatrixes.Clear();
            sphereHandleMatrixes.Clear();
            if (manipulate.FlattenedAxis == BoundingBox.FlattenModeEnum.DoNotFlatten)
            {
                localBounds.GetCornerAndMidPointPositions(transform, ref handlePositions);
            }
            else
            {
                switch (manipulate.FlattenedAxis)
                {
                case BoundingBox.FlattenModeEnum.FlattenX:
                    localBounds.GetCornerAndMidPointPositions2D(transform, ref handlePositions, BoundsExtentions.Axis.X);
                    break;

                case BoundingBox.FlattenModeEnum.FlattenY:
                    localBounds.GetCornerAndMidPointPositions2D(transform, ref handlePositions, BoundsExtentions.Axis.Y);
                    break;

                case BoundingBox.FlattenModeEnum.FlattenZ:
                    localBounds.GetCornerAndMidPointPositions2D(transform, ref handlePositions, BoundsExtentions.Axis.Z);
                    break;
                }
            }

            // Pos / rot / scale for our handles
            // Scale is based on smallest dimension to ensure handles don't overlap
            // Rotation is just the rotation of our gizmo
            Vector3    pos               = Vector3.zero;
            Quaternion rotation          = transform.rotation;
            float      smallestDimension = Mathf.Min(Mathf.Min(localBounds.size.x, localBounds.size.y), localBounds.size.z);

            if (ClampHandleScale)
            {
                smallestDimension = Mathf.Clamp(smallestDimension, HandleScaleMin, HandleScaleMax);
            }
            Vector3 scale = Vector3.one * smallestDimension;

            // Get the index of our active handle so we can draw it with a different material
            activeHandleIndex = -1;
            if (manipulate.ActiveHandle != null && manipulate.ActiveHandle.HandleType != BoundingBoxHandle.HandleTypeEnum.Drag)
            {
                if (manipulate.ActiveHandle.HandleTypeFlattened == BoundingBoxHandle.HandleTypeFlattenedEnum.None)
                {
                    activeHandleIndex = (int)manipulate.ActiveHandle.HandleType;
                }
                else
                {
                    activeHandleIndex = (int)manipulate.ActiveHandle.HandleTypeFlattened;
                }
            }

            // If we're not accepting input, just draw the box bounds
            if (!manipulate.AcceptInput)
            {
                edgeRenderer.enabled = DisplayEdgesWhenSelected;
                edgeMaterial.SetColor("_EmissionColor", InactiveColor);
            }
            else
            {
                switch (manipulate.CurrentOperation)
                {
                default:
                case BoundingBoxManipulate.OperationEnum.None:
                    // No visible bounds
                    // No visible handles
                    edgeRenderer.enabled = false;
                    break;

                case BoundingBoxManipulate.OperationEnum.Drag:
                    // Target bounds
                    // Inactive scale handles
                    // Inactive rotate handles (based on permitted operations)
                    edgeRenderer.enabled = true;
                    edgeMaterial.SetColor("_EmissionColor", manipulate.ManipulatingNow ? TargetColor : ActiveColor);

                    // Get all our handle positions
                    if (manipulate.FlattenedAxis == BoundingBox.FlattenModeEnum.DoNotFlatten)
                    {
                        GetUnflattenedHandleMatrixes(manipulate.PermittedOperations, handlePositions, rotation, scale, cubeHandleMatrixes, sphereHandleMatrixes, activeHandleIndex);
                    }
                    else
                    {
                        GetFlattenedHandleMatrixes(manipulate.PermittedOperations, manipulate.FlattenedAxis, handlePositions, rotation, scale, cubeHandleMatrixes, sphereHandleMatrixes, activeHandleIndex);
                    }
                    // Draw our handles
                    DrawHandleMeshes(cubeHandleMatrixes, BoxMesh, InactiveColor);
                    DrawHandleMeshes(sphereHandleMatrixes, SphereMesh, InactiveColor);
                    break;

                case BoundingBoxManipulate.OperationEnum.RotateY:
                case BoundingBoxManipulate.OperationEnum.RotateZ:
                case BoundingBoxManipulate.OperationEnum.RotateX:
                    // Visible bounds
                    // Inactive scale handles
                    // Active / Target rotate handles (based on permitted operations)
                    edgeRenderer.enabled = true;
                    edgeMaterial.SetColor("_EmissionColor", InactiveColor);

                    // Get all our handle positions
                    if (manipulate.FlattenedAxis == BoundingBox.FlattenModeEnum.DoNotFlatten)
                    {
                        GetUnflattenedHandleMatrixes(manipulate.PermittedOperations, handlePositions, rotation, scale, cubeHandleMatrixes, sphereHandleMatrixes, activeHandleIndex);
                    }
                    else
                    {
                        GetFlattenedHandleMatrixes(manipulate.PermittedOperations, manipulate.FlattenedAxis, handlePositions, rotation, scale, cubeHandleMatrixes, sphereHandleMatrixes, activeHandleIndex);
                    }
                    // Draw our handles
                    DrawHandleMeshes(cubeHandleMatrixes, BoxMesh, InactiveColor);
                    DrawHandleMeshes(sphereHandleMatrixes, SphereMesh, ActiveColor);
                    DrawTargetMesh(activeHandleIndex, SphereMesh, handlePositions, rotation, scale, manipulate.ManipulatingNow ? TargetColor : ActiveColor);
                    break;

                case BoundingBoxManipulate.OperationEnum.ScaleUniform:
                    // Inactive bounds
                    // Active / Target scale handles
                    // Inactive rotate handles  (based on permitted operations)
                    edgeRenderer.enabled = true;
                    edgeMaterial.SetColor("_EmissionColor", InactiveColor);

                    // Get all our handle positions
                    if (manipulate.FlattenedAxis == BoundingBox.FlattenModeEnum.DoNotFlatten)
                    {
                        GetUnflattenedHandleMatrixes(manipulate.PermittedOperations, handlePositions, rotation, scale, cubeHandleMatrixes, sphereHandleMatrixes, activeHandleIndex);
                    }
                    else
                    {
                        GetFlattenedHandleMatrixes(manipulate.PermittedOperations, manipulate.FlattenedAxis, handlePositions, rotation, scale, cubeHandleMatrixes, sphereHandleMatrixes, activeHandleIndex);
                    }
                    // Draw our handles
                    DrawHandleMeshes(cubeHandleMatrixes, BoxMesh, ActiveColor);
                    DrawHandleMeshes(sphereHandleMatrixes, SphereMesh, InactiveColor);
                    DrawTargetMesh(activeHandleIndex, BoxMesh, handlePositions, rotation, scale, manipulate.ManipulatingNow ? TargetColor : ActiveColor);
                    break;
                }
            }
        }