[Bf-extensions-cvs] [d5732014] master: glTF exporter: export attributes only if start with underscore

Julien Duroure noreply at git.blender.org
Wed Jan 18 17:58:14 CET 2023


Commit: d5732014b103c7dd28e79bdc8e4bffc8201ba260
Author: Julien Duroure
Date:   Wed Jan 18 17:52:33 2023 +0100
Branches: master
https://developer.blender.org/rBAd5732014b103c7dd28e79bdc8e4bffc8201ba260

glTF exporter: export attributes only if start with underscore

Now Blender has lots of attributes (material_index, position, uv, ...) that are already exported in glTF
And we don't want to export them as custom attributes

===================================================================

M	io_scene_gltf2/__init__.py
M	io_scene_gltf2/blender/com/gltf2_blender_default.py
M	io_scene_gltf2/blender/exp/gltf2_blender_gather_primitives_extract.py

===================================================================

diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py
index f87c8fb4..95f22981 100755
--- a/io_scene_gltf2/__init__.py
+++ b/io_scene_gltf2/__init__.py
@@ -4,7 +4,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": (3, 5, 15),
+    "version": (3, 5, 16),
     'blender': (3, 4, 0),
     'location': 'File > Import-Export',
     'description': 'Import-Export as glTF 2.0',
@@ -307,7 +307,7 @@ class ExportGLTF2_Base(ConvertGLTF2_Base):
 
     export_attributes: BoolProperty(
         name='Attributes',
-        description='Export Attributes',
+        description='Export Attributes (when starting with underscore)',
         default=False
     )
 
diff --git a/io_scene_gltf2/blender/com/gltf2_blender_default.py b/io_scene_gltf2/blender/com/gltf2_blender_default.py
index 13a3bb48..554ff783 100644
--- a/io_scene_gltf2/blender/com/gltf2_blender_default.py
+++ b/io_scene_gltf2/blender/com/gltf2_blender_default.py
@@ -4,11 +4,3 @@
 BLENDER_IOR = 1.45
 BLENDER_SPECULAR = 0.5
 BLENDER_SPECULAR_TINT = 0.0
-
-
-SPECIAL_ATTRIBUTES = {
-    ".select_vert",
-    ".select_edge",
-    ".select_poly",
-    "material_index"
-    }
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_primitives_extract.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_primitives_extract.py
index ea7e39e1..c2bf96fd 100644
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_primitives_extract.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_primitives_extract.py
@@ -9,7 +9,7 @@ from ...io.com.gltf2_io_debug import print_console
 from io_scene_gltf2.blender.exp import gltf2_blender_gather_skins
 from io_scene_gltf2.io.com import gltf2_io_constants
 from io_scene_gltf2.blender.com import gltf2_blender_conversion
-from io_scene_gltf2.blender.com import gltf2_blender_default
+from io_scene_gltf2.io.exp.gltf2_io_user_extensions import export_user_extensions
 
 
 def extract_primitives(blender_mesh, uuid_for_skined_data, blender_vertex_groups, modifiers, export_settings):
@@ -136,13 +136,16 @@ class PrimitiveCreator:
                 self.export_settings['vtree'].nodes[armature_uuid].need_neutral_bone = True
 
     def define_attributes(self):
+
+
+        class KeepAttribute:
+            def __init__(self, attr_name):
+                self.attr_name = attr_name
+                self.keep = attr_name.startswith("_")
+
         # Manage attributes + COLOR_0
         for blender_attribute_index, blender_attribute in enumerate(self.blender_mesh.attributes):
 
-            # Excluse special attributes (used internally by Blender)
-            if blender_attribute.name in gltf2_blender_default.SPECIAL_ATTRIBUTES:
-                continue
-
             attr = {}
             attr['blender_attribute_index'] = blender_attribute_index
             attr['blender_name'] = blender_attribute.name
@@ -169,10 +172,21 @@ class PrimitiveCreator:
                 attr['get'] = self.get_function()
 
             else:
-                attr['gltf_attribute_name'] = '_' + blender_attribute.name.upper()
-                attr['get'] = self.get_function()
+                # Custom attributes
+                # Keep only attributes that starts with _
+                # As Blender create lots of attributes that are internal / not needed are as duplicated of standard glTF accessors (position, uv, material_index...)
                 if self.export_settings['gltf_attributes'] is False:
                     continue
+                # Check if there is an extension that want to keep this attribute, or change the exported name
+                keep_attribute = KeepAttribute(blender_attribute.name)
+
+                export_user_extensions('gather_attribute_keep', self.export_settings, keep_attribute)
+
+                if keep_attribute.keep is False:
+                    continue
+
+                attr['gltf_attribute_name'] = keep_attribute.attr_name.upper()
+                attr['get'] = self.get_function()
 
             self.blender_attributes.append(attr)



More information about the Bf-extensions-cvs mailing list