Skip to content

Commit

Permalink
A lot of refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Decencies committed Dec 28, 2024
1 parent 78f7f3a commit 78689d4
Show file tree
Hide file tree
Showing 86 changed files with 84 additions and 3,527 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import dev.vexor.radium.frapi.api.renderer.v1.material.MaterialFinder;
import dev.vexor.radium.frapi.api.renderer.v1.material.RenderMaterial;
import dev.vexor.radium.frapi.api.renderer.v1.mesh.MutableMesh;
import dev.vexor.radium.frapi.impl.renderer.RendererManager;

/**
Expand Down Expand Up @@ -50,15 +49,6 @@ static void register(Renderer renderer) {
RendererManager.registerRenderer(renderer);
}

/**
* Obtain a new {@link MutableMesh} instance to build optimized meshes and create baked models
* with enhanced features.
*
* <p>Renderer does not retain a reference to returned instances, so they should be re-used
* when possible to avoid memory allocation overhead.
*/
MutableMesh mutableMesh();

/**
* Obtain a new {@link MaterialFinder} instance to retrieve standard {@link RenderMaterial}
* instances.
Expand All @@ -68,12 +58,6 @@ static void register(Renderer renderer) {
*/
MaterialFinder materialFinder();

/**
* Return a material previously registered via {@link #registerMaterial(Identifier, RenderMaterial)}.
* Will return null if no material was found matching the given identifier.
*/
@Nullable
RenderMaterial materialById(Identifier id);

/**
* Register a material for re-use by other mods or models within a mod.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,4 @@ public enum BlendMode {
BlendMode(@Nullable RenderLayer blockRenderLayer) {
this.blockRenderLayer = blockRenderLayer;
}

public static BlendMode fromRenderLayer(@Nullable RenderLayer renderLayer) {
if (renderLayer == RenderLayer.SOLID) {
return SOLID;
} else if (renderLayer == RenderLayer.CUTOUT_MIPPED) {
return CUTOUT_MIPPED;
} else if (renderLayer == RenderLayer.CUTOUT) {
return CUTOUT;
} else if (renderLayer == RenderLayer.TRANSLUCENT) {
return TRANSLUCENT;
} else {
return DEFAULT;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ public interface MaterialFinder extends MaterialView {
*/
MaterialFinder shadeMode(ShadeMode mode);

/**
* Copies all properties from the given {@link MaterialView} to this material finder.
*/
MaterialFinder copyFrom(MaterialView material);

