Skip to content

Commit

Permalink
Fix quad transform stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphaMode committed Nov 14, 2024
1 parent a0a842b commit aa8dec5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected void addQuads(IGeometryBakingContext context, IModelBuilder<?> modelBu
// If there is a root transform, undo the ModelState transform, apply it, then re-apply the ModelState transform.
// This is necessary because of things like UV locking, which should only respond to the ModelState, and as such
// that is the only transform that should be applied during face bake.
var postTransform = FabricQuadTransformers.empty();
var postTransform = QuadTransformers.empty();
var rootTransform = context.getRootTransform();
if (!rootTransform.isIdentity())
postTransform = UnbakedGeometryHelper.applyRootTransform(modelState, rootTransform);
Expand All @@ -49,7 +49,7 @@ protected void addQuads(IGeometryBakingContext context, IModelBuilder<?> modelBu
var face = element.faces.get(direction);
var sprite = spriteGetter.apply(context.getMaterial(face.texture()));
var quad = BlockModel.bakeFace(element, face, sprite, direction, modelState);
// postTransform.processInPlace(quad); TODO: PORT
postTransform.processInPlace(quad);

if (face.cullForDirection() == null)
modelBuilder.addUnculledFace(quad);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,22 @@ public static BakedQuad bakeElementFace(BlockElement element, BlockElementFace f
return FACE_BAKERY.bakeQuad(element.from, element.to, face, sprite, direction, state, element.rotation, element.shade);
}

/**
* Create an {@link IQuadTransformer} to apply a {@link Transformation} that undoes the {@link ModelState}
* transform (blockstate transform), applies the given root transform and then re-applies the
* blockstate transform.
*
* @return an {@code IQuadTransformer} that applies the root transform to a baked quad that already has the
* transformation of the given {@code ModelState} applied to it
*/
public static IQuadTransformer applyRootTransform(ModelState modelState, Transformation rootTransform) {
// Move the origin of the ModelState transform and its inverse from the negative corner to the block center
// to replicate the way the ModelState transform is applied in the FaceBakery by moving the vertices such that
// the negative corner acts as the block center
Transformation transform = modelState.getRotation().applyOrigin(new Vector3f(.5F, .5F, .5F));
return QuadTransformers.applying(transform.compose(rootTransform).compose(transform.inverse()));
}

/**
* Create an {@link RenderContext.QuadTransform} to apply a {@link Transformation} that undoes the {@link ModelState}
* transform (blockstate transform), applies the given root transform and then re-applies the
Expand All @@ -243,7 +259,7 @@ public static BakedQuad bakeElementFace(BlockElement element, BlockElementFace f
* @return an {@code IQuadTransformer} that applies the root transform to a baked quad that already has the
* transformation of the given {@code ModelState} applied to it
*/
public static RenderContext.QuadTransform applyRootTransform(ModelState modelState, Transformation rootTransform) {
public static RenderContext.QuadTransform applyFabricRootTransform(ModelState modelState, Transformation rootTransform) {
// Move the origin of the ModelState transform and its inverse from the negative corner to the block center
// to replicate the way the ModelState transform is applied in the FaceBakery by moving the vertices such that
// the negative corner acts as the block center
Expand Down

0 comments on commit aa8dec5

Please sign in to comment.