Hide navigation sidebar
Hide table of contents sidebar
Back to top
Toggle table of contents sidebar

# `Hydra.common`

Global data and common functions module. Also defines `Heightmap` class.

## Module Contents

class Hydra.common.Heightmap(name: str, txt: moderngl.Texture)

  A wrapper around ModernGL textures.

  size

    Texture size `tuple` property.

  release()

    Releases the stored texture.

  read() → bytes

    Reads the ModernGL texture.

    Returns:

      Pixel data `bytes`.

    Return type:

      `bytes`

  get_size() → tuple[int, int]

    Stored texture size property getter.

    Returns:

      Texture size `tuple`.

    Return type:

      `tuple`

class Hydra.common.HydraData

  Global data object. Stores all ModernGL resources, including the context.

  context: moderngl.Context

    Addon’s ModernGL context. Attached to Blender’s OpenGL context.

  maps: dict[str, Heightmap]

    Heightmap dictionary. Uses UUID strings as keys.

  active: list[mgl.Texture | None] = []

    List of temporary textures for erosion simulations.

  programs: dict[str, moderngl.Program]

    Compiled ModernGL program list.

  shaders: dict[str, moderngl.ComputeShader]

    Compiled ModernGL compute shader list.

  scope: moderngl.Scope

    Temporary ModernGL scope.

  fbo: moderngl.Framebuffer

    Temporary ModernGL Frame Buffer Object.

  running: bool = False

    Unused. Allows erosion to be terminated.

  progress: float = 0.0

    Unused. Erosion progress.

  iteration: int = 0

    Unused. Erosion iteration.

  lastPreview: str | None

    Name of last previewed object.

  info: list[str] = []

    Info message list.

  error: list[str] = []

    Error message list.

  initContext()

    Creates and saves the attached ModernGL `context`.

  hasMap(id: str | None) → bool

    Checks if map exists.

    Returns:

      True if map exists in the `maps` list. False otherwise.

    Return type:

      `bool`

  releaseMap(id: str | None)

    Release specified map. Does nothing on invalid id.

    Parameters:

      id (`str` or `None`) – Map ID.

  createMap(name: str, txt: moderngl.Texture) → str

    Creates and adds a heightmap into maps. Returns map ID.

    Parameters:

      - name (`str`) – Name of created map.

      - txt (`moderngl.Texture`) – Texture to be added.

    Returns:

      New map UUID string.

    Return type:

      `str`

  releaseActive()

    Releases all temporary textures from the `active` list.

  clear()

    Clears `info` and `error` messages.

  report(caller, callerName: str = 'Hydra')

    Shows either stored error or info messages.

    Parameters:

      - caller – Operation calling this function.

      - callerName (`str`) – Message box title.

  freeAll()

    Frees all allocated textures.

Hydra.common.showMessage(message: str, title: str = 'Hydra', icon: str = 'INFO')

  Displays a message as popup.

  Parameters:

    - message (`str`) – Message to be shown.

    - title (`str`) – Popup title.

    - icon (`str`) – Blender icon ID for the popup.

Hydra.common.getPreferences()

  Returns Hydra Blender preferences.

  Returns:

    Blender preferences for the Hydra addon.

Hydra.common.incrementLayer(name: str, default: str) → str

  Increments given layer name.

  Parameters:

    - name (`str`) – Layer name to be incremented.

    - default (`str`) – Default layer name if incrementation fails.

  Returns:

    Incremented layer name.

Hydra.common.getOwner(name: str, previewName: str) → str | None

  Gets the original object, which generated the given name.

  Parameters:

    - name (`str`) – Name, which was generated by other object.

    - previewName (`str`) – Name for a corresponding preview object.

  Returns:

    Name of the original object. None if not found or if name is a preview.

  Return type:

    `str` or `None`

Hydra.common.data: HydraData

  Global data variable for the whole project.