示例#1
0
        public SelfDestructTimer()
        {
            DefaultStyleKey = typeof(SelfDestructTimer);
            Visibility      = Visibility.Collapsed;

            var ellipse = Window.Current.Compositor.CreateEllipseGeometry();

            ellipse.Radius = new Vector2((float)Radius);
            ellipse.Center = new Vector2((float)Center);

            var shape = Window.Current.Compositor.CreateSpriteShape(ellipse);

            shape.CenterPoint     = new Vector2((float)Center);
            shape.StrokeThickness = 2;
            shape.StrokeStartCap  = CompositionStrokeCap.Round;
            shape.StrokeEndCap    = CompositionStrokeCap.Round;

            if (Foreground is SolidColorBrush brush)
            {
                shape.StrokeBrush = Window.Current.Compositor.CreateColorBrush(brush.Color);
            }

            var visual = Window.Current.Compositor.CreateShapeVisual();

            visual.Shapes.Add(shape);
            visual.Size        = new Vector2((float)Center * 2);
            visual.CenterPoint = new Vector3((float)Center);

            _visual  = visual;
            _shape   = shape;
            _ellipse = ellipse;

            ElementCompositionPreview.SetElementChildVisual(this, visual);
            RegisterPropertyChangedCallback(ForegroundProperty, OnForegroundChanged);
        }
示例#2
0
        ShapeVisual GetShapeVisual(ShapeVisual obj)
        {
            if (GetExisting(obj, out ShapeVisual result))
            {
                return(result);
            }

            result = CacheAndInitializeVisual(obj, _c.CreateShapeVisual());

            if (obj.ViewBox != null)
            {
                result.ViewBox = GetCompositionViewBox(obj.ViewBox);
            }

            var shapesCollection = result.Shapes;

            foreach (var child in obj.Shapes)
            {
                shapesCollection.Add(GetCompositionShape(child));
            }

            InitializeContainerVisual(obj, result);
            StartAnimationsAndFreeze(obj, result);
            return(result);
        }
示例#3
0
        public NumericTextBlock()
        {
            if (!ApiInfo.CanUseDirectComposition)
            {
                return;
            }

            var shape = Window.Current.Compositor.CreateShapeVisual();
            //shape.Clip = Window.Current.Compositor.CreateInsetClip(0, 0, 1, 0);
            //shape.Size = new Vector2(100, 36);

            var part   = GetPart('9');
            var bounds = part.ComputeBounds();

            _shape      = shape;
            _nineRight  = (float)bounds.Right;
            _nineBottom = (float)bounds.Bottom;

            Height     = _nineBottom;
            shape.Size = new Vector2(0, _nineBottom);

            ElementCompositionPreview.SetElementChildVisual(this, shape);

            ApplyForeground();
            RegisterPropertyChangedCallback(ForegroundProperty, OnForegroundChanged);
        }
示例#4
0
        private void OnCreateResources(CanvasAnimatedControl sender, CanvasCreateResourcesEventArgs args)
        {
            _c = Window.Current.Compositor;
            _g = _c.CreateCompositionGenerator();

            _rootShape      = _c.CreateShapeVisual();
            _rootShape.Size = new Vector2((float)RenderGrid.ActualWidth, (float)RenderGrid.ActualHeight);
            _rootSize       = _rootShape.Size.ToSize();

            var rectGeom = _c.CreatePathGeometry(new CompositionPath(CanvasGeometry.CreateRectangle(_g.Device, new Rect(new Point(), _rootSize))));
            var bgShape  = _c.CreateSpriteShape(rectGeom);

            bgShape.FillBrush = _c.CreateColorBrush(CanvasObject.CreateColor("#161616"));

            _rootShape.Shapes.Add(bgShape);

            for (var i = 0; i < MaxLayerCount; i++)
            {
                var shape = _c.CreateSpriteShape(_c.CreatePathGeometry(GetClip(_rootSize, 0f)));
                // Offset each of the shape to the right to hide the bump of lower layers
                shape.Offset    = HideOffset;
                shape.FillBrush = _c.CreateColorBrush(_colors[i]);
                _rootShape.Shapes.Add(shape);
            }

            _selectedIndex   = -1;
            _swipeRightIndex = -1;
            _swipeLeftIndex  = MaxLayerCount;
            _nextShapeIndex  = -1;
            // Reset offset of top most shape
            _rootShape.Shapes[MaxLayerCount].Offset = Vector2.Zero;

            ElementCompositionPreview.SetElementChildVisual(RenderGrid, _rootShape);
        }
示例#5
0
        public StorageChart()
        {
            DefaultStyleKey = typeof(StorageChart);

            _visual = Window.Current.Compositor.CreateShapeVisual();
            ElementCompositionPreview.SetElementChildVisual(this, _visual);
        }
示例#6
0
        private ContainerVisual GenerateGraphStructure()
        {
            mainContainer = compositor.CreateContainerVisual();

            // Create shape tree to hold.
            shapeContainer = compositor.CreateShapeVisual();

            xAxisLine = compositor.CreateLineGeometry();
            yAxisLine = compositor.CreateLineGeometry();

            var xAxisShape = compositor.CreateSpriteShape(xAxisLine);

            xAxisShape.StrokeBrush = compositor.CreateColorBrush(Colors.Black);
            xAxisShape.FillBrush   = compositor.CreateColorBrush(Colors.Black);

            var yAxisShape = compositor.CreateSpriteShape(yAxisLine);

            yAxisShape.StrokeBrush = compositor.CreateColorBrush(Colors.Black);

            shapeContainer.Shapes.Add(xAxisShape);
            shapeContainer.Shapes.Add(yAxisShape);

            mainContainer.Children.InsertAtTop(shapeContainer);

            UpdateSizeAndPositions();

            // Draw text.
            DrawText(textRenderTarget, Title, XAxisLabel, YAxisLabel, textSize);

            // Return root node for graph.
            return(mainContainer);
        }
        protected void Render(CanvasPathBuilder canvasPathBuilder)
        {
            // Path
            var canvasGeometry  = CanvasGeometry.CreatePath(canvasPathBuilder);
            var compositionPath = new CompositionPath(canvasGeometry);
            var compositor      = Window.Current.Compositor;
            var pathGeometry    = compositor.CreatePathGeometry();

            pathGeometry.Path = compositionPath;
            var spriteShape = compositor.CreateSpriteShape(pathGeometry);

            spriteShape.FillBrush       = compositor.CreateColorBrush(Fill);
            spriteShape.StrokeThickness = (float)StrokeThickness;
            spriteShape.StrokeBrush     = compositor.CreateColorBrush(Stroke);
            spriteShape.StrokeStartCap  = IsStrokeRounded ? CompositionStrokeCap.Round : CompositionStrokeCap.Square;
            spriteShape.StrokeEndCap    = IsStrokeRounded ? CompositionStrokeCap.Round : CompositionStrokeCap.Square;

            // Visual
            var shapeVisual = compositor.CreateShapeVisual();

            shapeVisual.Size = new Vector2((float)Container.ActualWidth, (float)Container.ActualHeight);
            shapeVisual.Shapes.Add(spriteShape);
            shapeVisual.CenterPoint   = new Vector3((float)RotationCenterX, (float)RotationCenterY, 0f);
            shapeVisual.RotationAxis  = new Vector3(0f, 0f, 1f);
            shapeVisual.RotationAngle = (float)RotationAngle;
            var root = Container.GetVisual();

            root.Children.RemoveAll();
            root.Children.InsertAtTop(shapeVisual);
            _shapeVisual = shapeVisual;
        }
示例#8
0
        private static RenderData GetRenderData(Transform transform)
        {
            var filters = transform.GetComponents <MeshFilter>();

            if (filters.Length == 0)
            {
                if (transform.GetComponent <DebugRenderData>() != null && transform.GetComponent <DebugRenderData>().Node != null)
                {
                    filters = transform.GetComponent <DebugRenderData>().Node.GetComponentsInChildren <MeshFilter>();
                }
                else if (transform.GetComponent <AGXUnity.Collide.Shape>() != null)
                {
                    var shape       = transform.GetComponent <AGXUnity.Collide.Shape>();
                    var shapeVisual = ShapeVisual.Find(shape);
                    if (shapeVisual != null)
                    {
                        filters = shapeVisual.GetComponentsInChildren <MeshFilter>();
                    }
                }
                else if (transform.GetComponent <AGXUnity.RigidBody>() != null)
                {
                    filters = transform.GetComponentsInChildren <MeshFilter>();
                }
            }
            return(new RenderData()
            {
                Color = GetColor(transform),
                MeshFilters = filters
            });
        }
示例#9
0
        public Shape()
        {
            _rectangleVisual = Visual.Compositor.CreateShapeVisual();
            Visual.Children.InsertAtBottom(_rectangleVisual);

            InitCommonShapeProperties();
        }
示例#10
0
        public static void CreateVisual(MenuCommand command)
        {
#if UNITY_2019_4_OR_NEWER
            if (command.context == null)
            {
                return;
            }
#endif

            var go = Selection.GetFiltered <GameObject>(SelectionMode.TopLevel |
                                                        SelectionMode.Editable).FirstOrDefault(selected => selected == command.context);
            if (go == null)
            {
                Debug.LogWarning($"Ignoring visual for {command.context.name} - object isn't editable.");
                return;
            }

            var validShapes = from shape in go.GetComponentsInChildren <Shape>()
                              where !ShapeVisual.HasShapeVisual(shape) &&
                              ShapeVisual.SupportsShapeVisual(shape)
                              select shape;
            var numSensors             = validShapes.Count(shape => shape.IsSensor);
            var createVisualForSensors = validShapes.Count() > 0 &&
                                         numSensors > 0 &&
                                         // Negated when "No" is first (left button)
                                         !EditorUtility.DisplayDialog("Sensors",
                                                                      "There are " +
                                                                      numSensors +
                                                                      " sensors in this object. Would you like to" +
                                                                      " create visuals for sensors as well?",
                                                                      "No",
                                                                      "Yes");

            if (validShapes.Count() > 0 && (createVisualForSensors || numSensors < validShapes.Count()))
            {
                Undo.SetCurrentGroupName("Create GameObject(s) shape visual.");
                var grouId = Undo.GetCurrentGroup();

                foreach (var shape in validShapes)
                {
                    if (shape.IsSensor && !createVisualForSensors)
                    {
                        continue;
                    }

                    var visual = ShapeVisual.Create(shape);
                    if (visual != null)
                    {
                        Undo.RegisterCreatedObjectUndo(visual, "Create visual: " + shape.name);
                    }
                }

                Undo.CollapseUndoOperations(grouId);
            }
            else
            {
                Debug.Log("Create visual ignored: All shapes already have visual data or doesn't support to be visualized.",
                          Selection.activeGameObject);
            }
        }
 public static bool CanCreateVisual(Shape shape)
 {
     return(shape != null &&
            ShapeVisual.SupportsShapeVisual(shape) &&
            !ShapeVisual.HasShapeVisual(shape) &&
            (!(shape is AGXUnity.Collide.Mesh) ||
             (shape as AGXUnity.Collide.Mesh).SourceObjects.Length > 0));
 }
示例#12
0
        public override void OnPostTargetMembersGUI()
        {
            if (IsMultiSelect)
            {
                return;
            }

            var shapeVisual = ShapeVisual.Find(Shape);

            if (shapeVisual == null)
            {
                return;
            }

            var materials = shapeVisual.GetMaterials();

            if (materials.Length > 1)
            {
                var names = (from renderer in shapeVisual.GetComponentsInChildren <MeshRenderer>()
                             from material in renderer.sharedMaterials
                             select renderer.name).ToArray();

                var distinctMaterials = materials.Distinct().ToArray();
                var isExtended        = false;
                if (distinctMaterials.Length == 1)
                {
                    isExtended = ShapeVisualMaterialGUI("Common Render Material",
                                                        distinctMaterials[0],
                                                        newMaterial => shapeVisual.SetMaterial(newMaterial));
                }
                else
                {
                    isExtended = InspectorGUI.Foldout(EditorData.Instance.GetData(Shape, "Render Materials"),
                                                      GUI.MakeLabel("Render Materials"));
                }

                if (isExtended)
                {
                    using (InspectorGUI.IndentScope.Single)
                        for (int i = 0; i < materials.Length; ++i)
                        {
                            ShapeVisualMaterialGUI(names[i],
                                                   materials[i],
                                                   newMaterial => shapeVisual.ReplaceMaterial(i, newMaterial));
                        }
                }
            }
            else if (materials.Length == 1)
            {
                ShapeVisualMaterialGUI("Render Material",
                                       materials[0],
                                       newMaterial => shapeVisual.ReplaceMaterial(0, newMaterial));
            }
        }
示例#13
0
        public static void CreateVisual()
        {
            if (Selection.activeGameObject == null)
            {
                Debug.Log("Unable to create visual: No game object selected in scene.");
                return;
            }

            if (AssetDatabase.Contains(Selection.activeGameObject))
            {
                Debug.Log("Unable to create visual: Selected game object is not an instance in a scene.", Selection.activeGameObject);
                return;
            }

            var shapes = Selection.activeGameObject.GetComponentsInChildren <Shape>();

            if (shapes.Length == 0)
            {
                Debug.Log("Unable to create visual: Selected game object doesn't have any shapes.", Selection.activeGameObject);
                return;
            }

            int numValidCreateVisual = 0;

            foreach (var shape in shapes)
            {
                numValidCreateVisual += Convert.ToInt32(!ShapeVisual.HasShapeVisual(shape) && ShapeVisual.SupportsShapeVisual(shape));
            }
            if (numValidCreateVisual == 0)
            {
                Debug.Log("Create visual ignored: All shapes already have visual data or doesn't support to be visualized.", Selection.activeGameObject);
                return;
            }

            Undo.SetCurrentGroupName("Create GameObject shape visual.");
            var grouId = Undo.GetCurrentGroup();

            foreach (var shape in shapes)
            {
                if (!ShapeVisual.HasShapeVisual(shape))
                {
                    var go = ShapeVisual.Create(shape);
                    if (go != null)
                    {
                        Undo.RegisterCreatedObjectUndo(go, "Shape visual");
                    }
                }
            }

            Undo.CollapseUndoOperations(grouId);
        }
        public void OnInspectorGUI()
        {
            if (RigidBody == null || GetChildren().Length == 0)
            {
                PerformRemoveFromParent();
                return;
            }

            var skin = InspectorEditor.Skin;

            InspectorGUI.OnDropdownToolBegin("Create visual representation of this rigid body given all supported shapes.");

            foreach (var tool in GetChildren <ShapeVisualCreateTool>())
            {
                if (ShapeVisual.HasShapeVisual(tool.Shape))
                {
                    continue;
                }

                EditorGUILayout.PrefixLabel(GUI.MakeLabel(tool.Shape.name,
                                                          true),
                                            skin.Label);
                using (InspectorGUI.IndentScope.Single)
                    tool.OnInspectorGUI(true);
            }

            var createCancelState = InspectorGUI.PositiveNegativeButtons(true,
                                                                         "Create",
                                                                         "Create shape visual for shapes that hasn't already got one.",
                                                                         "Cancel");

            if (createCancelState == InspectorGUI.PositiveNegativeResult.Positive)
            {
                foreach (var tool in GetChildren <ShapeVisualCreateTool>())
                {
                    if (!ShapeVisual.HasShapeVisual(tool.Shape))
                    {
                        tool.CreateShapeVisual();
                    }
                }
            }

            InspectorGUI.OnDropdownToolEnd();

            if (createCancelState != InspectorGUI.PositiveNegativeResult.Neutral)
            {
                PerformRemoveFromParent();
            }
        }
