Skip to content

Commit

Permalink
Tuning: fixed mesh RG of props/flexbodies in .addonpart
Browse files Browse the repository at this point in the history
Problem: if addonpart defines new prop or flexbody, the meshes are still searched in the mod's resource group. This is because the new elements are added as extra 'section' (Module) to the RigDef::Document so they're treated as any other.

Solution: add a `_mesh_rg_override` string field to RigDef::Prop/Flexbody (in RigDef_File.h) and make ActorSpawner respect it.
  • Loading branch information
ohlidalp committed Jan 9, 2024
1 parent b4e6299 commit 6e0bc5f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
10 changes: 6 additions & 4 deletions source/main/physics/ActorSpawner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1530,6 +1530,7 @@ void ActorSpawner::ProcessFlexbody(RigDef::Flexbody& def)

try
{
std::string mesh_rg = (def._mesh_rg_override != "") ? def._mesh_rg_override : m_actor->GetGfxActor()->GetResourceGroup();
auto* flexbody = m_flex_factory.CreateFlexBody(
(FlexbodyID_t)m_actor->m_gfx_actor->m_flexbodies.size(),
this->GetNodeIndexOrThrow(def.reference_node),
Expand All @@ -1539,7 +1540,7 @@ void ActorSpawner::ProcessFlexbody(RigDef::Flexbody& def)
TuneupUtil::getTweakedFlexbodyRotation(m_actor->getUsedTuneupEntry(), flexbody_id, def.rotation),
node_indices,
TuneupUtil::getTweakedFlexbodyMedia(m_actor->getUsedTuneupEntry(), flexbody_id, 0, def.mesh_name),
TuneupUtil::getTweakedFlexbodyMediaRG(m_actor, flexbody_id, 0)
TuneupUtil::getTweakedFlexbodyMediaRG(m_actor, flexbody_id, 0, mesh_rg)
);

if (flexbody == nullptr)
Expand Down Expand Up @@ -1623,26 +1624,27 @@ void ActorSpawner::ProcessProp(RigDef::Prop & def)
{
steering_wheel_offset = def.special_prop_dashboard.offset;
}
std::string media1_rg = (def._mesh_rg_override != "") ? def._mesh_rg_override : m_actor->GetGfxActor()->GetResourceGroup();
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;
prop.pp_media[1] = TuneupUtil::getTweakedPropMedia(m_actor->getUsedTuneupEntry(), prop_id, 1, def.special_prop_dashboard.mesh_name);
prop.pp_wheel_mesh_obj = new MeshObject(
prop.pp_media[1],
TuneupUtil::getTweakedPropMediaRG(m_actor, prop_id, 1),
TuneupUtil::getTweakedPropMediaRG(m_actor, prop_id, 1, media1_rg),
this->ComposeName("SteeringWheelPropEntity", prop_id),
prop.pp_wheel_scene_node
);
this->SetupNewEntity(prop.pp_wheel_mesh_obj->getEntity(), Ogre::ColourValue(0, 0.5, 0.5));
}

/* CREATE THE PROP */

std::string media0_rg = (def._mesh_rg_override != "") ? def._mesh_rg_override : m_actor->GetGfxActor()->GetResourceGroup();
prop.pp_scene_node = App::GetGfxScene()->GetSceneManager()->getRootSceneNode()->createChildSceneNode();
prop.pp_media[0] = TuneupUtil::getTweakedPropMedia(m_actor->getUsedTuneupEntry(), prop_id, 0, def.mesh_name);
prop.pp_mesh_obj = new MeshObject(//def.mesh_name, resource_group, instance_name, prop.pp_scene_node);
prop.pp_media[0],
TuneupUtil::getTweakedPropMediaRG(m_actor, prop_id, 1),
TuneupUtil::getTweakedPropMediaRG(m_actor, prop_id, 1, media0_rg),
this->ComposeName("PropEntity", prop_id),
prop.pp_scene_node);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ void AddonPartUtility::ProcessProp()
def.rotation.z = m_context->getTokFloat(8);

def.mesh_name = m_context->getTokString(9);
def._mesh_rg_override = m_addonpart_entry->resource_group;

m_module->props.push_back(def);
}
Expand Down Expand Up @@ -255,6 +256,7 @@ void AddonPartUtility::ProcessFlexbody()
def.rotation.z = m_context->getTokFloat(8);

def.mesh_name = m_context->getTokString(9);
def._mesh_rg_override = m_addonpart_entry->resource_group;

m_context->seekNextLine();

Expand Down
4 changes: 3 additions & 1 deletion source/main/resources/rig_def_fileformat/RigDef_File.h
Original file line number Diff line number Diff line change
Expand Up @@ -885,8 +885,9 @@ struct Flexbody
Ogre::Vector3 offset = Ogre::Vector3::ZERO;
Ogre::Vector3 rotation = Ogre::Vector3::ZERO;
Ogre::String mesh_name;
Ogre::String _mesh_rg_override; //!< Needed for addonparts
std::list<Animation> animations;
std::vector<Node::Range> node_list_to_import; //!< Node ranges are disallowed in fileformatversion >=450
std::vector<Node::Range> node_list_to_import;
std::vector<Node::Ref> node_list;
CameraSettings camera_settings;
};
Expand Down Expand Up @@ -1094,6 +1095,7 @@ struct Prop
Ogre::Vector3 offset = Ogre::Vector3::ZERO;
Ogre::Vector3 rotation = Ogre::Vector3::ZERO;
Ogre::String mesh_name;
Ogre::String _mesh_rg_override; //!< Needed for addonparts
std::list<Animation> animations;
CameraSettings camera_settings;
SpecialProp special = SpecialProp::NONE;
Expand Down
16 changes: 8 additions & 8 deletions source/main/resources/tuneup_fileformat/TuneupFileFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,20 +220,20 @@ std::string RoR::TuneupUtil::getTweakedPropMedia(CacheEntryPtr& tuneup_entry, Pr
? itor->second.tpt_media[media_idx] : orig_val;
}

