feat: add ObjectRef for scene loading to not rely on runtime id's
This commit is contained in:
@@ -563,8 +563,8 @@ bool SceneSerializer::ConstructScene(Scene& scene, LoadResult& result,
|
||||
const std::string name = objectJson.value("name", "GameObject");
|
||||
const bool active = objectJson.value("active", true);
|
||||
|
||||
// File ids are local to the file, every loaded object gets a fresh runtime id
|
||||
GameObject* object = stagingScene.CreateGameObject(name);
|
||||
object->SetIdForDeserialization(id);
|
||||
object->SetActive(active);
|
||||
|
||||
idMap.emplace(id, object);
|
||||
@@ -687,11 +687,14 @@ bool SceneSerializer::ConstructScene(Scene& scene, LoadResult& result,
|
||||
scene.m_name = root.at("name").get<std::string>();
|
||||
}
|
||||
scene.m_SelectedObjectId = InvalidObjectId;
|
||||
scene.m_CurrentCameraId = root.value("currentCamera", InvalidObjectId);
|
||||
if (scene.m_CurrentCameraId != InvalidObjectId && !idMap.contains(scene.m_CurrentCameraId)) {
|
||||
spdlog::warn("Scene \"{}\" current camera id {} does not exist, ignoring it",
|
||||
scene.m_name, scene.m_CurrentCameraId);
|
||||
scene.m_CurrentCameraId = InvalidObjectId;
|
||||
scene.m_CurrentCameraId = InvalidObjectId;
|
||||
if (const ObjectId cameraFileId = root.value("currentCamera", InvalidObjectId); cameraFileId != InvalidObjectId) {
|
||||
if (const auto it = idMap.find(cameraFileId); it != idMap.end()) {
|
||||
scene.m_CurrentCameraId = it->second->GetId();
|
||||
} else {
|
||||
spdlog::warn("Scene \"{}\" current camera id {} does not exist, ignoring it",
|
||||
scene.m_name, cameraFileId);
|
||||
}
|
||||
}
|
||||
scene.m_Environment = SceneEnvironment{};
|
||||
if (root.contains("environment") && root.at("environment").is_object()) {
|
||||
|
||||
Reference in New Issue
Block a user