From 90035ab084d02e8b72a985845591f3767d1e721c Mon Sep 17 00:00:00 2001 From: tterrag Date: Wed, 1 Jan 2020 22:25:30 -0500 Subject: [PATCH] Remove custom vertex format from BakedQuad --- .../blaze3d/vertex/IVertexBuilder.java.patch | 7 +- .../renderer/model/BakedQuad.java.patch | 14 +- .../renderer/model/FaceBakery.java.patch | 10 +- .../client/ForgeHooksClient.java | 11 +- .../extensions/IForgeVertexBuilder.java | 20 +- .../client/model/Attributes.java | 83 ------ .../client/model/DynamicBucketModel.java | 14 +- .../client/model/FancyMissingModel.java | 53 ++-- .../client/model/FluidModel.java | 4 +- .../client/model/ItemLayerModel.java | 42 +-- .../model/ItemTextureQuadConverter.java | 48 ++-- .../client/model/QuadTransformer.java | 71 +++--- .../client/model/SimpleModelFontRenderer.java | 21 +- .../animation/AnimationItemOverrideList.java | 1 - .../client/model/b3d/B3DLoader.java | 36 ++- .../model/geometry/IModelGeometryPart.java | 1 - .../client/model/obj/OBJModel.java | 16 +- .../model/pipeline/BakedQuadBuilder.java | 192 ++++++++++++++ .../client/model/pipeline/LightUtil.java | 2 +- .../model/pipeline/UnpackedBakedQuad.java | 240 ------------------ src/main/resources/forge.exc | 2 +- .../client/model/TRSRTransformerTest.java | 25 +- 22 files changed, 390 insertions(+), 523 deletions(-) delete mode 100644 src/main/java/net/minecraftforge/client/model/Attributes.java create mode 100644 src/main/java/net/minecraftforge/client/model/pipeline/BakedQuadBuilder.java delete mode 100644 src/main/java/net/minecraftforge/client/model/pipeline/UnpackedBakedQuad.java diff --git a/patches/minecraft/com/mojang/blaze3d/vertex/IVertexBuilder.java.patch b/patches/minecraft/com/mojang/blaze3d/vertex/IVertexBuilder.java.patch index a9c398891..b98e6093b 100644 --- a/patches/minecraft/com/mojang/blaze3d/vertex/IVertexBuilder.java.patch +++ b/patches/minecraft/com/mojang/blaze3d/vertex/IVertexBuilder.java.patch @@ -9,7 +9,7 @@ Logger field_227884_f_ = LogManager.getLogger(); IVertexBuilder func_225582_a_(double p_225582_1_, double p_225582_3_, double p_225582_5_); -@@ -95,7 +95,7 @@ +@@ -95,11 +95,12 @@ f5 = p_227890_3_[k] * p_227890_6_; } @@ -18,3 +18,8 @@ float f9 = bytebuffer.getFloat(16); float f10 = bytebuffer.getFloat(20); Vector4f vector4f = new Vector4f(f, f1, f2, 1.0F); + vector4f.func_229372_a_(matrix4f); ++ applyBakedNormals(vector3f, bytebuffer); + this.func_225588_a_(vector4f.func_195910_a(), vector4f.func_195913_b(), vector4f.func_195914_c(), f3, f4, f5, 1.0F, f9, f10, p_227890_8_, l, vector3f.func_195899_a(), vector3f.func_195900_b(), vector3f.func_195902_c()); + } + } diff --git a/patches/minecraft/net/minecraft/client/renderer/model/BakedQuad.java.patch b/patches/minecraft/net/minecraft/client/renderer/model/BakedQuad.java.patch index 6e19f061d..aef18704e 100644 --- a/patches/minecraft/net/minecraft/client/renderer/model/BakedQuad.java.patch +++ b/patches/minecraft/net/minecraft/client/renderer/model/BakedQuad.java.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/client/renderer/model/BakedQuad.java +++ b/net/minecraft/client/renderer/model/BakedQuad.java -@@ -6,13 +6,23 @@ +@@ -6,13 +6,22 @@ import net.minecraftforge.api.distmarker.OnlyIn; @OnlyIn(Dist.CLIENT) @@ -16,22 +16,20 @@ + */ + @Deprecated public BakedQuad(int[] p_i46574_1_, int p_i46574_2_, Direction p_i46574_3_, TextureAtlasSprite p_i46574_4_) { -+ this(p_i46574_1_, p_i46574_2_, p_i46574_3_, p_i46574_4_, true, net.minecraft.client.renderer.vertex.DefaultVertexFormats.field_176600_a); ++ this(p_i46574_1_, p_i46574_2_, p_i46574_3_, p_i46574_4_, true); + } + -+ public BakedQuad(int[] p_i46574_1_, int p_i46574_2_, Direction p_i46574_3_, TextureAtlasSprite p_i46574_4_, boolean applyDiffuseLighting, net.minecraft.client.renderer.vertex.VertexFormat format) { -+ this.format = format; ++ public BakedQuad(int[] p_i46574_1_, int p_i46574_2_, Direction p_i46574_3_, TextureAtlasSprite p_i46574_4_, boolean applyDiffuseLighting) { + this.applyDiffuseLighting = applyDiffuseLighting; this.field_178215_a = p_i46574_1_; this.field_178213_b = p_i46574_2_; this.field_178214_c = p_i46574_3_; -@@ -34,4 +44,25 @@ +@@ -34,4 +43,20 @@ public Direction func_178210_d() { return this.field_178214_c; } + + // Forge start -+ protected final net.minecraft.client.renderer.vertex.VertexFormat format; + protected final boolean applyDiffuseLighting; + + @Override @@ -39,10 +37,6 @@ + net.minecraftforge.client.model.pipeline.LightUtil.putBakedQuad(consumer, this); + } + -+ public net.minecraft.client.renderer.vertex.VertexFormat getFormat() { -+ return format; -+ } -+ + public TextureAtlasSprite func_187508_a() { + return field_187509_d; + } diff --git a/patches/minecraft/net/minecraft/client/renderer/model/FaceBakery.java.patch b/patches/minecraft/net/minecraft/client/renderer/model/FaceBakery.java.patch index 904a0460f..a21fdb8a8 100644 --- a/patches/minecraft/net/minecraft/client/renderer/model/FaceBakery.java.patch +++ b/patches/minecraft/net/minecraft/client/renderer/model/FaceBakery.java.patch @@ -15,14 +15,16 @@ - return new BakedQuad(aint, p_228824_3_.field_178245_c, direction, p_228824_4_); + net.minecraftforge.client.ForgeHooksClient.fillNormal(aint, direction); -+ return new BakedQuad(aint, p_228824_3_.field_178245_c, direction, p_228824_4_, p_228824_8_, net.minecraft.client.renderer.vertex.DefaultVertexFormats.field_176600_a); ++ return new BakedQuad(aint, p_228824_3_.field_178245_c, direction, p_228824_4_, p_228824_8_); } public static BlockFaceUV func_228821_a_(BlockFaceUV p_228821_0_, Direction p_228821_1_, TransformationMatrix p_228821_2_, ResourceLocation p_228821_3_) { -@@ -152,6 +154,8 @@ +@@ -150,8 +152,8 @@ + p_228826_1_[i + 1] = Float.floatToRawIntBits(p_228826_3_.func_195900_b()); + p_228826_1_[i + 2] = Float.floatToRawIntBits(p_228826_3_.func_195902_c()); p_228826_1_[i + 3] = p_228826_4_; - p_228826_1_[i + 4] = Float.floatToRawIntBits(p_228826_5_.func_94214_a((double)p_228826_6_.func_178348_a(p_228826_2_))); - p_228826_1_[i + 4 + 1] = Float.floatToRawIntBits(p_228826_5_.func_94207_b((double)p_228826_6_.func_178346_b(p_228826_2_))); +- p_228826_1_[i + 4] = Float.floatToRawIntBits(p_228826_5_.func_94214_a((double)p_228826_6_.func_178348_a(p_228826_2_))); +- p_228826_1_[i + 4 + 1] = Float.floatToRawIntBits(p_228826_5_.func_94207_b((double)p_228826_6_.func_178346_b(p_228826_2_))); + p_228826_1_[i + 4] = Float.floatToRawIntBits(p_228826_5_.func_94214_a((double)p_228826_6_.func_178348_a(p_228826_2_) * .999 + p_228826_6_.func_178348_a((p_228826_2_ + 2) % 4) * .001)); + p_228826_1_[i + 4 + 1] = Float.floatToRawIntBits(p_228826_5_.func_94207_b((double)p_228826_6_.func_178346_b(p_228826_2_) * .999 + p_228826_6_.func_178346_b((p_228826_2_ + 2) % 4) * .001)); } diff --git a/src/main/java/net/minecraftforge/client/ForgeHooksClient.java b/src/main/java/net/minecraftforge/client/ForgeHooksClient.java index 3315e39f6..817b825b8 100644 --- a/src/main/java/net/minecraftforge/client/ForgeHooksClient.java +++ b/src/main/java/net/minecraftforge/client/ForgeHooksClient.java @@ -643,14 +643,11 @@ public class ForgeHooksClient int bl = 0; int sl = 0; - if (q.getFormat().hasUV(1)) + LightUtil.putBakedQuad(lightGatherer, q); + if (lightGatherer.hasLighting()) { - LightUtil.putBakedQuad(lightGatherer, q); - if (lightGatherer.hasLighting()) - { - bl = lightGatherer.blockLight; - sl = lightGatherer.skyLight; - } + bl = lightGatherer.blockLight; + sl = lightGatherer.skyLight; } boolean shade = q.shouldApplyDiffuseLighting(); diff --git a/src/main/java/net/minecraftforge/client/extensions/IForgeVertexBuilder.java b/src/main/java/net/minecraftforge/client/extensions/IForgeVertexBuilder.java index 80775cad5..1a026f10c 100644 --- a/src/main/java/net/minecraftforge/client/extensions/IForgeVertexBuilder.java +++ b/src/main/java/net/minecraftforge/client/extensions/IForgeVertexBuilder.java @@ -21,6 +21,8 @@ package net.minecraftforge.client.extensions; import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.IVertexBuilder; + +import net.minecraft.client.renderer.LightTexture; import net.minecraft.client.renderer.Matrix4f; import net.minecraft.client.renderer.Vector3f; import net.minecraft.client.renderer.Vector4f; @@ -96,16 +98,26 @@ public interface IForgeVertexBuilder float f10 = bytebuffer.getFloat(20); Vector4f pos = new Vector4f(f, f1, f2, 1.0F); pos.func_229372_a_(matrix4f); + applyBakedNormals(normal, bytebuffer); ((IVertexBuilder)this).func_225588_a_(pos.getX(), pos.getY(), pos.getZ(), cr, cg, cb, ca, f9, f10, overlayCoords, lightmapCoord, normal.getX(), normal.getY(), normal.getZ()); } } } default int applyBakedLighting(int lightmapCoord, ByteBuffer data) { - int sl = (lightmapCoord >> 16) & 0xFFFF; - int bl = lightmapCoord & 0xFFFF; - sl = Math.max(sl, Short.toUnsignedInt(data.getShort(24))); + int bl = LightTexture.func_228450_a_(lightmapCoord); + int sl = LightTexture.func_228454_b_(lightmapCoord); bl = Math.max(bl, Short.toUnsignedInt(data.getShort(26))); - return (sl << 16) | bl; + sl = Math.max(sl, Short.toUnsignedInt(data.getShort(24))); + return LightTexture.func_228451_a_(bl, sl); + } + + default void applyBakedNormals(Vector3f generated, ByteBuffer data) { + byte nx = data.get(28); + byte ny = data.get(29); + byte nz = data.get(30); + if (nx != 0 || ny != 0 || nz != 0) { + generated.set(nx / 127f, ny / 127f, nz / 127f); + } } } diff --git a/src/main/java/net/minecraftforge/client/model/Attributes.java b/src/main/java/net/minecraftforge/client/model/Attributes.java deleted file mode 100644 index 9d13b15ce..000000000 --- a/src/main/java/net/minecraftforge/client/model/Attributes.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Minecraft Forge - * Copyright (c) 2016-2019. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation version 2.1 - * of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -package net.minecraftforge.client.model; - -import com.google.common.collect.ImmutableList; -import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import net.minecraft.client.renderer.vertex.VertexFormat; -import net.minecraft.client.renderer.vertex.VertexFormatElement; -import net.minecraft.client.renderer.vertex.VertexFormatElement.Type; -import net.minecraft.client.renderer.vertex.VertexFormatElement.Usage; - -public class Attributes -{ - /* - * Default format of the data in IBakedModel - */ - public static final VertexFormat DEFAULT_BAKED_FORMAT = DefaultVertexFormats.BLOCK; - - /* - * Can first format be used where second is expected - */ - public static boolean moreSpecific(VertexFormat first, VertexFormat second) - { - int size = first.getSize(); - if(size != second.getSize()) return false; - - int padding = 0; - int j = 0; - ImmutableList elementsFirst = first.func_227894_c_(); - ImmutableList elementsSecond = second.func_227894_c_(); - for(VertexFormatElement firstAttr : elementsFirst) - { - while(j < elementsSecond.size() && elementsSecond.get(j).getUsage() == Usage.PADDING) - { - padding += elementsSecond.get(j++).getSize(); - } - if(j >= elementsSecond.size() && padding == 0) - { - // if no padding is left, but there are still elements in first (we're processing one) - it doesn't fit - return false; - } - if(padding == 0) - { - // no padding - attributes have to match - VertexFormatElement secondAttr = elementsSecond.get(j++); - if( - firstAttr.getIndex() != secondAttr.getIndex() || - firstAttr.getElementCount() != secondAttr.getElementCount() || - firstAttr.getType() != secondAttr.getType() || - firstAttr.getUsage() != secondAttr.getUsage()) - { - return false; - } - } - else - { - // padding - attribute should fit in it - padding -= firstAttr.getSize(); - if(padding < 0) return false; - } - } - - if(padding != 0 || j != elementsSecond.size()) return false; - return true; - } -} diff --git a/src/main/java/net/minecraftforge/client/model/DynamicBucketModel.java b/src/main/java/net/minecraftforge/client/model/DynamicBucketModel.java index 72673f70b..747ca330d 100644 --- a/src/main/java/net/minecraftforge/client/model/DynamicBucketModel.java +++ b/src/main/java/net/minecraftforge/client/model/DynamicBucketModel.java @@ -147,7 +147,7 @@ public final class DynamicBucketModel implements IModelGeometry fontCache = CacheBuilder.newBuilder().maximumSize(3).build(new CacheLoader() - { - @Override - public SimpleModelFontRenderer load(VertexFormat format) throws Exception - { - float [] mv = new float[16]; - mv[2*4+0] = 1f / 128f; - mv[0*4+1] =mv[1*4+2] = -mv[2*4+0]; - mv[3*4+3] = 1; - mv[0*4+3] = 1; - mv[0*4+3] = 1 + 1f / 0x100; - mv[0*4+3] = 0; - Matrix4f m = new Matrix4f(mv); - return new SimpleModelFontRenderer( - Minecraft.getInstance().gameSettings, - font, - Minecraft.getInstance().getTextureManager(), - false, - m, - format - ) {/* TODO Implement once SimpleModelFontRenderer is fixed - @Override - protected float renderUnicodeChar(char c, boolean italic) - { - return super.renderDefaultChar(126, italic); - } - */}; - } + private static final SimpleModelFontRenderer fontRenderer = Util.make(() -> { + float [] mv = new float[16]; + mv[2*4+0] = 1f / 128f; + mv[0*4+1] =mv[1*4+2] = -mv[2*4+0]; + mv[3*4+3] = 1; + mv[0*4+3] = 1; + mv[0*4+3] = 1 + 1f / 0x100; + mv[0*4+3] = 0; + Matrix4f m = new Matrix4f(mv); + return new SimpleModelFontRenderer( + Minecraft.getInstance().gameSettings, + font, + Minecraft.getInstance().getTextureManager(), + false, + m + ) {/* TODO Implement once SimpleModelFontRenderer is fixed + @Override + protected float renderUnicodeChar(char c, boolean italic) + { + return super.renderDefaultChar(126, italic); + } + */}; }); private final IUnbakedModel missingModel; @@ -114,7 +109,7 @@ final class FancyMissingModel implements IUnbakedModel IBakedModel bigMissing = missingModel.func_225613_a_(bakery, spriteGetter, modelTransform, modelLocation); ModelTransformComposition smallState = new ModelTransformComposition(modelTransform, new SimpleModelTransform(smallTransformation)); IBakedModel smallMissing = missingModel.func_225613_a_(bakery, spriteGetter, smallState, modelLocation); - return new BakedModel(bigMissing, smallMissing, fontCache.getUnchecked(DefaultVertexFormats.BLOCK), message, spriteGetter.apply(font2)); + return new BakedModel(bigMissing, smallMissing, fontRenderer, message, spriteGetter.apply(font2)); } static final class BakedModel implements IBakedModel diff --git a/src/main/java/net/minecraftforge/client/model/FluidModel.java b/src/main/java/net/minecraftforge/client/model/FluidModel.java index 46613b040..4f3582aad 100644 --- a/src/main/java/net/minecraftforge/client/model/FluidModel.java +++ b/src/main/java/net/minecraftforge/client/model/FluidModel.java @@ -47,9 +47,9 @@ import net.minecraft.util.math.MathHelper; import net.minecraftforge.client.ForgeHooksClient; import net.minecraftforge.client.model.data.IModelData; import net.minecraftforge.client.model.geometry.IModelGeometry; +import net.minecraftforge.client.model.pipeline.BakedQuadBuilder; import net.minecraftforge.client.model.pipeline.IVertexConsumer; import net.minecraftforge.client.model.pipeline.TRSRTransformer; -import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad; import net.minecraftforge.fluids.FluidAttributes; import com.google.common.cache.CacheBuilder; @@ -364,7 +364,7 @@ public final class FluidModel implements IModelGeometry private BakedQuad buildQuad(Direction side, TextureAtlasSprite texture, boolean flip, boolean offset, VertexParameter x, VertexParameter y, VertexParameter z, VertexParameter u, VertexParameter v) { - UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(DefaultVertexFormats.BLOCK); + BakedQuadBuilder builder = new BakedQuadBuilder(); builder.setQuadOrientation(side); builder.setTexture(texture); diff --git a/src/main/java/net/minecraftforge/client/model/ItemLayerModel.java b/src/main/java/net/minecraftforge/client/model/ItemLayerModel.java index 0ed80801e..a30fa11fb 100644 --- a/src/main/java/net/minecraftforge/client/model/ItemLayerModel.java +++ b/src/main/java/net/minecraftforge/client/model/ItemLayerModel.java @@ -31,9 +31,9 @@ import net.minecraft.client.renderer.vertex.VertexFormat; import net.minecraft.util.Direction; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.model.geometry.IModelGeometry; +import net.minecraftforge.client.model.pipeline.BakedQuadBuilder; import net.minecraftforge.client.model.pipeline.IVertexConsumer; import net.minecraftforge.client.model.pipeline.TRSRTransformer; -import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad; import java.util.Arrays; import java.util.BitSet; @@ -86,7 +86,7 @@ public final class ItemLayerModel implements IModelGeometry { //TODO: Verify TransformationMatrix transform = modelTransform.func_225615_b_(); - ImmutableList quads = getQuadsForSprites(textures, DefaultVertexFormats.BLOCK, transform, spriteGetter); + ImmutableList quads = getQuadsForSprites(textures, transform, spriteGetter); TextureAtlasSprite particle = spriteGetter.apply( owner.isTexturePresent("particle") ? owner.resolveTexture("particle") : textures.get(0) ); @@ -94,18 +94,18 @@ public final class ItemLayerModel implements IModelGeometry return new BakedItemModel(quads, particle, map, overrides, transform.isIdentity()); } - public static ImmutableList getQuadsForSprites(List textures, VertexFormat format, TransformationMatrix transform, Function spriteGetter) + public static ImmutableList getQuadsForSprites(List textures, TransformationMatrix transform, Function spriteGetter) { ImmutableList.Builder builder = ImmutableList.builder(); for(int i = 0; i < textures.size(); i++) { TextureAtlasSprite tas = spriteGetter.apply(textures.get(i)); - builder.addAll(getQuadsForSprite(i, tas, format, transform)); + builder.addAll(getQuadsForSprite(i, tas, transform)); } return builder.build(); } - public static ImmutableList getQuadsForSprite(int tint, TextureAtlasSprite sprite, VertexFormat format, TransformationMatrix transform) + public static ImmutableList getQuadsForSprite(int tint, TextureAtlasSprite sprite, TransformationMatrix transform) { ImmutableList.Builder builder = ImmutableList.builder(); @@ -196,7 +196,7 @@ public final class ItemLayerModel implements IModelGeometry { // make quad [uStart, u] int off = facing == Direction.DOWN ? 1 : 0; - builder.add(buildSideQuad(format, transform, facing, tint, sprite, uStart, v+off, u-uStart)); + builder.add(buildSideQuad(transform, facing, tint, sprite, uStart, v+off, u-uStart)); building = false; } else if (!building && face) // start new quad @@ -210,7 +210,7 @@ public final class ItemLayerModel implements IModelGeometry { // make quad [uStart, uEnd] int off = facing == Direction.DOWN ? 1 : 0; - builder.add(buildSideQuad(format, transform, facing, tint, sprite, uStart, v+off, uEnd-uStart)); + builder.add(buildSideQuad(transform, facing, tint, sprite, uStart, v+off, uEnd-uStart)); } } } @@ -243,7 +243,7 @@ public final class ItemLayerModel implements IModelGeometry { // make quad [vStart, v] int off = facing == Direction.EAST ? 1 : 0; - builder.add(buildSideQuad(format, transform, facing, tint, sprite, u+off, vStart, v-vStart)); + builder.add(buildSideQuad(transform, facing, tint, sprite, u+off, vStart, v-vStart)); building = false; } else if (!building && face) // start new quad @@ -257,20 +257,20 @@ public final class ItemLayerModel implements IModelGeometry { // make quad [vStart, vEnd] int off = facing == Direction.EAST ? 1 : 0; - builder.add(buildSideQuad(format, transform, facing, tint, sprite, u+off, vStart, vEnd-vStart)); + builder.add(buildSideQuad(transform, facing, tint, sprite, u+off, vStart, vEnd-vStart)); } } } // front - builder.add(buildQuad(format, transform, Direction.NORTH, sprite, tint, + builder.add(buildQuad(transform, Direction.NORTH, sprite, tint, 0, 0, 7.5f / 16f, sprite.getMinU(), sprite.getMaxV(), 0, 1, 7.5f / 16f, sprite.getMinU(), sprite.getMinV(), 1, 1, 7.5f / 16f, sprite.getMaxU(), sprite.getMinV(), 1, 0, 7.5f / 16f, sprite.getMaxU(), sprite.getMaxV() )); // back - builder.add(buildQuad(format, transform, Direction.SOUTH, sprite, tint, + builder.add(buildQuad(transform, Direction.SOUTH, sprite, tint, 0, 0, 8.5f / 16f, sprite.getMinU(), sprite.getMaxV(), 1, 0, 8.5f / 16f, sprite.getMaxU(), sprite.getMaxV(), 1, 1, 8.5f / 16f, sprite.getMaxU(), sprite.getMinV(), @@ -319,7 +319,7 @@ public final class ItemLayerModel implements IModelGeometry } } - private static BakedQuad buildSideQuad(VertexFormat format, TransformationMatrix transform, Direction side, int tint, TextureAtlasSprite sprite, int u, int v, int size) + private static BakedQuad buildSideQuad(TransformationMatrix transform, Direction side, int tint, TextureAtlasSprite sprite, int u, int v, int size) { final float eps = 1e-2f; @@ -358,7 +358,7 @@ public final class ItemLayerModel implements IModelGeometry float v1 = 16f * (1f - y1 - dy); return buildQuad( - format, transform, remap(side), sprite, tint, + transform, remap(side), sprite, tint, x0, y0, z0, sprite.getInterpolatedU(u0), sprite.getInterpolatedV(v0), x1, y1, z0, sprite.getInterpolatedU(u1), sprite.getInterpolatedV(v1), x1, y1, z1, sprite.getInterpolatedU(u1), sprite.getInterpolatedV(v1), @@ -372,14 +372,13 @@ public final class ItemLayerModel implements IModelGeometry return side.getAxis() == Direction.Axis.Y ? side.getOpposite() : side; } - private static BakedQuad buildQuad( - VertexFormat format, TransformationMatrix transform, Direction side, TextureAtlasSprite sprite, int tint, + private static BakedQuad buildQuad(TransformationMatrix transform, Direction side, TextureAtlasSprite sprite, int tint, float x0, float y0, float z0, float u0, float v0, float x1, float y1, float z1, float u1, float v1, float x2, float y2, float z2, float u2, float v2, float x3, float y3, float z3, float u3, float v3) { - UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(format); + BakedQuadBuilder builder = new BakedQuadBuilder(); builder.setQuadTint(tint); builder.setQuadOrientation(side); @@ -388,16 +387,17 @@ public final class ItemLayerModel implements IModelGeometry boolean hasTransform = !transform.isIdentity(); IVertexConsumer consumer = hasTransform ? new TRSRTransformer(builder, transform) : builder; - putVertex(consumer, format, side, x0, y0, z0, u0, v0); - putVertex(consumer, format, side, x1, y1, z1, u1, v1); - putVertex(consumer, format, side, x2, y2, z2, u2, v2); - putVertex(consumer, format, side, x3, y3, z3, u3, v3); + putVertex(consumer, side, x0, y0, z0, u0, v0); + putVertex(consumer, side, x1, y1, z1, u1, v1); + putVertex(consumer, side, x2, y2, z2, u2, v2); + putVertex(consumer, side, x3, y3, z3, u3, v3); return builder.build(); } - private static void putVertex(IVertexConsumer consumer, VertexFormat format, Direction side, float x, float y, float z, float u, float v) + private static void putVertex(IVertexConsumer consumer, Direction side, float x, float y, float z, float u, float v) { + VertexFormat format = consumer.getVertexFormat(); for(int e = 0; e < format.func_227894_c_().size(); e++) { switch(format.func_227894_c_().get(e).getUsage()) diff --git a/src/main/java/net/minecraftforge/client/model/ItemTextureQuadConverter.java b/src/main/java/net/minecraftforge/client/model/ItemTextureQuadConverter.java index f1bd85be0..fd0ef7a71 100644 --- a/src/main/java/net/minecraftforge/client/model/ItemTextureQuadConverter.java +++ b/src/main/java/net/minecraftforge/client/model/ItemTextureQuadConverter.java @@ -22,12 +22,13 @@ package net.minecraftforge.client.model; import com.google.common.collect.Lists; import net.minecraft.client.renderer.TransformationMatrix; +import net.minecraft.client.renderer.model.BakedQuad; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.vertex.VertexFormat; import net.minecraft.util.Direction; +import net.minecraftforge.client.model.pipeline.BakedQuadBuilder; import net.minecraftforge.client.model.pipeline.IVertexConsumer; import net.minecraftforge.client.model.pipeline.TRSRTransformer; -import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad; import java.util.List; @@ -51,10 +52,10 @@ public final class ItemTextureQuadConverter * @param sprite The texture whose UVs shall be used * @return The generated quads. */ - public static List convertTexture(VertexFormat format, TransformationMatrix transform, TextureAtlasSprite template, TextureAtlasSprite sprite, float z, Direction facing, int color, int tint) + public static List convertTexture(TransformationMatrix transform, TextureAtlasSprite template, TextureAtlasSprite sprite, float z, Direction facing, int color, int tint) { - List horizontal = convertTextureHorizontal(format, transform, template, sprite, z, facing, color, tint); - List vertical = convertTextureVertical(format, transform, template, sprite, z, facing, color, tint); + List horizontal = convertTextureHorizontal(transform, template, sprite, z, facing, color, tint); + List vertical = convertTextureVertical(transform, template, sprite, z, facing, color, tint); return horizontal.size() <= vertical.size() ? horizontal : vertical; } @@ -63,13 +64,13 @@ public final class ItemTextureQuadConverter * Scans a texture and converts it into a list of horizontal strips stacked on top of each other. * The height of the strips is as big as possible. */ - public static List convertTextureHorizontal(VertexFormat format, TransformationMatrix transform, TextureAtlasSprite template, TextureAtlasSprite sprite, float z, Direction facing, int color, int tint) + public static List convertTextureHorizontal(TransformationMatrix transform, TextureAtlasSprite template, TextureAtlasSprite sprite, float z, Direction facing, int color, int tint) { int w = template.getWidth(); int h = template.getHeight(); float wScale = 16f / (float)w; float hScale = 16f / (float)h; - List quads = Lists.newArrayList(); + List quads = Lists.newArrayList(); // the upper left x-position of the current quad int start = -1; @@ -109,7 +110,7 @@ public final class ItemTextureQuadConverter } // create the quad - quads.add(genQuad(format, transform, + quads.add(genQuad(transform, (float)start * wScale, (float)y * hScale, (float)x * wScale, @@ -134,13 +135,13 @@ public final class ItemTextureQuadConverter * Scans a texture and converts it into a list of vertical strips stacked next to each other from left to right. * The width of the strips is as big as possible. */ - public static List convertTextureVertical(VertexFormat format, TransformationMatrix transform, TextureAtlasSprite template, TextureAtlasSprite sprite, float z, Direction facing, int color, int tint) + public static List convertTextureVertical(TransformationMatrix transform, TextureAtlasSprite template, TextureAtlasSprite sprite, float z, Direction facing, int color, int tint) { int w = template.getWidth(); int h = template.getHeight(); float wScale = 16f / (float)w; float hScale = 16f / (float)h; - List quads = Lists.newArrayList(); + List quads = Lists.newArrayList(); // the upper left y-position of the current quad int start = -1; @@ -180,7 +181,7 @@ public final class ItemTextureQuadConverter } // create the quad - quads.add(genQuad(format, transform, + quads.add(genQuad(transform, (float)x * wScale, (float)start * hScale, (float)endX * wScale, @@ -210,7 +211,7 @@ public final class ItemTextureQuadConverter * Generates a Front/Back quad for an itemmodel. Therefore only supports facing NORTH and SOUTH. * Coordinates are [0,16] to match the usual coordinates used in TextureAtlasSprites */ - public static UnpackedBakedQuad genQuad(VertexFormat format, TransformationMatrix transform, float x1, float y1, float x2, float y2, float z, TextureAtlasSprite sprite, Direction facing, int color, int tint) + public static BakedQuad genQuad(TransformationMatrix transform, float x1, float y1, float x2, float y2, float z, TextureAtlasSprite sprite, Direction facing, int color, int tint) { float u1 = sprite.getInterpolatedU(x1); float v1 = sprite.getInterpolatedV(y1); @@ -226,14 +227,14 @@ public final class ItemTextureQuadConverter y1 = 1f - y2; y2 = 1f - tmp; - return putQuad(format, transform, facing, sprite, color, tint, x1, y1, x2, y2, z, u1, v1, u2, v2); + return putQuad(transform, facing, sprite, color, tint, x1, y1, x2, y2, z, u1, v1, u2, v2); } - private static UnpackedBakedQuad putQuad(VertexFormat format, TransformationMatrix transform, Direction side, TextureAtlasSprite sprite, int color, int tint, + private static BakedQuad putQuad(TransformationMatrix transform, Direction side, TextureAtlasSprite sprite, int color, int tint, float x1, float y1, float x2, float y2, float z, float u1, float v1, float u2, float v2) { - UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(format); + BakedQuadBuilder builder = new BakedQuadBuilder(); builder.setQuadTint(tint); builder.setQuadOrientation(side); @@ -245,24 +246,25 @@ public final class ItemTextureQuadConverter if (side == Direction.SOUTH) { - putVertex(consumer, format, side, x1, y1, z, u1, v2, color); - putVertex(consumer, format, side, x2, y1, z, u2, v2, color); - putVertex(consumer, format, side, x2, y2, z, u2, v1, color); - putVertex(consumer, format, side, x1, y2, z, u1, v1, color); + putVertex(consumer, side, x1, y1, z, u1, v2, color); + putVertex(consumer, side, x2, y1, z, u2, v2, color); + putVertex(consumer, side, x2, y2, z, u2, v1, color); + putVertex(consumer, side, x1, y2, z, u1, v1, color); } else { - putVertex(consumer, format, side, x1, y1, z, u1, v2, color); - putVertex(consumer, format, side, x1, y2, z, u1, v1, color); - putVertex(consumer, format, side, x2, y2, z, u2, v1, color); - putVertex(consumer, format, side, x2, y1, z, u2, v2, color); + putVertex(consumer, side, x1, y1, z, u1, v2, color); + putVertex(consumer, side, x1, y2, z, u1, v1, color); + putVertex(consumer, side, x2, y2, z, u2, v1, color); + putVertex(consumer, side, x2, y1, z, u2, v2, color); } return builder.build(); } - private static void putVertex(IVertexConsumer consumer, VertexFormat format, Direction side, + private static void putVertex(IVertexConsumer consumer, Direction side, float x, float y, float z, float u, float v, int color) { + VertexFormat format = consumer.getVertexFormat(); for (int e = 0; e < format.func_227894_c_().size(); e++) { switch (format.func_227894_c_().get(e).getUsage()) diff --git a/src/main/java/net/minecraftforge/client/model/QuadTransformer.java b/src/main/java/net/minecraftforge/client/model/QuadTransformer.java index ef38b051d..16f44f27b 100644 --- a/src/main/java/net/minecraftforge/client/model/QuadTransformer.java +++ b/src/main/java/net/minecraftforge/client/model/QuadTransformer.java @@ -19,40 +19,38 @@ package net.minecraftforge.client.model; -import com.google.common.collect.Lists; -import net.minecraft.client.renderer.TransformationMatrix; -import net.minecraft.client.renderer.Vector3f; -import net.minecraft.client.renderer.Vector4f; -import net.minecraft.client.renderer.model.BakedQuad; -import net.minecraft.client.renderer.vertex.VertexFormat; -import net.minecraft.client.renderer.vertex.VertexFormatElement; - import java.util.Arrays; import java.util.Collections; import java.util.List; +import com.google.common.collect.Lists; + +import net.minecraft.client.renderer.TransformationMatrix; +import net.minecraft.client.renderer.Vector3f; +import net.minecraft.client.renderer.Vector4f; +import net.minecraft.client.renderer.model.BakedQuad; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.client.renderer.vertex.VertexFormat; +import net.minecraft.client.renderer.vertex.VertexFormatElement; + public class QuadTransformer { - private final VertexFormat format; - private final int positionOffset; - private final int normalOffset; + private static final int POSITION = findPositionOffset(DefaultVertexFormats.BLOCK); + private static final int NORMAL = findNormalOffset(DefaultVertexFormats.BLOCK); private final TransformationMatrix transform; - public QuadTransformer(VertexFormat format, TransformationMatrix transform) + public QuadTransformer(TransformationMatrix transform) { - this.format = format; - this.positionOffset = findPositionOffset(format); - this.normalOffset = findNormalOffset(format); this.transform = transform; } private void processVertices(int[] inData, int[] outData) { - int stride = format.getSize(); + int stride = DefaultVertexFormats.BLOCK.getSize(); int count = (inData.length * 4) / stride; for (int i=0;i= 0) + for (int i=0;i> 24) & 0xFF) / 255.0f; - float y = (((normalIn << 8) >> 24) & 0xFF) / 255.0f; - float z = (((normalIn << 16) >> 24) & 0xFF) / 255.0f; + float x = (((normalIn) >> 24) & 0xFF) / 255.0f; + float y = (((normalIn << 8) >> 24) & 0xFF) / 255.0f; + float z = (((normalIn << 16) >> 24) & 0xFF) / 255.0f; - Vector3f pos = new Vector3f(x, y, z); - transform.transformNormal(pos); - pos.func_229194_d_(); + Vector3f pos = new Vector3f(x, y, z); + transform.transformNormal(pos); + pos.func_229194_d_(); - int normalOut = (((int) (x / 255.0) & 0xFF) << 24) | - (((int) (y / 255.0) & 0xFF) << 16) | - (((int) (z / 255.0) & 0xFF) << 8) | - (normalIn & 0xFF); + int normalOut = (((int) (x / 255.0) & 0xFF) << 24) | + (((int) (y / 255.0) & 0xFF) << 16) | + (((int) (z / 255.0) & 0xFF) << 8) | + (normalIn & 0xFF); - putAtByteOffset(outData, offset, normalOut); - } + putAtByteOffset(outData, offset, normalOut); } } } @@ -158,7 +153,7 @@ public class QuadTransformer } } if (index == fmt.func_227894_c_().size() || element == null) - return -1; + throw new IllegalStateException("BLOCK format does not have normals?"); if (element.getType() != VertexFormatElement.Type.BYTE) throw new RuntimeException("Expected NORMAL attribute to have data type BYTE"); if (element.getSize() < 3) @@ -177,7 +172,7 @@ public class QuadTransformer int[] outData = Arrays.copyOf(inData, inData.length); processVertices(inData, outData); - return new BakedQuad(outData, input.getTintIndex(), input.getFace(), input.getSprite(), input.shouldApplyDiffuseLighting(), format); + return new BakedQuad(outData, input.getTintIndex(), input.getFace(), input.getSprite(), input.shouldApplyDiffuseLighting()); } /** @@ -209,7 +204,7 @@ public class QuadTransformer int[] outData = Arrays.copyOf(inData, inData.length); processVertices(inData, outData); - outputs.add(new BakedQuad(outData, input.getTintIndex(), input.getFace(), input.getSprite(), input.shouldApplyDiffuseLighting(), format)); + outputs.add(new BakedQuad(outData, input.getTintIndex(), input.getFace(), input.getSprite(), input.shouldApplyDiffuseLighting())); } return outputs; } diff --git a/src/main/java/net/minecraftforge/client/model/SimpleModelFontRenderer.java b/src/main/java/net/minecraftforge/client/model/SimpleModelFontRenderer.java index 6b8c42070..fbb04c929 100644 --- a/src/main/java/net/minecraftforge/client/model/SimpleModelFontRenderer.java +++ b/src/main/java/net/minecraftforge/client/model/SimpleModelFontRenderer.java @@ -19,41 +19,38 @@ package net.minecraftforge.client.model; -import net.minecraft.client.renderer.Matrix4f; -import net.minecraft.client.renderer.TransformationMatrix; -import net.minecraft.client.renderer.Vector3f; -import net.minecraft.client.renderer.Vector4f; -import net.minecraft.client.renderer.vertex.VertexFormatElement; -import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad; - import com.google.common.collect.ImmutableList; import net.minecraft.client.GameSettings; import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.renderer.Matrix4f; +import net.minecraft.client.renderer.TransformationMatrix; +import net.minecraft.client.renderer.Vector3f; +import net.minecraft.client.renderer.Vector4f; import net.minecraft.client.renderer.model.BakedQuad; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.renderer.vertex.VertexFormat; +import net.minecraft.client.renderer.vertex.VertexFormatElement; import net.minecraft.util.Direction; import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.model.pipeline.BakedQuadBuilder; public abstract class SimpleModelFontRenderer extends FontRenderer { private float r, g, b, a; private final TransformationMatrix transform; private ImmutableList.Builder builder = ImmutableList.builder(); - private final VertexFormat format; private final Vector3f normal = new Vector3f(0, 0, 1); private final Direction orientation; private boolean fillBlanks = false; private TextureAtlasSprite sprite; - public SimpleModelFontRenderer(GameSettings settings, ResourceLocation font, TextureManager manager, boolean isUnicode, Matrix4f matrix, VertexFormat format) + public SimpleModelFontRenderer(GameSettings settings, ResourceLocation font, TextureManager manager, boolean isUnicode, Matrix4f matrix) { super(manager, null); this.transform = new TransformationMatrix(matrix); - this.format = format; transform.transformNormal(normal); orientation = Direction.getFacingFromVector(normal.getX(), normal.getY(), normal.getZ()); } @@ -70,9 +67,9 @@ public abstract class SimpleModelFontRenderer extends FontRenderer { private final Vector4f vec = new Vector4f(); - private void addVertex(UnpackedBakedQuad.Builder quadBuilder, float x, float y, float u, float v) + private void addVertex(BakedQuadBuilder quadBuilder, float x, float y, float u, float v) { - ImmutableList elements = format.func_227894_c_(); + ImmutableList elements = quadBuilder.getVertexFormat().func_227894_c_(); for(int e = 0; e < elements.size(); e++) { VertexFormatElement element = elements.get(e); diff --git a/src/main/java/net/minecraftforge/client/model/animation/AnimationItemOverrideList.java b/src/main/java/net/minecraftforge/client/model/animation/AnimationItemOverrideList.java index 0316ad1e2..caf069ac7 100644 --- a/src/main/java/net/minecraftforge/client/model/animation/AnimationItemOverrideList.java +++ b/src/main/java/net/minecraftforge/client/model/animation/AnimationItemOverrideList.java @@ -27,7 +27,6 @@ import javax.annotation.Nullable; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.model.*; import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.vertex.VertexFormat; import net.minecraft.entity.LivingEntity; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; diff --git a/src/main/java/net/minecraftforge/client/model/b3d/B3DLoader.java b/src/main/java/net/minecraftforge/client/model/b3d/B3DLoader.java index 827ec20a8..dac331351 100644 --- a/src/main/java/net/minecraftforge/client/model/b3d/B3DLoader.java +++ b/src/main/java/net/minecraftforge/client/model/b3d/B3DLoader.java @@ -68,7 +68,6 @@ import com.google.gson.JsonParser; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.model.ItemCameraTransforms.TransformType; import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.vertex.VertexFormat; import net.minecraft.resources.IResource; import net.minecraft.resources.IResourceManager; import net.minecraft.util.Direction; @@ -83,7 +82,8 @@ import net.minecraftforge.client.model.b3d.B3DModel.Texture; import net.minecraftforge.client.model.b3d.B3DModel.Vertex; import net.minecraftforge.client.model.data.IDynamicBakedModel; import net.minecraftforge.client.model.data.IModelData; -import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad; +import net.minecraftforge.client.model.pipeline.BakedQuadBuilder; +import net.minecraftforge.client.model.pipeline.IVertexConsumer; import net.minecraftforge.common.model.animation.IClip; import net.minecraftforge.common.model.animation.IJoint; import net.minecraftforge.common.property.Properties; @@ -477,7 +477,7 @@ public enum B3DLoader implements ISelectiveResourceReloadListener } } builder.put("missingno", missing); - return new BakedWrapper(model.getRoot(), modelTransform, smooth, gui3d, DefaultVertexFormats.BLOCK, meshes, builder.build()); + return new BakedWrapper(model.getRoot(), modelTransform, smooth, gui3d, meshes, builder.build()); } public ModelWrapper retexture(ImmutableMap textures) @@ -597,16 +597,15 @@ public enum B3DLoader implements ISelectiveResourceReloadListener private final IModelTransform state; private final boolean smooth; private final boolean gui3d; - private final VertexFormat format; private final ImmutableSet meshes; private final ImmutableMap textures; private final LoadingCache cache; private ImmutableList quads; - public BakedWrapper(final Node node, final IModelTransform state, final boolean smooth, final boolean gui3d, final VertexFormat format, final ImmutableSet meshes, final ImmutableMap textures) + public BakedWrapper(final Node node, final IModelTransform state, final boolean smooth, final boolean gui3d, final ImmutableSet meshes, final ImmutableMap textures) { - this(node, state, smooth, gui3d, format, meshes, textures, CacheBuilder.newBuilder() + this(node, state, smooth, gui3d, meshes, textures, CacheBuilder.newBuilder() .maximumSize(128) .expireAfterAccess(2, TimeUnit.MINUTES) .build(new CacheLoader() @@ -626,13 +625,12 @@ public enum B3DLoader implements ISelectiveResourceReloadListener })); } - public BakedWrapper(Node node, IModelTransform state, boolean smooth, boolean gui3d, VertexFormat format, ImmutableSet meshes, ImmutableMap textures, LoadingCache cache) + public BakedWrapper(Node node, IModelTransform state, boolean smooth, boolean gui3d, ImmutableSet meshes, ImmutableMap textures, LoadingCache cache) { this.node = node; this.state = state; this.smooth = smooth; this.gui3d = gui3d; - this.format = format; this.meshes = meshes; this.textures = textures; this.cache = cache; @@ -713,7 +711,7 @@ public enum B3DLoader implements ISelectiveResourceReloadListener }); for(Face f : faces) { - UnpackedBakedQuad.Builder quadBuilder = new UnpackedBakedQuad.Builder(format); + BakedQuadBuilder quadBuilder = new BakedQuadBuilder(); quadBuilder.setContractUVs(true); quadBuilder.setQuadOrientation(Direction.getFacingFromVector(f.getNormal().getX(), f.getNormal().getY(), f.getNormal().getZ())); List textures = null; @@ -732,32 +730,32 @@ public enum B3DLoader implements ISelectiveResourceReloadListener } } - private final void putVertexData(UnpackedBakedQuad.Builder builder, Vertex v, Vector3f faceNormal, TextureAtlasSprite sprite) + private final void putVertexData(IVertexConsumer consumer, Vertex v, Vector3f faceNormal, TextureAtlasSprite sprite) { // TODO handle everything not handled (texture transformations, bones, transformations, normals, e.t.c) - ImmutableList vertexFormatElements = format.func_227894_c_(); + ImmutableList vertexFormatElements = consumer.getVertexFormat().func_227894_c_(); for(int e = 0; e < vertexFormatElements.size(); e++) { switch(vertexFormatElements.get(e).getUsage()) { case POSITION: - builder.put(e, v.getPos().getX(), v.getPos().getY(), v.getPos().getZ(), 1); + consumer.put(e, v.getPos().getX(), v.getPos().getY(), v.getPos().getZ(), 1); break; case COLOR: if(v.getColor() != null) { - builder.put(e, v.getColor().getX(), v.getColor().getY(), v.getColor().getZ(), v.getColor().getW()); + consumer.put(e, v.getColor().getX(), v.getColor().getY(), v.getColor().getZ(), v.getColor().getW()); } else { - builder.put(e, 1, 1, 1, 1); + consumer.put(e, 1, 1, 1, 1); } break; case UV: // TODO handle more brushes if(vertexFormatElements.get(e).getIndex() < v.getTexCoords().length) { - builder.put(e, + consumer.put(e, sprite.getInterpolatedU(v.getTexCoords()[0].getX() * 16), sprite.getInterpolatedV(v.getTexCoords()[0].getY() * 16), 0, @@ -766,21 +764,21 @@ public enum B3DLoader implements ISelectiveResourceReloadListener } else { - builder.put(e, 0, 0, 0, 1); + consumer.put(e, 0, 0, 0, 1); } break; case NORMAL: if(v.getNormal() != null) { - builder.put(e, v.getNormal().getX(), v.getNormal().getY(), v.getNormal().getZ(), 0); + consumer.put(e, v.getNormal().getX(), v.getNormal().getY(), v.getNormal().getZ(), 0); } else { - builder.put(e, faceNormal.getX(), faceNormal.getY(), faceNormal.getZ(), 0); + consumer.put(e, faceNormal.getX(), faceNormal.getY(), faceNormal.getZ(), 0); } break; default: - builder.put(e); + consumer.put(e); } } } diff --git a/src/main/java/net/minecraftforge/client/model/geometry/IModelGeometryPart.java b/src/main/java/net/minecraftforge/client/model/geometry/IModelGeometryPart.java index 3a8e76a2f..afb3f50dd 100644 --- a/src/main/java/net/minecraftforge/client/model/geometry/IModelGeometryPart.java +++ b/src/main/java/net/minecraftforge/client/model/geometry/IModelGeometryPart.java @@ -25,7 +25,6 @@ import net.minecraft.client.renderer.model.IUnbakedModel; import net.minecraft.client.renderer.model.Material; import net.minecraft.client.renderer.model.ModelBakery; import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.vertex.VertexFormat; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.model.IModelBuilder; import net.minecraftforge.client.model.IModelConfiguration; diff --git a/src/main/java/net/minecraftforge/client/model/obj/OBJModel.java b/src/main/java/net/minecraftforge/client/model/obj/OBJModel.java index e26e4e471..a85ebc203 100644 --- a/src/main/java/net/minecraftforge/client/model/obj/OBJModel.java +++ b/src/main/java/net/minecraftforge/client/model/obj/OBJModel.java @@ -29,8 +29,6 @@ import net.minecraft.client.renderer.Vector3f; import net.minecraft.client.renderer.Vector4f; import net.minecraft.client.renderer.model.*; import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import net.minecraft.client.renderer.vertex.VertexFormat; import net.minecraft.client.renderer.vertex.VertexFormatElement; import net.minecraft.util.Direction; import net.minecraft.util.ResourceLocation; @@ -39,8 +37,8 @@ import net.minecraft.util.math.Vec2f; import net.minecraftforge.client.model.*; import net.minecraftforge.client.model.geometry.IModelGeometryPart; import net.minecraftforge.client.model.geometry.IMultipartModelGeometry; +import net.minecraftforge.client.model.pipeline.BakedQuadBuilder; import net.minecraftforge.client.model.pipeline.IVertexConsumer; -import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad; import net.minecraftforge.common.model.TransformationHelper; import org.apache.commons.lang3.tuple.Pair; @@ -339,7 +337,7 @@ public class OBJModel implements IMultipartModelGeometry return Optional.ofNullable(parts.get(name)); } - private Pair makeQuad(int[][] indices, int tintIndex, Vector4f colorTint, Vector4f ambientColor, boolean isFullbright, TextureAtlasSprite texture, VertexFormat format, TransformationMatrix transform) + private Pair makeQuad(int[][] indices, int tintIndex, Vector4f colorTint, Vector4f ambientColor, boolean isFullbright, TextureAtlasSprite texture, TransformationMatrix transform) { boolean needsNormalRecalculation = false; for (int[] ints : indices) @@ -363,7 +361,7 @@ public class OBJModel implements IMultipartModelGeometry Vector4f[] pos = new Vector4f[4]; Vector3f[] norm = new Vector3f[4]; - UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(format); + BakedQuadBuilder builder = new BakedQuadBuilder(); builder.setQuadTint(tintIndex); builder.setTexture(texture); @@ -396,7 +394,7 @@ public class OBJModel implements IMultipartModelGeometry color.getY() * colorTint.getY(), color.getZ() * colorTint.getZ(), color.getW() * colorTint.getW()); - putVertexData(builder, format, position, texCoord, normal, tintedColor, uv2, texture); + putVertexData(builder, position, texCoord, normal, tintedColor, uv2, texture); pos[i] = position; norm[i] = normal; } @@ -459,9 +457,9 @@ public class OBJModel implements IMultipartModelGeometry return Pair.of(builder.build(), cull); } - private void putVertexData(IVertexConsumer consumer, VertexFormat format, Vector4f position0, Vec2f texCoord0, Vector3f normal0, Vector4f color0, Vec2f uv2, TextureAtlasSprite texture) + private void putVertexData(IVertexConsumer consumer, Vector4f position0, Vec2f texCoord0, Vector3f normal0, Vector4f color0, Vec2f uv2, TextureAtlasSprite texture) { - ImmutableList elements = format.func_227894_c_(); + ImmutableList elements = consumer.getVertexFormat().func_227894_c_(); for(int j=0;j for (int[][] face : mesh.faces) { - Pair quad = makeQuad(face, tintIndex, colorTint, mat.ambientColor, isFullbright, texture, DefaultVertexFormats.BLOCK, modelTransform.func_225615_b_()); + Pair quad = makeQuad(face, tintIndex, colorTint, mat.ambientColor, isFullbright, texture, modelTransform.func_225615_b_()); if (quad.getRight() == null) modelBuilder.addGeneralQuad(quad.getLeft()); else diff --git a/src/main/java/net/minecraftforge/client/model/pipeline/BakedQuadBuilder.java b/src/main/java/net/minecraftforge/client/model/pipeline/BakedQuadBuilder.java new file mode 100644 index 000000000..69c200b7b --- /dev/null +++ b/src/main/java/net/minecraftforge/client/model/pipeline/BakedQuadBuilder.java @@ -0,0 +1,192 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2019. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package net.minecraftforge.client.model.pipeline; + +import com.google.common.collect.ImmutableList; + +import net.minecraft.client.renderer.model.BakedQuad; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.client.renderer.vertex.VertexFormat; +import net.minecraft.client.renderer.vertex.VertexFormatElement; +import net.minecraft.util.Direction; + +// advantages: non-fixed-length vertex format, no overhead of packing and unpacking attributes to transform the model +// disadvantages: (possibly) larger memory footprint, overhead on packing the attributes at the final rendering stage +public class BakedQuadBuilder implements IVertexConsumer +{ + private static final int SIZE = DefaultVertexFormats.BLOCK.func_227894_c_().size(); + + private final float[][][] unpackedData; + private int tint = -1; + private Direction orientation; + private TextureAtlasSprite texture; + private boolean applyDiffuseLighting = true; + + private int vertices = 0; + private int elements = 0; + private boolean full = false; + private boolean contractUVs = false; + + public BakedQuadBuilder() + { + unpackedData = new float[4][SIZE][4]; + } + + public void setContractUVs(boolean value) + { + this.contractUVs = value; + } + + @Override + public VertexFormat getVertexFormat() + { + return DefaultVertexFormats.BLOCK; + } + + @Override + public void setQuadTint(int tint) + { + this.tint = tint; + } + + @Override + public void setQuadOrientation(Direction orientation) + { + this.orientation = orientation; + } + + // FIXME: move (or at least add) into constructor + @Override + public void setTexture(TextureAtlasSprite texture) + { + this.texture = texture; + } + + @Override + public void setApplyDiffuseLighting(boolean diffuse) + { + this.applyDiffuseLighting = diffuse; + } + + @Override + public void put(int element, float... data) + { + for(int i = 0; i < 4; i++) + { + if(i < data.length) + { + unpackedData[vertices][element][i] = data[i]; + } + else + { + unpackedData[vertices][element][i] = 0; + } + } + elements++; + if(elements == SIZE) + { + vertices++; + elements = 0; + } + if(vertices == 4) + { + full = true; + } + } + + private final float eps = 1f / 0x100; + + public BakedQuad build() + { + if(!full) + { + throw new IllegalStateException("not enough data"); + } + if(texture == null) + { + throw new IllegalStateException("texture not set"); + } + if(contractUVs) + { + float tX = texture.getWidth() / (texture.getMaxU() - texture.getMinU()); + float tY = texture.getHeight() / (texture.getMaxV() - texture.getMinV()); + float tS = tX > tY ? tX : tY; + float ep = 1f / (tS * 0x100); + int uve = 0; + ImmutableList elements = DefaultVertexFormats.BLOCK.func_227894_c_(); + while(uve < elements.size()) + { + VertexFormatElement e = elements.get(uve); + if(e.getUsage() == VertexFormatElement.Usage.UV && e.getIndex() == 0) + { + break; + } + uve++; + } + if(uve == elements.size()) + { + throw new IllegalStateException("Can't contract UVs: format doesn't contain UVs"); + } + float[] uvc = new float[4]; + for(int v = 0; v < 4; v++) + { + for(int i = 0; i < 4; i++) + { + uvc[i] += unpackedData[v][uve][i] / 4; + } + } + for(int v = 0; v < 4; v++) + { + for (int i = 0; i < 4; i++) + { + float uo = unpackedData[v][uve][i]; + float un = uo * (1 - eps) + uvc[i] * eps; + float ud = uo - un; + float aud = ud; + if(aud < 0) aud = -aud; + if(aud < ep) // not moving a fraction of a pixel + { + float udc = uo - uvc[i]; + if(udc < 0) udc = -udc; + if(udc < 2 * ep) // center is closer than 2 fractions of a pixel, don't move too close + { + un = (uo + uvc[i]) / 2; + } + else // move at least by a fraction + { + un = uo + (ud < 0 ? ep : -ep); + } + } + unpackedData[v][uve][i] = un; + } + } + } + int[] packed = new int[SIZE * 4]; + for (int v = 0; v < 4; v++) + { + for (int e = 0; e < SIZE; e++) + { + LightUtil.pack(unpackedData[v][e], packed, DefaultVertexFormats.BLOCK, v, e); + } + } + return new BakedQuad(packed, tint, orientation, texture, applyDiffuseLighting); + } +} diff --git a/src/main/java/net/minecraftforge/client/model/pipeline/LightUtil.java b/src/main/java/net/minecraftforge/client/model/pipeline/LightUtil.java index 2f65908a9..24737df7d 100644 --- a/src/main/java/net/minecraftforge/client/model/pipeline/LightUtil.java +++ b/src/main/java/net/minecraftforge/client/model/pipeline/LightUtil.java @@ -96,7 +96,7 @@ public class LightUtil consumer.setApplyDiffuseLighting(quad.shouldApplyDiffuseLighting()); float[] data = new float[4]; VertexFormat formatFrom = consumer.getVertexFormat(); - VertexFormat formatTo = quad.getFormat(); + VertexFormat formatTo = DefaultVertexFormats.BLOCK; int countFrom = formatFrom.func_227894_c_().size(); int countTo = formatTo.func_227894_c_().size(); int[] eMap = mapFormats(formatFrom, formatTo); diff --git a/src/main/java/net/minecraftforge/client/model/pipeline/UnpackedBakedQuad.java b/src/main/java/net/minecraftforge/client/model/pipeline/UnpackedBakedQuad.java deleted file mode 100644 index 79364b452..000000000 --- a/src/main/java/net/minecraftforge/client/model/pipeline/UnpackedBakedQuad.java +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Minecraft Forge - * Copyright (c) 2016-2019. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation version 2.1 - * of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -package net.minecraftforge.client.model.pipeline; - -import com.google.common.collect.ImmutableList; -import net.minecraft.client.renderer.model.BakedQuad; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.vertex.VertexFormat; -import net.minecraft.client.renderer.vertex.VertexFormatElement; -import net.minecraft.util.Direction; - -// advantages: non-fixed-length vertex format, no overhead of packing and unpacking attributes to transform the model -// disadvantages: (possibly) larger memory footprint, overhead on packing the attributes at the final rendering stage -public class UnpackedBakedQuad extends BakedQuad -{ - protected final float[][][] unpackedData; - protected final VertexFormat format; - protected boolean packed = false; - - public UnpackedBakedQuad(float[][][] unpackedData, int tint, Direction orientation, TextureAtlasSprite texture, boolean applyDiffuseLighting, VertexFormat format) - { - super(new int[format.getSize() /* / 4 * 4 */], tint, orientation, texture, applyDiffuseLighting, format); - this.unpackedData = unpackedData; - this.format = format; - } - - @Override - public int[] getVertexData() - { - if(!packed) - { - packed = true; - for(int v = 0; v < 4; v++) - { - for(int e = 0; e < format.func_227894_c_().size(); e++) - { - LightUtil.pack(unpackedData[v][e], vertexData, format, v, e); - } - } - } - return vertexData; - } - - @Override - public void pipe(IVertexConsumer consumer) - { - int[] eMap = LightUtil.mapFormats(consumer.getVertexFormat(), format); - - if(hasTintIndex()) - { - consumer.setQuadTint(getTintIndex()); - } - consumer.setTexture(sprite); - consumer.setApplyDiffuseLighting(applyDiffuseLighting); - consumer.setQuadOrientation(getFace()); - for(int v = 0; v < 4; v++) - { - for(int e = 0; e < consumer.getVertexFormat().func_227894_c_().size(); e++) - { - if(eMap[e] != format.func_227894_c_().size()) - { - consumer.put(e, unpackedData[v][eMap[e]]); - } - else - { - consumer.put(e); - } - } - } - } - - public static class Builder implements IVertexConsumer - { - private final VertexFormat format; - private final float[][][] unpackedData; - private int tint = -1; - private Direction orientation; - private TextureAtlasSprite texture; - private boolean applyDiffuseLighting = true; - - private int vertices = 0; - private int elements = 0; - private boolean full = false; - private boolean contractUVs = false; - - public Builder(VertexFormat format) - { - this.format = format; - unpackedData = new float[4][format.func_227894_c_().size()][4]; - } - - @Override - public VertexFormat getVertexFormat() - { - return format; - } - - public void setContractUVs(boolean value) - { - this.contractUVs = value; - } - @Override - public void setQuadTint(int tint) - { - this.tint = tint; - } - - @Override - public void setQuadOrientation(Direction orientation) - { - this.orientation = orientation; - } - - // FIXME: move (or at least add) into constructor - @Override - public void setTexture(TextureAtlasSprite texture) - { - this.texture = texture; - } - - @Override - public void setApplyDiffuseLighting(boolean diffuse) - { - this.applyDiffuseLighting = diffuse; - } - - @Override - public void put(int element, float... data) - { - for(int i = 0; i < 4; i++) - { - if(i < data.length) - { - unpackedData[vertices][element][i] = data[i]; - } - else - { - unpackedData[vertices][element][i] = 0; - } - } - elements++; - if(elements == format.func_227894_c_().size()) - { - vertices++; - elements = 0; - } - if(vertices == 4) - { - full = true; - } - } - - private final float eps = 1f / 0x100; - - public UnpackedBakedQuad build() - { - if(!full) - { - throw new IllegalStateException("not enough data"); - } - if(texture == null) - { - throw new IllegalStateException("texture not set"); - } - if(contractUVs) - { - float tX = texture.getWidth() / (texture.getMaxU() - texture.getMinU()); - float tY = texture.getHeight() / (texture.getMaxV() - texture.getMinV()); - float tS = tX > tY ? tX : tY; - float ep = 1f / (tS * 0x100); - int uve = 0; - ImmutableList elements = format.func_227894_c_(); - while(uve < elements.size()) - { - VertexFormatElement e = elements.get(uve); - if(e.getUsage() == VertexFormatElement.Usage.UV && e.getIndex() == 0) - { - break; - } - uve++; - } - if(uve == elements.size()) - { - throw new IllegalStateException("Can't contract UVs: format doesn't contain UVs"); - } - float[] uvc = new float[4]; - for(int v = 0; v < 4; v++) - { - for(int i = 0; i < 4; i++) - { - uvc[i] += unpackedData[v][uve][i] / 4; - } - } - for(int v = 0; v < 4; v++) - { - for (int i = 0; i < 4; i++) - { - float uo = unpackedData[v][uve][i]; - float un = uo * (1 - eps) + uvc[i] * eps; - float ud = uo - un; - float aud = ud; - if(aud < 0) aud = -aud; - if(aud < ep) // not moving a fraction of a pixel - { - float udc = uo - uvc[i]; - if(udc < 0) udc = -udc; - if(udc < 2 * ep) // center is closer than 2 fractions of a pixel, don't move too close - { - un = (uo + uvc[i]) / 2; - } - else // move at least by a fraction - { - un = uo + (ud < 0 ? ep : -ep); - } - } - unpackedData[v][uve][i] = un; - } - } - } - return new UnpackedBakedQuad(unpackedData, tint, orientation, texture, applyDiffuseLighting, format); - } - } -} diff --git a/src/main/resources/forge.exc b/src/main/resources/forge.exc index d2e4c8ce5..304956a98 100644 --- a/src/main/resources/forge.exc +++ b/src/main/resources/forge.exc @@ -14,7 +14,7 @@ net/minecraft/client/renderer/FluidBlockRenderer.func_228797_a_(Lcom/mojang/blaz net/minecraft/client/renderer/FogRenderer.setupFog(Lnet/minecraft/client/renderer/ActiveRenderInfo;Lnet/minecraft/client/renderer/FogRenderer$FogType;FZF)V=|p_228372_0_,p_228372_1_,p_228372_2_,p_228372_3_,partialTicks -net/minecraft/client/renderer/model/BakedQuad.([IILnet/minecraft/util/Direction;Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;ZLnet/minecraft/client/renderer/vertex/VertexFormat;)V=|p_i46574_1_,p_i46574_2_,p_i46574_3_,p_i46574_4_,applyDiffuseLighting,format +net/minecraft/client/renderer/model/BakedQuad.([IILnet/minecraft/util/Direction;Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;Z)V=|p_i46574_1_,p_i46574_2_,p_i46574_3_,p_i46574_4_,applyDiffuseLighting net/minecraft/client/renderer/model/ModelBakery.getBakedModel(Lnet/minecraft/util/ResourceLocation;Lnet/minecraft/client/renderer/texture/IModelTransform;Ljava/util/function/Function;Lnet/minecraft/client/renderer/vertex/VertexFormat;)Lnet/minecraft/client/renderer/model/IBakedModel;=|p_217845_1_,p_217845_2_,textureGetter,format diff --git a/src/test/java/net/minecraftforge/debug/client/model/TRSRTransformerTest.java b/src/test/java/net/minecraftforge/debug/client/model/TRSRTransformerTest.java index 55b1b5cb4..cb2d824bd 100644 --- a/src/test/java/net/minecraftforge/debug/client/model/TRSRTransformerTest.java +++ b/src/test/java/net/minecraftforge/debug/client/model/TRSRTransformerTest.java @@ -19,7 +19,13 @@ package net.minecraftforge.debug.client.model; +import java.util.List; +import java.util.Random; + +import javax.annotation.Nullable; + import com.google.common.collect.ImmutableList; + import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.material.Material; @@ -37,8 +43,11 @@ import net.minecraft.util.Direction; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.ModelBakeEvent; import net.minecraftforge.client.model.QuadTransformer; +import net.minecraftforge.client.model.data.EmptyModelData; +import net.minecraftforge.client.model.data.IDynamicBakedModel; +import net.minecraftforge.client.model.data.IModelData; +import net.minecraftforge.client.model.pipeline.BakedQuadBuilder; import net.minecraftforge.client.model.pipeline.TRSRTransformer; -import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.model.TransformationHelper; import net.minecraftforge.event.RegistryEvent; @@ -47,10 +56,6 @@ import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.registries.ObjectHolder; -import javax.annotation.Nullable; -import java.util.List; -import java.util.Random; - @Mod(TRSRTransformerTest.MODID) public class TRSRTransformerTest { public static final String MODID = "trsr_transformer_test"; @@ -71,7 +76,7 @@ public class TRSRTransformerTest { } } - public class MyBakedModel implements IBakedModel + public class MyBakedModel implements IDynamicBakedModel { private final IBakedModel base; @@ -80,7 +85,7 @@ public class TRSRTransformerTest { } @Override - public List getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) { + public List getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand, IModelData data) { ImmutableList.Builder quads = new ImmutableList.Builder<>(); Quaternion rot = TransformationHelper.quatFromXYZ(new Vector3f(0, 45, 0), true); @@ -88,11 +93,11 @@ public class TRSRTransformerTest { TransformationMatrix trans = new TransformationMatrix(translation, rot, null, null).blockCenterToCorner(); - for (BakedQuad quad : base.getQuads(state, side, rand)) { + for (BakedQuad quad : base.getQuads(state, side, rand, data)) { if(true) { - UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(quad.getFormat()); + BakedQuadBuilder builder = new BakedQuadBuilder(); TRSRTransformer transformer = new TRSRTransformer(builder, trans); @@ -102,7 +107,7 @@ public class TRSRTransformerTest { } else { - QuadTransformer qt = new QuadTransformer(quad.getFormat(), trans); + QuadTransformer qt = new QuadTransformer(trans); quads.add(qt.processOne(quad)); } }