Esempio n. 1
0
        public void SelectWidgets(IEnumerable <GrabWidget> widgets)
        {
            foreach (var widget in widgets)
            {
                if (IsWidgetSelected(widget))
                {
                    Debug.LogWarning("Attempted to select widget that is already selected.");
                    continue;
                }

                widget.SetCanvas(App.Scene.SelectionCanvas);
                HierarchyUtils.RecursivelySetLayer(widget.transform,
                                                   App.Scene.SelectionCanvas.gameObject.layer);
                m_SelectedWidgets.Add(widget);

                if (!m_GroupToSelectedWidgets.TryGetValue(widget.Group, out var groupWidgets))
                {
                    groupWidgets = m_GroupToSelectedWidgets[widget.Group] = new HashSet <GrabWidget>();
                }
                Debug.Assert(!groupWidgets.Contains(widget));
                groupWidgets.Add(widget);
            }

            // If the manager is tasked to select something, make sure the SelectionTool is active.
            // b/64029485 In the event that the user does not have the SelectionTool active and presses
            // undo causing something to be highlighted, force the user to have the SelectionTool.
            SketchSurfacePanel.m_Instance.EnableSpecificTool(BaseTool.ToolType.SelectionTool);
        }
Esempio n. 2
0
        override public GrabWidget Clone()
        {
            StencilWidget clone = Instantiate(WidgetManager.m_Instance.GetStencilPrefab(this.Type));

            clone.transform.position = transform.position;
            clone.transform.rotation = transform.rotation;
            clone.m_SkipIntroAnim    = true;
            // We want to lie about our intro transition amount.
            clone.m_ShowTimer      = clone.m_ShowDuration;
            clone.transform.parent = transform.parent;
            clone.Show(true, false);
            clone.SetSignedWidgetSize(this.m_Size);
            clone.CloneInitialMaterials(this);
            clone.Extents = this.Extents;
            HierarchyUtils.RecursivelySetLayer(clone.transform, gameObject.layer);

            CanvasScript canvas = transform.parent.GetComponent <CanvasScript>();

            if (canvas != null)
            {
                var materials = clone.GetComponentsInChildren <Renderer>().SelectMany(x => x.materials);
                foreach (var material in materials)
                {
                    foreach (string keyword in canvas.BatchManager.MaterialKeywords)
                    {
                        material.EnableKeyword(keyword);
                    }
                }
            }

            return(clone);
        }
Esempio n. 3
0
        override public GrabWidget Clone()
        {
            ImageWidget clone = Instantiate(WidgetManager.m_Instance.ImageWidgetPrefab);

            clone.transform.position = transform.position;
            clone.transform.rotation = transform.rotation;
            // We're obviously not loading from a sketch.  This is to prevent the intro animation.
            // TODO: Change variable name to something more explicit of what this flag does.
            clone.m_LoadingFromSketch = true;
            // We also want to lie about our intro transition amount.
            // TODO: I think this is an old concept and redundant with other intro anim members.
            clone.m_TransitionScale = 1.0f;
            if (m_ReferenceImage != null)
            {
                m_ReferenceImage.SynchronousLoad();
            }
            clone.ReferenceImage = m_ReferenceImage;
            clone.Show(true, false);
            clone.transform.parent = transform.parent;
            clone.SetSignedWidgetSize(this.m_Size);
            clone.UseLegacyTint = this.m_UseLegacyTint;
            HierarchyUtils.RecursivelySetLayer(clone.transform, gameObject.layer);
            TiltMeterScript.m_Instance.AdjustMeterWithWidget(clone.GetTiltMeterCost(), up: true);
            clone.CloneInitialMaterials(this);
            clone.TrySetCanvasKeywordsFromObject(transform);
            return(clone);
        }
