@@ -99,14 +99,14 @@ class ObjModelLoader : Model3DLoader {
99
99
// f v1
100
100
1 -> {
101
101
data.currentGroup.currentSubGroup.faces + = faceVertex[0 ].toInt() - 1
102
- data.currentGroup.currentSubGroup.faces + = 0
102
+ // add vt1 as 0
103
103
data.currentGroup.currentSubGroup.faces + = 0
104
104
}
105
105
106
106
// f v1/vt1
107
107
2 -> {
108
108
data.currentGroup.currentSubGroup.faces + = faceVertex[0 ].toInt() - 1
109
- data.currentGroup.currentSubGroup.faces + = 0
109
+ // add vt1
110
110
data.currentGroup.currentSubGroup.faces + = faceVertex[1 ].toInt() - 1
111
111
}
112
112
@@ -115,7 +115,9 @@ class ObjModelLoader : Model3DLoader {
115
115
3 -> {
116
116
data.currentGroup.currentSubGroup.faces + = faceVertex[0 ].toInt() - 1
117
117
data.currentGroup.currentSubGroup.faces + = faceVertex[2 ].toInt() - 1
118
+ // add vt1 if present, else 0
118
119
data.currentGroup.currentSubGroup.faces + = (faceVertex[1 ].toIntOrNull() ? : 1 ) - 1
120
+ data.currentGroup.currentSubGroup.vertexFormat = VertexFormat .POINT_NORMAL_TEXCOORD
119
121
}
120
122
}
121
123
}
@@ -237,7 +239,7 @@ class ObjModelLoader : Model3DLoader {
237
239
// TODO: ?
238
240
if (! it.faces.isEmpty()) {
239
241
240
- val mesh = TriangleMesh (VertexFormat . POINT_NORMAL_TEXCOORD )
242
+ val mesh = TriangleMesh (it.vertexFormat )
241
243
242
244
mesh.points.addAll(* data.vertices.map { it * 0.05f }.toFloatArray())
243
245
@@ -248,11 +250,13 @@ class ObjModelLoader : Model3DLoader {
248
250
mesh.texCoords.addAll(* data.vertexTextures.toFloatArray())
249
251
}
250
252
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
+ }
256
260
}
257
261
258
262
mesh.faces.addAll(* it.faces.toIntArray())
0 commit comments