Guard against models providing quads with null orientations.

This commit is contained in:
covers1624
2018-11-29 15:02:47 +10:30
committed by yueh
parent 06cca13087
commit 184b1f8efb
@@ -46,7 +46,6 @@ public class Quad implements IVertexProducer, ISmartVertexConsumer
public CachedFormat format;
public int tintIndex = -1;
// TODO, sometimes this is null because people don't do models properly.
public EnumFacing orientation;
public boolean diffuseLighting = true;
public TextureAtlasSprite sprite;
@@ -130,6 +129,10 @@ public class Quad implements IVertexProducer, ISmartVertexConsumer
{
this.vertexIndex = 0;
this.full = true;
if(orientation == null)
{
calculateOrientation(false);
}
}
}
}
@@ -195,7 +198,17 @@ public class Quad implements IVertexProducer, ISmartVertexConsumer
vec[1] = (float) MathHelper.clamp( vec[1], bb.minY, bb.maxY );
vec[2] = (float) MathHelper.clamp( vec[2], bb.minZ, bb.maxZ );
}
calculateOrientation(true);
}
/**
* Re-calculates the Orientation of this quad,
* optionally the normal vector.
*
* @param setNormal If the normal vector should be updated.
*/
public void calculateOrientation( boolean setNormal )
{
this.v1.set( this.vertices[3].vec );
this.t.set( this.vertices[1].vec );
this.v1.sub( this.t );
@@ -207,7 +220,7 @@ public class Quad implements IVertexProducer, ISmartVertexConsumer
this.normal.cross( this.v2, this.v1 );
this.normal.normalize();
if( this.format.hasNormal )
if( this.format.hasNormal && setNormal)
{
for( Vertex vertex : this.vertices )
{