.obj additional exporters/importers

This commit is contained in:
brothermechanic 2023-06-18 15:30:44 +00:00 committed by Igor Brylyov
parent 1fb7077774
commit 47773be8d4
5 changed files with 49 additions and 6 deletions

View file

@ -5,10 +5,9 @@ OBJ mesh exporter.
Exports all objects in scene.
You can set export path and subdir.
"""
__version__ = "0.1"
__version__ = "0.2"
import logging
import sys
import bpy
import os
@ -16,19 +15,22 @@ logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
def export_obj(path, subdir=""):
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
filename = bpy.context.active_object.name
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('vizual:', outpath)
logger.debug('Exporting to %s', outpath)
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)
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)

View file

@ -0,0 +1 @@
## Модули импорта для Blender

View file

@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
"""
DESCRIPTION.
Blender export modules.
Modules exports all objests in scene.
You can set export path and subdir.
"""

View file

@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
"""
DESCRIPTION.
OBJ mesh importer.
Import files in blender scene.
"""
__version__ = "0.2"
import logging
import bpy
import os
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
def import_obj(path):
bpy.ops.object.select_all(action='DESELECT')
path = path.replace('\\', '/')
if os.path.isfile(path) and path.endswith('.obj'):
return bpy.ops.wm.obj_import(filepath=path, global_scale=0.001, clamp_size=0, forward_axis='Y', up_axis='Z')
if os.path.isdir(path):
file_list = sorted(os.listdir(path))
obj_list = [dict(name=item) for item in file_list if item.endswith('.obj')]
return bpy.ops.wm.obj_import(directory=path, files=obj_list, global_scale=0.001, clamp_size=0, forward_axis='Y', up_axis='Z')
return logger.info("Path must be a directory or *.obj file!")

View file

@ -12,3 +12,7 @@
- обработку mesh объектов для использования в качестве ассетов
- импорт FEM материалов и назначение их для mesh объектов
- экспорт mesh объектов в требуемые форматы
### blender_opts.py
Различные операции в Bledner