esp::assets::ResourceManager class

Singleton class responsible for loading and managing common simulator assets such as meshes, textures, and materials.

Public types

using DrawableGroup = gfx::DrawableGroup
Stores references to a set of drawable elements.
using Importer = Mn::Trade::AbstractImporter
Convenience typedef for Importer class.

Constructors, destructors, conversion operators

ResourceManager(std::shared_ptr<metadata::MetadataMediator> _metadataMediator) explicit
Constructor.
~ResourceManager()
Destructor.

Public functions

auto getCreateRenderer() const -> bool
Whether the renderer should be created or not.
void buildImporters()
This function will build the various Magnum importers used by the system.
void initDefaultPrimAttributes()
Build default primitive attribute files and synthesize an object of each type.
void initPhysicsManager(std::shared_ptr<physics::PhysicsManager>& physicsManager, scene::SceneNode* parent, const std::shared_ptr<metadata::attributes::PhysicsManagerAttributes>& physicsManagerAttributes)
Instantiate, or reinstantiate, PhysicsManager defined by passed attributes.
void loadAllIBLAssets()
called after MM is set or reset, go through and load/generate IBL assets that have not already been loaded. Will not reload assets already loaded.
auto getSemanticScene() -> std::shared_ptr<scene::SemanticScene>
Return the currently loaded esp::scene::SemanticScene .
auto getSemanticSceneColormap() const -> const std::vector<Mn::Vector3ub>&
Return a view of the currently set Semantic scene colormap.
void buildSemanticColorMap()
Build semanticColorMapBeingUsed_ holding the semantic colors defined from a semantic scene descriptor, by iterating through the objects and mapping their color values to their semantic ids.
void buildSemanticColorAsIntMap()
Build semanticColorAsInt_ (array of colors as integers) from the current semanticColorMapBeingUsed_ map. The semanticColorAsInt_ is used when building the color matrix for conversion of colors found in semantic textures to their semantic IDs. When semantic textures are preprocessed, this will not need to be performed.
auto convertRGBToSemanticId(const Mn::ImageView2D& srcImage, Cr::Containers::Array<Mn::UnsignedShort>& clrToSemanticId) -> Mn::Image2D
Remap a semantic annotation texture to have the semantic IDs per pxl.
auto semanticSceneExists() const -> bool
check if the esp::scene::SemanticScene exists.
auto loadSemanticScene(const std::shared_ptr<metadata::attributes::SemanticAttributes>& semanticAttr, const std::string& activeSceneName) -> bool
Load semantic scene data from descriptor file and metadata specified in semanticAttr , for the passed activeSceneName .
auto loadStage(const std::shared_ptr<metadata::attributes::StageAttributes>& stageAttributes, const std::shared_ptr<const metadata::attributes::SceneObjectInstanceAttributes>& stageInstanceAttributes, const std::shared_ptr<physics::PhysicsManager>& _physicsManager, esp::scene::SceneManager* sceneManagerPtr, std::vector<int>& activeSceneIDs) -> bool
Load a scene mesh and add it to the specified DrawableGroup as a child of the specified scene::SceneNode.
template<class T>
auto buildStageCollisionMeshGroup(const std::string& filename, std::vector<CollisionMeshData>& meshGroup) -> bool
Construct scene collision mesh group based on name and type of scene.
auto instantiateAssetsOnDemand(const std::shared_ptr<metadata::attributes::ObjectAttributes>& ObjectAttributes) -> bool
Load/instantiate any required render and collision assets for an object, if they do not already exist in resourceDict_ or collisionMeshGroups_, respectively. Assumes valid render and collisions asset handles have been specified (This is checked/verified during registration.)
auto getCollisionMesh(const std::string& collisionAssetHandle) const -> const std::vector<assets::CollisionMeshData>&
Getter for all assets::CollisionMeshData associated with the particular asset.
auto getAssetAttributesManager() const -> std::shared_ptr<metadata::managers::AssetAttributesManager>
Return manager for construction and access to asset attributes.
auto getLightLayoutAttributesManager() const -> std::shared_ptr<metadata::managers::LightLayoutAttributesManager>
Return manager for construction and access to light and lighting layout attributes.
auto getAOAttributesManager() const -> std::shared_ptr<metadata::managers::AOAttributesManager>
Return manager for construction and access to articulated object attributes.
auto getObjectAttributesManager() const -> std::shared_ptr<metadata::managers::ObjectAttributesManager>
Return manager for construction and access to object attributes.
auto getPhysicsAttributesManager() const -> std::shared_ptr<metadata::managers::PhysicsAttributesManager>
Return manager for construction and access to physics world attributes.
auto getSceneInstanceAttributesManager() const -> std::shared_ptr<metadata::managers::SceneInstanceAttributesManager>
Return manager for construction and access to scene instance attributes.
auto getStageAttributesManager() const -> std::shared_ptr<metadata::managers::StageAttributesManager>
Return manager for construction and access to stage attributes.
void setMetadataMediator(std::shared_ptr<metadata::MetadataMediator> MM)
Set a reference to the current metadataMediator_. Perform any initialization that may be required when metadataMediator_ is changed.
auto getMeshMetaData(const std::string& metaDataName) const -> const MeshMetaData&
Retrieve the meta data for a particular asset.
auto getLightSetup(const Mn::ResourceKey& key = Mn::ResourceKey{DEFAULT_LIGHTING_KEY}) -> Mn::Resource<gfx::LightSetup>
Get a named esp::gfx::LightSetup.
void setLightSetup(gfx::LightSetup setup, const Mn::ResourceKey& key = Mn::ResourceKey{ DEFAULT_LIGHTING_KEY})
Set a named esp::gfx::LightSetup.
auto createJoinedCollisionMesh(const std::string& filename) const -> std::unique_ptr<MeshData>
Construct a unified MeshData from a loaded asset's collision meshes.
auto createJoinedSemanticCollisionMesh(std::vector<std::uint16_t>& objectIds, const std::string& filename) const -> std::unique_ptr<MeshData>
Construct a unified MeshData from a loaded asset's semantic meshes.
void addObjectToDrawables(const std::shared_ptr<metadata::attributes::ObjectAttributes>& ObjectAttributes, scene::SceneNode* parent, DrawableGroup* drawables, std::vector<scene::SceneNode*>& visNodeCache, const std::string& lightSetupKey = DEFAULT_LIGHTING_KEY)
Add an object from a specified object template handle to the specified DrawableGroup as a child of the specified scene::SceneNode if provided.
void addPrimitiveToDrawables(int primitiveID, scene::SceneNode& node, DrawableGroup* drawables)
Create a new drawable primitive attached to the desired scene::SceneNode.
void createDrawable(Mn::GL::Mesh* mesh, gfx::Drawable::Flags& meshAttributeFlags, scene::SceneNode& node, gfx::DrawableConfiguration& drawableCfg)
Create a gfx::Drawable for the specified mesh, and node.
void removePrimitiveMesh(int primitiveID)
Remove the specified primitive mesh.
auto loadNavMeshVisualization(esp::nav::PathFinder& pathFinder, scene::SceneNode* parent, DrawableGroup* drawables) -> int
Generate a new primitive mesh asset for the NavMesh loaded in the provided PathFinder object.
auto buildTrajectoryVisualization(const std::string& trajVisName, const std::vector<Mn::Vector3>& pts, const std::vector<Mn::Color3>& colorVec, int numSegments = 3, float radius = .001, bool smooth = false, int numInterp = 10) -> bool
Generate a tube following the passed trajectory of points.
auto buildFrameFromAttributes(const std::string& attribName, const Magnum::Vector3& up, const Magnum::Vector3& front, const Magnum::Vector3& origin) -> esp::geo::CoordinateFrame
Build a configuration frame from specified up and front vectors and return it. If up is not orthogonal to front, will return default frame.
void setRequiresTextures(bool newVal)
Sets whether or not the current agent sensor suite requires textures for rendering. Textures will not be loaded if this is false.
void setRecorder(std::shared_ptr<gfx::replay::Recorder> gfxReplayRecorder)
Set a replay recorder so that ResourceManager can notify it about render assets.
auto createColorMaterial(const esp::assets::PhongMaterialColor& materialColor) -> std::string
Construct and return a unique string key for the color material and create an entry in the shaderManager_ if new.
auto createModifiedAssetName(const AssetInfo& info, std::string& materialId) -> std::string
Creates an asset name appropriately modified based certain conditions present in passed assetInfo. This function will derive encodings based on the state of the assetInfo so that different material configurations can be specified on the same asset.
auto loadAndCreateRenderAssetInstance(const AssetInfo& assetInfo, const RenderAssetInstanceCreationInfo& creation, esp::scene::SceneManager* sceneManagerPtr, const std::vector<int>& activeSceneIDs) -> scene::SceneNode*
Load a render asset (if not already loaded) and create a render asset instance.
auto loadAndCreateRenderAssetInstance(const AssetInfo& assetInfo, const RenderAssetInstanceCreationInfo& creation, scene::SceneNode* parent = nullptr, DrawableGroup* drawables = nullptr, std::vector<scene::SceneNode*>* visNodeCache = nullptr) -> scene::SceneNode*
Load a render asset (if not already loaded) and create a render asset instance at a known SceneNode and Drawables.
auto loadRenderAsset(const AssetInfo& info) -> bool
Load a render asset so it can be instanced. See also createRenderAssetInstance.
auto getShaderManager() -> gfx::ShaderManager&
Get the shader manager.
auto getRigManager() -> RigManager&
Get the rig manager.
auto buildSemanticCCObjects(const std::shared_ptr<metadata::attributes::StageAttributes>& stageAttributes) -> std::unordered_map<uint32_t, std::vector<std::shared_ptr<scene::CCSemanticObject>>>
Build data for a report for semantic mesh connected components based on color/id. Returns map of data keyed by SemanticObject index in SemanticObjs array.
auto buildVertexColorMapReport(const std::shared_ptr<metadata::attributes::StageAttributes>& stageAttributes) -> std::vector<std::string>
Build data for a report for vertex color mapping to semantic scene objects - this list of strings will disclose which colors are found in vertices but not in semantic scene descriptors, and which semantic objects do not have their colors mapped in mesh verts.
auto getDrawableCountAndNumFaces() -> auto
Get the count of Drawables and the total face count across all Drawables in the scene. This is helpful for troubleshooting runtime perf. See also resetDrawableCountAndNumFaces.
void resetDrawableCountAndNumFaces()
Reset this count and this number. See also getDrawableCountAndNumFaces.

