# Path: blendergltf/blendergltf.py
# DEFAULT_SETTINGS = {
#     'gltf_output_dir': '',
#     'gltf_name': 'gltf',
#     'gltf_export_binary': False,
#     'buffers_embed_data': True,
#     'buffers_combine_data': False,
#     'nodes_export_hidden': False,
#     'nodes_global_matrix': mathutils.Matrix.Identity(4),
#     'nodes_global_matrix_apply': True,
#     'nodes_selected_only': False,
#     'blocks_prune_unused': True,
#     'meshes_apply_modifiers': True,
#     'meshes_interleave_vertex_data': True,
#     'meshes_vertex_color_alpha': True,
#     'images_data_storage': 'COPY',
#     'asset_version': '2.0',
#     'asset_copyright': '',
#     'asset_profile': 'WEB',
#     'images_allow_srgb': False,
#     'extension_exporters': [],
#     'animations_object_export': 'ACTIVE',
#     'animations_armature_export': 'ELIGIBLE',
#     'animations_shape_key_export': 'ELIGIBLE',
#     'hacks_streaming': False,
# }
# PROFILE_MAP = {
#     'WEB': {'api': 'WebGL', 'version': '1.0'},
#     'DESKTOP': {'api': 'OpenGL', 'version': '3.0'}
# }
# def togl(matrix):
# def _decompose(matrix):
# def export_joint(state, bone):
# def export_buffers(state):
# def insert_root_nodes(state, root_matrix):
# def build_string_refmap(input_data):
# def build_int_refmap(input_data):
# def initialize_state(settings=None):
# def export_gltf(scene_delta, settings=None):
#         def decompose_apply(matrix):
#         def decompose_mesh_apply(matrix):


from ..blendergltf import Reference


class BlenderPhysics:
    ext_meta = {
        'name': 'BLENDER_physics',
        'url': (
            'https://github.com/Kupoman/blendergltf/tree/master/extensions/'
            'BLENDER_physics'
        ),
        'isDraft': True,
    }

    def export_physics(self, state, obj, gltf_node):
        body = obj.rigid_body
        bounds = [obj.dimensions[i] / gltf_node['scale'][i] for i in range(3)]
        collision_layers = sum(layer << i for i, layer in enumerate(body.collision_groups))
        physics = {
            'collisionShapes': [{
                'shapeType': body.collision_shape.upper(),
                'boundingBox': bounds,
                'primaryAxis': "Z",
            }],
            'mass': body.mass,
            'static': body.type == 'PASSIVE',
            'collisionGroups': collision_layers,
            'collisionMasks': collision_layers,
        }

        if body.collision_shape in ('CONVEX_HULL', 'MESH'):
            mesh = state['mod_meshes'].get(obj.name, obj.data)

# Path: blendergltf/blendergltf.py
# DEFAULT_SETTINGS = {
#     'gltf_output_dir': '',
#     'gltf_name': 'gltf',
#     'gltf_export_binary': False,
#     'buffers_embed_data': True,
#     'buffers_combine_data': False,
#     'nodes_export_hidden': False,
#     'nodes_global_matrix': mathutils.Matrix.Identity(4),
#     'nodes_global_matrix_apply': True,
#     'nodes_selected_only': False,
#     'blocks_prune_unused': True,
#     'meshes_apply_modifiers': True,
#     'meshes_interleave_vertex_data': True,
#     'meshes_vertex_color_alpha': True,
#     'images_data_storage': 'COPY',
#     'asset_version': '2.0',
#     'asset_copyright': '',
#     'asset_profile': 'WEB',
#     'images_allow_srgb': False,
#     'extension_exporters': [],
#     'animations_object_export': 'ACTIVE',
#     'animations_armature_export': 'ELIGIBLE',
#     'animations_shape_key_export': 'ELIGIBLE',
#     'hacks_streaming': False,
# }
# PROFILE_MAP = {
#     'WEB': {'api': 'WebGL', 'version': '1.0'},
#     'DESKTOP': {'api': 'OpenGL', 'version': '3.0'}
# }
# def togl(matrix):
# def _decompose(matrix):
# def export_joint(state, bone):
# def export_buffers(state):
# def insert_root_nodes(state, root_matrix):
# def build_string_refmap(input_data):
# def build_int_refmap(input_data):
# def initialize_state(settings=None):
# def export_gltf(scene_delta, settings=None):
#         def decompose_apply(matrix):
#         def decompose_mesh_apply(matrix):


# Path: blendergltf/extension_exporters/blender_physics.py
from ..blendergltf import Reference



class BlenderPhysics:
    ext_meta = {
        'name': 'BLENDER_physics',
        'url': (
            'https://github.com/Kupoman/blendergltf/tree/master/extensions/'
            'BLENDER_physics'
        ),
        'isDraft': True,
    }

    def export_physics(self, state, obj, gltf_node):
        body = obj.rigid_body
        bounds = [obj.dimensions[i] / gltf_node['scale'][i] for i in range(3)]
        collision_layers = sum(layer << i for i, layer in enumerate(body.collision_groups))
        physics = {
            'collisionShapes': [{
                'shapeType': body.collision_shape.upper(),
                'boundingBox': bounds,
                'primaryAxis': "Z",
            }],
            'mass': body.mass,
            'static': body.type == 'PASSIVE',
            'collisionGroups': collision_layers,
            'collisionMasks': collision_layers,
        }

        if body.collision_shape in ('CONVEX_HULL', 'MESH'):
            mesh = state['mod_meshes'].get(obj.name, obj.data)

            meshref = Reference('meshes', mesh.name, physics['collisionShapes'][0], 'mesh')