Exemplo n.º 1
0
 internal void SetHighlighted()
 {
     //update the box material to the grabbed material
     if (boxDisplay != null)
     {
         VisualUtils.ApplyMaterialToAllRenderers(boxDisplay, config.BoxGrabbedMaterial);
     }
 }
Exemplo n.º 2
0
 internal void ResetVisibility(bool activate)
 {
     //set box display visibility
     if (boxDisplay != null)
     {
         boxDisplay.SetActive(activate);
         VisualUtils.ApplyMaterialToAllRenderers(boxDisplay, config.BoxMaterial);
     }
 }
Exemplo n.º 3
0
        private void CreateHandles(Transform parent, bool drawManipulationTether)
        {
            for (int i = 0; i < edgeCenters.Length; ++i)
            {
                GameObject midpoint = new GameObject();
                midpoint.name = "midpoint_" + i.ToString();
                midpoint.transform.position = edgeCenters[i];
                midpoint.transform.parent   = parent;

                GameObject midpointVisual;
                GameObject prefabType = config.HandlePrefab;
                if (prefabType != null)
                {
                    midpointVisual = GameObject.Instantiate(prefabType);
                }
                else
                {
                    midpointVisual = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                    GameObject.Destroy(midpointVisual.GetComponent <SphereCollider>());
                }

                // Align handle with its edge assuming that the prefab is initially aligned with the up direction
                if (edgeAxes[i] == CardinalAxisType.X)
                {
                    Quaternion realignment = Quaternion.FromToRotation(Vector3.up, Vector3.right);
                    midpointVisual.transform.localRotation = realignment * midpointVisual.transform.localRotation;
                }
                else if (edgeAxes[i] == CardinalAxisType.Z)
                {
                    Quaternion realignment = Quaternion.FromToRotation(Vector3.up, Vector3.forward);
                    midpointVisual.transform.localRotation = realignment * midpointVisual.transform.localRotation;
                }

                Bounds midpointBounds = VisualUtils.GetMaxBounds(midpointVisual);
                float  maxDim         = Mathf.Max(
                    Mathf.Max(midpointBounds.size.x, midpointBounds.size.y),
                    midpointBounds.size.z);
                float invScale = config.HandleSize / maxDim;

                midpointVisual.name                    = "visuals";
                midpointVisual.transform.parent        = midpoint.transform;
                midpointVisual.transform.localScale    = new Vector3(invScale, invScale, invScale);
                midpointVisual.transform.localPosition = Vector3.zero;

                VisualUtils.AddComponentsToAffordance(midpoint, new Bounds(midpointBounds.center * invScale, midpointBounds.size * invScale),
                                                      config.RotationHandlePrefabColliderType, CursorContextInfo.CursorAction.Rotate, config.ColliderPadding, parent, drawManipulationTether);

                handles.Add(midpoint.transform);

                if (config.HandleMaterial != null)
                {
                    VisualUtils.ApplyMaterialToAllRenderers(midpointVisual, config.HandleMaterial);
                }
            }
        }
 internal void ResetHandleVisibility(bool isVisible)
 {
     if (handles != null)
     {
         for (int i = 0; i < handles.Count; ++i)
         {
             handles[i].gameObject.SetActive(isVisible && IsVisible(handles[i]));
             VisualUtils.ApplyMaterialToAllRenderers(handles[i].gameObject, BaseConfig.HandleMaterial);
         }
     }
 }
Exemplo n.º 5
0
 protected void UpdateBaseMaterial()
 {
     if (handles != null)
     {
         for (int i = 0; i < handles.Count; ++i)
         {
             if (handles[i] != highlightedHandle)
             {
                 VisualUtils.ApplyMaterialToAllRenderers(handles[i].gameObject, BaseConfig.HandleMaterial);
             }
         }
     }
 }
Exemplo n.º 6
0
        internal void AddBoxDisplay(Transform parent, Vector3 currentBoundsExtents, FlattenModeType flattenAxis)
        {
            if (config.BoxMaterial != null)
            {
                // this has to be cube even in flattened mode as flattened box display can still have a thickness of flattenAxisDisplayScale
                boxDisplay = GameObject.CreatePrimitive(PrimitiveType.Cube);
                GameObject.Destroy(boxDisplay.GetComponent <Collider>());
                boxDisplay.name = "bounding box";

                VisualUtils.ApplyMaterialToAllRenderers(boxDisplay, config.BoxMaterial);
                boxDisplay.transform.localScale = GetBoxDisplayScale(currentBoundsExtents, flattenAxis);
                boxDisplay.transform.parent     = parent;
            }
        }