Protected types

struct LoadedAssetData
Data for a loaded asset.
struct StaticDrawableInfo

Protected functions

auto isRenderAssetGeneral(AssetType type) -> bool
Determines if passed type is a general mesh data.
void addComponent(const MeshMetaData& metaData, scene::SceneNode& parent, const Mn::ResourceKey& lightSetupKey, DrawableGroup* drawables, const MeshTransformNode& meshTransformNode, std::vector<scene::SceneNode*>& visNodeCache, bool computeAbsoluteAABBs, std::vector<StaticDrawableInfo>& staticDrawableInfo, const std::shared_ptr<gfx::InstanceSkinData>& skinData = nullptr)
Recursive construction of scene nodes for an asset.
void mapSkinnedModelToRig(const MeshTransformNode& meshTransformNode, const gfx::Rig& rig, const std::shared_ptr<gfx::InstanceSkinData>& skinData)
Recursive construction of instance skinning data.
void loadTextures(Importer& importer, LoadedAssetData& loadedAssetData)
Load textures from importer into assets, and update metaData for an asset to link textures to that asset.
void loadMeshes(Importer& importer, LoadedAssetData& loadedAssetData)
Load meshes from importer into assets.
void loadSkins(Importer& importer, LoadedAssetData& loadedAssetData)
Load skins from importer into assets.
void joinHierarchy(MeshData& mesh, const MeshMetaData& metaData, const MeshTransformNode& node, const Mn::Matrix4& transformFromParentToWorld) const
Recursively build a unified MeshData from loaded assets via a tree of MeshTransformNode.
void joinSemanticHierarchy(MeshData& mesh, std::vector<uint16_t>& meshObjectIds, const MeshMetaData& metaData, const MeshTransformNode& node, const Mn::Matrix4& transformFromParentToWorld) const
Recursively build a unified MeshData from loaded semantic assets via a tree of MeshTransformNode.
void loadMaterials(Importer& importer, LoadedAssetData& loadedAssetData)
Load materials from importer into assets, and update metaData for an asset to link materials to that asset.
auto getMaterialShaderType(const AssetInfo& info) const -> ObjectInstanceShaderType
Get the appropriate the esp::metadata::attributes::ObjectInstanceShaderType to use to render the passed material based on specification in passed info or the material itself.
auto checkForPassedShaderType(ObjectInstanceShaderType typeToCheck, const Mn::Trade::MaterialData& materialData, ObjectInstanceShaderType verificationType, Mn::Trade::MaterialType mnVerificationType) const -> bool
Boolean check if typeToCheck aligns with passed types explicitly specified, or type in material.
auto buildCustomAttributeFlatMaterial(const Mn::Trade::MaterialData& materialData, int textureBaseIndex) -> Mn::Trade::MaterialData
Build a Magnum::Trade::MaterialData for use with Flat shading that holds all custom attributes except texture pointers. Note : habitat-sim currently uses the Phong shader for Flat materials.
auto buildCustomAttributePhongMaterial(const Mn::Trade::MaterialData& material, int textureBaseIndex) const -> Mn::Trade::MaterialData
Build a Magnum::Trade::MaterialData for use with Phong shading that holds all custom attributes except texture pointers.
auto buildCustomAttributePbrMaterial(const Mn::Trade::MaterialData& material, int textureBaseIndex) const -> Mn::Trade::MaterialData
Build a Magnum::Trade::MaterialData for use with PBR shading that holds all custom attributes except texture pointers.
auto loadStageInternal(const AssetInfo& info, const RenderAssetInstanceCreationInfo* creation, scene::SceneNode* parent, DrawableGroup* drawables) -> bool
Load a mesh describing some scene asset based on the passed assetInfo.
auto buildMeshGroups(const AssetInfo& info, std::vector<CollisionMeshData>& meshGroup) -> bool
Builds the appropriate collision mesh groups for the passed assetInfo, and adds it to the collisionMeshGroup map.
auto createStageAssetInfosFromAttributes(const std::shared_ptr<metadata::attributes::StageAttributes>& stageAttributes, bool createCollisionInfo, bool createSemanticInfo) -> std::map<std::string, AssetInfo>
Creates a map of appropriate asset infos for sceneries. Will always create render asset info. Will create collision asset info and semantic stage asset info if requested.
auto flattenImportedMeshAndBuildSemantic(Importer& fileImporter, const AssetInfo& info) -> std::unique_ptr<GenericSemanticMeshData>
Build GenericSemanticMeshData from a single, flattened Magnum Meshdata, built from the meshes provided by the importer, preserving all transformations. This building process will also synthesize bounding boxes if requested from the semanticScene_ .
auto loadSemanticRenderAsset(const AssetInfo& info) -> bool
Semantic Mesh backend for loadRenderAsset. Either use loadRenderAssetSemantic if semantic mesh has vertex annotations only, or loadRenderAssetGeneral if semantic mesh has texture-based annotations. This choice is governed by info.hasSemanticTextures.
auto loadRenderAssetSemantic(const AssetInfo& info) -> bool
Semantic (vertex-annotated) Mesh backend for loadRenderAsset.
auto loadRenderAssetGeneral(const AssetInfo& info) -> bool
General Mesh backend for loadRenderAsset.
auto createRenderAssetInstance(const RenderAssetInstanceCreationInfo& creation, scene::SceneNode* parent, DrawableGroup* drawables, std::vector<scene::SceneNode*>* visNodeCache = nullptr) -> scene::SceneNode*
Create a render asset instance.
auto createSemanticRenderAssetInstance(const RenderAssetInstanceCreationInfo& creation, scene::SceneNode* parent, DrawableGroup* drawables) -> scene::SceneNode*
Semantic Mesh backend creation. Either use createRenderAssetInstanceVertSemantic if semantic mesh has vertex annotations only, or createRenderAssetInstanceGeneralPrimitive if semantic mesh has texture-based annotations. This choice is governed by creation.isTextureBasedSemantic().
auto createRenderAssetInstanceVertSemantic(const RenderAssetInstanceCreationInfo& creation, scene::SceneNode* parent, DrawableGroup* drawables) -> scene::SceneNode*
Semantic Mesh (vertex-annotated) backend for createRenderAssetInstance.
auto createRenderAssetInstanceGeneralPrimitive(const RenderAssetInstanceCreationInfo& creation, scene::SceneNode* parent, DrawableGroup* drawables, std::vector<scene::SceneNode*>* userVisNodeCache) -> scene::SceneNode*
backend for both General Mesh and Primitive Mesh, for createRenderAssetInstance
void initDefaultLightSetups()
initialize default lighting setups in the current ShaderManager
void initDefaultMaterials()
initialize default material setups in the current ShaderManager
auto getDefaultMaterialShaderType() -> ObjectInstanceShaderType
Retrieve the shader type to use for the various default materials.
auto isLightSetupCompatible(const LoadedAssetData& loadedAssetData, const Mn::ResourceKey& lightSetupKey) const -> bool
Checks if light setup is compatible with loaded asset.
auto computeMeshBB(BaseMesh* meshDataGL) -> Mn::Range3D
Compute and return the axis aligned bounding box of a mesh in mesh local space.
void computeGeneralMeshAbsoluteAABBs(const std::vector<StaticDrawableInfo>& staticDrawableInfo)
Compute the absolute AABBs for drawables in general mesh (e.g., MP3D) world space.
void computeInstanceMeshAbsoluteAABBs(const std::vector<StaticDrawableInfo>& staticDrawableInfo)
Compute the absolute AABBs for drawables in semantic mesh in world space.
auto computeAbsoluteTransformations(const std::vector<StaticDrawableInfo>& staticDrawableInfo) -> std::vector<Mn::Matrix4>
Compute absolute transformations of all drawables stored in staticDrawableInfo_.

