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
This commit is contained in:
parent
a131db64b9
commit
d5732014b1
|
@ -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
|
||||
)
|
||||
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue