Fix a derp in that we provision the various arrays for a face, even if we are not going to parse data into it. Solves NPEs for when obj models that don't have texture coordinates attempt to render.
This commit is contained in:
parent
3818ffdf56
commit
6bb839e13c
|
@ -31,7 +31,7 @@ public class Face
|
||||||
float averageU = 0F;
|
float averageU = 0F;
|
||||||
float averageV = 0F;
|
float averageV = 0F;
|
||||||
|
|
||||||
if (textureCoordinates.length != 0)
|
if ((textureCoordinates != null) && (textureCoordinates.length != 0))
|
||||||
{
|
{
|
||||||
for (int i = 0; i < textureCoordinates.length; ++i)
|
for (int i = 0; i < textureCoordinates.length; ++i)
|
||||||
{
|
{
|
||||||
|
@ -48,7 +48,7 @@ public class Face
|
||||||
for (int i = 0; i < vertices.length; ++i)
|
for (int i = 0; i < vertices.length; ++i)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (textureCoordinates.length != 0)
|
if ((textureCoordinates != null) && (textureCoordinates.length != 0))
|
||||||
{
|
{
|
||||||
offsetU = textureOffset;
|
offsetU = textureOffset;
|
||||||
offsetV = textureOffset;
|
offsetV = textureOffset;
|
||||||
|
|
|
@ -341,13 +341,13 @@ public class WavefrontObject implements IModelCustom
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// f v1/vt1/vn1 v2/vt2/vn2 v3/vt3/vn3 ...
|
||||||
|
if (isValidFace_V_VT_VN_Line(line))
|
||||||
|
{
|
||||||
face.vertices = new Vertex[tokens.length];
|
face.vertices = new Vertex[tokens.length];
|
||||||
face.textureCoordinates = new TextureCoordinate[tokens.length];
|
face.textureCoordinates = new TextureCoordinate[tokens.length];
|
||||||
face.vertexNormals = new Vertex[tokens.length];
|
face.vertexNormals = new Vertex[tokens.length];
|
||||||
|
|
||||||
// f v1/vt1/vn1 v2/vt2/vn2 v3/vt3/vn3 ...
|
|
||||||
if (isValidFace_V_VT_VN_Line(line))
|
|
||||||
{
|
|
||||||
for (int i = 0; i < tokens.length; ++i)
|
for (int i = 0; i < tokens.length; ++i)
|
||||||
{
|
{
|
||||||
subTokens = tokens[i].split("/");
|
subTokens = tokens[i].split("/");
|
||||||
|
@ -362,6 +362,9 @@ public class WavefrontObject implements IModelCustom
|
||||||
// f v1/vt1 v2/vt2 v3/vt3 ...
|
// f v1/vt1 v2/vt2 v3/vt3 ...
|
||||||
else if (isValidFace_V_VT_Line(line))
|
else if (isValidFace_V_VT_Line(line))
|
||||||
{
|
{
|
||||||
|
face.vertices = new Vertex[tokens.length];
|
||||||
|
face.textureCoordinates = new TextureCoordinate[tokens.length];
|
||||||
|
|
||||||
for (int i = 0; i < tokens.length; ++i)
|
for (int i = 0; i < tokens.length; ++i)
|
||||||
{
|
{
|
||||||
subTokens = tokens[i].split("/");
|
subTokens = tokens[i].split("/");
|
||||||
|
@ -375,6 +378,9 @@ public class WavefrontObject implements IModelCustom
|
||||||
// f v1//vn1 v2//vn2 v3//vn3 ...
|
// f v1//vn1 v2//vn2 v3//vn3 ...
|
||||||
else if (isValidFace_V_VN_Line(line))
|
else if (isValidFace_V_VN_Line(line))
|
||||||
{
|
{
|
||||||
|
face.vertices = new Vertex[tokens.length];
|
||||||
|
face.vertexNormals = new Vertex[tokens.length];
|
||||||
|
|
||||||
for (int i = 0; i < tokens.length; ++i)
|
for (int i = 0; i < tokens.length; ++i)
|
||||||
{
|
{
|
||||||
subTokens = tokens[i].split("//");
|
subTokens = tokens[i].split("//");
|
||||||
|
@ -388,6 +394,8 @@ public class WavefrontObject implements IModelCustom
|
||||||
// f v1 v2 v3 ...
|
// f v1 v2 v3 ...
|
||||||
else if (isValidFace_V_Line(line))
|
else if (isValidFace_V_Line(line))
|
||||||
{
|
{
|
||||||
|
face.vertices = new Vertex[tokens.length];
|
||||||
|
|
||||||
for (int i = 0; i < tokens.length; ++i)
|
for (int i = 0; i < tokens.length; ++i)
|
||||||
{
|
{
|
||||||
face.vertices[i] = vertices.get(Integer.parseInt(tokens[i]) - 1);
|
face.vertices[i] = vertices.get(Integer.parseInt(tokens[i]) - 1);
|
||||||
|
|
Loading…
Reference in New Issue