Class MeshBuilder

java.lang.Object
io.github.toxicity188.javamesh.MeshBuilder

public final class MeshBuilder extends Object
Builds Minecraft resource-pack model JSON from parsed mesh polygons.

A builder instance collects triangulated mesh faces, applies an optional matrix transform, and emits the final composite model definition used by Minecraft item models.


 var json = MeshBuilder.of(MeshTriangleName.of("item/mesh_triangle", "item/mesh_triangle_double"))
     .image(Map.of("blade.png", MeshImage.from(texture)))
     .load(kr.toxicity.library.javamesh.parser.obj.ObjParser.INSTANCE.parse(
         kr.toxicity.library.javamesh.parser.MeshParseContext.builder("sword")
             .asset("obj", () -> Files.newInputStream(objPath))
             .asset("mtl", () -> Files.newInputStream(mtlPath))
             .build()
     ))
     .toJson();
 
Since:
0.0.1
  • Method Details

    • of

      @NotNull public static @NotNull MeshBuilder of(@NotNull @NotNull MeshTriangleName name)
      Creates a builder configured with the model ids used for single-sided and double-sided triangles.
      Parameters:
      name - triangle model identifiers used in the generated Minecraft model JSON
      Returns:
      a new builder instance
      Since:
      0.0.1
    • image

      @NotNull public @NotNull MeshBuilder image(@NotNull @NotNull Map<String,MeshImage> image)
      Registers texture images by resource name so triangle tint colors can be sampled from UVs.
      Parameters:
      image - images keyed by the texture name referenced by parsed mesh faces
      Returns:
      this builder
      Throws:
      NullPointerException - if image is null
      Since:
      0.0.1
    • matrixModifier

      @NotNull public @NotNull MeshBuilder matrixModifier(@NotNull @NotNull Consumer<org.joml.Matrix4f> matrixModifier)
      Registers a callback that can mutate each triangle transform before JSON serialization.
      Parameters:
      matrixModifier - callback applied to every finite triangle transformation matrix
      Returns:
      this builder
      Throws:
      NullPointerException - if matrixModifier is null
      Since:
      0.0.1
    • load

      @NotNull public @NotNull MeshBuilder load(@NotNull @NotNull MeshParseResult result)
      Loads parsed mesh data into this builder.
      Parameters:
      result - parser output to convert into Minecraft triangles
      Returns:
      this builder
      Throws:
      NullPointerException - if result is null
      IllegalArgumentException - if the parsed mesh contains degenerate polygons
      IllegalStateException - if polygon triangulation fails
      Since:
      0.0.1
    • load

      @NotNull public @NotNull MeshBuilder load(@NotNull @NotNull List<MeshShape> shapes)
      Loads polygon shapes and infers whether each shape should use a single-sided or double-sided triangle model.
      Parameters:
      shapes - polygon shapes extracted from a mesh source such as OBJ
      Returns:
      this builder
      Throws:
      NullPointerException - if shapes is null
      IllegalArgumentException - if a shape contains degenerate polygon data
      IllegalStateException - if polygon triangulation fails
      Since:
      0.0.1
    • load

      @NotNull public @NotNull MeshBuilder load(@NotNull @NotNull MeshShape shape, @NotNull @NotNull MeshFace face)
      Loads a single shape using the specified triangle face type.
      Parameters:
      shape - polygon to triangulate and serialize
      face - face type that selects the single-sided or double-sided triangle model id
      Returns:
      this builder
      Throws:
      NullPointerException - if shape or face is null
      IllegalArgumentException - if the shape contains degenerate polygon data
      IllegalStateException - if polygon triangulation fails
      Since:
      0.0.1
    • toJson

      @NotNull public @NotNull com.google.gson.JsonObject toJson()
      Serializes the loaded mesh into Minecraft composite model JSON.
      Returns:
      a composite model JSON object ready for resource-pack output
      Since:
      0.0.1