2025-12-29 11:54:31 +08:00
|
|
|
|
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
|
|
|
|
|
|
{
|
2025-12-31 13:07:31 +08:00
|
|
|
|
get => (KeepAspect)(int)Resource.Get(PropertyName.KeepAspect);
|
|
|
|
|
|
set => Resource.Set(PropertyName.KeepAspect, (int)value);
|
2025-12-29 11:54:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int CullMask
|
|
|
|
|
|
{
|
2025-12-31 13:07:31 +08:00
|
|
|
|
get => (int)Resource.Get(PropertyName.CullMask);
|
|
|
|
|
|
set => Resource.Set(PropertyName.CullMask, value);
|
2025-12-29 11:54:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public float HOffset
|
|
|
|
|
|
{
|
2025-12-31 13:07:31 +08:00
|
|
|
|
get => (float)Resource.Get(PropertyName.HOffset);
|
|
|
|
|
|
set => Resource.Set(PropertyName.HOffset, value);
|
2025-12-29 11:54:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public float VOffset
|
|
|
|
|
|
{
|
2025-12-31 13:07:31 +08:00
|
|
|
|
get => (float)Resource.Get(PropertyName.VOffset);
|
|
|
|
|
|
set => Resource.Set(PropertyName.VOffset, value);
|
2025-12-29 11:54:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ProjectionType Projection
|
|
|
|
|
|
{
|
2025-12-31 13:07:31 +08:00
|
|
|
|
get => (ProjectionType)(int)Resource.Get(PropertyName.Projection);
|
|
|
|
|
|
set => Resource.Set(PropertyName.Projection, (int)value);
|
2025-12-29 11:54:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public float Fov
|
|
|
|
|
|
{
|
2025-12-31 13:07:31 +08:00
|
|
|
|
get => (float)Resource.Get(PropertyName.Fov);
|
|
|
|
|
|
set => Resource.Set(PropertyName.Fov, Mathf.Clamp(value, 1, 179));
|
2025-12-29 11:54:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public float Size
|
|
|
|
|
|
{
|
2025-12-31 13:07:31 +08:00
|
|
|
|
get => (float)Resource.Get(PropertyName.Size);
|
|
|
|
|
|
set => Resource.Set(PropertyName.Size, Mathf.Clamp(value, 0.001f, float.PositiveInfinity));
|
2025-12-29 11:54:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Vector2 FrustumOffset
|
|
|
|
|
|
{
|
2025-12-31 13:07:31 +08:00
|
|
|
|
get => (Vector2)Resource.Get(PropertyName.FrustumOffset);
|
|
|
|
|
|
set => Resource.Set(PropertyName.FrustumOffset, value);
|
2025-12-29 11:54:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public float Near
|
|
|
|
|
|
{
|
2025-12-31 13:07:31 +08:00
|
|
|
|
get => (float)Resource.Get(PropertyName.Near);
|
|
|
|
|
|
set => Resource.Set(PropertyName.Near, Mathf.Clamp(value, 0.001f, float.PositiveInfinity));
|
2025-12-29 11:54:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public float Far
|
|
|
|
|
|
{
|
2025-12-31 13:07:31 +08:00
|
|
|
|
get => (float)Resource.Get(PropertyName.Far);
|
|
|
|
|
|
set => Resource.Set(PropertyName.Far, Mathf.Clamp(value, 0.01f, float.PositiveInfinity));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static Camera3DResource New()
|
|
|
|
|
|
{
|
|
|
|
|
|
Resource resource = new();
|
|
|
|
|
|
#if GODOT4_4_OR_GREATER
|
|
|
|
|
|
resource.SetScript(GD.Load<GDScript>("uid://b8hhnqsugykly"));
|
|
|
|
|
|
#else
|
|
|
|
|
|
resource.SetScript(GD.Load<GDScript>("res://addons/phantom_camera/scripts/resources/camera_3d_resource.gd"));
|
|
|
|
|
|
#endif
|
|
|
|
|
|
return new Camera3DResource(resource);
|
2025-12-29 11:54:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-31 13:07:31 +08:00
|
|
|
|
public static class PropertyName
|
2025-12-29 11:54:31 +08:00
|
|
|
|
{
|
2025-12-31 13:07:31 +08:00
|
|
|
|
public static readonly StringName KeepAspect = new("keep_aspect");
|
2025-12-29 11:54:31 +08:00
|
|
|
|
|
2025-12-31 13:07:31 +08:00
|
|
|
|
public static readonly StringName CullMask = new("cull_mask");
|
2025-12-29 11:54:31 +08:00
|
|
|
|
|
2025-12-31 13:07:31 +08:00
|
|
|
|
public static readonly StringName HOffset = new("h_offset");
|
2025-12-29 11:54:31 +08:00
|
|
|
|
|
2025-12-31 13:07:31 +08:00
|
|
|
|
public static readonly StringName VOffset = new("v_offset");
|
2025-12-29 11:54:31 +08:00
|
|
|
|
|
2025-12-31 13:07:31 +08:00
|
|
|
|
public static readonly StringName Projection = new("projection");
|
2025-12-29 11:54:31 +08:00
|
|
|
|
|
2025-12-31 13:07:31 +08:00
|
|
|
|
public static readonly StringName Fov = new("fov");
|
2025-12-29 11:54:31 +08:00
|
|
|
|
|
2025-12-31 13:07:31 +08:00
|
|
|
|
public static readonly StringName Size = new("size");
|
2025-12-29 11:54:31 +08:00
|
|
|
|
|
2025-12-31 13:07:31 +08:00
|
|
|
|
public static readonly StringName FrustumOffset = new("frustum_offset");
|
2025-12-29 11:54:31 +08:00
|
|
|
|
|
2025-12-31 13:07:31 +08:00
|
|
|
|
public static readonly StringName Near = new("near");
|
2025-12-29 11:54:31 +08:00
|
|
|
|
|
2025-12-31 13:07:31 +08:00
|
|
|
|
public static readonly StringName Far = new("far");
|
2025-12-29 11:54:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|