diff options
| -rw-r--r-- | crates/teleia/examples/assets/fonts/ComicNeue-Regular.ttf (renamed from examples/assets/fonts/ComicNeue-Regular.ttf) | bin | 54848 -> 54848 bytes | |||
| -rw-r--r-- | crates/teleia/examples/assets/meshes/cube.obj (renamed from examples/assets/meshes/cube.obj) | 0 | ||||
| -rw-r--r-- | crates/teleia/examples/assets/scenes/dagger.glb | bin | 0 -> 13208 bytes | |||
| -rw-r--r-- | crates/teleia/examples/assets/scenes/fox.glb (renamed from examples/assets/scenes/fox.glb) | bin | 162852 -> 162852 bytes | |||
| -rw-r--r-- | crates/teleia/examples/assets/textures/test.png (renamed from examples/assets/textures/test.png) | bin | 125 -> 125 bytes | |||
| -rw-r--r-- | crates/teleia/examples/fox.rs (renamed from examples/fox.rs) | 38 | ||||
| -rw-r--r-- | crates/teleia/src/assets/shaders/scene/vert.glsl | 3 | ||||
| -rw-r--r-- | crates/teleia/src/scene.rs | 6 |
8 files changed, 20 insertions, 27 deletions
diff --git a/examples/assets/fonts/ComicNeue-Regular.ttf b/crates/teleia/examples/assets/fonts/ComicNeue-Regular.ttf Binary files differindex d454f46..d454f46 100644 --- a/examples/assets/fonts/ComicNeue-Regular.ttf +++ b/crates/teleia/examples/assets/fonts/ComicNeue-Regular.ttf diff --git a/examples/assets/meshes/cube.obj b/crates/teleia/examples/assets/meshes/cube.obj index 2f3a670..2f3a670 100644 --- a/examples/assets/meshes/cube.obj +++ b/crates/teleia/examples/assets/meshes/cube.obj diff --git a/crates/teleia/examples/assets/scenes/dagger.glb b/crates/teleia/examples/assets/scenes/dagger.glb Binary files differnew file mode 100644 index 0000000..4eb8528 --- /dev/null +++ b/crates/teleia/examples/assets/scenes/dagger.glb diff --git a/examples/assets/scenes/fox.glb b/crates/teleia/examples/assets/scenes/fox.glb Binary files differindex 1ef5c0d..1ef5c0d 100644 --- a/examples/assets/scenes/fox.glb +++ b/crates/teleia/examples/assets/scenes/fox.glb diff --git a/examples/assets/textures/test.png b/crates/teleia/examples/assets/textures/test.png Binary files differindex 0752be0..0752be0 100644 --- a/examples/assets/textures/test.png +++ b/crates/teleia/examples/assets/textures/test.png diff --git a/examples/fox.rs b/crates/teleia/examples/fox.rs index bfa97f0..e0d0d5c 100644 --- a/examples/fox.rs +++ b/crates/teleia/examples/fox.rs @@ -1,24 +1,18 @@ use teleia::*; -use std::ops::Rem; - pub struct TestGame { - font: font::Bitmap, - tt: font::TrueType, // cube: mesh::Mesh, - fox: scene::Scene, + scene: scene::Scene, tex: texture::Texture, shader: shader::Shader, } impl TestGame { - pub async fn new(ctx: &context::Context) -> Self { + pub fn new(ctx: &context::Context, _st: &mut state::State) -> Self { Self { - font: font::Bitmap::new(ctx), - tt: font::TrueType::new(ctx, 12.0, include_bytes!("assets/fonts/ComicNeue-Regular.ttf")), // cube: mesh::Mesh::from_obj(ctx, include_bytes!("assets/meshes/cube.obj")), - fox: scene::Scene::from_gltf(ctx, include_bytes!("assets/scenes/fox.glb")), - // fox: scene::Scene::from_gltf(ctx, include_bytes!("/home/llll/src/colonq/assets/lcolonq_flat.vrm")), + // fox: scene::Scene::from_gltf(ctx, include_bytes!("assets/scenes/fox.glb")), + scene: scene::Scene::from_gltf(ctx, include_bytes!("assets/scenes/dagger.glb")), tex: texture::Texture::new(ctx, include_bytes!("assets/textures/test.png")), shader: scene::Scene::load_default_shader(ctx), } @@ -40,33 +34,23 @@ impl state::Game for TestGame { // n.transform *= glam::Mat4::from_rotation_z(0.05); // } ctx.clear(); - self.fox.reflect_animation("Run", (st.tick as f32 / 60.0).rem(3.0)); + // self.fox.reflect_animation("Run", (st.tick as f32 / 60.0).rem(3.0)); st.bind_3d(ctx, &self.shader); self.shader.set_position_3d( - ctx, + ctx, st, &glam::Mat4::from_scale_rotation_translation( - glam::Vec3::new(0.005, 0.005, 0.005), - // glam::Vec3::new(1.0, 1.0, 1.0), + // glam::Vec3::new(0.005, 0.005, 0.005), + glam::Vec3::new(1.0, 1.0, 1.0), glam::Quat::from_rotation_y(st.tick as f32 / 60.0), glam::Vec3::new(0.0, -0.2, 0.0), ), ); self.tex.bind(ctx); - self.fox.render(ctx, &self.shader); - self.font.render_text(ctx, &glam::Vec2::new(0.0, 10.0), "he's all FIXED up"); - self.tt.render_text_helper( - ctx, &glam::Vec2::new(10.0, 60.0), &glam::Vec2::new(20.0, 30.0), - "tESTge", - &[ - glam::Vec3::new(1.0, 0.0, 0.0), - glam::Vec3::new(0.0, 1.0, 0.0), - ], - ); + self.scene.render(ctx, &self.shader); Ok(()) } } -#[tokio::main] -pub async fn main() { - run("teleia test", 240, 160, Options::empty(), TestGame::new).await; +pub fn main() -> Erm<()> { + run("teleia test", 240, 160, Options::empty(), TestGame::new) } diff --git a/crates/teleia/src/assets/shaders/scene/vert.glsl b/crates/teleia/src/assets/shaders/scene/vert.glsl index 64f400c..5be64b9 100644 --- a/crates/teleia/src/assets/shaders/scene/vert.glsl +++ b/crates/teleia/src/assets/shaders/scene/vert.glsl @@ -1,6 +1,7 @@ in vec4 joint; in vec4 weight; +uniform int has_joints; uniform mat4 joint_matrices[128]; void main() @@ -12,7 +13,9 @@ void main() + weight.y * joint_matrices[int(joint.y)] + weight.z * joint_matrices[int(joint.z)] + weight.w * joint_matrices[int(joint.w)]; + if (has_joints == 0) skin = mat4(1.0); vec3 pos = (position * skin * vec4(vertex, 1.0)).xyz; + // vec3 pos = (position * vec4(vertex, 1.0)).xyz; vertex_view_vector = camera_pos - pos; gl_Position = projection * view * vec4(pos, 1.0); } diff --git a/crates/teleia/src/scene.rs b/crates/teleia/src/scene.rs index 26615fb..13b09ad 100644 --- a/crates/teleia/src/scene.rs +++ b/crates/teleia/src/scene.rs @@ -76,6 +76,7 @@ pub struct Scene { pub nodes: Vec<Node>, pub nodes_by_name: HashMap<String, Index>, pub scene_nodes: Vec<Index>, + pub has_joints: bool, } impl Scene { @@ -91,6 +92,7 @@ impl Scene { let get_buffer_data = |b: gltf::Buffer| { buffers.get(b.index()).map(|gltf::buffer::Data(bytes)| bytes.as_slice()) }; + let mut has_joints = false; let objects = gltf.meshes().map(|m| { let primitives = m.primitives().map(|p| { let mode = match p.mode() { @@ -163,11 +165,13 @@ impl Scene { } } if let Some(iter) = reader.read_joints(0) { + has_joints = true; for (i, j) in iter.into_u16().enumerate() { vertices[i].joints = glam::Vec4::from_slice(&j.into_iter().map(|x| x as f32).collect::<Vec<f32>>()) } } if let Some(iter) = reader.read_weights(0) { + has_joints = true; for (i, w) in iter.into_f32().enumerate() { vertices[i].weights = glam::Vec4::from_array(w) } @@ -318,6 +322,7 @@ impl Scene { nodes, nodes_by_name, scene_nodes, + has_joints, } } @@ -363,6 +368,7 @@ impl Scene { for sn in &self.scene_nodes { q.push_back(*sn); } + shader.set_i32(ctx, "has_joints", self.has_joints as i32); while let Some(ni) = q.pop_front() { let n = &self.nodes[ni]; self.render_node(ctx, shader, n); |
