forked from DrBrainlove/Mimsy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInternals.pde
365 lines (277 loc) · 9.97 KB
/
Internals.pde
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
import java.io.*;
import java.nio.file.*;
import java.util.*;
import java.util.stream.Stream;
import java.util.stream.IntStream;
// Need to manually import minim
import ddf.minim.*;
//*************************************************************** P3LX OBJECTS
// Top-level, we have a model and a P3LX instance
static GraphModel model;
P3LX lx;
LXPattern[] patterns;
//LXTransition[] transitions;
//Effects effects;
LXEffect[] effectsArr;
UI3dContext uiContext;
UI3dComponent pointCloudDodecahedron;
UI3dComponent pointCloudTetraLeft;
UI3dComponent pointCloudTetraRight;
UI3dComponent uiWalls;
UI3dComponent uiNodes;
public BooleanParameter uiOrthoCamera = new BooleanParameter("Ortho");
public BoundedParameter clipNear = new BoundedParameter("Clip Near", 0, 0, 100);
public BoundedParameter clipFar = new BoundedParameter("Clip Far", 100, 0, 100);
// Let's NOT work in inches, but will leave these here for porting
// patterns that do.
final static float INCHES = 25.4;
final static float FEET = 12.0*INCHES;
// Video Mixing Channels
static final int LEFT_CHANNEL = 0;
static final int RIGHT_CHANNEL = 1;
LXChannel L;
LXChannel R;
//************************************* Engine Construction and Initialization
//LXTransition _transition(P3LX lx) {
// return new DissolveTransition(lx).setDuration(1000);
//}
/*
LXPattern[] _leftPatterns(P3LX lx) {
LXPattern[] patterns = patterns(lx);
for (LXPattern p : patterns) {
p.setTransition(_transition(lx));
}
return patterns;
}
LXPattern[] _rightPatterns(P3LX lx) {
LXPattern[] patterns = _leftPatterns(lx);
LXPattern[] rightPatterns = new LXPattern[patterns.length+1];
int i = 0;
rightPatterns[i++] = new BlankPattern(lx).setTransition(_transition(lx));
for (LXPattern p : patterns) {
rightPatterns[i++] = p;
}
return rightPatterns;
}
*/
/*
LXEffect[] _effectsArray(Effects effects) {
List<LXEffect> effectList = new ArrayList<LXEffect>();
for (Field f : effects.getClass().getDeclaredFields()) {
try {
Object val = f.get(effects);
if (val instanceof LXEffect) {
effectList.add((LXEffect)val);
}
} catch (IllegalAccessException iax) {}
}
return effectList.toArray(new LXEffect[]{});
}
LXEffect getSelectedEffect() {
return effectsArr[selectedEffect.getValuei()];
}
*/
/** *************************************************************** MAIN SETUP
* Set up models etc for whole package (Processing thing)
* Fill out UI elements
* Connect to output hardware
************************************************************************** **/
public void settings() {
size(1200, 900, "processing.opengl.PGraphics3D");
}
void setup() {
startMillis = System.currentTimeMillis();
lastMillis = startMillis;
//==================================================================== Model
model = buildMimsyModel();
out("Model Name: %s\n", model.layer);
out("Finished Building Model");
//from tenere
try {
lx = new LXStudio(this, model, false) {
public void initialize(LXStudio lx, LXStudio.UI ui) {
//lx.engine.registerComponent("tenereSettings", new Settings(lx, ui));
lx.registerEffect(BlurEffect.class);
lx.registerEffect(DesaturationEffect.class);
// TODO: the UDP output instantiation will go in here!
smooth(4);
out("Initialized LXStudio");
}
public void onUIReady(LXStudio lx, LXStudio.UI ui) {
//ui.preview.setRadius(80*FEET).setPhi(-PI/18).setTheta(PI/12);
//ui.preview.setCenter(0, model.cy - 2*FEET, 0);
//ui.preview.addComponent(new UISimulation());
ui.preview.pointCloud.setPointSize(5.0)
.disablePointSizeAttenuation();
//ui.preview.pointCloud.setVisible(false); //TODO doesnt work
smooth(4);
// Narrow angle lens, for a fuller visualization
//ui.preview.perspective.setValue(30);
// uiTreeControls = (UITreeControls) new UITreeControls(ui).addToContainer(ui.leftPane.global);
out("Initialized LX UI");
}
};
} catch (Exception x) {
x.printStackTrace();
}
//end from tenere
if (TEST_SYMMETRY) {
symTest = new SymmetryTest(model);
symTest.runSymmetryTests();
exit();
}
//===================================================================== P3LX
//lx = new LXStudio(this, model, false);
//anything that extends LXPattern gets loaded automatically now (using reflection)
//lx.setPatterns(patterns(lx));
//out("Finished Loading Patterns");
//================================================================= 3D Model
////-------------- Prepare 3D Reference Elements
//uiWalls = new UIWalls();
//uiWalls.setVisible(false);
//uiNodes = new UINodes();
////-------------- Prepare 3D Point Clouds
//pointCloudDodecahedron
// = new UIPointCloud(lx, model.getLayer(DD))
// .setPointSize(DODECAHEDRON_BAR_THICKNESS);
//pointCloudTetraLeft
// = new UIPointCloud(lx, model.getLayer(TL))
// .setPointSize(TETRAHEDRON_BAR_THICKNESS);
//pointCloudTetraRight
// = new UIPointCloud(lx, model.getLayer(TR))
// .setPointSize(TETRAHEDRON_BAR_THICKNESS);
////-------------- Build the 3D UI
//uiContext =
// // A camera layer makes an OpenGL layer that we can easily
// // pivot around with the mouse
// new UI3dContext(lx.ui) {
// protected void beforeDraw(UI ui, PGraphics pg) {
// int H = UI_LIGHT_HUE;
// int S = UI_LIGHT_SATURATION;
// int B = UI_LIGHT_BRIGHTNESS;
// //-------- Lights!
// for (float mx : new float[]{model.xMin, model.xMax}) {
// for (float my : new float[]{model.yMin, model.yMax}) {
// for (float mz : new float[]{model.zMin, model.zMax}) {
// float x = mx*10;
// float y = my*10;
// float z = mz*10;
// pointLight(H,S,B, x, y, z);
// pushMatrix();
// translate(x,y,z);
// sphere(10.0);
// popMatrix();
// }
// }
// }
// int scale = 6;
// if (uiOrthoCamera.isOn()) {
// ortho(-width/scale, width/scale,
// -height/scale, height/scale,
// clipNear.getValuef() * radius.getValuef() / 100.0,
// clipFar.getValuef() * radius.getValuef() / 100.0 * 2.0);
// }
// hint(ENABLE_DEPTH_TEST);
// }
// protected void afterDraw(UI ui, PGraphics pg) {
// // Turn off the lights and kill depth testing before the 2D layers
// noLights();
// hint(DISABLE_DEPTH_TEST);
// }
// }
// //------------ Camera!
// .setRadius(1000)
// .setPerspective(0)
// //.setDepth(4)
// .setCenter(model.cx, model.cy, model.cz)
// //.setPhi(-PI/2) // Rotate model around X
// //.setTheta(-PI/2) // Rotate around Y
// //------------ Action! (actually just some stuff)
// // Let's add a point cloud of our animation points
// //.addComponent(pointCloud = new UIPointCloud(lx, model).setPointSize(BAR_THICKNESS))
// .addComponent(pointCloudDodecahedron)
// .addComponent(pointCloudTetraLeft)
// .addComponent(pointCloudTetraRight)
// // And a custom UI object of our own
// .addComponent(uiWalls)
// .addComponent(uiNodes)
//;
//lx.ui.addLayer(uiContext);
//out("Finished 3D Layer");
////=========================================================== 2D Control GUI
//UI2dContext[] layers = new UI2dContext[] {
// // Left Side
// new UIChannelControl (lx.ui, lx.engine.getChannel(0), 4, 4),
// new UISimulationControl (lx.ui, 4, 326),
// new UIEngineControl (lx.ui, 4, 466),
// new UICameraControlMimsy (lx.ui, uiContext, 4, 600),
// // Right Side
// new UIComponentsDemo (lx.ui, width-144, 4),
//};
//for (UI2dContext layer : layers) {
// lx.ui.addLayer(layer);
//}
out("Finished 2D Layer");
//==================================================== Output to Controllers
// create outputs via CortexOutput
if (OUTPUT) {
buildChannelMap(model);
buildOutputs();
out("Built output clients");
}
}
void draw() {
// Wipe the frame...
background(#292929);
//background(#888888);
// ...and everything else is handled by P3LX!
drawFPS();
// DMK: Somewhat strongly suspect cubic gamma on APA102 is wild overkill, but we'll check /
// add as a config
// Gamma correction here. Apply a cubic to the brightness
// for better representation of dynamic range
//
/*
color[] sendColors = lx.getColors();
float hsb[] = new float[3];
for (int i = 0; i < sendColors.length; ++i) {
LXColor.RGBtoHSB(sendColors[i], hsb);
float b = hsb[2];
sendColors[i] = lx.hsb(360.*hsb[0], 100.*hsb[1], (b*b)/256.);
}
*/
}
//************************************************************ AUX SUBROUTINES
//------------------------------------------------------------------ FPS Meter
long simulationNanos = 0;
static long startMillis = System.currentTimeMillis();
static long lastMillis = startMillis;
int FPS_TARGET = 60;
boolean DRAW_FPS = true;
void drawFPS() {
if (DRAW_FPS) {
fill(#FFFFFF);
textSize(9);
textAlign(LEFT, BASELINE);
text("FPS: " + ((int) (frameRate*10)) / 10. + " / " + "60" + " (-/+)", 4, height-4);
}
}
//-------------------------------------------------------------------- Logging
import java.text.SimpleDateFormat;
public static void mark() {
lastMillis = System.currentTimeMillis();
}
public static void out(String format, Object... args) {
String timeStamp = new SimpleDateFormat("HH:mm:ss")
.format(new Date());
//int now = millis();
long now = System.currentTimeMillis();
long dif = now - lastMillis;
String prefix = String.format("%s (%5d ms): ", timeStamp, dif);
System.out.format(prefix);
System.out.format(format, args);
if (!format.endsWith("\n")) {
System.out.format("\n");
}
lastMillis = now;
}