Преглед изворни кода

Update lights, add curve in fx editor

ShiroSmith пре 5 година
родитељ
комит
29a74fc437
4 измењених фајлова са 85 додато и 9 уклоњено
  1. 31 0
      hide/view/FXEditor.hx
  2. 2 8
      hrt/prefab/Light.hx
  3. 9 1
      hrt/prefab/fx/BaseFX.hx
  4. 43 0
      hrt/prefab/fx/FX.hx

+ 31 - 0
hide/view/FXEditor.hx

@@ -1225,6 +1225,7 @@ class FXEditor extends FileView {
 		var emitterElt = Std.downcast(elt, hrt.prefab.fx.Emitter);
 		var particle2dElt = Std.downcast(elt, hrt.prefab.fx2d.Particle2D);
 		var menuItems : Array<hide.comp.ContextMenu.ContextMenuItem> = [];
+		var lightElt = Std.downcast(elt, Light);
 
 		inline function hasTrack(pname) {
 			return getTrack(elt, pname) != null;
@@ -1367,6 +1368,36 @@ class FXEditor extends FileView {
 				addParam(param, "");
 			}
 		}
+		if( lightElt != null ) {
+			switch lightElt.kind {
+				case Point:
+					menuItems.push({
+						label: "PointLight",
+						menu: [	trackItem("Color", hslTracks(), "color"),
+								trackItem("Power",[{name: "power"}]),
+								trackItem("Size", [{name: "size"}]),
+								trackItem("Range", [{name: "range"}]), 
+								]
+					});
+				case Directional:
+					menuItems.push({
+						label: "DirLight",
+						menu: [	trackItem("Color", hslTracks(), "color"),
+								trackItem("Power",[{name: "power"}]),
+								]
+					});
+				case Spot:
+					menuItems.push({
+						label: "SpotLight",
+						menu: [	trackItem("Color", hslTracks(), "color"),
+								trackItem("Power",[{name: "power"}]),
+								trackItem("Range", [{name: "range"}]),
+								trackItem("Angle", [{name: "angle"}]),
+								trackItem("FallOff", [{name: "fallOff"}]), 
+								]
+					});
+			}
+		}
 		return menuItems;
 	}
 

+ 2 - 8
hrt/prefab/Light.hx

@@ -55,7 +55,6 @@ class Light extends Object3D {
 	public var zNear : Float = 0.02;
 
 	// Spot
-	public var maxRange : Float = 20;
 	public var angle : Float = 90;
 	public var fallOff : Float = 80;
 	public var cookieTex : h3d.mat.Texture = null;
@@ -90,7 +89,6 @@ class Light extends Object3D {
 		obj.isMainLight = isMainLight;
 		obj.angle = angle;
 		obj.fallOff = fallOff;
-		obj.maxRange = maxRange;
 		obj.cookiePath = cookiePath;
 		obj.occlusionFactor = occlusionFactor;
 
@@ -112,7 +110,6 @@ class Light extends Object3D {
 		isMainLight = obj.isMainLight;
 		angle = obj.angle;
 		fallOff = obj.fallOff;
-		maxRange = obj.maxRange;
 		cookiePath = obj.cookiePath;
 		occlusionFactor = obj.occlusionFactor == null ? 0.0 : obj.occlusionFactor;
 
@@ -207,7 +204,6 @@ class Light extends Object3D {
 			case Spot:
 				var sl = Std.downcast(light, h3d.scene.pbr.SpotLight);
 				sl.range = range;
-				sl.maxRange = maxRange;
 				sl.angle = angle;
 				sl.fallOff = fallOff;
 				sl.cookie = cookieTex;
@@ -245,7 +241,6 @@ class Light extends Object3D {
 		}
 
 		#if editor
-
 		var debugPoint = ctx.local3d.find(c -> if(c.name == "_debugPoint") c else null);
 		var debugDir = ctx.local3d.find(c -> if(c.name == "_debugDir") c else null);
 		var debugSpot = ctx.local3d.find(c -> if(c.name == "_debugSpot") c else null);
@@ -363,7 +358,7 @@ class Light extends Object3D {
 					sel = g;
 				}
 
-				mesh.setScale(0.2/maxRange);
+				mesh.setScale(0.2/range);
 		}
 
 		if(mesh != null){
@@ -429,8 +424,7 @@ class Light extends Object3D {
 		switch( kind ) {
 		case Spot:
 			group.append(hide.comp.PropsEditor.makePropsList([
-				{ name: "range", t: PFloat(1, 200), def: 10 },
-				{ name: "maxRange", t: PFloat(1, 200), def: 10 },
+				{ name: "range", t: PFloat(1, 20), def: 10 },
 				{ name: "angle", t: PFloat(1, 90), def: 90 },
 				{ name: "fallOff", t: PFloat(1, 90), def: 80 },
 				{ name: "cookiePath", t: PTexture },

+ 9 - 1
hrt/prefab/fx/BaseFX.hx

@@ -7,6 +7,13 @@ typedef ShaderParam = {
 	value: Value
 };
 
+enum AdditionalProperies {
+	None;
+	PointLight(color : Value, power : Value, size : Value, range : Value );
+	SpotLight(color : Value, power : Value, range : Value, angle : Value, fallOff : Value );
+	DirLight(color : Value, power : Value);
+}
+
 typedef ShaderParams = Array<ShaderParam>;
 
 class ShaderAnimation extends Evaluator {
@@ -45,7 +52,8 @@ typedef ObjectAnimation = {
 	?scale: Value,
 	?rotation: Value,
 	?color: Value,
-	?visibility: Value
+	?visibility: Value,
+	?additionalProperies : AdditionalProperies
 };
 
 class BaseFX extends hrt.prefab.Library {

+ 43 - 0
hrt/prefab/fx/FX.hx

@@ -1,9 +1,11 @@
 package hrt.prefab.fx;
+import hrt.prefab.fx.BaseFX.AdditionalProperies;
 import hrt.prefab.Curve;
 import hrt.prefab.Prefab as PrefabElement;
 import hrt.prefab.fx.BaseFX.ObjectAnimation;
 import hrt.prefab.fx.BaseFX.ShaderAnimation;
 
+
 @:allow(hrt.prefab.fx.FX)
 class FXAnimation extends h3d.scene.Object {
 
@@ -162,6 +164,35 @@ class FXAnimation extends h3d.scene.Object {
 					}
 				}
 				Event.updateEvents(anim.events, time, prevTime);
+
+				if( anim.additionalProperies != null ) {
+					switch(anim.additionalProperies) {
+						case None :
+						case PointLight( color, power, size, range ) :
+							var l = Std.downcast(anim.obj, h3d.scene.pbr.PointLight);
+							if( l != null ) {
+								if( color != null ) l.color = evaluator.getVector(color, time, tempVec);
+								if( power != null ) l.power = evaluator.getFloat(power, time);
+								if( size != null ) l.size = evaluator.getFloat(size, time);
+								if( range != null ) l.range = evaluator.getFloat(range, time);
+							}
+						case DirLight(color, power):
+							var l = Std.downcast(anim.obj, h3d.scene.pbr.DirLight);
+							if( l != null ) {
+								if( color != null ) l.color = evaluator.getVector(color, time, tempVec);
+								if( power != null ) l.power = evaluator.getFloat(power, time);
+							}
+						case SpotLight(color, power, range, angle, fallOff):
+							var l = Std.downcast(anim.obj, h3d.scene.pbr.SpotLight);
+							if( l != null ) {
+								if( color != null ) l.color = evaluator.getVector(color, time, tempVec);
+								if( power != null ) l.power = evaluator.getFloat(power, time);
+								if( range != null ) l.range = evaluator.getFloat(range, time);
+								if( angle != null ) l.angle = evaluator.getFloat(angle, time);
+								if( fallOff != null ) l.fallOff = evaluator.getFloat(fallOff, time);
+							}
+					}
+				}
 			}
 		}
 
@@ -248,6 +279,17 @@ class FXAnimation extends h3d.scene.Object {
 			return Curve.getColorValue(curves);
 		}
 
+		var ap : AdditionalProperies = null;
+		if( Std.is(objCtx.local3d, h3d.scene.pbr.PointLight)) {
+			ap = PointLight(makeColor("color"), makeVal("power", null), makeVal("size", null), makeVal("range", null) );
+		}
+		else if( Std.is(objCtx.local3d, h3d.scene.pbr.SpotLight)) {
+			ap = SpotLight(makeColor("color"), makeVal("power", null), makeVal("range", null), makeVal("angle", null), makeVal("fallOff", null) );
+		}
+		else if( Std.is(objCtx.local3d, h3d.scene.pbr.DirLight)) {
+			ap = DirLight(makeColor("color"), makeVal("power", null));
+		}
+
 		var anim : ObjectAnimation = {
 			elt: obj3d,
 			obj: objCtx.local3d,
@@ -257,6 +299,7 @@ class FXAnimation extends h3d.scene.Object {
 			rotation: makeVector("rotation", 0.0, 360.0),
 			color: makeColor("color"),
 			visibility: makeVal("visibility", null),
+			additionalProperies: ap,
 		};
 
 		anim.events = initEvents(elt, objCtx);