Skip to content

Commit

Permalink
Increase flexibility of allowed avatar node structures (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronfranke authored Apr 17, 2024
1 parent 7c88d09 commit d076374
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
30 changes: 25 additions & 5 deletions mirror-godot-app/player/animations/animation_controller.gd
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ func set_avatar_with_node(new_avatar: Node) -> void:
if is_instance_valid(_avatar):
remove_child(_avatar)
_avatar.queue_free()
_avatar = new_avatar
add_child(new_avatar)
_avatar = _cleanup_avatar_node_structure(new_avatar)
add_child(_avatar)
_set_meshes()
_set_meshes_layer()
_adjust_model_height()
Expand All @@ -364,9 +364,13 @@ func set_movement_scale(movement_scale: float) -> void:


func get_eyes_position(force_rest: bool = false) -> Vector3:
var center: Vector3 = _center_of_two_bones("LeftEye", "RightEye", not _sitting or force_rest)
if center:
return center
if _skeleton:
var center: Vector3 = _center_of_two_bones("LeftEye", "RightEye", not _sitting or force_rest)
if center:
return center
center = _get_bone_transform("Head", true).origin
if center:
return center
# Fallback for when the bones can't be found.
if _sitting:
return _EYES_POSITION_SITTING
Expand Down Expand Up @@ -489,6 +493,22 @@ func _adjust_model_height() -> void:
_player.refresh_player_scale()


func _cleanup_avatar_node_structure(new_avatar: Node) -> Node:
if new_avatar.get_child_count() != 0:
# Determine if we need an extra Armature node (we need this for VRM avatars).
var first_child: Node = new_avatar.get_child(0)
if first_child is Skeleton3D:
var extra_root = Node3D.new()
extra_root.name = new_avatar.name
new_avatar.name = &"Armature"
extra_root.add_child(new_avatar)
return extra_root
# Determine if we need to rename the existing node to Armature.
if new_avatar.get_node(^"Armature") == null:
first_child.name = &"Armature"
return new_avatar


func _on_equipable_changed(equipable: Node) -> void:
if equipable == null:
stance = STANCE.UNARMED
Expand Down
1 change: 0 additions & 1 deletion mirror-godot-app/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ global_script_class_icons={
[application]

config/name="The Mirror"
config/version=""
run/main_scene="res://scenes/boot_scene.tscn"
config/features=PackedStringArray("4.3", "4309e8e8", "mirror")
boot_splash/bg_color=Color(0.0745098, 0.0862745, 0.184314, 1)
Expand Down

0 comments on commit d076374

Please sign in to comment.