diff --git a/decisions/20241019-reduce-size-difference-between-capsules-and-mesh-volume.md b/decisions/20241019-reduce-size-difference-between-capsules-and-mesh-volume.md index 3c42c76cc4..5c29a86928 100644 --- a/decisions/20241019-reduce-size-difference-between-capsules-and-mesh-volume.md +++ b/decisions/20241019-reduce-size-difference-between-capsules-and-mesh-volume.md @@ -19,108 +19,9 @@ The goal is to minimize the size discrepancies between the capsules surrounding - The objective is to minimize the size differences between the capsules (nodes) and the volume of the skin mesh. This is quantified using a cost function that measures the deviation from ideal capsule sizes. -### Implementation Using GDScript - -```gdscript -# SPDX-FileCopyrightText: 2024 K. S. Ernest "iFire" Lee -# SPDX-License-Identifier: MIT - -extends Node - -class Node: - var id: int - var position: Vector3 - var flow: float = 0.0 - var target_size: float = 0.0 # Ideal size for the capsule around this node - - func _init(id: int, position: Vector3, target_size: float): - self.id = id - self.position = position - self.target_size = target_size - -class Edge: - var u: Node - var v: Node - var cost_function: Callable - - func _init(u: Node, v: Node, cost_function: Callable): - self.u = u - self.v = v - self.cost_function = cost_function - -class BiMDF: - var nodes: Dictionary = {} - var edges: Array = [] - - func add_node(position: Vector3, target_size: float) -> Node: - var new_node = Node(nodes.size(), position, target_size) - nodes[new_node.id] = new_node - return new_node - - func add_edge(u: Node, v: Node, cost_function: Callable) -> Edge: - var new_edge = Edge(u, v, cost_function) - edges.append(new_edge) - return new_edge - - func solve() -> Dictionary: - # Placeholder for Bi-MDF algorithm implementation - # Return a sample output structure for demonstration - return {"cost": 0, "solution": {}} - -# Cost Function Definitions -func quad_deviation(flow: float, target: float) -> float: - return pow(flow - target, 2) # Quadratic cost based on deviation - -# Function to create a cost function with specific parameters -func create_cost_function(target_size: float, weight: float) -> Callable: - return Callable(self, "quad_deviation").bind(target_size * weight) - -# Main function to set up and run the Bi-MDF problem -func _ready(): - var bimdf = BiMDF.new() - var array_mesh: ArrayMesh = preload("res://path_to_your_mesh.mesh") - var mesh_data_tool = MeshDataTool.new() - mesh_data_tool.create_from_surface(array_mesh, 0) - - # Extract vertices using MeshDataTool - var vertex_count = mesh_data_tool.get_vertex_count() - for i in range(vertex_count): - var vertex_position = mesh_data_tool.get_vertex(i) - bimdf.add_node(vertex_position, 1.0) # Assuming a default target size for simplicity - - # Example setup for bones (if applicable) - var bone1 = bimdf.add_node(Vector3(0, 0, 0), 3.0) # Position and target size for bone1 - var bone2 = bimdf.add_node(Vector3(1, 0, 0), 2.0) # Position and target size for bone2 - - # Example skin weights (adjust according to your specific setup) - var weights = { - vertex1: [0.5, 0.5], # Vertex 1 influenced equally by bone1 and bone2 - vertex2: [0.7, 0.3], # More influence from bone1 - vertex3: [0.9, 0.1], # Mostly bone1 - vertex4: [0.6, 0.4], # Somewhat balanced - vertex5: [0.4, 0.6], # More influence from bone2 - vertex6: [0.2, 0.8], # Mostly bone2 - vertex7: [0.3, 0.7], # More influence from bone2 - vertex8: [0.5, 0.5] # Equally influenced - } - - # Connect bones to vertices based on skin weights - for vertex_id in weights.keys(): - var vertex = bimdf.nodes[vertex_id] - var weight1 = weights[vertex_id][0] - var weight2 = weights[vertex_id][1] - var cost_func1 = create_cost_function(vertex.target_size, weight1) - var cost_func2 = create_cost_function(vertex.target_size, weight2) - bimdf.add_edge(bone1, vertex, cost_func1) - bimdf.add_edge(bone2, vertex, cost_func2) - - # Solve the Bi-MDF problem - var result = bimdf.solve() - print("Total cost: ", result["cost"]) - - for edge in bimdf.edges: - print("Flow on edge: ", edge.u.flow + edge.v.flow) # Placeholder for flow values -``` +### Implementation + +I have no idea. ## The Benefits