pub struct Assets {Show 22 fields
pub map_sources: FxHashMap<String, String>,
pub maps: FxHashMap<String, Map>,
pub entities: FxHashMap<String, (String, String)>,
pub items: FxHashMap<String, (String, String)>,
pub tiles: IndexMap<Uuid, Tile>,
pub materials: FxHashMap<Uuid, Tile>,
pub textures: FxHashMap<String, Texture>,
pub tile_list: Vec<Tile>,
pub tile_indices: FxHashMap<Uuid, u16>,
pub screens: FxHashMap<String, Map>,
pub character_maps: FxHashMap<String, Map>,
pub entity_tiles: FxHashMap<u32, IndexMap<String, Tile>>,
pub item_maps: FxHashMap<String, Map>,
pub item_tiles: FxHashMap<u32, IndexMap<String, Tile>>,
pub config: String,
pub atlas: Texture,
pub fonts: FxHashMap<String, Font>,
pub audio: FxHashMap<String, Vec<u8>>,
pub palette: ThePalette,
pub global: ShapeFXGraph,
pub locales: FxHashMap<String, FxHashMap<String, String>>,
pub avatars: FxHashMap<String, Avatar>,
}Fields§
§map_sources: FxHashMap<String, String>§maps: FxHashMap<String, Map>§entities: FxHashMap<String, (String, String)>§items: FxHashMap<String, (String, String)>§tiles: IndexMap<Uuid, Tile>§materials: FxHashMap<Uuid, Tile>§textures: FxHashMap<String, Texture>§tile_list: Vec<Tile>§tile_indices: FxHashMap<Uuid, u16>§screens: FxHashMap<String, Map>§character_maps: FxHashMap<String, Map>Maps which build character tiles.
entity_tiles: FxHashMap<u32, IndexMap<String, Tile>>The rendered tiles for a given entity.
item_maps: FxHashMap<String, Map>Maps which build item tiles.
item_tiles: FxHashMap<u32, IndexMap<String, Tile>>The rendered tiles for a given item.
config: String§atlas: Texture§fonts: FxHashMap<String, Font>§audio: FxHashMap<String, Vec<u8>>§palette: ThePalette§global: ShapeFXGraph§locales: FxHashMap<String, FxHashMap<String, String>>A map of locale names to their translations.
avatars: FxHashMap<String, Avatar>The avatars
Implementations§
Source§impl Assets
impl Assets
pub fn new() -> Self
Sourcepub fn read_locales(&mut self)
pub fn read_locales(&mut self)
Reads all locale tables (locale_*) from the config file.
Sourcepub fn clean_tile_list(&mut self)
pub fn clean_tile_list(&mut self)
Clears the tile list.
Sourcepub fn tile_index(&self, id: &Uuid) -> Option<u16>
pub fn tile_index(&self, id: &Uuid) -> Option<u16>
Returns the index into the tile_list for the given Tile Id
Sourcepub fn set_tiles(&mut self, tiles: IndexMap<Uuid, Tile>)
pub fn set_tiles(&mut self, tiles: IndexMap<Uuid, Tile>)
Set the tiles and atlas from a list of RGBA tiles.
Sourcepub fn set_materials(&mut self, materials: FxHashMap<Uuid, Map>)
pub fn set_materials(&mut self, materials: FxHashMap<Uuid, Map>)
Compile the materials.
Sourcepub fn blocking_tiles(&self) -> FxHashSet<Uuid>
pub fn blocking_tiles(&self) -> FxHashSet<Uuid>
Returns an FxHashSet of Uuid representing the blocking tiles and materials.
Sourcepub fn collect_from_directory(&mut self, dir_path: String)
pub fn collect_from_directory(&mut self, dir_path: String)
Collects the assets from a directory.
Examples found in repository?
examples/minigame.rs (line 24)
19 fn new() -> Self
20 where
21 Self: Sized,
22 {
23 let mut assets = Assets::default();
24 assets.collect_from_directory("minigame".to_string());
25 // assets.compile_source_maps();
26
27 let mut rusterix = Rusterix::default();
28 rusterix.set_assets(assets);
29 rusterix.create_regions();
30
31 let camera = Box::new(D3FirstPCamera::new());
32 rusterix.client.set_camera_d3(camera);
33
34 // if let Some(map) = rusterix.assets.get_map("world") {
35 // // Build the 3D scene from the map meta data
36 // rusterix
37 // .client
38 // .build_scene_d3(map, &rusterix.assets, &ValueContainer::default());
39 // }
40
41 // Add logo on top of the scene
42 rusterix.client.scene_d3.d2_static = vec![
43 Batch2D::from_rectangle(0.0, 0.0, 200.0, 200.0)
44 .receives_light(false)
45 .source(PixelSource::StaticTileIndex(0)),
46 ];
47 // rusterix
48 // .client
49 // .scene_d3
50 // .textures
51 // .push(Tile::from_texture(Texture::from_image(Path::new(
52 // "images/logo.png",
53 // ))));
54
55 Self { rusterix }
56 }Sourcepub fn get_map(&self, name: &str) -> Option<&Map>
pub fn get_map(&self, name: &str) -> Option<&Map>
Get a map by name.
Examples found in repository?
examples/minigame.rs (line 65)
59 fn draw(&mut self, pixels: &mut [u8], ctx: &mut TheContext) {
60 let _start = get_time();
61
62 // Update the entities on the server.
63 self.rusterix.server.update(&mut self.rusterix.assets);
64
65 if let Some(mut map) = self.rusterix.assets.get_map("world").cloned() {
66 self.rusterix.server.apply_entities_items(&mut map);
67 self.rusterix.build_entities_items_d3(&map);
68
69 self.rusterix
70 .draw_scene(&map, pixels, ctx.width, ctx.height);
71 }
72
73 let _stop = get_time();
74 println!("Execution time: {:?} ms.", _stop - _start);
75 }Sourcepub fn add_entity(&mut self, name: String, code: String, data: String)
pub fn add_entity(&mut self, name: String, code: String, data: String)
Add an entity.
Sourcepub fn textures(self, textures: Vec<Tile>) -> Self
pub fn textures(self, textures: Vec<Tile>) -> Self
Sets textures using the builder pattern.
Examples found in repository?
examples/obj.rs (lines 46-48)
24 fn new() -> Self
25 where
26 Self: Sized,
27 {
28 let scene = Scene::from_static(
29 vec![Batch2D::from_rectangle(0.0, 0.0, 200.0, 200.0)],
30 vec![
31 Batch3D::from_obj(Path::new("examples/teapot.obj"))
32 .source(PixelSource::StaticTileIndex(0))
33 .repeat_mode(RepeatMode::RepeatXY)
34 .transform(Mat4::scaling_3d(Vec3::new(0.35, -0.35, 0.35)))
35 .with_computed_normals(),
36 ],
37 )
38 .lights(vec![
39 Light::new(LightType::Point)
40 .with_intensity(1.0)
41 .with_color([1.0, 1.0, 0.95])
42 .compile(),
43 ])
44 .background(Box::new(VGrayGradientShader::new()));
45
46 let assets = Assets::default().textures(vec![Tile::from_texture(Texture::from_image(
47 Path::new("images/logo.png"),
48 ))]);
49
50 let mut camera = D3OrbitCamera::new();
51 camera.set_parameter_f32("distance", 1.5);
52
53 Self {
54 camera,
55 scene,
56 start_time: Instant::now(),
57 assets,
58 }
59 }More examples
examples/cube.rs (lines 52-54)
23 fn new() -> Self
24 where
25 Self: Sized,
26 {
27 let scene = Scene::from_static(
28 vec![Batch2D::from_rectangle(0.0, 0.0, 200.0, 200.0)],
29 vec![
30 Batch3D::from_box(-0.5, -0.5, -0.5, 1.0, 1.0, 1.0)
31 .source(PixelSource::StaticTileIndex(0))
32 .cull_mode(CullMode::Off)
33 // Metallic material which is based on half of the
34 // saturation of the pixel color
35 .material(Material::new(
36 MaterialRole::Metallic,
37 MaterialModifier::Saturation,
38 0.6,
39 0.0,
40 ))
41 .with_computed_normals(),
42 ],
43 )
44 .lights(vec![
45 Light::new(LightType::Point)
46 .with_intensity(1.0)
47 .with_color([1.0, 1.0, 0.95])
48 .compile(),
49 ])
50 .background(Box::new(VGrayGradientShader::new()));
51
52 let assets = Assets::default().textures(vec![Tile::from_texture(Texture::from_image(
53 Path::new("images/logo.png"),
54 ))]);
55
56 let mut camera = D3OrbitCamera::new();
57 camera.set_parameter_f32("distance", 1.5);
58
59 Self {
60 camera,
61 scene,
62 start_time: Instant::now(),
63 assets,
64 }
65 }examples/cube_shaded.rs (lines 104-106)
23 fn new() -> Self
24 where
25 Self: Sized,
26 {
27 let mut scene = Scene::from_static(
28 vec![Batch2D::from_rectangle(0.0, 0.0, 200.0, 200.0)],
29 vec![
30 Batch3D::from_box(-0.5, -0.5, -0.5, 1.0, 1.0, 1.0)
31 .source(PixelSource::StaticTileIndex(0))
32 .cull_mode(CullMode::Off)
33 .ambient_color(Vec3::broadcast(0.3))
34 .shader(0)
35 .with_computed_normals(),
36 ],
37 )
38 .lights(vec![
39 Light::new(LightType::Point)
40 .with_intensity(1.0)
41 .with_color([1.0, 1.0, 0.95])
42 .compile(),
43 ])
44 .background(Box::new(VGrayGradientShader::new()));
45
46 scene.add_shader(
47 r#"
48 fn shade() {
49 // Procedural wood: concentric growth rings warped by turbulence + fine grain.
50 // Only the .x channel of textures is used (value channel).
51 let t = time * 0.0;
52
53 // Move and scale domain; center the rings roughly in the middle of each face.
54 let uv2 = uv / 3.0 - vec2(1.5);
55
56 // fBm turbulence (zero-mean) to warp the rings
57 let n1 = sample(uv2 + vec2(t, 0.0), "fbm_perlin"); // [0,1]
58 let n2 = sample(uv2 * 2.0 + vec2(0.0, t*0.7), "fbm_perlin");
59 let turb = 0.65 * n1 + 0.35 * n2; // [0,1]
60 let turb_zm = (turb - 0.5) * 2.0; // [-1,1]
61
62 // Radial distance from center (log cross-section look)
63 let r = length(uv2);
64
65 // Warp rings by turbulence (phase modulation)
66 let ring_freq = 10.0; // number of rings
67 let ring_warp = 0.22; // strength of warp
68 let rings = r + ring_warp * turb_zm;
69 let waves = sin(rings * ring_freq);
70
71 // Map sine to ring mask; sharpen valleys to make rings thinner
72 let rings_mask = pow(1.0 - abs(waves), 3.0);
73
74 // Fine longitudinal grain: high-frequency value noise stretched along X
75 let grain_uv = vec2(uv2.x * 8.0, uv2.y * 40.0);
76 let g = sample(grain_uv + vec2(0.0, t*0.5), "value");
77 let grain = (g - 0.5) * 2.0; // zero-mean
78
79 // Base wood hues
80 let base_light = vec3(0.72, 0.52, 0.32);
81 let base_dark = vec3(0.45, 0.30, 0.16);
82
83 // Mix light/dark by ring mask
84 color = mix(base_light, base_dark, rings_mask);
85
86 // Apply subtle anisotropic grain as a multiplicative zero-mean factor
87 color *= (1.0 + 0.06 * grain);
88
89 // Optional pore streaks (cathedrals): directional bands along Y with slight turbulence
90 let band = uv2.y + 0.15 * turb_zm;
91 let cathedral = pow(1.0 - abs(sin(band * 6.0)), 4.0);
92 color = mix(color, color * 0.9, cathedral * 0.2);
93
94 // Roughness varies: pores are rougher, rings smoother
95 roughness = 0.6 + cathedral * 0.3;
96
97 // 16 Colors
98 //let color_steps = 16.0;
99 //color = floor(color * color_steps) / color_steps;
100 }
101 "#,
102 );
103
104 let assets = Assets::default().textures(vec![Tile::from_texture(Texture::from_image(
105 Path::new("images/logo.png"),
106 ))]);
107
108 let mut camera = D3OrbitCamera::new();
109 camera.set_parameter_f32("distance", 1.5);
110
111 Self {
112 camera,
113 scene,
114 start_time: Instant::now(),
115 assets,
116 }
117 }Trait Implementations§
Auto Trait Implementations§
impl Freeze for Assets
impl RefUnwindSafe for Assets
impl Send for Assets
impl Sync for Assets
impl Unpin for Assets
impl UnsafeUnpin for Assets
impl UnwindSafe for Assets
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.