MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / ReplaceObjects

Method ReplaceObjects

Source/Editors/map_editor.cpp:1844–1882  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1842}
1843
1844int MapEditor::ReplaceObjects(const std::vector<Object*>& objects, const std::string& replacement_path) {
1845 if (LoadEntitiesFromFile(replacement_path) != 0)
1846 return -1;
1847
1848 ActorsEditor_UnlocalizeIDs(&add_desc_list_, scenegraph_);
1849
1850 for (auto object : objects) {
1851 std::vector<Object*> new_objects = ActorsEditor_AddEntitiesAtPosition(add_desc_list_source_, scenegraph_, add_desc_list_, object->GetTranslation(), create_as_prefab_);
1852
1853 if (!new_objects.empty()) {
1854 vec3 scale = object->GetScale();
1855 vec3 dims = object->box_.dims;
1856 vec3 target_dims = dims * scale;
1857 if (create_as_prefab_) {
1858 Prefab* prefab = static_cast<Prefab*>(new_objects[0]);
1859 vec3 prefab_scale = target_dims / prefab->original_scale_;
1860
1861 prefab->SetScale(prefab->original_scale_ * prefab_scale);
1862 prefab->SetRotation(object->GetRotation());
1863 prefab->SetTranslation(object->GetTranslation());
1864 prefab->PropagateTransformsDown(true);
1865 } else {
1866 for (auto& new_object : new_objects) {
1867 vec3 new_dims = new_object->box_.dims;
1868 vec3 target_scale = target_dims / new_dims;
1869
1870 new_object->SetScale(target_scale);
1871 new_object->SetRotation(object->GetRotation());
1872 new_object->SetTranslation(object->GetTranslation());
1873 }
1874 }
1875 }
1876
1877 RemoveObject(object, scenegraph_, true);
1878 }
1879
1880 QueueSaveHistoryState();
1881 return 0;
1882}
1883
1884void MapEditor::UpdateTools(const LineSegment& mouseray, GameCursor* cursor) {
1885 EditorTypes::Tool t;

Callers 1

DrawImGuiFunction · 0.80

Calls 10

RemoveObjectClass · 0.85
GetTranslationMethod · 0.80
GetRotationMethod · 0.80
emptyMethod · 0.45
SetScaleMethod · 0.45
SetRotationMethod · 0.45
SetTranslationMethod · 0.45

Tested by

no test coverage detected