示例#15
0
        public void OnInspectorGUI()
        {
            if (RigidBody == null || GetChildren().Length == 0)
            {
                PerformRemoveFromParent();
                return;
            }

            var skin = InspectorEditor.Skin;

            GUILayout.Space(4);
            using (GUI.AlignBlock.Center)
                GUILayout.Label(GUI.MakeLabel("Create visual tool", 16, true), skin.label);

            GUILayout.Space(2);
            GUI.Separator();
            GUILayout.Space(4);

            foreach (var tool in GetChildren <ShapeVisualCreateTool>())
            {
                if (ShapeVisual.HasShapeVisual(tool.Shape))
                {
                    continue;
                }

                using (GUI.AlignBlock.Center)
                    GUILayout.Label(GUI.MakeLabel(tool.Shape.name, 16, true), skin.label);
                tool.OnInspectorGUI(true);
            }

            var createCancelState = GUI.CreateCancelButtons(true, skin, "Create shape visual for shapes that hasn't already got one.");

            if (createCancelState == GUI.CreateCancelState.Create)
            {
                foreach (var tool in GetChildren <ShapeVisualCreateTool>())
                {
                    if (!ShapeVisual.HasShapeVisual(tool.Shape))
                    {
                        tool.CreateShapeVisual();
                    }
                }
            }
            if (createCancelState != GUI.CreateCancelState.Nothing)
            {
                PerformRemoveFromParent();
            }
        }
示例#16
0
        private void OnCreateResources(CanvasAnimatedControl sender, CanvasCreateResourcesEventArgs args)
        {
            _c = Window.Current.Compositor;
            _g = _c.CreateCompositionGenerator();

            _rootShape      = _c.CreateShapeVisual();
            _rootShape.Size = new Vector2((float)RenderGrid.ActualWidth, (float)RenderGrid.ActualHeight);
            _rootSize       = _rootShape.Size.ToSize();

            var rectGeom = _c.CreatePathGeometry(new CompositionPath(CanvasGeometry.CreateRectangle(_g.Device, new Rect(new Point(), _rootSize))));
            var bgShape  = _c.CreateSpriteShape(rectGeom);

            bgShape.FillBrush = _c.CreateColorBrush(CanvasObject.CreateColor("#161616"));

            _rootShape.Shapes.Add(bgShape);

            _slideLeftImplicitAnimationCollection = _c.CreateImplicitAnimationCollection();
            var slideLeftAnim = _c.GenerateVector2KeyFrameAnimation()
                                .HavingDuration(700)
                                .ForTarget(() => _c.CreateSpriteShape().Offset);

            slideLeftAnim.InsertFinalValueKeyFrame(1f, _c.CreateEaseInOutBackEasingFunction());
            _slideLeftImplicitAnimationCollection["Offset"] = slideLeftAnim.Animation;

            _slideRightImplicitAnimationCollection = _c.CreateImplicitAnimationCollection();
            var slideRightAnim = _c.GenerateVector2KeyFrameAnimation()
                                 .HavingDuration(2000)
                                 .ForTarget(() => _c.CreateSpriteShape().Offset);

            slideRightAnim.InsertFinalValueKeyFrame(1f, _c.CreateEaseInOutBackEasingFunction());
            _slideRightImplicitAnimationCollection["Offset"] = slideRightAnim.Animation;

            for (var i = 0; i < MaxShapeCount; i++)
            {
                var shape = _c.CreateSpriteShape(_c.CreatePathGeometry(GetClip(_rootSize)));
                shape.Offset    = HideOffset;
                shape.FillBrush = _c.CreateColorBrush(_colors[i]);
                _rootShape.Shapes.Add(shape);
            }

            _selIndex = MaxShapeCount;
            _rootShape.Shapes[_selIndex].Offset = Vector2.Zero;

            ElementCompositionPreview.SetElementChildVisual(RenderGrid, _rootShape);
            PrevBtn.IsEnabled = false;
        }
