Skip to content

Commit

Permalink
Tuning: added ability to flip rim meshes via UI
Browse files Browse the repository at this point in the history
Codechanges:
* enum `WheelSide` moved from RigDef_File.h (namespace RigDef) to GfxData.h (namespace RoR)
* GfxActor.cpp - SetWheelsVisible() - removed redundant code, rim entity visibility is already handed in FlexMeshWheel::setVisible()
* GfxData.h - added wheel ID, side and redundant mesh name to struct WheelGfx
* GUI_TopMenubar.cpp - fixed prop/flexbody counts, added wheels code.
* ActorSpawner: Unified all wheel-visual setup func names to Create*, always passing wheel side as WheelSide. In `CreateFlexBodyWheelVisuals()`, reverted code to use CreateMeshWheelVisuals() again as the setup was incomplete and the rim wouldn't be updated at all.
* CacheSystem: added FORCED_WHEEL_SET/RESET actions to ModifyProjectRequest.
* TuneupFileFormat: fixed `getTweakedWheelSide()` not querying the UI overrides.
  • Loading branch information
ohlidalp committed Dec 2, 2023
1 parent 08a0414 commit c221bf8
Show file tree
Hide file tree
Showing 15 changed files with 169 additions and 87 deletions.
8 changes: 0 additions & 8 deletions source/main/gfx/GfxActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1859,14 +1859,6 @@ void RoR::GfxActor::SetWheelsVisible(bool value)
if (w.wx_flex_mesh != nullptr)
{
w.wx_flex_mesh->setVisible(value);
if (w.wx_is_meshwheel)
{
Ogre::Entity* e = ((FlexMeshWheel*)(w.wx_flex_mesh))->getRimEntity();
if (e != nullptr)
{
e->setVisible(false);
}
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions source/main/gfx/GfxActor.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ class GfxActor
std::vector<Prop>& getProps() { return m_props; }
bool hasCamera() { return m_videocameras.size() > 0; }
SurveyMapEntity& getSurveyMapEntity() { return m_surveymap_entity; }
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; }
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 : ""; }

private:

Expand Down
16 changes: 13 additions & 3 deletions source/main/gfx/GfxData.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ enum class DebugViewType
DEBUGVIEW_SUBMESH,
};

/// Used by rig-def/addonpart/tuneup formats to specify wheel rim mesh orientation.
enum class WheelSide: char
{
INVALID = 'n',
RIGHT = 'r',
LEFT = 'l'
};

// Dynamic visibility control (value 0 and higher is cinecam index) - common to 'props' and 'flexbodies'
static const int CAMERA_MODE_ALWAYS_HIDDEN = -3;
static const int CAMERA_MODE_ALWAYS_VISIBLE = -2;
Expand Down Expand Up @@ -278,9 +286,11 @@ struct BeamGfx

struct WheelGfx
{
Flexable* wx_flex_mesh = nullptr;
Ogre::SceneNode* wx_scenenode = nullptr;
bool wx_is_meshwheel = false;
WheelID_t wx_wheel_id = WHEELID_INVALID;
Flexable* wx_flex_mesh = nullptr;
Ogre::SceneNode* wx_scenenode = nullptr;
WheelSide wx_side = WheelSide::INVALID;
std::string wx_rim_mesh_name; //!< Redundant, for Tuning UI. Only for 'meshwheels[2]' and 'flexbodywheels'
};

struct AirbrakeGfx
Expand Down
53 changes: 51 additions & 2 deletions source/main/gui/panels/GUI_TopMenubar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1625,7 +1625,7 @@ void TopMenubar::Draw(float dt)
}

// Draw props
size_t total_props = tuneup_entry->tuneup_def->remove_props.size() + tuning_actor->GetGfxActor()->getProps().size();
size_t total_props = tuning_actor->GetGfxActor()->getProps().size();
std::string props_title = fmt::format(_LC("TopMenubar", "Props ({})"), total_props);
if (ImGui::CollapsingHeader(props_title.c_str()))
{
Expand Down Expand Up @@ -1686,7 +1686,7 @@ void TopMenubar::Draw(float dt)
}

