Skip to content

Commit

Permalink
Merge pull request #2 from gweltou/import
Browse files Browse the repository at this point in the history
Import
  • Loading branch information
gweltou authored Mar 22, 2022
2 parents 4a50811 + 74351b8 commit b38d5e7
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 43 deletions.
41 changes: 33 additions & 8 deletions Events.pde
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;


boolean axeSetFirst = false; // Used when animation's axe is chosen before function
String axeSetFirstName;

void controlEvent(ControlEvent event) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
if (paramLocked)
return;
Expand All @@ -11,13 +15,13 @@ void controlEvent(ControlEvent event) throws InstantiationException, IllegalAcce
if (event.isController()) {
String name = event.getName();
float value = event.getValue();
//println("event", name, value);
//println("event", event);

if (name.equals("partslist")) {
select(avatar.getPartsList()[int(value)]);
selectedIndex = int(partsList.getValue());
return;
} else { // Don't reset animation when selecting parts
} else if (avatar != null) { // Don't reset animation when selecting parts
avatar.resetAnimation();
}

Expand All @@ -36,7 +40,12 @@ void controlEvent(ControlEvent event) throws InstantiationException, IllegalAcce
if (animNum < numberOfAnimations) {
selected.getAnimation(animNum).setFunction(tf);
} else {
selected.addAnimation(new Animation(tf));
Animation a = new Animation(tf);
if (axeSetFirst && parseInt(match(axeSetFirstName, "axe(\\d+)")[1]) == animNum) {
int axeVal = (int) cp5.getController(axeSetFirstName).getValue();
a.setAxe(axeVal);
}
selected.addAnimation(a);
}
//selected.reset();
/*if (tf instanceof TFTimetable) {
Expand All @@ -52,16 +61,23 @@ void controlEvent(ControlEvent event) throws InstantiationException, IllegalAcce
else if (name.startsWith("axe")) {
String[] m = match(name, "axe(\\d+)");
int animNum = parseInt(m[1]);
selected.getAnimation(animNum).setAxe((int) value);
mustUpdateUI = true;
playing = true;
setAnimationCollectionDirty();
// Should check if an function is set first
if (animNum == selected.getAnimationList().length) {
// No function set yet
axeSetFirst = true;
axeSetFirstName = name;
} else {
selected.getAnimation(animNum).setAxe((int) value);
mustUpdateUI = true;
playing = true;
setAnimationCollectionDirty();
}
}

else if (name.startsWith("animamp")) {
String[] m = match(name, "animamp(\\d+)");
int animNum = parseInt(m[1]);
selected.getAnimation(animNum).setAmp(value);
selected.getAnimation(animNum).setAmp(int(value*100f) / 100f);
setAnimationCollectionDirty();
}

Expand All @@ -78,6 +94,13 @@ void controlEvent(ControlEvent event) throws InstantiationException, IllegalAcce
playing = false;
}

else if (name.equals("importbutton")) {
println("yay");
importButton.hide();
selectInput("Select a file", "inputFileSelected");
loadScreen = new LoadScreen();
}

else if (name.startsWith("copybutton")) {
String[] m = match(name, "copybutton(\\d+)");
int animNum = parseInt(m[1]);
Expand Down Expand Up @@ -179,6 +202,8 @@ void controlEvent(ControlEvent event) throws InstantiationException, IllegalAcce
int idx = floor(value);
fn.setParam(paramName, Animation.interpolationNamesSimp[idx]);
} else {
// Round to 2 decimals
value = int(value*100f) / 100f;
fn.setParam(paramName, value);
}
playing = true;
Expand Down
17 changes: 10 additions & 7 deletions LoadScreen.pde
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ public class LoadScreen extends Screen {
return;

loadAvatarFile(selection);

selectedIndex = 0;
selected = null;
partsList.setItems(avatar.getPartsNamePre());
baseFilename = filename.substring(0, filename.length()-5);
showUI();
//accordion.hide(); // Whyyy ???

if (avatar != null) {
selectedIndex = 0;
selected = null;
partsList.setItems(avatar.getPartsNamePre());
baseFilename = filename.substring(0, filename.length()-5);
showUI();
//accordion.hide(); // Whyyy ???
}

mustDestroy = true;
}
Expand All @@ -110,6 +112,7 @@ public class LoadScreen extends Screen {
boolean loadAnim = animToggle.getValue() == 1.0f;

Avatar newAvatar = Avatar.fromFile(file);

if (newAvatar == null)
return;

Expand Down
51 changes: 33 additions & 18 deletions MainScreen.pde
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class MainScreen extends Screen {
private int remainingFrames = 0;
private boolean clearBackground = true;
private float timeScale = 1f;

private int mouse_button;


public MainScreen() {
Expand Down Expand Up @@ -44,32 +46,35 @@ public class MainScreen extends Screen {


public void draw() {
if (avatar == null) {
/*if (avatar == null) {
hideUI();
currentScreen = welcomeScreen;
currentScreen = mainScreen;
return;
}
}*/

if (clearBackground || showUI)
background(255);

renderer.pushMatrix(transform);
if (playing)
avatar.update(1f/framerate);
avatar.draw(renderer);

if (renderer.isRecording() && playing) {
renderer.flush();
if (remainingFrames > 0) {
remainingFrames--;
transport.increaseCounter();
if (remainingFrames == 0) {
stopRecording();
transport.buttonRec.setOff();
if (avatar != null) {
if (playing)
avatar.update(1f/framerate);
avatar.draw(renderer);

if (renderer.isRecording() && playing) {
renderer.flush();
if (remainingFrames > 0) {
remainingFrames--;
transport.increaseCounter();
if (remainingFrames == 0) {
stopRecording();
transport.buttonRec.setOff();
}
}
} else {
avatar.drawSelectedOnly(renderer);
}
} else {
avatar.drawSelectedOnly(renderer);
}

if (showUI) {
Expand Down Expand Up @@ -219,6 +224,7 @@ public class MainScreen extends Screen {

void mouseWheel(MouseEvent event) {
pivotButton.hide();
importButton.hide();
if (!partsList.isInside()) {
float z = pow(1.1, -event.getCount());
Affine2 unproject = new Affine2(transform).inv();
Expand All @@ -238,6 +244,7 @@ public class MainScreen extends Screen {


void mousePressed(MouseEvent event) {
mouse_button = event.getButton();
if (transport.contains(mouseX, mouseY))
transport.isMoving = true;
else if (timeline != null && timeline.contains(mouseX, mouseY))
Expand All @@ -249,6 +256,8 @@ public class MainScreen extends Screen {
transport.isMoving = false;
if (timeline != null)
timeline.isMoving = false;

mouse_button = 0;
}


Expand All @@ -263,21 +272,27 @@ public class MainScreen extends Screen {
playing = true;
}
pivotButton.hide();
importButton.hide();
} else {
// RIGHT CLICK opens context menu (pivot button)
int btn_y = 0;
if (selected != null) {
pivotButton.setPosition(mouseX, mouseY);
pivotButton.setPosition(mouseX, mouseY+btn_y);
pivotButton.show();
btn_y += 20;
}
importButton.setPosition(mouseX, mouseY+btn_y);
importButton.show();
}
}


void mouseDragged(MouseEvent event) {
pivotButton.hide();
importButton.hide();
int dx = mouseX-pmouseX;
int dy = mouseY-pmouseY;
if (event.getButton() == RIGHT) {
if (mouse_button == RIGHT) {
if (keyPressed && keyCode == SHIFT && selected != null) {
// scale translation by the zoom factor
hardTransform.translate(dx/transform.m00, dy/transform.m11);
Expand Down
16 changes: 8 additions & 8 deletions SgAnimator.pde
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

// TODO:
// Lib : Points de pivots différents par postures
// Option to reset control values (by double clicking on them ?)
// Elastic function
// Option to duplicate previous AnimationCollection when new animCollection
// UV coords in polygon class
// Add a chart for every Animation to show function progression over time
// Lib : avatar.playSequentially()
// Ouverture de plusieurs fichiers avec Tabs
// Librairie d'Avatars à l'ouverture d'un fichier
// Add a chart for every Animation to show function progression over time

/*
BUGS:
* fullscreen
* Can't select axe before function
* Resize window doesn't resize UI immediately (click on displaced controls are missed)
* Part list disapearing (Remove part list header Bar)
* fullscreen
* Resize window doesn't resize UI immediately (click on displaced controls are missed)
* Part list disapearing (Remove part list header Bar)
*/


Expand All @@ -33,7 +33,7 @@ import java.util.*;
import java.lang.reflect.Field;


String version = "0.7.0";
String version = "0.7.1";
String appName = "SgAnimator " + version;


Expand Down Expand Up @@ -72,8 +72,8 @@ void settings() {


void setup() {
surface.setResizable(true);
surface.setTitle(appName);
windowResizable(true);
windowTitle(appName);

mainScreen = new MainScreen();
welcomeScreen = new WelcomeScreen();
Expand Down
14 changes: 13 additions & 1 deletion UI.pde
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ControlP5 cp5; //<>//
FunctionAccordion accordion;
Button pivotButton;
Button importButton;


PFont defaultFont;
Expand Down Expand Up @@ -170,13 +171,23 @@ void setupUI() {
accordion = new FunctionAccordion(cp5, "accordion");

pivotButton = cp5.addButton("pivotbutton")
.setPosition(300, 10)
//.setPosition(300, 10)
.setSize(70, 20)
.setSwitch(true)
.activateBy(ControlP5.PRESS)
.setLabel("Set pivot")
.hide()
;

importButton = cp5.addButton("importbutton")
//.setPosition(300, 30)
.setSize(70, 20)
.setSwitch(true)
.activateBy(ControlP5.PRESS)
.setLabel("Import")
.hide()
;

}


Expand Down Expand Up @@ -538,6 +549,7 @@ void hideUI() {
accordion.hide();
partsList.hide();
pivotButton.hide();
importButton.hide();
transport.hide();
renderer.setSelected(null);
if (timeline != null)
Expand Down
2 changes: 1 addition & 1 deletion WelcomeScreen.pde
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class WelcomeScreen extends Screen {
text("Ver. " + version, width-100, height-40);
text("Lib. " + MyRenderer.version(), width-100, height-20);
}

@Override
void mouseClicked(MouseEvent event) {
selectInput("Select a file", "inputFileSelected");
Expand Down
4 changes: 4 additions & 0 deletions changes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
0.7.1
* Values from controlers are rounded to 2 decimals
* Axe can be chosen before function for new animations
* Opening a corrupted json file will not make the program crash anymore

0 comments on commit b38d5e7

Please sign in to comment.