star-3d

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

s3d_scene_view_c.h (3535B)


      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_SCENE_VIEW_C_H
     19 #define S3D_SCENE_VIEW_C_H
     20 
     21 #include "s3d_backend.h"
     22 #include "s3d_scene_c.h"
     23 
     24 #include <rsys/dynamic_array.h>
     25 #include <rsys/dynamic_array_uint.h>
     26 #include <rsys/hash_table.h>
     27 #include <rsys/list.h>
     28 #include <rsys/ref_count.h>
     29 
     30 /* Forward declarations */
     31 struct s3d_scene_view;
     32 struct geometry;
     33 
     34 /* Generate the htable_geom hash table */
     35 #define HTABLE_NAME geom
     36 #define HTABLE_DATA struct geometry*
     37 #define HTABLE_KEY unsigned /* Id of the shape */
     38 #include <rsys/hash_table.h>
     39 
     40 /* Generate the darray_fltui dynamic array */
     41 struct fltui { float flt; unsigned ui; };
     42 #define DARRAY_NAME fltui
     43 #define DARRAY_DATA struct fltui
     44 #include <rsys/dynamic_array.h>
     45 
     46 /* Generate the darray_geom_nprims array */
     47 struct nprims_cdf { unsigned nprims, ishape; };
     48 #define DARRAY_NAME nprims_cdf
     49 #define DARRAY_DATA struct nprims_cdf
     50 #include <rsys/dynamic_array.h>
     51 
     52 /* Generate the htable_instview hash table */
     53 #define HTABLE_NAME instview
     54 #define HTABLE_DATA struct s3d_scene_view*
     55 #define HTABLE_KEY struct s3d_scene*
     56 #include <rsys/hash_table.h>
     57 
     58 struct s3d_scene_view {
     59   struct list_node node; /* Attachment point to the scene scene_views pool */
     60 
     61   struct htable_geom cached_geoms; /* Cached shape geometries */
     62   struct darray_fltui cdf; /* Unormalized cumulative of the primitive areas */
     63   struct darray_nprims_cdf nprims_cdf;
     64 
     65   /* Map an instantiated scene to its scene view */
     66   struct htable_instview instviews;
     67 
     68   /* Id of Shapes detached while the scnview is active */
     69   struct darray_uint detached_shapes;
     70 
     71   float lower[3], upper[3]; /* AABB of the scene */
     72 
     73   /* Callback attached to the sig_shape_detach signal of scn */
     74   scene_shape_cb_T on_shape_detach_cb;
     75 
     76   int aabb_update; /* Define if the geometry AABB must be updated */
     77   int mask; /* Combination of enum s3d_scene_view_flag */
     78   int rtc_scn_update; /* Define if Embree geometries were deleted/added */
     79   int rtc_commit; /* Define whether or not the Embree scene was committed */
     80   int rtc_scn_flags; /* Flags used to configure the Embree scene */
     81   enum RTCBuildQuality rtc_scn_build_quality; /* Build quality of the BVH */
     82   RTCScene rtc_scn; /* Embree scene */
     83 
     84   ref_T ref;
     85   struct s3d_scene* scn;
     86 };
     87 
     88 extern LOCAL_SYM void
     89 rtc_hit_filter_wrapper
     90   (const struct RTCFilterFunctionNArguments* args);
     91 
     92 extern LOCAL_SYM void
     93 scene_view_destroy
     94   (struct s3d_scene_view* scnview);
     95 
     96 static FINLINE struct geometry*
     97 scene_view_geometry_from_embree_id
     98   (struct s3d_scene_view* scnview,
     99    const unsigned irtc)
    100 {
    101   struct geometry* geom;
    102   RTCGeometry rtc_geom;
    103   ASSERT(scnview && irtc != RTC_INVALID_GEOMETRY_ID);
    104   rtc_geom = rtcGetGeometry(scnview->rtc_scn, irtc);
    105   ASSERT(rtc_geom);
    106   geom = rtcGetGeometryUserData(rtc_geom);
    107   ASSERT(geom);
    108   return geom;
    109 }
    110 
    111 #endif /* S3D_SCENE_VIEW_C_H */
    112