diff --git a/examples/java/tech/fastj/examples/behaviors/Main.java b/examples/java/tech/fastj/examples/behaviors/Main.java index 7c28a65d..ed0b0e9c 100644 --- a/examples/java/tech/fastj/examples/behaviors/Main.java +++ b/examples/java/tech/fastj/examples/behaviors/Main.java @@ -59,7 +59,8 @@ public void init(FastJCanvas canvas) { * * For this example, we'll just use simpleRotation. */ - Polygon2D premadeBehaviorsBox = Polygon2D.create(DrawUtil.createBox(500f, 500f, 50f), RenderStyle.FillAndOutline) + Polygon2D premadeBehaviorsBox = Polygon2D.create(DrawUtil.createBox(500f, 500f, 50f)) + .withRenderStyle(RenderStyle.FillAndOutline) .withFill(Color.red) .withOutline(Polygon2D.DefaultOutlineStroke, Polygon2D.DefaultOutlineColor) .build(); diff --git a/examples/java/tech/fastj/examples/polygon2d/Main.java b/examples/java/tech/fastj/examples/polygon2d/Main.java index 101fc8cc..d4872a70 100644 --- a/examples/java/tech/fastj/examples/polygon2d/Main.java +++ b/examples/java/tech/fastj/examples/polygon2d/Main.java @@ -77,7 +77,8 @@ public void init(FastJCanvas canvas) { float largeSquareRotation = 30f; Pointf largeSquareScale = new Pointf(0.5f, 0.5f); - Polygon2D largeSquare = Polygon2D.create(largeSquareMesh, RenderStyle.FillAndOutline) + Polygon2D largeSquare = Polygon2D.create(largeSquareMesh) + .withRenderStyle(RenderStyle.FillAndOutline) .withFill(Color.blue) .withOutline(largeSquareOutlineStroke, Color.black) .withTransform(largeSquareTranslation, largeSquareRotation, largeSquareScale) diff --git a/src/main/java/tech/fastj/graphics/game/Polygon2D.java b/src/main/java/tech/fastj/graphics/game/Polygon2D.java index 7b31ea7a..709ab4e0 100644 --- a/src/main/java/tech/fastj/graphics/game/Polygon2D.java +++ b/src/main/java/tech/fastj/graphics/game/Polygon2D.java @@ -72,64 +72,51 @@ protected Polygon2D(Pointf[] points, Point[] altIndexes) { /** * Gets a {@link Polygon2DBuilder} instance while setting the eventual {@link Polygon2D}'s {@code points} field. - *
* * @param points {@code Pointf} array that defines the points for the {@code Polygon2D}. * @return A {@code Polygon2DBuilder} instance for creating a {@code Polygon2D}. */ public static Polygon2DBuilder create(Pointf[] points) { - return new Polygon2DBuilder(points, null, DefaultRenderStyle, Drawable.DefaultShouldRender); + return new Polygon2DBuilder(points, null, Drawable.DefaultShouldRender); } /** - * Gets a {@link Polygon2DBuilder} instance while setting the eventual {@link Polygon2D}'s {@code points} field. - *
+ * Gets a {@link Polygon2DBuilder} instance while setting the eventual {@link Polygon2D}'s {@code points} and + * {@code altIndexes} fields. * - * @param points {@code Pointf} array that defines the points for the {@code Polygon2D}. + * @param points {@code Pointf} array that defines the points for the {@code Polygon2D}. + * @param altIndexes The {@code Point} array of alternate indexes defining where curves are in the array of points, + * as well as other {@code Path2D} options. * @return A {@code Polygon2DBuilder} instance for creating a {@code Polygon2D}. */ public static Polygon2DBuilder create(Pointf[] points, Point[] altIndexes) { - return new Polygon2DBuilder(points, altIndexes, DefaultRenderStyle, Drawable.DefaultShouldRender); + return new Polygon2DBuilder(points, altIndexes, Drawable.DefaultShouldRender); } /** * Gets a {@link Polygon2DBuilder} instance while setting the eventual {@link Polygon2D}'s {@code points} and * {@code shouldRender} fields. - *
* * @param points {@code Pointf} array that defines the points for the {@code Polygon2D}. * @param shouldRender {@code boolean} that defines whether the {@code Polygon2D} would be rendered to the screen. * @return A {@code Polygon2DBuilder} instance for creating a {@code Polygon2D}. */ public static Polygon2DBuilder create(Pointf[] points, boolean shouldRender) { - return new Polygon2DBuilder(points, null, DefaultRenderStyle, shouldRender); - } - - /** - * Gets a {@link Polygon2DBuilder} instance while setting the eventual {@link Polygon2D}'s {@code points} and - * {@code renderStyle} fields. - *
- * - * @param points {@code Pointf} array that defines the points for the {@code Polygon2D}. - * @param renderStyle {@code RenderStyle} that defines the render style for the {@code Polygon2D}. - * @return A {@code Polygon2DBuilder} instance for creating a {@code Polygon2D}. - */ - public static Polygon2DBuilder create(Pointf[] points, RenderStyle renderStyle) { - return new Polygon2DBuilder(points, null, renderStyle, Drawable.DefaultShouldRender); + return new Polygon2DBuilder(points, null, shouldRender); } /** * Gets a {@link Polygon2DBuilder} instance while setting the eventual {@link Polygon2D}'s {@code points}, * {@code renderStyle}, and {@code shouldRender} fields. - *
*
* @param points {@code Pointf} array that defines the points for the {@code Polygon2D}.
- * @param renderStyle {@code RenderStyle} that defines the render style for the {@code Polygon2D}.
+ * @param altIndexes The {@code Point} array of alternate indexes defining where curves are in the array of
+ * points, as well as other {@code Path2D} options.
* @param shouldRender {@code boolean} that defines whether the {@code Polygon2D} would be rendered to the screen.
* @return A {@code Polygon2DBuilder} instance for creating a {@code Polygon2D}.
*/
- public static Polygon2DBuilder create(Pointf[] points, RenderStyle renderStyle, boolean shouldRender) {
- return new Polygon2DBuilder(points, null, renderStyle, shouldRender);
+ public static Polygon2DBuilder create(Pointf[] points, Point[] altIndexes, boolean shouldRender) {
+ return new Polygon2DBuilder(points, altIndexes, shouldRender);
}
/**
@@ -139,17 +126,19 @@ public static Polygon2DBuilder create(Pointf[] points, RenderStyle renderStyle,
* @return The resulting {@code Polygon2D}.
*/
public static Polygon2D fromPoints(Pointf[] points) {
- return new Polygon2DBuilder(points, null, DefaultRenderStyle, Drawable.DefaultShouldRender).build();
+ return new Polygon2DBuilder(points, null, Drawable.DefaultShouldRender).build();
}
/**
- * Creates a {@code Polygon2D} from the specified points.
+ * Creates a {@code Polygon2D} from the specified points and alternate indexes.
*
- * @param points {@code Pointf} array that defines the points for the {@code Polygon2D}.
+ * @param points {@code Pointf} array that defines the points for the {@code Polygon2D}.
+ * @param altIndexes The {@code Point} array of alternate indexes defining where curves are in the array of points,
+ * as well as other {@code Path2D} options.
* @return The resulting {@code Polygon2D}.
*/
public static Polygon2D fromPoints(Pointf[] points, Point[] altIndexes) {
- return new Polygon2DBuilder(points, altIndexes, DefaultRenderStyle, Drawable.DefaultShouldRender).build();
+ return new Polygon2DBuilder(points, altIndexes, Drawable.DefaultShouldRender).build();
}
/**
@@ -163,7 +152,7 @@ public Pointf[] getOriginalPoints() {
/**
* Gets the polygon's alternate indexes, which are associated with the
- * {@link #getOriginalPoints() original point set.}
+ * {@link #getOriginalPoints() original point set}.
*
* @return The original set of points for this polygon, as a {@code Pointf[]}.
*/
diff --git a/src/main/java/tech/fastj/graphics/game/Polygon2DBuilder.java b/src/main/java/tech/fastj/graphics/game/Polygon2DBuilder.java
index cb3929a8..0f466c9a 100644
--- a/src/main/java/tech/fastj/graphics/game/Polygon2DBuilder.java
+++ b/src/main/java/tech/fastj/graphics/game/Polygon2DBuilder.java
@@ -15,8 +15,8 @@ public class Polygon2DBuilder {
private final Pointf[] points;
private final Point[] altIndexes;
private final boolean shouldRender;
- private final RenderStyle renderStyle;
+ private RenderStyle renderStyle = Polygon2D.DefaultRenderStyle;
private Paint fillPaint = Polygon2D.DefaultFill;
private BasicStroke outlineStroke = Polygon2D.DefaultOutlineStroke;
private Color outlineColor = Polygon2D.DefaultOutlineColor;
@@ -26,20 +26,31 @@ public class Polygon2DBuilder {
private Pointf scale = Transform2D.DefaultScale.copy();
/**
- * {@code Polygon2DBuilder} constructor, taking in a set of points, a render style, and a {@code shouldRender}
- * boolean.
+ * {@code Polygon2DBuilder} constructor, taking in a set of points, a set of alternate indexes (for defining
+ * curves), and a {@code shouldRender} boolean.
*
* @param points The {@code Pointf} array of mesh points to use for the resulting {@code Polygon2D}.
- * @param renderStyle The {@code RenderStyle} to use for the resulting {@code Polygon2D}.
+ * @param altIndexes The {@code Point} array of alternate indexes defining where curves are in the array of
+ * points, as well as other {@code Path2D} options.
* @param shouldRender The "should render" {@code boolean} to use for the resulting {@code Polygon2D}.
*/
- Polygon2DBuilder(Pointf[] points, Point[] altIndexes, RenderStyle renderStyle, boolean shouldRender) {
+ Polygon2DBuilder(Pointf[] points, Point[] altIndexes, boolean shouldRender) {
this.points = Objects.requireNonNull(points, "The array of points must not be null.");
this.altIndexes = altIndexes;
- this.renderStyle = Objects.requireNonNull(renderStyle, "The render style must not be null.");
this.shouldRender = shouldRender;
}
+ /**
+ * Sets the builder's render style value.
+ *
+ * @param renderStyle The {@code RenderStyle} to be used in the resulting {@code Polygon2D}.
+ * @return The {@code Polygon2DBuilder}, for method chaining.
+ */
+ public Polygon2DBuilder withRenderStyle(RenderStyle renderStyle) {
+ this.renderStyle = Objects.requireNonNull(renderStyle, "The render style must not be null.");
+ return this;
+ }
+
/**
* Sets the builder's fill paint value.
*
diff --git a/src/main/java/tech/fastj/resources/models/ObjUtil.java b/src/main/java/tech/fastj/resources/models/ObjUtil.java
index 2fabf97e..395b77de 100644
--- a/src/main/java/tech/fastj/resources/models/ObjUtil.java
+++ b/src/main/java/tech/fastj/resources/models/ObjUtil.java
@@ -69,7 +69,7 @@ public static Polygon2D[] parse(Path modelPath, List