Class MutableQuad
BakedQuad.
This class can be used for constructing quads from scratch, or for loading and modifying existing quads.
It provides several utility methods that go beyond simply manipulating the attributes of the quad:
setCubeFaceFromSpriteCoords(Direction, float, float, float, float, float)generates the positions of a face by using a 2D coordinate system as if you were looking at the sprite textured on that face.setCubeFace(Direction, Vector3fc, Vector3fc)generates the positions of a 3D cube face by giving the cubes extent.bakeUvsFromPosition(UVTransform)generates the texture coordinates of the quad similar to how Vanilla block models do, with optional transformations.recalculateWinding()can reorder the vertices of the quad to match the vertex order expected by Vanilla ambient occlusion for axis-aligned quads.setSpriteInfoAndMoveUv(BakedQuad.SpriteInfo)can change the sprite used by a quad while remapping the atlas uv automatically.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final int[]private Directionprivate booleanprivate @Nullable BakedQuadThis is only used to reuse position vectors when possible.private intprivate final int[]private final Vector3f[]private booleanprivate @Nullable BakedQuad.SpriteInfoprivate intprivate final long[] -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionProjects each vertex onto the cube face the quad is sourcing its block lighting from, and derives the vertex UV that way.bakeUvsFromPosition(UVTransform transform) Same asbakeUvsFromPosition(), but applies a transform to the generated UVs before baking.intcolor(int vertexIndex) Returns the color of a given vertex in ARGB form.copy()Returns a copy of this mutable quad.copyInto(MutableQuad dest) Copies the contents of this mutable quad into the provided mutable quad and returns it.copyNormal(int vertexIndex) Same ascopyNormal(int, Vector3f), but constructs a new destination vector automatically.copyNormal(int vertexIndex, Vector3f dest) Copies the normal vector of a vertex into a given vector and returns it.copyPosition(int vertexIndex) Copies a vertex's position into a new vector and returns it.copyPosition(int vertexIndex, Vector3f dest) Copies a vertex's position into the given vector and returns it.copyUv(int vertexIndex) Same ascopyUv(int, Vector2f), but constructs a destination vector automatically.Copies the texture coordinates of a vertex into a given vector and returns it.booleanintfloatnormalComponent(int vertexIndex, int componentIndex) Returns a component of a vertex's normal or NaN if the normal is undefined.floatnormalX(int vertexIndex) Returns the x-component of a vertex's normal or NaN if the normal is undefined.floatnormalY(int vertexIndex) Returns the y-component of a vertex's normal or NaN if the normal is undefined.floatnormalZ(int vertexIndex) Returns the z-component of a vertex's normal or NaN if the normal is undefined.intpackedNormal(int vertexIndex) Returns a vertex normal in packed form.longpackedUv(int vertexIndex) Returns the texture coordinates in atlas-space for a vertex in packed form.floatpositionComponent(int vertexIndex, int componentIndex) Returns a component of a vertex's position.Recalculates the order of vertices to conform to the order expected by the Vanilla AO algorithm.recomputeNormals(boolean updateDirection) Recomputes the quad normal from the vertex positions.Same asspriteInfo(), but throws an exception if no sprite is set on the quad yet.reset()private static Vector3fcreuseVector(BakedQuad quad, Vector3f position) Tries to reuse the position vectors of the last quad we sourced any data from.setColor(int packedColor) Sets the color of all vertices to a packed ARGB color.setColor(int vertexIndex, int packedColor) Sets the color of a vertex to a packed ARGB color.setColor(int vertexIndex, int r, int g, int b, int a) Sets the color of a vertex from integer components (0-255).setColor(BakedColors bakedColors) Sets the color of all vertices to a packed ARGB color.setCubeFace(Direction side, float fromX, float fromY, float fromZ, float toX, float toY, float toZ) Sets the positions of this quad to the face of a cube as it would be defined in a Vanilla block model.setCubeFace(Direction side, Vector3fc from, Vector3fc to) Same assetCubeFace(Direction, float, float, float, float, float, float), but takes the from and to positions from vectors.setCubeFaceFromSpriteCoords(Direction side, float left, float bottom, float right, float top, float depth) Sets the positions of this quad to form a rectangle on the given block side using a coordinate-system matching the default orientation of sprites in Vanilla block-models.setDirection(Direction direction) setFullCubeFace(Direction side) Same assetCubeFace(Direction, float, float, float, float, float, float), but uses the full cube.setHasAmbientOcclusion(boolean hasAmbientOcclusion) setLightEmission(int lightEmission) setNormal(int vertexIndex, float x, float y, float z) Sets the normal vector of a vertex.Sets the normal vector of a vertex.setNormal(BakedNormals bakedNormals) Sets the normal vector of all vertices to the normal vectors encoded in the given baked normals object.setNormalComponent(int vertexIndex, int componentIndex, float value) Sets a component of a vertex's normal.setPackedNormal(int vertexIndex, int packedNormal) Sets the normal vector of a vertex from its packed representation.setPackedUv(int vertexIndex, long packedUv) Sets the texture coordinate of a vertex from their packed representation.setPosition(int vertexIndex, float x, float y, float z) Sets a vertex's position.setPosition(int vertexIndex, Vector3fc position) Sets a vertex's position.setPositionComponent(int vertexIndex, int componentIndex, float value) Sets a component of a vertex's position.setShade(boolean shade) setSpriteInfo(BakedQuad.SpriteInfo spriteInfo) Changes the texture atlas sprite used by this quad.setSpriteInfoAndMoveUv(BakedQuad.SpriteInfo spriteInfo) Changes the sprite and remaps the UV to the new sprites position in the texture atlas.setTintIndex(int tintIndex) setUv(int vertexIndex, float u, float v) Sets the texture coordinate of a vertex.Sets the texture coordinate of a vertex.setUvComponent(int vertexIndex, int componentIndex, float value) Sets a component of the texture coordinate of a vertex.setUvFromSprite(int vertexIndex, float u, float v) Assigns UV coordinates to a vertex of the current quad based on its sprite and the given UV coordinates within that sprite.setUvFromSprite(int vertexIndex, Vector2fc uv) Assigns UV coordinates to a vertex of the current quad based on its sprite and the given UV coordinates within that sprite.setX(int vertexIndex, float x) Sets the x-component of a vertex's position.setY(int vertexIndex, float y) Sets the y-component of a vertex's position.setZ(int vertexIndex, float z) Sets the x-component of a vertex's position.booleanshade()@Nullable BakedQuad.SpriteInfoReturns the sprite associated with the quad or null if no sprite has been set yet.intApplies the given matrix to this quads position and normals (if specified).private voidAssumes that the UV coordinates are in atlas-space and transforms them to sprite-space.private voidAssumes that the UV coordinates are in sprite-space and transforms them to atlas-space.floatu(int vertexIndex) Returns the horizontal texture coordinate in atlas-space for a vertex.floatuvComponent(int vertexIndex, int componentIndex) Returns the a texture coordinate in atlas-space for a vertex.floatv(int vertexIndex) Returns the vertical texture coordinate in atlas-space for a vertex.floatx(int vertexIndex) Returns the x-component of a vertex's position.floaty(int vertexIndex) Returns the y-component of a vertex's position.floatz(int vertexIndex) Returns the z-component of a vertex's position.
-
Field Details
-
positions
-
uvs
private final long[] uvs -
normals
private final int[] normals -
colors
private final int[] colors -
tintIndex
private int tintIndex -
direction
-
spriteInfo
-
shade
private boolean shade -
lightEmission
private int lightEmission -
hasAmbientOcclusion
private boolean hasAmbientOcclusion -
lastSourceQuad
This is only used to reuse position vectors when possible.
-
-
Constructor Details
-
MutableQuad
public MutableQuad()
-
-
Method Details
-
x
@Contract(pure=true) public float x(int vertexIndex) Returns the x-component of a vertex's position.- Returns:
- the x-component of a vertex's position
-
y
@Contract(pure=true) public float y(int vertexIndex) Returns the y-component of a vertex's position.- Returns:
- the y-component of a vertex's position
-
z
@Contract(pure=true) public float z(int vertexIndex) Returns the z-component of a vertex's position.- Returns:
- the z-component of a vertex's position
-
positionComponent
@Contract(pure=true) public float positionComponent(int vertexIndex, int componentIndex) Returns a component of a vertex's position.- Returns:
- a component of a vertex's position
- See Also:
-
copyPosition
Copies a vertex's position into a new vector and returns it. -
copyPosition
-
setX
Sets the x-component of a vertex's position. -
setY
Sets the y-component of a vertex's position. -
setZ
Sets the x-component of a vertex's position. -
setPositionComponent
Sets a component of a vertex's position.- See Also:
-
setPosition
Sets a vertex's position. -
setPosition
Sets a vertex's position. -
setCubeFaceFromSpriteCoords
public MutableQuad setCubeFaceFromSpriteCoords(Direction side, float left, float bottom, float right, float top, float depth) Sets the positions of this quad to form a rectangle on the given block side using a coordinate-system matching the default orientation of sprites in Vanilla block-models.Inspired by the Fabric Renderer API method
square.The left, bottom, right and top parameters correspond to the default sprite orientation in Vanilla block models. For
Direction.UPthe "up" direction is facingDirection.NORTH, while forDirection.DOWN, it facesDirection.SOUTH.All coordinates use a normalized [0,1] range.
Passing left=0, bottom=0, right=1, top=1, depth=0 will produce a face on the blocks
side. -
setFullCubeFace
Same assetCubeFace(Direction, float, float, float, float, float, float), but uses the full cube. -
setCubeFace
Same assetCubeFace(Direction, float, float, float, float, float, float), but takes the from and to positions from vectors. -
setCubeFace
public MutableQuad setCubeFace(Direction side, float fromX, float fromY, float fromZ, float toX, float toY, float toZ) Sets the positions of this quad to the face of a cube as it would be defined in a Vanilla block model.All coordinates use a normalized [0,1] range.
-
u
@Contract(pure=true) public float u(int vertexIndex) Returns the horizontal texture coordinate in atlas-space for a vertex.- Returns:
- the horizontal texture coordinate in atlas-space for a vertex
-
v
@Contract(pure=true) public float v(int vertexIndex) Returns the vertical texture coordinate in atlas-space for a vertex.- Returns:
- the vertical texture coordinate in atlas-space for a vertex
-
uvComponent
@Contract(pure=true) public float uvComponent(int vertexIndex, int componentIndex) Returns the a texture coordinate in atlas-space for a vertex.- Returns:
- the a texture coordinate in atlas-space for a vertex
-
packedUv
@Contract(pure=true) public long packedUv(int vertexIndex) Returns the texture coordinates in atlas-space for a vertex in packed form.- Returns:
- the texture coordinates in atlas-space for a vertex in packed form
- See Also:
-
copyUv
Same ascopyUv(int, Vector2f), but constructs a destination vector automatically. -
copyUv
-
setUv
Sets the texture coordinate of a vertex.Note that this method expects texture coordinates in the coordinate space of the atlas, not the sprite.
- See Also:
-
setUv
Sets the texture coordinate of a vertex.Note that this method expects texture coordinates in the coordinate space of the atlas, not the sprite.
- See Also:
-
setUvComponent
Sets a component of the texture coordinate of a vertex.Note that this method expects texture coordinates in the coordinate space of the atlas, not the sprite.
- See Also:
-
setPackedUv
Sets the texture coordinate of a vertex from their packed representation.Note that this method expects texture coordinates in the coordinate space of the atlas, not the sprite.
- See Also:
-
setUvFromSprite
Assigns UV coordinates to a vertex of the current quad based on its sprite and the given UV coordinates within that sprite. -
setUvFromSprite
Assigns UV coordinates to a vertex of the current quad based on its sprite and the given UV coordinates within that sprite. -
bakeUvsFromPosition
Projects each vertex onto the cube face the quad is sourcing its block lighting from, and derives the vertex UV that way.Requires
spriteInfo()to be set. -
bakeUvsFromPosition
Same asbakeUvsFromPosition(), but applies a transform to the generated UVs before baking. -
tintIndex
@Contract(pure=true) public int tintIndex() -
setTintIndex
-
direction
-
setDirection
-
spriteInfo
Returns the sprite associated with the quad or null if no sprite has been set yet.Note that
BakedQuadmust have an associated sprite.- Returns:
- the sprite associated with the quad or null if no sprite has been set yet
-
requiredSpriteInfo
Same asspriteInfo(), but throws an exception if no sprite is set on the quad yet.- Throws:
IllegalStateException- If no sprite is set yet.
-
setSpriteInfo
Changes the texture atlas sprite used by this quad.Note that changing the sprite does not automatically translate the current UV coordinates within the atlas to be within this new sprite. Use
setSpriteInfoAndMoveUv(BakedQuad.SpriteInfo)to change sprites and remap them,bakeUvsFromPosition()to generate texture coordinates from scratch, or set them manually. -
setSpriteInfoAndMoveUv
Changes the sprite and remaps the UV to the new sprites position in the texture atlas.- Throws:
IllegalStateException- If no sprite is currently set. There would be nothing to remap from.
-
shade
@Contract(pure=true) public boolean shade() -
setShade
-
lightEmission
@Contract(pure=true) public int lightEmission() -
setLightEmission
-
normalX
@Contract(pure=true) public float normalX(int vertexIndex) Returns the x-component of a vertex's normal or NaN if the normal is undefined.- Returns:
- the x-component of a vertex's normal or NaN if the normal is undefined
-
normalY
@Contract(pure=true) public float normalY(int vertexIndex) Returns the y-component of a vertex's normal or NaN if the normal is undefined.- Returns:
- the y-component of a vertex's normal or NaN if the normal is undefined
-
normalZ
@Contract(pure=true) public float normalZ(int vertexIndex) Returns the z-component of a vertex's normal or NaN if the normal is undefined.- Returns:
- the z-component of a vertex's normal or NaN if the normal is undefined
-
normalComponent
@Contract(pure=true) public float normalComponent(int vertexIndex, int componentIndex) Returns a component of a vertex's normal or NaN if the normal is undefined.- Returns:
- a component of a vertex's normal or NaN if the normal is undefined
- See Also:
-
packedNormal
@Contract(pure=true) public int packedNormal(int vertexIndex) Returns a vertex normal in packed form.- Returns:
- a vertex normal in packed form
- See Also:
-
copyNormal
Same ascopyNormal(int, Vector3f), but constructs a new destination vector automatically. -
copyNormal
-
setNormal
Sets the normal vector of a vertex. -
setNormal
Sets the normal vector of a vertex. -
setNormalComponent
Sets a component of a vertex's normal.If a normal was unspecified before this method was called, its other components will be set to 0.
- See Also:
-
setPackedNormal
Sets the normal vector of a vertex from its packed representation.- See Also:
-
setNormal
Sets the normal vector of all vertices to the normal vectors encoded in the given baked normals object. -
recomputeNormals
Recomputes the quad normal from the vertex positions.Assumes that the quad is planar.
-
color
@Contract(pure=true) public int color(int vertexIndex) Returns the color of a given vertex in ARGB form.- Returns:
- the color of a given vertex in ARGB form
- See Also:
-
setColor
Sets the color of all vertices to a packed ARGB color.- See Also:
-
setColor
Sets the color of a vertex to a packed ARGB color.- See Also:
-
setColor
Sets the color of a vertex from integer components (0-255).- See Also:
-
setColor
Sets the color of all vertices to a packed ARGB color. -
hasAmbientOcclusion
@Contract(pure=true) public boolean hasAmbientOcclusion() -
setHasAmbientOcclusion
-
setFrom
-
transformUvsFromSpriteToAtlas
private void transformUvsFromSpriteToAtlas()Assumes that the UV coordinates are in sprite-space and transforms them to atlas-space. -
transformUvsFromAtlasToSprite
private void transformUvsFromAtlasToSprite()Assumes that the UV coordinates are in atlas-space and transforms them to sprite-space. -
toBakedQuad
-
reuseVector
-
transform
Applies the given matrix to this quads position and normals (if specified).Note that the direction() is not transformed.
-
recalculateWinding
Recalculates the order of vertices to conform to the order expected by the Vanilla AO algorithm.It uses the current direction and only works correctly for axis-aligned quads.
- See Also:
-
copy
-
copyInto
Copies the contents of this mutable quad into the provided mutable quad and returns it. -
reset
-