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
FlexFactory.h
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
26
27
28#pragma once
29
30#include "BitFlags.h"
31#include "ForwardDeclarations.h"
32#include "Locator_t.h"
34
35#include <OgreVector3.h>
36#include <OgreColourValue.h>
37#include <vector>
38
39namespace RoR
40{
41
44
47
65
67{
69 dst_pos(nullptr),
70 src_normals(nullptr),
71 src_colors(nullptr),
72 locators(nullptr)
73 {}
74
75 // NOTE: No freeing of memory needed, pointers will be copied to FlexBody instances.
76
78
79 Ogre::Vector3* dst_pos;
80 Ogre::Vector3* src_normals;
81 Ogre::ARGB* src_colors;
83};
84
98{
99public:
111
112 static const char* SIGNATURE;
113 static const unsigned int FILE_FORMAT_VERSION = 1;
114
116
117 std::vector<FlexBody*> & GetList();
118 inline void AddItemToSave(FlexBody* fb) { m_items_to_save.push_back(fb); }
119 inline FlexBodyCacheData* GetLoadedItem(unsigned index) { return & m_loaded_items[index]; }
122
123private:
125 {
127 unsigned int num_flexbodies;
128 };
129
130 void OpenFile(const char* fopen_mode);
131 void WriteToFile(void* source, size_t length);
132 void ReadFromFile(void* dest, size_t length);
133 inline void CloseFile() { if (m_file != nullptr) { fclose(m_file); } }
134
135 void WriteSignature();
137
138 void WriteMetadata();
139 void ReadMetadata(FlexBodyFileMetadata* meta);
140
141 void WriteFlexbodyHeader(FlexBody* flexbody);
143
144 void WriteFlexbodyLocatorList(FlexBody* flexbody);
146
147 void WriteFlexbodyNormalsBuffer(FlexBody* flexbody);
149
152
153 void WriteFlexbodyColorsBuffer(FlexBody* flexbody);
155
156 std::vector<FlexBody*> m_items_to_save;
157 std::vector<FlexBodyCacheData> m_loaded_items;
158 FILE* m_file;
161};
162
164{
165public:
167
168 FlexFactory(ActorSpawner* spawner);
169
171 FlexbodyID_t flexbody_id,
172 const NodeNum_t ref_node,
173 const NodeNum_t x_node,
174 const NodeNum_t y_node,
175 Ogre::Vector3 offset,
176 Ogre::Vector3 rotation,
177 std::vector<unsigned int> & node_indices,
178 std::vector<ForvertTempData>& forvert_data,
179 const std::string& mesh_name,
180 const std::string& resource_group_name);
181
183 unsigned int wheel_index,
184 int axis_node_1_index,
185 int axis_node_2_index,
186 int nstart,
187 int nrays,
188 float rim_radius,
189 bool rim_reverse,
190 std::string const & rim_mesh_name,
191 std::string const & rim_mesh_rg,
192 std::string const & tire_material_name,
193 std::string const & tire_material_rg);
194
197
198private:
199
201
206};
207
210
211} // namespace RoR
Bit operations.
#define BITMASK(OFFSET)
Definition BitFlags.h:10
uint32_t BitMask_t
Definition BitFlags.h:7
Global forward declarations.
Processes a RigDef::Document (parsed from 'truck' file format) into a simulated gameplay object (Acto...
Enables saving and loading flexbodies from/to binary file.
Definition FlexFactory.h:98
void ReadFlexbodyColorsBuffer(FlexBodyCacheData *flexbody)
void WriteFlexbodyNormalsBuffer(FlexBody *flexbody)
void ReadFlexbodyPositionsBuffer(FlexBodyCacheData *flexbody)
void OpenFile(const char *fopen_mode)
ResultCode LoadFile()
FlexBodyCacheData * GetLoadedItem(unsigned index)
unsigned int m_fileformat_version
void ReadFromFile(void *dest, size_t length)
void WriteToFile(void *source, size_t length)
void WriteFlexbodyHeader(FlexBody *flexbody)
void WriteFlexbodyLocatorList(FlexBody *flexbody)
void ReadFlexbodyNormalsBuffer(FlexBodyCacheData *flexbody)
void ReadFlexbodyHeader(FlexBodyCacheData *flexbody)
void AddItemToSave(FlexBody *fb)
void WriteFlexbodyColorsBuffer(FlexBody *flexbody)
ResultCode SaveFile()
void ReadFlexbodyLocatorList(FlexBodyCacheData *flexbody)
@ RESULT_CODE_ERR_CACHE_NUMBER_UNDEFINED
void WriteFlexbodyPositionsBuffer(FlexBody *flexbody)
std::vector< FlexBodyCacheData > m_loaded_items
void ReadMetadata(FlexBodyFileMetadata *meta)
static const unsigned int FILE_FORMAT_VERSION
static const char * SIGNATURE
std::vector< FlexBody * > m_items_to_save
std::vector< FlexBody * > & GetList()
Flexbody = A deformable mesh; updated on CPU every frame, then uploaded to video memory.
Definition FlexBody.h:44
FlexMeshWheel * CreateFlexMeshWheel(unsigned int wheel_index, int axis_node_1_index, int axis_node_2_index, int nstart, int nrays, float rim_radius, bool rim_reverse, std::string const &rim_mesh_name, std::string const &rim_mesh_rg, std::string const &tire_material_name, std::string const &tire_material_rg)
bool m_is_flexbody_cache_loaded
void SaveFlexbodiesToCache()
FlexBodyFileIO m_flexbody_cache
FlexBody * CreateFlexBody(FlexbodyID_t flexbody_id, const NodeNum_t ref_node, const NodeNum_t x_node, const NodeNum_t y_node, Ogre::Vector3 offset, Ogre::Vector3 rotation, std::vector< unsigned int > &node_indices, std::vector< ForvertTempData > &forvert_data, const std::string &mesh_name, const std::string &resource_group_name)
unsigned int m_flexbody_cache_next_index
void CheckAndLoadFlexbodyCache()
ActorSpawner * m_rig_spawner
bool m_is_flexbody_cache_enabled
Consists of static mesh, representing the rim, and dynamic mesh, representing the tire.
int FlexbodyID_t
Index to GfxActor::m_flexbodies, use RoR::FLEXBODYID_INVALID as empty value.
uint16_t NodeNum_t
Node position within Actor::ar_nodes; use RoR::NODENUM_INVALID as empty value.
Ogre::Vector3 * dst_pos
Definition FlexFactory.h:79
Ogre::ARGB * src_colors
Definition FlexFactory.h:81
Ogre::Vector3 * src_normals
Definition FlexFactory.h:80
FlexBodyRecordHeader header
Definition FlexFactory.h:77
Locator_t * locators
1 loc per vertex
Definition FlexFactory.h:82
static const BitMask_t HAS_TEXTURE_BLEND
Definition FlexFactory.h:63
Ogre::Vector3 center_offset
Definition FlexFactory.h:54
static const BitMask_t HAS_TEXTURE
Definition FlexFactory.h:62
static const BitMask_t IS_FAULTY
Definition FlexFactory.h:60
static const BitMask_t USES_SHARED_VERTEX_DATA
Definition FlexFactory.h:61