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
FlexBody.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#pragma once
23
25#include "Application.h"
26#include "Locator_t.h"
27#include "SimData.h"
28#include "GfxData.h"
29#include "RigDef_File.h"
30#include "Utils.h"
31
32#include <Ogre.h>
33
34namespace RoR {
35
38
41
44{
45 friend class RoR::FlexFactory;
46 friend class RoR::FlexBodyFileIO;
47
48 FlexBody( // Private, for FlexFactory
49 RoR::FlexBodyCacheData* preloaded_from_cache,
50 RoR::GfxActor* gfx_actor,
51 Ogre::Entity* entity,
52 NodeNum_t ref,
53 NodeNum_t nx,
54 NodeNum_t ny,
55 Ogre::Vector3 offset,
56 Ogre::Quaternion const & rot,
57 std::vector<unsigned int>& node_indices,
58 std::vector<ForvertTempData>& forvert_data
59 );
60
61public:
62
70 static const char* PlaceholderTypeToString(PlaceholderType type);
71
77
78 FlexBody(PlaceholderType, FlexbodyID_t id, const std::string& orig_meshname);
79 ~FlexBody();
80
81 void reset();
82 void updateBlend();
83 void writeBlend();
84
85 void computeFlexbody();
87
88 bool isVisible() const;
89 void setVisible(bool visible);
90
91 void setFlexbodyCastShadow(bool val);
92
93 int getVertexCount() { return static_cast<int>(m_vertex_count); };
94 Locator_t& getVertexLocator(int vert) { ROR_ASSERT((size_t)vert < m_vertex_count); return m_locators[vert]; }
95 Ogre::Vector3 getVertexPos(int vert) { ROR_ASSERT((size_t)vert < m_vertex_count); return m_dst_pos[vert] + m_flexit_center; }
96 Ogre::Entity* getEntity() { return m_scene_entity; }
97 const std::string& getOrigMeshName() const { return m_orig_mesh_name; }
98 std::vector<NodeNum_t>& getForsetNodes() { return m_forset_nodes; };
99 std::string getOrigMeshInfo() { return m_orig_mesh_info; }
100 std::string getLiveMeshInfo() { return RoR::PrintMeshInfo("Live", m_scene_entity->getMesh()); }
101
105
106 FlexbodyID_t getID() const { return m_id; }
108 void destroyOgreObjects();
109
110private:
111
113
115 size_t m_vertex_count = 0;
116 Ogre::Vector3 m_flexit_center = Ogre::Vector3::ZERO;
117 FlexbodyID_t m_id = FLEXBODYID_INVALID; // Filled by FlexFactory
119
120 Ogre::Vector3* m_dst_pos = nullptr;
121 Ogre::Vector3* m_src_normals = nullptr;
122 Ogre::Vector3* m_dst_normals = nullptr;
123 Ogre::ARGB* m_src_colors = nullptr;
125
129 Ogre::Vector3 m_center_offset = Ogre::Vector3::ZERO;
130 Ogre::SceneNode* m_scene_node = nullptr;
131 Ogre::Entity* m_scene_entity = nullptr;
133
135 Ogre::HardwareVertexBufferSharedPtr m_shared_vbuf_pos;
136 Ogre::HardwareVertexBufferSharedPtr m_shared_vbuf_norm;
137 Ogre::HardwareVertexBufferSharedPtr m_shared_vbuf_color;
138
141 Ogre::HardwareVertexBufferSharedPtr m_submesh_vbufs_pos[16];
142 Ogre::HardwareVertexBufferSharedPtr m_submesh_vbufs_norm[16];
143 Ogre::HardwareVertexBufferSharedPtr m_submesh_vbufs_color[16];
144
146 bool m_has_texture = true;
148 bool m_blend_changed = false;
149
150 // Diagnostic data, not used for calculations
151 std::vector<NodeNum_t> m_forset_nodes;
152 std::string m_orig_mesh_info;
153 std::string m_orig_mesh_name;
154};
155
158
159} // namespace RoR
Central state/object manager and communications hub.
#define ROR_ASSERT(_EXPR)
Definition Application.h:40
Data structures representing 'truck' file format, see https://docs.rigsofrods.org/vehicle-creation/fi...
Core data structures for simulation; Everything affected by by either physics, network or user intera...
Enables saving and loading flexbodies from/to binary file.
Definition FlexFactory.h:98
Flexbody = A deformable mesh; updated on CPU every frame, then uploaded to video memory.
Definition FlexBody.h:44
void updateFlexbodyVertexBuffers()
Definition FlexBody.cpp:661
std::string m_orig_mesh_name
Definition FlexBody.h:153
Ogre::ARGB * m_src_colors
Definition FlexBody.h:123
CameraMode_t fb_camera_mode_orig
Dynamic visibility mode {0 and higher = cinecam index}.
Definition FlexBody.h:75
Ogre::SceneNode * m_scene_node
Definition FlexBody.h:130
NodeNum_t getXNode()
Definition FlexBody.h:103
Ogre::HardwareVertexBufferSharedPtr m_submesh_vbufs_norm[16]
normals
Definition FlexBody.h:142
Locator_t * m_locators
1 loc per vertex
Definition FlexBody.h:124
std::vector< NodeNum_t > m_forset_nodes
Definition FlexBody.h:151
void updateBlend()
Definition FlexBody.cpp:717
NodeNum_t m_node_y
Definition FlexBody.h:128
Ogre::Entity * m_scene_entity
Definition FlexBody.h:131
NodeNum_t getYNode()
Definition FlexBody.h:104
static const char * PlaceholderTypeToString(PlaceholderType type)
Definition FlexBody.cpp:560
int m_num_submesh_vbufs
Definition FlexBody.h:139
Ogre::Vector3 m_center_offset
Definition FlexBody.h:129
Ogre::Entity * getEntity()
Definition FlexBody.h:96
NodeNum_t m_node_center
Definition FlexBody.h:126
void defragmentFlexbodyMesh()
Definition FlexBody.cpp:793
bool m_has_texture
Definition FlexBody.h:146
FlexbodyID_t getID() const
Definition FlexBody.h:106
int m_submesh_vbufs_vertex_counts[16]
Definition FlexBody.h:140
RoR::GfxActor * m_gfx_actor
Definition FlexBody.h:114
void setFlexbodyCastShadow(bool val)
Definition FlexBody.cpp:613
std::string getOrigMeshInfo()
Definition FlexBody.h:99
std::string m_orig_mesh_info
Definition FlexBody.h:152
Ogre::HardwareVertexBufferSharedPtr m_shared_vbuf_pos
Definition FlexBody.h:135
void setVisible(bool visible)
Definition FlexBody.cpp:606
Ogre::HardwareVertexBufferSharedPtr m_submesh_vbufs_pos[16]
positions
Definition FlexBody.h:141
size_t m_vertex_count
Definition FlexBody.h:115
Ogre::HardwareVertexBufferSharedPtr m_shared_vbuf_color
Definition FlexBody.h:137
int m_camera_mode
Visibility control {-2 = always, -1 = 3rdPerson only, 0+ = cinecam index}.
Definition FlexBody.h:132
Ogre::Vector3 getVertexPos(int vert)
Definition FlexBody.h:95
FlexbodyID_t m_id
Definition FlexBody.h:117
bool m_has_texture_blend
Definition FlexBody.h:147
int getVertexCount()
Definition FlexBody.h:93
void writeBlend()
Definition FlexBody.cpp:701
void destroyOgreObjects()
Definition FlexBody.cpp:572
bool isVisible() const
Definition FlexBody.cpp:597
Locator_t & getVertexLocator(int vert)
Definition FlexBody.h:94
Ogre::Vector3 * m_dst_pos
Definition FlexBody.h:120
int m_shared_buf_num_verts
Definition FlexBody.h:134
Ogre::HardwareVertexBufferSharedPtr m_submesh_vbufs_color[16]
colors
Definition FlexBody.h:143
void computeFlexbody()
Updates mesh deformation; works on CPU using local copy of vertex data.
Definition FlexBody.cpp:620
Ogre::Vector3 m_flexit_center
Updated per frame.
Definition FlexBody.h:116
Ogre::Vector3 * m_src_normals
Definition FlexBody.h:121
bool m_blend_changed
Definition FlexBody.h:148
const std::string & getOrigMeshName() const
Definition FlexBody.h:97
PlaceholderType m_placeholder_type
Definition FlexBody.h:118
CameraMode_t fb_camera_mode_active
Dynamic visibility mode {0 and higher = cinecam index}.
Definition FlexBody.h:74
Ogre::Vector3 * m_dst_normals
Definition FlexBody.h:122
PlaceholderType getPlaceholderType() const
Definition FlexBody.h:107
NodeNum_t getRefNode()
Definition FlexBody.h:102
bool m_uses_shared_vertex_data
Definition FlexBody.h:145
NodeNum_t m_node_x
Definition FlexBody.h:127
std::string getLiveMeshInfo()
Definition FlexBody.h:100
std::vector< NodeNum_t > & getForsetNodes()
Definition FlexBody.h:98
Ogre::HardwareVertexBufferSharedPtr m_shared_vbuf_norm
Definition FlexBody.h:136
static const NodeNum_t NODENUM_INVALID
static CameraMode_t CAMERA_MODE_ALWAYS_VISIBLE
int FlexbodyID_t
Index to GfxActor::m_flexbodies, use RoR::FLEXBODYID_INVALID as empty value.
int CameraMode_t
std::string PrintMeshInfo(std::string const &title, Ogre::MeshPtr mesh)
uint16_t NodeNum_t
Node position within Actor::ar_nodes; use RoR::NODENUM_INVALID as empty value.
static const FlexbodyID_t FLEXBODYID_INVALID