glTF exporter: various fixes / enhancements

* export double-sided mesh flag
* add export time logging
* Enhacement of export at current frame / frame 0 management
This commit is contained in:
Julien Duroure 2019-02-21 14:17:11 +01:00
parent 29a359840e
commit 62af5c6886
5 changed files with 26 additions and 21 deletions

View File

@ -179,12 +179,6 @@ class ExportGLTF2_Base:
max=120
)
export_move_keyframes: BoolProperty(
name='Keyframes Start at 0',
description='Keyframes start at 0, instead of 1',
default=True
)
export_force_sampling: BoolProperty(
name='Always Sample Animations',
description='Apply sampling to all animations',
@ -194,7 +188,7 @@ class ExportGLTF2_Base:
export_current_frame: BoolProperty(
name='Use Current Frame',
description='Export the scene in the current animation frame',
default=True
default=False
)
export_skins: BoolProperty(
@ -313,14 +307,12 @@ class ExportGLTF2_Base:
export_settings['gltf_extras'] = self.export_extras
export_settings['gltf_yup'] = self.export_yup
export_settings['gltf_apply'] = self.export_apply
export_settings['gltf_current_frame'] = self.export_current_frame
export_settings['gltf_animations'] = self.export_animations
if self.export_animations:
export_settings['gltf_current_frame'] = False
export_settings['gltf_frame_range'] = self.export_frame_range
export_settings['gltf_move_keyframes'] = self.export_move_keyframes
export_settings['gltf_force_sampling'] = self.export_force_sampling
else:
export_settings['gltf_current_frame'] = self.export_current_frame
export_settings['gltf_frame_range'] = False
export_settings['gltf_move_keyframes'] = False
export_settings['gltf_force_sampling'] = False
@ -389,14 +381,13 @@ class ExportGLTF2_Base:
def draw_animation_settings(self):
col = self.layout.box().column()
col.prop(self, 'export_current_frame')
col.prop(self, 'export_animations')
if self.export_animations:
col.prop(self, 'export_frame_range')
col.prop(self, 'export_frame_step')
col.prop(self, 'export_move_keyframes')
col.prop(self, 'export_force_sampling')
else:
col.prop(self, 'export_current_frame')
col.prop(self, 'export_skins')
if self.export_skins:
col.prop(self, 'export_bake_skins')

View File

@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import time
import bpy
import sys
@ -29,10 +30,20 @@ def save(context, export_settings):
if bpy.context.active_object is not None:
bpy.ops.object.mode_set(mode='OBJECT')
original_frame = bpy.context.scene.frame_current
if not export_settings['gltf_current_frame']:
bpy.context.scene.frame_set(0)
__notify_start(context)
start_time = time.time()
json, buffer = __export(export_settings)
__write_file(json, buffer, export_settings)
__notify_end(context)
end_time = time.time()
__notify_end(context, end_time - start_time)
if not export_settings['gltf_current_frame']:
bpy.context.scene.frame_set(original_frame)
return {'FINISHED'}
@ -123,8 +134,8 @@ def __notify_start(context):
context.window_manager.progress_update(0)
def __notify_end(context):
print_console('INFO', 'Finished glTF 2.0 export')
def __notify_end(context, elapsed):
print_console('INFO', 'Finished glTF 2.0 export in {} s'.format(elapsed))
context.window_manager.progress_end()
print_newline()

View File

@ -46,7 +46,6 @@ NORMALS = 'gltf_normals'
TANGENTS = 'gltf_tangents'
MORPH_TANGENT = 'gltf_morph_tangent'
MORPH_NORMAL = 'gltf_morph_normal'
MOVE_KEYFRAMES = 'gltf_move_keyframes'
MATERIALS = 'gltf_materials'
EXTRAS = 'gltf_extras'
CAMERAS = 'gltf_cameras'

View File

@ -27,7 +27,7 @@ from io_scene_gltf2.blender.exp import gltf2_blender_get
@cached
def gather_material(blender_material, export_settings):
def gather_material(blender_material, mesh_double_sided, export_settings):
"""
Gather the material used by the blender primitive.
@ -41,7 +41,7 @@ def gather_material(blender_material, export_settings):
material = gltf2_io.Material(
alpha_cutoff=__gather_alpha_cutoff(blender_material, export_settings),
alpha_mode=__gather_alpha_mode(blender_material, export_settings),
double_sided=__gather_double_sided(blender_material, export_settings),
double_sided=__gather_double_sided(blender_material, mesh_double_sided, export_settings),
emissive_factor=__gather_emissive_factor(blender_material, export_settings),
emissive_texture=__gather_emissive_texture(blender_material, export_settings),
extensions=__gather_extensions(blender_material, export_settings),
@ -87,7 +87,10 @@ def __gather_alpha_mode(blender_material, export_settings):
return None
def __gather_double_sided(blender_material, export_settings):
def __gather_double_sided(blender_material, mesh_double_sided, export_settings):
if mesh_double_sided:
return True
old_double_sided_socket = gltf2_blender_get.get_socket_or_texture_slot_old(blender_material, "DoubleSided")
if old_double_sided_socket is not None and\
not old_double_sided_socket.is_linked and\

View File

@ -63,10 +63,11 @@ def gather_primitives(
def __gather_materials(blender_primitive, blender_mesh, modifiers, export_settings):
if not blender_primitive['material']:
# TODO: fix 'extract_promitives' so that the value of 'material' is None and not empty string
# TODO: fix 'extract_primitives' so that the value of 'material' is None and not empty string
return None
mesh_double_sided = blender_mesh.show_double_sided
material = bpy.data.materials[blender_primitive['material']]
return gltf2_blender_gather_materials.gather_material(material, export_settings)
return gltf2_blender_gather_materials.gather_material(material, mesh_double_sided, export_settings)
def __gather_indices(blender_primitive, blender_mesh, modifiers, export_settings):