EditorTools.hx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package hrt.impl;
  2. #if editor
  3. class EditorIcon extends hrt.prefab.l3d.Billboard.BillboardObj {
  4. public var scaleWithParent = false;
  5. public var category : IconCategory;
  6. public function new(?tile : h3d.mat.Texture, ?parent : h3d.scene.Object, category: IconCategory) {
  7. super(tile, parent);
  8. ignoreCollide = false;
  9. this.category = category;
  10. }
  11. override function sync(ctx) {
  12. visible = EditorTools.isVisible(category);
  13. super.sync(ctx);
  14. }
  15. override function getLocalCollider():h3d.col.Collider {
  16. return new h3d.col.Sphere(0,0,0,billboardScale/2.0);
  17. }
  18. // Ingonre scale and rotation
  19. override function calcAbsPos() {
  20. absPos.identity();
  21. absPos.tx = x;
  22. absPos.ty = y;
  23. absPos.tx = z;
  24. if (parent != null) {
  25. absPos.tx += parent.absPos.tx;
  26. absPos.ty += parent.absPos.ty;
  27. absPos.tz += parent.absPos.tz;
  28. }
  29. if( invPos != null )
  30. invPos._44 = 0; // mark as invalid
  31. }
  32. }
  33. class Editor2DIcon extends h2d.ObjectFollower {
  34. public var category : IconCategory;
  35. public function new( obj, ?parent, texture, category: IconCategory) {
  36. super(obj, parent);
  37. horizontalAlign = Middle;
  38. followVisibility = true;
  39. var ico = new h2d.Bitmap(h2d.Tile.fromTexture(texture), this);
  40. this.category = category;
  41. }
  42. override function sync(ctx) {
  43. visible = EditorTools.isVisible(category);
  44. super.sync(ctx);
  45. }
  46. }
  47. enum IconCategory {
  48. Light;
  49. Trails;
  50. Object3D;
  51. Audio;
  52. Misc;
  53. }
  54. class EditorTools {
  55. // Create a 3d Icon that will be displayed inside the scene as a 3d object, meaning that it can be
  56. // obscured by the other objects
  57. public static function create3DIcon(object:h3d.scene.Object, iconPath:String, scale:Float = 1.0, category: IconCategory) : EditorIcon {
  58. var ide = hide.Ide.inst;
  59. var tex = ide.getTexture(iconPath);
  60. var icon = new EditorIcon(tex, object, category);
  61. icon.texture = tex;
  62. icon.billboardScale = scale;
  63. return icon;
  64. }
  65. // Creates a 2d Icon that will be displayed in front of all the other icons
  66. public static function create2DIcon(object: h3d.scene.Object, s2d: h2d.Object, iconPath: String, category: IconCategory) : Editor2DIcon {
  67. var ide = hide.Ide.inst;
  68. return new Editor2DIcon(object, s2d, ide.getTexture(iconPath), category);
  69. }
  70. public static function setupIconCategories() {
  71. for (categoryName in haxe.EnumTools.getConstructors(IconCategory)) {
  72. var category = haxe.EnumTools.createByName(IconCategory, categoryName, []);
  73. var ide = hide.Ide.inst;
  74. if(!ide.show3DIconsCategory.exists(category)) {
  75. var value = js.Browser.window.localStorage.getItem(iconVisibilityKey(category));
  76. var shouldBeDisplayed = false;
  77. if (value == null || value == "true") {
  78. shouldBeDisplayed = true;
  79. }
  80. ide.show3DIconsCategory.set(category, shouldBeDisplayed);
  81. }
  82. }
  83. }
  84. public static function iconVisibilityKey(category: IconCategory) {
  85. return "3dIconVisibility/" + haxe.EnumTools.EnumValueTools.getName(category);
  86. }
  87. public static function isVisible(category: IconCategory) : Bool {
  88. return hide.Ide.inst.show3DIcons && hide.Ide.inst.show3DIconsCategory.get(category);
  89. }
  90. }
  91. #end