-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmethods.java
More file actions
117 lines (100 loc) · 3.22 KB
/
methods.java
File metadata and controls
117 lines (100 loc) · 3.22 KB
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
107
108
109
110
111
112
113
114
115
116
117
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.List;
import java.io.IOException;
class float2 {
public float x, y;
public float2(float x, float y) {
this.x = x;
this.y = y;
}
}
class float3 {
public float x, y, z;
public float3(float x, float y, float z) {
this.x = x;
this.y = y;
this.z = z;
}
}
class screen {
public int x_res, y_res;
public float3 color;
public screen(int x_res, int y_res , float3 color) {
this.x_res = x_res;
this.y_res = y_res;
this.color = color;
}
}
class triangle {
public float3 a, b, c;
public triangle(float3 a, float3 b, float3 c) {
this.a = a;
this.b = b;
this.c = c;
}
}
public class methods {
public static float3[][] generateTestImage(screen scrn) {
float3[][] image = new float3[scrn.x_res][scrn.y_res];
for (int y = 0; y < scrn.y_res; y++) {
for (int x = 0; x < scrn.x_res; x++) {
float r = x / (float)(scrn.x_res - 1);
float g = y / (float)(scrn.y_res - 1);
image[x][y] = new float3(r, g, 0f);
}
}
return image;
}
public static void generateParseMetadata(String input_filename) throws IOException {
OBJParser parser = new OBJParser(input_filename);
List<float3> vertices = parser.parse("v");
List<float3> normals = parser.parse("vn");
List<float3> textures = parser.parse("vt");
List<float3> faces = parser.parse("f");
BufferedWriter out = new BufferedWriter(new FileWriter(input_filename + ".json"));
out.write("{\n");
out.write(" \"vertices\": [\n");
for (int i = 0; i < vertices.size(); i++) {
float3 v = vertices.get(i);
out.write(" {\"x\": " + v.x + ", \"y\": " + v.y + ", \"z\": " + v.z + "}");
if (i < vertices.size() - 1) {
out.write(",");
}
out.write("\n");
}
out.write(" ],\n");
out.write(" \"normals\": [\n");
for (int i = 0; i < normals.size(); i++) {
float3 n = normals.get(i);
out.write(" {\"x\": " + n.x + ", \"y\": " + n.y + ", \"z\": " + n.z + "}");
if (i < normals.size() - 1) {
out.write(",");
}
out.write("\n");
}
out.write(" ],\n");
out.write(" \"textures\": [\n");
for (int i = 0; i < textures.size(); i++) {
float3 t = textures.get(i);
out.write(" {\"x\": " + t.x + ", \"y\": " + t.y + ", \"z\": " + t.z + "}");
if (i < textures.size() - 1) {
out.write(",");
}
out.write("\n");
}
out.write(" ],\n");
out.write(" \"faces\": [\n");
for (int i = 0; i < faces.size(); i++) {
float3 f = faces.get(i);
out.write(" {\"x\": " + f.x + ", \"y\": " + f.y + ", \"z\": " + f.z + "}");
if (i < faces.size() - 1) {
out.write(",");
}
out.write("\n");
}
out.write(" ]\n");
out.write("}\n");
out.close();
}
}