Skip to content

Commit b877836

Browse files
committed
entities sort of working
1 parent 0671cd4 commit b877836

File tree

12 files changed

+232
-155
lines changed

12 files changed

+232
-155
lines changed

azalea-graphics/azalea-assets/src/entity.rs

Lines changed: 0 additions & 37 deletions
This file was deleted.

azalea-graphics/azalea-assets/src/lib.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
pub mod entity;
21
pub mod processed;
32
mod raw;
4-
use std::{collections::HashMap, fs, ops::Deref, path::PathBuf, sync::Arc, time::Instant};
3+
use std::{collections::HashMap, fs, path::PathBuf, sync::Arc, time::Instant};
54

6-
use azalea_block::{BlockState, BlockTrait};
5+
use azalea_block::BlockState;
76
use log::*;
87
use raw::{
98
block_state::{BlockRenderState, Variant},
@@ -18,7 +17,7 @@ use self::{
1817
},
1918
raw::atlas::SpriteAtlas,
2019
};
21-
use crate::processed::atlas::TextureEntry;
20+
use crate::processed::{atlas::TextureEntry, entity_model::Model};
2221

2322
pub struct Assets {
2423
path: PathBuf,
@@ -30,7 +29,7 @@ pub struct Assets {
3029

3130
pub block_textures: HashMap<String, TextureEntry>,
3231

33-
pub entity_models: HashMap<String, entity::ModelPart>,
32+
pub entity_models: HashMap<String, Model>,
3433
}
3534

3635
impl Assets {
@@ -213,7 +212,7 @@ pub fn load_assets(path: impl Into<PathBuf>, max_tex: u32) -> Assets {
213212
.filter(|case| {
214213
case.when
215214
.as_ref()
216-
.map_or(true, |cond| cond.matches(dyn_block.deref()))
215+
.map_or(true, |cond| cond.matches(dyn_block))
217216
})
218217
.filter_map(|case| match &case.apply {
219218
Variant::Single(desc) => Some(desc),
@@ -236,12 +235,17 @@ pub fn load_assets(path: impl Into<PathBuf>, max_tex: u32) -> Assets {
236235
info!("Mapped blockstates to models in {:?}", start.elapsed());
237236

238237
let entity_models_path = path.join("entity_models.json");
239-
let entity_models: HashMap<String, entity::ModelPart> = serde_json::from_str(
238+
let raw_entity_models: HashMap<String, raw::entity_model::ModelPart> = serde_json::from_str(
240239
&fs::read_to_string(&entity_models_path)
241240
.unwrap_or_else(|_| panic!("missing {}", entity_models_path.display())),
242241
)
243242
.expect("invalid entity_models.json");
244243

244+
let entity_models = raw_entity_models
245+
.into_iter()
246+
.map(|(name, raw)| (name, Model::from_raw(raw)))
247+
.collect();
248+
245249
let start = Instant::now();
246250

247251
let blocks_atlas_path = path.join("atlases/blocks.json");
@@ -317,7 +321,3 @@ fn load_colormap(textures_root: &PathBuf, relative_path: &str) -> Option<image::
317321
}
318322
}
319323
}
320-
321-
fn strip_namespace(model_name: &str) -> &str {
322-
model_name.strip_prefix("minecraft:").unwrap_or(model_name)
323-
}

azalea-graphics/azalea-assets/src/processed/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::processed::model::BlockModel;
55
pub mod animation;
66
pub mod atlas;
77
pub mod model;
8+
pub mod entity_model;
89

910
#[derive(Debug, Clone)]
1011
pub struct VariantDesc {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pub(crate) mod atlas;
22
pub(crate) mod block_state;
33
pub(crate) mod model;
4+
pub(crate) mod entity_model;

azalea-graphics/shaders/src/entity.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,33 @@ use crate::terrain::WorldUniform;
99

1010
#[repr(C)]
1111
pub struct PC {
12-
model: Mat4,
1312
texture: u32,
13+
transform_offset: u32,
1414
}
1515
#[spirv(vertex)]
1616
pub fn vert(
1717
#[spirv(descriptor_set = 0, binding = 0, uniform)] uniform: &WorldUniform,
18+
#[spirv(descriptor_set = 0, binding = 1, storage_buffer)] transforms: &[Mat4],
1819
#[spirv(push_constant)] pc: &PC,
1920

2021
in_pos: Vec3,
21-
_in_transform_id: u32,
22+
in_transform_id: u32,
2223
in_uv: Vec2,
2324

2425
out_uv: &mut Vec2,
2526
out_texture: &mut u32,
2627

2728
#[spirv(position)] out_pos: &mut Vec4,
2829
) {
29-
*out_pos = uniform.view_proj * pc.model * in_pos.extend(1.0);
30+
*out_pos = uniform.view_proj * transforms[in_transform_id as usize + pc.transform_offset as usize] * in_pos.extend(1.0);
3031
*out_uv = in_uv;
3132
*out_texture = pc.texture;
3233
}
3334

3435
#[spirv(fragment)]
3536
pub fn frag(
3637
in_uv: Vec2,
37-
#[spirv(flat)]in_tex: u32,
38+
#[spirv(flat)] in_tex: u32,
3839
#[spirv(descriptor_set = 1, binding = 0)] textures: &RuntimeArray<
3940
SampledImage<Image!(2D, type=f32, sampled)>,
4041
>,

0 commit comments

Comments
 (0)