Merge remote-tracking branch 'origin/master' into 1.9

This commit is contained in:
Wojtek Figat
2024-08-22 17:33:20 +02:00
24 changed files with 269 additions and 88 deletions

View File

@@ -396,6 +396,7 @@ void AudioClip::unload(bool isReloading)
}
StopStreaming();
CancelStreamingTasks();
StreamingQueue.Clear();
if (hasAnyBuffer && AudioBackend::Instance)
{

View File

@@ -788,7 +788,7 @@ void DebugDraw::Draw(RenderContext& renderContext, GPUTextureView* target, GPUTe
Matrix vp;
Matrix::Multiply(view.View, view.Projection, vp);
Matrix::Transpose(vp, data.ViewProjection);
data.ClipPosZBias = -0.2f; // Reduce Z-fighting artifacts (eg. editor grid)
data.ClipPosZBias = view.IsPerspectiveProjection() ? -0.2f : 0.0f; // Reduce Z-fighting artifacts (eg. editor grid)
data.EnableDepthTest = enableDepthTest;
context->UpdateCB(cb, &data);
context->BindCB(0, cb);
@@ -953,11 +953,11 @@ void DebugDraw::DrawActorsTree(Actor* actor)
}
#if USE_EDITOR
void DebugDraw::DrawColliderDebugPhysics(Collider* collider, RenderView& view)
{
if (!collider)
return;
collider->DrawPhysicsDebug(view);
}
@@ -965,10 +965,11 @@ void DebugDraw::DrawLightDebug(Light* light, RenderView& view)
{
if (!light)
return;
light->DrawLightsDebug(view);
}
#endif
void DebugDraw::DrawAxisFromDirection(const Vector3& origin, const Vector3& direction, float size, float duration, bool depthTest)
{
CHECK_DEBUG(direction.IsNormalized());

View File

@@ -75,6 +75,7 @@ API_CLASS(Static) class FLAXENGINE_API DebugDraw
/// </summary>
/// <param name="actor">The actor to start drawing at.</param>
API_FUNCTION() static void DrawActorsTree(Actor* actor);
#if USE_EDITOR
/// <summary>
/// Draws the physics debug shapes for the given collider. Editor Only
@@ -90,6 +91,7 @@ API_CLASS(Static) class FLAXENGINE_API DebugDraw
/// <param name="view">The render view to draw in.</param>
API_FUNCTION() static void DrawLightDebug(Light* light, RenderView& view);
#endif
/// <summary>
/// Draws the lines axis from direction.
/// </summary>

View File

@@ -60,6 +60,7 @@ namespace FlaxEngine
~InputAxis()
{
Input.AxisValueChanged -= Handler;
ValueChanged = null;
}
/// <summary>
@@ -68,6 +69,7 @@ namespace FlaxEngine
public void Dispose()
{
Input.AxisValueChanged -= Handler;
ValueChanged = null;
GC.SuppressFinalize(this);
}

View File

@@ -70,6 +70,10 @@ namespace FlaxEngine
~InputEvent()
{
Input.ActionTriggered -= Handler;
Triggered = null;
Pressed = null;
Pressing = null;
Released = null;
}
private void Handler(string name, InputActionState state)
@@ -100,6 +104,10 @@ namespace FlaxEngine
public void Dispose()
{
Input.ActionTriggered -= Handler;
Triggered = null;
Pressed = null;
Pressing = null;
Released = null;
GC.SuppressFinalize(this);
}

View File

@@ -157,6 +157,8 @@ void InputSettings::Deserialize(DeserializeStream& stream, ISerializeModifier* m
config.Gamepad = JsonTools::GetEnum(v, "Gamepad", InputGamepadIndex::All);
config.PositiveButton = JsonTools::GetEnum(v, "PositiveButton", KeyboardKeys::None);
config.NegativeButton = JsonTools::GetEnum(v, "NegativeButton", KeyboardKeys::None);
config.GamepadPositiveButton = JsonTools::GetEnum(v, "GamepadPositiveButton", GamepadButton::None);
config.GamepadNegativeButton = JsonTools::GetEnum(v, "GamepadNegativeButton", GamepadButton::None);
config.DeadZone = JsonTools::GetFloat(v, "DeadZone", 0.1f);
config.Sensitivity = JsonTools::GetFloat(v, "Sensitivity", 0.4f);
config.Gravity = JsonTools::GetFloat(v, "Gravity", 1.0f);
@@ -873,8 +875,8 @@ void InputService::Update()
const AxisData& data = Axes[name];
// Get key raw value
const bool isPositiveKey = Input::GetKey(config.PositiveButton);
const bool isNegativeKey = Input::GetKey(config.NegativeButton);
const bool isPositiveKey = Input::GetKey(config.PositiveButton) || Input::GetGamepadButton(config.Gamepad, config.GamepadPositiveButton);
const bool isNegativeKey = Input::GetKey(config.NegativeButton) || Input::GetGamepadButton(config.Gamepad, config.GamepadNegativeButton);
float keyRawValue = 0;
if (isPositiveKey && !isNegativeKey)
{

View File

@@ -87,6 +87,18 @@ API_STRUCT() struct AxisConfig
API_FIELD(Attributes="EditorOrder(40)")
KeyboardKeys NegativeButton;
/// <summary>
/// The button to be pressed for movement in positive direction. Use <see cref="GamepadButton.None"/> to ignore it.
/// </summary>
API_FIELD(Attributes="EditorOrder(45)")
GamepadButton GamepadPositiveButton;
/// <summary>
/// The button to be pressed for movement in negative direction. Use <see cref="GamepadButton.None"/> to ignore it.
/// </summary>
API_FIELD(Attributes="EditorOrder(46)")
GamepadButton GamepadNegativeButton;
/// <summary>
/// Any positive or negative values that are less than this number will register as zero. Useful for gamepads to specify the deadzone.
/// </summary>

View File

@@ -39,6 +39,7 @@ Camera::Camera(const SpawnParams& params)
, _customAspectRatio(0.0f)
, _near(10.0f)
, _far(40000.0f)
, _orthoSize(0.0f)
, _orthoScale(1.0f)
{
#if USE_EDITOR
@@ -120,6 +121,21 @@ void Camera::SetFarPlane(float value)
}
}
float Camera::GetOrthographicSize() const
{
return _orthoSize;
}
void Camera::SetOrthographicSize(float value)
{
value = Math::Clamp(value, 0.0f, 1000000.0f);
if (Math::NotNearEqual(_orthoSize, value))
{
_orthoSize = value;
UpdateCache();
}
}
float Camera::GetOrthographicScale() const
{
return _orthoScale;
@@ -191,39 +207,37 @@ Ray Camera::ConvertMouseToRay(const Float2& mousePosition) const
Ray Camera::ConvertMouseToRay(const Float2& mousePosition, const Viewport& viewport) const
{
#if 1
// Gather camera properties
Vector3 position = GetPosition();
if (viewport.Width < ZeroTolerance || viewport.Height < ZeroTolerance)
return Ray(position, GetDirection());
// Use different logic in orthographic projection
if (!_usePerspective)
{
Float2 screenPosition(mousePosition.X / viewport.Width - 0.5f, -mousePosition.Y / viewport.Height + 0.5f);
Quaternion orientation = GetOrientation();
Float3 direction = orientation * Float3::Forward;
const float orthoSize = (_orthoSize > 0.0f ? _orthoSize : viewport.Height) * _orthoScale;
const float aspect = _customAspectRatio <= 0.0f ? viewport.GetAspectRatio() : _customAspectRatio;
Vector3 rayOrigin(screenPosition.X * orthoSize * aspect, screenPosition.Y * orthoSize, 0);
rayOrigin = position + Vector3::Transform(rayOrigin, orientation);
rayOrigin += direction * _near;
return Ray(rayOrigin, direction);
}
// Create view frustum
Matrix v, p, ivp;
GetMatrices(v, p, viewport);
Matrix::Multiply(v, p, ivp);
ivp.Invert();
// Create near and far points
Vector3 nearPoint(mousePosition, 0.0f);
Vector3 farPoint(mousePosition, 1.0f);
Vector3 nearPoint(mousePosition, _near);
Vector3 farPoint(mousePosition, _far);
viewport.Unproject(nearPoint, ivp, nearPoint);
viewport.Unproject(farPoint, ivp, farPoint);
// Create direction vector
Vector3 direction = farPoint - nearPoint;
direction.Normalize();
return Ray(nearPoint, direction);
#else
// Create near and far points
Vector3 nearPoint, farPoint;
Matrix ivp;
_frustum.GetInvMatrix(&ivp);
viewport.Unproject(Vector3(mousePosition, 0.0f), ivp, nearPoint);
viewport.Unproject(Vector3(mousePosition, 1.0f), ivp, farPoint);
// Create direction vector
Vector3 direction = farPoint - nearPoint;
direction.Normalize();
// Return result
return Ray(nearPoint, direction);
#endif
return Ray(nearPoint, Vector3::Normalize(farPoint - nearPoint));
}
Viewport Camera::GetViewport() const
@@ -264,14 +278,15 @@ void Camera::GetMatrices(Matrix& view, Matrix& projection, const Viewport& viewp
void Camera::GetMatrices(Matrix& view, Matrix& projection, const Viewport& viewport, const Vector3& origin) const
{
// Create projection matrix
const float aspect = _customAspectRatio <= 0.0f ? viewport.GetAspectRatio() : _customAspectRatio;
if (_usePerspective)
{
const float aspect = _customAspectRatio <= 0.0f ? viewport.GetAspectRatio() : _customAspectRatio;
Matrix::PerspectiveFov(_fov * DegreesToRadians, aspect, _near, _far, projection);
}
else
{
Matrix::Ortho(viewport.Width * _orthoScale, viewport.Height * _orthoScale, _near, _far, projection);
const float orthoSize = (_orthoSize > 0.0f ? _orthoSize : viewport.Height) * _orthoScale;
Matrix::Ortho(orthoSize * aspect, orthoSize, _near, _far, projection);
}
// Create view matrix

View File

@@ -44,6 +44,7 @@ private:
float _customAspectRatio;
float _near;
float _far;
float _orthoSize;
float _orthoScale;
#if USE_EDITOR
@@ -88,7 +89,7 @@ public:
/// <summary>
/// Gets the custom aspect ratio. 0 if not use custom value.
/// </summary>
API_PROPERTY(Attributes="EditorOrder(50), DefaultValue(0.0f), Limit(0, 10, 0.01f), EditorDisplay(\"Camera\"), VisibleIf(nameof(UsePerspective))")
API_PROPERTY(Attributes="EditorOrder(50), DefaultValue(0.0f), Limit(0, 10, 0.01f), EditorDisplay(\"Camera\")")
float GetCustomAspectRatio() const;
/// <summary>
@@ -118,6 +119,17 @@ public:
/// </summary>
API_PROPERTY() void SetFarPlane(float value);
/// <summary>
/// Gets the orthographic projection view height (width is based on the aspect ratio). Use `0` for size to be based on the viewport size.
/// </summary>
API_PROPERTY(Attributes="EditorOrder(59), DefaultValue(0.0f), Limit(0.0f), EditorDisplay(\"Camera\"), VisibleIf(nameof(UsePerspective), true)")
float GetOrthographicSize() const;
/// <summary>
/// Sets the orthographic projection view height (width is based on the aspect ratio). Use `0` for size to be based on the viewport size.
/// </summary>
API_PROPERTY() void SetOrthographicSize(float value);
/// <summary>
/// Gets the orthographic projection scale.
/// </summary>

View File

@@ -123,6 +123,7 @@ public:
/// <returns>The scene object (loaded).</returns>
API_FUNCTION() static Scene* GetScene(int32 index)
{
CHECK_RETURN(index < GetScenesCount(), nullptr);
return Scenes[index];
}

View File

@@ -219,7 +219,7 @@ Asset::LoadResult ParticleEmitter::load()
ClearDependencies();
for (const auto& node : Graph.Nodes)
{
if (node.Type == GRAPH_NODE_MAKE_TYPE(14, 300))
if (node.Type == GRAPH_NODE_MAKE_TYPE(14, 300) && node.Assets.Count() > 0)
{
const auto function = node.Assets[0].As<ParticleEmitterFunction>();
if (function)

View File

@@ -143,9 +143,11 @@ namespace FlaxEngine.GUI
if (!Mathf.NearEqual(value, _value))
{
_value = value;
if (!UseSmoothing)
if (!UseSmoothing || _firstUpdate)
{
_current = _value;
if (_firstUpdate)
_firstUpdate = false;
}
}
}
@@ -169,6 +171,9 @@ namespace FlaxEngine.GUI
[EditorDisplay("Bar Style"), EditorOrder(2012), Tooltip("The brush used for progress bar drawing.")]
public IBrush BarBrush { get; set; }
// Used to remove initial lerp from the value on play.
private bool _firstUpdate = true;
/// <summary>
/// Initializes a new instance of the <see cref="ProgressBar"/> class.
/// </summary>

View File

@@ -18,7 +18,7 @@ SpriteRender::SpriteRender(const SpawnParams& params)
{
_quadModel = Content::LoadAsyncInternal<Model>(TEXT("Engine/Models/Quad"));
Material.Loaded.Bind<SpriteRender, &SpriteRender::OnMaterialLoaded>(this);
Image.Changed.Bind<SpriteRender, &SpriteRender::SetImage>(this);
Image.Changed.Bind<SpriteRender, &SpriteRender::SetImageParam>(this);
}
Float2 SpriteRender::GetSize() const
@@ -42,8 +42,7 @@ Color SpriteRender::GetColor() const
void SpriteRender::SetColor(const Color& value)
{
_color = value;
if (_paramColor)
_paramColor->SetValue(value);
SetColorParam();
}
SpriteHandle SpriteRender::GetSprite() const
@@ -54,7 +53,7 @@ SpriteHandle SpriteRender::GetSprite() const
void SpriteRender::SetSprite(const SpriteHandle& value)
{
_sprite = value;
SetImage();
SetImageParam();
}
void SpriteRender::OnMaterialLoaded()
@@ -66,6 +65,7 @@ void SpriteRender::OnMaterialLoaded()
_materialInstance->AddReference();
}
_materialInstance->SetBaseMaterial(Material);
_materialInstance->ResetParameters();
// Cache parameters
_paramImageMAD = _materialInstance->GetParameter(TEXT("ImageMAD"));
@@ -75,15 +75,15 @@ void SpriteRender::OnMaterialLoaded()
if (_paramImage && _paramImage->GetParameterType() != MaterialParameterType::Texture)
_paramImage = nullptr;
else if (_paramImage)
SetImage();
SetImageParam();
_paramColor = _materialInstance->GetParameter(TEXT("Color"));
if (_paramColor && _paramColor->GetParameterType() != MaterialParameterType::Color && _paramColor->GetParameterType() != MaterialParameterType::Vector4 && _paramColor->GetParameterType() != MaterialParameterType::Vector3)
_paramColor = nullptr;
else if (_paramColor)
_paramColor->SetValue(_color);
SetColorParam();
}
void SpriteRender::SetImage()
void SpriteRender::SetImageParam()
{
TextureBase* image = Image.Get();
Vector4 imageMAD(Vector2::One, Vector2::Zero);
@@ -94,9 +94,24 @@ void SpriteRender::SetImage()
imageMAD = Vector4(sprite->Area.Size, sprite->Area.Location);
}
if (_paramImage)
{
_paramImage->SetValue(image);
_paramImage->SetIsOverride(true);
}
if (_paramImageMAD)
{
_paramImageMAD->SetValue(imageMAD);
_paramImageMAD->SetIsOverride(true);
}
}
void SpriteRender::SetColorParam()
{
if (_paramColor)
{
_paramColor->SetValue(_color);
_paramColor->SetIsOverride(true);
}
}
bool SpriteRender::HasContentLoaded() const
@@ -164,9 +179,8 @@ void SpriteRender::Deserialize(DeserializeStream& stream, ISerializeModifier* mo
DESERIALIZE(DrawModes);
DESERIALIZE(SortOrder);
SetImage();
if (_paramColor)
_paramColor->SetValue(_color);
SetImageParam();
SetColorParam();
}
void SpriteRender::OnLayerChanged()

View File

@@ -92,7 +92,8 @@ public:
private:
void OnMaterialLoaded();
void SetImage();
void SetImageParam();
void SetColorParam();
public:
// [Actor]