esp::metadata::managers::ObjectAttributesManager class

single instance class managing templates describing physical objects

Base classes

template<class T, ManagedObjectAccess Access>
class AbstractObjectAttributesManager<attributes::ObjectAttributes, ManagedObjectAccess::Copy>
Class template defining responsibilities and functionality for managing esp::metadata::attributes::AbstractObjectAttributes constructs.

Constructors, destructors, conversion operators

ObjectAttributesManager()

Public functions

void setAssetAttributesManager(AssetAttributesManager::cptr assetAttributesMgr)
auto createPrimBasedAttributesTemplate(const std::string& primAttrTemplateHandle, bool registerTemplate = true) -> attributes::ObjectAttributes::ptr override
Creates an instance of an object template described by passed string, which should be a reference to an existing primitive asset template to be used in the construction of the object (as render and collision mesh). It returns created instance if successful, and nullptr if fails.
void setValsFromJSONDoc(attributes::ObjectAttributes::ptr attribs, const io::JsonGenericValue& jsonConfig) override
Method to take an existing attributes and set its values from passed json config file.
auto isValidPrimitiveAttributes(const std::string& handle) -> bool override
Check if currently configured primitive asset template library has passed handle.
auto getNumFileTemplateObjects() const -> int
Gets the number of file-based loaded object templates stored in the physicsFileObjTmpltLibByID_.
auto getRandomFileTemplateHandle() const -> std::string
Get a random loaded attribute handle for the loaded file-based object templates.
auto getFileTemplateHandlesBySubstring(const std::string& subStr = "", bool contains = true, bool sorted = true) const -> std::vector<std::string>
Get a list of all file-based templates whose origin handles contain subStr, ignoring subStr's case.
auto getNumSynthTemplateObjects() const -> int
Gets the number of synthesized (primitive-based) template objects stored in the physicsSynthObjTmpltLibByID_.
auto getRandomSynthTemplateHandle() const -> std::string
Get a random loaded attribute handle for the loaded synthesized (primitive-based) object templates.
auto getSynthTemplateHandlesBySubstring(const std::string& subStr = "", bool contains = true, bool sorted = true) const -> std::vector<std::string>
Get a list of all synthesized (primitive-based) object templates whose origin handles contain subStr, ignoring subStr's case.

Protected functions

void createDefaultPrimBasedAttributesTemplates()
Create and save default primitive asset-based object templates, saving their handles as non-deletable default handles.
void setDefaultAssetNameBasedAttributes(attributes::ObjectAttributes::ptr attributes, bool setFrame, const std::string& meshHandle, const std::function<void(int)>& assetTypeSetter) override
Perform file-name-based attributes initialization. This is to take the place of the AssetInfo::fromPath functionality, and is only intended to provide default values and other help if certain mistakes are made by the user, such as specifying an asset handle in json but not specifying the asset type corresponding to that handle. These settings should not restrict anything, only provide defaults.
auto initNewObjectInternal(const std::string& handleName, bool builtFromConfig) -> attributes::ObjectAttributes::ptr override
Used Internally. Create and configure newly-created attributes with any default values, before any specific values are set.
void deleteObjectInternalFinalize(int templateID, const std::string& templateHandle) override
This method will perform any necessary updating that is attributesManager-specific upon template removal, such as removing a specific template handle from the list of file-based template handles in ObjectAttributesManager. This should only be called esp::core::ManagedContainerBase.
auto registerObjectFinalize(attributes::ObjectAttributes::ptr attributesTemplate, const std::string& attributesTemplateHandle, bool forceRegistration) -> int override
Add a copy of esp::metadata::attributes::AbstractAttributes object to the objectLibrary_. Verify that render and collision handles have been set properly. We are doing this since these values can be modified by the user.
void resetFinalize() override
Any object-attributes-specific resetting that needs to happen on reset.

Protected variables

AssetAttributesManager::cptr assetAttributesMgr_
Reference to AssetAttributesManager to give access to primitive attributes for object construction.
std::unordered_map<int, std::string> physicsFileObjTmpltLibByID_
Maps loaded object template IDs to the appropriate template handles.
std::unordered_map<int, std::string> physicsSynthObjTmpltLibByID_
Maps synthesized, primitive-based object template IDs to the appropriate template handles.

Function documentation

attributes::ObjectAttributes::ptr esp::metadata::managers::ObjectAttributesManager::createPrimBasedAttributesTemplate(const std::string& primAttrTemplateHandle, bool registerTemplate = true) override

Creates an instance of an object template described by passed string, which should be a reference to an existing primitive asset template to be used in the construction of the object (as render and collision mesh). It returns created instance if successful, and nullptr if fails.

Parameters
primAttrTemplateHandle The handle to an existing primitive asset template. Fails if does not.
registerTemplate whether to add this template to the library. If the user is going to edit this template, this should be false - any subsequent editing will require re-registration. Defaults to true.
Returns a reference to the desired template, or nullptr if fails.

