Bug Fixes
script and actors not having connect transform in on awake and in on start join auto anchor having wrong anchor because was including scale fixed selection do to changes to transform accessibility ?
This commit is contained in:
@@ -898,16 +898,14 @@ namespace FlaxEditor.Viewport
|
||||
ivp.Invert();
|
||||
|
||||
// Create near and far points
|
||||
var nearPoint = new Vector3(mousePosition, 0.0f);
|
||||
var farPoint = new Vector3(mousePosition, 1.0f);
|
||||
viewport.Unproject(ref nearPoint, ref ivp, out nearPoint);
|
||||
viewport.Unproject(ref farPoint, ref ivp, out farPoint);
|
||||
|
||||
// Create direction vector
|
||||
Vector3 direction = farPoint - nearPoint;
|
||||
Vector3 direction = farPoint;
|
||||
direction.Normalize();
|
||||
|
||||
return new Ray(nearPoint + viewOrigin, direction);
|
||||
return new Ray(position, direction);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -993,7 +993,7 @@ bool Level::loadScene(rapidjson_flax::Value& data, int32 engineBuild, Scene** ou
|
||||
|
||||
// /\ all above this has to be done on an any thread
|
||||
// \/ all below this has to be done on multiple threads at once
|
||||
|
||||
|
||||
{
|
||||
PROFILE_CPU_NAMED("Deserialize");
|
||||
|
||||
@@ -1016,8 +1016,16 @@ bool Level::loadScene(rapidjson_flax::Value& data, int32 engineBuild, Scene** ou
|
||||
|
||||
// Synchronize prefab instances (prefab may have objects removed or reordered so deserialized instances need to synchronize with it)
|
||||
// TODO: resave and force sync scenes during game cooking so this step could be skipped in game
|
||||
|
||||
SceneObjectsFactory::SynchronizePrefabInstances(context, prefabSyncData);
|
||||
|
||||
// Cache transformations
|
||||
{
|
||||
PROFILE_CPU_NAMED("Cache Transform");
|
||||
|
||||
scene->OnTransformChanged();
|
||||
}
|
||||
|
||||
// Initialize scene objects
|
||||
{
|
||||
PROFILE_CPU_NAMED("Initialize");
|
||||
@@ -1039,13 +1047,6 @@ bool Level::loadScene(rapidjson_flax::Value& data, int32 engineBuild, Scene** ou
|
||||
}
|
||||
}
|
||||
|
||||
// Cache transformations
|
||||
{
|
||||
PROFILE_CPU_NAMED("Cache Transform");
|
||||
|
||||
scene->OnTransformChanged();
|
||||
}
|
||||
|
||||
// /\ all above this has to be done on an any thread
|
||||
// \/ all below this has to be done on a main thread
|
||||
|
||||
|
||||
@@ -1229,14 +1229,14 @@ bool Prefab::SyncChangesInternal(PrefabInstancesData& prefabInstancesData)
|
||||
{
|
||||
ScopeLock lock(Locker);
|
||||
_isCreatingDefaultInstance = true;
|
||||
_defaultInstance = PrefabManager::SpawnPrefab(this, nullptr, &ObjectsCache, true);
|
||||
_defaultInstance = PrefabManager::SpawnPrefab(this,Transform::Identity, nullptr, &ObjectsCache, true);
|
||||
_isCreatingDefaultInstance = false;
|
||||
}
|
||||
|
||||
// Instantiate prefab instance from prefab (default spawning logic)
|
||||
// Note: it will get any added or removed objects from the nested prefabs
|
||||
// TODO: try to optimize by using recreated default instance to ApplyAllInternal (will need special path there if apply is done with default instance to unlink it instead of destroying)
|
||||
const auto targetActor = PrefabManager::SpawnPrefab(this, nullptr, nullptr, true);
|
||||
const auto targetActor = PrefabManager::SpawnPrefab(this, Transform::Identity, nullptr, nullptr, true);
|
||||
if (targetActor == nullptr)
|
||||
{
|
||||
LOG(Warning, "Failed to instantiate default prefab instance from changes synchronization.");
|
||||
|
||||
@@ -76,7 +76,7 @@ Actor* Prefab::GetDefaultInstance()
|
||||
_isCreatingDefaultInstance = true;
|
||||
|
||||
// Instantiate objects from prefab (default spawning logic)
|
||||
_defaultInstance = PrefabManager::SpawnPrefab(this, nullptr, &ObjectsCache);
|
||||
_defaultInstance = PrefabManager::SpawnPrefab(this, Transform::Identity, nullptr, &ObjectsCache);
|
||||
|
||||
_isCreatingDefaultInstance = false;
|
||||
return _defaultInstance;
|
||||
|
||||
@@ -39,42 +39,37 @@ PrefabManagerService PrefabManagerServiceInstance;
|
||||
Actor* PrefabManager::SpawnPrefab(Prefab* prefab)
|
||||
{
|
||||
Actor* parent = Level::Scenes.Count() != 0 ? Level::Scenes.Get()[0] : nullptr;
|
||||
return SpawnPrefab(prefab, parent, nullptr);
|
||||
return SpawnPrefab(prefab,Transform::Identity, parent, nullptr);
|
||||
}
|
||||
|
||||
Actor* PrefabManager::SpawnPrefab(Prefab* prefab, const Vector3& position)
|
||||
{
|
||||
auto instance = SpawnPrefab(prefab);
|
||||
if (instance)
|
||||
instance->SetPosition(position);
|
||||
return instance;
|
||||
Actor* parent = Level::Scenes.Count() != 0 ? Level::Scenes.Get()[0] : nullptr;
|
||||
return SpawnPrefab(prefab, Transform(position), parent, nullptr);
|
||||
}
|
||||
|
||||
Actor* PrefabManager::SpawnPrefab(Prefab* prefab, const Vector3& position, const Quaternion& rotation)
|
||||
{
|
||||
auto instance = SpawnPrefab(prefab);
|
||||
if (instance)
|
||||
instance->SetTransform(Transform(position, rotation, instance->GetScale()));
|
||||
return instance;
|
||||
Actor* parent = Level::Scenes.Count() != 0 ? Level::Scenes.Get()[0] : nullptr;
|
||||
return SpawnPrefab(prefab, Transform(position, rotation), parent, nullptr);
|
||||
}
|
||||
|
||||
Actor* PrefabManager::SpawnPrefab(Prefab* prefab, const Vector3& position, const Quaternion& rotation, const Vector3& scale)
|
||||
{
|
||||
auto instance = SpawnPrefab(prefab);
|
||||
if (instance)
|
||||
instance->SetTransform(Transform(position, rotation, scale));
|
||||
return instance;
|
||||
Actor* parent = Level::Scenes.Count() != 0 ? Level::Scenes.Get()[0] : nullptr;
|
||||
return SpawnPrefab(prefab, Transform(position, rotation, scale), parent, nullptr);
|
||||
}
|
||||
|
||||
Actor* PrefabManager::SpawnPrefab(Prefab* prefab, const Transform& transform)
|
||||
{
|
||||
auto instance = SpawnPrefab(prefab);
|
||||
if (instance)
|
||||
instance->SetTransform(transform);
|
||||
return instance;
|
||||
Actor* parent = Level::Scenes.Count() != 0 ? Level::Scenes.Get()[0] : nullptr;
|
||||
return SpawnPrefab(prefab, transform, parent, nullptr);
|
||||
}
|
||||
|
||||
Actor* PrefabManager::SpawnPrefab(Prefab* prefab, Actor* parent, Dictionary<Guid, const void*>* objectsCache, bool withSynchronization)
|
||||
Actor* PrefabManager::SpawnPrefab(Prefab* prefab, Actor* parent)
|
||||
{
|
||||
return SpawnPrefab(prefab, Transform::Identity, parent, nullptr);
|
||||
}
|
||||
Actor* PrefabManager::SpawnPrefab(Prefab* prefab,const Transform& transform, Actor* parent, Dictionary<Guid, const void*>* objectsCache, bool withSynchronization)
|
||||
{
|
||||
PROFILE_CPU_NAMED("Prefab.Spawn");
|
||||
if (prefab == nullptr)
|
||||
@@ -183,6 +178,10 @@ Actor* PrefabManager::SpawnPrefab(Prefab* prefab, Actor* parent, Dictionary<Guid
|
||||
if (parent)
|
||||
parent->Children.Add(root);
|
||||
|
||||
//move root to right location
|
||||
if (transform != Transform::Identity)
|
||||
root->SetTransform(transform);
|
||||
|
||||
// Link actors hierarchy
|
||||
for (int32 i = 0; i < sceneObjects->Count(); i++)
|
||||
{
|
||||
|
||||
@@ -70,20 +70,18 @@ API_CLASS(Static) class FLAXENGINE_API PrefabManager
|
||||
/// <param name="prefab">The prefab asset.</param>
|
||||
/// <param name="parent">The parent actor to add spawned object instance. Can be null to just deserialize contents of the prefab.</param>
|
||||
/// <returns>The created actor (root) or null if failed.</returns>
|
||||
API_FUNCTION() static Actor* SpawnPrefab(Prefab* prefab, Actor* parent)
|
||||
{
|
||||
return SpawnPrefab(prefab, parent, nullptr);
|
||||
}
|
||||
API_FUNCTION() static Actor* SpawnPrefab(Prefab* prefab, Actor* parent);
|
||||
|
||||
/// <summary>
|
||||
/// Spawns the instance of the prefab objects. If parent actor is specified then created actors are fully initialized (OnLoad event and BeginPlay is called if parent actor is already during gameplay).
|
||||
/// </summary>
|
||||
/// <param name="prefab">The prefab asset.</param>
|
||||
/// <param name="transform">prefab instance transform.</param>
|
||||
/// <param name="parent">The parent actor to add spawned object instance. Can be null to just deserialize contents of the prefab.</param>
|
||||
/// <param name="objectsCache">The options output objects cache that can be filled with prefab object id mapping to deserialized object (actor or script).</param>
|
||||
/// <param name="withSynchronization">True if perform prefab changes synchronization for the spawned objects. It will check if need to add new objects due to nested prefab modifications.</param>
|
||||
/// <returns>The created actor (root) or null if failed.</returns>
|
||||
static Actor* SpawnPrefab(Prefab* prefab, Actor* parent, Dictionary<Guid, const void*, HeapAllocation>* objectsCache, bool withSynchronization = false);
|
||||
static Actor* SpawnPrefab(Prefab* prefab, const Transform& transform, Actor* parent, Dictionary<Guid, const void*, HeapAllocation>* objectsCache, bool withSynchronization = false);
|
||||
|
||||
#if USE_EDITOR
|
||||
|
||||
|
||||
@@ -1738,7 +1738,7 @@ void NetworkInternal::OnNetworkMessageObjectSpawn(NetworkEvent& event, NetworkCl
|
||||
NETWORK_REPLICATOR_LOG(Error, "[NetworkReplicator] Failed to find prefab {}", msgData.PrefabId.ToString());
|
||||
return;
|
||||
}
|
||||
prefabInstance = PrefabManager::SpawnPrefab(prefab, nullptr, nullptr);
|
||||
prefabInstance = PrefabManager::SpawnPrefab(prefab, Transform::Identity, nullptr, nullptr);
|
||||
if (!prefabInstance)
|
||||
{
|
||||
NETWORK_REPLICATOR_LOG(Error, "[NetworkReplicator] Failed to spawn object type {}", msgData.PrefabId.ToString());
|
||||
|
||||
@@ -146,7 +146,7 @@ void Joint::Create()
|
||||
if (_enableAutoAnchor && target)
|
||||
{
|
||||
// Place target anchor at the joint location
|
||||
desc.Pos1 = Target->GetTransform().WorldToLocal(GetPosition());
|
||||
desc.Pos1 = (Target->GetOrientation() * (GetPosition() - Target->GetPosition())) + Target->GetPosition();
|
||||
desc.Rot1 = WorldToLocal(Target->GetOrientation(), GetOrientation());
|
||||
}
|
||||
_joint = CreateJoint(desc);
|
||||
@@ -158,7 +158,7 @@ void Joint::Create()
|
||||
|
||||
void Joint::OnJointBreak()
|
||||
{
|
||||
JointBreak();
|
||||
JointBreak(this);
|
||||
}
|
||||
|
||||
void Joint::Delete()
|
||||
@@ -197,8 +197,9 @@ Vector3 Joint::GetTargetPosition() const
|
||||
if (Target)
|
||||
{
|
||||
if (_enableAutoAnchor)
|
||||
position = Target->GetTransform().WorldToLocal(GetPosition());
|
||||
position = Target->GetOrientation() * position + Target->GetPosition();
|
||||
position = (Target->GetOrientation() * (GetPosition() - Target->GetPosition())) + Target->GetPosition();
|
||||
else
|
||||
position = Target->GetOrientation() * position + Target->GetPosition();
|
||||
}
|
||||
return position;
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ public:
|
||||
/// <summary>
|
||||
/// Occurs when a joint gets broken during simulation.
|
||||
/// </summary>
|
||||
API_EVENT() Action JointBreak;
|
||||
API_EVENT() Delegate<Joint*> JointBreak;
|
||||
|
||||
/// <summary>
|
||||
/// Called by the physics system when joint gets broken.
|
||||
|
||||
Reference in New Issue
Block a user