Browse Source

added retarget animation toggle

Nicolas Cannasse 4 years ago
parent
commit
b4e94480eb
1 changed files with 17 additions and 0 deletions
  1. 17 0
      hide/view/Model.hx

+ 17 - 0
hide/view/Model.hx

@@ -17,6 +17,7 @@ class Model extends FileView {
 	var aspeed : hide.comp.Range;
 	var aspeed : hide.comp.Range;
 	var aloop : { function toggle( v : Bool ) : Void; var element : Element; }
 	var aloop : { function toggle( v : Bool ) : Void; var element : Element; }
 	var apause : { function toggle( v : Bool ) : Void; var element : Element; };
 	var apause : { function toggle( v : Bool ) : Void; var element : Element; };
+	var aretarget : { var element : Element; };
 	var timeline : h2d.Graphics;
 	var timeline : h2d.Graphics;
 	var timecursor : h2d.Bitmap;
 	var timecursor : h2d.Bitmap;
 	var frameIndex : h2d.Text;
 	var frameIndex : h2d.Text;
@@ -418,6 +419,10 @@ class Model extends FileView {
 			if( obj.currentAnimation != null ) obj.currentAnimation.pause = v;
 			if( obj.currentAnimation != null ) obj.currentAnimation.pause = v;
 		});
 		});
 
 
+		aretarget = tools.addToggle("share-square-o", "Retarget Animation", function(b) {
+			setRetargetAnim(b);
+		});
+
 		aspeed = tools.addRange("Animation speed", function(v) {
 		aspeed = tools.addRange("Animation speed", function(v) {
 			if( obj.currentAnimation != null ) obj.currentAnimation.speed = v;
 			if( obj.currentAnimation != null ) obj.currentAnimation.speed = v;
 		}, 1, 0, 2);
 		}, 1, 0, 2);
@@ -428,6 +433,17 @@ class Model extends FileView {
 		setAnimation(null);
 		setAnimation(null);
 	}
 	}
 
 
+	function setRetargetAnim(b:Bool) {
+		for( m in obj.getMeshes() ) {
+			var sk = Std.downcast(m, h3d.scene.Skin);
+			if( sk == null ) continue;
+			for( j in sk.getSkinData().allJoints ) {
+				if( j.parent == null ) continue; // skip root join (might contain feet translation)
+				j.retargetAnim = b;
+			}
+		}
+	}
+
 	function initConsole() {
 	function initConsole() {
 		var c = new h2d.Console(hxd.res.DefaultFont.get(), scene.s2d);
 		var c = new h2d.Console(hxd.res.DefaultFont.get(), scene.s2d);
 		c.addCommand("rotate",[{ name : "speed", t : AFloat }], function(r) {
 		c.addCommand("rotate",[{ name : "speed", t : AFloat }], function(r) {
@@ -486,6 +502,7 @@ class Model extends FileView {
 		aloop.element.toggle(file != null);
 		aloop.element.toggle(file != null);
 		aspeed.element.toggle(file != null);
 		aspeed.element.toggle(file != null);
 		apause.element.toggle(file != null);
 		apause.element.toggle(file != null);
+		aretarget.element.toggle(file != null);
 		if( file == null ) {
 		if( file == null ) {
 			obj.stopAnimation();
 			obj.stopAnimation();
 			currentAnimation = null;
 			currentAnimation = null;