void esp::metadata::managers::ObjectAttributesManager::setValsFromJSONDoc(attributes::ObjectAttributes::ptr attribs, const io::JsonGenericValue& jsonConfig) override

Method to take an existing attributes and set its values from passed json config file.

Parameters
attribs (out) an existing attributes to be modified.
jsonConfig json document to parse

bool esp::metadata::managers::ObjectAttributesManager::isValidPrimitiveAttributes(const std::string& handle) override

Check if currently configured primitive asset template library has passed handle.

Parameters
handle String name of primitive asset attributes desired
Returns whether handle exists or not in asset attributes library

int esp::metadata::managers::ObjectAttributesManager::getNumFileTemplateObjects() const

Gets the number of file-based loaded object templates stored in the physicsFileObjTmpltLibByID_.

Returns The number of entries in physicsFileObjTmpltLibByID_ that are loaded from files.

std::string esp::metadata::managers::ObjectAttributesManager::getRandomFileTemplateHandle() const

Get a random loaded attribute handle for the loaded file-based object templates.

Returns a randomly selected handle corresponding to a file-based object attributes template, or empty string if none loaded

std::vector<std::string> esp::metadata::managers::ObjectAttributesManager::getFileTemplateHandlesBySubstring(const std::string& subStr = "", bool contains = true, bool sorted = true) const

Get a list of all file-based templates whose origin handles contain subStr, ignoring subStr's case.

Parameters
subStr substring to search for within existing file-based object templates
contains whether to search for keys containing, or not containing, subStr
sorted whether the return vector values are sorted
Returns vector of 0 or more template handles containing the passed substring

int esp::metadata::managers::ObjectAttributesManager::getNumSynthTemplateObjects() const

Gets the number of synthesized (primitive-based) template objects stored in the physicsSynthObjTmpltLibByID_.

Returns The number of entries in physicsSynthObjTmpltLibByID_ that describe primitives.

std::string esp::metadata::managers::ObjectAttributesManager::getRandomSynthTemplateHandle() const

Get a random loaded attribute handle for the loaded synthesized (primitive-based) object templates.

Returns a randomly selected handle corresponding to the a primitive attributes template, or empty string if none loaded

std::vector<std::string> esp::metadata::managers::ObjectAttributesManager::getSynthTemplateHandlesBySubstring(const std::string& subStr = "", bool contains = true, bool sorted = true) const

Get a list of all synthesized (primitive-based) object templates whose origin handles contain subStr, ignoring subStr's case.

Parameters
subStr substring to search for within existing primitive object templates
contains whether to search for keys containing, or not containing, subStr
sorted whether the return vector values are sorted
Returns vector of 0 or more template handles containing the passed substring

void esp::metadata::managers::ObjectAttributesManager::setDefaultAssetNameBasedAttributes(attributes::ObjectAttributes::ptr attributes, bool setFrame, const std::string& meshHandle, const std::function<void(int)>& assetTypeSetter) override protected

Perform file-name-based attributes initialization. This is to take the place of the AssetInfo::fromPath functionality, and is only intended to provide default values and other help if certain mistakes are made by the user, such as specifying an asset handle in json but not specifying the asset type corresponding to that handle. These settings should not restrict anything, only provide defaults.

Parameters
attributes The AbstractObjectAttributes object to be configured
setFrame whether the frame should be set or not (only for render assets in scenes)
meshHandle Mesh Handle to check.
assetTypeSetter Setter for mesh type.

attributes::ObjectAttributes::ptr esp::metadata::managers::ObjectAttributesManager::initNewObjectInternal(const std::string& handleName, bool builtFromConfig) override protected

Used Internally. Create and configure newly-created attributes with any default values, before any specific values are set.

Parameters
handleName handle name to be assigned to attributes
builtFromConfig Whether this object attributes is being constructed from a config file or from some other source.
Returns Newly created but unregistered ObjectAttributes pointer, with only default values set.

void esp::metadata::managers::ObjectAttributesManager::deleteObjectInternalFinalize(int templateID, const std::string& templateHandle) override protected

This method will perform any necessary updating that is attributesManager-specific upon template removal, such as removing a specific template handle from the list of file-based template handles in ObjectAttributesManager. This should only be called esp::core::ManagedContainerBase.

Parameters
templateID the ID of the template to remove
templateHandle the string key of the attributes desired.

int esp::metadata::managers::ObjectAttributesManager::registerObjectFinalize(attributes::ObjectAttributes::ptr attributesTemplate, const std::string& attributesTemplateHandle, bool forceRegistration) override protected

Add a copy of esp::metadata::attributes::AbstractAttributes object to the objectLibrary_. Verify that render and collision handles have been set properly. We are doing this since these values can be modified by the user.

Parameters
attributesTemplate The attributes template.
attributesTemplateHandle The key for referencing the template in the objectLibrary_. Will be set as origin handle for template.
forceRegistration Will register object even if conditional registration checks fail.
Returns The index in the objectLibrary_ of object template.