blueprints.cache module#
- class blueprints.cache.BaseCache[source]#
Bases:
UniqueThing,CacheTypeCachesare used to store large amounts of data. For blueprints to allow for the modification of this data, it has to be loaded to memory. If this data is part of a Thing which is copied multiple times, this would drastically increase the memory usage for redundant data. Caches solve this, by implementing a single source of data for multiple copies of a Thing. Thing classes that contain large amounts of data can simply outsource them to a cache (by linking the outsourced properties to the caches properties) while keeping small attributes that are modified frequently. To ensure data integrity, if a Things property which is stored in itsCacheis modified, a new copy of the caches content is created replacing the oldcacheattribute of the Thing (unless only one Thing uses the Cache, in which case the Cache is modified directly). For example, consider the following scenario:Cache example — The large data attribute is outsourced to a Cache#>>> one = SomeThing(data=open('large.file').read()) >>> one.cache SomeCache<None:2> >>> one.data is one.cache.data True >>> two = one.copy() >>> one.cache is two.cache True >>> one.name = 'one' >>> two.name = 'two' >>> one.cache is two.cache True >>> two.data = open('other.file').read() >>> one.cache is two.cache False
- class blueprints.cache.MeshCache[source]#
Bases:
MeshCacheType,BaseCacheThis class stores the mesh data which might be loaded from a file and is too large to be copied frequently.
- built#
A flag indicating whether the MeshAssets has been built. This is necessary since multiple
MeshAssetsmight use the sameMeshCachein which case it should be built only once.- Type:
bool
- centered#
If
Truethe vertecies are normalized such that their mean position is the reference frames origin.- Type:
bool
- vertecies#
The list of vertecies. Each vertex is a np.ndarray with 3 components for each of the spatial dimensions.
- Type:
list
- texcoords#
The list of texture coordinates.
- Type:
list
- texcoords_idx#
A dictionary used to link texture coordinates with face vertecies.
- Type:
dict
- normals#
The normals used by mujoco, this attribute is derived and should not be used for modification, see
face_normalsorvertex_normalsfor this instead.- Type:
list
- face_normals#
Face normals are the normal vectors of faces. They specify the direction in which the face points.
- Type:
list
- vertex_normals#
Vertex normals are the normal vectors of vertecies. They specify the direction in which the vertecies of a face point. Specifying vertex normals instead of face normals enables mujoco to renderer soft edges.
- Type:
list
- normals_idx#
A dictionary used to link normals with faces.
- Type:
TYPE
- faces#
This attribute is used to write to xml. It returns a flattened list of indecies that is written raw to xml. For a structured list of faces see
faces.- Type:
list
- filename#
The user specified file name.
- Type:
str
- __init__(vertecies=None, faces=None, filename=None, centered=False, **kwargs)[source]#
- Parameters:
vertecies (
np.ndarray | list[np.ndarray | list[float | int]] | None, optional) – A list of all vertex positions.faces (
list[np.ndarray | list[float | int]] | None, optional) – A list of all faces. A face consists of at least 3 indecies of vertecies.file (
str | None, optional) – The filename from which the mesh data is loaded and to to which the mesh will be saved. The file is saved in a special directory such that no input file is overwritten by the output file.centered (
bool, optional) – IfTruethe vertecies are normalized such that their mean position is the reference frames origin.**kwargs – Keyword arguments are passed to
super().__init__.filename (str | None)
- Return type:
None
- copy(**kwargs)[source]#
This method constructs a copy of the Cache with possible alterations to its attributes as specified in kwargs.
- Parameters:
**kwargs – Keyword arguments are passed to the
__init__()to replace the attributes of the current Thing from which copy is called.- Returns:
A new instance of the Cache
- Return type:
blue.CacheType
- load(filename)[source]#
This methods loads the mesh data from a file.
- Parameters:
filename (
str) – Possible file types are'.stl'binary or ascii and'.obj'ascii.- Return type:
None
- save(file)[source]#
This method saves the Mesh data to a file.
- Parameters:
file (
str) – The name to which the file is saved.- Raises:
NotImplemented – If the file format is not supported an error is raised.
- Return type:
None
- property file: str | None#
Filename for Mujoco XML
- Return type:
str
- property vertex#
- returns: This attribute is used to write construct the mujoco xml. It returns a flattened list of
coordinates that is written raw to xml. For a structured list of vertecies see
vertecies.
- Return type:
np.ndarray
- property face: ndarray | None#
- returns: This attribute is used to write construct the mujoco xml. It returns a flattened list of
coordinates that is written raw to xml. For a structured list of faces see
faces.
- Return type:
np.ndarray | None
- property texcoord: ndarray | None#
- returns: This attribute is used to write to xml. It returns a flattened list of texture coordinates that
is written raw to xml. For a structured list of texture coordinates see
texcoords.
- Return type:
np.ndarray | None
- property normal: ndarray | None#
- returns: This attribute is used to write to xml. It returns a flattened list of face normals that
is written raw to xml. For a structured list of face normals see
normals.
- Return type:
np.ndarray | None
- property size: ndarray#
- returns: The size of the Mesh is computed as the difference of the minimal and maximal component
for each axis on each vertex.
- Return type:
np.ndarray
- property vertecies: ndarray#
- returns: The list of vertecies. Each vertex is a np.ndarray with 3 components for each of the
spatial dimensions.
- Return type:
np.ndarray
- property faces: list[ndarray] | None#
- returns: The list of faces. Each face is a np.ndarray with n indecies for each of the vertecies
of the face.
- Return type:
list[np.ndarray] | None
- property texcoords: list[ndarray] | None#
- returns: The list of texture coordinates. Each texture coordinate is a np.ndarray with
coordinates in the range [0, 1] specifying the point on the texture which is mapped to the referencing face vertex.
- Return type:
list[np.ndarray] | None
- property texcoords_idx: dict | None#
returns: The list of texture coordinate indecies for faces. :rtype:
dict | None
- property face_normals: list[ndarray] | None#
- returns: Face normals are the normal vectors of faces. They specify the direction in which the
face points.
- Return type:
list[np.ndarray] | None
- property vertex_normals: list[ndarray] | None#
- returns: Vertex normals are the normal vectors of vertecies. They specify the direction in which
the vertecies of a face point. Specifying vertex normals instead of face normals enables mujoco torenderer soft edges.
- Return type:
list[np.ndarray] | None
- property normals_idx: dict | None#
The list of normals indecies for faces.
- Return type:
dict | None
- property vertecies_min#
The minimum for each axis component of all vertecies.
- Return type:
np.ndarray
- property vertecies_max#
The maximum for each axis component of all vertecies.
- Return type:
np.ndarray
- property vertecies_center#
The middle point for each axis component of all vertecies.
- Return type:
np.ndarray
- class blueprints.cache.HFieldCache[source]#
Bases:
HFieldCacheType,BaseCache- __init__(terrain=None, filename=None, **kwargs)[source]#
- Parameters:
terrain (ndarray | list[ndarray | list[float | int]] | None)
filename (str | None)
- copy(**kwargs)[source]#
This method constructs a copy of the Cache with possible alterations to its attributes as specified in kwargs.
- Parameters:
**kwargs – Keyword arguments are passed to the
__init__()to replace the attributes of the current Thing from which copy is called.- Returns:
A new instance of the Cache
- Return type:
blue.CacheType
- load(filename)[source]#
This methods loads the mesh data from a file.
- Parameters:
filename (
str) – Possible file types are'.stl'binary or ascii and'.obj'ascii.- Return type:
None
- save(filename)[source]#
This method saves the Mesh data to a file.
- Parameters:
file (
str) – The name to which the file is saved.filename (str)
- Raises:
NotImplemented – If the file format is not supported an error is raised.
- Return type:
None
- property elevation#
Derived dummy property
- property nrow: int#
Number of rows in the terrain.
- Return type:
int
- property ncol: int#
Number of collumns in the terrain.
- Return type:
int
- property filename: str#
The filename of the hfield data.
- Return type:
str
- property terrain: ndarray#
- returns: The list of vertecies. Each vertex is a np.ndarray with 3 components for each of the
spatial dimensions.
- Return type:
np.ndarray
- property file: str#
Dummy variable for the default names of hfield data files.
- Return type:
str