bevy init
This commit is contained in:
parent
3d46388478
commit
292f9141ec
11 changed files with 5824 additions and 37 deletions
1
.envrc
Normal file
1
.envrc
Normal file
|
|
@ -0,0 +1 @@
|
|||
use flake
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1 +1,3 @@
|
|||
/target
|
||||
/result
|
||||
.direnv
|
||||
|
|
|
|||
5685
Cargo.lock
generated
5685
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
11
Cargo.toml
11
Cargo.toml
|
|
@ -1,8 +1,3 @@
|
|||
[package]
|
||||
edition = "2024"
|
||||
name = "website"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
axum = "0.8"
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
[workspace]
|
||||
members = ["server", "app"]
|
||||
resolver = "2"
|
||||
|
|
|
|||
24
Dockerfile
24
Dockerfile
|
|
@ -1,15 +1,29 @@
|
|||
FROM rust:1 AS builder
|
||||
WORKDIR /usr/src/website
|
||||
COPY . .
|
||||
RUN cargo install --path .
|
||||
|
||||
RUN rustup target add wasm32-unknown-unknown
|
||||
RUN cargo install wasm-bindgen-cli
|
||||
|
||||
RUN cargo build --release --target wasm32-unknown-unknown -p app
|
||||
|
||||
RUN mkdir -p static && \
|
||||
wasm-bindgen --out-name wasm_example \
|
||||
--out-dir static \
|
||||
--target web \
|
||||
target/wasm32-unknown-unknown/release/app.wasm && \
|
||||
cp web/index.html static/
|
||||
|
||||
RUN cargo build --release -p server
|
||||
|
||||
FROM debian:trixie-slim
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl && rm -rf /var/lib/apt/lists/*
|
||||
COPY --from=builder /usr/local/cargo/bin/website /usr/local/bin/website
|
||||
COPY --from=builder /usr/src/website/target/release/server /usr/local/bin/server
|
||||
COPY --from=builder /usr/src/website/static /app/static
|
||||
|
||||
WORKDIR /app
|
||||
EXPOSE 3000
|
||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
|
||||
CMD curl -f http://localhost:3000/ || exit 1
|
||||
|
||||
CMD ["website"]
|
||||
CMD curl -f http://localhost:3000/health || exit 1
|
||||
|
||||
CMD ["server"]
|
||||
|
|
|
|||
12
app/Cargo.toml
Normal file
12
app/Cargo.toml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
[package]
|
||||
name = "app"
|
||||
edition = "2024"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
bevy = { version = "0.18", default-features = false, features = [
|
||||
"3d",
|
||||
"webgl2",
|
||||
"web",
|
||||
"tonemapping_luts",
|
||||
] }
|
||||
47
app/src/main.rs
Normal file
47
app/src/main.rs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins.set(WindowPlugin {
|
||||
primary_window: Some(Window {
|
||||
fit_canvas_to_parent: true,
|
||||
prevent_default_event_handling: false,
|
||||
canvas: Some("#bevy-canvas".into()),
|
||||
..default()
|
||||
}),
|
||||
..default()
|
||||
}))
|
||||
.add_systems(Startup, setup)
|
||||
.run();
|
||||
}
|
||||
|
||||
fn setup(
|
||||
mut commands: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
commands.spawn((
|
||||
Mesh3d(meshes.add(Circle::new(4.0))),
|
||||
MeshMaterial3d(materials.add(Color::WHITE)),
|
||||
Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
|
||||
));
|
||||
|
||||
commands.spawn((
|
||||
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
|
||||
MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
|
||||
Transform::from_xyz(0.0, 0.5, 0.0),
|
||||
));
|
||||
|
||||
commands.spawn((
|
||||
PointLight {
|
||||
shadows_enabled: true,
|
||||
..default()
|
||||
},
|
||||
Transform::from_xyz(4.0, 8.0, 4.0),
|
||||
));
|
||||
|
||||
commands.spawn((
|
||||
Camera3d::default(),
|
||||
Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
|
||||
));
|
||||
}
|
||||
33
flake.nix
Normal file
33
flake.nix
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
description = "Bevy WASM website";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
rust-overlay = {
|
||||
url = "github:oxalica/rust-overlay";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, rust-overlay, flake-utils, ... }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
overlays = [ (import rust-overlay) ];
|
||||
pkgs = import nixpkgs {
|
||||
inherit system overlays;
|
||||
};
|
||||
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
|
||||
targets = [ "wasm32-unknown-unknown" ];
|
||||
};
|
||||
in
|
||||
{
|
||||
devShells.default = pkgs.mkShell {
|
||||
buildInputs = [
|
||||
rustToolchain
|
||||
pkgs.wasm-bindgen-cli
|
||||
];
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
9
server/Cargo.toml
Normal file
9
server/Cargo.toml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "server"
|
||||
edition = "2024"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
axum = "0.8"
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
tower-http = { version = "0.6", features = ["fs"] }
|
||||
|
|
@ -1,11 +1,12 @@
|
|||
use axum::{Router, routing::get};
|
||||
use tower_http::services::ServeDir;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
// build our application with a single route
|
||||
let app = Router::new().route("/", get(|| async { "Hello, World!" }));
|
||||
let app = Router::new()
|
||||
.route("/health", get(|| async { "OK" }))
|
||||
.fallback_service(ServeDir::new("static"));
|
||||
|
||||
// run our app with hyper, listening globally on port 3000
|
||||
println!("Listening on http://0.0.0.0:3000");
|
||||
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
|
||||
axum::serve(listener, app).await.unwrap();
|
||||
30
web/index.html
Normal file
30
web/index.html
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Bevy App</title>
|
||||
<style>
|
||||
html, body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
background: #1a1a2e;
|
||||
}
|
||||
canvas {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: block;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="bevy-canvas"></canvas>
|
||||
<script type="module">
|
||||
import init from './wasm_example.js';
|
||||
init();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in a new issue