/**
* Resets this instance to default values. Values will match those in effect when an instance is newly obtained via
* {@link Renderer#materialFinder()}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,49 +19,6 @@
import net.minecraft.block.Block;
import net.minecraft.util.Identifier;

import dev.vexor.radium.frapi.api.renderer.v1.Renderer;
import dev.vexor.radium.frapi.api.renderer.v1.mesh.MutableMesh;
import dev.vexor.radium.frapi.api.renderer.v1.mesh.MutableQuadView;

/**
* All model quads have an associated render material governing
* how the quad will be rendered.
*
* <p>A material instance is always immutable and thread-safe. References to a material
* remain valid until the end of the current game session.
*
* <p>Materials can be registered and shared between mods using {@link Renderer#registerMaterial(Identifier, RenderMaterial)}.
* The registering mod is responsible for creating each registered material at startup.
*
* <p>Materials are not required to know their registration identity, and two materials
* with the same attributes may or may not satisfy equality and identity tests. Model
* implementations should never attempt to analyze materials or implement control logic based on them.
* They are only tokens for communicating quad attributes to the ModelRenderer.
*
* <p>There are three classes of materials...
*
* <p><b>STANDARD MATERIALS</b>
*
* <p>Standard materials have "normal" rendering with control over lighting,
* color, and texture blending. In the default renderer, "normal" rendering
* emulates unmodified Minecraft. Other renderers may offer a different aesthetic.
*
* <p>The number of standard materials is finite, but not necessarily small.
* To find a standard material, use {@link Renderer#materialFinder()}.
*
* <p>All renderer implementations should support standard materials.
*
* <p><b>SPECIAL MATERIALS</b>
*
* <p>Special materials are implemented directly by the Renderer implementation, typically
* with the aim of providing advanced/extended features. Such materials may offer additional
* vertex attributes via extensions to {@link MutableMesh} and {@link MutableQuadView}.
*
* <p>Special materials can be obtained using {@link Renderer#materialById(Identifier)}
* with a known identifier. Renderers may provide other means of access. Popular
* special materials could be implemented by multiple renderers, however there is
* no requirement that special materials be cross-compatible.
*/
public interface RenderMaterial extends MaterialView {
/**
* This will be identical to the material that would be obtained by calling {@link MaterialFinder#find()} on a new,
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,6 @@ default MutableQuadView normal(int vertexIndex, Vector3fc normal) {
*/
MutableQuadView tag(int tag);

/**
* Copies all quad properties from the given {@link QuadView} to this quad.
*
* <p>Calling this method does not emit the quad.
*/
MutableQuadView copyFrom(QuadView quad);

/**
* Enables bulk vertex data transfer using the standard Minecraft vertex formats.
* Only the {@link BakedQuad#getVertexData() quad vertex data} is copied.
Expand All @@ -292,12 +285,12 @@ default MutableQuadView normal(int vertexIndex, Vector3fc normal) {
* Enables bulk vertex data transfer using the standard Minecraft quad format.
*
* <p>The material applied to this quad view might be slightly different from the {@code material} parameter
* regarding diffuse shading. If either the baked quad {@link BakedQuad#hasShade() does not have shade} or the
* regarding diffuse shading. If either the baked quad {@link BakedQuad#hasColor() does not have shade} or the
* material {@link MaterialFinder#disableDiffuse(boolean) does not have shade}, diffuse shading will be disabled for
* this quad view. This is reflected in the quad view's {@link #material()}, but the {@code material} parameter is
* unchanged (it is immutable anyway).
*
* <p>The {@linkplain BakedQuad#getLightEmission() baked quad's light emission} will be applied to the lightmap
* <p>The {@linkplain BakedQuad#getColorIndex() baked quad's light emission} will be applied to the lightmap
* values from the vertex data after copying.
*
* <p>Calling this method does not emit the quad.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,6 @@ default QuadEmitter uv(int vertexIndex, Vector2fc uv) {
@Override
QuadEmitter spriteBake(Sprite sprite, int bakeFlags);

default QuadEmitter uvUnitSquare() {
uv(0, 0, 0);
uv(1, 0, 1);
uv(2, 1, 1);
uv(3, 1, 0);
return this;
}

@Override
QuadEmitter lightmap(int vertexIndex, int lightmap);

Expand Down Expand Up @@ -127,100 +119,12 @@ default QuadEmitter normal(int vertexIndex, Vector3fc normal) {
@Override
QuadEmitter tag(int tag);

QuadEmitter copyFrom(QuadView quad);

@Override
QuadEmitter fromVanilla(int[] quadData, int startIndex);

@Override
QuadEmitter fromVanilla(BakedQuad quad, RenderMaterial material, @Nullable Direction cullFace);

/**
* Tolerance for determining if the depth parameter to {@link #square(Direction, float, float, float, float, float)}
* is effectively zero - meaning the face is a cull face.
*/
float CULL_FACE_EPSILON = 0.00001f;

/**
* Helper method to assign vertex coordinates for a square aligned with the given face.
* Ensures that vertex order is consistent with vanilla convention. (Incorrect order can
* lead to bad AO lighting unless enhanced lighting logic is available/enabled.)
*
* <p>Square will be parallel to the given face and coplanar with the face (and culled if the
* face is occluded) if the depth parameter is approximately zero. See {@link #CULL_FACE_EPSILON}.
*
* <p>All coordinates should be normalized (0-1).
*/
default QuadEmitter square(Direction nominalFace, float left, float bottom, float right, float top, float depth) {
if (Math.abs(depth) < CULL_FACE_EPSILON) {
cullFace(nominalFace);
depth = 0; // avoid any inconsistency for face quads
} else {
cullFace(null);
}

nominalFace(nominalFace);
switch (nominalFace) {
case UP:
depth = 1 - depth;
top = 1 - top;
bottom = 1 - bottom;

case DOWN:
pos(0, left, depth, top);
pos(1, left, depth, bottom);
pos(2, right, depth, bottom);
pos(3, right, depth, top);
break;

case EAST:
depth = 1 - depth;
left = 1 - left;
right = 1 - right;

case WEST:
pos(0, depth, top, left);
pos(1, depth, bottom, left);
pos(2, depth, bottom, right);
pos(3, depth, top, right);
break;

case SOUTH:
depth = 1 - depth;
left = 1 - left;
right = 1 - right;

case NORTH:
pos(0, 1 - left, top, depth);
pos(1, 1 - left, bottom, depth);
pos(2, 1 - right, bottom, depth);
pos(3, 1 - right, top, depth);
break;
}

return this;
}

/**
* Pushed transforms will be applied immediately after every call to {@link #emit()} and before the quad data is
* delivered to its destination. If any transform returns {@code false}, the emitted quad will be discarded and will
* not be delivered to its destination.
*
* <p>You MUST call {@link #popTransform()} once you are done using this emitter in the current scope.
*
* <p>More than one transformer can be pushed. Transformers are applied in reverse order. (Last pushed is applied
* first.)
*
* <p>Using {@code this} emitter from inside the pushed quad transform is not supported.
*/
void pushTransform(QuadTransform transform);

/**
* Removes the transformer added by the last call to {@link #pushTransform(QuadTransform)}. MUST be called once you
* are done using this emitter in the current scope.
*/
void popTransform();

/**
* In static mesh building, causes quad to be appended to the mesh being built. In a dynamic render context, create
* a new quad to be output to rendering. In both cases, current instance is reset to default values.
Expand Down
Loading

0 comments on commit 78689d4

Please sign in to comment.