Parcourir la source

FX: Support obj anims

trethaller il y a 7 ans
Parent
commit
38dfa5543d
3 fichiers modifiés avec 22 ajouts et 10 suppressions
  1. 1 1
      hide/prefab/fx/Emitter.hx
  2. 17 5
      hide/prefab/fx/FXScene.hx
  3. 4 4
      hide/view/FXScene.hx

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

@@ -60,7 +60,7 @@ private class ParticleInstance extends Evaluator {
 		curPos.x += curVelocity.x * dt;
 		curPos.y += curVelocity.y * dt;
 		curPos.z += curVelocity.z * dt;
-		obj.setPos(curPos.x, curPos.y, curPos.z);
+		obj.setPosition(curPos.x, curPos.y, curPos.z);
 
 		var scaleVec = getVector(def.scale, life);
 		obj.scaleX = scaleVec.x;

+ 17 - 5
hide/prefab/fx/FXScene.hx

@@ -108,12 +108,14 @@ typedef ObjectAnimation = {
 	curves: ObjectCurves
 };
 
-class FXAnimation {
+class FXAnimation extends h3d.scene.Object {
 	
 	public var objects: Array<ObjectAnimation> = [];
 	public var shaderAnims : Array<ShaderAnimation> = [];
 
-	public function new() { }
+	public function new(?parent) {
+		super(parent);
+	}
 
 	public function setTime(time: Float) {
 		for(anim in objects) {
@@ -129,6 +131,16 @@ class FXAnimation {
 		for(anim in shaderAnims) {
 			anim.setTime(time);
 		}
+
+		for(i in 0...numChildren) {
+			var child = getChildAt(i);
+			if(child.currentAnimation != null) {
+				var anim = child.currentAnimation;
+				anim.loop = false;
+				anim.pause = true;
+				anim.setFrame(hxd.Math.clamp(time * anim.sampling * anim.speed, 0, anim.frameCount));
+			}
+		}
 	}
 
 	public function getTransform(curves: ObjectCurves, time: Float, ?m: h3d.Matrix) {
@@ -221,11 +233,11 @@ class FXScene extends Library {
 		if( inRec )
 			return ctx;
 		ctx = ctx.clone(this);
-		super.makeInstance(ctx);
-		var anim = new FXAnimation();
+		var anim = new FXAnimation(ctx.local3d);
 		getObjAnimations(ctx, this, anim.objects);
 		getShaderAnims(ctx, this, anim.shaderAnims);
-		ctx.custom = anim;
+		ctx.local3d = anim;
+		super.makeInstance(ctx);
 		return ctx; 
 	}
 

+ 4 - 4
hide/view/FXScene.hx

@@ -46,7 +46,7 @@ private class FXSceneEditor extends hide.comp.SceneEditor {
 			});
 
 			var allRegs = @:privateAccess hide.prefab.Library.registeredElements;
-			var allowed = ["model", "object", "shader", "emitter"];
+			var allowed = ["model", "object", "shader", "emitter", "constraint", "polygon"];
 			for( ptype in allowed ) {
 				var pcl = allRegs.get(ptype);
 				var props = Type.createEmptyInstance(pcl).getHideProps();
@@ -736,8 +736,8 @@ class FXScene extends FileView {
 	function onUpdate(dt:Float) {
 
 		var ctx = sceneEditor.getContext(data);
-		if(ctx != null && ctx.custom != null) {
-			var anim : hide.prefab.fx.FXScene.FXAnimation = cast ctx.custom;
+		if(ctx != null && ctx.local3d != null) {
+			var anim : hide.prefab.fx.FXScene.FXAnimation = cast ctx.local3d;
 			anim.setTime(currentTime);
 		}
 		// var allObjects = data.getAll(hide.prefab.Object3D);
@@ -774,7 +774,7 @@ class FXScene extends FileView {
 		}
 
 		if(true) {
-			currentTime += dt / hxd.Timer.wantedFPS;
+			currentTime += scene.speed * dt / hxd.Timer.wantedFPS;
 			if(timeLineEl != null)
 				timeLineEl.css({left: xt(currentTime)});
 			if(currentTime >= selectMax) {