2011-08-05 00:51:44 +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 #####
|
|
|
|
|
2017-03-25 11:07:05 +11:00
|
|
|
# <pep8 compliant>
|
|
|
|
|
2011-08-05 00:51:44 +00:00
|
|
|
import bpy
|
|
|
|
|
2015-01-27 17:46:07 +11:00
|
|
|
from bpy.props import (
|
2017-03-25 11:07:05 +11:00
|
|
|
BoolProperty,
|
|
|
|
EnumProperty,
|
|
|
|
StringProperty,
|
|
|
|
)
|
2011-08-05 00:51:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SCENE_OT_freestyle_fill_range_by_selection(bpy.types.Operator):
|
2013-04-07 10:21:22 +00:00
|
|
|
"""Fill the Range Min/Max entries by the min/max distance between selected mesh objects and the source object """
|
|
|
|
"""(either a user-specified object or the active camera)"""
|
2011-08-05 00:51:44 +00:00
|
|
|
bl_idname = "scene.freestyle_fill_range_by_selection"
|
|
|
|
bl_label = "Fill Range by Selection"
|
2013-04-26 02:44:21 +00:00
|
|
|
bl_options = {'INTERNAL'}
|
2011-08-05 00:51:44 +00:00
|
|
|
|
2015-01-27 17:46:07 +11:00
|
|
|
type = EnumProperty(
|
|
|
|
name="Type", description="Type of the modifier to work on",
|
|
|
|
items=(("COLOR", "Color", "Color modifier type"),
|
|
|
|
("ALPHA", "Alpha", "Alpha modifier type"),
|
|
|
|
("THICKNESS", "Thickness", "Thickness modifier type")),
|
|
|
|
)
|
|
|
|
name = StringProperty(
|
|
|
|
name="Name",
|
|
|
|
description="Name of the modifier to work on",
|
|
|
|
)
|
2011-08-05 00:51:44 +00:00
|
|
|
|
2013-04-26 02:29:31 +00:00
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
2017-11-22 10:52:39 -02:00
|
|
|
view_layer = context.scene.view_layers.active
|
|
|
|
return view_layer and view_layer.freestyle_settings.linesets.active
|
2013-04-26 02:29:31 +00:00
|
|
|
|
2011-08-05 00:51:44 +00:00
|
|
|
def execute(self, context):
|
2015-01-27 17:46:07 +11:00
|
|
|
import sys
|
|
|
|
|
2014-01-18 09:13:51 +11:00
|
|
|
scene = context.scene
|
2017-11-22 10:52:39 -02:00
|
|
|
view_layer = scene.view_layers.active
|
|
|
|
lineset = view_layer.freestyle_settings.linesets.active
|
2011-08-05 00:51:44 +00:00
|
|
|
linestyle = lineset.linestyle
|
|
|
|
# Find the modifier to work on
|
|
|
|
if self.type == 'COLOR':
|
|
|
|
m = linestyle.color_modifiers[self.name]
|
|
|
|
elif self.type == 'ALPHA':
|
|
|
|
m = linestyle.alpha_modifiers[self.name]
|
|
|
|
else:
|
|
|
|
m = linestyle.thickness_modifiers[self.name]
|
2017-01-30 12:18:39 +09:00
|
|
|
# Find the reference object
|
2011-08-24 15:47:05 +00:00
|
|
|
if m.type == 'DISTANCE_FROM_CAMERA':
|
2017-01-30 12:18:39 +09:00
|
|
|
ref = scene.camera
|
|
|
|
matrix_to_camera = ref.matrix_world.inverted()
|
2011-08-24 15:47:05 +00:00
|
|
|
elif m.type == 'DISTANCE_FROM_OBJECT':
|
|
|
|
if m.target is None:
|
|
|
|
self.report({'ERROR'}, "Target object not specified")
|
|
|
|
return {'CANCELLED'}
|
2017-01-30 12:18:39 +09:00
|
|
|
ref = m.target
|
|
|
|
target_location = ref.location
|
2011-08-24 15:47:05 +00:00
|
|
|
else:
|
|
|
|
self.report({'ERROR'}, "Unexpected modifier type: " + m.type)
|
|
|
|
return {'CANCELLED'}
|
2017-01-31 09:04:05 +09:00
|
|
|
# Find selected vertices in editmesh
|
2018-02-07 15:47:54 +11:00
|
|
|
ob = context.active_object
|
2018-04-05 18:20:27 +02:00
|
|
|
if ob.type == 'MESH' and ob.mode == 'EDIT' and ob.name != ref.name:
|
2017-01-31 09:04:05 +09:00
|
|
|
bpy.ops.object.mode_set(mode='OBJECT')
|
2018-02-07 15:47:54 +11:00
|
|
|
selected_verts = [v for v in ob.data.vertices if v.select]
|
2017-01-31 09:04:05 +09:00
|
|
|
bpy.ops.object.mode_set(mode='EDIT')
|
|
|
|
# Compute the min/max distance from the reference to mesh vertices
|
|
|
|
min_dist = sys.float_info.max
|
|
|
|
max_dist = -min_dist
|
|
|
|
if m.type == 'DISTANCE_FROM_CAMERA':
|
|
|
|
ob_to_cam = matrix_to_camera * ob.matrix_world
|
|
|
|
for vert in selected_verts:
|
|
|
|
# dist in the camera space
|
|
|
|
dist = (ob_to_cam * vert.co).length
|
|
|
|
min_dist = min(dist, min_dist)
|
|
|
|
max_dist = max(dist, max_dist)
|
|
|
|
elif m.type == 'DISTANCE_FROM_OBJECT':
|
|
|
|
for vert in selected_verts:
|
|
|
|
# dist in the world space
|
|
|
|
dist = (ob.matrix_world * vert.co - target_location).length
|
|
|
|
min_dist = min(dist, min_dist)
|
|
|
|
max_dist = max(dist, max_dist)
|
|
|
|
# Fill the Range Min/Max entries with the computed distances
|
|
|
|
m.range_min = min_dist
|
|
|
|
m.range_max = max_dist
|
|
|
|
return {'FINISHED'}
|
2011-08-05 00:51:44 +00:00
|
|
|
# Find selected mesh objects
|
Render Layers and Collections (merge from render-layers)
Design Documents
----------------
* https://wiki.blender.org/index.php/Dev:2.8/Source/Layers
* https://wiki.blender.org/index.php/Dev:2.8/Source/DataDesignRevised
User Commit Log
---------------
* New Layer and Collection system to replace render layers and viewport layers.
* A layer is a set of collections of objects (and their drawing options) required for specific tasks.
* A collection is a set of objects, equivalent of the old layers in Blender. A collection can be shared across multiple layers.
* All Scenes have a master collection that all other collections are children of.
* New collection "context" tab (in Properties Editor)
* New temporary viewport "collections" panel to control per-collection
visibility
Missing User Features
---------------------
* Collection "Filter"
Option to add objects based on their names
* Collection Manager operators
The existing buttons are placeholders
* Collection Manager drawing
The editor main region is empty
* Collection Override
* Per-Collection engine settings
This will come as a separate commit, as part of the clay-engine branch
Dev Commit Log
--------------
* New DNA file (DNA_layer_types.h) with the new structs
We are replacing Base by a new extended Base while keeping it backward
compatible with some legacy settings (i.e., lay, flag_legacy).
Renamed all Base to BaseLegacy to make it clear the areas of code that
still need to be converted
Note: manual changes were required on - deg_builder_nodes.h, rna_object.c, KX_Light.cpp
* Unittesting for main syncronization requirements
- read, write, add/copy/remove objects, copy scene, collection
link/unlinking, context)
* New Editor: Collection Manager
Based on patch by Julian Eisel
This is extracted from the layer-manager branch. With the following changes:
- Renamed references of layer manager to collections manager
- I doesn't include the editors/space_collections/ draw and util files
- The drawing code itself will be implemented separately by Julian
* Base / Object:
A little note about them. Original Blender code would try to keep them
in sync through the code, juggling flags back and forth. This will now
be handled by Depsgraph, keeping Object and Bases more separated
throughout the non-rendering code.
Scene.base is being cleared in doversion, and the old viewport drawing
code was poorly converted to use the new bases while the new viewport
code doesn't get merged and replace the old one.
Python API Changes
------------------
```
- scene.layers
+ # no longer exists
- scene.objects
+ scene.scene_layers.active.objects
- scene.objects.active
+ scene.render_layers.active.objects.active
- bpy.context.scene.objects.link()
+ bpy.context.scene_collection.objects.link()
- bpy_extras.object_utils.object_data_add(context, obdata, operator=None, use_active_layer=True, name=None)
+ bpy_extras.object_utils.object_data_add(context, obdata, operator=None, name=None)
- bpy.context.object.select
+ bpy.context.object.select = True
+ bpy.context.object.select = False
+ bpy.context.object.select_get()
+ bpy.context.object.select_set(action='SELECT')
+ bpy.context.object.select_set(action='DESELECT')
-AddObjectHelper.layers
+ # no longer exists
```
2017-02-07 10:18:38 +01:00
|
|
|
selection = [ob for ob in scene.objects if ob.select_get() and ob.type == 'MESH' and ob.name != source.name]
|
2014-01-18 09:13:51 +11:00
|
|
|
if selection:
|
2017-01-30 12:18:39 +09:00
|
|
|
# Compute the min/max distance from the reference to mesh vertices
|
2013-03-02 18:27:50 +00:00
|
|
|
min_dist = sys.float_info.max
|
2011-08-05 00:51:44 +00:00
|
|
|
max_dist = -min_dist
|
2017-01-30 12:18:39 +09:00
|
|
|
if m.type == 'DISTANCE_FROM_CAMERA':
|
|
|
|
for ob in selection:
|
|
|
|
ob_to_cam = matrix_to_camera * ob.matrix_world
|
|
|
|
for vert in ob.data.vertices:
|
|
|
|
# dist in the camera space
|
|
|
|
dist = (ob_to_cam * vert.co).length
|
|
|
|
min_dist = min(dist, min_dist)
|
|
|
|
max_dist = max(dist, max_dist)
|
|
|
|
elif m.type == 'DISTANCE_FROM_OBJECT':
|
|
|
|
for ob in selection:
|
|
|
|
for vert in ob.data.vertices:
|
|
|
|
# dist in the world space
|
|
|
|
dist = (ob.matrix_world * vert.co - target_location).length
|
|
|
|
min_dist = min(dist, min_dist)
|
|
|
|
max_dist = max(dist, max_dist)
|
2011-08-05 00:51:44 +00:00
|
|
|
# Fill the Range Min/Max entries with the computed distances
|
|
|
|
m.range_min = min_dist
|
|
|
|
m.range_max = max_dist
|
|
|
|
return {'FINISHED'}
|
2012-04-22 00:59:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SCENE_OT_freestyle_add_edge_marks_to_keying_set(bpy.types.Operator):
|
|
|
|
'''Add the data paths to the Freestyle Edge Mark property of selected edges to the active keying set'''
|
|
|
|
bl_idname = "scene.freestyle_add_edge_marks_to_keying_set"
|
|
|
|
bl_label = "Add Edge Marks to Keying Set"
|
|
|
|
bl_options = {'UNDO'}
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
|
|
|
ob = context.active_object
|
|
|
|
return (ob and ob.type == 'MESH')
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
# active keying set
|
|
|
|
scene = context.scene
|
|
|
|
ks = scene.keying_sets.active
|
|
|
|
if ks is None:
|
|
|
|
ks = scene.keying_sets.new(idname="FreestyleEdgeMarkKeyingSet", name="Freestyle Edge Mark Keying Set")
|
|
|
|
ks.bl_description = ""
|
|
|
|
# add data paths to the keying set
|
|
|
|
ob = context.active_object
|
2018-04-05 18:20:27 +02:00
|
|
|
ob_mode = ob.mode
|
2012-04-22 00:59:27 +00:00
|
|
|
mesh = ob.data
|
|
|
|
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
|
|
|
|
for i, edge in enumerate(mesh.edges):
|
|
|
|
if not edge.hide and edge.select:
|
2014-04-15 14:44:08 +09:00
|
|
|
path = 'edges[%d].use_freestyle_mark' % i
|
2012-04-22 00:59:27 +00:00
|
|
|
ks.paths.add(mesh, path, index=0)
|
|
|
|
bpy.ops.object.mode_set(mode=ob_mode, toggle=False)
|
|
|
|
return {'FINISHED'}
|
|
|
|
|
|
|
|
|
|
|
|
class SCENE_OT_freestyle_add_face_marks_to_keying_set(bpy.types.Operator):
|
|
|
|
'''Add the data paths to the Freestyle Face Mark property of selected polygons to the active keying set'''
|
|
|
|
bl_idname = "scene.freestyle_add_face_marks_to_keying_set"
|
|
|
|
bl_label = "Add Face Marks to Keying Set"
|
|
|
|
bl_options = {'UNDO'}
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
|
|
|
ob = context.active_object
|
|
|
|
return (ob and ob.type == 'MESH')
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
# active keying set
|
|
|
|
scene = context.scene
|
|
|
|
ks = scene.keying_sets.active
|
|
|
|
if ks is None:
|
|
|
|
ks = scene.keying_sets.new(idname="FreestyleFaceMarkKeyingSet", name="Freestyle Face Mark Keying Set")
|
|
|
|
ks.bl_description = ""
|
|
|
|
# add data paths to the keying set
|
|
|
|
ob = context.active_object
|
2018-04-05 18:20:27 +02:00
|
|
|
ob_mode = ob.mode
|
2012-04-22 00:59:27 +00:00
|
|
|
mesh = ob.data
|
|
|
|
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
|
|
|
|
for i, polygon in enumerate(mesh.polygons):
|
|
|
|
if not polygon.hide and polygon.select:
|
2014-04-15 14:44:08 +09:00
|
|
|
path = 'polygons[%d].use_freestyle_mark' % i
|
2012-04-22 00:59:27 +00:00
|
|
|
ks.paths.add(mesh, path, index=0)
|
|
|
|
bpy.ops.object.mode_set(mode=ob_mode, toggle=False)
|
|
|
|
return {'FINISHED'}
|
2013-06-01 22:37:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SCENE_OT_freestyle_module_open(bpy.types.Operator):
|
|
|
|
"""Open a style module file"""
|
|
|
|
bl_idname = "scene.freestyle_module_open"
|
|
|
|
bl_label = "Open Style Module File"
|
|
|
|
bl_options = {'INTERNAL'}
|
|
|
|
|
|
|
|
filepath = StringProperty(subtype='FILE_PATH')
|
|
|
|
|
|
|
|
make_internal = BoolProperty(
|
|
|
|
name="Make internal",
|
|
|
|
description="Make module file internal after loading",
|
|
|
|
default=True)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
2017-11-22 10:52:39 -02:00
|
|
|
view_layer = context.scene.view_layers.active
|
|
|
|
return view_layer and view_layer.freestyle_settings.mode == 'SCRIPT'
|
2013-06-01 22:37:15 +00:00
|
|
|
|
|
|
|
def invoke(self, context, event):
|
|
|
|
self.freestyle_module = context.freestyle_module
|
|
|
|
wm = context.window_manager
|
|
|
|
wm.fileselect_add(self)
|
|
|
|
return {'RUNNING_MODAL'}
|
|
|
|
|
|
|
|
def execute(self, context):
|
2013-06-02 17:52:06 +00:00
|
|
|
text = bpy.data.texts.load(self.filepath, self.make_internal)
|
2013-06-01 22:37:15 +00:00
|
|
|
self.freestyle_module.script = text
|
|
|
|
return {'FINISHED'}
|
2017-03-20 02:07:24 +11:00
|
|
|
|
|
|
|
|
|
|
|
classes = (
|
|
|
|
SCENE_OT_freestyle_add_edge_marks_to_keying_set,
|
|
|
|
SCENE_OT_freestyle_add_face_marks_to_keying_set,
|
|
|
|
SCENE_OT_freestyle_fill_range_by_selection,
|
|
|
|
SCENE_OT_freestyle_module_open,
|
|
|
|
)
|