Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase flexibility of allowed avatar node structures #110

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading