Skip to content

Commit

Permalink
Merge branch 'blender-v4.3-release'
Browse files Browse the repository at this point in the history
  • Loading branch information
julienduroure committed Oct 31, 2024
2 parents 0783ad8 + c6f401f commit fd2e751
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion addons/io_scene_gltf2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
bl_info = {
'name': 'glTF 2.0 format',
'author': 'Julien Duroure, Scurest, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors',
"version": (4, 4, 10),
"version": (4, 4, 11),
'blender': (4, 3, 0),
'location': 'File > Import-Export',
'description': 'Import-Export as glTF 2.0',
Expand Down
35 changes: 30 additions & 5 deletions addons/io_scene_gltf2/blender/exp/animation/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import bpy
import typing
from math import ceil
from ....io.com import gltf2_io
from ....io.exp.user_extensions import export_user_extensions
from ....blender.com.conversion import get_gltf_interpolation
Expand Down Expand Up @@ -75,11 +76,27 @@ def gather_actions_animations(export_settings):

return new_animations

# We need to align if step is not 1
# For example, cache will get frame 1/4/7/10 if step is 3, with an action starting at frame 1
# If all backing is enabled, and scene start at 0, we will get frame 0/3/6/9 => Cache will fail
# Set the reference frame from the first action retrieve, and align all actions to this frame
def _align_frame_start(reference_frame_start, frame, export_settings):

if reference_frame_start is None:
return frame

if export_settings['gltf_frame_step'] == 1:
return frame

return reference_frame_start + export_settings['gltf_frame_step'] * ceil((frame - reference_frame_start) / export_settings['gltf_frame_step'])


def prepare_actions_range(export_settings):

track_slide = {}

start_frame_reference = None

vtree = export_settings['vtree']
for obj_uuid in vtree.get_all_objects():

Expand Down Expand Up @@ -124,9 +141,17 @@ def prepare_actions_range(export_settings):
start_frame = max(bpy.context.scene.frame_start, start_frame)
end_frame = min(bpy.context.scene.frame_end, end_frame)

export_settings['ranges'][obj_uuid][blender_action.name]['start'] = start_frame
export_settings['ranges'][obj_uuid][blender_action.name]['start'] = _align_frame_start(start_frame_reference, start_frame, export_settings)
export_settings['ranges'][obj_uuid][blender_action.name]['end'] = end_frame

if start_frame_reference is None:
start_frame_reference = start_frame

# Recheck all actions to align to this frame
for obj_uuid_tmp in export_settings['ranges'].keys():
for action_name_tmp in export_settings['ranges'][obj_uuid_tmp].keys():
export_settings['ranges'][obj_uuid_tmp][action_name_tmp]['start'] = _align_frame_start(start_frame_reference, export_settings['ranges'][obj_uuid_tmp][action_name_tmp]['start'], export_settings)

if export_settings['gltf_negative_frames'] == "SLIDE":
if track is not None:
if not (track.startswith("NlaTrack") or track.startswith("[Action Stash]")):
Expand Down Expand Up @@ -163,7 +188,7 @@ def prepare_actions_range(export_settings):

if type_ == "SHAPEKEY" and export_settings['gltf_bake_animation']:
export_settings['ranges'][obj_uuid][obj_uuid] = {}
export_settings['ranges'][obj_uuid][obj_uuid]['start'] = bpy.context.scene.frame_start
export_settings['ranges'][obj_uuid][obj_uuid]['start'] = _align_frame_start(start_frame_reference, bpy.context.scene.frame_start, export_settings)
export_settings['ranges'][obj_uuid][obj_uuid]['end'] = bpy.context.scene.frame_end

# For baking drivers
Expand All @@ -173,15 +198,15 @@ def prepare_actions_range(export_settings):
if obj_dr not in export_settings['ranges']:
export_settings['ranges'][obj_dr] = {}
export_settings['ranges'][obj_dr][obj_uuid + "_" + blender_action.name] = {}
export_settings['ranges'][obj_dr][obj_uuid + "_" + blender_action.name]['start'] = start_frame
export_settings['ranges'][obj_dr][obj_uuid + "_" + blender_action.name]['start'] = _align_frame_start(start_frame_reference, start_frame, export_settings)
export_settings['ranges'][obj_dr][obj_uuid + "_" + blender_action.name]['end'] = end_frame

if len(blender_actions) == 0 and export_settings['gltf_bake_animation']:
# No animation on this object
# In case of baking animation, we will use scene frame range
# Will be calculated later if max range. Can be set here if scene frame range
export_settings['ranges'][obj_uuid][obj_uuid] = {}
export_settings['ranges'][obj_uuid][obj_uuid]['start'] = bpy.context.scene.frame_start
export_settings['ranges'][obj_uuid][obj_uuid]['start'] = _align_frame_start(start_frame_reference, bpy.context.scene.frame_start, export_settings)
export_settings['ranges'][obj_uuid][obj_uuid]['end'] = bpy.context.scene.frame_end

# For baking drivers
Expand All @@ -192,7 +217,7 @@ def prepare_actions_range(export_settings):
export_settings['ranges'][obj_dr] = {}
export_settings['ranges'][obj_dr][obj_uuid + "_" + obj_uuid] = {}
export_settings['ranges'][obj_dr][obj_uuid + "_" +
obj_uuid]['start'] = bpy.context.scene.frame_start
obj_uuid]['start'] = _align_frame_start(start_frame_reference, bpy.context.scene.frame_start, export_settings)
export_settings['ranges'][obj_dr][obj_uuid + "_" + obj_uuid]['end'] = bpy.context.scene.frame_end

if (export_settings['gltf_negative_frames'] == "SLIDE"
Expand Down

0 comments on commit fd2e751

Please sign in to comment.