形式
Plain text
投稿日時
2021-03-18 21:06
公開期間
無期限
  1. class Cell {
  2. Cell[] children;
  3. Triangles[] triangles;
  4. AABB box;
  5. Cell(Triangles[] t, AABB b){
  6. triangles = t;
  7. if(triangles.length > 10){
  8. box = b;
  9. createChildren();
  10. }
  11. }
  12. void createChildren(){
  13. AABB bbox1 = new AABB(box.min, box.max/2);
  14. AABB bbox2 = new AABB(Vec3(box.min.x, box.min.y, box.max.z/2), Vec3(box.max.x, box.max.y/2, box.max.z));
  15. AABB bbox3 = new AABB(Vec3(box.max.x/2, box.min.y, box.min.z), Vec3(box.max.x, box.max.y/2, box.max.z));
  16. AABB bbox4 = new AABB(Vec3(box.max.x/2, box.min.y, box.max.z/2), Vec3(box.max.x, box.max.y/2, box.max.z));
  17. AABB bbox5 = new AABB(Vec3(box.min.x, box.max.y/2, box.min.z), Vec3(box.max.x/2, box.max.y, box.max.z/2));
  18. AABB bbox6 = new AABB(Vec3(box.min.x, box.max.y/2, box.max.z/2), Vec3(box.max.x/2, box.max.y, box.max.z/2));
  19. AABB bbox7 = new AABB(Vec3(box.max.x/2, box.max.y/2, box.min.z), Vec3(box.max.x, box.max.y, box.max.z/2));
  20. AABB bbox8 = new AABB(Vec3(box.max.x/2, box.max.y/2, box.max.z/2), box.max);
  21. //Array that contains the 8 boxes
  22. AABB[] arrayBox;
  23. for(int i = 0; i < 8; i++){
  24. Triangles[] t;
  25. for(int j = 0; j < triangles.length; j++){
  26. if(arrayBox[i].isIn(triangles[i])){
  27. t.add(triangles[i]);
  28. }
  29. }
  30. children.add(new Cell(t, arrayBox[i]));
  31. }
  32. }
  33. }
  34. bool AABB::isIn(Triangle t){
  35. Vec3 taille = max - min;
  36. Vec3 pos = min;
  37. Segment s1 = new Segment(pos, pos + Vec3(taille.x, 0, 0);
  38. Segment s2 = new Segment(pos, pos + Vec3(0, taille.y, 0);
  39. Segment s3 = new Segment(pos, pos + Vec3(0, 0, taille.z);
  40. pos = min + Vec3(taille.x, 0, taille.z);
  41. Segment s4 = new Segment(pos, pos + Vec3(-taille.x, 0, 0);
  42. Segment s5 = new Segment(pos, pos + Vec3(0, taille.y, 0);
  43. Segment s6 = new Segment(pos, pos + Vec3(0, 0, -taille.z);
  44. pos = min + Vec3(taille.x, taille.y, 0);
  45. Segment s7 = new Segment(pos, pos + Vec3(-taille.x, 0, 0);
  46. Segment s8 = new Segment(pos, pos + Vec3(0, -taille.y, 0);
  47. Segment s9 = new Segment(pos, pos + Vec3(0, 0, taille.z);
  48. pos = min + Vec3(0, taille.y, taille.z);
  49. Segment s10 = new Segment(pos, pos + Vec3(taille.x, 0, 0);
  50. Segment s11 = new Segment(pos, pos + Vec3(0, -taille.y, 0);
  51. Segment s12 = new Segment(pos, pos + Vec3(0, 0, -taille.z);
  52. Pour chaque Segment s de la AABB faire :
  53. if (intersection(s, t)){
  54. retourner vrai
  55. }
  56. Carre c1 = new Carre(s1, s3 ,s4, s6);
  57. Carre c2 = new Carre(s3, s2, s11, s12);
  58. Carre c3 = new Carre(s10, s7, s9, s12);
  59. Carre c4 = new Carre(s8, s9, s5, s6);
  60. Carre c5 = ///
  61. Carre c6 = ///
  62. Pour chaque Carre c de la AABB faire {
  63. si(intersection(c, st1) ou intersection(c, st2) ou intersection(c, t3)){
  64. retourner vrai ;
  65. }
  66. }
  67. // Déterminer les triangles de la AABB
  68. // Déterminer les segments du triangles st1 st2 st3
  69. Pour chaque Triangle t de la AABB faire {
  70. si (intersection(t, st1) ou intersection(t, st2) ou intersection(t, st3)){
  71. retourner vrai
  72. }
  73. bool intersection(Segment s, Triangle t){
  74. }
  75. // Main program
  76. Triangles triangles....;
  77. AABB aabb = new AABB();
  78. aabb = calculeBoite(triangles);
  79. aabb = aabb.adjustBox();
  80. Cell cell = new Cell(triangles, aabb);
ダウンロード 印刷用表示

このコピペの URL

JavaScript での埋め込み

iframe での埋め込み

元のテキスト