std::string RoR::TuneupUtil::getTweakedPropMediaRG(ActorPtr& actor, PropID_t prop_id, int media_idx)
std::string RoR::TuneupUtil::getTweakedPropMediaRG(ActorPtr& actor, PropID_t prop_id, int media_idx, const std::string& orig_val)
{
// Check there's a tuneup at all
ROR_ASSERT(actor);
if (!actor->getUsedTuneupEntry())
return actor->GetGfxActor()->GetResourceGroup();
return orig_val;

// Check there's a tweak
TuneupDefPtr& doc = actor->getUsedTuneupEntry()->tuneup_def;
ROR_ASSERT(doc);
auto itor = doc->prop_tweaks.find(prop_id);
auto endi = doc->prop_tweaks.end();
if (itor == endi || itor->second.tpt_media[media_idx] == "")
return actor->GetGfxActor()->GetResourceGroup();
return orig_val;

// Find the tweak addonpart
CacheEntryPtr addonpart_entry = App::GetCacheSystem()->FindEntryByFilename(LT_AddonPart, /*partial:*/false, itor->second.tpt_origin);
Expand All @@ -242,7 +242,7 @@ std::string RoR::TuneupUtil::getTweakedPropMediaRG(ActorPtr& actor, PropID_t pro
else
{
LOG(fmt::format("[RoR|Tuneup] WARN Addonpart '{}' not found in modcache!", itor->second.tpt_origin));
return actor->GetGfxActor()->GetResourceGroup();
return orig_val;
}
}

Expand Down Expand Up @@ -301,20 +301,20 @@ std::string RoR::TuneupUtil::getTweakedFlexbodyMedia(CacheEntryPtr& tuneup_entry
? itor->second.tft_media : orig_val;
}

std::string RoR::TuneupUtil::getTweakedFlexbodyMediaRG(ActorPtr& actor, FlexbodyID_t flexbody_id, int media_idx)
std::string RoR::TuneupUtil::getTweakedFlexbodyMediaRG(ActorPtr& actor, FlexbodyID_t flexbody_id, int media_idx, const std::string& orig_val)
{
// Check there's a tuneup at all
ROR_ASSERT(actor);
if (!actor->getUsedTuneupEntry())
return actor->GetGfxActor()->GetResourceGroup();
return orig_val;

// Check there's a tweak
TuneupDefPtr& doc = actor->getUsedTuneupEntry()->tuneup_def;
ROR_ASSERT(doc);
auto itor = doc->flexbody_tweaks.find(flexbody_id);
auto endi = doc->flexbody_tweaks.end();
if (itor == endi || itor->second.tft_media == "")
return actor->GetGfxActor()->GetResourceGroup();
return orig_val;

// Find the tweak addonpart
CacheEntryPtr addonpart_entry = App::GetCacheSystem()->FindEntryByFilename(LT_AddonPart, /*partial:*/false, itor->second.tft_origin);
Expand All @@ -323,7 +323,7 @@ std::string RoR::TuneupUtil::getTweakedFlexbodyMediaRG(ActorPtr& actor, Flexbody
else
{
LOG(fmt::format("[RoR|Tuneup] WARN Addonpart '{}' not found in modcache!", itor->second.tft_origin));
return actor->GetGfxActor()->GetResourceGroup();
return orig_val;
}
}

Expand Down
4 changes: 2 additions & 2 deletions source/main/resources/tuneup_fileformat/TuneupFileFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class TuneupUtil
static Ogre::Vector3 getTweakedPropOffset(CacheEntryPtr& tuneup_entry, PropID_t prop_id, Ogre::Vector3 orig_val);
static Ogre::Vector3 getTweakedPropRotation(CacheEntryPtr& tuneup_entry, PropID_t prop_id, Ogre::Vector3 orig_val);
static std::string getTweakedPropMedia(CacheEntryPtr& tuneup_entry, PropID_t prop_id, int media_idx, const std::string& orig_val);
static std::string getTweakedPropMediaRG(ActorPtr& actor, PropID_t prop_id, int media_idx);
static std::string getTweakedPropMediaRG(ActorPtr& actor, PropID_t prop_id, int media_idx, const std::string& orig_val);
/// @}

/// @name Flexbody helpers
Expand All @@ -172,7 +172,7 @@ class TuneupUtil
static Ogre::Vector3 getTweakedFlexbodyOffset(CacheEntryPtr& tuneup_entry, FlexbodyID_t flexbody_id, Ogre::Vector3 orig_val);
static Ogre::Vector3 getTweakedFlexbodyRotation(CacheEntryPtr& tuneup_entry, FlexbodyID_t flexbody_id, Ogre::Vector3 orig_val);
static std::string getTweakedFlexbodyMedia(CacheEntryPtr& tuneup_entry, FlexbodyID_t flexbody_id, int media_idx, const std::string& orig_val);
static std::string getTweakedFlexbodyMediaRG(ActorPtr& actor, FlexbodyID_t flexbody_id, int media_idx);
static std::string getTweakedFlexbodyMediaRG(ActorPtr& actor, FlexbodyID_t flexbody_id, int media_idx, const std::string& orig_val);
/// @}

private:
Expand Down

0 comments on commit 6e0bc5f

Please sign in to comment.