Skip to content

Commit

Permalink
Actors: grouped/renamed scene nodes for nicer inspector view.
Browse files Browse the repository at this point in the history
Prettier and more uniform object names - Helper func `ActorSpawner::ComposeName()` is now smarter, outputs nicer IDs and is used even more.

This has no effect on rendering, it just helps users to diagnose the scene graph using the inspector script.
  • Loading branch information
ohlidalp committed Feb 12, 2024
1 parent 18b2751 commit 44b991c
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 75 deletions.
132 changes: 66 additions & 66 deletions source/main/physics/ActorSpawner.cpp

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions source/main/physics/ActorSpawner.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ class ActorSpawner
void SetBeamDeformationThreshold(beam_t & beam, std::shared_ptr<RigDef::BeamDefaults> beam_defaults);
void ValidateRotator(int id, int axis1, int axis2, NodeNum_t *nodes1, NodeNum_t *nodes2);

/// Creates name containing actor ID token, i.e. "Object_1@Actor_2"
std::string ComposeName(const char* base, int number);
/// Creates name containing actor ID token, i.e. "Object#1 (filename.truck [Instance ID 1])".
std::string ComposeName(const std::string& object, int number = -1);

/// Finds wheel with given axle nodes and returns it's index.
/// @param _out_axle_wheel Index of the found wheel.
Expand Down Expand Up @@ -486,12 +486,18 @@ class ActorSpawner
std::map<std::string, CustomMaterial> m_material_substitutions; //!< Maps original material names (shared) to their actor-specific substitutes; There's 1 substitute per 1 material, regardless of user count.
std::map<std::string, Ogre::MaterialPtr> m_managed_materials;
Ogre::MaterialPtr m_managedmat_placeholder_template; //!< An 'error marker' material (bright magenta) to generate managedmaterial placeholders from.
Ogre::SceneNode* m_particles_parent_scenenode;
Ogre::MaterialPtr m_cab_trans_material;
Ogre::MaterialPtr m_simple_material_base;
RoR::Renderdash* m_oldstyle_renderdash;
CustomMaterial::MirrorPropType m_curr_mirror_prop_type;
Ogre::SceneNode* m_curr_mirror_prop_scenenode;
// Grouping nodes for diagnostics:
Ogre::SceneNode* m_actor_grouping_scenenode = nullptr; //!< Topmost common parent; this isn't used for moving things, just helps developers inspect the scene graph.
Ogre::SceneNode* m_wheels_parent_scenenode = nullptr; //!< this isn't used for moving/hiding things, just helps developers inspect the scene graph.
Ogre::SceneNode* m_props_parent_scenenode = nullptr; //!< this isn't used for moving/hiding things, just helps developers inspect the scene graph.
Ogre::SceneNode* m_flexbodies_parent_scenenode = nullptr; //!< this isn't used for moving/hiding things, just helps developers inspect the scene graph.
Ogre::SceneNode* m_flares_parent_scenenode = nullptr; //!< this isn't used for moving/hiding things, just helps developers inspect the scene graph.
Ogre::SceneNode* m_particles_parent_scenenode = nullptr; //!< this isn't used for moving/hiding things, just helps developers inspect the scene graph.
/// @}
};

