Skip to content

Commit 1c89312

Browse files
committed
Format changes.
1 parent 51594ea commit 1c89312

File tree

4 files changed

+175
-185
lines changed

4 files changed

+175
-185
lines changed

src/main/java/workspace/render/ColorGenerator.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44

55
public class ColorGenerator {
66

7-
private int i = 0;
8-
9-
public Color next() {
10-
i++;
11-
java.awt.Color c = new java.awt.Color(i);
12-
Color c1 = Color.getColorFromInt(c.getRed(), c.getGreen(), c.getBlue());
13-
return c1;
14-
}
15-
7+
private int i = 0;
8+
9+
public Color next() {
10+
i++;
11+
java.awt.Color c = new java.awt.Color(i);
12+
Color c1 = Color.getColorFromInt(c.getRed(), c.getGreen(), c.getBlue());
13+
return c1;
14+
}
1615
}

src/main/java/workspace/render/ObjectSelectionRender.java

Lines changed: 83 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -12,112 +12,108 @@
1212

1313
public class ObjectSelectionRender {
1414

15-
private ColorGenerator generator;
15+
private ColorGenerator generator;
1616

17-
private int width;
17+
private int width;
1818

19-
private int height;
19+
private int height;
2020

21-
private PApplet p;
21+
private PApplet p;
2222

23-
private PGraphics3D g3d;
23+
private PGraphics3D g3d;
2424

25-
private HashMap<Integer, String> colorToObjectName;
25+
private HashMap<Integer, String> colorToObjectName;
2626

27-
private HashMap<String, Integer> nameToColor;
27+
private HashMap<String, Integer> nameToColor;
2828

29-
public ObjectSelectionRender(PApplet p) {
30-
colorToObjectName = new HashMap<Integer, String>();
31-
nameToColor = new HashMap<String, Integer>();
32-
generator = new ColorGenerator();
33-
this.p = p;
34-
g3d = (PGraphics3D) p.createGraphics(p.width, p.height, PApplet.P3D);
35-
p.registerMethod("pre", this);
36-
}
37-
38-
public void pre() {
39-
if (p.width != this.width || p.height != this.height) {
40-
this.width = p.width;
41-
this.height = p.height;
42-
g3d = (PGraphics3D) p
43-
.createGraphics(p.width, p.height, PApplet.P3D);
44-
}
45-
}
29+
public ObjectSelectionRender(PApplet p) {
30+
colorToObjectName = new HashMap<Integer, String>();
31+
nameToColor = new HashMap<String, Integer>();
32+
generator = new ColorGenerator();
33+
this.p = p;
34+
g3d = (PGraphics3D) p.createGraphics(p.width, p.height, PApplet.P3D);
35+
p.registerMethod("pre", this);
36+
}
4637

47-
public String getObject(int x, int y) {
48-
int color = getColor(x, y);
49-
return colorToObjectName.get(color);
38+
public void pre() {
39+
if (p.width != this.width || p.height != this.height) {
40+
this.width = p.width;
41+
this.height = p.height;
42+
g3d = (PGraphics3D) p.createGraphics(p.width, p.height, PApplet.P3D);
5043
}
51-
52-
public int getColor(int x, int y) {
53-
int color = g3d.get(x, y);
54-
return color;
55-
}
56-
57-
public void draw(List<SceneObject> sceneObjects) {
58-
g3d.beginDraw();
59-
g3d.setMatrix(p.getMatrix());
60-
g3d.noLights();
61-
g3d.background(0, 0, 0, 0);
62-
g3d.noStroke();
63-
for (SceneObject sceneObject : sceneObjects)
64-
drawBuffer(sceneObject);
65-
g3d.endDraw();
44+
}
45+
46+
public String getObject(int x, int y) {
47+
int color = getColor(x, y);
48+
return colorToObjectName.get(color);
49+
}
50+
51+
public int getColor(int x, int y) {
52+
int color = g3d.get(x, y);
53+
return color;
54+
}
55+
56+
public void draw(List<SceneObject> sceneObjects) {
57+
g3d.beginDraw();
58+
g3d.setMatrix(p.getMatrix());
59+
g3d.noLights();
60+
g3d.background(0, 0, 0, 0);
61+
g3d.noStroke();
62+
for (SceneObject sceneObject : sceneObjects) drawBuffer(sceneObject);
63+
g3d.endDraw();
64+
}
65+
66+
public void drawColorBuffer() {
67+
if (g3d == null) return;
68+
p.image(g3d, 0, 0, p.width, p.height);
69+
}
70+
71+
private void drawBuffer(SceneObject sceneObject) {
72+
PGraphics3D context = g3d;
73+
Mesh3D mesh = sceneObject.getMesh();
74+
75+
int c = -1;
76+
if (nameToColor.containsKey(sceneObject.getName())) {
77+
c = nameToColor.get(sceneObject.getName());
78+
} else {
79+
c = generator.next().getRGBA();
80+
nameToColor.put(sceneObject.getName(), c);
6681
}
6782

68-
public void drawColorBuffer() {
69-
if (g3d == null)
70-
return;
71-
p.image(g3d, 0, 0, p.width, p.height);
72-
}
73-
74-
private void drawBuffer(SceneObject sceneObject) {
75-
PGraphics3D context = g3d;
76-
Mesh3D mesh = sceneObject.getMesh();
77-
78-
int c = -1;
79-
if (nameToColor.containsKey(sceneObject.getName())) {
80-
c = nameToColor.get(sceneObject.getName());
81-
} else {
82-
c = generator.next().getRGBA();
83-
nameToColor.put(sceneObject.getName(), c);
84-
}
85-
86-
this.colorToObjectName.put(c, sceneObject.getName());
87-
88-
context.fill(c);
83+
this.colorToObjectName.put(c, sceneObject.getName());
8984

90-
context.pushMatrix();
85+
context.fill(c);
9186

92-
for (int i = 0; i < mesh.faces.size(); i++) {
93-
Face3D f = mesh.getFaceAt(i);
94-
Vector3f v;
87+
context.pushMatrix();
9588

96-
if (f.indices.length == 3) {
97-
context.beginShape(PApplet.TRIANGLES);
98-
}
89+
for (int i = 0; i < mesh.faces.size(); i++) {
90+
Face3D f = mesh.getFaceAt(i);
91+
Vector3f v;
9992

100-
if (f.indices.length == 4) {
101-
context.beginShape(PApplet.QUADS);
102-
}
93+
if (f.indices.length == 3) {
94+
context.beginShape(PApplet.TRIANGLES);
95+
}
10396

104-
if (f.indices.length > 4) {
105-
context.beginShape();
106-
}
97+
if (f.indices.length == 4) {
98+
context.beginShape(PApplet.QUADS);
99+
}
107100

108-
for (int j = 0; j < f.indices.length; j++) {
109-
v = mesh.vertices.get(f.indices[j]);
110-
context.vertex(v.getX(), v.getY(), v.getZ());
111-
}
101+
if (f.indices.length > 4) {
102+
context.beginShape();
103+
}
112104

113-
if (f.indices.length > 4) {
114-
context.endShape(PApplet.CLOSE);
115-
} else {
116-
context.endShape();
117-
}
118-
}
105+
for (int j = 0; j < f.indices.length; j++) {
106+
v = mesh.vertices.get(f.indices[j]);
107+
context.vertex(v.getX(), v.getY(), v.getZ());
108+
}
119109

120-
context.popMatrix();
110+
if (f.indices.length > 4) {
111+
context.endShape(PApplet.CLOSE);
112+
} else {
113+
context.endShape();
114+
}
121115
}
122116

117+
context.popMatrix();
118+
}
123119
}

src/main/java/workspace/render/SelectionRenderer.java

Lines changed: 82 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -11,98 +11,95 @@
1111

1212
public class SelectionRenderer {
1313

14-
private int width;
14+
private int width;
1515

16-
private int height;
16+
private int height;
1717

18-
private PApplet p;
18+
private PApplet p;
1919

20-
private PGraphics3D g3d;
20+
private PGraphics3D g3d;
2121

22-
private HashMap<Integer, Face3D> colorToFaceMap;
22+
private HashMap<Integer, Face3D> colorToFaceMap;
2323

24-
public SelectionRenderer(PApplet p) {
25-
this.p = p;
26-
g3d = (PGraphics3D) p.createGraphics(p.width, p.height, PApplet.P3D);
27-
colorToFaceMap = new HashMap<Integer, Face3D>();
28-
p.registerMethod("pre", this);
29-
}
30-
31-
public void pre() {
32-
if (p.width != this.width || p.height != this.height) {
33-
this.width = p.width;
34-
this.height = p.height;
35-
g3d = (PGraphics3D) p
36-
.createGraphics(p.width, p.height, PApplet.P3D);
37-
}
38-
}
39-
40-
public Face3D getFace(int x, int y) {
41-
int color = getColor(x, y);
42-
return colorToFaceMap.get(color);
43-
}
24+
public SelectionRenderer(PApplet p) {
25+
this.p = p;
26+
g3d = (PGraphics3D) p.createGraphics(p.width, p.height, PApplet.P3D);
27+
colorToFaceMap = new HashMap<Integer, Face3D>();
28+
p.registerMethod("pre", this);
29+
}
4430

45-
public int getColor(int x, int y) {
46-
int color = g3d.get(x, y);
47-
return color;
31+
public void pre() {
32+
if (p.width != this.width || p.height != this.height) {
33+
this.width = p.width;
34+
this.height = p.height;
35+
g3d = (PGraphics3D) p.createGraphics(p.width, p.height, PApplet.P3D);
4836
}
49-
50-
public void drawFaces(Mesh3D mesh) {
51-
g3d.beginDraw();
52-
g3d.setMatrix(p.getMatrix());
53-
g3d.noLights();
54-
g3d.background(0, 0, 0, 0);
55-
g3d.noStroke();
56-
drawFacesBuffer(mesh, mesh.faces);
57-
g3d.endDraw();
58-
}
59-
60-
public void drawColorBuffer() {
61-
if (g3d == null)
62-
return;
63-
p.image(g3d, 0, 0, p.width, p.height);
64-
}
65-
66-
private void drawFacesBuffer(Mesh3D mesh, Collection<Face3D> faces) {
67-
PGraphics3D context = g3d;
68-
69-
context.pushMatrix();
70-
71-
ColorGenerator generator = new ColorGenerator();
72-
this.colorToFaceMap.clear();
73-
74-
for (int i = 0; i < mesh.faces.size(); i++) {
75-
Face3D f = mesh.getFaceAt(i);
76-
Vector3f v;
77-
int c = generator.next().getRGBA();
78-
context.fill(c);
79-
this.colorToFaceMap.put(c, f);
80-
81-
if (f.indices.length == 3) {
82-
context.beginShape(PApplet.TRIANGLES);
83-
}
84-
85-
if (f.indices.length == 4) {
86-
context.beginShape(PApplet.QUADS);
87-
}
88-
89-
if (f.indices.length > 4) {
90-
context.beginShape();
91-
}
92-
93-
for (int j = 0; j < f.indices.length; j++) {
94-
v = mesh.vertices.get(f.indices[j]);
95-
context.vertex(v.getX(), v.getY(), v.getZ());
96-
}
97-
98-
if (f.indices.length > 4) {
99-
context.endShape(PApplet.CLOSE);
100-
} else {
101-
context.endShape();
102-
}
103-
}
104-
105-
context.popMatrix();
37+
}
38+
39+
public Face3D getFace(int x, int y) {
40+
int color = getColor(x, y);
41+
return colorToFaceMap.get(color);
42+
}
43+
44+
public int getColor(int x, int y) {
45+
int color = g3d.get(x, y);
46+
return color;
47+
}
48+
49+
public void drawFaces(Mesh3D mesh) {
50+
g3d.beginDraw();
51+
g3d.setMatrix(p.getMatrix());
52+
g3d.noLights();
53+
g3d.background(0, 0, 0, 0);
54+
g3d.noStroke();
55+
drawFacesBuffer(mesh, mesh.faces);
56+
g3d.endDraw();
57+
}
58+
59+
public void drawColorBuffer() {
60+
if (g3d == null) return;
61+
p.image(g3d, 0, 0, p.width, p.height);
62+
}
63+
64+
private void drawFacesBuffer(Mesh3D mesh, Collection<Face3D> faces) {
65+
PGraphics3D context = g3d;
66+
67+
context.pushMatrix();
68+
69+
ColorGenerator generator = new ColorGenerator();
70+
this.colorToFaceMap.clear();
71+
72+
for (int i = 0; i < mesh.faces.size(); i++) {
73+
Face3D f = mesh.getFaceAt(i);
74+
Vector3f v;
75+
int c = generator.next().getRGBA();
76+
context.fill(c);
77+
this.colorToFaceMap.put(c, f);
78+
79+
if (f.indices.length == 3) {
80+
context.beginShape(PApplet.TRIANGLES);
81+
}
82+
83+
if (f.indices.length == 4) {
84+
context.beginShape(PApplet.QUADS);
85+
}
86+
87+
if (f.indices.length > 4) {
88+
context.beginShape();
89+
}
90+
91+
for (int j = 0; j < f.indices.length; j++) {
92+
v = mesh.vertices.get(f.indices[j]);
93+
context.vertex(v.getX(), v.getY(), v.getZ());
94+
}
95+
96+
if (f.indices.length > 4) {
97+
context.endShape(PApplet.CLOSE);
98+
} else {
99+
context.endShape();
100+
}
106101
}
107102

103+
context.popMatrix();
104+
}
108105
}

0 commit comments

Comments
 (0)