Refactor PhysicalMaterial usage to utilize JsonAssetReference struct

This commit is contained in:
Wojtek Figat
2024-02-15 11:45:50 +01:00
parent fe7cc62728
commit 7538296775
8 changed files with 12 additions and 25 deletions

View File

@@ -206,7 +206,7 @@ void CharacterController::CreateController()
_cachedScale = GetScale();
const float scaling = _cachedScale.GetAbsolute().MaxValue();
const Vector3 position = _transform.LocalToWorld(_center);
_controller = PhysicsBackend::CreateController(GetPhysicsScene()->GetPhysicsScene(), this, this, _contactOffset, position, _slopeLimit, (int32)_nonWalkableMode, Material.Get(), Math::Abs(_radius) * scaling, Math::Abs(_height) * scaling, _stepOffset, _shape);
_controller = PhysicsBackend::CreateController(GetPhysicsScene()->GetPhysicsScene(), this, this, _contactOffset, position, _slopeLimit, (int32)_nonWalkableMode, Material, Math::Abs(_radius) * scaling, Math::Abs(_height) * scaling, _stepOffset, _shape);
// Setup
PhysicsBackend::SetControllerUpDirection(_controller, _upDirection);

View File

@@ -201,7 +201,7 @@ void Collider::CreateShape()
// Create shape
const bool isTrigger = _isTrigger && CanBeTrigger();
_shape = PhysicsBackend::CreateShape(this, shape, Material.Get(), IsActiveInHierarchy(), isTrigger);
_shape = PhysicsBackend::CreateShape(this, shape, Material, IsActiveInHierarchy(), isTrigger);
PhysicsBackend::SetShapeContactOffset(_shape, _contactOffset);
UpdateLayerBits();
}
@@ -288,7 +288,7 @@ void Collider::OnMaterialChanged()
{
// Update the shape material
if (_shape)
PhysicsBackend::SetShapeMaterial(_shape, Material.Get());
PhysicsBackend::SetShapeMaterial(_shape, Material);
}
void Collider::BeginPlay(SceneBeginData* data)

View File

@@ -4,7 +4,7 @@
#include "Engine/Physics/Types.h"
#include "Engine/Content/JsonAsset.h"
#include "Engine/Content/AssetReference.h"
#include "Engine/Content/JsonAssetReference.h"
#include "Engine/Physics/Actors/PhysicsColliderActor.h"
struct RayCastHit;
@@ -80,8 +80,8 @@ public:
/// <summary>
/// The physical material used to define the collider physical properties.
/// </summary>
API_FIELD(Attributes="EditorOrder(2), DefaultValue(null), AssetReference(typeof(PhysicalMaterial), true), EditorDisplay(\"Collider\")")
AssetReference<JsonAsset> Material;
API_FIELD(Attributes="EditorOrder(2), DefaultValue(null), EditorDisplay(\"Collider\")")
JsonAssetReference<PhysicalMaterial> Material;
public:
/// <summary>

View File

@@ -15,17 +15,9 @@ class FLAXENGINE_API PhysicalMaterial final : public ISerializable
API_AUTO_SERIALIZATION();
DECLARE_SCRIPTING_TYPE_MINIMAL(PhysicalMaterial);
private:
void* _material;
void* _material = nullptr;
public:
/// <summary>
/// Initializes a new instance of the <see cref="PhysicalMaterial"/> class.
/// </summary>
PhysicalMaterial();
/// <summary>
/// Finalizes an instance of the <see cref="PhysicalMaterial"/> class.
/// </summary>
~PhysicalMaterial();
public:

View File

@@ -78,11 +78,6 @@ void PhysicsSettings::Deserialize(DeserializeStream& stream, ISerializeModifier*
}
}
PhysicalMaterial::PhysicalMaterial()
: _material(nullptr)
{
}
PhysicalMaterial::~PhysicalMaterial()
{
if (_material)

View File

@@ -239,7 +239,7 @@ void Terrain::OnPhysicalMaterialChanged()
const auto patch = _patches[pathIndex];
if (patch->HasCollision())
{
PhysicsBackend::SetShapeMaterial(patch->_physicsShape, PhysicalMaterial.Get());
PhysicsBackend::SetShapeMaterial(patch->_physicsShape, PhysicalMaterial);
}
}
}

View File

@@ -2,7 +2,7 @@
#pragma once
#include "Engine/Content/JsonAsset.h"
#include "Engine/Content/JsonAssetReference.h"
#include "Engine/Content/Assets/MaterialBase.h"
#include "Engine/Physics/Actors/PhysicsColliderActor.h"
@@ -79,8 +79,8 @@ public:
/// <summary>
/// The physical material used to define the terrain collider physical properties.
/// </summary>
API_FIELD(Attributes="EditorOrder(520), DefaultValue(null), Limit(-1, 100, 0.1f), EditorDisplay(\"Collision\"), AssetReference(typeof(PhysicalMaterial), true)")
AssetReference<JsonAsset> PhysicalMaterial;
API_FIELD(Attributes="EditorOrder(520), DefaultValue(null), Limit(-1, 100, 0.1f), EditorDisplay(\"Collision\")")
JsonAssetReference<::PhysicalMaterial> PhysicalMaterial;
/// <summary>
/// The draw passes to use for rendering this object.

View File

@@ -2125,7 +2125,7 @@ void TerrainPatch::CreateCollision()
shape.SetHeightField(_physicsHeightField, heightScale, rowScale, columnScale);
// Create shape
_physicsShape = PhysicsBackend::CreateShape(_terrain, shape, _terrain->PhysicalMaterial.Get(), _terrain->IsActiveInHierarchy(), false);
_physicsShape = PhysicsBackend::CreateShape(_terrain, shape, _terrain->PhysicalMaterial, _terrain->IsActiveInHierarchy(), false);
PhysicsBackend::SetShapeLocalPose(_physicsShape, Vector3(0, _yOffset * terrainTransform.Scale.Y, 0), Quaternion::Identity);
// Create static actor