1
1
use std:: time:: Duration ;
2
2
use std:: collections:: VecDeque ;
3
+ use include_dir:: { include_dir, DirEntry } ;
4
+ use regex:: Regex ;
5
+ use lazy_static:: lazy_static;
3
6
use ammolite_math:: * ;
4
7
use wasm_bindgen:: prelude:: * ;
5
8
use mlib:: * ;
@@ -57,25 +60,45 @@ macro_rules! dbg {
57
60
} ;
58
61
}
59
62
60
- // const MODEL_MAIN_BYTES: &'static [u8] = include_bytes!(env!("MODEL"));
61
- // const MODEL_MAIN_BYTES: &'static [u8] = include_bytes!("/home/limeth/Downloads/meteor-crater-arizona/source/Meteor Crater.glb");
62
- const MODEL_BUTTON_PREVIOUS_BYTES : & ' static [ u8 ] = include_bytes ! ( "/home/limeth/Documents/School/mvr/metaview models/button_previous.glb" ) ;
63
- const MODEL_BUTTON_NEXT_BYTES : & ' static [ u8 ] = include_bytes ! ( "/home/limeth/Documents/School/mvr/metaview models/button_next.glb" ) ;
64
- // TODO: Use a procedural macro to output include_bytes! macros for every model
65
- // in the resources directory (if a feature is used/release build; otherwise it
66
- // would slow down linting)
67
- const MODELS_MAIN_LEN : usize = 1 ;
68
- const MODELS_MAIN_BYTES_SCALE : [ ( & ' static [ u8 ] , f32 ) ; MODELS_MAIN_LEN ] = [
69
- // (include_bytes!("../../ammolite/resources/DamagedHelmet/glTF-Binary/DamagedHelmet.glb"), 1.0),
70
- // (include_bytes!("../../ammolite/resources/Corset/glTF-Binary/Corset.glb"), 40.0),
71
- // (include_bytes!("../../ammolite/resources/AntiqueCamera/glTF-Binary/AntiqueCamera.glb"), 0.1),
72
- ( include_bytes ! ( "../../ammolite/resources/WaterBottle/glTF-Binary/WaterBottle.glb" ) , 5.0 ) ,
73
- // (include_bytes!("/home/limeth/Documents/School/mvr/team07/mvr_3D_models/hlusijak/laser/zaba.glb"), 0.01),
74
- ] ;
75
- const MODEL_MARKER_BYTES : & ' static [ u8 ] = include_bytes ! ( "../../ammolite/resources/sphere_1m_radius.glb" ) ;
76
63
const SELECTION_DELAY : f32 = 1.0 ;
77
- const ANIMATION_SPEED : f32 = 0.0 ;
78
- const ENTITY_COUNT : usize = 20 ;
64
+ const ANIMATION_SPEED : f32 = 0.2 ;
65
+ const ENTITY_COUNT : usize = 3 ;
66
+
67
+ const MODEL_BUTTON_PREVIOUS_BYTES : & ' static [ u8 ] = include_bytes ! ( "../resources/ui/button_previous.glb" ) ;
68
+ const MODEL_BUTTON_NEXT_BYTES : & ' static [ u8 ] = include_bytes ! ( "../resources/ui/button_next.glb" ) ;
69
+ const MODEL_MARKER_BYTES : & ' static [ u8 ] = include_bytes ! ( "../resources/ui/sphere_1m_radius.glb" ) ;
70
+
71
+ lazy_static ! {
72
+ static ref MODELS_MAIN_BYTES_SCALE : Vec <( & ' static [ u8 ] , f32 ) > = {
73
+ let dir = include_dir!( "resources/showcase" ) ;
74
+ let files = dir. find( "**/*_(*).glb" )
75
+ . expect( "Could not traverse the resource directory tree." )
76
+ . flat_map( |dir_entry| {
77
+ match dir_entry {
78
+ DirEntry :: File ( file) => Some ( file) ,
79
+ DirEntry :: Dir ( _) => None ,
80
+ }
81
+ } )
82
+ . collect:: <Vec <_>>( ) ;
83
+
84
+ if files. len( ) <= 0 {
85
+ panic!( "No `.glb` glTF models in the `resources/showcase` directory." )
86
+ }
87
+
88
+ files. into_iter( )
89
+ . map( |file| {
90
+ lazy_static! {
91
+ static ref PATTERN : Regex = Regex :: new( r"^(?P<name>.*)_\((?P<scale>.*?)\)$" ) . unwrap( ) ;
92
+ }
93
+ let stem = file. path( ) . file_stem( ) . unwrap( ) . to_str( ) . unwrap( ) ;
94
+ let captures = PATTERN . captures( stem) . unwrap( ) ;
95
+ let scale = captures. name( "scale" ) . unwrap( ) . as_str( ) . parse( ) . unwrap( ) ;
96
+
97
+ ( file. contents( ) , scale)
98
+ } )
99
+ . collect:: <Vec <_>>( )
100
+ } ;
101
+ }
79
102
80
103
fn construct_model_matrix ( scale : f32 , translation : & Vec3 , rotation : & Vec3 ) -> Mat4 {
81
104
Mat4 :: translation ( translation)
@@ -114,7 +137,7 @@ pub struct ExampleMapp {
114
137
commands : VecDeque < Command > ,
115
138
view_orientations : Option < Vec < Option < Orientation > > > ,
116
139
root_entity : Option < Entity > ,
117
- models_main : [ Option < Model > ; MODELS_MAIN_LEN ] ,
140
+ models_main : Vec < Option < Model > > ,
118
141
model_marker : Option < Model > ,
119
142
model_button_previous : Option < Model > ,
120
143
model_button_next : Option < Model > ,
@@ -147,13 +170,13 @@ impl ExampleMapp {
147
170
}
148
171
149
172
fn change_main_model_next ( & mut self ) {
150
- let new_index = ( self . current_main_model_index + 1 ) % MODELS_MAIN_LEN ;
173
+ let new_index = ( self . current_main_model_index + 1 ) % MODELS_MAIN_BYTES_SCALE . len ( ) ;
151
174
self . change_main_model_index ( new_index) ;
152
175
}
153
176
154
177
fn change_main_model_previous ( & mut self ) {
155
178
let new_index = if self . current_main_model_index == 0 {
156
- MODELS_MAIN_LEN - 1
179
+ MODELS_MAIN_BYTES_SCALE . len ( ) - 1
157
180
} else {
158
181
self . current_main_model_index - 1
159
182
} ;
@@ -171,7 +194,7 @@ impl Mapp for ExampleMapp {
171
194
commands : VecDeque :: new ( ) ,
172
195
view_orientations : None ,
173
196
root_entity : None ,
174
- models_main : [ None ; MODELS_MAIN_LEN ] ,
197
+ models_main : vec ! [ None ; MODELS_MAIN_BYTES_SCALE . len ( ) ] ,
175
198
model_marker : None ,
176
199
model_button_previous : None ,
177
200
model_button_next : None ,
@@ -184,7 +207,7 @@ impl Mapp for ExampleMapp {
184
207
current_selection : None ,
185
208
} ;
186
209
result. cmd ( CommandKind :: EntityRootGet ) ;
187
- for ( model_bytes, _) in & MODELS_MAIN_BYTES_SCALE {
210
+ for ( model_bytes, _) in & MODELS_MAIN_BYTES_SCALE [ .. ] {
188
211
result. cmd ( CommandKind :: ModelCreate {
189
212
data : model_bytes. into ( ) ,
190
213
} ) ;
@@ -225,7 +248,7 @@ impl Mapp for ExampleMapp {
225
248
226
249
let transform = construct_model_matrix (
227
250
MODELS_MAIN_BYTES_SCALE [ self . current_main_model_index ] . 1 ,
228
- & [ 0.0 , 0.0 , 2.0 + 1 .0 * index as f32 ] . into ( ) ,
251
+ & [ 0.0 , 0.0 , 2.0 + 4 .0 * index as f32 ] . into ( ) ,
229
252
& [ ( secs_elapsed * ANIMATION_SPEED ) . sin ( ) * 1.0 , std:: f32:: consts:: PI + ( secs_elapsed * ANIMATION_SPEED ) . cos ( ) * 3.0 / 2.0 , 0.0 ] . into ( ) ,
230
253
) ;
231
254
0 commit comments