Skip to content

Commit

Permalink
Improved caching of icons
Browse files Browse the repository at this point in the history
  • Loading branch information
nik012003 committed Feb 23, 2023
1 parent 6f43110 commit 8fa9e68
Show file tree
Hide file tree
Showing 5 changed files with 225 additions and 43 deletions.
172 changes: 165 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.4.0"
edition = "2021"

[dependencies]
cached = "0.42.0"
clap = { version = "4.1.3", features = ["derive"] }
color-eyre = "0.6.2"
directories = "4.0.1"
Expand Down
2 changes: 1 addition & 1 deletion examples/app_grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use stardust_xr_molecules::fusion::{
spatial::Spatial, drawable::{Text, TextStyle, Bounds, TextFit, Alignment}, core::values::Transform,
};

const APP_LIMIT: usize = 100;
const APP_LIMIT: usize = 300;
const APP_SIZE: f32 = 0.05;
const GRID_PADDING: f32 = 0.01;

Expand Down
32 changes: 20 additions & 12 deletions src/protostar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,34 @@ use tween::{QuartInOut, Tweener};
use ustr::ustr;

fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result<Model> {

return match &icon.icon_type {
IconType::Png(path) => {
IconType::Png => {
let t = Transform::from_rotation_scale(Quat::from_rotation_x(PI/2.0),[0.03,0.03,0.03]);

let model = Model::create(
parent,
Transform::from_rotation(Quat::from_rotation_y(PI)),
&ResourceID::new_namespaced("protostar", "cartridge"),
t,
&ResourceID::new_namespaced("protostar", "hexagon/hexagon"),
)?;
model.set_material_parameter(
1,
"color",
MaterialParameter::Color([0.0,1.0,1.0,1.0]),
)?;
model.set_material_parameter(
0,
2,
"diffuse",
MaterialParameter::Texture(ResourceID::Direct(path.clone())),
MaterialParameter::Texture(ResourceID::Direct(icon.path.clone())),
)?;
Ok(model)
}
IconType::Gltf(path) => Ok(Model::create(
IconType::Gltf => Ok(Model::create(
parent,
Transform::from_scale([0.05; 3]),
&ResourceID::new_direct(path)?,
&ResourceID::new_direct(icon.path.clone())?,
)?),
_ => panic!("asd"),
_ => panic!("Invalid Icon Type"),
};
}

Expand All @@ -59,7 +67,7 @@ impl ProtoStar {
.clone()
.into_iter()
.find(|i| match i.icon_type {
IconType::Gltf(_) => true,
IconType::Gltf => true,
_ => false,
})
.or(
Expand All @@ -70,7 +78,7 @@ impl ProtoStar {

match icon{
Some(i) => {
icon = match i.process(128) {
icon = match i.cached_process(128) {
Ok(i) => Some(i),
_ => None,
}},
Expand Down Expand Up @@ -107,8 +115,8 @@ impl ProtoStar {
.unwrap_or_else(|| {
Ok(Model::create(
grabbable.content_parent(),
Transform::from_scale([0.05; 3]),
&ResourceID::new_namespaced("protostar", "default_icon"),
Transform::from_rotation_scale(Quat::from_rotation_x(PI/2.0),[0.03,0.03,0.03]),
&ResourceID::new_namespaced("protostar", "hexagon/hexagon"),
)?)
})?;
Ok(ProtoStar {
Expand Down
Loading

0 comments on commit 8fa9e68

Please sign in to comment.