Rigs of Rods 2026.01
Soft-body Physics Simulation
Loading...
Searching...
No Matches
TObjFileFormat.h
Go to the documentation of this file.
1/*
2 This source file is part of Rigs of Rods
3 Copyright 2016-2017 Petr Ohlidal
4
5 For more information, see http://www.rigsofrods.org/
6
7 Rigs of Rods is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 3, as
9 published by the Free Software Foundation.
10
11 Rigs of Rods is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
25
26#include "Collisions.h"
27#include "ForwardDeclarations.h"
28#include "PagedGeometryConfig.h" // enums GrassTechnique, FadeTechnique
29
30#include <Ogre.h>
31
32#include <memory>
33
34namespace RoR {
35
36namespace TObj {
37
38 const int STR_LEN = 300;
39 const int LINE_BUF_LEN = 4000;
40
41 void WriteToStream(TObjDocumentPtr doc, Ogre::DataStreamPtr stream);
42
43} // namespace TObj
44
45// -----------------------------------------------------------------------------
47{
49 yaw_from(0.f), yaw_to(0.f),
50 scale_from(0.f), scale_to(0.f),
51 min_distance(90), max_distance(700),
52 high_density(1.f),
53 grid_spacing(0.f)
54 {
55 tree_mesh [0] = '\0';
56 color_map [0] = '\0';
57 density_map [0] = '\0';
58 collision_mesh[0] = '\0';
59 }
60
66
71
73};
74
75// -----------------------------------------------------------------------------
96
97// -----------------------------------------------------------------------------
99{
100 Ogre::Vector3 position;
101 Ogre::Quaternion rotation;
102 Ogre::Vector3 tobj_rotation;
105 std::string comments;
106};
107
108// -----------------------------------------------------------------------------
110{
112 TObjEntry(
113 Ogre::Vector3 pos, Ogre::Vector3 rot, const char* instance_name,
114 TObjSpecialObject special, const char* type, const char* name);
115
116 bool IsActor() const;
117 bool IsRoad() const;
118
119 Ogre::Vector3 position = Ogre::Vector3::ZERO;
120 Ogre::Vector3 rotation = Ogre::Vector3::ZERO;
122 char type[TObj::STR_LEN] = {};
125 float rendering_distance = 0.f; // 0 means 'always rendered', see https://ogrecave.github.io/ogre/api/1.11/class_ogre_1_1_movable_object.html#afe1f2a1009e3f14f36e1bcc9b1b9557e
126 std::string comments;
127};
128
129// -----------------------------------------------------------------------------
131{
134 grid_enabled(false)
135 {}
136
137 std::string document_name;
138 Ogre::Vector3 grid_position;
141 std::vector<TObjTree> trees;
142 std::vector<TObjGrass> grass;
143 std::vector<TObjVehicle> vehicles;
144 std::vector<TObjEntry> objects;
145 std::vector<ProceduralObjectPtr> proc_objects;
146};
147
148// -----------------------------------------------------------------------------
150{
151public:
152 void Prepare();
153 bool ProcessLine(const char* line);
154 void ProcessOgreStream(Ogre::DataStream* stream);
156
157 static Ogre::Quaternion CalcRotation(Ogre::Vector3 const& rot, bool rot_yxz);
158
159private:
160 // Processing:
161 bool ProcessCurrentLine();
163 void ProcessGridLine();
164 void ProcessTreesLine();
165 void ProcessGrassLine();
166 void ProcessActorObject(const TObjEntry& object);
167 void ProcessRoadObject(const TObjEntry& object);
168
169 // Helpers:
170 void ImportProceduralPoint(Ogre::Vector3 const& pos, Ogre::Vector3 const& rot, TObjSpecialObject special);
171 bool ParseObjectLine(TObjEntry& object);
173
175 std::string m_filename;
177 const char* m_cur_line;
181
182 // Procedural roads
186
187 // Auto-importing legacy road blocks (ODEF) as procedural roads
188 Ogre::Vector3 m_road2_last_pos;
189 Ogre::Vector3 m_road2_last_rot;
191
193};
194
195} // namespace RoR
Global forward declarations.
TObjDocumentPtr Finalize()
Passes ownership.
Ogre::Vector3 m_road2_last_rot
ProceduralObjectPtr m_cur_procedural_obj
bool ProcessLine(const char *line)
float m_default_rendering_distance
std::string m_filename
TObjDocumentPtr m_def
void ProcessRoadObject(const TObjEntry &object)
std::string m_preceding_line_comments
bool ParseObjectLine(TObjEntry &object)
void ProcessActorObject(const TObjEntry &object)
const char * m_cur_line_trimmed
void ImportProceduralPoint(Ogre::Vector3 const &pos, Ogre::Vector3 const &rot, TObjSpecialObject special)
static Ogre::Quaternion CalcRotation(Ogre::Vector3 const &rot, bool rot_yxz)
const char * m_cur_line
int m_cur_procedural_obj_start_line
Ogre::Vector3 m_road2_last_pos
void ProcessOgreStream(Ogre::DataStream *stream)
GrassTechnique
A technique used to render grass.
@ GRASSTECH_CROSSQUADS
Grass constructed of two quads forming a "X" cross shape.
FadeTechnique
A technique used to fade grass into the distance.
@ FADETECH_GROW
Grass that fades in by "growing" up out of the ground. Very effective when grass fades in against the...
const int LINE_BUF_LEN
const int STR_LEN
void WriteToStream(TObjDocumentPtr doc, Ogre::DataStreamPtr stream)
std::shared_ptr< TObjDocument > TObjDocumentPtr
TObjSpecialObject
std::vector< ProceduralObjectPtr > proc_objects
std::string document_name
std::vector< TObjGrass > grass
std::vector< TObjTree > trees
std::vector< TObjEntry > objects
std::vector< TObjVehicle > vehicles
Ogre::Vector3 grid_position
char instance_name[TObj::STR_LEN]
bool IsRoad() const
bool IsActor() const
Ogre::Vector3 rotation
Ogre::Vector3 position
char type[TObj::STR_LEN]
char odef_name[TObj::STR_LEN]
std::string comments
Comment line(s) preceding the object-line in the .TOBJ file.
TObjSpecialObject special
float rendering_distance
TObjEntry()
Unified 'grass' and 'grass2'.
char density_map_filename[TObj::STR_LEN]
char material_name[TObj::STR_LEN]
Forests::GrassTechnique technique
Forests::FadeTechnique fadetech
char color_map_filename[TObj::STR_LEN]
char collision_mesh[TObj::STR_LEN]
char density_map[TObj::STR_LEN]
char tree_mesh[TObj::STR_LEN]
int origin_tobj_line_number
char color_map[TObj::STR_LEN]
Ogre::Quaternion rotation
std::string comments
Comment line(s) preceding the vehicle-line in the .TOBJ file.
Ogre::Vector3 position
Ogre::Vector3 tobj_rotation
Original rotation specified in .TOBJ file.
char name[TObj::STR_LEN]
TObjSpecialObject type