示例#17
0
        private void CreateTopCircleButtonShadow()
        {
            CompositionRoundedRectangleGeometry circleShaowGeometry = compositor.CreateRoundedRectangleGeometry();

            circleShaowGeometry.Size         = new Vector2(50, 50);
            circleShaowGeometry.CornerRadius = new Vector2(25, 25);
            CompositionSpriteShape         compositionSpriteShapeShadow         = compositor.CreateSpriteShape(circleShaowGeometry);
            CompositionRadialGradientBrush compositionLinearGradientShadowBrush = compositor.CreateRadialGradientBrush();

            compositionLinearGradientShadowBrush.ColorStops.Insert(0, compositor.CreateColorGradientStop(0.5f, Color.FromArgb(255, 86, 57, 14)));
            compositionLinearGradientShadowBrush.ColorStops.Insert(1, compositor.CreateColorGradientStop(1f, Color.FromArgb(255, 230, 160, 53)));
            compositionLinearGradientShadowBrush.Offset = new Vector2(0, 4);
            compositionSpriteShapeShadow.FillBrush      = compositionLinearGradientShadowBrush;
            shapeVisualShadow      = compositor.CreateShapeVisual();
            shapeVisualShadow.Size = new Vector2(50, 50);
            shapeVisualShadow.Shapes.Add(compositionSpriteShapeShadow);
        }
示例#18
0
        public void CreateBar(float maxHeight)
        {
            var strokeThickness = 8;

            // Define shape visual for bar outline.
            shapeOutlineVisual      = compositor.CreateShapeVisual();
            shapeOutlineVisual.Size = new Vector2(maxHeight, maxHeight);
            shapeOutlineVisual.RotationAngleInDegrees = -90f;

            // Create geometry and shape for the bar outline.
            rectOutlineGeometry = compositor.CreateRectangleGeometry();
            // Reverse width and height since rect will be at a 90* angle.
            rectOutlineGeometry.Size = new Vector2(Height, Width);
            var barOutlineVisual = compositor.CreateSpriteShape(rectOutlineGeometry);

            barOutlineVisual.StrokeThickness = (float)strokeThickness;
            barOutlineVisual.StrokeBrush     = Brush;

            shapeOutlineVisual.Shapes.Add(barOutlineVisual);

            // Define shape visual.
            shapeVisual      = compositor.CreateShapeVisual();
            shapeVisual.Size = new Vector2(maxHeight, maxHeight);
            shapeVisual.RotationAngleInDegrees = -90f;

            // Create rectangle geometry and shape for the bar.
            rectGeometry = compositor.CreateRectangleGeometry();
            // Reverse width and height since rect will be at a 90* angle.
            rectGeometry.Size   = new Vector2(Height, Width);
            barVisual           = compositor.CreateSpriteShape(rectGeometry);
            barVisual.FillBrush = Brush;

            shapeVisual.Shapes.Add(barVisual);

            Root        = shapeVisual;
            OutlineRoot = shapeOutlineVisual;

            // Add implict animation to bar.
            var implicitAnimations = compositor.CreateImplicitAnimationCollection();

            // Trigger animation when the size property changes.
            implicitAnimations["Size"]             = CreateAnimation();
            rectGeometry.ImplicitAnimations        = implicitAnimations;
            rectOutlineGeometry.ImplicitAnimations = implicitAnimations;
        }
示例#19
0
        public ShapeVisualCreateTool(Shape shape)
        {
            Shape   = shape;
            Preview = ShapeVisual.Create(shape);
            if (Preview != null)
            {
                Preview.transform.parent   = Manager.VisualsParent.transform;
                Preview.transform.position = Shape.transform.position;
                Preview.transform.rotation = Shape.transform.rotation;
            }

            Material = GetData(DataEntry.Material).Asset as Material;
            Name     = GetData(DataEntry.Name).String;
            if (Name == "")
            {
                Name = Shape.name + "_Visual";
            }
        }
        public ShapeVisualCreateTool(Shape shape, bool isGloballyUnique = true)
            : base(isSingleInstanceTool: isGloballyUnique)
        {
            Shape   = shape;
            Preview = ShapeVisual.Create(shape);
            if (Preview != null)
            {
                Preview.transform.parent   = Manager.VisualsParent.transform;
                Preview.transform.position = Shape.transform.position;
                Preview.transform.rotation = Shape.transform.rotation;
            }

            Material = GetData(DataEntry.Material).Asset as Material ?? Manager.GetOrCreateShapeVisualDefaultMaterial();
            Name     = GetData(DataEntry.Name).String;
            if (Name == "")
            {
                Name = Shape.name + "_Visual";
            }
        }
