summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock7
-rw-r--r--Cargo.toml5
-rw-r--r--examples/assets/fonts/ComicNeue-Regular.ttf (renamed from src/assets/fonts/ComicNeue-Regular.ttf)bin54848 -> 54848 bytes
-rw-r--r--examples/assets/meshes/cube.obj (renamed from src/assets/meshes/cube.obj)0
-rw-r--r--examples/assets/scenes/fox.glb (renamed from src/assets/scenes/fox.glb)bin162852 -> 162852 bytes
-rw-r--r--examples/assets/textures/test.png (renamed from src/assets/textures/test.png)bin125 -> 125 bytes
-rw-r--r--examples/fox.rs72
-rw-r--r--flake.nix25
-rw-r--r--index.css54
-rw-r--r--index.html24
-rw-r--r--src/lib.rs74
-rw-r--r--src/main.rs8
-rw-r--r--src/scene.rs7
13 files changed, 98 insertions, 178 deletions
diff --git a/Cargo.lock b/Cargo.lock
index d2c408f..e2d1d2c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -160,6 +160,12 @@ dependencies = [
]
[[package]]
+name = "anyhow"
+version = "1.0.97"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f"
+
+[[package]]
name = "arrayref"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2450,6 +2456,7 @@ dependencies = [
name = "teleia"
version = "0.1.0"
dependencies = [
+ "anyhow",
"bimap",
"bitflags 2.6.0",
"bytes",
diff --git a/Cargo.toml b/Cargo.toml
index 8998a11..25be8fd 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,10 +7,6 @@ edition = "2021"
[lib]
crate-type = ["cdylib", "rlib"]
-[[bin]]
-name = "tel"
-path = "src/main.rs"
-
[profile.release]
opt-level = 2
codegen-units = 1
@@ -35,6 +31,7 @@ bimap = "*" # bijective maps
reqwest = "*" # http requests
bytes = "*" # bytes for http responses
bitflags = "*" # bitwise flags
+anyhow = "*" # generic error type handling
[target.'cfg(target_arch = "wasm32")'.dependencies]
winit = {version = "=0.29.15", features = ["serde"]} # windowing and events
diff --git a/src/assets/fonts/ComicNeue-Regular.ttf b/examples/assets/fonts/ComicNeue-Regular.ttf
index d454f46..d454f46 100644
--- a/src/assets/fonts/ComicNeue-Regular.ttf
+++ b/examples/assets/fonts/ComicNeue-Regular.ttf
Binary files differ
diff --git a/src/assets/meshes/cube.obj b/examples/assets/meshes/cube.obj
index 2f3a670..2f3a670 100644
--- a/src/assets/meshes/cube.obj
+++ b/examples/assets/meshes/cube.obj
diff --git a/src/assets/scenes/fox.glb b/examples/assets/scenes/fox.glb
index 1ef5c0d..1ef5c0d 100644
--- a/src/assets/scenes/fox.glb
+++ b/examples/assets/scenes/fox.glb
Binary files differ
diff --git a/src/assets/textures/test.png b/examples/assets/textures/test.png
index 0752be0..0752be0 100644
--- a/src/assets/textures/test.png
+++ b/examples/assets/textures/test.png
Binary files differ
diff --git a/examples/fox.rs b/examples/fox.rs
new file mode 100644
index 0000000..33df561
--- /dev/null
+++ b/examples/fox.rs
@@ -0,0 +1,72 @@
+use teleia::*;
+
+use std::ops::Rem;
+
+pub struct TestGame {
+ font: font::Bitmap,
+ tt: font::TrueType,
+ // cube: mesh::Mesh,
+ fox: scene::Scene,
+ tex: texture::Texture,
+ shader: shader::Shader,
+}
+
+impl TestGame {
+ pub async fn new(ctx: &context::Context) -> 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")),
+ tex: texture::Texture::new(ctx, include_bytes!("assets/textures/test.png")),
+ shader: scene::Scene::load_default_shader(ctx),
+ }
+ }
+}
+
+impl state::Game for TestGame {
+ fn update(&mut self, ctx: &context::Context, st: &mut state::State) -> Option<()> {
+ st.move_camera(
+ ctx,
+ &glam::Vec3::new(0.0, 0.0, -1.0),
+ &glam::Vec3::new(0.0, 0.0, 1.0),
+ &glam::Vec3::new(0.0, 1.0, 0.0),
+ );
+ Some(())
+ }
+ fn render(&mut self, ctx: &context::Context, st: &mut state::State) -> Option<()> {
+ // if let Some(n) = self.fox.nodes_by_name.get("J_Bip_C_Neck").and_then(|i| self.fox.nodes.get_mut(*i)) {
+ // 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));
+ st.bind_3d(ctx, &self.shader);
+ self.shader.set_position_3d(
+ ctx,
+ &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::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),
+ ],
+ );
+ Some(())
+ }
+}
+
+#[tokio::main]
+pub async fn main() {
+ run("teleia test", 240, 160, Options::empty(), TestGame::new).await;
+}
diff --git a/flake.nix b/flake.nix
index 0599005..78a8767 100644
--- a/flake.nix
+++ b/flake.nix
@@ -64,23 +64,10 @@
cargoHash = "sha256-ckJxAR20GuVGstzXzIj1M0WBFj5eJjrO2/DRMUK5dwM=";
};
});
- in
- {
- checks = {
- inherit teleia;
- teleia-clippy = craneLib.cargoClippy (commonArgs // {
- inherit cargoArtifacts;
- cargoClippyExtraArgs = "--all-targets -- --deny warnings";
- });
- teleia-fmt = craneLib.cargoFmt {
- inherit src;
- };
- };
-
+ in {
packages.default = teleia;
devShells.default = craneLib.devShell {
- checks = self.checks.${system};
packages = [
pkgs.trunk
pkgs.rust-analyzer
@@ -99,6 +86,16 @@
pkgs.xorg.libxcb
pkgs.libglvnd
];
+ LD_LIBRARY_PATH = "$LD_LIBRARY_PATH:${
+ pkgs.lib.makeLibraryPath [
+ pkgs.xorg.libX11
+ pkgs.xorg.libXcursor
+ pkgs.xorg.libXi
+ pkgs.libxkbcommon
+ pkgs.xorg.libxcb
+ pkgs.libglvnd
+ ]
+ }";
};
});
}
diff --git a/index.css b/index.css
deleted file mode 100644
index c5219bc..0000000
--- a/index.css
+++ /dev/null
@@ -1,54 +0,0 @@
-html {
- /* Remove touch delay: */
- touch-action: manipulation;
-}
-
-body {
- /* Light mode background color for what is not covered by the egui canvas,
- or where the egui canvas is translucent. */
- background: #909090;
-}
-
-@media (prefers-color-scheme: dark) {
- body {
- /* Dark mode background color for what is not covered by the egui canvas,
- or where the egui canvas is translucent. */
- background: #404040;
- }
-}
-
-/* Allow canvas to fill entire web page: */
-html,
-body {
- overflow: hidden;
- margin: 0 !important;
- padding: 0 !important;
- height: 100%;
- width: 100%;
-}
-
-/* Position canvas in center-top: */
-canvas {
- margin-right: auto;
- margin-left: auto;
- display: block;
- position: absolute;
- top: 0%;
- left: 50%;
- transform: translate(-50%, 0%);
-}
-
-.centered {
- margin-right: auto;
- margin-left: auto;
- display: block;
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- color: #f0f0f0;
- font-size: 24px;
- font-family: Ubuntu-Light, Helvetica, sans-serif;
- text-align: center;
- image-transform: pixelated;
-}
diff --git a/index.html b/index.html
deleted file mode 100644
index 84b99ea..0000000
--- a/index.html
+++ /dev/null
@@ -1,24 +0,0 @@
-<!DOCTYPE html>
-<html>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
- <head>
- <meta charset="UTF-8">
- <link data-trunk rel="rust" data-wasm-opt="2" data-target-name="teleia" />
- <base data-trunk-public-url />
- <meta name="theme-color" media="(prefers-color-scheme: light)" content="white">
- <meta name="theme-color" media="(prefers-color-scheme: dark)" content="#404040">
- <link rel="icon" href="data:;base64,iVBORw0KGgo=">
- <link data-trunk rel="css" href="index.css" />
- <title>teleia</title>
- </head>
- <body>
- <script>
- addEventListener("TrunkApplicationStarted", async (event) => {
- console.log("initialized, starting...");
- window.wasmBindings.main_js_test();
- });
- </script>
- <div id="teleia-parent"></canvas>
- </body>
-</html>
diff --git a/src/lib.rs b/src/lib.rs
index 7f60300..e39b474 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -13,8 +13,6 @@ pub mod audio;
pub mod net;
pub mod save;
-use std::ops::Rem;
-
#[cfg(target_arch = "wasm32")]
use winit::platform::web::EventLoopExtWebSys;
@@ -312,75 +310,3 @@ where
});
});
}
-
-#[cfg(target_arch = "wasm32")]
-use wasm_bindgen::prelude::*;
-
-pub struct TestGame {
- font: font::Bitmap,
- tt: font::TrueType,
- // cube: mesh::Mesh,
- fox: scene::Scene,
- tex: texture::Texture,
- shader: shader::Shader,
-}
-
-impl TestGame {
- pub async fn new(ctx: &context::Context) -> 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")),
- tex: texture::Texture::new(ctx, include_bytes!("assets/textures/test.png")),
- shader: shader::Shader::new(ctx, include_str!("assets/shaders/scene/vert.glsl"), include_str!("assets/shaders/scene/frag.glsl")),
- }
- }
-}
-
-impl state::Game for TestGame {
- fn update(&mut self, ctx: &context::Context, st: &mut state::State) -> Option<()> {
- st.move_camera(
- ctx,
- &glam::Vec3::new(0.0, 0.0, -1.0),
- &glam::Vec3::new(0.0, 0.0, 1.0),
- &glam::Vec3::new(0.0, 1.0, 0.0),
- );
- Some(())
- }
- fn render(&mut self, ctx: &context::Context, st: &mut state::State) -> Option<()> {
- // if let Some(n) = self.fox.nodes_by_name.get("J_Bip_C_Neck").and_then(|i| self.fox.nodes.get_mut(*i)) {
- // n.transform *= glam::Mat4::from_rotation_z(0.05);
- // }
- 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,
- &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::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),
- ],
- );
- Some(())
- }
-}
-
-#[cfg(target_arch = "wasm32")]
-#[wasm_bindgen]
-pub async fn main_js_test() {
- run(240, 160, Options::empty(), TestGame::new).await;
-}
diff --git a/src/main.rs b/src/main.rs
deleted file mode 100644
index f7c2a88..0000000
--- a/src/main.rs
+++ /dev/null
@@ -1,8 +0,0 @@
-#[cfg(target_arch = "wasm32")]
-pub fn main() {}
-
-#[cfg(not(target_arch = "wasm32"))]
-#[tokio::main]
-pub async fn main() {
- teleia::run("teleia test", 240, 160, teleia::Options::empty(), teleia::TestGame::new).await;
-}
diff --git a/src/scene.rs b/src/scene.rs
index 9e98936..3146b5d 100644
--- a/src/scene.rs
+++ b/src/scene.rs
@@ -79,6 +79,13 @@ pub struct Scene {
}
impl Scene {
+ pub fn load_default_shader(ctx: &context::Context) -> shader::Shader {
+ shader::Shader::new(
+ ctx,
+ include_str!("assets/shaders/scene/vert.glsl"),
+ include_str!("assets/shaders/scene/frag.glsl")
+ )
+ }
pub fn from_gltf(ctx: &context::Context, bytes: &[u8]) -> Self {
let (gltf, buffers, images) = gltf::import_slice(bytes).expect("failed to parse GLTF");
let get_buffer_data = |b: gltf::Buffer| {