RigsofRods
Soft-body Physics Simulation
FlexMesh.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 
24 #include "Application.h"
25 
26 #include "Flexable.h"
27 #include "SimData.h" // NodeNum_t
28 
29 #include <OgreString.h>
30 #include <OgreEntity.h>
31 #include <OgreVector3.h>
32 #include <OgreMesh.h>
33 #include <OgreSubMesh.h>
34 #include <OgreHardwareBuffer.h>
35 
36 namespace RoR {
37 
40 
43 
44 class FlexMesh: public Flexable
45 {
46 public:
47 
48  FlexMesh(
49  Ogre::String const& name,
50  RoR::GfxActor* gfx_actor,
51  NodeNum_t n1,
52  NodeNum_t n2,
53  NodeNum_t nstart,
54  int nrays,
55  Ogre::String const& face_material_name,
56  Ogre::String const& face_material_rg,
57  Ogre::String const& band_material_name,
58  Ogre::String const& band_material_rg,
59  bool rimmed = false,
60  float rimratio = 1.f
61  );
62 
63  ~FlexMesh();
64 
65  Ogre::Vector3 updateVertices();
66 
67  // Flexable
68  bool flexitPrepare() { return true; };
69  void flexitCompute();
70  Ogre::Vector3 flexitFinal();
71 
72  void setVisible(bool visible) {} // Nothing to do here
73 
74 private:
75 
76  struct FlexMeshVertex // staging
77  {
78  Ogre::Vector3 position = Ogre::Vector3::ZERO;
79  Ogre::Vector3 normal = Ogre::Vector3::ZERO;
80  Ogre::Vector2 texcoord = Ogre::Vector2::ZERO;
81  };
82 
83  // Wheel
84  Ogre::Vector3 m_flexit_center;
88 
89  // Meshes
90  Ogre::MeshPtr m_mesh;
91  Ogre::SubMesh* m_submesh_wheelface = nullptr;
92  Ogre::SubMesh* m_submesh_tiretread = nullptr;
93  Ogre::VertexDeclaration* m_vertex_format;
94  Ogre::HardwareVertexBufferSharedPtr m_hw_vbuf;
95 
96  // Vertices - staging
97  std::vector<FlexMeshVertex> m_vertices;
98  std::vector<NodeNum_t> m_vertex_nodes;
99 
100  // Indices
101  std::vector<uint16_t> m_wheelface_indices;
102  std::vector<uint16_t> m_tiretread_indices;
103 
104  // Skeletal animation (1 bone per node)
105 };
106 
109 
110 } // namespace RoR
RoR::FlexMesh::m_num_rays
int m_num_rays
Definition: FlexMesh.h:86
RoR::FlexMesh::m_submesh_wheelface
Ogre::SubMesh * m_submesh_wheelface
Definition: FlexMesh.h:91
RoR::FlexMesh::m_is_rimmed
bool m_is_rimmed
Definition: FlexMesh.h:87
RoR::FlexMesh::FlexMesh
FlexMesh(Ogre::String const &name, RoR::GfxActor *gfx_actor, NodeNum_t n1, NodeNum_t n2, NodeNum_t nstart, int nrays, Ogre::String const &face_material_name, Ogre::String const &face_material_rg, Ogre::String const &band_material_name, Ogre::String const &band_material_rg, bool rimmed=false, float rimratio=1.f)
Definition: FlexMesh.cpp:33
RoR::Flexable
Definition: Flexable.h:34
RoR::FlexMesh::m_vertices
std::vector< FlexMeshVertex > m_vertices
Definition: FlexMesh.h:97
RoR::FlexMesh::m_submesh_tiretread
Ogre::SubMesh * m_submesh_tiretread
Definition: FlexMesh.h:92
RoR::FlexMesh::flexitCompute
void flexitCompute()
Definition: FlexMesh.cpp:293
RoR::FlexMesh::FlexMeshVertex::texcoord
Ogre::Vector2 texcoord
Definition: FlexMesh.h:80
RoR::FlexMesh::m_wheelface_indices
std::vector< uint16_t > m_wheelface_indices
Definition: FlexMesh.h:101
RoR::FlexMesh::FlexMeshVertex::position
Ogre::Vector3 position
Definition: FlexMesh.h:78
RoR::FlexMesh::updateVertices
Ogre::Vector3 updateVertices()
Definition: FlexMesh.cpp:243
RoR::FlexMesh::flexitFinal
Ogre::Vector3 flexitFinal()
Definition: FlexMesh.cpp:298
RoR::FlexMesh::m_vertex_nodes
std::vector< NodeNum_t > m_vertex_nodes
Definition: FlexMesh.h:98
RoR::FlexMesh::flexitPrepare
bool flexitPrepare()
Definition: FlexMesh.h:68
Flexable.h
RoR::NodeNum_t
uint16_t NodeNum_t
Node position within Actor::ar_nodes; use RoR::NODENUM_INVALID as empty value.
Definition: ForwardDeclarations.h:52
SimData.h
Core data structures for simulation; Everything affected by by either physics, network or user intera...
RoR::FlexMesh::FlexMeshVertex
Definition: FlexMesh.h:76
RoR::FlexMesh::~FlexMesh
~FlexMesh()
Definition: FlexMesh.cpp:234
RoR::FlexMesh
Definition: FlexMesh.h:44
Application.h
Central state/object manager and communications hub.
RoR::FlexMesh::m_vertex_format
Ogre::VertexDeclaration * m_vertex_format
Definition: FlexMesh.h:93
RoR::FlexMesh::m_hw_vbuf
Ogre::HardwareVertexBufferSharedPtr m_hw_vbuf
Definition: FlexMesh.h:94
RoR::FlexMesh::setVisible
void setVisible(bool visible)
Definition: FlexMesh.h:72
RoR::FlexMesh::m_gfx_actor
RoR::GfxActor * m_gfx_actor
Definition: FlexMesh.h:85
RoR::GfxActor
Definition: GfxActor.h:52
RoR::FlexMesh::m_tiretread_indices
std::vector< uint16_t > m_tiretread_indices
Definition: FlexMesh.h:102
RoR::FlexMesh::FlexMeshVertex::normal
Ogre::Vector3 normal
Definition: FlexMesh.h:79
RoR
Definition: AppContext.h:36
RoR::FlexMesh::m_flexit_center
Ogre::Vector3 m_flexit_center
Definition: FlexMesh.h:84
RoR::FlexMesh::m_mesh
Ogre::MeshPtr m_mesh
Definition: FlexMesh.h:90