示例#21
0
        private void CreateMainElipse()
        {
            CompositionRoundedRectangleGeometry roundedRectangle = compositor.CreateRoundedRectangleGeometry();

            roundedRectangle.Size         = new Vector2(150, 50);
            roundedRectangle.CornerRadius = new Vector2(25, 25);
            CompositionSpriteShape compositionSpriteShape = compositor.CreateSpriteShape(roundedRectangle);

            linearGradientBrush            = compositor.CreateLinearGradientBrush();
            linearGradientBrush.StartPoint = new Vector2(0, 1);
            linearGradientBrush.EndPoint   = new Vector2(0f, 1);
            linearGradientBrush.ColorStops.Insert(0, compositor.CreateColorGradientStop(0f, backgroundColor));
            linearGradientBrush.ColorStops.Insert(1, compositor.CreateColorGradientStop(0.5f, waveColor));
            linearGradientBrush.ColorStops.Insert(2, compositor.CreateColorGradientStop(1f, backgroundColor));

            compositionSpriteShape.FillBrush = linearGradientBrush;
            shapeVisualElipse      = compositor.CreateShapeVisual();
            shapeVisualElipse.Size = new Vector2(150, 50);
            shapeVisualElipse.Shapes.Add(compositionSpriteShape);
        }
        public void CreateShapeVisual()
        {
            if (Preview != null)
            {
                GameObject.DestroyImmediate(Preview);
            }

            var go = ShapeVisual.Create(Shape);

            if (go == null)
            {
                return;
            }

            var shapeVisual = go.GetComponent <ShapeVisual>();

            shapeVisual.name = Name;
            shapeVisual.SetMaterial(Material);

            Undo.RegisterCreatedObjectUndo(go, "Shape visual for shape: " + Shape.name);
        }
示例#23
0
        private ShapeVisual RandomStar()
        {
            Compositor compositor = _root.Compositor;
            var        ellipse    = compositor.CreateEllipseGeometry();

            ellipse.Center = new Vector2(1.5f, 1.5f);
            ellipse.Radius = new Vector2(1.5f, 1.5f);
            CompositionSpriteShape sprite = compositor.CreateSpriteShape(ellipse);
            Color color = Color.FromArgb(
                255,
                (byte)Random.Next(0, byte.MaxValue),
                (byte)Random.Next(0, byte.MaxValue),
                (byte)Random.Next(0, byte.MaxValue)
                );

            sprite.FillBrush = compositor.CreateColorBrush(color);
            ShapeVisual visual = compositor.CreateShapeVisual();

            visual.Size = new Vector2(3, 3);
            visual.Shapes.Add(sprite);
            return(visual);
        }
示例#24
0
        void OnLoading(object sender, object args)
        {
            // DirectX layer
            _device     = CanvasDevice.GetSharedDevice();
            _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;

            // create text format
            using CanvasTextFormat textformat = new CanvasTextFormat
                  {
                      FontFamily          = FontFamily.Source,
                      FontSize            = (float)FontSize,
                      FontWeight          = FontWeight,
                      WordWrapping        = CanvasWordWrapping.NoWrap,
                      LineSpacingMode     = CanvasLineSpacingMode.Proportional, // no option to make it properly centered.
                      LineSpacing         = 0.4f,
                      LineSpacingBaseline = 0.6f,
                      HorizontalAlignment = CanvasHorizontalAlignment.Center,
                      VerticalAlignment   = CanvasVerticalAlignment.Center
                  };
            using CanvasTextLayout textLayout = new CanvasTextLayout(_device, Text, textformat, 0, 0);

            if (this.Width < textLayout.LayoutBounds.Width)
            {
                this.Width = textLayout.LayoutBounds.Width + 20;
            }

            _size = new Vector2((float)Width, (float)Height);

            _shape      = _compositor.CreateShapeVisual();
            _shape.Size = _size;

            _graphdevice = CanvasComposition.CreateCompositionGraphicsDevice(_compositor, _device);
            _drawsurface = _graphdevice.CreateDrawingSurface(new Size(Width, Height), DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied);

            DrawText(textLayout);
            DrawShape();

            ElementCompositionPreview.SetElementChildVisual(this, _shape);
        }
示例#25
0
        XElement FromShapeVisual(ShapeVisual obj)
        {
            return(new XElement(GetCompositionObjectName(obj), GetContents()));

            IEnumerable <XObject> GetContents()
            {
                foreach (var item in GetContainerVisualContents(obj))
                {
                    yield return(item);
                }

                foreach (var item in FromCompositionObject(obj.ViewBox))
                {
                    yield return(item);
                }

                foreach (var item in obj.Shapes.SelectMany(FromCompositionObject))
                {
                    yield return(item);
                }
            }
        }
