Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
29#include <Ogre.h>
30
31#include <memory>
32
33namespace RoR {
34
35namespace TObj {
36
37 const int STR_LEN = 300;
38 const int LINE_BUF_LEN = 4000;
39
40 void WriteToStream(TObjDocumentPtr doc, Ogre::DataStreamPtr stream);
41
42} // namespace TObj
43
44// -----------------------------------------------------------------------------
46{
48 yaw_from(0.f), yaw_to(0.f),
49 scale_from(0.f), scale_to(0.f),
50 min_distance(90), max_distance(700),
51 high_density(1.f),
52 grid_spacing(0.f)
53 {
54 tree_mesh [0] = '\0';
55 color_map [0] = '\0';
56 density_map [0] = '\0';
57 collision_mesh[0] = '\0';
58 }
59
65
70};
71
72// -----------------------------------------------------------------------------
75{
77 range(80),
78 technique(1), // GRASSTECH_CROSSQUADS
79 grow_techniq(0),
80 sway_speed(0.5f),
81 sway_length(0.05f),
82 sway_distrib(10.f),
83
84 min_x(0.2f), min_y(0.2f), min_h(-9999.f),
85 max_x(1.0f), max_y(0.6f), max_h(+9999.f)
86 {
87 material_name [0] = '\0';
88 color_map_filename [0] = '\0';
89 density_map_filename [0] = '\0';
90 }
91
92 int range;
98 float density;
99
102
106};
107
108// -----------------------------------------------------------------------------
110{
111 Ogre::Vector3 position;
112 Ogre::Quaternion rotation;
113 Ogre::Vector3 tobj_rotation;
116 std::string comments;
117};
118
119// -----------------------------------------------------------------------------
121{
123 TObjEntry(
124 Ogre::Vector3 pos, Ogre::Vector3 rot, const char* instance_name,
125 TObjSpecialObject special, const char* type, const char* name);
126
127 bool IsActor() const;
128 bool IsRoad() const;
129
130 Ogre::Vector3 position = Ogre::Vector3::ZERO;
131 Ogre::Vector3 rotation = Ogre::Vector3::ZERO;
133 char type[TObj::STR_LEN] = {};
136 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
137 std::string comments;
138};
139
140// -----------------------------------------------------------------------------
142{
145 grid_enabled(false)
146 {}
147
148 std::string document_name;
149 Ogre::Vector3 grid_position;
152 std::vector<TObjTree> trees;
153 std::vector<TObjGrass> grass;
154 std::vector<TObjVehicle> vehicles;
155 std::vector<TObjEntry> objects;
156 std::vector<ProceduralObjectPtr> proc_objects;
157};
158
159// -----------------------------------------------------------------------------
161{
162public:
163 void Prepare();
164 bool ProcessLine(const char* line);
165 void ProcessOgreStream(Ogre::DataStream* stream);
167
168 static Ogre::Quaternion CalcRotation(Ogre::Vector3 const& rot, bool rot_yxz);
169
170private:
171 // Processing:
172 bool ProcessCurrentLine();
174 void ProcessGridLine();
175 void ProcessTreesLine();
176 void ProcessGrassLine();
177 void ProcessActorObject(const TObjEntry& object);
178 void ProcessRoadObject(const TObjEntry& object);
179
180 // Helpers:
181 void ImportProceduralPoint(Ogre::Vector3 const& pos, Ogre::Vector3 const& rot, TObjSpecialObject special);
182 bool ParseObjectLine(TObjEntry& object);
184
186 std::string m_filename;
188 const char* m_cur_line;
192
193 // Procedural roads
197
198 // Auto-importing legacy road blocks (ODEF) as procedural roads
199 Ogre::Vector3 m_road2_last_pos;
200 Ogre::Vector3 m_road2_last_rot;
202
204};
205
206} // 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)
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]
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]
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