honeycomb_render/
lib.rs

1//! # honeycomb-render
2//!
3//! This crate implements a graphical debugging tool using the `bevy` crate. The [`App`] structure
4//! can be used to render a given combinatorial map, using underlying ECS logic to render map
5//! items.
6//!
7//! All the ECS code used to render maps is left public, allowing advanced user to customize the
8//! rendering tool to account for user-defined attributes.
9//!
10//! Note that rendering large maps may require running the program in `release` mode.
11//!
12
13// ------ CUSTOM LINTS
14
15// more lints
16#![warn(clippy::pedantic)]
17#![warn(missing_docs)]
18// some exceptions
19#![allow(clippy::module_name_repetitions)]
20#![allow(clippy::cast_possible_truncation)]
21#![allow(clippy::cast_sign_loss)]
22#![allow(clippy::cast_precision_loss)]
23#![allow(clippy::similar_names)]
24#![allow(clippy::must_use_candidate)]
25#![allow(clippy::needless_pass_by_value)] // all ECS systems are flagged with this one
26
27// ------ MODULE DECLARATIONS
28
29mod gui;
30mod import_map;
31mod options;
32mod render_map;
33mod scene;
34
35// ------ PUBLIC API
36
37// out of the box render tool
38
39use bevy::prelude::*;
40use honeycomb_core::cmap::{CMap2, CMap3};
41use honeycomb_core::geometry::CoordsFloat;
42
43/// Main rendering function.
44pub fn render_2d_map<T: CoordsFloat>(cmap: CMap2<T>) {
45    let mut app = App::new();
46    app.insert_resource(resources::Map(cmap));
47    app.init_gizmo_group::<resources::DartGizmos>()
48        .init_gizmo_group::<resources::VertexGizmos>()
49        .init_gizmo_group::<resources::EdgeGizmos>();
50    app.add_systems(Startup, import_map::extract_data_from_map::<T>);
51    // resource
52    app.insert_resource(Msaa::Sample4)
53        .insert_resource(ClearColor(Color::srgb(0.9, 0.9, 0.9)));
54    // plugins
55    app.add_plugins(DefaultPlugins)
56        .add_plugins(plugins::OptionsPlugin)
57        .add_plugins(plugins::GuiPlugin)
58        .add_plugins(plugins::ScenePlugin);
59
60    app.run();
61}
62
63/// Main rendering function.
64pub fn render_3d_map<T: CoordsFloat>(cmap: CMap3<T>) {
65    let mut app = App::new();
66    app.insert_resource(resources::Map3(cmap));
67    app.init_gizmo_group::<resources::DartGizmos>()
68        .init_gizmo_group::<resources::VertexGizmos>()
69        .init_gizmo_group::<resources::EdgeGizmos>();
70    app.add_systems(Startup, import_map::extract_data_from_3d_map::<T>);
71    // resource
72    app.insert_resource(Msaa::Sample4)
73        .insert_resource(ClearColor(Color::srgb(0.9, 0.9, 0.9)));
74    // plugins
75    app.add_plugins(DefaultPlugins)
76        .add_plugins(plugins::OptionsPlugin)
77        .add_plugins(plugins::GuiPlugin)
78        .add_plugins(plugins::ScenePlugin);
79
80    app.run();
81}
82// item for custom composition
83
84/// plugins used to build the default [`App`]
85pub mod plugins {
86    pub use crate::gui::GuiPlugin;
87    pub use crate::options::OptionsPlugin;
88    pub use crate::scene::ScenePlugin;
89}
90
91/// bundles used to build the default [`App`]
92pub mod bundles {
93    pub use crate::import_map::{DartBundle, EdgeBundle, FaceBundle, VertexBundle};
94}
95
96/// components used to build the default [`App`]
97pub mod components {
98    pub use crate::import_map::{
99        Beta, Dart, DartId, Edge, EdgeId, Face, FaceId, Vertex, VertexId, Volume, VolumeId,
100    };
101}
102
103/// resources used to build the default [`App`]
104pub mod resources {
105    pub use crate::gui::WindowVisible;
106    pub use crate::import_map::{FaceNormals, Map, Map3, MapVertices, VolumeNormals};
107    pub use crate::options::{
108        DartHeadMul, DartRenderColor, DartShrink, DartWidth, EdgeRenderColor, EdgeWidth,
109        FaceRenderColor, FaceShrink, VertexRenderColor, VertexWidth, VolumeRenderColor,
110        VolumeShrink,
111    };
112    pub use crate::render_map::{DartGizmos, EdgeGizmos, FaceGizmos, VertexGizmos};
113}
114
115/// systems used to build the default [`App`]
116pub mod systems {
117    pub use crate::gui::{draw_inspected_data, draw_options};
118    pub use crate::import_map::{extract_data_from_3d_map, extract_data_from_map};
119    pub use crate::render_map::{
120        render_dart_enabled, render_darts, render_darts_3d, render_edge_enabled, render_edges,
121        render_face_enabled, render_faces, render_vertex_enabled, render_vertices,
122    };
123}