Protected variables

int nextMeshID_
The next available unique ID for loaded meshes.
std::map<int, std::shared_ptr<BaseMesh>> meshes_
The mesh data for loaded assets.
std::pair<int, int> drawableCountAndNumFaces_
int nextTextureID_
The next available unique ID for loaded textures.
std::map<int, std::shared_ptr<Mn::GL::Texture2D>> textures_
The texture data for loaded assets.
int nextMaterialID_
The next available unique ID for loaded materials.
int nextSkinID_
The next available unique ID for loaded skins.
std::map<int, std::shared_ptr<gfx::SkinData>> skins_
The skin data for loaded assets.
std::map<std::string, LoadedAssetData> resourceDict_
Asset metadata linking meshes, textures, materials, and the component transformation hierarchy for loaded assets.
gfx::ShaderManager shaderManager_
The ShaderManager used to store shader information for drawables created by this ResourceManager.
RigManager rigManager_
The RigManager used to store rig information for skinned drawables created by this ResourceManager.
std::shared_ptr<metadata::MetadataMediator> metadataMediator_
A reference to the MetadataMediator managing all the metadata currently in use.
Corrade::PluginManager::Manager<Importer> importerManager_
Plugin Manager used to instantiate importers which in turn are used to load asset data.
std::unique_ptr<GenericSemanticMeshData> infoSemanticMeshData_
This GenericSemanticMeshData unique pointer is not used to actually create a mesh, but rather for reporting and color annotations (for texture-based semantics processing). We retain this so we do not need to re-load from scratch for future reporting functionality. NOTE : We must not use this to retain a semantic mesh that is actually being rendered, since that mesh will have its components moved into actual render mesh constructs.
Corrade::Containers::Pointer<Importer> primitiveImporter_
Importer used to synthesize Magnum Primitives (PrimitiveImporter). This object allows for similar usage to File-based importers, but requires no file to be available/read.
Corrade::Containers::Pointer<Importer> fileImporter_
Importer used to load generic mesh files (AnySceneImporter)
Corrade::Containers::Pointer<Importer> imageImporter_
Importer used to load images (AnyImageImporter)
std::shared_ptr<scene::SemanticScene> semanticScene_
Reference to the currently loaded semanticScene Descriptor.
std::vector<Mn::Vector3ub> semanticColorMapBeingUsed_
Colormap to use for visualizing currently loaded semantic scene.
std::vector<uint32_t> semanticColorAsInt_
Cache semantic colors as ints.
int nextPrimitiveMeshId
tracks primitive mesh ids
std::map<int, std::unique_ptr<Mn::GL::Mesh>> primitive_meshes_
Primitive meshes available for instancing via addPrimitiveToDrawables for debugging or visualization purposes.
std::map<std::string, std::vector<CollisionMeshData>> collisionMeshGroups_
Maps string keys (typically property filenames) to CollisionMeshData for all components of a loaded asset.
bool requiresTextures_
Flag to load textures of meshes.
std::shared_ptr<esp::gfx::replay::Recorder> gfxReplayRecorder_
See setRecorder.
std::unordered_map<std::string, std::shared_ptr<esp::gfx::PbrIBLHelper>> pbrIBLHelpers_
Helper objects that calculate and manage assets for IBL : an environment map, an irradiance map, a BRDF lookup table (2D texture), and a pre-filtered map.
std::unordered_map<std::string, std::shared_ptr<Mn::GL::Texture2D>> iblBLUTsAndEnvMaps_
Map of brdf Lookup table textures and environment map textures loaded already to be used for IBL.

