Skip to content

Commit

Permalink
Added 'remove_flexbody' to .tuneup format + GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
ohlidalp committed Oct 30, 2023
1 parent a3f6db5 commit e135dfe
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 28 deletions.
40 changes: 40 additions & 0 deletions source/main/gui/panels/GUI_TopMenubar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "Actor.h"
#include "ActorManager.h"
#include "CameraManager.h"
#include "FlexBody.h"
#include "GameContext.h"
#include "GfxScene.h"
#include "GUIManager.h"
Expand Down Expand Up @@ -1545,6 +1546,45 @@ void TopMenubar::Update()
ImGui::PopID(); // meshname
}
}

ImGui::Separator(); // Ditto for flexbodies

ImGui::TextDisabled(_LC("TopMenubar", "Default flexbodies:"));
// Draw removed flexbodies
for (const std::string& meshname: tuneup_entry->tuneup_def->remove_flexbodies)
{
ImGui::PushID(meshname.c_str());

bool flexbEnabled = false;
if (ImGui::Checkbox(meshname.c_str(), &flexbEnabled))
{
ModifyProjectRequest* req = new ModifyProjectRequest();
req->mpr_type = ModifyProjectRequestType::TUNEUP_REMOVE_FLEXBODY_RESET;
req->mpr_subject = meshname;
req->mpr_target_actor = actor;
App::GetGameContext()->PushMessage(Message(MSG_EDI_MODIFY_PROJECT_REQUESTED, req));
}

ImGui::PopID(); // meshname
}
// Then draw existing flexbodies
for (FlexBody* flexbody: actor->GetGfxActor()->GetFlexbodies())
{
std::string meshname = flexbody->getOrigMeshName();
ImGui::PushID(meshname.c_str());

bool propEnabled = true;
if (ImGui::Checkbox(meshname.c_str(), &propEnabled))
{
ModifyProjectRequest* req = new ModifyProjectRequest();
req->mpr_type = ModifyProjectRequestType::TUNEUP_REMOVE_FLEXBODY_SET;
req->mpr_subject = meshname;
req->mpr_target_actor = actor;
App::GetGameContext()->PushMessage(Message(MSG_EDI_MODIFY_PROJECT_REQUESTED, req));
}

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

Expand Down
53 changes: 31 additions & 22 deletions source/main/physics/ActorSpawner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1487,6 +1487,14 @@ void ActorSpawner::ProcessSubmesh(RigDef::Submesh & def)

void ActorSpawner::ProcessFlexbody(RigDef::Flexbody& def)
{
// Check if disabled by .tuneup mod.
if (m_actor->m_used_tuneup_entry &&
m_actor->m_used_tuneup_entry->tuneup_def &&
m_actor->m_used_tuneup_entry->tuneup_def->remove_flexbodies.count(def.mesh_name) > 0)
{
return;
}

// Collect nodes
std::vector<unsigned int> node_indices;
bool nodes_found = true;
Expand Down Expand Up @@ -1524,8 +1532,9 @@ void ActorSpawner::ProcessFlexbody(RigDef::Flexbody& def)

try
{
std::string resource_group = (m_current_module->origin_addonpart) ? m_current_module->origin_addonpart->resource_group : m_custom_resource_group;
auto* flexbody = m_flex_factory.CreateFlexBody(
&def, reference_node, x_axis_node, y_axis_node, rot, node_indices, m_custom_resource_group);
&def, reference_node, x_axis_node, y_axis_node, rot, node_indices, resource_group);

if (flexbody == nullptr)
return; // Error already logged
Expand All @@ -1547,7 +1556,7 @@ void ActorSpawner::ProcessMinimass(RigDef::Minimass & def)
m_actor->ar_minimass_skip_loaded_nodes = (def.option == RigDef::MinimassOption::l_SKIP_LOADED);
}

void ActorSpawner::ProcessProp(RigDef::Prop & def, const std::string& override_rg /*= ""*/)
void ActorSpawner::ProcessProp(RigDef::Prop & def)
{
// Check if removed via .tuneup
CacheEntryPtr& tuneup_entry = m_actor->getUsedTuneup();
Expand All @@ -1556,6 +1565,7 @@ void ActorSpawner::ProcessProp(RigDef::Prop & def, const std::string& override_r
LOG(fmt::format("{}: Prop '{}' removed by tuneup '{}'", m_actor->ar_filename, def.mesh_name, tuneup_entry->fname));
return;
}
std::string resource_group = (m_current_module->origin_addonpart) ? m_current_module->origin_addonpart->resource_group : m_custom_resource_group;

RoR::Prop prop;
int prop_index = static_cast<int>(m_actor->m_gfx_actor->m_props.size());
Expand Down Expand Up @@ -1610,8 +1620,7 @@ void ActorSpawner::ProcessProp(RigDef::Prop & def, const std::string& override_r
prop.pp_wheel_rot_degree = def.special_prop_dashboard.rotation_angle;
prop.pp_wheel_scene_node = App::GetGfxScene()->GetSceneManager()->getRootSceneNode()->createChildSceneNode();
prop.pp_wheel_pos = steering_wheel_offset;
const std::string instance_name = this->ComposeName("SteeringWheelPropEntity", prop_index);
const std::string& resource_group = (override_rg != "") ? override_rg : m_custom_resource_group;
std::string instance_name = this->ComposeName("SteeringWheelPropEntity", prop_index);
prop.pp_wheel_mesh_obj = new MeshObject(
def.special_prop_dashboard.mesh_name,
resource_group,
Expand All @@ -1625,7 +1634,7 @@ void ActorSpawner::ProcessProp(RigDef::Prop & def, const std::string& override_r

prop.pp_scene_node = App::GetGfxScene()->GetSceneManager()->getRootSceneNode()->createChildSceneNode();
const std::string instance_name = this->ComposeName("PropEntity", prop_index);
prop.pp_mesh_obj = new MeshObject(def.mesh_name, m_custom_resource_group, instance_name, prop.pp_scene_node);
prop.pp_mesh_obj = new MeshObject(def.mesh_name, resource_group, instance_name, prop.pp_scene_node);

prop.pp_mesh_obj->setCastShadows(true); // Orig code {{ prop.pp_mesh_obj->setCastShadows(shadowmode != 0); }}, shadowmode has default value 1 and changes with undocumented directive 'set_shadows'

Expand Down Expand Up @@ -2172,7 +2181,7 @@ void ActorSpawner::ProcessFlare2(RigDef::Flare2 & def)
}
}

Ogre::MaterialPtr material = this->FindOrCreateCustomizedMaterial(material_name);
Ogre::MaterialPtr material = this->FindOrCreateCustomizedMaterial(material_name, m_custom_resource_group);
if (!material.isNull())
{
flare.bbs->setMaterial(material);
Expand Down Expand Up @@ -2294,22 +2303,22 @@ void ActorSpawner::ProcessManagedMaterial(RigDef::ManagedMaterial & def)
}

// Check all textures exist
Ogre::ResourceGroupManager& rgm = Ogre::ResourceGroupManager::getSingleton();
if (!rgm.resourceExists(m_custom_resource_group, def.diffuse_map))
std::string resource_group = (m_current_module->origin_addonpart) ? m_current_module->origin_addonpart->resource_group : m_custom_resource_group;
if (!Ogre::ResourceGroupManager::getSingleton().resourceExists(resource_group, def.diffuse_map))
{
this->AddMessage(Message::TYPE_WARNING, "Skipping managed material, missing texture file: " + def.diffuse_map);
return;
}

if (def.damaged_diffuse_map != "" &&
!rgm.resourceExists(m_custom_resource_group, def.damaged_diffuse_map))
!Ogre::ResourceGroupManager::getSingleton().resourceExists(resource_group, def.damaged_diffuse_map))
{
this->AddMessage(Message::TYPE_WARNING, "Damage texture not found: " + def.damaged_diffuse_map);
def.damaged_diffuse_map = "";
}

if (def.specular_map != "" &&
!rgm.resourceExists(m_custom_resource_group, def.specular_map))
!Ogre::ResourceGroupManager::getSingleton().resourceExists(resource_group, def.specular_map))
{
this->AddMessage(Message::TYPE_WARNING, "Specular texture not found: " + def.specular_map);
def.specular_map = "";
Expand All @@ -2318,9 +2327,9 @@ void ActorSpawner::ProcessManagedMaterial(RigDef::ManagedMaterial & def)
// Create temporary placeholder
// This is necessary to load meshes with original material names (= unchanged managed mat names)
// - if not found, OGRE substitutes them with 'BaseWhite' which breaks subsequent processing.
if (Ogre::MaterialManager::getSingleton().getByName(def.name, m_custom_resource_group).isNull())
if (Ogre::MaterialManager::getSingleton().getByName(def.name, resource_group).isNull())
{
m_placeholder_managedmat->clone(def.name, /*changeGroup=*/true, m_custom_resource_group);
m_placeholder_managedmat->clone(def.name, /*changeGroup=*/true, resource_group);
}

std::string custom_name = def.name + ACTOR_ID_TOKEN + TOSTRING(m_actor->ar_instance_id);
Expand Down Expand Up @@ -5922,7 +5931,7 @@ void ActorSpawner::AddExhaust(
}
exhaust.smoker->setVisibilityFlags(DEPTHMAP_DISABLED); // Disable particles in depthmap

Ogre::MaterialPtr mat = this->FindOrCreateCustomizedMaterial("tracks/Smoke");
Ogre::MaterialPtr mat = this->FindOrCreateCustomizedMaterial("tracks/Smoke", m_custom_resource_group);
exhaust.smoker->setMaterialName(mat->getName(), mat->getGroup());

exhaust.smokeNode = m_particles_parent_scenenode->createChildSceneNode();
Expand Down Expand Up @@ -6394,7 +6403,7 @@ RigDef::VideoCamera* ActorSpawner::FindVideoCameraByMaterial(std::string const &
return nullptr;
}

Ogre::MaterialPtr ActorSpawner::FindOrCreateCustomizedMaterial(std::string mat_lookup_name)
Ogre::MaterialPtr ActorSpawner::FindOrCreateCustomizedMaterial(const std::string& mat_lookup_name, const std::string& mat_lookup_rg)
{
try
{
Expand All @@ -6416,7 +6425,7 @@ Ogre::MaterialPtr ActorSpawner::FindOrCreateCustomizedMaterial(std::string mat_l
static int mirror_counter = 0;
const std::string new_mat_name = this->ComposeName("RenderMaterial", mirror_counter);
++mirror_counter;
lookup_entry.material = Ogre::MaterialManager::getSingleton().getByName("mirror")->clone(new_mat_name, true, m_custom_resource_group);
lookup_entry.material = Ogre::MaterialManager::getSingleton().getByName("mirror")->clone(new_mat_name, true, mat_lookup_rg);
// Special case - register under generated name. This is because all mirrors use the same material 'mirror'
m_material_substitutions.insert(std::make_pair(new_mat_name, lookup_entry));
return lookup_entry.material; // Done!
Expand All @@ -6441,7 +6450,7 @@ Ogre::MaterialPtr ActorSpawner::FindOrCreateCustomizedMaterial(std::string mat_l
{
lookup_entry.video_camera_def = videocam_def;
const std::string video_mat_name = this->ComposeName(videocam_def->material_name.c_str(), 0);
lookup_entry.material = video_mat_shared->clone(video_mat_name, true, m_custom_resource_group);
lookup_entry.material = video_mat_shared->clone(video_mat_name, true, mat_lookup_rg);
m_material_substitutions.insert(std::make_pair(mat_lookup_name, lookup_entry));
return lookup_entry.material; // Done!
}
Expand Down Expand Up @@ -6474,7 +6483,7 @@ Ogre::MaterialPtr ActorSpawner::FindOrCreateCustomizedMaterial(std::string mat_l
{
std::stringstream name_buf;
name_buf << skin_mat->getName() << ACTOR_ID_TOKEN << m_actor->ar_instance_id;
lookup_entry.material = skin_mat->clone(name_buf.str(), /*changeGroup=*/true, m_custom_resource_group);
lookup_entry.material = skin_mat->clone(name_buf.str(), /*changeGroup=*/true, mat_lookup_rg);
m_material_substitutions.insert(std::make_pair(mat_lookup_name, lookup_entry));
return lookup_entry.material;
}
Expand All @@ -6500,7 +6509,7 @@ Ogre::MaterialPtr ActorSpawner::FindOrCreateCustomizedMaterial(std::string mat_l
else
{
// Generate new substitute
Ogre::MaterialPtr orig_mat = Ogre::MaterialManager::getSingleton().getByName(mat_lookup_name, m_custom_resource_group);
Ogre::MaterialPtr orig_mat = Ogre::MaterialManager::getSingleton().getByName(mat_lookup_name, mat_lookup_rg);
if (orig_mat.isNull())
{
std::stringstream buf;
Expand All @@ -6511,7 +6520,7 @@ Ogre::MaterialPtr ActorSpawner::FindOrCreateCustomizedMaterial(std::string mat_l

std::stringstream name_buf;
name_buf << orig_mat->getName() << ACTOR_ID_TOKEN << m_actor->ar_instance_id;
lookup_entry.material = orig_mat->clone(name_buf.str(), true, m_custom_resource_group);
lookup_entry.material = orig_mat->clone(name_buf.str(), true, mat_lookup_rg);
}

// Finally, query texture replacements - .skin and builtins
Expand Down Expand Up @@ -6548,7 +6557,7 @@ Ogre::MaterialPtr ActorSpawner::FindOrCreateCustomizedMaterial(std::string mat_l
if (query != end)
{
// Skin has replacement for this texture
if (m_actor->m_used_skin_entry->resource_group != m_custom_resource_group) // The skin comes from a SkinZip bundle (different resource group)
if (m_actor->m_used_skin_entry->resource_group != mat_lookup_rg) // The skin comes from a SkinZip bundle (different resource group)
{
Ogre::TexturePtr tex = Ogre::TextureManager::getSingleton().getByName(
query->second, m_actor->m_used_skin_entry->resource_group);
Expand Down Expand Up @@ -6649,7 +6658,7 @@ void ActorSpawner::SetupNewEntity(Ogre::Entity* ent, Ogre::ColourValue simple_co

if (!subent->getMaterial().isNull())
{
Ogre::MaterialPtr own_mat = this->FindOrCreateCustomizedMaterial(subent->getMaterialName());
Ogre::MaterialPtr own_mat = this->FindOrCreateCustomizedMaterial(subent->getMaterialName(), subent->getSubMesh()->parent->getGroup());
if (!own_mat.isNull())
{
subent->setMaterial(own_mat);
Expand Down Expand Up @@ -6904,7 +6913,7 @@ void ActorSpawner::CreateVideoCamera(RigDef::VideoCamera* def)
{
RoR::VideoCamera vcam;

vcam.vcam_material = this->FindOrCreateCustomizedMaterial(def->material_name);
vcam.vcam_material = this->FindOrCreateCustomizedMaterial(def->material_name, m_custom_resource_group);
if (vcam.vcam_material.isNull())
{
this->AddMessage(Message::TYPE_ERROR, "Failed to create VideoCamera with material: " + def->material_name);
Expand Down
7 changes: 4 additions & 3 deletions source/main/physics/ActorSpawner.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class ActorSpawner
void ProcessNode(RigDef::Node & def);
void ProcessParticle(RigDef::Particle & def);
void ProcessPistonprop(RigDef::Pistonprop & def);
void ProcessProp(RigDef::Prop & def, const std::string& override_rg = ""); //!< Resource group override is used with addonparts
void ProcessProp(RigDef::Prop & def); //!< Resource group override is used with addonparts
void ProcessRailGroup(RigDef::RailGroup & def);
void ProcessRopable(RigDef::Ropable & def);
void ProcessRope(RigDef::Rope & def);
Expand Down Expand Up @@ -374,7 +374,7 @@ class ActorSpawner
void CreateBeamVisuals(beam_t const& beam, int beam_index, bool visible, std::shared_ptr<RigDef::BeamDefaults> const& beam_defaults, std::string material_override="");
void CreateWheelSkidmarks(unsigned int wheel_index);
void FinalizeGfxSetup();
Ogre::MaterialPtr FindOrCreateCustomizedMaterial(std::string orig_name);
Ogre::MaterialPtr FindOrCreateCustomizedMaterial(const std::string& mat_lookup_name, const std::string& mat_lookup_rg);
Ogre::MaterialPtr CreateSimpleMaterial(Ogre::ColourValue color);
Ogre::ParticleSystem* CreateParticleSystem(std::string const & name, std::string const & template_name);
RigDef::MaterialFlareBinding* FindFlareBindingForMaterial(std::string const & material_name); //!< Returns NULL if none found
Expand Down Expand Up @@ -463,7 +463,8 @@ class ActorSpawner
int m_first_wing_index;
std::vector<CabTexcoord> m_oldstyle_cab_texcoords;
std::vector<CabSubmesh> m_oldstyle_cab_submeshes;
RigDef::Keyword m_current_keyword; //!< For error reports
RigDef::Keyword m_current_keyword; //!< For error reports
std::shared_ptr<RigDef::Document::Module> m_current_module; //!< For resolving addonparts
std::map<Ogre::String, unsigned int> m_named_nodes;
/// @}

Expand Down
2 changes: 2 additions & 0 deletions source/main/physics/ActorSpawnerFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ using namespace RoR;
this->SetCurrentKeyword(_KEYWORD_); \
for (auto& m: m_selected_modules) \
{ \
m_current_module = m; \
for (auto& entry: m->_FIELD_) \
{ \
try { \
Expand All @@ -50,6 +51,7 @@ using namespace RoR;
this->HandleException(); \
} \
} \
m_current_module.reset(); \
} \
this->SetCurrentKeyword(RigDef::Keyword::INVALID); \
}
Expand Down
10 changes: 10 additions & 0 deletions source/main/resources/CacheSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,16 @@ void CacheSystem::ModifyProject(ModifyProjectRequest* request)
// Erase the prop from 'remove_props' in the TuneupDef document.
tuneup_entry->tuneup_def->remove_props.erase(request->mpr_subject);
break;

case ModifyProjectRequestType::TUNEUP_REMOVE_FLEXBODY_SET:
// Add the flexbody to the 'remove_flexbodies' in TuneupDef document.
tuneup_entry->tuneup_def->remove_flexbodies.insert(request->mpr_subject);
break;

case ModifyProjectRequestType::TUNEUP_REMOVE_FLEXBODY_RESET:
// Erase the flexbody from 'remove_flexbodies' in the TuneupDef document.
tuneup_entry->tuneup_def->remove_flexbodies.erase(request->mpr_subject);
break;

default:
break;
Expand Down
2 changes: 2 additions & 0 deletions source/main/resources/CacheSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ enum class ModifyProjectRequestType
TUNEUP_USE_ADDONPART_RESET,
TUNEUP_REMOVE_PROP_SET,
TUNEUP_REMOVE_PROP_RESET,
TUNEUP_REMOVE_FLEXBODY_SET,
TUNEUP_REMOVE_FLEXBODY_RESET,
};

struct ModifyProjectRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,10 @@ void AddonPartParser::ProcessFlexbody()
return;
}

def.reference_node = Node::Ref(m_context->getStringData(0), (unsigned int)m_context->getTokFloat(0), 0, 0);
def.x_axis_node = Node::Ref(m_context->getTokString(1), (unsigned int)m_context->getTokFloat(1), 0, 0);
def.y_axis_node = Node::Ref(m_context->getTokString(2), (unsigned int)m_context->getTokFloat(2), 0, 0);
int importflags = Node::Ref::REGULAR_STATE_IS_VALID | Node::Ref::REGULAR_STATE_IS_NUMBERED;
def.reference_node = Node::Ref("", (unsigned int)m_context->getTokFloat(0), importflags, 0);
def.x_axis_node = Node::Ref("", (unsigned int)m_context->getTokFloat(1), importflags, 0);
def.y_axis_node = Node::Ref("", (unsigned int)m_context->getTokFloat(2), importflags, 0);

def.offset.x = m_context->getTokFloat(3);
def.offset.y = m_context->getTokFloat(4);
Expand Down
Loading

0 comments on commit e135dfe

Please sign in to comment.