Skip to content

Commit

Permalink
Allow to disable armor rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
NickAcPT committed Aug 14, 2024
1 parent e621000 commit e621000
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
4 changes: 2 additions & 2 deletions nmsr-aas/src/routes/bbmodel_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ pub(crate) async fn internal_bbmodel_export(
);
}

if let Some(slots) = &part_context.armor_slots {
let (armor_1, armor_2) = state.armor_manager.create_armor_texture(slots).await?;
if let (Some(armor_manager), Some(slots)) = (&state.armor_manager, &part_context.armor_slots) {
let (armor_1, armor_2) = armor_manager.create_armor_texture(slots).await?;

textures.insert(
VanillaMinecraftArmorMaterialData::ARMOR_TEXTURE_ONE,
Expand Down
19 changes: 15 additions & 4 deletions nmsr-aas/src/routes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub trait RenderRequestValidator {
#[derive(Clone)]
pub struct NMSRState<'a> {
pub resolver: Arc<RenderRequestResolver>,
pub armor_manager: Arc<VanillaMinecraftArmorManager>,
pub armor_manager: Option<Arc<VanillaMinecraftArmorManager>>,
pub graphics_context: Arc<GraphicsContext<'a>>,
pools: Arc<GraphicsContextPools<'a>>,
cache_config: ModelCacheConfiguration,
Expand All @@ -66,6 +66,13 @@ impl<'a> RenderRequestValidator for NMSRState<'a> {
}

request.features.remove_all(disabled_features);

if let (None, Some(extra)) = (&self.armor_manager, &mut request.extra_settings) {
extra.helmet.take();
extra.chestplate.take();
extra.leggings.take();
extra.boots.take();
}
}
}

Expand Down Expand Up @@ -100,14 +107,18 @@ impl<'a> NMSRState<'a> {

let pools = GraphicsContextPools::new(graphics_context.clone())?;

let armor_manager = VanillaMinecraftArmorManager::new("cache".into()).await?;

let armor_manager = if config.features.as_ref().is_some_and(|f| f.disable_armor_rendering) {
None
} else {
Some(Arc::new(VanillaMinecraftArmorManager::new("cache".into()).await?))
};

Ok(Self {
resolver: Arc::new(resolver),
graphics_context,
pools: Arc::new(pools),
cache_config: config.caching.clone(),
armor_manager: Arc::new(armor_manager),
armor_manager,
features_config: config.features.clone().unwrap_or_default(),
})
}
Expand Down
10 changes: 5 additions & 5 deletions nmsr-aas/src/routes/render_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ async fn load_textures<'a>(
scene.set_texture(&state.graphics_context, texture_type.into(), &image_buffer);
}

if let Some(armor_slots) = part_provider.armor_slots.as_ref() {
let (main_layer, second_armor_layer) = state
.armor_manager
.create_armor_texture(armor_slots)
.await?;
if let (Some(armor_manager), Some(armor_slots)) =
(&state.armor_manager, part_provider.armor_slots.as_ref())
{
let (main_layer, second_armor_layer) =
armor_manager.create_armor_texture(armor_slots).await?;

scene.set_texture(
&state.graphics_context,
Expand Down
6 changes: 6 additions & 0 deletions nmsr-aas/src/utils/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,17 @@ pub struct RenderingConfiguration {
#[serde_as]
#[derive(Default, Serialize, Deserialize, Clone, Debug)]
pub struct FeaturesConfiguration {
#[serde(default)]
#[serde_as(as = "Vec<DisplayFromStr>")]
pub disabled_features: Vec<RenderRequestFeatures>,

#[serde(default)]
#[serde_as(as = "Vec<DisplayFromStr>")]
pub disabled_modes: Vec<RenderRequestMode>,

/// Whether to disable downloading armor textures - this makes it so there is no armor rendering support.
#[serde(default)]
pub disable_armor_rendering: bool,
}

impl ModelCacheConfiguration {
Expand Down

0 comments on commit e621000

Please sign in to comment.