Skip to content

Commit

Permalink
Port some movement logic into player parts
Browse files Browse the repository at this point in the history
  • Loading branch information
NickAcPT committed Mar 1, 2025
1 parent 92d5bb4 commit 4cd1b27
Show file tree
Hide file tree
Showing 22 changed files with 587 additions and 297 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -220,5 +220,5 @@ parts/**

utils/nmsr-rendering-blockbench-model-generator-experiment-wasm/pkg/**
utils/nmsr-rendering-blockbench-model-generator-experiment-wasm/pkg
cache
/cache/
config.toml
12 changes: 7 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,17 @@ http = { version = "1.1" }

enumset = { version = "1.1" }

chrono = { version = "0.4"}
chrono = { version = "0.4" }
tokio-stream = { version = "0.1", features = ["fs"] }
sync_wrapper = { version = "1.0"}
sync_wrapper = { version = "1.0" }

indoc = { version = "2"}
indoc = { version = "2" }

is_empty = { version = "0.2"}
is_empty = { version = "0.2" }

urlencoding = { version = "2.1.3"}
urlencoding = { version = "2.1.3" }

renderdoc = { version = "0.12.1" }

[profile.dev.package.image]
opt-level = 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<M: ArmorMaterial> EarsModPartProvider<M> for EarsModTailsPartProvider<M> {
let tail_mode = tail.mode;
let [bend_0, bend_1, bend_2, bend_3] = tail.bends;

let (ang, swing) = if tail_mode == TailMode::Down {
let (mut ang, swing) = if tail_mode == TailMode::Down {
(30, 40)
} else if matches!(tail_mode, TailMode::Back | TailMode::Cross | TailMode::CrossOverlap | TailMode::Star | TailMode::StarOverlap) {
(if bend_0 != 0.0 { 90 } else { 80 }, 20)
Expand All @@ -57,16 +57,27 @@ impl<M: ArmorMaterial> EarsModPartProvider<M> for EarsModTailsPartProvider<M> {
(0, 0)
};

let base_angle = tail.bends[0];
let mut base_angle = tail.bends[0];

if context.movement.is_gliding {
base_angle = -30.0;
ang = 0;
}

let swing_amount = context.movement.limb_swing;

builder.stack(|b| {
b.anchor_to(PlayerBodyPartType::Body);
b.translate_i(0, 2, 4);

b.rotate_i(180, 0, 0, 1);
b.translate_i(-8, 0, 0);

let swing_rot = swing_amount * (swing as f32);
let time_offset = f32::sin(context.movement.time / 12.) * 4.;

b.rotate_i(ang, 1, 0, 0);
b.rotate(swing_rot + time_offset, 0., 0.);
let vert = tail_mode == TailMode::Vertical;

if vert {
Expand Down Expand Up @@ -102,7 +113,7 @@ impl<M: ArmorMaterial> EarsModPartProvider<M> for EarsModTailsPartProvider<M> {
0
};

b.rotate(angles[i], 0., 0.);
b.rotate(angles[i] * (1.-(swing_amount/2.0)), 0., 0.);
b.quad_back(
56,
(16 + (i * seg_height)) as u16,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,18 @@ impl<M: ArmorMaterial> EarsModPartProvider<M> for EarsModWingsPartProvider<M> {

b.stack(|b| {
let wiggle = if wing.animated {
f32::sin(8.0 / 12.0) * 2.0
let g = context.movement.is_gliding;
let f = context.movement.is_creative_flying;

if g {
-40.0
} else {
let speed_1 = if f { 2.0 } else { 12.0 };
let speed_2 = if f { 20. } else { 2.0 };

(f32::sin((context.movement.time + 8.0) / speed_1) * speed_2)
+ (context.movement.limb_swing * 10.0)
}
} else {
0.0
};
Expand Down Expand Up @@ -115,9 +126,9 @@ impl<M: ArmorMaterial> EarsModPartProvider<M> for EarsModWingsPartProvider<M> {
"Wing (Asymmetric Left)",
);
});

b.translate(4., 0., 0.);

b.stack(|b| {
b.rotate(0.0, -60. + wiggle, 0.0);
b.quad_back(
Expand All @@ -134,7 +145,15 @@ impl<M: ArmorMaterial> EarsModPartProvider<M> for EarsModWingsPartProvider<M> {
if wing_mode == WingMode::Flat {
b.translate(-8., 0., 0.75);
b.stack(|b| {
b.quad_back(0, 0, 20, 16, TextureRotation::None, TextureFlip::Horizontal, "Wing (Flat)");
b.quad_back(
0,
0,
20,
16,
TextureRotation::None,
TextureFlip::Horizontal,
"Wing (Flat)",
);
});
}
});
Expand Down
30 changes: 23 additions & 7 deletions nmsr-3d-renderer/nmsr-player-parts/src/parts/provider/minecraft.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::marker::PhantomData;
use std::{f32::consts::PI, marker::PhantomData};

use glam::Vec3;
use itertools::Itertools;
Expand Down Expand Up @@ -253,27 +253,43 @@ pub fn compute_base_part(non_layer_body_part_type: PlayerBodyPartType, is_slim_a
}
}

pub(crate) fn perform_arm_part_rotation(
fn compute_arm_part_rotation<M: ArmorMaterial>(
non_layer_body_part_type: PlayerBodyPartType,
context: &PlayerPartProviderContext<M>,
) -> f32 {
let arm_rotation_angle = context.custom_arm_rotation_z;

if let Some(angle) = context.custom_arm_rotation_z {
angle
} else {
let rotation = PI * 0.02;
let t = context.movement.time / 10.0;

((t).cos() * 0.03 + rotation).to_degrees()
}
}

pub(crate) fn perform_arm_part_rotation<M: ArmorMaterial>(
non_layer_body_part_type: PlayerBodyPartType,
part: &mut Part,
is_slim_arms: bool,
arm_rotation_angle: f32,
context: &PlayerPartProviderContext<M>,
) {
let normal_part = compute_base_part(non_layer_body_part_type, is_slim_arms);
let normal_part_size = normal_part.get_size();

let arm_rotation_z = compute_arm_part_rotation(non_layer_body_part_type, context);

if non_layer_body_part_type == LeftArm {
let anchor = normal_part.get_position() + normal_part_size * Vec3::new(1.0, 1.0, 0.5);

part.rotate(
[0.0, 0.0, -arm_rotation_angle].into(),
[0.0, 0.0, -arm_rotation_z].into(),
Some(PartAnchorInfo::new_rotation_anchor_position(anchor)),
);
} else if non_layer_body_part_type == RightArm {
let anchor = normal_part.get_position() + normal_part_size * Vec3::new(0.0, 1.0, 0.5);

part.rotate(
[0.0, 0.0, arm_rotation_angle].into(),
[0.0, 0.0, arm_rotation_z].into(),
Some(PartAnchorInfo::new_rotation_anchor_position(anchor)),
);
}
Expand Down
23 changes: 21 additions & 2 deletions nmsr-3d-renderer/nmsr-player-parts/src/parts/provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,33 @@ where
pub has_cape: bool,
pub has_deadmau5_ears: bool,
pub is_flipped_upside_down: bool,
pub arm_rotation: f32,
pub custom_arm_rotation_z: Option<f32>,
pub shadow_y_pos: Option<f32>,
pub shadow_is_square: bool,
pub armor_slots: Option<PlayerArmorSlots<M>>,
pub movement: PlayerMovementContext,

#[cfg(feature = "ears")]
pub ears_features: Option<EarsFeatures>,
}

#[derive(Debug, Copy, Clone, Default)]
pub struct PlayerMovementContext {
pub time: f32,

pub limb_swing: f32,
pub stride: f32,
pub body_yaw: f32,

pub location: Vec3,
pub cape_location: Vec3,
pub horizontal_speed: f32,

pub is_flying: bool,
pub is_creative_flying: bool,
pub is_gliding: bool,
}

impl<M> PlayerPartProviderContext<M>
where
M: ArmorMaterial,
Expand Down Expand Up @@ -141,7 +160,7 @@ impl<M: ArmorMaterial> PartsProvider<M> for PlayerPartsProvider {
body_part.get_non_layer_part(),
part,
context.model.is_slim_arms(),
context.arm_rotation,
&context,
);
}

Expand Down
20 changes: 13 additions & 7 deletions nmsr-3d-renderer/nmsr-rendering/src/high_level/utils/parts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,18 @@ fn uv(face_uvs: &FaceUv, texture_size: (u32, u32)) -> [Vec2; 4] {
let mut bottom_left = face_uvs.bottom_left.to_uv(texture_size);
let mut bottom_right = face_uvs.bottom_right.to_uv(texture_size);

let small_offset = 0.000; //Vec2::ONE / texture_size / 32.0;//001;

top_left += small_offset;
top_right += Vec2::new(-small_offset, small_offset);
bottom_right -= small_offset;
bottom_left += Vec2::new(small_offset, -small_offset);

let small_offset: Option<Vec2> = None;//Vec2::ZERO; //Vec2::ONE / texture_size / 16.0;

if let Some(small_offset) = small_offset {
// Apply offset inward from each edge to prevent texture bleeding
// Move each coordinate slightly toward the center of the UV quad
let center = (top_left + top_right + bottom_left + bottom_right) / 4.0;

top_left = top_left + (center - top_left).normalize() * small_offset;
top_right = top_right + (center - top_right).normalize() * small_offset;
bottom_left = bottom_left + (center - bottom_left).normalize() * small_offset;
bottom_right = bottom_right + (center - bottom_right).normalize() * small_offset;
}

[top_left, top_right, bottom_left, bottom_right]
}
Loading

0 comments on commit 4cd1b27

Please sign in to comment.