Use hand texture as render background

This commit is contained in:
lenn
2026-06-26 16:59:58 +08:00
parent 0b658d11c5
commit b3fa3c8341
13 changed files with 1962 additions and 1375180 deletions

View File

@@ -2,6 +2,7 @@ use eframe::egui_wgpu::wgpu;
use std::ops::Range;
use crate::texture;
pub trait Vertex {
fn desc<'a>() -> wgpu::VertexBufferLayout<'a>;
}
@@ -12,6 +13,8 @@ pub struct ModelVertex {
pub position: [f32; 3],
pub tex_coords: [f32; 2],
pub normal: [f32; 3],
pub color: [f32; 4],
pub tangent: [f32; 4],
}
impl Vertex for ModelVertex {
@@ -36,6 +39,16 @@ impl Vertex for ModelVertex {
shader_location: 2,
format: wgpu::VertexFormat::Float32x3,
},
wgpu::VertexAttribute {
offset: mem::size_of::<[f32; 8]>() as wgpu::BufferAddress,
shader_location: 3,
format: wgpu::VertexFormat::Float32x4,
},
wgpu::VertexAttribute {
offset: mem::size_of::<[f32; 12]>() as wgpu::BufferAddress,
shader_location: 4,
format: wgpu::VertexFormat::Float32x4,
},
],
}
}
@@ -54,7 +67,8 @@ impl Instance {
pub fn to_raw(&self) -> InstanceRaw {
InstanceRaw {
model: (glam::Mat4::from_translation(self.position)
* glam::Mat4::from_quat(self.rotation))
* glam::Mat4::from_quat(self.rotation)
* glam::Mat4::from_scale(glam::Vec3::splat(128.0)))
.to_cols_array_2d(),
}
}
@@ -111,9 +125,43 @@ pub struct Model {
pub materials: Vec<Material>,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum AlphaMode {
Opaque,
Mask,
Blend,
}
impl AlphaMode {
pub fn as_str(self) -> &'static str {
match self {
Self::Opaque => "OPAQUE",
Self::Mask => "MASK",
Self::Blend => "BLEND",
}
}
pub fn shader_value(self) -> f32 {
match self {
Self::Opaque => 0.0,
Self::Mask => 1.0,
Self::Blend => 2.0,
}
}
}
pub struct Material {
pub name: String,
pub diffuse_texture: texture::Texture,
pub alpha_mode: AlphaMode,
pub alpha_cutoff: f32,
pub base_color_factor: [f32; 4],
pub double_sided: bool,
pub base_color_texture: texture::Texture,
pub metallic_roughness_texture: texture::Texture,
pub normal_texture: texture::Texture,
pub occlusion_texture: texture::Texture,
pub emissive_texture: texture::Texture,
pub params_buffer: wgpu::Buffer,
pub bind_group: wgpu::BindGroup,
}
@@ -123,6 +171,7 @@ pub struct Mesh {
pub index_buffer: wgpu::Buffer,
pub num_elements: u32,
pub material: usize,
pub center: [f32; 3],
}
pub trait DrawModel<'a> {