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

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 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.
void finalizeAttrPathsBeforeRegister(const attributes::ObjectAttributes::ptr& attributes) const override
This function will be called to finalize attributes' paths before registration, moving fully qualified paths to the appropriate hidden attribute fields. This can also be called without registration to make sure the paths specified in an attributes are properly configured.

Protected functions

void createDefaultPrimBasedAttributesTemplates() override
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(AssetType)>& 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 AbstractAttributesManager-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::managedContainers::ManagedContainerBase.
auto preRegisterObjectFinalize(attributes::ObjectAttributes::ptr attributesTemplate, const std::string& attributesTemplateHandle, bool forceRegistration) -> core::managedContainers::ManagedObjectPreregistration override
This method will perform any essential updating to the managed object before registration is performed. If this updating fails, registration will also fail.
void postRegisterObjectHandling(int objectID, const std::string& objectHandle) override
This method will perform any final manager-related handling after successfully registering an object.
void resetFinalize() override
Any object-attributes-specific resetting that needs to happen on reset.

Protected variables

std::unordered_map<int, std::string>* mapToAddTo_
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

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::finalizeAttrPathsBeforeRegister(const attributes::ObjectAttributes::ptr& attributes) const override

This function will be called to finalize attributes' paths before registration, moving fully qualified paths to the appropriate hidden attribute fields. This can also be called without registration to make sure the paths specified in an attributes are properly configured.

Parameters
attributes The attributes to be filtered.

void esp::metadata::managers::ObjectAttributesManager::setDefaultAssetNameBasedAttributes(attributes::ObjectAttributes::ptr attributes, bool setFrame, const std::string& meshHandle, const std::function<void(AssetType)>& 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 AbstractAttributesManager-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::managedContainers::ManagedContainerBase.

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

core::managedContainers::ManagedObjectPreregistration esp::metadata::managers::ObjectAttributesManager::preRegisterObjectFinalize(attributes::ObjectAttributes::ptr attributesTemplate, const std::string& attributesTemplateHandle, bool forceRegistration) override protected

This method will perform any essential updating to the managed object before registration is performed. If this updating fails, registration will also fail.

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 Whether the preregistration has succeeded and what handle to use to register the object if it has.

void esp::metadata::managers::ObjectAttributesManager::postRegisterObjectHandling(int objectID, const std::string& objectHandle) override protected

This method will perform any final manager-related handling after successfully registering an object.

Parameters
objectID the ID of the successfully registered managed object
objectHandle The name of the managed object