This commit is contained in:
AmadeusWM
2025-04-05 15:49:23 +02:00
parent 748245f84d
commit 9af3c65ee2

View File

@@ -1,58 +1,32 @@
//! Illustrates the use of vertex colors. use bevy::prelude::*;
use blenvy::*;
use bevy::{prelude::*, render::mesh::VertexAttributeValues}; fn main() -> AppExit {
fn main() {
App::new() App::new()
.add_plugins(DefaultPlugins) .add_plugins((DefaultPlugins, BlenvyPlugin::default()))
// We need to register components to make them visible to Blenvy
.register_type::<Player>()
.add_systems(Startup, setup) .add_systems(Startup, setup)
.run(); .run()
} }
/// set up a simple 3D scene #[derive(Component, Reflect)]
fn setup( #[reflect(Component)]
mut commands: Commands, struct Player {
mut meshes: ResMut<Assets<Mesh>>, strength: f32,
mut materials: ResMut<Assets<StandardMaterial>>, perception: f32,
) { endurance: f32,
// plane charisma: f32,
commands.spawn(( intelligence: f32,
Mesh3d(meshes.add(Plane3d::default().mesh().size(5.0, 5.0))), agility: f32,
MeshMaterial3d(materials.add(Color::srgb(0.3, 0.5, 0.3))), luck: f32,
));
// 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 fn setup(mut commands: Commands) {
commands.spawn(( commands.spawn((
PointLight { BlueprintInfo::from_path("levels/World.glb"),
shadows_enabled: true, SpawnBlueprint,
..default() HideUntilReady,
}, GameWorldTag,
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),
)); ));
} }