Esempio n. 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));
                }
            }
        }
        /// <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>();
        }
        public void Tapped()
        {
            // Return if there isn't a Manipulation Manager
            if (ManipulationManager.Instance == null)
            {
                UnityEngine.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.Target == this.gameObject)
            {
                return;
            }

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

            if (ShowAppBar)
            {
                // 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;
            }
        }
Esempio n. 4
0
        protected override void DrawGizmoObjects()
        {
            if (boundingBox.Target == null)
            {
                edgeRenderer.enabled = false;
                return;
            }

            // 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;
            localBounds.GetCornerAndMidPointPositions(transform, ref handlePositions);
            cubeHandleMatrixes.Clear();
            sphereHandleMatrixes.Clear();

            // 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;
            Vector3    scale    = Vector3.one * Mathf.Min(Mathf.Min(localBounds.size.x, localBounds.size.y), localBounds.size.z);


            // Get the index of our active handle so we can draw it with a different material
            activeHandleIndex = -1;
            BoundingBoxManipulate manipulate = boundingBox.GetComponent <BoundingBoxManipulate>();

            if (manipulate.ActiveHandle != null && manipulate.ActiveHandle.HandleType != BoundingBoxHandle.HandleTypeEnum.Drag)
            {
                activeHandleIndex = (int)manipulate.ActiveHandle.HandleType;
            }

            // If we're not accepting input, just draw the box bounds
            if (!manipulate.AcceptInput)
            {
                edgeRenderer.enabled = true;
                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
                    GetAllHandleMatrixes(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
                    GetAllHandleMatrixes(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
                    GetAllHandleMatrixes(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;
                }
            }
        }