[Bf-extensions-cvs] [9c76d5b3] master: glTF exporter: Deduplicate cameras, animation sampler and accessors
Julien Duroure
noreply at git.blender.org
Tue Mar 12 17:36:44 CET 2019
Commit: 9c76d5b39aa7d3531781637b93bd744849af4e3d
Author: Julien Duroure
Date: Tue Mar 12 17:36:02 2019 +0100
Branches: master
https://developer.blender.org/rBA9c76d5b39aa7d3531781637b93bd744849af4e3d
glTF exporter: Deduplicate cameras, animation sampler and accessors
===================================================================
A io_scene_gltf2/blender/exp/gltf2_blender_gather_accessors.py
M io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py
M io_scene_gltf2/blender/exp/gltf2_blender_gather_cameras.py
M io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py
M io_scene_gltf2/blender/exp/gltf2_blender_gather_primitives.py
M io_scene_gltf2/blender/exp/gltf2_blender_gather_skins.py
M io_scene_gltf2/io/exp/gltf2_io_binary_data.py
===================================================================
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_accessors.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_accessors.py
new file mode 100644
index 00000000..949720d1
--- /dev/null
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_accessors.py
@@ -0,0 +1,48 @@
+# 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 typing
+
+import bpy
+from io_scene_gltf2.blender.exp.gltf2_blender_gather_cache import cached
+from io_scene_gltf2.io.com import gltf2_io
+from io_scene_gltf2.io.com import gltf2_io_constants
+from io_scene_gltf2.io.exp import gltf2_io_binary_data
+from . import gltf2_blender_export_keys
+
+
+ at cached
+def gather_accessor(buffer_view: gltf2_io_binary_data.BinaryData,
+ component_type: gltf2_io_constants.ComponentType,
+ count,
+ max,
+ min,
+ type: gltf2_io_constants.DataType,
+ export_settings) -> gltf2_io.Accessor:
+ return gltf2_io.Accessor(
+ buffer_view=buffer_view,
+ byte_offset=None,
+ component_type=component_type,
+ count=count,
+ extensions=None,
+ extras=None,
+ max=list(max) if max is not None else None,
+ min=list(min) if min is not None else None,
+ name=None,
+ normalized=None,
+ sparse=None,
+ type=type
+ )
+
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py
index 4000ce5e..981428c9 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py
@@ -20,6 +20,7 @@ from io_scene_gltf2.blender.com import gltf2_blender_math
from io_scene_gltf2.blender.com.gltf2_blender_data_path import get_target_property_name, get_target_object_path
from io_scene_gltf2.blender.exp import gltf2_blender_gather_animation_sampler_keyframes
from io_scene_gltf2.blender.exp.gltf2_blender_gather_cache import cached
+from io_scene_gltf2.blender.exp import gltf2_blender_gather_accessors
from io_scene_gltf2.io.com import gltf2_io
from io_scene_gltf2.io.com import gltf2_io_constants
from io_scene_gltf2.io.exp import gltf2_io_binary_data
@@ -34,9 +35,11 @@ def gather_animation_sampler(channels: typing.Tuple[bpy.types.FCurve],
return gltf2_io.AnimationSampler(
extensions=__gather_extensions(channels, blender_object, export_settings),
extras=__gather_extras(channels, blender_object, export_settings),
- input=__gather_input(channels, blender_object, export_settings),
+ input=__gather_input(channels, export_settings),
interpolation=__gather_interpolation(channels, blender_object, export_settings),
- output=__gather_output(channels, blender_object, export_settings)
+ output=__gather_output(channels, blender_object.matrix_parent_inverse.copy().freeze(),
+ blender_object if blender_object.type == "ARMATURE" else None,
+ export_settings)
)
@@ -54,27 +57,22 @@ def __gather_extras(channels: typing.Tuple[bpy.types.FCurve],
return None
+ at cached
def __gather_input(channels: typing.Tuple[bpy.types.FCurve],
- blender_object: bpy.types.Object,
export_settings
) -> gltf2_io.Accessor:
"""Gather the key time codes."""
keyframes = gltf2_blender_gather_animation_sampler_keyframes.gather_keyframes(channels, export_settings)
times = [k.seconds for k in keyframes]
- return gltf2_io.Accessor(
- buffer_view=gltf2_io_binary_data.BinaryData.from_list(times, gltf2_io_constants.ComponentType.Float),
- byte_offset=None,
- component_type=gltf2_io_constants.ComponentType.Float,
- count=len(times),
- extensions=None,
- extras=None,
- max=[max(times)],
- min=[min(times)],
- name=None,
- normalized=None,
- sparse=None,
- type=gltf2_io_constants.DataType.Scalar
+ return gltf2_blender_gather_accessors.gather_accessor(
+ gltf2_io_binary_data.BinaryData.from_list(times, gltf2_io_constants.ComponentType.Float),
+ gltf2_io_constants.ComponentType.Float,
+ len(times),
+ tuple([max(times)]),
+ tuple([min(times)]),
+ gltf2_io_constants.DataType.Scalar,
+ export_settings
)
@@ -95,8 +93,10 @@ def __gather_interpolation(channels: typing.Tuple[bpy.types.FCurve],
}[blender_keyframe.interpolation]
+ at cached
def __gather_output(channels: typing.Tuple[bpy.types.FCurve],
- blender_object: bpy.types.Object,
+ parent_inverse,
+ blender_object_if_armature: typing.Optional[bpy.types.Object],
export_settings
) -> gltf2_io.Accessor:
"""Gather the data of the keyframes."""
@@ -104,14 +104,14 @@ def __gather_output(channels: typing.Tuple[bpy.types.FCurve],
target_datapath = channels[0].data_path
- transform = blender_object.matrix_parent_inverse
+ transform = parent_inverse
is_yup = export_settings[gltf2_blender_export_keys.YUP]
object_path = get_target_object_path(target_datapath)
- is_armature_animation = blender_object.type == "ARMATURE" and object_path != ""
+ is_armature_animation = blender_object_if_armature is not None and object_path != ""
if is_armature_animation:
- bone = blender_object.path_resolve(object_path)
+ bone = blender_object_if_armature.path_resolve(object_path)
if isinstance(bone, bpy.types.PoseBone):
if bone.parent is not None:
parent_transform = bone.parent.bone.matrix_local
@@ -134,12 +134,12 @@ def __gather_output(channels: typing.Tuple[bpy.types.FCurve],
keyframe_value = gltf2_blender_math.mathutils_to_gltf(value)
if keyframe.in_tangent is not None:
in_tangent = gltf2_blender_math.transform(keyframe.in_tangent, target_datapath, transform)
- if is_yup and not blender_object.type == "ARMATURE":
+ if is_yup and blender_object_if_armature is None:
in_tangent = gltf2_blender_math.swizzle_yup(in_tangent, target_datapath)
keyframe_value = gltf2_blender_math.mathutils_to_gltf(in_tangent) + keyframe_value
if keyframe.out_tangent is not None:
out_tangent = gltf2_blender_math.transform(keyframe.out_tangent, target_datapath, transform)
- if is_yup and not blender_object.type == "ARMATURE":
+ if is_yup and blender_object_if_armature is None:
out_tangent = gltf2_blender_math.swizzle_yup(out_tangent, target_datapath)
keyframe_value = keyframe_value + gltf2_blender_math.mathutils_to_gltf(out_tangent)
values += keyframe_value
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_cameras.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_cameras.py
index 9640a7ce..a34048a0 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_cameras.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_cameras.py
@@ -21,43 +21,38 @@ import math
@cached
-def gather_camera(blender_object, export_settings):
- if not __filter_camera(blender_object, export_settings):
+def gather_camera(blender_camera, export_settings):
+ if not __filter_camera(blender_camera, export_settings):
return None
return gltf2_io.Camera(
- extensions=__gather_extensions(blender_object, export_settings),
- extras=__gather_extras(blender_object, export_settings),
- name=__gather_name(blender_object, export_settings),
- orthographic=__gather_orthographic(blender_object, export_settings),
- perspective=__gather_perspective(blender_object, export_settings),
- type=__gather_type(blender_object, export_settings)
+ extensions=__gather_extensions(blender_camera, export_settings),
+ extras=__gather_extras(blender_camera, export_settings),
+ name=__gather_name(blender_camera, export_settings),
+ orthographic=__gather_orthographic(blender_camera, export_settings),
+ perspective=__gather_perspective(blender_camera, export_settings),
+ type=__gather_type(blender_camera, export_settings)
)
-def __filter_camera(blender_object, export_settings):
- if blender_object.type != 'CAMERA':
- return False
- if not __gather_type(blender_object, export_settings):
- return False
+def __filter_camera(blender_camera, export_settings):
+ return bool(__gather_type(blender_camera, export_settings))
- return True
-
-def __gather_extensions(blender_object, export_settings):
+def __gather_extensions(blender_camera, export_settings):
return None
-def __gather_extras(blender_object, export_settings):
+def __gather_extras(blender_camera, export_settings):
return None
-def __gather_name(blender_object, export_settings):
- return blender_object.data.name
+def __gather_name(blender_camera, export_settings):
+ return blender_camera.name
-def __gather_orthographic(blender_object, export_settings):
- if __gather_type(blender_object, export_settings) == "orthographic":
+def __gather_orthographic(blender_camera, export_settings):
+ if __gather_type(blender_camera, export_settings) == "orthographic":
orthographic = gltf2_io.CameraOrthographic(
extensions=None,
extras=None,
@@ -66,7 +61,6 @@ def __gather_orthographic(blender_object, export_settings):
zfar=Non
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list