Interactive.hx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //PARAM=-D resourcesPath=../../skin_res
  2. class Interactive extends hxd.App {
  3. var rnd : hxd.Rand;
  4. var light : h3d.scene.DirLight;
  5. var obj : h3d.scene.Object;
  6. var b : h2d.Interactive;
  7. function initInteract( i : h3d.scene.Interactive, m : h3d.scene.Mesh ) {
  8. var beacon = null;
  9. var color = m.material.color.clone();
  10. i.bestMatch = true;
  11. i.onOver = function(e : hxd.Event) {
  12. m.material.color.set(0, 1, 0);
  13. var s = new h3d.prim.Sphere(1, 32, 32);
  14. s.addNormals();
  15. beacon = new h3d.scene.Mesh(s, s3d);
  16. beacon.material.mainPass.enableLights = true;
  17. beacon.material.color.set(1, 0, 0);
  18. beacon.scale(0.01);
  19. beacon.x = e.relX;
  20. beacon.y = e.relY;
  21. beacon.z = e.relZ;
  22. };
  23. i.onMove = i.onCheck = function(e:hxd.Event) {
  24. if( beacon == null ) return;
  25. beacon.x = e.relX;
  26. beacon.y = e.relY;
  27. beacon.z = e.relZ;
  28. };
  29. i.onOut = function(e : hxd.Event) {
  30. m.material.color.load(color);
  31. beacon.remove();
  32. beacon = null;
  33. };
  34. }
  35. override function init() {
  36. light = new h3d.scene.DirLight(new h3d.Vector( 0.3, -0.4, -0.9), s3d);
  37. light.enableSpecular = true;
  38. light.color.set(0.28, 0.28, 0.28);
  39. s3d.lightSystem.ambientLight.set(0.74, 0.74, 0.74);
  40. rnd = new hxd.Rand(5);
  41. for(i in 0...8) {
  42. var c = if( rnd.random(2) == 0 ) new h3d.prim.Cube() else new h3d.prim.Sphere(1,64,32);
  43. //c.unindex();
  44. c.addNormals();
  45. c.addUVs();
  46. var m = new h3d.scene.Mesh(c, s3d);
  47. m.x = rnd.srand() * 0.9;
  48. m.y = rnd.srand() * 0.9;
  49. m.scale(0.25 + rnd.rand() * 0.3);
  50. m.material.mainPass.enableLights = true;
  51. m.material.shadows = true;
  52. var c = 0.3 + rnd.rand() * 0.3;
  53. var color = new h3d.Vector(c, c * 0.6, c * 0.6);
  54. m.material.color.load(color);
  55. var interact = new h3d.scene.Interactive(m.getCollider(), s3d);
  56. initInteract(interact, m);
  57. }
  58. var cache = new h3d.prim.ModelCache();
  59. obj = cache.loadModel(hxd.Res.Model);
  60. obj.scale(1 / 20);
  61. obj.rotate(0,0,Math.PI / 2);
  62. obj.y = 0.2;
  63. obj.z = 0.2;
  64. s3d.addChild(obj);
  65. obj.playAnimation(cache.loadAnimation(hxd.Res.Model)).speed = 0.1;
  66. for( o in obj ) {
  67. var m = o.toMesh();
  68. var i = new h3d.scene.Interactive(m.getCollider(), s3d);
  69. initInteract(i, m);
  70. }
  71. b = new h2d.Interactive(150, 100, s2d);
  72. b.backgroundColor = 0x80204060;
  73. b.rotation = Math.PI / 3;
  74. //b.scaleX = 1.5; // TODO
  75. var pix = null;
  76. b.onOver = function(e) {
  77. var t = h2d.Tile.fromColor(0xFF0000, 3, 3);
  78. t.dx = -1;
  79. t.dy = -1;
  80. pix = new h2d.Bitmap(t, b);
  81. pix.x = e.relX;
  82. pix.y = e.relY;
  83. };
  84. b.onMove = function(e) {
  85. if( pix == null ) return;
  86. pix.x = e.relX;
  87. pix.y = e.relY;
  88. }
  89. b.onOut = function(e) {
  90. pix.remove();
  91. pix = null;
  92. };
  93. onResize();
  94. }
  95. override function onResize() {
  96. b.x = (s2d.width >> 1) - 200;
  97. b.y = 150;
  98. }
  99. override function update(dt:Float) {
  100. obj.rotate(0, 0, 0.002 * dt);
  101. }
  102. static function main() {
  103. hxd.Res.initEmbed();
  104. new Interactive();
  105. }
  106. }