From 7b3f4d8c5e57aad1d92fb8ea274a34a68031ea00 Mon Sep 17 00:00:00 2001 From: Josef Date: Sun, 19 Jan 2025 21:35:51 +0100 Subject: [PATCH] Outlines&More --- Runtime/Actions/Time/Delay.cs | 2 +- Runtime/Actions/Time/DelayedList.cs | 2 +- Runtime/Actions/Time/Repeat.cs | 2 +- Runtime/Actions/Time/TimeLooper.cs | 8 +- Runtime/Animation/Flash/Flash.cs | 16 +- Runtime/Animation/Follow.cs | 2 +- .../Animation/Highlight/HighlightEffect.cs | 171 ++++++++++++++--- .../Presets/White Outline - Highlight.tres | 18 +- .../Yellow Scan Outline - Highlight.tres | 35 ++++ Runtime/Animation/Rotate.cs | 35 ++++ Runtime/Animation/Shake/Shake.cs | 12 +- .../Animation/Transform/AnimateTransform.cs | 8 +- Runtime/Math/Geometry/Triangle2.cs | 5 - Runtime/Procedural/Assets/Grass/GrassPatch.cs | 2 - Runtime/Procedural/Mesh/MeshCombiner.cs | 3 +- .../PC/Default-Sensors-PC.tres | 6 +- .../PC/Mouse Editor Camera/Move Down.tres | 16 ++ .../PC/Mouse Editor Camera/Move Forward.tres | 2 +- .../PC/Mouse Editor Camera/Move Left.tres | 2 +- .../PC/Mouse Editor Camera/Move Up.tres | 16 ++ Runtime/Shading/Materials/Materials.cs | 72 ++++++-- ...FancyOutline Scan White 500ms 20x.material | Bin 0 -> 522 bytes .../Effects/FancyOutline/FancyOutline.cs | 62 +++++++ .../FancyOutline/FancyOutline.gdshader | 44 +++++ .../Outline/Outline Thin White.material | Bin 412 -> 457 bytes .../Shaders/Effects/Outline/Outline.cs | 9 + .../Shaders/Effects/Outline/Outline.gdshader | 13 +- .../Shaders/Effects/Overlay/Overlay.cs | 36 ++++ .../Shaders/Effects/Overlay/Overlay.gdshader | 24 +++ .../Effects/RainbowGlow/RainbowGlow.gdshader | 48 +++++ .../CSShaderClassGenerator.cs | 12 +- Runtime/Structures/MapList.cs | 9 +- Runtime/Text/RegexUtility.cs | 2 +- Runtime/Time/SetTimeLineSpeed.cs | 6 +- Runtime/Time/TImeLineManager_Scheduling.cs | 76 ++++++++ Runtime/Time/TimeLine.cs | 39 ++-- Runtime/Time/TimeLineEvent.cs | 2 + Runtime/Time/TimeLineManager.cs | 173 +++--------------- Runtime/Time/TimeLineRunner.cs | 114 ++++++------ Runtime/Time/TimeLineScheduler.cs | 167 ----------------- Runtime/Time/TimeLineSpan.cs | 19 +- Runtime/Tools/Lists.cs | 3 +- Runtime/UI/Styling/UIColor.cs | 7 +- Runtime/UI/Styling/UINumber.cs | 6 +- .../UI/Transitions/ActiveStyleTransition.cs | 4 +- .../VirtualCameras/Effects/CameraEffect.cs | 4 +- .../Effects/Presets/ScreenShake.tres | 61 ++++++ 47 files changed, 870 insertions(+), 505 deletions(-) create mode 100644 Runtime/Animation/Highlight/Presets/Yellow Scan Outline - Highlight.tres create mode 100644 Runtime/Animation/Rotate.cs create mode 100644 Runtime/Sensors/Default-Sensors/PC/Mouse Editor Camera/Move Down.tres create mode 100644 Runtime/Sensors/Default-Sensors/PC/Mouse Editor Camera/Move Up.tres create mode 100644 Runtime/Shading/Shaders/Effects/FancyOutline/FancyOutline Scan White 500ms 20x.material create mode 100644 Runtime/Shading/Shaders/Effects/FancyOutline/FancyOutline.cs create mode 100644 Runtime/Shading/Shaders/Effects/FancyOutline/FancyOutline.gdshader create mode 100644 Runtime/Shading/Shaders/Effects/Overlay/Overlay.cs create mode 100644 Runtime/Shading/Shaders/Effects/Overlay/Overlay.gdshader create mode 100644 Runtime/Shading/Shaders/Effects/RainbowGlow/RainbowGlow.gdshader create mode 100644 Runtime/Time/TImeLineManager_Scheduling.cs delete mode 100644 Runtime/Time/TimeLineScheduler.cs create mode 100644 Runtime/VirtualCameras/Effects/Presets/ScreenShake.tres diff --git a/Runtime/Actions/Time/Delay.cs b/Runtime/Actions/Time/Delay.cs index 6207d5d..128de8a 100644 --- a/Runtime/Actions/Time/Delay.cs +++ b/Runtime/Actions/Time/Delay.cs @@ -21,7 +21,7 @@ namespace Rokojori { var sequenceID = DispatchStart(); - var eventID = TimeLineScheduler.ScheduleEventIn( timeLine, duration, + var eventID = TimeLineManager.ScheduleEventIn( timeLine, duration, ( eventID ) => { RJLog.Log( ">> delay ended", Time.GetTicksMsec(), sequenceID, eventID ); diff --git a/Runtime/Actions/Time/DelayedList.cs b/Runtime/Actions/Time/DelayedList.cs index 2724cba..0d512b7 100644 --- a/Runtime/Actions/Time/DelayedList.cs +++ b/Runtime/Actions/Time/DelayedList.cs @@ -41,7 +41,7 @@ namespace Rokojori for ( int i = 0; i < list.Count; i++ ) { - TimeLineScheduler.ScheduleEventIn( timeLine, offset, + TimeLineManager.ScheduleEventIn( timeLine, offset, id => { Action.Trigger( list[ i ] ); diff --git a/Runtime/Actions/Time/Repeat.cs b/Runtime/Actions/Time/Repeat.cs index 35bf2d3..98c859d 100644 --- a/Runtime/Actions/Time/Repeat.cs +++ b/Runtime/Actions/Time/Repeat.cs @@ -32,7 +32,7 @@ namespace Rokojori { for ( int i = 0; i < numRepeats; i++ ) { - TimeLineScheduler.ScheduleEventIn( timeLine, i * duration, + TimeLineManager.ScheduleEventIn( timeLine, i * duration, id => { if ( i == 0 ) diff --git a/Runtime/Actions/Time/TimeLooper.cs b/Runtime/Actions/Time/TimeLooper.cs index 45738da..555c99b 100644 --- a/Runtime/Actions/Time/TimeLooper.cs +++ b/Runtime/Actions/Time/TimeLooper.cs @@ -49,11 +49,13 @@ namespace Rokojori { if ( _eventID != -1 ) { - TimeLineScheduler.RemoveEvent( timeLine, _eventID ); + TimeLineManager.RemoveEvent( timeLine, _eventID ); return; } - _eventID = TimeLineScheduler.ScheduleLoopEvent( timeLine, duration, offset, id => Action.Trigger( action ) ); + var tle = TimeLineManager.ScheduleLoopEvent( timeLine, duration, offset, tle => Action.Trigger( action ) ); + + _eventID = tle.id; } else { @@ -62,7 +64,7 @@ namespace Rokojori return; } - TimeLineScheduler.RemoveEvent( timeLine, _eventID ); + TimeLineManager.RemoveEvent( timeLine, _eventID ); _eventID = -1; } diff --git a/Runtime/Animation/Flash/Flash.cs b/Runtime/Animation/Flash/Flash.cs index 4f1ef0a..bc1f659 100644 --- a/Runtime/Animation/Flash/Flash.cs +++ b/Runtime/Animation/Flash/Flash.cs @@ -138,20 +138,20 @@ namespace Rokojori } ); - var start = TimeLineManager.GetPosition( timeline ); + var start = timeline.position; var end = start + duration; - animationID = TimeLineScheduler.ScheduleSpanIn( timeline, 0, duration, - ( int id, TimeLineSpanUpdateType type )=> + animationID = TimeLineManager.ScheduleSpanIn( timeline, 0, duration, + ( TimeLineSpan span, TimeLineSpanUpdateType type )=> { - if ( animationID != id ) + if ( animationID != span.id ) { return; } - var phase = TimeLineManager.GetRangePhase( timeline, start, end ); + var phase = span.phase; var value = flashCurve.Sample( phase ); @@ -195,7 +195,7 @@ namespace Rokojori } } - ); + ); if ( type == TimeLineSpanUpdateType.End ) @@ -211,15 +211,13 @@ namespace Rokojori } } - ); + ).id; - // RJLog.Log( "Processing animationID", animationID ); } public override void CancelAction( int id ) { - // RJLog.Log( "CancelAction", id ); if ( false && actionID != id ) { diff --git a/Runtime/Animation/Follow.cs b/Runtime/Animation/Follow.cs index a01ede2..9fba544 100644 --- a/Runtime/Animation/Follow.cs +++ b/Runtime/Animation/Follow.cs @@ -61,7 +61,7 @@ namespace Rokojori return; } - var tl = TimeLine.IfNull_ReplaceByGameTime( timeline ); + var tl = TimeLineManager.Ensure( timeline ); target.GlobalPosition = Smoothing.Apply( positionSmoothing, source.GlobalPosition, tl.delta ); } } diff --git a/Runtime/Animation/Highlight/HighlightEffect.cs b/Runtime/Animation/Highlight/HighlightEffect.cs index a1a4cc9..8eda146 100644 --- a/Runtime/Animation/Highlight/HighlightEffect.cs +++ b/Runtime/Animation/Highlight/HighlightEffect.cs @@ -31,6 +31,9 @@ namespace Rokojori [Export] public TimeLine timeline; + + [ExportGroup( "Transition")] + [Export] public float inDuration; @@ -43,23 +46,54 @@ namespace Rokojori [Export] public Curve outCurve = MathX.Curve( 0, 1 ); + [ExportGroup( "Color")] [Export] public HDRColor color; - public enum MaterialMode + [Export( PropertyHint.Range, "0,1")] + public float opacityModulationStrength = 0.5f; + + [Export( PropertyHint.Range, "0,10")] + public float opacityModulationDuration = 0.5f; + + [Export( PropertyHint.Range, "0,1")] + public float opacityModulationTransition = 1f; + + public enum OutlineMaterialMode { Flat_Outline, + Scanner_FancyOutline, Custom_Material } + [ExportGroup( "Outline")] [Export] - public MaterialMode materialMode; + public OutlineMaterialMode outlineMaterialMode; [Export] - public Material customMaterial; + public Material outlineCustomMaterial; [Export] - public ColorPropertyName customColorProperty; + public ColorPropertyName outlineCustomColorProperty; + + public enum OverlayMaterialMode + { + Flat_Overlay, + Custom_Material + } + + [ExportGroup( "Overlay")] + [Export( PropertyHint.Range, "0,1")] + public float overlayOpacity = 0.02f; + + [Export] + public OverlayMaterialMode overlayMaterialMode; + + [Export] + public Material overlayCustomMaterial; + + [Export] + public ColorPropertyName overlayCustomColorProperty; List _active = new List(); @@ -92,17 +126,48 @@ namespace Rokojori Material material = null; - if ( MaterialMode.Flat_Outline == materialMode ) + if ( OutlineMaterialMode.Flat_Outline == outlineMaterialMode ) { var outlineMaterial = new OutlineMaterial(); outlineMaterial.albedo.Set( colorTransparent ); material = outlineMaterial; + + outlineMaterial.opacityModulationDuration.Set( opacityModulationDuration ); + outlineMaterial.opacityModulationStrength.Set( opacityModulationStrength ); } - else if ( MaterialMode.Custom_Material == materialMode ) + else if ( OutlineMaterialMode.Scanner_FancyOutline == outlineMaterialMode ) { - material = (Material) customMaterial.Duplicate(); - customColorProperty.Set( material, colorTransparent ); + var outlineMaterial = new FancyOutlineMaterial(); + outlineMaterial.albedo.Set( colorTransparent ); + material = outlineMaterial; + + outlineMaterial.opacityModulationDuration.Set( opacityModulationDuration ); + outlineMaterial.opacityModulationStrength.Set( opacityModulationStrength ); } + else if ( OutlineMaterialMode.Custom_Material == outlineMaterialMode ) + { + material = (Material) outlineCustomMaterial.Duplicate(); + outlineCustomColorProperty.Set( material, colorTransparent ); + } + + + if ( OverlayMaterialMode.Flat_Overlay == overlayMaterialMode ) + { + var overlay = new OverlayMaterial(); + overlay.albedo.Set( ColorX.SetAlpha( hdrColor, 0 ) ); + material.NextPass = overlay; + + overlay.opacityModulationDuration.Set( opacityModulationDuration ); + overlay.opacityModulationStrength.Set( opacityModulationStrength ); + } + else if ( OverlayMaterialMode.Custom_Material == overlayMaterialMode ) + { + var overlay = (Material) overlayCustomMaterial.Duplicate(); + overlayCustomColorProperty.Set( overlay, colorTransparent ); + material.NextPass = overlay; + } + + Arrays.ForEach( targets, t => @@ -118,16 +183,19 @@ namespace Rokojori var startPhase = animation.phase; - animation.tweenID = TimeLineManager.Tween( timeline, inDuration, - ( id, type, phase )=> + animation.tweenID = TimeLineManager.ScheduleSpanIn( timeline, 0, inDuration, + ( span, type )=> { - // RJLog.Log( "Start Highlight: ", id, "Active:",animation.tweenID, "Phase:", phase ); - if ( animation.tweenID != id ) + + if ( animation.tweenID != span.id ) { return; } - animation.phase = MathX.Map( phase, 0, 1, startPhase, 1 ); + var phase = span.phase; + + + animation.phase = MathX.Map( phase, 0, 1, startPhase, 1 ); var p = animation.phase; @@ -136,6 +204,11 @@ namespace Rokojori p = inCurve.Sample( p ); } + var transitionModulationStrength = Mathf.Lerp( + opacityModulationStrength, opacityModulationStrength * p, + opacityModulationTransition ); + + var tweenColor = ColorX.Fade( hdrColor, p ); if ( TimeLineSpanUpdateType.End == type ) @@ -147,21 +220,41 @@ namespace Rokojori animation.materials.ForEach( ( m )=> { - if ( MaterialMode.Flat_Outline == materialMode ) + if ( OutlineMaterialMode.Flat_Outline == outlineMaterialMode ) { var outlineMaterial = ( OutlineMaterial ) m; outlineMaterial.albedo.Set( tweenColor ); + outlineMaterial.opacityModulationStrength.Set( transitionModulationStrength ); } - else if ( MaterialMode.Custom_Material == materialMode ) + else if ( OutlineMaterialMode.Scanner_FancyOutline == outlineMaterialMode ) { - customColorProperty.Set( m, tweenColor); + var outlineMaterial = ( FancyOutlineMaterial ) m; + outlineMaterial.albedo.Set( tweenColor ); + outlineMaterial.opacityModulationStrength.Set( transitionModulationStrength ); } + else if ( OutlineMaterialMode.Custom_Material == outlineMaterialMode ) + { + outlineCustomColorProperty.Set( m, tweenColor); + } + + if ( OverlayMaterialMode.Flat_Overlay == overlayMaterialMode ) + { + var overlay = (OverlayMaterial) m.NextPass; + overlay.albedo.Set( ColorX.Fade( tweenColor, overlayOpacity ) ); + overlay.opacityModulationStrength.Set( transitionModulationStrength ); + } + else if ( OutlineMaterialMode.Custom_Material == outlineMaterialMode ) + { + var material = (OverlayMaterial) m.NextPass; + outlineCustomColorProperty.Set( m, tweenColor); + } + } ); } - ); + ).id; } void EndHighlight( Node3D[] targets ) @@ -170,7 +263,6 @@ namespace Rokojori if ( animation == null ) { - // RJLog.Log( "No animation found:", targets ); return; } @@ -178,17 +270,16 @@ namespace Rokojori var hdrColor = ColorX.Fade( color.GetHDRColor(), startPhase ); var colorTransparent = ColorX.Fade( hdrColor, 0 ); - animation.tweenID = TimeLineManager.Tween( timeline, outDuration, - ( id, type, phase )=> + animation.tweenID = TimeLineManager.ScheduleSpanIn( timeline, 0, outDuration, + ( span, type )=> { - // RJLog.Log( "End Highlight: ", id, "Active:",animation.tweenID, "Phase:", phase ); - - if ( animation.tweenID != id ) + + if ( animation.tweenID != span.id ) { return; } - animation.phase = MathX.Map( phase, 0, 1, startPhase, 0 ); + animation.phase = MathX.Map( span.phase, 0, 1, startPhase, 0 ); var p = animation.phase; @@ -197,6 +288,10 @@ namespace Rokojori p = outCurve.Sample( p ); } + var transitionModulationStrength = Mathf.Lerp( + opacityModulationStrength, opacityModulationStrength * p, + opacityModulationTransition ); + var tweenColor = ColorX.Fade( hdrColor, p ); if ( TimeLineSpanUpdateType.End == type ) @@ -216,21 +311,41 @@ namespace Rokojori animation.materials.ForEach( ( m )=> { - if ( MaterialMode.Flat_Outline == materialMode ) + if ( OutlineMaterialMode.Flat_Outline == outlineMaterialMode ) { var outlineMaterial = ( OutlineMaterial ) m; outlineMaterial.albedo.Set( tweenColor ); + outlineMaterial.opacityModulationStrength.Set( transitionModulationStrength ); } - else if ( MaterialMode.Custom_Material == materialMode ) + else if ( OutlineMaterialMode.Scanner_FancyOutline == outlineMaterialMode ) { - customColorProperty.Set( m, tweenColor ); + var outlineMaterial = ( FancyOutlineMaterial ) m; + outlineMaterial.albedo.Set( tweenColor ); + outlineMaterial.opacityModulationStrength.Set( transitionModulationStrength ); } + else if ( OutlineMaterialMode.Custom_Material == outlineMaterialMode ) + { + outlineCustomColorProperty.Set( m, tweenColor ); + } + + if ( OverlayMaterialMode.Flat_Overlay == overlayMaterialMode ) + { + var overlay = (OverlayMaterial) m.NextPass; + overlay.albedo.Set( ColorX.Fade( tweenColor, overlayOpacity ) ); + overlay.opacityModulationStrength.Set( transitionModulationStrength ); + } + else if ( OutlineMaterialMode.Custom_Material == outlineMaterialMode ) + { + var material = (OverlayMaterial) m.NextPass; + outlineCustomColorProperty.Set( m, tweenColor); + } + } ); } } - ); + ).id; } diff --git a/Runtime/Animation/Highlight/Presets/White Outline - Highlight.tres b/Runtime/Animation/Highlight/Presets/White Outline - Highlight.tres index 27ae624..d836046 100644 --- a/Runtime/Animation/Highlight/Presets/White Outline - Highlight.tres +++ b/Runtime/Animation/Highlight/Presets/White Outline - Highlight.tres @@ -1,4 +1,4 @@ -[gd_resource type="Resource" script_class="HighlightEffect" load_steps=5 format=3 uid="uid://dadr1kd14m7g3"] +[gd_resource type="Resource" script_class="HighlightEffect" load_steps=6 format=3 uid="uid://dadr1kd14m7g3"] [ext_resource type="Script" path="res://addons/rokojori_action_library/Runtime/Animation/HDRColor.cs" id="1_sk831"] [ext_resource type="Script" path="res://addons/rokojori_action_library/Runtime/Animation/Highlight/HighlightEffect.cs" id="2_pq63c"] @@ -11,10 +11,20 @@ colorMultiply = 1.0 rgbMultiply = 1.0 alphaMultiply = 1.0 +[sub_resource type="Curve" id="Curve_q8jgr"] +_data = [Vector2(0, 0), 0.0, 0.0, 0, 0, Vector2(0.503676, 0.105417), 0.560859, 0.560859, 0, 0, Vector2(1, 1), 4.02668, 0.0, 0, 0] +point_count = 3 + [resource] script = ExtResource("2_pq63c") timeline = ExtResource("3_8mahg") -inDuration = 0.1 -outDuration = 0.1 +inDuration = 0.167 +outDuration = 0.333 +outCurve = SubResource("Curve_q8jgr") color = SubResource("Resource_27v41") -materialMode = 0 +opacityModulationStrength = 0.75 +opacityModulationDuration = 1.0 +opacityModulationTransition = 1.0 +outlineMaterialMode = 0 +overlayOpacity = 0.01 +overlayMaterialMode = 0 diff --git a/Runtime/Animation/Highlight/Presets/Yellow Scan Outline - Highlight.tres b/Runtime/Animation/Highlight/Presets/Yellow Scan Outline - Highlight.tres new file mode 100644 index 0000000..4bdf5cb --- /dev/null +++ b/Runtime/Animation/Highlight/Presets/Yellow Scan Outline - Highlight.tres @@ -0,0 +1,35 @@ +[gd_resource type="Resource" script_class="HighlightEffect" load_steps=7 format=3 uid="uid://di1vy33cwab4s"] + +[ext_resource type="Script" path="res://addons/rokojori_action_library/Runtime/Animation/HDRColor.cs" id="1_3edxo"] +[ext_resource type="Script" path="res://addons/rokojori_action_library/Runtime/Animation/Highlight/HighlightEffect.cs" id="2_itc7c"] +[ext_resource type="Resource" uid="uid://h6oi6vkj4c2m" path="res://addons/rokojori_action_library/Runtime/Time/TimeLines/RealTime.tres" id="3_ttsky"] + +[sub_resource type="Resource" id="Resource_27v41"] +script = ExtResource("1_3edxo") +color = Color(1, 0.9375, 0, 1) +colorMultiply = 1.0 +rgbMultiply = 1.0 +alphaMultiply = 1.0 + +[sub_resource type="Curve" id="Curve_vqio6"] +_data = [Vector2(0, 0), 0.0, 1.0, 0, 1, Vector2(1, 1), 1.0, 0.0, 1, 0] +point_count = 2 + +[sub_resource type="Curve" id="Curve_4o1t0"] +_data = [Vector2(0, 0), 0.0, 1.0, 0, 1, Vector2(1, 1), 1.0, 0.0, 1, 0] +point_count = 2 + +[resource] +script = ExtResource("2_itc7c") +timeline = ExtResource("3_ttsky") +inDuration = 0.083 +inCurve = SubResource("Curve_vqio6") +outDuration = 0.167 +outCurve = SubResource("Curve_4o1t0") +color = SubResource("Resource_27v41") +opacityModulationStrength = 0.75 +opacityModulationDuration = 0.5 +opacityModulationTransition = 1.0 +outlineMaterialMode = 1 +overlayOpacity = 0.01 +overlayMaterialMode = 0 diff --git a/Runtime/Animation/Rotate.cs b/Runtime/Animation/Rotate.cs new file mode 100644 index 0000000..b6e7b32 --- /dev/null +++ b/Runtime/Animation/Rotate.cs @@ -0,0 +1,35 @@ +using System.Collections; +using System.Collections.Generic; +using System.Text.RegularExpressions; +using System.Text; +using Godot; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class Rotate:Node3D + { + [Export] + public Vector3 eulerRotation; + + [Export] + public Node3D target; + + [Export] + public TimeLine timeline; + + public override void _Process( double delta ) + { + if ( target == null ) + { + return; + } + + var tl = TimeLineManager.Ensure( timeline ); + var rotation = target.GetGlobalQuaternion() * Quaternion.FromEuler( eulerRotation * (float)tl.delta ); + target.SetGlobalQuaternion( rotation ); + } + } + +} \ No newline at end of file diff --git a/Runtime/Animation/Shake/Shake.cs b/Runtime/Animation/Shake/Shake.cs index e5a5b24..54e2e2d 100644 --- a/Runtime/Animation/Shake/Shake.cs +++ b/Runtime/Animation/Shake/Shake.cs @@ -44,7 +44,7 @@ namespace Rokojori var duration = shakeEffect.shakeAmountCurve.GetRandomizedEndTime( randomization ); var curve = shakeEffect; - var start = TimeLineManager.GetPosition( shakeEffect.timeline ); + var start = shakeEffect.timeline.position; var keyFrames = new List>(); var elapsed = 0f; @@ -74,10 +74,10 @@ namespace Rokojori - _currentSpanAnimationID = TimeLineScheduler.ScheduleSpanIn( timeline, 0, duration, - ( int spanAnimationID, TimeLineSpanUpdateType type )=> + _currentSpanAnimationID = TimeLineManager.ScheduleSpanIn( timeline, 0, duration, + ( TimeLineSpan span, TimeLineSpanUpdateType type )=> { - if ( spanAnimationID != _currentSpanAnimationID ) + if ( span.id != _currentSpanAnimationID ) { return; } @@ -107,7 +107,7 @@ namespace Rokojori } - var offset = TimeLineManager.GetPosition( shakeEffect.timeline ) - start; + var offset = shakeEffect.timeline.position - start; var keyFrame = kfAnimation.GetKeyFrameAt( offset ); if ( keyFrame == lastKeyFrame && ! shakeEffect.smooth ) @@ -155,7 +155,7 @@ namespace Rokojori lastKeyFrame = keyFrame; } - ); + ).id; } diff --git a/Runtime/Animation/Transform/AnimateTransform.cs b/Runtime/Animation/Transform/AnimateTransform.cs index 123fd7d..c9941b4 100644 --- a/Runtime/Animation/Transform/AnimateTransform.cs +++ b/Runtime/Animation/Transform/AnimateTransform.cs @@ -39,7 +39,7 @@ namespace Rokojori var timeline = animations.timeline; var duration = animations.GetMaxDuration( _randomizations ); - var start = TimeLineManager.GetPosition( timeline ); + var start = timeline.position; var end = start + animations.GetMaxDuration( _randomizations ); var actionID = DispatchStart(); @@ -49,10 +49,10 @@ namespace Rokojori AnimationManager.StartAnimation( c, target, c.animationMember ); } - TimeLineScheduler.ScheduleSpanIn( timeline, 0, duration, - ( int id, TimeLineSpanUpdateType type )=> + TimeLineManager.ScheduleSpanIn( timeline, 0, duration, + ( span, type )=> { - var timeNow = TimeLineManager.GetPosition( timeline ); + var timeNow = timeline.position; var elapsed = timeNow - start; var index = 0; diff --git a/Runtime/Math/Geometry/Triangle2.cs b/Runtime/Math/Geometry/Triangle2.cs index 7837784..188fea7 100644 --- a/Runtime/Math/Geometry/Triangle2.cs +++ b/Runtime/Math/Geometry/Triangle2.cs @@ -76,11 +76,6 @@ namespace Rokojori public bool ContainsPoint( Vector2 p ) { - if ( true) - { - return true; - } - var d1 = Sign( p, a, b ); var d2 = Sign( p, b, c ); var d3 = Sign( p, c, a ); diff --git a/Runtime/Procedural/Assets/Grass/GrassPatch.cs b/Runtime/Procedural/Assets/Grass/GrassPatch.cs index f67d27b..b912e6f 100644 --- a/Runtime/Procedural/Assets/Grass/GrassPatch.cs +++ b/Runtime/Procedural/Assets/Grass/GrassPatch.cs @@ -266,8 +266,6 @@ namespace Rokojori var allBladesX = bladesX + blades; var allBladesZ = bladesZ + blades; - var numDebugs = 0; - for ( int i = 0; i < allBladesX; i++ ) { var x = ( i + 0.5f ) * cellSizeX; diff --git a/Runtime/Procedural/Mesh/MeshCombiner.cs b/Runtime/Procedural/Mesh/MeshCombiner.cs index b9891b8..fe8737a 100644 --- a/Runtime/Procedural/Mesh/MeshCombiner.cs +++ b/Runtime/Procedural/Mesh/MeshCombiner.cs @@ -146,8 +146,7 @@ namespace Rokojori this.LogInfo( "Combining", _surfaces.Count, "meshes" ); var index = 0; - var nm = 0; - var max = 100; + _materials.ForEach( ( m )=> { diff --git a/Runtime/Sensors/Default-Sensors/PC/Default-Sensors-PC.tres b/Runtime/Sensors/Default-Sensors/PC/Default-Sensors-PC.tres index c97d32f..05a93a7 100644 --- a/Runtime/Sensors/Default-Sensors/PC/Default-Sensors-PC.tres +++ b/Runtime/Sensors/Default-Sensors/PC/Default-Sensors-PC.tres @@ -1,4 +1,4 @@ -[gd_resource type="Resource" script_class="SensorGroup" load_steps=11 format=3 uid="uid://c5rvf5v86ybks"] +[gd_resource type="Resource" script_class="SensorGroup" load_steps=13 format=3 uid="uid://c5rvf5v86ybks"] [ext_resource type="Script" path="res://addons/rokojori_action_library/Runtime/Sensors/SensorGroup.cs" id="1_eh8lb"] [ext_resource type="Resource" uid="uid://ci42d04kv03yx" path="res://addons/rokojori_action_library/Runtime/Sensors/Default-Sensors/PC/Mouse Button Left.tres" id="2_7ixeu"] @@ -10,7 +10,9 @@ [ext_resource type="Resource" uid="uid://cwoisyc1in6ew" path="res://addons/rokojori_action_library/Runtime/Sensors/Default-Sensors/PC/Mouse Editor Camera/Move Back.tres" id="8_iju1w"] [ext_resource type="Resource" uid="uid://dfrnedeefk0qk" path="res://addons/rokojori_action_library/Runtime/Sensors/Default-Sensors/PC/Mouse Editor Camera/Move Left.tres" id="9_d7wj5"] [ext_resource type="Resource" uid="uid://cbsltqawsp4yy" path="res://addons/rokojori_action_library/Runtime/Sensors/Default-Sensors/PC/Mouse Editor Camera/Move Right.tres" id="10_3fc02"] +[ext_resource type="Resource" uid="uid://ds1rrltuj0mse" path="res://addons/rokojori_action_library/Runtime/Sensors/Default-Sensors/PC/Mouse Editor Camera/Move Up.tres" id="11_is0bq"] +[ext_resource type="Resource" uid="uid://dwigqkllvj8dq" path="res://addons/rokojori_action_library/Runtime/Sensors/Default-Sensors/PC/Mouse Editor Camera/Move Down.tres" id="12_rvojt"] [resource] script = ExtResource("1_eh8lb") -sensors = [ExtResource("2_7ixeu"), ExtResource("3_03o43"), ExtResource("4_v0fjp"), ExtResource("5_dks5x"), ExtResource("6_l4cqu"), ExtResource("7_0kr2e"), ExtResource("8_iju1w"), ExtResource("9_d7wj5"), ExtResource("10_3fc02")] +sensors = [ExtResource("2_7ixeu"), ExtResource("3_03o43"), ExtResource("4_v0fjp"), ExtResource("5_dks5x"), ExtResource("6_l4cqu"), ExtResource("7_0kr2e"), ExtResource("8_iju1w"), ExtResource("9_d7wj5"), ExtResource("10_3fc02"), ExtResource("11_is0bq"), ExtResource("12_rvojt")] diff --git a/Runtime/Sensors/Default-Sensors/PC/Mouse Editor Camera/Move Down.tres b/Runtime/Sensors/Default-Sensors/PC/Mouse Editor Camera/Move Down.tres new file mode 100644 index 0000000..a4b81d0 --- /dev/null +++ b/Runtime/Sensors/Default-Sensors/PC/Mouse Editor Camera/Move Down.tres @@ -0,0 +1,16 @@ +[gd_resource type="Resource" script_class="KeySensor" load_steps=2 format=3 uid="uid://dwigqkllvj8dq"] + +[ext_resource type="Script" path="res://addons/rokojori_action_library/Runtime/Sensors/KeySensor.cs" id="1_7vkga"] + +[resource] +script = ExtResource("1_7vkga") +key = 81 +ctrlHold = 2 +altHold = 2 +shiftHold = 2 +modifiersMode = 0 +continous = false +_value = 0.0 +_wasActive = false +_active = false +_activeTreshold = 0.5 diff --git a/Runtime/Sensors/Default-Sensors/PC/Mouse Editor Camera/Move Forward.tres b/Runtime/Sensors/Default-Sensors/PC/Mouse Editor Camera/Move Forward.tres index 788bae1..12cbc98 100644 --- a/Runtime/Sensors/Default-Sensors/PC/Mouse Editor Camera/Move Forward.tres +++ b/Runtime/Sensors/Default-Sensors/PC/Mouse Editor Camera/Move Forward.tres @@ -4,7 +4,7 @@ [resource] script = ExtResource("1_jess7") -key = 68 +key = 87 ctrlHold = 2 altHold = 2 shiftHold = 2 diff --git a/Runtime/Sensors/Default-Sensors/PC/Mouse Editor Camera/Move Left.tres b/Runtime/Sensors/Default-Sensors/PC/Mouse Editor Camera/Move Left.tres index 026c7ab..f94982f 100644 --- a/Runtime/Sensors/Default-Sensors/PC/Mouse Editor Camera/Move Left.tres +++ b/Runtime/Sensors/Default-Sensors/PC/Mouse Editor Camera/Move Left.tres @@ -4,7 +4,7 @@ [resource] script = ExtResource("1_1s7kb") -key = 0 +key = 65 ctrlHold = 2 altHold = 2 shiftHold = 2 diff --git a/Runtime/Sensors/Default-Sensors/PC/Mouse Editor Camera/Move Up.tres b/Runtime/Sensors/Default-Sensors/PC/Mouse Editor Camera/Move Up.tres new file mode 100644 index 0000000..b7337bf --- /dev/null +++ b/Runtime/Sensors/Default-Sensors/PC/Mouse Editor Camera/Move Up.tres @@ -0,0 +1,16 @@ +[gd_resource type="Resource" script_class="KeySensor" load_steps=2 format=3 uid="uid://ds1rrltuj0mse"] + +[ext_resource type="Script" path="res://addons/rokojori_action_library/Runtime/Sensors/KeySensor.cs" id="1_2vgvk"] + +[resource] +script = ExtResource("1_2vgvk") +key = 69 +ctrlHold = 2 +altHold = 2 +shiftHold = 2 +modifiersMode = 0 +continous = false +_value = 0.0 +_wasActive = false +_active = false +_activeTreshold = 0.5 diff --git a/Runtime/Shading/Materials/Materials.cs b/Runtime/Shading/Materials/Materials.cs index 9dbb9e8..8db78f9 100644 --- a/Runtime/Shading/Materials/Materials.cs +++ b/Runtime/Shading/Materials/Materials.cs @@ -127,18 +127,62 @@ namespace Rokojori } + public static Material GetLastMaterial( Material material ) + { + while ( material != null ) + { + var nextMaterial = material.NextPass; + + if ( nextMaterial == null ) + { + return material; + } + + material = nextMaterial; + } + + return null; + } + + public static Material GetLastMaterialOverlay( Node node ) + { + if ( node is GeometryInstance3D gi ) + { + return GetLastMaterial( gi.MaterialOverlay ); + } + + return null; + } + + public static Material GetPreviousPass( Material firstMaterial, Material nextMaterial ) + { + var material = firstMaterial; + + while ( material != null ) + { + if ( material.NextPass == nextMaterial ) + { + return material; + } + + material = material.NextPass; + } + + return null; + } + + public static void AddOverlay( Node node, Material material, bool forceTop = true ) { - if ( node is GeometryInstance3D gi ) + if ( node is GeometryInstance3D gi ) { if ( gi.MaterialOverlay == null || forceTop ) { gi.MaterialOverlay = material; + return; } - else - { - gi.MaterialOverlay.NextPass = material; - } + + GetLastMaterial( gi.MaterialOverlay ).NextPass = material; return; } @@ -148,26 +192,14 @@ namespace Rokojori { if ( node is GeometryInstance3D gi ) { - if ( forceTop ) + if ( gi.MaterialOverlay == material || forceTop ) { gi.MaterialOverlay = null; } - else if ( gi.MaterialOverlay == material ) - { - gi.MaterialOverlay = gi.MaterialOverlay.NextPass; - } else { - var mo = gi.MaterialOverlay; - - while ( mo != null && mo.NextPass != material ) - { - mo = mo.NextPass; - } - - var next = material.NextPass; - - mo.NextPass = next; + var previous = GetPreviousPass( gi.MaterialOverlay, material ); + previous.NextPass = null; } return; diff --git a/Runtime/Shading/Shaders/Effects/FancyOutline/FancyOutline Scan White 500ms 20x.material b/Runtime/Shading/Shaders/Effects/FancyOutline/FancyOutline Scan White 500ms 20x.material new file mode 100644 index 0000000000000000000000000000000000000000..fd8b345d4cc32a3a6c0f898edd2aed00e6b0349a GIT binary patch literal 522 zcmV+l0`>h;Q$s@n000005C8!50{{T>0RR9fwJ-f(^a4c>0OnUxJy30u4lvUwN#Rkp z&Ge?+n3>@Y)U-fkmyc}O4JKP_a`&aDQOTCqqHfxTvF_ZdYJ*cZhGzfghi!x&HU&EX zKL9@f%KtCkiQ8{mTCI&auAF3zD=UNR#pRMcx0Lntp!R=?0T3LX5G5W)+~u~$1Zi!# ziT-c=ulPUtAK(uYW)n569V31l(@pJxbmFp<-hUa50QQ=f{GpOBN}7?ozpK zSeW3iX^2bJ8kLis(t`gj4q-|wiUc1DMy8nz1qE9*yh=G6d4g1@vqRP`mTUWAco|+R z$gj0jssnERQ#?xBtf@*7 shader = new CachedResource( + "res://addons/rokojori_action_library/Runtime/Shading/Shaders/Effects/FancyOutline/FancyOutline.gdshader" + ); + + public static readonly ColorPropertyName albedo = ColorPropertyName.Create( "albedo" ); + public static readonly FloatPropertyName size = FloatPropertyName.Create( "size" ); + public static readonly FloatPropertyName sizeCloseScale = FloatPropertyName.Create( "sizeCloseScale" ); + public static readonly FloatPropertyName sizeFarScale = FloatPropertyName.Create( "sizeFarScale" ); + public static readonly FloatPropertyName closeDistance = FloatPropertyName.Create( "closeDistance" ); + public static readonly FloatPropertyName farDistance = FloatPropertyName.Create( "farDistance" ); + public static readonly FloatPropertyName opacityModulationStrength = FloatPropertyName.Create( "opacityModulationStrength" ); + public static readonly FloatPropertyName opacityModulationDuration = FloatPropertyName.Create( "opacityModulationDuration" ); + public static readonly FloatPropertyName scanLineAmount = FloatPropertyName.Create( "scanLineAmount" ); + public static readonly FloatPropertyName scanLineDivisions = FloatPropertyName.Create( "scanLineDivisions" ); + public static readonly FloatPropertyName scanLineSpeed = FloatPropertyName.Create( "scanLineSpeed" ); + + } + + public partial class FancyOutlineMaterial:CustomMaterial + { + public static readonly CachedResource ScanWhite500Ms20x = CustomMaterial.Cached( + "res://addons/rokojori_action_library/Runtime/Shading/Shaders/Effects/FancyOutline/FancyOutline Scan White 500ms 20x.material" + ); + + public readonly CustomMaterialProperty albedo; + public readonly CustomMaterialProperty size; + public readonly CustomMaterialProperty sizeCloseScale; + public readonly CustomMaterialProperty sizeFarScale; + public readonly CustomMaterialProperty closeDistance; + public readonly CustomMaterialProperty farDistance; + public readonly CustomMaterialProperty opacityModulationStrength; + public readonly CustomMaterialProperty opacityModulationDuration; + public readonly CustomMaterialProperty scanLineAmount; + public readonly CustomMaterialProperty scanLineDivisions; + public readonly CustomMaterialProperty scanLineSpeed; + + public FancyOutlineMaterial() + { + Shader = FancyOutline.shader.Get(); + + albedo = new CustomMaterialProperty( this, FancyOutline.albedo ); + size = new CustomMaterialProperty( this, FancyOutline.size ); + sizeCloseScale = new CustomMaterialProperty( this, FancyOutline.sizeCloseScale ); + sizeFarScale = new CustomMaterialProperty( this, FancyOutline.sizeFarScale ); + closeDistance = new CustomMaterialProperty( this, FancyOutline.closeDistance ); + farDistance = new CustomMaterialProperty( this, FancyOutline.farDistance ); + opacityModulationStrength = new CustomMaterialProperty( this, FancyOutline.opacityModulationStrength ); + opacityModulationDuration = new CustomMaterialProperty( this, FancyOutline.opacityModulationDuration ); + scanLineAmount = new CustomMaterialProperty( this, FancyOutline.scanLineAmount ); + scanLineDivisions = new CustomMaterialProperty( this, FancyOutline.scanLineDivisions ); + scanLineSpeed = new CustomMaterialProperty( this, FancyOutline.scanLineSpeed ); + } + + } + +} \ No newline at end of file diff --git a/Runtime/Shading/Shaders/Effects/FancyOutline/FancyOutline.gdshader b/Runtime/Shading/Shaders/Effects/FancyOutline/FancyOutline.gdshader new file mode 100644 index 0000000..4d1de39 --- /dev/null +++ b/Runtime/Shading/Shaders/Effects/FancyOutline/FancyOutline.gdshader @@ -0,0 +1,44 @@ +shader_type spatial; +render_mode blend_mix, world_vertex_coords, depth_draw_opaque, cull_front, diffuse_burley, specular_schlick_ggx, unshaded; + +#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Math.gdshaderinc" +#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Transform.gdshaderinc" +#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Noise.gdshaderinc" + +uniform vec4 albedo : source_color; +uniform float size:hint_range(0,10) = 2; +uniform float sizeCloseScale : hint_range(0,10) = 1; +uniform float sizeFarScale : hint_range(0,10) = 0.5; +uniform float closeDistance = 20; +uniform float farDistance = 40; +uniform float opacityModulationStrength : hint_range(0,1) = 0.2; +uniform float opacityModulationDuration : hint_range(0,10) = 1; +uniform float scanLineAmount : hint_range(0,1) = 1; +uniform float scanLineDivisions = 50; +uniform float scanLineSpeed = 2; +varying vec4 appliedColor; + + +void vertex() +{ + float cameraDistance = distance( VERTEX, CAMERA_POSITION_WORLD ); + float outlineSize = size * mapClamped( cameraDistance, closeDistance, farDistance, sizeCloseScale, sizeFarScale ); + VERTEX += NORMAL * outlineSize/500.0 * cameraDistance; + + float sinTime = sin( mod( TIME, opacityModulationDuration ) / opacityModulationDuration * PI * 2.0 ) / 2.0; + float alpha = 1.0 - opacityModulationStrength * 0.5 + sinTime * opacityModulationStrength; + + appliedColor = albedo; + appliedColor.a *= alpha; + +} + +void fragment() +{ + vec2 sceenUV = SCREEN_UV; + float scanline = mix( 1, mod( sceenUV.y * scanLineDivisions - TIME * scanLineSpeed, 1.0 ), scanLineAmount ); + + + ALBEDO = appliedColor.rgb; + ALPHA = appliedColor.a * scanline; +} diff --git a/Runtime/Shading/Shaders/Effects/Outline/Outline Thin White.material b/Runtime/Shading/Shaders/Effects/Outline/Outline Thin White.material index 6bd4ff728bbf1491e8f1eb9fc6547d5706f2cfde..d80e831dd1004551e73bca70c2675e1721fc6bc4 100644 GIT binary patch literal 457 zcmV;)0XF_pQ$s@n000005C8z20{{TA0RR9fwJ-f(oB}-!02WnAJz!~*4xk{QFyzm` zAc*RkBpC)`sAQLn?9Gis$Tms4%*;UxXK=KI*(TNlWl3E=!tFcidweuB{5E{FC2rM-or}aE#y>lyVwVM1dxs+5?*H?y`Ahf|kfo)G>N6K{4hQ% zU~p;hwy-dE*p4`W$rM^CbYQhaJjEL3-&!zZ$;PM@=D8aN)M^5)TZ=f-L-Rd1-P-?yL1yaNz+P3SltWD}v0{ z;t5F|R%&e!zXl^ur;R&$#E;la!dO+x7=`TkAMkl`yQwww@O4n907B5jn$u0!-zeA}i7k zkO_SmSLUue3qd;OH=`Av@mP_;fx&H|747s8VF1olPAPa`S3*3+I?TgbFk>3W$Q0&t z+hbaxTN4(o*w=N*w1EU+0ehyb5OaqhZ9({fnvLtlW}~{i+Ew!6UMB#hY_{Qu8x$5& GQ$s_ZM7d}H diff --git a/Runtime/Shading/Shaders/Effects/Outline/Outline.cs b/Runtime/Shading/Shaders/Effects/Outline/Outline.cs index 89e2d05..83f2828 100644 --- a/Runtime/Shading/Shaders/Effects/Outline/Outline.cs +++ b/Runtime/Shading/Shaders/Effects/Outline/Outline.cs @@ -14,6 +14,9 @@ namespace Rokojori public static readonly FloatPropertyName sizeFarScale = FloatPropertyName.Create( "sizeFarScale" ); public static readonly FloatPropertyName closeDistance = FloatPropertyName.Create( "closeDistance" ); public static readonly FloatPropertyName farDistance = FloatPropertyName.Create( "farDistance" ); + public static readonly FloatPropertyName opacityModulationStrength = FloatPropertyName.Create( "opacityModulationStrength" ); + public static readonly FloatPropertyName opacityModulationDuration = FloatPropertyName.Create( "opacityModulationDuration" ); + public static readonly FloatPropertyName opacityModulationOffset = FloatPropertyName.Create( "opacityModulationOffset" ); } @@ -32,6 +35,9 @@ namespace Rokojori public readonly CustomMaterialProperty sizeFarScale; public readonly CustomMaterialProperty closeDistance; public readonly CustomMaterialProperty farDistance; + public readonly CustomMaterialProperty opacityModulationStrength; + public readonly CustomMaterialProperty opacityModulationDuration; + public readonly CustomMaterialProperty opacityModulationOffset; public OutlineMaterial() { @@ -43,6 +49,9 @@ namespace Rokojori sizeFarScale = new CustomMaterialProperty( this, Outline.sizeFarScale ); closeDistance = new CustomMaterialProperty( this, Outline.closeDistance ); farDistance = new CustomMaterialProperty( this, Outline.farDistance ); + opacityModulationStrength = new CustomMaterialProperty( this, Outline.opacityModulationStrength ); + opacityModulationDuration = new CustomMaterialProperty( this, Outline.opacityModulationDuration ); + opacityModulationOffset = new CustomMaterialProperty( this, Outline.opacityModulationOffset ); } } diff --git a/Runtime/Shading/Shaders/Effects/Outline/Outline.gdshader b/Runtime/Shading/Shaders/Effects/Outline/Outline.gdshader index 9a1655d..6146965 100644 --- a/Runtime/Shading/Shaders/Effects/Outline/Outline.gdshader +++ b/Runtime/Shading/Shaders/Effects/Outline/Outline.gdshader @@ -11,17 +11,26 @@ uniform float sizeCloseScale : hint_range(0,10) = 1; uniform float sizeFarScale : hint_range(0,10) = 0.5; uniform float closeDistance = 20; uniform float farDistance = 40; +uniform float opacityModulationStrength : hint_range(0,1) = 0.2; +uniform float opacityModulationDuration : hint_range(0,10) = 1; +varying vec4 appliedColor; void vertex() { float cameraDistance = distance( VERTEX, CAMERA_POSITION_WORLD ); float outlineSize = size * mapClamped( cameraDistance, closeDistance, farDistance, sizeCloseScale, sizeFarScale ); VERTEX += NORMAL * outlineSize/500.0 * cameraDistance; + + float sinTime = sin( mod( TIME, opacityModulationDuration ) / opacityModulationDuration * PI * 2.0 ) / 2.0; + float alpha = 1.0 - opacityModulationStrength * 0.5 + sinTime * opacityModulationStrength; + + appliedColor = albedo ; + appliedColor.a *= alpha; } void fragment() { - ALBEDO = albedo.rgb; - ALPHA = albedo.a; + ALBEDO = appliedColor.rgb; + ALPHA = appliedColor.a; } diff --git a/Runtime/Shading/Shaders/Effects/Overlay/Overlay.cs b/Runtime/Shading/Shaders/Effects/Overlay/Overlay.cs new file mode 100644 index 0000000..1dcfc67 --- /dev/null +++ b/Runtime/Shading/Shaders/Effects/Overlay/Overlay.cs @@ -0,0 +1,36 @@ +using Godot; + +namespace Rokojori +{ + public class Overlay + { + public static readonly CachedResource shader = new CachedResource( + "res://addons/rokojori_action_library/Runtime/Shading/Shaders/Effects/Overlay/Overlay.gdshader" + ); + + public static readonly ColorPropertyName albedo = ColorPropertyName.Create( "albedo" ); + public static readonly FloatPropertyName opacityModulationStrength = FloatPropertyName.Create( "opacityModulationStrength" ); + public static readonly FloatPropertyName opacityModulationDuration = FloatPropertyName.Create( "opacityModulationDuration" ); + + } + + public partial class OverlayMaterial:CustomMaterial + { + + + public readonly CustomMaterialProperty albedo; + public readonly CustomMaterialProperty opacityModulationStrength; + public readonly CustomMaterialProperty opacityModulationDuration; + + public OverlayMaterial() + { + Shader = Overlay.shader.Get(); + + albedo = new CustomMaterialProperty( this, Overlay.albedo ); + opacityModulationStrength = new CustomMaterialProperty( this, Overlay.opacityModulationStrength ); + opacityModulationDuration = new CustomMaterialProperty( this, Overlay.opacityModulationDuration ); + } + + } + +} \ No newline at end of file diff --git a/Runtime/Shading/Shaders/Effects/Overlay/Overlay.gdshader b/Runtime/Shading/Shaders/Effects/Overlay/Overlay.gdshader new file mode 100644 index 0000000..a70b6b3 --- /dev/null +++ b/Runtime/Shading/Shaders/Effects/Overlay/Overlay.gdshader @@ -0,0 +1,24 @@ +// NOTE: Shader automatically converted from Godot Engine 4.3.stable.mono's StandardMaterial3D. + +shader_type spatial; +render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_burley, specular_schlick_ggx, unshaded; + +uniform vec4 albedo : source_color; +uniform float opacityModulationStrength : hint_range(0,1) = 0.2; +uniform float opacityModulationDuration : hint_range(0,10) = 1; +varying vec4 appliedColor; + +void vertex() +{ + float sinTime = sin( mod( TIME, opacityModulationDuration ) / opacityModulationDuration * PI * 2.0 ) / 2.0; + float alpha = 1.0 - opacityModulationStrength * 0.5 + sinTime * opacityModulationStrength; + + appliedColor = albedo ; + appliedColor.a *= alpha; +} + +void fragment() +{ + ALBEDO = appliedColor.rgb; + ALPHA *= appliedColor.a; +} diff --git a/Runtime/Shading/Shaders/Effects/RainbowGlow/RainbowGlow.gdshader b/Runtime/Shading/Shaders/Effects/RainbowGlow/RainbowGlow.gdshader new file mode 100644 index 0000000..9ffe690 --- /dev/null +++ b/Runtime/Shading/Shaders/Effects/RainbowGlow/RainbowGlow.gdshader @@ -0,0 +1,48 @@ +// NOTE: Shader automatically converted from Godot Engine 4.3.stable.mono's StandardMaterial3D. + +shader_type spatial; +render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_burley, specular_schlick_ggx, unshaded; + +#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Math.gdshaderinc" +#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Transform.gdshaderinc" +#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Noise.gdshaderinc" + +uniform vec4 albedo : source_color; +uniform sampler2D texture_albedo : source_color, filter_linear_mipmap, repeat_enable; + +uniform float colorScale = 1; + +uniform float normalWrap = 1; +uniform float normalShift = 0; +uniform float weight = 1; + +uniform float normalWrap2 = 1; +uniform float normalShift2 = 0; +uniform float weight2 = 1; + +uniform float normalWrap3 = 1; +uniform float normalShift3 = 0; +uniform float weight3 = 1; + +varying vec3 worldNormal; + +void vertex() +{ + worldNormal = NORMAL * MODEL_NORMAL_MATRIX; + +} + + +void fragment() +{ + float dotP = mod( dot( worldNormal, VIEW ) * normalWrap + normalShift, 1 ); + float dotP2 = mod( dot( -NORMAL, -VIEW ) * normalWrap2 + normalShift2, 1 ); + float dotP3 = mod( dot( -NORMAL, -VIEW ) * normalWrap3 + normalShift3, 1 ); + vec4 albedo_tex = texture( texture_albedo, vec2( dotP, 0 ) ) * weight + + texture( texture_albedo, vec2( dotP2, 0 ) ) * weight2 + + texture( texture_albedo, vec2( dotP3, 0 ) ) * weight3; + + + ALBEDO = albedo.rgb * albedo_tex.rgb * colorScale; + +} diff --git a/Runtime/Shading/Tools/CSShaderClassGenerator/CSShaderClassGenerator.cs b/Runtime/Shading/Tools/CSShaderClassGenerator/CSShaderClassGenerator.cs index ea7a977..62df5cd 100644 --- a/Runtime/Shading/Tools/CSShaderClassGenerator/CSShaderClassGenerator.cs +++ b/Runtime/Shading/Tools/CSShaderClassGenerator/CSShaderClassGenerator.cs @@ -121,7 +121,17 @@ namespace Rokojori var mMap = new StringMap(); mMap[ "${materialPath}" ] = resourceParentPath + "/" + materialName + ".material"; mMap[ "${ShaderName}" ] = shaderName; - mMap[ "${csName}" ] = RegexUtility.ToValidCSName( shortName ).ToPascalCase(); + + var csName = RegexUtility.ToValidCSName( shortName ).ToPascalCase(); + + if ( System.Char.IsDigit( csName[ 0 ] ) ) + { + csName = "_" + csName; + } + + mMap[ "${csName}" ] = csName; + + presets.Add( mMap.ReplaceAll( declaration ) ); } diff --git a/Runtime/Structures/MapList.cs b/Runtime/Structures/MapList.cs index 5f36989..f4b8d5e 100644 --- a/Runtime/Structures/MapList.cs +++ b/Runtime/Structures/MapList.cs @@ -10,14 +10,7 @@ namespace Rokojori { public class MapList:Map> { - public void ForEach( Action> callback ) - { - foreach ( var vk in this ) - { - callback( vk.Key, vk.Value ); - } - } - + public void Add( K key, V value ) { if ( ! ContainsKey( key ) ) diff --git a/Runtime/Text/RegexUtility.cs b/Runtime/Text/RegexUtility.cs index a8ffa34..253fb2a 100644 --- a/Runtime/Text/RegexUtility.cs +++ b/Runtime/Text/RegexUtility.cs @@ -510,7 +510,7 @@ namespace Rokojori public static string ToValidCSName( string source) { - var output = new StringBuilder(); + var output = new StringBuilder(); for ( int i = 0; i < source.Length; i++) { diff --git a/Runtime/Time/SetTimeLineSpeed.cs b/Runtime/Time/SetTimeLineSpeed.cs index 3bc3684..867f9e2 100644 --- a/Runtime/Time/SetTimeLineSpeed.cs +++ b/Runtime/Time/SetTimeLineSpeed.cs @@ -14,9 +14,9 @@ namespace Rokojori public float speed = 1; protected override void _OnTrigger() - { - var tm = Unique.Get(); - tm.SetSpeed( timeline, speed ); + { + timeline = TimeLineManager.Ensure( timeline ); + timeline.runner.speed = speed; } } diff --git a/Runtime/Time/TImeLineManager_Scheduling.cs b/Runtime/Time/TImeLineManager_Scheduling.cs new file mode 100644 index 0000000..a76a7ee --- /dev/null +++ b/Runtime/Time/TImeLineManager_Scheduling.cs @@ -0,0 +1,76 @@ + +using System.Diagnostics; +using System.Collections; +using System.Collections.Generic; +using System; +using Godot; + + +namespace Rokojori +{ + public partial class TimeLineManager:NetworkNode + { + public static void RemoveEvent( TimeLine timeline, int id ) + { + timeline = TimeLineManager.Ensure( timeline ); + var runner = timeline.runner; + + runner.RemoveEvent( id ); + + } + + public static TimeLineEvent ScheduleEvent( TimeLine timeline, float position, Action callback ) + { + timeline = TimeLineManager.Ensure( timeline ); + var runner = timeline.runner; + var eventID = TimeLineManager.CreateID(); + + return runner._ScheduleEvent( position, eventID, false, callback ); + } + + public static TimeLineEvent ScheduleEventIn( TimeLine timeline, float offset, Action callback ) + { + timeline = TimeLineManager.Ensure( timeline ); + var runner = timeline.runner; + var position = timeline.position + offset; + var eventID = TimeLineManager.CreateID(); + + return runner._ScheduleEvent( position, eventID, false, callback ); + } + + public static TimeLineEvent ScheduleLoopEvent( TimeLine timeline, float duration, float offset, Action callback ) + { + timeline = TimeLineManager.Ensure( timeline ); + var runner = timeline.runner; + var eventID = TimeLineManager.CreateID(); + + return runner._ScheduleLoopEvent( duration, offset, eventID, false, callback ); + } + + + public static TimeLineSpan ScheduleSpan( TimeLine timeline, float start, float end, Action callback ) + { + timeline = TimeLineManager.Ensure( timeline ); + var runner = timeline.runner; + var spanID = TimeLineManager.CreateID(); + var duration = end - start; + + return runner._ScheduleSpan( start, end, spanID, false, callback ); + } + + public static TimeLineSpan ScheduleSpanIn( TimeLine timeline, float delay, float duration, Action callback ) + { + timeline = TimeLineManager.Ensure( timeline ); + var runner = timeline.runner; + + var start = timeline.position + delay; + var end = start + duration; + + var spanID = TimeLineManager.CreateID(); + + return runner._ScheduleSpan( start, end, spanID, false, callback ); + } + + + } +} \ No newline at end of file diff --git a/Runtime/Time/TimeLine.cs b/Runtime/Time/TimeLine.cs index c904194..8c4d9ad 100644 --- a/Runtime/Time/TimeLine.cs +++ b/Runtime/Time/TimeLine.cs @@ -28,37 +28,38 @@ namespace Rokojori public bool autoStart = true; - public float delta + public TimeLineRunner runner { get { - var tm = Unique.Get(); - return tm.GetRunner( this ).currentDelta; + + var tm = TimeLineManager.Get(); + + if ( tm == null ) + { + return null; + } + + return tm.GetRunner( this ); } } + + public float delta => runner == null ? 1/60f : runner.currentDelta; - public static TimeLine IfNull_ReplaceByGameTime( TimeLine other ) + public float position => runner.position; + + public float ComputePhase( float duration, float offset = 0 ) { - if ( other != null ) - { - return other; - } + var time = position + offset; - var tm = Unique.Get(); - return tm.gameTimeTimeLine; + return ( time % duration ) / duration; } - public static TimeLine IfNull_ReplaceByRealTime( TimeLine other ) + public float ComputeRange( float start, float end ) { - if ( other != null ) - { - return other; - } - - var tm = Unique.Get(); - return tm.realTimeTimeLine; + return MathX.Normalize( position, start, end ); } - + } } \ No newline at end of file diff --git a/Runtime/Time/TimeLineEvent.cs b/Runtime/Time/TimeLineEvent.cs index c1be354..e9199d5 100644 --- a/Runtime/Time/TimeLineEvent.cs +++ b/Runtime/Time/TimeLineEvent.cs @@ -16,6 +16,8 @@ namespace Rokojori public bool wasInside = false; public bool looping = false; public float loopDuration = 0; + public Action callback; + public TimeLine timeLine; public float GetNextLoopPosition( float timelinePosition ) diff --git a/Runtime/Time/TimeLineManager.cs b/Runtime/Time/TimeLineManager.cs index d12764b..bef8ade 100644 --- a/Runtime/Time/TimeLineManager.cs +++ b/Runtime/Time/TimeLineManager.cs @@ -24,9 +24,6 @@ namespace Rokojori [Export] public bool computeRealtimeWithEngineDelta; - public readonly EventSlot onEvent = new EventSlot(); - public readonly EventSlot> onSpan = new EventSlot>(); - List _runners = new List(); @@ -38,6 +35,11 @@ namespace Rokojori Initialize(); } + public static TimeLineManager Get() + { + return Unique.Get(); + } + float _lastUpdate = 0; DateTime lastUpdated = DateTime.Now; float _estimatedDelta = 0; @@ -52,12 +54,12 @@ namespace Rokojori { UpdateRealTime( delta ); - if ( gameTimeTimeLine != null ) + if ( ! Engine.IsEditorHint() && gameTimeTimeLine != null ) { - Engine.TimeScale = GetModulatedSpeed( gameTimeTimeLine ); + Engine.TimeScale = gameTimeTimeLine.runner.modulatedSpeed; } - _runners.ForEach( r => r.UpdateTimeLine( unscaledTimeDelta, this ) ); + _runners.ForEach( r => r.UpdateTimeLine( unscaledTimeDelta ) ); } @@ -70,26 +72,7 @@ namespace Rokojori { var runner = GetRunner( GetTimeLineIndex( timeline ) ); runner.Modulate( c, onReady ); - } - - public static int Tween( TimeLine timeline, float duration, Action callback ) - { - timeline = TimeLine.IfNull_ReplaceByGameTime( timeline ); - var startTime = GetPosition( timeline ); - - var spanID = TimeLineScheduler.ScheduleSpanIn( timeline, 0, duration, - ( int id, TimeLineSpanUpdateType type )=> - { - var timeNow = GetPosition( timeline ); - var elapsed = timeNow - startTime; - var phase = Mathf.Clamp( elapsed / duration, 0, 1 ); - - callback( id, type, phase ); - } - ); - - return spanID; - } + } void UpdateRealTime( double engineDelta ) { @@ -128,13 +111,26 @@ namespace Rokojori } _initialized = true; - _runners = Lists.Map( timeLines, tl => new TimeLineRunner( tl ) ); + _runners = Lists.Map( timeLines, tl => new TimeLineRunner( tl, this ) ); + } + + public static TimeLine Ensure( TimeLine timeline ) + { + if ( timeline != null ) + { + return timeline; + } + + var tm = TimeLineManager.Get(); + + return tm.gameTimeTimeLine; } public TimeLineRunner GetRunner( TimeLine timeline ) { return GetRunner( _runners.FindIndex( r => r.timeLine == timeline ) ); } + public TimeLineRunner GetRunner( int index ) { if ( index < 0 || index >= _runners.Count ) @@ -145,128 +141,17 @@ namespace Rokojori return _runners[ index ]; } - public int CreateID() - { + int _CreateID() + { _idCounter ++; return _idCounter; } - public static float GetPosition( TimeLine timeLine ) + public static int CreateID() { - var manager = Unique.Get(); - - if ( manager == null ) - { - return Time.GetTicksMsec() / 1000f; - } - - var index = Arrays.IndexOf( manager.timeLines, timeLine ); - - index = Mathf.Max( index, 0 ); - - return (float) manager.GetPosition( index ); - } - - - public static float GetPhase( TimeLine timeLine, float duration, float offset = 0 ) - { - var time = GetPosition( timeLine ) + offset; - - return ( time % duration ) / duration; - } - - public static float GetRangePhase( TimeLine timeLine, float start, float end ) - { - var time = GetPosition( timeLine ); - var normalized = MathX.Normalize( time, start, end ); - return normalized; - } - - public void ScheduleEvent( int timeLineIndex, float position, int callbackID, bool isPersistent ) - { - var runner = _runners[ timeLineIndex ]; - runner.ScheduleEvent( position, callbackID, isPersistent ); - } - - public void ScheduleLoopEvent( int timeLineIndex, float loopDuration, float loopOffset, int callbackID, bool isPersistent ) - { - var runner = _runners[ timeLineIndex ]; - runner.ScheduleLoopEvent( loopDuration, loopOffset, callbackID, isPersistent ); - } - - public void RemoveEvent( int timeLineIndex, int eventID ) - { - var runner = _runners[ timeLineIndex ]; - runner.RemoveEvent( eventID ); - } - - - public void ScheduleSpan( int timeLineIndex, float start, float end, int callbackID, bool isPersistent ) - { - var runner = _runners[ timeLineIndex ]; - runner.ScheduleSpan( start, end, callbackID, isPersistent ); - } - - public float GetLastPosition( int timeLineIndex ) - { - var runner = GetRunner( timeLineIndex ); if ( runner == null ){ return 0; } - - return runner.lastPosition; - } - - public float GetPosition( int timeLineIndex ) - { - var runner = GetRunner( timeLineIndex ); if ( runner == null ){ return 0; } - return runner.position; - } - - public void SetPosition( int timeLineIndex, float position ) - { - var runner = GetRunner( timeLineIndex ); if ( runner == null ){ return; } - runner.position = position; - } - - public double GetSpeed( int timeLineIndex ) - { - var runner = GetRunner( timeLineIndex ); if ( runner == null ){ return 1; } - return runner.speed; - } - - public float GetModulatedSpeed( TimeLine timeline ) - { - var timeLineIndex = GetTimeLineIndex( timeline ); - var runner = GetRunner( timeLineIndex ); if ( runner == null ){ return 1; } - return runner.modulatedSpeed; - } - - public float GetSpeed( TimeLine timeline ) - { - return (float) GetSpeed( GetTimeLineIndex( timeline ) ); - } - - public void SetSpeed( int timeLineIndex, float speed ) - { - var runner = GetRunner( timeLineIndex ); if ( runner == null ){ return; } - runner.speed = speed; - } - - public void SetSpeed( TimeLine timeline, float speed ) - { - SetSpeed( GetTimeLineIndex( timeline ), speed ); - } - - - - public bool GetPlayState( int timeLineIndex ) - { - var runner = GetRunner( timeLineIndex ); if ( runner == null ){ return false; } - return runner.playing; - } - - public void SetPlayState( int timeLineIndex, bool isPlaying ) - { - var runner = GetRunner( timeLineIndex ); if ( runner == null ){ return; } - runner.playing = isPlaying; + var tm = TimeLineManager.Get(); + return tm._CreateID(); } + } } \ No newline at end of file diff --git a/Runtime/Time/TimeLineRunner.cs b/Runtime/Time/TimeLineRunner.cs index 702c2b1..2ec4005 100644 --- a/Runtime/Time/TimeLineRunner.cs +++ b/Runtime/Time/TimeLineRunner.cs @@ -11,6 +11,7 @@ namespace Rokojori public class TimeLineRunner { public TimeLine timeLine; + public TimeLineManager manager; public float lastPosition = 0; public float position = 0; @@ -31,9 +32,10 @@ namespace Rokojori public float modulatedSpeed => (float)( speed * _lastModulation * deltaScale ); public float currentDelta => _currentDelta; - public TimeLineRunner( TimeLine timeLine ) + public TimeLineRunner( TimeLine timeLine, TimeLineManager manager ) { this.timeLine = timeLine; + this.manager = manager; playing = timeLine.autoStart; } @@ -51,7 +53,7 @@ namespace Rokojori modulatorOnReady = onReady; } - public void UpdateTimeLine( float realtimeDelta, TimeLineManager manager ) + public void UpdateTimeLine( float realtimeDelta ) { if ( ! playing ) { @@ -95,43 +97,33 @@ namespace Rokojori if ( isForward ) { - ProcessForward( manager ); + ProcessForward(); } } - List AddRemoval( bool isPersistent, int i, List list ) - { - if ( isPersistent ) - { - return list; - } - - if ( list == null ) - { - list = new List(); - } - - list.Add( i ); - - return list; - } - void ProcessForward( TimeLineManager manager ) + void ProcessForward() + { + ProcessEvents(); + ProcessSpans(); + + + + + } + + void ProcessEvents() { if ( requestedRemovals.Count > 0 ) { requestedRemovals.Sort(); Lists.RemoveIncreasingSortedIndices( events, requestedRemovals ); requestedRemovals.Clear(); - } + } List eventRemovals = null; - List spanRemovals = null; - - var scheduler = Unique.Get(); - for ( int i = 0; i < events.Count; i++ ) { @@ -160,36 +152,28 @@ namespace Rokojori continue; } - RJLog.Log( "Emitting:", - "last:", lastPosition, - "now:", position, - "event:", eventPosition - ); - - - - // 0 1 2 3 4 5 - // Last 3, Position 4 - // - - - // manager.EmitSignal( TimeLineManager.SignalName.OnEvent, events[ i ].id ); - manager.onEvent.DispatchEvent( events[ i ].id ); + events[ i ].callback( events[ i ] ); events[ i ].wasInside = true; } if ( eventRemovals != null ) { - eventRemovals.ForEach( ev => scheduler._RemoveEventEntry( ev ) ); Lists.RemoveIncreasingSortedIndices( events, eventRemovals ); } + + } + + void ProcessSpans() + { if ( spans.Count == 0 ) { return; } + List spanRemovals = null; + var timelineSpan = new RangeDouble( lastPosition, position ); var span = new RangeDouble( 0, 1 ); var isForward = lastPosition < position; @@ -201,13 +185,11 @@ namespace Rokojori var overlaps = timelineSpan.Overlaps( span ); - // RJLog.Log( "Span", i, overlaps, spans[ i ].id, ">>", spans[ i ].start, spans[ i ].end, "||", lastPosition, position ); - if ( ! overlaps ) { if ( spans[ i ].wasInside ) { - spanRemovals = AddRemoval( spans[ i ].persistent, i, spanRemovals ); + spanRemovals = AddRemoval( spans[ i ].persistent, i, spanRemovals ); } continue; @@ -234,18 +216,34 @@ namespace Rokojori spans[ i ].wasInside = true; - manager.onSpan.DispatchEvent( new Tuple( spans[ i ].id, spanType ) ); - // manager.EmitSignal( TimeLineManager.SignalName.OnSpan, spans[ i ].id, spanType ); + spans[ i ].callback( spans[ i ], spanType ); } - if ( spanRemovals != null ) + if ( spanRemovals != null ) { - spanRemovals.ForEach( ev => scheduler._RemoveSpanEntry( ev ) ); Lists.RemoveIncreasingSortedIndices( spans, spanRemovals ); } } + + List AddRemoval( bool isPersistent, int index, List list ) + { + if ( isPersistent ) + { + return list; + } + + if ( list == null ) + { + list = new List(); + } + + list.Add( index ); + + return list; + } + List requestedRemovals = new List(); public void RemoveEvent( int eventID ) @@ -253,18 +251,21 @@ namespace Rokojori requestedRemovals.Add( eventID ); } - - public void ScheduleEvent( float position, int callbackID, bool isPersistent ) + public TimeLineEvent _ScheduleEvent( float position, int callbackID, bool isPersistent, Action callback ) { var tle = new TimeLineEvent(); tle.position = position; tle.id = callbackID; tle.persistent = isPersistent; + tle.callback = callback; + tle.timeLine = timeLine; events.Add( tle ); + + return tle; } - public void ScheduleLoopEvent( float loopDuration, float loopOffset, int callbackID, bool isPersistent ) + public TimeLineEvent _ScheduleLoopEvent( float loopDuration, float loopOffset, int callbackID, bool isPersistent, Action callback ) { var tle = new TimeLineEvent(); tle.position = loopOffset; @@ -272,11 +273,14 @@ namespace Rokojori tle.loopDuration = loopDuration; tle.id = callbackID; tle.persistent = isPersistent; - + tle.callback = callback; + tle.timeLine = timeLine; events.Add( tle ); + + return tle; } - public void ScheduleSpan( float start, float end, int callbackID, bool isPersistent ) + public TimeLineSpan _ScheduleSpan( float start, float end, int callbackID, bool isPersistent, Action callback ) { var tse = new TimeLineSpan(); tse.start = start; @@ -284,8 +288,12 @@ namespace Rokojori tse.id = callbackID; tse.persistent = isPersistent; tse.wasInside = false; + tse.callback = callback; + tse.timeLine = timeLine; spans.Add( tse ); + + return tse; } } } \ No newline at end of file diff --git a/Runtime/Time/TimeLineScheduler.cs b/Runtime/Time/TimeLineScheduler.cs deleted file mode 100644 index 41b920c..0000000 --- a/Runtime/Time/TimeLineScheduler.cs +++ /dev/null @@ -1,167 +0,0 @@ - -using System.Diagnostics; -using System.Collections; -using System.Collections.Generic; -using System; -using Godot; - - -namespace Rokojori -{ - [GlobalClass] - public partial class TimeLineScheduler:Node - { - public static int ScheduleEventIn( TimeLine timeLine, float offset, Action action, bool persistent = false ) - { - var scheduler = Unique.Get(); - return scheduler._ScheduleEventIn( timeLine, offset, action, persistent ); - } - - int _ScheduleEventIn( TimeLine timeLine, float offset, Action action, bool persistent = false ) - { - var tm = Unique.Get(); - var tIndex = tm.GetTimeLineIndex( timeLine ); - var position = tm.GetPosition( tIndex ) + offset; - return _ScheduleEventAt( timeLine, position, action, persistent ); - } - - - public static int ScheduleEventAt( TimeLine timeLine, float position, Action action, bool persistent = false ) - { - var scheduler = Unique.Get(); - return scheduler._ScheduleEventAt( timeLine, position, action, persistent ); - } - - int _ScheduleEventAt( TimeLine timeLine, float position, Action action, bool persistent = false ) - { - AttachListeners(); - var tm = Unique.Get(); - var tIndex = tm.GetTimeLineIndex( timeLine ); - var id = tm.CreateID(); - _eventActions[ id ] = action; - tm.ScheduleEvent( tIndex, position, id, persistent ); - return id; - } - - public static int ScheduleLoopEvent( TimeLine timeLine, float loopDuration, float loopOffset, Action action, bool persistent = false ) - { - var scheduler = Unique.Get(); - return scheduler._ScheduleLoopEvent( timeLine, loopDuration, loopOffset, action, persistent ); - } - - int _ScheduleLoopEvent( TimeLine timeLine, float loopDuration, float loopOffset, Action action, bool persistent = false ) - { - AttachListeners(); - var tm = Unique.Get(); - var tIndex = tm.GetTimeLineIndex( timeLine ); - var id = tm.CreateID(); - _eventActions[ id ] = action; - tm.ScheduleLoopEvent( tIndex, loopDuration, loopOffset, id, persistent ); - return id; - } - - public static void RemoveEvent( TimeLine timeLine, int id ) - { - var tm = Unique.Get(); - var tIndex = tm.GetTimeLineIndex( timeLine ); - tm.RemoveEvent( tIndex, id ); - } - - - public static int ScheduleSpanAt( TimeLine timeLine, float start, float end, Action action, bool persistent = false ) - { - var scheduler = Unique.Get(); - return scheduler._ScheduleSpan( timeLine, start, end, action, persistent ); - } - - public static int ScheduleSpanIn( TimeLine timeLine, float offset, float duration, Action action, bool persistent = false ) - { - var scheduler = Unique.Get(); - var tm = Unique.Get(); - var tIndex = tm.GetTimeLineIndex( timeLine ); - var position = tm.GetPosition( tIndex ); - var start = position + offset; - var end = start + duration; - return scheduler._ScheduleSpan( timeLine, start, end, action, persistent ); - } - - int _ScheduleSpan( TimeLine timeLine, float start, float end, Action action, bool persistent = false ) - { - AttachListeners(); - var tm = Unique.Get(); - var tIndex = tm.GetTimeLineIndex( timeLine ); - var id = tm.CreateID(); - _spanActions[ id ] = action; - tm.ScheduleSpan( tIndex, start, end, id, persistent ); - return id; - } - - bool _listenersAttached = false; - - - HashSet _persistentEventsAndSpans = new HashSet(); - Dictionary> _eventActions = new Dictionary>(); - Dictionary> _spanActions = new Dictionary>(); - - - void AttachListeners() - { - if ( _listenersAttached ) - { - return; - } - - _listenersAttached = true; - - var tm = Unique.Get(); - - tm.onEvent.AddAction( - ( id )=> - { - OnEvent( id ); - } - ); - - tm.onSpan.AddAction( - ( t )=> - { - OnSpan( t.Item1 , t.Item2 ); - } - ); - } - - public void _RemoveEventEntry( int id ) - { - _eventActions.Remove( id ); - } - - public void _RemoveSpanEntry( int id ) - { - _spanActions.Remove( id ); - } - - - - void OnEvent( int id ) - { - if ( ! _eventActions.ContainsKey( id ) ) - { - return; - } - - _eventActions[ id ]( id ); - - } - - void OnSpan( int id, TimeLineSpanUpdateType type ) - { - if ( ! _spanActions.ContainsKey( id ) ) - { - return; - } - - _spanActions[ id ]( id, type ); - - } - } -} \ No newline at end of file diff --git a/Runtime/Time/TimeLineSpan.cs b/Runtime/Time/TimeLineSpan.cs index 77ae2e1..59c12bc 100644 --- a/Runtime/Time/TimeLineSpan.cs +++ b/Runtime/Time/TimeLineSpan.cs @@ -16,11 +16,6 @@ namespace Rokojori CompletelyInside } - public class TimeLineSpanUpdate - { - public TimeLineSpan span; - public TimeLineSpanUpdate type; - } public class TimeLineSpan { @@ -29,5 +24,19 @@ namespace Rokojori public float start; public float end; public bool wasInside = false; + public TimeLine timeLine; + + public Action callback; + + public float duration => end - start; + + public float phase + { + get + { + var position = timeLine.position; + return Mathf.Clamp( ( position - start ) / duration, 0, 1 ); + } + } } } \ No newline at end of file diff --git a/Runtime/Tools/Lists.cs b/Runtime/Tools/Lists.cs index b95c5b7..db96307 100644 --- a/Runtime/Tools/Lists.cs +++ b/Runtime/Tools/Lists.cs @@ -217,7 +217,8 @@ namespace Rokojori { for ( var i = increasinglySortedRemovals.Count - 1; i >= 0; i-- ) { - list.RemoveAt( i ); + var index = increasinglySortedRemovals[ i ]; + list.RemoveAt( index ); } } diff --git a/Runtime/UI/Styling/UIColor.cs b/Runtime/UI/Styling/UIColor.cs index 026eb0f..00f2ebc 100644 --- a/Runtime/UI/Styling/UIColor.cs +++ b/Runtime/UI/Styling/UIColor.cs @@ -75,7 +75,7 @@ namespace Rokojori { var transitionSettings = UIStyle.GetTransitionSettings( container, property ); propertyTransition.timeLine = transitionSettings.timeLine; - propertyTransition.start = TimeLineManager.GetPosition( transitionSettings.timeLine ); + propertyTransition.start = transitionSettings.timeLine.position; propertyTransition.end = propertyTransition.start + transitionSettings.duration; propertyTransition.transitioning = true; propertyTransition.curve = transitionSettings.curve; @@ -90,7 +90,7 @@ namespace Rokojori var computedTransitionValue = Compute( control, propertyTransition.value, defaultColor ); - var transitionPhase = TimeLineManager.GetRangePhase( propertyTransition.timeLine, propertyTransition.start, propertyTransition.end ); + var transitionPhase = propertyTransition.timeLine.ComputeRange( propertyTransition.start, propertyTransition.end ); if ( transitionPhase >= 1 ) { @@ -120,7 +120,8 @@ namespace Rokojori return color.color; } - var phase = TimeLineManager.GetPhase( color.timeLine, color.animationDuration, color.animationOffset ); + // var phase = TimeLineManager.GetPhase( color.timeLine, color.animationDuration, color.animationOffset ); + var phase = color.timeLine.ComputePhase( color.animationDuration, color.animationOffset ); var gradientColor = color.animationGradient.Sample( phase ); diff --git a/Runtime/UI/Styling/UINumber.cs b/Runtime/UI/Styling/UINumber.cs index 14af34d..fa30b99 100644 --- a/Runtime/UI/Styling/UINumber.cs +++ b/Runtime/UI/Styling/UINumber.cs @@ -170,7 +170,7 @@ namespace Rokojori { var transitionSettings = UIStyle.GetTransitionSettings( container, property ); propertyTransition.timeLine = transitionSettings.timeLine; - propertyTransition.start = TimeLineManager.GetPosition( transitionSettings.timeLine ); + propertyTransition.start = transitionSettings.timeLine.position; propertyTransition.end = propertyTransition.start + transitionSettings.duration; propertyTransition.transitioning = true; propertyTransition.curve = transitionSettings.curve; @@ -185,7 +185,7 @@ namespace Rokojori var computedTransitionValue = Compute( control, propertyTransition.value, alternative, relative ); - var transitionPhase = TimeLineManager.GetRangePhase( propertyTransition.timeLine, propertyTransition.start, propertyTransition.end ); + var transitionPhase = propertyTransition.timeLine.ComputeRange( propertyTransition.start, propertyTransition.end ); if ( transitionPhase >= 1 ) { @@ -235,7 +235,7 @@ namespace Rokojori return value; } - var phase = TimeLineManager.GetPhase( number.timeLine, number.animationDuration, number.animationOffset ); + var phase = number.timeLine.ComputePhase( number.animationDuration, number.animationOffset ); return number.animationCurve.Sample( phase ) * value; diff --git a/Runtime/UI/Transitions/ActiveStyleTransition.cs b/Runtime/UI/Transitions/ActiveStyleTransition.cs index 58cb389..079061b 100644 --- a/Runtime/UI/Transitions/ActiveStyleTransition.cs +++ b/Runtime/UI/Transitions/ActiveStyleTransition.cs @@ -46,7 +46,7 @@ namespace Rokojori { var transitionSettings = getTransitionSettings(); propertyTransition.timeLine = transitionSettings.timeLine; - propertyTransition.start = TimeLineManager.GetPosition( transitionSettings.timeLine ); + propertyTransition.start = transitionSettings.timeLine.position; propertyTransition.end = propertyTransition.start + transitionSettings.duration; propertyTransition.transitioning = true; propertyTransition.curve = transitionSettings.curve; @@ -61,7 +61,7 @@ namespace Rokojori var computedTransitionValue = computeValue( propertyTransition.value ); - var transitionPhase = TimeLineManager.GetRangePhase( propertyTransition.timeLine, propertyTransition.start, propertyTransition.end ); + var transitionPhase = propertyTransition.timeLine.ComputeRange( propertyTransition.start, propertyTransition.end ); if ( transitionPhase >= 1 ) { diff --git a/Runtime/VirtualCameras/Effects/CameraEffect.cs b/Runtime/VirtualCameras/Effects/CameraEffect.cs index 27b26a2..7476a36 100644 --- a/Runtime/VirtualCameras/Effects/CameraEffect.cs +++ b/Runtime/VirtualCameras/Effects/CameraEffect.cs @@ -56,7 +56,7 @@ namespace Rokojori void Start() { - timelineOffset = TimeLineManager.GetPosition( effect.timeline ); + timelineOffset = effect.timeline.position; randomOffsets = new List(); Arrays.ForEach( effect.animations, ( a => randomOffsets.Add( a.Randomize() ) ) ) ; @@ -64,7 +64,7 @@ namespace Rokojori public void Update() { - float timeLinePosition = TimeLineManager.GetPosition( effect.timeline ); + float timeLinePosition = effect.timeline.position; timePosition = timeLinePosition - timelineOffset; position = Vector3.Zero; diff --git a/Runtime/VirtualCameras/Effects/Presets/ScreenShake.tres b/Runtime/VirtualCameras/Effects/Presets/ScreenShake.tres new file mode 100644 index 0000000..fddb555 --- /dev/null +++ b/Runtime/VirtualCameras/Effects/Presets/ScreenShake.tres @@ -0,0 +1,61 @@ +[gd_resource type="Resource" script_class="CameraEffect" load_steps=10 format=3 uid="uid://uyuplc6hm25j"] + +[ext_resource type="Script" path="res://addons/rokojori_action_library/Runtime/VirtualCameras/Effects/CameraEffect.cs" id="1_5l6xm"] +[ext_resource type="Script" path="res://addons/rokojori_action_library/Runtime/VirtualCameras/Effects/CameraEffectTargetAnimationCurve.cs" id="1_x21rf"] +[ext_resource type="Resource" uid="uid://ch5nsa6yafs5l" path="res://addons/rokojori_action_library/Runtime/Time/TimeLines/GameTime.tres" id="3_lfgu3"] + +[sub_resource type="Curve" id="Curve_62jxv"] +min_value = -1.0 +_data = [Vector2(0, 0), 0.0, 5.72558, 0, 1, Vector2(0.0625, 0.357849), 0.0, 0.0, 0, 0, Vector2(0.231707, -0.252644), 0.0, 0.0, 0, 0, Vector2(0.429878, 0.113984), 0.0, 0.0, 0, 0, Vector2(1, 0), -0.199929, 0.0, 1, 0] +point_count = 5 + +[sub_resource type="Resource" id="Resource_esvga"] +script = ExtResource("1_x21rf") +target = 0 +flipScaleYRandomly = true +duration = 0.2 +durationRandomRange = 0.0 +delay = 0.0 +delayRandomRange = 0.0 +curve = SubResource("Curve_62jxv") +scaleY = 0.1 +scaleRandomRange = 0.2 + +[sub_resource type="Curve" id="Curve_h7nko"] +min_value = -1.0 +_data = [Vector2(0, 0), 0.0, -2.46399, 0, 1, Vector2(0.170732, -0.420681), 0.0, 0.0, 0, 0, Vector2(0.271341, 0.388954), 0.0, 0.0, 0, 0, Vector2(0.503049, -0.130435), 0.0, 0.0, 0, 0, Vector2(0.689024, 0.0223267), 0.0, 0.0, 0, 0, Vector2(1, 0), -0.0717957, 0.0, 1, 0] +point_count = 6 + +[sub_resource type="Resource" id="Resource_s8na2"] +script = ExtResource("1_x21rf") +target = 1 +flipScaleYRandomly = false +duration = 0.2 +durationRandomRange = 0.0 +delay = 0.0 +delayRandomRange = 0.0 +curve = SubResource("Curve_h7nko") +scaleY = 0.1 +scaleRandomRange = 0.2 + +[sub_resource type="Curve" id="Curve_opp1p"] +min_value = -1.0 +_data = [Vector2(0, 0), 0.0, 3.46886, 0, 1, Vector2(0.0945122, 0.32785), 0.0, 0.0, 0, 0, Vector2(1, 0), -0.36207, 0.0, 1, 0] +point_count = 3 + +[sub_resource type="Resource" id="Resource_wlebh"] +script = ExtResource("1_x21rf") +target = 6 +flipScaleYRandomly = true +duration = 0.3 +durationRandomRange = 0.0 +delay = 0.0 +delayRandomRange = 0.0 +curve = SubResource("Curve_opp1p") +scaleY = 10.0 +scaleRandomRange = 0.0 + +[resource] +script = ExtResource("1_5l6xm") +animations = [SubResource("Resource_esvga"), SubResource("Resource_s8na2"), SubResource("Resource_wlebh")] +timeline = ExtResource("3_lfgu3")