diff --git a/resources/scripts/road_editor.as b/resources/scripts/road_editor.as index 42ce04cd8c..26a0507294 100644 --- a/resources/scripts/road_editor.as +++ b/resources/scripts/road_editor.as @@ -363,7 +363,19 @@ void drawMeshRebuildPanel() ImGui::InputFloat("Common extra point elevation (meters)", global_extra_point_elevation); ImGui::SetNextItemWidth(120.f); - ImGui::InputInt("Num smoothing splits (0=off)", obj.smoothing_num_splits); + + // create temporary varible because `smoothing_num_splits` is a property {get;set;} + int objSmoothingNumSplits = obj.smoothing_num_splits; + if (ImGui::InputInt("Num smoothing splits (0=off)", objSmoothingNumSplits)) + { + obj.smoothing_num_splits = objSmoothingNumSplits; + } + // create temporary varible because `collision_enabled` is a property {get;set;} + bool objCollisionEnabled = obj.collision_enabled; + if(ImGui::Checkbox("Collision enabled", objCollisionEnabled)) + { + obj.collision_enabled = objCollisionEnabled; + } // NOTE: hotkey is processed in `updateInputEvents()` to be independent of the UI if (ImGui::Button("Rebuild road mesh (hotkey: '" + inputs.getEventCommandTrimmed(EV_ROAD_EDITOR_REBUILD_MESH) + "')")) @@ -383,13 +395,9 @@ void rebuildMesh(ProceduralObjectClass@ obj) { ProceduralManagerClass@ roads = game.getTerrain().getHandle().getProceduralManager(); - roads.removeObject(obj); // Clears the existing mesh recalculatePointElevations(obj); recalculatePointRotations(obj); - roads.addObject(obj); // Generates new mesh - // Because we removed and re-added the ProceduralObject from/to the manager, - // it got new index, so our selection is invalid. Update it. - setSelectedRoad(roads.getNumObjects() - 1); + roads.rebuildObjectMesh(obj); } void recalculatePointElevations(ProceduralObjectClass@ obj) diff --git a/source/main/scripting/bindings/ProceduralRoadAngelscript.cpp b/source/main/scripting/bindings/ProceduralRoadAngelscript.cpp index 2a19a763bd..84d9ff9d01 100644 --- a/source/main/scripting/bindings/ProceduralRoadAngelscript.cpp +++ b/source/main/scripting/bindings/ProceduralRoadAngelscript.cpp @@ -128,4 +128,6 @@ void RoR::RegisterProceduralRoad(asIScriptEngine* engine) result = engine->RegisterObjectMethod("ProceduralManagerClass", "void removeObject(ProceduralObjectClassPtr@)", asMETHOD(ProceduralManager, removeObject), asCALL_THISCALL); ROR_ASSERT(result >= 0); result = engine->RegisterObjectMethod("ProceduralManagerClass", "int getNumObjects()", asMETHOD(RoR::ProceduralManager, getNumObjects), asCALL_THISCALL); ROR_ASSERT(result >= 0); result = engine->RegisterObjectMethod("ProceduralManagerClass", "ProceduralObjectClassPtr @getObject(int pos)", asMETHOD(ProceduralManager, getObject), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("ProceduralManagerClass", "void rebuildObjectMesh(ProceduralObjectClassPtr@)", asMETHOD(ProceduralManager, rebuildObjectMesh), asCALL_THISCALL); ROR_ASSERT(result >= 0); + result = engine->RegisterObjectMethod("ProceduralManagerClass", "void deleteObjectMesh(ProceduralObjectClassPtr@)", asMETHOD(ProceduralManager, deleteObjectMesh), asCALL_THISCALL); ROR_ASSERT(result >= 0); } diff --git a/source/main/terrain/ProceduralManager.cpp b/source/main/terrain/ProceduralManager.cpp index 9d94f3a229..ae5c8e98ec 100644 --- a/source/main/terrain/ProceduralManager.cpp +++ b/source/main/terrain/ProceduralManager.cpp @@ -87,12 +87,12 @@ void ProceduralManager::removeAllObjects() { for (ProceduralObjectPtr obj : pObjects) { - this->deleteObject(obj); + this->deleteObjectMesh(obj); } pObjects.clear(); // delete (unreference) all objects. } -void ProceduralManager::deleteObject(ProceduralObjectPtr po) +void ProceduralManager::deleteObjectMesh(ProceduralObjectPtr po) { if (po->road) { @@ -112,10 +112,10 @@ void ProceduralManager::removeObject(ProceduralObjectPtr po) } } -void ProceduralManager::updateObject(ProceduralObjectPtr po) +void ProceduralManager::rebuildObjectMesh(ProceduralObjectPtr po) { if (po->road) - this->deleteObject(po); + this->deleteObjectMesh(po); po->road = new ProceduralRoad(); po->road->setCollisionEnabled(po->collision_enabled); @@ -172,7 +172,7 @@ void ProceduralManager::updateObject(ProceduralObjectPtr po) void ProceduralManager::addObject(ProceduralObjectPtr po) { - updateObject(po); + rebuildObjectMesh(po); pObjects.push_back(po); } diff --git a/source/main/terrain/ProceduralManager.h b/source/main/terrain/ProceduralManager.h index c09221c912..704ba50a7b 100644 --- a/source/main/terrain/ProceduralManager.h +++ b/source/main/terrain/ProceduralManager.h @@ -97,11 +97,13 @@ class ProceduralManager: public RefCountingObject void removeAllObjects(); -private: /// Rebuilds the road mesh - void updateObject(ProceduralObjectPtr po); + void rebuildObjectMesh(ProceduralObjectPtr po); + /// Deletes the road mesh - void deleteObject(ProceduralObjectPtr po); + void deleteObjectMesh(ProceduralObjectPtr po); + +private: std::vector pObjects; Ogre::SceneNode* pGroupingSceneNode = nullptr;