jhylands

Coordinates for greedy meshing

Oct 26th, 2022
1,758
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. export function get_mesh(is_faced){
  3.   var mesh = {};
  4.   mesh.vertices = [];
  5.   mesh.normals = [];
  6.   mesh.uvs = [];
  7.   mesh.indices = [];
  8.   var faces;
  9.   /*         +--------+
  10.    *       x/        /|
  11.    *       /        / |
  12.    *      +--------+  |
  13.    *     ^|   z->  |  |
  14.    *     ||        |  +
  15.    *     y|        | /
  16.    *      |        |/
  17.    *      +--------+
  18.    */
  19.   for(let x=0;x<=cell_size;x++){
  20.     faces = get_faces(function(y,z){return is_faced(x, y, z, [-1,0,0]);});
  21.     for(let i=0;i<faces.length;i++){
  22.       add_face_x(mesh, x, faces[i]);
  23.     }
  24.   }
  25.   for(let y=0;y<=cell_size;y++){
  26.     faces = get_faces(function(x,z){return is_faced(x,y,z, [0,-1,0]);});
  27.     for(let i=0;i<faces.length;i++){
  28.       add_face_y(mesh, y, faces[i]);
  29.     }
  30.   }
  31.  
  32.   for(let z=0;z<=cell_size;z++){
  33.     faces = get_faces(function(x,y){return is_faced(x,y,z, [0,0,-1]);});
  34.     for(let i=0;i<faces.length;i++){
  35.       add_face_z(mesh, z, faces[i]);
  36.     }
  37.   }
  38.   return mesh;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment