Fix various issues

This commit is contained in:
Wojtek Figat
2026-02-06 10:37:52 +01:00
parent 5d0fdc8313
commit 4a7f1a5fde
5 changed files with 37 additions and 27 deletions

View File

@@ -99,7 +99,14 @@ namespace FlaxEditor.Windows.Assets
Window = window;
var surfaceParam = window.Surface.GetParameter(BaseModelId);
if (surfaceParam != null)
BaseModel = FlaxEngine.Content.LoadAsync<SkinnedModel>((Guid)surfaceParam.Value);
{
if (surfaceParam.Value is Guid asGuid)
BaseModel = FlaxEngine.Content.LoadAsync<SkinnedModel>(asGuid);
else if (surfaceParam.Value is SkinnedModel asModel)
BaseModel = asModel;
else
BaseModel = null;
}
else
BaseModel = window.PreviewActor.GetParameterValue(BaseModelId) as SkinnedModel;
}

View File

@@ -41,8 +41,7 @@ Foliage::Foliage(const SpawnParams& params)
void Foliage::AddToCluster(ChunkedArray<FoliageCluster, FOLIAGE_CLUSTER_CHUNKS_SIZE>& clusters, FoliageCluster* cluster, FoliageInstance& instance)
{
ASSERT(instance.Bounds.Radius > ZeroTolerance);
ASSERT(cluster->Bounds.Intersects(instance.Bounds));
ASSERT_LOW_LAYER(instance.Bounds.Radius > ZeroTolerance);
// Minor clusters don't use bounds intersection but try to find the first free cluster instead
if (cluster->IsMinor)
@@ -63,6 +62,7 @@ void Foliage::AddToCluster(ChunkedArray<FoliageCluster, FOLIAGE_CLUSTER_CHUNKS_S
else
{
// Find target cluster
ASSERT(cluster->Bounds.Intersects(instance.Bounds));
while (cluster->Children[0])
{
#define CHECK_CHILD(idx) \

View File

@@ -21,26 +21,7 @@ void FoliageCluster::Init(const BoundingBox& bounds)
void FoliageCluster::UpdateTotalBoundsAndCullDistance()
{
if (Children[0])
{
ASSERT(Instances.IsEmpty());
Children[0]->UpdateTotalBoundsAndCullDistance();
Children[1]->UpdateTotalBoundsAndCullDistance();
Children[2]->UpdateTotalBoundsAndCullDistance();
Children[3]->UpdateTotalBoundsAndCullDistance();
TotalBounds = Children[0]->TotalBounds;
BoundingBox::Merge(TotalBounds, Children[1]->TotalBounds, TotalBounds);
BoundingBox::Merge(TotalBounds, Children[2]->TotalBounds, TotalBounds);
BoundingBox::Merge(TotalBounds, Children[3]->TotalBounds, TotalBounds);
MaxCullDistance = Children[0]->MaxCullDistance;
MaxCullDistance = Math::Max(MaxCullDistance, Children[1]->MaxCullDistance);
MaxCullDistance = Math::Max(MaxCullDistance, Children[2]->MaxCullDistance);
MaxCullDistance = Math::Max(MaxCullDistance, Children[3]->MaxCullDistance);
}
else if (Instances.HasItems())
if (Instances.HasItems())
{
BoundingBox box;
BoundingBox::FromSphere(Instances[0]->Bounds, TotalBounds);
@@ -58,6 +39,30 @@ void FoliageCluster::UpdateTotalBoundsAndCullDistance()
MaxCullDistance = 0;
}
if (Children[0])
{
Children[0]->UpdateTotalBoundsAndCullDistance();
Children[1]->UpdateTotalBoundsAndCullDistance();
Children[2]->UpdateTotalBoundsAndCullDistance();
Children[3]->UpdateTotalBoundsAndCullDistance();
if (Instances.HasItems())
BoundingBox::Merge(TotalBounds, Children[0]->TotalBounds, TotalBounds);
else
TotalBounds = Children[0]->TotalBounds;
BoundingBox::Merge(TotalBounds, Children[1]->TotalBounds, TotalBounds);
BoundingBox::Merge(TotalBounds, Children[2]->TotalBounds, TotalBounds);
BoundingBox::Merge(TotalBounds, Children[3]->TotalBounds, TotalBounds);
if (Instances.HasItems())
MaxCullDistance = Math::Max(MaxCullDistance, Children[0]->MaxCullDistance);
else
MaxCullDistance = Children[0]->MaxCullDistance;
MaxCullDistance = Math::Max(MaxCullDistance, Children[1]->MaxCullDistance);
MaxCullDistance = Math::Max(MaxCullDistance, Children[2]->MaxCullDistance);
MaxCullDistance = Math::Max(MaxCullDistance, Children[3]->MaxCullDistance);
}
BoundingSphere::FromBox(TotalBounds, TotalBoundsSphere);
}

View File

@@ -1685,7 +1685,7 @@ Quaternion Actor::LookingAt(const Vector3& worldPos) const
{
const Vector3 direction = worldPos - _transform.Translation;
if (direction.LengthSquared() < ZeroTolerance)
return _parent->GetOrientation();
return _parent ? _parent->GetOrientation() : Quaternion::Identity;
const Float3 newForward = Vector3::Normalize(direction);
const Float3 oldForward = _transform.Orientation * Vector3::Forward;
@@ -1712,7 +1712,7 @@ Quaternion Actor::LookingAt(const Vector3& worldPos, const Vector3& worldUp) con
{
const Vector3 direction = worldPos - _transform.Translation;
if (direction.LengthSquared() < ZeroTolerance)
return _parent->GetOrientation();
return _parent ? _parent->GetOrientation() : Quaternion::Identity;
const Float3 forward = Vector3::Normalize(direction);
const Float3 up = Vector3::Normalize(worldUp);
if (Math::IsOne(Float3::Dot(forward, up)))

View File

@@ -317,7 +317,6 @@ int64 JobSystem::Dispatch(const Function<void(int32)>& job, int32 jobCount)
context.DependantsCount = 0;
context.DependenciesLeft = 0;
context.JobsCount = jobCount;
ASSERT(context.Dependants.IsEmpty());
context.Dependants.Clear();
// Move the job queue forward
@@ -367,7 +366,6 @@ int64 JobSystem::Dispatch(const Function<void(int32)>& job, Span<int64> dependen
context.DependantsCount = 0;
context.DependenciesLeft = 0;
context.JobsCount = jobCount;
ASSERT(context.Dependants.IsEmpty());
context.Dependants.Clear();
{
JobsLocker.Lock();