示例#26
0
        // Main circle
        private void CreateTopCircleButton()
        {
            CompositionRoundedRectangleGeometry circleGeometry = compositor.CreateRoundedRectangleGeometry();

            circleGeometry.Size         = new Vector2(40, 40);
            circleGeometry.CornerRadius = new Vector2(20, 20);
            CompositionSpriteShape compositionSpriteShape = compositor.CreateSpriteShape(circleGeometry);

            circleGradientBrush = compositor.CreateRadialGradientBrush();

            // Color animation
            ColorStop1 = compositor.CreateColorGradientStop(1, Colors.White);
            circleGradientBrush.ColorStops.Add(ColorStop1);
            color1Animation          = compositor.CreateColorKeyFrameAnimation();
            color1Animation.Duration = TimeSpan.FromSeconds(0.5);
            color1Animation.InsertKeyFrame(1.0f, Color.FromArgb(255, 247, 211, 156));
            color1Animation.InsertKeyFrame(0.0f, Colors.White);
            color2Animation          = compositor.CreateColorKeyFrameAnimation();
            color2Animation.Duration = TimeSpan.FromSeconds(0.5);
            color2Animation.InsertKeyFrame(1.0f, Colors.White);
            color2Animation.InsertKeyFrame(0.0f, Color.FromArgb(255, 247, 211, 156));

            compositionSpriteShape.FillBrush = circleGradientBrush;
            compositionSpriteShape.Offset    = new Vector2(5, 5);

            shapeVisualCircle      = compositor.CreateShapeVisual();
            shapeVisualCircle.Size = new Vector2(50, 50);
            shapeVisualCircle.Shapes.Add(compositionSpriteShape);
            shapeVisualCircle.Offset = new Vector3(sliderMargins.X, 0, 0);

            // Return animation
            _leftoffsetAnimation = compositor.CreateVector3KeyFrameAnimation();
            _leftoffsetAnimation.InsertKeyFrame(1.0f, new Vector3(0 + sliderMargins.X, 0, 0));
            _leftoffsetAnimation.Duration = TimeSpan.FromSeconds(0.2f);
            _rightoffsetAnimation         = compositor.CreateVector3KeyFrameAnimation();
            _rightoffsetAnimation.InsertKeyFrame(1.0f, new Vector3(100 - sliderMargins.Y, 0, 0));
            _rightoffsetAnimation.Duration = TimeSpan.FromSeconds(0.2f);
        }
示例#27
0
        public void CreateBar(float maxHeight)
        {
            shapeVisual      = _compositor.CreateShapeVisual();
            shapeVisual.Size = new System.Numerics.Vector2(maxHeight, maxHeight);
            shapeVisual.RotationAngleInDegrees = -90f;

            rectGeometry      = _compositor.CreateRectangleGeometry();
            rectGeometry.Size = new System.Numerics.Vector2(Height, Width); //reverse width and height since rect will be at a 90* angle

            barVisual           = _compositor.CreateSpriteShape(rectGeometry);
            barVisual.FillBrush = Brush;

            shapeVisual.Shapes.Add(barVisual);

            Root = shapeVisual;

            // Add implict animation to bar
            var implicitAnimations = _compositor.CreateImplicitAnimationCollection();

            // Trigger animation when the size property changes.
            implicitAnimations["Size"]      = CreateAnimation();
            rectGeometry.ImplicitAnimations = implicitAnimations;
        }
示例#28
0
        private bool CreateRenderData(Node node)
        {
            var nativeShape = m_tree.GetShape(node.Uuid);
            var renderData  = nativeShape.getRenderData();

            if (renderData == null || !renderData.getShouldRender())
            {
                return(false);
            }

            var nativeGeometry = m_tree.GetGeometry(node.Parent.Uuid);
            var shape          = node.GameObject.GetComponent <AGXUnity.Collide.Shape>();

            var toWorld = nativeGeometry.getTransform();
            var toLocal = shape.transform.worldToLocalMatrix;

            var meshes = new Mesh[] { };

            if (renderData.getVertexArray().Count > UInt16.MaxValue)
            {
                Debug.LogWarning("Render data contains more than " +
                                 UInt16.MaxValue +
                                 " vertices. Splitting it into smaller meshes.");

                var splitter = MeshSplitter.Split(renderData.getVertexArray(),
                                                  renderData.getIndexArray(),
                                                  v => toLocal.MultiplyPoint3x4(toWorld.preMult(v).ToHandedVector3()));
                meshes = splitter.Meshes;
                for (int i = 0; i < meshes.Length; ++i)
                {
                    meshes[i].name = shape.name + "_Visual_Mesh_" + i.ToString();
                }
            }
            else
            {
                var mesh = new Mesh();
                mesh.name = shape.name + "_Visual_Mesh";

                // Assigning and converting vertices.
                // Note: RenderData vertices assumed to be given in geometry coordinates.
                mesh.SetVertices((from v
                                  in renderData.getVertexArray()
                                  select toLocal.MultiplyPoint3x4(toWorld.preMult(v).ToHandedVector3())).ToList());

                // Assigning and converting colors.
                mesh.SetColors((from c
                                in renderData.getColorArray()
                                select c.ToColor()).ToList());

                // Unsure about this one.
                mesh.SetUVs(0,
                            (from uv
                             in renderData.getTexCoordArray()
                             select uv.ToVector2()).ToList());

                // Converting counter clockwise -> clockwise.
                var triangles  = new List <int>();
                var indexArray = renderData.getIndexArray();
                for (int i = 0; i < indexArray.Count; i += 3)
                {
                    triangles.Add(Convert.ToInt32(indexArray[i + 0]));
                    triangles.Add(Convert.ToInt32(indexArray[i + 2]));
                    triangles.Add(Convert.ToInt32(indexArray[i + 1]));
                }
                mesh.SetTriangles(triangles, 0, false);

                mesh.RecalculateBounds();
                mesh.RecalculateNormals();
                mesh.RecalculateTangents();

                meshes = new Mesh[] { mesh };
            }

            var shader = Shader.Find("Standard") ?? Shader.Find("Diffuse");

            if (shader == null)
            {
                Debug.LogError("Unable to find standard shaders.");
            }

            var renderMaterial = renderData.getRenderMaterial();
            var material       = new Material(shader);

            material.name = shape.name + "_Visual_Material";

            if (renderMaterial.hasDiffuseColor())
            {
                var color = renderMaterial.getDiffuseColor().ToColor();
                color.a = 1.0f - renderMaterial.getTransparency();

                material.SetVector("_Color", color);
            }
            if (renderMaterial.hasEmissiveColor())
            {
                material.SetVector("_EmissionColor", renderMaterial.getEmissiveColor().ToColor());
            }

            material.SetFloat("_Metallic", 0.3f);
            material.SetFloat("_Glossiness", 0.8f);

            if (renderMaterial.getTransparency() > 0.0f)
            {
                material.SetBlendMode(BlendMode.Transparent);
            }

            material = AddOrReplaceAsset(material, node, AGXUnity.IO.AssetType.Material);
            foreach (var mesh in meshes)
            {
                AddOrReplaceAsset(mesh, node, AGXUnity.IO.AssetType.RenderMesh);
            }

            var shapeVisual = ShapeVisual.Find(shape);

            if (shapeVisual != null)
            {
                // Verify so that the meshes matches the current configuration?
            }
            else
            {
                ShapeVisual.CreateRenderData(shape, meshes, material);
            }

            return(true);
        }
