### Configure Fracture Settings in C# Source: https://context7.com/robertvaradan/voronoishatter/llms.txt Provides examples for creating different fracture presets using the AdaptedVoronoiGeneratorConfig class. ```csharp using Godot; using One.Woolly.VoronoiShatter; public partial class FractureSettings : Node { // Create different fracture presets public static AdaptedVoronoiGeneratorConfig CreateFineShatter() { var config = AdaptedVoronoiGeneratorConfig.New(); config.RandomSeed = (long)GD.Randi(); config.NumSamples = 100; // Many small pieces return config; } public static AdaptedVoronoiGeneratorConfig CreateCoarseShatter() { var config = AdaptedVoronoiGeneratorConfig.New(); config.RandomSeed = (long)GD.Randi(); config.NumSamples = 10; // Few large pieces return config; } public static AdaptedVoronoiGeneratorConfig CreateTexturedShatter(Texture3D noiseTexture) { var config = AdaptedVoronoiGeneratorConfig.New(); config.RandomSeed = (long)GD.Randi(); config.NumSamples = 50; config.Texture = noiseTexture; // Control fracture distribution return config; } // Properties available: // config.RandomSeed: long - RNG seed for sample placement // config.NumSamples: int - Number of fracture sample points // config.Texture: Texture3D - Optional 3D texture for pattern control } ``` -------------------------------- ### Shatter on Collision Example Source: https://context7.com/robertvaradan/voronoishatter/llms.txt Example demonstrating how to shatter a mesh when a collision occurs. ```APIDOC ## _on_body_entered ### Description Callback function that triggers when a physics body enters the collision shape. It shatters a target mesh and adds the fragments as new RigidBody3D nodes to the scene. ### Method N/A (Function within a script) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Create Various Fracture Patterns Source: https://context7.com/robertvaradan/voronoishatter/llms.txt Provides examples of creating different fracture configurations using VoronoiGeneratorConfig. ```gdscript # Example: Create various fracture patterns func create_fine_shatter() -> VoronoiGeneratorConfig: var config = VoronoiGeneratorConfig.new() config.random_seed = randi() config.num_samples = 100 # Many small fragments return config func create_coarse_shatter() -> VoronoiGeneratorConfig: var config = VoronoiGeneratorConfig.new() config.random_seed = randi() config.num_samples = 8 # Few large fragments return config func create_texture_guided_shatter(noise_texture: Texture3D) -> VoronoiGeneratorConfig: var config = VoronoiGeneratorConfig.new() config.random_seed = randi() config.num_samples = 50 config.texture = noise_texture # Concentrate fractures in bright areas return config ``` -------------------------------- ### sample_points Source: https://context7.com/robertvaradan/voronoishatter/llms.txt Generates a set of sample points within a mesh's AABB, either randomly or guided by a 3D texture. ```APIDOC ## Method sample_points ### Description Generates sample points within the mesh's Axis-Aligned Bounding Box (AABB). Points can be generated randomly or based on a 3D texture for controlled distribution. ### Parameters #### Request Body - **mesh** (Mesh) - Required - The target mesh to sample. - **config** (VoronoiGeneratorConfig) - Required - Configuration object containing num_samples, random_seed, and optional texture. ``` -------------------------------- ### Configure and Create Voronoi Geometry (C#) Source: https://github.com/robertvaradan/voronoishatter/blob/master/README.md Instantiate and configure AdaptedVoronoiGeneratorConfig in C#, then retrieve the singleton and use it to create Voronoi geometry from a mesh. ```csharp var voronoiGenerator = Engine.GetSingleton("MyVoronoiGenerator") as AdaptedVoronoiGenerator; var config = AdaptedVoronoiGeneratorConfig.New(); config.RandomSeed = 13240324032; config.NumSamples = 100; List results = voronoiGenerator.CreateFromMesh(myAwesomeMesh, config); ``` -------------------------------- ### Implement FractureController in C# Source: https://context7.com/robertvaradan/voronoishatter/llms.txt Demonstrates how to use AdaptedVoronoiGenerator to shatter a mesh and apply physics to the resulting fragments. ```csharp using Godot; using One.Woolly.VoronoiShatter.CSVoronoiAdapter; using One.Woolly.VoronoiShatter; using System.Collections.Generic; public partial class FractureController : Node3D { private AdaptedVoronoiGenerator _voronoiGenerator; public override void _Ready() { // Create generator instance (loads GDScript automatically) _voronoiGenerator = AdaptedVoronoiGenerator.New(); // Optionally register as singleton Engine.RegisterSingleton("CSharpVoronoiGenerator", _voronoiGenerator.Instance); } public List ShatterMesh(MeshInstance3D targetMesh, int samples = 32) { // Configure generation var config = AdaptedVoronoiGeneratorConfig.New(); config.RandomSeed = GD.Randi(); config.NumSamples = samples; // config.Texture = GD.Load("res://noise.tres"); // Generate fractures List results = _voronoiGenerator.CreateFromMesh(targetMesh, config); // Convert to MeshInstance3D nodes var fragments = new List(); foreach (AdaptedVoronoiMesh voronoiMesh in results) { var fragment = new MeshInstance3D(); fragment.Mesh = voronoiMesh.Mesh; fragment.Position = -voronoiMesh.Position * targetMesh.Scale; fragments.Add(fragment); } return fragments; } // Example: On-demand shattering with physics public void OnImpact(MeshInstance3D target, Vector3 impactPoint, float force) { var fragments = ShatterMesh(target, samples: 40); foreach (var fragment in fragments) { var rigidBody = new RigidBody3D(); rigidBody.AddChild(fragment); // Create convex collision fragment.CreateConvexCollision(true, true); // Reparent collision shape foreach (var child in fragment.GetChildren()) { if (child is StaticBody3D staticBody) { var collisionShape = staticBody.GetChild(0); collisionShape.Reparent(rigidBody); staticBody.QueueFree(); } } AddChild(rigidBody); rigidBody.GlobalPosition = target.GlobalPosition + fragment.Position; // Apply explosion force var direction = (rigidBody.GlobalPosition - impactPoint).Normalized(); rigidBody.ApplyCentralImpulse(direction * force); } target.QueueFree(); } } ``` -------------------------------- ### Configure and Create Voronoi Geometry (GDScript) Source: https://github.com/robertvaradan/voronoishatter/blob/master/README.md Instantiate and configure VoronoiGeneratorConfig in GDScript, then retrieve the singleton and use it to create Voronoi geometry from a mesh. ```gdscript var config = VoronoiGeneratorConfig.new() config.random_seed = 13240324032 config.num_samples = 100 var voronoi_generator = Engine.get_singleton("MyVoronoiGenerator", voronoi_generator) var results = voronoi_generator.create_from_mesh(my_awesome_mesh, config) ... create the meshes and add them as children to the scene, e.g ... ``` -------------------------------- ### Create and Register VoronoiGenerator (C#) Source: https://github.com/robertvaradan/voronoishatter/blob/master/README.md Create an instance of AdaptedVoronoiGenerator in C# and register it as a singleton. This facilitates cross-language scripting. ```csharp var voronoiGenerator = AdaptedVoronoiGenerator.New(); // Creates the object assuming you installed this in your `addons` folder // Similar code for registering the singleton ... ``` -------------------------------- ### Initialize VoronoiGenerator Singleton Source: https://context7.com/robertvaradan/voronoishatter/llms.txt Register the VoronoiGenerator as a singleton to enable programmatic fracture generation. ```gdscript # Initialize VoronoiGenerator as singleton (do this once at startup) func _ready(): var voronoi_generator = VoronoiGenerator.new() Engine.register_singleton("MyVoronoiGenerator", voronoi_generator) add_child(voronoi_generator) # Must be in scene tree for CSG operations ``` -------------------------------- ### Generate Sample Points in GDScript Source: https://context7.com/robertvaradan/voronoishatter/llms.txt Shows how to generate random 3D points within a mesh's bounding box using the VoronoiGenerator. ```gdscript # Generate sample points for visualization or custom processing var voronoi_generator = Engine.get_singleton("MyVoronoiGenerator") as VoronoiGenerator var config = VoronoiGeneratorConfig.new() config.random_seed = 12345 config.num_samples = 25 config.texture = null # Optional Texture3D var mesh = $MyMesh.mesh var sample_points: Array[Vector3] = voronoi_generator.sample_points(mesh, config) # sample_points includes: ``` -------------------------------- ### Visualize Sample Points in Editor Source: https://context7.com/robertvaradan/voronoishatter/llms.txt This snippet visualizes sample points within the AABB (Axis-Aligned Bounding Box) in the editor or for debugging purposes. It adds CSGSphere3D nodes to represent each point. ```gdscript # - num_samples random points within the AABB # - 8 corner points of the AABB (prevents geometry loss) # Visualize sample points in editor/debug for point in sample_points: var marker = CSGSphere3D.new() marker.radius = 0.02 marker.position = point add_child(marker) ``` -------------------------------- ### Sample Points with 3D Texture Source: https://context7.com/robertvaradan/voronoishatter/llms.txt This code demonstrates how to sample points from a mesh using a 3D texture for controlled distribution. Lighter texture values increase the probability of sample placement. ```gdscript # With 3D texture for controlled distribution: # Lighter texture values = higher probability of sample placement config.texture = preload("res://textures/fracture_pattern.tres") var texture_guided_points = voronoi_generator.sample_points(mesh, config) ``` -------------------------------- ### Register VoronoiGenerator as Singleton (GDScript) Source: https://github.com/robertvaradan/voronoishatter/blob/master/README.md Register the VoronoiGenerator as a singleton in GDScript for easy access. This is the recommended way to use the plugin's core functionality. ```gdscript var voronoi_generator = VoronoiWorker.new() Engine.register_singleton("MyVoronoiGenerator", voronoi_generator) ``` -------------------------------- ### Configure VoronoiShatter via GDScript Source: https://context7.com/robertvaradan/voronoishatter/llms.txt Programmatically configure the VoronoiShatter node and trigger fracture generation. ```gdscript # Scene tree setup for editor usage: # - VoronoiShatter (Node3D) # - YourMesh (MeshInstance3D) <- The mesh to shatter # VoronoiShatter node properties: # Materials random_color: bool = true # Assign random colors to fragments (preview mode) inherit_outer_material: bool # Use source mesh's materials on outer surfaces outer_material: StandardMaterial3D # Material for outer/original surfaces inner_material: StandardMaterial3D # Material for inner fracture surfaces # Structure samples: int = 32 # Number of fracture points (1-1024) seed: int = 0 # RNG seed for sample placement cell_scale: float = 1.0 # Scale of generated cell meshes sample_texture: Texture3D # 3D texture for controlled sample distribution # Original Mesh hide_original: bool = true # Hide source mesh after generation delete_existing_fractures: bool = true # Remove previous fractures on regenerate # Example: Configure VoronoiShatter via code var shatter_node = VoronoiShatter.new() shatter_node.samples = 48 shatter_node.seed = 12345 shatter_node.random_color = false shatter_node.inner_material = preload("res://materials/glass_inner.tres") shatter_node.outer_material = preload("res://materials/glass_outer.tres") shatter_node.hide_original = true # Add mesh as child var mesh_instance = MeshInstance3D.new() mesh_instance.mesh = preload("res://models/vase.res") shatter_node.add_child(mesh_instance) add_child(shatter_node) # Trigger fracture generation (in editor, use the button) shatter_node.execute() ``` -------------------------------- ### Process VoronoiMesh Results with Materials Source: https://context7.com/robertvaradan/voronoishatter/llms.txt Processes VoronoiMesh results to create MeshInstance3D fragments and apply materials to their surfaces. ```gdscript # Example: Process VoronoiMesh results with materials func process_fracture_results( results: Array[VoronoiMesh], target: MeshInstance3D, inner_mat: Material, outer_mat: Material ) -> Array[MeshInstance3D]: var fragments: Array[MeshInstance3D] = [] for voronoi_mesh in results: if voronoi_mesh == null: continue var fragment = MeshInstance3D.new() fragment.mesh = voronoi_mesh.mesh fragment.position = -voronoi_mesh.position * target.scale # Surface 0 = inner faces, Surface 1+ = outer faces var surface_count = fragment.mesh.get_surface_count() if inner_mat and surface_count > 0: fragment.mesh.surface_set_material(0, inner_mat) if outer_mat and surface_count > 1: for surface_id in range(1, surface_count): fragment.mesh.surface_set_material(surface_id, outer_mat) fragments.append(fragment) return fragments ``` -------------------------------- ### VoronoiGeneratorConfig - Fracture Configuration Source: https://context7.com/robertvaradan/voronoishatter/llms.txt Configuration object for controlling Voronoi fracture generation. ```APIDOC ## VoronoiGeneratorConfig ### Description Configuration object for controlling Voronoi fracture generation, including sample count, random seed, and optional texture for sample distribution. ### Method N/A (Class definition) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```gdscript var config = VoronoiGeneratorConfig.new() config.random_seed = 42 config.num_samples = 32 config.texture = preload("res://textures/noise_3d.tres") ``` ### Response N/A ### Properties - **random_seed** (int) - Controls the random number generator for sample point placement. - **num_samples** (int) - The number of fracture sample points. More samples result in more fragments and smaller pieces. Fewer than ~6 samples may result in missing geometry. - **texture** (Texture3D, optional) - Controls sample distribution. Lighter areas have a higher probability of samples. Uses rejection-based sampling. ``` -------------------------------- ### create_delauney_tetrahedra Source: https://context7.com/robertvaradan/voronoishatter/llms.txt Converts a point cloud into a Delaunay tetrahedron mesh for Voronoi cell calculation. ```APIDOC ## Method create_delauney_tetrahedra ### Description Converts a provided point cloud into a Delaunay tetrahedron mesh. This is the primary step for calculating Voronoi cell vertices via circumcenter computation. ### Parameters #### Request Body - **points** (Array[Vector3]) - Required - The array of points generated from the sampling process. ### Response #### Success Response (200) - **tetrahedra** (Array[Tetrahedron]) - An array of Tetrahedron objects, each containing vertices and indices. ``` -------------------------------- ### Shatter Mesh Function Source: https://context7.com/robertvaradan/voronoishatter/llms.txt This function takes a MeshInstance3D and shatters it into multiple fragments based on Voronoi generation. ```APIDOC ## shatter_mesh ### Description Shatters a given MeshInstance3D into multiple fragments using Voronoi generation. ### Method N/A (Function within a script) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) - **Array[MeshInstance3D]** - An array of MeshInstance3D nodes representing the shattered fragments. #### Response Example N/A ``` -------------------------------- ### Create Fractures from a Mesh Source: https://context7.com/robertvaradan/voronoishatter/llms.txt Generates fragments from a target mesh using Voronoi generation. Converts VoronoiMesh results into MeshInstance3D nodes. ```gdscript func shatter_mesh(target_mesh: MeshInstance3D) -> Array[MeshInstance3D]: var voronoi_generator = Engine.get_singleton("MyVoronoiGenerator") as VoronoiGenerator # Configure generation parameters var config = VoronoiGeneratorConfig.new() config.random_seed = randi() config.num_samples = 50 config.texture = null # Optional: Texture3D for sample distribution # Generate fracture geometry var results: Array[VoronoiMesh] = voronoi_generator.create_from_mesh(target_mesh, config) # Convert VoronoiMesh results to MeshInstance3D nodes var fragments: Array[MeshInstance3D] = [] for voronoi_mesh in results: var fragment = MeshInstance3D.new() fragment.mesh = voronoi_mesh.mesh fragment.position = -voronoi_mesh.position * target_mesh.scale fragments.append(fragment) return fragments ``` -------------------------------- ### Create Delaunay Tetrahedra from Points Source: https://context7.com/robertvaradan/voronoishatter/llms.txt This low-level API method converts a point cloud into a Delaunay tetrahedron mesh. This mesh is essential for calculating Voronoi cell vertices via circumcenter computation. Ensure you have a VoronoiGenerator singleton available. ```gdscript # Low-level API: Create tetrahedra from points var voronoi_generator = Engine.get_singleton("MyVoronoiGenerator") as VoronoiGenerator # First generate sample points var config = VoronoiGeneratorConfig.new() config.random_seed = 42 config.num_samples = 30 var points: Array[Vector3] = voronoi_generator.sample_points($Mesh.mesh, config) # Create Delaunay tetrahedra from points var tetrahedra: Array[Tetrahedron] = voronoi_generator.create_delauney_tetrahedra(points) # Each Tetrahedron contains: # - vertices: Array[Vector3] - The 4 corner vertices # - indices: Array[int] - Indices into the original points array # Process tetrahedra (e.g., for debugging) for tetra in tetrahedra: var circumcenter: Vector3 = tetra.try_calculate_tetrahedron_circumcenter() if circumcenter != Vector3.INF: # Valid circumcenter - this becomes a Voronoi cell vertex print("Circumcenter at: ", circumcenter) else: # Degenerate tetrahedron (coplanar points) print("Skipping degenerate tetrahedron") ``` -------------------------------- ### Manage VoronoiCollection Rigid Bodies Source: https://context7.com/robertvaradan/voronoishatter/llms.txt Convert static mesh fragments into physics-enabled rigid bodies and apply forces to them. ```gdscript # VoronoiCollection is auto-generated as child of VoronoiShatter after fracturing # Structure after generation: # - VoronoiShatter # - OriginalMesh (MeshInstance3D, hidden) # - Fractured_OriginalMesh_12345 (VoronoiCollection) # - FracturedPiece_1 (MeshInstance3D) # - FracturedPiece_2 (MeshInstance3D) # - ... more fragments # Convert fragments to rigid bodies for physics simulation # In editor: Click "Create Rigid Bodies" button on VoronoiCollection # In code: var collection = $VoronoiShatter/Fractured_Teapot_12345 as VoronoiCollection collection.create_rigid_bodies() # After create_rigid_bodies(), structure becomes: # - Fractured_OriginalMesh_12345 (VoronoiCollection) # - Rigid_FracturedPiece_1 (RigidBody3D) # - FracturedPiece_1 (MeshInstance3D) # - CollisionShape3D # - Rigid_FracturedPiece_2 (RigidBody3D) # - FracturedPiece_2 (MeshInstance3D) # - CollisionShape3D # Example: Apply explosion force to fragments func explode_fragments(collection: VoronoiCollection, origin: Vector3, force: float): for child in collection.get_children(): if child is RigidBody3D: var direction = (child.global_position - origin).normalized() child.apply_central_impulse(direction * force) ``` -------------------------------- ### VoronoiGeneratorConfig Properties Source: https://context7.com/robertvaradan/voronoishatter/llms.txt Defines properties for fracture generation, including random seed, number of samples, and optional texture for sample distribution. ```gdscript # VoronoiGeneratorConfig properties: var config = VoronoiGeneratorConfig.new() # random_seed: int - Controls RNG for sample point placement config.random_seed = 42 # num_samples: int - Number of fracture sample points # More samples = more fragments = smaller pieces # Fewer than ~6 samples may result in missing geometry config.num_samples = 32 # texture: Texture3D (optional) - Controls sample distribution # Lighter areas = higher probability of samples # Uses rejection-based sampling config.texture = preload("res://textures/noise_3d.tres") ``` -------------------------------- ### VoronoiMesh - Fracture Result Data Source: https://context7.com/robertvaradan/voronoishatter/llms.txt Represents a single fracture fragment with its mesh and position data. ```APIDOC ## VoronoiMesh ### Description Represents a single fracture fragment, containing the generated ArrayMesh and position offset data needed to properly place the fragment in the scene. ### Method N/A (Class definition) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response N/A ### Properties - **mesh** (ArrayMesh) - The generated fragment mesh. - **position** (Vector3) - Offset from the original mesh center. - **target** (MeshInstance3D, optional) - Reference to the source mesh. ``` -------------------------------- ### VoronoiMesh Properties Source: https://context7.com/robertvaradan/voronoishatter/llms.txt Details the properties of a VoronoiMesh, representing a single fracture fragment with its mesh and position offset. ```gdscript # VoronoiMesh properties: # mesh: ArrayMesh - The generated fragment mesh # position: Vector3 - Offset from original mesh center # target: MeshInstance3D - Reference to source mesh (may be null) ``` -------------------------------- ### Shatter Mesh on Collision Source: https://context7.com/robertvaradan/voronoishatter/llms.txt Handles mesh shattering when a body enters a collision area. Adds fragments to the scene and creates physics bodies for them. ```gdscript func _on_body_entered(body: Node3D): var target = $TeapotMesh as MeshInstance3D var fragments = shatter_mesh(target) # Add fragments to scene and create physics bodies for fragment in fragments: var rigid_body = RigidBody3D.new() rigid_body.add_child(fragment) fragment.create_convex_collision(true, true) # Reparent collision to rigid body for child in fragment.get_children(): if child is StaticBody3D: var collision = child.get_child(0) collision.reparent(rigid_body) child.queue_free() add_child(rigid_body) rigid_body.global_position = target.global_position + fragment.position target.queue_free() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.