RigsofRods
Soft-body Physics Simulation
TerrainObjectManager.cpp
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3  Copyright 2005-2012 Pierre-Michel Ricordel
4  Copyright 2007-2012 Thomas Fischer
5  Copyright 2013-2020 Petr Ohlidal
6 
7  For more information, see http://www.rigsofrods.org/
8 
9  Rigs of Rods is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License version 3, as
11  published by the Free Software Foundation.
12 
13  Rigs of Rods is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #include "TerrainObjectManager.h"
23 
24 #include "Actor.h"
25 #include "Application.h"
26 #include "AutoPilot.h"
27 #include "CacheSystem.h"
28 #include "Collisions.h"
29 #include "Console.h"
30 #include "ErrorUtils.h"
31 #include "Language.h"
32 #include "GameContext.h"
33 #include "GfxScene.h"
34 #include "GUIManager.h"
35 #include "GUI_LoadingWindow.h"
36 #include "MeshObject.h"
37 #include "ODefFileFormat.h"
38 #include "PlatformUtils.h"
39 #include "ProceduralRoad.h"
40 #include "ScriptEngine.h"
41 #include "SoundScriptManager.h"
42 #include "TerrainGeometryManager.h"
43 #include "Terrain.h"
44 #include "TObjFileFormat.h"
45 #include "Utils.h"
46 #include "WriteTextToTexture.h"
47 
48 #include <RTShaderSystem/OgreRTShaderSystem.h>
49 #include <Overlay/OgreFontManager.h>
50 
51 #ifdef USE_ANGELSCRIPT
53 #endif // USE_ANGELSCRIPT
54 
55 using namespace Ogre;
56 using namespace RoR;
57 #ifdef USE_PAGED
58 using namespace Forests;
59 #endif //USE_PAGED
60 
61 //workaround for pagedgeometry
62 inline float getTerrainHeight(Real x, Real z, void* unused = 0)
63 {
65 }
66 
67 TerrainObjectManager::TerrainObjectManager(Terrain* terrainManager) :
68  terrainManager(terrainManager)
69 {
70  m_terrn2_grouping_node = App::GetGfxScene()->GetSceneManager()->getRootSceneNode()->createChildSceneNode(fmt::format("Terrain: {}", terrainManager->GetDef().name));
71 
72  m_procedural_manager = new ProceduralManager(m_terrn2_grouping_node->createChildSceneNode("Procedural Roads"));
73 }
74 
76 {
77  for (MeshObject* mo : m_mesh_objects)
78  {
79  if (mo)
80  delete mo;
81  }
82 #ifdef USE_PAGED
83  for (auto geom : m_paged_geometry)
84  {
85  delete geom->getPageLoader();
86  delete geom;
87  }
88 #endif //USE_PAGED
89 
90  App::GetGfxScene()->GetSceneManager()->destroyAllEntities();
91 
93 }
94 
95 void GenerateGridAndPutToScene(Ogre::Vector3 position)
96 {
97  Ogre::ColourValue background_color(Ogre::ColourValue::White);
98  Ogre::ColourValue grid_color(0.2f, 0.2f, 0.2f, 1.0f);
99 
100  Ogre::ManualObject* mo = new Ogre::ManualObject("ReferenceGrid");
101 
102  mo->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_LIST);
103 
104  const float step = 1.0f;
105  const size_t count = 50;
106  unsigned int halfCount = count / 2;
107  const float half = (step * count) / 2;
108  const float y = 0;
109  Ogre::ColourValue c;
110  for (size_t i=0; i < count+1; i++)
111  {
112  if (i == halfCount)
113  c = Ogre::ColourValue(1.f, 0.f, 0.f, 1.f);
114  else
115  c = grid_color;
116 
117  mo->position(-half, y, -half+(step*i));
118  mo->colour(background_color);
119  mo->position(0, y, -half+(step*i));
120  mo->colour(c);
121  mo->position(0, y, -half+(step*i));
122  mo->colour(c);
123  mo->position(half, y, -half+(step*i));
124  mo->colour(background_color);
125 
126  if (i == halfCount)
127  c = Ogre::ColourValue(0,0,1,1.0f);
128  else
129  c = grid_color;
130 
131  mo->position(-half+(step*i), y, -half);
132  mo->colour(background_color);
133  mo->position(-half+(step*i), y, 0);
134  mo->colour(c);
135  mo->position(-half+(step*i), y, 0);
136  mo->colour(c);
137  mo->position(-half+(step*i), y, half);
138  mo->colour(background_color);
139  }
140 
141  mo->end();
142  mo->setCastShadows(false);
143  Ogre::SceneNode *n = App::GetGameContext()->GetTerrain()->getObjectManager()->getGroupingSceneNode()->createChildSceneNode();
144  n->setPosition(position);
145  n->attachObject(mo);
146  n->setVisible(true);
147 }
148 
149 void TerrainObjectManager::LoadTObjFile(Ogre::String tobj_name)
150 {
151  ROR_ASSERT(this->terrainManager);
154 
155  std::shared_ptr<TObjFile> tobj;
156  try
157  {
158  DataStreamPtr stream_ptr = ResourceGroupManager::getSingleton().openResource(
159  tobj_name, this->terrainManager->getCacheEntry()->resource_group);
160  TObjParser parser;
161  parser.Prepare();
162  parser.ProcessOgreStream(stream_ptr.get());
163  tobj = parser.Finalize();
164  }
165  catch (Ogre::Exception& e)
166  {
167  LOG("[RoR|Terrain] Error reading TObj file: " + tobj_name + "\nMessage" + e.getFullDescription());
168  return;
169  }
170  catch (std::exception& e)
171  {
172  LOG("[RoR|Terrain] Error reading TObj file: " + tobj_name + "\nMessage" + e.what());
173  return;
174  }
175 
177  m_tobj_grouping_node = m_terrn2_grouping_node->createChildSceneNode(tobj_name);
178 
179  int mapsizex = terrainManager->getGeometryManager()->getMaxTerrainSize().x;
180  int mapsizez = terrainManager->getGeometryManager()->getMaxTerrainSize().z;
181 
182  // Section 'grid'
183  if (tobj->grid_enabled)
184  {
185  GenerateGridAndPutToScene(tobj->grid_position);
186  }
187 
188  // Section 'trees'
189  if (App::gfx_vegetation_mode->getEnum<GfxVegetation>() != GfxVegetation::NONE)
190  {
191  for (TObjTree tree : tobj->trees)
192  {
193  try
194  {
195  this->ProcessTree(
196  tree.yaw_from, tree.yaw_to,
197  tree.scale_from, tree.scale_to,
198  tree.color_map, tree.density_map, tree.tree_mesh, tree.collision_mesh,
199  tree.grid_spacing, tree.high_density,
200  tree.min_distance, tree.max_distance, mapsizex, mapsizez);
201  }
202  catch (...)
203  {
204  RoR::HandleGenericException(fmt::format("Error processing 'trees' line (mesh: {}) from TOBJ file {}", tree.tree_mesh, tobj_name));
205  }
206  }
207  }
208 
209  // Section 'grass' / 'grass2'
210  if (App::gfx_vegetation_mode->getEnum<GfxVegetation>() != GfxVegetation::NONE)
211  {
212  for (TObjGrass grass : tobj->grass)
213  {
214  try
215  {
216  this->ProcessGrass(
217  grass.sway_speed, grass.sway_length, grass.sway_distrib, grass.density,
218  grass.min_x, grass.min_y, grass.min_h,
219  grass.max_x, grass.max_y, grass.max_h,
221  grass.grow_techniq, grass.technique, grass.range, mapsizex, mapsizez);
222  }
223  catch (...)
224  {
225  RoR::HandleGenericException(fmt::format("Error processing 'grass' line (material: {}) from TOBJ file {}", grass.material_name, tobj_name));
226  }
227  }
228  }
229 
230  // Procedural roads
231  for (ProceduralObjectPtr& po : tobj->proc_objects)
232  {
233  try
234  {
236  }
237  catch (...)
238  {
239  RoR::HandleGenericException(fmt::format("Error processing procedural road {} from TOBJ file {}", po->name, tobj_name));
240  }
241  }
242 
243  // Vehicles
244  for (TObjVehicle const& veh : tobj->vehicles)
245  {
246  if ((veh.type == TObj::SpecialObject::BOAT) && (terrainManager->getWater() == nullptr))
247  {
248  continue; // Don't spawn boats if there's no water.
249  }
250 
251  // NOTE: The filename may be in "Bundle-qualified" format, i.e. "mybundle.zip:myactor.truck"
252 
253  PredefinedActor p;
254  p.px = veh.position.x;
255  p.py = veh.position.y;
256  p.pz = veh.position.z;
259  p.rotation = veh.rotation;
260  p.name = veh.name;
261  m_predefined_actors.push_back(p);
262  }
263 
264  // Entries
265  for (TObjEntry entry : tobj->objects)
266  {
267  try
268  {
269  this->LoadTerrainObject(entry.odef_name, entry.position, entry.rotation, entry.instance_name, entry.type, entry.rendering_distance);
270  }
271  catch (...)
272  {
273  RoR::HandleGenericException(fmt::format("Error processing object line (ODEF: {}) from TOBJ file {}", entry.odef_name, tobj_name));
274  }
275  }
276 
277  if (App::diag_terrn_log_roads->getBool())
278  {
280  }
281 
282  m_tobj_grouping_node = nullptr;
283 }
284 
286  float yawfrom, float yawto,
287  float scalefrom, float scaleto,
288  char* ColorMap, char* DensityMap, char* treemesh, char* treeCollmesh,
289  float gridspacing, float highdens,
290  int minDist, int maxDist, int mapsizex, int mapsizez)
291 {
292 #ifdef USE_PAGED
293  if (strnlen(ColorMap, 3) == 0)
294  {
295  LOG("tree ColorMap map zero!");
296  return;
297  }
298  if (strnlen(DensityMap, 3) == 0)
299  {
300  LOG("tree DensityMap zero!");
301  return;
302  }
303  Forests::DensityMap *densityMap = Forests::DensityMap::load(DensityMap, Forests::CHANNEL_COLOR);
304  if (!densityMap)
305  {
306  LOG("could not load densityMap: "+String(DensityMap));
307  return;
308  }
309  densityMap->setFilter(Forests::MAPFILTER_BILINEAR);
310  //densityMap->setMapBounds(TRect(0, 0, mapsizex, mapsizez));
311 
312  PagedGeometry* geom = new PagedGeometry();
313  geom->setTempDir(App::sys_cache_dir->getStr() + PATH_SLASH);
314  geom->setCamera(App::GetCameraManager()->GetCamera());
315  geom->setPageSize(50);
316  geom->setInfinite();
317  Ogre::TRect<Ogre::Real> bounds = TBounds(0, 0, mapsizex, mapsizez);
318  geom->setBounds(bounds);
319 
320  //Set up LODs
321  //trees->addDetailLevel<EntityPage>(50);
322  float min = minDist * terrainManager->getPagedDetailFactor();
323  if (min < 10)
324  min = 10;
325  geom->addDetailLevel<BatchPage>(min, min / 2);
326  float max = maxDist * terrainManager->getPagedDetailFactor();
327  if (max < 10)
328  max = 10;
329 
330  // Check if farther details level is greater than closer
331  if (max / 10 > min / 2)
332  {
333  geom->addDetailLevel<ImpostorPage>(max, max / 10);
334  }
335 
336  TreeLoader2D *treeLoader = new TreeLoader2D(geom, TBounds(0, 0, mapsizex, mapsizez));
337  treeLoader->setMinimumScale(scalefrom);
338  treeLoader->setMaximumScale(scaleto);
339  geom->setPageLoader(treeLoader);
340  treeLoader->setHeightFunction(&getTerrainHeight);
341  if (String(ColorMap) != "none")
342  {
343  treeLoader->setColorMap(ColorMap);
344  }
345 
346  Entity* curTree = App::GetGfxScene()->GetSceneManager()->createEntity(String("paged_") + treemesh + TOSTRING(m_paged_geometry.size()), treemesh);
347 
348  if (gridspacing > 0)
349  {
350  // grid style
351  for (float x=0; x < mapsizex; x += gridspacing)
352  {
353  for (float z=0; z < mapsizez; z += gridspacing)
354  {
355  float density = densityMap->_getDensityAt_Unfiltered(x, z, bounds);
356  if (density < 0.8f) continue;
357  float nx = x + gridspacing * 0.5f;
358  float nz = z + gridspacing * 0.5f;
359  float yaw = Math::RangeRandom(yawfrom, yawto);
360  float scale = Math::RangeRandom(scalefrom, scaleto);
361  Vector3 pos = Vector3(nx, 0, nz);
362  treeLoader->addTree(curTree, pos, Degree(yaw), (Ogre::Real)scale);
363  if (strlen(treeCollmesh))
364  {
365  pos.y = terrainManager->GetHeightAt(pos.x, pos.z);
366  scale *= 0.1f;
367  terrainManager->GetCollisions()->addCollisionMesh(curTree->getName(), String(treeCollmesh), pos, Quaternion(Degree(yaw), Vector3::UNIT_Y), Vector3(scale, scale, scale));
368  }
369  }
370  }
371  }
372  else
373  {
374  float gridsize = 10;
375  if (gridspacing < 0 && gridspacing != 0)
376  {
377  gridsize = -gridspacing;
378  }
379  float hd = highdens;
380  // normal style, random
381  for (float x=0; x < mapsizex; x += gridsize)
382  {
383  for (float z=0; z < mapsizez; z += gridsize)
384  {
385  if (highdens < 0) hd = Math::RangeRandom(0, -highdens);
386  float density = densityMap->_getDensityAt_Unfiltered(x, z, bounds);
387  int numTreesToPlace = (int)((float)(hd) * density * terrainManager->getPagedDetailFactor());
388  float nx=0, nz=0;
389  while(numTreesToPlace-->0)
390  {
391  nx = Math::RangeRandom(x, x + gridsize);
392  nz = Math::RangeRandom(z, z + gridsize);
393  float yaw = Math::RangeRandom(yawfrom, yawto);
394  float scale = Math::RangeRandom(scalefrom, scaleto);
395  Vector3 pos = Vector3(nx, 0, nz);
396  treeLoader->addTree(curTree, pos, Degree(yaw), (Ogre::Real)scale);
397  if (strlen(treeCollmesh))
398  {
399  pos.y = terrainManager->GetHeightAt(pos.x, pos.z);
400  terrainManager->GetCollisions()->addCollisionMesh(treemesh, String(treeCollmesh),pos, Quaternion(Degree(yaw), Vector3::UNIT_Y), Vector3(scale, scale, scale));
401  }
402  }
403  }
404  }
405  }
406  m_paged_geometry.push_back(geom);
407 #endif //USE_PAGED
408 }
409 
411  float SwaySpeed, float SwayLength, float SwayDistribution, float Density,
412  float minx, float miny, float minH, float maxx, float maxy, float maxH,
413  char* grassmat, char* colorMapFilename, char* densityMapFilename,
414  int growtechnique, int techn, int range,
415  int mapsizex, int mapsizez)
416 {
417 #ifdef USE_PAGED
418  //Initialize the PagedGeometry engine
419  try
420  {
421  PagedGeometry *grass = new PagedGeometry(App::GetCameraManager()->GetCamera(), 30);
422  //Set up LODs
423 
424  grass->addDetailLevel<GrassPage>(range * terrainManager->getPagedDetailFactor()); // original value: 80
425 
426  //Set up a GrassLoader for easy use
427  GrassLoader *grassLoader = new GrassLoader(grass);
428  grass->setPageLoader(grassLoader);
429  grassLoader->setHeightFunction(&getTerrainHeight);
430 
431  // render grass at first
432  grassLoader->setRenderQueueGroup(RENDER_QUEUE_MAIN-1);
433 
434  GrassLayer* grassLayer = grassLoader->addLayer(grassmat);
435  grassLayer->setHeightRange(minH, maxH);
436  grassLayer->setLightingEnabled(true);
437 
438  grassLayer->setAnimationEnabled((SwaySpeed>0));
439  grassLayer->setSwaySpeed(SwaySpeed);
440  grassLayer->setSwayLength(SwayLength);
441  grassLayer->setSwayDistribution(SwayDistribution);
442 
443  grassLayer->setDensity(Density * terrainManager->getPagedDetailFactor());
444  if (techn>10)
445  grassLayer->setRenderTechnique(static_cast<GrassTechnique>(techn-10), true);
446  else
447  grassLayer->setRenderTechnique(static_cast<GrassTechnique>(techn), false);
448 
449  grassLayer->setMapBounds(TBounds(0, 0, mapsizex, mapsizez));
450 
451  if (strcmp(colorMapFilename,"none") != 0)
452  {
453  grassLayer->setColorMap(colorMapFilename);
454  grassLayer->setColorMapFilter(MAPFILTER_BILINEAR);
455  }
456 
457  if (strcmp(densityMapFilename,"none") != 0)
458  {
459  grassLayer->setDensityMap(densityMapFilename);
460  grassLayer->setDensityMapFilter(MAPFILTER_BILINEAR);
461  }
462 
463  grassLayer->setMinimumSize(minx, miny);
464  grassLayer->setMaximumSize(maxx, maxy);
465 
466  // growtechnique
467  if (growtechnique == 0)
468  grassLayer->setFadeTechnique(FADETECH_GROW);
469  else if (growtechnique == 1)
470  grassLayer->setFadeTechnique(FADETECH_ALPHAGROW);
471  else if (growtechnique == 2)
472  grassLayer->setFadeTechnique(FADETECH_ALPHA);
473 
474  m_paged_geometry.push_back(grass);
475  }
476  catch(...)
477  {
478  LOG("error loading grass!");
479  }
480 #endif //USE_PAGED
481 }
482 
483 void TerrainObjectManager::MoveObjectVisuals(const String& instancename, const Ogre::Vector3& pos)
484 {
485  if (m_static_objects.find(instancename) == m_static_objects.end())
486  {
487  LOG(instancename+ " not found!");
488  return;
489  }
490 
491  StaticObject obj = m_static_objects[instancename];
492 
493  if (!obj.enabled)
494  return;
495 
496  obj.sceneNode->setPosition(pos);
497 }
498 
499 void TerrainObjectManager::unloadObject(const String& instancename)
500 {
501  if (m_static_objects.find(instancename) == m_static_objects.end())
502  {
503  LOG("unable to unload object: " + instancename);
504  return;
505  }
506 
507  StaticObject obj = m_static_objects[instancename];
508 
509  if (!obj.enabled)
510  return;
511 
512  for (auto tri : obj.collTris)
513  {
515  }
516  for (auto box : obj.collBoxes)
517  {
519  }
520 
521  obj.sceneNode->detachAllObjects();
522  obj.sceneNode->setVisible(false);
523  obj.enabled = false;
524 
525  m_editor_objects.erase(std::remove_if(m_editor_objects.begin(), m_editor_objects.end(),
526  [instancename](EditorObject& e) { return e.instance_name == instancename; }), m_editor_objects.end());
527 }
528 
529 ODefFile* TerrainObjectManager::FetchODef(std::string const & odef_name)
530 {
531  // Consult cache first
532  auto search_res = m_odef_cache.find(odef_name);
533  if (search_res != m_odef_cache.end())
534  {
535  return search_res->second.get();
536  }
537 
538  // Search for the file
539  const std::string filename = odef_name + ".odef";
540  std::string group_name;
541  try
542  {
543  group_name = Ogre::ResourceGroupManager::getSingleton().findGroupContainingResource(filename);
544  }
545  catch (...) // This means "not found"
546  {
547  LOG(fmt::format("[ODEF] Could not find {} in any resource group", filename));
548  return nullptr;
549  }
550 
551  try
552  {
553  // Load and parse the file
554  Ogre::DataStreamPtr ds = ResourceGroupManager::getSingleton().openResource(filename, group_name);
555  ODefParser parser;
556  parser.Prepare();
557  parser.ProcessOgreStream(ds.get());
558  std::shared_ptr<ODefFile> odef = parser.Finalize();
559 
560  // Add to cache and return
561  m_odef_cache.insert(std::make_pair(odef_name, odef));
562  return odef.get();
563  }
564  catch (...)
565  {
566  LOG(fmt::format("[ODEF] An exception occurred when loading or parsing {}", filename));
567  return nullptr;
568  }
569 }
570 
571 bool TerrainObjectManager::LoadTerrainObject(const Ogre::String& name, const Ogre::Vector3& pos, const Ogre::Vector3& rot, const Ogre::String& instancename, const Ogre::String& type, float rendering_distance /* = 0 */, bool enable_collisions /* = true */, int scripthandler /* = -1 */, bool uniquifyMaterial /* = false */)
572 {
573  if (type == "grid")
574  {
575  // some fast grid object hacks :)
576  for (int x = 0; x < 500; x += 50)
577  {
578  for (int z = 0; z < 500; z += 50)
579  {
580  const String notype = "";
581  LoadTerrainObject(name, pos + Vector3(x, 0.0f, z), rot, name, notype, /*rendering_distance:*/0, enable_collisions, scripthandler, uniquifyMaterial);
582  }
583  }
584  return true;
585  }
586 
587  const std::string odefname = name + ".odef"; // for logging
588  ODefFile* odef = this->FetchODef(name);
589  if (odef == nullptr)
590  {
591  // Only log to console if requested from Console UI or script (debug message to RoR.log is written anyway).
592  if (App::app_state->getEnum<AppState>() == AppState::SIMULATION)
593  {
595  fmt::format(_L("Could not load file '{}'"), odefname));
596  }
597  return false;
598  }
599 
600  SceneNode* tenode = this->getGroupingSceneNode()->createChildSceneNode();
601 
602  MeshObject* mo = nullptr;
603  if (odef->header.mesh_name != "none")
604  {
605  Str<100> ebuf; ebuf << m_entity_counter++ << "-" << odef->header.mesh_name;
606  mo = new MeshObject(odef->header.mesh_name, terrainManager->getTerrainFileResourceGroup(), ebuf.ToCStr(), tenode);
607  if (mo->getEntity())
608  {
609  mo->getEntity()->setCastShadows(odef->header.cast_shadows);
610  mo->getEntity()->setRenderingDistance(rendering_distance);
611  m_mesh_objects.push_back(mo);
612  }
613  else
614  {
615  delete mo;
616  // Only log to console if requested from Console UI or script (debug message to RoR.log is written anyway).
617  if (App::app_state->getEnum<AppState>() == AppState::SIMULATION)
618  {
620  fmt::format(_L("Could not load mesh '{}' (used by object '{}')"), odef->header.mesh_name, odefname));
621  }
622  }
623  }
624 
625  tenode->setScale(odef->header.scale);
626  tenode->setPosition(pos);
627  Quaternion rotation = Quaternion(Degree(rot.x), Vector3::UNIT_X) * Quaternion(Degree(rot.y), Vector3::UNIT_Y) * Quaternion(Degree(rot.z), Vector3::UNIT_Z);
628  tenode->rotate(rotation);
629  tenode->pitch(Degree(-90));
630  tenode->setVisible(true);
631 
632  // register in map
633  StaticObject* obj = &m_static_objects[instancename];
634  obj->instanceName = instancename;
635  obj->enabled = true;
636  obj->sceneNode = tenode;
637  obj->collTris.clear();
638 
639  EditorObject object;
640  object.name = name;
641  object.instance_name = instancename;
642  object.type = type;
643  object.position = pos;
644  object.rotation = rot;
645  object.initial_position = pos;
646  object.initial_rotation = rot;
647  object.node = tenode;
648  object.enable_collisions = enable_collisions;
649  object.script_handler = scripthandler;
650  m_editor_objects.push_back(object);
651 
652  if (mo && uniquifyMaterial && !instancename.empty())
653  {
654  for (unsigned int i = 0; i < mo->getEntity()->getNumSubEntities(); i++)
655  {
656  SubEntity* se = mo->getEntity()->getSubEntity(i);
657  String matname = se->getMaterialName();
658  String newmatname = matname + "/" + instancename;
659  se->getMaterial()->clone(newmatname);
660  se->setMaterialName(newmatname);
661  }
662  }
663 
664  for (LocalizerType type : odef->localizers)
665  {
666  localizer_t loc;
667  loc.position = Vector3(pos.x, pos.y, pos.z);
668  loc.rotation = rotation;
669  loc.type = type;
670  localizers.push_back(loc);
671  }
672 
673  if (odef->mode_standard)
674  {
675  tenode->pitch(Degree(90));
676  }
677 
678 #ifdef USE_OPENAL
679  if (!App::GetSoundScriptManager()->isDisabled())
680  {
681  for (std::string& snd_name : odef->sounds)
682  {
684  sound->setPosition(tenode->getPosition());
685  sound->start();
686  }
687  }
688 #endif //USE_OPENAL
689 
690  for (std::string& gmodel_file: odef->groundmodel_files)
691  {
693  }
694 
695  bool race_event = !object.instance_name.compare(0, 10, "checkpoint") ||
696  !object.instance_name.compare(0, 4, "race");
697 
698  if (race_event)
699  {
700  String type = "checkpoint";
701  auto res = StringUtil::split(object.instance_name, "|");
702  if ((res.size() == 4 && res[2] == "0") || !object.instance_name.compare(0, 4, "race"))
703  {
704  type = "racestart";
705  }
706  int race_id = res.size() > 1 ? StringConverter::parseInt(res[1], -1) : -1;
707  m_map_entities.push_back(SurveyMapEntity(type, /*caption:*/type, fmt::format("icon_{}.dds", type), /*resource_group:*/"", object.position, Ogre::Radian(0), race_id));
708  }
709  else if (!object.type.empty())
710  {
711  String caption = "";
712  if (object.type == "station" || object.type == "hotel" || object.type == "village" ||
713  object.type == "observatory" || object.type == "farm" || object.type == "ship" || object.type == "sign")
714  {
715  caption = object.instance_name + " " + object.type;
716  }
717  m_map_entities.push_back(SurveyMapEntity(object.type, caption, fmt::format("icon_{}.dds", object.type), /*resource_group:*/"", object.position, Ogre::Radian(0), -1));
718  }
719 
720  this->ProcessODefCollisionBoxes(obj, odef, object, race_event);
721 
722  for (ODefCollisionMesh& cmesh : odef->collision_meshes)
723  {
724  if (cmesh.mesh_name == "")
725  {
726  LOG("[ODEF] Skipping collision mesh with empty name. Object: " + odefname);
727  continue;
728  }
729 
732  odefname,
733  cmesh.mesh_name, pos, tenode->getOrientation(),
734  cmesh.scale, gm, &(obj->collTris));
735  }
736 
737  for (ODefParticleSys& psys : odef->particle_systems)
738  {
739 
740  // hacky: prevent duplicates
741  String paname = String(psys.instance_name);
742  while (App::GetGfxScene()->GetSceneManager()->hasParticleSystem(paname))
743  paname += "_";
744 
745  // create particle system
746  ParticleSystem* pParticleSys = App::GetGfxScene()->GetSceneManager()->createParticleSystem(paname, String(psys.template_name));
747  pParticleSys->setCastShadows(false);
748  pParticleSys->setVisibilityFlags(DEPTHMAP_DISABLED); // disable particles in depthmap
749 
750  // Some affectors may need its instance name (e.g. for script feedback purposes)
751 #ifdef USE_ANGELSCRIPT
752  unsigned short affCount = pParticleSys->getNumAffectors();
753  ParticleAffector* pAff;
754  for (unsigned short i = 0; i < affCount; ++i)
755  {
756  pAff = pParticleSys->getAffector(i);
757  if (pAff->getType() == "ExtinguishableFire")
758  {
759  ((ExtinguishableFireAffector*)pAff)->setInstanceName(obj->instanceName);
760  }
761  }
762 #endif // USE_ANGELSCRIPT
763 
764  SceneNode* sn = tenode->createChildSceneNode();
765  sn->attachObject(pParticleSys);
766  sn->pitch(Degree(90));
767  }
768 
769  if (!odef->mat_name.empty())
770  {
771  if (mo->getEntity())
772  {
773  mo->getEntity()->setMaterialName(odef->mat_name);
774  }
775  }
776 
777  if (odef->mat_name_generate != "")
778  {
779  Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create(odef->mat_name_generate,"generatedMaterialShaders");
780  Ogre::RTShader::ShaderGenerator::getSingleton().createShaderBasedTechnique(*mat, Ogre::MaterialManager::DEFAULT_SCHEME_NAME, Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);
781  Ogre::RTShader::ShaderGenerator::getSingleton().invalidateMaterial(RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME, String(odef->mat_name_generate));
782  }
783 
784  for (ODefAnimation& anim : odef->animations)
785  {
786  if (tenode && mo->getEntity())
787  {
788  AnimationStateSet *s = mo->getEntity()->getAllAnimationStates();
789  String anim_name_str(anim.name);
790  if (!s->hasAnimationState(anim_name_str))
791  {
792  LOG("[ODEF] animation '" + anim_name_str + "' for mesh: '" + odef->header.mesh_name + "' in odef file '" + name + ".odef' not found!");
793  //continue;
794  }
795  AnimatedObject ao;
796  ao.node = tenode;
797  ao.ent = mo->getEntity();
798  ao.speedfactor = anim.speed_min;
799  if (anim.speed_min != anim.speed_max)
800  ao.speedfactor = Math::RangeRandom(anim.speed_min, anim.speed_max);
801  ao.anim = 0;
802  try
803  {
804  ao.anim = mo->getEntity()->getAnimationState(anim_name_str);
805  } catch (...)
806  {
807  ao.anim = 0;
808  }
809  if (!ao.anim)
810  {
811  LOG("[ODEF] animation '" + anim_name_str + "' for mesh: '" + odef->header.mesh_name + "' in odef file '" + name + ".odef' not found!");
812  continue;
813  }
814  ao.anim->setEnabled(true);
815  m_animated_objects.push_back(ao);
816  }
817  }
818 
819  for (ODefTexPrint& tex_print : odef->texture_prints)
820  {
821  if (!mo->getEntity())
822  continue;
823  String matName = mo->getEntity()->getSubEntity(0)->getMaterialName();
824  MaterialPtr m = MaterialManager::getSingleton().getByName(matName);
825  if (m.getPointer() == 0)
826  {
827  LOG("[ODEF] problem with drawTextOnMeshTexture command: mesh material not found: "+odefname+" : "+matName);
828  continue;
829  }
830  String texName = m->getTechnique(0)->getPass(0)->getTextureUnitState(0)->getTextureName();
831  Texture* background = (Texture *)TextureManager::getSingleton().getByName(texName).getPointer();
832  if (!background)
833  {
834  LOG("[ODEF] problem with drawTextOnMeshTexture command: mesh texture not found: "+odefname+" : "+texName);
835  continue;
836  }
837 
838  static int textureNumber = 0;
839  textureNumber++;
840  char tmpTextName[256] = "", tmpMatName[256] = "";
841  sprintf(tmpTextName, "TextOnTexture_%d_Texture", textureNumber);
842  sprintf(tmpMatName, "TextOnTexture_%d_Material", textureNumber); // Make sure the texture is not WRITE_ONLY, we need to read the buffer to do the blending with the font (get the alpha for example)
843  TexturePtr texture = TextureManager::getSingleton().createManual(tmpTextName, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, (Ogre::uint)background->getWidth(), (Ogre::uint)background->getHeight(), MIP_UNLIMITED, PF_X8R8G8B8, Ogre::TU_STATIC | Ogre::TU_AUTOMIPMAP);
844  if (texture.getPointer() == 0)
845  {
846  LOG("[ODEF] problem with drawTextOnMeshTexture command: could not create texture: "+odefname+" : "+tmpTextName);
847  continue;
848  }
849 
850  Str<200> text_buf; text_buf << tex_print.text;
851 
852  // check if we got a template argument
853  if (!strncmp(text_buf.GetBuffer(), "{{argument1}}", 13))
854  {
855  text_buf.Clear();
856  text_buf << instancename;
857  }
858 
859  // replace '_' with ' '
860  char *text_pointer = text_buf.GetBuffer();
861  while (*text_pointer!=0) {if (*text_pointer=='_') *text_pointer=' ';text_pointer++;};
862 
863  String font_name_str(tex_print.font_name);
864  Ogre::Font* font = (Ogre::Font *)FontManager::getSingleton().getByName(font_name_str).getPointer();
865  if (!font)
866  {
867  LOG("[ODEF] problem with drawTextOnMeshTexture command: font not found: "+odefname+" : "+font_name_str);
868  continue;
869  }
870 
871  //Draw the background to the new texture
872  texture->getBuffer()->blit(background->getBuffer());
873 
874  float x = background->getWidth() * tex_print.x;
875  float y = background->getHeight() * tex_print.y;
876  float w = background->getWidth() * tex_print.w;
877  float h = background->getHeight() * tex_print.h;
878 
879  ColourValue color(tex_print.r, tex_print.g, tex_print.b, tex_print.a);
880  Ogre::Box box = Ogre::Box((size_t)x, (size_t)y, (size_t)(x+w), (size_t)(y+h));
881  WriteToTexture(text_buf.ToCStr(), texture, box, font, color, tex_print.font_size, tex_print.font_dpi, tex_print.option);
882 
883  // we can save it to disc for debug purposes:
884  //SaveImage(texture, "test.png");
885 
886  m->clone(tmpMatName);
887  MaterialPtr mNew = MaterialManager::getSingleton().getByName(tmpMatName);
888  mNew->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(tmpTextName);
889 
890  mo->getEntity()->setMaterialName(String(tmpMatName));
891  }
892 
893  for (ODefSpotlight& spotl: odef->spotlights)
894  {
895  Light* spotLight = App::GetGfxScene()->GetSceneManager()->createLight();
896 
897  spotLight->setType(Light::LT_SPOTLIGHT);
898  spotLight->setPosition(spotl.pos);
899  spotLight->setDirection(spotl.dir);
900  spotLight->setAttenuation(spotl.range, 1.0, 0.3, 0.0);
901  spotLight->setDiffuseColour(spotl.color);
902  spotLight->setSpecularColour(spotl.color);
903  spotLight->setSpotlightRange(Degree(spotl.angle_inner), Degree(spotl.angle_outer));
904 
905  BillboardSet* lflare = App::GetGfxScene()->GetSceneManager()->createBillboardSet(1);
906  lflare->createBillboard(spotl.pos, spotl.color);
907  lflare->setMaterialName("tracks/flare");
908  lflare->setVisibilityFlags(DEPTHMAP_DISABLED);
909 
910  float fsize = Math::Clamp(spotl.range / 10, 0.2f, 2.0f);
911  lflare->setDefaultDimensions(fsize, fsize);
912 
913  SceneNode *sn = tenode->createChildSceneNode();
914  sn->attachObject(spotLight);
915  sn->attachObject(lflare);
916  }
917 
918  for (ODefPointLight& plight : odef->point_lights)
919  {
920  Light* pointlight = App::GetGfxScene()->GetSceneManager()->createLight();
921 
922  pointlight->setType(Light::LT_POINT);
923  pointlight->setPosition(plight.pos);
924  pointlight->setDirection(plight.dir);
925  pointlight->setAttenuation(plight.range, 1.0, 0.3, 0.0);
926  pointlight->setDiffuseColour(plight.color);
927  pointlight->setSpecularColour(plight.color);
928 
929  BillboardSet* lflare = App::GetGfxScene()->GetSceneManager()->createBillboardSet(1);
930  lflare->createBillboard(plight.pos, plight.color);
931  lflare->setMaterialName("tracks/flare");
932  lflare->setVisibilityFlags(DEPTHMAP_DISABLED);
933 
934  float fsize = Math::Clamp(plight.range / 10, 0.2f, 2.0f);
935  lflare->setDefaultDimensions(fsize, fsize);
936 
937  SceneNode *sn = tenode->createChildSceneNode();
938  sn->attachObject(pointlight);
939  sn->attachObject(lflare);
940  }
941 
942  return true;
943 }
944 
945 bool TerrainObjectManager::LoadTerrainScript(const Ogre::String& filename)
946 {
948 
949  m_angelscript_grouping_node = m_terrn2_grouping_node->createChildSceneNode(filename);
950  ScriptUnitId_t result = App::GetScriptEngine()->loadScript(filename);
951  m_angelscript_grouping_node = nullptr;
952 
953  return result != SCRIPTUNITID_INVALID;
954 }
955 
957 {
958  if (m_animated_objects.size() == 0)
959  return true;
960 
961  std::vector<AnimatedObject>::iterator it;
962 
963  for (it = m_animated_objects.begin(); it != m_animated_objects.end(); it++)
964  {
965  if (it->anim && it->speedfactor != 0)
966  {
967  Real time = dt * it->speedfactor;
968  it->anim->addTime(time);
969  }
970  }
971  return true;
972 }
973 
975 {
976  for (Terrn2Telepoint& telepoint: terrainManager->GetDef().telepoints)
977  {
978  m_map_entities.push_back(SurveyMapEntity("telepoint", telepoint.name, "icon_telepoint.dds", /*resource_group:*/"", telepoint.position, Ogre::Radian(0), -1));
979  }
980 }
981 
983 {
984  // in netmode, don't load other actors!
985  if (RoR::App::mp_state->getEnum<MpState>() == RoR::MpState::CONNECTED)
986  {
987  return;
988  }
989 
990  for (unsigned int i = 0; i < m_predefined_actors.size(); i++)
991  {
993  rq->asr_position = Vector3(m_predefined_actors[i].px, m_predefined_actors[i].py, m_predefined_actors[i].pz);
994  rq->asr_filename = m_predefined_actors[i].name;
995  rq->asr_rotation = m_predefined_actors[i].rotation;
997  rq->asr_free_position = m_predefined_actors[i].freePosition;
998  rq->asr_terrn_machine = m_predefined_actors[i].ismachine;
1000  }
1001 }
1002 
1004 {
1005 #ifdef USE_PAGED
1006  for (auto geom : m_paged_geometry)
1007  {
1008  geom->update();
1009  }
1010 #endif //USE_PAGED
1011  this->UpdateAnimatedObjects(dt);
1012 
1013  return true;
1014 }
1015 
1017 {
1018  for (ODefCollisionBox& cbox : odef->collision_boxes)
1019  {
1020  if (params.enable_collisions && (App::sim_races_enabled->getBool() || !race_event))
1021  {
1022  // Validate AABB (minimum corners must be less or equal to maximum corners)
1023  if (cbox.aabb_min.x > cbox.aabb_max.x || cbox.aabb_min.y > cbox.aabb_max.y || cbox.aabb_min.z > cbox.aabb_max.z)
1024  {
1025  // Only log to console if invoked from Console UI or script.
1026  std::string msg = "Skipping invalid collision box, min: " + TOSTRING(cbox.aabb_min) + ", max: " + TOSTRING(cbox.aabb_max);
1027  if (App::app_state->getEnum<AppState>() == AppState::SIMULATION)
1028  {
1030  }
1031  else
1032  {
1033  LOG(fmt::format("[ODEF] {}", msg));
1034  }
1035  continue;
1036  }
1037 
1038  int boxnum = terrainManager->GetCollisions()->addCollisionBox(
1039  cbox.is_rotating, cbox.is_virtual, params.position, params.rotation,
1040  cbox.aabb_min, cbox.aabb_max, cbox.box_rot, cbox.event_name,
1041  params.instance_name, cbox.force_cam_pos, cbox.cam_pos,
1042  cbox.scale, cbox.direction, cbox.event_filter, params.script_handler);
1043 
1044  obj->collBoxes.push_back(boxnum);
1045  }
1046  }
1047 }
1048 
1050 {
1051  // This has no effect on rendering, it just helps users to diagnose the scene graph.
1052  // --------------------------------------------------------------------------------
1053 
1056  else if (m_tobj_grouping_node)
1057  return m_tobj_grouping_node;
1058  else if (m_terrn2_grouping_node)
1059  return m_terrn2_grouping_node;
1060  else
1061  return App::GetGfxScene()->GetSceneManager()->getRootSceneNode();
1062 }
RoR::TObj::SpecialObject::BOAT
@ BOAT
ROR_ASSERT
#define ROR_ASSERT(_EXPR)
Definition: Application.h:40
GameContext.h
Game state manager and message-queue provider.
RoR::ODefSpotlight::range
float range
Definition: ODefFileFormat.h:104
RoR::ProceduralManager::addObject
void addObject(ProceduralObjectPtr po)
Generates road mesh and adds to internal list.
Definition: ProceduralManager.cpp:174
RoR::TerrainObjectManager::EditorObject::rotation
Ogre::Vector3 rotation
Definition: TerrainObjectManager.h:60
RoR::TObj::SpecialObject::MACHINE
@ MACHINE
RoR::ODefFile::mode_standard
bool mode_standard
Definition: ODefFileFormat.h:127
RoR::App::GetSoundScriptManager
SoundScriptManager * GetSoundScriptManager()
Definition: Application.cpp:277
RoR::SoundScriptInstance::start
void start()
Definition: SoundScriptManager.cpp:1386
RoR::TerrainObjectManager::localizer_t::type
LocalizerType type
Definition: TerrainObjectManager.h:97
RoR::ODefTexPrint::option
char option
Definition: ODefFileFormat.h:94
RoR::ActorSpawnRequest::asr_free_position
bool asr_free_position
Disables the automatic spawn position adjustment.
Definition: SimData.h:863
RoR::ODefAnimation::name
std::string name
Definition: ODefFileFormat.h:85
y
float y
Definition: (ValueTypes) quaternion.h:6
RoR::ODefTexPrint::y
float y
Definition: ODefFileFormat.h:96
RoR::TerrainObjectManager::UpdateAnimatedObjects
bool UpdateAnimatedObjects(float dt)
Definition: TerrainObjectManager.cpp:956
RoR::TObjGrass::density
float density
Definition: TObjFileFormat.h:114
RoR::TerrainObjectManager::PredefinedActor::freePosition
bool freePosition
Definition: TerrainObjectManager.h:135
RoR::ODefTexPrint
Definition: ODefFileFormat.h:88
RoR::TObjVehicle::type
TObj::SpecialObject type
Definition: TObjFileFormat.h:130
RoR::TerrainObjectManager::localizer_t::position
Ogre::Vector3 position
Definition: TerrainObjectManager.h:98
RoR::Terrain::getPagedDetailFactor
float getPagedDetailFactor() const
Definition: Terrain.h:67
RoR::ODefSpotlight::dir
Ogre::Vector3 dir
Definition: ODefFileFormat.h:103
RoR::TerrainObjectManager::StaticObject::sceneNode
Ogre::SceneNode * sceneNode
Definition: TerrainObjectManager.h:140
RoR::ODefParser::ProcessOgreStream
void ProcessOgreStream(Ogre::DataStream *stream)
Definition: ODefFileFormat.cpp:30
RoR::MpState::CONNECTED
@ CONNECTED
RoR::TObjGrass::min_y
float min_y
Definition: TObjFileFormat.h:116
RoR::TObjParser
Definition: TObjFileFormat.h:171
RoR::Console::CONSOLE_MSGTYPE_TERRN
@ CONSOLE_MSGTYPE_TERRN
Parsing/spawn/simulation messages for terrain.
Definition: Console.h:64
RoR::TObjGrass::range
int range
Definition: TObjFileFormat.h:108
RoR::Str::GetBuffer
char * GetBuffer()
Definition: Str.h:48
RoR::TerrainObjectManager::LoadTelepoints
void LoadTelepoints()
Definition: TerrainObjectManager.cpp:974
RoR::ODefFile::texture_prints
std::list< ODefTexPrint > texture_prints
Section 'drawTextOnMeshTexture'.
Definition: ODefFileFormat.h:135
RoR::App::GetCameraManager
CameraManager * GetCameraManager()
Definition: Application.cpp:275
RoR::ActorSpawnRequest::asr_origin
Origin asr_origin
Definition: SimData.h:857
RoR::TObjGrass::max_y
float max_y
Definition: TObjFileFormat.h:117
RoR::ODefParser::Finalize
std::shared_ptr< ODefFile > Finalize()
Passes ownership.
Definition: ODefFileFormat.cpp:61
RoR::Collisions::addCollisionBox
int addCollisionBox(bool rotating, bool virt, Ogre::Vector3 pos, Ogre::Vector3 rot, Ogre::Vector3 l, Ogre::Vector3 h, Ogre::Vector3 sr, const Ogre::String &eventname, const Ogre::String &instancename, bool forcecam, Ogre::Vector3 campos, Ogre::Vector3 sc=Ogre::Vector3::UNIT_SCALE, Ogre::Vector3 dr=Ogre::Vector3::ZERO, CollisionEventFilter event_filter=EVENT_ALL, int scripthandler=-1)
Definition: Collisions.cpp:401
RoR::SoundScriptInstance::ACTOR_ID_TERRAIN_OBJECT
static const int ACTOR_ID_TERRAIN_OBJECT
Definition: SoundScriptManager.h:270
RoR::TObjVehicle::rotation
Ogre::Quaternion rotation
Definition: TObjFileFormat.h:128
RoR::ODefTexPrint::r
float r
Definition: ODefFileFormat.h:97
RoR::TerrainObjectManager::m_map_entities
SurveyMapEntityVec m_map_entities
Definition: TerrainObjectManager.h:165
z
float z
Definition: (ValueTypes) quaternion.h:7
RoR::TerrainObjectManager::PredefinedActor::ismachine
bool ismachine
Definition: TerrainObjectManager.h:134
RoR::TObjGrass::sway_distrib
float sway_distrib
Definition: TObjFileFormat.h:113
RoR::TObjParser::Prepare
void Prepare()
Definition: TObjFileFormat.cpp:58
RoR::TerrainObjectManager::LoadTObjFile
void LoadTObjFile(Ogre::String filename)
Definition: TerrainObjectManager.cpp:149
MeshObject::getEntity
Ogre::Entity * getEntity()
Definition: MeshObject.h:43
RoR::TerrainObjectManager::EditorObject::name
Ogre::String name
Definition: TerrainObjectManager.h:56
RoR::TObjTree::yaw_to
float yaw_to
Definition: TObjFileFormat.h:76
RoR::Terrain::getTerrainFileResourceGroup
std::string getTerrainFileResourceGroup()
Definition: Terrain.cpp:555
format
Truck file format(technical spec)
RoR::ODefCollisionBox::cam_pos
Ogre::Vector3 cam_pos
Definition: ODefFileFormat.h:51
RoR::TObj::SpecialObject::TRUCK2
@ TRUCK2
RoR::Terrain::getObjectManager
TerrainObjectManager * getObjectManager()
Definition: Terrain.h:77
RoR::TObjGrass::min_x
float min_x
Definition: TObjFileFormat.h:116
AutoPilot.h
RoR::ODefCollisionBox::is_virtual
bool is_virtual
Definition: ODefFileFormat.h:59
GenerateGridAndPutToScene
void GenerateGridAndPutToScene(Ogre::Vector3 position)
Definition: TerrainObjectManager.cpp:95
RoR::ODefTexPrint::a
float a
Definition: ODefFileFormat.h:97
RoR::TerrainObjectManager::m_editor_objects
std::vector< EditorObject > m_editor_objects
Definition: TerrainObjectManager.h:161
ExtinguishableFireAffector.h
RoR::HandleGenericException
void HandleGenericException(const std::string &from, BitMask_t flags)
Definition: Application.cpp:369
RoR::TerrainObjectManager::EditorObject
Definition: TerrainObjectManager.h:54
TerrainGeometryManager.h
RoR::TObjEntry::rendering_distance
float rendering_distance
Definition: TObjFileFormat.h:150
RoR::CVar::getBool
bool getBool() const
Definition: CVar.h:98
TObjFileFormat.h
Parser and data structures for TOBJ (Terrain Objects) file format.
RoR::ODefParticleSys::template_name
std::string template_name
Definition: ODefFileFormat.h:77
RoR::TObjEntry::instance_name
char instance_name[TObj::STR_LEN]
Definition: TObjFileFormat.h:148
RoR::ODefPointLight
Definition: ODefFileFormat.h:110
RoR::Terrain::GetDef
Terrn2Def & GetDef()
Definition: Terrain.h:63
MeshObject.h
RoR::TerrainObjectManager::terrainManager
Terrain * terrainManager
Definition: TerrainObjectManager.h:166
Console.h
RoR::TerrainObjectManager::ProcessODefCollisionBoxes
void ProcessODefCollisionBoxes(StaticObject *obj, ODefFile *odef, const EditorObject &params, bool race_event)
Definition: TerrainObjectManager.cpp:1016
RoR::Console::putMessage
void putMessage(MessageArea area, MessageType type, std::string const &msg, std::string icon="")
Definition: Console.cpp:97
RoR::TerrainObjectManager::getGroupingSceneNode
Ogre::SceneNode * getGroupingSceneNode()
Definition: TerrainObjectManager.cpp:1049
RoR::CacheEntry::resource_group
Ogre::String resource_group
Resource group of the loaded bundle. Empty if not loaded yet.
Definition: CacheSystem.h:89
RoR::Collisions::addCollisionMesh
void addCollisionMesh(Ogre::String const &srcname, Ogre::String const &meshname, Ogre::Vector3 const &pos, Ogre::Quaternion const &q, Ogre::Vector3 const &scale, ground_model_t *gm=0, std::vector< int > *collTris=0)
generate collision tris from existing mesh resource
Definition: Collisions.cpp:1408
RoR::ODefTexPrint::x
float x
Definition: ODefFileFormat.h:96
RoR::ODefCollisionBox::scale
Ogre::Vector3 scale
Definition: ODefFileFormat.h:53
RoR::ODefTexPrint::font_dpi
int font_dpi
Definition: ODefFileFormat.h:92
RoR::ODefCollisionBox::is_rotating
bool is_rotating
Definition: ODefFileFormat.h:58
RoR::TObjTree::min_distance
float min_distance
Definition: TObjFileFormat.h:78
RoR::ScriptEngine::loadScript
ScriptUnitId_t loadScript(Ogre::String scriptname, ScriptCategory category=ScriptCategory::TERRAIN, ActorPtr associatedActor=nullptr, std::string buffer="")
Loads a script.
Definition: ScriptEngine.cpp:759
RoR::TerrainObjectManager::LoadTerrainObject
bool LoadTerrainObject(const Ogre::String &name, const Ogre::Vector3 &pos, const Ogre::Vector3 &rot, const Ogre::String &instancename, const Ogre::String &type, float rendering_distance=0, bool enable_collisions=true, int scripthandler=-1, bool uniquifyMaterial=false)
Definition: TerrainObjectManager.cpp:571
RoR::TObjEntry::odef_name
char odef_name[TObj::STR_LEN]
Definition: TObjFileFormat.h:149
RoR::TerrainObjectManager::AnimatedObject
Definition: TerrainObjectManager.h:119
Utils.h
RoR::TerrainObjectManager::LoadTerrainScript
bool LoadTerrainScript(const Ogre::String &filename)
Definition: TerrainObjectManager.cpp:945
RoR::ActorSpawnRequest::asr_filename
std::string asr_filename
Can be in "Bundle-qualified" format, i.e. "mybundle.zip:myactor.truck".
Definition: SimData.h:849
RoR::ODefCollisionMesh::groundmodel_name
std::string groundmodel_name
Definition: ODefFileFormat.h:71
RoR::TerrainObjectManager::m_mesh_objects
std::vector< MeshObject * > m_mesh_objects
Definition: TerrainObjectManager.h:164
RoR::ODefFile::collision_boxes
std::list< ODefCollisionBox > collision_boxes
Definition: ODefFileFormat.h:131
Language.h
RoR::ODefCollisionBox::aabb_max
Ogre::Vector3 aabb_max
Definition: ODefFileFormat.h:49
RoR::TerrainObjectManager::EditorObject::enable_collisions
bool enable_collisions
Definition: TerrainObjectManager.h:64
RoR::TObjGrass::material_name
char material_name[TObj::STR_LEN]
Definition: TObjFileFormat.h:119
TerrainObjectManager.h
RefCountingObjectPtr< ProceduralObject >
RoR::TerrainObjectManager::LoadPredefinedActors
void LoadPredefinedActors()
Definition: TerrainObjectManager.cpp:982
RoR::Console::CONSOLE_SYSTEM_ERROR
@ CONSOLE_SYSTEM_ERROR
Definition: Console.h:52
RoR::TerrainObjectManager::localizer_t::rotation
Ogre::Quaternion rotation
Definition: TerrainObjectManager.h:99
GUIManager.h
RoR::Collisions::removeCollisionTri
void removeCollisionTri(int number)
Definition: Collisions.cpp:356
RoR::Terrn2Telepoint
< Teleport drop location
Definition: Terrn2FileFormat.h:42
RoR::ODefFile::header
struct RoR::ODefFile::ODefFileHeader header
Actor.h
RoR::TerrainObjectManager::MoveObjectVisuals
void MoveObjectVisuals(const Ogre::String &instancename, const Ogre::Vector3 &pos)
Definition: TerrainObjectManager.cpp:483
RoR::ProceduralManager
Definition: ProceduralManager.h:79
RoR::App::GetScriptEngine
ScriptEngine * GetScriptEngine()
Definition: Application.cpp:279
RoR::TerrainObjectManager::FetchODef
RoR::ODefFile * FetchODef(std::string const &odef_name)
Definition: TerrainObjectManager.cpp:529
RoR::GfxScene::GetSceneManager
Ogre::SceneManager * GetSceneManager()
Definition: GfxScene.h:64
w
float w
Definition: (ValueTypes) quaternion.h:4
RoR::TerrainObjectManager::EditorObject::instance_name
Ogre::String instance_name
Definition: TerrainObjectManager.h:57
RoR::ActorSpawnRequest
Definition: SimData.h:832
RoR::TObjGrass::max_h
float max_h
Definition: TObjFileFormat.h:117
RoR::TerrainObjectManager::AnimatedObject::ent
Ogre::Entity * ent
Definition: TerrainObjectManager.h:121
RoR::ODefParticleSys::instance_name
std::string instance_name
Definition: ODefFileFormat.h:76
RoR::Terrain::GetHeightAt
float GetHeightAt(float x, float z)
Definition: Terrain.cpp:503
RoR::App::mp_state
CVar * mp_state
Definition: Application.cpp:115
RoR::TObjTree::density_map
char density_map[TObj::STR_LEN]
Definition: TObjFileFormat.h:84
RoR::TObjEntry
Definition: TObjFileFormat.h:134
RoR::SCRIPTUNITID_INVALID
static const ScriptUnitId_t SCRIPTUNITID_INVALID
Definition: ForwardDeclarations.h:41
RoR::Collisions::loadGroundModelsConfigFile
int loadGroundModelsConfigFile(Ogre::String filename)
Definition: Collisions.cpp:150
ProceduralRoad.h
TOSTRING
#define TOSTRING(x)
Definition: Application.h:56
RoR::TObjGrass::sway_length
float sway_length
Definition: TObjFileFormat.h:112
RoR::PATH_SLASH
char PATH_SLASH
Definition: PlatformUtils.cpp:161
RoR::TObjEntry::rotation
Ogre::Vector3 rotation
Definition: TObjFileFormat.h:145
RoR::TerrainObjectManager::m_entity_counter
int m_entity_counter
Definition: TerrainObjectManager.h:168
RoR::ODefTexPrint::g
float g
Definition: ODefFileFormat.h:97
RoR::TerrainGeometryManager::getMaxTerrainSize
Ogre::Vector3 getMaxTerrainSize()
Definition: TerrainGeometryManager.cpp:689
RoR::TerrainObjectManager::StaticObject::instanceName
Ogre::String instanceName
Definition: TerrainObjectManager.h:141
RoR::ODefCollisionMesh
Definition: ODefFileFormat.h:63
RoR::ODefFile::groundmodel_files
std::list< std::string > groundmodel_files
Definition: ODefFileFormat.h:130
RoR::Str
Wrapper for classic c-string (local buffer) Refresher: strlen() excludes '\0' terminator; strncat() A...
Definition: Str.h:35
RoR::Collisions::removeCollisionBox
void removeCollisionBox(int number)
Definition: Collisions.cpp:343
RoR::Collisions::getGroundModelByString
ground_model_t * getGroundModelByString(const Ogre::String name)
Definition: Collisions.cpp:365
RoR::ODefSpotlight::angle_outer
float angle_outer
Degrees.
Definition: ODefFileFormat.h:106
RoR::TerrainObjectManager::ProcessGrass
void ProcessGrass(float SwaySpeed, float SwayLength, float SwayDistribution, float Density, float minx, float miny, float minH, float maxx, float maxy, float maxH, char *grassmat, char *colorMapFilename, char *densityMapFilename, int growtechnique, int techn, int range, int mapsizex, int mapsizez)
Definition: TerrainObjectManager.cpp:410
GUI_LoadingWindow.h
CacheSystem.h
A database of user-installed content alias 'mods' (vehicles, terrains...)
RoR::TObjGrass::technique
int technique
Definition: TObjFileFormat.h:109
ErrorUtils.h
RoR::GfxVegetation::NONE
@ NONE
ScriptEngine.h
RoR::TerrainObjectManager::AnimatedObject::node
Ogre::SceneNode * node
Definition: TerrainObjectManager.h:122
RoR::TObjGrass::density_map_filename
char density_map_filename[TObj::STR_LEN]
Definition: TObjFileFormat.h:121
RoR::TerrainObjectManager::m_terrn2_grouping_node
Ogre::SceneNode * m_terrn2_grouping_node
For a readable scene graph (via inspector script)
Definition: TerrainObjectManager.h:169
RoR::GameContext::PushMessage
void PushMessage(Message m)
Doesn't guarantee order! Use ChainMessage() if order matters.
Definition: GameContext.cpp:65
strnlen
#define strnlen(str, len)
Definition: InputEngine.cpp:397
RoR::App::app_state
CVar * app_state
Definition: Application.cpp:79
RoR::Terrain::getGeometryManager
TerrainGeometryManager * getGeometryManager()
Definition: Terrain.h:75
RoR::ScriptUnitId_t
int ScriptUnitId_t
Unique sequentially generated ID of a loaded and running scriptin session. Use ScriptEngine::getScrip...
Definition: ForwardDeclarations.h:40
RoR::ODefFile::collision_meshes
std::list< ODefCollisionMesh > collision_meshes
Definition: ODefFileFormat.h:132
RoR::ODefFile::animations
std::list< ODefAnimation > animations
Definition: ODefFileFormat.h:134
RoR::Str::ToCStr
const char * ToCStr() const
Definition: Str.h:46
ODefFileFormat.h
RoR::Terrain::GetCollisions
Collisions * GetCollisions()
Definition: Terrain.h:83
RoR::App::sys_cache_dir
CVar * sys_cache_dir
Definition: Application.cpp:165
RoR::ODefParticleSys
Definition: ODefFileFormat.h:74
GfxScene.h
RoR::TerrainObjectManager::m_predefined_actors
std::vector< PredefinedActor > m_predefined_actors
Definition: TerrainObjectManager.h:162
PlatformUtils.h
Platform-specific utilities. We use narrow UTF-8 encoded strings as paths. Inspired by http://utf8eve...
RoR::ODefFile::ODefFileHeader::scale
Ogre::Vector3 scale
Definition: ODefFileFormat.h:123
RoR::TerrainObjectManager::StaticObject::collTris
std::vector< int > collTris
Definition: TerrainObjectManager.h:144
RoR::SoundScriptManager::createInstance
SoundScriptInstancePtr createInstance(Ogre::String templatename, int actor_id, int soundLinkType=SL_DEFAULT, int soundLinkItemId=-1)
Definition: SoundScriptManager.cpp:356
RoR::App::sim_races_enabled
CVar * sim_races_enabled
Definition: Application.cpp:105
MeshObject
Definition: MeshObject.h:35
RoR::TObjVehicle::position
Ogre::Vector3 position
Definition: TObjFileFormat.h:127
Application.h
Central state/object manager and communications hub.
RoR::TerrainObjectManager::m_procedural_manager
ProceduralManagerPtr m_procedural_manager
Definition: TerrainObjectManager.h:167
RoR::App::GetConsole
Console * GetConsole()
Definition: Application.cpp:270
RoR::TerrainObjectManager::m_animated_objects
std::vector< AnimatedObject > m_animated_objects
Definition: TerrainObjectManager.h:163
RoR::TerrainObjectManager::PredefinedActor::py
float py
Definition: TerrainObjectManager.h:130
RoR::Terrn2Def::telepoints
std::list< Terrn2Telepoint > telepoints
Definition: Terrn2FileFormat.h:67
SoundScriptManager.h
RoR::App::GetGameContext
GameContext * GetGameContext()
Definition: Application.cpp:280
RoR::ODefCollisionBox::box_rot
Ogre::Vector3 box_rot
Definition: ODefFileFormat.h:50
RoR::AppState::SIMULATION
@ SIMULATION
RoR::ODefCollisionBox::force_cam_pos
bool force_cam_pos
Definition: ODefFileFormat.h:60
RoR::TerrainObjectManager::PredefinedActor::name
std::string name
Definition: TerrainObjectManager.h:133
RoR::TObjTree::tree_mesh
char tree_mesh[TObj::STR_LEN]
Definition: TObjFileFormat.h:82
RoR::ActorSpawnRequest::Origin::TERRN_DEF
@ TERRN_DEF
Preloaded with terrain.
getTerrainHeight
float getTerrainHeight(Real x, Real z, void *unused=0)
Definition: TerrainObjectManager.cpp:62
RoR::ActorSpawnRequest::asr_terrn_machine
bool asr_terrn_machine
This is a fixed machinery.
Definition: SimData.h:865
RoR::TObjGrass::sway_speed
float sway_speed
Definition: TObjFileFormat.h:111
RoR::ODefFile::spotlights
std::list< ODefSpotlight > spotlights
Definition: ODefFileFormat.h:136
RoR::TObjEntry::type
char type[TObj::STR_LEN]
Definition: TObjFileFormat.h:147
RoR::TerrainObjectManager::AnimatedObject::anim
Ogre::AnimationState * anim
Definition: TerrainObjectManager.h:123
RoR::ODefPointLight::pos
Ogre::Vector3 pos
Definition: ODefFileFormat.h:112
Ogre::ExtinguishableFireAffector
This class defines a ParticleAffector which deflects particles.
Definition: ExtinguishableFireAffector.h:45
RoR::TerrainObjectManager::localizers
std::vector< localizer_t > localizers
Definition: TerrainObjectManager.h:158
RoR::TObjTree::scale_from
float scale_from
Definition: TObjFileFormat.h:77
RoR::ODefFile::point_lights
std::list< ODefPointLight > point_lights
Definition: ODefFileFormat.h:137
RoR::TObjTree::max_distance
float max_distance
Definition: TObjFileFormat.h:78
RoR::ODefPointLight::dir
Ogre::Vector3 dir
Definition: ODefFileFormat.h:113
RoR::ODefPointLight::range
float range
Definition: ODefFileFormat.h:114
RoR::Terrain
Definition: Terrain.h:40
RoR::ODefCollisionBox
Definition: ODefFileFormat.h:37
RoR::ODefTexPrint::font_name
std::string font_name
Definition: ODefFileFormat.h:90
RoR::TObjParser::ProcessOgreStream
void ProcessOgreStream(Ogre::DataStream *stream)
Definition: TObjFileFormat.cpp:203
RoR::TObjTree::grid_spacing
float grid_spacing
Definition: TObjFileFormat.h:80
RoR::TerrainObjectManager::m_static_objects
std::map< std::string, StaticObject > m_static_objects
Definition: TerrainObjectManager.h:160
RoR::ODefSpotlight::color
Ogre::ColourValue color
Definition: ODefFileFormat.h:107
RoR::ODefSpotlight::pos
Ogre::Vector3 pos
Definition: ODefFileFormat.h:102
WriteToTexture
void WriteToTexture(const String &str, TexturePtr destTexture, Ogre::Box destRectangle, Ogre::Font *Reffont, const ColourValue &color, int fontSize, int fontDPI, char justify, bool wordwrap)
Definition: WriteTextToTexture.cpp:52
RoR::TerrainObjectManager::UpdateTerrainObjects
bool UpdateTerrainObjects(float dt)
Definition: TerrainObjectManager.cpp:1003
RoR::TerrainObjectManager::ProcessTree
void ProcessTree(float yawfrom, float yawto, float scalefrom, float scaleto, char *ColorMap, char *DensityMap, char *treemesh, char *treeCollmesh, float gridspacing, float highdens, int minDist, int maxDist, int mapsizex, int mapsizez)
Definition: TerrainObjectManager.cpp:285
RoR::TerrainObjectManager::PredefinedActor::pz
float pz
Definition: TerrainObjectManager.h:131
RoR::ODefCollisionBox::direction
Ogre::Vector3 direction
Definition: ODefFileFormat.h:52
RoR::Message
Unified game event system - all requests and state changes are reported using a message.
Definition: GameContext.h:51
RoR::TerrainObjectManager::PredefinedActor
Definition: TerrainObjectManager.h:127
RoR::TerrainObjectManager::PredefinedActor::px
float px
Definition: TerrainObjectManager.h:129
_L
#define _L
Definition: ErrorUtils.cpp:34
RoR::ODefPointLight::color
Ogre::ColourValue color
Definition: ODefFileFormat.h:115
RoR::TObjGrass::color_map_filename
char color_map_filename[TObj::STR_LEN]
Definition: TObjFileFormat.h:120
RoR::TObjTree::high_density
float high_density
Definition: TObjFileFormat.h:79
RoR::ODefParser::Prepare
void Prepare()
Definition: ODefFileFormat.cpp:53
RoR::ODefFile::particle_systems
std::list< ODefParticleSys > particle_systems
Definition: ODefFileFormat.h:133
RoR::TObjVehicle::name
char name[TObj::STR_LEN]
Definition: TObjFileFormat.h:129
RoR::TerrainObjectManager::m_odef_cache
std::unordered_map< std::string, std::shared_ptr< RoR::ODefFile > > m_odef_cache
Definition: TerrainObjectManager.h:159
RoR::TObjGrass::max_x
float max_x
Definition: TObjFileFormat.h:117
RoR::ODefTexPrint::b
float b
Definition: ODefFileFormat.h:97
RoR::ODefAnimation::speed_min
float speed_min
Definition: ODefFileFormat.h:84
RoR::Terrain::getCacheEntry
CacheEntryPtr getCacheEntry()
Definition: Terrain.cpp:575
RoR::TObjGrass
Unified 'grass' and 'grass2'.
Definition: TObjFileFormat.h:90
RoR::MSG_SIM_SPAWN_ACTOR_REQUESTED
@ MSG_SIM_SPAWN_ACTOR_REQUESTED
Payload = RoR::ActorSpawnRequest* (owner)
Definition: Application.h:119
RoR::LocalizerType
LocalizerType
Definition: SimData.h:251
RoR::TerrainObjectManager::~TerrainObjectManager
~TerrainObjectManager()
Definition: TerrainObjectManager.cpp:75
RoR::ODefCollisionMesh::scale
Ogre::Vector3 scale
Definition: ODefFileFormat.h:70
RoR::TObjGrass::grow_techniq
int grow_techniq
Definition: TObjFileFormat.h:110
RoR::ProceduralManager::logDiagnostics
void logDiagnostics()
Definition: ProceduralManager.cpp:180
RoR::TerrainObjectManager::unloadObject
void unloadObject(const Ogre::String &instancename)
Definition: TerrainObjectManager.cpp:499
RoR::TObjTree::color_map
char color_map[TObj::STR_LEN]
Definition: TObjFileFormat.h:83
RoR::TObjTree
Definition: TObjFileFormat.h:61
RoR::ODefCollisionBox::aabb_min
Ogre::Vector3 aabb_min
Definition: ODefFileFormat.h:48
RoR::ODefFile::mat_name_generate
std::string mat_name_generate
Section 'generateMaterialShaders'.
Definition: ODefFileFormat.h:139
RoR::TerrainObjectManager::localizer_t
Definition: TerrainObjectManager.h:95
Terrain.h
RoR::ODefCollisionMesh::mesh_name
std::string mesh_name
Definition: ODefFileFormat.h:69
RoR::ProceduralObject::name
std::string name
Definition: ProceduralManager.h:73
Ogre
Definition: ExtinguishableFireAffector.cpp:35
WriteTextToTexture.h
RoR::TObjTree::scale_to
float scale_to
Definition: TObjFileFormat.h:77
RoR::TerrainObjectManager::m_angelscript_grouping_node
Ogre::SceneNode * m_angelscript_grouping_node
For even more readable scene graph (via inspector script)
Definition: TerrainObjectManager.h:171
RoR::Console::CONSOLE_SYSTEM_WARNING
@ CONSOLE_SYSTEM_WARNING
Definition: Console.h:53
RoR::ODefTexPrint::font_size
int font_size
Definition: ODefFileFormat.h:91
RoR::TObjEntry::position
Ogre::Vector3 position
Definition: TObjFileFormat.h:144
RoR::TObjParser::Finalize
std::shared_ptr< TObjFile > Finalize()
Passes ownership.
Definition: TObjFileFormat.cpp:185
RoR::ODefParser
Definition: ODefFileFormat.h:143
RoR::ODefAnimation::speed_max
float speed_max
Definition: ODefFileFormat.h:84
RoR::ODefFile::ODefFileHeader::mesh_name
std::string mesh_name
Definition: ODefFileFormat.h:122
RoR::TerrainObjectManager::EditorObject::position
Ogre::Vector3 position
Definition: TerrainObjectManager.h:59
RoR::App::gfx_vegetation_mode
CVar * gfx_vegetation_mode
Definition: Application.cpp:223
RoR::ODefFile
Definition: ODefFileFormat.h:118
RoR::TObjVehicle
Definition: TObjFileFormat.h:125
RoR::ActorSpawnRequest::asr_position
Ogre::Vector3 asr_position
Definition: SimData.h:851
RoR::ODefTexPrint::w
float w
Definition: ODefFileFormat.h:96
RoR::TerrainObjectManager::StaticObject::collBoxes
std::vector< int > collBoxes
Definition: TerrainObjectManager.h:143
Collisions.h
RoR::App::diag_terrn_log_roads
CVar * diag_terrn_log_roads
Definition: Application.cpp:157
RoR::TerrainObjectManager::EditorObject::script_handler
int script_handler
Definition: TerrainObjectManager.h:65
RoR::TerrainObjectManager::StaticObject
Definition: TerrainObjectManager.h:138
RoR::DEPTHMAP_DISABLED
@ DEPTHMAP_DISABLED
Definition: Application.h:285
RoR::Terrn2Def::name
std::string name
Definition: Terrn2FileFormat.h:52
RoR::TerrainObjectManager::PredefinedActor::rotation
Ogre::Quaternion rotation
Definition: TerrainObjectManager.h:132
RoR::SurveyMapEntity
Definition: SurveyMapEntity.h:35
RoR::TObjGrass::min_h
float min_h
Definition: TObjFileFormat.h:116
RoR::ODefFile::sounds
std::list< std::string > sounds
Definition: ODefFileFormat.h:129
RoR::ODefTexPrint::text
std::string text
Definition: ODefFileFormat.h:93
RoR::TerrainObjectManager::AnimatedObject::speedfactor
float speedfactor
Definition: TerrainObjectManager.h:124
RoR::ODefFile::localizers
std::vector< LocalizerType > localizers
Definition: ODefFileFormat.h:128
RoR::ODefFile::ODefFileHeader::cast_shadows
bool cast_shadows
Definition: ODefFileFormat.h:124
Forests
Definition: RandomTreeLoader.h:32
RoR::ActorSpawnRequest::asr_rotation
Ogre::Quaternion asr_rotation
Definition: SimData.h:852
RoR
Definition: AppContext.h:36
RoR::ODefFile::mat_name
std::string mat_name
Section 'setMeshMaterial'.
Definition: ODefFileFormat.h:138
RoR::Str::Clear
Str & Clear()
Definition: Str.h:54
RoR::TerrainObjectManager::m_tobj_grouping_node
Ogre::SceneNode * m_tobj_grouping_node
For even more readable scene graph (via inspector script)
Definition: TerrainObjectManager.h:170
x
float x
Definition: (ValueTypes) quaternion.h:5
RoR::SoundScriptInstance::setPosition
void setPosition(Ogre::Vector3 pos)
Definition: SoundScriptManager.cpp:1310
RoR::ODefAnimation
Definition: ODefFileFormat.h:82
RoR::App::GetGfxScene
GfxScene * GetGfxScene()
Definition: Application.cpp:276
RoR::TerrainObjectManager::StaticObject::enabled
bool enabled
Definition: TerrainObjectManager.h:142
RoR::ODefSpotlight
Definition: ODefFileFormat.h:100
RoR::Terrain::getWater
IWater * getWater()
Definition: Terrain.h:84
RoR::ODefCollisionBox::event_name
std::string event_name
Definition: ODefFileFormat.h:54
RoR::ODefCollisionBox::event_filter
CollisionEventFilter event_filter
Definition: ODefFileFormat.h:55
RoR::TObjTree::collision_mesh
char collision_mesh[TObj::STR_LEN]
Definition: TObjFileFormat.h:85
RoR::TObjTree::yaw_from
float yaw_from
Definition: TObjFileFormat.h:76
RoR::ODefTexPrint::h
float h
Definition: ODefFileFormat.h:96
RoR::GameContext::GetTerrain
const TerrainPtr & GetTerrain()
Definition: GameContext.h:117
RoR::ODefSpotlight::angle_inner
float angle_inner
Degrees.
Definition: ODefFileFormat.h:105