# Path: third_party/xiuminglib/xiuminglib/imprt.py
# def preset_import(name, assert_success=False):
#     """A unified importer for both regular and ``google3`` modules, according
#     to specified presets/profiles (e.g., ignoring ``ModuleNotFoundError``).
#     """
#     if name in ('cv2', 'opencv'):
#         try:
#             # BUILD dep:
#             # "//third_party/py/cvx2",
#             from cvx2 import latest as mod
#             # Or
#             # BUILD dep:
#             # "//third_party/OpenCVX:cvx2",
#             # from google3.third_party.OpenCVX import cvx2 as cv2
#         except ModuleNotFoundError:
#             mod = import_module_404ok('cv2')
# 
#     elif name in ('tf', 'tensorflow'):
#         mod = import_module_404ok('tensorflow')
# 
#     elif name == 'gfile':
#         # BUILD deps:
#         # "//pyglib:gfile",
#         # "//file/colossus/cns",
#         mod = import_module_404ok('google3.pyglib.gfile')
# 
#     elif name == 'video_api':
#         # BUILD deps:
#         # "//learning/deepmind/video/python:video_api",
#         mod = import_module_404ok(
#             'google3.learning.deepmind.video.python.video_api')
# 
#     elif name in ('bpy', 'bmesh', 'OpenEXR', 'Imath'):
#         # BUILD deps:
#         # "//third_party/py/Imath",
#         # "//third_party/py/OpenEXR",
#         mod = import_module_404ok(name)
# 
#     elif name in ('Vector', 'Matrix', 'Quaternion'):
#         mod = import_module_404ok('mathutils')
#         mod = _get_module_class(mod, name)
# 
#     elif name == 'BVHTree':
#         mod = import_module_404ok('mathutils.bvhtree')
#         mod = _get_module_class(mod, name)
# 
#     else:
#         raise NotImplementedError(name)
# 
#     if assert_success:
#         assert mod is not None, "Failed in importing '%s'" % name
# 
#     return mod
# 
# Path: third_party/xiuminglib/xiuminglib/log.py
# def get_logger(level=None):
#     """Creates a logger for functions in the library.
# 
#     Args:
#         level (str, optional): Logging level. Defaults to ``logging.INFO``.
# 
#     Returns:
#         logging.Logger: Logger created.
#     """
#     if level is None:
#         level = logging.INFO
#     logging.basicConfig(level=level)
#     logger = logging.getLogger()
#     return logger


from os.path import basename
from ..imprt import preset_import
from ..log import get_logger
import numpy as np
    # Point it to target
    direction = target - light.location
    # Find quaternion that rotates lamp facing direction '-Z',
    # so that it aligns with 'direction'
    # This rotation is not unique because the rotated lamp can still rotate
    # about direction vector
    # Specifying 'Y' gives the rotation quaternion with lamp's 'Y' pointing up
    rot_quat = direction.to_track_quat('-Z', 'Y')
    light.rotation_euler = rot_quat.to_euler()

    logger.info("Lamp '%s' points to %s now", light.name, target)


def add_light_sun(xyz=(0, 0, 0), rot_vec_rad=(0, 0, 0), name=None,
                  energy=1, size=0.1):
    """Adds a sun lamp that emits parallel light rays.

    Args:
        xyz (tuple(float), optional): Location only used to compute light ray
            direction.
        rot_vec_rad (tuple(float), optional): Rotations in radians around x,
            y and z.
        name (str, optional): Light name.
        energy (float, optional): Light intensity.
        size (float, optional): Light size for ray shadow tracing. Use larger
            for softer shadows.

    Returns:
        bpy_types.Object: Light added.
    """

# Path: third_party/xiuminglib/xiuminglib/imprt.py
# def preset_import(name, assert_success=False):
#     """A unified importer for both regular and ``google3`` modules, according
#     to specified presets/profiles (e.g., ignoring ``ModuleNotFoundError``).
#     """
#     if name in ('cv2', 'opencv'):
#         try:
#             # BUILD dep:
#             # "//third_party/py/cvx2",
#             from cvx2 import latest as mod
#             # Or
#             # BUILD dep:
#             # "//third_party/OpenCVX:cvx2",
#             # from google3.third_party.OpenCVX import cvx2 as cv2
#         except ModuleNotFoundError:
#             mod = import_module_404ok('cv2')
# 
#     elif name in ('tf', 'tensorflow'):
#         mod = import_module_404ok('tensorflow')
# 
#     elif name == 'gfile':
#         # BUILD deps:
#         # "//pyglib:gfile",
#         # "//file/colossus/cns",
#         mod = import_module_404ok('google3.pyglib.gfile')
# 
#     elif name == 'video_api':
#         # BUILD deps:
#         # "//learning/deepmind/video/python:video_api",
#         mod = import_module_404ok(
#             'google3.learning.deepmind.video.python.video_api')
# 
#     elif name in ('bpy', 'bmesh', 'OpenEXR', 'Imath'):
#         # BUILD deps:
#         # "//third_party/py/Imath",
#         # "//third_party/py/OpenEXR",
#         mod = import_module_404ok(name)
# 
#     elif name in ('Vector', 'Matrix', 'Quaternion'):
#         mod = import_module_404ok('mathutils')
#         mod = _get_module_class(mod, name)
# 
#     elif name == 'BVHTree':
#         mod = import_module_404ok('mathutils.bvhtree')
#         mod = _get_module_class(mod, name)
# 
#     else:
#         raise NotImplementedError(name)
# 
#     if assert_success:
#         assert mod is not None, "Failed in importing '%s'" % name
# 
#     return mod
# 
# Path: third_party/xiuminglib/xiuminglib/log.py
# def get_logger(level=None):
#     """Creates a logger for functions in the library.
# 
#     Args:
#         level (str, optional): Logging level. Defaults to ``logging.INFO``.
# 
#     Returns:
#         logging.Logger: Logger created.
#     """
#     if level is None:
#         level = logging.INFO
#     logging.basicConfig(level=level)
#     logger = logging.getLogger()
#     return logger


# Path: third_party/xiuminglib/xiuminglib/blender/light.py
from os.path import basename
from ..imprt import preset_import
from ..log import get_logger
import numpy as np

    # Point it to target
    direction = target - light.location
    # Find quaternion that rotates lamp facing direction '-Z',
    # so that it aligns with 'direction'
    # This rotation is not unique because the rotated lamp can still rotate
    # about direction vector
    # Specifying 'Y' gives the rotation quaternion with lamp's 'Y' pointing up
    rot_quat = direction.to_track_quat('-Z', 'Y')
    light.rotation_euler = rot_quat.to_euler()

    logger.info("Lamp '%s' points to %s now", light.name, target)


def add_light_sun(xyz=(0, 0, 0), rot_vec_rad=(0, 0, 0), name=None,
                  energy=1, size=0.1):
    """Adds a sun lamp that emits parallel light rays.

    Args:
        xyz (tuple(float), optional): Location only used to compute light ray
            direction.
        rot_vec_rad (tuple(float), optional): Rotations in radians around x,
            y and z.
        name (str, optional): Light name.
        energy (float, optional): Light intensity.
        size (float, optional): Light size for ray shadow tracing. Use larger
            for softer shadows.

    Returns:
        bpy_types.Object: Light added.
    """

    bpy = preset_import('bpy', assert_success=True)