Fix crash when building BakedQuadBuilder

Add javadocs and move sprite to constructor where possible
This commit is contained in:
tterrag 2020-01-05 13:36:06 -05:00
parent 7c99b756f9
commit 3096608d4a
6 changed files with 17 additions and 19 deletions

View file

@ -364,10 +364,9 @@ public final class FluidModel implements IModelGeometry<FluidModel>
private BakedQuad buildQuad(Direction side, TextureAtlasSprite texture, boolean flip, boolean offset, VertexParameter x, VertexParameter y, VertexParameter z, VertexParameter u, VertexParameter v) private BakedQuad buildQuad(Direction side, TextureAtlasSprite texture, boolean flip, boolean offset, VertexParameter x, VertexParameter y, VertexParameter z, VertexParameter u, VertexParameter v)
{ {
BakedQuadBuilder builder = new BakedQuadBuilder(); BakedQuadBuilder builder = new BakedQuadBuilder(texture);
builder.setQuadOrientation(side); builder.setQuadOrientation(side);
builder.setTexture(texture);
builder.setQuadTint(0); builder.setQuadTint(0);
boolean hasTransform = !transformation.isIdentity(); boolean hasTransform = !transformation.isIdentity();

View file

@ -378,11 +378,10 @@ public final class ItemLayerModel implements IModelGeometry<ItemLayerModel>
float x2, float y2, float z2, float u2, float v2, float x2, float y2, float z2, float u2, float v2,
float x3, float y3, float z3, float u3, float v3) float x3, float y3, float z3, float u3, float v3)
{ {
BakedQuadBuilder builder = new BakedQuadBuilder(); BakedQuadBuilder builder = new BakedQuadBuilder(sprite);
builder.setQuadTint(tint); builder.setQuadTint(tint);
builder.setQuadOrientation(side); builder.setQuadOrientation(side);
builder.setTexture(sprite);
boolean hasTransform = !transform.isIdentity(); boolean hasTransform = !transform.isIdentity();
IVertexConsumer consumer = hasTransform ? new TRSRTransformer(builder, transform) : builder; IVertexConsumer consumer = hasTransform ? new TRSRTransformer(builder, transform) : builder;

View file

@ -234,11 +234,10 @@ public final class ItemTextureQuadConverter
float x1, float y1, float x2, float y2, float z, float x1, float y1, float x2, float y2, float z,
float u1, float v1, float u2, float v2) float u1, float v1, float u2, float v2)
{ {
BakedQuadBuilder builder = new BakedQuadBuilder(); BakedQuadBuilder builder = new BakedQuadBuilder(sprite);
builder.setQuadTint(tint); builder.setQuadTint(tint);
builder.setQuadOrientation(side); builder.setQuadOrientation(side);
builder.setTexture(sprite);
// only apply the transform if it's not identity // only apply the transform if it's not identity
boolean hasTransform = !transform.isIdentity(); boolean hasTransform = !transform.isIdentity();

View file

@ -711,16 +711,15 @@ public enum B3DLoader implements ISelectiveResourceReloadListener
}); });
for(Face f : faces) for(Face f : faces)
{ {
BakedQuadBuilder quadBuilder = new BakedQuadBuilder();
quadBuilder.setContractUVs(true);
quadBuilder.setQuadOrientation(Direction.getFacingFromVector(f.getNormal().getX(), f.getNormal().getY(), f.getNormal().getZ()));
List<Texture> textures = null; List<Texture> textures = null;
if(f.getBrush() != null) textures = f.getBrush().getTextures(); if(f.getBrush() != null) textures = f.getBrush().getTextures();
TextureAtlasSprite sprite; TextureAtlasSprite sprite;
if(textures == null || textures.isEmpty()) sprite = this.textures.get("missingno"); if(textures == null || textures.isEmpty()) sprite = this.textures.get("missingno");
else if(textures.get(0) == B3DModel.Texture.White) sprite = ModelLoader.White.instance(); else if(textures.get(0) == B3DModel.Texture.White) sprite = ModelLoader.White.instance();
else sprite = this.textures.get(textures.get(0).getPath()); else sprite = this.textures.get(textures.get(0).getPath());
quadBuilder.setTexture(sprite); BakedQuadBuilder quadBuilder = new BakedQuadBuilder(sprite);
quadBuilder.setContractUVs(true);
quadBuilder.setQuadOrientation(Direction.getFacingFromVector(f.getNormal().getX(), f.getNormal().getY(), f.getNormal().getZ()));
putVertexData(quadBuilder, f.getV1(), f.getNormal(), sprite); putVertexData(quadBuilder, f.getV1(), f.getNormal(), sprite);
putVertexData(quadBuilder, f.getV2(), f.getNormal(), sprite); putVertexData(quadBuilder, f.getV2(), f.getNormal(), sprite);
putVertexData(quadBuilder, f.getV3(), f.getNormal(), sprite); putVertexData(quadBuilder, f.getV3(), f.getNormal(), sprite);

View file

@ -361,10 +361,9 @@ public class OBJModel implements IMultipartModelGeometry<OBJModel>
Vector4f[] pos = new Vector4f[4]; Vector4f[] pos = new Vector4f[4];
Vector3f[] norm = new Vector3f[4]; Vector3f[] norm = new Vector3f[4];
BakedQuadBuilder builder = new BakedQuadBuilder(); BakedQuadBuilder builder = new BakedQuadBuilder(texture);
builder.setQuadTint(tintIndex); builder.setQuadTint(tintIndex);
builder.setTexture(texture);
builder.setApplyDiffuseLighting(!isFullbright); builder.setApplyDiffuseLighting(!isFullbright);
int fakeLight = (int)((ambientColor.getX() + ambientColor.getY() + ambientColor.getZ()) * 15 / 3.0f); int fakeLight = (int)((ambientColor.getX() + ambientColor.getY() + ambientColor.getZ()) * 15 / 3.0f);

View file

@ -28,13 +28,15 @@ import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.renderer.vertex.VertexFormatElement; import net.minecraft.client.renderer.vertex.VertexFormatElement;
import net.minecraft.util.Direction; 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 * Allows easier building of BakedQuad objects. During building, data is stored
* unpacked as floats, but is packed into the typical int array format on build.
*/
public class BakedQuadBuilder implements IVertexConsumer public class BakedQuadBuilder implements IVertexConsumer
{ {
private static final int SIZE = DefaultVertexFormats.BLOCK.func_227894_c_().size(); private static final int SIZE = DefaultVertexFormats.BLOCK.func_227894_c_().size();
private final float[][][] unpackedData; private final float[][][] unpackedData = new float[4][SIZE][4];
private int tint = -1; private int tint = -1;
private Direction orientation; private Direction orientation;
private TextureAtlasSprite texture; private TextureAtlasSprite texture;
@ -45,9 +47,11 @@ public class BakedQuadBuilder implements IVertexConsumer
private boolean full = false; private boolean full = false;
private boolean contractUVs = false; private boolean contractUVs = false;
public BakedQuadBuilder() public BakedQuadBuilder() {}
public BakedQuadBuilder(TextureAtlasSprite texture)
{ {
unpackedData = new float[4][SIZE][4]; this.texture = texture;
} }
public void setContractUVs(boolean value) public void setContractUVs(boolean value)
@ -73,7 +77,6 @@ public class BakedQuadBuilder implements IVertexConsumer
this.orientation = orientation; this.orientation = orientation;
} }
// FIXME: move (or at least add) into constructor
@Override @Override
public void setTexture(TextureAtlasSprite texture) public void setTexture(TextureAtlasSprite texture)
{ {
@ -179,7 +182,7 @@ public class BakedQuadBuilder implements IVertexConsumer
} }
} }
} }
int[] packed = new int[SIZE * 4]; int[] packed = new int[DefaultVertexFormats.BLOCK.getIntegerSize() * 4];
for (int v = 0; v < 4; v++) for (int v = 0; v < 4; v++)
{ {
for (int e = 0; e < SIZE; e++) for (int e = 0; e < SIZE; e++)