// Ditto for flexbodies
size_t total_flexbodies = tuneup_entry->tuneup_def->remove_flexbodies.size() + tuning_actor->GetGfxActor()->GetFlexbodies().size();
size_t total_flexbodies = tuning_actor->GetGfxActor()->GetFlexbodies().size();
std::string flexbodies_title = fmt::format(_LC("TopMenubar", "Flexbodies ({})"), total_flexbodies);
if (ImGui::CollapsingHeader(flexbodies_title.c_str()))
{
Expand Down Expand Up @@ -1721,6 +1721,55 @@ void TopMenubar::Draw(float dt)
ImGui::PopID(); // flexbody->getID()
}
}

// Draw wheels
const int total_wheels = tuning_actor->ar_num_wheels;
std::string wheels_title = fmt::format(_LC("TopMenubar", "Wheels ({})"), total_wheels);
if (ImGui::CollapsingHeader(wheels_title.c_str()))
{
for (WheelID_t i = 0; i < total_wheels; i++)
{
ImGui::PushID(i);
ImGui::AlignTextToFramePadding();

this->DrawTuningBoxedSubjectIdInline(i);

// Draw R/L radio buttons
const RoR::WheelSide active_side = TuneupUtil::getTweakedWheelSide(tuneup_entry, i, tuning_actor->GetGfxActor()->getWheelSide(i));
RoR::WheelSide selected_side = active_side;
if (ImGui::RadioButton("##L", active_side == WheelSide::LEFT))
selected_side = WheelSide::LEFT;
ImGui::SameLine();
ImGui::TextDisabled("|");
ImGui::SameLine();
if (ImGui::RadioButton("##R", active_side == WheelSide::RIGHT))
selected_side = WheelSide::RIGHT;

// Apply selection
if (selected_side != active_side)
{
ModifyProjectRequest* req = new ModifyProjectRequest();
req->mpr_type = ModifyProjectRequestType::TUNEUP_FORCED_WHEEL_SIDE_SET;
req->mpr_subject_id = i;
req->mpr_value_int = (int)selected_side;
req->mpr_target_actor = tuning_actor;
req->mpr_subject_set_protected = true; // stop evaluating addonparts for the wheel (that would undo the user selection).
App::GetGameContext()->PushMessage(Message(MSG_EDI_MODIFY_PROJECT_REQUESTED, req));
}

// Draw rim mesh name
ImGui::SameLine();
ImGui::Text("%s", tuning_actor->GetGfxActor()->getWheelRimMeshName(i).c_str());

this->DrawTuningProtectedChkRightAligned(
i,
tuneup_entry->tuneup_def->isWheelProtected(i),
ModifyProjectRequestType::TUNEUP_PROTECTED_WHEEL_SET,
ModifyProjectRequestType::TUNEUP_PROTECTED_WHEEL_RESET);

ImGui::PopID(); // i
}
}
}

m_open_menu_hoverbox_min = menu_pos - MENU_HOVERBOX_PADDING;
Expand Down
46 changes: 21 additions & 25 deletions source/main/physics/ActorSpawner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4422,18 +4422,18 @@ void ActorSpawner::ProcessMeshWheel(RigDef::MeshWheel & meshwheel_def)
meshwheel_def.rigidity_node
);

this->BuildMeshWheelVisuals(
this->CreateMeshWheelVisuals(
wheel_id,
base_node_index,
axis_node_1->pos,
axis_node_2->pos,
meshwheel_def.num_rays,
TuneupUtil::getTweakedWheelSide(m_actor->getUsedTuneupEntry(), wheel_id, meshwheel_def.side),
TuneupUtil::getTweakedWheelMedia(m_actor->getUsedTuneupEntry(), wheel_id, 0, meshwheel_def.mesh_name),
TuneupUtil::getTweakedWheelMediaRG(m_actor, wheel_id, 0),
TuneupUtil::getTweakedWheelMedia(m_actor->getUsedTuneupEntry(), wheel_id, 1, meshwheel_def.material_name),
TuneupUtil::getTweakedWheelMediaRG(m_actor, wheel_id, 1),
meshwheel_def.rim_radius,
/*rim_reverse:*/meshwheel_def.side != RigDef::WheelSide::RIGHT
meshwheel_def.rim_radius
);

this->CreateWheelSkidmarks(wheel_id);
Expand Down Expand Up @@ -4487,37 +4487,37 @@ void ActorSpawner::ProcessMeshWheel2(RigDef::MeshWheel2 & def)
0.15 // max_extension
);

