first commit
This commit is contained in:
117
addons/phantom_camera/scripts/resources/Camera3DResource.cs
Normal file
117
addons/phantom_camera/scripts/resources/Camera3DResource.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
using Godot;
|
||||
|
||||
namespace PhantomCamera;
|
||||
|
||||
public enum KeepAspect
|
||||
{
|
||||
KeepWidth,
|
||||
KeepHeight
|
||||
}
|
||||
|
||||
public enum ProjectionType
|
||||
{
|
||||
Perspective,
|
||||
Orthogonal,
|
||||
Frustum
|
||||
}
|
||||
|
||||
public class Camera3DResource(Resource resource)
|
||||
{
|
||||
public readonly Resource Resource = resource;
|
||||
|
||||
public KeepAspect KeepAspect
|
||||
{
|
||||
get => (KeepAspect)(int)Resource.Call(MethodName.GetKeepAspect);
|
||||
set => Resource.Call(MethodName.SetKeepAspect, (int)value);
|
||||
}
|
||||
|
||||
public int CullMask
|
||||
{
|
||||
get => (int)Resource.Call(MethodName.GetCullMask);
|
||||
set => Resource.Call(MethodName.SetCullMask, value);
|
||||
}
|
||||
|
||||
public void SetCullMaskValue(int layer, bool value) => Resource.Call(MethodName.SetCullMaskValue, layer, value);
|
||||
|
||||
public float HOffset
|
||||
{
|
||||
get => (float)Resource.Call(MethodName.GetHOffset);
|
||||
set => Resource.Call(MethodName.SetHOffset, value);
|
||||
}
|
||||
|
||||
public float VOffset
|
||||
{
|
||||
get => (float)Resource.Call(MethodName.GetVOffset);
|
||||
set => Resource.Call(MethodName.SetVOffset, value);
|
||||
}
|
||||
|
||||
public ProjectionType Projection
|
||||
{
|
||||
get => (ProjectionType)(int)Resource.Call(MethodName.GetProjection);
|
||||
set => Resource.Call(MethodName.SetProjection, (int)value);
|
||||
}
|
||||
|
||||
public float Fov
|
||||
{
|
||||
get => (float)Resource.Call(MethodName.GetFov);
|
||||
set => Resource.Call(MethodName.SetFov, Mathf.Clamp(value, 1, 179));
|
||||
}
|
||||
|
||||
public float Size
|
||||
{
|
||||
get => (float)Resource.Call(MethodName.GetSize);
|
||||
set => Resource.Call(MethodName.SetSize, Mathf.Clamp(value, 0.001f, float.PositiveInfinity));
|
||||
}
|
||||
|
||||
public Vector2 FrustumOffset
|
||||
{
|
||||
get => (Vector2)Resource.Call(MethodName.GetFrustumOffset);
|
||||
set => Resource.Call(MethodName.SetFrustumOffset, value);
|
||||
}
|
||||
|
||||
public float Near
|
||||
{
|
||||
get => (float)Resource.Call(MethodName.GetNear);
|
||||
set => Resource.Call(MethodName.SetNear, Mathf.Clamp(value, 0.001f, float.PositiveInfinity));
|
||||
}
|
||||
|
||||
public float Far
|
||||
{
|
||||
get => (float)Resource.Call(MethodName.GetFar);
|
||||
set => Resource.Call(MethodName.SetFar, Mathf.Clamp(value, 0.01f, float.PositiveInfinity));
|
||||
}
|
||||
|
||||
public static class MethodName
|
||||
{
|
||||
public const string GetKeepAspect = "get_keep_aspect";
|
||||
public const string SetKeepAspect = "set_keep_aspect";
|
||||
|
||||
public const string GetCullMask = "get_cull_mask";
|
||||
public const string SetCullMask = "set_cull_mask";
|
||||
public const string SetCullMaskValue = "set_cull_mask_value";
|
||||
|
||||
public const string GetHOffset = "get_h_offset";
|
||||
public const string SetHOffset = "set_h_offset";
|
||||
|
||||
public const string GetVOffset = "get_v_offset";
|
||||
public const string SetVOffset = "set_v_offset";
|
||||
|
||||
public const string GetProjection = "get_projection";
|
||||
public const string SetProjection = "set_projection";
|
||||
|
||||
public const string GetFov = "get_fov";
|
||||
public const string SetFov = "set_fov";
|
||||
|
||||
public const string GetSize = "get_size";
|
||||
public const string SetSize = "set_size";
|
||||
|
||||
public const string GetFrustumOffset = "get_frustum_offset";
|
||||
public const string SetFrustumOffset = "set_frustum_offset";
|
||||
|
||||
public const string GetNear = "get_near";
|
||||
public const string SetNear = "set_near";
|
||||
|
||||
public const string GetFar = "get_far";
|
||||
public const string SetFar = "set_far";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://jedyxlihuwbj
|
||||
@@ -0,0 +1,92 @@
|
||||
using Godot;
|
||||
|
||||
namespace PhantomCamera.Noise;
|
||||
|
||||
public class PhantomCameraNoise2D(Resource resource)
|
||||
{
|
||||
public readonly Resource Resource = resource;
|
||||
|
||||
public float Amplitude
|
||||
{
|
||||
get => (float)Resource.Call(MethodName.GetAmplitude);
|
||||
set => Resource.Call(MethodName.SetAmplitude, value);
|
||||
}
|
||||
|
||||
public float Frequency
|
||||
{
|
||||
get => (float)Resource.Call(MethodName.GetFrequency);
|
||||
set => Resource.Call(MethodName.SetFrequency, value);
|
||||
}
|
||||
|
||||
public bool RandomizeNoiseSeed
|
||||
{
|
||||
get => (bool)Resource.Call(MethodName.GetRandomizeNoiseSeed);
|
||||
set => Resource.Call(MethodName.SetRandomizeNoiseSeed, value);
|
||||
}
|
||||
|
||||
public int NoiseSeed
|
||||
{
|
||||
get => (int)Resource.Call(MethodName.GetNoiseSeed);
|
||||
set => Resource.Call(MethodName.SetNoiseSeed, value);
|
||||
}
|
||||
|
||||
public bool RotationalNoise
|
||||
{
|
||||
get => (bool)Resource.Call(MethodName.GetRotationalNoise);
|
||||
set => Resource.Call(MethodName.SetRotationalNoise, value);
|
||||
}
|
||||
|
||||
public bool PositionalNoise
|
||||
{
|
||||
get => (bool)Resource.Call(MethodName.GetPositionalNoise);
|
||||
set => Resource.Call(MethodName.SetPositionalNoise, value);
|
||||
}
|
||||
|
||||
public float RotationalMultiplier
|
||||
{
|
||||
get => (float)Resource.Call(MethodName.GetRotationalMultiplier);
|
||||
set => Resource.Call(MethodName.SetRotationalMultiplier, value);
|
||||
}
|
||||
|
||||
public float PositionalMultiplierX
|
||||
{
|
||||
get => (float)Resource.Call(MethodName.GetPositionalMultiplierX);
|
||||
set => Resource.Call(MethodName.SetPositionalMultiplierX, value);
|
||||
}
|
||||
|
||||
public float PositionalMultiplierY
|
||||
{
|
||||
get => (float)Resource.Call(MethodName.GetPositionalMultiplierY);
|
||||
set => Resource.Call(MethodName.SetPositionalMultiplierY, value);
|
||||
}
|
||||
|
||||
public static class MethodName
|
||||
{
|
||||
public const string GetAmplitude = "get_amplitude";
|
||||
public const string SetAmplitude = "set_amplitude";
|
||||
|
||||
public const string GetFrequency = "get_frequency";
|
||||
public const string SetFrequency = "set_frequency";
|
||||
|
||||
public const string GetRandomizeNoiseSeed = "get_randomize_noise_seed";
|
||||
public const string SetRandomizeNoiseSeed = "set_randomize_noise_seed";
|
||||
|
||||
public const string GetNoiseSeed = "get_noise_seed";
|
||||
public const string SetNoiseSeed = "set_noise_seed";
|
||||
|
||||
public const string GetRotationalNoise = "get_rotational_noise";
|
||||
public const string SetRotationalNoise = "set_rotational_noise";
|
||||
|
||||
public const string GetPositionalNoise = "get_positional_noise";
|
||||
public const string SetPositionalNoise = "set_positional_noise";
|
||||
|
||||
public const string GetRotationalMultiplier = "get_rotational_multiplier";
|
||||
public const string SetRotationalMultiplier = "set_rotational_multiplier";
|
||||
|
||||
public const string GetPositionalMultiplierX = "get_positional_multiplier_x";
|
||||
public const string SetPositionalMultiplierX = "set_positional_multiplier_x";
|
||||
|
||||
public const string GetPositionalMultiplierY = "get_positional_multiplier_y";
|
||||
public const string SetPositionalMultiplierY = "set_positional_multiplier_y";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://capjdoxs6gs6r
|
||||
119
addons/phantom_camera/scripts/resources/PhantomCameraNoise3D.cs
Normal file
119
addons/phantom_camera/scripts/resources/PhantomCameraNoise3D.cs
Normal file
@@ -0,0 +1,119 @@
|
||||
using Godot;
|
||||
|
||||
namespace PhantomCamera.Noise;
|
||||
|
||||
public class PhantomCameraNoise3D(Resource resource)
|
||||
{
|
||||
public readonly Resource Resource = resource;
|
||||
|
||||
public float Amplitude
|
||||
{
|
||||
get => (float)Resource.Call(MethodName.GetAmplitude);
|
||||
set => Resource.Call(MethodName.SetAmplitude, value);
|
||||
}
|
||||
|
||||
public float Frequency
|
||||
{
|
||||
get => (float)Resource.Call(MethodName.GetFrequency);
|
||||
set => Resource.Call(MethodName.SetFrequency, value);
|
||||
}
|
||||
|
||||
public bool RandomizeNoiseSeed
|
||||
{
|
||||
get => (bool)Resource.Call(MethodName.GetRandomizeNoiseSeed);
|
||||
set => Resource.Call(MethodName.SetRandomizeNoiseSeed, value);
|
||||
}
|
||||
|
||||
public int NoiseSeed
|
||||
{
|
||||
get => (int)Resource.Call(MethodName.GetNoiseSeed);
|
||||
set => Resource.Call(MethodName.SetNoiseSeed, value);
|
||||
}
|
||||
|
||||
public bool RotationalNoise
|
||||
{
|
||||
get => (bool)Resource.Call(MethodName.GetRotationalNoise);
|
||||
set => Resource.Call(MethodName.SetRotationalNoise, value);
|
||||
}
|
||||
|
||||
public bool PositionalNoise
|
||||
{
|
||||
get => (bool)Resource.Call(MethodName.GetPositionalNoise);
|
||||
set => Resource.Call(MethodName.SetPositionalNoise, value);
|
||||
}
|
||||
|
||||
public float RotationalMultiplierX
|
||||
{
|
||||
get => (float)Resource.Call(MethodName.GetRotationalMultiplierX);
|
||||
set => Resource.Call(MethodName.SetRotationalMultiplierX, value);
|
||||
}
|
||||
|
||||
public float RotationalMultiplierY
|
||||
{
|
||||
get => (float)Resource.Call(MethodName.GetRotationalMultiplierY);
|
||||
set => Resource.Call(MethodName.SetRotationalMultiplierY, value);
|
||||
}
|
||||
|
||||
public float RotationalMultiplierZ
|
||||
{
|
||||
get => (float)Resource.Call(MethodName.GetRotationalMultiplierZ);
|
||||
set => Resource.Call(MethodName.SetRotationalMultiplierZ, value);
|
||||
}
|
||||
|
||||
public float PositionalMultiplierX
|
||||
{
|
||||
get => (float)Resource.Call(MethodName.GetPositionalMultiplierX);
|
||||
set => Resource.Call(MethodName.SetPositionalMultiplierX, value);
|
||||
}
|
||||
|
||||
public float PositionalMultiplierY
|
||||
{
|
||||
get => (float)Resource.Call(MethodName.GetPositionalMultiplierY);
|
||||
set => Resource.Call(MethodName.SetPositionalMultiplierY, value);
|
||||
}
|
||||
|
||||
public float PositionalMultiplierZ
|
||||
{
|
||||
get => (float)Resource.Call(MethodName.GetPositionalMultiplierZ);
|
||||
set => Resource.Call(MethodName.SetPositionalMultiplierZ, value);
|
||||
}
|
||||
|
||||
public static class MethodName
|
||||
{
|
||||
public const string GetAmplitude = "get_amplitude";
|
||||
public const string SetAmplitude = "set_amplitude";
|
||||
|
||||
public const string GetFrequency = "get_frequency";
|
||||
public const string SetFrequency = "set_frequency";
|
||||
|
||||
public const string GetRandomizeNoiseSeed = "get_randomize_noise_seed";
|
||||
public const string SetRandomizeNoiseSeed = "set_randomize_noise_seed";
|
||||
|
||||
public const string GetNoiseSeed = "get_noise_seed";
|
||||
public const string SetNoiseSeed = "set_noise_seed";
|
||||
|
||||
public const string GetRotationalNoise = "get_rotational_noise";
|
||||
public const string SetRotationalNoise = "set_rotational_noise";
|
||||
|
||||
public const string GetPositionalNoise = "get_positional_noise";
|
||||
public const string SetPositionalNoise = "set_positional_noise";
|
||||
|
||||
public const string GetRotationalMultiplierX = "get_rotational_multiplier_x";
|
||||
public const string SetRotationalMultiplierX = "set_rotational_multiplier_x";
|
||||
|
||||
public const string GetRotationalMultiplierY = "get_rotational_multiplier_y";
|
||||
public const string SetRotationalMultiplierY = "set_rotational_multiplier_y";
|
||||
|
||||
public const string GetRotationalMultiplierZ = "get_rotational_multiplier_z";
|
||||
public const string SetRotationalMultiplierZ = "set_rotational_multiplier_z";
|
||||
|
||||
public const string GetPositionalMultiplierX = "get_positional_multiplier_x";
|
||||
public const string SetPositionalMultiplierX = "set_positional_multiplier_x";
|
||||
|
||||
public const string GetPositionalMultiplierY = "get_positional_multiplier_y";
|
||||
public const string SetPositionalMultiplierY = "set_positional_multiplier_y";
|
||||
|
||||
public const string GetPositionalMultiplierZ = "get_positional_multiplier_z";
|
||||
public const string SetPositionalMultiplierZ = "set_positional_multiplier_z";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://chk7643ynhe4f
|
||||
@@ -0,0 +1,64 @@
|
||||
using Godot;
|
||||
|
||||
namespace PhantomCamera;
|
||||
|
||||
public enum TransitionType
|
||||
{
|
||||
Linear,
|
||||
Sine,
|
||||
Quint,
|
||||
Quart,
|
||||
Quad,
|
||||
Expo,
|
||||
Elastic,
|
||||
Cubic,
|
||||
Circ,
|
||||
Bounce,
|
||||
Back
|
||||
}
|
||||
|
||||
public enum EaseType
|
||||
{
|
||||
EaseIn,
|
||||
EaseOut,
|
||||
EaseInOut,
|
||||
EaseOutIn
|
||||
}
|
||||
|
||||
public static class PhantomCameraTweenExtensions
|
||||
{
|
||||
public static PhantomCameraTween AsPhantomCameraTween(this Resource resource)
|
||||
{
|
||||
return new PhantomCameraTween(resource);
|
||||
}
|
||||
}
|
||||
|
||||
public class PhantomCameraTween(Resource tweenResource)
|
||||
{
|
||||
public Resource Resource { get; } = tweenResource;
|
||||
|
||||
public float Duration
|
||||
{
|
||||
get => (float)Resource.Get(PropertyName.Duration);
|
||||
set => Resource.Set(PropertyName.Duration, value);
|
||||
}
|
||||
|
||||
public TransitionType Transition
|
||||
{
|
||||
get => (TransitionType)(int)Resource.Get(PropertyName.Transition);
|
||||
set => Resource.Set(PropertyName.Transition, (int)value);
|
||||
}
|
||||
|
||||
public EaseType Ease
|
||||
{
|
||||
get => (EaseType)(int)Resource.Get(PropertyName.Ease);
|
||||
set => Resource.Set(PropertyName.Ease, (int)value);
|
||||
}
|
||||
|
||||
public static class PropertyName
|
||||
{
|
||||
public const string Duration = "duration";
|
||||
public const string Transition = "transition";
|
||||
public const string Ease = "ease";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://ybr5c2s0tfvx
|
||||
110
addons/phantom_camera/scripts/resources/camera_3d_resource.gd
Normal file
110
addons/phantom_camera/scripts/resources/camera_3d_resource.gd
Normal file
@@ -0,0 +1,110 @@
|
||||
@tool
|
||||
@icon("res://addons/phantom_camera/icons/phantom_camera_camera_3d_resource.svg")
|
||||
class_name Camera3DResource
|
||||
extends Resource
|
||||
|
||||
## Resource for [PhantomCamera3D] to override various [Camera3D] properties.
|
||||
##
|
||||
## The overrides defined here will be applied to the [Camera3D] upon the
|
||||
## [PhantomCamera3D] becoming active.
|
||||
|
||||
enum KeepAspect {
|
||||
KEEP_WIDTH = 0, ## Preserves the horizontal aspect ratio; also known as Vert- scaling. This is usually the best option for projects running in portrait mode, as taller aspect ratios will benefit from a wider vertical FOV.
|
||||
KEEP_HEIGHT = 1, ## Preserves the vertical aspect ratio; also known as Hor+ scaling. This is usually the best option for projects running in landscape mode, as wider aspect ratios will automatically benefit from a wider horizontal FOV.
|
||||
}
|
||||
|
||||
enum ProjectionType {
|
||||
PERSPECTIVE = 0, ## Perspective projection. Objects on the screen becomes smaller when they are far away.
|
||||
ORTHOGONAL = 1, ## Orthogonal projection, also known as orthographic projection. Objects remain the same size on the screen no matter how far away they are.
|
||||
FRUSTUM = 2, ## Frustum projection. This mode allows adjusting frustum_offset to create "tilted frustum" effects.
|
||||
}
|
||||
|
||||
## Overrides [member Camera3D.keep_aspect].
|
||||
@export var keep_aspect: KeepAspect = KeepAspect.KEEP_HEIGHT:
|
||||
set(value):
|
||||
keep_aspect = value
|
||||
emit_changed()
|
||||
get:
|
||||
return keep_aspect
|
||||
|
||||
## Overrides [member Camera3D.cull_mask].
|
||||
@export_flags_3d_render var cull_mask: int = 1048575:
|
||||
set(value):
|
||||
cull_mask = value
|
||||
emit_changed()
|
||||
get:
|
||||
return cull_mask
|
||||
|
||||
## Overrides [member Camera3D.h_offset].
|
||||
@export_range(0, 1, 0.001, "or_greater", "or_less", "hide_slider", "suffix:m") var h_offset: float = 0:
|
||||
set(value):
|
||||
h_offset = value
|
||||
emit_changed()
|
||||
get:
|
||||
return h_offset
|
||||
|
||||
## Overrides [member Camera3D.v_offset].
|
||||
@export_range(0, 1, 0.001, "or_greater", "or_less", "hide_slider", "suffix:m") var v_offset: float = 0:
|
||||
set(value):
|
||||
v_offset = value
|
||||
emit_changed()
|
||||
|
||||
## Overrides [member Camera3D.projection].
|
||||
@export var projection: ProjectionType = ProjectionType.PERSPECTIVE:
|
||||
set(value):
|
||||
projection = value
|
||||
notify_property_list_changed()
|
||||
emit_changed()
|
||||
get:
|
||||
return projection
|
||||
|
||||
## Overrides [member Camera3D.fov].
|
||||
@export_range(1, 179, 0.1, "degrees") var fov: float = 75:
|
||||
set(value):
|
||||
fov = value
|
||||
emit_changed()
|
||||
get:
|
||||
return fov
|
||||
|
||||
## Overrides [member Camera3D.size].
|
||||
@export_range(0.001, 100, 0.001, "suffix:m", "or_greater") var size: float = 1:
|
||||
set(value):
|
||||
size = value
|
||||
emit_changed()
|
||||
get:
|
||||
return size
|
||||
|
||||
## Overrides [member Camera3d.frustum_offset].
|
||||
@export var frustum_offset: Vector2 = Vector2.ZERO:
|
||||
set(value):
|
||||
frustum_offset = value
|
||||
emit_changed()
|
||||
get:
|
||||
return frustum_offset
|
||||
|
||||
## Overrides [member Camera3D.near].
|
||||
@export_range(0.001, 10, 0.001, "suffix:m", "or_greater") var near: float = 0.05:
|
||||
set(value):
|
||||
near = value
|
||||
emit_changed()
|
||||
get:
|
||||
return near
|
||||
|
||||
## Overrides [member Camera3D.far].
|
||||
@export_range(0.01, 4000, 0.001, "suffix:m","or_greater") var far: float = 4000:
|
||||
set(value):
|
||||
far = value
|
||||
emit_changed()
|
||||
get:
|
||||
return far
|
||||
|
||||
|
||||
func _validate_property(property: Dictionary) -> void:
|
||||
if property.name == "fov" and not projection == ProjectionType.PERSPECTIVE:
|
||||
property.usage = PROPERTY_USAGE_NO_EDITOR
|
||||
|
||||
if property.name == "size" and projection == ProjectionType.PERSPECTIVE:
|
||||
property.usage = PROPERTY_USAGE_NO_EDITOR
|
||||
|
||||
if property.name == "frustum_offset" and not projection == ProjectionType.FRUSTUM:
|
||||
property.usage = PROPERTY_USAGE_NO_EDITOR
|
||||
@@ -0,0 +1 @@
|
||||
uid://bc2tn187qiatpcheck
|
||||
@@ -0,0 +1,228 @@
|
||||
@tool
|
||||
@icon("res://addons/phantom_camera/icons/phantom_camera_noise_resource.svg")
|
||||
class_name PhantomCameraNoise2D
|
||||
extends Resource
|
||||
|
||||
## A resource type used to apply noise, or shake, to [Camera2D]s that have a [PhantomCameraHost] as a child.
|
||||
##
|
||||
## Is a resource type that defines, calculates and outputs the noise values to a [Camera2D] through active
|
||||
## [PhantomCamera3D].[br]
|
||||
## It can be applied to either [PhantomCameraNoiseEmitter2D] or a [PhantomCamera2D] noise property directly
|
||||
|
||||
#region Exported Properties
|
||||
|
||||
## Defines the size of the noise pattern.[br]
|
||||
## Higher values will increase the range the noise can reach.
|
||||
@export_range(0, 1000, 0.001, "or_greater") var amplitude: float = 10:
|
||||
set = set_amplitude,
|
||||
get = get_amplitude
|
||||
|
||||
## Sets the density of the noise pattern.[br]
|
||||
## Higher values will result in more erratic noise.
|
||||
@export_range(0, 10, 0.001, "or_greater") var frequency: float = 0.5:
|
||||
set = set_frequency,
|
||||
get = get_frequency
|
||||
|
||||
## If true, randomizes the noise pattern every time the noise is run.[br]
|
||||
## If disabled, [member seed] can be used to define a fixed noise pattern.
|
||||
@export var randomize_noise_seed: bool = true:
|
||||
set = set_randomize_noise_seed,
|
||||
get = get_randomize_noise_seed
|
||||
|
||||
## Sets a predetermined seed noise value.[br]
|
||||
## Useful if wanting to achieve a persistent noise pattern every time the noise is emitted.
|
||||
@export var noise_seed: int = 0:
|
||||
set = set_noise_seed,
|
||||
get = get_noise_seed
|
||||
|
||||
## Enables noise changes to the [member Camera2D.offset] position.
|
||||
@export var positional_noise: bool = true:
|
||||
set = set_positional_noise,
|
||||
get = get_positional_noise
|
||||
|
||||
## Enables noise changes to the [Camera2D]'s rotation.
|
||||
@export var rotational_noise: bool = false:
|
||||
set = set_rotational_noise,
|
||||
get = get_rotational_noise
|
||||
|
||||
@export_group("Positional Multiplier")
|
||||
## Multiplies positional noise amount in the X-axis.[br]
|
||||
## Set the value to [param 0] to disable noise in the axis.
|
||||
@export_range(0, 1, 0.001, "or_greater") var positional_multiplier_x: float = 1:
|
||||
set = set_positional_multiplier_x,
|
||||
get = get_positional_multiplier_x
|
||||
|
||||
## Multiplies positional noise amount in the Y-axis.[br]
|
||||
## Set the value to [param 0] to disable noise in the axis.
|
||||
@export_range(0, 1, 0.001, "or_greater") var positional_multiplier_y: float = 1:
|
||||
set = set_positional_multiplier_y,
|
||||
get = get_positional_multiplier_y
|
||||
|
||||
@export_group("Rotational Multiplier")
|
||||
## Multiplies rotational noise amount.
|
||||
@export_range(0, 1, 0.001, "or_greater") var rotational_multiplier: float = 1:
|
||||
set = set_rotational_multiplier,
|
||||
get = get_rotational_multiplier
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Variables
|
||||
|
||||
var _noise_algorithm: FastNoiseLite = FastNoiseLite.new()
|
||||
|
||||
var _noise_positional_multiplier: Vector2 = Vector2(
|
||||
positional_multiplier_x,
|
||||
positional_multiplier_y
|
||||
)
|
||||
|
||||
var _trauma: float = 0.0:
|
||||
set(value):
|
||||
_trauma = value
|
||||
|
||||
var _noise_time: float = 0.0
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Functions
|
||||
|
||||
func _init():
|
||||
_noise_algorithm.noise_type = FastNoiseLite.TYPE_PERLIN
|
||||
if randomize_noise_seed: _noise_algorithm.seed = randi()
|
||||
_noise_algorithm.frequency = frequency
|
||||
|
||||
|
||||
func _validate_property(property: Dictionary) -> void:
|
||||
if randomize_noise_seed and property.name == "noise_seed":
|
||||
property.usage = PROPERTY_USAGE_NO_EDITOR
|
||||
|
||||
if not rotational_noise and property.name == "rotational_multiplier":
|
||||
property.usage = PROPERTY_USAGE_NO_EDITOR
|
||||
|
||||
if not positional_noise:
|
||||
match property.name:
|
||||
"positional_multiplier_x", \
|
||||
"positional_multiplier_y":
|
||||
property.usage = PROPERTY_USAGE_NO_EDITOR
|
||||
|
||||
|
||||
func _get_noise_from_seed(noise_seed: int) -> float:
|
||||
return _noise_algorithm.get_noise_2d(noise_seed, _noise_time) * amplitude
|
||||
|
||||
|
||||
func set_trauma(value: float) -> void:
|
||||
_trauma = value
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Functions
|
||||
|
||||
func get_noise_transform(delta: float) -> Transform2D:
|
||||
var output_position: Vector2 = Vector2.ZERO
|
||||
var output_rotation: float = 0.0
|
||||
_noise_time += delta
|
||||
_trauma = maxf(_trauma, 0.0)
|
||||
|
||||
if positional_noise:
|
||||
for i in 2:
|
||||
output_position[i] = _noise_positional_multiplier[i] * pow(_trauma, 2) * _get_noise_from_seed(i + noise_seed)
|
||||
if rotational_noise:
|
||||
output_rotation = rotational_multiplier / 100 * pow(_trauma, 2) * _get_noise_from_seed(noise_seed)
|
||||
|
||||
return Transform2D(output_rotation, output_position)
|
||||
|
||||
|
||||
func reset_noise_time() -> void:
|
||||
_noise_time = 0
|
||||
|
||||
#endregion
|
||||
|
||||
#region Setters & Getters
|
||||
|
||||
## Sets the [member amplitude] value.
|
||||
func set_amplitude(value: float) -> void:
|
||||
amplitude =value
|
||||
|
||||
## Returns the [member amplitude] value.
|
||||
func get_amplitude() -> float:
|
||||
return amplitude
|
||||
|
||||
|
||||
## Sets the [member frequency] value.
|
||||
func set_frequency(value: float) -> void:
|
||||
frequency = value
|
||||
_noise_algorithm.frequency = value
|
||||
|
||||
## Returns the [member frequency] value.
|
||||
func get_frequency() -> float:
|
||||
return frequency
|
||||
|
||||
|
||||
## Sets the [member randomize_seed] value.
|
||||
func set_randomize_noise_seed(value: int) -> void:
|
||||
randomize_noise_seed = value
|
||||
if value: _noise_algorithm.seed = randi()
|
||||
notify_property_list_changed()
|
||||
|
||||
## Returns the [member randomize_seed] value.
|
||||
func get_randomize_noise_seed() -> int:
|
||||
return randomize_noise_seed
|
||||
|
||||
|
||||
## Sets the [member randomize_seed] value.
|
||||
func set_noise_seed(value: int) -> void:
|
||||
noise_seed = value
|
||||
|
||||
## Returns the [member seed] value.
|
||||
func get_noise_seed() -> int:
|
||||
return noise_seed
|
||||
|
||||
|
||||
## Sets the [member positional_noise] value.
|
||||
func set_positional_noise(value: bool) -> void:
|
||||
positional_noise = value
|
||||
notify_property_list_changed()
|
||||
|
||||
## Returns the [member positional_noise] value.
|
||||
func get_positional_noise() -> bool:
|
||||
return positional_noise
|
||||
|
||||
|
||||
## Sets the [member rotational_noise] value.
|
||||
func set_rotational_noise(value: bool) -> void:
|
||||
rotational_noise = value
|
||||
notify_property_list_changed()
|
||||
|
||||
## Returns the [member rotational_noise] value.
|
||||
func get_rotational_noise() -> bool:
|
||||
return rotational_noise
|
||||
|
||||
|
||||
## Sets the [member positional_multiplier_x] value.
|
||||
func set_positional_multiplier_x(value: float) -> void:
|
||||
positional_multiplier_x = value
|
||||
_noise_positional_multiplier.x = value
|
||||
|
||||
## Returns the [member positional_multiplier_x] value.
|
||||
func get_positional_multiplier_x() -> float:
|
||||
return positional_multiplier_x
|
||||
|
||||
|
||||
## Sets the [member positional_multiplier_y] value.
|
||||
func set_positional_multiplier_y(value: float) -> void:
|
||||
positional_multiplier_y = value
|
||||
_noise_positional_multiplier.y = value
|
||||
|
||||
## Returns the [member positional_multiplier_y] value.
|
||||
func get_positional_multiplier_y() -> float:
|
||||
return positional_multiplier_y
|
||||
|
||||
|
||||
## Sets the [member rotational_multiplier] value.
|
||||
func set_rotational_multiplier(value: float) -> void:
|
||||
rotational_multiplier = value
|
||||
|
||||
## Returns the [member rotational_multiplier] value.
|
||||
func get_rotational_multiplier() -> float:
|
||||
return rotational_multiplier
|
||||
|
||||
#endregion
|
||||
@@ -0,0 +1 @@
|
||||
uid://dimvdouy8g0sv
|
||||
@@ -0,0 +1,301 @@
|
||||
@tool
|
||||
@icon("res://addons/phantom_camera/icons/phantom_camera_noise_resource.svg")
|
||||
class_name PhantomCameraNoise3D
|
||||
extends Resource
|
||||
|
||||
## A resource type used to apply noise, or shake, to [Camera3D]s that have a [PhantomCameraHost] as a child.
|
||||
##
|
||||
## Is a resource type that defines, calculates and outputs the noise values to a [Camera3D] through active
|
||||
## [PhantomCamera3D].[br]
|
||||
## It can be applied to either [PhantomCameraNoiseEmitter3D] or a [PhantomCamera3D] noise property directly
|
||||
|
||||
#region Exported Properties
|
||||
|
||||
## Defines the size of the noise pattern.[br]
|
||||
## Higher values will increase the range the noise can reach.
|
||||
@export_range(0, 100, 0.001, "or_greater") var amplitude: float = 10:
|
||||
set = set_amplitude,
|
||||
get = get_amplitude
|
||||
|
||||
## Sets the density of the noise pattern.[br]
|
||||
## Higher values will result in more erratic noise.
|
||||
@export_range(0, 10, 0.001, "or_greater") var frequency: float = 0.2:
|
||||
set = set_frequency,
|
||||
get = get_frequency
|
||||
|
||||
## If true, randomizes the noise pattern every time the noise is run.[br]
|
||||
## If disabled, [member seed] can be used to define a fixed noise pattern.
|
||||
@export var randomize_noise_seed: bool = true:
|
||||
set = set_randomize_noise_seed,
|
||||
get = get_randomize_noise_seed
|
||||
|
||||
## Sets a predetermined seed noise value.[br]
|
||||
## Useful if wanting to achieve a persistent noise pattern every time the noise is emitted.
|
||||
@export var noise_seed: int = 0:
|
||||
set = set_noise_seed,
|
||||
get = get_noise_seed
|
||||
|
||||
## Enables noise changes to the [Camera3D]'s rotation.
|
||||
@export var rotational_noise: bool = true:
|
||||
set = set_rotational_noise,
|
||||
get = get_rotational_noise
|
||||
|
||||
## Enables noise changes to the camera's position.[br][br]
|
||||
## [b]Important[/b][br]This can cause geometry clipping if the camera gets too close while this is active.
|
||||
@export var positional_noise: bool = false:
|
||||
set = set_positional_noise,
|
||||
get = get_positional_noise
|
||||
|
||||
@export_group("Rotational Multiplier")
|
||||
## Multiplies rotational noise amount in the X-axis.[br]
|
||||
## Set the value to [param 0] to disable noise in the axis.
|
||||
@export_range(0, 1, 0.001, "or_greater") var rotational_multiplier_x: float = 1:
|
||||
set = set_rotational_multiplier_x,
|
||||
get = get_rotational_multiplier_x
|
||||
|
||||
## Multiplies rotational noise amount in the Y-axis.[br]
|
||||
## Set the value to [param 0] to disable noise in the axis.
|
||||
@export_range(0, 1, 0.001, "or_greater") var rotational_multiplier_y: float = 1:
|
||||
set = set_rotational_multiplier_y,
|
||||
get = get_rotational_multiplier_y
|
||||
|
||||
## Multiplies rotational noise amount in the Z-axis.[br]
|
||||
## Set the value to [param 0] to disable noise in the axis.
|
||||
@export_range(0, 1, 0.001, "or_greater") var rotational_multiplier_z: float = 1:
|
||||
set = set_rotational_multiplier_z,
|
||||
get = get_rotational_multiplier_z
|
||||
|
||||
@export_group("Positional Multiplier")
|
||||
## Multiplies positional noise amount in the X-axis.[br]
|
||||
## Set the value to [param 0] to disable noise in the axis.[br]
|
||||
## [b]Note:[/b] Rotational Offset is recommended to avoid potential camera clipping with the environment.
|
||||
@export_range(0, 1, 0.001, "or_greater") var positional_multiplier_x: float = 1:
|
||||
set = set_positional_multiplier_x,
|
||||
get = get_positional_multiplier_x
|
||||
|
||||
## Multiplies positional noise amount in the Y-axis.[br]
|
||||
## Set the value to [param 0] to disable noise in the axis.[br]
|
||||
## [b]Note:[/b] Rotational Offset is recommended to avoid potential camera clipping with the environment.
|
||||
@export_range(0, 1, 0.001, "or_greater") var positional_multiplier_y: float = 1:
|
||||
set = set_positional_multiplier_y,
|
||||
get = get_positional_multiplier_y
|
||||
|
||||
## Multiplies positional noise amount in the Z-axis.[br]
|
||||
## Set the value to [param 0] to disable noise in the axis.[br]
|
||||
## [b]Note:[/b] Rotational Offset is recommended to avoid potential camera clipping with the environment.
|
||||
@export_range(0, 1, 0.001, "or_greater") var positional_multiplier_z: float = 1:
|
||||
set = set_positional_multiplier_z,
|
||||
get = get_positional_multiplier_z
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Variables
|
||||
|
||||
var _noise_algorithm: FastNoiseLite = FastNoiseLite.new()
|
||||
|
||||
var _noise_rotational_multiplier: Vector3 = Vector3(
|
||||
rotational_multiplier_x,
|
||||
rotational_multiplier_y,
|
||||
rotational_multiplier_z,
|
||||
)
|
||||
|
||||
var _noise_positional_multiplier: Vector3 = Vector3(
|
||||
positional_multiplier_x,
|
||||
positional_multiplier_y,
|
||||
positional_multiplier_z,
|
||||
)
|
||||
|
||||
var _trauma: float = 0.0:
|
||||
set(value):
|
||||
_trauma = value
|
||||
if _trauma == 0.0:
|
||||
_noise_time = 0.0
|
||||
|
||||
var _noise_time: float = 0.0
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Functions
|
||||
|
||||
func _init():
|
||||
_noise_algorithm.noise_type = FastNoiseLite.TYPE_PERLIN
|
||||
|
||||
if randomize_noise_seed: _noise_algorithm.seed = randi()
|
||||
_noise_algorithm.frequency = frequency
|
||||
|
||||
|
||||
func _validate_property(property: Dictionary) -> void:
|
||||
if randomize_noise_seed and property.name == "noise_seed":
|
||||
property.usage = PROPERTY_USAGE_NO_EDITOR
|
||||
|
||||
if not rotational_noise:
|
||||
match property.name:
|
||||
"rotational_multiplier_x", \
|
||||
"rotational_multiplier_y", \
|
||||
"rotational_multiplier_z":
|
||||
property.usage = PROPERTY_USAGE_NO_EDITOR
|
||||
|
||||
if not positional_noise:
|
||||
match property.name:
|
||||
"positional_multiplier_x", \
|
||||
"positional_multiplier_y", \
|
||||
"positional_multiplier_z":
|
||||
property.usage = PROPERTY_USAGE_NO_EDITOR
|
||||
|
||||
|
||||
func _get_noise_from_seed(noise_seed: int) -> float:
|
||||
return _noise_algorithm.get_noise_2d(noise_seed, _noise_time) * amplitude
|
||||
|
||||
|
||||
func set_trauma(value: float) -> void:
|
||||
_trauma = value
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Functions
|
||||
|
||||
func get_noise_transform(delta: float) -> Transform3D:
|
||||
var output_rotation: Vector3 = Vector3.ZERO
|
||||
var output_position: Vector3 = Vector3.ZERO
|
||||
_noise_time += delta
|
||||
_trauma = maxf(_trauma, 0.0)
|
||||
|
||||
for i in 3:
|
||||
if rotational_noise:
|
||||
output_rotation[i] = deg_to_rad(
|
||||
_noise_rotational_multiplier[i] * pow(_trauma, 2) * _get_noise_from_seed(i + noise_seed)
|
||||
)
|
||||
|
||||
if positional_noise:
|
||||
output_position[i] += _noise_positional_multiplier[i] / 10 * \
|
||||
pow(_trauma, 2) * _get_noise_from_seed(i + noise_seed)
|
||||
|
||||
return Transform3D(Quaternion.from_euler(output_rotation), output_position)
|
||||
|
||||
|
||||
func reset_noise_time() -> void:
|
||||
_noise_time = 0
|
||||
|
||||
#endregion
|
||||
|
||||
#region Setters & Getters
|
||||
|
||||
## Sets the [member amplitude] value.
|
||||
func set_amplitude(value: float) -> void:
|
||||
amplitude =value
|
||||
|
||||
## Returns the [member amplitude] value.
|
||||
func get_amplitude() -> float:
|
||||
return amplitude
|
||||
|
||||
|
||||
## Sets the [member frequency] value.
|
||||
func set_frequency(value: float) -> void:
|
||||
frequency = value
|
||||
_noise_algorithm.frequency = value
|
||||
|
||||
## Returns the [member frequency] value.
|
||||
func get_frequency() -> float:
|
||||
return frequency
|
||||
|
||||
|
||||
## Sets the [member randomize_seed] value.
|
||||
func set_randomize_noise_seed(value: int) -> void:
|
||||
randomize_noise_seed = value
|
||||
if value: _noise_algorithm.seed = randi()
|
||||
notify_property_list_changed()
|
||||
|
||||
## Returns the [member randomize_seed] value.
|
||||
func get_randomize_noise_seed() -> int:
|
||||
return randomize_noise_seed
|
||||
|
||||
|
||||
## Sets the [member randomize_seed] value.
|
||||
func set_noise_seed(value: int) -> void:
|
||||
noise_seed = value
|
||||
|
||||
## Returns the [member seed] value.
|
||||
func get_noise_seed() -> int:
|
||||
return noise_seed
|
||||
|
||||
|
||||
## Sets the [member positional_noise] value.
|
||||
func set_positional_noise(value: bool) -> void:
|
||||
positional_noise = value
|
||||
notify_property_list_changed()
|
||||
|
||||
## Returns the [member positional_noise] value.
|
||||
func get_positional_noise() -> bool:
|
||||
return positional_noise
|
||||
|
||||
|
||||
## Sets the [member rotational_noise] value.
|
||||
func set_rotational_noise(value: bool) -> void:
|
||||
rotational_noise = value
|
||||
notify_property_list_changed()
|
||||
|
||||
## Returns the [member rotational_noise] value.
|
||||
func get_rotational_noise() -> bool:
|
||||
return rotational_noise
|
||||
|
||||
|
||||
## Sets the [member positional_multiplier_x] value.
|
||||
func set_positional_multiplier_x(value: float) -> void:
|
||||
positional_multiplier_x = value
|
||||
_noise_positional_multiplier.x = value
|
||||
|
||||
## Returns the [member positional_multiplier_x] value.
|
||||
func get_positional_multiplier_x() -> float:
|
||||
return positional_multiplier_x
|
||||
|
||||
|
||||
## Sets the [member positional_multiplier_y] value.
|
||||
func set_positional_multiplier_y(value: float) -> void:
|
||||
positional_multiplier_y = value
|
||||
_noise_positional_multiplier.y = value
|
||||
|
||||
## Returns the [member positional_multiplier_y] value.
|
||||
func get_positional_multiplier_y() -> float:
|
||||
return positional_multiplier_y
|
||||
|
||||
|
||||
## Sets the [member positional_multiplier_z] value.
|
||||
func set_positional_multiplier_z(value: float) -> void:
|
||||
positional_multiplier_z = value
|
||||
_noise_positional_multiplier.z = value
|
||||
|
||||
## Returns the [member positional_multiplier_z] value.
|
||||
func get_positional_multiplier_z() -> float:
|
||||
return positional_multiplier_z
|
||||
|
||||
|
||||
## Sets the [member rotational_multiplier_x] value.
|
||||
func set_rotational_multiplier_x(value: float) -> void:
|
||||
rotational_multiplier_x = value
|
||||
_noise_rotational_multiplier.x = value
|
||||
|
||||
## Returns the [member rotational_multiplier_x] value.
|
||||
func get_rotational_multiplier_x() -> float:
|
||||
return rotational_multiplier_x
|
||||
|
||||
|
||||
## Sets the [member rotational_multiplier_y] value.
|
||||
func set_rotational_multiplier_y(value: float) -> void:
|
||||
rotational_multiplier_y = value
|
||||
_noise_rotational_multiplier.y = value
|
||||
|
||||
## Returns the [member rotational_multiplier_y] value.
|
||||
func get_rotational_multiplier_y() -> float:
|
||||
return rotational_multiplier_y
|
||||
|
||||
|
||||
## Sets the [member rotational_multiplier_z] value.
|
||||
func set_rotational_multiplier_z(value: float) -> void:
|
||||
rotational_multiplier_z = value
|
||||
_noise_rotational_multiplier.z = value
|
||||
|
||||
## Returns the [member rotational_multiplier_z] value.
|
||||
func get_rotational_multiplier_z() -> float:
|
||||
return rotational_multiplier_z
|
||||
|
||||
#endregion
|
||||
@@ -0,0 +1 @@
|
||||
uid://cuffvge5ad4aa
|
||||
41
addons/phantom_camera/scripts/resources/tween_resource.gd
Normal file
41
addons/phantom_camera/scripts/resources/tween_resource.gd
Normal file
@@ -0,0 +1,41 @@
|
||||
@icon("res://addons/phantom_camera/icons/phantom_camera_tween.svg")
|
||||
class_name PhantomCameraTween
|
||||
extends Resource
|
||||
|
||||
## Tweening resource for [PhantomCamera2D] and [PhantomCamera3D].
|
||||
##
|
||||
## Defines how [param PhantomCameras] transition between one another.
|
||||
## Changing the tween values for a given [param PhantomCamera] determines how
|
||||
## transitioning to that instance will look like.
|
||||
|
||||
enum TransitionType {
|
||||
LINEAR = 0, ## The animation is interpolated linearly.
|
||||
SINE = 1, ## The animation is interpolated using a sine function.
|
||||
QUINT = 2, ## The animation is interpolated with a quintic (to the power of 5) function.
|
||||
QUART = 3, ## The animation is interpolated with a quartic (to the power of 4) function.
|
||||
QUAD = 4, ## The animation is interpolated with a quadratic (to the power of 2) function.
|
||||
EXPO = 5, ## The animation is interpolated with an exponential (to the power of x) function.
|
||||
ELASTIC = 6, ## The animation is interpolated with elasticity, wiggling around the edges.
|
||||
CUBIC = 7, ## The animation is interpolated with a cubic (to the power of 3) function.
|
||||
CIRC = 8, ## The animation is interpolated with a function using square roots.
|
||||
BOUNCE = 9, ## The animation is interpolated by bouncing at the end.
|
||||
BACK = 10, ## The animation is interpolated backing out at ends.
|
||||
# CUSTOM = 11,
|
||||
# NONE = 12,
|
||||
}
|
||||
|
||||
enum EaseType {
|
||||
EASE_IN = 0, ## The interpolation starts slowly and speeds up towards the end.
|
||||
EASE_OUT = 1, ## The interpolation starts quickly and slows down towards the end.
|
||||
EASE_IN_OUT = 2, ## A combination of EASE_IN and EASE_OUT. The interpolation is slowest at both ends.
|
||||
EASE_OUT_IN = 3, ## A combination of EASE_IN and EASE_OUT. The interpolation is fastest at both ends.
|
||||
}
|
||||
|
||||
## The time it takes to tween to this PhantomCamera in [param seconds].
|
||||
@export var duration: float = 1.0
|
||||
|
||||
## The transition bezier type for the tween. The options are defined in the [enum TransitionType].
|
||||
@export var transition: TransitionType = TransitionType.LINEAR
|
||||
|
||||
## The ease type for the tween. The options are defined in the [enum EaseType].
|
||||
@export var ease: EaseType = EaseType.EASE_IN_OUT
|
||||
@@ -0,0 +1 @@
|
||||
uid://8umksf8e80fw
|
||||
Reference in New Issue
Block a user