Lovense Integration
|
This component calculates Lovense command speeds based on the average bone movement of N bones on N skeletal mesh components and broadcasts commands to all connected toys.
The commands that are sent are ELovenseCommand::Pattern for Lovense Remote and ELovenseCommand::Vibrate, ELovenseCommand::RotateClockwise, ELovenseCommand::RotateAntiClockwise, ELovenseCommand::AirAuto for Lovense Connect.
For ELovenseCommand::Pattern, a pattern will be generated every 4 seconds based on animation data that gets passed in via getAnimationDataDelegate. This mode is called "Pattern Generation".
For the Lovense Connect commands, we average the physics linear velocities of all bones in real time. This mode is called "Realtime Evaluation".
More...
#include <LovenseIntegration/Source/LovenseIntegration/Public/Components/LovenseToyAnimationControlComponent.h>
Public Member Functions | |
virtual void | Initialize (const TArray< USkeletalMeshComponent * > &inSkeletalMeshComponents, const TArray< FName > &inBoneNames, const FLovenseGetAnimationData &inGetAnimationDataDelegate) |
Initializes the component with required data. Can be called multiple times. More... | |
virtual void | StartBehaviour () |
Resets running values and calls SetEnabled(true). Should be called when first enabling this component and after each animation transition (See StartTransition()). | |
virtual void | StartTransition () |
Sets max toy speed to maxToySpeedTargetDuringTransition and flips rotation direction. Should be called before blending to a new animation, though it's not necessary. This will prevent the toy from freaking out due to high bone velocities during an animation blend. The Rotation direction change only works for Lovense Connect, as rotation direction can't be controlled with Lovense Remote. Call StartBehaviour() once transition has finished to reset. | |
virtual void | SetEnabled (bool value) |
Enable/Disable the component. Component will not run and no commands will be sent while the component is disabled. More... | |
FORCEINLINE bool | IsEnabled () |
virtual void | OnGamePaused () |
Disables the component when the game has been paused to stop the toys. More... | |
virtual void | OnGameUnpaused () |
Enables the component when the game has been unpaused. More... | |
virtual void | TickComponent (float DeltaTime, ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override |
virtual void | EndPlay (const EEndPlayReason::Type EndPlayReason) override |
FORCEINLINE float | GetMaxRecordedVelocityDecaySpeed () |
Get the speed (per second) at which maxRecordedVelocity will decay at. Only relevant for realtime evaluation. | |
FORCEINLINE void | SetMaxRecordedVelocityDecaySpeed (float newDecaySpeed) |
Set the speed (per second) at which maxRecordedVelocity will decay at. Only relevant for realtime evaluation. | |
FORCEINLINE float | GetMaxRecordedVelocityDecayMinimum () |
Naming is a bit confusing, this is the minimum value that maxRecordedVelocity can decay to. Only relevant for realtime evaluation. | |
FORCEINLINE void | SetMaxRecordedVelocityDecayMinimum (float newDecayMinimum) |
Naming is a bit confusing, this is the minimum value that maxRecordedVelocity can decay to. Only relevant for realtime evaluation. | |
FORCEINLINE float | GetMaxToySpeedInterpolationSpeed () |
Get interpolation speed at which currentMaxToySpeed will be interpolated towards maxToySpeedTarget. Only relevant for realtime evaluation. | |
FORCEINLINE void | SetMaxToySpeedInterpolationSpeed (float newInterpolationSpeed) |
Set interpolation speed at which currentMaxToySpeed will be interpolated towards maxToySpeedTarget. Only relevant for realtime evaluation. | |
FORCEINLINE float | GetMaxToySpeedTargetDuringTransition () |
Get maximum toy command speed that maxToySpeedTarget will be set to during transitions (See StartTransition()). Value is between 1-20. Only relevant for realtime evaluation. | |
FORCEINLINE void | SetMaxToySpeedTargetDuringTransition (float newSpeedTargetDuringTransition) |
Set maximum toy command speed that maxToySpeedTarget will be set to during transitions (See StartTransition()). Value should be between 1-20. Only relevant for realtime evaluation. | |
FORCEINLINE FVector2D | GetPatternToySpeedInputRange () |
Get input value range for the average velocity to toy command speed conversion. E.g. if X = 5cm/s and Y = 15cm/s, toy command speed will be 1 if average velocity is <=5cm/s and 20 if average velocity is >= 15cm/s. Values are >=0 and X<=Y. Only relevant for pattern generation. | |
FORCEINLINE void | SetPatternToySpeedInputRange (FVector2D newInputRange) |
Set input value range for the average velocity to toy command speed conversion. E.g. if X = 5cm/s and Y = 15cm/s, toy command speed will be 1 if average velocity is <=5cm/s and 20 if average velocity is >= 15cm/s. Values should be >=0 and X<=Y. Only relevant for pattern generation. | |
const FORCEINLINE TArray< USkeletalMeshComponent * > & | GetSkeletalMeshComponents () |
Get the skeletal meshes that will be evaluated. All of these components have to use the same skeleton or have all bones defined in boneNames. Gets passed in via Initialize(). | |
const FORCEINLINE TArray< FName > & | GetBoneNames () |
Get the names of the bones of the skeletal meshes that will be evaluated. This component calculates an average velocity across these bones of all skeletal meshes, which is then converted to a toy command speed. Gets passed in via Initialize(). | |
FORCEINLINE float | GeMaxRecordedVelocity () |
Get the current maximum velocity that has been calculated. Used to remap the current velocity to a toy command speed value. This will slowly decay if the current velocity is smaller. Decay speed is defined by maxRecordedVelocityDecaySpeed. Only relevant for realtime evaluation. | |
FORCEINLINE float | GeCurrentMaxToySpeed () |
Get the current maximum toy command speed. Is interpolated towards maxToySpeedTarget with maxToySpeedInterpolationSpeed. Only relevant for realtime evaluation. | |
FORCEINLINE float | GeMaxToySpeedTarget () |
Get the target value that currentMaxToySpeed gets interpolated to. Is usually 20, but will be dropped to maxToySpeedTargetDuringTransition during transitions (see StartTransition()). Only relevant for realtime evaluation. | |
FORCEINLINE bool | GeRotateClockwise () |
Whether the toys should rotate clockwise or anticlockwise. Gets toggled in StartTransition(). Only relevant for realtime evaluation. | |
Protected Member Functions | |
virtual void | OnPatternGenerationTimerFinished () |
Called every 4 seconds when the generate pattern timer loops. Generates a pattern based on animation data passed in via getAnimationDataDelegate and sends a pattern command with the generated pattern. | |
virtual void | RealtimeEvaluationUpdate (float deltaTime) |
Called every tick. Calculates current toy command speed based on the average physics linear velocity of all boneNames of all skeletalMeshComponents and sends Lovense Connect commands. | |
virtual bool | GeneratePattern (const TArray< class UAnimSequence * > &animations, const TArray< float > ×, FLovensePattern &outPattern) |
Called by OnPatternGenerationTimerFinished(). Generates a pattern based on animation data passed in via getAnimationDataDelegate. More... | |
Protected Attributes | |
float | maxAverageVelocity |
Maximum velocity the average velocity of all bones on all skeletal mesh components will be capped to. Should be as small as possible to prevent situations where it takes a long time for maxRecordedVelocity to decay. Only relevant for realtime evaluation. | |
float | maxRecordedVelocityDecaySpeed |
The speed (per second) at which maxRecordedVelocity will decay at. Only relevant for realtime evaluation. | |
float | maxRecordedVelocityDecayMinimum |
Naming is a bit confusing, this is the minimum value that maxRecordedVelocity can decay to. Only relevant for realtime evaluation. | |
float | maxToySpeedInterpolationSpeed |
Interpolation speed at which currentMaxToySpeed will be interpolated towards maxToySpeedTarget. Only relevant for realtime evaluation. | |
float | maxToySpeedTargetDuringTransition |
Maximum toy command speed that maxToySpeedTarget will be set to during transitions (See StartTransition()). Value should be between 1-20. Only relevant for realtime evaluation. | |
FVector2D | patternToySpeedInputRange |
Input value range for the average velocity to toy command speed conversion. E.g. if X = 5cm/s and Y = 15cm/s, toy command speed will be 1 if average velocity is <=5cm/s and 20 if average velocity is >= 15cm/s. Values should be >=0 and X<=Y. Only relevant for pattern generation. | |
TArray< USkeletalMeshComponent * > | skeletalMeshComponents |
The skeletal meshes that will be evaluated. All of these components have to use the same skeleton or have all bones defined in boneNames. Gets passed in via Initialize(). | |
TArray< FName > | boneNames |
The names of the bones of the skeletal meshes that will be evaluated. This component calculates an average velocity across these bones of all skeletal meshes, which is then converted to a toy command speed. Gets passed in via Initialize(). | |
float | maxRecordedVelocity |
The current maximum velocity that has been calculated. Used to remap the current velocity to a toy command speed value. This will slowly decay if the current velocity is smaller. Decay speed is defined by maxRecordedVelocityDecaySpeed. Only relevant for realtime evaluation. | |
float | currentMaxToySpeed |
The current maximum toy command speed. Is interpolated towards maxToySpeedTarget with maxToySpeedInterpolationSpeed. Only relevant for realtime evaluation. | |
float | maxToySpeedTarget |
The target value that currentMaxToySpeed gets interpolated to. Is usually 20, but will be dropped to maxToySpeedTargetDuringTransition during transitions (see StartTransition()). Only relevant for realtime evaluation. | |
bool | bRotateClockwise |
Whether the toys should rotate clockwise or anticlockwise. Gets toggled in StartTransition(). Only relevant for realtime evaluation. | |
bool | bIsEnabled |
Whether the component is currently enabled. Component will not run and no commands will be sent while the component is disabled. | |
FTimerHandle | patternGenerationTimerHandle |
Handle for the pattern generation timer. Timer is looping with an interval of 4 seconds. Will generate and send a pattern command on each iteration. Only relevant for pattern generation. | |
FLovenseGetAnimationData | getAnimationDataDelegate |
Executed every 4 seconds in OnPatternGenerationTimerFinished() when pattern generation timer loops to retrieve animation data from external code that uses this component. Gets passed in via Initialize(). Only relevant for pattern generation. | |
This component calculates Lovense command speeds based on the average bone movement of N bones on N skeletal mesh components and broadcasts commands to all connected toys.
The commands that are sent are ELovenseCommand::Pattern for Lovense Remote and ELovenseCommand::Vibrate, ELovenseCommand::RotateClockwise, ELovenseCommand::RotateAntiClockwise, ELovenseCommand::AirAuto for Lovense Connect.
For ELovenseCommand::Pattern, a pattern will be generated every 4 seconds based on animation data that gets passed in via getAnimationDataDelegate. This mode is called "Pattern Generation".
For the Lovense Connect commands, we average the physics linear velocities of all bones in real time. This mode is called "Realtime Evaluation".
|
protectedvirtual |
Called by OnPatternGenerationTimerFinished().
Generates a pattern based on animation data passed in via getAnimationDataDelegate.
|
virtual |
Initializes the component with required data. Can be called multiple times.
inSkeletalMeshComponents | The skeletal meshes that will be evaluated. All of these components have to use the same skeleton or have all bones defined in boneNames. |
inBoneNames | The names of the bones of the skeletal meshes that will be evaluated. This component calculates an average velocity across these bones of all skeletal meshes, which is then converted to a toy command speed. |
inGetAnimationDataDelegate | Event delegate called once every 4 seconds to retrieve animation data. See FLovenseCalculateAnimationTime for more information. |
|
inline |
|
virtual |
Disables the component when the game has been paused to stop the toys.
|
virtual |
Enables the component when the game has been unpaused.
|
virtual |
Enable/Disable the component. Component will not run and no commands will be sent while the component is disabled.
value | If false, realtime evaluation will be stopped, pattern generation timer will be stopped and all commands cleared. If true, realtime evaluation will be (re)started, will immediately generate and send a pattern command and (re)start the generate pattern timer. |