diff --git a/common/src/api/java/dev/engine_room/flywheel/api/internal/FlwApiLink.java b/common/src/api/java/dev/engine_room/flywheel/api/internal/FlwApiLink.java index a6378aada..2fe8537cc 100644 --- a/common/src/api/java/dev/engine_room/flywheel/api/internal/FlwApiLink.java +++ b/common/src/api/java/dev/engine_room/flywheel/api/internal/FlwApiLink.java @@ -2,13 +2,10 @@ import org.jetbrains.annotations.Nullable; -import com.mojang.blaze3d.vertex.VertexFormat; - import dev.engine_room.flywheel.api.backend.Backend; import dev.engine_room.flywheel.api.layout.LayoutBuilder; import dev.engine_room.flywheel.api.registry.IdRegistry; import dev.engine_room.flywheel.api.registry.Registry; -import dev.engine_room.flywheel.api.vertex.VertexViewProvider; import dev.engine_room.flywheel.api.visualization.BlockEntityVisualizer; import dev.engine_room.flywheel.api.visualization.EntityVisualizer; import dev.engine_room.flywheel.api.visualization.VisualizationManager; @@ -35,10 +32,6 @@ public interface FlwApiLink { LayoutBuilder createLayoutBuilder(); - VertexViewProvider getVertexViewProvider(VertexFormat format); - - void setVertexViewProvider(VertexFormat format, VertexViewProvider provider); - boolean supportsVisualization(@Nullable LevelAccessor level); @Nullable diff --git a/common/src/api/java/dev/engine_room/flywheel/api/vertex/VertexViewProvider.java b/common/src/api/java/dev/engine_room/flywheel/api/vertex/VertexViewProvider.java deleted file mode 100644 index 333643d33..000000000 --- a/common/src/api/java/dev/engine_room/flywheel/api/vertex/VertexViewProvider.java +++ /dev/null @@ -1,5 +0,0 @@ -package dev.engine_room.flywheel.api.vertex; - -public interface VertexViewProvider { - VertexView createVertexView(); -} diff --git a/common/src/api/java/dev/engine_room/flywheel/api/vertex/VertexViewProviderRegistry.java b/common/src/api/java/dev/engine_room/flywheel/api/vertex/VertexViewProviderRegistry.java deleted file mode 100644 index 558fd32a1..000000000 --- a/common/src/api/java/dev/engine_room/flywheel/api/vertex/VertexViewProviderRegistry.java +++ /dev/null @@ -1,18 +0,0 @@ -package dev.engine_room.flywheel.api.vertex; - -import com.mojang.blaze3d.vertex.VertexFormat; - -import dev.engine_room.flywheel.api.internal.FlwApiLink; - -public final class VertexViewProviderRegistry { - private VertexViewProviderRegistry() { - } - - public static VertexViewProvider getProvider(VertexFormat format) { - return FlwApiLink.INSTANCE.getVertexViewProvider(format); - } - - public static void setProvider(VertexFormat format, VertexViewProvider provider) { - FlwApiLink.INSTANCE.setVertexViewProvider(format, provider); - } -} diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/model/ModelUtil.java b/common/src/lib/java/dev/engine_room/flywheel/lib/model/ModelUtil.java index e249284cb..0f9816e7f 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/model/ModelUtil.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/model/ModelUtil.java @@ -1,23 +1,15 @@ package dev.engine_room.flywheel.lib.model; -import java.nio.ByteBuffer; import java.util.Collection; import org.jetbrains.annotations.Nullable; import org.joml.Vector3f; import org.joml.Vector4f; -import org.lwjgl.system.MemoryUtil; - -import com.mojang.blaze3d.vertex.BufferBuilder; -import com.mojang.blaze3d.vertex.BufferBuilder.DrawState; -import com.mojang.blaze3d.vertex.VertexFormat; import dev.engine_room.flywheel.api.material.Material; import dev.engine_room.flywheel.api.model.Mesh; import dev.engine_room.flywheel.api.model.Model; import dev.engine_room.flywheel.api.vertex.VertexList; -import dev.engine_room.flywheel.api.vertex.VertexView; -import dev.engine_room.flywheel.api.vertex.VertexViewProviderRegistry; import dev.engine_room.flywheel.lib.internal.FlwLibXplat; import dev.engine_room.flywheel.lib.material.Materials; import dev.engine_room.flywheel.lib.memory.MemoryBlock; @@ -36,27 +28,6 @@ public final class ModelUtil { private ModelUtil() { } - public static MemoryBlock convertVanillaBuffer(BufferBuilder.RenderedBuffer buffer, VertexView vertexView) { - DrawState drawState = buffer.drawState(); - int vertexCount = drawState.vertexCount(); - VertexFormat srcFormat = drawState.format(); - - ByteBuffer src = buffer.vertexBuffer(); - MemoryBlock dst = MemoryBlock.malloc((long) vertexCount * vertexView.stride()); - long srcPtr = MemoryUtil.memAddress(src); - long dstPtr = dst.ptr(); - - VertexView srcView = VertexViewProviderRegistry.getProvider(srcFormat).createVertexView(); - srcView.ptr(srcPtr); - vertexView.ptr(dstPtr); - srcView.vertexCount(vertexCount); - vertexView.vertexCount(vertexCount); - - srcView.writeAll(vertexView); - - return dst; - } - @Nullable public static Material getMaterial(RenderType chunkRenderType, boolean shaded) { if (chunkRenderType == RenderType.solid()) { diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/model/baked/MeshHelper.java b/common/src/lib/java/dev/engine_room/flywheel/lib/model/baked/MeshHelper.java new file mode 100644 index 000000000..e6326600b --- /dev/null +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/model/baked/MeshHelper.java @@ -0,0 +1,47 @@ +package dev.engine_room.flywheel.lib.model.baked; + +import java.nio.ByteBuffer; + +import org.jetbrains.annotations.Nullable; +import org.lwjgl.system.MemoryUtil; + +import com.mojang.blaze3d.vertex.BufferBuilder; + +import dev.engine_room.flywheel.api.vertex.VertexView; +import dev.engine_room.flywheel.lib.memory.MemoryBlock; +import dev.engine_room.flywheel.lib.model.SimpleMesh; +import dev.engine_room.flywheel.lib.vertex.NoOverlayVertexView; + +final class MeshHelper { + private MeshHelper() { + } + + public static SimpleMesh blockVerticesToMesh(BufferBuilder.RenderedBuffer buffer, @Nullable String meshDescriptor) { + BufferBuilder.DrawState drawState = buffer.drawState(); + int vertexCount = drawState.vertexCount(); + long srcStride = drawState.format().getVertexSize(); + + VertexView vertexView = new NoOverlayVertexView(); + long dstStride = vertexView.stride(); + + ByteBuffer src = buffer.vertexBuffer(); + MemoryBlock dst = MemoryBlock.malloc((long) vertexCount * dstStride); + long srcPtr = MemoryUtil.memAddress(src); + long dstPtr = dst.ptr(); + // The first 31 bytes of each vertex in a block vertex buffer are guaranteed to contain the same data in the + // same order regardless of whether the format is extended by mods like Iris or OptiFine. Copy these bytes and + // ignore the rest. + long bytesToCopy = Math.min(dstStride, 31); + + for (int i = 0; i < vertexCount; i++) { + // It is safe to copy bytes directly since the NoOverlayVertexView uses the same memory layout as the first + // 31 bytes of the block vertex format, vanilla or otherwise. + MemoryUtil.memCopy(srcPtr + srcStride * i, dstPtr + dstStride * i, bytesToCopy); + } + + vertexView.ptr(dstPtr); + vertexView.vertexCount(vertexCount); + + return new SimpleMesh(vertexView, dst, meshDescriptor); + } +} diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/vertex/EmptyVertexList.java b/common/src/lib/java/dev/engine_room/flywheel/lib/vertex/EmptyVertexList.java index 8b8ee1625..171ad10e6 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/vertex/EmptyVertexList.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/vertex/EmptyVertexList.java @@ -11,12 +11,12 @@ default float x(int index) { } @Override - default float y(int index){ + default float y(int index) { return 0.0f; } @Override - default float z(int index){ + default float z(int index) { return 0.0f; } diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/visual/SimpleEntityVisual.java b/common/src/lib/java/dev/engine_room/flywheel/lib/visual/SimpleEntityVisual.java index 12b8fc8d7..0af57ec5b 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/visual/SimpleEntityVisual.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/visual/SimpleEntityVisual.java @@ -4,7 +4,6 @@ import java.util.List; import dev.engine_room.flywheel.api.visualization.VisualizationContext; - import net.minecraft.world.entity.Entity; public class SimpleEntityVisual extends AbstractEntityVisual implements SimpleDynamicVisual { diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/visual/SimpleEntityVisualizer.java b/common/src/lib/java/dev/engine_room/flywheel/lib/visual/SimpleEntityVisualizer.java index 828aeffcf..4e908cdce 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/visual/SimpleEntityVisualizer.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/visual/SimpleEntityVisualizer.java @@ -9,7 +9,6 @@ import dev.engine_room.flywheel.api.visualization.EntityVisualizer; import dev.engine_room.flywheel.api.visualization.VisualizationContext; import dev.engine_room.flywheel.api.visualization.VisualizerRegistry; - import net.minecraft.client.renderer.entity.EntityRenderer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/visual/VisualizationHelper.java b/common/src/lib/java/dev/engine_room/flywheel/lib/visual/VisualizationHelper.java index 03cba9b70..b76f3107c 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/visual/VisualizationHelper.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/visual/VisualizationHelper.java @@ -6,7 +6,6 @@ import dev.engine_room.flywheel.api.visualization.EntityVisualizer; import dev.engine_room.flywheel.api.visualization.VisualizationManager; import dev.engine_room.flywheel.api.visualization.VisualizerRegistry; - import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.level.Level; diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/FlwApiLinkImpl.java b/common/src/main/java/dev/engine_room/flywheel/impl/FlwApiLinkImpl.java index 203f8def5..c7e6e8899 100644 --- a/common/src/main/java/dev/engine_room/flywheel/impl/FlwApiLinkImpl.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/FlwApiLinkImpl.java @@ -2,21 +2,17 @@ import org.jetbrains.annotations.Nullable; -import com.mojang.blaze3d.vertex.VertexFormat; - import dev.engine_room.flywheel.api.backend.Backend; import dev.engine_room.flywheel.api.internal.FlwApiLink; import dev.engine_room.flywheel.api.layout.LayoutBuilder; import dev.engine_room.flywheel.api.registry.IdRegistry; import dev.engine_room.flywheel.api.registry.Registry; -import dev.engine_room.flywheel.api.vertex.VertexViewProvider; import dev.engine_room.flywheel.api.visualization.BlockEntityVisualizer; import dev.engine_room.flywheel.api.visualization.EntityVisualizer; import dev.engine_room.flywheel.api.visualization.VisualizationManager; import dev.engine_room.flywheel.impl.layout.LayoutBuilderImpl; import dev.engine_room.flywheel.impl.registry.IdRegistryImpl; import dev.engine_room.flywheel.impl.registry.RegistryImpl; -import dev.engine_room.flywheel.impl.vertex.VertexViewProviderRegistryImpl; import dev.engine_room.flywheel.impl.visualization.VisualizationManagerImpl; import dev.engine_room.flywheel.impl.visualization.VisualizerRegistryImpl; import net.minecraft.world.entity.Entity; @@ -61,16 +57,6 @@ public LayoutBuilder createLayoutBuilder() { return new LayoutBuilderImpl(); } - @Override - public VertexViewProvider getVertexViewProvider(VertexFormat format) { - return VertexViewProviderRegistryImpl.getProvider(format); - } - - @Override - public void setVertexViewProvider(VertexFormat format, VertexViewProvider provider) { - VertexViewProviderRegistryImpl.setProvider(format, provider); - } - @Override public boolean supportsVisualization(@Nullable LevelAccessor level) { return VisualizationManagerImpl.supportsVisualization(level); diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/event/RenderContextImpl.java b/common/src/main/java/dev/engine_room/flywheel/impl/event/RenderContextImpl.java index a35272771..a211307ea 100644 --- a/common/src/main/java/dev/engine_room/flywheel/impl/event/RenderContextImpl.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/event/RenderContextImpl.java @@ -2,9 +2,9 @@ import org.joml.Matrix4f; -import dev.engine_room.flywheel.api.event.RenderContext; import com.mojang.blaze3d.vertex.PoseStack; +import dev.engine_room.flywheel.api.event.RenderContext; import net.minecraft.client.Camera; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.renderer.LevelRenderer; diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/extension/BlockEntityTypeExtension.java b/common/src/main/java/dev/engine_room/flywheel/impl/extension/BlockEntityTypeExtension.java index 139789bfe..b15f29c7a 100644 --- a/common/src/main/java/dev/engine_room/flywheel/impl/extension/BlockEntityTypeExtension.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/extension/BlockEntityTypeExtension.java @@ -3,7 +3,6 @@ import org.jetbrains.annotations.Nullable; import dev.engine_room.flywheel.api.visualization.BlockEntityVisualizer; - import net.minecraft.world.level.block.entity.BlockEntity; public interface BlockEntityTypeExtension { diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/extension/EntityTypeExtension.java b/common/src/main/java/dev/engine_room/flywheel/impl/extension/EntityTypeExtension.java index dc8f27dc8..2b0f8927f 100644 --- a/common/src/main/java/dev/engine_room/flywheel/impl/extension/EntityTypeExtension.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/extension/EntityTypeExtension.java @@ -3,7 +3,6 @@ import org.jetbrains.annotations.Nullable; import dev.engine_room.flywheel.api.visualization.EntityVisualizer; - import net.minecraft.world.entity.Entity; public interface EntityTypeExtension { diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/extension/PoseStackExtension.java b/common/src/main/java/dev/engine_room/flywheel/impl/extension/PoseStackExtension.java index 7c63f38f1..a136522fd 100644 --- a/common/src/main/java/dev/engine_room/flywheel/impl/extension/PoseStackExtension.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/extension/PoseStackExtension.java @@ -1,8 +1,9 @@ package dev.engine_room.flywheel.impl.extension; -import dev.engine_room.flywheel.lib.transform.PoseTransformStack; import com.mojang.blaze3d.vertex.PoseStack; +import dev.engine_room.flywheel.lib.transform.PoseTransformStack; + /** * An extension interface for {@link PoseStack} that provides a {@link PoseTransformStack} wrapper. *
diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/extension/VertexFormatExtension.java b/common/src/main/java/dev/engine_room/flywheel/impl/extension/VertexFormatExtension.java deleted file mode 100644 index 3fa60e0c5..000000000 --- a/common/src/main/java/dev/engine_room/flywheel/impl/extension/VertexFormatExtension.java +++ /dev/null @@ -1,18 +0,0 @@ -package dev.engine_room.flywheel.impl.extension; - -import dev.engine_room.flywheel.api.vertex.VertexViewProvider; -import com.mojang.blaze3d.vertex.VertexFormat; - -/** - * Duck interface to make VertexFormat store a VertexListProvider. - * - * @see VertexFormat - */ -public interface VertexFormatExtension { - /** - * @return The VertexViewProvider associated with this VertexFormat. - */ - VertexViewProvider flywheel$getVertexViewProvider(); - - void flywheel$setVertexViewProvider(VertexViewProvider provider); -} diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/layout/LayoutBuilderImpl.java b/common/src/main/java/dev/engine_room/flywheel/impl/layout/LayoutBuilderImpl.java index a2f7c07cc..fbd2f8178 100644 --- a/common/src/main/java/dev/engine_room/flywheel/impl/layout/LayoutBuilderImpl.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/layout/LayoutBuilderImpl.java @@ -16,7 +16,6 @@ import dev.engine_room.flywheel.api.layout.ValueRepr; import dev.engine_room.flywheel.impl.layout.LayoutImpl.ElementImpl; import dev.engine_room.flywheel.lib.math.MoreMath; - import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/layout/LayoutImpl.java b/common/src/main/java/dev/engine_room/flywheel/impl/layout/LayoutImpl.java index cb86c5c25..447a6aab0 100644 --- a/common/src/main/java/dev/engine_room/flywheel/impl/layout/LayoutImpl.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/layout/LayoutImpl.java @@ -8,7 +8,6 @@ import dev.engine_room.flywheel.api.layout.ElementType; import dev.engine_room.flywheel.api.layout.Layout; - import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; final class LayoutImpl implements Layout { diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/mixin/BlockEntityTypeMixin.java b/common/src/main/java/dev/engine_room/flywheel/impl/mixin/BlockEntityTypeMixin.java index 7b7921233..93c660d8d 100644 --- a/common/src/main/java/dev/engine_room/flywheel/impl/mixin/BlockEntityTypeMixin.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/mixin/BlockEntityTypeMixin.java @@ -6,7 +6,6 @@ import dev.engine_room.flywheel.api.visualization.BlockEntityVisualizer; import dev.engine_room.flywheel.impl.extension.BlockEntityTypeExtension; - import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/mixin/VertexFormatMixin.java b/common/src/main/java/dev/engine_room/flywheel/impl/mixin/VertexFormatMixin.java deleted file mode 100644 index cd5ab7653..000000000 --- a/common/src/main/java/dev/engine_room/flywheel/impl/mixin/VertexFormatMixin.java +++ /dev/null @@ -1,25 +0,0 @@ -package dev.engine_room.flywheel.impl.mixin; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; - -import com.mojang.blaze3d.vertex.VertexFormat; - -import dev.engine_room.flywheel.api.vertex.VertexViewProvider; -import dev.engine_room.flywheel.impl.extension.VertexFormatExtension; - -@Mixin(VertexFormat.class) -abstract class VertexFormatMixin implements VertexFormatExtension { - @Unique - private VertexViewProvider flywheel$vertexViewProvider; - - @Override - public VertexViewProvider flywheel$getVertexViewProvider() { - return flywheel$vertexViewProvider; - } - - @Override - public void flywheel$setVertexViewProvider(VertexViewProvider provider) { - flywheel$vertexViewProvider = provider; - } -} diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/mixin/visualmanage/BlockEntityMixin.java b/common/src/main/java/dev/engine_room/flywheel/impl/mixin/visualmanage/BlockEntityMixin.java index b6d1ab508..0f0945629 100644 --- a/common/src/main/java/dev/engine_room/flywheel/impl/mixin/visualmanage/BlockEntityMixin.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/mixin/visualmanage/BlockEntityMixin.java @@ -8,7 +8,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import dev.engine_room.flywheel.api.visualization.VisualizationManager; - import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/mixin/visualmanage/LevelChunkMixin.java b/common/src/main/java/dev/engine_room/flywheel/impl/mixin/visualmanage/LevelChunkMixin.java index 0486fd366..8b4c297e6 100644 --- a/common/src/main/java/dev/engine_room/flywheel/impl/mixin/visualmanage/LevelChunkMixin.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/mixin/visualmanage/LevelChunkMixin.java @@ -8,7 +8,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import dev.engine_room.flywheel.api.visualization.VisualizationManager; - import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.chunk.LevelChunk; diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/mixin/visualmanage/LevelRendererMixin.java b/common/src/main/java/dev/engine_room/flywheel/impl/mixin/visualmanage/LevelRendererMixin.java index 675211b67..6ecbbc75f 100644 --- a/common/src/main/java/dev/engine_room/flywheel/impl/mixin/visualmanage/LevelRendererMixin.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/mixin/visualmanage/LevelRendererMixin.java @@ -7,7 +7,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import dev.engine_room.flywheel.api.visualization.VisualizationManager; - import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.renderer.LevelRenderer; import net.minecraft.core.BlockPos; diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/mixin/visualmanage/RebuildTaskMixin.java b/common/src/main/java/dev/engine_room/flywheel/impl/mixin/visualmanage/RebuildTaskMixin.java index 203bb40de..c55c532fa 100644 --- a/common/src/main/java/dev/engine_room/flywheel/impl/mixin/visualmanage/RebuildTaskMixin.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/mixin/visualmanage/RebuildTaskMixin.java @@ -7,7 +7,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import dev.engine_room.flywheel.lib.visual.VisualizationHelper; - import net.minecraft.world.level.block.entity.BlockEntity; @Mixin(targets = "net.minecraft.client.renderer.chunk.ChunkRenderDispatcher$RenderChunk$RebuildTask") diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/vertex/InferredVertexFormatInfo.java b/common/src/main/java/dev/engine_room/flywheel/impl/vertex/InferredVertexFormatInfo.java deleted file mode 100644 index 7990cc20c..000000000 --- a/common/src/main/java/dev/engine_room/flywheel/impl/vertex/InferredVertexFormatInfo.java +++ /dev/null @@ -1,53 +0,0 @@ -package dev.engine_room.flywheel.impl.vertex; - -import com.mojang.blaze3d.vertex.DefaultVertexFormat; -import com.mojang.blaze3d.vertex.VertexFormat; -import com.mojang.blaze3d.vertex.VertexFormatElement; - -public class InferredVertexFormatInfo { - public final VertexFormat format; - - public final int positionOffset; - public final int colorOffset; - public final int textureOffset; - public final int overlayOffset; - public final int lightOffset; - public final int normalOffset; - - public InferredVertexFormatInfo(VertexFormat format) { - this.format = format; - - int positionOffset = -1; - int colorOffset = -1; - int textureOffset = -1; - int overlayOffset = -1; - int lightOffset = -1; - int normalOffset = -1; - - int offset = 0; - for (VertexFormatElement element : format.getElements()) { - if (element == DefaultVertexFormat.ELEMENT_POSITION) { - positionOffset = offset; - } else if (element == DefaultVertexFormat.ELEMENT_COLOR) { - colorOffset = offset; - } else if (element == DefaultVertexFormat.ELEMENT_UV0) { - textureOffset = offset; - } else if (element == DefaultVertexFormat.ELEMENT_UV1) { - overlayOffset = offset; - } else if (element == DefaultVertexFormat.ELEMENT_UV2) { - lightOffset = offset; - } else if (element == DefaultVertexFormat.ELEMENT_NORMAL) { - normalOffset = offset; - } - - offset += element.getByteSize(); - } - - this.positionOffset = positionOffset; - this.colorOffset = colorOffset; - this.textureOffset = textureOffset; - this.overlayOffset = overlayOffset; - this.lightOffset = lightOffset; - this.normalOffset = normalOffset; - } -} diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/vertex/InferredVertexView.java b/common/src/main/java/dev/engine_room/flywheel/impl/vertex/InferredVertexView.java deleted file mode 100644 index 6503ba21f..000000000 --- a/common/src/main/java/dev/engine_room/flywheel/impl/vertex/InferredVertexView.java +++ /dev/null @@ -1,207 +0,0 @@ -package dev.engine_room.flywheel.impl.vertex; - -import org.lwjgl.system.MemoryUtil; - -import com.mojang.blaze3d.vertex.VertexFormat; - -import dev.engine_room.flywheel.api.vertex.VertexView; -import dev.engine_room.flywheel.lib.math.RenderMath; -import dev.engine_room.flywheel.lib.vertex.AbstractVertexView; -import net.minecraft.client.renderer.LightTexture; -import net.minecraft.client.renderer.texture.OverlayTexture; - -public class InferredVertexView extends AbstractVertexView implements VertexView { - protected final VertexFormat format; - protected final int stride; - - protected final int positionOffset; - protected final int colorOffset; - protected final int textureOffset; - protected final int overlayOffset; - protected final int lightOffset; - protected final int normalOffset; - - public InferredVertexView(InferredVertexFormatInfo formatInfo) { - format = formatInfo.format; - stride = format.getVertexSize(); - positionOffset = formatInfo.positionOffset; - colorOffset = formatInfo.colorOffset; - textureOffset = formatInfo.textureOffset; - overlayOffset = formatInfo.overlayOffset; - lightOffset = formatInfo.lightOffset; - normalOffset = formatInfo.normalOffset; - } - - @Override - public long stride() { - return stride; - } - - @Override - public float x(int index) { - if (positionOffset < 0) return 0; - return MemoryUtil.memGetFloat(ptr + index * stride + positionOffset); - } - - @Override - public float y(int index) { - if (positionOffset < 0) return 0; - return MemoryUtil.memGetFloat(ptr + index * stride + positionOffset + 4); - } - - @Override - public float z(int index) { - if (positionOffset < 0) return 0; - return MemoryUtil.memGetFloat(ptr + index * stride + positionOffset + 8); - } - - @Override - public float r(int index) { - if (colorOffset < 0) return 1; - return RenderMath.uf(MemoryUtil.memGetByte(ptr + index * stride + colorOffset)); - } - - @Override - public float g(int index) { - if (colorOffset < 0) return 1; - return RenderMath.uf(MemoryUtil.memGetByte(ptr + index * stride + colorOffset + 1)); - } - - @Override - public float b(int index) { - if (colorOffset < 0) return 1; - return RenderMath.uf(MemoryUtil.memGetByte(ptr + index * stride + colorOffset + 2)); - } - - @Override - public float a(int index) { - if (colorOffset < 0) return 1; - return RenderMath.uf(MemoryUtil.memGetByte(ptr + index * stride + colorOffset + 3)); - } - - @Override - public float u(int index) { - if (textureOffset < 0) return 0; - return MemoryUtil.memGetFloat(ptr + index * stride + textureOffset); - } - - @Override - public float v(int index) { - if (textureOffset < 0) return 0; - return MemoryUtil.memGetFloat(ptr + index * stride + textureOffset + 4); - } - - @Override - public int overlay(int index) { - if (overlayOffset < 0) return OverlayTexture.NO_OVERLAY; - return MemoryUtil.memGetInt(ptr + index * stride + overlayOffset); - } - - @Override - public int light(int index) { - if (lightOffset < 0) return LightTexture.FULL_BRIGHT; - return MemoryUtil.memGetInt(ptr + index * stride + lightOffset); - } - - @Override - public float normalX(int index) { - if (normalOffset < 0) return 0; - return RenderMath.f(MemoryUtil.memGetByte(ptr + index * stride + normalOffset)); - } - - @Override - public float normalY(int index) { - if (normalOffset < 0) return 0; - return RenderMath.f(MemoryUtil.memGetByte(ptr + index * stride + normalOffset + 1)); - } - - @Override - public float normalZ(int index) { - if (normalOffset < 0) return 0; - return RenderMath.f(MemoryUtil.memGetByte(ptr + index * stride + normalOffset + 2)); - } - - @Override - public void x(int index, float x) { - if (positionOffset < 0) return; - MemoryUtil.memPutFloat(ptr + index * stride + positionOffset, x); - } - - @Override - public void y(int index, float y) { - if (positionOffset < 0) return; - MemoryUtil.memPutFloat(ptr + index * stride + positionOffset + 4, y); - } - - @Override - public void z(int index, float z) { - if (positionOffset < 0) return; - MemoryUtil.memPutFloat(ptr + index * stride + positionOffset + 8, z); - } - - @Override - public void r(int index, float r) { - if (colorOffset < 0) return; - MemoryUtil.memPutByte(ptr + index * stride + colorOffset, RenderMath.unb(r)); - } - - @Override - public void g(int index, float g) { - if (colorOffset < 0) return; - MemoryUtil.memPutByte(ptr + index * stride + colorOffset + 1, RenderMath.unb(g)); - } - - @Override - public void b(int index, float b) { - if (colorOffset < 0) return; - MemoryUtil.memPutByte(ptr + index * stride + colorOffset + 2, RenderMath.unb(b)); - } - - @Override - public void a(int index, float a) { - if (colorOffset < 0) return; - MemoryUtil.memPutByte(ptr + index * stride + colorOffset + 3, RenderMath.unb(a)); - } - - @Override - public void u(int index, float u) { - if (textureOffset < 0) return; - MemoryUtil.memPutFloat(ptr + index * stride + textureOffset, u); - } - - @Override - public void v(int index, float v) { - if (textureOffset < 0) return; - MemoryUtil.memPutFloat(ptr + index * stride + textureOffset + 4, v); - } - - @Override - public void overlay(int index, int overlay) { - if (overlayOffset < 0) return; - MemoryUtil.memPutInt(ptr + index * stride + overlayOffset, overlay); - } - - @Override - public void light(int index, int light) { - if (lightOffset < 0) return; - MemoryUtil.memPutInt(ptr + index * stride + lightOffset, light); - } - - @Override - public void normalX(int index, float normalX) { - if (normalOffset < 0) return; - MemoryUtil.memPutByte(ptr + index * stride + normalOffset, RenderMath.nb(normalX)); - } - - @Override - public void normalY(int index, float normalY) { - if (normalOffset < 0) return; - MemoryUtil.memPutByte(ptr + index * stride + normalOffset + 1, RenderMath.nb(normalY)); - } - - @Override - public void normalZ(int index, float normalZ) { - if (normalOffset < 0) return; - MemoryUtil.memPutByte(ptr + index * stride + normalOffset + 2, RenderMath.nb(normalZ)); - } -} diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/vertex/InferredVertexViewProvider.java b/common/src/main/java/dev/engine_room/flywheel/impl/vertex/InferredVertexViewProvider.java deleted file mode 100644 index 9cf24cdde..000000000 --- a/common/src/main/java/dev/engine_room/flywheel/impl/vertex/InferredVertexViewProvider.java +++ /dev/null @@ -1,19 +0,0 @@ -package dev.engine_room.flywheel.impl.vertex; - -import com.mojang.blaze3d.vertex.VertexFormat; - -import dev.engine_room.flywheel.api.vertex.VertexView; -import dev.engine_room.flywheel.api.vertex.VertexViewProvider; - -public class InferredVertexViewProvider implements VertexViewProvider { - private final InferredVertexFormatInfo formatInfo; - - public InferredVertexViewProvider(VertexFormat format) { - formatInfo = new InferredVertexFormatInfo(format); - } - - @Override - public VertexView createVertexView() { - return new InferredVertexView(formatInfo); - } -} diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/vertex/VertexViewProviderRegistryImpl.java b/common/src/main/java/dev/engine_room/flywheel/impl/vertex/VertexViewProviderRegistryImpl.java deleted file mode 100644 index 451886018..000000000 --- a/common/src/main/java/dev/engine_room/flywheel/impl/vertex/VertexViewProviderRegistryImpl.java +++ /dev/null @@ -1,26 +0,0 @@ -package dev.engine_room.flywheel.impl.vertex; - -import com.mojang.blaze3d.vertex.VertexFormat; - -import dev.engine_room.flywheel.api.vertex.VertexViewProvider; -import dev.engine_room.flywheel.impl.extension.VertexFormatExtension; - -// TODO: Add freezing -public final class VertexViewProviderRegistryImpl { - private VertexViewProviderRegistryImpl() { - } - - public static VertexViewProvider getProvider(VertexFormat format) { - VertexFormatExtension extension = (VertexFormatExtension) format; - VertexViewProvider provider = extension.flywheel$getVertexViewProvider(); - if (provider == null) { - provider = new InferredVertexViewProvider(format); - extension.flywheel$setVertexViewProvider(provider); - } - return provider; - } - - public static void setProvider(VertexFormat format, VertexViewProvider provider) { - ((VertexFormatExtension) format).flywheel$setVertexViewProvider(provider); - } -} diff --git a/common/src/main/resources/flywheel.impl.mixins.json b/common/src/main/resources/flywheel.impl.mixins.json index ea7474cb8..c8d878e85 100644 --- a/common/src/main/resources/flywheel.impl.mixins.json +++ b/common/src/main/resources/flywheel.impl.mixins.json @@ -13,7 +13,6 @@ "LevelRendererMixin", "MinecraftMixin", "PoseStackMixin", - "VertexFormatMixin", "fix.FixFabulousDepthMixin", "fix.FixNormalScalingMixin", "visualmanage.BlockEntityMixin", diff --git a/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/FabricBakedModelBuilder.java b/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/FabricBakedModelBuilder.java index 4245cb8e0..88c3b486f 100644 --- a/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/FabricBakedModelBuilder.java +++ b/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/FabricBakedModelBuilder.java @@ -5,13 +5,10 @@ import com.mojang.blaze3d.vertex.PoseStack; import dev.engine_room.flywheel.api.material.Material; +import dev.engine_room.flywheel.api.model.Mesh; import dev.engine_room.flywheel.api.model.Model; -import dev.engine_room.flywheel.api.vertex.VertexView; -import dev.engine_room.flywheel.lib.memory.MemoryBlock; import dev.engine_room.flywheel.lib.model.ModelUtil; -import dev.engine_room.flywheel.lib.model.SimpleMesh; import dev.engine_room.flywheel.lib.model.SimpleModel; -import dev.engine_room.flywheel.lib.vertex.NoOverlayVertexView; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.world.level.BlockAndTintGetter; @@ -64,9 +61,7 @@ public SimpleModel build() { BakedModelBufferer.bufferSingle(ModelUtil.VANILLA_RENDERER.getModelRenderer(), level, bakedModel, blockState, poseStack, (renderType, shaded, data) -> { Material material = materialFunc.apply(renderType, shaded); if (material != null) { - VertexView vertexView = new NoOverlayVertexView(); - MemoryBlock meshData = ModelUtil.convertVanillaBuffer(data, vertexView); - var mesh = new SimpleMesh(vertexView, meshData, "source=BakedModelBuilder," + "bakedModel=" + bakedModel + ",renderType=" + renderType + ",shaded=" + shaded); + Mesh mesh = MeshHelper.blockVerticesToMesh(data, "source=BakedModelBuilder," + "bakedModel=" + bakedModel + ",renderType=" + renderType + ",shaded=" + shaded); builder.add(renderType, new Model.ConfiguredMesh(material, mesh)); } }); diff --git a/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/FabricBlockModelBuilder.java b/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/FabricBlockModelBuilder.java index 030f0893d..fecda55b4 100644 --- a/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/FabricBlockModelBuilder.java +++ b/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/FabricBlockModelBuilder.java @@ -5,13 +5,10 @@ import com.mojang.blaze3d.vertex.PoseStack; import dev.engine_room.flywheel.api.material.Material; +import dev.engine_room.flywheel.api.model.Mesh; import dev.engine_room.flywheel.api.model.Model; -import dev.engine_room.flywheel.api.vertex.VertexView; -import dev.engine_room.flywheel.lib.memory.MemoryBlock; import dev.engine_room.flywheel.lib.model.ModelUtil; -import dev.engine_room.flywheel.lib.model.SimpleMesh; import dev.engine_room.flywheel.lib.model.SimpleModel; -import dev.engine_room.flywheel.lib.vertex.NoOverlayVertexView; import net.minecraft.client.renderer.RenderType; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; @@ -53,9 +50,7 @@ public SimpleModel build() { BakedModelBufferer.bufferBlock(ModelUtil.VANILLA_RENDERER, level, state, poseStack, (renderType, shaded, data) -> { Material material = materialFunc.apply(renderType, shaded); if (material != null) { - VertexView vertexView = new NoOverlayVertexView(); - MemoryBlock meshData = ModelUtil.convertVanillaBuffer(data, vertexView); - var mesh = new SimpleMesh(vertexView, meshData, "source=BlockModelBuilder," + "blockState=" + state + ",renderType=" + renderType + ",shaded=" + shaded); + Mesh mesh = MeshHelper.blockVerticesToMesh(data, "source=BlockModelBuilder," + "blockState=" + state + ",renderType=" + renderType + ",shaded=" + shaded); builder.add(renderType, new Model.ConfiguredMesh(material, mesh)); } }); diff --git a/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/FabricMultiBlockModelBuilder.java b/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/FabricMultiBlockModelBuilder.java index 4be30322f..1420895eb 100644 --- a/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/FabricMultiBlockModelBuilder.java +++ b/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/FabricMultiBlockModelBuilder.java @@ -5,13 +5,10 @@ import com.mojang.blaze3d.vertex.PoseStack; import dev.engine_room.flywheel.api.material.Material; +import dev.engine_room.flywheel.api.model.Mesh; import dev.engine_room.flywheel.api.model.Model; -import dev.engine_room.flywheel.api.vertex.VertexView; -import dev.engine_room.flywheel.lib.memory.MemoryBlock; import dev.engine_room.flywheel.lib.model.ModelUtil; -import dev.engine_room.flywheel.lib.model.SimpleMesh; import dev.engine_room.flywheel.lib.model.SimpleModel; -import dev.engine_room.flywheel.lib.vertex.NoOverlayVertexView; import net.minecraft.client.renderer.RenderType; import net.minecraft.core.BlockPos; import net.minecraft.world.level.BlockAndTintGetter; @@ -50,9 +47,7 @@ public SimpleModel build() { BakedModelBufferer.bufferMultiBlock(ModelUtil.VANILLA_RENDERER, positions.iterator(), level, poseStack, renderFluids, (renderType, shaded, data) -> { Material material = materialFunc.apply(renderType, shaded); if (material != null) { - VertexView vertexView = new NoOverlayVertexView(); - MemoryBlock meshData = ModelUtil.convertVanillaBuffer(data, vertexView); - var mesh = new SimpleMesh(vertexView, meshData, "source=MultiBlockModelBuilder," + "renderType=" + renderType + ",shaded=" + shaded); + Mesh mesh = MeshHelper.blockVerticesToMesh(data, "source=MultiBlockModelBuilder," + "renderType=" + renderType + ",shaded=" + shaded); builder.add(renderType, new Model.ConfiguredMesh(material, mesh)); } }); diff --git a/forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ForgeBakedModelBuilder.java b/forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ForgeBakedModelBuilder.java index 33bf8b86f..10714e848 100644 --- a/forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ForgeBakedModelBuilder.java +++ b/forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ForgeBakedModelBuilder.java @@ -7,13 +7,10 @@ import com.mojang.blaze3d.vertex.PoseStack; import dev.engine_room.flywheel.api.material.Material; +import dev.engine_room.flywheel.api.model.Mesh; import dev.engine_room.flywheel.api.model.Model; -import dev.engine_room.flywheel.api.vertex.VertexView; -import dev.engine_room.flywheel.lib.memory.MemoryBlock; import dev.engine_room.flywheel.lib.model.ModelUtil; -import dev.engine_room.flywheel.lib.model.SimpleMesh; import dev.engine_room.flywheel.lib.model.SimpleModel; -import dev.engine_room.flywheel.lib.vertex.NoOverlayVertexView; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.world.level.BlockAndTintGetter; @@ -78,9 +75,7 @@ public SimpleModel build() { BakedModelBufferer.bufferSingle(ModelUtil.VANILLA_RENDERER.getModelRenderer(), level, bakedModel, blockState, poseStack, modelData, (renderType, shaded, data) -> { Material material = materialFunc.apply(renderType, shaded); if (material != null) { - VertexView vertexView = new NoOverlayVertexView(); - MemoryBlock meshData = ModelUtil.convertVanillaBuffer(data, vertexView); - var mesh = new SimpleMesh(vertexView, meshData, "source=BakedModelBuilder," + "bakedModel=" + bakedModel + ",renderType=" + renderType + ",shaded=" + shaded); + Mesh mesh = MeshHelper.blockVerticesToMesh(data, "source=BakedModelBuilder," + "bakedModel=" + bakedModel + ",renderType=" + renderType + ",shaded=" + shaded); builder.add(renderType, new Model.ConfiguredMesh(material, mesh)); } }); diff --git a/forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ForgeBlockModelBuilder.java b/forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ForgeBlockModelBuilder.java index c66997ad1..4e1d9df82 100644 --- a/forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ForgeBlockModelBuilder.java +++ b/forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ForgeBlockModelBuilder.java @@ -7,13 +7,10 @@ import com.mojang.blaze3d.vertex.PoseStack; import dev.engine_room.flywheel.api.material.Material; +import dev.engine_room.flywheel.api.model.Mesh; import dev.engine_room.flywheel.api.model.Model; -import dev.engine_room.flywheel.api.vertex.VertexView; -import dev.engine_room.flywheel.lib.memory.MemoryBlock; import dev.engine_room.flywheel.lib.model.ModelUtil; -import dev.engine_room.flywheel.lib.model.SimpleMesh; import dev.engine_room.flywheel.lib.model.SimpleModel; -import dev.engine_room.flywheel.lib.vertex.NoOverlayVertexView; import net.minecraft.client.renderer.RenderType; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; @@ -67,9 +64,7 @@ public SimpleModel build() { BakedModelBufferer.bufferBlock(ModelUtil.VANILLA_RENDERER, level, state, poseStack, modelData, (renderType, shaded, data) -> { Material material = materialFunc.apply(renderType, shaded); if (material != null) { - VertexView vertexView = new NoOverlayVertexView(); - MemoryBlock meshData = ModelUtil.convertVanillaBuffer(data, vertexView); - var mesh = new SimpleMesh(vertexView, meshData, "source=BlockModelBuilder," + "blockState=" + state + ",renderType=" + renderType + ",shaded=" + shaded); + Mesh mesh = MeshHelper.blockVerticesToMesh(data, "source=BlockModelBuilder," + "blockState=" + state + ",renderType=" + renderType + ",shaded=" + shaded); builder.add(renderType, new Model.ConfiguredMesh(material, mesh)); } }); diff --git a/forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ForgeMultiBlockModelBuilder.java b/forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ForgeMultiBlockModelBuilder.java index 3c4afa1ea..183e03d84 100644 --- a/forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ForgeMultiBlockModelBuilder.java +++ b/forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ForgeMultiBlockModelBuilder.java @@ -8,13 +8,10 @@ import com.mojang.blaze3d.vertex.PoseStack; import dev.engine_room.flywheel.api.material.Material; +import dev.engine_room.flywheel.api.model.Mesh; import dev.engine_room.flywheel.api.model.Model; -import dev.engine_room.flywheel.api.vertex.VertexView; -import dev.engine_room.flywheel.lib.memory.MemoryBlock; import dev.engine_room.flywheel.lib.model.ModelUtil; -import dev.engine_room.flywheel.lib.model.SimpleMesh; import dev.engine_room.flywheel.lib.model.SimpleModel; -import dev.engine_room.flywheel.lib.vertex.NoOverlayVertexView; import net.minecraft.client.renderer.RenderType; import net.minecraft.core.BlockPos; import net.minecraft.world.level.BlockAndTintGetter; @@ -65,9 +62,7 @@ public SimpleModel build() { BakedModelBufferer.bufferMultiBlock(ModelUtil.VANILLA_RENDERER, positions.iterator(), level, poseStack, modelDataLookup, renderFluids, (renderType, shaded, data) -> { Material material = materialFunc.apply(renderType, shaded); if (material != null) { - VertexView vertexView = new NoOverlayVertexView(); - MemoryBlock meshData = ModelUtil.convertVanillaBuffer(data, vertexView); - var mesh = new SimpleMesh(vertexView, meshData, "source=MultiBlockModelBuilder," + "renderType=" + renderType + ",shaded=" + shaded); + Mesh mesh = MeshHelper.blockVerticesToMesh(data, "source=MultiBlockModelBuilder," + "renderType=" + renderType + ",shaded=" + shaded); builder.add(renderType, new Model.ConfiguredMesh(material, mesh)); } });