Beispiel #1
0
 internal void SetHighlighted()
 {
     // Update the box material to the grabbed material
     if (boxDisplay != null)
     {
         VisualUtils.ApplyMaterialToAllRenderers(boxDisplay, config.BoxGrabbedMaterial);
     }
 }
 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);
             }
         }
     }
 }
Beispiel #3
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);
         }
     }
 }
Beispiel #4
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 with box collider
                cornerVisual = GameObject.CreatePrimitive(PrimitiveType.Cube);
                cornerVisual.transform.parent        = parent.transform;
                cornerVisual.transform.localPosition = Vector3.zero;
                // deactivate collider on visuals and register for deletion - actual collider
                // of handle is attached to the handle gameobject, not the visual
                var collider = cornerVisual.GetComponent <BoxCollider>();
                collider.enabled = false;
                Object.Destroy(collider);
            }
            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);
        }
 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;
 }
        /// <summary>
        /// Creates the corner visual and returns the bounds of the created visual
        /// </summary>
        /// <param name="handleIndex">cornerIndex</param>
        /// <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(int handleIndex, GameObject parent, bool isFlattened)
        {
            // figure out which prefab to instantiate
            GameObject handleVisual = null;

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

            if (prefabType == null)
            {
                // instantiate default prefab, a cube with box collider
                handleVisual = GameObject.CreatePrimitive(PrimitiveType.Cube);

                // deactivate collider on visuals and register for deletion - actual collider
                // of handle is attached to the handle gameobject, not the visual
                var collider = handleVisual.GetComponent <BoxCollider>();
                collider.enabled = false;
                UnityEngine.Object.Destroy(collider);
            }
            else
            {
                handleVisual = GameObject.Instantiate(prefabType, parent.transform);
            }

            // this is the size of the corner visuals
            var   handleVisualBounds = VisualUtils.GetMaxBounds(handleVisual);
            float maxDim             = VisualUtils.GetMaxComponent(handleVisualBounds.size);
            float invScale           = maxDim == 0.0f ? 0.0f : config.HandleSize / maxDim;

            handleVisual.name                    = visualsName;
            handleVisual.transform.parent        = parent.transform;
            handleVisual.transform.localScale    = new Vector3(invScale, invScale, invScale);
            handleVisual.transform.localPosition = Vector3.zero;
            handleVisual.transform.localRotation = Quaternion.identity;


            Quaternion realignment = GetRotationRealignment(handleIndex, isFlattened);

            parent.transform.localRotation = realignment;

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

            return(handleVisualBounds);
        }
        private Bounds CreateVisual(int handleIndex, GameObject parent)
        {
            GameObject handleVisual;
            GameObject prefabType = config.HandlePrefab;

            if (prefabType != null)
            {
                handleVisual = Object.Instantiate(prefabType);
            }
            else
            {
                handleVisual = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                // We only want the Primitive sphere mesh, but CreatePrimitive will
                // give us a sphere collider too. Remove the sphere collider here
                // so we can manually add our own properly configured collider later.
                var collider = handleVisual.GetComponent <SphereCollider>();
                collider.enabled = false;

                // Caution, Destroy() will destroy one frame later.
                // Do not check later for presence this frame!
                Object.Destroy(collider);
            }

            // handleVisualBounds are returned in handleVisual-local space.
            Bounds handleVisualBounds = VisualUtils.GetMaxBounds(handleVisual);
            float  maxDim             = VisualUtils.GetMaxComponent(handleVisualBounds.size);
            float  invScale           = maxDim == 0.0f ? 0.0f : config.HandleSize / maxDim;

            handleVisual.name                    = visualsName;
            handleVisual.transform.parent        = parent.transform;
            handleVisual.transform.localScale    = new Vector3(invScale, invScale, invScale);
            handleVisual.transform.localPosition = Vector3.zero;
            handleVisual.transform.localRotation = Quaternion.identity;

            Quaternion realignment = GetRotationRealignment(handleIndex);

            parent.transform.localRotation = realignment;

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

            return(handleVisualBounds);
        }
 internal void SetHighlighted(Transform handleToHighlight, IMixedRealityPointer associatedPointer = null)
 {
     // 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);
                 highlightedHandle = handleToHighlight;
             }
         }
     }
 }
        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);
                // deactivate collider on visuals and register for deletion - actual collider
                // of handle is attached to the handle gameobject, not the visual
                var collider = midpointVisual.GetComponent <SphereCollider>();
                collider.enabled = false;
                Object.Destroy(collider);
            }

            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);
        }
        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);
        }