[Bf-extensions-cvs] [9683e4a0] gltf_vtree: glTF exporter VTree
Julien Duroure
noreply at git.blender.org
Tue Feb 1 18:25:28 CET 2022
Commit: 9683e4a05fbb0c92f26c28b0644e9069bd249409
Author: Julien Duroure
Date: Tue Feb 1 18:24:26 2022 +0100
Branches: gltf_vtree
https://developer.blender.org/rBA9683e4a05fbb0c92f26c28b0644e9069bd249409
glTF exporter VTree
===================================================================
M io_scene_gltf2/__init__.py
M io_scene_gltf2/blender/com/gltf2_blender_math.py
M io_scene_gltf2/blender/exp/gltf2_blender_export_keys.py
M io_scene_gltf2/blender/exp/gltf2_blender_extract.py
M io_scene_gltf2/blender/exp/gltf2_blender_gather.py
M io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channel_target.py
M io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channels.py
M io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_sampler_keyframes.py
M io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py
M io_scene_gltf2/blender/exp/gltf2_blender_gather_animations.py
M io_scene_gltf2/blender/exp/gltf2_blender_gather_cache.py
M io_scene_gltf2/blender/exp/gltf2_blender_gather_drivers.py
M io_scene_gltf2/blender/exp/gltf2_blender_gather_joints.py
M io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py
M io_scene_gltf2/blender/exp/gltf2_blender_gather_mesh.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
A io_scene_gltf2/blender/exp/gltf2_blender_gather_tree.py
M io_scene_gltf2/blender/exp/gltf2_blender_gltf2_exporter.py
===================================================================
diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py
index fe1867b3..bc7d6056 100755
--- a/io_scene_gltf2/__init__.py
+++ b/io_scene_gltf2/__init__.py
@@ -876,6 +876,8 @@ class GLTF_PT_export_animation_export(bpy.types.Panel):
row = layout.row()
row.active = operator.export_force_sampling
row.prop(operator, 'export_def_bones')
+ if operator.export_force_sampling is False and operator.export_def_bones is True:
+ layout.label(text="Export only deformation bones is not possible when not sampling animation")
class GLTF_PT_export_animation_shapekeys(bpy.types.Panel):
diff --git a/io_scene_gltf2/blender/com/gltf2_blender_math.py b/io_scene_gltf2/blender/com/gltf2_blender_math.py
index 9dcae661..a45fe91a 100755
--- a/io_scene_gltf2/blender/com/gltf2_blender_math.py
+++ b/io_scene_gltf2/blender/com/gltf2_blender_math.py
@@ -109,7 +109,7 @@ def swizzle_yup_value(value: typing.Any) -> typing.Any:
return value
-def transform(v: typing.Union[Vector, Quaternion], data_path: str, transform: Matrix = Matrix.Identity(4)) -> typing \
+def transform(v: typing.Union[Vector, Quaternion], data_path: str, transform: Matrix = Matrix.Identity(4), need_rotation_correction: bool = False) -> typing \
.Union[Vector, Quaternion]:
"""Manage transformations."""
target = get_target_property_name(data_path)
@@ -127,25 +127,31 @@ def transform(v: typing.Union[Vector, Quaternion], data_path: str, transform: Ma
if transform_func is None:
raise RuntimeError("Cannot transform values at {}".format(data_path))
- return transform_func(v, transform)
+ return transform_func(v, transform, need_rotation_correction)
-def transform_location(location: Vector, transform: Matrix = Matrix.Identity(4)) -> Vector:
+def transform_location(location: Vector, transform: Matrix = Matrix.Identity(4), need_rotation_correction:bool = False) -> Vector:
"""Transform location."""
+ correction = Quaternion((2**0.5/2, -2**0.5/2, 0.0, 0.0))
m = Matrix.Translation(location)
+ if need_rotation_correction:
+ m @= correction.to_matrix().to_4x4()
m = transform @ m
return m.to_translation()
-def transform_rotation(rotation: Quaternion, transform: Matrix = Matrix.Identity(4)) -> Quaternion:
+def transform_rotation(rotation: Quaternion, transform: Matrix = Matrix.Identity(4), need_rotation_correction: bool = False) -> Quaternion:
"""Transform rotation."""
rotation.normalize()
+ correction = Quaternion((2**0.5/2, -2**0.5/2, 0.0, 0.0))
m = rotation.to_matrix().to_4x4()
+ if need_rotation_correction:
+ m @= correction.to_matrix().to_4x4()
m = transform @ m
return m.to_quaternion()
-def transform_scale(scale: Vector, transform: Matrix = Matrix.Identity(4)) -> Vector:
+def transform_scale(scale: Vector, transform: Matrix = Matrix.Identity(4), need_rotation_correction: bool = False) -> Vector:
"""Transform scale."""
m = Matrix.Identity(4)
m[0][0] = scale.x
@@ -156,7 +162,7 @@ def transform_scale(scale: Vector, transform: Matrix = Matrix.Identity(4)) -> Ve
return m.to_scale()
-def transform_value(value: Vector, _: Matrix = Matrix.Identity(4)) -> Vector:
+def transform_value(value: Vector, _: Matrix = Matrix.Identity(4), need_rotation_correction: bool = False) -> Vector:
"""Transform value."""
return value
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_export_keys.py b/io_scene_gltf2/blender/exp/gltf2_blender_export_keys.py
index 06fe6a47..f6a7a46f 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_export_keys.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_export_keys.py
@@ -30,6 +30,7 @@ VISIBLE = 'gltf_visible'
RENDERABLE = 'gltf_renderable'
ACTIVE_COLLECTION = 'gltf_active_collection'
SKINS = 'gltf_skins'
+DEF_BONES_ONLY = 'gltf_def_bones'
DISPLACEMENT = 'gltf_displacement'
FORCE_SAMPLING = 'gltf_force_sampling'
FRAME_RANGE = 'gltf_frame_range'
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_extract.py b/io_scene_gltf2/blender/exp/gltf2_blender_extract.py
index f7318c2b..8fed1073 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_extract.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_extract.py
@@ -20,10 +20,14 @@ from ...io.com.gltf2_io_debug import print_console
from io_scene_gltf2.blender.exp import gltf2_blender_gather_skins
-def extract_primitives(glTF, blender_mesh, library, blender_object, blender_vertex_groups, modifiers, export_settings):
+def extract_primitives(blender_mesh, uuid_for_skined_data, blender_vertex_groups, modifiers, export_settings):
"""Extract primitives from a mesh."""
print_console('INFO', 'Extracting primitive: ' + blender_mesh.name)
+ blender_object = None
+ if uuid_for_skined_data:
+ blender_object = export_settings['vtree'].nodes[uuid_for_skined_data].blender_object
+
use_normals = export_settings[gltf2_blender_export_keys.NORMALS]
if use_normals:
blender_mesh.calc_normals_split()
@@ -68,7 +72,7 @@ def extract_primitives(glTF, blender_mesh, library, blender_object, blender_vert
armature = None
if armature:
- skin = gltf2_blender_gather_skins.gather_skin(armature, export_settings)
+ skin = gltf2_blender_gather_skins.gather_skin(export_settings['vtree'].nodes[uuid_for_skined_data].armature, export_settings)
if not skin:
armature = None
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather.py
index 6f68c19e..9ac3138f 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather.py
@@ -18,10 +18,12 @@ from io_scene_gltf2.io.com import gltf2_io
from io_scene_gltf2.io.com.gltf2_io_debug import print_console
from io_scene_gltf2.blender.exp import gltf2_blender_gather_nodes
from io_scene_gltf2.blender.exp import gltf2_blender_gather_animations
+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 ..com.gltf2_blender_extras import generate_extras
from io_scene_gltf2.blender.exp import gltf2_blender_export_keys
from io_scene_gltf2.io.exp.gltf2_io_user_extensions import export_user_extensions
+from io_scene_gltf2.blender.exp import gltf2_blender_gather_tree
def gather_gltf2(export_settings):
@@ -33,12 +35,18 @@ def gather_gltf2(export_settings):
scenes = []
animations = [] # unfortunately animations in gltf2 are just as 'root' as scenes.
active_scene = None
+ store_user_scene = bpy.context.scene
for blender_scene in bpy.data.scenes:
scenes.append(__gather_scene(blender_scene, export_settings))
if export_settings[gltf2_blender_export_keys.ANIMATIONS]:
+ # resetting object cache
+ gltf2_blender_gather_animation_sampler_keyframes.get_object_matrix.reset_cache()
animations += __gather_animations(blender_scene, export_settings)
if bpy.context.scene.name == blender_scene.name:
active_scene = len(scenes) -1
+
+ # restore user scene
+ bpy.context.window.scene = store_user_scene
return active_scene, scenes, animations
@@ -51,15 +59,25 @@ def __gather_scene(blender_scene, export_settings):
nodes=[]
)
- for _blender_object in [obj for obj in blender_scene.objects if obj.proxy is None]:
- if _blender_object.parent is None:
- blender_object = _blender_object.proxy if _blender_object.proxy else _blender_object
- node = gltf2_blender_gather_nodes.gather_node(
- blender_object,
- blender_object.library.name if blender_object.library else None,
- blender_scene, None, export_settings)
- if node is not None:
- scene.nodes.append(node)
+
+ vtree = gltf2_blender_gather_tree.VExportTree(export_settings)
+ vtree.construct(blender_scene)
+ vtree.search_missing_armature() # In case armature are no parented correctly
+
+ export_user_extensions('vtree_before_filter_hook', export_settings, vtree)
+
+ # Now, we can filter tree if needed
+ vtree.filter()
+
+ export_user_extensions('vtree_after_filter_hook', export_settings, vtree)
+
+ export_settings['vtree'] = vtree
+
+ for r in [vtree.nodes[r] for r in vtree.roots]:
+ node = gltf2_blender_gather_nodes.gather_node(
+ r, export_settings)
+ if node is not None:
+ scene.nodes.append(node)
export_user_extensions('gather_scene_hook', export_settings, scene, blender_scene)
@@ -70,18 +88,16 @@ def __gather_animations(blender_scene, export_settings):
animations = []
merged_tracks = {}
- for _blender_object in blender_scene.objects:
+ vtree = export_settings['vtree']
+ for obj_uuid in vtree.get_all_objects():
+ blender_object = vtree.nodes[obj_uuid].blender_object
- blender_object = _blender_object.proxy if _blender_object.proxy else _blender_object
+ # Do not manage not exported objects
+ if vtree.nodes[obj_uuid].node is None:
+ continue
- # First check if this object is exported or not. Do not export animation of not exported object
- obj_node = gltf2_blender_gather_nodes.gather_node(blender_object,
- blender_object.library.name if blender_object.library else None,
- blender_scene, None, export_settings)
- if obj_node is not None:
- # Check was done on armature, but use here the _proxy object, because this is where the animation is
- animations_, merged_tracks = gltf2_blender_gather_animations.gather_animations(_blender_object, merged_tracks, len(animations), export_settings)
- animations += animations_
+ animations_, merged_tracks = gltf2_blender_gather_animations.gather_animations(obj_uuid, merged_tracks, len(animations), export_settings)
+ animations += animations_
if export_settings['gltf_nla_strips'] is False:
# Fake an animation with all animations of the scene
diff --git a/io_scene_gltf2/blend
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list