feat: Implement Stickman Factory and Test Harness for runtime rigging
- Added StickmanFactory to load and instantiate .stk files into master_rig.tscn. - Created a Test Harness scene for debugging bone scales, vector drawing offsets, and IK limits. - Updated stk_rig_adapter to fit head bone and mount head shapes as full geometry. - Enhanced README and PROJECT documentation to reflect new features and usage. - Introduced UI elements for file selection and visual debugging in the Test Harness. - Refactored code to improve clarity and maintainability, including removal of unused functions.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
class_name StickmanFactory
|
||||
extends RefCounted
|
||||
## StickmanFactory - Runtime factory for spawning rig instances from .stk files
|
||||
## (Phase 9).
|
||||
##
|
||||
## Loads a versioned .stk JSON dictionary and instantiates a master_rig.tscn,
|
||||
## adapting it via StkRigAdapter. Consumed by the standalone test harness, not
|
||||
## referenced by the editor.
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Constants
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
const RIG_SCENE := preload("res://master_rig.tscn")
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Public API
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
static func load_stk(path: String) -> Dictionary:
|
||||
var file := FileAccess.open(path, FileAccess.READ)
|
||||
if file == null:
|
||||
push_warning("StickmanFactory: failed to open '%s' (error %d)." % [path, FileAccess.get_open_error()])
|
||||
return {}
|
||||
|
||||
var text := file.get_as_text()
|
||||
file.close()
|
||||
|
||||
var parsed: Variant = JSON.parse_string(text)
|
||||
if parsed == null or not parsed is Dictionary:
|
||||
push_warning("StickmanFactory: failed to parse '%s' as JSON." % path)
|
||||
return {}
|
||||
|
||||
return parsed as Dictionary
|
||||
|
||||
|
||||
static func spawn_from_data(stk_data: Dictionary) -> Node2D:
|
||||
var rig := RIG_SCENE.instantiate() as Node2D
|
||||
StkRigAdapter.apply(stk_data, rig)
|
||||
return rig
|
||||
|
||||
|
||||
static func spawn(path: String) -> Node2D:
|
||||
var data := load_stk(path)
|
||||
if data.is_empty():
|
||||
return null
|
||||
return spawn_from_data(data)
|
||||
Reference in New Issue
Block a user