From 85580c3dc53fe1b871fc8b99339283b2b48d30b8 Mon Sep 17 00:00:00 2001 From: adia redmoon Date: Tue, 2 Apr 2024 17:50:34 -0700 Subject: [PATCH] Fixing two warnings for imports and a mut --- .vscode/settings.json | 2 + src/main.rs | 1 - src/vvlib/mod.rs | 6 +- src/vvum.rs | 220 +----------------------------------------- 4 files changed, 4 insertions(+), 225 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 51cec23..7ca7841 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,6 +4,8 @@ "./Cargo.toml", "./Cargo.toml", "./Cargo.toml", + "./Cargo.toml", + "./Cargo.toml", "./Cargo.toml" ], "rust-analyzer.cargo.target": "wasm32-unknown-unknown" diff --git a/src/main.rs b/src/main.rs index c64ea26..605d8b3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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; diff --git a/src/vvlib/mod.rs b/src/vvlib/mod.rs index fc52a9f..3611f21 100644 --- a/src/vvlib/mod.rs +++ b/src/vvlib/mod.rs @@ -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, - mut mesh_assets: Option>>, + mesh_assets: Option>>, ) -> OctTreeModelComponent { if mesh_assets.is_some() { return OctTreeModelComponent { diff --git a/src/vvum.rs b/src/vvum.rs index 21ff591..a8bfe5d 100644 --- a/src/vvum.rs +++ b/src/vvum.rs @@ -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, - 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, - 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, - mut commands: Commands, - mut meshes: ResMut>, - ) { - /* - 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 = - meshes.add(as_mesh(vertices, indices, normals, colors)); - - commands.spawn(PbrBundle { - mesh: test_mesh_handle, - ..default() - }); - } - } - fn setup(mesh_assets: ResMut>, 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