Merge pull request #197 from ludovic111/fix/end-crystal-102
End crystals from EndCrystalModel: lit, with their base and beams
This commit is contained in:
@@ -294,12 +294,26 @@ fn main() -> horizon_client::Result<()> {
|
||||
let types = MobTypes::load(&root)?;
|
||||
let animations = MobData::load_animations(&root);
|
||||
let mut out = String::new();
|
||||
let crystal = horizon_client::mobs::load_model(&root, "minecraft:end_crystal#main");
|
||||
for line in fs::read_to_string(&args[1])?.lines() {
|
||||
let v: Value = serde_json::from_str(line)?;
|
||||
let layer = v["layer"]
|
||||
.as_str()
|
||||
.unwrap_or_default()
|
||||
.trim_start_matches("minecraft:");
|
||||
// EndCrystalModel is not a mob's: horizon_client::end_crystal poses it.
|
||||
if layer == "end_crystal#main"
|
||||
&& let Some(model) = &crystal
|
||||
{
|
||||
let case = &v["case"];
|
||||
let mut poses = horizon_client::end_crystal::poses(
|
||||
model,
|
||||
case["ageInTicks"].as_f64().unwrap_or(0.0) as f32,
|
||||
case["showsBottom"].as_bool().unwrap_or(false),
|
||||
);
|
||||
out.push_str(&format!("{}\n", emit(model, &mut poses, case, layer)));
|
||||
continue;
|
||||
}
|
||||
let baby = layer.contains("_baby#");
|
||||
let adult = layer.replace("_baby#", "#");
|
||||
// Variant layers (sizes, hatless villagers, climate cows...) animate
|
||||
@@ -576,35 +590,38 @@ fn main() -> horizon_client::Result<()> {
|
||||
}
|
||||
_ => anim::setup(&mob, s, p, &animations),
|
||||
}
|
||||
// The harness's part-scale override, set after setupAnim as the oracle does.
|
||||
if let Some(scale) = case["@partScale"].as_array() {
|
||||
let pose = poses.get(scale[0].as_str().unwrap_or_default());
|
||||
for i in 0..3 {
|
||||
pose[6 + i] = scale[1 + i].as_f64().unwrap_or(1.0) as f32;
|
||||
}
|
||||
}
|
||||
let mut parts = BTreeMap::new();
|
||||
walk(&model, "", &poses, &mut parts);
|
||||
let mut emitted = Vec::new();
|
||||
render::draw(
|
||||
&model,
|
||||
root_transform(case),
|
||||
&poses,
|
||||
[0.0, 0.0, 1.0, 1.0],
|
||||
0xFFFF_FFFF,
|
||||
240 | 240 << 8,
|
||||
0,
|
||||
&mut emitted,
|
||||
);
|
||||
let mut vertices = BTreeMap::new();
|
||||
let mut cursor = 0;
|
||||
drawn(&model, "", &poses, &emitted, &mut cursor, &mut vertices);
|
||||
assert_eq!(cursor, emitted.len(), "{layer}: draw's walk changed");
|
||||
out.push_str(&format!(
|
||||
"{}\n",
|
||||
json!({"parts": parts, "vertices": vertices})
|
||||
));
|
||||
out.push_str(&format!("{}\n", emit(&model, &mut poses, case, layer)));
|
||||
}
|
||||
fs::write(&args[2], out)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Every part's pose, and the vertices drawn under the harness's root transform.
|
||||
fn emit(model: &Part, poses: &mut Poses, case: &Value, layer: &str) -> Value {
|
||||
// The harness's part-scale override, set after setupAnim as the oracle does.
|
||||
if let Some(scale) = case["@partScale"].as_array() {
|
||||
let pose = poses.get(scale[0].as_str().unwrap_or_default());
|
||||
for i in 0..3 {
|
||||
pose[6 + i] = scale[1 + i].as_f64().unwrap_or(1.0) as f32;
|
||||
}
|
||||
}
|
||||
let poses = &*poses;
|
||||
let mut parts = BTreeMap::new();
|
||||
walk(model, "", poses, &mut parts);
|
||||
let mut emitted = Vec::new();
|
||||
render::draw(
|
||||
model,
|
||||
root_transform(case),
|
||||
poses,
|
||||
[0.0, 0.0, 1.0, 1.0],
|
||||
0xFFFF_FFFF,
|
||||
240 | 240 << 8,
|
||||
0,
|
||||
&mut emitted,
|
||||
);
|
||||
let mut vertices = BTreeMap::new();
|
||||
let mut cursor = 0;
|
||||
drawn(model, "", poses, &emitted, &mut cursor, &mut vertices);
|
||||
assert_eq!(cursor, emitted.len(), "{layer}: draw's walk changed");
|
||||
json!({"parts": parts, "vertices": vertices})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
//! `EndCrystalRenderer` and `EndCrystalModel.setupAnim`: the crystal's bob
|
||||
//! and the poses of its base, glass and cube.
|
||||
use crate::mobs::{Part, anim::Poses};
|
||||
use horizon_core::geometry::trig::Mth;
|
||||
|
||||
/// `EndCrystalRenderer.getY`: the crystal's bob below its resting height.
|
||||
pub fn y(age: f32) -> f32 {
|
||||
let hh = (age * 0.2).msin() / 2.0 + 0.5;
|
||||
(hh * hh + hh) * 0.4 - 1.4
|
||||
}
|
||||
|
||||
/// `EndCrystalModel.setupAnim`: the base shown or not, the glass raised by
|
||||
/// half the bob (in model pixels) and the three cubes turned with
|
||||
/// `ModelPart.rotateBy`, which stores the composed rotation as ZYX angles.
|
||||
pub fn poses(model: &Part, age: f32, show_bottom: bool) -> Poses {
|
||||
let mut poses = Poses::new(model);
|
||||
poses.visible("base", show_bottom);
|
||||
let speed = age * 3.0;
|
||||
let sin45 = std::f32::consts::FRAC_PI_4.sin();
|
||||
let tilt = glam::Quat::from_axis_angle(
|
||||
glam::Vec3::new(sin45, 0.0, sin45),
|
||||
std::f32::consts::FRAC_PI_3,
|
||||
);
|
||||
let spin = glam::Quat::from_rotation_y(speed.to_radians());
|
||||
poses.get("outer_glass")[1] += y(age) * 16.0 / 2.0;
|
||||
for (part, rotation) in [
|
||||
("outer_glass", spin * tilt),
|
||||
("inner_glass", tilt * spin),
|
||||
("cube", tilt * spin),
|
||||
] {
|
||||
let (z, y, x) = rotation.to_euler(glam::EulerRot::ZYX);
|
||||
let pose = poses.get(part);
|
||||
pose[3] = x;
|
||||
pose[4] = y;
|
||||
pose[5] = z;
|
||||
}
|
||||
poses
|
||||
}
|
||||
@@ -834,6 +834,8 @@ struct Game<'a> {
|
||||
armor_stand_assets: armor_stands::ArmorStandAssets,
|
||||
boats: Vec<boats::Boat>,
|
||||
boat_models: boats::BoatModels,
|
||||
/// EndCrystalModel's baked layer.
|
||||
crystal_model: Option<horizon_client::mobs::Part>,
|
||||
carts: Vec<minecarts::Minecart>,
|
||||
/// Songs playing from jukeboxes (tracked sound handles).
|
||||
jukebox_sounds: HashMap<(i32, i32, i32), u64>,
|
||||
@@ -9141,6 +9143,7 @@ pub fn run() -> Result<()> {
|
||||
armor_stand_assets: armor_stands::ArmorStandAssets::load(&root),
|
||||
boats: Vec::new(),
|
||||
boat_models: boats::BoatModels::load(&root),
|
||||
crystal_model: horizon_client::mobs::load_model(&root, "minecraft:end_crystal#main"),
|
||||
carts: Vec::new(),
|
||||
jukebox_sounds: HashMap::new(),
|
||||
bolts: Vec::new(),
|
||||
|
||||
@@ -2066,9 +2066,7 @@ impl Game<'_> {
|
||||
}
|
||||
// The healing beam to the nearest crystal.
|
||||
if let Some(c) = d.nearest_crystal.and_then(|i| self.crystals.get(i)) {
|
||||
let age = c.time as f32 + a;
|
||||
let hh = (age * 0.2).sin() / 2.0 + 0.5;
|
||||
let bob = f64::from((hh * hh + hh) * 0.4 - 1.4);
|
||||
let bob = f64::from(horizon_client::end_crystal::y(c.time as f32 + a));
|
||||
let to = glam::DVec3::new(c.position.x, c.position.y + bob, c.position.z);
|
||||
self.crystal_beam(pos, to - pos, self.ticks as f32 + a, camera, out);
|
||||
}
|
||||
@@ -2122,7 +2120,7 @@ impl Game<'_> {
|
||||
}
|
||||
/// `submitCrystalBeams`: an eight-sided tube from `from` (+2 up) along
|
||||
/// `delta`, the beam texture scrolling along it.
|
||||
fn crystal_beam(
|
||||
pub(super) fn crystal_beam(
|
||||
&self,
|
||||
from: glam::DVec3,
|
||||
delta: glam::DVec3,
|
||||
|
||||
@@ -881,130 +881,67 @@ impl Game<'_> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The End crystals on the spikes and thrown eyes of ender, as
|
||||
/// camera-relative entity geometry (End portals and gateways are block
|
||||
/// entities).
|
||||
/// End crystals (on the spikes, or placed in any dimension) and thrown
|
||||
/// eyes of ender, as camera-relative entity geometry (End portals and
|
||||
/// gateways are block entities).
|
||||
pub(super) fn end_geometry(&self, camera: glam::DVec3, out: &mut Vec<Vertex>) {
|
||||
if self.dim == Dim::End {
|
||||
self.end_crystal_geometry(camera, out);
|
||||
}
|
||||
self.end_crystal_geometry(camera, out);
|
||||
self.eye_geometry(camera, out);
|
||||
}
|
||||
|
||||
/// EndCrystalRenderer and EndCrystalModel for the end crystals.
|
||||
/// EndCrystalRenderer and EndCrystalModel for the end crystals, and the
|
||||
/// beam to a crystal's target (the spikes being summoned back).
|
||||
fn end_crystal_geometry(&self, camera: glam::DVec3, out: &mut Vec<Vertex>) {
|
||||
let Some(r) = self
|
||||
.res
|
||||
.atlas
|
||||
.sprites
|
||||
.get("entity/end_crystal/end_crystal")
|
||||
.copied()
|
||||
else {
|
||||
let (Some(model), Some(r)) = (
|
||||
self.crystal_model.as_ref(),
|
||||
self.res
|
||||
.atlas
|
||||
.sprites
|
||||
.get("entity/end_crystal/end_crystal")
|
||||
.copied(),
|
||||
) else {
|
||||
return;
|
||||
};
|
||||
let sin45 = std::f32::consts::FRAC_PI_4.sin();
|
||||
let axis = glam::Vec3::new(sin45, 0.0, sin45).normalize();
|
||||
let tilt = glam::Quat::from_axis_angle(axis, std::f32::consts::FRAC_PI_3);
|
||||
// A 8×8×8 model box at texture offset (u, v) of the 64×32 texture.
|
||||
let uv = |u: f32, v: f32, w: f32, h: f32| {
|
||||
let su = |x: f32| r.u0 + (r.u1 - r.u0) * x / 64.0;
|
||||
let sv = |y: f32| r.v0 + (r.v1 - r.v0) * y / 32.0;
|
||||
(su(u), su(u + w), sv(v), sv(v + h))
|
||||
};
|
||||
let uv = [r.u0, r.v0, r.u1, r.v1];
|
||||
let partial = self.clock.fraction() as f32;
|
||||
for crystal in &self.crystals {
|
||||
let feet = glam::DVec3::new(crystal.position.x, crystal.position.y, crystal.position.z);
|
||||
let age = crystal.time as f32 + self.clock.fraction() as f32;
|
||||
let spin = glam::Quat::from_rotation_y((age * 3.0).to_radians());
|
||||
let hh = (age * 0.2).sin() / 2.0 + 0.5;
|
||||
let bob = (hh * hh + hh) * 0.4 - 1.4;
|
||||
let rel = feet - camera;
|
||||
if rel.length_squared() > 256.0 * 256.0 {
|
||||
continue;
|
||||
}
|
||||
let age = crystal.time as f32 + partial;
|
||||
let light = self.world.light(
|
||||
feet.x.floor() as i32,
|
||||
feet.y.floor() as i32,
|
||||
feet.z.floor() as i32,
|
||||
);
|
||||
let packed = (u32::from(light >> 4) * 16) | ((u32::from(light & 15) * 16) << 8);
|
||||
// poseStack.scale(2) then translate(0, -0.5, 0); outer_glass at y 24 px + bob.
|
||||
let center = rel.as_vec3() + glam::Vec3::new(0.0, 2.0 * (24.0 / 16.0 - 0.5) + bob, 0.0);
|
||||
let outer = spin * tilt;
|
||||
let inner = tilt * spin;
|
||||
let parts = [
|
||||
(outer, 1.0, 0.0),
|
||||
(outer * inner, 0.875, 0.0),
|
||||
(outer * inner * inner, 0.875 * 0.765_625, 32.0),
|
||||
];
|
||||
for (rotation, scale, u) in parts {
|
||||
// Half extent: 4 px, times the renderer's scale of 2.
|
||||
let h = 0.25 * 2.0 * scale;
|
||||
let corner = |x: f32, y: f32, z: f32| {
|
||||
center + rotation * glam::Vec3::new(x * h, y * h, z * h)
|
||||
};
|
||||
let faces: [([f32; 3], [f32; 3], [f32; 3], (f32, f32, f32, f32)); 6] = [
|
||||
(
|
||||
[-1.0, 1.0, -1.0],
|
||||
[1.0, 0.0, 0.0],
|
||||
[0.0, 0.0, 1.0],
|
||||
uv(u + 8.0, 0.0, 8.0, 8.0),
|
||||
),
|
||||
(
|
||||
[-1.0, -1.0, -1.0],
|
||||
[1.0, 0.0, 0.0],
|
||||
[0.0, 0.0, 1.0],
|
||||
uv(u + 16.0, 0.0, 8.0, 8.0),
|
||||
),
|
||||
(
|
||||
[-1.0, -1.0, -1.0],
|
||||
[0.0, 0.0, 1.0],
|
||||
[0.0, 1.0, 0.0],
|
||||
uv(u, 8.0, 8.0, 8.0),
|
||||
),
|
||||
(
|
||||
[-1.0, -1.0, -1.0],
|
||||
[1.0, 0.0, 0.0],
|
||||
[0.0, 1.0, 0.0],
|
||||
uv(u + 8.0, 8.0, 8.0, 8.0),
|
||||
),
|
||||
(
|
||||
[1.0, -1.0, -1.0],
|
||||
[0.0, 0.0, 1.0],
|
||||
[0.0, 1.0, 0.0],
|
||||
uv(u + 16.0, 8.0, 8.0, 8.0),
|
||||
),
|
||||
(
|
||||
[-1.0, -1.0, 1.0],
|
||||
[1.0, 0.0, 0.0],
|
||||
[0.0, 1.0, 0.0],
|
||||
uv(u + 24.0, 8.0, 8.0, 8.0),
|
||||
),
|
||||
];
|
||||
for (o, a, b, (u0, u1, v0, v1)) in faces {
|
||||
let p = |s: f32, t: f32| {
|
||||
corner(
|
||||
o[0] + 2.0 * (a[0] * s + b[0] * t),
|
||||
o[1] + 2.0 * (a[1] * s + b[1] * t),
|
||||
o[2] + 2.0 * (a[2] * s + b[2] * t),
|
||||
)
|
||||
};
|
||||
let quad = [
|
||||
(p(0.0, 0.0), [u0, v1]),
|
||||
(p(1.0, 0.0), [u1, v1]),
|
||||
(p(1.0, 1.0), [u1, v0]),
|
||||
(p(0.0, 1.0), [u0, v0]),
|
||||
];
|
||||
for (pos, uv) in quad {
|
||||
out.push(Vertex {
|
||||
normal: [0; 4],
|
||||
pos: pos.to_array(),
|
||||
uv,
|
||||
layer: 0,
|
||||
color: 0xFFFF_FFFF,
|
||||
light: packed,
|
||||
});
|
||||
}
|
||||
}
|
||||
let poses = horizon_client::end_crystal::poses(model, age, crystal.show_bottom);
|
||||
// poseStack.scale(2) then translate(0, -0.5, 0), not flipped.
|
||||
let base = glam::Mat4::from_translation(rel.as_vec3())
|
||||
* glam::Mat4::from_scale(glam::Vec3::splat(2.0))
|
||||
* glam::Mat4::from_translation(glam::Vec3::new(0.0, -0.5, 0.0));
|
||||
horizon_client::mobs::render::draw(
|
||||
model,
|
||||
base,
|
||||
&poses,
|
||||
uv,
|
||||
0xFFFF_FFFF,
|
||||
packed,
|
||||
0,
|
||||
out,
|
||||
);
|
||||
if let Some(target) = crystal.beam {
|
||||
// The beam from the target's centre up to the bobbing crystal.
|
||||
let from = glam::DVec3::new(
|
||||
f64::from(target[0]) + 0.5,
|
||||
f64::from(target[1]) + 0.5,
|
||||
f64::from(target[2]) + 0.5,
|
||||
);
|
||||
let delta = feet - from
|
||||
+ glam::DVec3::new(0.0, f64::from(horizon_client::end_crystal::y(age)), 0.0);
|
||||
self.crystal_beam(from, delta, age, camera, out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ pub mod datapack;
|
||||
pub mod debug_keys;
|
||||
pub mod effects;
|
||||
pub mod enchant;
|
||||
pub mod end_crystal;
|
||||
pub mod entities;
|
||||
pub mod entity_nbt;
|
||||
pub mod environment;
|
||||
|
||||
@@ -78,7 +78,7 @@ EXTRAS = [
|
||||
# Layers a renderer reuses for another entity under a different constant.
|
||||
SKIP_LAYERS = re.compile(r'(banner|bell|book|skull|head|chest|shulker_box|boat|cushion|conduit|leash|arrow|trident|'
|
||||
r'shield|elytra|spin_attack|ears|cape|decorated_pot|minecart|wind_charge|evoker_fangs|'
|
||||
r'llama_spit|shulker_bullet|bee_stinger|end_crystal|armor_stand|copper_golem_\w+|#(helmet|chestplate|leggings|'
|
||||
r'llama_spit|shulker_bullet|bee_stinger|armor_stand|copper_golem_\w+|#(helmet|chestplate|leggings|'
|
||||
r'boots|outer|armor|decor|saddle|collar|wool|wool_undercoat|eyes|wind|inner|pattern|tendrils|'
|
||||
r'heart|bioluminescent|pulsating_spots|water_patch|flag|cage|shell)$)')
|
||||
|
||||
@@ -249,6 +249,8 @@ SPECIES = {
|
||||
'frog': [{'isSwimming': T}, {'isSwimming': F}, {'jumpAnimationState': 2}, {'croakAnimationState': 1},
|
||||
{'tongueAnimationState': 3}, {'swimIdleAnimationState': 2, 'isSwimming': T}],
|
||||
'rabbit': [{'hopAnimationState': 2}, {'idleHeadTiltAnimationState': 1}],
|
||||
# EndCrystalModel (not a mob): the base hidden for a placed crystal.
|
||||
'end_crystal': [{'showsBottom': F}, {'showsBottom': F, 'ageInTicks': 91234.5}],
|
||||
'fox': FOX,
|
||||
# CopperGolemModel: the idle head spin and the four chest interactions (started N ticks ago).
|
||||
'copper_golem': [{'idleAnimationState': 4}, {'idleAnimationState': 37}, {'interactionGetItem': 3},
|
||||
@@ -266,7 +268,7 @@ SPECIES = {
|
||||
DEFAULTS = {'creaking': {'canMove': T}, 'wolf': {'tailAngle': 0.6283185307179586}, 'axolotl': {'inWaterFactor': 1.0}, 'bee': {'hasStinger': T}, 'sheep': {'eatTick': 0},
|
||||
'goat': {'hasLeftHorn': T, 'hasRightHorn': T}, 'parrot': {'pose': 'STANDING'},
|
||||
'phantom': {'flapOffset': 21.0}, 'guardian': {'tailAnimation': 1.3, 'spikesAnimation': 1.0},
|
||||
'elder_guardian': {'tailAnimation': 1.3, 'spikesAnimation': 1.0}}
|
||||
'elder_guardian': {'tailAnimation': 1.3, 'spikesAnimation': 1.0}, 'end_crystal': {'showsBottom': T}}
|
||||
|
||||
|
||||
def species_cases(layer, base_cases):
|
||||
|
||||
Reference in New Issue
Block a user