Fixing two warnings for imports and a mut

This commit is contained in:
Lillian Vixe 2024-04-02 17:50:34 -07:00
parent 3dce7650d5
commit 85580c3dc5
4 changed files with 4 additions and 225 deletions

View file

@ -4,6 +4,8 @@
"./Cargo.toml",
"./Cargo.toml",
"./Cargo.toml",
"./Cargo.toml",
"./Cargo.toml",
"./Cargo.toml"
],
"rust-analyzer.cargo.target": "wasm32-unknown-unknown"

View file

@ -4,7 +4,6 @@ use bevy::window::WindowResolution;
use bevy::DefaultPlugins;
mod orbit_camera;
mod vvum;
use vvlib::octtree;
use vvlib::OctTreePlugin;
use vvum::mesh_plugin;
mod vvlib;

View file

@ -1,16 +1,12 @@
#![allow(dead_code)]
use bevy::app::App;
use bevy::app::Last;
use bevy::app::Plugin;
use bevy::app::Update;
use bevy::asset::Asset;
use bevy::asset::AssetServer;
use bevy::asset::Assets;
use bevy::asset::Handle;
use bevy::ecs::component::Component;
use bevy::ecs::system::Query;
use bevy::ecs::system::Res;
use bevy::ecs::system::ResMut;
use bevy::math::Vec3;
use bevy::render::color::Color;
@ -196,7 +192,7 @@ pub fn oct_tree_edit_updater(
impl OctTreeModelComponent {
pub fn new(
model: octtree::OctTree<Color>,
mut mesh_assets: Option<ResMut<Assets<Mesh>>>,
mesh_assets: Option<ResMut<Assets<Mesh>>>,
) -> OctTreeModelComponent {
if mesh_assets.is_some() {
return OctTreeModelComponent {

View file

@ -1,21 +1,11 @@
pub mod mesh_plugin {
use bevy::{
prelude::*,
render::{
mesh::Indices, render_asset::RenderAssetUsages, render_resource::PrimitiveTopology,
},
};
use bevy::prelude::*;
use crate::{
orbit_camera::orbit_camera::*,
vvlib::{octtree::OctTree, OctTreeModelComponent},
};
#[derive(Event)]
pub struct SendMeshEvent {
location: Vec3,
}
pub struct PluginInitializer;
impl Plugin for PluginInitializer {
fn build(&self, app: &mut App) {
@ -24,216 +14,8 @@ pub mod mesh_plugin {
}
}
fn as_mesh(
vertices: Vec<[f32; 3]>,
indices: Vec<u32>,
normals: Vec<[f32; 3]>,
colors: Vec<[f32; 4]>,
) -> Mesh {
Mesh::new(
PrimitiveTopology::TriangleList,
RenderAssetUsages::RENDER_WORLD,
)
.with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, vertices)
.with_inserted_attribute(Mesh::ATTRIBUTE_COLOR, colors)
.with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, normals)
.with_inserted_indices(Indices::U32(indices))
}
fn emit_cube_at(
pos: Vec3,
vertices: &mut Vec<[f32; 3]>,
indices: &mut Vec<u32>,
normals: &mut Vec<[f32; 3]>,
colors: &mut Vec<[f32; 4]>,
color: Color,
render_px: bool,
render_nx: bool,
render_py: bool,
render_ny: bool,
render_pz: bool,
render_nz: bool,
) {
if render_px {
let len = vertices.len() as u32;
vertices.extend([
[pos.x + 0.5, pos.y - 0.5, pos.z - 0.5],
[pos.x + 0.5, pos.y - 0.5, pos.z + 0.5],
[pos.x + 0.5, pos.y + 0.5, pos.z + 0.5],
[pos.x + 0.5, pos.y + 0.5, pos.z - 0.5],
]);
normals.extend([
[1.0, 0.0, 0.0],
[1.0, 0.0, 0.0],
[1.0, 0.0, 0.0],
[1.0, 0.0, 0.0],
]);
colors.extend([
color.as_rgba_f32(),
color.as_rgba_f32(),
color.as_rgba_f32(),
color.as_rgba_f32(),
]);
indices.extend([len, len + 3, len + 1, len + 1, len + 3, len + 2]);
}
if render_nx {
let len = vertices.len() as u32;
vertices.extend([
[pos.x - 0.5, pos.y - 0.5, pos.z - 0.5],
[pos.x - 0.5, pos.y - 0.5, pos.z + 0.5],
[pos.x - 0.5, pos.y + 0.5, pos.z + 0.5],
[pos.x - 0.5, pos.y + 0.5, pos.z - 0.5],
]);
normals.extend([
[-1.0, 0.0, 0.0],
[-1.0, 0.0, 0.0],
[-1.0, 0.0, 0.0],
[-1.0, 0.0, 0.0],
]);
colors.extend([
color.as_rgba_f32(),
color.as_rgba_f32(),
color.as_rgba_f32(),
color.as_rgba_f32(),
]);
indices.extend([len + 2, len + 3, len + 1, len + 1, len + 3, len]);
}
if render_py {
let len = vertices.len() as u32;
vertices.extend([
[pos.x - 0.5, pos.y + 0.5, pos.z - 0.5],
[pos.x + 0.5, pos.y + 0.5, pos.z - 0.5],
[pos.x + 0.5, pos.y + 0.5, pos.z + 0.5],
[pos.x - 0.5, pos.y + 0.5, pos.z + 0.5],
]);
normals.extend([
[0.0, 1.0, 0.0],
[0.0, 1.0, 0.0],
[0.0, 1.0, 0.0],
[0.0, 1.0, 0.0],
]);
colors.extend([
color.as_rgba_f32(),
color.as_rgba_f32(),
color.as_rgba_f32(),
color.as_rgba_f32(),
]);
indices.extend([len, len + 3, len + 1, len + 1, len + 3, len + 2]);
}
if render_ny {
let len = vertices.len() as u32;
vertices.extend([
[pos.x - 0.5, pos.y - 0.5, pos.z - 0.5],
[pos.x + 0.5, pos.y - 0.5, pos.z - 0.5],
[pos.x + 0.5, pos.y - 0.5, pos.z + 0.5],
[pos.x - 0.5, pos.y - 0.5, pos.z + 0.5],
]);
normals.extend([
[0.0, -1.0, 0.0],
[0.0, -1.0, 0.0],
[0.0, -1.0, 0.0],
[0.0, -1.0, 0.0],
]);
colors.extend([
color.as_rgba_f32(),
color.as_rgba_f32(),
color.as_rgba_f32(),
color.as_rgba_f32(),
]);
indices.extend([len + 2, len + 3, len + 1, len + 1, len + 3, len]);
}
if render_pz {
let len = vertices.len() as u32;
vertices.extend([
[pos.x - 0.5, pos.y - 0.5, pos.z + 0.5],
[pos.x - 0.5, pos.y + 0.5, pos.z + 0.5],
[pos.x + 0.5, pos.y + 0.5, pos.z + 0.5],
[pos.x + 0.5, pos.y - 0.5, pos.z + 0.5],
]);
normals.extend([
[0.0, 0.0, 1.0],
[0.0, 0.0, 1.0],
[0.0, 0.0, 1.0],
[0.0, 0.0, 1.0],
]);
colors.extend([
color.as_rgba_f32(),
color.as_rgba_f32(),
color.as_rgba_f32(),
color.as_rgba_f32(),
]);
indices.extend([len, len + 3, len + 1, len + 1, len + 3, len + 2]);
}
if render_nz {
let len = vertices.len() as u32;
vertices.extend([
[pos.x - 0.5, pos.y - 0.5, pos.z - 0.5],
[pos.x - 0.5, pos.y + 0.5, pos.z - 0.5],
[pos.x + 0.5, pos.y + 0.5, pos.z - 0.5],
[pos.x + 0.5, pos.y - 0.5, pos.z - 0.5],
]);
normals.extend([
[0.0, 0.0, -1.0],
[0.0, 0.0, -1.0],
[0.0, 0.0, -1.0],
[0.0, 0.0, -1.0],
]);
colors.extend([
color.as_rgba_f32(),
color.as_rgba_f32(),
color.as_rgba_f32(),
color.as_rgba_f32(),
]);
indices.extend([len + 2, len + 3, len + 1, len + 1, len + 3, len]);
}
}
fn listen_send_mesh_event(
mut events: EventReader<SendMeshEvent>,
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
) {
/*
in the send mesh event will be the handle of what we update if it is already present, and the mesh data in an octtree or other voxel format
*/
for ev in events.read() {
let mut vertices = Vec::new();
let mut normals = Vec::new();
let mut indices = Vec::new();
let mut colors: Vec<[f32; 4]> = Vec::new();
emit_cube_at(
ev.location,
&mut vertices,
&mut indices,
&mut normals,
&mut colors,
Color::RED,
true,
true,
true,
true,
true,
true,
);
let test_mesh_handle: Handle<Mesh> =
meshes.add(as_mesh(vertices, indices, normals, colors));
commands.spawn(PbrBundle {
mesh: test_mesh_handle,
..default()
});
}
}
fn setup(mesh_assets: ResMut<Assets<Mesh>>, mut commands: Commands) {
let oct = OctTree::new(Vec3::ZERO, Color::RED);
//commands.spawn(oct);
let mut model_oct = OctTreeModelComponent::new(oct, Some(mesh_assets));
model_oct