-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReader.java
106 lines (102 loc) · 3.91 KB
/
Reader.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
/**
* Created by Rezenter on 12/1/15.
*/
public class Reader {
final static String PATH = "/objects/";
static String name;
static ArrayList<Vector3f> res;
static ArrayList<Vector3f> cons;
static String colour;
static String file;
static ArrayList<Obj> objects;
static int count;
static int num;
static int currNum;
public Reader(String nnn) throws IOException {
res = new ArrayList<Vector3f>();
cons = new ArrayList<Vector3f>();
colour = "";
file = "";
count = -1;
num = 0;
currNum = 0;
objects = new ArrayList<>();
name = nnn;
BufferedReader in =
new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(PATH + name +".obj")));
while (in.ready()) {
String curr = in.readLine();
if (curr.length() > 1) {
if (curr.charAt(0) == 'v' && curr.charAt(1) == ' ') {
String[] split = curr.split(" ");
float[] tmp = new float[3];
for (int i = 1; i < 4; i++) {
tmp[i - 1] = Float.parseFloat(split[i + 1]);
}
currNum++;
res.add(new Vector3f(tmp));
} else {
if (curr.charAt(0) == 'f') {
String[] split = curr.split(" ");
float[] tmp = new float[3];
for (int i = 1; i < 4; i++) {
tmp[i - 1] = Float.parseFloat(split[i]) - num;
}
cons.add(new Vector3f(tmp));
} else {
if (curr.charAt(0) == 'm') {
String[] split = curr.split(" ");
file = split[1];
} else {
if (curr.charAt(0) == '#' && curr.charAt(1) == ' ' && curr.charAt(2) == 'o') {
if (count != -1) {
objects.get(count).set(res, cons, colour);
}
count++;
cons.clear();
res.clear();
num = currNum;
objects.add(new Obj());
}
if (curr.charAt(0) == 'u') {
String[] split = curr.split(" ");
colour = split[1];
}
}
}
}
}
}
objects.get(count).set(res, cons, colour);
in.close();
in = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(PATH + file)));
String a = "";
while (in.ready()) {
String curr = in.readLine();
if (curr.length() > 1) {
if (curr.charAt(0) == 'n' && curr.charAt(1) == 'e') {
String[] split = curr.split(" ");
a = split[1];
} else {
if (curr.charAt(0) == '\t' && curr.charAt(1) == 'K' && curr.charAt(2) == 'd') {
String[] cols = curr.split(" ");
for (Obj t : objects) {
if (t.getCol().equals(a)) {
t.setCol(new Vector3f(Float.parseFloat(cols[1]), Float.parseFloat(cols[2]),
Float.parseFloat(cols[3])));
}
}
}
}
}
}
in.close();
}
public static ArrayList<Obj> pointReader(){
return objects;
}
}