From aa8dec58e85f4ebcd022b45f371aa327cd9f5d76 Mon Sep 17 00:00:00 2001 From: alpha Date: Thu, 14 Nov 2024 00:01:29 -0600 Subject: [PATCH] Fix quad transform stuff --- .../porting_lib/models/ElementsModel.java | 4 ++-- .../models/UnbakedGeometryHelper.java | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/modules/model_loader/src/main/java/io/github/fabricators_of_create/porting_lib/models/ElementsModel.java b/modules/model_loader/src/main/java/io/github/fabricators_of_create/porting_lib/models/ElementsModel.java index 87d30bc7..04d58a5e 100644 --- a/modules/model_loader/src/main/java/io/github/fabricators_of_create/porting_lib/models/ElementsModel.java +++ b/modules/model_loader/src/main/java/io/github/fabricators_of_create/porting_lib/models/ElementsModel.java @@ -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); @@ -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); diff --git a/modules/model_loader/src/main/java/io/github/fabricators_of_create/porting_lib/models/UnbakedGeometryHelper.java b/modules/model_loader/src/main/java/io/github/fabricators_of_create/porting_lib/models/UnbakedGeometryHelper.java index 9a151e9a..3d20341e 100644 --- a/modules/model_loader/src/main/java/io/github/fabricators_of_create/porting_lib/models/UnbakedGeometryHelper.java +++ b/modules/model_loader/src/main/java/io/github/fabricators_of_create/porting_lib/models/UnbakedGeometryHelper.java @@ -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 @@ -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