3d done
This commit is contained in:
10
.gitignore
vendored
10
.gitignore
vendored
@@ -14,4 +14,12 @@ target/
|
|||||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/.direnv
|
||||||
|
|
||||||
|
|
||||||
|
# Added by cargo
|
||||||
|
|
||||||
|
/target
|
||||||
|
|
||||||
|
# nixos
|
||||||
|
.direnv
|
||||||
|
|||||||
4911
Cargo.lock
generated
Normal file
4911
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
7
Cargo.toml
Normal file
7
Cargo.toml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
[package]
|
||||||
|
name = "among-me"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
bevy = "0.15.3"
|
||||||
48
flake.lock
generated
Normal file
48
flake.lock
generated
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1743583204,
|
||||||
|
"narHash": "sha256-F7n4+KOIfWrwoQjXrL2wD9RhFYLs2/GGe/MQY1sSdlE=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "2c8d3f48d33929642c1c12cd243df4cc7d2ce434",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": "nixpkgs",
|
||||||
|
"rust-overlay": "rust-overlay"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"rust-overlay": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": [
|
||||||
|
"nixpkgs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1743820323,
|
||||||
|
"narHash": "sha256-UXxJogXhPhBFaX4uxmMudcD/x3sEGFtoSc4busTcftY=",
|
||||||
|
"owner": "oxalica",
|
||||||
|
"repo": "rust-overlay",
|
||||||
|
"rev": "b4734ce867252f92cdc7d25f8cc3b7cef153e703",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "oxalica",
|
||||||
|
"repo": "rust-overlay",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
58
flake.nix
Normal file
58
flake.nix
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
{
|
||||||
|
description = "A Nix-flake-based Bevy development environment";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
|
rust-overlay = {
|
||||||
|
url = "github:oxalica/rust-overlay";
|
||||||
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = { self, nixpkgs, rust-overlay }:
|
||||||
|
let
|
||||||
|
overlays = [
|
||||||
|
rust-overlay.overlays.default
|
||||||
|
(final: prev: {
|
||||||
|
rustToolchain =
|
||||||
|
let
|
||||||
|
rust = prev.rust-bin;
|
||||||
|
in
|
||||||
|
if builtins.pathExists ./rust-toolchain.toml then
|
||||||
|
rust.fromRustupToolchainFile ./rust-toolchain.toml
|
||||||
|
else if builtins.pathExists ./rust-toolchain then
|
||||||
|
rust.fromRustupToolchainFile ./rust-toolchain
|
||||||
|
else
|
||||||
|
rust.stable.latest.default.override {
|
||||||
|
extensions = [ "rust-src" "rustfmt" ];
|
||||||
|
};
|
||||||
|
})
|
||||||
|
];
|
||||||
|
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
|
||||||
|
forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f {
|
||||||
|
pkgs = import nixpkgs { inherit overlays system; };
|
||||||
|
});
|
||||||
|
in
|
||||||
|
{
|
||||||
|
devShells = forEachSupportedSystem ({ pkgs }: {
|
||||||
|
default = pkgs.mkShell rec {
|
||||||
|
packages = with pkgs; [
|
||||||
|
cargo-deny
|
||||||
|
cargo-edit
|
||||||
|
cargo-watch
|
||||||
|
openssl
|
||||||
|
pkg-config
|
||||||
|
rust-analyzer
|
||||||
|
rustToolchain
|
||||||
|
];
|
||||||
|
# bevy
|
||||||
|
buildInputs = with pkgs; [
|
||||||
|
udev alsa-lib vulkan-loader
|
||||||
|
xorg.libX11 xorg.libXcursor xorg.libXi xorg.libXrandr # To use the x11 feature
|
||||||
|
libxkbcommon wayland # To use the wayland feature
|
||||||
|
];
|
||||||
|
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath buildInputs;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
58
src/main.rs
Normal file
58
src/main.rs
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
//! Illustrates the use of vertex colors.
|
||||||
|
|
||||||
|
use bevy::{prelude::*, render::mesh::VertexAttributeValues};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
App::new()
|
||||||
|
.add_plugins(DefaultPlugins)
|
||||||
|
.add_systems(Startup, setup)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// set up a simple 3D scene
|
||||||
|
fn setup(
|
||||||
|
mut commands: Commands,
|
||||||
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
|
) {
|
||||||
|
// plane
|
||||||
|
commands.spawn((
|
||||||
|
Mesh3d(meshes.add(Plane3d::default().mesh().size(5.0, 5.0))),
|
||||||
|
MeshMaterial3d(materials.add(Color::srgb(0.3, 0.5, 0.3))),
|
||||||
|
));
|
||||||
|
// cube
|
||||||
|
// Assign vertex colors based on vertex positions
|
||||||
|
let mut colorful_cube = Mesh::from(Cuboid::default());
|
||||||
|
if let Some(VertexAttributeValues::Float32x3(positions)) =
|
||||||
|
colorful_cube.attribute(Mesh::ATTRIBUTE_POSITION)
|
||||||
|
{
|
||||||
|
let colors: Vec<[f32; 4]> = positions
|
||||||
|
.iter()
|
||||||
|
.map(|[r, g, b]| [(1. - *r) / 2., (1. - *g) / 2., (1. - *b) / 2., 1.])
|
||||||
|
.collect();
|
||||||
|
colorful_cube.insert_attribute(Mesh::ATTRIBUTE_COLOR, colors);
|
||||||
|
}
|
||||||
|
commands.spawn((
|
||||||
|
Mesh3d(meshes.add(colorful_cube)),
|
||||||
|
// This is the default color, but note that vertex colors are
|
||||||
|
// multiplied by the base color, so you'll likely want this to be
|
||||||
|
// white if using vertex colors.
|
||||||
|
MeshMaterial3d(materials.add(Color::srgb(1., 1., 1.))),
|
||||||
|
Transform::from_xyz(0.0, 0.5, 0.0),
|
||||||
|
));
|
||||||
|
|
||||||
|
// Light
|
||||||
|
commands.spawn((
|
||||||
|
PointLight {
|
||||||
|
shadows_enabled: true,
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
Transform::from_xyz(4.0, 5.0, 4.0).looking_at(Vec3::ZERO, Vec3::Y),
|
||||||
|
));
|
||||||
|
|
||||||
|
// Camera
|
||||||
|
commands.spawn((
|
||||||
|
Camera3d::default(),
|
||||||
|
Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
|
||||||
|
));
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user