Last active
September 16, 2025 18:26
-
-
Save lowercasebtw/756824ce177951e6db014c6379ec9056 to your computer and use it in GitHub Desktop.
DynamicTransformsBuilder Util Class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.mojang.blaze3d.buffers.GpuBufferSlice; | |
| import com.mojang.blaze3d.systems.RenderSystem; | |
| import org.joml.Matrix4f; | |
| import org.joml.Vector3f; | |
| import org.joml.Vector4f; | |
| import java.util.Optional; | |
| public class DynamicTransformsBuilder { | |
| private Optional<Matrix4f> modelViewMatrix = Optional.empty(); | |
| private Optional<Vector4f> colorModulator = Optional.empty(); | |
| private Optional<Vector3f> modelOffset = Optional.empty(); | |
| private Optional<Matrix4f> textureMatrix = Optional.empty(); | |
| private Optional<Float> lineWidth = Optional.empty(); | |
| public static DynamicTransformsBuilder of() { | |
| return new DynamicTransformsBuilder(); | |
| } | |
| public DynamicTransformsBuilder withModelViewMatrix(Matrix4f matrix4f) { | |
| this.modelViewMatrix = Optional.of(matrix4f); | |
| return this; | |
| } | |
| public DynamicTransformsBuilder withShaderColor(Vector4f vector4f) { | |
| this.colorModulator = Optional.of(vector4f); | |
| return this; | |
| } | |
| public DynamicTransformsBuilder withShaderColor(Vector3f vector3f) { | |
| return this.withShaderColor(new Vector4f(vector3f, 1.0F)); | |
| } | |
| public DynamicTransformsBuilder withModelOffset(Vector3f vector3f) { | |
| this.modelOffset = Optional.of(vector3f); | |
| return this; | |
| } | |
| public DynamicTransformsBuilder withTextureMatrix(Matrix4f matrix4f) { | |
| this.textureMatrix = Optional.of(matrix4f); | |
| return this; | |
| } | |
| public DynamicTransformsBuilder withLineWidth(float lineWidth) { | |
| this.lineWidth = Optional.of(lineWidth); | |
| return this; | |
| } | |
| public GpuBufferSlice build() { | |
| return RenderSystem.getDynamicUniforms().writeTransform( | |
| this.modelViewMatrix.orElse(RenderSystem.getModelViewMatrix()), | |
| this.colorModulator.orElse(new Vector4f(1.0F, 1.0F, 1.0F, 1.0F)), | |
| this.modelOffset.orElse(new Vector3f()), | |
| this.textureMatrix.orElse(RenderSystem.getTextureMatrix()), | |
| this.lineWidth.orElse(RenderUtils.getLineWidth(RenderSystem.getShaderLineWidth())) | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment