Box.hx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package hrt.prefab;
  2. class Box extends Object3D {
  3. public function setColor(ctx: Context, color: Int) {
  4. #if editor
  5. if(ctx.local3d == null)
  6. return;
  7. var mesh = Std.instance(ctx.local3d, h3d.scene.Mesh);
  8. if(mesh != null) {
  9. setDebugColor(color, mesh.material);
  10. }
  11. #end
  12. }
  13. override function makeInstance(ctx:Context):Context {
  14. ctx = ctx.clone(this);
  15. var mesh = new h3d.scene.Mesh(h3d.prim.Cube.defaultUnitCube(), ctx.local3d);
  16. #if editor
  17. setDebugColor(0x60ffffff, mesh.material);
  18. var wire = new h3d.scene.Box(mesh);
  19. wire.color = 0;
  20. wire.ignoreCollide = true;
  21. wire.material.shadows = false;
  22. #end
  23. ctx.local3d = mesh;
  24. ctx.local3d.name = name;
  25. updateInstance(ctx);
  26. return ctx;
  27. }
  28. #if editor
  29. static public function setDebugColor(color : Int, mat : h3d.mat.Material) {
  30. mat.color.setColor(color);
  31. var opaque = (color >>> 24) == 0xff;
  32. mat.shadows = false;
  33. if(opaque) {
  34. var alpha = mat.getPass("debuggeom_alpha");
  35. if(alpha != null)
  36. mat.removePass(alpha);
  37. mat.mainPass.setPassName("default");
  38. mat.mainPass.setBlendMode(None);
  39. mat.mainPass.depthWrite = true;
  40. mat.mainPass.culling = None;
  41. }
  42. else {
  43. mat.mainPass.setPassName("debuggeom");
  44. mat.mainPass.setBlendMode(Alpha);
  45. mat.mainPass.depthWrite = true;
  46. mat.mainPass.culling = Front;
  47. var alpha = mat.allocPass("debuggeom_alpha");
  48. alpha.setBlendMode(Alpha);
  49. alpha.culling = Back;
  50. alpha.depthWrite = false;
  51. }
  52. }
  53. override function getHideProps() : HideProps {
  54. return { icon : "square", name : "Box" };
  55. }
  56. #end
  57. static var _ = Library.register("box", Box);
  58. }