|
@@ -1,50 +1,8 @@
|
|
package hrt.prefab.fx;
|
|
package hrt.prefab.fx;
|
|
import hrt.prefab.Curve;
|
|
import hrt.prefab.Curve;
|
|
import hrt.prefab.Prefab as PrefabElement;
|
|
import hrt.prefab.Prefab as PrefabElement;
|
|
-
|
|
|
|
-typedef ShaderParam = {
|
|
|
|
- def: hxsl.Ast.TVar,
|
|
|
|
- value: Value
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-typedef ShaderParams = Array<ShaderParam>;
|
|
|
|
-
|
|
|
|
-class ShaderAnimation extends Evaluator {
|
|
|
|
- public var params : ShaderParams;
|
|
|
|
- public var shader : hxsl.DynamicShader;
|
|
|
|
-
|
|
|
|
- public function setTime(time: Float) {
|
|
|
|
- for(param in params) {
|
|
|
|
- var v = param.def;
|
|
|
|
- switch(v.type) {
|
|
|
|
- case TFloat:
|
|
|
|
- var val = getFloat(param.value, time);
|
|
|
|
- shader.setParamValue(v, val);
|
|
|
|
- case TInt:
|
|
|
|
- var val = hxd.Math.round(getFloat(param.value, time));
|
|
|
|
- shader.setParamValue(v, val);
|
|
|
|
- case TBool:
|
|
|
|
- var val = getFloat(param.value, time) >= 0.5;
|
|
|
|
- shader.setParamValue(v, val);
|
|
|
|
- case TVec(_, VFloat):
|
|
|
|
- var val = getVector(param.value, time);
|
|
|
|
- shader.setParamValue(v, val);
|
|
|
|
- default:
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-typedef ObjectAnimation = {
|
|
|
|
- elt: hrt.prefab.Object3D,
|
|
|
|
- obj: h3d.scene.Object,
|
|
|
|
- events: Array<hrt.prefab.fx.Event.EventInstance>,
|
|
|
|
- ?position: Value,
|
|
|
|
- ?scale: Value,
|
|
|
|
- ?rotation: Value,
|
|
|
|
- ?color: Value,
|
|
|
|
- ?visibility: Value
|
|
|
|
-};
|
|
|
|
|
|
+import hrt.prefab.fx.BaseFX.ObjectAnimation;
|
|
|
|
+import hrt.prefab.fx.BaseFX.ShaderAnimation;
|
|
|
|
|
|
class FXAnimation extends h3d.scene.Object {
|
|
class FXAnimation extends h3d.scene.Object {
|
|
|
|
|
|
@@ -56,7 +14,6 @@ class FXAnimation extends h3d.scene.Object {
|
|
public var duration : Float;
|
|
public var duration : Float;
|
|
public var cullingRadius : Float;
|
|
public var cullingRadius : Float;
|
|
|
|
|
|
- public var loopAnims : Bool;
|
|
|
|
public var objects: Array<ObjectAnimation> = [];
|
|
public var objects: Array<ObjectAnimation> = [];
|
|
public var shaderAnims : Array<ShaderAnimation> = [];
|
|
public var shaderAnims : Array<ShaderAnimation> = [];
|
|
public var emitters : Array<hrt.prefab.fx.Emitter.EmitterObject> = [];
|
|
public var emitters : Array<hrt.prefab.fx.Emitter.EmitterObject> = [];
|
|
@@ -204,25 +161,16 @@ class FXAnimation extends h3d.scene.Object {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-class FX extends hrt.prefab.Library {
|
|
|
|
-
|
|
|
|
- public var duration : Float;
|
|
|
|
- public var loopAnims : Bool;
|
|
|
|
- public var scriptCode : String;
|
|
|
|
- public var cullingRadius : Float;
|
|
|
|
|
|
+class FX extends BaseFX {
|
|
|
|
|
|
public function new() {
|
|
public function new() {
|
|
super();
|
|
super();
|
|
type = "fx";
|
|
type = "fx";
|
|
- duration = 5.0;
|
|
|
|
cullingRadius = 3.0;
|
|
cullingRadius = 3.0;
|
|
- loopAnims = true;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
override function save() {
|
|
override function save() {
|
|
var obj : Dynamic = super.save();
|
|
var obj : Dynamic = super.save();
|
|
- obj.duration = duration;
|
|
|
|
- obj.loopAnims = loopAnims;
|
|
|
|
obj.cullingRadius = cullingRadius;
|
|
obj.cullingRadius = cullingRadius;
|
|
if( scriptCode != "" ) obj.scriptCode = scriptCode;
|
|
if( scriptCode != "" ) obj.scriptCode = scriptCode;
|
|
return obj;
|
|
return obj;
|
|
@@ -230,13 +178,17 @@ class FX extends hrt.prefab.Library {
|
|
|
|
|
|
override function load( obj : Dynamic ) {
|
|
override function load( obj : Dynamic ) {
|
|
super.load(obj);
|
|
super.load(obj);
|
|
- duration = obj.duration == null ? 5.0 : obj.duration;
|
|
|
|
- loopAnims = obj.loopAnims == null ? true : obj.loopAnims;
|
|
|
|
if(obj.cullingRadius != null)
|
|
if(obj.cullingRadius != null)
|
|
cullingRadius = obj.cullingRadius;
|
|
cullingRadius = obj.cullingRadius;
|
|
scriptCode = obj.scriptCode;
|
|
scriptCode = obj.scriptCode;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ override public function refreshObjectAnims(ctx: Context) {
|
|
|
|
+ var fxanim = Std.downcast(ctx.local3d, FXAnimation);
|
|
|
|
+ fxanim.objects = [];
|
|
|
|
+ getObjAnimations(ctx, this, fxanim.objects);
|
|
|
|
+ }
|
|
|
|
+
|
|
static function getObjAnimations(ctx:Context, elt: PrefabElement, anims: Array<ObjectAnimation>) {
|
|
static function getObjAnimations(ctx:Context, elt: PrefabElement, anims: Array<ObjectAnimation>) {
|
|
if(Std.downcast(elt, hrt.prefab.fx.Emitter) == null) {
|
|
if(Std.downcast(elt, hrt.prefab.fx.Emitter) == null) {
|
|
// Don't extract animations for children of Emitters
|
|
// Don't extract animations for children of Emitters
|
|
@@ -308,79 +260,6 @@ class FX extends hrt.prefab.Library {
|
|
anims.push(anim);
|
|
anims.push(anim);
|
|
}
|
|
}
|
|
|
|
|
|
- public function refreshObjectAnims(ctx: Context) {
|
|
|
|
- var fxanim = Std.downcast(ctx.local3d, FXAnimation);
|
|
|
|
- fxanim.objects = [];
|
|
|
|
- getObjAnimations(ctx, this, fxanim.objects);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public static function makeShaderParams(ctx: Context, shaderElt: hrt.prefab.Shader) {
|
|
|
|
- shaderElt.loadShaderDef(ctx);
|
|
|
|
- var shaderDef = shaderElt.shaderDef;
|
|
|
|
- if(shaderDef == null)
|
|
|
|
- return null;
|
|
|
|
-
|
|
|
|
- var ret : ShaderParams = [];
|
|
|
|
-
|
|
|
|
- for(v in shaderDef.shader.data.vars) {
|
|
|
|
- if(v.kind != Param)
|
|
|
|
- continue;
|
|
|
|
-
|
|
|
|
- var prop = Reflect.field(shaderElt.props, v.name);
|
|
|
|
- if(prop == null)
|
|
|
|
- prop = hrt.prefab.Shader.getDefault(v.type);
|
|
|
|
-
|
|
|
|
- var curves = Curve.getCurves(shaderElt, v.name);
|
|
|
|
- if(curves == null || curves.length == 0)
|
|
|
|
- continue;
|
|
|
|
-
|
|
|
|
- switch(v.type) {
|
|
|
|
- case TVec(_, VFloat) :
|
|
|
|
- var isColor = v.name.toLowerCase().indexOf("color") >= 0;
|
|
|
|
- var val = isColor ? Curve.getColorValue(curves) : Curve.getVectorValue(curves);
|
|
|
|
- ret.push({
|
|
|
|
- def: v,
|
|
|
|
- value: val
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- default:
|
|
|
|
- var base = 1.0;
|
|
|
|
- if(Std.is(prop, Float) || Std.is(prop, Int))
|
|
|
|
- base = cast prop;
|
|
|
|
- var curve = Curve.getCurve(shaderElt, v.name);
|
|
|
|
- var val = Value.VConst(base);
|
|
|
|
- if(curve != null)
|
|
|
|
- val = Value.VCurveScale(curve, base);
|
|
|
|
- ret.push({
|
|
|
|
- def: v,
|
|
|
|
- value: val
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return ret;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public static function getShaderAnims(ctx: Context, elt: PrefabElement, anims: Array<ShaderAnimation>) {
|
|
|
|
- if(Std.downcast(elt, hrt.prefab.fx.Emitter) == null) {
|
|
|
|
- for(c in elt.children) {
|
|
|
|
- getShaderAnims(ctx, c, anims);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- var shader = elt.to(hrt.prefab.Shader);
|
|
|
|
- if(shader == null)
|
|
|
|
- return;
|
|
|
|
-
|
|
|
|
- for(shCtx in ctx.shared.getContexts(elt)) {
|
|
|
|
- if(shCtx.custom == null) continue;
|
|
|
|
- var anim: ShaderAnimation = new ShaderAnimation(new hxd.Rand(0));
|
|
|
|
- anim.shader = shCtx.custom;
|
|
|
|
- anim.params = makeShaderParams(ctx, shader);
|
|
|
|
- anims.push(anim);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
function getEmitters(ctx: Context, elt: PrefabElement, emitters: Array<hrt.prefab.fx.Emitter.EmitterObject>) {
|
|
function getEmitters(ctx: Context, elt: PrefabElement, emitters: Array<hrt.prefab.fx.Emitter.EmitterObject>) {
|
|
var em = Std.downcast(elt, hrt.prefab.fx.Emitter);
|
|
var em = Std.downcast(elt, hrt.prefab.fx.Emitter);
|
|
if(em != null) {
|
|
if(em != null) {
|
|
@@ -396,36 +275,10 @@ class FX extends hrt.prefab.Library {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- function getFXRoot( ctx : Context, elt : PrefabElement ) : PrefabElement {
|
|
|
|
- if( elt.name == "FXRoot" )
|
|
|
|
- return elt;
|
|
|
|
- else {
|
|
|
|
- for(c in elt.children) {
|
|
|
|
- var elt = getFXRoot(ctx, c);
|
|
|
|
- if(elt != null) return elt;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- function getConstraints( ctx : Context, elt : PrefabElement, constraints : Array<hrt.prefab.Constraint>){
|
|
|
|
- var co = Std.downcast(elt, hrt.prefab.Constraint);
|
|
|
|
- if(co != null)
|
|
|
|
- constraints.push(co);
|
|
|
|
- else
|
|
|
|
- for(c in elt.children)
|
|
|
|
- getConstraints(ctx, c, constraints);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- function createInstance(parent: h3d.scene.Object) : FXAnimation {
|
|
|
|
- return new FXAnimation(parent);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
override function make( ctx : Context ) : Context {
|
|
override function make( ctx : Context ) : Context {
|
|
ctx = ctx.clone(this);
|
|
ctx = ctx.clone(this);
|
|
var fxanim = createInstance(ctx.local3d);
|
|
var fxanim = createInstance(ctx.local3d);
|
|
fxanim.duration = duration;
|
|
fxanim.duration = duration;
|
|
- fxanim.loopAnims = loopAnims;
|
|
|
|
fxanim.cullingRadius = cullingRadius;
|
|
fxanim.cullingRadius = cullingRadius;
|
|
ctx.local3d = fxanim;
|
|
ctx.local3d = fxanim;
|
|
fxanim.playSpeed = 1.0;
|
|
fxanim.playSpeed = 1.0;
|
|
@@ -446,7 +299,7 @@ class FX extends hrt.prefab.Library {
|
|
#end
|
|
#end
|
|
|
|
|
|
getObjAnimations(ctx, this, fxanim.objects);
|
|
getObjAnimations(ctx, this, fxanim.objects);
|
|
- getShaderAnims(ctx, this, fxanim.shaderAnims);
|
|
|
|
|
|
+ BaseFX.getShaderAnims(ctx, this, fxanim.shaderAnims);
|
|
getEmitters(ctx, this, fxanim.emitters);
|
|
getEmitters(ctx, this, fxanim.emitters);
|
|
|
|
|
|
if(scriptCode != null && scriptCode != ""){
|
|
if(scriptCode != null && scriptCode != ""){
|
|
@@ -462,10 +315,13 @@ class FX extends hrt.prefab.Library {
|
|
super.updateInstance(ctx, null);
|
|
super.updateInstance(ctx, null);
|
|
var fxanim = Std.downcast(ctx.local3d, FXAnimation);
|
|
var fxanim = Std.downcast(ctx.local3d, FXAnimation);
|
|
fxanim.duration = duration;
|
|
fxanim.duration = duration;
|
|
- fxanim.loopAnims = loopAnims;
|
|
|
|
fxanim.cullingRadius = cullingRadius;
|
|
fxanim.cullingRadius = cullingRadius;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ function createInstance(parent: h3d.scene.Object) : FXAnimation {
|
|
|
|
+ return new FXAnimation(parent);
|
|
|
|
+ }
|
|
|
|
+
|
|
#if editor
|
|
#if editor
|
|
override function edit( ctx : EditContext ) {
|
|
override function edit( ctx : EditContext ) {
|
|
var props = new hide.Element('
|
|
var props = new hide.Element('
|
|
@@ -473,7 +329,6 @@ class FX extends hrt.prefab.Library {
|
|
<dl>
|
|
<dl>
|
|
<dt>Duration</dt><dd><input type="number" value="0" field="duration"/></dd>
|
|
<dt>Duration</dt><dd><input type="number" value="0" field="duration"/></dd>
|
|
<dt>Culling radius</dt><dd><input type="number" field="cullingRadius"/></dd>
|
|
<dt>Culling radius</dt><dd><input type="number" field="cullingRadius"/></dd>
|
|
- <dt>Loop Anims</dt><dd><input type="checkbox" field="loopAnims"/></dd>
|
|
|
|
</dl>
|
|
</dl>
|
|
</div>');
|
|
</div>');
|
|
ctx.properties.add(props, this, function(pname) {
|
|
ctx.properties.add(props, this, function(pname) {
|