star-geometry-3d

Clean and decorate 3D geometries
git clone git://git.meso-star.fr/star-geometry-3d.git
Log | Files | Refs | README | LICENSE

test_sg3d_cube_on_cube.c (3353B)


      1 /* Copyright (C) 2019, 2020, 2023, 2024 |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 #include "sg3d.h"
     17 #include "test_sg3d_utils.h"
     18 
     19 #include <rsys/double3.h>
     20 
     21 #include <stdio.h>
     22 
     23 /*
     24         +-----------------------+
     25         |                       3
     26         |     +------+          |
     27      m2 | m1  | m0   2          |
     28         |     |      |--> N     |
     29         |     +------+          |
     30         |     | m0   1          |
     31         |     |      |--> N     |
     32         |     +------+          |
     33         |--> N                  |
     34         +-----------------------+
     35  */
     36 
     37 int
     38 main(int argc, char** argv)
     39 {
     40   struct mem_allocator allocator;
     41   struct sg3d_device* dev;
     42   struct sg3d_geometry* geom;
     43   struct context ctx = CONTEXT_NULL__;
     44   struct sg3d_geometry_add_callbacks callbacks = SG3D_ADD_CALLBACKS_NULL__;
     45   unsigned count;
     46   (void)argc, (void)argv;
     47 
     48   OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator));
     49   OK(sg3d_device_create(NULL, &allocator, 1, &dev));
     50   OK(sg3d_geometry_create(dev, &geom));
     51   SG3D(device_ref_put(dev));
     52 
     53   callbacks.get_indices = get_indices;
     54   callbacks.get_properties = get_properties;
     55   callbacks.get_position = get_position;
     56 
     57   ctx.positions = cube_vertices;
     58   ctx.indices = cube_indices;
     59   d3(ctx.offset, 1, 1, 2);
     60   ctx.front_media = medium1_front0;
     61   ctx.back_media = medium0;
     62   ctx.intface = intface0;
     63 
     64   /* First cube (front: 0 on top face, 1 elsewhere, back: 0),
     65    * right-handed normal outside */
     66   OK(sg3d_geometry_add(geom, nvertices, ntriangles, &callbacks, &ctx));
     67 
     68   d3(ctx.offset, 1, 1, 1);
     69   ctx.front_media = medium1_back0;
     70 
     71   /* Second cube (front: 0 on bottom face, 1 elsewhere, back: 0),
     72    * right-handed normal outside */
     73   OK(sg3d_geometry_add(geom, nvertices, ntriangles, &callbacks, &ctx));
     74 
     75   ctx.positions = box_vertices; /* Can use distorded cube for cube #3 */
     76   d3(ctx.offset, 0, 0, 0);
     77   d3_splat(ctx.scale, 4);
     78   ctx.reverse_vrtx = 1;
     79   ctx.reverse_med = 1;
     80   ctx.front_media = medium2;
     81   ctx.back_media = medium1;
     82 
     83   /* Third cube (front: 2, back: 1), right-handed normal inside */
     84   OK(sg3d_geometry_add(geom, nvertices, ntriangles, &callbacks, &ctx));
     85 
     86   OK(sg3d_geometry_get_unique_triangles_with_merge_conflict_count(geom, &count));
     87   CHK(count == 0);
     88   OK(sg3d_geometry_get_unique_triangles_with_unspecified_interface_count(geom, &count));
     89   CHK(count == 0);
     90   OK(sg3d_geometry_get_unique_triangles_with_unspecified_side_count(geom, &count));
     91   CHK(count == 0);
     92   OK(sg3d_geometry_dump_as_c_code(geom, stdout, "cube_on_cube",
     93     SG3D_C_DUMP_CONST | SG3D_C_DUMP_STATIC));
     94 
     95   SG3D(geometry_ref_put(geom));
     96 
     97   check_memory_allocator(&allocator);
     98   mem_shutdown_proxy_allocator(&allocator);
     99   CHK(mem_allocated_size() == 0);
    100   return 0;
    101 }