Exemplo n.º 7
0
 internal void Reset(bool visible)
 {
     isVisible = visible;
     // Set box display visibility
     if (boxDisplay != null)
     {
         bool activate = config.BoxMaterial != null && isVisible; // only set active if material is set
         boxDisplay.SetActive(activate);
         if (activate)
         {
             VisualUtils.ApplyMaterialToAllRenderers(boxDisplay, config.BoxMaterial);
         }
     }
 }
Exemplo n.º 8
0
 protected void ResetHandles()
 {
     if (handles != null)
     {
         for (int i = 0; i < handles.Count; ++i)
         {
             bool isVisible = IsVisible(handles[i]);
             handles[i].gameObject.SetActive(isVisible);
             if (isVisible)
             {
                 VisualUtils.ApplyMaterialToAllRenderers(handles[i].gameObject, BaseConfig.HandleMaterial);
             }
         }
     }
     highlightedHandle = null;
 }
 internal void SetHighlighted(Transform handleToHighlight)
 {
     // turn off all handles that aren't the handle we want to highlight
     if (handles != null)
     {
         for (int i = 0; i < handles.Count; ++i)
         {
             if (handles[i] != handleToHighlight)
             {
                 handles[i].gameObject.SetActive(false);
             }
             else
             {
                 VisualUtils.ApplyMaterialToAllRenderers(handles[i].gameObject, BaseConfig.HandleGrabbedMaterial);
             }
         }
     }
 }
Exemplo n.º 10
0
        /// <summary>
        /// Creates the corner visual and returns the bounds of the created visual
        /// </summary>
        /// <param name="parent">parent of visual</param>
        /// <param name="isFlattened">instantiate in flattened mode - slate</param>
        /// <returns>bounds of the created visual</returns>
        private Bounds CreateVisual(GameObject parent, bool isFlattened)
        {
            // figure out which prefab to instantiate
            GameObject cornerVisual = null;

            areHandlesFlattened = isFlattened;
            GameObject prefabType = isFlattened ? config.HandleSlatePrefab : config.HandlePrefab;

            if (prefabType == null)
            {
                // instantiate default prefab, a cube. Remove the box collider from it
                cornerVisual = GameObject.CreatePrimitive(PrimitiveType.Cube);
                cornerVisual.transform.parent        = parent.transform;
                cornerVisual.transform.localPosition = Vector3.zero;
                GameObject.Destroy(cornerVisual.GetComponent <BoxCollider>());
            }
            else
            {
                cornerVisual = GameObject.Instantiate(prefabType, parent.transform);
            }

            if (isFlattened)
            {
                // Rotate 2D slate handle asset for proper orientation
                cornerVisual.transform.Rotate(0, 0, -90);
            }

            cornerVisual.name = visualsName;

            // this is the size of the corner visuals
            var   cornerbounds = VisualUtils.GetMaxBounds(cornerVisual);
            float maxDim       = Mathf.Max(Mathf.Max(cornerbounds.size.x, cornerbounds.size.y), cornerbounds.size.z);

            cornerbounds.size = maxDim * Vector3.one;

            // we need to multiply by this amount to get to desired scale handle size
            var invScale = cornerbounds.size.x == 0.0f ? 0.0f : config.HandleSize / cornerbounds.size.x;

            cornerVisual.transform.localScale = new Vector3(invScale, invScale, invScale);

            VisualUtils.ApplyMaterialToAllRenderers(cornerVisual, config.HandleMaterial);

            return(cornerbounds);
        }
Exemplo n.º 11
0
        private Bounds CreateVisual(int handleIndex, GameObject parent)
        {
            GameObject midpointVisual;
            GameObject prefabType = config.HandlePrefab;

            if (prefabType != null)
            {
                midpointVisual = Object.Instantiate(prefabType);
            }
            else
            {
                midpointVisual = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                Object.Destroy(midpointVisual.GetComponent <SphereCollider>());
            }

            // Align handle with its edge assuming that the prefab is initially aligned with the up direction
            if (edgeAxes[handleIndex] == CardinalAxisType.X)
            {
                Quaternion realignment = Quaternion.FromToRotation(Vector3.up, Vector3.right);
                midpointVisual.transform.localRotation = realignment * midpointVisual.transform.localRotation;
            }
            else if (edgeAxes[handleIndex] == CardinalAxisType.Z)
            {
                Quaternion realignment = Quaternion.FromToRotation(Vector3.up, Vector3.forward);
                midpointVisual.transform.localRotation = realignment * midpointVisual.transform.localRotation;
            }

            Bounds midpointBounds = VisualUtils.GetMaxBounds(midpointVisual);
            float  maxDim         = VisualUtils.GetMaxComponent(midpointBounds.size);
            float  invScale       = maxDim == 0.0f ? 0.0f : config.HandleSize / maxDim;

            midpointVisual.name                    = "visuals";
            midpointVisual.transform.parent        = parent.transform;
            midpointVisual.transform.localScale    = new Vector3(invScale, invScale, invScale);
            midpointVisual.transform.localPosition = Vector3.zero;

            if (config.HandleMaterial != null)
            {
                VisualUtils.ApplyMaterialToAllRenderers(midpointVisual, config.HandleMaterial);
            }

            return(midpointBounds);
        }
Exemplo n.º 12
0
        private Bounds CreateVisual(int handleIndex, GameObject parent)
        {
            GameObject midpointVisual;
            GameObject prefabType = config.HandlePrefab;

            if (prefabType != null)
            {
                midpointVisual = Object.Instantiate(prefabType);
            }
            else
            {
                midpointVisual = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                if (config.HandlePrefabColliderType != HandlePrefabCollider.Sphere)
                {
                    Object.Destroy(midpointVisual.GetComponent <SphereCollider>());
                }
            }

            Quaternion realignment = GetRotationRealignment(handleIndex);

            midpointVisual.transform.localRotation = realignment * midpointVisual.transform.localRotation;

            Bounds midpointBounds = VisualUtils.GetMaxBounds(midpointVisual);
            float  maxDim         = VisualUtils.GetMaxComponent(midpointBounds.size);
            float  invScale       = maxDim == 0.0f ? 0.0f : config.HandleSize / maxDim;

            midpointVisual.name                    = visualsName;
            midpointVisual.transform.parent        = parent.transform;
            midpointVisual.transform.localScale    = new Vector3(invScale, invScale, invScale);
            midpointVisual.transform.localPosition = Vector3.zero;

            if (config.HandleMaterial != null)
            {
                VisualUtils.ApplyMaterialToAllRenderers(midpointVisual, config.HandleMaterial);
            }

            return(midpointBounds);
        }
        internal void Create(ref Vector3[] boundsCorners, Transform parent, bool drawManipulationTether, bool isFlattened)
        {
            // create corners
            for (int i = 0; i < boundsCorners.Length; ++i)
            {
                GameObject corner = new GameObject
                {
                    name = "corner_" + i.ToString()
                };
                corner.transform.parent        = parent;
                corner.transform.localPosition = boundsCorners[i];

                GameObject visualsScale = new GameObject();
                visualsScale.name                    = "visualsScale";
                visualsScale.transform.parent        = corner.transform;
                visualsScale.transform.localPosition = Vector3.zero;

                // Compute mirroring scale
                {
                    Vector3 p = boundsCorners[i];
                    visualsScale.transform.localScale = new Vector3(Mathf.Sign(p[0]), Mathf.Sign(p[1]), Mathf.Sign(p[2]));
                }

                // figure out which prefab to instantiate
                GameObject cornerVisual = null;
                GameObject prefabType   = isFlattened ? config.HandleSlatePrefab : config.HandlePrefab;
                if (prefabType == null)
                {
                    // instantiate default prefab, a cube. Remove the box collider from it
                    cornerVisual = GameObject.CreatePrimitive(PrimitiveType.Cube);
                    cornerVisual.transform.parent        = visualsScale.transform;
                    cornerVisual.transform.localPosition = Vector3.zero;
                    GameObject.Destroy(cornerVisual.GetComponent <BoxCollider>());
                }
                else
                {
                    cornerVisual = GameObject.Instantiate(prefabType, visualsScale.transform);
                }

                if (isFlattened)
                {
                    // Rotate 2D slate handle asset for proper orientation
                    cornerVisual.transform.Rotate(0, 0, -90);
                }

                cornerVisual.name = "visuals";

                // this is the size of the corner visuals
                var   cornerbounds = VisualUtils.GetMaxBounds(cornerVisual);
                float maxDim       = Mathf.Max(Mathf.Max(cornerbounds.size.x, cornerbounds.size.y), cornerbounds.size.z);
                cornerbounds.size = maxDim * Vector3.one;

                // we need to multiply by this amount to get to desired scale handle size
                var invScale = config.HandleSize / cornerbounds.size.x;
                cornerVisual.transform.localScale = new Vector3(invScale, invScale, invScale);

                VisualUtils.ApplyMaterialToAllRenderers(cornerVisual, config.HandleMaterial);

                VisualUtils.AddComponentsToAffordance(corner, new Bounds(cornerbounds.center * invScale, cornerbounds.size * invScale),
                                                      RotationHandlePrefabCollider.Box, CursorContextInfo.CursorAction.Scale, config.ColliderPadding, parent, drawManipulationTether);
                handles.Add(corner.transform);
            }
        }