GpuParticles.hx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. class GpuParticles extends SampleApp {
  2. var parts : h3d.parts.GpuParticles;
  3. var group : h3d.parts.GpuParticles.GpuPartGroup;
  4. var box : h3d.scene.Box;
  5. var tf : h2d.Text;
  6. var moving = false;
  7. var time = 0.;
  8. override function init() {
  9. super.init();
  10. parts = new h3d.parts.GpuParticles(s3d);
  11. var g = new h3d.parts.GpuParticles.GpuPartGroup(parts);
  12. g.emitMode = Cone;
  13. g.emitAngle = 0.5;
  14. g.emitDist = 0;
  15. g.fadeIn = 0.8;
  16. g.fadeOut = 0.8;
  17. g.fadePower = 10;
  18. g.gravity = 1;
  19. g.size = 0.1;
  20. g.sizeRand = 0.5;
  21. g.rotSpeed = 10;
  22. g.speed = 2;
  23. g.speedRand = 0.5;
  24. g.life = 2;
  25. g.lifeRand = 0.5;
  26. g.nparts = 10000;
  27. addSlider("Amount", function() return parts.amount, function(v) parts.amount = v);
  28. addSlider("Speed", function() return g.speed, function(v) g.speed = v, 0, 10);
  29. addSlider("Gravity", function() return g.gravity, function(v) g.gravity = v, 0, 5);
  30. addCheck("Sort", function() return g.sortMode == Dynamic, function(v) g.sortMode = v ? Dynamic : None);
  31. addCheck("Loop", function() return g.emitLoop, function(v) { g.emitLoop = v; if( !v ) parts.currentTime = 0; });
  32. addCheck("Move", function() return moving, function(v) moving = v);
  33. addCheck("Relative", function() return g.isRelative, function(v) g.isRelative = v);
  34. parts.onEnd = function() {
  35. engine.backgroundColor = 0xFF000080;
  36. parts.currentTime = 0;
  37. };
  38. parts.addGroup(g);
  39. group = g;
  40. new h3d.scene.CameraController(20, s3d);
  41. box = new h3d.scene.Box(0x80404050, parts.bounds, parts);
  42. tf = addText();
  43. }
  44. override function update(dt:Float) {
  45. if( moving ) {
  46. time += dt * 0.6;
  47. parts.x = Math.cos(time) * 5;
  48. parts.y = Math.sin(time) * 5;
  49. }
  50. if( engine.backgroundColor&0xFFFFFF > 0 )
  51. engine.backgroundColor -= 8;
  52. var cur = @:privateAccess group.currentParts;
  53. tf.text = ("cur=" + Std.int(cur * 100 / group.nparts) + "%");
  54. if( parts.uploadedCount > 0 )
  55. tf.text += " U="+parts.uploadedCount;
  56. }
  57. static function main() {
  58. new GpuParticles();
  59. }
  60. }