Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'release/scripts/modules')
-rw-r--r--release/scripts/modules/bl_i18n_utils/bl_extract_messages.py5
-rw-r--r--release/scripts/modules/bl_i18n_utils/settings.py11
-rw-r--r--release/scripts/modules/bl_i18n_utils/utils_spell_check.py4
-rw-r--r--release/scripts/modules/bl_previews_utils/bl_previews_render.py491
-rw-r--r--release/scripts/modules/bpy/path.py28
-rw-r--r--release/scripts/modules/bpy/utils/__init__.py59
-rw-r--r--release/scripts/modules/bpy_extras/anim_utils.py18
-rw-r--r--release/scripts/modules/bpy_extras/image_utils.py12
-rw-r--r--release/scripts/modules/bpy_extras/object_utils.py31
-rw-r--r--release/scripts/modules/nodeitems_utils.py2
-rw-r--r--release/scripts/modules/progress_report.py3
-rw-r--r--release/scripts/modules/rna_prop_ui.py5
-rw-r--r--release/scripts/modules/sys_info.py119
13 files changed, 654 insertions, 134 deletions
diff --git a/release/scripts/modules/bl_i18n_utils/bl_extract_messages.py b/release/scripts/modules/bl_i18n_utils/bl_extract_messages.py
index 43a09a1acbd..baa9140aaef 100644
--- a/release/scripts/modules/bl_i18n_utils/bl_extract_messages.py
+++ b/release/scripts/modules/bl_i18n_utils/bl_extract_messages.py
@@ -304,7 +304,8 @@ def dump_rna_messages(msgs, reports, settings, verbose=False):
else:
bl_rna_base_props = set()
- for prop in bl_rna.properties:
+ props = sorted(bl_rna.properties, key=lambda p: p.identifier)
+ for prop in props:
# Only write this property if our parent hasn't got it.
if prop in bl_rna_base_props:
continue
@@ -456,7 +457,7 @@ def dump_py_messages_from_files(msgs, reports, files, settings):
def extract_strings_split(node):
"""
- Returns a list args as returned by 'extract_strings()', But split into groups based on separate_nodes, this way
+ Returns a list args as returned by 'extract_strings()', but split into groups based on separate_nodes, this way
expressions like ("A" if test else "B") wont be merged but "A" + "B" will.
"""
estr_ls = []
diff --git a/release/scripts/modules/bl_i18n_utils/settings.py b/release/scripts/modules/bl_i18n_utils/settings.py
index a63633d25aa..49dbfbe62af 100644
--- a/release/scripts/modules/bl_i18n_utils/settings.py
+++ b/release/scripts/modules/bl_i18n_utils/settings.py
@@ -184,15 +184,15 @@ DOMAIN = "blender"
# File type (ext) to parse.
PYGETTEXT_ALLOWED_EXTS = {".c", ".cpp", ".cxx", ".hpp", ".hxx", ".h"}
-# Max number of contexts into a BLF_I18N_MSGID_MULTI_CTXT macro...
+# Max number of contexts into a BLT_I18N_MSGID_MULTI_CTXT macro...
PYGETTEXT_MAX_MULTI_CTXT = 16
# Where to search contexts definitions, relative to SOURCE_DIR (defined below).
-PYGETTEXT_CONTEXTS_DEFSRC = os.path.join("source", "blender", "blenfont", "BLF_translation.h")
+PYGETTEXT_CONTEXTS_DEFSRC = os.path.join("source", "blender", "blentranslation", "BLT_translation.h")
-# Regex to extract contexts defined in BLF_translation.h
+# Regex to extract contexts defined in BLT_translation.h
# XXX Not full-proof, but should be enough here!
-PYGETTEXT_CONTEXTS = "#define\\s+(BLF_I18NCONTEXT_[A-Z_0-9]+)\\s+\"([^\"]*)\""
+PYGETTEXT_CONTEXTS = "#define\\s+(BLT_I18NCONTEXT_[A-Z_0-9]+)\\s+\"([^\"]*)\""
# Keywords' regex.
# XXX Most unfortunately, we can't use named backreferences inside character sets,
@@ -255,7 +255,7 @@ PYGETTEXT_KEYWORDS = (() +
tuple((r"{}\(\s*" + _msg_re + r"\s*,\s*(?:" +
r"\s*,\s*)?(?:".join(_ctxt_re_gen(i) for i in range(PYGETTEXT_MAX_MULTI_CTXT)) + r")?\s*\)").format(it)
- for it in ("BLF_I18N_MSGID_MULTI_CTXT",))
+ for it in ("BLT_I18N_MSGID_MULTI_CTXT",))
)
# Check printf mismatches between msgid and msgstr.
@@ -333,6 +333,7 @@ WARN_MSGID_NOT_CAPITALIZED_ALLOWED = {
"expected a view3d region & editcurve",
"expected a view3d region & editmesh",
"image file not found",
+ "image format is read-only",
"image path can't be written to",
"in memory to enable editing!",
"jumps over",
diff --git a/release/scripts/modules/bl_i18n_utils/utils_spell_check.py b/release/scripts/modules/bl_i18n_utils/utils_spell_check.py
index e2f2aeef7b2..b1aa4e02cee 100644
--- a/release/scripts/modules/bl_i18n_utils/utils_spell_check.py
+++ b/release/scripts/modules/bl_i18n_utils/utils_spell_check.py
@@ -97,6 +97,7 @@ class SpellChecker:
"denoise",
"deselect", "deselecting", "deselection",
"despill", "despilling",
+ "dirtree",
"editcurve",
"editmesh",
"filebrowser",
@@ -113,7 +114,7 @@ class SpellChecker:
"libdata",
"lightless",
"lineset",
- "linestyle",
+ "linestyle", "linestyles",
"localview",
"lookup", "lookups",
"mathutils",
@@ -128,6 +129,7 @@ class SpellChecker:
"multiuser",
"multiview",
"namespace",
+ "nodetree", "nodetrees",
"keyconfig",
"online",
"playhead",
diff --git a/release/scripts/modules/bl_previews_utils/bl_previews_render.py b/release/scripts/modules/bl_previews_utils/bl_previews_render.py
new file mode 100644
index 00000000000..627a6ab2d3d
--- /dev/null
+++ b/release/scripts/modules/bl_previews_utils/bl_previews_render.py
@@ -0,0 +1,491 @@
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ***** END GPL LICENSE BLOCK *****
+
+# <pep8 compliant>
+
+# Populate a template file (POT format currently) from Blender RNA/py/C data.
+# Note: This script is meant to be used from inside Blender!
+
+import collections
+import os
+import sys
+
+import bpy
+from mathutils import Vector, Euler
+
+
+INTERN_PREVIEW_TYPES = {'MATERIAL', 'LAMP', 'WORLD', 'TEXTURE', 'IMAGE'}
+OBJECT_TYPES_RENDER = {'MESH', 'CURVE', 'SURFACE', 'META', 'FONT'}
+
+
+def ids_nolib(bids):
+ return (bid for bid in bids if not bid.library)
+
+
+def rna_backup_gen(data, include_props=None, exclude_props=None, root=()):
+ # only writable properties...
+ for p in data.bl_rna.properties:
+ pid = p.identifier
+ if pid in {'rna_type', }:
+ continue
+ path = root + (pid,)
+ if include_props is not None and path not in include_props:
+ continue
+ if exclude_props is not None and path in exclude_props:
+ continue
+ val = getattr(data, pid)
+ if val is not None and p.type == 'POINTER':
+ # recurse!
+ yield from rna_backup_gen(val, include_props, exclude_props, root=path)
+ elif data.is_property_readonly(pid):
+ continue
+ else:
+ yield path, val
+
+
+def rna_backup_restore(data, backup):
+ for path, val in backup:
+ dt = data
+ for pid in path[:-1]:
+ dt = getattr(dt, pid)
+ setattr(dt, path[-1], val)
+
+
+def do_previews(do_objects, do_groups, do_scenes, do_data_intern):
+ # Helpers.
+ RenderContext = collections.namedtuple("RenderContext", (
+ "scene", "world", "camera", "lamp", "camera_data", "lamp_data", "image", # All those are names!
+ "backup_scene", "backup_world", "backup_camera", "backup_lamp", "backup_camera_data", "backup_lamp_data",
+ ))
+
+ RENDER_PREVIEW_SIZE = bpy.app.render_preview_size
+
+ def render_context_create(engine, objects_ignored):
+ if engine == '__SCENE':
+ backup_scene, backup_world, backup_camera, backup_lamp, backup_camera_data, backup_lamp_data = [()] * 6
+ scene = bpy.context.screen.scene
+ exclude_props = {('world',), ('camera',), ('tool_settings',), ('preview',)}
+ backup_scene = tuple(rna_backup_gen(scene, exclude_props=exclude_props))
+ world = scene.world
+ camera = scene.camera
+ if camera:
+ camera_data = camera.data
+ else:
+ backup_camera, backup_camera_data = [None] * 2
+ camera_data = bpy.data.cameras.new("TEMP_preview_render_camera")
+ camera = bpy.data.objects.new("TEMP_preview_render_camera", camera_data)
+ camera.rotation_euler = Euler((1.1635528802871704, 0.0, 0.7853981852531433), 'XYZ') # (66.67, 0.0, 45.0)
+ scene.camera = camera
+ scene.objects.link(camera)
+ # TODO: add lamp if none found in scene?
+ lamp = None
+ lamp_data = None
+ else:
+ backup_scene, backup_world, backup_camera, backup_lamp, backup_camera_data, backup_lamp_data = [None] * 6
+
+ scene = bpy.data.scenes.new("TEMP_preview_render_scene")
+ world = bpy.data.worlds.new("TEMP_preview_render_world")
+ camera_data = bpy.data.cameras.new("TEMP_preview_render_camera")
+ camera = bpy.data.objects.new("TEMP_preview_render_camera", camera_data)
+ lamp_data = bpy.data.lamps.new("TEMP_preview_render_lamp", 'SPOT')
+ lamp = bpy.data.objects.new("TEMP_preview_render_lamp", lamp_data)
+
+ objects_ignored.add((camera.name, lamp.name))
+
+ scene.world = world
+
+ camera.rotation_euler = Euler((1.1635528802871704, 0.0, 0.7853981852531433), 'XYZ') # (66.67, 0.0, 45.0)
+ scene.camera = camera
+ scene.objects.link(camera)
+
+ lamp.rotation_euler = Euler((0.7853981852531433, 0.0, 1.7453292608261108), 'XYZ') # (45.0, 0.0, 100.0)
+ lamp_data.falloff_type = 'CONSTANT'
+ lamp_data.spot_size = 1.0471975803375244 # 60
+ scene.objects.link(lamp)
+
+ if engine == 'BLENDER_RENDER':
+ scene.render.engine = 'BLENDER_RENDER'
+ scene.render.alpha_mode = 'TRANSPARENT'
+
+ world.use_sky_blend = True
+ world.horizon_color = 0.9, 0.9, 0.9
+ world.zenith_color = 0.5, 0.5, 0.5
+ world.ambient_color = 0.1, 0.1, 0.1
+ world.light_settings.use_environment_light = True
+ world.light_settings.environment_energy = 1.0
+ world.light_settings.environment_color = 'SKY_COLOR'
+ elif engine == 'CYCLES':
+ scene.render.engine = 'CYCLES'
+ scene.cycles.film_transparent = True
+ # TODO: define Cycles world?
+
+ scene.render.image_settings.file_format = 'PNG'
+ scene.render.image_settings.color_depth = '8'
+ scene.render.image_settings.color_mode = 'RGBA'
+ scene.render.image_settings.compression = 25
+ scene.render.resolution_x = RENDER_PREVIEW_SIZE
+ scene.render.resolution_y = RENDER_PREVIEW_SIZE
+ scene.render.resolution_percentage = 100
+ scene.render.filepath = os.path.join(bpy.app.tempdir, 'TEMP_preview_render.png')
+ scene.render.use_overwrite = True
+ scene.render.use_stamp = False
+
+ image = bpy.data.images.new("TEMP_render_image", RENDER_PREVIEW_SIZE, RENDER_PREVIEW_SIZE, alpha=True)
+ image.source = 'FILE'
+ image.filepath = scene.render.filepath
+
+ return RenderContext(
+ scene.name, world.name if world else None, camera.name, lamp.name if lamp else None,
+ camera_data.name, lamp_data.name if lamp_data else None, image.name,
+ backup_scene, backup_world, backup_camera, backup_lamp, backup_camera_data, backup_lamp_data,
+ )
+
+ def render_context_delete(render_context):
+ # We use try/except blocks here to avoid crash, too much things can go wrong, and we want to leave the current
+ # .blend as clean as possible!
+ success = True
+
+ scene = bpy.data.scenes[render_context.scene, None]
+ try:
+ if render_context.backup_scene is None:
+ scene.world = None
+ scene.camera = None
+ if render_context.camera:
+ scene.objects.unlink(bpy.data.objects[render_context.camera, None])
+ if render_context.lamp:
+ scene.objects.unlink(bpy.data.objects[render_context.lamp, None])
+ bpy.data.scenes.remove(scene)
+ scene = None
+ else:
+ rna_backup_restore(scene, render_context.backup_scene)
+ except Exception as e:
+ print("ERROR:", e)
+ success = False
+
+ if render_context.world is not None:
+ try:
+ world = bpy.data.worlds[render_context.world, None]
+ if render_context.backup_world is None:
+ if scene is not None:
+ scene.world = None
+ world.user_clear()
+ bpy.data.worlds.remove(world)
+ else:
+ rna_backup_restore(world, render_context.backup_world)
+ except Exception as e:
+ print("ERROR:", e)
+ success = False
+
+ if render_context.camera:
+ try:
+ camera = bpy.data.objects[render_context.camera, None]
+ if render_context.backup_camera is None:
+ if scene is not None:
+ scene.camera = None
+ scene.objects.unlink(camera)
+ camera.user_clear()
+ bpy.data.objects.remove(camera)
+ bpy.data.cameras.remove(bpy.data.cameras[render_context.camera_data, None])
+ else:
+ rna_backup_restore(camera, render_context.backup_camera)
+ rna_backup_restore(bpy.data.cameras[render_context.camera_data, None],
+ render_context.backup_camera_data)
+ except Exception as e:
+ print("ERROR:", e)
+ success = False
+
+ if render_context.lamp:
+ try:
+ lamp = bpy.data.objects[render_context.lamp, None]
+ if render_context.backup_lamp is None:
+ if scene is not None:
+ scene.objects.unlink(lamp)
+ lamp.user_clear()
+ bpy.data.objects.remove(lamp)
+ bpy.data.lamps.remove(bpy.data.lamps[render_context.lamp_data, None])
+ else:
+ rna_backup_restore(lamp, render_context.backup_lamp)
+ rna_backup_restore(bpy.data.lamps[render_context.lamp_data, None], render_context.backup_lamp_data)
+ except Exception as e:
+ print("ERROR:", e)
+ success = False
+
+ try:
+ image = bpy.data.images[render_context.image, None]
+ image.user_clear()
+ bpy.data.images.remove(image)
+ except Exception as e:
+ print("ERROR:", e)
+ success = False
+
+ return success
+
+ def objects_render_engine_guess(obs):
+ for obname in obs:
+ ob = bpy.data.objects[obname, None]
+ for matslot in ob.material_slots:
+ mat = matslot.material
+ if mat and mat.use_nodes and mat.node_tree:
+ for nd in mat.node_tree.nodes:
+ if nd.shading_compatibility == {'NEW_SHADING'}:
+ return 'CYCLES'
+ return 'BLENDER_RENDER'
+
+ def object_bbox_merge(bbox, ob, ob_space):
+ if ob.bound_box:
+ ob_bbox = ob.bound_box
+ else:
+ ob_bbox = ((-ob.scale.x, -ob.scale.y, -ob.scale.z), (ob.scale.x, ob.scale.y, ob.scale.z))
+ for v in ob.bound_box:
+ v = ob_space.matrix_world.inverted() * ob.matrix_world * Vector(v)
+ if bbox[0].x > v.x:
+ bbox[0].x = v.x
+ if bbox[0].y > v.y:
+ bbox[0].y = v.y
+ if bbox[0].z > v.z:
+ bbox[0].z = v.z
+ if bbox[1].x < v.x:
+ bbox[1].x = v.x
+ if bbox[1].y < v.y:
+ bbox[1].y = v.y
+ if bbox[1].z < v.z:
+ bbox[1].z = v.z
+
+ def objects_bbox_calc(camera, objects):
+ bbox = (Vector((1e9, 1e9, 1e9)), Vector((-1e9, -1e9, -1e9)))
+ for obname in objects:
+ ob = bpy.data.objects[obname, None]
+ object_bbox_merge(bbox, ob, camera)
+ # Our bbox has been generated in camera local space, bring it back in world one
+ bbox[0][:] = camera.matrix_world * bbox[0]
+ bbox[1][:] = camera.matrix_world * bbox[1]
+ cos = (
+ bbox[0].x, bbox[0].y, bbox[0].z,
+ bbox[0].x, bbox[0].y, bbox[1].z,
+ bbox[0].x, bbox[1].y, bbox[0].z,
+ bbox[0].x, bbox[1].y, bbox[1].z,
+ bbox[1].x, bbox[0].y, bbox[0].z,
+ bbox[1].x, bbox[0].y, bbox[1].z,
+ bbox[1].x, bbox[1].y, bbox[0].z,
+ bbox[1].x, bbox[1].y, bbox[1].z,
+ )
+ return cos
+
+ def preview_render_do(render_context, item_container, item_name, objects):
+ scene = bpy.data.scenes[render_context.scene, None]
+ if objects is not None:
+ camera = bpy.data.objects[render_context.camera, None]
+ lamp = bpy.data.objects[render_context.lamp, None] if render_context.lamp is not None else None
+ cos = objects_bbox_calc(camera, objects)
+ loc, ortho_scale = camera.camera_fit_coords(scene, cos)
+ camera.location = loc
+ if lamp:
+ loc, ortho_scale = lamp.camera_fit_coords(scene, cos)
+ lamp.location = loc
+ scene.update()
+
+ bpy.ops.render.render(write_still=True)
+
+ image = bpy.data.images[render_context.image, None]
+ item = getattr(bpy.data, item_container)[item_name, None]
+ image.reload()
+ item.preview.image_size = (RENDER_PREVIEW_SIZE, RENDER_PREVIEW_SIZE)
+ item.preview.image_pixels_float[:] = image.pixels
+
+ # And now, main code!
+ do_save = True
+
+ if do_data_intern:
+ bpy.ops.wm.previews_clear(id_type=INTERN_PREVIEW_TYPES)
+ bpy.ops.wm.previews_ensure()
+
+ render_contexts = {}
+
+ objects_ignored = set()
+ groups_ignored = set()
+
+ prev_scenename = bpy.context.screen.scene.name
+
+ if do_objects:
+ prev_shown = tuple(ob.hide_render for ob in ids_nolib(bpy.data.objects))
+ for ob in ids_nolib(bpy.data.objects):
+ if ob in objects_ignored:
+ continue
+ ob.hide_render = True
+ for root in ids_nolib(bpy.data.objects):
+ if root.name in objects_ignored:
+ continue
+ if root.type not in OBJECT_TYPES_RENDER:
+ continue
+ objects = (root.name,)
+
+ render_engine = objects_render_engine_guess(objects)
+ render_context = render_contexts.get(render_engine, None)
+ if render_context is None:
+ render_context = render_context_create(render_engine, objects_ignored)
+ render_contexts[render_engine] = render_context
+
+ scene = bpy.data.scenes[render_context.scene, None]
+ bpy.context.screen.scene = scene
+
+ for obname in objects:
+ ob = bpy.data.objects[obname, None]
+ if obname not in scene.objects:
+ scene.objects.link(ob)
+ ob.hide_render = False
+ scene.update()
+
+ preview_render_do(render_context, 'objects', root.name, objects)
+
+ # XXX Hyper Super Uber Suspicious Hack!
+ # Without this, on windows build, script excepts with following message:
+ # Traceback (most recent call last):
+ # File "<string>", line 1, in <module>
+ # File "<string>", line 451, in <module>
+ # File "<string>", line 443, in main
+ # File "<string>", line 327, in do_previews
+ # OverflowError: Python int too large to convert to C long
+ # ... :(
+ import sys
+ scene = bpy.data.scenes[render_context.scene, None]
+ for obname in objects:
+ ob = bpy.data.objects[obname, None]
+ scene.objects.unlink(ob)
+ ob.hide_render = True
+
+ for ob, is_rendered in zip(tuple(ids_nolib(bpy.data.objects)), prev_shown):
+ ob.hide_render = is_rendered
+
+ if do_groups:
+ for grp in ids_nolib(bpy.data.groups):
+ if grp.name in groups_ignored:
+ continue
+ objects = tuple(ob.name for ob in grp.objects)
+
+ render_engine = objects_render_engine_guess(objects)
+ render_context = render_contexts.get(render_engine, None)
+ if render_context is None:
+ render_context = render_context_create(render_engine, objects_ignored)
+ render_contexts[render_engine] = render_context
+
+ scene = bpy.data.scenes[render_context.scene, None]
+ bpy.context.screen.scene = scene
+
+ bpy.ops.object.group_instance_add(group=grp.name)
+ grp_ob = next((ob for ob in scene.objects if ob.dupli_group and ob.dupli_group.name == grp.name))
+ grp_obname = grp_ob.name
+ scene.update()
+
+ preview_render_do(render_context, 'groups', grp.name, objects)
+
+ scene = bpy.data.scenes[render_context.scene, None]
+ scene.objects.unlink(bpy.data.objects[grp_obname, None])
+
+ bpy.context.screen.scene = bpy.data.scenes[prev_scenename, None]
+ for render_context in render_contexts.values():
+ if not render_context_delete(render_context):
+ do_save = False # Do not save file if something went wrong here, we could 'pollute' it with temp data...
+
+ if do_scenes:
+ for scene in ids_nolib(bpy.data.scenes):
+ has_camera = scene.camera is not None
+ bpy.context.screen.scene = scene
+ render_context = render_context_create('__SCENE', objects_ignored)
+ scene.update()
+
+ objects = None
+ if not has_camera:
+ # We had to add a temp camera, now we need to place it to see interesting objects!
+ objects = tuple(ob.name for ob in scene.objects
+ if (not ob.hide_render) and (ob.type in OBJECT_TYPES_RENDER))
+
+ preview_render_do(render_context, 'scenes', scene.name, objects)
+
+ if not render_context_delete(render_context):
+ do_save = False
+
+ bpy.context.screen.scene = bpy.data.scenes[prev_scenename, None]
+ if do_save:
+ print("Saving %s..." % bpy.data.filepath)
+ try:
+ bpy.ops.wm.save_mainfile()
+ except Exception as e:
+ # Might fail in some odd cases, like e.g. in regression files we have glsl/ram_glsl.blend which
+ # references an inexistent texture... Better not break in this case, just spit error to console.
+ print("ERROR:", e)
+ else:
+ print("*NOT* Saving %s, because some error(s) happened while deleting temp render data..." % bpy.data.filepath)
+
+
+def do_clear_previews(do_objects, do_groups, do_scenes, do_data_intern):
+ if do_data_intern:
+ bpy.ops.wm.previews_clear(id_type=INTERN_PREVIEW_TYPES)
+
+ if do_objects:
+ for ob in ids_nolib(bpy.data.objects):
+ ob.preview.image_size = (0, 0)
+
+ if do_groups:
+ for grp in ids_nolib(bpy.data.groups):
+ grp.preview.image_size = (0, 0)
+
+ if do_scenes:
+ for scene in ids_nolib(bpy.data.scenes):
+ scene.preview.image_size = (0, 0)
+
+ print("Saving %s..." % bpy.data.filepath)
+ bpy.ops.wm.save_mainfile()
+
+
+def main():
+ try:
+ import bpy
+ except ImportError:
+ print("This script must run from inside blender")
+ return
+
+ import sys
+ import argparse
+
+ # Get rid of Blender args!
+ argv = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []
+
+ parser = argparse.ArgumentParser(description="Use Blender to generate previews for currently open Blender file's items.")
+ parser.add_argument('--clear', default=False, action="store_true", help="Clear previews instead of generating them.")
+ parser.add_argument('--no_scenes', default=True, action="store_false", help="Do not generate/clear previews for scene IDs.")
+ parser.add_argument('--no_groups', default=True, action="store_false", help="Do not generate/clear previews for group IDs.")
+ parser.add_argument('--no_objects', default=True, action="store_false", help="Do not generate/clear previews for object IDs.")
+ parser.add_argument('--no_data_intern', default=True, action="store_false",
+ help="Do not generate/clear previews for mat/tex/image/etc. IDs (those handled by core Blender code).")
+ args = parser.parse_args(argv)
+
+ if args.clear:
+ print("clear!")
+ do_clear_previews(do_objects=args.no_objects, do_groups=args.no_groups, do_scenes=args.no_scenes,
+ do_data_intern=args.no_data_intern)
+ else:
+ print("render!")
+ do_previews(do_objects=args.no_objects, do_groups=args.no_groups, do_scenes=args.no_scenes,
+ do_data_intern=args.no_data_intern)
+
+
+if __name__ == "__main__":
+ print("\n\n *** Running {} *** \n".format(__file__))
+ print(" *** Blend file {} *** \n".format(bpy.data.filepath))
+ main()
+ bpy.ops.wm.quit_blender()
diff --git a/release/scripts/modules/bpy/path.py b/release/scripts/modules/bpy/path.py
index d5b64933165..d7c6101115d 100644
--- a/release/scripts/modules/bpy/path.py
+++ b/release/scripts/modules/bpy/path.py
@@ -61,7 +61,7 @@ def abspath(path, start=None, library=None):
:arg start: Relative to this path,
when not set the current filename is used.
- :type start: string
+ :type start: string or bytes
:arg library: The library this path is from. This is only included for
convenience, when the library is not None its path replaces *start*.
:type library: :class:`bpy.types.Library`
@@ -90,9 +90,11 @@ def relpath(path, start=None):
"""
Returns the path relative to the current blend file using the "//" prefix.
+ :arg path: An absolute path.
+ :type path: string or bytes
:arg start: Relative to this path,
when not set the current filename is used.
- :type start: string
+ :type start: string or bytes
"""
if isinstance(path, bytes):
if not path.startswith(b"//"):
@@ -112,6 +114,9 @@ def is_subdir(path, directory):
"""
Returns true if *path* in a subdirectory of *directory*.
Both paths must be absolute.
+
+ :arg path: An absolute path.
+ :type path: string or bytes
"""
from os.path import normpath, normcase
path = normpath(normcase(path))
@@ -129,7 +134,7 @@ def clean_name(name, replace="_"):
may cause problems under various circumstances,
such as writing to a file.
All characters besides A-Z/a-z, 0-9 are replaced with "_"
- or the replace argument if defined.
+ or the *replace* argument if defined.
"""
if replace != "_":
@@ -278,22 +283,21 @@ def ensure_ext(filepath, ext, case_sensitive=False):
"""
Return the path with the extension added if it is not already set.
- :arg ext: The extension to check for.
+ :arg ext: The extension to check for, can be a compound extension. Should
+ start with a dot, such as '.blend' or '.tar.gz'.
:type ext: string
:arg case_sensitive: Check for matching case when comparing extensions.
:type case_sensitive: bool
"""
- fn_base, fn_ext = _os.path.splitext(filepath)
- if fn_base and fn_ext:
- if ((case_sensitive and ext == fn_ext) or
- (ext.lower() == fn_ext.lower())):
+ if case_sensitive:
+ if filepath.endswith(ext):
return filepath
- else:
- return fn_base + ext
-
else:
- return filepath + ext
+ if filepath[-len(ext):].lower().endswith(ext.lower()):
+ return filepath
+
+ return filepath + ext
def module_names(path, recursive=False):
diff --git a/release/scripts/modules/bpy/utils/__init__.py b/release/scripts/modules/bpy/utils/__init__.py
index 7a1224db226..481db4659af 100644
--- a/release/scripts/modules/bpy/utils/__init__.py
+++ b/release/scripts/modules/bpy/utils/__init__.py
@@ -377,46 +377,31 @@ def preset_paths(subdir):
def smpte_from_seconds(time, fps=None):
"""
- Returns an SMPTE formatted string from the time in seconds: "HH:MM:SS:FF".
+ Returns an SMPTE formatted string from the *time*:
+ ``HH:MM:SS:FF``.
If the *fps* is not given the current scene is used.
- """
- import math
-
- if fps is None:
- fps = _bpy.context.scene.render.fps
-
- hours = minutes = seconds = frames = 0
-
- if time < 0:
- time = - time
- neg = "-"
- else:
- neg = ""
-
- if time >= 3600.0: # hours
- hours = int(time / 3600.0)
- time = time % 3600.0
- if time >= 60.0: # minutes
- minutes = int(time / 60.0)
- time = time % 60.0
- seconds = int(time)
- frames = int(round(math.floor(((time - seconds) * fps))))
+ :arg time: time in seconds.
+ :type time: int, float or ``datetime.timedelta``.
+ :return: the frame string.
+ :rtype: string
+ """
- return "%s%02d:%02d:%02d:%02d" % (neg, hours, minutes, seconds, frames)
+ return smpte_from_frame(time_to_frame(time, fps=fps), fps)
def smpte_from_frame(frame, fps=None, fps_base=None):
"""
- Returns an SMPTE formatted string from the frame: "HH:MM:SS:FF".
+ Returns an SMPTE formatted string from the *frame*:
+ ``HH:MM:SS:FF``.
If *fps* and *fps_base* are not given the current scene is used.
- :arg time: time in seconds.
- :type time: number or timedelta object
- :return: the frame.
- :rtype: float
+ :arg frame: frame number.
+ :type frame: int or float.
+ :return: the frame string.
+ :rtype: string
"""
if fps is None:
@@ -425,7 +410,17 @@ def smpte_from_frame(frame, fps=None, fps_base=None):
if fps_base is None:
fps_base = _bpy.context.scene.render.fps_base
- return smpte_from_seconds((frame * fps_base) / fps, fps)
+ sign = "-" if frame < 0 else ""
+ frame = abs(frame * fps_base)
+
+ return (
+ "%s%02d:%02d:%02d:%02d" % (
+ sign,
+ int(frame / (3600 * fps)), # HH
+ int((frame / (60 * fps)) % 60), # MM
+ int((frame / fps) % 60), # SS
+ int(frame % fps), # FF
+ ))
def time_from_frame(frame, fps=None, fps_base=None):
@@ -435,7 +430,7 @@ def time_from_frame(frame, fps=None, fps_base=None):
If *fps* and *fps_base* are not given the current scene is used.
:arg frame: number.
- :type frame: the frame number
+ :type frame: int or float.
:return: the time in seconds.
:rtype: datetime.timedelta
"""
@@ -459,7 +454,7 @@ def time_to_frame(time, fps=None, fps_base=None):
If *fps* and *fps_base* are not given the current scene is used.
:arg time: time in seconds.
- :type time: number or a datetime.timedelta object
+ :type time: number or a ``datetime.timedelta`` object
:return: the frame.
:rtype: float
"""
diff --git a/release/scripts/modules/bpy_extras/anim_utils.py b/release/scripts/modules/bpy_extras/anim_utils.py
index 4ee5e685668..021a8bbb530 100644
--- a/release/scripts/modules/bpy_extras/anim_utils.py
+++ b/release/scripts/modules/bpy_extras/anim_utils.py
@@ -142,6 +142,13 @@ def bake_action(frame_start,
obj_info.append(obj_frame_info(obj))
# -------------------------------------------------------------------------
+ # Clean (store initial data)
+ if do_clean and action is not None:
+ clean_orig_data = {fcu: {p.co[1] for p in fcu.keyframe_points} for fcu in action.fcurves}
+ else:
+ clean_orig_data = {}
+
+ # -------------------------------------------------------------------------
# Create action
# in case animation data hasn't been created
@@ -230,12 +237,19 @@ def bake_action(frame_start,
if do_clean:
for fcu in action.fcurves:
+ fcu_orig_data = clean_orig_data.get(fcu, set())
+
keyframe_points = fcu.keyframe_points
i = 1
- while i < len(fcu.keyframe_points) - 1:
+ while i < len(keyframe_points) - 1:
+ val = keyframe_points[i].co[1]
+
+ if val in fcu_orig_data:
+ i += 1
+ continue
+
val_prev = keyframe_points[i - 1].co[1]
val_next = keyframe_points[i + 1].co[1]
- val = keyframe_points[i].co[1]
if abs(val - val_prev) + abs(val - val_next) < 0.0001:
keyframe_points.remove(keyframe_points[i])
diff --git a/release/scripts/modules/bpy_extras/image_utils.py b/release/scripts/modules/bpy_extras/image_utils.py
index ff6d23badb6..ad774cd1bda 100644
--- a/release/scripts/modules/bpy_extras/image_utils.py
+++ b/release/scripts/modules/bpy_extras/image_utils.py
@@ -32,6 +32,8 @@ def load_image(imagepath,
convert_callback=None,
verbose=False,
relpath=None,
+ check_existing=False,
+ force_reload=False,
):
"""
Return an image from the file path with options to search multiple paths
@@ -60,6 +62,12 @@ def load_image(imagepath,
:type convert_callback: function
:arg relpath: If not None, make the file relative to this path.
:type relpath: None or string
+ :arg check_existing: If true, returns already loaded image datablock if possible
+ (based on file path).
+ :type check_existing: bool
+ :arg force_reload: If true, force reloading of image (only useful when `check_existing`
+ is also enabled).
+ :type force_reload: bool
:return: an image or None
:rtype: :class:`bpy.types.Image`
"""
@@ -86,7 +94,7 @@ def load_image(imagepath,
path = convert_callback(path)
try:
- image = bpy.data.images.load(path)
+ image = bpy.data.images.load(path, check_existing)
except RuntimeError:
image = None
@@ -102,6 +110,8 @@ def load_image(imagepath,
image = _image_load_placeholder(path)
if image:
+ if force_reload:
+ image.reload()
if relpath is not None:
# make relative
from bpy.path import relpath as relpath_fn
diff --git a/release/scripts/modules/bpy_extras/object_utils.py b/release/scripts/modules/bpy_extras/object_utils.py
index 78fb6aa8fa2..c2c306e5145 100644
--- a/release/scripts/modules/bpy_extras/object_utils.py
+++ b/release/scripts/modules/bpy_extras/object_utils.py
@@ -33,6 +33,7 @@ import bpy
from bpy.props import (
BoolProperty,
+ BoolVectorProperty,
FloatVectorProperty,
)
@@ -136,16 +137,22 @@ def object_data_add(context, obdata, operator=None, use_active_layer=True, name=
if context.space_data and context.space_data.type == 'VIEW_3D':
v3d = context.space_data
- if use_active_layer:
- if v3d and v3d.local_view:
- base.layers_from_view(context.space_data)
- base.layers[scene.active_layer] = True
- else:
- base.layers = [True if i == scene.active_layer
- else False for i in range(len(scene.layers))]
+ if operator is not None and any(operator.layers):
+ base.layers = operator.layers
else:
- if v3d:
- base.layers_from_view(context.space_data)
+ if use_active_layer:
+ if v3d and v3d.local_view:
+ base.layers_from_view(context.space_data)
+ base.layers[scene.active_layer] = True
+ else:
+ base.layers = [True if i == scene.active_layer
+ else False for i in range(len(scene.layers))]
+ else:
+ if v3d:
+ base.layers_from_view(context.space_data)
+
+ if operator is not None:
+ operator.layers = base.layers
obj_new.matrix_world = add_object_align_init(context, operator)
@@ -209,6 +216,12 @@ class AddObjectHelper:
name="Rotation",
subtype='EULER',
)
+ layers = BoolVectorProperty(
+ name="Layers",
+ size=20,
+ subtype='LAYER',
+ options={'HIDDEN', 'SKIP_SAVE'},
+ )
@classmethod
def poll(self, context):
diff --git a/release/scripts/modules/nodeitems_utils.py b/release/scripts/modules/nodeitems_utils.py
index 1cc9afc78cc..be6f031217c 100644
--- a/release/scripts/modules/nodeitems_utils.py
+++ b/release/scripts/modules/nodeitems_utils.py
@@ -85,6 +85,7 @@ class NodeItemCustom:
_node_categories = {}
+
def register_node_categories(identifier, cat_list):
if identifier in _node_categories:
raise KeyError("Node categories list '%s' already registered" % identifier)
@@ -167,6 +168,7 @@ def unregister_node_categories(identifier=None):
unregister_node_cat_types(cat_types)
_node_categories.clear()
+
def draw_node_categories_menu(self, context):
for cats in _node_categories.values():
cats[1](self, context)
diff --git a/release/scripts/modules/progress_report.py b/release/scripts/modules/progress_report.py
index 0d1f4f2bef8..fc77a3e998e 100644
--- a/release/scripts/modules/progress_report.py
+++ b/release/scripts/modules/progress_report.py
@@ -20,6 +20,7 @@
import time
+
class ProgressReport:
"""
A basic 'progress report' using either simple prints in console, or WindowManager's 'progress' API.
@@ -98,7 +99,7 @@ class ProgressReport:
def enter_substeps(self, nbr, msg=""):
if msg:
self.update(msg)
- self.steps.append(self.steps[-1] / nbr)
+ self.steps.append(self.steps[-1] / max(nbr, 1))
self.curr_step.append(0)
self.start_time.append(time.time())
diff --git a/release/scripts/modules/rna_prop_ui.py b/release/scripts/modules/rna_prop_ui.py
index 44722fa7162..195b5767189 100644
--- a/release/scripts/modules/rna_prop_ui.py
+++ b/release/scripts/modules/rna_prop_ui.py
@@ -39,6 +39,11 @@ def rna_idprop_ui_del(item):
pass
+def rna_idprop_ui_prop_update(item, prop):
+ prop_rna = item.path_resolve("[\"%s\"]" % prop.replace("\"", "\\\""), False)
+ prop_rna.update()
+
+
def rna_idprop_ui_prop_get(item, prop, create=True):
rna_ui = rna_idprop_ui_get(item, create)
diff --git a/release/scripts/modules/sys_info.py b/release/scripts/modules/sys_info.py
index 1b63d1d9d8d..c79865d2fca 100644
--- a/release/scripts/modules/sys_info.py
+++ b/release/scripts/modules/sys_info.py
@@ -26,29 +26,9 @@ import bgl
import sys
-def cutPoint(text, length):
- """Returns position of the last space found before 'length' chars"""
- l = length
- c = text[l]
- while c != ' ':
- l -= 1
- if l == 0:
- return length # no space found
- c = text[l]
- return l
-
-
-def textWrap(text, length=70):
- lines = []
- while len(text) > 70:
- cpt = cutPoint(text, length)
- line, text = text[:cpt], text[cpt + 1:]
- lines.append(line)
- lines.append(text)
- return lines
-
-
def write_sysinfo(op):
+ import textwrap
+
output_filename = "system-info.txt"
output = bpy.data.texts.get(output_filename)
@@ -57,49 +37,56 @@ def write_sysinfo(op):
else:
output = bpy.data.texts.new(name=output_filename)
+ # pretty repr
+ def prepr(v):
+ r = repr(v)
+ vt = type(v)
+ if vt is bytes:
+ r = r[2:-1]
+ elif vt is list or vt is tuple:
+ r = r[1:-1]
+ return r
+
+
header = "= Blender %s System Information =\n" % bpy.app.version_string
- lilies = "%s\n\n" % (len(header) * "=")
- firstlilies = "%s\n" % (len(header) * "=")
- output.write(firstlilies)
+ lilies = "%s\n\n" % ((len(header) - 1) * "=")
+ output.write(lilies[:-1])
output.write(header)
output.write(lilies)
+ def title(text):
+ return "\n%s:\n%s" % (text, lilies)
+
# build info
- output.write("\nBlender:\n")
- output.write(lilies)
- if bpy.app.build_branch and bpy.app.build_branch != "Unknown":
- output.write("version %s, branch %r, commit date %r %r, hash %r, %r\n" %
- (bpy.app.version_string,
- bpy.app.build_branch,
- bpy.app.build_commit_date,
- bpy.app.build_commit_time,
- bpy.app.build_hash,
- bpy.app.build_type))
- else:
- output.write("version %s, revision %r. %r\n" %
- (bpy.app.version_string,
- bpy.app.build_change,
- bpy.app.build_type))
-
- output.write("build date: %r, %r\n" % (bpy.app.build_date, bpy.app.build_time))
- output.write("platform: %r\n" % (bpy.app.build_platform))
- output.write("binary path: %r\n" % (bpy.app.binary_path))
- output.write("build cflags: %r\n" % (bpy.app.build_cflags))
- output.write("build cxxflags: %r\n" % (bpy.app.build_cxxflags))
- output.write("build linkflags: %r\n" % (bpy.app.build_linkflags))
- output.write("build system: %r\n" % (bpy.app.build_system))
+ output.write(title("Blender"))
+ output.write("version: %s, branch: %s, commit date: %s %s, hash: %s, type: %s\n" %
+ (bpy.app.version_string,
+ prepr(bpy.app.build_branch),
+ prepr(bpy.app.build_commit_date),
+ prepr(bpy.app.build_commit_time),
+ prepr(bpy.app.build_hash),
+ prepr(bpy.app.build_type),
+ ))
+
+ output.write("build date: %s, %s\n" % (prepr(bpy.app.build_date), prepr(bpy.app.build_time)))
+ output.write("platform: %s\n" % prepr(bpy.app.build_platform))
+ output.write("binary path: %s\n" % prepr(bpy.app.binary_path))
+ output.write("build cflags: %s\n" % prepr(bpy.app.build_cflags))
+ output.write("build cxxflags: %s\n" % prepr(bpy.app.build_cxxflags))
+ output.write("build linkflags: %s\n" % prepr(bpy.app.build_linkflags))
+ output.write("build system: %s\n" % prepr(bpy.app.build_system))
# python info
- output.write("\nPython:\n")
- output.write(lilies)
+ output.write(title("Python"))
output.write("version: %s\n" % (sys.version))
output.write("paths:\n")
for p in sys.path:
- output.write("\t%r\n" % (p))
+ output.write("\t%r\n" % p)
- output.write("\nDirectories:\n")
- output.write(lilies)
- output.write("scripts: %r\n" % (bpy.utils.script_paths()))
+ output.write(title("Directories"))
+ output.write("scripts:\n")
+ for p in bpy.utils.script_paths():
+ output.write("\t%r\n" % p)
output.write("user scripts: %r\n" % (bpy.utils.script_path_user()))
output.write("pref scripts: %r\n" % (bpy.utils.script_path_pref()))
output.write("datafiles: %r\n" % (bpy.utils.user_resource('DATAFILES')))
@@ -108,19 +95,17 @@ def write_sysinfo(op):
output.write("autosave: %r\n" % (bpy.utils.user_resource('AUTOSAVE')))
output.write("tempdir: %r\n" % (bpy.app.tempdir))
- output.write("\nFFmpeg:\n")
- output.write(lilies)
+ output.write(title("FFmpeg"))
ffmpeg = bpy.app.ffmpeg
if ffmpeg.supported:
for lib in ("avcodec", "avdevice", "avformat", "avutil", "swscale"):
- output.write("%r:%r%r\n" % (lib, " " * (10 - len(lib)),
+ output.write("%s:%s%r\n" % (lib, " " * (10 - len(lib)),
getattr(ffmpeg, lib + "_version_string")))
else:
output.write("Blender was built without FFmpeg support\n")
if bpy.app.build_options.sdl:
- output.write("\nSDL\n")
- output.write(lilies)
+ output.write(title("SDL"))
output.write("Version: %s\n" % bpy.app.sdl.version_string)
output.write("Loading method: ")
if bpy.app.build_options.sdl_dynload:
@@ -130,8 +115,7 @@ def write_sysinfo(op):
if not bpy.app.sdl.available:
output.write("WARNING: Blender could not load SDL library\n")
- output.write("\nOther Libraries:\n")
- output.write(lilies)
+ output.write(title("Other Libraries"))
ocio = bpy.app.ocio
output.write("OpenColorIO: ")
if ocio.supported:
@@ -166,8 +150,7 @@ def write_sysinfo(op):
if bpy.app.background:
output.write("\nOpenGL: missing, background mode\n")
else:
- output.write("\nOpenGL\n")
- output.write(lilies)
+ output.write(title("OpenGL"))
version = bgl.glGetString(bgl.GL_RENDERER)
output.write("renderer:\t%r\n" % version)
output.write("vendor:\t\t%r\n" % (bgl.glGetString(bgl.GL_VENDOR)))
@@ -175,12 +158,11 @@ def write_sysinfo(op):
output.write("extensions:\n")
glext = bgl.glGetString(bgl.GL_EXTENSIONS)
- glext = textWrap(glext, 70)
+ glext = textwrap.wrap(glext, 70)
for l in glext:
- output.write("\t\t%r\n" % (l))
+ output.write("\t%s\n" % l)
- output.write("\nImplementation Dependent OpenGL Limits:\n")
- output.write(lilies)
+ output.write(title("Implementation Dependent OpenGL Limits"))
limit = bgl.Buffer(bgl.GL_INT, 1)
bgl.glGetIntegerv(bgl.GL_MAX_TEXTURE_UNITS, limit)
output.write("Maximum Fixed Function Texture Units:\t%d\n" % limit[0])
@@ -204,8 +186,7 @@ def write_sysinfo(op):
if bpy.app.build_options.cycles:
import cycles
- output.write("\nCycles\n")
- output.write(lilies)
+ output.write(title("Cycles"))
output.write(cycles.engine.system_info())
output.current_line_index = 0