-
Notifications
You must be signed in to change notification settings - Fork 20
/
KinectToPin.pde
358 lines (315 loc) · 9.57 KB
/
KinectToPin.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
// KinectToPin v1.3.8
// by Nick Fox-Gieg and Victoria Nece
// kinecttopin.fox-gieg.com
import oscP5.*;
import netP5.*;
import proxml.*;
import ddf.minim.*;
import SimpleOpenNI.*;
import java.awt.Desktop;
//import com.rhizomatiks.bvh.*;
//~~~~~~~~~~~~~~~~~~
//**************************
//float durationFrames = 10 * fps;
int numParticles = 100;
boolean motionBlur = true;
boolean applyEffects = false;
boolean applySmoothing = true;
//smoothing
int smoothNum = 6;
float weight = 18;
float scaleNum = 1.0 / (weight + 2);
//---
boolean tracePath = true;
//**************************
boolean loadSimpleOpenNIatStart = true;
boolean firstRun=true;
boolean modePreview = false;
int previewLevel = 1;
PImage previewImg;
int[] previewInt;
SimpleOpenNI context;
boolean mirror = false;
boolean multiThread = true;
boolean autoCalibrate = false;
int masterFileCounter=0;
String[] allFiles;
//this sketch
int sW = 640;
int sH = 480;
float sD = 200; //range of depth...FYI After Effects puppet tool doesn't use Z position
//destination After Effects comp
int dW = 1920;
int dH = 1080;
int fps = 24;
int counter = 0;
int counterMax = 0; //number of MocapFrames to record
Countdown countdown;
String sayText = "";
String sayTextPrefix = "";
String sayTextSeparator = " ... ";
Minim minim;
String beepFile = "24th blip sync pop.wav";
String dialogueFile = "none";
OscP5 oscP5;
boolean found=false;
String ipNumber = "127.0.0.1";
int receivePort = 7110;
int sendPort = 1234;
NetAddress myRemoteLocation;
NetAddress myRemoteLocationEcho;
boolean sendOsc = false;
String oscChannelFormat = "Animata"; // "Isadora", "OSCeleton, Animata"
boolean oscLocalEcho = false;
XMLInOut xmlIO;
XMLElement MotionCapture;
String xmlFileName = "mocapData";
String xmlFileType = "xml";
String xmlFilePath = "savexml";
boolean saveXml = true;
//~
String aeFileName = "AEpinData";
String aeFilePath = "saveae-pins";
String aeFileType = "txt";
boolean savePins = true;
//~
String aePointFileName = "AEpointData";
String aePointFilePath = "saveae-points";
String aePointFileType = "txt";
boolean savePoints = true;
//~
String aePoint3DFileName = "AEpoint3Ddata";
String aePoint3DFilePath = "saveae-points3D";
String aePoint3DFileType = "txt";
boolean savePoints3D = true;
//~
String jsonFileName = "jsonData";
String jsonFilePath = "savejson";
String jsonFileType = "json";
boolean saveJson = true;
//~
String aeJsxFileName = "AEscript";
String aeJsxFilePath = "saveae-jsx";
String aeJsxFileType = "jsx";
boolean saveJsx = false;
String mayaFileName = "mayaScript";
String mayaFilePath = "saveMaya";
String mayaFileType = "py";
boolean saveMaya = false;
String objFileName = "pointcloud";
String objFilePath = "saveObj";
String objFileType = "obj";
boolean saveObj = false;
boolean limitReached = false;
boolean loaded = false;
int saveDelayInterval = 100; //ms
PVector bvhScaleFactor = new PVector(1,1,1);
PVector bvhOffset = new PVector(0,0,0);
ArrayList bvhNames; //file names, not joint names
int bvhConversionCounter = 0;
int bvhConversionCounterMax = 0;
BvhParser parserA;
PBvh bvh1;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//1. OSCELETON / OPENNI / MS SDK
String[] osceletonNamesNormal = {
"head", "neck", "torso", "r_shoulder", "r_elbow", "r_hand", "l_shoulder", "l_elbow", "l_hand", "r_hip", "r_knee", "r_foot", "l_hip", "l_knee", "l_foot"
};
String[] osceletonNamesReversed = { //standard non-mirrored
"head", "neck", "torso", "l_shoulder", "l_elbow", "l_hand", "r_shoulder", "r_elbow", "r_hand", "l_hip", "l_knee", "l_foot", "r_hip", "r_knee", "r_foot"
};
String[] osceletonNames = new String[15];
//2. CMU BVH default
/*
String[] bvhJointNames = {
"Head", "Neck1", "Spine", "LeftArm", "LeftForeArm", "LeftFingerBase", "RightArm", "RightForeArm", "RightFingerBase", "LeftUpLeg", "LeftLeg", "LeftToeBase", "RightUpLeg", "RightLeg", "RightToeBase"
};
*/
String[] bvhJointNames = {
"Head", "Neck1", "Spine", "LeftArm", "LeftForeArm", "LeftFingerBase", "RightArm", "RightForeArm", "RightFingerBase", "LeftUpLeg", "LeftLeg", "LeftToeBase", "RightUpLeg", "RightLeg", "RightToeBase"
};
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PVector[] simpleOpenNiPos = new PVector[osceletonNames.length];
PVector[] simpleOpenNiPos_proj = new PVector[osceletonNames.length];
File dataFolder, dialogueFolder;
//Data data;
int[] pinNums = new int[osceletonNames.length];
XMLElement[] oscXmlTags = new XMLElement[osceletonNames.length];
float posX, posY, posZ;
float[] x = new float[osceletonNames.length];
float[] y = new float[osceletonNames.length];
float[] z = new float[osceletonNames.length];
int circleSize = 30;//50;
boolean modeRec = false;
boolean modeOsc = false;
boolean modePlay = false;
boolean modeExport = false;
boolean modeBvh = false;
boolean modeStop = true;
boolean needsSaving = false;
int buttonRecNum = 0;
int buttonOscNum = 1;
int buttonStopNum = 2;
int buttonPlayNum = 3;
int buttonSaveNum = 4;
int buttonCamNum = 5;
int buttonBvhNum = 6;
int totalButtons = 7;
Button[] buttons = new Button[totalButtons];
boolean buttonFreeze = false;
int introWarningCounter = 0;
int introWarningCounterMax = 6*fps;
int camDelayCounter=0;
int camDelayCounterMax = 10;
//~~~~~~~~~~~~~~~~~~
void initSettings() {
Settings settings = new Settings("settings.txt");
if (mirror) {
osceletonNames = osceletonNamesNormal;
}
else {
osceletonNames = osceletonNamesReversed;
}
simpleOpenNiPos = new PVector[osceletonNames.length];
simpleOpenNiPos_proj = new PVector[osceletonNames.length];
pinNums = new int[osceletonNames.length];
oscXmlTags = new XMLElement[osceletonNames.length];
x = new float[osceletonNames.length];
y = new float[osceletonNames.length];
z = new float[osceletonNames.length];
}
void setup() {
size(50, 50, P3D);
surface.setSize(sW, sH);
initSettings();
frameRate(fps);
for (int i=0;i<osceletonNames.length;i++) {
simpleOpenNiPos[i] = new PVector(0, 0, 0);
simpleOpenNiPos_proj[i] = new PVector(0, 0, 0);
}
//~~~~~~~~~~~~~~~~~
dialogueFolder = new File(sketchPath(""), "dialogue");
allFiles = dialogueFolder.list();
try {
int dialogueFileCounter = 0;
for (int j=0;j<allFiles.length;j++) {
if (allFiles[j].toLowerCase().endsWith("wav")||allFiles[j].toLowerCase().endsWith("aif")||allFiles[j].toLowerCase().endsWith("aiff")||allFiles[j].toLowerCase().endsWith("mp3")) {
dialogueFile = allFiles[j];
}
}
}
catch (Exception e) {
//
}
//~~~~~~~~~~~~~~~~~
dataFolder = new File(sketchPath(""), "data" + "/" + xmlFilePath + "/");
allFiles = dataFolder.list();
try {
for (int i=0;i<allFiles.length;i++) {
if (allFiles[i].toLowerCase().endsWith(xmlFileType)) {
masterFileCounter++;
}
}
}
catch (Exception e) {
//
}
//masterFileCounter = allFiles.length;
if (masterFileCounter==1) {
sayTextPrefix = masterFileCounter + " existing saved XML file";
}
else {
sayTextPrefix = masterFileCounter + " existing saved XML files";
}
ellipseMode(CENTER);
minim = new Minim(this);
oscSetup();
buttons[buttonRecNum] = new Button(25, sH-20, 30, color(240, 10, 10), 12, "rec");
buttons[buttonOscNum] = new Button(60, sH-20, 30, color(200, 20, 200), 12, "osc");
buttons[buttonSaveNum] = new Button(sW-25, sH-20, 30, color(50, 100, 220), 12, "save");
buttons[buttonPlayNum] = new Button(sW-95, sH-20, 30, color(20, 200, 20), 12, "play");
buttons[buttonStopNum] = new Button(95, sH-20, 30, color(100, 100, 100), 12, "stop");
buttons[buttonCamNum] = new Button(sW/2, sH-20, 30, color(200, 200, 50), 12, "cam");
buttons[buttonBvhNum] = new Button(sW-60, sH-20, 30, color(250, 130, 50), 12, "data");
//~~
buttons[buttonBvhNum].isSquare = true;
buttons[buttonSaveNum].isSquare = true;
buttons[buttonStopNum].isSquare = true;
buttons[buttonPlayNum].isSquare = true;
//~~
xmlPlayerInit(masterFileCounter);
xmlRecorderInit();
countdown = new Countdown(8, 2);
previewImg = createImage(sW, sH, RGB);
previewInt = new int[sW*sH];
//~~~~~~~ get rid of this to use with OSC device that grabs camera
if (loadSimpleOpenNIatStart) setupUser(); //this sets up SimpleOpenNi
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
background(0);
}
//~~~
void draw() {
background(0);
if (modeRec||modePreview) {
drawUser(); //looking for one user; may upgrade later
}
if (!modePreview) {
if (modeRec||modeOsc) {
//if(modeRec){
xmlRecorderUpdate();
}
else if (modeBvh){
bvhConvert();
}
else if (modePlay) {
xmlPlayerUpdate();
}
}
buttonHandler();
recDot();
sayText = xmlFileName + (masterFileCounter);
//println(counter);
if (introWarningCounter<introWarningCounterMax && !loadSimpleOpenNIatStart) {
textAlign(CENTER);
text("PLEASE NOTE:", width/2, (height/2)-70);
text("The app will freeze for ~20 sec. the first time you press REC or CAM.", width/2, (height/2)-50);
introWarningCounter++;
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void recDot() {
fill(200);
textAlign(LEFT);
text(sayTextPrefix + sayTextSeparator + sayText, 40, 35);
text(int(frameRate) + " fps", sW-60, 35);
noFill();
if (counter%2!=0) {
if (modeRec) {
stroke(255, 20, 0);
}
else if (modeOsc) {
stroke(225, 0, 205);
}
else if (!modeRec&&!modeOsc) {
//else if (!modeRec) {
stroke(35, 25, 35);
}
}
else {
stroke(35, 25, 35);
}
strokeWeight(20);
point(20, 30);
stroke(200);
strokeWeight(1);
rectMode(CORNER);
rect(3, 59, 633, 360);
line((sW/2)-10, (sH/2), (sW/2)+10, (sH/2));
line((sW/2), (sH/2)-10, (sW/2), (sH/2)+10);
}
void stop() {
countdown.stop();
minim.stop();
super.stop();
exit();
}