示例#29
0
        public static CompositionAnimation ParseThumbnail(int width, int height, IList <ClosedVectorPath> contours, out ShapeVisual visual, bool animated = true)
        {
            CompositionPath path;

            if (contours?.Count > 0)
            {
                path = Parse(contours);
            }
            else
            {
                path = new CompositionPath(CanvasGeometry.CreateRoundedRectangle(null, 0, 0, width, height, 80, 80));
            }

            var transparent     = Color.FromArgb(0x00, 0x7A, 0x8A, 0x96);
            var foregroundColor = Color.FromArgb(0x33, 0x7A, 0x8A, 0x96);
            var backgroundColor = Color.FromArgb(0x33, 0x7A, 0x8A, 0x96);

            var gradient = Window.Current.Compositor.CreateLinearGradientBrush();

            gradient.StartPoint = new Vector2(0, 0);
            gradient.EndPoint   = new Vector2(1, 0);
            gradient.ColorStops.Add(Window.Current.Compositor.CreateColorGradientStop(0.0f, transparent));
            gradient.ColorStops.Add(Window.Current.Compositor.CreateColorGradientStop(0.5f, foregroundColor));
            gradient.ColorStops.Add(Window.Current.Compositor.CreateColorGradientStop(1.0f, transparent));

            var background = Window.Current.Compositor.CreateRectangleGeometry();

            background.Size = new Vector2(width, height);
            var backgroundShape = Window.Current.Compositor.CreateSpriteShape(background);

            backgroundShape.FillBrush = Window.Current.Compositor.CreateColorBrush(backgroundColor);

            var foreground = Window.Current.Compositor.CreateRectangleGeometry();

            foreground.Size = new Vector2(width, height);
            var foregroundShape = Window.Current.Compositor.CreateSpriteShape(foreground);

            foregroundShape.FillBrush = gradient;

            var clip = Window.Current.Compositor.CreateGeometricClip(Window.Current.Compositor.CreatePathGeometry(path));

            clip.ViewBox         = Window.Current.Compositor.CreateViewBox();
            clip.ViewBox.Size    = new Vector2(width, height);
            clip.ViewBox.Stretch = CompositionStretch.UniformToFill;

            visual      = Window.Current.Compositor.CreateShapeVisual();
            visual.Clip = clip;
            visual.Shapes.Add(backgroundShape);
            visual.Shapes.Add(foregroundShape);
            visual.RelativeSizeAdjustment = Vector2.One;

            if (animated)
            {
                var animation = Window.Current.Compositor.CreateVector2KeyFrameAnimation();
                animation.InsertKeyFrame(0, new Vector2(-width, 0));
                animation.InsertKeyFrame(1, new Vector2(width, 0));
                animation.IterationBehavior = AnimationIterationBehavior.Forever;
                animation.Duration          = TimeSpan.FromSeconds(1);

                foregroundShape.StartAnimation("Offset", animation);

                return(animation);
            }

            return(null);
        }
示例#30
0
 public static CompositionAnimation ParseThumbnail(StickerViewModel sticker, out ShapeVisual visual, bool animated = true)
 {
     return(ParseThumbnail(sticker.Width, sticker.Height, sticker.Outline, out visual, animated));
 }