Last active
August 29, 2015 14:18
-
-
Save fjenett/53245a5fe651a7a49fad to your computer and use it in GitHub Desktop.
Example showing how to load 3D path from Piecemaker2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Motion Bank research, http://motionbank.org/ | |
* | |
* Example of how to load a 3D path through Piecemaker2 API | |
*/ | |
import org.piecemaker2.api.*; | |
import org.piecemaker2.models.*; | |
PieceMakerApi api; | |
float[][] positions; | |
float[] boundingBox; | |
String s3_base_url = "http://d35vpnmjdsiejq.cloudfront.net/dh/piecemaker/"; | |
String lab_data_base_url = "http://lab.motionbank.org/dhay/data"; | |
void setup () | |
{ | |
size( 360, 360 ); | |
api = new PieceMakerApi( this, "https://piecemaker2-api-public.herokuapp.com", "0310XPC6JEeF0oCy" ); | |
api.listAllGroups( api.createCallback( "groupsLoaded" ) ); | |
} | |
void draw () | |
{ | |
background( 255 ); | |
if ( positions != null && positions.length >= 0 ) | |
{ | |
noFill(); | |
stroke( 1 ); | |
// center in window | |
translate( width/2, height/2 ); | |
// center bbox | |
translate( - boundingBox[0] - (boundingBox[2]-boundingBox[0])/2.0, | |
- boundingBox[1] - (boundingBox[3]-boundingBox[1])/2.0 ); | |
beginShape(); | |
for ( int i = 0; i < positions.length; i++ ) | |
{ | |
vertex( positions[i][0], positions[i][1] ); | |
} | |
endShape(); | |
} | |
noLoop(); | |
} | |
void groupsLoaded ( Group[] groups ) | |
{ | |
for ( Group g : groups ) | |
{ | |
// println( g.title ); | |
if ( g.id == 29 ) { // Deborah Hay group ID | |
api.getGroup( g.id, api.createCallback("groupLoaded") ); | |
break; | |
} | |
} | |
} | |
void groupLoaded ( Group group ) | |
{ | |
// println( "Group '" + group.title + "' (#" + group.id + ") loaded" ); | |
api.listEventsOfType( group.id, "data", api.createCallback( "groupEventsLoaded", group ) ); | |
} | |
void groupEventsLoaded ( org.piecemaker2.models.Event[] groupEvents, Group group ) | |
{ | |
for ( org.piecemaker2.models.Event e : groupEvents ) | |
{ | |
//println( e.utc_timestamp + " " + e.type + " " + e.fields.get("type") + " " + e.fields.get("title") ); | |
//println( lab_data_base_url + "/" + e.fields.get("data-file") ); | |
if ( e.fields.get("data-file").toString().indexOf("D06T02") >= 0 ) | |
{ | |
loadData( e.fields.get("data-file").toString() ); | |
} | |
} | |
} | |
// load data file, upscale and calc bouding box | |
void loadData ( String filename ) | |
{ | |
String path = lab_data_base_url + "/" + filename.replace( ".txt", "_com.txt" ); | |
String[] values = loadStrings( path ); | |
float[][] positionsTmp = new float[values.length/2][3]; | |
float scale = 20; | |
float minx = 100000, miny = 100000, maxx = -100000, maxy = -100000; | |
for ( int i = 0, i2 = 0, vi = positionsTmp.length; i < vi; i++, i2+=2 ) | |
{ | |
String[] vs = values[i2].split( " " ); | |
positionsTmp[i] = float( vs ); | |
positionsTmp[i][0] = positionsTmp[i][0] * scale; | |
positionsTmp[i][1] = positionsTmp[i][1] * scale; | |
positionsTmp[i][2] = positionsTmp[i][2] * scale; | |
minx = min( minx, positionsTmp[i][0] ); | |
miny = min( miny, positionsTmp[i][1] ); | |
maxx = max( maxx, positionsTmp[i][0] ); | |
maxy = max( maxy, positionsTmp[i][1] ); | |
} | |
positions = positionsTmp; | |
boundingBox = new float[]{ minx, miny, maxx, maxy }; | |
// println( boundingBox ); | |
loop(); | |
} | |
void piecemakerError ( int status, String err ) | |
{ | |
println( err ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment