32 #include <OgreStringConverter.h>
40 m_file_path(file_path),
44 m_inertia_function_width(10),
46 m_command_key_width(2),
64 <<
"; ---------------------------------------------------------------------------- ;" << endl
65 <<
"; Rigs of Rods project (www.rigsofrods.org) ;" << endl
66 <<
"; ========================================= ;" << endl
68 <<
"; This is a rig definition file. ;" << endl
69 <<
"; See http://www.rigsofrods.org/wiki/pages/Truck_Description_File for details. ;" << endl
70 <<
"; ---------------------------------------------------------------------------- ;" << endl
168 for (
auto itor = module->
pistonprops.begin(); itor != end_itor; ++itor)
172 m_stream <<
"\n\t" << def.reference_node.ToString()
173 <<
", " << def.axis_node.ToString()
174 <<
", " << def.blade_tip_nodes[0].ToString()
175 <<
", " << def.blade_tip_nodes[1].ToString()
176 <<
", " << def.blade_tip_nodes[2].ToString()
177 <<
", " << def.blade_tip_nodes[3].ToString()
178 <<
", " << (def.couple_node.IsValidAnyState() ? def.couple_node.ToString() :
"-1")
179 <<
", " << def.turbine_power_kW
181 <<
", " << def.airfoil;
194 for (
auto itor = module->
turbojets.begin(); itor != end_itor; ++itor)
198 m_stream <<
"\n\t" << def.front_node.ToString()
199 <<
", " << def.back_node.ToString()
200 <<
", " << def.side_node.ToString()
201 <<
", " << def.is_reversable
202 <<
", " << def.dry_thrust
203 <<
", " << def.wet_thrust
204 <<
", " << def.front_diameter
205 <<
", " << def.back_diameter
206 <<
", " << def.nozzle_length;
219 for (
auto itor = module->
screwprops.begin(); itor != end_itor; ++itor)
223 m_stream <<
"\n\t" << def.prop_node.ToString()
224 <<
", " << def.back_node.ToString()
225 <<
", " << def.top_node.ToString()
226 <<
", " << def.power;
234 m_stream <<
";fusedrag -- STUB" << endl;
247 for (
auto itor = module->
turboprops2.begin(); itor != end_itor; ++itor)
271 for (
auto itor = module->
airbrakes.begin(); itor != end_itor; ++itor)
296 if (module->
wings.empty())
301 auto end_itor = module->
wings.end();
302 for (
auto itor = module->
wings.begin(); itor != end_itor; ++itor)
340 for (
auto itor = module->
soundsources.begin(); itor != end_itor; ++itor)
355 m_stream <<
"soundsources2" << endl;
357 for (
auto itor = module->
soundsources2.begin(); itor != end_itor; ++itor)
379 case ExtCameraMode::NODE:
382 case ExtCameraMode::CINECAM:
385 case ExtCameraMode::CLASSIC:
401 for (
auto itor = module->
videocameras.begin(); itor != end_itor; ++itor)
459 auto end_itor = module->
exhausts.end();
460 for (
auto itor = module->
exhausts.begin(); itor != end_itor; ++itor)
474 m_stream <<
";submesh_groundmodel -- STUB"<< endl << endl;
485 for (
auto itor = module->
submeshes.begin(); itor != end_itor; ++itor)
493 for (
auto texcoord_itor = def.
texcoords.begin(); texcoord_itor != texcoord_end; ++texcoord_itor)
495 m_stream <<
"\n\t" << texcoord_itor->node.ToString() <<
", " << texcoord_itor->u <<
", " << texcoord_itor->v;
502 for (
auto cab_itor = def.
cab_triangles.begin(); cab_itor != cab_end; ++cab_itor)
504 m_stream <<
"\n\t" << cab_itor->nodes[0].ToString()
505 <<
", " << cab_itor->nodes[1].ToString()
506 <<
", " << cab_itor->nodes[2].ToString()
529 #define PROP_ANIMATION_ADD_FLAG(FLAGS_VAR, AND_VAR, BITMASK_CONST, NAME_STR) \
530 if (AND_VAR) { m_stream << " | "; } \
531 if (BITMASK_IS_1((FLAGS_VAR), RigDef::Animation::BITMASK_CONST)) { \
533 m_stream << NAME_STR; \
545 unsigned int src_flags = anim.
source;
581 unsigned int mode_flags = anim.
mode;
607 for (
auto itor = module->
flexbodies.begin(); itor != end_itor; ++itor)
624 m_stream <<
"\n\t\tforset (node list)";
626 auto forset_itor = def->
node_list.begin();
628 for (; forset_itor != forset_end; ++forset_itor)
634 m_stream << forset_itor->ToString();
640 for (
auto anim_itor = def->
animations.begin(); anim_itor != anim_end; ++anim_itor)
650 if (module->
props.empty())
655 auto end_itor = module->
props.end();
656 for (
auto itor = module->
props.begin(); itor != end_itor; ++itor)
696 for (
auto anim_itor = def.
animations.begin(); anim_itor != anim_end; ++anim_itor)
710 m_stream <<
"materialflarebindings" << endl;
727 auto end_itor = module->
flares2.end();
728 for (
auto itor = module->
flares2.begin(); itor != end_itor; ++itor)
737 <<
", " << (char)def.
type
752 m_stream <<
"managedmaterials" << endl;
756 for (
auto itor = module->
managedmaterials.begin(); itor != end_itor; ++itor)
774 m_stream <<
"flexmesh_transparent ";
806 m_stream <<
"collisionboxes" << endl;
808 for (
auto itor = module->
collisionboxes.begin(); itor != end_itor; ++itor)
812 auto nodes_end = def.
nodes.end();
813 auto node_itor = def.
nodes.begin();
816 for (; node_itor != nodes_end; ++node_itor)
818 m_stream <<
", " << node_itor->ToString();
826 if (module->
axles.empty())
831 auto end_itor = module->
axles.end();
832 for (
auto itor = module->
axles.begin(); itor != end_itor; ++itor)
843 for (
auto itor = def.
options.begin(); itor != end; ++itor)
861 for (
auto itor = module->
interaxles.begin(); itor != end_itor; ++itor)
872 for (
auto itor = def.
options.begin(); itor != end; ++itor)
936 if (module->
torquecurve[0].predefined_func_name.empty())
938 auto itor_end = module->
torquecurve[0].samples.end();
939 auto itor = module->
torquecurve[0].samples.begin();
940 for (; itor != itor_end; ++itor)
942 m_stream <<
"\n\t" << itor->power <<
", " << itor->torque_percent;
960 for (
auto itor = module->
particles.begin(); itor != end_itor; ++itor)
979 auto end_itor = module->
ropables.end();
980 for (
auto itor = module->
ropables.begin(); itor != end_itor; ++itor)
993 if (module->
ties.empty())
998 auto end_itor = module->
ties.end();
999 for (
auto itor = module->
ties.begin(); itor != end_itor; ++itor)
1011 <<
", " << def.
group;
1018 if (module->
fixes.empty())
1023 auto end_itor = module->
fixes.end();
1024 for (
auto itor = module->
fixes.begin(); itor != end_itor; ++itor)
1033 if (module->
ropes.empty())
1038 auto end_itor = module->
ropes.end();
1041 for (
auto itor = module->
ropes.begin(); itor != end_itor; ++itor)
1068 m_stream <<
"railgroups" << endl << endl;
1070 for (
auto itor = module->
railgroups.begin(); itor != end_itor; ++itor)
1076 for (
auto node_itor = def.
node_list.begin(); node_itor != node_end; ++node_itor)
1078 m_stream <<
", " << node_itor->start.ToString();
1079 if (node_itor->IsRange())
1081 m_stream <<
" - " << node_itor->end.ToString();
1094 m_stream <<
"slidenodes" << endl << endl;
1096 for (
auto itor = module->
slidenodes.begin(); itor != end_itor; ++itor)
1107 for (; itor != end; ++itor)
1109 m_stream <<
", " << itor->start.ToString();
1110 if (itor->IsRange())
1112 m_stream <<
" - " << itor->end.ToString();
1139 if (module->
hooks.empty())
1143 m_stream <<
"hooks" << endl << endl;
1144 auto end_itor = module->
hooks.end();
1145 for (
auto itor = module->
hooks.begin(); itor != end_itor; ++itor)
1177 m_stream <<
"lockgroups" << endl << endl;
1179 for (
auto itor = module->
lockgroups.begin(); itor != end_itor; ++itor)
1184 auto nodes_end = def.
nodes.end();
1185 for (
auto nodes_itor = def.
nodes.begin(); nodes_itor != nodes_end; ++nodes_itor)
1187 m_stream <<
", " << nodes_itor->ToString();
1199 m_stream <<
"animators" << endl << endl;
1200 auto end_itor = module->
triggers.end();
1201 for (
auto itor = module->
triggers.begin(); itor != end_itor; ++itor)
1230 #define ANIMATOR_ADD_FLAG(DEF_VAR, AND_VAR, BITMASK_CONST, NAME_STR) \
1231 if (AND_VAR) { m_stream << " | "; } \
1232 if (BITMASK_IS_1((DEF_VAR).flags, RigDef::Animator::BITMASK_CONST)) { \
1234 m_stream << NAME_STR; \
1237 #define ANIMATOR_ADD_AERIAL_FLAG(DEF_VAR, AND_VAR, BITMASK_CONST, NAME_STR) \
1238 if (AND_VAR) { m_stream << " | "; } \
1239 if (BITMASK_IS_1((DEF_VAR).aero_animator.flags, RigDef::AeroAnimator::BITMASK_CONST)) { \
1241 m_stream << NAME_STR << DEF_VAR.aero_animator.engine_idx + 1; \
1244 #define ANIMATOR_ADD_LIMIT(DEF_VAR, AND_VAR, BITMASK_CONST, NAME_STR, VALUE) \
1245 if (AND_VAR) { m_stream << " | "; } \
1246 if (BITMASK_IS_1((DEF_VAR).aero_animator.flags, RigDef::Animator::BITMASK_CONST)) { \
1248 m_stream << NAME_STR << ": " << VALUE; \
1257 m_stream <<
"animators" << endl << endl;
1258 auto end_itor = module->
animators.end();
1259 for (
auto itor = module->
animators.begin(); itor != end_itor; ++itor)
1318 m_stream <<
"contacters" << endl << endl;
1319 auto end_itor = module->
rotators.end();
1320 for (
auto itor = module->
rotators.begin(); itor != end_itor; ++itor)
1332 m_stream <<
"rotators" << endl << endl;
1333 auto end_itor = module->
rotators.end();
1334 for (
auto itor = module->
rotators.begin(); itor != end_itor; ++itor)
1344 for (
int i = 0; i < 4; ++i)
1350 for (
int i = 0; i < 4; ++i)
1376 m_stream <<
"rotators2" << endl << endl;
1377 auto end_itor = module->
rotators2.end();
1378 for (
auto itor = module->
rotators2.begin(); itor != end_itor; ++itor)
1388 for (
int i = 0; i < 4; ++i)
1394 for (
int i = 0; i < 4; ++i)
1426 m_stream <<
"flexbodywheels" << endl << endl;
1428 for (
auto itor = module->
flexbodywheels.begin(); itor != end_itor; ++itor)
1434 << setw(3) << itor->num_rays <<
", "
1438 << setw(3) << (int)itor->braking <<
", "
1439 << setw(3) << (int)itor->propulsion <<
", "
1440 << setw(
m_node_id_width) << itor->reference_arm_node.ToString() <<
", "
1444 << (
static_cast<char>(itor->side)) <<
", "
1445 << itor->rim_mesh_name <<
" "
1446 << itor->tyre_mesh_name
1495 if (module->
engine.size() == 0)
1510 " Forward gears...\n\t"
1513 << setw(10) << engine.
torque <<
", "
1520 for (; itor != end; ++itor)
1524 m_stream <<
", -1.0" << endl << endl;
1550 << setw(10) << engoption.
inertia <<
", "
1551 << setw(10) << (char)engoption.
type <<
", "
1556 << setw( 8) << engoption.
stall_rpm <<
", "
1557 << setw( 7) << engoption.
idle_rpm <<
", "
1567 if (module->
help.size() == 0)
1571 m_stream <<
"help\n\t" << module->
help[module->
help.size() - 1].material << endl << endl;
1580 m_stream <<
"wheels2" << endl << endl;
1581 auto end_itor = module->
wheels2.end();
1582 for (
auto itor = module->
wheels2.begin(); itor != end_itor; ++itor)
1588 << setw(3) << itor->num_rays <<
", "
1592 << setw(3) << (int)itor->braking <<
", "
1593 << setw(3) << (int)itor->propulsion <<
", "
1594 << setw(
m_node_id_width) << itor->reference_arm_node.ToString() <<
", "
1600 << itor->face_material_name <<
" "
1601 << itor->band_material_name <<
" "
1611 if (module->
wheels.empty())
1615 m_stream <<
"wheels" << endl << endl;
1616 auto end_itor = module->
wheels.end();
1617 for (
auto itor = module->
wheels.begin(); itor != end_itor; ++itor)
1622 << setw(3) << itor->num_rays <<
", "
1626 << setw(3) << (int)itor->braking <<
", "
1627 << setw(3) << (int)itor->propulsion <<
", "
1628 << setw(
m_node_id_width) << itor->reference_arm_node.ToString() <<
", "
1632 << itor->face_material_name <<
" "
1633 << itor->band_material_name <<
" "
1651 << setw(3) << (int)def.
braking <<
", "
1657 << (
static_cast<char>(def.
side)) <<
", "
1667 m_stream <<
"meshwheels" <<
"\n\n";
1681 m_stream <<
"meshwheels2" <<
"\n\n";
1698 m_stream <<
"cinecam" << endl << endl;
1700 for (
auto itor = module->
cinecam.begin(); itor != module->
cinecam.end(); ++itor)
1725 if (module->
beams.empty())
1731 std::map< BeamDefaults*, std::vector<Beam*> > beams_by_preset;
1732 auto itor_end = module->
beams.end();
1733 for (
auto itor = module->
beams.begin(); itor != itor_end; ++itor)
1735 Beam & beam = *itor;
1739 auto found_itor = beams_by_preset.find(preset);
1740 if (found_itor == beams_by_preset.end())
1743 std::vector<Beam*> list;
1745 list.push_back(&beam);
1746 beams_by_preset.insert(std::make_pair(preset, list));
1751 found_itor->second.push_back(&beam);
1756 m_stream <<
"beams" << endl << endl;
1757 auto preset_itor_end = beams_by_preset.end();
1758 for (
auto preset_itor = beams_by_preset.begin(); preset_itor != preset_itor_end; ++preset_itor)
1765 std::vector<Beam*> & beam_list = preset_itor->second;
1766 auto beam_itor_end = beam_list.end();
1767 for (
auto beam_itor = beam_list.begin(); beam_itor != beam_itor_end; ++beam_itor)
1769 Beam & beam = *(*beam_itor);
1780 if (module->
shocks.empty())
1786 std::map< BeamDefaults*, std::vector<Shock*> > shocks_by_preset;
1787 auto itor_end = module->
shocks.end();
1788 for (
auto itor = module->
shocks.begin(); itor != itor_end; ++itor)
1790 Shock & shock = *itor;
1794 auto found_itor = shocks_by_preset.find(preset);
1795 if (found_itor == shocks_by_preset.end())
1798 std::vector<Shock*> list;
1800 list.push_back(&shock);
1801 shocks_by_preset.insert(std::make_pair(preset, list));
1806 found_itor->second.push_back(&shock);
1811 m_stream <<
"shocks" << endl << endl;
1812 auto preset_itor_end = shocks_by_preset.end();
1813 for (
auto preset_itor = shocks_by_preset.begin(); preset_itor != preset_itor_end; ++preset_itor)
1820 auto shock_list = preset_itor->second;
1821 auto shock_itor_end = shock_list.end();
1822 for (
auto shock_itor = shock_list.begin(); shock_itor != shock_itor_end; ++shock_itor)
1824 Shock & shock = *(*shock_itor);
1841 std::map< BeamDefaults*, std::vector<Shock2*> > shocks_by_preset;
1842 auto itor_end = module->
shocks2.end();
1843 for (
auto itor = module->
shocks2.begin(); itor != itor_end; ++itor)
1849 auto found_itor = shocks_by_preset.find(preset);
1850 if (found_itor == shocks_by_preset.end())
1853 std::vector<Shock2*> list;
1855 list.push_back(&shock);
1856 shocks_by_preset.insert(std::make_pair(preset, list));
1861 found_itor->second.push_back(&shock);
1866 m_stream <<
"shocks2" << endl << endl;
1867 auto preset_itor_end = shocks_by_preset.end();
1868 for (
auto preset_itor = shocks_by_preset.begin(); preset_itor != preset_itor_end; ++preset_itor)
1875 auto shock_list = preset_itor->second;
1876 auto shock_itor_end = shock_list.end();
1877 for (
auto shock_itor = shock_list.begin(); shock_itor != shock_itor_end; ++shock_itor)
1879 Shock2 & shock = *(*shock_itor);
1896 std::map< BeamDefaults*, std::vector<Shock3*> > shocks_by_preset;
1897 auto itor_end = module->
shocks3.end();
1898 for (
auto itor = module->
shocks3.begin(); itor != itor_end; ++itor)
1904 auto found_itor = shocks_by_preset.find(preset);
1905 if (found_itor == shocks_by_preset.end())
1908 std::vector<Shock3*> list;
1910 list.push_back(&shock);
1911 shocks_by_preset.insert(std::make_pair(preset, list));
1916 found_itor->second.push_back(&shock);
1921 m_stream <<
"shocks3" << endl << endl;
1922 auto preset_itor_end = shocks_by_preset.end();
1923 for (
auto preset_itor = shocks_by_preset.begin(); preset_itor != preset_itor_end; ++preset_itor)
1930 auto shock_list = preset_itor->second;
1931 auto shock_itor_end = shock_list.end();
1932 for (
auto shock_itor = shock_list.begin(); shock_itor != shock_itor_end; ++shock_itor)
1934 Shock3 & shock = *(*shock_itor);
1945 if (module->
hydros.empty())
1951 std::map< BeamDefaults*, std::vector<Hydro*> > grouped_by_preset;
1952 auto itor_end = module->
hydros.end();
1953 for (
auto itor = module->
hydros.begin(); itor != itor_end; ++itor)
1955 Hydro & hydro = *itor;
1959 auto found_itor = grouped_by_preset.find(preset);
1960 if (found_itor == grouped_by_preset.end())
1963 std::vector<Hydro*> list;
1965 list.push_back(&hydro);
1966 grouped_by_preset.insert(std::make_pair(preset, list));
1971 found_itor->second.push_back(&hydro);
1976 m_stream <<
"hydros" << endl << endl;
1977 auto preset_itor_end = grouped_by_preset.end();
1978 for (
auto preset_itor = grouped_by_preset.begin(); preset_itor != preset_itor_end; ++preset_itor)
1985 auto hydro_list = preset_itor->second;
1986 auto hydro_itor_end = hydro_list.end();
1987 for (
auto hydro_itor = hydro_list.begin(); hydro_itor != hydro_itor_end; ++hydro_itor)
1989 Hydro & hydro = *(*hydro_itor);
2006 std::map< BeamDefaults*, std::vector<Command2*> > commands_by_preset;
2007 auto itor_end = module->
commands2.end();
2008 for (
auto itor = module->
commands2.begin(); itor != itor_end; ++itor)
2014 auto found_itor = commands_by_preset.find(preset);
2015 if (found_itor == commands_by_preset.end())
2018 std::vector<Command2*> list;
2020 list.push_back(&command);
2021 commands_by_preset.insert(std::make_pair(preset, list));
2026 found_itor->second.push_back(&command);
2031 m_stream <<
"commands" << endl << endl;
2032 auto preset_itor_end = commands_by_preset.end();
2033 for (
auto preset_itor = commands_by_preset.begin(); preset_itor != preset_itor_end; ++preset_itor)
2040 auto command_list = preset_itor->second;
2041 auto command_itor_end = command_list.end();
2042 for (
auto command_itor = command_list.begin(); command_itor != command_itor_end; ++command_itor)
2044 Command2 & command = *(*command_itor);
2268 if (beam_defaults ==
nullptr)
2272 m_stream << prefix <<
"set_beam_defaults "
2283 m_stream << prefix <<
"set_beam_defaults_scale "
2328 if (module->
nodes.empty())
2335 std::map< NodeDefaults*, std::vector<Node*> > nodes_by_presets;
2336 Node* node_zero =
nullptr;
2337 auto itor_end = module->
nodes.end();
2338 for (
auto itor = module->
nodes.begin(); itor != itor_end; ++itor)
2340 Node & node = *itor;
2343 if (node.
id.IsValid() && node.
id.
Str().empty() && node.
id.
Num() == 0)
2345 if (node_zero !=
nullptr)
2347 throw std::runtime_error(
"FATAL: Multiple nodes zero!!!");
2356 auto found_itor = nodes_by_presets.find(preset);
2357 if (found_itor == nodes_by_presets.end())
2360 std::vector<Node*> list;
2362 list.push_back(&node);
2363 nodes_by_presets.insert(std::make_pair(preset, list));
2368 found_itor->second.push_back(&node);
2373 m_stream <<
"nodes" << endl << endl;
2376 if (node_zero ==
nullptr)
2378 throw std::runtime_error(
"FATAL: Node zero not defined!!!");
2384 auto preset_itor_end = nodes_by_presets.end();
2385 for (
auto preset_itor = nodes_by_presets.begin(); preset_itor != preset_itor_end; ++preset_itor)
2392 std::vector<Node*> & node_list = preset_itor->second;
2393 auto node_itor_end = node_list.end();
2394 for (
auto node_itor = node_list.begin(); node_itor != node_itor_end; ++node_itor)
2396 Node & node = *(*node_itor);
2397 if (node.
id.
Str().empty())
2405 m_stream << endl << endl <<
"nodes2" << endl << endl;
2406 for (
auto preset_itor = nodes_by_presets.begin(); preset_itor != preset_itor_end; ++preset_itor)
2413 std::vector<Node*> & node_list = preset_itor->second;
2414 auto node_itor_end = node_list.end();
2415 for (
auto node_itor = node_list.begin(); node_itor != node_itor_end; ++node_itor)
2417 Node & node = *(*node_itor);
2418 if (!node.
id.
Str().empty() && node.
id.
Num() == 0)
2432 if (node_defaults ==
nullptr)
2434 m_stream <<
"-1, -1, -1, -1, n" << endl;
2441 << node_defaults->
volume <<
", "
2442 << node_defaults->
surface <<
", ";
2513 if (
m_rig_def->enable_advanced_deformation)
2515 m_stream <<
"enable_advanced_deformation" << endl << endl;
2519 m_stream <<
"hideInChooser" << endl << endl;
2521 if (
m_rig_def->slide_nodes_connect_instantly)
2523 m_stream <<
"slidenode_connect_instantly" << endl << endl;
2525 if (
m_rig_def->lockgroup_default_nolock)
2527 m_stream <<
"lockgroup_default_nolock" << endl << endl;
2531 m_stream <<
"rollon" << endl << endl;
2535 m_stream <<
"rescuer" << endl << endl;
2539 m_stream <<
"disabledefaultsounds" << endl << endl;
2543 m_stream <<
"forwardcommands" << endl << endl;
2547 m_stream <<
"importcommands" << endl << endl;
2568 if (! module->
guid.empty())
2570 m_stream <<
"guid " << module->
guid[module->
guid.size() - 1].guid << endl << endl;
2581 std::string line = *itor;
2584 m_stream << endl <<
"end_description" << endl << endl;
2590 for (
auto itor = module->
author.begin(); itor != module->
author.end(); ++itor)
2609 if (module->
globals.size() == 0)
2615 << module->
globals[0].dry_mass <<
", "
2616 << module->
globals[0].cargo_mass;
2617 if (!module->
globals[0].material_name.empty())