2
0
Эх сурвалжийг харах

FX: Rotation curves defined in full-circle units

trethaller 6 жил өмнө
parent
commit
095007ea7d

+ 9 - 5
hide/prefab/Curve.hx

@@ -288,7 +288,7 @@ class Curve extends Prefab {
 		return curves.find(c -> StringTools.endsWith(c.name, suffix));
 	}
 
-	public static function getVectorValue(curves: Array<Curve>, defVal: Float=0.0) : hide.prefab.fx.Value {
+	public static function getVectorValue(curves: Array<Curve>, defVal: Float=0.0, scale: Float=1.0) : hide.prefab.fx.Value {
 		inline function find(s) {
 			return findCurve(curves, s);
 		}
@@ -297,11 +297,15 @@ class Curve extends Prefab {
 		var z = find(".z");
 		var w = find(".w");
 
+		inline function curveOrVal(c: Curve, defVal: Float) : hide.prefab.fx.Value {
+			return c != null ? (scale != 1.0 ? VCurveScale(c, scale) : VCurve(c)) : VConst(defVal);
+		}
+
 		return VVector(
-			x != null ? VCurve(x) : VConst(defVal),
-			y != null ? VCurve(y) : VConst(defVal),
-			z != null ? VCurve(z) : VConst(defVal),
-			w != null ? VCurve(w) : VConst(1.0));
+			curveOrVal(x, defVal),
+			curveOrVal(y, defVal),
+			curveOrVal(z, defVal),
+			curveOrVal(w, 1.0));
 	}
 
 	public static function getColorValue(curves: Array<Curve>) : hide.prefab.fx.Value {

+ 2 - 2
hide/prefab/fx/Emitter.hx

@@ -567,7 +567,7 @@ class Emitter extends Object3D {
 				var xVal : Value = VZero;
 				var xCurve = getCurve(pname + suffix);
 				if(xCurve != null)
-					xVal = VCurveValue(xCurve, baseProp != null ? baseProp : 1.0);
+					xVal = VCurveScale(xCurve, baseProp != null ? baseProp : 1.0);
 				else if(baseProp != null)
 					xVal = VConst(baseProp);
 				else
@@ -576,7 +576,7 @@ class Emitter extends Object3D {
 				var randCurve = getCurve(pname + suffix + ".rand");
 				var randVal : Value = VZero;
 				if(randCurve != null)
-					randVal = VRandom(randIdx++, VCurveValue(randCurve, randProp != null ? randProp : 1.0));
+					randVal = VRandom(randIdx++, VCurveScale(randCurve, randProp != null ? randProp : 1.0));
 				else if(randProp != null)
 					randVal = VRandom(randIdx++, VConst(randProp));
 

+ 2 - 2
hide/prefab/fx/Evaluator.hx

@@ -15,7 +15,7 @@ class Evaluator {
 			case VZero: return 0.0;
 			case VConst(v): return v;
 			case VCurve(c): return c.getVal(time);
-			case VCurveValue(c, scale): return c.getVal(time) * scale;
+			case VCurveScale(c, scale): return c.getVal(time) * scale;
 			case VRandom(idx, scale):
 				var len = randValues.length;
 				while(idx >= len) {
@@ -35,7 +35,7 @@ class Evaluator {
 	public function getSum(val: Value, time: Float) : Float {
 		switch(val) {
 			case VConst(v): return v * time;
-			case VCurveValue(c, scale): return c.getSum(time) * scale;
+			case VCurveScale(c, scale): return c.getSum(time) * scale;
 			case VAdd(a, b):
 				return getSum(a, time) + getSum(b, time);
 			default: 0.0;

+ 5 - 5
hide/prefab/fx/FX.hx

@@ -246,7 +246,7 @@ class FX extends hxd.prefab.Library {
 			return c != null ? VCurve(c) : def;
 		}
 
-		function makeVector(name: String, defVal: Float, uniform: Bool=true) : Value {
+		function makeVector(name: String, defVal: Float, uniform: Bool=true, scale: Float=1.0) : Value {
 			var curves = hide.prefab.Curve.getCurves(elt, name);
 			if(curves == null || curves.length == 0)
 				return null;
@@ -254,9 +254,9 @@ class FX extends hxd.prefab.Library {
 			anyFound = true;
 
 			if(uniform && curves.length == 1 && curves[0].name == name)
-				return VCurve(curves[0]);
+				return scale != 1.0 ? VCurveScale(curves[0], scale) : VCurve(curves[0]);
 
-			return hide.prefab.Curve.getVectorValue(curves, defVal);
+			return hide.prefab.Curve.getVectorValue(curves, defVal, scale);
 		}
 
 		function makeColor(name: String) {
@@ -273,7 +273,7 @@ class FX extends hxd.prefab.Library {
 			obj: objCtx.local3d,
 			position: makeVector("position", 0.0),
 			scale: makeVector("scale", 1.0, true),
-			rotation: makeVector("rotation", 0.0),
+			rotation: makeVector("rotation", 0.0, 360.0),
 			color: makeColor("color"),
 			visibility: makeVal("visibility", null),
 		};
@@ -318,7 +318,7 @@ class FX extends hxd.prefab.Library {
 					var curve = hide.prefab.Curve.getCurve(shaderElt, v.name);
 					var val = Value.VConst(base);
 					if(curve != null)
-						val = Value.VCurveValue(curve, base);
+						val = Value.VCurveScale(curve, base);
 					ret.push({
 						def: v,
 						value: val

+ 1 - 1
hide/prefab/fx/Value.hx

@@ -4,7 +4,7 @@ enum Value {
 	VZero;
 	VConst(v: Float);
 	VCurve(c: Curve);
-	VCurveValue(c: Curve, scale: Float);
+	VCurveScale(c: Curve, scale: Float);
 	VRandom(idx: Int, scale: Value);
 	VAdd(a: Value, b: Value);
 	VMult(a: Value, b: Value);