Skip to content

Commit e0f7212

Browse files
committed
Format changes.
1 parent a97a54d commit e0f7212

File tree

3 files changed

+203
-189
lines changed

3 files changed

+203
-189
lines changed

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

Lines changed: 107 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -12,105 +12,112 @@
1212

1313
public class ObjectSelectionRender {
1414

15-
private ColorGenerator generator;
16-
private int width;
17-
private int height;
18-
private PApplet p;
19-
private PGraphics3D g3d;
20-
private HashMap<Integer, String> colorToObjectName;
21-
private HashMap<String, Integer> nameToColor;
22-
23-
public ObjectSelectionRender(PApplet p) {
24-
colorToObjectName = new HashMap<Integer, String>();
25-
nameToColor = new HashMap<String, Integer>();
26-
generator = new ColorGenerator();
27-
this.p = p;
28-
g3d = (PGraphics3D) p.createGraphics(p.width, p.height, PApplet.P3D);
29-
p.registerMethod("pre", this);
30-
}
31-
32-
public void pre() {
33-
if (p.width != this.width || p.height != this.height) {
34-
this.width = p.width;
35-
this.height = p.height;
36-
g3d = (PGraphics3D) p.createGraphics(p.width, p.height, PApplet.P3D);
37-
}
38-
}
39-
40-
public String getObject(int x, int y) {
41-
int color = getColor(x, y);
42-
return colorToObjectName.get(color);
43-
}
44-
45-
public int getColor(int x, int y) {
46-
int color = g3d.get(x, y);
47-
return color;
48-
}
49-
50-
public void draw(List<SceneObject> sceneObjects) {
51-
g3d.beginDraw();
52-
g3d.setMatrix(p.getMatrix());
53-
g3d.noLights();
54-
g3d.background(0, 0, 0, 0);
55-
g3d.noStroke();
56-
for (SceneObject sceneObject : sceneObjects)
57-
drawBuffer(sceneObject);
58-
g3d.endDraw();
59-
}
60-
61-
public void drawColorBuffer() {
62-
if (g3d == null)
63-
return;
64-
p.image(g3d, 0, 0, p.width, p.height);
65-
}
66-
67-
private void drawBuffer(SceneObject sceneObject) {
68-
PGraphics3D context = g3d;
69-
Mesh3D mesh = sceneObject.getMesh();
70-
71-
int c = -1;
72-
if (nameToColor.containsKey(sceneObject.getName())) {
73-
c = nameToColor.get(sceneObject.getName());
74-
} else {
75-
c = generator.next().getRGBA();
76-
nameToColor.put(sceneObject.getName(), c);
77-
}
78-
79-
this.colorToObjectName.put(c, sceneObject.getName());
80-
81-
context.fill(c);
82-
83-
context.pushMatrix();
84-
85-
for (int i = 0; i < mesh.faces.size(); i++) {
86-
Face3D f = mesh.getFaceAt(i);
87-
Vector3f v;
88-
89-
if (f.indices.length == 3) {
90-
context.beginShape(PApplet.TRIANGLES);
91-
}
92-
93-
if (f.indices.length == 4) {
94-
context.beginShape(PApplet.QUADS);
95-
}
96-
97-
if (f.indices.length > 4) {
98-
context.beginShape();
99-
}
100-
101-
for (int j = 0; j < f.indices.length; j++) {
102-
v = mesh.vertices.get(f.indices[j]);
103-
context.vertex(v.getX(), v.getY(), v.getZ());
104-
}
105-
106-
if (f.indices.length > 4) {
107-
context.endShape(PApplet.CLOSE);
108-
} else {
109-
context.endShape();
110-
}
111-
}
112-
113-
context.popMatrix();
114-
}
15+
private ColorGenerator generator;
16+
17+
private int width;
18+
19+
private int height;
20+
21+
private PApplet p;
22+
23+
private PGraphics3D g3d;
24+
25+
private HashMap<Integer, String> colorToObjectName;
26+
27+
private HashMap<String, Integer> nameToColor;
28+
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+
}
46+
47+
public String getObject(int x, int y) {
48+
int color = getColor(x, y);
49+
return colorToObjectName.get(color);
50+
}
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();
66+
}
67+
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);
89+
90+
context.pushMatrix();
91+
92+
for (int i = 0; i < mesh.faces.size(); i++) {
93+
Face3D f = mesh.getFaceAt(i);
94+
Vector3f v;
95+
96+
if (f.indices.length == 3) {
97+
context.beginShape(PApplet.TRIANGLES);
98+
}
99+
100+
if (f.indices.length == 4) {
101+
context.beginShape(PApplet.QUADS);
102+
}
103+
104+
if (f.indices.length > 4) {
105+
context.beginShape();
106+
}
107+
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+
}
112+
113+
if (f.indices.length > 4) {
114+
context.endShape(PApplet.CLOSE);
115+
} else {
116+
context.endShape();
117+
}
118+
}
119+
120+
context.popMatrix();
121+
}
115122

116123
}

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

Lines changed: 93 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -11,93 +11,98 @@
1111

1212
public class SelectionRenderer {
1313

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

103108
}

0 commit comments

Comments
 (0)