star-3d

Surface structuring for efficient 3D geometric queries
git clone git://git.meso-star.fr/star-3d.git
Log | Files | Refs | README | LICENSE

s3d_mesh.h (2884B)


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