Class ObjModel

java.lang.Object
net.ixdarklord.coolcatcanvas.api.client.model.ObjModel

public final class ObjModel extends Object
A model read from a Wavefront .obj file: triangles with positions, texture coordinates and normals, in named parts. Get one from ObjModels.get(Identifier) (a resource, cached and reloaded with resource packs) or parse(String) (any text).

What is read: v, vt, vn and f (faces of any number of corners, cut into triangles as a fan; indices counted from the end; corners with no texture coordinate or no normal), and o, g and usemtl, which begin a new part. A face with no normals gets its own flat one. Materials (.mtl) are not read: a part carries its material's name and the caller picks the texture, so one model can be drawn in any render type. Everything else in the file is passed over.

Units are the file's own: one unit is one block unless the pose is scaled. Texture coordinates are turned to the game's (the file's v runs up, the game's down).

Drawing goes through the game's own renderers, so a model is lit, fogged and sorted as anything else is: submit(PoseStack, SubmitNodeCollector, RenderType, int) from an entity or block entity renderer, or render(PoseStack.Pose, VertexConsumer, int, int, int) into any vertex consumer. Both are made for render types that draw quads with the entity vertex format (RenderTypes.entityCutout(texture), entityTranslucent, eyes...): each triangle is sent as a quad with its last corner twice.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    A stretch of a model drawn as one: the faces under one o, g or usemtl line.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final ObjModel
    A model with nothing in it: what a missing or broken file gives.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    org.joml.Vector3f
    max()
    The greatest corner of the box the model fills.
    org.joml.Vector3f
    min()
    The least corner of the box the model fills.
    static ObjModel
    parse(Reader reader)
    Reads a model from an .obj file.
    static ObjModel
    parse(String text)
    Reads a model from the text of an .obj file.
    part(String name)
    The first part of this name (an o or g line's), or null.
    The model's parts, in the file's order.
    void
    render(com.mojang.blaze3d.vertex.PoseStack.Pose pose, com.mojang.blaze3d.vertex.VertexConsumer consumer, int light, int overlay, int argb)
    Writes every part into a vertex consumer.
    void
    submit(com.mojang.blaze3d.vertex.PoseStack pose, net.minecraft.client.renderer.SubmitNodeCollector collector, net.minecraft.client.renderer.rendertype.RenderType type, int light)
    Every part, white, with no overlay.
    void
    submit(com.mojang.blaze3d.vertex.PoseStack pose, net.minecraft.client.renderer.SubmitNodeCollector collector, net.minecraft.client.renderer.rendertype.RenderType type, int light, int overlay, int argb)
    Hands every part to the game to draw in one render type, from a renderer's submit.
    int
     

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • EMPTY

      public static final ObjModel EMPTY
      A model with nothing in it: what a missing or broken file gives.
  • Method Details

    • parts

      public List<ObjModel.Part> parts()
      The model's parts, in the file's order.
    • part

      public ObjModel.Part part(String name)
      The first part of this name (an o or g line's), or null.
    • isEmpty

      public boolean isEmpty()
    • triangles

      public int triangles()
    • min

      public org.joml.Vector3f min()
      The least corner of the box the model fills.
    • max

      public org.joml.Vector3f max()
      The greatest corner of the box the model fills.
    • submit

      public void submit(com.mojang.blaze3d.vertex.PoseStack pose, net.minecraft.client.renderer.SubmitNodeCollector collector, net.minecraft.client.renderer.rendertype.RenderType type, int light)
      Every part, white, with no overlay.
    • submit

      public void submit(com.mojang.blaze3d.vertex.PoseStack pose, net.minecraft.client.renderer.SubmitNodeCollector collector, net.minecraft.client.renderer.rendertype.RenderType type, int light, int overlay, int argb)
      Hands every part to the game to draw in one render type, from a renderer's submit.
      Parameters:
      light - packed light, as renderers are given it (0xF000F0 for a thing that glows)
      overlay - packed overlay (OverlayTexture.NO_OVERLAY)
      argb - a tint, 0xAARRGGBB; alpha only shows in a translucent render type
    • render

      public void render(com.mojang.blaze3d.vertex.PoseStack.Pose pose, com.mojang.blaze3d.vertex.VertexConsumer consumer, int light, int overlay, int argb)
      Writes every part into a vertex consumer.
    • parse

      public static ObjModel parse(String text)
      Reads a model from the text of an .obj file.
    • parse

      public static ObjModel parse(Reader reader) throws IOException
      Reads a model from an .obj file.
      Throws:
      IllegalArgumentException - if a line that is read cannot be understood (the message names the line)
      IOException