s3d_mesh.h (2911B)
1 /* Copyright (C) 2015-2023, 2026 |Méso|Star> (contact@meso-star.com) 2 * 3 * This file is part of Star-3D. 4 * 5 * Star-3D is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * Star-3D is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with Star-3D. If not, see <http://www.gnu.org/licenses/>. */ 17 18 #ifndef S3D_MESH_H 19 #define S3D_MESH_H 20 21 #include "s3d_c.h" 22 23 #include "s3d_buffer.h" 24 #include "s3d_geometry.h" 25 26 #include <rsys/dynamic_array_u32.h> 27 #include <rsys/dynamic_array_float.h> 28 #include <rsys/ref_count.h> 29 30 /* Generate the index buffer data type */ 31 #define BUFFER_NAME index_buffer 32 #define BUFFER_DARRAY darray_u32 33 #include "s3d_buffer.h" 34 35 /* Generate the vertex buffer data type */ 36 #define BUFFER_NAME vertex_buffer 37 #define BUFFER_DARRAY darray_float 38 #include "s3d_buffer.h" 39 40 struct mesh { /* Triangular mesh */ 41 struct index_buffer* indices; 42 struct vertex_buffer* attribs[S3D_ATTRIBS_COUNT__]; 43 enum s3d_type attribs_type[S3D_ATTRIBS_COUNT__]; 44 struct darray_float cdf; 45 struct hit_filter filter; 46 47 struct s3d_device* dev; 48 ref_T ref; 49 }; 50 51 extern LOCAL_SYM res_T 52 mesh_create 53 (struct s3d_device* dev, 54 struct mesh** mesh); 55 56 extern LOCAL_SYM void 57 mesh_ref_get 58 (struct mesh* mesh); 59 60 extern LOCAL_SYM void 61 mesh_ref_put 62 (struct mesh* mesh); 63 64 extern LOCAL_SYM void 65 mesh_clear 66 (struct mesh* mesh); 67 68 extern LOCAL_SYM size_t 69 mesh_get_ntris 70 (const struct mesh* mesh); 71 72 extern LOCAL_SYM size_t 73 mesh_get_nverts 74 (const struct mesh* mesh); 75 76 extern LOCAL_SYM uint32_t* 77 mesh_get_ids 78 (struct mesh* mesh); 79 80 extern LOCAL_SYM float* 81 mesh_get_pos 82 (struct mesh* mesh); 83 84 extern LOCAL_SYM float* 85 mesh_get_attr 86 (struct mesh* mesh, 87 const enum s3d_attrib_usage usage); 88 89 extern LOCAL_SYM float 90 mesh_compute_area 91 (struct mesh* mesh); 92 93 /* Compute mesh CDF */ 94 extern LOCAL_SYM res_T 95 mesh_compute_cdf 96 (struct mesh* mesh); 97 98 extern LOCAL_SYM float 99 mesh_compute_volume 100 (struct mesh* mesh, 101 const char flip_surface); /* Flip the shape surface or not */ 102 103 extern LOCAL_SYM res_T 104 mesh_setup_indexed_vertices 105 (struct mesh* mesh, 106 const unsigned ntris, 107 void (*get_indices)(const unsigned itri, unsigned ids[3], void* ctx), 108 const unsigned nverts, 109 struct s3d_vertex_data attribs[], 110 const unsigned nattribs, 111 void* data); 112 113 extern LOCAL_SYM void 114 mesh_compute_aabb 115 (struct mesh* mesh, 116 float lower[3], 117 float upper[3]); 118 119 extern LOCAL_SYM void 120 mesh_copy_indexed_vertices 121 (const struct mesh* src, 122 struct mesh* dst); 123 124 #endif /* S3D_MESH_H */ 125