From fe7e5fd343005eba7b416889263695d27a01d2a4 Mon Sep 17 00:00:00 2001 From: Maurice Raybaud Date: Mon, 31 Jan 2022 00:19:46 +0100 Subject: POV: Fix importer fix useless enumeration providing index in place of string --- render_povray/scripting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/render_povray/scripting.py b/render_povray/scripting.py index 5f7a2b6e..77e266ef 100755 --- a/render_povray/scripting.py +++ b/render_povray/scripting.py @@ -194,7 +194,7 @@ class ImportPOV(bpy.types.Operator, ImportHelper): S = S.replace(";", " ; ") S = S.split() # lenS = len(S) # Not used... why written? - for word in enumerate(S): + for word in S: # -------- Primitives Import -------- # if word == 'cone': cone_search = True -- cgit v1.2.3 From d4c8716c5b684faa2264a53822f3d32409a22c59 Mon Sep 17 00:00:00 2001 From: Demeter Dzadik Date: Mon, 31 Jan 2022 11:29:27 +0100 Subject: PoseLib: use bpy.utils.flip_name() Instead of re-implementing BLI_string_flip_side_name, use the python function that was exposed in D12322. Reviewed By: sybren Differential Revision: https://developer.blender.org/D13191 --- pose_library/pose_usage.py | 124 +-------------------------------------------- 1 file changed, 2 insertions(+), 122 deletions(-) diff --git a/pose_library/pose_usage.py b/pose_library/pose_usage.py index dc496d9c..7bc9377e 100644 --- a/pose_library/pose_usage.py +++ b/pose_library/pose_usage.py @@ -22,6 +22,7 @@ Pose Library - usage functions. from typing import Set import re +import bpy from bpy.types import ( Action, @@ -48,7 +49,7 @@ def select_bones(arm_object: Object, action: Action, *, select: bool, flipped: b seen_bone_names.add(bone_name) if flipped: - bone_name = flip_side_name(bone_name) + bone_name = bpy.utils.flip_name(bone_name) try: pose_bone = pose.bones[bone_name] @@ -58,127 +59,6 @@ def select_bones(arm_object: Object, action: Action, *, select: bool, flipped: b pose_bone.bone.select = select -_FLIP_SEPARATORS = set(". -_") - -# These are single-character replacements, others are handled differently. -_FLIP_REPLACEMENTS = { - "l": "r", - "L": "R", - "r": "l", - "R": "L", -} - - -def flip_side_name(to_flip: str) -> str: - """Flip left and right indicators in the name. - - Basically a Python implementation of BLI_string_flip_side_name. - - >>> flip_side_name('bone_L.004') - 'bone_R.004' - >>> flip_side_name('left_bone') - 'right_bone' - >>> flip_side_name('Left_bone') - 'Right_bone' - >>> flip_side_name('LEFT_bone') - 'RIGHT_bone' - >>> flip_side_name('some.bone-RIGHT.004') - 'some.bone-LEFT.004' - >>> flip_side_name('some.bone-right.004') - 'some.bone-left.004' - >>> flip_side_name('some.bone-Right.004') - 'some.bone-Left.004' - >>> flip_side_name('some.bone-LEFT.004') - 'some.bone-RIGHT.004' - >>> flip_side_name('some.bone-left.004') - 'some.bone-right.004' - >>> flip_side_name('some.bone-Left.004') - 'some.bone-Right.004' - >>> flip_side_name('.004') - '.004' - >>> flip_side_name('L.004') - 'R.004' - """ - import string - - if len(to_flip) < 3: - # we don't flip names like .R or .L - return to_flip - - # We first check the case with a .### extension, let's find the last period. - number = "" - replace = to_flip - if to_flip[-1] in string.digits: - try: - index = to_flip.rindex(".") - except ValueError: - pass - else: - if to_flip[index + 1] in string.digits: - # TODO(Sybren): this doesn't handle "bone.1abc2" correctly. - number = to_flip[index:] - replace = to_flip[:index] - - if not replace: - # Nothing left after the number, so no flips necessary. - return replace + number - - if len(replace) == 1: - replace = _FLIP_REPLACEMENTS.get(replace, replace) - return replace + number - - # First case; separator . - _ with extensions r R l L. - if replace[-2] in _FLIP_SEPARATORS and replace[-1] in _FLIP_REPLACEMENTS: - replace = replace[:-1] + _FLIP_REPLACEMENTS[replace[-1]] - return replace + number - - # Second case; beginning with r R l L, with separator after it. - if replace[1] in _FLIP_SEPARATORS and replace[0] in _FLIP_REPLACEMENTS: - replace = _FLIP_REPLACEMENTS[replace[0]] + replace[1:] - return replace + number - - lower = replace.lower() - prefix = suffix = "" - if lower.startswith("right"): - bit = replace[0:2] - if bit == "Ri": - prefix = "Left" - elif bit == "RI": - prefix = "LEFT" - else: - prefix = "left" - replace = replace[5:] - elif lower.startswith("left"): - bit = replace[0:2] - if bit == "Le": - prefix = "Right" - elif bit == "LE": - prefix = "RIGHT" - else: - prefix = "right" - replace = replace[4:] - elif lower.endswith("right"): - bit = replace[-5:-3] - if bit == "Ri": - suffix = "Left" - elif bit == "RI": - suffix = "LEFT" - else: - suffix = "left" - replace = replace[:-5] - elif lower.endswith("left"): - bit = replace[-4:-2] - if bit == "Le": - suffix = "Right" - elif bit == "LE": - suffix = "RIGHT" - else: - suffix = "right" - replace = replace[:-4] - - return prefix + replace + suffix + number - - if __name__ == '__main__': import doctest -- cgit v1.2.3 From faa9fc7f98e19be54a715c24061185b04dff5b6c Mon Sep 17 00:00:00 2001 From: Julien Duroure Date: Tue, 1 Feb 2022 21:42:27 +0100 Subject: Fix T95300: glTF importer: fix import binary images --- io_scene_gltf2/__init__.py | 2 +- io_scene_gltf2/blender/imp/gltf2_blender_image.py | 112 ++++++++++++---------- 2 files changed, 61 insertions(+), 53 deletions(-) diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py index 1a97bee8..9ed65aed 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, Scurest, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors', - "version": (1, 8, 13), + "version": (1, 8, 14), 'blender': (3, 1, 0), 'location': 'File > Import-Export', 'description': 'Import-Export as glTF 2.0', diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_image.py b/io_scene_gltf2/blender/imp/gltf2_blender_image.py index 0df6dc0e..cf4a9595 100755 --- a/io_scene_gltf2/blender/imp/gltf2_blender_image.py +++ b/io_scene_gltf2/blender/imp/gltf2_blender_image.py @@ -34,68 +34,76 @@ class BlenderImage(): """Image creation.""" img = gltf.data.images[img_idx] - import_user_extensions('gather_import_image_before_hook', gltf, img) - - img_name = img.name - if img.blender_image_name is not None: # Image is already used somewhere return - is_binary = False - is_placeholder = False - - num_images = len(bpy.data.images) + import_user_extensions('gather_import_image_before_hook', gltf, img) if img.uri is not None and not img.uri.startswith('data:'): - # Image stored in a file - path = join(dirname(gltf.filename), _uri_to_path(img.uri)) - path = os.path.abspath(path) - if bpy.data.is_saved and bpy.context.preferences.filepaths.use_relative_paths: - try: - path = bpy.path.relpath(path) - except: - # May happen on Windows if on different drives, eg. C:\ and D:\ - pass - - img_name = img_name or basename(path) - - try: - blender_image = bpy.data.images.load( - path, - check_existing=True, - ) - except RuntimeError: - gltf.log.error("Missing image file (index %d): %s" % (img_idx, path)) - blender_image = _placeholder_image(img_name, os.path.abspath(path)) - is_placeholder = True - + blender_image = create_from_file(gltf, img_idx) else: - # Image stored as data => pack - is_binary = True - img_data = BinaryData.get_image_data(gltf, img_idx) - if img_data is None: - return - img_name = 'Image_%d' % img_idx - - # Create image, width and height are dummy values - img_pack = bpy.data.images.new(img_name, 8, 8) - # Set packed file data - img_pack.pack(data=img_data.tobytes(), data_len=len(img_data)) - img_pack.source = 'FILE' - img.blender_image_name = img_pack.name - - if is_binary is False: - if len(bpy.data.images) != num_images: # If created a new image - blender_image.name = img_name - img.blender_image_name = img_name - - needs_pack = gltf.import_settings['import_pack_images'] - if not is_placeholder and needs_pack: - blender_image.pack() + blender_image = create_from_data(gltf, img_idx) + + if blender_image: + img.blender_image_name = blender_image.name import_user_extensions('gather_import_image_after_hook', gltf, img, blender_image) + +def create_from_file(gltf, img_idx): + # Image stored in a file + + num_images = len(bpy.data.images) + + img = gltf.data.images[img_idx] + + path = join(dirname(gltf.filename), _uri_to_path(img.uri)) + path = os.path.abspath(path) + if bpy.data.is_saved and bpy.context.preferences.filepaths.use_relative_paths: + try: + path = bpy.path.relpath(path) + except: + # May happen on Windows if on different drives, eg. C:\ and D:\ + pass + + img_name = img.name or basename(path) + + try: + blender_image = bpy.data.images.load( + path, + check_existing=True, + ) + + needs_pack = gltf.import_settings['import_pack_images'] + if needs_pack: + blender_image.pack() + + except RuntimeError: + gltf.log.error("Missing image file (index %d): %s" % (img_idx, path)) + blender_image = _placeholder_image(img_name, os.path.abspath(path)) + + if len(bpy.data.images) != num_images: # If created a new image + blender_image.name = img_name + + return blender_image + + +def create_from_data(gltf, img_idx): + # Image stored as data => pack + img_data = BinaryData.get_image_data(gltf, img_idx) + if img_data is None: + return + img_name = 'Image_%d' % img_idx + + # Create image, width and height are dummy values + blender_image = bpy.data.images.new(img_name, 8, 8) + # Set packed file data + blender_image.pack(data=img_data.tobytes(), data_len=len(img_data)) + blender_image.source = 'FILE' + + return blender_image + def _placeholder_image(name, path): image = bpy.data.images.new(name, 128, 128) # allow the path to be resolved later -- cgit v1.2.3