Function documentation

void esp::assets::ResourceManager::initPhysicsManager(std::shared_ptr<physics::PhysicsManager>& physicsManager, scene::SceneNode* parent, const std::shared_ptr<metadata::attributes::PhysicsManagerAttributes>& physicsManagerAttributes)

Instantiate, or reinstantiate, PhysicsManager defined by passed attributes.

Parameters
physicsManager The currently defined physics::PhysicsManager. Will be reseated to the specified physics implementation.
parent The scene::SceneNode of which the scene mesh will be added as a child. Typically near the root of the scene. Expected to be static.
physicsManagerAttributes A smart pointer to meta data structure storing configured physics simulation parameters.

Mn::Image2D esp::assets::ResourceManager::convertRGBToSemanticId(const Mn::ImageView2D& srcImage, Cr::Containers::Array<Mn::UnsignedShort>& clrToSemanticId)

Remap a semantic annotation texture to have the semantic IDs per pxl.

Parameters
srcImage The source texture with the semantic colors.
clrToSemanticId Large table of all possible colors to their semantic IDs. initialized to 0xffff
Returns An image of the semantic IDs, with the ID mapped

bool esp::assets::ResourceManager::loadSemanticScene(const std::shared_ptr<metadata::attributes::SemanticAttributes>& semanticAttr, const std::string& activeSceneName)

Load semantic scene data from descriptor file and metadata specified in semanticAttr , for the passed activeSceneName .

Parameters
semanticAttr Pointer to semantic attributes, if they exist. This will hold fully-qualified filename along with other attributes required to create the semantic scene.
activeSceneName Name of the currently active scene that we will be loading the SSD for.
Returns whether loaded successfully or not.

bool esp::assets::ResourceManager::loadStage(const std::shared_ptr<metadata::attributes::StageAttributes>& stageAttributes, const std::shared_ptr<const metadata::attributes::SceneObjectInstanceAttributes>& stageInstanceAttributes, const std::shared_ptr<physics::PhysicsManager>& _physicsManager, esp::scene::SceneManager* sceneManagerPtr, std::vector<int>& activeSceneIDs)

Load a scene mesh and add it to the specified DrawableGroup as a child of the specified scene::SceneNode.

Parameters
stageAttributes The metadata::attributes::StageAttributes that describes the stage
stageInstanceAttributes The metadata::attributes::SceneObjectInstanceAttributes that describes this particular instance of the stage. If nullptr then not created by SceneInstanceAttributes.
_physicsManager The currently defined esp::physics::PhysicsManager.
sceneManagerPtr Pointer to scene manager, to fetch drawables and parent node.
activeSceneIDs out active scene ID is in idx 0, if semantic scene is made, its activeID should be pushed onto vector
Returns Whether or not the scene load succeeded.

If parent and drawables are not specified, the assets are loaded, but no new gfx::Drawable is added for the scene (i.e. it will not be rendered).

template<class T>
bool esp::assets::ResourceManager::buildStageCollisionMeshGroup(const std::string& filename, std::vector<CollisionMeshData>& meshGroup)

Construct scene collision mesh group based on name and type of scene.

Template parameters
T type of meshdata desired based on scene type.
Parameters
filename The name of the file holding the mesh data
meshGroup The meshgroup to build
Returns whether built successfully or not

bool esp::assets::ResourceManager::instantiateAssetsOnDemand(const std::shared_ptr<metadata::attributes::ObjectAttributes>& ObjectAttributes)

Load/instantiate any required render and collision assets for an object, if they do not already exist in resourceDict_ or collisionMeshGroups_, respectively. Assumes valid render and collisions asset handles have been specified (This is checked/verified during registration.)

Parameters
ObjectAttributes The object template describing the object we wish to instantiate, copied from an entry in esp::metadata::managers::ObjectAttributesManager::objectLibrary_.
Returns whether process succeeded or not - only currently fails if registration call fails.

const std::vector<assets::CollisionMeshData>& esp::assets::ResourceManager::getCollisionMesh(const std::string& collisionAssetHandle) const

Getter for all assets::CollisionMeshData associated with the particular asset.

Parameters
collisionAssetHandle The key by which the asset is referenced in collisionMeshGroups_, from the esp::metadata::managers::ObjectAttributesManager::objectLibrary_.
Returns A vector reference to assets::CollisionMeshData instances for individual components of the asset.

void esp::assets::ResourceManager::setMetadataMediator(std::shared_ptr<metadata::MetadataMediator> MM)

Set a reference to the current metadataMediator_. Perform any initialization that may be required when metadataMediator_ is changed.

Parameters
MM a reference to the new metadataMediator_.

const MeshMetaData& esp::assets::ResourceManager::getMeshMetaData(const std::string& metaDataName) const

Retrieve the meta data for a particular asset.

Parameters
metaDataName The key identifying the asset in resourceDict_. Typically the filepath of file-based assets.
Returns The asset's MeshMetaData object.

This includes identifiers for meshes, textures, materials, and a component hierarchy.

Mn::Resource<gfx::LightSetup> esp::assets::ResourceManager::getLightSetup(const Mn::ResourceKey& key = Mn::ResourceKey{DEFAULT_LIGHTING_KEY})

Get a named esp::gfx::LightSetup.

Parameters
key The key identifying the light setup in shaderManager_.
Returns The LightSetup object.

void esp::assets::ResourceManager::setLightSetup(gfx::LightSetup setup, const Mn::ResourceKey& key = Mn::ResourceKey{ DEFAULT_LIGHTING_KEY})

Set a named esp::gfx::LightSetup.

Parameters
setup Light setup this key will now reference
key Key to identify this esp::gfx::LightSetup

If this name already exists, the esp::gfx::LightSetup is updated and all Drawables using this setup are updated.

std::unique_ptr<MeshData> esp::assets::ResourceManager::createJoinedCollisionMesh(const std::string& filename) const

Construct a unified MeshData from a loaded asset's collision meshes.

Parameters
filename The identifying string key for the asset. See resourceDict_ and meshes_.
Returns The unified MeshData object for the asset.

See joinHierarchy.

std::unique_ptr<MeshData> esp::assets::ResourceManager::createJoinedSemanticCollisionMesh(std::vector<std::uint16_t>& objectIds, const std::string& filename) const

