Fix spawning actors in viewport to have better origin placement

Empty Actor is a building block of hierarchies so don't include dummy bounds there.
Wait for dragged asset to be loaded for proper bounds.
Use mesh bounds for non-active Animated Model for accurate placement.
This commit is contained in:
2026-09-26 23:01:15 +02:00
parent 5592351253
commit 330df10902
6 changed files with 17 additions and 20 deletions
@@ -120,7 +120,7 @@ namespace FlaxEditor.Content
/// <inheritdoc />
public override Actor OnEditorDrop(object context)
{
return new StaticModel { Model = FlaxEngine.Content.LoadAsync<Model>(ID) };
return new StaticModel { Model = FlaxEngine.Content.Load<Model>(ID) };
}
/// <inheritdoc />
@@ -171,7 +171,7 @@ namespace FlaxEditor.Content
/// <inheritdoc />
public override Actor OnEditorDrop(object context)
{
return new AnimatedModel { SkinnedModel = FlaxEngine.Content.LoadAsync<SkinnedModel>(ID) };
return new AnimatedModel { SkinnedModel = FlaxEngine.Content.Load<SkinnedModel>(ID) };
}
/// <inheritdoc />
+1 -1
View File
@@ -32,7 +32,7 @@ namespace FlaxEditor.Content
/// <inheritdoc />
public override Actor OnEditorDrop(object context)
{
return PrefabManager.SpawnPrefab(FlaxEngine.Content.LoadAsync<Prefab>(ID), null);
return PrefabManager.SpawnPrefab(FlaxEngine.Content.Load<Prefab>(ID), null);
}
/// <inheritdoc />
@@ -179,7 +179,7 @@ namespace FlaxEditor.Viewport
private Vector3 PostProcessSpawnedActorLocation(Actor actor, ref Vector3 hitLocation)
{
// Refresh actor position to ensure that cached bounds are valid
// Refresh actor position to ensure that cached bounds are valid (in Actor::OnTransformChanged)
actor.Position = Vector3.One;
actor.Position = Vector3.Zero;
+13 -1
View File
@@ -1250,7 +1250,19 @@ BoundingBox AnimatedModel::GetEditorBoundingBox() const
{
if (SkinnedModel)
SkinnedModel->WaitForLoaded(100);
return BoundingBox::MakeScaled(_box, 1.0f / BoundsScale);
BoundingBox box = _box;
if (CustomBounds.GetSize().LengthSquared() <= 0.01f)
{
if (!IsDuringPlay())
{
Matrix world;
GetLocalToWorldMatrix(world);
box = SkinnedModel->GetBox(world);
}
else
box = BoundingBox::MakeScaled(box, 1.0f / BoundsScale);
}
return box;
}
#endif
-10
View File
@@ -7,16 +7,6 @@ EmptyActor::EmptyActor(const SpawnParams& params)
{
}
#if USE_EDITOR
BoundingBox EmptyActor::GetEditorBoundingBox() const
{
const Vector3 size(50);
return BoundingBox(_transform.Translation - size, _transform.Translation + size);
}
#endif
void EmptyActor::OnTransformChanged()
{
// Base
-5
View File
@@ -11,11 +11,6 @@ API_CLASS(Attributes="ActorContextMenu(\"New/Actor\"), ActorToolbox(\"Other\")")
class FLAXENGINE_API EmptyActor : public Actor
{
DECLARE_SCENE_OBJECT(EmptyActor);
public:
// [Actor]
#if USE_EDITOR
BoundingBox GetEditorBoundingBox() const override;
#endif
protected:
// [Actor]