Пример #1
0
        internal static void ApplyColorOrFill <T>(T fillable, ShapeFill fill, Color baseColor) where T : MetaMpb, IFillable
        {
            bool useFill = fill != null;

            fillable.color.Add(useFill ? fill.colorStart : baseColor);
            fillable.fillType.Add(fill.GetShaderFillModeInt());
            fillable.fillSpace.Add(useFill ? (float)fill.space : default);
Пример #2
0
        [OvldGenCallTarget] public static void Polygon([OvldDefault(nameof(BlendMode))] ShapesBlendMode blendMode,
                                                       PolygonPath path,
                                                       [OvldDefault(nameof(PolygonTriangulation))] PolygonTriangulation triangulation,
                                                       [OvldDefault(nameof(Color))] Color color,
                                                       [OvldDefault(nameof(PolygonShapeFill))] ShapeFill fill)
        {
            if (path.EnsureMeshIsReadyToRender(triangulation, out Mesh mesh) == false)
            {
                return;                 // no points defined in the mesh
            }
            switch (path.Count)
            {
            case 0:
                Debug.LogWarning("Tried to draw polygon with no points");
                return;

            case 1:
                Debug.LogWarning("Tried to draw polygon with only one point");
                return;

            case 2:
                Debug.LogWarning("Tried to draw polygon with only two points");
                return;
            }

            Material matPolygon = ShapesMaterialUtils.matPolygon[blendMode];

            ApplyGlobalProperties(matPolygon);
            TryApplyFillAndColor(matPolygon, fill, color);
            DrawMesh(Vector3.zero, Quaternion.identity, mesh, matPolygon);
        }
Пример #3
0
        [OvldGenCallTarget] static void Rectangle_Internal([OvldDefault(nameof(BlendMode))] ShapesBlendMode blendMode,
                                                           [OvldDefault("false")] bool hollow,
                                                           Rect rect,
                                                           [OvldDefault(nameof(Color))] Color color,
                                                           [OvldDefault(nameof(RectangleThickness))] float thickness,
                                                           [OvldDefault("default")] Vector4 cornerRadii,
                                                           [OvldDefault(nameof(PolygonShapeFill))] ShapeFill fill)
        {
            bool rounded = ShapesMath.MaxComp(cornerRadii) >= 0.0001f;

            // positive vibes only
            if (rect.width < 0)
            {
                rect.x -= rect.width *= -1;
            }
            if (rect.height < 0)
            {
                rect.y -= rect.height *= -1;
            }

            if (hollow && thickness * 2 >= Mathf.Min(rect.width, rect.height))
            {
                hollow = false;
            }

            using (new IMDrawer(mpbRectangle, ShapesMaterialUtils.GetRectMaterial(hollow, rounded)[blendMode], ShapesMeshUtils.QuadMesh[0])) {
                MetaMpb.ApplyColorOrFill(mpbRectangle, fill, color);
                mpbRectangle.rect.Add(rect.ToVector4());
                mpbRectangle.cornerRadii.Add(cornerRadii);
                mpbRectangle.thickness.Add(thickness);
                mpbRectangle.thicknessSpace.Add((int)Draw.RegularPolygonThicknessSpace);
                mpbRectangle.scaleMode.Add((int)ScaleMode);
            }
        }
Пример #4
0
        [OvldGenCallTarget] static void Polygon_Internal(PolygonPath path,
                                                         [OvldDefault(nameof(PolygonTriangulation))] PolygonTriangulation triangulation,
                                                         [OvldDefault(nameof(Color))] Color color,
                                                         [OvldDefault(nameof(PolygonShapeFill))] ShapeFill fill)
        {
            if (path.EnsureMeshIsReadyToRender(triangulation, out Mesh mesh) == false)
            {
                return;                 // no points defined in the mesh
            }
            switch (path.Count)
            {
            case 0:
                Debug.LogWarning("Tried to draw polygon with no points");
                return;

            case 1:
                Debug.LogWarning("Tried to draw polygon with only one point");
                return;

            case 2:
                Debug.LogWarning("Tried to draw polygon with only two points");
                return;
            }

            if (DrawCommand.IsAddingDrawCommandsToBuffer)              // mark as used by this command to prevent destroy in dispose
            {
                path.lastCommandUsedIn = DrawCommand.CurrentWritingCommandBuffer;
            }

            using (new IMDrawer(mpbPolygon, ShapesMaterialUtils.matPolygon[Draw.BlendMode], mesh)) {
                MetaMpb.ApplyColorOrFill(mpbPolygon, fill, color);
            }
        }
Пример #5
0
 [OvldGenCallTarget] static void RegularPolygon([OvldDefault(nameof(BlendMode))] ShapesBlendMode blendMode,
                                                [OvldDefault(nameof(RegularPolygonRadiusSpace))] ThicknessSpace spaceRadius,
                                                [OvldDefault(nameof(RegularPolygonThicknessSpace))] ThicknessSpace spaceThickness,
                                                Vector3 pos,
                                                [OvldDefault("Quaternion.identity")] Quaternion rot,
                                                [OvldDefault(nameof(RegularPolygonSideCount))] int sideCount,
                                                [OvldDefault(nameof(RegularPolygonRadius))] float radius,
                                                [OvldDefault(nameof(RegularPolygonThickness))] float thickness,
                                                [OvldDefault(nameof(Color))] Color color,
                                                bool hollow,
                                                [OvldDefault("0f")] float roundness,
                                                [OvldDefault("0f")] float angle,
                                                [OvldDefault(nameof(PolygonShapeFill))] ShapeFill fill)
 {
     using (new IMDrawer(mpbRegularPolygon, ShapesMaterialUtils.matRegularPolygon[blendMode], ShapesMeshUtils.QuadMesh[0], pos, rot)) {
         MetaMpb.ApplyColorOrFill(mpbRegularPolygon, fill, color);
         mpbRegularPolygon.radius.Add(radius);
         mpbRegularPolygon.radiusSpace.Add((int)spaceRadius);
         mpbRegularPolygon.geometry.Add((int)Draw.RegularPolygonGeometry);
         mpbRegularPolygon.sides.Add(Mathf.Max(3, sideCount));
         mpbRegularPolygon.angle.Add(angle);
         mpbRegularPolygon.roundness.Add(roundness);
         mpbRegularPolygon.hollow.Add(hollow.AsInt());
         mpbRegularPolygon.thicknessSpace.Add((int)spaceThickness);
         mpbRegularPolygon.thickness.Add(thickness);
         mpbRegularPolygon.scaleMode.Add((int)ScaleMode);
     }
 }
Пример #6
0
        [OvldGenCallTarget] static void Polygon([OvldDefault(nameof(BlendMode))] ShapesBlendMode blendMode,
                                                PolygonPath path,
                                                [OvldDefault(nameof(PolygonTriangulation))] PolygonTriangulation triangulation,
                                                [OvldDefault(nameof(Color))] Color color,
                                                [OvldDefault(nameof(PolygonShapeFill))] ShapeFill fill)
        {
            if (path.EnsureMeshIsReadyToRender(triangulation, out Mesh mesh) == false)
            {
                return;                 // no points defined in the mesh
            }
            switch (path.Count)
            {
            case 0:
                Debug.LogWarning("Tried to draw polygon with no points");
                return;

            case 1:
                Debug.LogWarning("Tried to draw polygon with only one point");
                return;

            case 2:
                Debug.LogWarning("Tried to draw polygon with only two points");
                return;
            }

            using (new IMDrawer(mpbPolygon, ShapesMaterialUtils.matPolygon[blendMode], mesh)) {
                MetaMpb.ApplyColorOrFill(mpbPolygon, fill, color);
            }
        }
Пример #7
0
        static void TryApplyFillAndColor(Material mat, ShapeFill fill, Color defaultColor)
        {
            bool useFill = fill != null;

            mat.SetColor(ShapesMaterialUtils.propColor, useFill ? fill.colorStart : defaultColor);
            mat.SetInt(ShapesMaterialUtils.propFillType, fill.GetShaderFillModeInt());
            if (useFill)
            {
                mat.SetInt(ShapesMaterialUtils.propFillSpace, (int)fill.space);
                mat.SetVector(ShapesMaterialUtils.propFillStart, fill.GetShaderStartVector());
                mat.SetColor(ShapesMaterialUtils.propColorEnd, fill.colorEnd);
                if (fill.type == FillType.LinearGradient)
                {
                    mat.SetVector(ShapesMaterialUtils.propFillEnd, fill.linearEnd);
                }
            }
        }
Пример #8
0
        [OvldGenCallTarget] public static void RegularPolygon([OvldDefault(nameof(BlendMode))] ShapesBlendMode blendMode,
                                                              [OvldDefault(nameof(RegularPolygonRadiusSpace))] ThicknessSpace spaceRadius,
                                                              [OvldDefault(nameof(RegularPolygonThicknessSpace))] ThicknessSpace spaceThickness,
                                                              Vector3 pos,
                                                              [OvldDefault("Quaternion.identity")] Quaternion rot,
                                                              [OvldDefault(nameof(RegularPolygonSideCount))] int sideCount,
                                                              [OvldDefault(nameof(RegularPolygonRadius))] float radius,
                                                              [OvldDefault(nameof(RegularPolygonThickness))] float thickness,
                                                              [OvldDefault(nameof(Color))] Color color,
                                                              bool hollow,
                                                              [OvldDefault("0f")] float roundness,
                                                              [OvldDefault("0f")] float angle,
                                                              [OvldDefault(nameof(PolygonShapeFill))] ShapeFill fill)
        {
            Material mat = ShapesMaterialUtils.matRegularPolygon[blendMode];

            ApplyGlobalProperties(mat);
            mat.SetFloat(ShapesMaterialUtils.propRadius, radius);
            mat.SetInt(ShapesMaterialUtils.propRadiusSpace, (int)spaceRadius);
            mat.SetInt(ShapesMaterialUtils.propAlignment, (int)Draw.RegularPolygonGeometry);
            mat.SetInt(ShapesMaterialUtils.propSides, Mathf.Max(3, sideCount));
            mat.SetFloat(ShapesMaterialUtils.propAng, angle);
            mat.SetFloat(ShapesMaterialUtils.propRoundness, roundness);

            mat.SetInt(ShapesMaterialUtils.propHollow, hollow.AsInt());
            if (hollow)
            {
                mat.SetInt(ShapesMaterialUtils.propThicknessSpace, (int)spaceThickness);
                mat.SetFloat(ShapesMaterialUtils.propThickness, thickness);
                mat.SetInt(ShapesMaterialUtils.propScaleMode, (int)ScaleMode);
            }

            TryApplyFillAndColor(mat, fill, color);

            DrawMesh(pos, rot, ShapesMeshUtils.QuadMesh, mat);
        }
Пример #9
0
 internal static int GetShaderFillModeInt(this ShapeFill fill) => fill != null ? (int)fill.type : ShapeFill.FILL_NONE;