Construct a unified MeshData from a loaded asset's semantic meshes.

Parameters
objectIds out vector of uint16_t, will be populated with the object ids of the semantic mesh
filename The identifying string key for the asset. See resourceDict_ and meshes_.
Returns The unified MeshData object for the asset.

See joinHierarchy.

void esp::assets::ResourceManager::addObjectToDrawables(const std::shared_ptr<metadata::attributes::ObjectAttributes>& ObjectAttributes, scene::SceneNode* parent, DrawableGroup* drawables, std::vector<scene::SceneNode*>& visNodeCache, const std::string& lightSetupKey = DEFAULT_LIGHTING_KEY)

Add an object from a specified object template handle to the specified DrawableGroup as a child of the specified scene::SceneNode if provided.

Parameters
ObjectAttributes The attributes used to create the object being added.
parent The scene::SceneNode of which the object will be a child.
drawables The DrawableGroup with which the object gfx::Drawable will be rendered.
visNodeCache out Cache for pointers to all nodes created as the result of this process.
lightSetupKey The esp::gfx::LightSetup key that will be used for the added component.

If the attributes specified by objTemplateHandle exists in esp::metadata::managers::ObjectAttributesManager::objectLibrary_, and both parent and drawables are specified, than an object referenced by that key is added to the scene.

void esp::assets::ResourceManager::addPrimitiveToDrawables(int primitiveID, scene::SceneNode& node, DrawableGroup* drawables)

Create a new drawable primitive attached to the desired scene::SceneNode.

Parameters
primitiveID The key of the primitive in primitive_meshes_.
node The scene::SceneNode to which the primitive drawable will be attached.
drawables The DrawableGroup with which the primitive will be rendered.

See primitive_meshes_.

void esp::assets::ResourceManager::createDrawable(Mn::GL::Mesh* mesh, gfx::Drawable::Flags& meshAttributeFlags, scene::SceneNode& node, gfx::DrawableConfiguration& drawableCfg)

Create a gfx::Drawable for the specified mesh, and node.

Parameters
mesh The render mesh.
meshAttributeFlags flags for the attributes of the render mesh
node The scene::SceneNode to which the drawable will be attached.
drawableCfg The esp::gfx::DrawableConfiguration that describes the drawable being created.

Add this drawable to the DrawableGroup if provided.

void esp::assets::ResourceManager::removePrimitiveMesh(int primitiveID)

Remove the specified primitive mesh.

Parameters
primitiveID The key of the primitive in primitive_meshes_.

int esp::assets::ResourceManager::loadNavMeshVisualization(esp::nav::PathFinder& pathFinder, scene::SceneNode* parent, DrawableGroup* drawables)

Generate a new primitive mesh asset for the NavMesh loaded in the provided PathFinder object.

Parameters
pathFinder Holds the NavMesh information.
parent The new Drawable is attached to this node.
drawables The group with which the new Drawable will be rendered.
Returns The primitive ID of the new object or ID_UNDEFINED if construction failed.

If parent and drawables are provided, create the Drawable and render the NavMesh.

bool esp::assets::ResourceManager::buildTrajectoryVisualization(const std::string& trajVisName, const std::vector<Mn::Vector3>& pts, const std::vector<Mn::Color3>& colorVec, int numSegments = 3, float radius = .001, bool smooth = false, int numInterp = 10)

Generate a tube following the passed trajectory of points.

Parameters
trajVisName The name to use for the trajectory visualization mesh.
pts The points of a trajectory, in order
colorVec Array of Colors for trajectory tube.
numSegments The number of the segments around the circumference of the tube. Must be greater than or equal to 3.
radius The radius of the tube.
smooth Whether to smooth the points in the trajectory or not
numInterp The number of interpolations between each trajectory point, if smoothing.
Returns Whether the process was a success or not

esp::geo::CoordinateFrame esp::assets::ResourceManager::buildFrameFromAttributes(const std::string& attribName, const Magnum::Vector3& up, const Magnum::Vector3& front, const Magnum::Vector3& origin)

Build a configuration frame from specified up and front vectors and return it. If up is not orthogonal to front, will return default frame.

Parameters
attribName the handle to the attributes the frame is being built for, for debug purposes.
up The up vector to build the frame from
front The front vector to build the frame from.
origin Either the origin of the stageAttributes or the COM value of the objectAttributes.
Returns the coordinate frame of the assets the passed attributes describes.

std::string esp::assets::ResourceManager::createColorMaterial(const esp::assets::PhongMaterialColor& materialColor)

Construct and return a unique string key for the color material and create an entry in the shaderManager_ if new.

Parameters
materialColor The color parameters.
Returns The unique key string identifying the material in shaderManager_.

std::string esp::assets::ResourceManager::createModifiedAssetName(const AssetInfo& info, std::string& materialId)

Creates an asset name appropriately modified based certain conditions present in passed assetInfo. This function will derive encodings based on the state of the assetInfo so that different material configurations can be specified on the same asset.

Parameters
info The AssetInfo that describes the asset being named.
materialId [in/out] A string key representing the material to use. If empty, this will be generated and populated.
Returns the modified asset name to be used to save this asset to resourceDict_.

scene::SceneNode* esp::assets::ResourceManager::loadAndCreateRenderAssetInstance(const AssetInfo& assetInfo, const RenderAssetInstanceCreationInfo& creation, esp::scene::SceneManager* sceneManagerPtr, const std::vector<int>& activeSceneIDs)

Load a render asset (if not already loaded) and create a render asset instance.