Esempio n. 4
0
        public void CreatePreviewModel()
        {
            // Is there a model, is it valid, and does it need a new preview object?
            if (m_Model == null || !m_Model.m_Valid || m_Model == m_ModelPreviewModel)
            {
                return;
            }

            // We know the model has changed, so destroy the preview.
            if (m_ModelPreview != null)
            {
                Destroy(m_ModelPreview.gameObject);
            }

            // Remember the model for which this preview was created.
            m_ModelPreviewModel = m_Model;

            // Build the actual preview.
            m_ModelPreview = Instantiate(m_Model.m_ModelParent);
            HierarchyUtils.RecursivelySetLayer(m_ModelPreview, LayerMask.NameToLayer("Panels"));
            m_ModelPreview.gameObject.SetActive(true);
            m_ModelPreview.parent = m_PreviewParent;
            float maxSide = Mathf.Max(m_Model.m_MeshBounds.size.x,
                                      Mathf.Max(m_Model.m_MeshBounds.size.y, m_Model.m_MeshBounds.size.z));
            TrTransform xf = TrTransform.S(1 / maxSide) * TrTransform.T(-m_Model.m_MeshBounds.center);

            Coords.AsLocal[m_ModelPreview] = xf;
            HierarchyUtils.RecursivelyDisableShadows(m_ModelPreview);
        }
Esempio n. 5
0
        override public void RestoreGameObjectLayer(int layer)
        {
            HierarchyUtils.RecursivelySetLayer(transform, layer);

            int layerIndex = Pinned ? WidgetManager.m_Instance.PinnedStencilLayerIndex :
                             WidgetManager.m_Instance.StencilLayerIndex;

            // The stencil collider object has to stay in the stencil layer so it can be picked
            // up by physics checks.
            m_Collider.gameObject.layer = WidgetManager.m_Instance.StencilLayerIndex;
            for (int i = 0; i < m_TintableMeshes.Length; ++i)
            {
                m_TintableMeshes[i].gameObject.layer = layerIndex;
            }
        }
Esempio n. 6
0
        protected void CreateOptionSides()
        {
            m_Sides         = new GameObject[NumOptions];
            m_SideRenderers = new Renderer[NumOptions];

            m_OptionContainer = new GameObject();
            m_OptionContainer.transform.parent        = transform;
            m_OptionContainer.transform.localPosition = new Vector3(0, 0, OptionSideDistance);
            m_OptionContainer.transform.localRotation = Quaternion.identity;
            m_OptionContainer.transform.localScale    = Vector3.one;

            for (int i = 0; i < NumOptions; i++)
            {
                Option     option = m_Options[i];
                GameObject side   = GameObject.CreatePrimitive(PrimitiveType.Quad);
                m_Sides[i] = side;

                side.GetComponent <Collider>().enabled = false;
                side.transform.parent        = m_OptionContainer.transform;
                side.transform.localRotation = Quaternion.Euler(0, OptionAngleDeltaDegrees * (i + 1), 0);
                side.transform.localPosition = side.transform.localRotation * new Vector3(0, 0, -OptionSideDistance);
                side.transform.localScale    = Vector3.one;

                Renderer renderer = side.GetComponent <Renderer>();
                m_SideRenderers[i]         = renderer;
                renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
                renderer.receiveShadows    = false;
                renderer.lightProbeUsage   = UnityEngine.Rendering.LightProbeUsage.Off;
                renderer.materials         = GetComponent <Renderer>().materials;

                Material material = renderer.material;
                material.mainTexture = option.m_Texture;
                if (m_MaterialTint.HasValue)
                {
                    material.SetColor("_Color", m_MaterialTint.Value);
                }
                foreach (string key in m_MaterialFloats.Keys)
                {
                    material.SetFloat(key, m_MaterialFloats[key]);
                }
            }

            // Keep all these new objects in the same layer as the button.
            HierarchyUtils.RecursivelySetLayer(m_OptionContainer.transform, gameObject.layer);
        }
