diff options
author | Julien Duroure <julien.duroure@gmail.com> | 2018-11-24 18:28:33 +0300 |
---|---|---|
committer | Julien Duroure <julien.duroure@gmail.com> | 2018-11-24 18:28:33 +0300 |
commit | b1f2133fa2849da272e9d8404f371220226ddaf1 (patch) | |
tree | 25db56e0f2211bd1059fe0e04e78430a6156e021 /io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channel_target.py | |
parent | 8959f1798cfc86924493347304118c61bd5c7f7a (diff) |
Initial commit of glTF 2.0 importer/exporter
Official Khronos Group Blender glTF 2.0 importer and exporter.
glTF specification: https://github.com/KhronosGroup/glTF
The upstream repository can be found here:
https://github.com/KhronosGroup/glTF-Blender-IO
Reviewed By: Bastien, Campbell
Differential Revision: https://developer.blender.org/D3929
Diffstat (limited to 'io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channel_target.py')
-rwxr-xr-x | io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channel_target.py | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channel_target.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channel_target.py new file mode 100755 index 00000000..fbe18323 --- /dev/null +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channel_target.py @@ -0,0 +1,82 @@ +# Copyright 2018 The glTF-Blender-IO authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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 bpy +import typing +from io_scene_gltf2.io.com import gltf2_io +from io_scene_gltf2.blender.exp.gltf2_blender_gather_cache import cached +from io_scene_gltf2.blender.exp import gltf2_blender_gather_nodes +from io_scene_gltf2.blender.exp import gltf2_blender_gather_joints + + +@cached +def gather_animation_channel_target(channels: typing.Tuple[bpy.types.FCurve], + blender_object: bpy.types.Object, + export_settings + ) -> gltf2_io.AnimationChannelTarget: + return gltf2_io.AnimationChannelTarget( + extensions=__gather_extensions(channels, blender_object, export_settings), + extras=__gather_extras(channels, blender_object, export_settings), + node=__gather_node(channels, blender_object, export_settings), + path=__gather_path(channels, blender_object, export_settings) + ) + + +def __gather_extensions(channels: typing.Tuple[bpy.types.FCurve], + blender_object: bpy.types.Object, + export_settings + ) -> typing.Any: + return None + + +def __gather_extras(channels: typing.Tuple[bpy.types.FCurve], + blender_object: bpy.types.Object, + export_settings + ) -> typing.Any: + return None + + +def __gather_node(channels: typing.Tuple[bpy.types.FCurve], + blender_object: bpy.types.Object, + export_settings + ) -> gltf2_io.Node: + if blender_object.type == "ARMATURE": + # TODO: get joint from fcurve data_path and gather_joint + blender_bone = blender_object.path_resolve(channels[0].data_path.rsplit('.', 1)[0]) + if isinstance(blender_bone, bpy.types.PoseBone): + return gltf2_blender_gather_joints.gather_joint(blender_bone, export_settings) + + return gltf2_blender_gather_nodes.gather_node(blender_object, export_settings) + + +def __gather_path(channels: typing.Tuple[bpy.types.FCurve], + blender_object: bpy.types.Object, + export_settings + ) -> str: + target = channels[0].data_path.split('.')[-1] + path = { + "location": "translation", + "rotation_axis_angle": "rotation", + "rotation_euler": "rotation", + "rotation_quaternion": "rotation", + "scale": "scale", + "value": "weights" + }.get(target) + + if target is None: + raise RuntimeError("Cannot export an animation with {} target".format(target)) + + return path + |