2015-08-10 15:26:37 +00:00
|
|
|
# ***** 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 os
|
|
|
|
|
|
|
|
import bpy
|
2017-11-29 07:00:41 +00:00
|
|
|
from mathutils import (
|
|
|
|
Euler,
|
|
|
|
Matrix,
|
|
|
|
Vector,
|
|
|
|
)
|
2015-08-10 15:26:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
OBJECT_TYPES_RENDER = {'MESH', 'CURVE', 'SURFACE', 'META', 'FONT'}
|
|
|
|
|
|
|
|
|
2015-08-30 13:48:40 +00:00
|
|
|
def ids_nolib(bids):
|
|
|
|
return (bid for bid in bids if not bid.library)
|
|
|
|
|
|
|
|
|
2015-08-10 15:26:37 +00:00
|
|
|
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
|
2019-01-11 15:18:00 +00:00
|
|
|
if pid == "rna_type" or pid == "original":
|
2015-08-10 15:26:37 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
Collections and groups unification
OVERVIEW
* In 2.7 terminology, all layers and groups are now collection datablocks.
* These collections are nestable, linkable, instanceable, overrideable, ..
which opens up new ways to set up scenes and link + override data.
* Viewport/render visibility and selectability are now a part of the collection
and shared across all view layers and linkable.
* View layers define which subset of the scene collection hierarchy is excluded
for each. For many workflows one view layer can be used, these are more of an
advanced feature now.
OUTLINER
* The outliner now has a "View Layer" display mode instead of "Collections",
which can display the collections and/or objects in the view layer.
* In this display mode, collections can be excluded with the right click menu.
These will then be greyed out and their objects will be excluded.
* To view collections not linked to any scene, the "Blender File" display mode
can be used, with the new filtering option to just see Colleciton datablocks.
* The outliner right click menus for collections and objects were reorganized.
* Drag and drop still needs to be improved. Like before, dragging the icon or
text gives different results, we'll unify this later.
LINKING AND OVERRIDES
* Collections can now be linked into the scene without creating an instance,
with the link/append operator or from the collections view in the outliner.
* Collections can get static overrides with the right click menu in the outliner,
but this is rather unreliable and not clearly communicated at the moment.
* We still need to improve the make override operator to turn collection instances
into collections with overrides directly in the scene.
PERFORMANCE
* We tried to make performance not worse than before and improve it in some
cases. The main thing that's still a bit slower is multiple scenes, we have to
change the layer syncing to only updated affected scenes.
* Collections keep a list of their parent collections for faster incremental
updates in syncing and caching.
* View layer bases are now in a object -> base hash to avoid quadratic time
lookups internally and in API functions like visible_get().
VERSIONING
* Compatibility with 2.7 files should be improved due to the new visibility
controls. Of course users may not want to set up their scenes differently
now to avoid having separate layers and groups.
* Compatibility with 2.8 is mostly there, and was tested on Eevee demo and Hero
files. There's a few things which are know to be not quite compatible, like
nested layer collections inside groups.
* The versioning code for 2.8 files is quite complicated, and isolated behind
#ifdef so it can be removed at the end of the release cycle.
KNOWN ISSUES
* The G-key group operators in the 3D viewport were left mostly as is, they
need to be modified still to fit better.
* Same for the groups panel in the object properties. This needs to be updated
still, or perhaps replaced by something better.
* Collections must all have a unique name. Less restrictive namespacing is to
be done later, we'll have to see how important this is as all objects within
the collections must also have a unique name anyway.
* Full scene copy and delete scene are exactly doing the right thing yet.
Differential Revision: https://developer.blender.org/D3383
https://code.blender.org/2018/05/collections-and-groups/
2018-04-30 13:57:22 +00:00
|
|
|
def do_previews(do_objects, do_collections, do_scenes, do_data_intern):
|
2016-08-01 01:54:02 +00:00
|
|
|
import collections
|
|
|
|
|
2015-08-10 15:26:37 +00:00
|
|
|
# Helpers.
|
|
|
|
RenderContext = collections.namedtuple("RenderContext", (
|
2018-06-27 12:41:53 +00:00
|
|
|
"scene", "world", "camera", "light", "camera_data", "light_data", "image", # All those are names!
|
|
|
|
"backup_scene", "backup_world", "backup_camera", "backup_light", "backup_camera_data", "backup_light_data",
|
2015-08-10 15:26:37 +00:00
|
|
|
))
|
|
|
|
|
|
|
|
RENDER_PREVIEW_SIZE = bpy.app.render_preview_size
|
|
|
|
|
|
|
|
def render_context_create(engine, objects_ignored):
|
|
|
|
if engine == '__SCENE':
|
2018-06-27 12:41:53 +00:00
|
|
|
backup_scene, backup_world, backup_camera, backup_light, backup_camera_data, backup_light_data = [()] * 6
|
2019-01-11 15:18:00 +00:00
|
|
|
scene = bpy.context.window.scene
|
2019-07-15 16:25:25 +00:00
|
|
|
exclude_props = {('world',), ('camera',), ('tool_settings',), ('preview',)}
|
2015-08-10 15:26:37 +00:00
|
|
|
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
|
2019-01-11 15:18:00 +00:00
|
|
|
scene.collection.objects.link(camera)
|
2018-06-27 12:41:53 +00:00
|
|
|
# TODO: add light if none found in scene?
|
|
|
|
light = None
|
|
|
|
light_data = None
|
2015-08-10 15:26:37 +00:00
|
|
|
else:
|
2018-06-27 12:41:53 +00:00
|
|
|
backup_scene, backup_world, backup_camera, backup_light, backup_camera_data, backup_light_data = [None] * 6
|
2015-08-10 15:26:37 +00:00
|
|
|
|
|
|
|
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)
|
2018-06-27 12:41:53 +00:00
|
|
|
light_data = bpy.data.lights.new("TEMP_preview_render_light", 'SPOT')
|
|
|
|
light = bpy.data.objects.new("TEMP_preview_render_light", light_data)
|
2015-08-10 15:26:37 +00:00
|
|
|
|
2018-06-27 12:41:53 +00:00
|
|
|
objects_ignored.add((camera.name, light.name))
|
2015-08-10 15:26:37 +00:00
|
|
|
|
|
|
|
scene.world = world
|
|
|
|
|
|
|
|
camera.rotation_euler = Euler((1.1635528802871704, 0.0, 0.7853981852531433), 'XYZ') # (66.67, 0.0, 45.0)
|
|
|
|
scene.camera = camera
|
2019-01-11 15:18:00 +00:00
|
|
|
scene.collection.objects.link(camera)
|
2015-08-10 15:26:37 +00:00
|
|
|
|
2018-06-27 12:41:53 +00:00
|
|
|
light.rotation_euler = Euler((0.7853981852531433, 0.0, 1.7453292608261108), 'XYZ') # (45.0, 0.0, 100.0)
|
|
|
|
light_data.falloff_type = 'CONSTANT'
|
|
|
|
light_data.spot_size = 1.0471975803375244 # 60
|
2019-01-11 15:18:00 +00:00
|
|
|
scene.collection.objects.link(light)
|
2015-08-10 15:26:37 +00:00
|
|
|
|
2018-07-05 17:18:43 +00:00
|
|
|
scene.render.engine = 'CYCLES'
|
2019-05-16 15:03:16 +00:00
|
|
|
scene.render.film_transparent = True
|
2018-07-05 17:18:43 +00:00
|
|
|
# TODO: define Cycles world?
|
2015-08-10 15:26:37 +00:00
|
|
|
|
|
|
|
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(
|
2018-06-27 12:41:53 +00:00
|
|
|
scene.name, world.name if world else None, camera.name, light.name if light else None,
|
|
|
|
camera_data.name, light_data.name if light_data else None, image.name,
|
|
|
|
backup_scene, backup_world, backup_camera, backup_light, backup_camera_data, backup_light_data,
|
2015-08-10 15:26:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2015-08-30 13:48:40 +00:00
|
|
|
scene = bpy.data.scenes[render_context.scene, None]
|
2015-08-10 15:26:37 +00:00
|
|
|
try:
|
|
|
|
if render_context.backup_scene is None:
|
|
|
|
scene.world = None
|
|
|
|
scene.camera = None
|
|
|
|
if render_context.camera:
|
2019-01-11 15:18:00 +00:00
|
|
|
scene.collection.objects.unlink(bpy.data.objects[render_context.camera, None])
|
2018-06-27 12:41:53 +00:00
|
|
|
if render_context.light:
|
2019-01-11 15:18:00 +00:00
|
|
|
scene.collection.objects.unlink(bpy.data.objects[render_context.light, None])
|
2016-08-20 12:48:33 +00:00
|
|
|
bpy.data.scenes.remove(scene, do_unlink=True)
|
2015-08-10 15:26:37 +00:00
|
|
|
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:
|
2015-08-30 13:48:40 +00:00
|
|
|
world = bpy.data.worlds[render_context.world, None]
|
2015-08-10 15:26:37 +00:00
|
|
|
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:
|
2015-08-30 13:48:40 +00:00
|
|
|
camera = bpy.data.objects[render_context.camera, None]
|
2015-08-10 15:26:37 +00:00
|
|
|
if render_context.backup_camera is None:
|
|
|
|
if scene is not None:
|
|
|
|
scene.camera = None
|
2019-01-11 15:18:00 +00:00
|
|
|
scene.collection.objects.unlink(camera)
|
2015-08-10 15:26:37 +00:00
|
|
|
camera.user_clear()
|
|
|
|
bpy.data.objects.remove(camera)
|
2015-08-30 13:48:40 +00:00
|
|
|
bpy.data.cameras.remove(bpy.data.cameras[render_context.camera_data, None])
|
2015-08-10 15:26:37 +00:00
|
|
|
else:
|
|
|
|
rna_backup_restore(camera, render_context.backup_camera)
|
2015-08-30 13:48:40 +00:00
|
|
|
rna_backup_restore(bpy.data.cameras[render_context.camera_data, None],
|
|
|
|
render_context.backup_camera_data)
|
2015-08-10 15:26:37 +00:00
|
|
|
except Exception as e:
|
|
|
|
print("ERROR:", e)
|
|
|
|
success = False
|
|
|
|
|
2018-06-27 12:41:53 +00:00
|
|
|
if render_context.light:
|
2015-08-10 15:26:37 +00:00
|
|
|
try:
|
2018-06-27 12:41:53 +00:00
|
|
|
light = bpy.data.objects[render_context.light, None]
|
|
|
|
if render_context.backup_light is None:
|
2015-08-10 15:26:37 +00:00
|
|
|
if scene is not None:
|
2019-01-11 15:18:00 +00:00
|
|
|
scene.collection.objects.unlink(light)
|
2018-06-27 12:41:53 +00:00
|
|
|
light.user_clear()
|
|
|
|
bpy.data.objects.remove(light)
|
|
|
|
bpy.data.lights.remove(bpy.data.lights[render_context.light_data, None])
|
2015-08-10 15:26:37 +00:00
|
|
|
else:
|
2018-06-27 12:41:53 +00:00
|
|
|
rna_backup_restore(light, render_context.backup_light)
|
|
|
|
rna_backup_restore(bpy.data.lights[render_context.light_data, None], render_context.backup_light_data)
|
2015-08-10 15:26:37 +00:00
|
|
|
except Exception as e:
|
|
|
|
print("ERROR:", e)
|
|
|
|
success = False
|
|
|
|
|
|
|
|
try:
|
2015-08-30 13:48:40 +00:00
|
|
|
image = bpy.data.images[render_context.image, None]
|
2015-08-10 15:26:37 +00:00
|
|
|
image.user_clear()
|
|
|
|
bpy.data.images.remove(image)
|
|
|
|
except Exception as e:
|
|
|
|
print("ERROR:", e)
|
|
|
|
success = False
|
|
|
|
|
|
|
|
return success
|
|
|
|
|
2016-02-11 16:32:21 +00:00
|
|
|
def object_bbox_merge(bbox, ob, ob_space, offset_matrix):
|
Collections and groups unification
OVERVIEW
* In 2.7 terminology, all layers and groups are now collection datablocks.
* These collections are nestable, linkable, instanceable, overrideable, ..
which opens up new ways to set up scenes and link + override data.
* Viewport/render visibility and selectability are now a part of the collection
and shared across all view layers and linkable.
* View layers define which subset of the scene collection hierarchy is excluded
for each. For many workflows one view layer can be used, these are more of an
advanced feature now.
OUTLINER
* The outliner now has a "View Layer" display mode instead of "Collections",
which can display the collections and/or objects in the view layer.
* In this display mode, collections can be excluded with the right click menu.
These will then be greyed out and their objects will be excluded.
* To view collections not linked to any scene, the "Blender File" display mode
can be used, with the new filtering option to just see Colleciton datablocks.
* The outliner right click menus for collections and objects were reorganized.
* Drag and drop still needs to be improved. Like before, dragging the icon or
text gives different results, we'll unify this later.
LINKING AND OVERRIDES
* Collections can now be linked into the scene without creating an instance,
with the link/append operator or from the collections view in the outliner.
* Collections can get static overrides with the right click menu in the outliner,
but this is rather unreliable and not clearly communicated at the moment.
* We still need to improve the make override operator to turn collection instances
into collections with overrides directly in the scene.
PERFORMANCE
* We tried to make performance not worse than before and improve it in some
cases. The main thing that's still a bit slower is multiple scenes, we have to
change the layer syncing to only updated affected scenes.
* Collections keep a list of their parent collections for faster incremental
updates in syncing and caching.
* View layer bases are now in a object -> base hash to avoid quadratic time
lookups internally and in API functions like visible_get().
VERSIONING
* Compatibility with 2.7 files should be improved due to the new visibility
controls. Of course users may not want to set up their scenes differently
now to avoid having separate layers and groups.
* Compatibility with 2.8 is mostly there, and was tested on Eevee demo and Hero
files. There's a few things which are know to be not quite compatible, like
nested layer collections inside groups.
* The versioning code for 2.8 files is quite complicated, and isolated behind
#ifdef so it can be removed at the end of the release cycle.
KNOWN ISSUES
* The G-key group operators in the 3D viewport were left mostly as is, they
need to be modified still to fit better.
* Same for the groups panel in the object properties. This needs to be updated
still, or perhaps replaced by something better.
* Collections must all have a unique name. Less restrictive namespacing is to
be done later, we'll have to see how important this is as all objects within
the collections must also have a unique name anyway.
* Full scene copy and delete scene are exactly doing the right thing yet.
Differential Revision: https://developer.blender.org/D3383
https://code.blender.org/2018/05/collections-and-groups/
2018-04-30 13:57:22 +00:00
|
|
|
# Take collections instances into account (including linked one in this case).
|
2018-11-28 16:49:52 +00:00
|
|
|
if ob.type == 'EMPTY' and ob.instance_type == 'COLLECTION':
|
|
|
|
grp_objects = tuple((ob.name, ob.library.filepath if ob.library else None) for ob in ob.instance_collection.all_objects)
|
2016-09-27 15:03:03 +00:00
|
|
|
if (len(grp_objects) == 0):
|
|
|
|
ob_bbox = ob.bound_box
|
|
|
|
else:
|
|
|
|
coords = objects_bbox_calc(ob_space, grp_objects,
|
2018-11-28 16:49:52 +00:00
|
|
|
Matrix.Translation(ob.instance_collection.instance_offset).inverted())
|
2016-09-27 15:03:03 +00:00
|
|
|
ob_bbox = ((coords[0], coords[1], coords[2]), (coords[21], coords[22], coords[23]))
|
|
|
|
elif ob.bound_box:
|
2015-08-10 15:26:37 +00:00
|
|
|
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))
|
2016-09-27 15:03:03 +00:00
|
|
|
|
2016-02-11 16:32:21 +00:00
|
|
|
for v in ob_bbox:
|
2019-01-11 15:18:00 +00:00
|
|
|
v = offset_matrix @ Vector(v) if offset_matrix is not None else Vector(v)
|
|
|
|
v = ob_space.matrix_world.inverted() @ ob.matrix_world @ v
|
2015-08-10 15:26:37 +00:00
|
|
|
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
|
|
|
|
|
2016-02-11 16:32:21 +00:00
|
|
|
def objects_bbox_calc(camera, objects, offset_matrix):
|
2017-10-05 16:12:10 +00:00
|
|
|
bbox = (Vector((1e24, 1e24, 1e24)), Vector((-1e24, -1e24, -1e24)))
|
2016-09-27 15:03:03 +00:00
|
|
|
for obname, libpath in objects:
|
|
|
|
ob = bpy.data.objects[obname, libpath]
|
2016-02-11 16:32:21 +00:00
|
|
|
object_bbox_merge(bbox, ob, camera, offset_matrix)
|
2015-08-10 15:26:37 +00:00
|
|
|
# Our bbox has been generated in camera local space, bring it back in world one
|
2019-01-11 15:18:00 +00:00
|
|
|
bbox[0][:] = camera.matrix_world @ bbox[0]
|
|
|
|
bbox[1][:] = camera.matrix_world @ bbox[1]
|
2015-08-10 15:26:37 +00:00
|
|
|
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
|
|
|
|
|
2016-02-11 16:32:21 +00:00
|
|
|
def preview_render_do(render_context, item_container, item_name, objects, offset_matrix=None):
|
2015-08-30 13:48:40 +00:00
|
|
|
scene = bpy.data.scenes[render_context.scene, None]
|
2015-08-10 15:26:37 +00:00
|
|
|
if objects is not None:
|
2015-08-30 13:48:40 +00:00
|
|
|
camera = bpy.data.objects[render_context.camera, None]
|
2018-06-27 12:41:53 +00:00
|
|
|
light = bpy.data.objects[render_context.light, None] if render_context.light is not None else None
|
2016-02-11 16:32:21 +00:00
|
|
|
cos = objects_bbox_calc(camera, objects, offset_matrix)
|
2019-06-04 12:11:55 +00:00
|
|
|
depsgraph = bpy.context.evaluated_depsgraph_get()
|
|
|
|
loc, _ortho_scale = camera.camera_fit_coords(depsgraph, cos)
|
2015-08-10 15:26:37 +00:00
|
|
|
camera.location = loc
|
2017-10-05 16:12:10 +00:00
|
|
|
# Set camera clipping accordingly to computed bbox.
|
|
|
|
min_dist = 1e24
|
|
|
|
max_dist = -1e24
|
|
|
|
for co in zip(*(iter(cos),) * 3):
|
|
|
|
dist = (Vector(co) - loc).length
|
|
|
|
if dist < min_dist:
|
|
|
|
min_dist = dist
|
|
|
|
if dist > max_dist:
|
|
|
|
max_dist = dist
|
|
|
|
camera.data.clip_start = min_dist / 2
|
|
|
|
camera.data.clip_end = max_dist * 2
|
2018-06-27 12:41:53 +00:00
|
|
|
if light:
|
2019-06-04 12:11:55 +00:00
|
|
|
loc, _ortho_scale = light.camera_fit_coords(depsgraph, cos)
|
2018-06-27 12:41:53 +00:00
|
|
|
light.location = loc
|
2019-06-04 12:11:55 +00:00
|
|
|
bpy.context.view_layer.update()
|
2015-08-10 15:26:37 +00:00
|
|
|
|
|
|
|
bpy.ops.render.render(write_still=True)
|
|
|
|
|
2015-08-30 13:48:40 +00:00
|
|
|
image = bpy.data.images[render_context.image, None]
|
|
|
|
item = getattr(bpy.data, item_container)[item_name, None]
|
2015-08-10 15:26:37 +00:00
|
|
|
image.reload()
|
|
|
|
item.preview.image_size = (RENDER_PREVIEW_SIZE, RENDER_PREVIEW_SIZE)
|
2015-09-01 15:45:16 +00:00
|
|
|
item.preview.image_pixels_float[:] = image.pixels
|
2015-08-10 15:26:37 +00:00
|
|
|
|
|
|
|
# And now, main code!
|
|
|
|
do_save = True
|
|
|
|
|
|
|
|
if do_data_intern:
|
2020-03-03 16:21:22 +00:00
|
|
|
bpy.ops.wm.previews_clear(id_type='SHADING')
|
2015-08-10 15:26:37 +00:00
|
|
|
bpy.ops.wm.previews_ensure()
|
|
|
|
|
|
|
|
render_contexts = {}
|
|
|
|
|
|
|
|
objects_ignored = set()
|
Collections and groups unification
OVERVIEW
* In 2.7 terminology, all layers and groups are now collection datablocks.
* These collections are nestable, linkable, instanceable, overrideable, ..
which opens up new ways to set up scenes and link + override data.
* Viewport/render visibility and selectability are now a part of the collection
and shared across all view layers and linkable.
* View layers define which subset of the scene collection hierarchy is excluded
for each. For many workflows one view layer can be used, these are more of an
advanced feature now.
OUTLINER
* The outliner now has a "View Layer" display mode instead of "Collections",
which can display the collections and/or objects in the view layer.
* In this display mode, collections can be excluded with the right click menu.
These will then be greyed out and their objects will be excluded.
* To view collections not linked to any scene, the "Blender File" display mode
can be used, with the new filtering option to just see Colleciton datablocks.
* The outliner right click menus for collections and objects were reorganized.
* Drag and drop still needs to be improved. Like before, dragging the icon or
text gives different results, we'll unify this later.
LINKING AND OVERRIDES
* Collections can now be linked into the scene without creating an instance,
with the link/append operator or from the collections view in the outliner.
* Collections can get static overrides with the right click menu in the outliner,
but this is rather unreliable and not clearly communicated at the moment.
* We still need to improve the make override operator to turn collection instances
into collections with overrides directly in the scene.
PERFORMANCE
* We tried to make performance not worse than before and improve it in some
cases. The main thing that's still a bit slower is multiple scenes, we have to
change the layer syncing to only updated affected scenes.
* Collections keep a list of their parent collections for faster incremental
updates in syncing and caching.
* View layer bases are now in a object -> base hash to avoid quadratic time
lookups internally and in API functions like visible_get().
VERSIONING
* Compatibility with 2.7 files should be improved due to the new visibility
controls. Of course users may not want to set up their scenes differently
now to avoid having separate layers and groups.
* Compatibility with 2.8 is mostly there, and was tested on Eevee demo and Hero
files. There's a few things which are know to be not quite compatible, like
nested layer collections inside groups.
* The versioning code for 2.8 files is quite complicated, and isolated behind
#ifdef so it can be removed at the end of the release cycle.
KNOWN ISSUES
* The G-key group operators in the 3D viewport were left mostly as is, they
need to be modified still to fit better.
* Same for the groups panel in the object properties. This needs to be updated
still, or perhaps replaced by something better.
* Collections must all have a unique name. Less restrictive namespacing is to
be done later, we'll have to see how important this is as all objects within
the collections must also have a unique name anyway.
* Full scene copy and delete scene are exactly doing the right thing yet.
Differential Revision: https://developer.blender.org/D3383
https://code.blender.org/2018/05/collections-and-groups/
2018-04-30 13:57:22 +00:00
|
|
|
collections_ignored = set()
|
2015-08-10 15:26:37 +00:00
|
|
|
|
2019-01-11 15:18:00 +00:00
|
|
|
prev_scenename = bpy.context.window.scene.name
|
2015-08-10 15:26:37 +00:00
|
|
|
|
|
|
|
if do_objects:
|
2016-02-11 16:32:21 +00:00
|
|
|
prev_shown = {ob.name: ob.hide_render for ob in ids_nolib(bpy.data.objects)}
|
2015-08-30 13:48:40 +00:00
|
|
|
for ob in ids_nolib(bpy.data.objects):
|
2015-08-10 15:26:37 +00:00
|
|
|
if ob in objects_ignored:
|
|
|
|
continue
|
|
|
|
ob.hide_render = True
|
2015-08-30 13:48:40 +00:00
|
|
|
for root in ids_nolib(bpy.data.objects):
|
2015-08-28 15:01:09 +00:00
|
|
|
if root.name in objects_ignored:
|
2015-08-10 15:26:37 +00:00
|
|
|
continue
|
|
|
|
if root.type not in OBJECT_TYPES_RENDER:
|
|
|
|
continue
|
2016-09-27 15:03:03 +00:00
|
|
|
objects = ((root.name, None),)
|
2015-08-10 15:26:37 +00:00
|
|
|
|
2018-07-05 17:18:43 +00:00
|
|
|
render_context = render_contexts.get('CYCLES', None)
|
2015-08-10 15:26:37 +00:00
|
|
|
if render_context is None:
|
2018-07-05 17:18:43 +00:00
|
|
|
render_context = render_context_create('CYCLES', objects_ignored)
|
|
|
|
render_contexts['CYCLES'] = render_context
|
2015-08-10 15:26:37 +00:00
|
|
|
|
2015-08-30 13:48:40 +00:00
|
|
|
scene = bpy.data.scenes[render_context.scene, None]
|
2019-01-11 15:18:00 +00:00
|
|
|
bpy.context.window.scene = scene
|
2015-08-10 15:26:37 +00:00
|
|
|
|
2016-09-27 15:03:03 +00:00
|
|
|
for obname, libpath in objects:
|
|
|
|
ob = bpy.data.objects[obname, libpath]
|
2015-08-10 15:26:37 +00:00
|
|
|
if obname not in scene.objects:
|
2019-01-11 15:18:00 +00:00
|
|
|
scene.collection.objects.link(ob)
|
2015-08-10 15:26:37 +00:00
|
|
|
ob.hide_render = False
|
2019-06-04 12:11:55 +00:00
|
|
|
bpy.context.view_layer.update()
|
2015-08-10 15:26:37 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
# ... :(
|
2015-08-30 13:48:40 +00:00
|
|
|
scene = bpy.data.scenes[render_context.scene, None]
|
2016-09-27 15:03:03 +00:00
|
|
|
for obname, libpath in objects:
|
|
|
|
ob = bpy.data.objects[obname, libpath]
|
2019-01-11 15:18:00 +00:00
|
|
|
scene.collection.objects.unlink(ob)
|
2015-08-10 15:26:37 +00:00
|
|
|
ob.hide_render = True
|
|
|
|
|
2016-02-11 16:32:21 +00:00
|
|
|
for ob in ids_nolib(bpy.data.objects):
|
|
|
|
is_rendered = prev_shown.get(ob.name, ...)
|
|
|
|
if is_rendered is not ...:
|
|
|
|
ob.hide_render = is_rendered
|
2015-08-10 15:26:37 +00:00
|
|
|
|
Collections and groups unification
OVERVIEW
* In 2.7 terminology, all layers and groups are now collection datablocks.
* These collections are nestable, linkable, instanceable, overrideable, ..
which opens up new ways to set up scenes and link + override data.
* Viewport/render visibility and selectability are now a part of the collection
and shared across all view layers and linkable.
* View layers define which subset of the scene collection hierarchy is excluded
for each. For many workflows one view layer can be used, these are more of an
advanced feature now.
OUTLINER
* The outliner now has a "View Layer" display mode instead of "Collections",
which can display the collections and/or objects in the view layer.
* In this display mode, collections can be excluded with the right click menu.
These will then be greyed out and their objects will be excluded.
* To view collections not linked to any scene, the "Blender File" display mode
can be used, with the new filtering option to just see Colleciton datablocks.
* The outliner right click menus for collections and objects were reorganized.
* Drag and drop still needs to be improved. Like before, dragging the icon or
text gives different results, we'll unify this later.
LINKING AND OVERRIDES
* Collections can now be linked into the scene without creating an instance,
with the link/append operator or from the collections view in the outliner.
* Collections can get static overrides with the right click menu in the outliner,
but this is rather unreliable and not clearly communicated at the moment.
* We still need to improve the make override operator to turn collection instances
into collections with overrides directly in the scene.
PERFORMANCE
* We tried to make performance not worse than before and improve it in some
cases. The main thing that's still a bit slower is multiple scenes, we have to
change the layer syncing to only updated affected scenes.
* Collections keep a list of their parent collections for faster incremental
updates in syncing and caching.
* View layer bases are now in a object -> base hash to avoid quadratic time
lookups internally and in API functions like visible_get().
VERSIONING
* Compatibility with 2.7 files should be improved due to the new visibility
controls. Of course users may not want to set up their scenes differently
now to avoid having separate layers and groups.
* Compatibility with 2.8 is mostly there, and was tested on Eevee demo and Hero
files. There's a few things which are know to be not quite compatible, like
nested layer collections inside groups.
* The versioning code for 2.8 files is quite complicated, and isolated behind
#ifdef so it can be removed at the end of the release cycle.
KNOWN ISSUES
* The G-key group operators in the 3D viewport were left mostly as is, they
need to be modified still to fit better.
* Same for the groups panel in the object properties. This needs to be updated
still, or perhaps replaced by something better.
* Collections must all have a unique name. Less restrictive namespacing is to
be done later, we'll have to see how important this is as all objects within
the collections must also have a unique name anyway.
* Full scene copy and delete scene are exactly doing the right thing yet.
Differential Revision: https://developer.blender.org/D3383
https://code.blender.org/2018/05/collections-and-groups/
2018-04-30 13:57:22 +00:00
|
|
|
if do_collections:
|
|
|
|
for grp in ids_nolib(bpy.data.collections):
|
|
|
|
if grp.name in collections_ignored:
|
2015-08-10 15:26:37 +00:00
|
|
|
continue
|
Collections and groups unification
OVERVIEW
* In 2.7 terminology, all layers and groups are now collection datablocks.
* These collections are nestable, linkable, instanceable, overrideable, ..
which opens up new ways to set up scenes and link + override data.
* Viewport/render visibility and selectability are now a part of the collection
and shared across all view layers and linkable.
* View layers define which subset of the scene collection hierarchy is excluded
for each. For many workflows one view layer can be used, these are more of an
advanced feature now.
OUTLINER
* The outliner now has a "View Layer" display mode instead of "Collections",
which can display the collections and/or objects in the view layer.
* In this display mode, collections can be excluded with the right click menu.
These will then be greyed out and their objects will be excluded.
* To view collections not linked to any scene, the "Blender File" display mode
can be used, with the new filtering option to just see Colleciton datablocks.
* The outliner right click menus for collections and objects were reorganized.
* Drag and drop still needs to be improved. Like before, dragging the icon or
text gives different results, we'll unify this later.
LINKING AND OVERRIDES
* Collections can now be linked into the scene without creating an instance,
with the link/append operator or from the collections view in the outliner.
* Collections can get static overrides with the right click menu in the outliner,
but this is rather unreliable and not clearly communicated at the moment.
* We still need to improve the make override operator to turn collection instances
into collections with overrides directly in the scene.
PERFORMANCE
* We tried to make performance not worse than before and improve it in some
cases. The main thing that's still a bit slower is multiple scenes, we have to
change the layer syncing to only updated affected scenes.
* Collections keep a list of their parent collections for faster incremental
updates in syncing and caching.
* View layer bases are now in a object -> base hash to avoid quadratic time
lookups internally and in API functions like visible_get().
VERSIONING
* Compatibility with 2.7 files should be improved due to the new visibility
controls. Of course users may not want to set up their scenes differently
now to avoid having separate layers and groups.
* Compatibility with 2.8 is mostly there, and was tested on Eevee demo and Hero
files. There's a few things which are know to be not quite compatible, like
nested layer collections inside groups.
* The versioning code for 2.8 files is quite complicated, and isolated behind
#ifdef so it can be removed at the end of the release cycle.
KNOWN ISSUES
* The G-key group operators in the 3D viewport were left mostly as is, they
need to be modified still to fit better.
* Same for the groups panel in the object properties. This needs to be updated
still, or perhaps replaced by something better.
* Collections must all have a unique name. Less restrictive namespacing is to
be done later, we'll have to see how important this is as all objects within
the collections must also have a unique name anyway.
* Full scene copy and delete scene are exactly doing the right thing yet.
Differential Revision: https://developer.blender.org/D3383
https://code.blender.org/2018/05/collections-and-groups/
2018-04-30 13:57:22 +00:00
|
|
|
# Here too, we do want to keep linked objects members of local collection...
|
2016-09-27 15:03:03 +00:00
|
|
|
objects = tuple((ob.name, ob.library.filepath if ob.library else None) for ob in grp.objects)
|
2015-08-10 15:26:37 +00:00
|
|
|
|
2018-07-05 17:18:43 +00:00
|
|
|
render_context = render_contexts.get('CYCLES', None)
|
2015-08-10 15:26:37 +00:00
|
|
|
if render_context is None:
|
2018-07-05 17:18:43 +00:00
|
|
|
render_context = render_context_create('CYCLES', objects_ignored)
|
|
|
|
render_contexts['CYCLES'] = render_context
|
2015-08-10 15:26:37 +00:00
|
|
|
|
2015-08-30 13:48:40 +00:00
|
|
|
scene = bpy.data.scenes[render_context.scene, None]
|
2019-01-11 15:18:00 +00:00
|
|
|
bpy.context.window.scene = scene
|
2015-08-10 15:26:37 +00:00
|
|
|
|
Collections and groups unification
OVERVIEW
* In 2.7 terminology, all layers and groups are now collection datablocks.
* These collections are nestable, linkable, instanceable, overrideable, ..
which opens up new ways to set up scenes and link + override data.
* Viewport/render visibility and selectability are now a part of the collection
and shared across all view layers and linkable.
* View layers define which subset of the scene collection hierarchy is excluded
for each. For many workflows one view layer can be used, these are more of an
advanced feature now.
OUTLINER
* The outliner now has a "View Layer" display mode instead of "Collections",
which can display the collections and/or objects in the view layer.
* In this display mode, collections can be excluded with the right click menu.
These will then be greyed out and their objects will be excluded.
* To view collections not linked to any scene, the "Blender File" display mode
can be used, with the new filtering option to just see Colleciton datablocks.
* The outliner right click menus for collections and objects were reorganized.
* Drag and drop still needs to be improved. Like before, dragging the icon or
text gives different results, we'll unify this later.
LINKING AND OVERRIDES
* Collections can now be linked into the scene without creating an instance,
with the link/append operator or from the collections view in the outliner.
* Collections can get static overrides with the right click menu in the outliner,
but this is rather unreliable and not clearly communicated at the moment.
* We still need to improve the make override operator to turn collection instances
into collections with overrides directly in the scene.
PERFORMANCE
* We tried to make performance not worse than before and improve it in some
cases. The main thing that's still a bit slower is multiple scenes, we have to
change the layer syncing to only updated affected scenes.
* Collections keep a list of their parent collections for faster incremental
updates in syncing and caching.
* View layer bases are now in a object -> base hash to avoid quadratic time
lookups internally and in API functions like visible_get().
VERSIONING
* Compatibility with 2.7 files should be improved due to the new visibility
controls. Of course users may not want to set up their scenes differently
now to avoid having separate layers and groups.
* Compatibility with 2.8 is mostly there, and was tested on Eevee demo and Hero
files. There's a few things which are know to be not quite compatible, like
nested layer collections inside groups.
* The versioning code for 2.8 files is quite complicated, and isolated behind
#ifdef so it can be removed at the end of the release cycle.
KNOWN ISSUES
* The G-key group operators in the 3D viewport were left mostly as is, they
need to be modified still to fit better.
* Same for the groups panel in the object properties. This needs to be updated
still, or perhaps replaced by something better.
* Collections must all have a unique name. Less restrictive namespacing is to
be done later, we'll have to see how important this is as all objects within
the collections must also have a unique name anyway.
* Full scene copy and delete scene are exactly doing the right thing yet.
Differential Revision: https://developer.blender.org/D3383
https://code.blender.org/2018/05/collections-and-groups/
2018-04-30 13:57:22 +00:00
|
|
|
bpy.ops.object.collection_instance_add(collection=grp.name)
|
2018-11-29 17:26:48 +00:00
|
|
|
grp_ob = next((ob for ob in scene.objects if ob.instance_collection and ob.instance_collection.name == grp.name))
|
2015-08-10 15:26:37 +00:00
|
|
|
grp_obname = grp_ob.name
|
2019-06-04 12:11:55 +00:00
|
|
|
bpy.context.view_layer.update()
|
2015-08-10 15:26:37 +00:00
|
|
|
|
2018-11-28 16:49:52 +00:00
|
|
|
offset_matrix = Matrix.Translation(grp.instance_offset).inverted()
|
2016-02-11 16:32:21 +00:00
|
|
|
|
Collections and groups unification
OVERVIEW
* In 2.7 terminology, all layers and groups are now collection datablocks.
* These collections are nestable, linkable, instanceable, overrideable, ..
which opens up new ways to set up scenes and link + override data.
* Viewport/render visibility and selectability are now a part of the collection
and shared across all view layers and linkable.
* View layers define which subset of the scene collection hierarchy is excluded
for each. For many workflows one view layer can be used, these are more of an
advanced feature now.
OUTLINER
* The outliner now has a "View Layer" display mode instead of "Collections",
which can display the collections and/or objects in the view layer.
* In this display mode, collections can be excluded with the right click menu.
These will then be greyed out and their objects will be excluded.
* To view collections not linked to any scene, the "Blender File" display mode
can be used, with the new filtering option to just see Colleciton datablocks.
* The outliner right click menus for collections and objects were reorganized.
* Drag and drop still needs to be improved. Like before, dragging the icon or
text gives different results, we'll unify this later.
LINKING AND OVERRIDES
* Collections can now be linked into the scene without creating an instance,
with the link/append operator or from the collections view in the outliner.
* Collections can get static overrides with the right click menu in the outliner,
but this is rather unreliable and not clearly communicated at the moment.
* We still need to improve the make override operator to turn collection instances
into collections with overrides directly in the scene.
PERFORMANCE
* We tried to make performance not worse than before and improve it in some
cases. The main thing that's still a bit slower is multiple scenes, we have to
change the layer syncing to only updated affected scenes.
* Collections keep a list of their parent collections for faster incremental
updates in syncing and caching.
* View layer bases are now in a object -> base hash to avoid quadratic time
lookups internally and in API functions like visible_get().
VERSIONING
* Compatibility with 2.7 files should be improved due to the new visibility
controls. Of course users may not want to set up their scenes differently
now to avoid having separate layers and groups.
* Compatibility with 2.8 is mostly there, and was tested on Eevee demo and Hero
files. There's a few things which are know to be not quite compatible, like
nested layer collections inside groups.
* The versioning code for 2.8 files is quite complicated, and isolated behind
#ifdef so it can be removed at the end of the release cycle.
KNOWN ISSUES
* The G-key group operators in the 3D viewport were left mostly as is, they
need to be modified still to fit better.
* Same for the groups panel in the object properties. This needs to be updated
still, or perhaps replaced by something better.
* Collections must all have a unique name. Less restrictive namespacing is to
be done later, we'll have to see how important this is as all objects within
the collections must also have a unique name anyway.
* Full scene copy and delete scene are exactly doing the right thing yet.
Differential Revision: https://developer.blender.org/D3383
https://code.blender.org/2018/05/collections-and-groups/
2018-04-30 13:57:22 +00:00
|
|
|
preview_render_do(render_context, 'collections', grp.name, objects, offset_matrix)
|
2015-08-10 15:26:37 +00:00
|
|
|
|
2015-08-30 13:48:40 +00:00
|
|
|
scene = bpy.data.scenes[render_context.scene, None]
|
2019-01-11 15:18:00 +00:00
|
|
|
scene.collection.objects.unlink(bpy.data.objects[grp_obname, None])
|
2015-08-10 15:26:37 +00:00
|
|
|
|
2019-01-11 15:18:00 +00:00
|
|
|
bpy.context.window.scene = bpy.data.scenes[prev_scenename, None]
|
2015-08-10 15:26:37 +00:00
|
|
|
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:
|
2015-08-30 13:48:40 +00:00
|
|
|
for scene in ids_nolib(bpy.data.scenes):
|
2015-08-28 15:01:09 +00:00
|
|
|
has_camera = scene.camera is not None
|
2019-01-11 15:18:00 +00:00
|
|
|
bpy.context.window.scene = scene
|
2015-08-10 15:26:37 +00:00
|
|
|
render_context = render_context_create('__SCENE', objects_ignored)
|
2019-06-04 12:11:55 +00:00
|
|
|
bpy.context.view_layer.update()
|
2015-08-10 15:26:37 +00:00
|
|
|
|
|
|
|
objects = None
|
|
|
|
if not has_camera:
|
|
|
|
# We had to add a temp camera, now we need to place it to see interesting objects!
|
2016-09-27 15:03:03 +00:00
|
|
|
objects = tuple((ob.name, ob.library.filepath if ob.library else None) for ob in scene.objects
|
2018-07-03 04:27:53 +00:00
|
|
|
if (not ob.hide_render) and (ob.type in OBJECT_TYPES_RENDER))
|
2015-08-10 15:26:37 +00:00
|
|
|
|
2015-08-28 15:01:09 +00:00
|
|
|
preview_render_do(render_context, 'scenes', scene.name, objects)
|
2015-08-10 15:26:37 +00:00
|
|
|
|
|
|
|
if not render_context_delete(render_context):
|
|
|
|
do_save = False
|
|
|
|
|
2019-01-11 15:18:00 +00:00
|
|
|
bpy.context.window.scene = bpy.data.scenes[prev_scenename, None]
|
2015-08-10 15:26:37 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
Collections and groups unification
OVERVIEW
* In 2.7 terminology, all layers and groups are now collection datablocks.
* These collections are nestable, linkable, instanceable, overrideable, ..
which opens up new ways to set up scenes and link + override data.
* Viewport/render visibility and selectability are now a part of the collection
and shared across all view layers and linkable.
* View layers define which subset of the scene collection hierarchy is excluded
for each. For many workflows one view layer can be used, these are more of an
advanced feature now.
OUTLINER
* The outliner now has a "View Layer" display mode instead of "Collections",
which can display the collections and/or objects in the view layer.
* In this display mode, collections can be excluded with the right click menu.
These will then be greyed out and their objects will be excluded.
* To view collections not linked to any scene, the "Blender File" display mode
can be used, with the new filtering option to just see Colleciton datablocks.
* The outliner right click menus for collections and objects were reorganized.
* Drag and drop still needs to be improved. Like before, dragging the icon or
text gives different results, we'll unify this later.
LINKING AND OVERRIDES
* Collections can now be linked into the scene without creating an instance,
with the link/append operator or from the collections view in the outliner.
* Collections can get static overrides with the right click menu in the outliner,
but this is rather unreliable and not clearly communicated at the moment.
* We still need to improve the make override operator to turn collection instances
into collections with overrides directly in the scene.
PERFORMANCE
* We tried to make performance not worse than before and improve it in some
cases. The main thing that's still a bit slower is multiple scenes, we have to
change the layer syncing to only updated affected scenes.
* Collections keep a list of their parent collections for faster incremental
updates in syncing and caching.
* View layer bases are now in a object -> base hash to avoid quadratic time
lookups internally and in API functions like visible_get().
VERSIONING
* Compatibility with 2.7 files should be improved due to the new visibility
controls. Of course users may not want to set up their scenes differently
now to avoid having separate layers and groups.
* Compatibility with 2.8 is mostly there, and was tested on Eevee demo and Hero
files. There's a few things which are know to be not quite compatible, like
nested layer collections inside groups.
* The versioning code for 2.8 files is quite complicated, and isolated behind
#ifdef so it can be removed at the end of the release cycle.
KNOWN ISSUES
* The G-key group operators in the 3D viewport were left mostly as is, they
need to be modified still to fit better.
* Same for the groups panel in the object properties. This needs to be updated
still, or perhaps replaced by something better.
* Collections must all have a unique name. Less restrictive namespacing is to
be done later, we'll have to see how important this is as all objects within
the collections must also have a unique name anyway.
* Full scene copy and delete scene are exactly doing the right thing yet.
Differential Revision: https://developer.blender.org/D3383
https://code.blender.org/2018/05/collections-and-groups/
2018-04-30 13:57:22 +00:00
|
|
|
def do_clear_previews(do_objects, do_collections, do_scenes, do_data_intern):
|
2015-08-10 15:26:37 +00:00
|
|
|
if do_data_intern:
|
2020-03-03 16:21:22 +00:00
|
|
|
bpy.ops.wm.previews_clear(id_type='SHADING')
|
2015-08-10 15:26:37 +00:00
|
|
|
|
|
|
|
if do_objects:
|
2015-08-30 13:48:40 +00:00
|
|
|
for ob in ids_nolib(bpy.data.objects):
|
2015-08-10 15:26:37 +00:00
|
|
|
ob.preview.image_size = (0, 0)
|
|
|
|
|
Collections and groups unification
OVERVIEW
* In 2.7 terminology, all layers and groups are now collection datablocks.
* These collections are nestable, linkable, instanceable, overrideable, ..
which opens up new ways to set up scenes and link + override data.
* Viewport/render visibility and selectability are now a part of the collection
and shared across all view layers and linkable.
* View layers define which subset of the scene collection hierarchy is excluded
for each. For many workflows one view layer can be used, these are more of an
advanced feature now.
OUTLINER
* The outliner now has a "View Layer" display mode instead of "Collections",
which can display the collections and/or objects in the view layer.
* In this display mode, collections can be excluded with the right click menu.
These will then be greyed out and their objects will be excluded.
* To view collections not linked to any scene, the "Blender File" display mode
can be used, with the new filtering option to just see Colleciton datablocks.
* The outliner right click menus for collections and objects were reorganized.
* Drag and drop still needs to be improved. Like before, dragging the icon or
text gives different results, we'll unify this later.
LINKING AND OVERRIDES
* Collections can now be linked into the scene without creating an instance,
with the link/append operator or from the collections view in the outliner.
* Collections can get static overrides with the right click menu in the outliner,
but this is rather unreliable and not clearly communicated at the moment.
* We still need to improve the make override operator to turn collection instances
into collections with overrides directly in the scene.
PERFORMANCE
* We tried to make performance not worse than before and improve it in some
cases. The main thing that's still a bit slower is multiple scenes, we have to
change the layer syncing to only updated affected scenes.
* Collections keep a list of their parent collections for faster incremental
updates in syncing and caching.
* View layer bases are now in a object -> base hash to avoid quadratic time
lookups internally and in API functions like visible_get().
VERSIONING
* Compatibility with 2.7 files should be improved due to the new visibility
controls. Of course users may not want to set up their scenes differently
now to avoid having separate layers and groups.
* Compatibility with 2.8 is mostly there, and was tested on Eevee demo and Hero
files. There's a few things which are know to be not quite compatible, like
nested layer collections inside groups.
* The versioning code for 2.8 files is quite complicated, and isolated behind
#ifdef so it can be removed at the end of the release cycle.
KNOWN ISSUES
* The G-key group operators in the 3D viewport were left mostly as is, they
need to be modified still to fit better.
* Same for the groups panel in the object properties. This needs to be updated
still, or perhaps replaced by something better.
* Collections must all have a unique name. Less restrictive namespacing is to
be done later, we'll have to see how important this is as all objects within
the collections must also have a unique name anyway.
* Full scene copy and delete scene are exactly doing the right thing yet.
Differential Revision: https://developer.blender.org/D3383
https://code.blender.org/2018/05/collections-and-groups/
2018-04-30 13:57:22 +00:00
|
|
|
if do_collections:
|
|
|
|
for grp in ids_nolib(bpy.data.collections):
|
2015-08-10 15:26:37 +00:00
|
|
|
grp.preview.image_size = (0, 0)
|
|
|
|
|
|
|
|
if do_scenes:
|
2015-08-30 13:48:40 +00:00
|
|
|
for scene in ids_nolib(bpy.data.scenes):
|
2015-08-10 15:26:37 +00:00
|
|
|
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.")
|
2016-03-01 16:46:21 +00:00
|
|
|
parser.add_argument('--clear', default=False, action="store_true",
|
|
|
|
help="Clear previews instead of generating them.")
|
|
|
|
parser.add_argument('--no_backups', default=False, action="store_true",
|
|
|
|
help="Do not generate a backup .blend1 file when saving processed ones.")
|
|
|
|
parser.add_argument('--no_scenes', default=True, action="store_false",
|
|
|
|
help="Do not generate/clear previews for scene IDs.")
|
Collections and groups unification
OVERVIEW
* In 2.7 terminology, all layers and groups are now collection datablocks.
* These collections are nestable, linkable, instanceable, overrideable, ..
which opens up new ways to set up scenes and link + override data.
* Viewport/render visibility and selectability are now a part of the collection
and shared across all view layers and linkable.
* View layers define which subset of the scene collection hierarchy is excluded
for each. For many workflows one view layer can be used, these are more of an
advanced feature now.
OUTLINER
* The outliner now has a "View Layer" display mode instead of "Collections",
which can display the collections and/or objects in the view layer.
* In this display mode, collections can be excluded with the right click menu.
These will then be greyed out and their objects will be excluded.
* To view collections not linked to any scene, the "Blender File" display mode
can be used, with the new filtering option to just see Colleciton datablocks.
* The outliner right click menus for collections and objects were reorganized.
* Drag and drop still needs to be improved. Like before, dragging the icon or
text gives different results, we'll unify this later.
LINKING AND OVERRIDES
* Collections can now be linked into the scene without creating an instance,
with the link/append operator or from the collections view in the outliner.
* Collections can get static overrides with the right click menu in the outliner,
but this is rather unreliable and not clearly communicated at the moment.
* We still need to improve the make override operator to turn collection instances
into collections with overrides directly in the scene.
PERFORMANCE
* We tried to make performance not worse than before and improve it in some
cases. The main thing that's still a bit slower is multiple scenes, we have to
change the layer syncing to only updated affected scenes.
* Collections keep a list of their parent collections for faster incremental
updates in syncing and caching.
* View layer bases are now in a object -> base hash to avoid quadratic time
lookups internally and in API functions like visible_get().
VERSIONING
* Compatibility with 2.7 files should be improved due to the new visibility
controls. Of course users may not want to set up their scenes differently
now to avoid having separate layers and groups.
* Compatibility with 2.8 is mostly there, and was tested on Eevee demo and Hero
files. There's a few things which are know to be not quite compatible, like
nested layer collections inside groups.
* The versioning code for 2.8 files is quite complicated, and isolated behind
#ifdef so it can be removed at the end of the release cycle.
KNOWN ISSUES
* The G-key group operators in the 3D viewport were left mostly as is, they
need to be modified still to fit better.
* Same for the groups panel in the object properties. This needs to be updated
still, or perhaps replaced by something better.
* Collections must all have a unique name. Less restrictive namespacing is to
be done later, we'll have to see how important this is as all objects within
the collections must also have a unique name anyway.
* Full scene copy and delete scene are exactly doing the right thing yet.
Differential Revision: https://developer.blender.org/D3383
https://code.blender.org/2018/05/collections-and-groups/
2018-04-30 13:57:22 +00:00
|
|
|
parser.add_argument('--no_collections', default=True, action="store_false",
|
|
|
|
help="Do not generate/clear previews for collection IDs.")
|
2016-03-01 16:46:21 +00:00
|
|
|
parser.add_argument('--no_objects', default=True, action="store_false",
|
|
|
|
help="Do not generate/clear previews for object IDs.")
|
2015-08-10 15:26:37 +00:00
|
|
|
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)
|
|
|
|
|
2018-12-21 01:47:44 +00:00
|
|
|
orig_save_version = bpy.context.preferences.filepaths.save_version
|
2016-03-01 16:46:21 +00:00
|
|
|
if args.no_backups:
|
2018-12-21 01:47:44 +00:00
|
|
|
bpy.context.preferences.filepaths.save_version = 0
|
2016-03-01 16:46:21 +00:00
|
|
|
elif orig_save_version < 1:
|
2018-12-21 01:47:44 +00:00
|
|
|
bpy.context.preferences.filepaths.save_version = 1
|
2016-03-01 16:46:21 +00:00
|
|
|
|
2015-08-10 15:26:37 +00:00
|
|
|
if args.clear:
|
|
|
|
print("clear!")
|
Collections and groups unification
OVERVIEW
* In 2.7 terminology, all layers and groups are now collection datablocks.
* These collections are nestable, linkable, instanceable, overrideable, ..
which opens up new ways to set up scenes and link + override data.
* Viewport/render visibility and selectability are now a part of the collection
and shared across all view layers and linkable.
* View layers define which subset of the scene collection hierarchy is excluded
for each. For many workflows one view layer can be used, these are more of an
advanced feature now.
OUTLINER
* The outliner now has a "View Layer" display mode instead of "Collections",
which can display the collections and/or objects in the view layer.
* In this display mode, collections can be excluded with the right click menu.
These will then be greyed out and their objects will be excluded.
* To view collections not linked to any scene, the "Blender File" display mode
can be used, with the new filtering option to just see Colleciton datablocks.
* The outliner right click menus for collections and objects were reorganized.
* Drag and drop still needs to be improved. Like before, dragging the icon or
text gives different results, we'll unify this later.
LINKING AND OVERRIDES
* Collections can now be linked into the scene without creating an instance,
with the link/append operator or from the collections view in the outliner.
* Collections can get static overrides with the right click menu in the outliner,
but this is rather unreliable and not clearly communicated at the moment.
* We still need to improve the make override operator to turn collection instances
into collections with overrides directly in the scene.
PERFORMANCE
* We tried to make performance not worse than before and improve it in some
cases. The main thing that's still a bit slower is multiple scenes, we have to
change the layer syncing to only updated affected scenes.
* Collections keep a list of their parent collections for faster incremental
updates in syncing and caching.
* View layer bases are now in a object -> base hash to avoid quadratic time
lookups internally and in API functions like visible_get().
VERSIONING
* Compatibility with 2.7 files should be improved due to the new visibility
controls. Of course users may not want to set up their scenes differently
now to avoid having separate layers and groups.
* Compatibility with 2.8 is mostly there, and was tested on Eevee demo and Hero
files. There's a few things which are know to be not quite compatible, like
nested layer collections inside groups.
* The versioning code for 2.8 files is quite complicated, and isolated behind
#ifdef so it can be removed at the end of the release cycle.
KNOWN ISSUES
* The G-key group operators in the 3D viewport were left mostly as is, they
need to be modified still to fit better.
* Same for the groups panel in the object properties. This needs to be updated
still, or perhaps replaced by something better.
* Collections must all have a unique name. Less restrictive namespacing is to
be done later, we'll have to see how important this is as all objects within
the collections must also have a unique name anyway.
* Full scene copy and delete scene are exactly doing the right thing yet.
Differential Revision: https://developer.blender.org/D3383
https://code.blender.org/2018/05/collections-and-groups/
2018-04-30 13:57:22 +00:00
|
|
|
do_clear_previews(do_objects=args.no_objects, do_collections=args.no_collections, do_scenes=args.no_scenes,
|
2015-08-10 15:26:37 +00:00
|
|
|
do_data_intern=args.no_data_intern)
|
|
|
|
else:
|
|
|
|
print("render!")
|
Collections and groups unification
OVERVIEW
* In 2.7 terminology, all layers and groups are now collection datablocks.
* These collections are nestable, linkable, instanceable, overrideable, ..
which opens up new ways to set up scenes and link + override data.
* Viewport/render visibility and selectability are now a part of the collection
and shared across all view layers and linkable.
* View layers define which subset of the scene collection hierarchy is excluded
for each. For many workflows one view layer can be used, these are more of an
advanced feature now.
OUTLINER
* The outliner now has a "View Layer" display mode instead of "Collections",
which can display the collections and/or objects in the view layer.
* In this display mode, collections can be excluded with the right click menu.
These will then be greyed out and their objects will be excluded.
* To view collections not linked to any scene, the "Blender File" display mode
can be used, with the new filtering option to just see Colleciton datablocks.
* The outliner right click menus for collections and objects were reorganized.
* Drag and drop still needs to be improved. Like before, dragging the icon or
text gives different results, we'll unify this later.
LINKING AND OVERRIDES
* Collections can now be linked into the scene without creating an instance,
with the link/append operator or from the collections view in the outliner.
* Collections can get static overrides with the right click menu in the outliner,
but this is rather unreliable and not clearly communicated at the moment.
* We still need to improve the make override operator to turn collection instances
into collections with overrides directly in the scene.
PERFORMANCE
* We tried to make performance not worse than before and improve it in some
cases. The main thing that's still a bit slower is multiple scenes, we have to
change the layer syncing to only updated affected scenes.
* Collections keep a list of their parent collections for faster incremental
updates in syncing and caching.
* View layer bases are now in a object -> base hash to avoid quadratic time
lookups internally and in API functions like visible_get().
VERSIONING
* Compatibility with 2.7 files should be improved due to the new visibility
controls. Of course users may not want to set up their scenes differently
now to avoid having separate layers and groups.
* Compatibility with 2.8 is mostly there, and was tested on Eevee demo and Hero
files. There's a few things which are know to be not quite compatible, like
nested layer collections inside groups.
* The versioning code for 2.8 files is quite complicated, and isolated behind
#ifdef so it can be removed at the end of the release cycle.
KNOWN ISSUES
* The G-key group operators in the 3D viewport were left mostly as is, they
need to be modified still to fit better.
* Same for the groups panel in the object properties. This needs to be updated
still, or perhaps replaced by something better.
* Collections must all have a unique name. Less restrictive namespacing is to
be done later, we'll have to see how important this is as all objects within
the collections must also have a unique name anyway.
* Full scene copy and delete scene are exactly doing the right thing yet.
Differential Revision: https://developer.blender.org/D3383
https://code.blender.org/2018/05/collections-and-groups/
2018-04-30 13:57:22 +00:00
|
|
|
do_previews(do_objects=args.no_objects, do_collections=args.no_collections, do_scenes=args.no_scenes,
|
2015-08-10 15:26:37 +00:00
|
|
|
do_data_intern=args.no_data_intern)
|
|
|
|
|
2016-03-01 16:46:21 +00:00
|
|
|
# Not really necessary, but better be consistent.
|
2018-12-21 01:47:44 +00:00
|
|
|
bpy.context.preferences.filepaths.save_version = orig_save_version
|
2016-03-01 16:46:21 +00:00
|
|
|
|
2015-08-10 15:26:37 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
print("\n\n *** Running {} *** \n".format(__file__))
|
|
|
|
print(" *** Blend file {} *** \n".format(bpy.data.filepath))
|
|
|
|
main()
|
|
|
|
bpy.ops.wm.quit_blender()
|