Skip to content

MaterialManager

MaterialManager

MaterialManager(mesh_maker: Model)

Local manager for Material lifecycle and tag assignment.

The manager is intentionally not a singleton. Each :class:Model instance owns one MaterialManager with an independent tag space.

Parameters:

Name Type Description Default
mesh_maker Model

The :class:Model that owns this manager.

required

Raises:

Type Description
TypeError

If mesh_maker is not a :class:Model instance.

Attributes

_mesh_maker instance-attribute

_mesh_maker = mesh_maker

_materials instance-attribute

_materials: Dict[int, Material] = {}

_names instance-attribute

_names: Dict[str, Material] = {}

_start_tag instance-attribute

_start_tag = 1

_tagging instance-attribute

_tagging = CompactRetagPolicy[Material]()

nd instance-attribute

nd = NDMaterialManager(self)

uniaxial instance-attribute

uniaxial = UniaxialMaterialManager(self)

Methods:

add

add(material: Material) -> Material

Add an existing material and assign a tag if needed.

Parameters:

Name Type Description Default
material Material

Unmanaged or already-managed :class:Material instance.

required

Returns:

Type Description
Material

The same material instance after it is stored by this manager.

Raises:

Type Description
TypeError

If material is not a :class:Material instance.

ValueError

If its preassigned tag conflicts with a different object already managed here, or if it already belongs to another manager.

get

get(tag: int) -> Optional[Material]

Return the material with tag if it exists, otherwise None.

get_by_name

get_by_name(name: str) -> Optional[Material]

Return the material with user_name == name, or None.

get_all

get_all() -> Dict[int, Material]

Return a shallow copy of all managed materials keyed by tag.

remove

remove(tag: int) -> None

Remove a managed material and compact the remaining tags.

Parameters:

Name Type Description Default
tag int

Tag of the material to remove. Missing tags are ignored.

required

clear

clear() -> None

Remove all materials and clear their assigned tags.

set_tag_start

set_tag_start(start_tag: int) -> None

Set the first tag used by this manager and retag existing objects.

Parameters:

Name Type Description Default
start_tag int

Positive integer for the first assigned tag.

required

Raises:

Type Description
ValueError

If start_tag is less than 1.

__len__

__len__() -> int

__iter__

__iter__() -> Iterator[Material]

_next_available_tag

_next_available_tag() -> int

_reassign_tags

_reassign_tags() -> None

Rebuild _materials and _names after a removal or start-tag change.