Package io.github.toxicity188.javamesh
Class MeshBuilder
java.lang.Object
io.github.toxicity188.javamesh.MeshBuilder
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 Summary
Modifier and TypeMethodDescription@NotNull MeshBuilderRegisters texture images by resource name so triangle tint colors can be sampled from UVs.@NotNull MeshBuilderLoads a single shape using the specified triangle face type.@NotNull MeshBuilderload(@NotNull MeshParseResult result) Loads parsed mesh data into this builder.@NotNull MeshBuilderLoads polygon shapes and infers whether each shape should use a single-sided or double-sided triangle model.@NotNull MeshBuildermatrixModifier(@NotNull Consumer<org.joml.Matrix4f> matrixModifier) Registers a callback that can mutate each triangle transform before JSON serialization.static @NotNull MeshBuilderof(@NotNull MeshTriangleName name) Creates a builder configured with the model ids used for single-sided and double-sided triangles.@NotNull com.google.gson.JsonObjecttoJson()Serializes the loaded mesh into Minecraft composite model JSON.
-
Method Details
-
of
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
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- ifimageisnull- 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- ifmatrixModifierisnull- Since:
- 0.0.1
-
load
Loads parsed mesh data into this builder.- Parameters:
result- parser output to convert into Minecraft triangles- Returns:
- this builder
- Throws:
NullPointerException- ifresultisnullIllegalArgumentException- if the parsed mesh contains degenerate polygonsIllegalStateException- if polygon triangulation fails- Since:
- 0.0.1
-
load
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- ifshapesisnullIllegalArgumentException- if a shape contains degenerate polygon dataIllegalStateException- 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 serializeface- face type that selects the single-sided or double-sided triangle model id- Returns:
- this builder
- Throws:
NullPointerException- ifshapeorfaceisnullIllegalArgumentException- if the shape contains degenerate polygon dataIllegalStateException- 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
-