Parameters
assetInfo the render asset to load
creation How to create the instance
sceneManagerPtr Info about the scene graph(s). See loadStage.
activeSceneIDs Info about the scene graph(s). See loadStage.
Returns the root node of the instance, or nullptr (if the load failed)

scene::SceneNode* esp::assets::ResourceManager::loadAndCreateRenderAssetInstance(const AssetInfo& assetInfo, const RenderAssetInstanceCreationInfo& creation, scene::SceneNode* parent = nullptr, DrawableGroup* drawables = nullptr, std::vector<scene::SceneNode*>* visNodeCache = nullptr)

Load a render asset (if not already loaded) and create a render asset instance at a known SceneNode and Drawables.

Parameters
assetInfo the render asset to load
creation How to create the instance
parent The parent node under which the visual node hierarchy will be generated.
drawables The DrawableGroup to which new Drawables will be added.
visNodeCache A reference to a SceneNode* vector which caches all new SceneNodes created by the attachment process.
Returns the root node of the instance, or nullptr (if the load failed)

bool esp::assets::ResourceManager::isRenderAssetGeneral(AssetType type) protected

Determines if passed type is a general mesh data.

Parameters
type The type to verify.
Returns Whether it is a General

void esp::assets::ResourceManager::addComponent(const MeshMetaData& metaData, scene::SceneNode& parent, const Mn::ResourceKey& lightSetupKey, DrawableGroup* drawables, const MeshTransformNode& meshTransformNode, std::vector<scene::SceneNode*>& visNodeCache, bool computeAbsoluteAABBs, std::vector<StaticDrawableInfo>& staticDrawableInfo, const std::shared_ptr<gfx::InstanceSkinData>& skinData = nullptr) protected

Recursive construction of scene nodes for an asset.

Parameters
metaData The MeshMetaData object containing information about the meshes, textures, materials, and component hierarchy of the asset.
parent The scene::SceneNode of which the component will be a child.
lightSetupKey The esp::gfx::LightSetup key that will be used for the added component.
drawables The DrawableGroup with which the component will be rendered.
meshTransformNode The MeshTransformNode for component identifying its mesh, material, transformation, and children.
visNodeCache out Cache for pointers to all nodes created as the result of this recursive process.
computeAbsoluteAABBs whether absolute bounding boxes should be computed
staticDrawableInfo structure holding the drawable infos for aabbs
skinData structure holding the skin and rig configuration for the instance

Creates a drawable for the component of an asset referenced by the MeshTransformNode and adds it to the DrawableGroup as child of parent.

void esp::assets::ResourceManager::mapSkinnedModelToRig(const MeshTransformNode& meshTransformNode, const gfx::Rig& rig, const std::shared_ptr<gfx::InstanceSkinData>& skinData) protected

Recursive construction of instance skinning data.

Parameters
meshTransformNode The MeshTransformNode being traversed.
rig
skinData Structure holding the skin and rig configuration for the instance.

Fills the fields of a InstanceSkinData to enable skinned mesh rendering by associating each bone to a corresponding articulated object link.

void esp::assets::ResourceManager::loadTextures(Importer& importer, LoadedAssetData& loadedAssetData) protected

Load textures from importer into assets, and update metaData for an asset to link textures to that asset.

Parameters
importer The importer already loaded with information for the asset.
loadedAssetData The asset's LoadedAssetData object.

void esp::assets::ResourceManager::loadMeshes(Importer& importer, LoadedAssetData& loadedAssetData) protected

Load meshes from importer into assets.

Parameters
importer The importer already loaded with information for the asset.
loadedAssetData The asset's LoadedAssetData object.

Compute bounding boxes, upload mesh data to GPU, and update metaData for an asset to link meshes to that asset.

void esp::assets::ResourceManager::loadSkins(Importer& importer, LoadedAssetData& loadedAssetData) protected

Load skins from importer into assets.

Parameters
importer The importer already loaded with information for the asset.
loadedAssetData The asset's LoadedAssetData object.

void esp::assets::ResourceManager::joinHierarchy(MeshData& mesh, const MeshMetaData& metaData, const MeshTransformNode& node, const Mn::Matrix4& transformFromParentToWorld) const protected

Recursively build a unified MeshData from loaded assets via a tree of MeshTransformNode.

Parameters
mesh in/out The MeshData being constructed.
metaData The MeshMetaData for the object hierarchy being joined.
node The current MeshTransformNode in the recursion.
transformFromParentToWorld The cumulative transformation up to but not including the current MeshTransformNode.

void esp::assets::ResourceManager::joinSemanticHierarchy(MeshData& mesh, std::vector<uint16_t>& meshObjectIds, const MeshMetaData& metaData, const MeshTransformNode& node, const Mn::Matrix4& transformFromParentToWorld) const protected

Recursively build a unified MeshData from loaded semantic assets via a tree of MeshTransformNode.

Parameters
mesh in/out The MeshData being constructed.
meshObjectIds out The object ids
metaData The MeshMetaData for the object hierarchy being joined.
node The current MeshTransformNode in the recursion.
transformFromParentToWorld The cumulative transformation up to but not including the current MeshTransformNode.

void esp::assets::ResourceManager::loadMaterials(Importer& importer, LoadedAssetData& loadedAssetData) protected

Load materials from importer into assets, and update metaData for an asset to link materials to that asset.

Parameters
importer The importer already loaded with information for the asset.
loadedAssetData The asset's LoadedAssetData object.

ObjectInstanceShaderType esp::assets::ResourceManager::getMaterialShaderType(const AssetInfo& info) const protected

Get the appropriate the esp::metadata::attributes::ObjectInstanceShaderType to use to render the passed material based on specification in passed info or the material itself.

