public void SetBrushOnStrokeSketchObjectRedo()
        {
            ICommand addCommand = new AddControlPointCommand(this.Stroke, new Vector3(0, 0, 0));

            Invoker.ExecuteCommand(addCommand);
            addCommand = new AddControlPointCommand(this.Stroke, new Vector3(1, 1, 1));
            Invoker.ExecuteCommand(addCommand);
            addCommand = new AddControlPointCommand(this.Stroke, new Vector3(2, 2, 0));
            Invoker.ExecuteCommand(addCommand);
            Assert.AreEqual((2 * 20 + 2) * 7, this.Stroke.GetComponent <MeshFilter>().sharedMesh.vertices.Length);

            StrokeBrush brush = this.Stroke.GetBrush() as StrokeBrush;

            brush.SketchMaterial.AlbedoColor = Color.green;
            brush.CrossSectionVertices.Add(Vector3.one);
            brush.CrossSectionNormals.Add(Vector3.one);
            ICommand SetBrushCommand = new SetBrushCommand(this.Stroke, brush);

            Invoker.ExecuteCommand(SetBrushCommand);
            Invoker.Undo();
            Invoker.Redo();

            Assert.AreEqual(Color.green, this.Stroke.GetComponent <MeshRenderer>().sharedMaterial.color);
            StrokeBrush updatedBrush = this.Stroke.GetBrush() as StrokeBrush;

            Assert.AreEqual(Color.green, updatedBrush.SketchMaterial.AlbedoColor);
            Assert.AreEqual((2 * 20 + 2) * 8, this.Stroke.GetComponent <MeshFilter>().sharedMesh.vertices.Length);
        }
Exemplo n.º 2
0
        public BasicStyleCache(BasicStyle style)
        {
            if (style == null)
            {
                return;
            }

            Thickness     = style.Thickness;
            HalfThickness = Thickness / 2.0;

            if (style.Fill != null)
            {
                FillBrush = ToBrush(style.Fill);
                FillBrush.Freeze();
            }

            if (style.Stroke != null)
            {
                StrokeBrush = ToBrush(style.Stroke);
                StrokeBrush.Freeze();

                StrokePen = new Pen(StrokeBrush, Thickness);
                StrokePen.Freeze();
            }
        }
        public Brush GetBrush()
        {
            StrokeBrush brush = new StrokeBrush();

            brush.SketchMaterial     = new SketchMaterialData(meshRenderer.sharedMaterial);
            brush.CrossSectionScale  = this.lineDiameter;
            brush.InterpolationSteps = this.InterpolationSteps;
            SplineMesh.GetCrossSectionShape(out brush.CrossSectionVertices, out brush.CrossSectionNormals);
            return(brush);
        }
Exemplo n.º 4
0
        internal override void Render(SKSurface surface, SKImageInfo info)
        {
            SkiaGeometrySource2D?geometrySource = Geometry?.BuildGeometry() as SkiaGeometrySource2D;

            SKPath?geometry = geometrySource?.Geometry;

            if (geometry == null)
            {
                return;
            }

            if (FillBrush != null)
            {
                var fillPaint = TryCreateAndClearFillPaint();

                FillBrush.UpdatePaint(fillPaint, geometry.Bounds);

                surface.Canvas.DrawPath(geometry, fillPaint);
            }

            if (StrokeBrush != null && StrokeThickness > 0)
            {
                var fillPaint   = TryCreateAndClearFillPaint();
                var strokePaint = TryCreateAndClearStrokePaint();

                // Set stroke thickness
                strokePaint.StrokeWidth = StrokeThickness;
                // TODO: Add support for dashes here
                // strokePaint.PathEffect = SKPathEffect.CreateDash();

                // Generate stroke geometry for bounds that will be passed to a brush.
                // - [Future]: This generated geometry should also be used for hit testing.
                using (var strokeGeometry = strokePaint.GetFillPath(geometry))
                {
                    StrokeBrush.UpdatePaint(fillPaint, strokeGeometry.Bounds);

                    surface.Canvas.DrawPath(strokeGeometry, fillPaint);
                }
            }
        }