@@ -99,14 +99,14 @@ class ObjModelLoader : Model3DLoader {
9999 // f v1
100100 1 -> {
101101 data.currentGroup.currentSubGroup.faces + = faceVertex[0 ].toInt() - 1
102- data.currentGroup.currentSubGroup.faces + = 0
102+ // add vt1 as 0
103103 data.currentGroup.currentSubGroup.faces + = 0
104104 }
105105
106106 // f v1/vt1
107107 2 -> {
108108 data.currentGroup.currentSubGroup.faces + = faceVertex[0 ].toInt() - 1
109- data.currentGroup.currentSubGroup.faces + = 0
109+ // add vt1
110110 data.currentGroup.currentSubGroup.faces + = faceVertex[1 ].toInt() - 1
111111 }
112112
@@ -115,7 +115,9 @@ class ObjModelLoader : Model3DLoader {
115115 3 -> {
116116 data.currentGroup.currentSubGroup.faces + = faceVertex[0 ].toInt() - 1
117117 data.currentGroup.currentSubGroup.faces + = faceVertex[2 ].toInt() - 1
118+ // add vt1 if present, else 0
118119 data.currentGroup.currentSubGroup.faces + = (faceVertex[1 ].toIntOrNull() ? : 1 ) - 1
120+ data.currentGroup.currentSubGroup.vertexFormat = VertexFormat .POINT_NORMAL_TEXCOORD
119121 }
120122 }
121123 }
@@ -237,7 +239,7 @@ class ObjModelLoader : Model3DLoader {
237239 // TODO: ?
238240 if (! it.faces.isEmpty()) {
239241
240- val mesh = TriangleMesh (VertexFormat . POINT_NORMAL_TEXCOORD )
242+ val mesh = TriangleMesh (it.vertexFormat )
241243
242244 mesh.points.addAll(* data.vertices.map { it * 0.05f }.toFloatArray())
243245
@@ -248,11 +250,13 @@ class ObjModelLoader : Model3DLoader {
248250 mesh.texCoords.addAll(* data.vertexTextures.toFloatArray())
249251 }
250252
251- // if there are no vertex normals, just add 3 values
252- if (data.vertexNormals.isEmpty()) {
253- mesh.normals.addAll(* FloatArray (3 ) { _ -> 0.0f })
254- } else {
255- mesh.normals.addAll(* data.vertexNormals.toFloatArray())
253+ if (it.vertexFormat == = VertexFormat .POINT_NORMAL_TEXCOORD ) {
254+ // if there are no vertex normals, just add 3 values
255+ if (data.vertexNormals.isEmpty()) {
256+ mesh.normals.addAll(* FloatArray (3 ) { _ -> 0.0f })
257+ } else {
258+ mesh.normals.addAll(* data.vertexNormals.toFloatArray())
259+ }
256260 }
257261
258262 mesh.faces.addAll(* it.faces.toIntArray())
0 commit comments