Cube.hx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package h3d.prim;
  2. import h3d.col.Point;
  3. class Cube extends Polygon {
  4. public function new( x = 1., y = 1., z = 1. )
  5. {
  6. var p = [
  7. new Point(0, 0, 0),
  8. new Point(x, 0, 0),
  9. new Point(0, y, 0),
  10. new Point(0, 0, z),
  11. new Point(x, y, 0),
  12. new Point(x, 0, z),
  13. new Point(0, y, z),
  14. new Point(x, y, z),
  15. ];
  16. var idx = new hxd.IndexBuffer();
  17. idx.push(0); idx.push(1); idx.push(5);
  18. idx.push(0); idx.push(5); idx.push(3);
  19. idx.push(1); idx.push(4); idx.push(7);
  20. idx.push(1); idx.push(7); idx.push(5);
  21. idx.push(3); idx.push(5); idx.push(7);
  22. idx.push(3); idx.push(7); idx.push(6);
  23. idx.push(0); idx.push(6); idx.push(2);
  24. idx.push(0); idx.push(3); idx.push(6);
  25. idx.push(2); idx.push(7); idx.push(4);
  26. idx.push(2); idx.push(6); idx.push(7);
  27. idx.push(0); idx.push(4); idx.push(1);
  28. idx.push(0); idx.push(2); idx.push(4);
  29. super(p, idx);
  30. }
  31. override function addUVs() {
  32. unindex();
  33. var z = new UV(0, 0);
  34. var x = new UV(1, 0);
  35. var y = new UV(0, 1);
  36. var o = new UV(1, 1);
  37. uvs = [
  38. z, x, o,
  39. z, o, y,
  40. x, z, y,
  41. x, y, o,
  42. z, x, o,
  43. z, o, y,
  44. z, o, x,
  45. z, y, o,
  46. x, y, z,
  47. x, o, y,
  48. z, o, x,
  49. z, y, o,
  50. ];
  51. }
  52. }