|
@@ -10,6 +10,7 @@ import java.io.FileNotFoundException;
|
|
|
import java.io.FileReader;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
|
@Slf4j
|
|
@@ -31,54 +32,7 @@ public class OBJReader {
|
|
|
return Points;
|
|
|
}
|
|
|
|
|
|
- public static ArrayList<Face> getFace(File OBJFile, File MTLFile) throws FileNotFoundException {
|
|
|
- BufferedReader reader = new BufferedReader(new FileReader(OBJFile));
|
|
|
- ArrayList<Face> Faces = new ArrayList<>();
|
|
|
- AtomicReference<HashMap<String, Color>> materials = new AtomicReference<>(new HashMap<>());
|
|
|
- AtomicReference<Color> color = new AtomicReference<>(new Color(0, 0, 0));
|
|
|
- reader.lines().forEach(l -> {
|
|
|
- try {
|
|
|
- materials.set(MTLReader.getColors(MTLFile));
|
|
|
- } catch (FileNotFoundException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
-
|
|
|
- if (l.startsWith("usemtl")) {
|
|
|
- color.set(materials.get().get(l.split(" ")[1]));
|
|
|
- }
|
|
|
-
|
|
|
- if (l.startsWith("f")) {
|
|
|
- Face face = new Face();
|
|
|
- String substring = l.substring(2);
|
|
|
- String[] cord = substring.split(" ");
|
|
|
- if (cord.length == 3) {
|
|
|
- for (int i = 0; i < cord.length; i++) {
|
|
|
- String id = cord[i].split("/")[0];
|
|
|
- face.points.add(Integer.valueOf(id));
|
|
|
- }
|
|
|
-
|
|
|
- face.color = color.get();
|
|
|
-
|
|
|
- Faces.add(face);
|
|
|
- } else if (cord.length == 4) {
|
|
|
- for (int i = 0; i < cord.length; i++) {
|
|
|
- String id = cord[i].split("/")[0];
|
|
|
- face.points.add(Integer.valueOf(id));
|
|
|
- }
|
|
|
- face.Has4Point = true;
|
|
|
-
|
|
|
- face.color = color.get();
|
|
|
-
|
|
|
- Faces.add(face);
|
|
|
- } else {
|
|
|
- log.error("A face had more than 4 point, ignoring it");
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- return Faces;
|
|
|
- }
|
|
|
-
|
|
|
- public static ArrayList<Face> getFaceAnimation(File OBJFile, File MTLFile) throws FileNotFoundException {
|
|
|
+ public static ArrayList<Face> getFaces(File OBJFile, File MTLFile) throws FileNotFoundException {
|
|
|
BufferedReader reader = new BufferedReader(new FileReader(OBJFile));
|
|
|
ArrayList<Face> Faces = new ArrayList<>();
|
|
|
AtomicReference<HashMap<String, Color>> materials = new AtomicReference<>(new HashMap<>());
|
|
@@ -99,7 +53,7 @@ public class OBJReader {
|
|
|
if (cord.length == 3) {
|
|
|
for (int i = 0; i < cord.length; i++) {
|
|
|
String id = cord[i].split("/")[0];
|
|
|
- face.points.add(Integer.valueOf(id));
|
|
|
+ face.pointsIndex.add(Integer.valueOf(id));
|
|
|
}
|
|
|
|
|
|
face.color = color.get();
|
|
@@ -108,7 +62,7 @@ public class OBJReader {
|
|
|
} else if (cord.length == 4) {
|
|
|
for (int i = 0; i < cord.length; i++) {
|
|
|
String id = cord[i].split("/")[0];
|
|
|
- face.points.add(Integer.valueOf(id));
|
|
|
+ face.pointsIndex.add(Integer.valueOf(id));
|
|
|
}
|
|
|
face.Has4Point = true;
|
|
|
|
|
@@ -118,6 +72,14 @@ public class OBJReader {
|
|
|
} else {
|
|
|
log.error("A face had more than 4 point, ignoring it");
|
|
|
}
|
|
|
+ try {
|
|
|
+ List<Vector4f> p = getPoints(OBJFile);
|
|
|
+ for (Integer index : face.pointsIndex) {
|
|
|
+ face.points.add(p.get(index-1));
|
|
|
+ }
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
return Faces;
|