__all__ = ["PrimitiveMeshExtension"]

import omni

from .mesh_actions import register_actions, deregister_actions
from pxr import Usd


class PrimitiveMeshExtension(omni.ext.IExt):
    def __init__(self):
        super().__init__()

    def on_startup(self, ext_id):
        self._ext_name = omni.ext.get_extension_name(ext_id)
        self._mesh_generator = None
        try:
            from .generator import MeshGenerator
            self._mesh_generator = MeshGenerator()
            self._mesh_generator.register_menu()
        except ImportError:
            pass
        register_actions(self._ext_name, PrimitiveMeshExtension, lambda: self._mesh_generator)

    def on_shutdown(self):
        deregister_actions(self._ext_name)

        if self._mesh_generator:
            self._mesh_generator.destroy()