Esempio n. 7
0
        public override GrabWidget Clone()
        {
            VideoWidget clone = Instantiate(WidgetManager.m_Instance.VideoWidgetPrefab) as VideoWidget;

            clone.m_LoadingFromSketch = true; // prevents intro animation
            clone.m_TransitionScale   = 1.0f;
            clone.transform.parent    = transform.parent;
            clone.SetVideo(m_Video);
            clone.SetSignedWidgetSize(m_Size);
            clone.Show(bShow: true, bPlayAudio: false);
            clone.transform.position = transform.position;
            clone.transform.rotation = transform.rotation;
            HierarchyUtils.RecursivelySetLayer(clone.transform, gameObject.layer);
            TiltMeterScript.m_Instance.AdjustMeterWithWidget(clone.GetTiltMeterCost(), up: true);
            clone.CloneInitialMaterials(this);
            clone.TrySetCanvasKeywordsFromObject(transform);
            return(clone);
        }
Esempio n. 8
0
        override public GrabWidget Clone()
        {
            ModelWidget clone = Instantiate(WidgetManager.m_Instance.ModelWidgetPrefab) as ModelWidget;

            clone.transform.position = transform.position;
            clone.transform.rotation = transform.rotation;
            clone.Model = this.Model;
            // We're obviously not loading from a sketch.  This is to prevent the intro animation.
            // TODO: Change variable name to something more explicit of what this flag does.
            clone.m_LoadingFromSketch = true;
            clone.Show(true, false);
            clone.transform.parent = transform.parent;
            clone.SetSignedWidgetSize(this.m_Size);
            HierarchyUtils.RecursivelySetLayer(clone.transform, gameObject.layer);
            TiltMeterScript.m_Instance.AdjustMeterWithWidget(clone.GetTiltMeterCost(), up: true);

            CanvasScript canvas = transform.parent.GetComponent <CanvasScript>();

            if (canvas != null)
            {
                var materials = clone.GetComponentsInChildren <Renderer>().SelectMany(x => x.materials);
                foreach (var material in materials)
                {
                    foreach (string keyword in canvas.BatchManager.MaterialKeywords)
                    {
                        material.EnableKeyword(keyword);
                    }
                }
            }

            if (!clone.Model.m_Valid)
            {
                App.PolyAssetCatalog.CatalogChanged += clone.OnPacCatalogChanged;
                clone.m_PolyCallbackActive           = true;
            }
            clone.CloneInitialMaterials(this);
            clone.TrySetCanvasKeywordsFromObject(transform);
            return(clone);
        }
Esempio n. 9
0
        public void SetVideo(ReferenceVideo video)
        {
            m_Video      = video;
            ImageTexture = m_NoImageTexture;

            var size = GetWidgetSizeRange();

            if (m_Video.Aspect > 1)
            {
                m_Size = Mathf.Clamp(2 / m_Video.Aspect / Coords.CanvasPose.scale, size.x, size.y);
            }
            else
            {
                m_Size = Mathf.Clamp(2 * m_Video.Aspect / Coords.CanvasPose.scale, size.x, size.y);
            }

            // Create in the main canvas.
            HierarchyUtils.RecursivelySetLayer(transform, App.Scene.MainCanvas.gameObject.layer);
            HierarchyUtils.RecursivelySetMaterialBatchID(transform, m_BatchId);

            InitSnapGhost(m_ImageQuad.transform, transform);
            Play();
        }
