-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModel.pde
More file actions
49 lines (43 loc) · 1.98 KB
/
Model.pde
File metadata and controls
49 lines (43 loc) · 1.98 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
import java.util.List;
LXModel buildModel() {
JSONObject config = applet.loadJSONObject("dome.json");
return new DomeModel(config);
}
// Currently this takes a JSON array of 3-float-array points [[x1,y1,z1], [x2,y2,z2], ...]
// multiplies all points by a SCALE factor and adds them all to the UI
// TODO: replace this with an actual parametric dome algorithm
public static class DomeModel extends LXModel {
public final static int SCALE = 10;
public DomeModel(JSONObject domeConf) {
super(DomeModel.BuildFixtures(domeConf));
}
public static DomeFixture[] BuildFixtures(JSONObject domeConf) {
ArrayList<DomeFixture> struts = new ArrayList<DomeFixture>();
JSONArray jsonSegments = domeConf.getJSONArray("segments");
for (int segmentIndex = 0; segmentIndex < jsonSegments.size(); segmentIndex++) {
JSONObject jsonSegment = jsonSegments.getJSONObject(segmentIndex);
JSONArray jsonPaths = jsonSegment.getJSONArray("paths");
for (int pathIndex = 0; pathIndex < jsonPaths.size(); pathIndex++) {
JSONObject jsonPath = jsonPaths.getJSONObject(pathIndex);
JSONArray jsonStruts = jsonPath.getJSONArray("struts");
for (int strutIndex = 0; strutIndex < jsonStruts.size(); strutIndex++) {
struts.add(new DomeFixture(jsonStruts.getJSONObject(strutIndex)));
}
}
}
JSONArray jsonUplights = domeConf.getJSONArray("uplights");
for (int uplightIndex = 0; uplightIndex < jsonUplights.size(); uplightIndex++) {
struts.add(new DomeFixture(jsonUplights.getJSONObject(uplightIndex)));
}
return struts.toArray(new DomeFixture[struts.size()]);
}
public static class DomeFixture extends LXAbstractFixture {
DomeFixture(JSONObject strutconf) {
JSONArray leds = strutconf.getJSONArray("leds");
for (int i=0; i<leds.size(); i++) {
JSONArray led = leds.getJSONArray(i);
addPoint(new LXPoint(led.getFloat(0)*SCALE, led.getFloat(1)*SCALE, led.getFloat(2)*SCALE));
}
}
}
}