36 lines
1.3 KiB
Python
36 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
DESCRIPTION.
|
|
OBJ mesh exporter.
|
|
Exports all objects in scene.
|
|
You can set export path and subdir.
|
|
DEPRECATED
|
|
"""
|
|
__version__ = "0.2"
|
|
|
|
import logging
|
|
import bpy
|
|
import os
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def export_obj(path, subdir="", filename=None):
|
|
""" OBJ mesh exporter. Exports all objects in scene. """
|
|
for ob in bpy.context.scene.objects:
|
|
# deselect all but just one object and make it active
|
|
bpy.ops.object.select_all(action='DESELECT')
|
|
ob.select_set(state=True)
|
|
bpy.context.view_layer.objects.active = ob
|
|
if not filename:
|
|
filename = bpy.context.active_object.name
|
|
if not filename.endswith('.obj'):
|
|
filename = (filename + '.obj')
|
|
# export obj
|
|
obj_path = os.path.join(path, subdir).replace('\\', '/')
|
|
if not os.path.isdir(obj_path):
|
|
os.makedirs(obj_path)
|
|
outpath = os.path.join(obj_path, filename)
|
|
logger.debug('Exporting to %s', outpath)
|
|
|
|
return bpy.ops.wm.obj_export(filepath=outpath, forward_axis='Y', up_axis='Z', global_scale=1000, apply_modifiers=True, export_selected_objects=True, export_uv=True, export_normals=True, export_colors=False, export_materials=True, export_pbr_extensions=False, path_mode='AUTO', export_triangulated_mesh=True)
|