Class BakedPipeline

java.lang.Object
codechicken.lib.model.pipeline.BakedPipeline
All Implemented Interfaces:
IVertexConsumer

public class BakedPipeline extends Object implements IVertexConsumer
The BakedPipeline! Basically this allows us to efficiently transform a BakedQuad, the Pipeline has Elements, each element has a name, state and a transformer, you can enable and disable elements easily, you can also grab the underlying transformer for the element if you need to set its state before rendering.

The BakedPipeline is final once created, you cannot add or remove elements, you should not need to add or remove them runtime, enable and disable exist.

You must use the Builder class to construct a BakedPipeline, see builder()

Transformers run on a mutable state inside each transformer, allowing for easy reuse. It is recommended to store your pipeline inside a ThreadLocal because 'minecraft'.

Each Transformer should be smart enough to expand itself for each newly sized VertexFormat it comes across, meaning that the internal states for the transformers can be safely shared across VertexFormats, this reduces array creations, and generally makes the system as efficient as it is.

To use the system: Grab any elements you need to set state data on first, using getElement(String, Class) transformers should NOT clear their state on pipeline Reset's so set any global data on elements now. Assuming you are looping over a set of quads to transform, next you need to reset(com.mojang.blaze3d.vertex.VertexFormat) the pipeline, Now you should disable / enable any optional elements that are needed, NOTE: Element states are reset when resetting the pipeline. Now you will need to call prepare(IVertexConsumer) on the pipeline, here you will pass your collector, usually Quad. Now final step, simply pipe the quad you want to transform INTO the pipeline 'quad.pipe(pipeline)' And that's it! hell, Pipe a pipeline into each other for all i care, the system is efficient enough that there would be no performance penalty for doing so.

  • Method Details

    • builder

      public static BakedPipeline.Builder builder()
      Used to create a BakedPipeline.
      Returns:
      The builder.
    • reset

      public void reset(com.mojang.blaze3d.vertex.VertexFormat format)
      Used to reset the pipeline for the next quad. MUST be called between quads.
      Parameters:
      format - The format.
    • reset

      public void reset(CachedFormat format)
      Used to reset the pipeline for the next quad. MUST be called between quads.
      Parameters:
      format - The format.
    • getElement

      public <T extends IPipelineConsumer> T getElement(String name, Class<T> clazz)
      Get an element from the pipeline.
      Parameters:
      name - The name of the element.
      clazz - The Class of the element, used to safe cast.
      Returns:
      The element.
    • enableElement

      public void enableElement(String name)
      Used to enable an element on the pipeline with the specified name.
      Parameters:
      name - The elements name.
    • disableElement

      public void disableElement(String name)
      Used to disable an element on the pipeline with the specified name.
      Parameters:
      name - The elements name.
    • setElementState

      public void setElementState(String name, boolean enabled)
      Used to set the state of an element on the pipeline.
      Parameters:
      name - The name of the element.
      enabled - The state to set it to.
    • prepare

      public void prepare(IVertexConsumer collector)
      Call when you are ready to use the pipeline. This builds the internal state of the Elements getting things ready to transform.
      Parameters:
      collector - The IVertexConsumer that should collect the transformed quad.
    • getVertexFormat

      public com.mojang.blaze3d.vertex.VertexFormat getVertexFormat()
      Specified by:
      getVertexFormat in interface IVertexConsumer
    • setQuadTint

      public void setQuadTint(int tint)
      Specified by:
      setQuadTint in interface IVertexConsumer
    • setQuadOrientation

      public void setQuadOrientation(net.minecraft.core.Direction orientation)
      Specified by:
      setQuadOrientation in interface IVertexConsumer
    • setApplyDiffuseLighting

      public void setApplyDiffuseLighting(boolean diffuse)
      Specified by:
      setApplyDiffuseLighting in interface IVertexConsumer
    • setTexture

      public void setTexture(net.minecraft.client.renderer.texture.TextureAtlasSprite texture)
      Specified by:
      setTexture in interface IVertexConsumer
    • put

      public void put(int element, float... data)
      Specified by:
      put in interface IVertexConsumer
    • put

      public void put(Quad quad)
      Description copied from interface: IVertexConsumer
      Assumes the data is already completely unpacked. You must always copy the data from the quad provided to an internal cache. basically: this.quad.put(quad);
      Specified by:
      put in interface IVertexConsumer
      Parameters:
      quad - The quad to copy data from.