-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update 20241019-reduce-size-difference-between-capsules-and-mesh-volu…
…me.md
- Loading branch information
Showing
1 changed file
with
3 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <[email protected]> | ||
# 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 | ||
|
||
|