Parameters
info The asset info describing the asset whose material is being rendered.
Returns the esp::metadata::attributes::ObjectInstanceShaderType to use to render the material.

bool esp::assets::ResourceManager::checkForPassedShaderType(ObjectInstanceShaderType typeToCheck, const Mn::Trade::MaterialData& materialData, ObjectInstanceShaderType verificationType, Mn::Trade::MaterialType mnVerificationType) const protected

Boolean check if typeToCheck aligns with passed types explicitly specified, or type in material.

Parameters
typeToCheck The ObjectInstanceShaderType value being queried for.
materialData The material whose type we are verifying against
verificationType The ObjectInstanceShaderType we are verifying against
mnVerificationType The Mn::Trade::MaterialType bitflag that the passed material's specified type is being verified against.
Returns Whether or not the passed typeToCheck matches the passed criteria.

Mn::Trade::MaterialData esp::assets::ResourceManager::buildCustomAttributeFlatMaterial(const Mn::Trade::MaterialData& materialData, int textureBaseIndex) protected

Build a Magnum::Trade::MaterialData for use with Flat shading that holds all custom attributes except texture pointers. Note : habitat-sim currently uses the Phong shader for Flat materials.

Parameters
materialData
textureBaseIndex Base index of the assets textures in textures_ store

Textures must already be loaded for the asset this material belongs to

Mn::Trade::MaterialData esp::assets::ResourceManager::buildCustomAttributePhongMaterial(const Mn::Trade::MaterialData& material, int textureBaseIndex) const protected

Build a Magnum::Trade::MaterialData for use with Phong shading that holds all custom attributes except texture pointers.

Parameters
material Material data with texture IDs
textureBaseIndex Base index of the assets textures in textures_ store

Textures must already be loaded for the asset this material belongs to

Mn::Trade::MaterialData esp::assets::ResourceManager::buildCustomAttributePbrMaterial(const Mn::Trade::MaterialData& material, int textureBaseIndex) const protected

Build a Magnum::Trade::MaterialData for use with PBR shading that holds all custom attributes except texture pointers.

Parameters
material Material data with texture IDs
textureBaseIndex Base index of the assets textures in textures_ store

Textures must already be loaded for the asset this material belongs to

bool esp::assets::ResourceManager::loadStageInternal(const AssetInfo& info, const RenderAssetInstanceCreationInfo* creation, scene::SceneNode* parent, DrawableGroup* drawables) protected

Load a mesh describing some scene asset based on the passed assetInfo.

Parameters
info The AssetInfo for the mesh, already parsed from a file.
creation How to instance the render asset, or nullptr if not instancing.
parent The scene::SceneNode to which the mesh will be added as a child. See also creation->isRGBD and creation->isSemantic. nullptr if not instancing.
drawables The DrawableGroup with which the mesh will be rendered. See also creation->isRGBD and creation->isSemantic. nullptr if not instancing.
Returns Whether or not the load was successful.

If both parent and drawables are provided, add the mesh to the scene graph for rendering.

bool esp::assets::ResourceManager::buildMeshGroups(const AssetInfo& info, std::vector<CollisionMeshData>& meshGroup) protected

Builds the appropriate collision mesh groups for the passed assetInfo, and adds it to the collisionMeshGroup map.

Parameters
info The AssetInfo for the mesh, already parsed from a file.
meshGroup The constructed meshGroup
Returns Whether the meshgroup was successfully built or not

std::map<std::string, AssetInfo> esp::assets::ResourceManager::createStageAssetInfosFromAttributes(const std::shared_ptr<metadata::attributes::StageAttributes>& stageAttributes, bool createCollisionInfo, bool createSemanticInfo) protected

Creates a map of appropriate asset infos for sceneries. Will always create render asset info. Will create collision asset info and semantic stage asset info if requested.

Parameters
stageAttributes The stage attributes file holding the stage's information.
createCollisionInfo Whether collision-based asset info should be created (only if physicsManager type is not none)
createSemanticInfo Whether semantic mesh-based asset info should be created

std::unique_ptr<GenericSemanticMeshData> esp::assets::ResourceManager::flattenImportedMeshAndBuildSemantic(Importer& fileImporter, const AssetInfo& info) protected

Build GenericSemanticMeshData from a single, flattened Magnum Meshdata, built from the meshes provided by the importer, preserving all transformations. This building process will also synthesize bounding boxes if requested from the semanticScene_ .

Parameters
fileImporter Importer used to load the scene.
info AssetInfo describing asset.
Returns The GenericSemanticMeshData being built.

scene::SceneNode* esp::assets::ResourceManager::createRenderAssetInstance(const RenderAssetInstanceCreationInfo& creation, scene::SceneNode* parent, DrawableGroup* drawables, std::vector<scene::SceneNode*>* visNodeCache = nullptr) protected

Create a render asset instance.

Parameters
creation Controls how the instance is created.
parent The scene::SceneNode to which the instance will be added as a child. See also creation.isRGBD and isSemantic.
drawables The DrawableGroup with which the instance will be rendered. See also creation.isRGBD and isSemantic.
visNodeCache out Optional; cache for pointers to all nodes created as the result of this process.

Mn::Range3D esp::assets::ResourceManager::computeMeshBB(BaseMesh* meshDataGL) protected

Compute and return the axis aligned bounding box of a mesh in mesh local space.

Parameters
meshDataGL The mesh data.
Returns The mesh bounding box.

Variable documentation

std::map<std::string, LoadedAssetData> esp::assets::ResourceManager::resourceDict_ protected

Asset metadata linking meshes, textures, materials, and the component transformation hierarchy for loaded assets.

Maps absolute path keys to metadata.