Esempio n. 10
0
        override protected void Awake()
        {
            base.Awake();
            // Normalize for size.
            // Use transform.localScale.x because prefabs have scales != Vector3.one.
            m_Size = transform.localScale.x / Coords.CanvasPose.scale;

            // Manually apply Canvas scale because Awake() is called before the transform is parented.
            var sizeRange = GetWidgetSizeRange();

            if (m_Size < sizeRange.x)
            {
                m_Size = sizeRange.x;
                transform.localScale = m_Size * Vector3.one * Coords.CanvasPose.scale;
            }
            if (m_Size > sizeRange.y)
            {
                m_Size = sizeRange.y;
                transform.localScale = m_Size * Vector3.one * Coords.CanvasPose.scale;
            }

            m_Collider = GetComponentInChildren <Collider>();
            InitSnapGhost(m_Collider.transform, transform);

            // Pull tintable meshes from collider and reuse them for the highlight meshes.
            m_HighlightMeshFilters = m_TintableMeshes.Select(x => x.GetComponent <MeshFilter>()).ToArray();

            // Custom pin scalar for stencils.
            m_PinScalar = 0.5f;

            // Set a new batchId on this image so it can be picked up in GPU intersections.
            m_BatchId = GpuIntersector.GetNextBatchId();
            WidgetManager.m_Instance.AddWidgetToBatchMap(this, m_BatchId);
            HierarchyUtils.RecursivelySetMaterialBatchID(transform, m_BatchId);
            RestoreGameObjectLayer(App.Scene.MainCanvas.gameObject.layer);
        }
Esempio n. 11
0
 override public void RestoreGPUIntersectionObjectLayer()
 {
     HierarchyUtils.RecursivelySetLayer(m_ModelInstance, m_BackupLayer);
 }
Esempio n. 12
0
 override public void SetGPUIntersectionObjectLayer(int layer)
 {
     HierarchyUtils.RecursivelySetLayer(m_ModelInstance, layer);
 }
Esempio n. 13
0
        void LoadModel()
        {
            // Clean up existing model
            if (m_ModelInstance != null)
            {
                GameObject.Destroy(m_ModelInstance.gameObject);
            }

            // Early out if we don't have a model to clone.
            // This can happen if model loading is deferred.
            if (m_Model == null || m_Model.m_ModelParent == null)
            {
                return;
            }

            m_ModelInstance = Instantiate(m_Model.m_ModelParent);
            m_ModelInstance.gameObject.SetActive(true);
            m_ModelInstance.parent = this.transform;

            Coords.AsLocal[m_ModelInstance] = TrTransform.identity;
            float maxExtent = 2 * Mathf.Max(m_Model.m_MeshBounds.extents.x,
                                            Mathf.Max(m_Model.m_MeshBounds.extents.y, m_Model.m_MeshBounds.extents.z));
            float size;

            if (maxExtent == 0.0f)
            {
                // If we created a widget with a model that doesn't have geo, we won't have calculated a
                // bounds worth much.  In that case, give us a default size.
                size = 1.0f;
            }
            else
            {
                size = kInitialSizeMeters_RS * App.METERS_TO_UNITS / maxExtent;
            }

            m_InitSize_CS = size / Coords.CanvasPose.scale;

            // Models are created in the main canvas.  Cache model layer in case it's overridden later.
            HierarchyUtils.RecursivelySetLayer(transform, App.Scene.MainCanvas.gameObject.layer);
            m_BackupLayer = m_ModelInstance.gameObject.layer;

            // Set a new batchId on this model so it can be picked up in GPU intersections.
            m_BatchId = GpuIntersector.GetNextBatchId();
            HierarchyUtils.RecursivelySetMaterialBatchID(m_ModelInstance, m_BatchId);
            WidgetManager.m_Instance.AddWidgetToBatchMap(this, m_BatchId);

            Vector3 ratios = GetBoundsRatios(m_Model.m_MeshBounds);

            m_ContainerBloat.x = Mathf.Max(0, m_MinContainerRatio - ratios.x);
            m_ContainerBloat.y = Mathf.Max(0, m_MinContainerRatio - ratios.y);
            m_ContainerBloat.z = Mathf.Max(0, m_MinContainerRatio - ratios.z);
            m_ContainerBloat  /= m_MinContainerRatio;               // Normalize for the min ratio.
            m_ContainerBloat  *= m_MaxBloat / App.Scene.Pose.scale; // Apply bloat to appropriate axes.

            m_BoxCollider.size = m_Model.m_MeshBounds.size + m_ContainerBloat;
            m_BoxCollider.transform.localPosition = m_Model.m_MeshBounds.center;

            InitSnapGhost(m_Model.m_ModelParent, m_ModelInstance);

            // Remove previous model vertex recording.
            WidgetManager.m_Instance.AdjustModelVertCount(-m_NumVertsTrackedByWidgetManager);
            m_NumVertsTrackedByWidgetManager = 0;

            m_ObjModelScript = GetComponentInChildren <ObjModelScript>();
            m_ObjModelScript.Init();
            if (m_ObjModelScript.NumMeshes == 0)
            {
                OutputWindowScript.Error("No usable geometry in model");
            }
            else
            {
                m_NumVertsTrackedByWidgetManager = m_ObjModelScript.GetNumVertsInMeshes();
                WidgetManager.m_Instance.AdjustModelVertCount(m_NumVertsTrackedByWidgetManager);
            }

            if (m_Model.IsCached())
            {
                m_Model.RefreshCache();
            }
        }
