diff --git a/index.html b/index.html index e225b8e..d1ad6cd 100644 --- a/index.html +++ b/index.html @@ -17,6 +17,7 @@ bluesky

Bevy Vaporwave

+

You may have to refresh to get the fill to work ¯\_(ツ)_/¯


Github

diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000..39652c8 Binary files /dev/null and b/src/.DS_Store differ diff --git a/src/blender_scripts/.DS_Store b/src/blender_scripts/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/src/blender_scripts/.DS_Store differ diff --git a/src/blender_scripts/assign_unique_indices.py b/src/blender_scripts/assign_unique_indices.py deleted file mode 100644 index e9c9ab9..0000000 --- a/src/blender_scripts/assign_unique_indices.py +++ /dev/null @@ -1,46 +0,0 @@ - -import bpy -import bmesh - -def add_indices(): - selected_objects = bpy.context.selected_objects - - if not selected_objects: - print("No objects selected. Please select at least one object.") - return - - for primitive_idx, obj in enumerate(selected_objects): - if obj.type != 'MESH': - print(f"Skipping {obj.name}: Not a mesh object") - continue - - # Assign primitive index to the object - obj["gltf_primitive_index"] = primitive_idx - - # Create a BMesh from the object data - bm = bmesh.new() - bm.from_mesh(obj.data) - - # Ensure lookup table is up-to-date - bm.verts.ensure_lookup_table() - - # Create a new custom attribute layer for vertex indices - vert_index_layer = bm.verts.layers.int.new('_VERT_INDEX') - - # Iterate through all vertices and assign unique IDs - for idx, v in enumerate(bm.verts): - v[vert_index_layer] = idx - - # Update the mesh with BMesh data - bm.to_mesh(obj.data) - obj.data.update() - - # Free the BMesh - bm.free() - - print(f"Object: {obj.name}") - print(f" Assigned primitive index: {primitive_idx}") - print(f" Added '_VERT_INDEX' attribute to {len(obj.data.vertices)} vertices") - -# Run the function -add_indices() \ No newline at end of file diff --git a/src/blender_scripts/bevy_vaporwabe_blender.py b/src/blender_scripts/bevy_vaporwabe_blender.py deleted file mode 100644 index 895da04..0000000 --- a/src/blender_scripts/bevy_vaporwabe_blender.py +++ /dev/null @@ -1,257 +0,0 @@ -import bpy -import bmesh -import json -from bpy.types import Panel, Operator - -def get_selected_edges(obj): - if obj.type != 'MESH': - return [] - - was_in_edit_mode = (obj.mode == 'EDIT') - if was_in_edit_mode: - bpy.ops.object.mode_set(mode='OBJECT') - - bm = bmesh.new() - bm.from_mesh(obj.data) - - selection = [edge for edge in bm.edges if edge.select] - result = selection.copy() - - bm.free() - - if was_in_edit_mode: - bpy.ops.object.mode_set(mode='EDIT') - - return result - -def add_to_visible_edges(obj): - if obj.type != 'MESH': - return - - was_in_edit_mode = (obj.mode == 'EDIT') - if was_in_edit_mode: - bpy.ops.object.mode_set(mode='OBJECT') - - # Create BMesh from the object - bm = bmesh.new() - bm.from_mesh(obj.data) - - # Get or create the '_VISIBLE_EDGE' layer - visible_layer = bm.edges.layers.int.get('_VISIBLE_EDGE') - if visible_layer is None: - visible_layer = bm.edges.layers.int.new('_VISIBLE_EDGE') - - selected_edges = [edge for edge in bm.edges if edge.select] - for edge in selected_edges: - edge[visible_layer] = 1 - edge.smooth = False # Mark edge as sharp - - # Update the mesh - bm.to_mesh(obj.data) - bm.free() - - if was_in_edit_mode: - bpy.ops.object.mode_set(mode='EDIT') - -def remove_from_visible_edges(obj): - if obj.type != 'MESH': - return - - was_in_edit_mode = (obj.mode == 'EDIT') - if was_in_edit_mode: - bpy.ops.object.mode_set(mode='OBJECT') - - # Create BMesh from the object - bm = bmesh.new() - bm.from_mesh(obj.data) - - # Get or create the '_VISIBLE_EDGE' layer - visible_layer = bm.edges.layers.int.get('_VISIBLE_EDGE') - if visible_layer is None: - visible_layer = bm.edges.layers.int.new('_VISIBLE_EDGE') - - selected_edges = [edge for edge in bm.edges if edge.select] - for edge in selected_edges: - edge[visible_layer] = 0 - edge.smooth = True # Unmark edge as sharp - - # Update the mesh - bm.to_mesh(obj.data) - bm.free() - - if was_in_edit_mode: - bpy.ops.object.mode_set(mode='EDIT') - -def clear_visible_edges(obj): - if obj.type != 'MESH': - return - - was_in_edit_mode = (obj.mode == 'EDIT') - if was_in_edit_mode: - bpy.ops.object.mode_set(mode='OBJECT') - - # Create BMesh from the object - bm = bmesh.new() - bm.from_mesh(obj.data) - - # Get the '_VISIBLE_EDGE' layer, if it exists - visible_layer = bm.edges.layers.int.get('_VISIBLE_EDGE') - if visible_layer is not None: - for edge in bm.edges: - edge[visible_layer] = 0 # Unmark as visible - edge.smooth = True # Unmark edge as sharp - # Optionally, remove the layer - bm.edges.layers.int.remove(visible_layer) - else: - # Even if the layer doesn't exist, ensure edges are unsharp - for edge in bm.edges: - edge.smooth = True - - # Update the mesh - bm.to_mesh(obj.data) - bm.free() - - if was_in_edit_mode: - bpy.ops.object.mode_set(mode='EDIT') - -def get_visible_edges_indices(obj): - if obj.type != 'MESH': - print(f"Skipping {obj.name}: Not a mesh object") - return None - - primitive_index = obj.get("gltf_primitive_index", -1) - - bm = bmesh.new() - bm.from_mesh(obj.data) - bm.verts.ensure_lookup_table() - bm.edges.ensure_lookup_table() - - vert_index_layer = bm.verts.layers.int.get('_VERT_INDEX') - visible_edge_layer = bm.edges.layers.int.get('_VISIBLE_EDGE') - - if vert_index_layer is None: - print(f"Custom vertex index layer not found for {obj.name}") - bm.free() - return None - - if visible_edge_layer is None: - print(f"Visible edge layer not found for {obj.name}") - bm.free() - return None - - visible_edges = [e for e in bm.edges if e[visible_edge_layer] == 1] - - line_list = [] - for edge in visible_edges: - v1, v2 = edge.verts - line_list.append([v1[vert_index_layer], v2[vert_index_layer]]) - - bm.free() - return primitive_index, line_list - -def create_and_store_json_line_list(): - selected_objects = bpy.context.selected_objects - if not selected_objects: - print("No objects selected. Please select at least one object.") - return - - all_visible_edges = {} - - for obj in selected_objects: - result = get_visible_edges_indices(obj) - if result is not None: - primitive_index, line_list = result - if line_list: - all_visible_edges[str(primitive_index)] = line_list - - if all_visible_edges: - json_string = json.dumps(all_visible_edges) - bpy.context.scene["gltf_all_selected_edges"] = json_string - print(f"Stored visible edges data for all objects in the scene") - print(f"JSON data: {json_string}") - else: - print("No visible edges found in any object") - -# Operators -class VIEW3D_OT_add_visible_edges(Operator): - bl_idname = "view3d.add_visible_edges" - bl_label = "Add Visible Edges" - bl_description = "Mark selected edges as visible and sharp" - - def execute(self, context): - for obj in context.selected_objects: - add_to_visible_edges(obj) - return {'FINISHED'} - -class VIEW3D_OT_remove_visible_edges(Operator): - bl_idname = "view3d.remove_visible_edges" - bl_label = "Remove Visible Edges" - bl_description = "Mark selected edges as not visible and unsharp" - - def execute(self, context): - for obj in context.selected_objects: - remove_from_visible_edges(obj) - return {'FINISHED'} - -class VIEW3D_OT_clear_visible_edges(Operator): - bl_idname = "view3d.clear_visible_edges" - bl_label = "Clear All Visible Edges" - bl_description = "Unmark all edges as visible and unsharp in selected objects" - - def execute(self, context): - for obj in context.selected_objects: - clear_visible_edges(obj) - return {'FINISHED'} - -class VIEW3D_OT_generate_edge_json(Operator): - bl_idname = "view3d.generate_edge_json" - bl_label = "Export Edge List" - bl_description = "Generate JSON line list from visible edges" - - def execute(self, context): - create_and_store_json_line_list() - return {'FINISHED'} - -# Panel -class VIEW3D_PT_edge_visibility(Panel): - bl_space_type = 'VIEW_3D' - bl_region_type = 'UI' - bl_category = 'Edge Visibility' - bl_label = "Edge Visibility" - - def draw(self, context): - layout = self.layout - - box = layout.box() - box.label(text="Edge Selection") - row = box.row() - row.operator("view3d.add_visible_edges", text="Add Visible Edges") - row = box.row() - row.operator("view3d.remove_visible_edges", text="Remove Visible Edges") - row = box.row() - row.operator("view3d.clear_visible_edges", text="Clear All Visible Edges") - - box = layout.box() - box.label(text="Export") - row = box.row() - row.operator("view3d.generate_edge_json", text="Export Edge List") - -# Registration -classes = ( - VIEW3D_OT_add_visible_edges, - VIEW3D_OT_remove_visible_edges, - VIEW3D_OT_clear_visible_edges, - VIEW3D_OT_generate_edge_json, - VIEW3D_PT_edge_visibility -) - -def register(): - for cls in classes: - bpy.utils.register_class(cls) - -def unregister(): - for cls in classes: - bpy.utils.unregister_class(cls) - -if __name__ == "__main__": - register() diff --git a/src/blender_scripts/new.py b/src/blender_scripts/bevy_vaporwave_blender_scripts.py similarity index 100% rename from src/blender_scripts/new.py rename to src/blender_scripts/bevy_vaporwave_blender_scripts.py diff --git a/src/blender_scripts/old/create_json_line_list.py b/src/blender_scripts/old/create_json_line_list.py deleted file mode 100644 index 32d1737..0000000 --- a/src/blender_scripts/old/create_json_line_list.py +++ /dev/null @@ -1,62 +0,0 @@ -import bpy -import bmesh -import json - -def get_selected_edges_indices(obj): - if obj.type != 'MESH': - print(f"Skipping {obj.name}: Not a mesh object") - return None - - primitive_index = obj.get("gltf_primitive_index", -1) - - bm = bmesh.new() - bm.from_mesh(obj.data) - - bm.verts.ensure_lookup_table() - bm.edges.ensure_lookup_table() - - vert_index_layer = bm.verts.layers.int.get('_VERT_INDEX') - - if vert_index_layer is None: - print(f"Custom vertex index layer not found for {obj.name}. Please run the index assignment script first.") - bm.free() - return None - - selected_edges = [e for e in bm.edges if e.select] - - line_list = [] - for edge in selected_edges: - v1, v2 = edge.verts - line_list.append([v1[vert_index_layer], v2[vert_index_layer]]) - - bm.free() - return primitive_index, line_list - -def create_and_store_json_line_list(): - selected_objects = bpy.context.selected_objects - - if not selected_objects: - print("No objects selected. Please select at least one object.") - return - - all_selected_edges = {} - - for obj in selected_objects: - result = get_selected_edges_indices(obj) - if result is not None: - primitive_index, line_list = result - if line_list: # Only add if there are selected edges - all_selected_edges[str(primitive_index)] = line_list - - if all_selected_edges: - json_string = json.dumps(all_selected_edges) - - # Store the JSON string as a custom property on the scene - bpy.context.scene["gltf_all_selected_edges"] = json_string - - print(f"Stored selected edges data for all objects in the scene") - else: - print("No selected edges found in any object") - -# Run the function -create_and_store_json_line_list() \ No newline at end of file diff --git a/src/blender_scripts/old/edge_selection.py b/src/blender_scripts/old/edge_selection.py deleted file mode 100644 index eea1bc5..0000000 --- a/src/blender_scripts/old/edge_selection.py +++ /dev/null @@ -1,134 +0,0 @@ -# Add or subtract selected edges to / from an edge attribute called _VISIBLE_EDGES - - -import bpy -import bmesh -from bpy.types import Panel, Operator - -def get_selected_edges(obj): - if obj.type != 'MESH': - return [] - - was_in_edit_mode = (obj.mode == 'EDIT') - if was_in_edit_mode: - bpy.ops.object.mode_set(mode='OBJECT') - - bm = bmesh.new() - bm.from_mesh(obj.data) - - selection = [edge for edge in bm.edges if edge.select] - - # Important: Return the selection before cleaning up - result = selection.copy() # Make a copy of the selection - - bm.free() - - if was_in_edit_mode: - bpy.ops.object.mode_set(mode='EDIT') - - return result - -def add_to_visible_edges(obj): - if obj.type != 'MESH': - return - - was_in_edit_mode = (obj.mode == 'EDIT') - if was_in_edit_mode: - bpy.ops.object.mode_set(mode='OBJECT') - - bm = bmesh.new() - bm.from_mesh(obj.data) - - visible_layer = bm.edges.layers.int.get('_VISIBLE_EDGE') - if visible_layer is None: - visible_layer = bm.edges.layers.int.new('_VISIBLE_EDGE') - - selected_edges = [edge for edge in bm.edges if edge.select] - for edge in selected_edges: - edge[visible_layer] = 1 - - bm.to_mesh(obj.data) - bm.free() - - if was_in_edit_mode: - bpy.ops.object.mode_set(mode='EDIT') - -def remove_from_visible_edges(obj): - if obj.type != 'MESH': - return - - was_in_edit_mode = (obj.mode == 'EDIT') - if was_in_edit_mode: - bpy.ops.object.mode_set(mode='OBJECT') - - bm = bmesh.new() - bm.from_mesh(obj.data) - - visible_layer = bm.edges.layers.int.get('_VISIBLE_EDGE') - if visible_layer is None: - visible_layer = bm.edges.layers.int.new('_VISIBLE_EDGE') - - selected_edges = [edge for edge in bm.edges if edge.select] - for edge in selected_edges: - edge[visible_layer] = 0 - - bm.to_mesh(obj.data) - bm.free() - - if was_in_edit_mode: - bpy.ops.object.mode_set(mode='EDIT') - -# Operators -class VIEW3D_OT_add_visible_edges(Operator): - bl_idname = "view3d.add_visible_edges" - bl_label = "Add Visible Edges" - bl_description = "Mark selected edges as visible" - - def execute(self, context): - for obj in context.selected_objects: - add_to_visible_edges(obj) - return {'FINISHED'} - -class VIEW3D_OT_remove_visible_edges(Operator): - bl_idname = "view3d.remove_visible_edges" - bl_label = "Remove Visible Edges" - bl_description = "Mark selected edges as not visible" - - def execute(self, context): - for obj in context.selected_objects: - remove_from_visible_edges(obj) - return {'FINISHED'} - -# Panel -class VIEW3D_PT_edge_visibility(Panel): - bl_space_type = 'VIEW_3D' - bl_region_type = 'UI' - bl_category = 'Edge Visibility' - bl_label = "Edge Visibility" - - def draw(self, context): - layout = self.layout - - row = layout.row() - row.operator("view3d.add_visible_edges", text="Add Visible Edges") - - row = layout.row() - row.operator("view3d.remove_visible_edges", text="Remove Visible Edges") - -# Registration -classes = ( - VIEW3D_OT_add_visible_edges, - VIEW3D_OT_remove_visible_edges, - VIEW3D_PT_edge_visibility -) - -def register(): - for cls in classes: - bpy.utils.register_class(cls) - -def unregister(): - for cls in classes: - bpy.utils.unregister_class(cls) - -if __name__ == "__main__": - register() \ No newline at end of file diff --git a/src/blender_scripts/old/json_from_visible_edges_attribute.py b/src/blender_scripts/old/json_from_visible_edges_attribute.py deleted file mode 100644 index 17b5c65..0000000 --- a/src/blender_scripts/old/json_from_visible_edges_attribute.py +++ /dev/null @@ -1,75 +0,0 @@ -## Generate json line list from "_VISIBLE_EDGES" edge attribute - -import bpy -import bmesh -import json - -def get_visible_edges_indices(obj): - if obj.type != 'MESH': - print(f"Skipping {obj.name}: Not a mesh object") - return None - - primitive_index = obj.get("gltf_primitive_index", -1) - - # Create BMesh - bm = bmesh.new() - bm.from_mesh(obj.data) - - bm.verts.ensure_lookup_table() - bm.edges.ensure_lookup_table() - - # Get the custom vertex indices and visible edges layers - vert_index_layer = bm.verts.layers.int.get('_VERT_INDEX') - visible_edge_layer = bm.edges.layers.int.get('_VISIBLE_EDGE') - - if vert_index_layer is None: - print(f"Custom vertex index layer not found for {obj.name}") - bm.free() - return None - - if visible_edge_layer is None: - print(f"Visible edge layer not found for {obj.name}") - bm.free() - return None - - # Get edges marked as visible - visible_edges = [e for e in bm.edges if e[visible_edge_layer] == 1] - - # Create line list from visible edges - line_list = [] - for edge in visible_edges: - v1, v2 = edge.verts - line_list.append([v1[vert_index_layer], v2[vert_index_layer]]) - - bm.free() - return primitive_index, line_list - -def create_and_store_json_line_list(): - selected_objects = bpy.context.selected_objects - - if not selected_objects: - print("No objects selected. Please select at least one object.") - return - - all_visible_edges = {} - - for obj in selected_objects: - result = get_visible_edges_indices(obj) - if result is not None: - primitive_index, line_list = result - if line_list: # Only add if there are visible edges - all_visible_edges[str(primitive_index)] = line_list - - if all_visible_edges: - json_string = json.dumps(all_visible_edges) - - # Store the JSON string as a custom property on the scene - bpy.context.scene["gltf_all_selected_edges"] = json_string - - print(f"Stored visible edges data for all objects in the scene") - print(f"JSON data: {json_string}") - else: - print("No visible edges found in any object") - -# Run the function -create_and_store_json_line_list() \ No newline at end of file diff --git a/src/blender_scripts/old/renove_attributes.py b/src/blender_scripts/old/renove_attributes.py deleted file mode 100644 index 7a8d55a..0000000 --- a/src/blender_scripts/old/renove_attributes.py +++ /dev/null @@ -1,46 +0,0 @@ -import bpy -import bmesh - -def remove_vertex_attribute(attribute_name): - selected_objects = bpy.context.selected_objects - - if not selected_objects: - print("No objects selected. Please select at least one object.") - return - - for obj in selected_objects: - if obj.type != 'MESH': - print(f"Skipping {obj.name}: Not a mesh object") - continue - - # Create a BMesh from the object data - bm = bmesh.new() - bm.from_mesh(obj.data) - - # Ensure lookup table is up-to-date - bm.verts.ensure_lookup_table() - - # Check if the attribute exists - if attribute_name in bm.verts.layers.int: - bm.verts.layers.int.remove(bm.verts.layers.int[attribute_name]) - print(f"Removed '{attribute_name}' attribute from {obj.name}") - elif attribute_name in bm.verts.layers.float: - bm.verts.layers.float.remove(bm.verts.layers.float[attribute_name]) - print(f"Removed '{attribute_name}' attribute from {obj.name}") - elif attribute_name in bm.verts.layers.string: - bm.verts.layers.string.remove(bm.verts.layers.string[attribute_name]) - print(f"Removed '{attribute_name}' attribute from {obj.name}") - else: - print(f"Attribute '{attribute_name}' not found in {obj.name}") - - # Update the mesh with BMesh data - bm.to_mesh(obj.data) - obj.data.update() - - # Free the BMesh - bm.free() - -# Example usage: -# Change '_VERT_INDEX' to the name of the attribute you want to remove -attribute_to_remove = '_INDEX' -remove_vertex_attribute(attribute_to_remove) \ No newline at end of file diff --git a/src/main_copy.rs b/src/main_copy.rs deleted file mode 100644 index bb6cd21..0000000 --- a/src/main_copy.rs +++ /dev/null @@ -1,517 +0,0 @@ -use line_material::{ - generate_edge_line_list_data, generate_edge_line_list_indices, IndexLineList, IntEdge, - LineMaterial, -}; -use mesh_ops::{random_color_mesh, smooth_normals}; -use std::time::Duration; - -use bevy::{ - animation::animate_targets, ecs::query, prelude::*, render::{ - mesh::VertexAttributeValues, render_asset::RenderAssetUsages, - render_resource::VertexFormat, renderer::RenderDevice, - }, scene::SceneInstanceReady, text::scale_value, utils::HashSet -}; -use fill_material::FillMaterial; -use outline_material::OutlineMaterial; - -use bevy::prelude::*; -use bevy::render::render_resource::{Buffer, BufferInitDescriptor, BufferUsages}; - -mod camera_plugin; -mod fill_material; -mod line_material; -mod mesh_ops; -mod outline_material; - -const PATH: &str = "astro/scene.gltf"; -// const PATH: &str = "sphere_flat.gltf"; - -fn main() { - App::new() - .insert_resource(AmbientLight { - color: Color::WHITE, - brightness: 2000., - }) - .add_plugins(DefaultPlugins) - .add_plugins(camera_plugin::CamPlugin) - .add_plugins(MaterialPlugin::::default()) - .add_plugins(MaterialPlugin::::default()) - .add_plugins(MaterialPlugin::::default()) - .add_systems(Startup, setup) - // .add_systems(Update, play_animation_once_loaded.before(animate_targets)) - .add_systems(Update, process_scene) - .add_systems(Update, mesh_added) - .run(); -} - -#[derive(Resource)] -struct Animations { - animations: Vec, - #[allow(dead_code)] - graph: Handle, -} - -fn setup( - mut commands: Commands, - asset_server: Res, - mut graphs: ResMut>, -) { - // // Build the animation graph - // let mut graph = AnimationGraph::new(); - // let animations = graph - // .add_clips( - // [ - // // GltfAssetLabel::Animation(2).from_asset(PATH), - // // GltfAssetLabel::Animation(1).from_asset(PATH), - // GltfAssetLabel::Animation(0).from_asset(PATH), - // ] - // .into_iter() - // .map(|path| asset_server.load(path)), - // 1.0, - // graph.root, - // ) - // .collect(); - - // // Insert a resource with the current scene information - // let graph = graphs.add(graph); - // commands.insert_resource(Animations { - // animations, - // graph: graph.clone(), - // }); - - // Character - commands.spawn(SceneBundle { - scene: asset_server.load(GltfAssetLabel::Scene(0).from_asset(PATH)), - transform: Transform::from_xyz(0.0, 0.3, 0.0), - ..default() - }); -} - -// Once the scene is loaded, start the animation -fn play_animation_once_loaded( - mut commands: Commands, - animations: Res, - mut players: Query<(Entity, &mut AnimationPlayer), Added>, -) { - for (entity, mut player) in &mut players { - println!("animation player added"); - let mut transitions = AnimationTransitions::new(); - - // Make sure to start the animation via the `AnimationTransitions` - // component. The `AnimationTransitions` component wants to manage all - // the animations and will get confused if the animations are started - // directly via the `AnimationPlayer`. - transitions - .play(&mut player, animations.animations[0], Duration::ZERO) - .repeat(); - - commands - .entity(entity) - .insert(animations.graph.clone()) - .insert(transitions); - } -} - - -fn mesh_added(mut commands: Commands, mut meshes: ResMut>, query: Query<(Entity, &Handle), Added>>) { - for (entity, mesh_handle) in query.iter() { - if let Some(mesh) = meshes.get_mut(mesh_handle) { - mesh_to_wireframe(mesh); - } - } -} - - -fn process_scene( - mut commands: Commands, - mut ready_events: EventReader, - query: Query<(&Children, Option<&Handle>)>, - mut meshes: ResMut>, -) { - for scene in ready_events.read() { - println!("a"); - let root_entity = scene.parent; - process_entity_recursive(root_entity, &query, &mut meshes); - } -} - -fn process_entity_recursive( - entity: Entity, - query: &Query<(&Children, Option<&Handle>)>, - meshes: &mut Assets, -) { - // println!("Processing entity: {:?}", entity); - - if let Ok((children, mesh_handle)) = query.get(entity) { - // println!("Entity has {} children", children.len()); - - match mesh_handle { - Some(_) => println!("Entity has a mesh handle"), - None => (), - // None => println!("Entity does not have a mesh handle"), - } - - // If this entity has a mesh, modify it - if let Some(mesh_handle) = mesh_handle { - println!("Attempting to get mesh from handle"); - if let Some(mesh) = meshes.get_mut(mesh_handle) { - println!("Successfully retrieved mesh, modifying..."); - mesh_to_wireframe(mesh); - } else { - println!("Failed to retrieve mesh from handle"); - } - } - - // Recursively process children - for &child in children.iter() { - process_entity_recursive(child, query, meshes); - } - } else { - // println!("Failed to get components for entity: {:?}", entity); - } -} - -fn mesh_to_wireframe(mesh: &mut Mesh) { - - random_color_mesh(mesh); - - let lines = generate_edge_line_list_data(mesh); - - let mut line_mesh = Mesh::new(bevy::render::render_resource::PrimitiveTopology::LineList, RenderAssetUsages::RENDER_WORLD); - - let positions: Vec<[f32; 3]> = lines - .lines - .iter() - .flat_map(|(start, end)| vec![start.position, end.position]) - .collect(); - - let colors: Vec<[f32; 4]> = lines - .lines - .iter() - .flat_map(|(start, end)| vec![start.color, end.color]) - .flatten() - .collect(); - - let normal: Vec<[f32; 3]> = lines - .lines - .iter() - .flat_map(|(start, end)| vec![start.normal, end.normal]) - .flatten() - .collect(); - - let joint_indices: Vec<[u16; 4]> = lines - .lines - .iter() - .flat_map(|(start, end)| vec![start.joint_indices, end.joint_indices]) - .flatten() - .collect(); - - let joint_weights: Vec<[f32; 4]> = lines - .lines - .iter() - .flat_map(|(start, end)| vec![start.joint_weights, end.joint_weights]) - .flatten() - .collect(); - - let joint_indices_count = joint_indices.len(); - let joint_weights_count = joint_weights.len(); - - println!("{} {}", joint_indices_count, joint_weights_count); - - assert_eq!( - joint_indices_count, joint_weights_count, - "Joint indices and weights must have the same length" - ); - - line_mesh.insert_attribute(Mesh::ATTRIBUTE_POSITION, positions); - line_mesh.insert_attribute(Mesh::ATTRIBUTE_COLOR, colors); - line_mesh.insert_attribute(Mesh::ATTRIBUTE_NORMAL, normal); - line_mesh.insert_attribute(Mesh::ATTRIBUTE_JOINT_INDEX,VertexAttributeValues::Uint16x4(joint_indices)); - line_mesh.insert_attribute(Mesh::ATTRIBUTE_JOINT_WEIGHT, joint_weights); - - *mesh = line_mesh; - -} - -// fn process_scene( -// mut commands: Commands, -// mut scene_spawner: ResMut, -// scene_handles: Res>, -// // query: Query<(Entity, &Handle)>, -// // query: Query<(Entity, &Handle), Added>>, -// query: Query< -// ( -// Entity, -// &Handle, -// // &Handle, -// // &Handle, -// // &GlobalTransform, -// ), -// // Added>, -// >, -// ) { - - -// for (entity, scene_handle ) in query.iter() { -// println!("a"); -// if let Some(scene) = scene_handles.get(scene_handle){ -// println!("b"); -// } -// } - -// // for (entity, scene_handle) in query.iter() { -// // println!("a"); -// // if let Some(scene) = scene_handles.get(scene_handle) { -// // println!("b"); -// // println!("entity: {:?}, scene: {:?}", entity, scene_handle); - -// // // // Iterate through the entities and components of the scene -// // // for entity in &scene.entities { -// // // println!("Entity in scene: {:?}", entity); - -// // // // If you want to modify or add components, you can use the entity from the scene -// // // // Example: commands.entity(*entity).insert(SomeComponent { ... }); -// // // } -// // } - -// // // Optionally, despawn the original entity if it's no longer needed -// // // commands.entity(entity).despawn(); -// // } -// } - -// fn process_scene( -// // mut world: World, -// mut commands: Commands, -// mut meshes: ResMut>, -// mut line_materials: ResMut>, -// mut standard_materials: ResMut>, -// query: Query< -// ( -// Entity, -// &Handle, -// &Handle, -// &GlobalTransform, -// &Handle -// ), -// Added>, -// >, -// ) { -// for (entity, _material_handle, mesh_handle, global_transform, scene) in query.iter() { -// if let Some(mesh) = meshes.get_mut(mesh_handle) { - -// println!("1"); - -// let line_material = line_materials.add(LineMaterial {}); - -// random_color_mesh(mesh); - -// // VertexAttributeValues::Float32x3(Mesh::ATTRIBUTE_POSITION); - -// // let index_line_list: IndexLineList = generate_edge_line_list_indices(mesh); - -// let lines = generate_edge_line_list_data(mesh); - -// println!("{} lines", lines.lines.len()); - -// let mut line_mesh = Mesh::new( -// bevy::render::render_resource::PrimitiveTopology::LineList, -// RenderAssetUsages::RENDER_WORLD, -// ); - -// let positions: Vec<[f32; 3]> = lines -// .lines -// .iter() -// .flat_map(|(start, end)| vec![start.position, end.position]) -// .collect(); - -// let colors: Vec<[f32; 4]> = lines -// .lines -// .iter() -// .flat_map(|(start, end)| vec![start.color, end.color]) -// .flatten() -// .collect(); - -// let normal: Vec<[f32; 3]> = lines -// .lines -// .iter() -// .flat_map(|(start, end)| vec![start.normal, end.normal]) -// .flatten() -// .collect(); - -// let joint_indices: Vec<[u16; 4]> = lines -// .lines -// .iter() -// .flat_map(|(start, end)| vec![start.joint_indices, end.joint_indices]) -// .flatten() -// .collect(); - -// let joint_weights: Vec<[f32; 4]> = lines -// .lines -// .iter() -// .flat_map(|(start, end)| vec![start.joint_weights, end.joint_weights]) -// .flatten() -// .collect(); - -// let joint_indices_count = joint_indices.len(); -// let joint_weights_count = joint_weights.len(); - -// println!("{} {}", joint_indices_count, joint_weights_count); - -// assert_eq!( -// joint_indices_count, joint_weights_count, -// "Joint indices and weights must have the same length" -// ); - -// line_mesh.insert_attribute(Mesh::ATTRIBUTE_POSITION, positions); -// line_mesh.insert_attribute(Mesh::ATTRIBUTE_COLOR, colors); -// line_mesh.insert_attribute(Mesh::ATTRIBUTE_NORMAL, normal); -// // line_mesh.insert_attribute(Mesh::ATTRIBUTE_JOINT_INDEX,VertexAttributeValues::Uint16x4(joint_indices)); -// line_mesh.insert_attribute(Mesh::ATTRIBUTE_JOINT_WEIGHT, joint_weights); - -// let line_mesh_handle = meshes.add(line_mesh); - -// // commands.entity(entity).with_children(|parent| { -// // parent.spawn(MaterialMeshBundle { -// // mesh: line_mesh_handle, -// // // material: line_material, -// // material: standard_materials.add(StandardMaterial::default()), -// // transform: Transform::from_matrix(global_transform.compute_matrix()) -// // .with_scale(Vec3::splat(10.)), -// // ..default() -// // }); -// // }); - -// commands.entity(entity).remove::>(); -// } -// } -// } - -// fn process_scene_old( -// mut commands: Commands, -// mut meshes: ResMut>, -// mut fill_materials: ResMut>, -// mut outline_materials: ResMut>, -// mut standard_materials: ResMut>, -// mut line_materials: ResMut>, -// query: Query< -// ( -// Entity, -// &Handle, -// &Handle, -// &GlobalTransform, -// ), -// Added>, -// >, -// ) { -// for (entity, _material_handle, mesh_handle, global_transform) in query.iter() { -// if let Some(mesh) = meshes.get_mut(mesh_handle) { -// random_color_mesh(mesh); -// smooth_normals(mesh); - -// // Create new materials -// let fill_material = fill_materials.add(FillMaterial { -// color: Vec4::new(0.0, 0.0, 0.0, 1.0), -// displacement: 10.0, -// }); - -// let outline_material = outline_materials.add(OutlineMaterial { -// flat_color: Vec4::new(0.0, 1.0, 1.0, 1.0), -// outline_width: 0.1, -// ..default() -// }); - -// let line_material = line_materials.add(LineMaterial {}); -// let line_list = generate_edge_line_list(mesh); - -// // let positions: Vec<[f32; 3]> = lines -// // .lines -// // .iter() -// // .flat_map(|(start, end)| vec![start.position.to_array(), end.position.to_array()]) -// // .collect(); - -// let colors: Vec<[f32; 4]> = line_list -// .lines -// .iter() -// .flat_map(|(start, end)| vec![start.color.to_array(), end.color.to_array()]) -// .collect(); - -// let mut line_mesh = Mesh::new( -// bevy::render::render_resource::PrimitiveTopology::LineList, -// RenderAssetUsages::RENDER_WORLD, -// ); - -// let positions: &VertexAttributeValues = -// mesh.attribute(Mesh::ATTRIBUTE_POSITION).unwrap(); - -// if let (Some(VertexAttributeValues::Float32x3(pp)),) = -// (mesh.attribute(Mesh::ATTRIBUTE_POSITION),) -// { -// let mut set = HashSet::new(); -// for line in line_list.lines { -// let print_it = |p1: [f32; 3], p2: [f32; 3]| { -// println!( -// "{}:{}:{} -> {}:{}:{}", -// p1[0], p1[1], p1[2], p2[0], p2[1], p2[2] -// ); -// }; - -// let edge: IntEdge = if line.0.index < line.1.index { -// IntEdge::new_from_floats( -// pp[line.0.index as usize], -// pp[line.1.index as usize], -// ) -// } else { -// IntEdge::new_from_floats( -// pp[line.1.index as usize], -// pp[line.0.index as usize], -// ) -// }; - -// set.insert(edge); - -// print_it(pp[line.0.index as usize], pp[line.1.index as usize]) -// } - -// println!("Unique lines: {}", set.len()); -// } - -// line_mesh.insert_attribute(Mesh::ATTRIBUTE_POSITION, positions.clone()); -// // line_mesh.insert_attribute(Mesh::ATTRIBUTE_COLOR, colors); -// let line_mesh_handle = meshes.add(line_mesh); - -// commands.entity(entity).with_children(|parent| { -// parent.spawn(MaterialMeshBundle { -// mesh: line_mesh_handle, -// material: line_material, -// transform: Transform::from_matrix(global_transform.compute_matrix()), // .with_scale(Vec3::splat(10.)) -// ..default() -// }); -// }); - -// // Remove the StandardMaterial component -// commands.entity(entity).remove::>(); - -// // // Add the new material components to the original mesh -// // commands -// // .entity(entity) -// // .insert(fill_material) -// // .insert(outline_material); -// } -// } -// } - -// fn count_unique_lines(line_list: &LineList, ps: &VertexAttributeValues) -> usize { - -// let p = VertexAttributeValues::Float32x3(ps); - -// let mut set = HashSet::new(); -// for line in line_list.lines.iter() { -// let edge = if line.0.index < line.1.index { -// (p[line.0.index as usize], p[line.1.index as usize]) -// } else { -// (p[line.1.index as usize], p[line.0.index as usize]) -// }; -// set.insert(edge); -// } -// set.len() -// }