Record Class MeshParseContext

java.lang.Object
java.lang.Record
io.github.toxicity188.javamesh.parser.MeshParseContext
Record Components:
name - logical mesh name used by parsers
scale - global scale applied while reading mesh coordinates
loaders - asset loaders keyed by file extension

public record MeshParseContext(@NotNull String name, float scale, @NotNull @Unmodifiable Map<String,MeshParseContext.StreamLoader> loaders) extends Record
Input configuration for mesh parsers.

The context supplies a logical asset name, a global scale factor, and lazily-opened streams for source files such as OBJ and MTL so they can be converted into Minecraft resource-pack models.


 MeshParseContext context = MeshParseContext.builder("sword")
     .scale(0.5f)
     .asset("obj", () -> Files.newInputStream(objPath))
     .asset("mtl", () -> Files.newInputStream(mtlPath))
     .build();
 
Since:
0.0.1
  • Constructor Details

    • MeshParseContext

      public MeshParseContext(@NotNull @NotNull String name, float scale, @NotNull @NotNull @Unmodifiable Map<String,MeshParseContext.StreamLoader> loaders)
      Creates an instance of a MeshParseContext record class.
      Parameters:
      name - the value for the name record component
      scale - the value for the scale record component
      loaders - the value for the loaders record component
  • Method Details

    • builder

      @NotNull public static @NotNull MeshParseContext.Builder builder(@NotNull @NotNull String name)
      Starts building a parser context for the given mesh asset name.
      Parameters:
      name - logical mesh name
      Returns:
      a new builder
      Since:
      0.0.1
    • loadExtension

      @NotNull public @NotNull InputStream loadExtension(@NotNull @NotNull String extension) throws IOException
      Opens the stream registered for the given extension.
      Parameters:
      extension - asset extension such as "obj" or "mtl"
      Returns:
      the opened stream
      Throws:
      IOException - if the underlying loader fails while opening the stream
      NullPointerException - if no loader is registered for extension
      Since:
      0.0.1
    • loadExtensionOrNull

      @Nullable public @Nullable InputStream loadExtensionOrNull(@NotNull @NotNull String extension) throws IOException
      Opens the stream registered for the given extension when available.
      Parameters:
      extension - asset extension such as "obj" or "mtl"
      Returns:
      the opened stream, or null when the extension is not registered
      Throws:
      IOException - if the underlying loader fails while opening the stream
      Since:
      0.0.1
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • name

      @NotNull public @NotNull String name()
      Returns the value of the name record component.
      Returns:
      the value of the name record component
    • scale

      public float scale()
      Returns the value of the scale record component.
      Returns:
      the value of the scale record component
    • loaders

      @NotNull public @NotNull @Unmodifiable Map<String,MeshParseContext.StreamLoader> loaders()
      Returns the value of the loaders record component.
      Returns:
      the value of the loaders record component