Esempio n. 14
0
        protected void CreateOptionSides()
        {
            m_Sides         = new GameObject[NumOptions];
            m_SideRenderers = new Renderer[NumOptions];

            m_OptionContainer                         = new GameObject();
            m_OptionContainer.name                    = "Options Container";
            m_OptionContainer.transform.parent        = transform;
            m_OptionContainer.transform.localPosition = new Vector3(0, 0, OptionSideDistance);
            m_OptionContainer.transform.localRotation = Quaternion.identity;
            m_OptionContainer.transform.localScale    = Vector3.one;

            for (int i = 0; i < NumOptions; i++)
            {
                Option     option = m_Options[i];
                GameObject side   = GameObject.CreatePrimitive(PrimitiveType.Quad);
                side.transform.parent = m_OptionContainer.transform;
                side.name             = $"Option {i}";
                m_Sides[i]            = side;
                side.GetComponent <Collider>().enabled = false;
                if (DisplayTextLabel)
                {
                    GameObject sideLabel = new GameObject($"Option Label {i}");
                    sideLabel.transform.parent = side.transform;
                    TextMeshPro   tmpText = sideLabel.AddComponent <TextMeshPro>();
                    RectTransform rt      = sideLabel.transform as RectTransform;
                    rt.sizeDelta      = new Vector2(1, 1);
                    rt.localPosition  = new Vector3(0, 0, -0.01f);
                    rt.localScale     = Vector3.one;
                    tmpText.text      = option.m_Description;
                    tmpText.fontSize  = 4;
                    tmpText.alignment = TextAlignmentOptions.Center;
                }

                side.transform.localRotation = Quaternion.Euler(0, OptionAngleDeltaDegrees * (i + 1), 0);
                side.transform.localPosition = side.transform.localRotation * new Vector3(0, 0, -OptionSideDistance);
                side.transform.localScale    = Vector3.one;

                Renderer renderer = side.GetComponent <Renderer>();
                m_SideRenderers[i] = renderer;

                Material material = renderer.material;
                renderer.materials   = GetComponent <Renderer>().materials;
                material.mainTexture = option.m_Texture;
                if (DisplayIcon)
                {
                    renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
                    renderer.receiveShadows    = false;
                    renderer.lightProbeUsage   = UnityEngine.Rendering.LightProbeUsage.Off;
                }
                else
                {
                    renderer.enabled = false;
                }
                if (m_MaterialTint.HasValue)
                {
                    material.SetColor("_Color", m_MaterialTint.Value);
                }
                foreach (string key in m_MaterialFloats.Keys)
                {
                    material.SetFloat(key, m_MaterialFloats[key]);
                }
            }

            // Keep all these new objects in the same layer as the button.
            HierarchyUtils.RecursivelySetLayer(m_OptionContainer.transform, gameObject.layer);
        }