[Bf-extensions-cvs] [8803d06e] master: glTF exporter: remove no more needed functions
Julien Duroure
noreply at git.blender.org
Sat Apr 11 13:43:51 CEST 2020
Commit: 8803d06e886d2cf990165e4463fad0b823e710bd
Author: Julien Duroure
Date: Sat Apr 11 13:36:29 2020 +0200
Branches: master
https://developer.blender.org/rBA8803d06e886d2cf990165e4463fad0b823e710bd
glTF exporter: remove no more needed functions
===================================================================
M io_scene_gltf2/__init__.py
M io_scene_gltf2/blender/exp/gltf2_blender_extract.py
===================================================================
diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py
index 92d452c0..c0fd6cd1 100755
--- a/io_scene_gltf2/__init__.py
+++ b/io_scene_gltf2/__init__.py
@@ -15,7 +15,7 @@
bl_info = {
'name': 'glTF 2.0 format',
'author': 'Julien Duroure, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors',
- "version": (1, 2, 57),
+ "version": (1, 2, 58),
'blender': (2, 82, 7),
'location': 'File > Import-Export',
'description': 'Import-Export as glTF 2.0',
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_extract.py b/io_scene_gltf2/blender/exp/gltf2_blender_extract.py
index 3db571fb..df0552cd 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_extract.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_extract.py
@@ -1,976 +1,701 @@
-# Copyright 2018-2019 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.
-
-#
-# Imports
-#
-
-from mathutils import Vector, Quaternion, Matrix
-from mathutils.geometry import tessellate_polygon
-from operator import attrgetter
-
-from . import gltf2_blender_export_keys
-from ...io.com.gltf2_io_debug import print_console
-from ...io.com.gltf2_io_color_management import color_srgb_to_scene_linear
-from io_scene_gltf2.blender.exp import gltf2_blender_gather_skins
-import bpy
-
-#
-# Globals
-#
-
-INDICES_ID = 'indices'
-MATERIAL_ID = 'material'
-ATTRIBUTES_ID = 'attributes'
-
-COLOR_PREFIX = 'COLOR_'
-MORPH_TANGENT_PREFIX = 'MORPH_TANGENT_'
-MORPH_NORMAL_PREFIX = 'MORPH_NORMAL_'
-MORPH_POSITION_PREFIX = 'MORPH_POSITION_'
-TEXCOORD_PREFIX = 'TEXCOORD_'
-WEIGHTS_PREFIX = 'WEIGHTS_'
-JOINTS_PREFIX = 'JOINTS_'
-
-TANGENT_ATTRIBUTE = 'TANGENT'
-NORMAL_ATTRIBUTE = 'NORMAL'
-POSITION_ATTRIBUTE = 'POSITION'
-
-GLTF_MAX_COLORS = 2
-
-
-#
-# Classes
-#
-
-class ShapeKey:
- def __init__(self, shape_key, vertex_normals, polygon_normals):
- self.shape_key = shape_key
- self.vertex_normals = vertex_normals
- self.polygon_normals = polygon_normals
-
-
-#
-# Functions
-#
-
-def convert_swizzle_normal(loc, armature, blender_object, export_settings):
- """Convert a normal data from Blender coordinate system to glTF coordinate system."""
- if (not armature) or (not blender_object):
- # Classic case. Mesh is not skined, no need to apply armature transfoms on vertices / normals / tangents
- if export_settings[gltf2_blender_export_keys.YUP]:
- return Vector((loc[0], loc[2], -loc[1]))
- else:
- return Vector((loc[0], loc[1], loc[2]))
- else:
- # Mesh is skined, we have to apply armature transforms on data
- apply_matrix = (armature.matrix_world.inverted() @ blender_object.matrix_world).to_3x3().inverted()
- apply_matrix.transpose()
- new_loc = ((armature.matrix_world.to_3x3() @ apply_matrix).to_4x4() @ Matrix.Translation(Vector((loc[0], loc[1], loc[2])))).to_translation()
-
- if export_settings[gltf2_blender_export_keys.YUP]:
- return Vector((new_loc[0], new_loc[2], -new_loc[1]))
- else:
- return Vector((new_loc[0], new_loc[1], new_loc[2]))
-
-def convert_swizzle_location(loc, armature, blender_object, export_settings):
- """Convert a location from Blender coordinate system to glTF coordinate system."""
- if (not armature) or (not blender_object):
- # Classic case. Mesh is not skined, no need to apply armature transfoms on vertices / normals / tangents
- if export_settings[gltf2_blender_export_keys.YUP]:
- return Vector((loc[0], loc[2], -loc[1]))
- else:
- return Vector((loc[0], loc[1], loc[2]))
- else:
- # Mesh is skined, we have to apply armature transforms on data
- apply_matrix = armature.matrix_world.inverted() @ blender_object.matrix_world
- new_loc = (armature.matrix_world @ apply_matrix @ Matrix.Translation(Vector((loc[0], loc[1], loc[2])))).to_translation()
-
- if export_settings[gltf2_blender_export_keys.YUP]:
- return Vector((new_loc[0], new_loc[2], -new_loc[1]))
- else:
- return Vector((new_loc[0], new_loc[1], new_loc[2]))
-
-
-def convert_swizzle_tangent(tan, armature, blender_object, export_settings):
- """Convert a tangent from Blender coordinate system to glTF coordinate system."""
- if tan[0] == 0.0 and tan[1] == 0.0 and tan[2] == 0.0:
- print_console('WARNING', 'Tangent has zero length.')
-
- if (not armature) or (not blender_object):
- # Classic case. Mesh is not skined, no need to apply armature transfoms on vertices / normals / tangents
- if export_settings[gltf2_blender_export_keys.YUP]:
- return Vector((tan[0], tan[2], -tan[1], 1.0))
- else:
- return Vector((tan[0], tan[1], tan[2], 1.0))
- else:
- # Mesh is skined, we have to apply armature transforms on data
- apply_matrix = armature.matrix_world.inverted() @ blender_object.matrix_world
- new_tan = apply_matrix.to_quaternion() @ tan
- if export_settings[gltf2_blender_export_keys.YUP]:
- return Vector((new_tan[0], new_tan[2], -new_tan[1], 1.0))
- else:
- return Vector((new_tan[0], new_tan[1], new_tan[2], 1.0))
-
-def convert_swizzle_rotation(rot, export_settings):
- """
- Convert a quaternion rotation from Blender coordinate system to glTF coordinate system.
-
- 'w' is still at first position.
- """
- if export_settings[gltf2_blender_export_keys.YUP]:
- return Quaternion((rot[0], rot[1], rot[3], -rot[2]))
- else:
- return Quaternion((rot[0], rot[1], rot[2], rot[3]))
-
-
-def convert_swizzle_scale(scale, export_settings):
- """Convert a scale from Blender coordinate system to glTF coordinate system."""
- if export_settings[gltf2_blender_export_keys.YUP]:
- return Vector((scale[0], scale[2], scale[1]))
- else:
- return Vector((scale[0], scale[1], scale[2]))
-
-
-def decompose_transition(matrix, export_settings):
- translation, rotation, scale = matrix.decompose()
-
- return translation, rotation, scale
-
-def extract_primitive_floor(a, indices, use_tangents):
- """Shift indices, that the first one starts with 0. It is assumed, that the indices are packed."""
- attributes = {
- POSITION_ATTRIBUTE: [],
- NORMAL_ATTRIBUTE: []
- }
-
- if use_tangents:
- attributes[TANGENT_ATTRIBUTE] = []
-
- result_primitive = {
- MATERIAL_ID: a[MATERIAL_ID],
- INDICES_ID: [],
- ATTRIBUTES_ID: attributes
- }
-
- source_attributes = a[ATTRIBUTES_ID]
-
- #
-
- tex_coord_index = 0
- process_tex_coord = True
- while process_tex_coord:
- tex_coord_id = TEXCOORD_PREFIX + str(tex_coord_index)
-
- if source_attributes.get(tex_coord_id) is not None:
- attributes[tex_coord_id] = []
- tex_coord_index += 1
- else:
- process_tex_coord = False
-
- tex_coord_max = tex_coord_index
-
- #
-
- color_index = 0
- process_color = True
- while process_color:
- color_id = COLOR_PREFIX + str(color_index)
-
- if source_attributes.get(color_id) is not None:
- attributes[color_id] = []
- color_index += 1
- else:
- process_color = False
-
- color_max = color_index
-
- #
-
- bone_index = 0
- process_bone = True
- while process_bone:
- joint_id = JOINTS_PREFIX + str(bone_index)
- weight_id = WEIGHTS_PREFIX + str(bone_index)
-
- if source_attributes.get(joint_id) is not None:
- attributes[joint_id] = []
- attributes[weight_id] = []
- bone_index += 1
- else:
- process_bone = False
-
- bone_max = bone_index
-
- #
-
- morph_index = 0
- process_morph = True
- while process_morph:
- morph_position_id = MORPH_POSITION_PREFIX + str(morph_index)
- morph_normal_id = MORPH_NORMAL_PREFIX + str(morph_index)
- morph_tangent_id = MORPH_TANGENT_PREFIX + str(morph_index)
-
- if source_attributes.get(morph_position_id) is not None:
- attributes[morph_position_id] = []
- attributes[morph_normal_id] = []
- if use_tangents:
- attributes[morph_tangent_id] = []
- morph_index += 1
- else:
- process_morph = False
-
- morph_max = morph_index
-
- #
-
- min_index = min(indices)
- max_index = max(indices)
-
- for old_index in indices:
- result_primitive[INDICES_ID].append(old_index - min_index)
-
- for old_index in range(min_index, max_index + 1):
- for vi in range(0, 3):
- attributes[POSITION_ATTRIBUTE].append(source_attributes[POSITION_ATTRIBUTE][old_index * 3 + vi])
- attributes[NORMAL_ATTRIBUTE].append(source_attributes[NORMAL_ATTRIBUTE][old_index * 3 + vi])
-
- if use_tangents:
- for vi in range(0, 4):
- attributes[TANGENT_ATTRIBUTE].append(source_attributes[TANGENT_ATTRIBUTE][old_index * 4 + vi])
-
- for tex_coord_index in range(0, tex_coord_max):
- tex_coord_id = TEXCOORD_PREFIX + str(tex_coord_index)
- for vi in range(0, 2):
- attributes[tex_coord_id].append(source_attributes[tex_coord_id][old_index * 2 + vi])
-
- for color_index in range(0, color_max):
- color_id = COLOR_PREFIX + str(color_index)
- for vi in range(0, 4):
- attributes[color_id].append(source_attributes[color_id][old_index * 4 + vi])
-
- for bone_index in range(0, bone_max):
- joint_id = JOINTS_PREFIX + str(bone_index)
- weight_id = WE
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list