rhodonite
    Preparing search index...

    Class MaterialRepository

    Repository class for managing material types and instances. Handles registration, creation, and lifecycle management of materials.

    Index

    Constructors

    Properties

    _soloDatumFields: Map<string, Map<string, ShaderVariable>> = ...

    Solo datum fields for each material type (engine-specific, not shared across engines)

    Accessors

    • get stateVersion(): number

      Gets the current state version for materials in this repository. This version is incremented whenever any material's state changes.

      Returns number

      The current state version number

    Methods

    • Internal

      Invalidates all shader programs for all registered materials. This method is typically called when global shader settings change and all materials need to recompile their shaders.

      Returns void

    • Internal

      Invalidates shader programs only for materials that are affected by morph changes. Affected materials are those that support morphing and are currently used by primitives with morph targets.

      Returns void

    • Creates a new material instance of the specified type. The material type must be registered before calling this method. This method handles instance counting and initialization.

      Parameters

      • engine: Engine
      • materialTypeName: string

        The name of the registered material type

      • materialNode: AbstractMaterialContent

        The material content definition for this specific instance

      Returns Material

      A new Material instance with proper initialization

      Error if the material type is not registered or maximum instances exceeded

    • Forcibly registers a material type, overwriting any existing registration. This method bypasses the duplicate check and always performs the registration. Use with caution as it can replace existing material type definitions.

      Parameters

      • engine: Engine
      • materialTypeName: string

        The unique name identifier for the material type

      • materialNode: AbstractMaterialContent

        The material content definition containing shader semantics and properties

      • materialCountPerBufferView: number = engine.config.materialCountPerBufferView

        The number of materials per buffer view

      Returns boolean

      Always returns true as the registration is forced

    • Gets all currently active material instances from the repository. Returns an array of WeakRef objects that may contain undefined values if materials have been garbage collected.

      Returns WeakRef<Material>[]

      Array of WeakRef objects pointing to all registered materials

    • Gets the memory location offset for a specific property of a material type. The offset is calculated in 16-byte aligned units for GPU buffer access. This is used for efficient GPU memory access in shaders.

      Parameters

      • engine: Engine

        The engine instance

      • materialTypeName: string

        The name of the material type

      • propertyName: string

        The shader semantic name of the property

      Returns number[]

      The byte offset divided by 16 (IndexOf16Bytes) for the property location

    • Retrieves a material instance by its unique identifier. Returns undefined if the material doesn't exist or has been garbage collected.

      Parameters

      • materialUid: number

        The unique identifier of the material to retrieve

      Returns Material | undefined

      The material instance if found and still alive, undefined otherwise

    • Determines if a new material node is compatible with an existing material. Compatibility is checked by comparing shader semantics information arrays. Materials are compatible if they have identical shader semantic structures.

      Parameters

      • currentMaterial: Material

        The existing material to compare against

      • newMaterialNode: AbstractMaterialContent

        The new material node to check for compatibility

      Returns boolean

      True if the materials are compatible, false otherwise

    • Checks if a material type is already registered in the repository.

      Parameters

      • materialTypeName: string

        The name of the material type to check

      Returns boolean

      True if the material type is registered, false otherwise

    • Registers a new material type with the repository. This method creates the necessary data structures and allocates memory for the material type. If the material type is already registered, the registration will be skipped.

      Parameters

      • engine: Engine
      • materialTypeName: string

        The unique name identifier for the material type

      • materialNode: AbstractMaterialContent

        The material content definition containing shader semantics and properties

      • materialCountPerBufferView: number = engine.config.materialCountPerBufferView

        The number of materials per buffer view

      Returns boolean

      True if the material type was successfully registered, false if it was already registered