Door Animation Module

This commit is contained in:
Marco 2025-07-09 09:20:48 +02:00
commit af44d96c33
24 changed files with 438 additions and 50 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

BIN
3D/BlockbenchModels/Tubes/Tube_Texture_Base_2.png (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bpoyj6s3hntji"
path="res://.godot/imported/Tube_Texture_Base_2.png-7c9dbc962b8b0a50a2a0e49d0ff1ac68.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://3D/BlockbenchModels/Tubes/Tube_Texture_Base_2.png"
dest_files=["res://.godot/imported/Tube_Texture_Base_2.png-7c9dbc962b8b0a50a2a0e49d0ff1ac68.ctex"]
[params]
compress/mode=3
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0

BIN
3D/BlockbenchModels/Tubes/Tube_Texture_Base_3.png (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://c85o48dgtwyw6"
path="res://.godot/imported/Tube_Texture_Base_3.png-a645144cd0ce1ff33d7a429ea11c34a0.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://3D/BlockbenchModels/Tubes/Tube_Texture_Base_3.png"
dest_files=["res://.godot/imported/Tube_Texture_Base_3.png-a645144cd0ce1ff33d7a429ea11c34a0.ctex"]
[params]
compress/mode=3
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,42 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://ce47xaenqb0ev"
path="res://.godot/imported/Tube_Valve_Base.gltf-58b84fb8efa1ac0055c1617c1fe5cb65.scn"
[deps]
source_file="res://3D/BlockbenchModels/Tubes/Tube_Valve_Base.gltf"
dest_files=["res://.godot/imported/Tube_Valve_Base.gltf-58b84fb8efa1ac0055c1617c1fe5cb65.scn"]
[params]
nodes/root_type=""
nodes/root_name=""
nodes/root_script=null
nodes/apply_root_scale=true
nodes/root_scale=1.0
nodes/import_as_skeleton_bones=false
nodes/use_name_suffixes=true
nodes/use_node_type_suffixes=true
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
meshes/force_disable_compression=false
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
animation/import_rest_as_RESET=false
import_script/path=""
materials/extract=0
materials/extract_format=0
materials/extract_path=""
_subresources={}
gltf/naming_version=2
gltf/embedded_image_handling=1

BIN
3D/BlockbenchModels/Tubes/Tube_Valve_Base_0.png (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -0,0 +1,43 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://b7ligx6d3ge02"
path="res://.godot/imported/Tube_Valve_Base_0.png-60ca5fa91cb4d1b9f8e33bfc21c18adc.ctex"
metadata={
"vram_texture": false
}
generator_parameters={
"md5": "8deea29cb261fda0819ef7976510c802"
}
[deps]
source_file="res://3D/BlockbenchModels/Tubes/Tube_Valve_Base_0.png"
dest_files=["res://.godot/imported/Tube_Valve_Base_0.png-60ca5fa91cb4d1b9f8e33bfc21c18adc.ctex"]
[params]
compress/mode=3
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,42 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://b11b5nh0lu7nq"
path="res://.godot/imported/Valve.gltf-be298b01936419b225cd0ef06f87de69.scn"
[deps]
source_file="res://3D/BlockbenchModels/Tubes/Valve.gltf"
dest_files=["res://.godot/imported/Valve.gltf-be298b01936419b225cd0ef06f87de69.scn"]
[params]
nodes/root_type=""
nodes/root_name=""
nodes/root_script=null
nodes/apply_root_scale=true
nodes/root_scale=1.0
nodes/import_as_skeleton_bones=false
nodes/use_name_suffixes=true
nodes/use_node_type_suffixes=true
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
meshes/force_disable_compression=false
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
animation/import_rest_as_RESET=false
import_script/path=""
materials/extract=0
materials/extract_format=0
materials/extract_path=""
_subresources={}
gltf/naming_version=2
gltf/embedded_image_handling=1

BIN
3D/BlockbenchModels/Tubes/Valve_0.png (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -0,0 +1,43 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://coqf2v7jaq0yt"
path="res://.godot/imported/Valve_0.png-5852d005e6de0ae1ef10e334a343375d.ctex"
metadata={
"vram_texture": false
}
generator_parameters={
"md5": "0b1368869fd0144c93319d5bf6cef5e1"
}
[deps]
source_file="res://3D/BlockbenchModels/Tubes/Valve_0.png"
dest_files=["res://.godot/imported/Valve_0.png-5852d005e6de0ae1ef10e334a343375d.ctex"]
[params]
compress/mode=3
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0

BIN
3D/BlockbenchModels/Tubes/Valve_Texture.png (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bnc07qsjkagnr"
path="res://.godot/imported/Valve_Texture.png-1213788ad8a6397d5de95db921965109.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://3D/BlockbenchModels/Tubes/Valve_Texture.png"
dest_files=["res://.godot/imported/Valve_Texture.png-1213788ad8a6397d5de95db921965109.ctex"]
[params]
compress/mode=3
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0

View file

@ -1,7 +1,8 @@
[gd_scene load_steps=5 format=3 uid="uid://bubtvv3pa06py"]
[gd_scene load_steps=6 format=3 uid="uid://bubtvv3pa06py"]
[ext_resource type="PackedScene" uid="uid://b12y0mtx6ibo8" path="res://3D/BlockbenchModels/Door/Door.gltf" id="1_7axon"]
[ext_resource type="Script" uid="uid://b5yceosypf3mu" path="res://Scripts/Actors/3D/Door3D.cs" id="1_y1ovr"]
[ext_resource type="Script" uid="uid://c077xadpua5iy" path="res://Scripts/Actors/3D/OpenCloseActorAnimationManager3D.cs" id="3_evf52"]
[sub_resource type="BoxShape3D" id="BoxShape3D_7axon"]
size = Vector3(1.99927, 2.00482, 0.140869)
@ -9,10 +10,10 @@ size = Vector3(1.99927, 2.00482, 0.140869)
[sub_resource type="BoxShape3D" id="BoxShape3D_evf52"]
size = Vector3(0.98187256, 2.0062256, 0.44836426)
[node name="Door3d" type="AnimatableBody3D" node_paths=PackedStringArray("AnimationPlayer") groups=["Solid"]]
[node name="Door3d" type="AnimatableBody3D" groups=["Solid"]]
collision_layer = 16
collision_mask = 0
script = ExtResource("1_y1ovr")
AnimationPlayer = NodePath("blockbench_export/AnimationPlayer")
[node name="blockbench_export" parent="." instance=ExtResource("1_7axon")]
@ -28,7 +29,17 @@ collision_mask = 2
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.035308838, 0.0099487305, -0.035583496)
shape = SubResource("BoxShape3D_evf52")
[node name="AnimationManager" type="Node" parent="." node_paths=PackedStringArray("AnimationPlayer")]
script = ExtResource("3_evf52")
AnimationPlayer = NodePath("../blockbench_export/AnimationPlayer")
[connection signal="Closing" from="." to="AnimationManager" method="PlayClosing"]
[connection signal="Opening" from="." to="AnimationManager" method="PlayOpening"]
[connection signal="SetClosed" from="." to="AnimationManager" method="SkipToClose"]
[connection signal="SetOpen" from="." to="AnimationManager" method="SkipToOpen"]
[connection signal="area_entered" from="PlayerDetector" to="." method="OnPlayerDetected"]
[connection signal="area_exited" from="PlayerDetector" to="." method="OnPlayerUndetected"]
[connection signal="ClosedAnimationCompleted" from="AnimationManager" to="." method="ClosedAnimationFinished"]
[connection signal="OpenAnimationCompleted" from="AnimationManager" to="." method="OpenAnimationFinished"]
[editable path="blockbench_export"]

View file

@ -10,24 +10,34 @@ public partial class Door3D : AnimatableBody3D, IActivable
[Export] public string GroupName { get; set; }
[Export] public DoorState State { get; set; } = DoorState.Closed;
[Signal] public delegate void OpeningEventHandler();
[Signal] public delegate void ClosingEventHandler();
[Signal]
public delegate void OpeningEventHandler();
[Export] public AnimationPlayer AnimationPlayer { get; set; }
[Signal]
public delegate void ClosingEventHandler();
[Export] public string OpenAnimationName { get; set; } = "Open";
[Signal]
public delegate void SetClosedEventHandler();
[Export] public string CloseAnimationName { get; set; } = "Close";
[Signal]
public delegate void SetOpenEventHandler();
[Export] public string OpenedAnimationName { get; set; } = "Opened";
[Export] public string ClosedAnimationName { get; set; } = "Closed";
// [Export] public AnimationPlayer AnimationPlayer { get; set; }
//
// [Export] public string OpenAnimationName { get; set; } = "Open";
//
// [Export] public string CloseAnimationName { get; set; } = "Close";
//
// [Export] public string OpenedAnimationName { get; set; } = "Opened";
//
// [Export] public string ClosedAnimationName { get; set; } = "Closed";
private bool _isAnimating = false;
private bool _isPlayerIncollider = false;
private CollisionShape3D _collisionShape;
public override void _Ready()
{
if (Engine.IsEditorHint()) return;
@ -41,37 +51,34 @@ public partial class Door3D : AnimatableBody3D, IActivable
SyncAnimation();
AnimationPlayer.AnimationFinished += AnimationPlayerOnAnimationFinished;
// AnimationPlayer.AnimationFinished += AnimationPlayerOnAnimationFinished;
}
private void SyncAnimation()
{
if (State is DoorState.Closed)
{
AnimationPlayer.Play(ClosedAnimationName);
EmitSignalSetClosed();
//AnimationPlayer.Play(ClosedAnimationName);
}
else
{
AnimationPlayer.Play(OpenedAnimationName);
EmitSignalSetOpen();
//AnimationPlayer.Play(OpenedAnimationName);
}
}
private void AnimationPlayerOnAnimationFinished(StringName animName)
public void ClosedAnimationFinished()
{
if (Engine.IsEditorHint()) return;
State = DoorState.Closed;
CallDeferred(MethodName.ToggleCollisionDeferred, true);
_isAnimating = false;
}
GD.Print($"Animation finished {animName}");
if ((animName == OpenAnimationName || animName == OpenedAnimationName))
{
State = DoorState.Open;
CallDeferred(MethodName.ToggleCollisionDeferred, false);
}
else if (animName == CloseAnimationName || animName == ClosedAnimationName)
{
State = DoorState.Closed;
CallDeferred(MethodName.ToggleCollisionDeferred, true);
}
public void OpenAnimationFinished()
{
State = DoorState.Open;
CallDeferred(MethodName.ToggleCollisionDeferred, false);
_isAnimating = false;
}
@ -91,6 +98,7 @@ public partial class Door3D : AnimatableBody3D, IActivable
{
return false;
}
Toggle();
break;
case ActivationType.Enable:
@ -99,6 +107,7 @@ public partial class Door3D : AnimatableBody3D, IActivable
{
return false;
}
ChangeState(DoorState.Closed);
break;
case ActivationType.Disable:
@ -123,14 +132,10 @@ public partial class Door3D : AnimatableBody3D, IActivable
switch (newState)
{
case DoorState.Open:
AnimationPlayer.Play(OpenAnimationName);
AnimationPlayer.SetSpeedScale(1);
//CallDeferred(MethodName.ToggleCollisionDeferred, false);
EmitSignalOpening();
break;
case DoorState.Closed:
AnimationPlayer.Play(CloseAnimationName);
AnimationPlayer.SetSpeedScale(1);
//CallDeferred(MethodName.ToggleCollisionDeferred, true);
EmitSignalClosing();
break;
}
@ -147,7 +152,7 @@ public partial class Door3D : AnimatableBody3D, IActivable
public void Toggle()
{
if (_isAnimating) return;
ChangeState(State is DoorState.Open ? DoorState.Closed : DoorState.Open);
ChangeState(State is DoorState.Open ? DoorState.Closed : DoorState.Open);
}
public void OnPlayerDetected(Node3D body)

View file

@ -0,0 +1,62 @@
using Godot;
namespace Cirno.Scripts.Actors._3D;
public partial class OpenCloseActorAnimationManager3D : Node
{
[Export] public AnimationPlayer AnimationPlayer { get; set; }
[Export] public StringName OpeningAnimationName { get; set; } = "Opening";
[Export] public StringName ClosingAnimationName { get; set; } = "Closing";
[Export] public StringName OpenAnimationName { get; set; } = "Open";
[Export] public StringName ClosedAnimationName { get; set; } = "Closed";
private bool _isAnimating = false;
[Signal]
public delegate void ClosedAnimationCompletedEventHandler();
[Signal]
public delegate void OpenAnimationCompletedEventHandler();
public override void _Ready()
{
AnimationPlayer.AnimationFinished += AnimationPlayerOnAnimationFinished;
}
private void AnimationPlayerOnAnimationFinished(StringName animName)
{
if (animName == OpenAnimationName || animName == OpeningAnimationName)
{
EmitSignalOpenAnimationCompleted();
}
else if (animName == ClosedAnimationName || animName == ClosingAnimationName)
{
EmitSignalClosedAnimationCompleted();
}
}
public void PlayOpening()
{
AnimationPlayer.Play(OpeningAnimationName);
AnimationPlayer.SetSpeedScale(1);
}
public void PlayClosing()
{
AnimationPlayer.Play(ClosingAnimationName);
AnimationPlayer.SetSpeedScale(1);
}
public void SkipToOpen()
{
AnimationPlayer.Play(OpenAnimationName);
}
public void SkipToClose()
{
AnimationPlayer.Play(ClosedAnimationName);
}
}

View file

@ -0,0 +1 @@
uid://c077xadpua5iy