From af3786e6b4815c339b744c35211f8333ccf89f7d Mon Sep 17 00:00:00 2001 From: Josef Date: Wed, 21 May 2025 22:44:28 +0200 Subject: [PATCH] Player/Camera Updates --- .../Animation/Highlight/HighlightEffect.cs | 4 +- .../Presets/White Outline - Highlight.tres | 2 +- Runtime/Animation/Smoothing/ExpSmoothing.cs | 12 +- Runtime/Animation/Smoothing/FrameSmoothing.cs | 6 +- .../Smoothing/FrameSmoothingTable.cs | 1661 +++++++++++++++-- .../Smoothing/FrameSmoothingTableGenerator.cs | 19 +- Runtime/Animation/Smoothing/Smoothing.cs | 88 +- Runtime/App/App.cs | 14 + Runtime/Files/FilesSync.cs | 5 + Runtime/Godot/Nodes.cs | 10 + Runtime/Interactions/Caster.cs | 2 +- .../CharacterController.cs | 21 +- .../CharacterControllerAction.cs | 1 + .../CharacterController/CharacterMovement.cs | 133 +- .../CharacterDirectionProcessing.cs | 14 + .../CharacterDirectionProcessing.cs.uid | 1 + .../CharacterMovementData.cs | 23 + .../CharacterMovementData.cs.uid | 1 + .../CharacterMovementType.cs | 17 + .../CharacterMovementType.cs.uid | 1 + .../CharacterMovements/StrafeMovementType.cs | 78 + .../StrafeMovementType.cs.uid | 1 + .../CharacterMovements/TurnMovementType.cs | 105 ++ .../TurnMovementType.cs.uid | 1 + .../CharacterController/Gravity.cs | 1 + .../CharacterController/GroundReset.cs | 1 + .../Interactions/CharacterController/Jump.cs | 66 +- .../CharacterController/MoveAndSlide.cs | 1 + Runtime/Interactions/Grabber.cs | 19 +- Runtime/Interactions/MultiRayCaster.cs | 13 +- Runtime/Interactions/Pointer.cs | 4 +- Runtime/Math/Math3D.cs | 64 +- Runtime/Math/MathX.cs | 26 + .../Procedural/Parametric/Cuboid/Cuboid.cs | 25 +- ...sitive.tres => Left-Joystick Down +Y.tres} | 0 ...gative.tres => Left-Joystick Left -X.tres} | 0 ...itive.tres => Left-Joystick Right +X.tres} | 0 ...Negative.tres => Left-Joystick Up -Y.tres} | 4 +- ...itive.tres => Right-Joystick Down +Y.tres} | 0 ...ative.tres => Right-Joystick Left -X.tres} | 0 ...tive.tres => Right-Joystick Right +X.tres} | 0 .../Gamepad/Axis/Right-Joystick Up -Y.tres | 9 + .../Axis/Right-Joystick Y-Negative.tres | 13 - .../Buttons/Button X, PS Square, Nin Y.tres | 8 +- .../Buttons/Button Y, PS Triangle, Nin X.tres | 8 +- .../Gamepad/Default - GamePad.tres | 18 +- Runtime/Sensors/HoldSensor.cs | 75 + Runtime/Sensors/HoldSensor.cs.uid | 1 + Runtime/Sensors/Sensor.cs | 13 +- Runtime/Sensors/SensorManager.cs | 48 +- Runtime/Sensors/SensorViewer.cs | 32 + Runtime/Sensors/SensorViewer.cs.uid | 1 + Runtime/Sensors/Sensors.cs | 18 + Runtime/Sensors/TriggerOnSensor.cs | 4 +- Runtime/Shading/Library/Math.gdshaderinc | 15 + Runtime/Shading/Library/Noise.gdshaderinc | 81 +- Runtime/Sorting/MinMaxSearch.cs | 3 +- Runtime/Tools/Async.cs | 14 + Runtime/Tools/Safe.cs | 2 +- Runtime/VirtualCameras/CameraTargetOffset.cs | 53 + .../VirtualCameras/CameraTargetOffset.cs.uid | 1 + Runtime/VirtualCameras/ThirdPersonCamera.cs | 148 +- .../ThirdPersonCameraTargetOffset.cs | 39 + .../ThirdPersonCameraTargetOffset.cs.uid | 1 + .../VirtualCameras/VirtualCamera3DManager.cs | 1 + 65 files changed, 2619 insertions(+), 431 deletions(-) create mode 100644 Runtime/Interactions/CharacterController/CharacterMovements/CharacterDirectionProcessing.cs create mode 100644 Runtime/Interactions/CharacterController/CharacterMovements/CharacterDirectionProcessing.cs.uid create mode 100644 Runtime/Interactions/CharacterController/CharacterMovements/CharacterMovementData.cs create mode 100644 Runtime/Interactions/CharacterController/CharacterMovements/CharacterMovementData.cs.uid create mode 100644 Runtime/Interactions/CharacterController/CharacterMovements/CharacterMovementType.cs create mode 100644 Runtime/Interactions/CharacterController/CharacterMovements/CharacterMovementType.cs.uid create mode 100644 Runtime/Interactions/CharacterController/CharacterMovements/StrafeMovementType.cs create mode 100644 Runtime/Interactions/CharacterController/CharacterMovements/StrafeMovementType.cs.uid create mode 100644 Runtime/Interactions/CharacterController/CharacterMovements/TurnMovementType.cs create mode 100644 Runtime/Interactions/CharacterController/CharacterMovements/TurnMovementType.cs.uid rename Runtime/Sensors/Default-Sensors/Gamepad/Axis/{Left-Joystick Y-Positive.tres => Left-Joystick Down +Y.tres} (100%) rename Runtime/Sensors/Default-Sensors/Gamepad/Axis/{Left-Joystick X-Negative.tres => Left-Joystick Left -X.tres} (100%) rename Runtime/Sensors/Default-Sensors/Gamepad/Axis/{Left-Joystick X-Positive.tres => Left-Joystick Right +X.tres} (100%) rename Runtime/Sensors/Default-Sensors/Gamepad/Axis/{Left-Joystick Y-Negative.tres => Left-Joystick Up -Y.tres} (61%) rename Runtime/Sensors/Default-Sensors/Gamepad/Axis/{Right-Joystick Y-Positive.tres => Right-Joystick Down +Y.tres} (100%) rename Runtime/Sensors/Default-Sensors/Gamepad/Axis/{Right-Joystick X-Negative.tres => Right-Joystick Left -X.tres} (100%) rename Runtime/Sensors/Default-Sensors/Gamepad/Axis/{Right-Joystick X-Positive.tres => Right-Joystick Right +X.tres} (100%) create mode 100644 Runtime/Sensors/Default-Sensors/Gamepad/Axis/Right-Joystick Up -Y.tres delete mode 100644 Runtime/Sensors/Default-Sensors/Gamepad/Axis/Right-Joystick Y-Negative.tres create mode 100644 Runtime/Sensors/HoldSensor.cs create mode 100644 Runtime/Sensors/HoldSensor.cs.uid create mode 100644 Runtime/Sensors/SensorViewer.cs create mode 100644 Runtime/Sensors/SensorViewer.cs.uid create mode 100644 Runtime/VirtualCameras/CameraTargetOffset.cs create mode 100644 Runtime/VirtualCameras/CameraTargetOffset.cs.uid create mode 100644 Runtime/VirtualCameras/ThirdPersonCameraTargetOffset.cs create mode 100644 Runtime/VirtualCameras/ThirdPersonCameraTargetOffset.cs.uid diff --git a/Runtime/Animation/Highlight/HighlightEffect.cs b/Runtime/Animation/Highlight/HighlightEffect.cs index 3ae701f..207c0a3 100644 --- a/Runtime/Animation/Highlight/HighlightEffect.cs +++ b/Runtime/Animation/Highlight/HighlightEffect.cs @@ -98,7 +98,8 @@ namespace Rokojori List _active = new List(); public void Highlight( HighlightActionType type, Node3D[] targets ) - { + { + if ( HighlightActionType.Start == type ) { StartHighlight( targets ); @@ -131,6 +132,7 @@ namespace Rokojori var outlineMaterial = new OutlineMaterial(); outlineMaterial.albedo.Set( colorTransparent ); material = outlineMaterial; + outlineMaterial.size.Set( 2 ); outlineMaterial.opacityModulationDuration.Set( opacityModulationDuration ); outlineMaterial.opacityModulationStrength.Set( opacityModulationStrength ); diff --git a/Runtime/Animation/Highlight/Presets/White Outline - Highlight.tres b/Runtime/Animation/Highlight/Presets/White Outline - Highlight.tres index ccd1361..f057526 100644 --- a/Runtime/Animation/Highlight/Presets/White Outline - Highlight.tres +++ b/Runtime/Animation/Highlight/Presets/White Outline - Highlight.tres @@ -31,5 +31,5 @@ opacityModulationStrength = 0.75 opacityModulationDuration = 1.0 opacityModulationTransition = 1.0 outlineMaterialMode = 0 -overlayOpacity = 0.01 +overlayOpacity = 0.1 overlayMaterialMode = 0 diff --git a/Runtime/Animation/Smoothing/ExpSmoothing.cs b/Runtime/Animation/Smoothing/ExpSmoothing.cs index 4fb553c..377b413 100644 --- a/Runtime/Animation/Smoothing/ExpSmoothing.cs +++ b/Runtime/Animation/Smoothing/ExpSmoothing.cs @@ -23,7 +23,17 @@ namespace Rokojori return exp.ComputeDuration(); } - + + public static float ComputeCoefficientForFramesAdaptiveTreshold( int numFrames ) + { + var fps60 = 1f/60f; + var treshold = MathX.MapClamped( numFrames, 400, 600, fps60/50, fps60/2 ); + + return ComputeCoefficientForFrames( numFrames, treshold ); + + + } + public static float ComputeCoefficientForFrames( int numFrames, float treshold = 1f/60f * 0.02f ) { diff --git a/Runtime/Animation/Smoothing/FrameSmoothing.cs b/Runtime/Animation/Smoothing/FrameSmoothing.cs index 0725537..48271f8 100644 --- a/Runtime/Animation/Smoothing/FrameSmoothing.cs +++ b/Runtime/Animation/Smoothing/FrameSmoothing.cs @@ -8,12 +8,12 @@ namespace Rokojori [GlobalClass] public partial class FrameSmoothing: Smoothing { - [Export( PropertyHint.Range, "0,600")] + [Export( PropertyHint.Range, "0,1800")] public float frames = 10; protected override float _ComputeInterpolationAmount( float delta ) { - frames = Mathf.Clamp( frames, 0, 600 ); + frames = Mathf.Clamp( frames, 0, 1800 ); if ( frames <= 0 ) { @@ -36,7 +36,7 @@ namespace Rokojori public static float ComputeCoefficientInt( float delta, int frames ) { - frames = Mathf.Clamp( frames, 0, 600 ); + frames = Mathf.Clamp( frames, 0, 1800 ); if ( frames <= 0 ) { diff --git a/Runtime/Animation/Smoothing/FrameSmoothingTable.cs b/Runtime/Animation/Smoothing/FrameSmoothingTable.cs index 4737634..82d04da 100644 --- a/Runtime/Animation/Smoothing/FrameSmoothingTable.cs +++ b/Runtime/Animation/Smoothing/FrameSmoothingTable.cs @@ -1,15 +1,17 @@ using System.Collections; using System.Collections.Generic; using Godot; +using System.Threading.Tasks; namespace Rokojori { public class FrameSmoothingTable { - public const int num = 601; + public const int num = 60 * 60; public static float Get( int key ) { + key = Mathf.Clamp( key, 0, data.Length - 1 ); return data[ key ]; } @@ -19,12 +21,71 @@ namespace Rokojori for ( int i = 0; i < num; i++ ) { - computed[ i ] = ExpSmoothing.ComputeCoefficientForFrames( i ); + computed[ i ] = ExpSmoothing.ComputeCoefficientForFramesAdaptiveTreshold( i ); } FilesSync.SaveUTF8( path, Lists.Join( Lists.From( computed ), "f,\n" ) ); } + public async static Task ComputeAndSaveTable( Node node, string path, int range = 0 ) + { + range = range <= 0 ? num : range; + // var computed = new float[ FrameSmoothingTable.num ]; + + var time = Async.StartTimer(); + + var lastReportInt = 0; + + var directoryPath = FilePath.Absolute( path ); + + FilesSync.EnsureDirectoryExists( path ); + + for ( int j = 0; j < num; j+=range ) + { + + var computed = new float[ range ]; + + var filePath = directoryPath.MakeRelative( j + "-" + ( j + range ) + ".txt" ); + + if ( FilesSync.FileExists( filePath.fullPath ) ) + { + node.LogInfo( "Skipping: ", j + "-" + ( j + range ) ); + continue; + } + + node.LogInfo( "Processing: ", j + "-" + ( j + range ) ); + + bool testing = true; + + if ( testing ) + { + // continue; + } + + for ( int i = 0; i < range; i++ ) + { + computed[ i ] = ExpSmoothing.ComputeCoefficientForFramesAdaptiveTreshold( i + j ); + + time = await Async.WaitIfExceeded( time, node ); + + var currentInt = Mathf.RoundToInt( i * 100f / num ); + + if ( lastReportInt != currentInt ) + { + lastReportInt = currentInt; + node.LogInfo( Mathf.Round( i * 100f / num ) + "%", i + "/" + num ); + } + + } + + FilesSync.SaveUTF8( filePath.fullPath, Lists.Join( Lists.From( computed ), "f,\n" ) ); + } + + + + // FilesSync.SaveUTF8( path, Lists.Join( Lists.From( computed ), "f,\n" ) ); + } + static readonly float[] data = new float[] { 500f, @@ -429,205 +490,1405 @@ namespace Rokojori 0.6925272941589355f, 0.6907827854156494f, 0.689068615436554f, - 0.687347412109375f, + 0.6873651742935181f, 0.6856591105461121f, 0.683970034122467f, 0.682276725769043f, - 0.6805812120437622f, - 0.6789281964302063f, - 0.6772623658180237f, - 0.6756013631820679f, - 0.6739364862442017f, - 0.6722993850708008f, - 0.6706674098968506f, - 0.6690364480018616f, - 0.6674287915229797f, - 0.6658235192298889f, - 0.6642293334007263f, - 0.6626189351081848f, - 0.6610497236251831f, - 0.6594691276550293f, - 0.6578971147537231f, - 0.656342625617981f, - 0.6547721028327942f, - 0.6532281041145325f, - 0.6517037749290466f, - 0.6501580476760864f, - 0.6486419439315796f, - 0.6471200585365295f, - 0.6455984711647034f, - 0.6440840363502502f, - 0.6425923109054565f, - 0.6411044597625732f, - 0.6396147012710571f, - 0.6381545066833496f, - 0.6366636753082275f, - 0.6352079510688782f, - 0.6337451338768005f, - 0.6323150396347046f, - 0.6308498382568359f, - 0.6294164061546326f, - 0.6279890537261963f, - 0.6265745759010315f, - 0.6251498460769653f, - 0.6237500905990601f, - 0.6223452091217041f, - 0.6209344267845154f, - 0.6195322275161743f, - 0.6181548833847046f, - 0.6167780756950378f, - 0.6154120564460754f, - 0.6140302419662476f, - 0.6126852035522461f, - 0.6113117337226868f, - 0.6099634766578674f, - 0.6086242198944092f, - 0.6072999835014343f, - 0.6059572696685791f, - 0.6046338677406311f, - 0.6033122539520264f, - 0.6020045876502991f, - 0.6006863713264465f, - 0.5994002223014832f, - 0.5980745553970337f, - 0.5967887043952942f, - 0.5955021977424622f, - 0.5942328572273254f, - 0.5929514765739441f, - 0.5916818976402283f, - 0.5904273390769958f, - 0.5891685485839844f, - 0.5879052877426147f, - 0.5866508483886719f, - 0.5854105949401855f, - 0.5841827392578125f, - 0.5829448103904724f, - 0.5817262530326843f, - 0.5804857015609741f, - 0.5792888402938843f, - 0.5780552625656128f, - 0.5768483877182007f, - 0.5756462216377258f, - 0.5744789242744446f, - 0.5732737183570862f, - 0.5720958113670349f, - 0.5708903074264526f, - 0.5697146058082581f, - 0.5685422420501709f, - 0.5673736333847046f, - 0.5662209391593933f, - 0.5650529861450195f, - 0.5639082789421082f, - 0.5627579092979431f, - 0.5616170167922974f, - 0.5604658722877502f, - 0.5593448281288147f, - 0.558205246925354f, - 0.5570909976959229f, - 0.5559751987457275f, - 0.5548509359359741f, - 0.5537335872650146f, - 0.552649974822998f, - 0.5515282154083252f, - 0.5504438877105713f, - 0.5493456721305847f, - 0.5482402443885803f, - 0.5471789240837097f, - 0.5460887551307678f, - 0.5449970960617065f, - 0.5439370274543762f, - 0.5428534150123596f, - 0.5417964458465576f, - 0.5407297015190125f, - 0.5396756529808044f, - 0.538644552230835f, - 0.5375834703445435f, - 0.5365545749664307f, - 0.5354890823364258f, - 0.5344588160514832f, - 0.53342604637146f, - 0.5324010848999023f, - 0.5313923954963684f, - 0.5303633809089661f, - 0.5293594002723694f, - 0.5283269286155701f, - 0.5273261070251465f, - 0.5263199210166931f, - 0.5253220200538635f, - 0.5243186950683594f, - 0.5233476758003235f, - 0.5223479866981506f, - 0.5213702917098999f, - 0.5203649401664734f, - 0.5193970799446106f, - 0.5184254050254822f, - 0.5174447298049927f, - 0.516491711139679f, - 0.5155284404754639f, - 0.514551043510437f, - 0.5136093497276306f, - 0.5126588344573975f, - 0.5117171406745911f, - 0.5107676386833191f, - 0.5098287463188171f, - 0.5088873505592346f, - 0.5079407095909119f, - 0.5070165395736694f, - 0.5060779452323914f, - 0.5051640868186951f, - 0.5042357444763184f, - 0.503326952457428f, - 0.5024080872535706f, - 0.5014938712120056f, - 0.5005781054496765f, - 0.49968376755714417f, - 0.49877265095710754f, - 0.4978860020637512f, - 0.49696969985961914f, - 0.4960835874080658f, - 0.49519139528274536f, - 0.4943094551563263f, - 0.4934454560279846f, - 0.4925616383552551f, - 0.4916682839393616f, - 0.4908157289028168f, - 0.4899247884750366f, - 0.4890671372413635f, - 0.48820558190345764f, - 0.48733872175216675f, - 0.4864858090877533f, - 0.48562294244766235f, - 0.4847657382488251f, - 0.4839414954185486f, - 0.4830806255340576f, - 0.4822426438331604f, - 0.48139166831970215f, - 0.480558305978775f, - 0.47972649335861206f, - 0.4788912832736969f, - 0.4780619144439697f, - 0.47723937034606934f, - 0.47642940282821655f, - 0.4756017029285431f, - 0.47477471828460693f, - 0.4739650785923004f, - 0.4731660485267639f, - 0.4723406136035919f, - 0.4715345501899719f, - 0.47073766589164734f, - 0.4699311852455139f, - 0.46913012862205505f, - 0.4683624804019928f, - 0.46754929423332214f, - 0.46675416827201843f, - 0.4659850001335144f, - 0.4651834964752197f, - 0.4644103944301605f, - 0.46363675594329834f, - 0.46285971999168396f, - 0.4620875120162964f, - 0.4613165557384491f, - 0.4605373442173004f - }; - } + 0.6806155443191528f, + 0.6789562106132507f, + 0.6772914528846741f, + 0.6756145358085632f, + 0.6739996075630188f, + 0.6723521947860718f, + 0.6707189679145813f, + 0.6690943241119385f, + 0.667471170425415f, + 0.6658817529678345f, + 0.6642791628837585f, + 0.6627091765403748f, + 0.6610907316207886f, + 0.6595312356948853f, + 0.6579535007476807f, + 0.6563933491706848f, + 0.6548567414283752f, + 0.6533052921295166f, + 0.6517643928527832f, + 0.6502271294593811f, + 0.6487271189689636f, + 0.6471983194351196f, + 0.6456824541091919f, + 0.6441740393638611f, + 0.6427110433578491f, + 0.6412062644958496f, + 0.6397189497947693f, + 0.6382338404655457f, + 0.6368032097816467f, + 0.6353349089622498f, + 0.6338663101196289f, + 0.632414698600769f, + 0.6309645175933838f, + 0.6295638084411621f, + 0.6281326413154602f, + 0.6266577243804932f, + 0.6252782940864563f, + 0.6238624453544617f, + 0.6224457025527954f, + 0.6210411190986633f, + 0.6196972131729126f, + 0.6183050870895386f, + 0.6169123649597168f, + 0.6155316233634949f, + 0.6141581535339355f, + 0.6127851009368896f, + 0.6114739775657654f, + 0.6101250648498535f, + 0.6087701320648193f, + 0.6074327826499939f, + 0.6060886979103088f, + 0.6047580242156982f, + 0.6034865379333496f, + 0.6021608114242554f, + 0.6008508801460266f, + 0.5995306968688965f, + 0.5982363224029541f, + 0.5969292521476746f, + 0.5957053899765015f, + 0.5944206714630127f, + 0.5931257605552673f, + 0.5918459892272949f, + 0.5905752778053284f, + 0.5893149971961975f, + 0.5880455374717712f, + 0.5868629813194275f, + 0.5856124758720398f, + 0.584365963935852f, + 0.5831298828125f, + 0.5818825364112854f, + 0.5806562304496765f, + 0.5795091986656189f, + 0.5782133936882019f, + 0.5770759582519531f, + 0.5758540034294128f, + 0.5746507048606873f, + 0.5734581351280212f, + 0.572260856628418f, + 0.5711557865142822f, + 0.5699601173400879f, + 0.56878262758255f, + 0.5676038265228271f, + 0.5664293766021729f, + 0.5652664303779602f, + 0.5641055107116699f, + 0.5629429817199707f, + 0.5617981553077698f, + 0.560724675655365f, + 0.5595853328704834f, + 0.5584439039230347f, + 0.5573145747184753f, + 0.5561866164207458f, + 0.5550540685653687f, + 0.5539348125457764f, + 0.5528168678283691f, + 0.551703691482544f, + 0.5506914854049683f, + 0.5495861172676086f, + 0.5484772324562073f, + 0.5473835468292236f, + 0.5462953448295593f, + 0.5452186465263367f, + 0.5441282391548157f, + 0.5430482625961304f, + 0.5420768857002258f, + 0.5410019159317017f, + 0.5399383902549744f, + 0.5388686060905457f, + 0.5378226637840271f, + 0.5367569923400879f, + 0.5357192158699036f, + 0.5346730947494507f, + 0.5336322784423828f, + 0.5326928496360779f, + 0.5316630005836487f, + 0.530632495880127f, + 0.5296065211296082f, + 0.5285836458206177f, + 0.527567982673645f, + 0.5265474915504456f, + 0.5255448222160339f, + 0.5245286226272583f, + 0.523533046245575f, + 0.5226390957832336f, + 0.5216454267501831f, + 0.520652711391449f, + 0.5196588635444641f, + 0.5186789631843567f, + 0.5176900029182434f, + 0.5167258381843567f, + 0.5157418847084045f, + 0.5147818326950073f, + 0.5139275193214417f, + 0.5129619836807251f, + 0.5119994282722473f, + 0.5110417008399963f, + 0.5100873708724976f, + 0.509143054485321f, + 0.5081951022148132f, + 0.5072543621063232f, + 0.5063202977180481f, + 0.5053861141204834f, + 0.504448652267456f, + 0.5036346316337585f, + 0.5027136206626892f, + 0.5017893314361572f, + 0.5008748173713684f, + 0.499958872795105f, + 0.49904754757881165f, + 0.4981437027454376f, + 0.49722805619239807f, + 0.496323823928833f, + 0.4954327642917633f, + 0.49453726410865784f, + 0.4936388432979584f, + 0.49287769198417664f, + 0.49198541045188904f, + 0.491106778383255f, + 0.49022388458251953f, + 0.4893478751182556f, + 0.4884764850139618f, + 0.4875950813293457f, + 0.4867376685142517f, + 0.48586568236351013f, + 0.4850086271762848f, + 0.48428311944007874f, + 0.4834233224391937f, + 0.48257315158843994f, + 0.4817160367965698f, + 0.48087117075920105f, + 0.4800178110599518f, + 0.4791848361492157f, + 0.4783398509025574f, + 0.477504700422287f, + 0.47667381167411804f, + 0.4758389890193939f, + 0.47501859068870544f, + 0.47420215606689453f, + 0.47351062297821045f, + 0.47269147634506226f, + 0.4718797504901886f, + 0.4710562527179718f, + 0.470244437456131f, + 0.4694313108921051f, + 0.46862855553627014f, + 0.46783313155174255f, + 0.4670245349407196f, + 0.46622806787490845f, + 0.4654315114021301f, + 0.4646444320678711f, + 0.46400779485702515f, + 0.46321550011634827f, + 0.4624347388744354f, + 0.4616488814353943f, + 0.4608704447746277f, + 0.4600817561149597f, + 0.4593166410923004f, + 0.45854735374450684f, + 0.4577728509902954f, + 0.4570140838623047f, + 0.45624762773513794f, + 0.4554744064807892f, + 0.4547233581542969f, + 0.45396924018859863f, + 0.4532163143157959f, + 0.4524644613265991f, + 0.45186465978622437f, + 0.451113760471344f, + 0.45037031173706055f, + 0.44962790608406067f, + 0.4488859474658966f, + 0.4481387436389923f, + 0.44741424918174744f, + 0.44668450951576233f, + 0.4459531903266907f, + 0.4452272355556488f, + 0.4444943368434906f, + 0.44376522302627563f, + 0.4430609941482544f, + 0.4423399269580841f, + 0.44162437319755554f, + 0.44092077016830444f, + 0.44035348296165466f, + 0.43963125348091125f, + 0.43893131613731384f, + 0.43821457028388977f, + 0.4375140964984894f, + 0.43682199716567993f, + 0.4361187517642975f, + 0.43542149662971497f, + 0.4347245991230011f, + 0.43403711915016174f, + 0.4333515167236328f, + 0.43265432119369507f, + 0.43198055028915405f, + 0.43129345774650574f, + 0.43061575293540955f, + 0.42994552850723267f, + 0.42940711975097656f, + 0.42858874797821045f, + 0.4280592203140259f, + 0.4273867607116699f, + 0.42671313881874084f, + 0.42605599761009216f, + 0.42539089918136597f, + 0.4247209131717682f, + 0.4240663945674896f, + 0.42341148853302f, + 0.42275765538215637f, + 0.42209509015083313f, + 0.42143765091896057f, + 0.42080140113830566f, + 0.4201468527317047f, + 0.4194980561733246f, + 0.4188656210899353f, + 0.41821470856666565f, + 0.41772547364234924f, + 0.41709259152412415f, + 0.41644570231437683f, + 0.4158170521259308f, + 0.41517263650894165f, + 0.4145396947860718f, + 0.41391560435295105f, + 0.4132928252220154f, + 0.4126638174057007f, + 0.4120407700538635f, + 0.41142719984054565f, + 0.41079431772232056f, + 0.41018378734588623f, + 0.40957632660865784f, + 0.4089510440826416f, + 0.40834856033325195f, + 0.4077397584915161f, + 0.40713584423065186f, + 0.40653058886528015f, + 0.40591660141944885f, + 0.40545427799224854f, + 0.40484878420829773f, + 0.4042467474937439f, + 0.40365779399871826f, + 0.40306055545806885f, + 0.4024546444416046f, + 0.40186887979507446f, + 0.4012792706489563f, + 0.4006851613521576f, + 0.40009668469429016f, + 0.39951032400131226f, + 0.39892905950546265f, + 0.39835870265960693f, + 0.39776912331581116f, + 0.39719560742378235f, + 0.396615594625473f, + 0.3960385322570801f, + 0.3954774737358093f, + 0.3949020504951477f, + 0.39445599913597107f, + 0.3938904106616974f, + 0.39331844449043274f, + 0.392758309841156f, + 0.39219677448272705f, + 0.3916293978691101f, + 0.3910665214061737f, + 0.39050790667533875f, + 0.389950692653656f, + 0.3893989324569702f, + 0.38883399963378906f, + 0.38829392194747925f, + 0.38773322105407715f, + 0.3871852457523346f, + 0.3866378366947174f, + 0.3860984444618225f, + 0.3855457901954651f, + 0.38500967621803284f, + 0.3844599723815918f, + 0.3839244246482849f, + 0.3833819627761841f, + 0.3829789459705353f, + 0.3824446201324463f, + 0.3819071352481842f, + 0.38137343525886536f, + 0.38084131479263306f, + 0.3802966773509979f, + 0.37978115677833557f, + 0.3792538046836853f, + 0.37872761487960815f, + 0.3782009482383728f, + 0.377670556306839f, + 0.3771509826183319f, + 0.37663358449935913f, + 0.37611761689186096f, + 0.37560227513313293f, + 0.37509289383888245f, + 0.3745761811733246f, + 0.3740687668323517f, + 0.3735479414463043f, + 0.3730413317680359f, + 0.37265872955322266f, + 0.3720226287841797f, + 0.371643602848053f, + 0.3711407780647278f, + 0.3706258535385132f, + 0.37013667821884155f, + 0.36963024735450745f, + 0.36912256479263306f, + 0.3686225712299347f, + 0.36813730001449585f, + 0.36763039231300354f, + 0.3671342730522156f, + 0.36665064096450806f, + 0.36616051197052f, + 0.36566630005836487f, + 0.3651680648326874f, + 0.36469766497612f, + 0.364213764667511f, + 0.3637215793132782f, + 0.3632481098175049f, + 0.36276188492774963f, + 0.3624085783958435f, + 0.36179980635643005f, + 0.36132243275642395f, + 0.36096569895744324f, + 0.3604854941368103f, + 0.3600185513496399f, + 0.35954388976097107f, + 0.3590605556964874f, + 0.35858938097953796f, + 0.3581317067146301f, + 0.35764870047569275f, + 0.3571859896183014f, + 0.3567151129245758f, + 0.35624682903289795f, + 0.35578250885009766f, + 0.3553260564804077f, + 0.35486695170402527f, + 0.354401171207428f, + 0.3539525270462036f, + 0.35349583625793457f, + 0.35302644968032837f, + 0.35258957743644714f, + 0.3521282970905304f, + 0.351673424243927f, + 0.35122764110565186f, + 0.35089540481567383f, + 0.35032305121421814f, + 0.3499942719936371f, + 0.349543035030365f, + 0.3491019904613495f, + 0.3486470580101013f, + 0.348204106092453f, + 0.3477635979652405f, + 0.34731149673461914f, + 0.34688109159469604f, + 0.34642982482910156f, + 0.34599629044532776f, + 0.3455651104450226f, + 0.3451215326786041f, + 0.3446847200393677f, + 0.34426259994506836f, + 0.3438153564929962f, + 0.3433886766433716f, + 0.34296250343322754f, + 0.3425285518169403f, + 0.3421013653278351f, + 0.3416734039783478f, + 0.3412553071975708f, + 0.34082120656967163f, + 0.3404068648815155f, + 0.3401075303554535f, + 0.3396795988082886f, + 0.33924874663352966f, + 0.33882710337638855f, + 0.33841201663017273f, + 0.33799099922180176f, + 0.33757779002189636f, + 0.3371507525444031f, + 0.3367448151111603f, + 0.3363204598426819f, + 0.33589497208595276f, + 0.33549508452415466f, + 0.33507639169692993f, + 0.33468082547187805f, + 0.3342556953430176f, + 0.3338509202003479f, + 0.3334386944770813f, + 0.3330461084842682f, + 0.33263781666755676f, + 0.33223792910575867f, + 0.3318367898464203f, + 0.33143073320388794f, + 0.33102700114250183f, + 0.3306204378604889f, + 0.33022868633270264f, + 0.3299452066421509f, + 0.32943421602249146f, + 0.3291661739349365f, + 0.3287597894668579f, + 0.3283606767654419f, + 0.3279717266559601f, + 0.3275641202926636f, + 0.32717373967170715f, + 0.32678133249282837f, + 0.3263908326625824f, + 0.32599589228630066f, + 0.3256118595600128f, + 0.32522615790367126f, + 0.3248441517353058f, + 0.32444849610328674f, + 0.32406193017959595f, + 0.3236929178237915f, + 0.32330766320228577f, + 0.32291358709335327f, + 0.3225407600402832f, + 0.3221597671508789f, + 0.3217817544937134f, + 0.3214161992073059f, + 0.3210352659225464f, + 0.32065457105636597f, + 0.3202817738056183f, + 0.3199090361595154f, + 0.31952476501464844f, + 0.319169282913208f, + 0.3187875747680664f, + 0.3185270428657532f, + 0.3181511163711548f, + 0.317775696516037f, + 0.3174203932285309f, + 0.3170458972454071f, + 0.31666886806488037f, + 0.3162999153137207f, + 0.3159377872943878f, + 0.31556838750839233f, + 0.31520411372184753f, + 0.3148469030857086f, + 0.3144857883453369f, + 0.3141215145587921f, + 0.31376320123672485f, + 0.31340187788009644f, + 0.3130473494529724f, + 0.31268247961997986f, + 0.31231939792633057f, + 0.3119741976261139f, + 0.3116225302219391f, + 0.31126993894577026f, + 0.31091198325157166f, + 0.31057122349739075f, + 0.31021246314048767f, + 0.3098519444465637f, + 0.3094977140426636f, + 0.3091588318347931f, + 0.30892714858055115f, + 0.30857694149017334f, + 0.3082209527492523f, + 0.3078847825527191f, + 0.3075329661369324f, + 0.3071773946285248f, + 0.30683404207229614f, + 0.3064839243888855f, + 0.3061547875404358f, + 0.30579352378845215f, + 0.30546462535858154f, + 0.30512529611587524f, + 0.30477094650268555f, + 0.3044355809688568f, + 0.30408528447151184f, + 0.3037561774253845f, + 0.3034191131591797f, + 0.3030731678009033f, + 0.30274105072021484f, + 0.30242061614990234f, + 0.30208802223205566f, + 0.3017595112323761f, + 0.3014223575592041f, + 0.30109384655952454f, + 0.3007519543170929f, + 0.3004204034805298f, + 0.30008986592292786f, + 0.299759179353714f, + 0.299442321062088f, + 0.2991182208061218f, + 0.29890474677085876f, + 0.2984606623649597f, + 0.2982538938522339f, + 0.2979181706905365f, + 0.29759877920150757f, + 0.29726243019104004f, + 0.296941339969635f, + 0.29661667346954346f, + 0.29628586769104004f, + 0.29597124457359314f, + 0.2956542372703552f, + 0.29532766342163086f, + 0.2950131297111511f, + 0.2946982681751251f, + 0.29437026381492615f, + 0.294062077999115f, + 0.29373520612716675f, + 0.29342857003211975f, + 0.29311829805374146f, + 0.2927953600883484f, + 0.29248350858688354f, + 0.2921796143054962f, + 0.29186367988586426f, + 0.29155081510543823f, + 0.29124289751052856f, + 0.2909250855445862f, + 0.29062604904174805f, + 0.2903158664703369f, + 0.2900070548057556f, + 0.2897077798843384f, + 0.28951889276504517f, + 0.2892034649848938f, + 0.2888925075531006f, + 0.288595587015152f, + 0.28828054666519165f, + 0.2879889905452728f, + 0.28767019510269165f, + 0.28737157583236694f, + 0.2870650291442871f, + 0.2867684066295624f, + 0.28646013140678406f, + 0.2861575782299042f, + 0.2858670949935913f, + 0.2855522036552429f, + 0.28526467084884644f, + 0.28496551513671875f, + 0.2846636176109314f, + 0.284365713596344f, + 0.28407022356987f, + 0.2837750017642975f, + 0.28347358107566833f, + 0.2831934988498688f, + 0.2828976511955261f, + 0.28260302543640137f, + 0.28230583667755127f, + 0.28202950954437256f, + 0.2817310094833374f, + 0.28143706917762756f, + 0.28114718198776245f, + 0.2808639705181122f, + 0.28057390451431274f, + 0.28029951453208923f, + 0.280012309551239f, + 0.2798384428024292f, + 0.2795555889606476f, + 0.2792515158653259f, + 0.2789651155471802f, + 0.27868083119392395f, + 0.2783908545970917f, + 0.2781171500682831f, + 0.27781638503074646f, + 0.27753525972366333f, + 0.2772636413574219f, + 0.27696749567985535f, + 0.2766968011856079f, + 0.27640965580940247f, + 0.2761270999908447f, + 0.27586647868156433f, + 0.2755773663520813f, + 0.2752978801727295f, + 0.27502650022506714f, + 0.27474793791770935f, + 0.27447831630706787f, + 0.2741829454898834f, + 0.27391597628593445f, + 0.2736358046531677f, + 0.273369163274765f, + 0.2731073796749115f, + 0.2728367745876312f, + 0.27255797386169434f, + 0.2722831964492798f, + 0.27201396226882935f, + 0.27174121141433716f, + 0.2714810073375702f, + 0.271202027797699f, + 0.27105721831321716f, + 0.2706688344478607f, + 0.27050918340682983f, + 0.27024585008621216f, + 0.26997825503349304f, + 0.269709050655365f, + 0.2694370150566101f, + 0.269164115190506f, + 0.2688915729522705f, + 0.2686392366886139f, + 0.26836714148521423f, + 0.26810500025749207f, + 0.2678486406803131f, + 0.26756900548934937f, + 0.26730361580848694f, + 0.2670464813709259f, + 0.2668019235134125f, + 0.2665204405784607f, + 0.2662788927555084f, + 0.26599955558776855f, + 0.26575011014938354f, + 0.2655024230480194f, + 0.2652343511581421f, + 0.26497983932495117f, + 0.2647083103656769f, + 0.2644578218460083f, + 0.2642085552215576f, + 0.26395532488822937f, + 0.26370131969451904f, + 0.263449490070343f, + 0.263189435005188f, + 0.26294055581092834f, + 0.26268911361694336f, + 0.26243090629577637f, + 0.2621835768222809f, + 0.26193270087242126f, + 0.2616826891899109f, + 0.2615540623664856f, + 0.26129040122032166f, + 0.2610347867012024f, + 0.2607840299606323f, + 0.26054710149765015f, + 0.26027703285217285f, + 0.2600274682044983f, + 0.2597811222076416f, + 0.2595488429069519f, + 0.25929802656173706f, + 0.25903254747390747f, + 0.25879475474357605f, + 0.2585379481315613f, + 0.2582918405532837f, + 0.25805673003196716f, + 0.2578195035457611f, + 0.257572203874588f, + 0.25732144713401794f, + 0.25707995891571045f, + 0.25684061646461487f, + 0.2565879821777344f, + 0.2563695013523102f, + 0.25612086057662964f, + 0.25587913393974304f, + 0.255633145570755f, + 0.25540968775749207f, + 0.2551721930503845f, + 0.2549220621585846f, + 0.254700630903244f, + 0.25446105003356934f, + 0.2542218565940857f, + 0.2539829611778259f, + 0.25375211238861084f, + 0.2535262703895569f, + 0.2532768249511719f, + 0.2531611919403076f, + 0.25292646884918213f, + 0.25268787145614624f, + 0.2524307668209076f, + 0.2521924376487732f, + 0.2519637644290924f, + 0.25172385573387146f, + 0.2515079975128174f, + 0.25126898288726807f, + 0.2510269284248352f, + 0.2507886588573456f, + 0.25056445598602295f, + 0.2503352165222168f, + 0.25009676814079285f, + 0.2498702108860016f, + 0.24963845312595367f, + 0.24942903220653534f, + 0.24918432533740997f, + 0.24895094335079193f, + 0.24872754514217377f, + 0.24850548803806305f, + 0.24829132854938507f, + 0.24806000292301178f, + 0.24783314764499664f, + 0.24762097001075745f, + 0.24738754332065582f, + 0.247167706489563f, + 0.24695299565792084f, + 0.2467201054096222f, + 0.24649381637573242f, + 0.24628238379955292f, + 0.246060311794281f, + 0.24583758413791656f, + 0.24561069905757904f, + 0.24550525844097137f, + 0.24525107443332672f, + 0.2450413703918457f, + 0.2447965145111084f, + 0.24457761645317078f, + 0.244342640042305f, + 0.24413128197193146f, + 0.24391278624534607f, + 0.24368220567703247f, + 0.2434716671705246f, + 0.24324753880500793f, + 0.24301570653915405f, + 0.2428036779165268f, + 0.24259786307811737f, + 0.24236488342285156f, + 0.242148756980896f, + 0.2419562190771103f, + 0.2417379468679428f, + 0.24150964617729187f, + 0.24130253493785858f, + 0.24109186232089996f, + 0.2408781796693802f, + 0.24066923558712006f, + 0.2404642105102539f, + 0.2402576357126236f, + 0.24005992710590363f, + 0.23985056579113007f, + 0.2396526038646698f, + 0.23944325745105743f, + 0.23922142386436462f, + 0.2390366494655609f, + 0.23881308734416962f, + 0.23860570788383484f, + 0.2384617030620575f, + 0.23822690546512604f, + 0.2379762977361679f, + 0.2377336621284485f, + 0.23748332262039185f, + 0.23739533126354218f, + 0.23720183968544006f, + 0.23698101937770844f, + 0.2367992401123047f, + 0.23657922446727753f, + 0.2363961786031723f, + 0.23619228601455688f, + 0.23597639799118042f, + 0.23578175902366638f, + 0.23557808995246887f, + 0.2353663593530655f, + 0.23517079651355743f, + 0.23498423397541046f, + 0.23477226495742798f, + 0.23457729816436768f, + 0.23437486588954926f, + 0.23418821394443512f, + 0.23396605253219604f, + 0.23378512263298035f, + 0.23358199000358582f, + 0.2333938032388687f, + 0.23318566381931305f, + 0.232975572347641f, + 0.23278391361236572f, + 0.23260772228240967f, + 0.23240657150745392f, + 0.23220720887184143f, + 0.23199425637722015f, + 0.23182547092437744f, + 0.2316315621137619f, + 0.2314368188381195f, + 0.2312292903661728f, + 0.23103848099708557f, + 0.23084689676761627f, + 0.2306482344865799f, + 0.2303827702999115f, + 0.23021303117275238f, + 0.23004060983657837f, + 0.22985106706619263f, + 0.22975048422813416f, + 0.22943352162837982f, + 0.22933898866176605f, + 0.22914543747901917f, + 0.22899281978607178f, + 0.2288072258234024f, + 0.22861431539058685f, + 0.22843509912490845f, + 0.22816847264766693f, + 0.22806860506534576f, + 0.22780157625675201f, + 0.22762224078178406f, + 0.22741560637950897f, + 0.22724071145057678f, + 0.22705252468585968f, + 0.2268504947423935f, + 0.22666625678539276f, + 0.22649532556533813f, + 0.22630980610847473f, + 0.226119264960289f, + 0.22594040632247925f, + 0.22574901580810547f, + 0.22555193305015564f, + 0.22536906599998474f, + 0.22519013285636902f, + 0.2250993400812149f, + 0.2249121069908142f, + 0.2246369868516922f, + 0.2244608998298645f, + 0.22436270117759705f, + 0.22417575120925903f, + 0.22398057579994202f, + 0.22379761934280396f, + 0.2236267328262329f, + 0.22343775629997253f, + 0.2232411950826645f, + 0.2230568677186966f, + 0.2228923738002777f, + 0.2226988673210144f, + 0.22252492606639862f, + 0.222340390086174f, + 0.22216126322746277f, + 0.22196727991104126f, + 0.2217983901500702f, + 0.22159728407859802f, + 0.2214152216911316f, + 0.22124730050563812f, + 0.22106245160102844f, + 0.22088639438152313f, + 0.22071680426597595f, + 0.22053596377372742f, + 0.22036345303058624f, + 0.2201765477657318f, + 0.21999706327915192f, + 0.21981528401374817f, + 0.219647616147995f, + 0.21948128938674927f, + 0.21930661797523499f, + 0.21912866830825806f, + 0.2189987599849701f, + 0.21882392466068268f, + 0.21860471367835999f, + 0.2184319645166397f, + 0.21827076375484467f, + 0.21810099482536316f, + 0.21792113780975342f, + 0.2177520990371704f, + 0.21756581962108612f, + 0.21740955114364624f, + 0.21723714470863342f, + 0.21705415844917297f, + 0.2168884575366974f, + 0.21672160923480988f, + 0.21655923128128052f, + 0.21638694405555725f, + 0.21622954308986664f, + 0.21604597568511963f, + 0.2158840000629425f, + 0.21571625769138336f, + 0.2155391424894333f, + 0.21538583934307098f, + 0.21519944071769714f, + 0.21505311131477356f, + 0.21487067639827728f, + 0.21470613777637482f, + 0.21453726291656494f, + 0.21436457335948944f, + 0.2142084687948227f, + 0.21404136717319489f, + 0.21386931836605072f, + 0.21371158957481384f, + 0.21354614198207855f, + 0.21337896585464478f, + 0.21321818232536316f, + 0.21306107938289642f, + 0.21288613975048065f, + 0.21270926296710968f, + 0.21254965662956238f, + 0.21240270137786865f, + 0.21222689747810364f, + 0.21206718683242798f, + 0.21189945936203003f, + 0.21174396574497223f, + 0.21158431470394135f, + 0.21141672134399414f, + 0.21126426756381989f, + 0.21110302209854126f, + 0.21093645691871643f, + 0.21075579524040222f, + 0.21061968803405762f, + 0.21045085787773132f, + 0.21029168367385864f, + 0.21012543141841888f, + 0.20997537672519684f, + 0.20979711413383484f, + 0.2096484750509262f, + 0.20949453115463257f, + 0.20933128893375397f, + 0.2092391550540924f, + 0.20908373594284058f, + 0.20891214907169342f, + 0.20874397456645966f, + 0.20856574177742004f, + 0.2084084302186966f, + 0.20823991298675537f, + 0.20807170867919922f, + 0.2079344242811203f, + 0.20777527987957f, + 0.20760463178157806f, + 0.2074466198682785f, + 0.20728443562984467f, + 0.20711849629878998f, + 0.20704475045204163f, + 0.20681829750537872f, + 0.206665500998497f, + 0.20651502907276154f, + 0.20636317133903503f, + 0.20621225237846375f, + 0.20606686174869537f, + 0.20590756833553314f, + 0.20575928688049316f, + 0.20561814308166504f, + 0.20545589923858643f, + 0.20531953871250153f, + 0.20517383515834808f, + 0.20502527058124542f, + 0.20486554503440857f, + 0.20473383367061615f, + 0.20456953346729279f, + 0.20443563163280487f, + 0.2042897790670395f, + 0.20412671566009521f, + 0.203985333442688f, + 0.20382718741893768f, + 0.20369099080562592f, + 0.20347239077091217f, + 0.20331762731075287f, + 0.20316165685653687f, + 0.20309443771839142f, + 0.20288388431072235f, + 0.20273058116436005f, + 0.20257724821567535f, + 0.2024327665567398f, + 0.2023533135652542f, + 0.20212598145008087f, + 0.20199725031852722f, + 0.20184215903282166f, + 0.201684832572937f, + 0.20153000950813293f, + 0.20138248801231384f, + 0.20132234692573547f, + 0.20110218226909637f, + 0.20095877349376678f, + 0.20080117881298065f, + 0.20065566897392273f, + 0.20058509707450867f, + 0.20044000446796417f, + 0.20022062957286835f, + 0.2001517117023468f, + 0.1999906450510025f, + 0.19985084235668182f, + 0.19970712065696716f, + 0.1995593160390854f, + 0.19940970838069916f, + 0.19925720989704132f, + 0.19912421703338623f, + 0.19896483421325684f, + 0.1988271027803421f, + 0.1986902952194214f, + 0.19854453206062317f, + 0.1983991265296936f, + 0.19824765622615814f, + 0.19809825718402863f, + 0.19794441759586334f, + 0.19781728088855743f, + 0.197679340839386f, + 0.19752560555934906f, + 0.19738903641700745f, + 0.19724692404270172f, + 0.19710291922092438f, + 0.19694319367408752f, + 0.19679763913154602f, + 0.19667893648147583f, + 0.19654053449630737f, + 0.19639882445335388f, + 0.1962447166442871f, + 0.19611676037311554f, + 0.19597302377223969f, + 0.1958155632019043f, + 0.19569317996501923f, + 0.19554798305034637f, + 0.19546417891979218f, + 0.19531387090682983f, + 0.1951518952846527f, + 0.19500510394573212f, + 0.1948569416999817f, + 0.1947188377380371f, + 0.19457601010799408f, + 0.1944355070590973f, + 0.1943163275718689f, + 0.19419316947460175f, + 0.19406013190746307f, + 0.1939316838979721f, + 0.19380061328411102f, + 0.19361799955368042f, + 0.19356895983219147f, + 0.19335971772670746f, + 0.19322030246257782f, + 0.19309407472610474f, + 0.19295793771743774f, + 0.19282597303390503f, + 0.1926853209733963f, + 0.19256816804409027f, + 0.19241055846214294f, + 0.19227875769138336f, + 0.19216206669807434f, + 0.19201426208019257f, + 0.19190306961536407f, + 0.19177010655403137f, + 0.19164131581783295f, + 0.19150659441947937f, + 0.19136707484722137f, + 0.19123968482017517f, + 0.19109953939914703f, + 0.19096407294273376f, + 0.19085878133773804f, + 0.19072504341602325f, + 0.19058534502983093f, + 0.19044341146945953f, + 0.19033217430114746f, + 0.19019955396652222f, + 0.1900748461484909f, + 0.18993522226810455f, + 0.18979689478874207f, + 0.18968908488750458f, + 0.18955446779727936f, + 0.1894242912530899f, + 0.1892847716808319f, + 0.18915081024169922f, + 0.18904006481170654f, + 0.18889068067073822f, + 0.188766211271286f, + 0.18864603340625763f, + 0.18851563334465027f, + 0.18837957084178925f, + 0.18825824558734894f, + 0.18812908232212067f, + 0.188008114695549f, + 0.1878795325756073f, + 0.1877526491880417f, + 0.18760880827903748f, + 0.18748433887958527f, + 0.18736301362514496f, + 0.1872415989637375f, + 0.18709830939769745f, + 0.18698199093341827f, + 0.18684744834899902f, + 0.18671074509620667f, + 0.18659581243991852f, + 0.18647025525569916f, + 0.18634554743766785f, + 0.1862228959798813f, + 0.18607831001281738f, + 0.18597042560577393f, + 0.18583640456199646f, + 0.1857118457555771f, + 0.18556807935237885f, + 0.18546096980571747f, + 0.18533286452293396f, + 0.1851893812417984f, + 0.18508218228816986f, + 0.18495319783687592f, + 0.18483921885490417f, + 0.18468913435935974f, + 0.18456900119781494f, + 0.1844482123851776f, + 0.1843346208333969f, + 0.18426157534122467f, + 0.18407920002937317f, + 0.1840098649263382f, + 0.18388019502162933f, + 0.1837506741285324f, + 0.18361012637615204f, + 0.18349850177764893f, + 0.18336111307144165f, + 0.18322956562042236f, + 0.1831212341785431f, + 0.18299393355846405f, + 0.18287387490272522f, + 0.18273331224918365f, + 0.18260888755321503f, + 0.18251749873161316f, + 0.1823824644088745f, + 0.1822899878025055f, + 0.18214130401611328f, + 0.18202616274356842f, + 0.18194933235645294f, + 0.18176619708538055f, + 0.18166181445121765f, + 0.18153472244739532f, + 0.18141895532608032f, + 0.1813163310289383f, + 0.18119414150714874f, + 0.18106402456760406f, + 0.18096478283405304f, + 0.1808406263589859f, + 0.18074311316013336f, + 0.180620476603508f, + 0.18049950897693634f, + 0.18039359152317047f, + 0.18029093742370605f, + 0.18012148141860962f, + 0.18005935847759247f, + 0.1798868477344513f, + 0.1797729879617691f, + 0.17966116964817047f, + 0.1795545071363449f, + 0.17941901087760925f, + 0.17930275201797485f, + 0.179204523563385f, + 0.17909133434295654f, + 0.1789587140083313f, + 0.1788659393787384f, + 0.17874272167682648f, + 0.17861700057983398f, + 0.17850957810878754f, + 0.17839275300502777f, + 0.17828509211540222f, + 0.17817743122577667f, + 0.1780514270067215f, + 0.17793850600719452f, + 0.1778256744146347f, + 0.17772488296031952f, + 0.17760786414146423f, + 0.17749641835689545f, + 0.17738603055477142f, + 0.17726750671863556f, + 0.17714694142341614f, + 0.17701052129268646f, + 0.17691530287265778f, + 0.1767774522304535f, + 0.17667871713638306f, + 0.17658495903015137f, + 0.17645849287509918f, + 0.17634360492229462f, + 0.17621174454689026f, + 0.17608866095542908f, + 0.17599357664585114f, + 0.17587827146053314f, + 0.17576055228710175f, + 0.175655335187912f, + 0.1755446493625641f, + 0.17543494701385498f, + 0.17532062530517578f, + 0.17520667612552643f, + 0.1750895380973816f, + 0.1749843806028366f, + 0.17488902807235718f, + 0.17476396262645721f, + 0.17466075718402863f, + 0.17455172538757324f, + 0.17443951964378357f, + 0.1743200421333313f, + 0.17422179877758026f, + 0.1741151660680771f, + 0.17399916052818298f, + 0.17389005422592163f, + 0.17378292977809906f, + 0.17365168035030365f, + 0.1735643893480301f, + 0.17345161736011505f, + 0.17334435880184174f, + 0.17317555844783783f, + 0.17308492958545685f, + 0.17301665246486664f, + 0.172912135720253f, + 0.1727500706911087f, + 0.1726379096508026f, + 0.1725439578294754f, + 0.1724371612071991f, + 0.172346293926239f, + 0.1722460836172104f, + 0.1721653789281845f, + 0.17207512259483337f, + 0.1719343364238739f, + 0.17184847593307495f, + 0.17173130810260773f, + 0.1716267615556717f, + 0.1715201884508133f, + 0.17139986157417297f, + 0.1713264435529709f, + 0.17120003700256348f, + 0.1711057722568512f, + 0.17097318172454834f, + 0.1709117293357849f, + 0.170778289437294f, + 0.17065805196762085f, + 0.17059460282325745f, + 0.17044983804225922f, + 0.1703534573316574f, + 0.17024719715118408f, + 0.1701587438583374f, + 0.17005027830600739f, + 0.1699545681476593f, + 0.1698647290468216f, + 0.16972842812538147f, + 0.1696062833070755f, + 0.16952422261238098f, + 0.16942402720451355f, + 0.16932529211044312f, + 0.1692180186510086f, + 0.1691202074289322f, + 0.1690051257610321f, + 0.16890999674797058f, + 0.16873781383037567f, + 0.1686418503522873f, + 0.16858814656734467f, + 0.168486550450325f, + 0.16837002336978912f, + 0.16828465461730957f, + 0.16817285120487213f, + 0.16806656122207642f, + 0.16796700656414032f, + 0.1678745001554489f, + 0.16775332391262054f, + 0.16765537858009338f, + 0.1675591617822647f, + 0.16747041046619415f, + 0.1673678755760193f, + 0.1672484427690506f, + 0.16713744401931763f, + 0.1670568436384201f, + 0.166981503367424f, + 0.16686902940273285f, + 0.1667419672012329f, + 0.16664457321166992f, + 0.1665564775466919f, + 0.16647207736968994f, + 0.16634348034858704f, + 0.1662454456090927f, + 0.16615059971809387f, + 0.166051983833313f, + 0.16595247387886047f, + 0.16585102677345276f, + 0.16576287150382996f, + 0.16566291451454163f, + 0.1655881404876709f, + 0.16547399759292603f, + 0.1653909832239151f, + 0.16526654362678528f, + 0.16514107584953308f, + 0.16506506502628326f, + 0.16495540738105774f, + 0.16488070785999298f, + 0.16478398442268372f, + 0.1646747887134552f, + 0.1645614057779312f, + 0.16447368264198303f, + 0.1643751710653305f, + 0.16422320902347565f, + 0.16416305303573608f, + 0.16406656801700592f, + 0.16399171948432922f, + 0.16390185058116913f, + 0.16380050778388977f, + 0.16370728611946106f, + 0.1636231541633606f, + 0.16353783011436462f, + 0.16339172422885895f, + 0.16329428553581238f, + 0.16320785880088806f, + 0.16310438513755798f, + 0.162996307015419f, + 0.16291500627994537f, + 0.16280920803546906f, + 0.16276128590106964f, + 0.16262003779411316f, + 0.16251814365386963f, + 0.16247931122779846f, + 0.16236905753612518f, + 0.1622738242149353f, + 0.162176251411438f, + 0.16205555200576782f, + 0.1619701385498047f, + 0.16187423467636108f, + 0.1617640107870102f, + 0.16167600452899933f, + 0.16152667999267578f, + 0.16149695217609406f, + 0.16139891743659973f, + 0.16133636236190796f, + 0.16123801469802856f, + 0.16111208498477936f, + 0.16100721061229706f, + 0.1609351634979248f, + 0.16081742942333221f, + 0.16075046360492706f, + 0.16062086820602417f, + 0.16053594648838043f, + 0.16046448051929474f, + 0.16038621962070465f, + 0.1602899432182312f, + 0.16022361814975739f, + 0.16006498038768768f, + 0.15998610854148865f, + 0.1599012315273285f, + 0.15978874266147614f, + 0.15971818566322327f, + 0.159612774848938f, + 0.15951795876026154f, + 0.159441277384758f, + 0.15937113761901855f, + 0.15927980840206146f, + 0.15915848314762115f, + 0.1590811163187027f, + 0.15896807610988617f, + 0.15888026356697083f, + 0.1588025689125061f, + 0.15870055556297302f, + 0.15861180424690247f, + 0.15851162374019623f, + 0.15843529999256134f, + 0.158340722322464f, + 0.15825113654136658f, + 0.1581512838602066f, + 0.1580662578344345f, + 0.1579820066690445f, + 0.15790003538131714f, + 0.1578054577112198f, + 0.15771929919719696f, + 0.15765094757080078f, + 0.15755470097064972f, + 0.15743505954742432f, + 0.15739582479000092f, + 0.15726667642593384f, + 0.15718722343444824f, + 0.15706954896450043f, + 0.15697892010211945f, + 0.15689809620380402f, + 0.1568191945552826f, + 0.1567181497812271f, + 0.15664193034172058f, + 0.15655569732189178f, + 0.15646186470985413f, + 0.1563776433467865f, + 0.1562684029340744f, + 0.1561981588602066f, + 0.1560996174812317f, + 0.15602006018161774f, + 0.15591232478618622f, + 0.15583202242851257f, + 0.1557215303182602f, + 0.15566304326057434f, + 0.155582994222641f, + 0.1554775834083557f, + 0.15543542802333832f, + 0.15533870458602905f, + 0.15524140000343323f, + 0.15515199303627014f, + 0.15504392981529236f, + 0.15495333075523376f, + 0.15486815571784973f, + 0.15481671690940857f, + 0.15472613275051117f, + 0.1546209454536438f, + 0.15452353656291962f, + 0.1544453203678131f, + 0.1543676257133484f, + 0.1543036252260208f, + 0.1541830599308014f, + 0.15408775210380554f, + 0.15400461852550507f, + 0.1539064198732376f, + 0.15384244918823242f, + 0.1537523865699768f, + 0.15370213985443115f, + 0.1535928100347519f + + }; + } } \ No newline at end of file diff --git a/Runtime/Animation/Smoothing/FrameSmoothingTableGenerator.cs b/Runtime/Animation/Smoothing/FrameSmoothingTableGenerator.cs index 5f7a0ff..a3338f8 100644 --- a/Runtime/Animation/Smoothing/FrameSmoothingTableGenerator.cs +++ b/Runtime/Animation/Smoothing/FrameSmoothingTableGenerator.cs @@ -11,20 +11,13 @@ namespace Rokojori [Export] public string path; - [Export] - public bool compute - { - get { return false; } - set - { - if ( ! value ) - { - return; - } + [ExportToolButton( "Compute")] + public Callable ComputeButton => Callable.From( Compute ); - FrameSmoothingTable.ComputeAndSaveTable( path ); - } - } + async void Compute() + { + await FrameSmoothingTable.ComputeAndSaveTable( this, path ); + } } } \ No newline at end of file diff --git a/Runtime/Animation/Smoothing/Smoothing.cs b/Runtime/Animation/Smoothing/Smoothing.cs index 5d80a3b..a1bf9f2 100644 --- a/Runtime/Animation/Smoothing/Smoothing.cs +++ b/Runtime/Animation/Smoothing/Smoothing.cs @@ -9,12 +9,44 @@ namespace Rokojori public partial class Smoothing: Resource { float _currentFloat = 0; + public void SetCurrent( float value ) + { + _currentFloat = value; + } + Vector2 _currentVector2 = Vector2.Zero; Vector3 _currentVector3 = Vector3.Zero; Vector4 _currentVector4 = Vector4.Zero; + + public void SetCurrent( Vector2 value ) + { + _currentVector2 = value; + } + + public void SetCurrent( Vector3 value ) + { + _currentVector3 = value; + } + + public void SetCurrent( Vector4 value ) + { + _currentVector4 = value; + } + + Quaternion _currentQuaternion = Quaternion.Identity; + + public void SetCurrent( Quaternion quaternion ) + { + _currentQuaternion = quaternion; + } + Color _currentColor = Colors.Black; + public void SetCurrent( Color color ) + { + _currentColor = color; + } public float Smooth( float nextValue, float delta ) { @@ -29,7 +61,16 @@ namespace Rokojori return sm.Smooth( value, delta ); } - public Vector2 Smooth( Vector2 nextValue, float delta ) + public static float ApplyWith( Smoothing sm, float oldValue, float nextValue, float delta ) + { + if ( sm == null ){ return nextValue; } + + sm._currentFloat = oldValue; + + return sm.Smooth( nextValue, delta ); + } + + public Vector2 Smooth( Vector2 nextValue, float delta ) { _currentVector2 = _currentVector2.Lerp( nextValue, _ComputeInterpolationAmount( delta ) ); @@ -42,6 +83,30 @@ namespace Rokojori return sm.Smooth( value, delta ); } + public static float ApplyDegrees( Smoothing sm, float value, float delta ) + { + var newV = MathX.RadiansToVector2( MathX.DegreesToRadians * value ); + + return MathX.RadiansToDegrees * MathX.Vector2ToRadians( Apply( sm, newV, delta ) ); + } + + public static float ApplyDegreesWith( Smoothing sm, float oldValue, float nextValue, float delta ) + { + var oldV = MathX.RadiansToVector2( MathX.DegreesToRadians * oldValue ); + var newV = MathX.RadiansToVector2( MathX.DegreesToRadians * nextValue ); + + return MathX.RadiansToDegrees * MathX.Vector2ToRadians( ApplyWith( sm, oldV, newV, delta ) ); + } + + public static Vector2 ApplyWith( Smoothing sm, Vector2 oldValue, Vector2 nextValue, float delta ) + { + if ( sm == null ){ return nextValue; } + + sm._currentVector2 = oldValue; + + return sm.Smooth( nextValue, delta ); + } + public Vector3 Smooth( Vector3 nextValue, float delta ) { _currentVector3 = _currentVector3.Lerp( nextValue, _ComputeInterpolationAmount( delta ) ); @@ -70,7 +135,8 @@ namespace Rokojori public Quaternion Smooth( Quaternion nextValue, float delta ) { - _currentQuaternion = _currentQuaternion.Slerp( nextValue, _ComputeInterpolationAmount( delta ) ); + _currentQuaternion = _currentQuaternion.GetNormalized(); + _currentQuaternion = _currentQuaternion.Slerp( nextValue.GetNormalized(), _ComputeInterpolationAmount( delta ) ); return _currentQuaternion; } @@ -109,16 +175,18 @@ namespace Rokojori var duration = 0f; var lastValue = value; - var maxDuration = 30; + var maxDuration = 120; - while ( value > tresholdValue && duration < maxDuration ) - { - lastValue = value; - value = Smooth( 0, delta ); + Safe.While( + ()=> value > tresholdValue && duration < maxDuration, + ()=> + { + lastValue = value; + value = Smooth( 0, delta ); - duration += delta; - - } + duration += delta; + } + ); _currentFloat = cached; diff --git a/Runtime/App/App.cs b/Runtime/App/App.cs index c0f76f6..6209151 100644 --- a/Runtime/App/App.cs +++ b/Runtime/App/App.cs @@ -76,8 +76,22 @@ namespace Rokojori ); + + } + void InitializeCamera() + { + var cameraManager = this.Get(); + var camera = this.Get(); + + cameraManager.camera = camera; + var slot = cameraManager.CreateChild(); + slot.camera = this.Get(); + + } + + } } \ No newline at end of file diff --git a/Runtime/Files/FilesSync.cs b/Runtime/Files/FilesSync.cs index 56565e9..f588c2d 100644 --- a/Runtime/Files/FilesSync.cs +++ b/Runtime/Files/FilesSync.cs @@ -13,6 +13,11 @@ namespace Rokojori return Directory.Exists( path ); } + public static bool FileExists( string path ) + { + return File.Exists( path ); + } + public static void CreateDirectory( string path ) { Directory.CreateDirectory( path ); diff --git a/Runtime/Godot/Nodes.cs b/Runtime/Godot/Nodes.cs index 8bdb146..cacb6bc 100644 --- a/Runtime/Godot/Nodes.cs +++ b/Runtime/Godot/Nodes.cs @@ -9,6 +9,16 @@ namespace Rokojori { public static class Nodes { + public static T Get( this Node node ) where T:Node + { + return GetAnyChild( node ); + } + + public static T GetChild( this Node node ) where T:Node + { + return GetDirectChild( node ); + } + public static void CopyData( T from, T to ) where T:Node { var memberInfos = ReflectionHelper.GetDataMemberInfos( BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly ); diff --git a/Runtime/Interactions/Caster.cs b/Runtime/Interactions/Caster.cs index 6f514a2..b6fd37f 100644 --- a/Runtime/Interactions/Caster.cs +++ b/Runtime/Interactions/Caster.cs @@ -5,7 +5,7 @@ using Godot.Collections; namespace Rokojori { - + [Tool] [GlobalClass] public partial class Caster:Node3D { diff --git a/Runtime/Interactions/CharacterController/CharacterController.cs b/Runtime/Interactions/CharacterController/CharacterController.cs index de983c6..25a59f5 100644 --- a/Runtime/Interactions/CharacterController/CharacterController.cs +++ b/Runtime/Interactions/CharacterController/CharacterController.cs @@ -5,6 +5,7 @@ using Godot.Collections; namespace Rokojori { + [Tool] [GlobalClass] public partial class CharacterController:Node { @@ -28,14 +29,10 @@ namespace Rokojori [Export] - public float rotationSmoothingDuration = 0; - - Smoother rotationSmoother = new Smoother(); + public Smoothing rotationSmoothing; [Export] - public float positionSmoothingDuration = 0; - - Smoother positionSmoother = new Smoother(); + public Smoothing positionSmoothing; public float delta = 0; @@ -49,22 +46,24 @@ namespace Rokojori if ( CharacterUpdateMode.Process == characterUpdateMode ) { - this.delta = (float)delta; - Nodes.ForEachDirectChild( actionsContainer, a => Action.Trigger( a ) ); + this.delta = (float) delta; + Nodes.ForEachDirectChild( actionsContainer, Action.Trigger ); } // positionSmoother.CopyPosition( graphics, body, rotationSmoothingDuration, delta ); // rotationSmoother.CopyRotation( graphics, body, positionSmoothingDuration, delta ); - Pose.CopyTo( body, graphics ); + graphics.GlobalPosition = Smoothing.Apply( positionSmoothing, body.GlobalPosition, this.delta ); + graphics.SetGlobalQuaternion( Smoothing.Apply( rotationSmoothing, body.GetGlobalQuaternion(), this.delta ) ); + // Pose.CopyTo( body, graphics ); } public override void _PhysicsProcess( double delta ) { if ( CharacterUpdateMode.Physics_Process == characterUpdateMode ) { - this.delta = (float)delta; - Nodes.ForEachDirectChild( actionsContainer, a => Action.Trigger( a ) ); + this.delta = (float) delta; + Nodes.ForEachDirectChild( actionsContainer, Action.Trigger ); } } } diff --git a/Runtime/Interactions/CharacterController/CharacterControllerAction.cs b/Runtime/Interactions/CharacterController/CharacterControllerAction.cs index caee2cf..923ded7 100644 --- a/Runtime/Interactions/CharacterController/CharacterControllerAction.cs +++ b/Runtime/Interactions/CharacterController/CharacterControllerAction.cs @@ -5,6 +5,7 @@ using Godot.Collections; namespace Rokojori { + [Tool] [GlobalClass] public partial class CharacterControllerAction:Action { diff --git a/Runtime/Interactions/CharacterController/CharacterMovement.cs b/Runtime/Interactions/CharacterController/CharacterMovement.cs index 7f9a238..6390146 100644 --- a/Runtime/Interactions/CharacterController/CharacterMovement.cs +++ b/Runtime/Interactions/CharacterController/CharacterMovement.cs @@ -5,30 +5,18 @@ using Godot.Collections; namespace Rokojori { + [Tool] [GlobalClass] public partial class CharacterMovement:CharacterControllerAction { [Export] - public float onFloorMultiply = 0f; - - [Export] - public bool overwriteVelocity = true; - - [ExportGroup( "Actions" )] - [Export] - public Action onMoving; - [Export] - public Action onIdle; + public float onFloorMultiply = 1f; [Export] - public Action onForward; - [Export] - public Action onBackwards; - [Export] - public Action onStrafeLeft; - [Export] - public Action onStrafeRight; + public float inAirMultiply = 0.01f; + [Export] + public CameraTargetOffset cameraTargetOffset; [ExportGroup( "Direction Source" )] [Export] @@ -39,34 +27,28 @@ namespace Rokojori None, Zero_Y_And_Normalize, Project_On_TransformPlane - } + } - [Export] - public DirectionProcessing directionProcessing; - - [ExportGroup( "Moving" )] + [ExportGroup("Movement")] [Export] public float moveSpeed; [Export] - public Sensor forward; + public CharacterMovementType controllerMovementType; [Export] - public Sensor backwards; - - [ExportGroup( "Strafing" )] - [Export] - public float strafeSpeed; + public CharacterMovementType mouseKeyboardMovementType; [Export] - public Sensor strafeLeft; + public CharacterMovementType currentMovementType; [Export] - public Sensor strafeRight; + public Smoothing onFloorMovementSmoothing = new FrameSmoothing(); [Export] - public bool useBodyDirection = true; + public Smoothing inAirMovementSmoothing = new FrameSmoothing(); + [ExportGroup( "Rotation" )] @@ -74,74 +56,73 @@ namespace Rokojori public bool adjustRotation = true; [Export] - public Curve forwardToRotation = MathX.Curve( 0, 1 ); + public Curve forwardToRotationSmoothingFrames = MathX.Curve( 0, 1 ); - [Export( PropertyHint.Range, "0,1")] - public float rotationSmoothingCoefficient = 0.1f; - Smoother rotationSmoother = new Smoother(); + [Export(PropertyHint.Range, "0,600")] + public int airRotationSmoothingFrames = 120; + FrameSmoothing rotationSmoothing = new FrameSmoothing(); + + protected CharacterMovementData characterMovementData = new CharacterMovementData(); protected override void _OnTrigger() { - if ( ! body.IsOnFloor() ) + var onFloor = body.IsOnFloor(); + + characterMovementData.Reset( this ); + + if ( currentMovementType == null ) { return; } - var movement = Vector3.Zero; + currentMovementType.ProcessMovement( characterMovementData ); - var fw = Sensors.GetValue( forward ); - var bw = Sensors.GetValue( backwards ); - - var fbAxis = Sensors.PolarAxis( backwards, forward ); - - var dir = directionSource != null ? directionSource : body; - var forwardDirection = dir.GlobalForward(); - var rightDirection = useBodyDirection ? body.GlobalRight() : dir.GlobalRight(); - - if ( DirectionProcessing.Zero_Y_And_Normalize == directionProcessing ) + if ( cameraTargetOffset != null ) { - forwardDirection.Y = 0; - rightDirection.Y = 0; + cameraTargetOffset.SetMovingForward( characterMovementData.isMovingForward ? 1f : 0f ); } - else if ( DirectionProcessing.Project_On_TransformPlane == directionProcessing ) - { - var bodyPlane = Plane3.CreateFromNode3D( body ); - forwardDirection = bodyPlane.ConstrainToPlane( forwardDirection + body.GlobalPosition ) - body.GlobalPosition; - rightDirection = bodyPlane.ConstrainToPlane( rightDirection + body.GlobalPosition ) - body.GlobalPosition; - } - - forwardDirection = forwardDirection.Normalized(); - rightDirection = rightDirection.Normalized(); - movement += forwardDirection * Sensors.PolarAxis( backwards, forward ) * moveSpeed; - - movement += rightDirection * Sensors.PolarAxis( strafeLeft, strafeRight ) * strafeSpeed ; + var movementMultiply = onFloor ? onFloorMultiply : inAirMultiply; + characterMovementData.movement *= movementMultiply; - if ( body.IsOnFloor() ) - { - movement *= onFloorMultiply; - } - if ( adjustRotation ) { - var currentRotation = body.GetGlobalQuaternion(); - var nextRotation = Math3D.LookRotation( forwardDirection ); + var nextRotation = Math3D.LookRotation( characterMovementData.forwardDirection ); + var speed = MathX.Clamp01( characterMovementData.movement.Length() / moveSpeed ); - var sm = 1f - rotationSmoothingCoefficient; - sm = sm * sm; + if ( speed > 0 ) + { + Quaternion rotation; - var speed = MathX.Clamp01( movement.Length() / moveSpeed ) * Mathf.Max( fw, bw ); - - sm *= forwardToRotation.Sample( speed ); + if ( onFloor ) + { + rotationSmoothing.frames = Mathf.Round( forwardToRotationSmoothingFrames.Sample( speed ) ); + } + else + { + rotationSmoothing.frames = airRotationSmoothingFrames; + } - var rotation = rotationSmoother.SmoothWithCoefficient( currentRotation, nextRotation, sm, controller.delta ); - body.SetGlobalQuaternion( rotation ); + rotation = rotationSmoothing.Smooth( nextRotation, controller.delta ); + body.SetGlobalQuaternion( rotation ); + } } - Velocity( movement, overwriteVelocity ); + var smoothedMovement = Vector3.Zero; + + if ( onFloor ) + { + smoothedMovement = onFloorMovementSmoothing.Smooth( characterMovementData.movement, controller.delta ); + } + else + { + smoothedMovement = inAirMovementSmoothing.Smooth( characterMovementData.movement, controller.delta ); + } + + Velocity( smoothedMovement, onFloor ); } } diff --git a/Runtime/Interactions/CharacterController/CharacterMovements/CharacterDirectionProcessing.cs b/Runtime/Interactions/CharacterController/CharacterMovements/CharacterDirectionProcessing.cs new file mode 100644 index 0000000..bb0c1b7 --- /dev/null +++ b/Runtime/Interactions/CharacterController/CharacterMovements/CharacterDirectionProcessing.cs @@ -0,0 +1,14 @@ +using Godot; +using System.Collections; +using System.Collections.Generic; +using Godot.Collections; + +namespace Rokojori +{ + public enum CharacterDirectionProcessing + { + None, + Zero_Y_And_Normalize, + Project_On_TransformPlane + } +} \ No newline at end of file diff --git a/Runtime/Interactions/CharacterController/CharacterMovements/CharacterDirectionProcessing.cs.uid b/Runtime/Interactions/CharacterController/CharacterMovements/CharacterDirectionProcessing.cs.uid new file mode 100644 index 0000000..8183d8a --- /dev/null +++ b/Runtime/Interactions/CharacterController/CharacterMovements/CharacterDirectionProcessing.cs.uid @@ -0,0 +1 @@ +uid://823d4vtyx5d3 diff --git a/Runtime/Interactions/CharacterController/CharacterMovements/CharacterMovementData.cs b/Runtime/Interactions/CharacterController/CharacterMovements/CharacterMovementData.cs new file mode 100644 index 0000000..e3ae12e --- /dev/null +++ b/Runtime/Interactions/CharacterController/CharacterMovements/CharacterMovementData.cs @@ -0,0 +1,23 @@ +using Godot; +using System.Collections; +using System.Collections.Generic; +using Godot.Collections; + +namespace Rokojori +{ + public class CharacterMovementData + { + public CharacterMovement characterMovement; + public Vector3 movement; + public Vector3 forwardDirection; + public bool isMovingForward; + + public void Reset( CharacterMovement characterMovement ) + { + this.characterMovement = characterMovement; + movement = Vector3.Zero; + forwardDirection = Vector3.Forward; + isMovingForward = false; + } + } +} \ No newline at end of file diff --git a/Runtime/Interactions/CharacterController/CharacterMovements/CharacterMovementData.cs.uid b/Runtime/Interactions/CharacterController/CharacterMovements/CharacterMovementData.cs.uid new file mode 100644 index 0000000..a31a8b2 --- /dev/null +++ b/Runtime/Interactions/CharacterController/CharacterMovements/CharacterMovementData.cs.uid @@ -0,0 +1 @@ +uid://bh7oo1wqi4cau diff --git a/Runtime/Interactions/CharacterController/CharacterMovements/CharacterMovementType.cs b/Runtime/Interactions/CharacterController/CharacterMovements/CharacterMovementType.cs new file mode 100644 index 0000000..0233b99 --- /dev/null +++ b/Runtime/Interactions/CharacterController/CharacterMovements/CharacterMovementType.cs @@ -0,0 +1,17 @@ +using Godot; +using System.Collections; +using System.Collections.Generic; +using Godot.Collections; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class CharacterMovementType:Resource + { + public virtual void ProcessMovement( CharacterMovementData characterMovementData ) + { + + } + } +} \ No newline at end of file diff --git a/Runtime/Interactions/CharacterController/CharacterMovements/CharacterMovementType.cs.uid b/Runtime/Interactions/CharacterController/CharacterMovements/CharacterMovementType.cs.uid new file mode 100644 index 0000000..c8f7368 --- /dev/null +++ b/Runtime/Interactions/CharacterController/CharacterMovements/CharacterMovementType.cs.uid @@ -0,0 +1 @@ +uid://dco3ngscxqjf5 diff --git a/Runtime/Interactions/CharacterController/CharacterMovements/StrafeMovementType.cs b/Runtime/Interactions/CharacterController/CharacterMovements/StrafeMovementType.cs new file mode 100644 index 0000000..75ec1b1 --- /dev/null +++ b/Runtime/Interactions/CharacterController/CharacterMovements/StrafeMovementType.cs @@ -0,0 +1,78 @@ +using Godot; +using System.Collections; +using System.Collections.Generic; +using Godot.Collections; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class StrafeMovementType:CharacterMovementType + { + public enum StrafeDirectionSource + { + Character_Movement_Direction_Source, + Character_Controller_Body + } + + [ExportGroup( "Movement" )] + [Export] + public Sensor forward; + + [Export] + public Sensor backwards; + + [Export] + public CharacterDirectionProcessing directionProcessing; + + [ExportGroup( "Strafing" )] + [Export] + public float strafeSpeedMultiply = 1.0f; + + [Export] + public Sensor strafeLeft; + + [Export] + public Sensor strafeRight; + + [Export] + public StrafeDirectionSource strafeDirectionSource = StrafeDirectionSource.Character_Controller_Body; + + public override void ProcessMovement( CharacterMovementData characterMovementData ) + { + var characterMovement = characterMovementData.characterMovement; + var directionSource = characterMovement.directionSource; + var body = characterMovement.body; + + var dir = directionSource != null ? directionSource : body; + var forwardDirection = dir.GlobalForward(); + var rightDirection = StrafeDirectionSource.Character_Controller_Body == strafeDirectionSource ? + body.GlobalRight() : dir.GlobalRight(); + + if ( CharacterDirectionProcessing.Zero_Y_And_Normalize == directionProcessing ) + { + forwardDirection.Y = 0; + rightDirection.Y = 0; + } + else if ( CharacterDirectionProcessing.Project_On_TransformPlane == directionProcessing ) + { + var bodyPlane = Plane3.CreateFromNode3D( body ); + forwardDirection = bodyPlane.ConstrainToPlane( forwardDirection + body.GlobalPosition ) - body.GlobalPosition; + rightDirection = bodyPlane.ConstrainToPlane( rightDirection + body.GlobalPosition ) - body.GlobalPosition; + } + + forwardDirection = forwardDirection.Normalized(); + rightDirection = rightDirection.Normalized(); + + var movement = forwardDirection * Sensors.PolarAxis( backwards, forward ) * characterMovement.moveSpeed; + + movement += rightDirection * Sensors.PolarAxis( strafeLeft, strafeRight ) * characterMovement.moveSpeed * strafeSpeedMultiply ; + + characterMovementData.movement = movement; + characterMovementData.isMovingForward = forward.isActive; + characterMovementData.forwardDirection = forwardDirection; + + + } + } +} \ No newline at end of file diff --git a/Runtime/Interactions/CharacterController/CharacterMovements/StrafeMovementType.cs.uid b/Runtime/Interactions/CharacterController/CharacterMovements/StrafeMovementType.cs.uid new file mode 100644 index 0000000..0169fb2 --- /dev/null +++ b/Runtime/Interactions/CharacterController/CharacterMovements/StrafeMovementType.cs.uid @@ -0,0 +1 @@ +uid://b37sjsfvphc8b diff --git a/Runtime/Interactions/CharacterController/CharacterMovements/TurnMovementType.cs b/Runtime/Interactions/CharacterController/CharacterMovements/TurnMovementType.cs new file mode 100644 index 0000000..66d9277 --- /dev/null +++ b/Runtime/Interactions/CharacterController/CharacterMovements/TurnMovementType.cs @@ -0,0 +1,105 @@ +using Godot; +using System.Collections; +using System.Collections.Generic; +using Godot.Collections; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class TurnMovementType:CharacterMovementType + { + [Export] + public CharacterDirectionProcessing directionProcessing; + + [ExportGroup( "Movement" )] + [Export] + public Sensor up; + + [Export] + public Sensor down; + + [Export] + public Sensor left; + + [Export] + public Sensor right; + + [ExportGroup( "Strafing" )] + [Export] + public bool useBodyDirection = true; + + [Export] + public Sensor strafeBack; + + [Export] + public Sensor strafeLeft; + + [Export] + public Sensor strafeRight; + + [Export] + public float strafeBackSpeedMultiply = 1.0f; + + [Export] + public float strafeSidewardsSpeedMultiply = 1.0f; + + public override void ProcessMovement( CharacterMovementData characterMovementData ) + { + var characterMovement = characterMovementData.characterMovement; + var directionSource = characterMovement.directionSource; + var body = characterMovement.body; + + var dir = directionSource != null ? directionSource : body; + var forwardDirection = dir.GlobalForward(); + var rightDirection = dir.GlobalRight(); + var forwardStrafe = useBodyDirection ? body.GlobalForward() : dir.GlobalForward(); + var rightStrafe = useBodyDirection ? body.GlobalRight() : dir.GlobalRight(); + + if ( CharacterDirectionProcessing.Zero_Y_And_Normalize == directionProcessing ) + { + forwardDirection.Y = 0; + rightDirection.Y = 0; + } + else if ( CharacterDirectionProcessing.Project_On_TransformPlane == directionProcessing ) + { + var bodyPlane = Plane3.CreateFromNode3D( body ); + forwardDirection = bodyPlane.ConstrainToPlane( forwardDirection + body.GlobalPosition ) - body.GlobalPosition; + rightDirection = bodyPlane.ConstrainToPlane( rightDirection + body.GlobalPosition ) - body.GlobalPosition; + } + + forwardDirection = forwardDirection.Normalized(); + rightDirection = rightDirection.Normalized(); + + + var direction = Sensors.FourDirectional( left, right, up, down ); + + var movement = forwardDirection * - direction.Y * characterMovement.moveSpeed; + + movement += rightDirection * direction.X * characterMovement.moveSpeed; + + var turningForwardDirection = movement.Normalized(); + + if ( Sensors.IsActive( strafeBack ) ) + { + movement += -Sensors.GetValue( strafeBack ) * forwardStrafe * characterMovement.moveSpeed * strafeBackSpeedMultiply; + turningForwardDirection = forwardDirection; + } + + if ( Sensors.IsActive( strafeLeft ) || Sensors.IsActive( strafeRight ) ) + { + var strafeStrength = Sensors.PolarAxis( strafeLeft, strafeRight ); + movement += strafeStrength * rightStrafe * characterMovement.moveSpeed * strafeSidewardsSpeedMultiply; + turningForwardDirection = forwardDirection; + } + + movement = movement.ConstrainLength( characterMovement.moveSpeed ); + + characterMovementData.movement = movement; + characterMovementData.isMovingForward = ! Math3D.FacingSameDirection( turningForwardDirection, forwardDirection ); + characterMovementData.forwardDirection = turningForwardDirection; + + + } + } +} \ No newline at end of file diff --git a/Runtime/Interactions/CharacterController/CharacterMovements/TurnMovementType.cs.uid b/Runtime/Interactions/CharacterController/CharacterMovements/TurnMovementType.cs.uid new file mode 100644 index 0000000..fc6dff0 --- /dev/null +++ b/Runtime/Interactions/CharacterController/CharacterMovements/TurnMovementType.cs.uid @@ -0,0 +1 @@ +uid://kodskdb1mcd4 diff --git a/Runtime/Interactions/CharacterController/Gravity.cs b/Runtime/Interactions/CharacterController/Gravity.cs index ed5aded..11bcb91 100644 --- a/Runtime/Interactions/CharacterController/Gravity.cs +++ b/Runtime/Interactions/CharacterController/Gravity.cs @@ -5,6 +5,7 @@ using Godot.Collections; namespace Rokojori { + [Tool] [GlobalClass] public partial class Gravity:CharacterControllerAction { diff --git a/Runtime/Interactions/CharacterController/GroundReset.cs b/Runtime/Interactions/CharacterController/GroundReset.cs index 731aee0..782acdd 100644 --- a/Runtime/Interactions/CharacterController/GroundReset.cs +++ b/Runtime/Interactions/CharacterController/GroundReset.cs @@ -5,6 +5,7 @@ using Godot.Collections; namespace Rokojori { + [Tool] [GlobalClass] public partial class GroundReset:CharacterControllerAction { diff --git a/Runtime/Interactions/CharacterController/Jump.cs b/Runtime/Interactions/CharacterController/Jump.cs index 4b27c49..47df17d 100644 --- a/Runtime/Interactions/CharacterController/Jump.cs +++ b/Runtime/Interactions/CharacterController/Jump.cs @@ -5,29 +5,43 @@ using Godot.Collections; namespace Rokojori { + [Tool] [GlobalClass] public partial class Jump:CharacterControllerAction { [Export] public Sensor button; - [Export] - public float jumpStrength; + [ExportGroup( "Jump Impulse")] [Export] - public float maxJumpDuration; + public float jumpImpulseStrength; - [Export] - public Curve jumpCurveStrength = MathX.Curve( 1, 0 ); + [Export( PropertyHint.Range, "0,100" )] + public float velocityToJumpDirection = 0.5f; [Export] - public float jumpedDuration; + public float velocityTresholdForJumpDirection = 1f; + + + [ExportGroup( "Air Control")] [Export] - public bool canJump = false; + public Curve airControlCurveStrength = MathX.Curve( 1, 0 ); [Export] - public bool jumping = false; + public float airMaxControlStrength; + + [Export] + public float maxAirControlDuration; + + float jumpedDuration; + + bool canJump = false; + + bool jumping = false; + + bool needsToRelease = false; @@ -35,7 +49,11 @@ namespace Rokojori { if ( body.IsOnFloor() ) { - jumping = false; + if ( jumping ) + { + jumping = false; + needsToRelease = true; + } } if ( ! ( jumping || body.IsOnFloor() ) ) @@ -46,6 +64,12 @@ namespace Rokojori if ( ! button.isActive ) { jumping = false; + needsToRelease = false; + return; + } + + if ( needsToRelease ) + { return; } @@ -53,17 +77,33 @@ namespace Rokojori { jumping = true; jumpedDuration = 0; + + var jumpDirection = Vector3.Up * jumpImpulseStrength; + + if ( body.Velocity.Length() > velocityTresholdForJumpDirection ) + { + var xz = body.Velocity; + xz.Y = 0; + // xz = xz.Normalized(); + + jumpDirection += xz * velocityToJumpDirection; + } + + SetVelocity( jumpDirection ); + + return; + } jumpedDuration += controller.delta; - canJump = jumpedDuration < maxJumpDuration; + canJump = jumpedDuration < maxAirControlDuration; - if ( jumpedDuration < maxJumpDuration ) + if ( canJump ) { - var jumpStrengthMultiply = jumpCurveStrength.Sample( jumpedDuration / maxJumpDuration ); - AddVelocity( Vector3.Up * jumpStrength ); + var jumpStrengthMultiply = airControlCurveStrength.Sample( jumpedDuration / maxAirControlDuration ); + AddVelocity( Vector3.Up * airMaxControlStrength * jumpStrengthMultiply ); } diff --git a/Runtime/Interactions/CharacterController/MoveAndSlide.cs b/Runtime/Interactions/CharacterController/MoveAndSlide.cs index 924f8d0..9e45303 100644 --- a/Runtime/Interactions/CharacterController/MoveAndSlide.cs +++ b/Runtime/Interactions/CharacterController/MoveAndSlide.cs @@ -5,6 +5,7 @@ using Godot.Collections; namespace Rokojori { + [Tool] [GlobalClass] public partial class MoveAndSlide:CharacterControllerAction { diff --git a/Runtime/Interactions/Grabber.cs b/Runtime/Interactions/Grabber.cs index 33ead85..a662285 100644 --- a/Runtime/Interactions/Grabber.cs +++ b/Runtime/Interactions/Grabber.cs @@ -21,10 +21,17 @@ namespace Rokojori [Export] public Node3D grabOffset; + [Export] + public Smoothing positionSmoothing; + + [Export] + public Smoothing rotationSmoothing; + [ExportGroup("Read Only")] [Export] public Grabbable grabbable; + public override void _Ready() { @@ -59,7 +66,7 @@ namespace Rokojori return; } - var grabbable = Nodes.Find( pointable.GetParent() ); + grabbable = Nodes.Find( pointable.GetParent() ); if ( grabbable == null ) { @@ -75,7 +82,9 @@ namespace Rokojori { return; } - + + positionSmoothing.SetCurrent( grabbable.grabTarget.GlobalPosition ); + rotationSmoothing.SetCurrent( grabbable.grabTarget.GetGlobalQuaternion() ); UpdateGrabbable(); } ); @@ -87,9 +96,11 @@ namespace Rokojori _callback = null; } - void UpdateGrabbable() + void UpdateGrabbable() { - + // this.LogInfo( "Grabbing", HierarchyName.Of( grabbable ) ); + grabbable.grabTarget.GlobalPosition = Smoothing.Apply( positionSmoothing, grabOffset.GlobalPosition, timeLine.delta ); + grabbable.grabTarget.SetGlobalQuaternion( Smoothing.Apply( rotationSmoothing, grabOffset.GetGlobalQuaternion(), timeLine.delta ) ); } } diff --git a/Runtime/Interactions/MultiRayCaster.cs b/Runtime/Interactions/MultiRayCaster.cs index 3b3a220..038c662 100644 --- a/Runtime/Interactions/MultiRayCaster.cs +++ b/Runtime/Interactions/MultiRayCaster.cs @@ -5,7 +5,7 @@ using Godot.Collections; namespace Rokojori { - + [Tool] [GlobalClass] public partial class MultiRayCaster:Caster { @@ -24,6 +24,9 @@ namespace Rokojori [Export] public Vector3 to; + [Export] + public Node collider; + public override int NumColliders() { return numCollisions; @@ -59,7 +62,15 @@ namespace Rokojori ResolveCollisions(); SortCollisions(); + var nextCollider = NumColliders() == 0 ? null : GetCollider( 0 ); + if ( nextCollider != collider ) + { + collider = nextCollider; + + // this.LogInfo( "New Collider:", HierarchyName.Of( collider ) ); + } + Action.Trigger( afterProcess ); } diff --git a/Runtime/Interactions/Pointer.cs b/Runtime/Interactions/Pointer.cs index 1ccfa75..e3a7792 100644 --- a/Runtime/Interactions/Pointer.cs +++ b/Runtime/Interactions/Pointer.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; using Godot.Collections; namespace Rokojori -{ - +{ + [Tool] [GlobalClass,Icon("res://addons/rokojori_action_library/Icons/Pointer.svg")] public partial class Pointer:Node3D { diff --git a/Runtime/Math/Math3D.cs b/Runtime/Math/Math3D.cs index c3f105a..0383af4 100644 --- a/Runtime/Math/Math3D.cs +++ b/Runtime/Math/Math3D.cs @@ -18,6 +18,11 @@ namespace Rokojori return LookingAtEachOtherAngle( lookDirectionA, lookDirectionB ) > 0; } + public static bool FacingSameDirection( Vector3 lookDirectionA, Vector3 lookDirectionB ) + { + return ! LookingAtEachOther( lookDirectionA, lookDirectionB ); + } + public static bool LookingTowards( Vector3 from, Vector3 fromDirection, Vector3 to ) { return LookingAtEachOther( fromDirection, to - from ); @@ -103,11 +108,26 @@ namespace Rokojori return v.X == 0 && v.Y == 0 && v.Z == 0; } + + public static Vector3 ConstrainLength( this Vector3 v, float maxLength ) + { + var length = v.Length(); + + if ( length <= maxLength ) + { + return v; + } + + return v.Normalized() * maxLength; + } + public static Vector3 ComputeNormalFast( Vector3 a, Vector3 b, Vector3 c ) { return Math3D.Cross( c - b , a - b ).Normalized(); } + + public static Vector3 ComputeNormal( Vector3 a, Vector3 b, Vector3 c ) { var cross = Math3D.Cross( c - b , a - b ); @@ -440,7 +460,12 @@ namespace Rokojori public static float GlobalYaw( Vector3 direction ) { - return Mathf.Atan2( direction.Z, direction.X ); + return ( Mathf.Pi * 2.0f - Mathf.Atan2( direction.Z, direction.X ) ) - Mathf.Pi / 2.0f; + } + + public static float GlobalYawDegrees( Vector3 direction ) + { + return Mathf.RadToDeg( GlobalYaw( direction ) ); } public static float GlobalPitch( Vector3 direction ) @@ -451,6 +476,11 @@ namespace Rokojori return Mathf.Atan2( y, xz ); } + public static float GlobalPitchDegrees( Vector3 direction ) + { + return Mathf.RadToDeg( GlobalPitch( direction ) ); + } + public static void SetGlobalQuaternion( this Node3D node, Quaternion quaternion ) { var localScale = node.Scale; @@ -620,6 +650,38 @@ namespace Rokojori node.GlobalPosition = gp; } + public static void SetLocalX( this Node3D node, float x ) + { + var gp = node.Position; + + gp.X = x; + + node.Position = gp; + } + + public static void SetLocalY( this Node3D node, float y ) + { + var gp = node.Position; + + gp.Y = y; + + node.Position = gp; + } + + public static void SetLocalZ( this Node3D node, float z ) + { + var gp = node.Position; + + gp.Z = z; + + node.Position = gp; + } + + public static Vector3 GetOrientationBasedGlobalOffset( this Node3D node, Vector3 offset ) + { + return offset.X * node.GlobalRight() + offset.Y * node.GlobalUp() + offset.Z * node.GlobalForward(); + } + public static Vector3 Average( List vectors ) { var average = Vector3.Zero; diff --git a/Runtime/Math/MathX.cs b/Runtime/Math/MathX.cs index 7948fc0..b446df8 100644 --- a/Runtime/Math/MathX.cs +++ b/Runtime/Math/MathX.cs @@ -96,6 +96,21 @@ namespace Rokojori return Mathf.Abs( AngleDelta( degreesA, degreesB ) ); } + public static float NormalizeAngle( float degrees ) + { + while ( degrees > 180 ) + { + degrees -= 360; + } + + while ( degrees < -180 ) + { + degrees += 360; + } + + return degrees; + } + public static float Smoothstep ( float edge0, float edge1, float x ) { x = MathX.Clamp01( ( x - edge0 ) / ( edge1 - edge0 ) ); @@ -118,6 +133,17 @@ namespace Rokojori return Mathf.Floor( value / snappingDistance ) * snappingDistance; } + public static Vector2 RadiansToVector2( float angle ) + { + return new Vector2( Mathf.Cos( angle ), Mathf.Sin( angle ) ); + } + + public static float Vector2ToRadians( Vector2 circle ) + { + return Mathf.Atan2( circle.Y, circle.X ); + } + + public const float DegreesToRadians = Mathf.Pi / 180f; public const float RadiansToDegrees = 180f / Mathf.Pi; diff --git a/Runtime/Procedural/Parametric/Cuboid/Cuboid.cs b/Runtime/Procedural/Parametric/Cuboid/Cuboid.cs index ca19372..d105f9e 100644 --- a/Runtime/Procedural/Parametric/Cuboid/Cuboid.cs +++ b/Runtime/Procedural/Parametric/Cuboid/Cuboid.cs @@ -27,23 +27,9 @@ namespace Rokojori [Export] public MeshInstance3D output; - [Export] - public bool update = false; - - [Export] - public bool updateAlways = false; - - public override void _Process( double delta ) - { - if ( ! ( update || updateAlways ) ) - { - return; - } - - update = false; - - Create(); - } + + [ExportToolButton( "Update")] + public Callable UpdateButton => Callable.From( () => Create() ); public float X() @@ -148,6 +134,11 @@ namespace Rokojori mg.AddQuad( 20, 21, 22, 23, true ); + if ( output == null ) + { + output = this.CreateChild(); + } + output.Mesh = mg.GenerateMesh(); } diff --git a/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Left-Joystick Y-Positive.tres b/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Left-Joystick Down +Y.tres similarity index 100% rename from Runtime/Sensors/Default-Sensors/Gamepad/Axis/Left-Joystick Y-Positive.tres rename to Runtime/Sensors/Default-Sensors/Gamepad/Axis/Left-Joystick Down +Y.tres diff --git a/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Left-Joystick X-Negative.tres b/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Left-Joystick Left -X.tres similarity index 100% rename from Runtime/Sensors/Default-Sensors/Gamepad/Axis/Left-Joystick X-Negative.tres rename to Runtime/Sensors/Default-Sensors/Gamepad/Axis/Left-Joystick Left -X.tres diff --git a/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Left-Joystick X-Positive.tres b/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Left-Joystick Right +X.tres similarity index 100% rename from Runtime/Sensors/Default-Sensors/Gamepad/Axis/Left-Joystick X-Positive.tres rename to Runtime/Sensors/Default-Sensors/Gamepad/Axis/Left-Joystick Right +X.tres diff --git a/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Left-Joystick Y-Negative.tres b/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Left-Joystick Up -Y.tres similarity index 61% rename from Runtime/Sensors/Default-Sensors/Gamepad/Axis/Left-Joystick Y-Negative.tres rename to Runtime/Sensors/Default-Sensors/Gamepad/Axis/Left-Joystick Up -Y.tres index dfc4c31..64630a2 100644 --- a/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Left-Joystick Y-Negative.tres +++ b/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Left-Joystick Up -Y.tres @@ -1,10 +1,10 @@ [gd_resource type="Resource" script_class="GamePadAxisSensor" load_steps=2 format=3 uid="uid://dbha8dmhxgm05"] -[ext_resource type="Script" path="res://addons/rokojori_action_library/Runtime/Sensors/GamePadAxisSensor.cs" id="1_yy4wi"] +[ext_resource type="Script" uid="uid://cb81s7ud1de7h" path="res://addons/rokojori_action_library/Runtime/Sensors/GamePadAxisSensor.cs" id="1_yy4wi"] [resource] script = ExtResource("1_yy4wi") -axis = 0 +axis = 1 type = 1 continous = true _value = 0.0 diff --git a/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Right-Joystick Y-Positive.tres b/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Right-Joystick Down +Y.tres similarity index 100% rename from Runtime/Sensors/Default-Sensors/Gamepad/Axis/Right-Joystick Y-Positive.tres rename to Runtime/Sensors/Default-Sensors/Gamepad/Axis/Right-Joystick Down +Y.tres diff --git a/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Right-Joystick X-Negative.tres b/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Right-Joystick Left -X.tres similarity index 100% rename from Runtime/Sensors/Default-Sensors/Gamepad/Axis/Right-Joystick X-Negative.tres rename to Runtime/Sensors/Default-Sensors/Gamepad/Axis/Right-Joystick Left -X.tres diff --git a/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Right-Joystick X-Positive.tres b/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Right-Joystick Right +X.tres similarity index 100% rename from Runtime/Sensors/Default-Sensors/Gamepad/Axis/Right-Joystick X-Positive.tres rename to Runtime/Sensors/Default-Sensors/Gamepad/Axis/Right-Joystick Right +X.tres diff --git a/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Right-Joystick Up -Y.tres b/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Right-Joystick Up -Y.tres new file mode 100644 index 0000000..10a2622 --- /dev/null +++ b/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Right-Joystick Up -Y.tres @@ -0,0 +1,9 @@ +[gd_resource type="Resource" script_class="GamePadAxisSensor" load_steps=2 format=3 uid="uid://ck7woerh7mhp"] + +[ext_resource type="Script" uid="uid://cb81s7ud1de7h" path="res://addons/rokojori_action_library/Runtime/Sensors/GamePadAxisSensor.cs" id="1_nrdau"] + +[resource] +script = ExtResource("1_nrdau") +axis = 3 +type = 1 +continous = true diff --git a/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Right-Joystick Y-Negative.tres b/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Right-Joystick Y-Negative.tres deleted file mode 100644 index 2b02f3e..0000000 --- a/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Right-Joystick Y-Negative.tres +++ /dev/null @@ -1,13 +0,0 @@ -[gd_resource type="Resource" script_class="GamePadAxisSensor" load_steps=2 format=3 uid="uid://ck7woerh7mhp"] - -[ext_resource type="Script" path="res://addons/rokojori_action_library/Runtime/Sensors/GamePadAxisSensor.cs" id="1_nrdau"] - -[resource] -script = ExtResource("1_nrdau") -axis = 3 -type = 1 -continous = true -_value = 0.0 -_wasActive = false -_active = false -_activeTreshold = 0.5 diff --git a/Runtime/Sensors/Default-Sensors/Gamepad/Buttons/Button X, PS Square, Nin Y.tres b/Runtime/Sensors/Default-Sensors/Gamepad/Buttons/Button X, PS Square, Nin Y.tres index deb82e6..59286c8 100644 --- a/Runtime/Sensors/Default-Sensors/Gamepad/Buttons/Button X, PS Square, Nin Y.tres +++ b/Runtime/Sensors/Default-Sensors/Gamepad/Buttons/Button X, PS Square, Nin Y.tres @@ -1,12 +1,8 @@ [gd_resource type="Resource" script_class="GamePadButtonSensor" load_steps=2 format=3 uid="uid://jvwwq6guhl77"] -[ext_resource type="Script" path="res://addons/rokojori_action_library/Runtime/Sensors/GamePadButtonSensor.cs" id="1_4da72"] +[ext_resource type="Script" uid="uid://0ji11kv86cpk" path="res://addons/rokojori_action_library/Runtime/Sensors/GamePadButtonSensor.cs" id="1_4da72"] [resource] script = ExtResource("1_4da72") -button = 1 +button = 2 continous = false -_value = 0.0 -_wasActive = false -_active = false -_activeTreshold = 0.5 diff --git a/Runtime/Sensors/Default-Sensors/Gamepad/Buttons/Button Y, PS Triangle, Nin X.tres b/Runtime/Sensors/Default-Sensors/Gamepad/Buttons/Button Y, PS Triangle, Nin X.tres index 9516078..66bce51 100644 --- a/Runtime/Sensors/Default-Sensors/Gamepad/Buttons/Button Y, PS Triangle, Nin X.tres +++ b/Runtime/Sensors/Default-Sensors/Gamepad/Buttons/Button Y, PS Triangle, Nin X.tres @@ -1,12 +1,8 @@ [gd_resource type="Resource" script_class="GamePadButtonSensor" load_steps=2 format=3 uid="uid://dpwq5eyla8rob"] -[ext_resource type="Script" path="res://addons/rokojori_action_library/Runtime/Sensors/GamePadButtonSensor.cs" id="1_yv1r0"] +[ext_resource type="Script" uid="uid://0ji11kv86cpk" path="res://addons/rokojori_action_library/Runtime/Sensors/GamePadButtonSensor.cs" id="1_yv1r0"] [resource] script = ExtResource("1_yv1r0") -button = 2 +button = 3 continous = false -_value = 0.0 -_wasActive = false -_active = false -_activeTreshold = 0.5 diff --git a/Runtime/Sensors/Default-Sensors/Gamepad/Default - GamePad.tres b/Runtime/Sensors/Default-Sensors/Gamepad/Default - GamePad.tres index d05279c..d5197bd 100644 --- a/Runtime/Sensors/Default-Sensors/Gamepad/Default - GamePad.tres +++ b/Runtime/Sensors/Default-Sensors/Gamepad/Default - GamePad.tres @@ -1,14 +1,14 @@ [gd_resource type="Resource" script_class="SensorGroup" load_steps=28 format=3 uid="uid://bv40lrpi3831d"] -[ext_resource type="Script" path="res://addons/rokojori_action_library/Runtime/Sensors/SensorGroup.cs" id="1_k6ypa"] -[ext_resource type="Resource" uid="uid://5gnh5dmv1p21" path="res://addons/rokojori_action_library/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Left-Joystick X-Negative.tres" id="2_1ywmr"] -[ext_resource type="Resource" uid="uid://dsrf03g6mgu5t" path="res://addons/rokojori_action_library/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Left-Joystick X-Positive.tres" id="3_1yuu5"] -[ext_resource type="Resource" uid="uid://dbha8dmhxgm05" path="res://addons/rokojori_action_library/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Left-Joystick Y-Negative.tres" id="4_ehig4"] -[ext_resource type="Resource" uid="uid://cyyy0ycusgil3" path="res://addons/rokojori_action_library/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Left-Joystick Y-Positive.tres" id="5_adyq7"] -[ext_resource type="Resource" uid="uid://b16mtcrpm1f6i" path="res://addons/rokojori_action_library/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Right-Joystick X-Negative.tres" id="6_g7fxo"] -[ext_resource type="Resource" uid="uid://d05w143o644d3" path="res://addons/rokojori_action_library/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Right-Joystick X-Positive.tres" id="7_b0v3q"] -[ext_resource type="Resource" uid="uid://ck7woerh7mhp" path="res://addons/rokojori_action_library/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Right-Joystick Y-Negative.tres" id="8_ljqng"] -[ext_resource type="Resource" uid="uid://6emg8n3qxhlv" path="res://addons/rokojori_action_library/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Right-Joystick Y-Positive.tres" id="9_qkgw5"] +[ext_resource type="Script" uid="uid://da4bhmvkury2" path="res://addons/rokojori_action_library/Runtime/Sensors/SensorGroup.cs" id="1_k6ypa"] +[ext_resource type="Resource" uid="uid://5gnh5dmv1p21" path="res://addons/rokojori_action_library/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Left-Joystick Left -X.tres" id="2_1ywmr"] +[ext_resource type="Resource" uid="uid://dsrf03g6mgu5t" path="res://addons/rokojori_action_library/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Left-Joystick Right +X.tres" id="3_1yuu5"] +[ext_resource type="Resource" uid="uid://dbha8dmhxgm05" path="res://addons/rokojori_action_library/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Left-Joystick Up -Y.tres" id="4_ehig4"] +[ext_resource type="Resource" uid="uid://cyyy0ycusgil3" path="res://addons/rokojori_action_library/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Left-Joystick Down +Y.tres" id="5_adyq7"] +[ext_resource type="Resource" uid="uid://b16mtcrpm1f6i" path="res://addons/rokojori_action_library/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Right-Joystick Left -X.tres" id="6_g7fxo"] +[ext_resource type="Resource" uid="uid://d05w143o644d3" path="res://addons/rokojori_action_library/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Right-Joystick Right +X.tres" id="7_b0v3q"] +[ext_resource type="Resource" uid="uid://ck7woerh7mhp" path="res://addons/rokojori_action_library/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Right-Joystick Up -Y.tres" id="8_ljqng"] +[ext_resource type="Resource" uid="uid://6emg8n3qxhlv" path="res://addons/rokojori_action_library/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Right-Joystick Down +Y.tres" id="9_qkgw5"] [ext_resource type="Resource" uid="uid://cs12bjge707ri" path="res://addons/rokojori_action_library/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Trigger Left, LT, PS L2, Nin ZL.tres" id="10_t2i3f"] [ext_resource type="Resource" uid="uid://cy3ja8squnin6" path="res://addons/rokojori_action_library/Runtime/Sensors/Default-Sensors/Gamepad/Axis/Trigger Right, RT, PS R2, Nin ZR.tres" id="11_u6ig2"] [ext_resource type="Resource" uid="uid://dffkdky8iowro" path="res://addons/rokojori_action_library/Runtime/Sensors/Default-Sensors/Gamepad/Buttons/Button A, PS Cross, Nin B.tres" id="12_0r6yt"] diff --git a/Runtime/Sensors/HoldSensor.cs b/Runtime/Sensors/HoldSensor.cs new file mode 100644 index 0000000..92ce34f --- /dev/null +++ b/Runtime/Sensors/HoldSensor.cs @@ -0,0 +1,75 @@ + +using Godot; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass,Icon("res://addons/rokojori_action_library/Icons/SensorGroup.svg")] + public partial class HoldSensor : Sensor + { + [Export] + public Sensor holdButton; + + [Export] + public bool negateHoldButton; + + [Export] + public Sensor triggerButton; + + protected override void UpdateValue() + { + if ( holdButton == null || triggerButton == null ) + { + SetFloatValue( 0 ); + return; + } + + var holdButtonValue = holdButton.isActive; + + if ( negateHoldButton ) + { + holdButtonValue = ! holdButtonValue; + } + + if ( ! holdButtonValue ) + { + SetFloatValue( 0 ); + return; + } + + SetFloatValue( triggerButton.value ); + } + + public override string ToString() + { + return RJLog.GetInfo( this, holdButton, triggerButton ); + } + + [Export] + public InputIcon[] inputIcons = []; + + [Export] + public bool useInputIconsFromSensors = true; + + public override List GetInputIcons() + { + var list = Lists.From( inputIcons ); + + if ( useInputIconsFromSensors ) + { + if ( holdButton != null ) + { + list.AddRange( holdButton.GetInputIcons() ); + } + + if ( triggerButton != null ) + { + list.AddRange( triggerButton.GetInputIcons() ); + } + } + + return list; + } + } +} \ No newline at end of file diff --git a/Runtime/Sensors/HoldSensor.cs.uid b/Runtime/Sensors/HoldSensor.cs.uid new file mode 100644 index 0000000..492ad1b --- /dev/null +++ b/Runtime/Sensors/HoldSensor.cs.uid @@ -0,0 +1 @@ +uid://b3c1sl7uhvqu8 diff --git a/Runtime/Sensors/Sensor.cs b/Runtime/Sensors/Sensor.cs index 936e4c4..d50a8cd 100644 --- a/Runtime/Sensors/Sensor.cs +++ b/Runtime/Sensors/Sensor.cs @@ -17,18 +17,13 @@ namespace Rokojori [Export] public bool continous = false; - [ExportGroup("Read Only")] - [Export] - public float _value = 0; + protected float _value = 0; - [Export] - public bool _wasActive = false; + protected bool _wasActive = false; - [Export] - public bool _active = false; + protected bool _active = false; - [Export] - public float _activeTreshold = 0.5f; + protected float _activeTreshold = 0.5f; public void ProcessSensor( SensorRunner runner, float delta ) { diff --git a/Runtime/Sensors/SensorManager.cs b/Runtime/Sensors/SensorManager.cs index 6468aaa..4678eb7 100644 --- a/Runtime/Sensors/SensorManager.cs +++ b/Runtime/Sensors/SensorManager.cs @@ -35,16 +35,22 @@ namespace Rokojori [ExportGroup("Read Only")] [Export] - public SensorDevice[] deviceList = new SensorDevice[]{}; + public SensorDevice[] deviceList =[]; [Export] - public float[] deviceLastInputTimeStamp = new float[]{}; + public float[] deviceLastInputTimeStamp = []; [ExportGroup("Testing")] [Export] public SensorDevice testingLastActiveDevice; + [Export] + public bool showRegistratedSensors = true; + + [Export] + public Sensor[] registratedSensors = []; + @@ -61,6 +67,12 @@ namespace Rokojori DateTime _startTime; + public bool isMouseKeyboardLastActive => lastActiveDevice == mouseKeyboardDevice || + lastActiveDevice == mouseDevice || + lastActiveDevice == keyboardDevice; + + public bool isControllerLastActive => lastActiveDevice == gamePadDevice; + public SensorDevice lastActiveDevice { get @@ -175,8 +187,11 @@ namespace Rokojori runners.ForEach( r => r.Update( (float) delta ) ); } + public void Register( Sensor s, SensorInputHandler sih ) { + this.LogInfo( "Registrating", s ); + var sensorRunner = sensorToRunner[ s ]; if ( sensorRunner.listeners.Contains( sih ) ) @@ -185,6 +200,8 @@ namespace Rokojori } sensorRunner.listeners.Add( sih ); + + } public void Unregister( Sensor s, SensorInputHandler sih ) @@ -196,6 +213,11 @@ namespace Rokojori public static void Register( SensorInputHandler handler, params Sensor[] sensors ) { var sm = Unique.Get(); + + if ( sm == null ) + { + Nodes.ForEachInScene( n => n.LogInfo() ); + } foreach ( var s in sensors ) { @@ -241,6 +263,11 @@ namespace Rokojori sensorsSet.Add( s ); runners.Add( new SensorRunner( s ) ); + + if ( showRegistratedSensors ) + { + registratedSensors = Arrays.Add( registratedSensors, s ); + } } HashSet _scannedObjects = new HashSet(); @@ -257,6 +284,19 @@ namespace Rokojori var sensors = ReflectionHelper.GetDataMemberValues( obj ); + if ( sensors.Count > 0 ) + { + if ( obj is Node n ) + { + n.LogInfo( sensors ); + } + else if ( obj is Resource r ) + { + r.LogInfo( sensors ); + } + } + + sensors.ForEach( s => { @@ -309,12 +349,12 @@ namespace Rokojori foreach ( var n in autoScanForSensors ) { - Nodes.ForEach( n, cn=> AddSensorsFrom( cn ) ); + Nodes.ForEach( n, AddSensorsFrom ); } if ( autoScanParent ) { - Nodes.ForEach( GetParent(), cn=> AddSensorsFrom( cn ) ); + Nodes.ForEach( GetParent(), AddSensorsFrom ); } runners.ForEach( diff --git a/Runtime/Sensors/SensorViewer.cs b/Runtime/Sensors/SensorViewer.cs new file mode 100644 index 0000000..e34a072 --- /dev/null +++ b/Runtime/Sensors/SensorViewer.cs @@ -0,0 +1,32 @@ + +using Godot; +using System.Collections.Generic; +using System; +namespace Rokojori +{ + [Tool] + [GlobalClass,Icon("res://addons/rokojori_action_library/Icons/SensorManager.svg")] + public partial class SensorViewer: Node + { + [Export] + public Sensor sensor; + + [Export] + public float value; + + [Export] + public bool active; + + + public override void _Process(double delta) + { + if ( sensor == null ) + { + return; + } + + value = sensor.value; + active = sensor.isActive; + } + } +} \ No newline at end of file diff --git a/Runtime/Sensors/SensorViewer.cs.uid b/Runtime/Sensors/SensorViewer.cs.uid new file mode 100644 index 0000000..46505fd --- /dev/null +++ b/Runtime/Sensors/SensorViewer.cs.uid @@ -0,0 +1 @@ +uid://bodk4mqlebnwi diff --git a/Runtime/Sensors/Sensors.cs b/Runtime/Sensors/Sensors.cs index 6b307ab..7838d2a 100644 --- a/Runtime/Sensors/Sensors.cs +++ b/Runtime/Sensors/Sensors.cs @@ -34,5 +34,23 @@ namespace Rokojori { return GetValue( negative, -scale, deadZone ) + GetValue( positive, scale, deadZone ); } + + public static Vector2 FourDirectional( Sensor left, Sensor right, Sensor up, Sensor down, bool normalize = true, float deadZone = 0.3f ) + { + var x = PolarAxis( left, right, 1, deadZone ); + var y = PolarAxis( up, down, 1, deadZone ); + + + var v = new Vector2( x, y ); + + if ( normalize && v.Length() > 1 ) + { + v = v.Normalized(); + } + + return v; + + + } } } \ No newline at end of file diff --git a/Runtime/Sensors/TriggerOnSensor.cs b/Runtime/Sensors/TriggerOnSensor.cs index 27b96c7..108fa24 100644 --- a/Runtime/Sensors/TriggerOnSensor.cs +++ b/Runtime/Sensors/TriggerOnSensor.cs @@ -14,7 +14,9 @@ namespace Rokojori public Action action; public override void _Ready() - { + { + this.LogInfo( "Root" ); + SensorManager.Register( this, sensor ); } diff --git a/Runtime/Shading/Library/Math.gdshaderinc b/Runtime/Shading/Library/Math.gdshaderinc index b6ed09f..bf9da50 100644 --- a/Runtime/Shading/Library/Math.gdshaderinc +++ b/Runtime/Shading/Library/Math.gdshaderinc @@ -72,4 +72,19 @@ float angleDelta( float degreesA, float degreesB ) float angleDelta = degreesB - degreesA; angleDelta = mod( angleDelta + 180.0, 360.0 ) - 180.0; return angleDelta; +} + + float snapRounded( float value, float snappingDistance ) +{ + return round( value / snappingDistance ) * snappingDistance; +} + +float snapCeiled( float value, float snappingDistance ) +{ + return ceil( value / snappingDistance ) * snappingDistance; +} + +float snapFloored( float value, float snappingDistance ) +{ + return floor( value / snappingDistance ) * snappingDistance; } \ No newline at end of file diff --git a/Runtime/Shading/Library/Noise.gdshaderinc b/Runtime/Shading/Library/Noise.gdshaderinc index de62ed6..ed203b3 100644 --- a/Runtime/Shading/Library/Noise.gdshaderinc +++ b/Runtime/Shading/Library/Noise.gdshaderinc @@ -1,5 +1,7 @@ // #include "res://addons/rokojori_action_library/Runtime/Shading/Library/Noise.gdshaderinc" +#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Math.gdshaderinc" + float random( vec2 uv ) { return fract( sin( dot( uv.xy, vec2( 12.9898, 78.233 ) ) ) * 43758.5453123 ); @@ -7,9 +9,16 @@ float random( vec2 uv ) vec2 random_v2( vec2 uv ) { - return vec2( fract( sin( dot( uv.xy, vec2( 12.9898,78.233 ) ) ) * 43758.5453123 ) ); + uv = vec2 + ( + dot(uv, vec2( 127.1,311.7 ) ), + dot(uv, vec2( 269.5,183.3 ) ) + ); + + return -1.0 + 2.0 * fract( sin( uv ) * 43758.5453123 ); } + vec3 random_v3( vec3 uvw ) { @@ -20,7 +29,20 @@ vec3 random_v3( vec3 uvw ) return -1.0 + 2.0 * fract(sin(uvw) * 43758.5453123); } -float perlin( vec2 uv ) +// float perlin( vec2 uv ) +// { +// vec2 uv_index = floor(uv); +// vec2 uv_fract = fract(uv); + +// vec2 blur = smoothstep(0.0, 1.0, uv_fract); + +// return mix( mix( dot( random_v2(uv_index + vec2(0.0,0.0) ), uv_fract - vec2(0.0,0.0) ), +// dot( random_v2(uv_index + vec2(1.0,0.0) ), uv_fract - vec2(1.0,0.0) ), blur.x), +// mix( dot( random_v2(uv_index + vec2(0.0,1.0) ), uv_fract - vec2(0.0,1.0) ), +// dot( random_v2(uv_index + vec2(1.0,1.0) ), uv_fract - vec2(1.0,1.0) ), blur.x), blur.y) + 0.5; +// } + +float perlin(vec2 uv) { vec2 uv_index = floor(uv); vec2 uv_fract = fract(uv); @@ -33,6 +55,61 @@ float perlin( vec2 uv ) dot( random_v2(uv_index + vec2(1.0,1.0) ), uv_fract - vec2(1.0,1.0) ), blur.x), blur.y) + 0.5; } +float perlinOctaves( vec2 uv, int octaves, float scale, float gain ) +{ + float s = 1.0; + float g = 1.0; + + float v = perlin( uv * s ) * g; + float n = 1.0; + + for ( int i = 0; i < octaves; i++ ) + { + s *= scale; + g *= gain; + + v += perlin( uv * s ) * g; + n += g; + } + + return v / n; +} + +vec2 seamLessCoordinate( vec2 uv, vec2 seamRange, vec2 seamFade, vec2 type ) +{ + return mod( uv - seamFade * type, seamRange ); +} + +float perlinOctavesSeamless( vec2 uv, int octaves, float scale, float gain, vec2 seamRange, vec2 seamFade ) +{ + // uv = mod( uv , seamRange ); + seamFade *= seamRange; + vec2 fading = mod( uv, seamRange ) ; + fading.x = normalizeToRange01( fading.x, seamRange.x - seamFade.x, seamRange.x ); + fading.y = normalizeToRange01( fading.y, seamRange.y - seamFade.y, seamRange.y ); + + + // 0, seamRange - seamFade, seamRange + // + + vec2 p00 = seamLessCoordinate( uv, seamRange, seamFade, vec2( 0.0, 0.0 ) ); + vec2 p10 = seamLessCoordinate( uv, seamRange, seamFade, vec2( 1.0, 0.0 ) ); + vec2 p01 = seamLessCoordinate( uv, seamRange, seamFade, vec2( 0.0, 1.0 ) ); + vec2 p11 = seamLessCoordinate( uv, seamRange, seamFade, vec2( 1.0, 1.0 ) ); + + float n00 = perlinOctaves( p00, octaves, scale, gain ); + float n10 = perlinOctaves( p10, octaves, scale, gain ); + float n01 = perlinOctaves( p01, octaves, scale, gain ); + float n11 = perlinOctaves( p11, octaves, scale, gain ); + + float n0 = mix( n00, n10, fading.x ); + float n1 = mix( n01, n11, fading.x ); + + return mix( n0, n1, fading.y ); +} + + + float perlin3D( vec3 uvw ) { vec3 gridIndex = floor( uvw ); diff --git a/Runtime/Sorting/MinMaxSearch.cs b/Runtime/Sorting/MinMaxSearch.cs index 308ce79..fbe8e08 100644 --- a/Runtime/Sorting/MinMaxSearch.cs +++ b/Runtime/Sorting/MinMaxSearch.cs @@ -43,11 +43,12 @@ namespace Rokojori { low = tweened; } - else + else { high = tweened; } + if ( validateLimits != null && ! validateLimits( low, high ) ) { throw new Exception( "Limit validation failed" ); diff --git a/Runtime/Tools/Async.cs b/Runtime/Tools/Async.cs index 62ee7c2..647ad46 100644 --- a/Runtime/Tools/Async.cs +++ b/Runtime/Tools/Async.cs @@ -39,6 +39,20 @@ namespace Rokojori return last; } + public static async Task WaitIfExceeded( double last, Node node, double waitTime = Async.waitTime ) + { + var now = Time.GetTicksMsec() / 1000.0; + + if ( ( now - last ) > waitTime ) + { + await node.RequestNextFrame(); + + return Time.GetTicksMsec() / 1000.0;; + } + + return last; + } + public static double DoIfExceeded( double last, System.Action action, double waitTime = Async.waitTime ) { var now = Time.GetTicksMsec() / 1000.0; diff --git a/Runtime/Tools/Safe.cs b/Runtime/Tools/Safe.cs index 83785b1..dbb85b6 100644 --- a/Runtime/Tools/Safe.cs +++ b/Runtime/Tools/Safe.cs @@ -8,7 +8,7 @@ namespace Rokojori { public class Safe { - static readonly int maxWhileIterations = 2000 * 1000; + static readonly int maxWhileIterations = 1000 * 1000; public static void While( Func condition, System.Action action, System.Action onTooManyIterations = null ) { diff --git a/Runtime/VirtualCameras/CameraTargetOffset.cs b/Runtime/VirtualCameras/CameraTargetOffset.cs new file mode 100644 index 0000000..f4a60b8 --- /dev/null +++ b/Runtime/VirtualCameras/CameraTargetOffset.cs @@ -0,0 +1,53 @@ + +using System.Diagnostics; +using System.Collections; +using System.Collections.Generic; +using System; +using Godot; + + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class CameraTargetOffset:Node3D + { + [Export] + public float cameraTargetMinOffsetZ = 0; + + [Export] + public float cameraTargetMaxOffsetZ = 10; + + [Export] + public Smoothing cameraTargetOffsetZSmoothing = new FrameSmoothing(); + + + [Export] + public float cameraTargetMinOffsetY = 1.7f; + + [Export] + public float cameraTargetMaxOffsetY = 2f; + + [Export] + public Smoothing cameraTargetOffsetYSmoothing = new FrameSmoothing(); + + protected float nextZ = 0; + protected float nextY = 0; + + public virtual void SetMovingForward( float movingForward ) + { + nextZ = Mathf.Lerp( cameraTargetMinOffsetZ, cameraTargetMaxOffsetZ, movingForward ); + nextY = Mathf.Lerp( cameraTargetMinOffsetY, cameraTargetMaxOffsetY, movingForward ); + } + + public override void _Process( double delta ) + { + var smoothedOffsetZ = cameraTargetOffsetZSmoothing.Smooth( nextZ, (float)delta ); + this.SetLocalZ( smoothedOffsetZ ); + + + var smoothedOffsetY = cameraTargetOffsetYSmoothing.Smooth( nextY, (float)delta ); + this.SetLocalY( smoothedOffsetY ); + } + } +} \ No newline at end of file diff --git a/Runtime/VirtualCameras/CameraTargetOffset.cs.uid b/Runtime/VirtualCameras/CameraTargetOffset.cs.uid new file mode 100644 index 0000000..14a2103 --- /dev/null +++ b/Runtime/VirtualCameras/CameraTargetOffset.cs.uid @@ -0,0 +1 @@ +uid://bk5eoi53m08jh diff --git a/Runtime/VirtualCameras/ThirdPersonCamera.cs b/Runtime/VirtualCameras/ThirdPersonCamera.cs index 8fb6438..03a76db 100644 --- a/Runtime/VirtualCameras/ThirdPersonCamera.cs +++ b/Runtime/VirtualCameras/ThirdPersonCamera.cs @@ -14,6 +14,9 @@ namespace Rokojori { [Export] public Node3D target; + + [Export] + public Smoothing targetFollowSmoothing = new FrameSmoothing(); [ExportGroup("Yaw")] @@ -26,14 +29,39 @@ namespace Rokojori [Export] public Sensor yawNegativeAxis; + [Export] + public bool roundYaw = false; + + [Export] + public int roundedYawResolution = 64; [Export] public float yaw = 0; [Export] - public float yawSmoothingDuration = 0.1f; + public Smoothing yawSmoothing = new FrameSmoothing(); + + [Export] + public bool yawGoesBehindPlayer = true; + + [Export] + public Smoothing yawToBehingSmoothing = new FrameSmoothing(); + + [Export] + public float yawBehindDelayDuration = 5; + + [Export] + public float yawGoesBehindActivation = 0.1f; + + [Export] + public float behindYaw = 0; + + [Export] + public float currentYaw = 0; + + [Export] + public float bcDelta = 0; - Smoother yawSmoother = new Smoother(); [ExportGroup("Pitch")] @@ -58,27 +86,44 @@ namespace Rokojori [Export] public float maxPitch = 80; + public float normalizedPitch => MathX.NormalizeClamped( pitch, minPitch, maxPitch ); + [Export] - public float pitchSmoothingDuration = 0.1f; + public Smoothing pitchSmoothing = new FrameSmoothing(); - Smoother pitchSmoother = new Smoother(); + [Export] + public bool pitchGoesBackToCenter = true; + [Export] + public Smoothing toCenterPitchSmoothing = new FrameSmoothing(); + + [Export] + public float centerPitchDelayDuration = 5; + + [Export] + public float centerPitch = 30; + + [Export] + public float centerPitchActivation = 0.1f; + + [ExportGroup("Distance")] [Export] public Curve distanceForPitch = MathX.Curve( 1, 1 ); [Export] public float distanceScale = 1; - [ExportGroup("Offset")] + [ExportGroup("Camera Offset")] [Export] public Vector3 offset; - Smoother distanceSmoother = new Smoother(); float smoothedYaw = 0; float smoothedPitch = 0; float smoothedDistance = 0; + float _centerPitchActivation = 0; + float _yawBehindActivation = 0; public override void _Process( double delta ) { @@ -87,38 +132,97 @@ namespace Rokojori return; } + behindYaw = Math3D.GlobalYawDegrees( target.GlobalForward() * -1 ); + behindYaw = MathX.NormalizeAngle( behindYaw ); + + currentYaw = MathX.NormalizeAngle( yaw ); + + bcDelta = MathX.NormalizeAngle( MathX.AngleDelta( behindYaw, currentYaw ) ); + + var targetPosition = Smoothing.Apply( targetFollowSmoothing, target.GlobalPosition, (float) delta ); + + var yawAxis = Sensors.PolarAxis( yawNegativeAxis, yawPositiveAxis ); var pitchAxis = Sensors.PolarAxis( pitchNegativeAxis, pitchPositiveAxis ); yaw += yawAxis * yawSpeed * (float)delta; + + if ( yawGoesBehindPlayer ) + { + if ( Mathf.Abs( yawAxis ) < yawGoesBehindActivation ) + { + _yawBehindActivation += (float)delta; + + if ( yawGoesBehindPlayer && _yawBehindActivation > yawBehindDelayDuration ) + { + yaw = Smoothing.ApplyDegreesWith( yawToBehingSmoothing, yaw, behindYaw, (float) delta ); + } + + } + else + { + _yawBehindActivation = 0; + } + } + // yaw = MathX.Repeat( yaw, 360f ); if ( pitchIsRelative ) { pitch += pitchAxis * pitchSpeed * (float)delta; pitch = Mathf.Clamp( pitch, minPitch, maxPitch ); + + if ( Mathf.Abs( pitchAxis ) < centerPitchActivation ) + { + _centerPitchActivation += (float)delta; + + if ( _centerPitchActivation > centerPitchDelayDuration ) + { + pitch = Smoothing.ApplyWith( toCenterPitchSmoothing, pitch, centerPitch, (float) delta ); + } + } + else + { + _centerPitchActivation = 0; + } } else { pitch = Mathf.Remap( pitchAxis, -1, 1, minPitch, maxPitch ); } + - if ( Mathf.Abs( yaw - smoothedYaw ) > 180 ) - { - if ( yaw > smoothedYaw ) - { - smoothedYaw += 360; - } - else if ( yaw < smoothedYaw ) - { - smoothedYaw -= 360; - } - } + // if ( Mathf.Abs( yaw - smoothedYaw ) > 180 ) + // { + // if ( yaw > smoothedYaw ) + // { + // smoothedYaw += 360; + // } + // else if ( yaw < smoothedYaw ) + // { + // smoothedYaw -= 360; + // } + // } + + var appliedYaw = yaw; + + // if ( roundYaw ) + // { + // appliedYaw = MathX.SnapRounded( yaw, 360f/roundedYawResolution ); + // } + + smoothedYaw = Smoothing.ApplyDegrees( yawSmoothing, appliedYaw, (float) delta ); + + + smoothedPitch = Smoothing.Apply( pitchSmoothing, pitch, (float) delta ); + + // if ( pitchGoesBackToCenter ) + // { + // pitch = toCenterPitchSmoothing.Smooth( centerPitch, (float) delta ); + // } - smoothedYaw = yaw; - smoothedPitch = pitchSmoother.SmoothForDuration( smoothedPitch, pitch, pitchSmoothingDuration, (float) delta ); // RJLog.Log( "Pitch", smoothedPitch ); @@ -126,11 +230,11 @@ namespace Rokojori // smoothedPitch = pitch; var distance = distanceForPitch.Sample( MathX.NormalizeClamped( pitch, minPitch, maxPitch ) ) * distanceScale; - GlobalPosition = target.GlobalPosition + Math3D.YawPitchRotation( smoothedYaw, smoothedPitch ) * Vector3.Forward * distance + offset; + GlobalPosition = targetPosition + Math3D.YawPitchRotation( smoothedYaw, smoothedPitch ) * Vector3.Forward * distance; - LookAt( target.GlobalPosition + offset, Vector3.Up, true ); + LookAt( targetPosition, Vector3.Up, true ); - + GlobalPosition += this.GetOrientationBasedGlobalOffset( offset ); } diff --git a/Runtime/VirtualCameras/ThirdPersonCameraTargetOffset.cs b/Runtime/VirtualCameras/ThirdPersonCameraTargetOffset.cs new file mode 100644 index 0000000..6fa7d57 --- /dev/null +++ b/Runtime/VirtualCameras/ThirdPersonCameraTargetOffset.cs @@ -0,0 +1,39 @@ + +using System.Diagnostics; +using System.Collections; +using System.Collections.Generic; +using System; +using Godot; + + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class ThirdPersonCameraTargetOffset:CameraTargetOffset + { + + [Export] + public ThirdPersonCamera thirdPersonCamera; + + [Export] + public Curve pitchMultiply; + + + public override void SetMovingForward( float movingForward ) + { + if ( pitchMultiply != null && thirdPersonCamera != null ) + { + var normalizedPitch = thirdPersonCamera.normalizedPitch; + var sampledPitchMultiply = pitchMultiply.Sample( normalizedPitch ); + movingForward *= sampledPitchMultiply; + } + + + + nextZ = Mathf.Lerp( cameraTargetMinOffsetZ, cameraTargetMaxOffsetZ, movingForward ); + nextY = Mathf.Lerp( cameraTargetMinOffsetY, cameraTargetMaxOffsetY, movingForward ); + } + + } +} \ No newline at end of file diff --git a/Runtime/VirtualCameras/ThirdPersonCameraTargetOffset.cs.uid b/Runtime/VirtualCameras/ThirdPersonCameraTargetOffset.cs.uid new file mode 100644 index 0000000..5f05268 --- /dev/null +++ b/Runtime/VirtualCameras/ThirdPersonCameraTargetOffset.cs.uid @@ -0,0 +1 @@ +uid://s7mi8hpmma3e diff --git a/Runtime/VirtualCameras/VirtualCamera3DManager.cs b/Runtime/VirtualCameras/VirtualCamera3DManager.cs index 892929e..c496397 100644 --- a/Runtime/VirtualCameras/VirtualCamera3DManager.cs +++ b/Runtime/VirtualCameras/VirtualCamera3DManager.cs @@ -21,6 +21,7 @@ namespace Rokojori [Export] public bool active = false; + public static VirtualCamera3DManager Get() { return Unique.Get();