浏览代码

Fix frameStart for particles

ShiroSmith 6 年之前
父节点
当前提交
f1aadff4d4
共有 1 个文件被更改,包括 13 次插入10 次删除
  1. 13 10
      hide/prefab/fx/Emitter.hx

+ 13 - 10
hide/prefab/fx/Emitter.hx

@@ -119,6 +119,8 @@ private class ParticleInstance  {
 	public var life = 0.0;
 	public var lifeTime = 0.0;
 	public var color = new h3d.Vector();
+	public var startFrame : Int;
+
 
 	public var curVelocity = new h3d.Vector();
 	public var orientation = new h3d.Quat();
@@ -424,7 +426,12 @@ class EmitterObject extends h3d.scene.Object {
 					part.setRotation(tmpq);
 					part.orientation = tmpq.clone();
 			}
+
+			var frameCount = frameCount == 0 ? frameDivisionX * frameDivisionY : frameCount;
+			part.startFrame = random.random(frameCount);
 		}
+
+
 		context.local3d = this;
 		emitCount += count;
 	}
@@ -467,20 +474,10 @@ class EmitterObject extends h3d.scene.Object {
 					var pshader = new h3d.shader.AnimatedTexture(mesh.material.texture, frameDivisionX, frameDivisionY, frameCount, frameCount * animationRepeat / lifeTime);
 					pshader.startTime = renderTime;
 					pshader.loop = animationLoop;
-					if( animationRepeat == 0 )
-						pshader.startFrame = random.random(frameCount);
 					mesh.material.mainPass.addShader(pshader);
 				}
 			}
 
-			#if editor
-			/*var shader = new h3d.shader.FixedColor(0xffffff);
-			var p = mesh.material.allocPass("highlight");
-			p.culling = None;
-			p.depthWrite = false;
-			p.addShader(shader);*/
-			#end
-
 			if( meshPrim != null ) {
 				batch = new h3d.scene.MeshBatch(meshPrim, mesh.material, this);
 				batch.name = "batch";
@@ -514,6 +511,12 @@ class EmitterObject extends h3d.scene.Object {
 						var t = hxd.Math.clamp(p.life / p.lifeTime, 0.0, 1.0);
 						anim.setTime(t);
 					}
+					// Init the start frame for each particle
+					var frameCount = frameCount == 0 ? frameDivisionX * frameDivisionY : frameCount;
+					if( frameCount > 0 && animationRepeat == 0 ) {
+						var s = batch.material.mainPass.getShader(h3d.shader.AnimatedTexture);
+						if( s != null) s.startFrame = p.startFrame;
+					}
 					batch.emitInstance();
 				}
 			}