this->BuildMeshWheelVisuals(
this->CreateMeshWheelVisuals(
wheel_id,
base_node_index,
axis_node_1->pos,
axis_node_2->pos,
def.num_rays,
TuneupUtil::getTweakedWheelSide(m_actor->getUsedTuneupEntry(), wheel_id, def.side),
TuneupUtil::getTweakedWheelMedia(m_actor->getUsedTuneupEntry(), wheel_id, 0, def.mesh_name),
TuneupUtil::getTweakedWheelMediaRG(m_actor, wheel_id, 0),
TuneupUtil::getTweakedWheelMedia(m_actor->getUsedTuneupEntry(), wheel_id, 1, def.material_name),
TuneupUtil::getTweakedWheelMediaRG(m_actor, wheel_id, 1),
def.rim_radius,
/*rim_reverse:*/def.side != RigDef::WheelSide::RIGHT
def.rim_radius
);

CreateWheelSkidmarks(wheel_id);

m_actor->ar_num_wheels++;
}

void ActorSpawner::BuildMeshWheelVisuals(
void ActorSpawner::CreateMeshWheelVisuals(
WheelID_t wheel_index,
NodeNum_t base_node_index,
NodeNum_t axis_node_1_index,
NodeNum_t axis_node_2_index,
unsigned int num_rays,
WheelSide side,
Ogre::String mesh_name,
Ogre::String mesh_rg,
Ogre::String material_name,
Ogre::String material_rg,
float rim_radius,
bool rim_reverse
float rim_radius
)
{
m_actor->GetGfxActor()->UpdateSimDataBuffer(); // fill all current nodes - needed to setup flexing meshes
Expand All @@ -4531,7 +4531,7 @@ void ActorSpawner::BuildMeshWheelVisuals(
base_node_index,
num_rays,
rim_radius,
rim_reverse,
side != WheelSide::RIGHT,
mesh_name,
mesh_rg,
material_name,
Expand All @@ -4540,9 +4540,11 @@ void ActorSpawner::BuildMeshWheelVisuals(
scene_node->attachObject(flexmesh_wheel->GetTireEntity());

WheelGfx visual_wheel;
visual_wheel.wx_is_meshwheel = false;
visual_wheel.wx_wheel_id = wheel_index;
visual_wheel.wx_flex_mesh = flexmesh_wheel;
visual_wheel.wx_scenenode = scene_node;
visual_wheel.wx_side = side;
visual_wheel.wx_rim_mesh_name = mesh_name;
m_actor->m_gfx_actor->m_wheels.push_back(visual_wheel);
}
catch (Ogre::Exception& e)
Expand Down Expand Up @@ -5009,7 +5011,6 @@ void ActorSpawner::CreateWheelVisuals(
WheelGfx visual_wheel;

const std::string wheel_mesh_name = this->ComposeName("WheelMesh", wheel_index);
visual_wheel.wx_is_meshwheel = false;
visual_wheel.wx_flex_mesh = new FlexMesh(
wheel_mesh_name,
m_actor->m_gfx_actor.get(),
Expand Down Expand Up @@ -5044,32 +5045,27 @@ void ActorSpawner::CreateFlexBodyWheelVisuals(
NodeNum_t axis_node_2,
int num_rays,
float radius,
RigDef::WheelSide side,
WheelSide side,
std::string rim_mesh_name,
std::string rim_mesh_rg,
std::string tire_mesh_name,
std::string tire_mesh_rg)
{
m_actor->GetGfxActor()->UpdateSimDataBuffer(); // fill all current nodes - needed to setup flexing meshes

/*this->BuildMeshWheelVisuals(
wheel_index,
this->CreateMeshWheelVisuals(
wheel_id,
node_base_index,
axis_node_1,
axis_node_2,
num_rays,
override_mesh_name,
override_mesh_rg,
side,
rim_mesh_name,
rim_mesh_rg,
"tracks/trans", // Use a builtin transparent material for the generated tire mesh, to effectively disable it.
m_actor->GetGfxActor()->GetResourceGroup(),
radius,
side != RigDef::WheelSide::RIGHT
);*/

// Just create the static rim entity directly (may be located in addonpart ZIP-bundle!)
const std::string rim_entity_name = this->ComposeName("MeshWheelRim", wheel_id);
Ogre::Entity* rim_prop_entity = App::GetGfxScene()->GetSceneManager()->createEntity(rim_entity_name, rim_mesh_name, rim_mesh_rg);
this->SetupNewEntity(rim_prop_entity, Ogre::ColourValue(0, 0.5, 0.8));
radius
);

int num_nodes = num_rays * 4;
std::vector<unsigned int> node_indices;
Expand Down
8 changes: 4 additions & 4 deletions source/main/physics/ActorSpawner.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,24 +408,24 @@ class ActorSpawner
NodeNum_t axis_node_2,
int num_rays,
float radius,
RigDef::WheelSide side,
WheelSide side,
std::string rim_mesh_name,
std::string rim_mesh_rg,
std::string tire_mesh_name,
std::string tire_mesh_rg);

void BuildMeshWheelVisuals(
void CreateMeshWheelVisuals(
WheelID_t wheel_id,
NodeNum_t base_node_index,
NodeNum_t axis_node_1_index,
NodeNum_t axis_node_2_index,
unsigned int num_rays,
WheelSide side,
Ogre::String mesh_name,
Ogre::String mesh_rg,
Ogre::String material_name,
Ogre::String material_rg,
float rim_radius,
bool rim_reverse);
float rim_radius);
/// @}

/// @name Audio setup
Expand Down
1 change: 0 additions & 1 deletion source/main/physics/flex/FlexMeshWheel.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class FlexMeshWheel: public Flexable

~FlexMeshWheel();

Ogre::Entity* getRimEntity() { return m_rim_entity; };
Ogre::Entity* GetTireEntity() { return m_tire_entity; }

Ogre::Vector3 updateVertices();
Expand Down
21 changes: 21 additions & 0 deletions source/main/resources/CacheSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1691,6 +1691,18 @@ void CacheSystem::ModifyProject(ModifyProjectRequest* request)
tuneup_entry->tuneup_def->protected_flexbodies.insert(request->mpr_subject_id);
break;

case ModifyProjectRequestType::TUNEUP_FORCED_WHEEL_SIDE_SET:
tuneup_entry->tuneup_def->wheel_forced_sides[request->mpr_subject_id] = (WheelSide)request->mpr_value_int;
if (request->mpr_subject_set_protected)
tuneup_entry->tuneup_def->protected_wheels.insert(request->mpr_subject_id);
break;

case ModifyProjectRequestType::TUNEUP_FORCED_WHEEL_SIDE_RESET:
tuneup_entry->tuneup_def->wheel_forced_sides.erase(request->mpr_subject_id);
if (request->mpr_subject_set_protected)
tuneup_entry->tuneup_def->protected_wheels.insert(request->mpr_subject_id);
break;

case ModifyProjectRequestType::TUNEUP_PROTECTED_PROP_SET:
tuneup_entry->tuneup_def->protected_props.insert(request->mpr_subject_id);
break;
Expand All @@ -1707,6 +1719,15 @@ void CacheSystem::ModifyProject(ModifyProjectRequest* request)
tuneup_entry->tuneup_def->protected_flexbodies.erase(request->mpr_subject_id);
break;

case ModifyProjectRequestType::TUNEUP_PROTECTED_WHEEL_SET:
tuneup_entry->tuneup_def->protected_wheels.insert(request->mpr_subject_id);
break;

case ModifyProjectRequestType::TUNEUP_PROTECTED_WHEEL_RESET:
tuneup_entry->tuneup_def->protected_wheels.erase(request->mpr_subject_id);
tuneup_entry->tuneup_def->wheel_forced_sides.erase(request->mpr_subject_id); // Unlike props and flexbodies, forced sides are not updated from addonparts - we must clear manually.
break;

case ModifyProjectRequestType::PROJECT_LOAD_TUNEUP:
{
// Instead of loading with the saved tuneup directly, keep the autogenerated and sync it with the save.
Expand Down
29 changes: 17 additions & 12 deletions source/main/resources/CacheSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,18 +216,22 @@ struct CreateProjectRequest
enum class ModifyProjectRequestType
{
NONE,
TUNEUP_USE_ADDONPART_SET, //!< 'subject' is addonpart filename.
TUNEUP_USE_ADDONPART_RESET, //!< 'subject' is addonpart filename.
TUNEUP_REMOVE_PROP_SET, //!< 'subject_id' is prop ID.
TUNEUP_REMOVE_PROP_RESET, //!< 'subject_id' is prop ID.
TUNEUP_REMOVE_FLEXBODY_SET, //!< 'subject_id' is flexbody ID.
TUNEUP_REMOVE_FLEXBODY_RESET,//!< 'subject_id' is flexbody ID.
TUNEUP_PROTECTED_PROP_SET, //!< 'subject' is prop ID.
TUNEUP_PROTECTED_PROP_RESET, //!< 'subject' is prop ID.
TUNEUP_PROTECTED_FLEXBODY_SET, //!< 'subject' is flexbody ID.
TUNEUP_PROTECTED_FLEXBODY_RESET,//!< 'subject' is flexbody ID.
PROJECT_LOAD_TUNEUP, //!< 'subject' is tuneup filename. This overwrites the auto-generated tuneup with the save.
PROJECT_RESET_TUNEUP, //!< 'subject' is empty. This resets the auto-generated tuneup to orig. values.
TUNEUP_USE_ADDONPART_SET, //!< 'subject' is addonpart filename.
TUNEUP_USE_ADDONPART_RESET, //!< 'subject' is addonpart filename.
TUNEUP_REMOVE_PROP_SET, //!< 'subject_id' is prop ID.
TUNEUP_REMOVE_PROP_RESET, //!< 'subject_id' is prop ID.
TUNEUP_REMOVE_FLEXBODY_SET, //!< 'subject_id' is flexbody ID.
TUNEUP_REMOVE_FLEXBODY_RESET, //!< 'subject_id' is flexbody ID.
TUNEUP_FORCED_WHEEL_SIDE_SET, //!< 'subject_id' is wheel ID, 'value_int' is RoR::WheelSide
TUNEUP_FORCED_WHEEL_SIDE_RESET, //!< 'subject_id' is wheel ID.
TUNEUP_PROTECTED_PROP_SET, //!< 'subject_id' is prop ID.
TUNEUP_PROTECTED_PROP_RESET, //!< 'subject_id' is prop ID.
TUNEUP_PROTECTED_FLEXBODY_SET, //!< 'subject_id' is flexbody ID.
TUNEUP_PROTECTED_FLEXBODY_RESET, //!< 'subject_id' is flexbody ID.
TUNEUP_PROTECTED_WHEEL_SET, //!< 'subject_id' is wheel ID.
TUNEUP_PROTECTED_WHEEL_RESET, //!< 'subject_id' is wheel ID.
PROJECT_LOAD_TUNEUP, //!< 'subject' is tuneup filename. This overwrites the auto-generated tuneup with the save.
PROJECT_RESET_TUNEUP, //!< 'subject' is empty. This resets the auto-generated tuneup to orig. values.
};

struct ModifyProjectRequest
Expand All @@ -238,6 +242,7 @@ struct ModifyProjectRequest
// Subject (either name or ID applies depending on type)
std::string mpr_subject; // addonpart
int mpr_subject_id = -1; // wheel, prop, flexbody, node
int mpr_value_int; // forced wheel side

// Protected state prevents addonparts from evaluating, which would undo user's selections.
bool mpr_subject_set_protected = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ void AddonPartUtility::ProcessTweakWheel()
data.twt_wheel_id = wheel_id;
data.twt_media[0] = m_context->getTokString(2);
if (m_context->isTokString(3)) { data.twt_media[1] = m_context->getTokString(3); }
if (m_context->isTokString(4)) { data.twt_side = (m_context->getTokString(4)[0] == 'l') ? RigDef::WheelSide::LEFT : RigDef::WheelSide::RIGHT; }
if (m_context->isTokString(4)) { data.twt_side = (m_context->getTokString(4)[0] == 'l') ? WheelSide::LEFT : WheelSide::RIGHT; }
if (m_context->isTokFloat(5)) { data.twt_rim_radius = m_context->getTokFloat(5); }
if (m_context->isTokFloat(6)) { data.twt_tire_radius = m_context->getTokFloat(6); }
m_tuneup->wheel_tweaks.insert(std::make_pair(wheel_id, data));
Expand Down
Loading

0 comments on commit c221bf8

Please sign in to comment.