diff options
author | Julien Duroure <julien.duroure@gmail.com> | 2018-12-02 18:44:57 +0300 |
---|---|---|
committer | Julien Duroure <julien.duroure@gmail.com> | 2018-12-02 18:44:57 +0300 |
commit | 6706c91ecf7dd759293b5a7e0b2b75e3c1d7c2e1 (patch) | |
tree | 1a2e3a6ad0514f259793fa4562207f5e9f9d3409 | |
parent | 6e91aa7bedbe09045d1218fc90367d405a722c16 (diff) |
glTF: Fix light export + export options refactoring
8 files changed, 43 insertions, 102 deletions
diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py index 5f226b52..f05e766a 100755 --- a/io_scene_gltf2/__init__.py +++ b/io_scene_gltf2/__init__.py @@ -72,44 +72,21 @@ class ExportGLTF2_Base: # TODO: refactor to avoid boilerplate + export_format: EnumProperty( + name='Format', + items=(('GLB', 'Binary (.glb)', 'Exports a single file, with all data packed in binary form. Most efficient and portable, but more difficult to edit later'), + ('GLTF', 'JSON (.gltf)', 'Exports a single file, with all data packed in JSON. Less efficient than binary, but easier to edit later'), + ('GLTF_SEPARATE', 'JSON (.gltf + .bin + textures)', 'Exports multiple files, with separate JSON (.gltf), binary (.bin), and texture data. Easiest to edit later')), + description='Output format and embedding options. Binary is most efficient, but JSON (embedded or separate) may be easier to edit later', + default='GLB' + ) + export_copyright: StringProperty( name='Copyright', description='Legal rights and conditions for the model', default='' ) - export_embed_buffers: BoolProperty( - name='Embed Buffers', - description='Buffers (mesh, animation, and optionally image data) are' \ - ' embedded in the asset, rather than in separate (.bin) files.' \ - ' Total size will be slightly larger than when embedded within a ' \ - ' binary glTF (.glb) file', - default=False - ) - - export_embed_images: BoolProperty( - name='Embed Images', - description='Images are embedded in asset buffers, rather than in' \ - ' separate image files', - default=False - ) - - export_indices: EnumProperty( - name='Maximum Indices Type', - items=(('UNSIGNED_BYTE', 'Unsigned Byte', ''), - ('UNSIGNED_SHORT', 'Unsigned Short', ''), - ('UNSIGNED_INT', 'Unsigned Integer', '')), - description='Largest data type allowed for indices', - default='UNSIGNED_INT' - ) - - export_force_indices: BoolProperty( - name='Force Maximum Indices', - description='Always use the selected indices data type, even if the' \ - ' size of the mesh does not require it', - default=False - ) - export_texcoords: BoolProperty( name='UVs', description='Export UVs (texture coordinates) with meshes', @@ -309,6 +286,11 @@ class ExportGLTF2_Base: if self.will_save_settings: self.save_settings(context) + if self.export_format == 'GLB': + self.filename_ext = '.glb' + else: + self.filename_ext = '.gltf' + # All custom export settings are stored in this container. export_settings = {} @@ -319,10 +301,6 @@ class ExportGLTF2_Base: export_settings['gltf_format'] = self.export_format export_settings['gltf_copyright'] = self.export_copyright - export_settings['gltf_embed_buffers'] = self.export_embed_buffers - export_settings['gltf_embed_images'] = self.export_embed_images - export_settings['gltf_indices'] = self.export_indices - export_settings['gltf_force_indices'] = self.export_force_indices export_settings['gltf_texcoords'] = self.export_texcoords export_settings['gltf_normals'] = self.export_normals export_settings['gltf_tangents'] = self.export_tangents and self.export_normals @@ -378,27 +356,17 @@ class ExportGLTF2_Base: # col = layout.box().column() - col.label(text='Embedding:') # , icon='PACKAGE') - col.prop(self, 'export_copyright') - if self.export_format == 'ASCII': - col.prop(self, 'export_embed_buffers') - col.prop(self, 'export_embed_images') - - col = layout.box().column() - col.label(text='Nodes:') # , icon='OOPS') + col.label(text='General:', icon='PREFERENCES') + col.prop(self, 'export_format') col.prop(self, 'export_selected') #col.prop(self, 'export_layers') - col.prop(self, 'export_extras') - col.prop(self, 'export_yup') - - col = layout.box().column() - col.label(text='Meshes:') # , icon='MESH_DATA') col.prop(self, 'export_apply') - col.prop(self, 'export_indices') - col.prop(self, 'export_force_indices') + col.prop(self, 'export_yup') + col.prop(self, 'export_extras') + col.prop(self, 'export_copyright') col = layout.box().column() - col.label(text='Attributes:') # , icon='SURFACE_DATA') + col.label(text='Meshes:', icon='MESH_DATA') col.prop(self, 'export_texcoords') col.prop(self, 'export_normals') if self.export_normals: @@ -406,20 +374,17 @@ class ExportGLTF2_Base: col.prop(self, 'export_colors') col = layout.box().column() - col.label(text='Objects:') # , icon='OBJECT_DATA') + col.label(text='Objects:', icon='OBJECT_DATA') col.prop(self, 'export_cameras') + col.prop(self, 'export_lights') col = layout.box().column() - col.label(text='Materials:') # , icon='MATERIAL_DATA') + col.label(text='Materials:', icon='MATERIAL_DATA') col.prop(self, 'export_materials') col.prop(self, 'export_texture_transform') col = layout.box().column() - col.label(text='Lights:') # , icon='LIGHT_DATA') - col.prop(self, 'export_lights') - - col = layout.box().column() - col.label(text='Animation:') # , icon='OUTLINER_DATA_POSE') + col.label(text='Animation:', icon='ARMATURE_DATA') col.prop(self, 'export_animations') if self.export_animations: col.prop(self, 'export_frame_range') @@ -444,40 +409,26 @@ class ExportGLTF2_Base: text=GLTF2ExportSettings.bl_label, icon="%s" % "PINNED" if self.will_save_settings else "UNPINNED") -# TODO: refactor operators to single operator for both cases -class ExportGLTF2_GLTF(bpy.types.Operator, ExportGLTF2_Base, ExportHelper): +class ExportGLTF2(bpy.types.Operator, ExportGLTF2_Base, ExportHelper): """Export scene as glTF 2.0 file""" bl_idname = 'export_scene.gltf' - bl_label = 'Export glTF 2.0' - - filename_ext = '.gltf' - filter_glob: StringProperty(default='*.gltf', options={'HIDDEN'}) - - export_format = 'ASCII' - - -class ExportGLTF2_GLB(bpy.types.Operator, ExportGLTF2_Base, ExportHelper): - """Export scene as binary glTF 2.0 file""" - bl_idname = 'export_scene.glb' - bl_label = 'Export Binary glTF 2.0' + bl_label = 'glTF 2.0 (.glb/.gltf)' - filename_ext = '.glb' - filter_glob: StringProperty(default='*.glb', options={'HIDDEN'}) + filename_ext = '' - export_format = 'BINARY' + filter_glob: StringProperty(default='*.glb;*.gltf', options={'HIDDEN'}) def menu_func_export(self, context): - self.layout.operator(ExportGLTF2_GLTF.bl_idname, text='glTF 2.0 (.gltf)') - self.layout.operator(ExportGLTF2_GLB.bl_idname, text='Binary glTF 2.0 (.glb)') + self.layout.operator(ExportGLTF2.bl_idname, text='glTF 2.0 (.glb/.gltf)') -class ImportglTF2(Operator, ImportHelper): +class ImportGLTF2(Operator, ImportHelper): bl_idname = 'import_scene.gltf' - bl_label = "glTF 2.0 (.gltf/.glb)" + bl_label = 'glTF 2.0 (.glb/.gltf)' - filter_glob: StringProperty(default="*.gltf;*.glb", options={'HIDDEN'}) + filter_glob: StringProperty(default="*.glb;*.gltf", options={'HIDDEN'}) loglevel: EnumProperty(items=Log.get_levels(), name="Log Level", default=Log.default()) @@ -531,14 +482,13 @@ class ImportglTF2(Operator, ImportHelper): def menu_func_import(self, context): - self.layout.operator(ImportglTF2.bl_idname, text=ImportglTF2.bl_label) + self.layout.operator(ImportGLTF2.bl_idname, text=ImportGLTF2.bl_label) classes = ( GLTF2ExportSettings, - ExportGLTF2_GLTF, - ExportGLTF2_GLB, - ImportglTF2 + ExportGLTF2, + ImportGLTF2 ) diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_export.py b/io_scene_gltf2/blender/exp/gltf2_blender_export.py index ae2db26b..1adbe473 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_export.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_export.py @@ -43,9 +43,9 @@ def save(operator, exporter.add_animation(animation) buffer = bytes() - if export_settings[gltf2_blender_export_keys.FORMAT] == 'ASCII': + if export_settings[gltf2_blender_export_keys.FORMAT] != 'GLB': # .gltf - if export_settings[gltf2_blender_export_keys.EMBED_BUFFERS]: + if export_settings[gltf2_blender_export_keys.FORMAT] == 'GLTF': exporter.finalize_buffer(export_settings[gltf2_blender_export_keys.FILE_DIRECTORY]) else: exporter.finalize_buffer(export_settings[gltf2_blender_export_keys.FILE_DIRECTORY], diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_export_keys.py b/io_scene_gltf2/blender/exp/gltf2_blender_export_keys.py index 06271a04..ca9ca139 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_export_keys.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_export_keys.py @@ -39,13 +39,11 @@ FILE_DIRECTORY = 'gltf_filedirectory' BINARY_FILENAME = 'gltf_binaryfilename' YUP = 'gltf_yup' MORPH = 'gltf_morph' -INDICES = 'gltf_indices' BAKE_SKINS = 'gltf_bake_skins' TEX_COORDS = 'gltf_texcoords' COLORS = 'gltf_colors' NORMALS = 'gltf_normals' TANGENTS = 'gltf_tangents' -FORCE_INDICES = 'gltf_force_indices' MORPH_TANGENT = 'gltf_morph_tangent' MORPH_NORMAL = 'gltf_morph_normal' MOVE_KEYFRAMES = 'gltf_move_keyframes' diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_extract.py b/io_scene_gltf2/blender/exp/gltf2_blender_extract.py index a5220129..c26429d3 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_extract.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_extract.py @@ -970,10 +970,6 @@ def extract_primitives(glTF, blender_mesh, blender_vertex_groups, modifiers, exp # range_indices = 65536 - if export_settings[gltf2_blender_export_keys.INDICES] == 'UNSIGNED_BYTE': - range_indices = 256 - elif export_settings[gltf2_blender_export_keys.INDICES] == 'UNSIGNED_INT': - range_indices = 4294967296 # diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_image.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_image.py index b89f51d7..42dd9bd7 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_image.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_image.py @@ -80,7 +80,7 @@ def __gather_name(sockets_or_slots, export_settings): def __gather_uri(sockets_or_slots, export_settings): - if export_settings[gltf2_blender_export_keys.FORMAT] == 'ASCII': + if export_settings[gltf2_blender_export_keys.FORMAT] != 'GLB': # as usual we just store the data in place instead of already resolving the references return __get_image_data(sockets_or_slots) return None diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py index 6186159c..dbfafbde 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py @@ -49,12 +49,12 @@ def gather_node(blender_object, export_settings): ) node.translation, node.rotation, node.scale = __gather_trans_rot_scale(blender_object, export_settings) - if blender_object.type == 'LIGHT': + if blender_object.type == 'LIGHT' and export_settings[gltf2_blender_export_keys.LIGHTS]: correction_node = __get_correction_node(blender_object, export_settings) correction_node.extensions = {"KHR_lights_punctual": node.extensions["KHR_lights_punctual"]} del node.extensions["KHR_lights_punctual"] node.children.append(correction_node) - if blender_object.type == 'CAMERA': + if blender_object.type == 'CAMERA' and export_settings[gltf2_blender_export_keys.CAMERAS]: correction_node = __get_correction_node(blender_object, export_settings) correction_node.camera = node.camera node.camera = None diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_primitives.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_primitives.py index 5b3e607b..4fa025b2 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_primitives.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_primitives.py @@ -15,7 +15,7 @@ import bpy from typing import List, Optional -from .gltf2_blender_export_keys import INDICES, FORCE_INDICES, NORMALS, MORPH_NORMAL, TANGENTS, MORPH_TANGENT, MORPH +from .gltf2_blender_export_keys import NORMALS, MORPH_NORMAL, TANGENTS, MORPH_TANGENT, MORPH from io_scene_gltf2.blender.exp.gltf2_blender_gather_cache import cached from io_scene_gltf2.blender.exp import gltf2_blender_extract @@ -83,9 +83,6 @@ def __gather_indices(blender_primitive, blender_mesh, modifiers, export_settings print_console('ERROR', 'Invalid max_index: ' + str(max_index)) return None - if export_settings[FORCE_INDICES]: - component_type = gltf2_io_constants.ComponentType.from_legacy_define(export_settings[INDICES]) - element_type = gltf2_io_constants.DataType.Scalar binary_data = gltf2_io_binary_data.BinaryData.from_list(indices, component_type) return gltf2_io.Accessor( diff --git a/io_scene_gltf2/io/exp/gltf2_io_export.py b/io_scene_gltf2/io/exp/gltf2_io_export.py index ebfad744..286d4e75 100755 --- a/io_scene_gltf2/io/exp/gltf2_io_export.py +++ b/io_scene_gltf2/io/exp/gltf2_io_export.py @@ -32,7 +32,7 @@ def save_gltf(glTF, export_settings, encoder, glb_buffer): indent = None separators = separators = (',', ':') - if export_settings['gltf_format'] == 'ASCII': + if export_settings['gltf_format'] != 'GLB': indent = 4 # The comma is typically followed by a newline, so no trailing whitespace is needed on it. separators = separators = (',', ' : ') @@ -41,7 +41,7 @@ def save_gltf(glTF, export_settings, encoder, glb_buffer): # - if export_settings['gltf_format'] == 'ASCII': + if export_settings['gltf_format'] != 'GLB': file = open(export_settings['gltf_filepath'], "w", encoding="utf8", newline="\n") file.write(glTF_encoded) file.write("\n") |