diff --git a/source/main/terrain/TerrainEditor.cpp b/source/main/terrain/TerrainEditor.cpp index 4b0e5a0101..35eacc5f71 100644 --- a/source/main/terrain/TerrainEditor.cpp +++ b/source/main/terrain/TerrainEditor.cpp @@ -54,7 +54,7 @@ void TerrainEditor::UpdateInputEvents(float dt) Vector3 direction = terrain_editor_mouse_ray.getDirection(); for (int i = 0; i < (int)object_list.size(); i++) { - Real ray_object_distance = direction.crossProduct(object_list[i]->node->getPosition() - origin).length(); + Real ray_object_distance = direction.crossProduct(object_list[i]->getPosition() - origin).length(); if (ray_object_distance < min_dist) { min_dist = ray_object_distance; @@ -77,7 +77,7 @@ void TerrainEditor::UpdateInputEvents(float dt) float min_dist = std::numeric_limits::max(); for (int i = 0; i < (int)object_list.size(); i++) { - float dist = ref_pos.squaredDistance(object_list[i]->node->getPosition()); + float dist = ref_pos.squaredDistance(object_list[i]->getPosition()); if (dist < min_dist) { this->SetSelectedObjectByID(i); @@ -406,9 +406,9 @@ void TerrainEditorObjectRefreshActorVisual(TerrainEditorObjectPtr obj) void TerrainEditorObject::setPosition(Ogre::Vector3 const& pos) { position = pos; - if (node) + if (static_object_node) { - node->setPosition(pos); + static_object_node->setPosition(pos); } else if (special_object_type != TObjSpecialObject::NONE) { @@ -419,10 +419,10 @@ void TerrainEditorObject::setPosition(Ogre::Vector3 const& pos) void TerrainEditorObject::setRotation(Ogre::Vector3 const& rot) { rotation = rot; - if (node) + if (static_object_node) { - node->setOrientation(Quaternion(Degree(rot.x), Vector3::UNIT_X) * Quaternion(Degree(rot.y), Vector3::UNIT_Y) * Quaternion(Degree(rot.z), Vector3::UNIT_Z)); - node->pitch(Degree(-90)); + static_object_node->setOrientation(Quaternion(Degree(rot.x), Vector3::UNIT_X) * Quaternion(Degree(rot.y), Vector3::UNIT_Y) * Quaternion(Degree(rot.z), Vector3::UNIT_Z)); + static_object_node->pitch(Degree(-90)); } else if (special_object_type != TObjSpecialObject::NONE) { diff --git a/source/main/terrain/TerrainEditor.h b/source/main/terrain/TerrainEditor.h index cab8941710..9804327ba5 100644 --- a/source/main/terrain/TerrainEditor.h +++ b/source/main/terrain/TerrainEditor.h @@ -43,13 +43,14 @@ class TerrainEditorObject : public RefCountingObject Ogre::Vector3 rotation = Ogre::Vector3::ZERO; Ogre::Vector3 initial_position = Ogre::Vector3::ZERO; Ogre::Vector3 initial_rotation = Ogre::Vector3::ZERO; - Ogre::SceneNode* node = nullptr; - bool enable_collisions = true; - int script_handler = -1; int tobj_cache_id = -1; std::string tobj_comments; + // ~ only for static objects: + Ogre::SceneNode* static_object_node = nullptr; std::vector static_collision_boxes; std::vector static_collision_tris; + bool enable_collisions = true; + int script_handler = -1; // ~ only for preloaded actors: TObjSpecialObject special_object_type = TObjSpecialObject::NONE; ActorInstanceID_t actor_instance_id = ACTORINSTANCEID_INVALID; @@ -62,8 +63,8 @@ class TerrainEditorObject : public RefCountingObject std::string const& getName(); std::string const& getInstanceName(); std::string const& getType(); - TObjSpecialObject getSpecialObjectType(); // ~ only for preloaded actors: + TObjSpecialObject getSpecialObjectType(); void setSpecialObjectType(TObjSpecialObject type); ActorInstanceID_t getActorInstanceId(); void setActorInstanceId(ActorInstanceID_t instance_id); @@ -74,7 +75,7 @@ class TerrainEditorObject : public RefCountingObject /// * Select object by middle mouse button or Enter key (closest to avatar) /// * Rotate/move selected object with keys /// * Select/edit also preloaded actors - this resets the actor (added 2024 by Petr Ohlidal) -/// Upon exit, file 'editor_out.cfg' is written to ROR_HOME/config (see RGN_CONFIG) +/// Upon exit, the original *.tobj files are updated in place (only if terrain is unzipped in directory) class TerrainEditor { public: diff --git a/source/main/terrain/TerrainObjectManager.cpp b/source/main/terrain/TerrainObjectManager.cpp index fe2a717cb0..590df4e6f3 100644 --- a/source/main/terrain/TerrainObjectManager.cpp +++ b/source/main/terrain/TerrainObjectManager.cpp @@ -510,21 +510,40 @@ void TerrainObjectManager::destroyObject(const String& instancename) return; } - for (int tri : m_editor_objects[id]->static_collision_tris) + TerrainEditorObjectPtr object = m_editor_objects[id]; + + if (object->getSpecialObjectType() != TObjSpecialObject::NONE) { - terrainManager->GetCollisions()->removeCollisionTri(tri); + // Preloaded actor: despawn it. + ROR_ASSERT(!object->static_object_node); + ROR_ASSERT(!object->static_collision_tris.size()); + ROR_ASSERT(!object->static_collision_boxes.size()); + ActorPtr actor = App::GetGameContext()->GetActorManager()->GetActorById(object->actor_instance_id); + if (actor) + { + App::GetGameContext()->PushMessage(Message(MSG_SIM_DELETE_ACTOR_REQUESTED, new ActorPtr(actor))); + } } - for (int box : m_editor_objects[id]->static_collision_boxes) + else { - terrainManager->GetCollisions()->removeCollisionBox(box); - } + // Static object: Destroy the scene node and everything attached to it. + ROR_ASSERT(object->static_object_node); + for (Ogre::MovableObject* mova : object->static_object_node->getAttachedObjects()) + { + App::GetGfxScene()->GetSceneManager()->destroyMovableObject(mova); + } + App::GetGfxScene()->GetSceneManager()->destroySceneNode(object->static_object_node); - // Destroy the scene node and everything attached to it. - for (Ogre::MovableObject* mova : m_editor_objects[id]->node->getAttachedObjects()) - { - App::GetGfxScene()->GetSceneManager()->destroyMovableObject(mova); + // Undo static collisions + for (int tri : object->static_collision_tris) + { + terrainManager->GetCollisions()->removeCollisionTri(tri); + } + for (int box : object->static_collision_boxes) + { + terrainManager->GetCollisions()->removeCollisionBox(box); + } } - App::GetGfxScene()->GetSceneManager()->destroySceneNode(m_editor_objects[id]->node); // Release the object from editor, if active. if (id == App::GetGameContext()->GetTerrain()->GetTerrainEditor()->GetSelectedObjectID()) @@ -647,7 +666,7 @@ bool TerrainObjectManager::LoadTerrainObject(const Ogre::String& name, const Ogr object->rotation = rot; object->initial_position = pos; object->initial_rotation = rot; - object->node = tenode; + object->static_object_node = tenode; object->enable_collisions = enable_collisions; object->script_handler = scripthandler; object->tobj_cache_id = m_tobj_cache_active_id;