From 05dc0b0007c98730792949c6aac6784e9b97f04e Mon Sep 17 00:00:00 2001 From: Jannis Date: Fri, 22 Jul 2022 17:22:55 +0200 Subject: [PATCH] Fix exporting multiple collada animations Only switch to mobile UI when touch screen detected --- js/api.js | 2 +- js/io/formats/collada.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/js/api.js b/js/api.js index 1d33c4c6..89962f20 100644 --- a/js/api.js +++ b/js/api.js @@ -2,7 +2,7 @@ const LastVersion = localStorage.getItem('last_version') || localStorage.getItem const Blockbench = { isWeb: !isApp, - isMobile: window.innerWidth <= 960 || window.innerHeight <= 500, + isMobile: (window.innerWidth <= 960 || window.innerHeight <= 500) && 'ontouchend' in document, isLandscape: window.innerWidth > window.innerHeight, isTouch: 'ontouchend' in document, get isPWA() { diff --git a/js/io/formats/collada.js b/js/io/formats/collada.js index 99d63bbe..22f5c6bf 100644 --- a/js/io/formats/collada.js +++ b/js/io/formats/collada.js @@ -602,11 +602,21 @@ var codec = new Codec('collada', { if (!animators[track.group_uuid]) animators[track.group_uuid] = {} if (!animators[track.group_uuid][track.channel]) { animators[track.group_uuid][track.channel] = { + animations_added: [], times: [], } } + }); + }); + + compiled_animations.forEach((anim_obj, anim_i) => { + if (anim_obj.duration < 0.01) return; + + anim_obj.tracks.forEach(track => { + let track_channel = animators[track.group_uuid][track.channel]; track_channel.times.push(...track.times.map(t => t + time_offset)); + track_channel.animations_added.push(anim_i); if (track.channel == 'rotation') { if (!track_channel.values) track_channel.values = {}; @@ -623,6 +633,29 @@ var codec = new Codec('collada', { } }) + for (let uuid in animators) { + for (let channel in animators[uuid]) { + let track_channel = animators[uuid][channel]; + if (track_channel.animations_added.includes(anim_i)) { + continue; + } else { + track_channel.times.push(time_offset, time_offset+anim_obj.duration); + + if (channel == 'rotation') { + if (!track_channel.values) track_channel.values = {}; + ['X', 'Y', 'Z'].forEach((axis, axis_i) => { + if (!track_channel.values[axis]) track_channel.values[axis] = []; + track_channel.values[axis].push(0, 0); + }) + } else { + if (!track_channel.values) track_channel.values = []; + let v = channel == 'scale' ? 1 : 0; + track_channel.values.push(v, v, v, v, v, v); + } + } + } + } + let animation_clip_tag = { type: 'animation_clip', attributes: {