Rigs of Rods 2026.01
Soft-body Physics Simulation
Loading...
Searching...
No Matches
GfxActor.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 2016-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
26
27#pragma once
28
29#include "AutoPilot.h"
30#include "Differentials.h"
31#include "ForwardDeclarations.h"
32#include "GfxData.h"
34#include "SimBuffers.h"
35#include "SurveyMapEntity.h"
36#include "ThreadPool.h" // class Task
37
38#include <OgreAxisAlignedBox.h>
39#include <OgreColourValue.h>
40#include <OgreMaterial.h>
41#include <OgreQuaternion.h>
42#include <OgreTexture.h>
43#include <OgreVector3.h>
44#include <string>
45#include <vector>
46
47namespace RoR {
48
51
53{
54 friend class ActorSpawner; // The factory
55
56public:
57
58 GfxActor(ActorPtr actor, ActorSpawner* spawner, std::string ogre_resource_group);
59
60 ~GfxActor();
61
62 // Adding elements
63
64 void RegisterCabMaterial(Ogre::MaterialPtr mat, Ogre::MaterialPtr mat_trans);
65 void RegisterCabMesh(Ogre::Entity* ent, Ogre::SceneNode* snode, FlexObj* flexobj);
66 void SortFlexbodies();
67
68 // Retrieving elements
69
70 std::vector<FlexBody*>& GetFlexbodies() { return m_flexbodies; };
71 std::vector<Prop>& getProps() { return m_props; }
72 std::vector<CParticle>& getCParticles() { return m_cparticles; }
73 std::vector<Exhaust>& getExhausts() { return m_exhausts; }
74 std::vector<VideoCamera>& getVideoCameras() { return m_videocameras; }
75
76 // Visual changes
77
78 void SetMaterialFlareOn(int flare_index, bool state_on);
79 void SetCabLightsActive(bool state_on);
81 void ScaleActor(Ogre::Vector3 relpos, float ratio);
82 void ToggleDebugView();
83 void CycleDebugViews();
84 void ResetFlexbodies();
85 void SetBeaconsEnabled(bool beacon_light_is_active);
87 void SetNodeHot(NodeNum_t nodenum, bool value);
88 void RemoveBeam(int beam_index);
89
90 // Visibility
91
92 void SetRodsVisible(bool visible);
93 void SetFlexbodyVisible (bool visible);
94 void SetWheelsVisible(bool value);
95 void SetAllMeshesVisible(bool value);
96 void SetWingsVisible(bool visible);
97 void SetCastShadows(bool value);
98 void SetFlexbodiesVisible(bool visible);
99 void SetPropsVisible(bool visible);
100 void SetAeroEnginesVisible(bool visible);
101
102 // Visual updates
103
104 void UpdateVideoCameras(float dt);
105 void UpdateParticles(float dt);
106 void UpdateRods();
107 void UpdateWheelVisuals();
108 void UpdateFlexbodies();
109 void UpdateDebugView();
110 void UpdateCabMesh();
111 void UpdateWingMeshes();
112 void UpdateBeaconFlare(Prop & prop, float dt, bool is_player_actor);
113 void UpdateProps(float dt, bool is_player_actor);
114 void UpdatePropAnimations(float dt);
115 void UpdateAirbrakes();
116 void UpdateCParticles();
117 void UpdateExhausts();
118 void UpdateAeroEngines();
119 void UpdateNetLabels(float dt);
120 void UpdateFlares(float dt, bool is_player);
121
122 // SimBuffers
123
124 void UpdateSimDataBuffer();
127
128 // Internal updates
129
130 void FinishWheelUpdates();
131 void FinishFlexbodyTasks();
132
133 // Helpers
134
135 bool IsActorLive() const;
136 bool IsActorInitialized() const { return m_initialized; }
137 void InitializeActor() { m_initialized = true; }
138 void CalculateDriverPos(Ogre::Vector3& out_pos, Ogre::Quaternion& out_rot);
139 int GetActorId() const;
140 int GetActorState() const;
143 Ogre::String GetResourceGroup() { return m_custom_resource_group; }
144 ActorPtr GetActor(); // Watch out for multithreading with this!
145 Ogre::MaterialPtr& GetCabTransMaterial() { return m_cab_mat_visual_trans; }
146 Ogre::TexturePtr GetHelpTex() { return m_help_tex; }
147 Ogre::MaterialPtr GetHelpMat() { return m_help_mat; }
148 bool HasDriverSeatProp() const { return m_driverseat_prop_index != -1; }
149 void CalcPropAnimation(PropAnim& anim, float& cstate, int& div, float dt);
151 WheelSide getWheelSide(WheelID_t wheel_id) { return (wheel_id >= 0 && (size_t)wheel_id < m_wheels.size()) ? m_wheels[wheel_id].wx_side : WheelSide::INVALID; }
152 std::string getWheelRimMeshName(WheelID_t wheel_id) { return (wheel_id >= 0 && (size_t)wheel_id < m_wheels.size()) ? m_wheels[wheel_id].wx_rim_mesh_name : ""; }
153 const ActorPtr& getOwningActor() { return m_actor; }
154 int countBeaconProps() const;
156private:
157
158 float UpdateSmoothShift(PropAnim& anim, float dt, float new_target_cstate); // Helper for `CalcPropAnimation()`
159
160 // Static info
164 Ogre::SceneNode* m_gfx_beams_parent_scenenode = nullptr;
165
166 // Game state
167 bool m_initialized = false;
171 bool m_beaconlight_active = true; // 'true' will trigger SetBeaconsEnabled(false) on the first buffer update
175
176 // Threaded tasks
177 std::vector<std::shared_ptr<Task>> m_flexwheel_tasks;
178 std::vector<std::shared_ptr<Task>> m_flexbody_tasks;
179
180 // Elements
181 std::vector<NodeGfx> m_gfx_nodes;
182 std::vector<BeamGfx> m_gfx_beams;
183 std::vector<AirbrakeGfx> m_gfx_airbrakes;
184 std::vector<Prop> m_props;
185 std::vector<FlexBody*> m_flexbodies;
186 std::vector<WheelGfx> m_wheels;
187 std::vector<VideoCamera> m_videocameras;
188 std::vector<FlareMaterial> m_flare_materials;
189 std::vector<CParticle> m_cparticles;
190 std::vector<Exhaust> m_exhausts;
191
192 // Particles
194 DustPool* m_particles_dust = nullptr; // dust, vapour and tyre smoke
199
200 // Cab mesh ('submesh' in truck fileformat)
201 FlexObj* m_cab_mesh = nullptr;
202 Ogre::SceneNode* m_cab_scene_node = nullptr;
203 Ogre::Entity* m_cab_entity = nullptr;
204 Ogre::MaterialPtr m_cab_mat_visual;
205 Ogre::MaterialPtr m_cab_mat_visual_trans;
206 Ogre::MaterialPtr m_cab_mat_template_plain;
208
209 // GUI
210 Ogre::MaterialPtr m_help_mat;
211 Ogre::TexturePtr m_help_tex;
213
215};
216
218
219} // Namespace RoR
Global forward declarations.
Processes a RigDef::Document (parsed from 'truck' file format) into a simulated gameplay object (Acto...
A visual mesh, forming a chassis for softbody actor At most one instance is created per actor.
Definition FlexObj.h:60
Ogre::MaterialPtr m_cab_mat_template_emissive
Definition GfxActor.h:207
void SetNodeHot(NodeNum_t nodenum, bool value)
void UpdateVideoCameras(float dt)
Definition GfxActor.cpp:468
std::vector< FlexBody * > & GetFlexbodies()
Definition GfxActor.h:70
SurveyMapEntity & getSurveyMapEntity()
Definition GfxActor.h:150
Ogre::TexturePtr m_help_tex
Definition GfxActor.h:211
bool m_beaconlight_active
Definition GfxActor.h:171
void SetCastShadows(bool value)
std::vector< CParticle > & getCParticles()
Definition GfxActor.h:72
float m_prop_anim_crankfactor_prev
Definition GfxActor.h:172
VideoCamState m_vidcam_state
Definition GfxActor.h:168
void SetRodsVisible(bool visible)
bool IsActorInitialized() const
Temporary TODO: Remove once the spawn routine is fixed.
Definition GfxActor.h:136
void ResetFlexbodies()
Ogre::String GetResourceGroup()
Definition GfxActor.h:143
bool IsActorLive() const
Should the visuals be updated for this actor?
DustPool * m_particles_drip
Definition GfxActor.h:193
void SetCabLightsActive(bool state_on)
Definition GfxActor.cpp:419
void UpdateWheelVisuals()
void SetVideoCamState(VideoCamState state)
Definition GfxActor.cpp:440
void UpdateAeroEngines()
DustPool * m_particles_splash
Definition GfxActor.h:195
void SetWingsVisible(bool visible)
Ogre::MaterialPtr GetHelpMat()
Definition GfxActor.h:147
DustPool * m_particles_sparks
Definition GfxActor.h:197
ActorSB & GetSimDataBuffer()
Definition GfxActor.h:125
void SetWheelsVisible(bool value)
void UpdateRods()
std::vector< BeamGfx > m_gfx_beams
Definition GfxActor.h:182
std::string getWheelRimMeshName(WheelID_t wheel_id)
Definition GfxActor.h:152
FlexObj * m_cab_mesh
Definition GfxActor.h:201
void RegisterCabMesh(Ogre::Entity *ent, Ogre::SceneNode *snode, FlexObj *flexobj)
bool IsDebugViewApplicable(DebugViewType dv)
float UpdateSmoothShift(PropAnim &anim, float dt, float new_target_cstate)
std::vector< VideoCamera > & getVideoCameras()
Definition GfxActor.h:74
SurveyMapEntity m_surveymap_entity
Definition GfxActor.h:212
void UpdateCParticles()
void UpdateExhausts()
int GetActorState() const
Ogre::SceneNode * m_cab_scene_node
Definition GfxActor.h:202
std::vector< std::shared_ptr< Task > > m_flexbody_tasks
Definition GfxActor.h:178
std::vector< Exhaust > m_exhausts
Definition GfxActor.h:190
std::vector< FlareMaterial > m_flare_materials
Definition GfxActor.h:188
DustPool * m_particles_clump
Definition GfxActor.h:198
void FinishFlexbodyTasks()
float m_prop_anim_shift_timer
Definition GfxActor.h:173
std::string m_custom_resource_group
Definition GfxActor.h:162
DebugViewType m_debug_view
Definition GfxActor.h:169
Ogre::Entity * m_cab_entity
Definition GfxActor.h:203
std::vector< Prop > & getProps()
Definition GfxActor.h:71
void UpdateSimDataBuffer()
Copies sim. data from Actor to GfxActor for later update.
void InitializeActor()
Temporary TODO: Remove once the spawn routine is fixed.
Definition GfxActor.h:137
void UpdatePropAnimations(float dt)
Ogre::MaterialPtr m_cab_mat_visual
Updated in-place from templates.
Definition GfxActor.h:204
VideoCamState GetVideoCamState() const
Definition GfxActor.h:141
ActorPtr GetActor()
Definition GfxActor.cpp:334
void UpdateDebugView()
Definition GfxActor.cpp:734
ActorSB m_simbuf
Definition GfxActor.h:214
std::vector< NodeGfx > m_gfx_nodes
Definition GfxActor.h:181
std::vector< std::shared_ptr< Task > > m_flexwheel_tasks
Definition GfxActor.h:177
Ogre::MaterialPtr m_cab_mat_visual_trans
Definition GfxActor.h:205
void SortFlexbodies()
int m_prop_anim_prev_gear
Definition GfxActor.h:174
std::vector< WheelGfx > m_wheels
Definition GfxActor.h:186
void UpdateAirbrakes()
void UpdateCabMesh()
void UpdateFlares(float dt, bool is_player)
void UpdateProps(float dt, bool is_player_actor)
Ogre::SceneNode * m_gfx_beams_parent_scenenode
Definition GfxActor.h:164
bool HasDriverSeatProp() const
Definition GfxActor.h:148
void CalcPropAnimation(PropAnim &anim, float &cstate, int &div, float dt)
ActorPtr m_actor
Definition GfxActor.h:161
void RemoveBeam(int beam_index)
NodeSB * GetSimNodeBuffer()
Definition GfxActor.h:126
void SetAllMeshesVisible(bool value)
std::vector< Prop > m_props
Definition GfxActor.h:184
void UpdateBeaconFlare(Prop &prop, float dt, bool is_player_actor)
void SetAeroEnginesVisible(bool visible)
WheelSide getWheelSide(WheelID_t wheel_id)
Definition GfxActor.h:151
void SetFlexbodyVisible(bool visible)
std::vector< VideoCamera > m_videocameras
Definition GfxActor.h:187
int m_driverseat_prop_index
Definition GfxActor.h:163
Ogre::MaterialPtr m_cab_mat_template_plain
Definition GfxActor.h:206
void SetDebugView(DebugViewType dv)
DustPool * m_particles_dust
Definition GfxActor.h:194
void SetPropsVisible(bool visible)
std::vector< Exhaust > & getExhausts()
Definition GfxActor.h:73
std::vector< CParticle > m_cparticles
Definition GfxActor.h:189
void UpdateParticles(float dt)
Definition GfxActor.cpp:589
int GetActorId() const
void RegisterCabMaterial(Ogre::MaterialPtr mat, Ogre::MaterialPtr mat_trans)
Definition GfxActor.cpp:403
Ogre::TexturePtr GetHelpTex()
Definition GfxActor.h:146
void ScaleActor(Ogre::Vector3 relpos, float ratio)
void SetFlexbodiesVisible(bool visible)
void CalculateDriverPos(Ogre::Vector3 &out_pos, Ogre::Quaternion &out_rot)
DustPool * m_particles_ripple
Definition GfxActor.h:196
DebugViewType m_last_debug_view
Definition GfxActor.h:170
Ogre::MaterialPtr & GetCabTransMaterial()
Definition GfxActor.h:145
std::vector< AirbrakeGfx > m_gfx_airbrakes
Definition GfxActor.h:183
void FinishWheelUpdates()
void SetMaterialFlareOn(int flare_index, bool state_on)
Definition GfxActor.cpp:339
std::vector< FlexBody * > m_flexbodies
Definition GfxActor.h:185
void CycleDebugViews()
void SetBeaconsEnabled(bool beacon_light_is_active)
void UpdateNetLabels(float dt)
bool m_initialized
Definition GfxActor.h:167
int countBeaconProps() const
void UpdateWingMeshes()
void ToggleDebugView()
DebugViewType GetDebugView() const
Definition GfxActor.h:142
void UpdateFlexbodies()
const ActorPtr & getOwningActor()
Definition GfxActor.h:153
Ogre::MaterialPtr m_help_mat
Definition GfxActor.h:210
DebugViewType
Definition GfxData.h:103
VideoCamState
Definition GfxData.h:95
WheelSide
Used by rig-def/addonpart/tuneup formats to specify wheel rim mesh orientation.
int WheelID_t
Index to Actor::ar_wheels, use RoR::WHEELID_INVALID as empty value.
uint16_t NodeNum_t
Node position within Actor::ar_nodes; use RoR::NODENUM_INVALID as empty value.
std::vector< NodeSB > simbuf_nodes
Definition SimBuffers.h:134
A mesh attached to vehicle frame via 3 nodes.
Definition GfxData.h:157