Expand Down
9 changes: 8 additions & 1 deletion source/main/physics/ActorSpawnerFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,14 @@ void ActorSpawner::ProcessNewActor(ActorPtr actor, ActorSpawnRequest rq, RigDef:
m_actor = actor;
m_file = def;

m_particles_parent_scenenode = App::GetGfxScene()->GetSceneManager()->getRootSceneNode()->createChildSceneNode();
// Under OGRE, every scenenode must have globally unique name.
m_actor_grouping_scenenode = App::GetGfxScene()->GetSceneManager()->getRootSceneNode()->createChildSceneNode(this->ComposeName("Actor"));
m_particles_parent_scenenode = m_actor_grouping_scenenode->createChildSceneNode(this->ComposeName("Particles"));
m_wheels_parent_scenenode = m_actor_grouping_scenenode->createChildSceneNode(this->ComposeName("Wheels"));
m_flexbodies_parent_scenenode = m_actor_grouping_scenenode->createChildSceneNode(this->ComposeName("Flexbodies"));
m_props_parent_scenenode = m_actor_grouping_scenenode->createChildSceneNode(this->ComposeName("Props"));
m_flares_parent_scenenode = m_actor_grouping_scenenode->createChildSceneNode(this->ComposeName("Flares"));

m_spawn_position = rq.asr_position;
m_current_keyword = RigDef::Keyword::INVALID;
m_wing_area = 0.f;
Expand Down
10 changes: 6 additions & 4 deletions source/main/physics/flex/FlexFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,21 @@ FlexMeshWheel* FlexFactory::CreateFlexMeshWheel(
const ActorPtr& actor = m_rig_spawner->GetActor();

// Load+instantiate static mesh for rim (may be located in addonpart ZIP-bundle!)
const std::string rim_entity_name = m_rig_spawner->ComposeName("MeshWheelRim", wheel_index);
const std::string rim_entity_name = m_rig_spawner->ComposeName("rim @ *wheel*", wheel_index);
Ogre::Entity* rim_prop_entity = App::GetGfxScene()->GetSceneManager()->createEntity(rim_entity_name, rim_mesh_name, rim_mesh_rg);
m_rig_spawner->SetupNewEntity(rim_prop_entity, Ogre::ColourValue(0, 0.5, 0.8));

// Create dynamic mesh for tire (always located in the actor resource group)
const std::string tire_mesh_name = m_rig_spawner->ComposeName("MWheelTireMesh", wheel_index);
const std::string tire_mesh_name = m_rig_spawner->ComposeName("tire @ *wheel*", wheel_index);
FlexMeshWheel* flex_mesh_wheel = new FlexMeshWheel(
rim_prop_entity, m_rig_spawner->GetActor()->GetGfxActor(), axis_node_1_index, axis_node_2_index, nstart, nrays,
rim_prop_entity,
m_rig_spawner->m_wheels_parent_scenenode->createChildSceneNode(m_rig_spawner->ComposeName("*wheel*", wheel_index)), // Friend access
m_rig_spawner->GetActor()->GetGfxActor(), axis_node_1_index, axis_node_2_index, nstart, nrays,
tire_mesh_name, actor->GetGfxActor()->GetResourceGroup(),
tire_material_name, tire_material_rg, rim_radius, rim_reverse);

// Instantiate the dynamic tire mesh (always located in the actor resource group)
const std::string tire_instance_name = m_rig_spawner->ComposeName("MWheelTireEntity", wheel_index);
const std::string tire_instance_name = m_rig_spawner->ComposeName("tire entity @ *wheel*", wheel_index);
Ogre::Entity *tire_entity = App::GetGfxScene()->GetSceneManager()->createEntity(
tire_instance_name, tire_mesh_name, actor->GetGfxActor()->GetResourceGroup());
m_rig_spawner->SetupNewEntity(tire_entity, Ogre::ColourValue(0, 0.5, 0.8));
Expand Down
3 changes: 2 additions & 1 deletion source/main/physics/flex/FlexMeshWheel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ using namespace RoR;

FlexMeshWheel::FlexMeshWheel(
Ogre::Entity* rim_prop_entity,
Ogre::SceneNode* rim_scene_node,
RoR::GfxActor* gfx_actor,
int axis_node_1_index,
int axis_node_2_index,
Expand All @@ -54,7 +55,7 @@ FlexMeshWheel::FlexMeshWheel(
, m_rim_radius(rimradius)
{
m_rim_entity = rim_prop_entity;
m_rim_scene_node=App::GetGfxScene()->GetSceneManager()->getRootSceneNode()->createChildSceneNode();
m_rim_scene_node = rim_scene_node;
m_rim_scene_node->attachObject(m_rim_entity);

// Create the tire mesh via the MeshManager
Expand Down
1 change: 1 addition & 0 deletions source/main/physics/flex/FlexMeshWheel.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class FlexMeshWheel: public Flexable

FlexMeshWheel( // Use FlexFactory
Ogre::Entity* rim_prop_entity,
Ogre::SceneNode* rim_scene_node,
RoR::GfxActor* gfx_actor,
int axis_node_1_index,
int axis_node_2_index,
Expand Down

0 comments on commit 44b991c

Please sign in to comment.