Browse Source

added AnimSpeedControl, fix dynamicshader source remap

Nicolas Cannasse 4 years ago
parent
commit
e6befa043e
3 changed files with 39 additions and 1 deletions
  1. 1 0
      hide.hxml
  2. 1 1
      hrt/prefab/DynamicShader.hx
  3. 37 0
      hrt/prefab/l3d/AnimSpeedControl.hx

+ 1 - 0
hide.hxml

@@ -8,5 +8,6 @@ common.hxml
 --macro include("hxd.poly2tri")
 --macro include("hxd.clipper")
 --macro include("hxd.earcut")
+--macro include("hrt.prefab")
 -dce no
 -debug

+ 1 - 1
hrt/prefab/DynamicShader.hx

@@ -65,8 +65,8 @@ class DynamicShader extends Shader {
 		path = path.split("\\").join("/");
 		if( StringTools.startsWith(path.toLowerCase(), shadersPath.toLowerCase()+"/") ) {
 			path = path.substr(shadersPath.length + 1);
+			source = path;
 		}
-		source = path;
 		#end
 	}
 

+ 37 - 0
hrt/prefab/l3d/AnimSpeedControl.hx

@@ -0,0 +1,37 @@
+package hrt.prefab.l3d;
+
+class AnimSpeedControl extends hrt.prefab.Prefab {
+
+	@:s var speed : Float = 1.;
+
+	override function makeInstance(ctx:Context):Context {
+		ctx = ctx.clone(this);
+		updateInstance(ctx);
+		return ctx;
+	}
+
+	override function updateInstance(ctx:Context,?propName) {
+		if( ctx.local3d != null && ctx.local3d.currentAnimation != null )
+			ctx.local3d.currentAnimation.speed = speed;
+	}
+
+	#if editor
+	override function getHideProps() : HideProps {
+		return {
+			name : "AnimSpeedCtrl",
+			icon : "cog",
+			allowParent : (p) -> Std.is(p,Object3D),
+		};
+	}
+	override function edit(ctx:EditContext) {
+		ctx.properties.add(new Element('<dl>
+			<dt>Speed</dt><dd><input type="range" field="speed"/></dd>
+		</dl>'), this, function(p) {
+			ctx.onChange(this, p);
+		});
+	}
+	#end
+
+	static var _ = Library.register("animSpeedCtrl", AnimSpeedControl);
+
+}