2011-11-07 12:55:18 +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>
|
|
|
|
import bpy
|
|
|
|
import os
|
|
|
|
from bpy.types import Operator
|
2015-02-13 02:17:23 +11:00
|
|
|
from bpy.props import FloatProperty
|
2017-03-25 11:07:05 +11:00
|
|
|
from mathutils import (
|
|
|
|
Vector,
|
|
|
|
Matrix,
|
|
|
|
)
|
2011-11-23 17:30:47 +00:00
|
|
|
|
|
|
|
|
2012-01-05 16:57:15 +00:00
|
|
|
def CLIP_spaces_walk(context, all_screens, tarea, tspace, callback, *args):
|
2011-11-23 17:30:47 +00:00
|
|
|
screens = bpy.data.screens if all_screens else [context.screen]
|
|
|
|
|
|
|
|
for screen in screens:
|
|
|
|
for area in screen.areas:
|
|
|
|
if area.type == tarea:
|
|
|
|
for space in area.spaces:
|
|
|
|
if space.type == tspace:
|
|
|
|
callback(space, *args)
|
|
|
|
|
|
|
|
|
2018-08-15 16:10:09 -03:00
|
|
|
def CLIP_set_viewport_background(context, clip, clip_user):
|
|
|
|
def set_background(cam, clip, user):
|
2011-11-23 17:30:47 +00:00
|
|
|
bgpic = None
|
|
|
|
|
2018-08-15 16:10:09 -03:00
|
|
|
for x in cam.background_images:
|
2011-11-30 05:34:32 +00:00
|
|
|
if x.source == 'MOVIE_CLIP':
|
2011-11-23 17:30:47 +00:00
|
|
|
bgpic = x
|
|
|
|
break
|
|
|
|
|
|
|
|
if not bgpic:
|
2018-08-15 16:10:09 -03:00
|
|
|
bgpic = cam.background_images.new()
|
2011-11-23 17:30:47 +00:00
|
|
|
|
2011-11-30 05:34:32 +00:00
|
|
|
bgpic.source = 'MOVIE_CLIP'
|
2011-11-23 17:30:47 +00:00
|
|
|
bgpic.clip = clip
|
|
|
|
bgpic.clip_user.proxy_render_size = user.proxy_render_size
|
|
|
|
bgpic.clip_user.use_render_undistorted = True
|
|
|
|
bgpic.use_camera_clip = False
|
|
|
|
|
2018-08-15 16:10:09 -03:00
|
|
|
cam.show_background_images = True
|
2011-11-23 17:30:47 +00:00
|
|
|
|
2018-08-15 16:10:09 -03:00
|
|
|
scene_camera = context.scene.camera
|
|
|
|
if (not scene_camera) or (scene_camera.type != 'CAMERA'):
|
|
|
|
return
|
|
|
|
set_background(scene_camera.data, clip, clip_user)
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
2012-01-04 09:19:39 +00:00
|
|
|
def CLIP_camera_for_clip(context, clip):
|
|
|
|
scene = context.scene
|
|
|
|
camera = scene.camera
|
|
|
|
|
|
|
|
for ob in scene.objects:
|
|
|
|
if ob.type == 'CAMERA':
|
|
|
|
for con in ob.constraints:
|
|
|
|
if con.type == 'CAMERA_SOLVER':
|
2012-02-04 11:12:18 +00:00
|
|
|
cur_clip = scene.active_clip if con.use_active_clip else con.clip
|
2012-01-04 09:19:39 +00:00
|
|
|
|
|
|
|
if cur_clip == clip:
|
|
|
|
return ob
|
|
|
|
|
|
|
|
return camera
|
|
|
|
|
2012-01-17 17:57:20 +00:00
|
|
|
|
2011-11-15 12:20:58 +00:00
|
|
|
def CLIP_track_view_selected(sc, track):
|
|
|
|
if track.select_anchor:
|
|
|
|
return True
|
|
|
|
|
|
|
|
if sc.show_marker_pattern and track.select_pattern:
|
|
|
|
return True
|
|
|
|
|
|
|
|
if sc.show_marker_search and track.select_search:
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
2011-11-16 13:39:58 +00:00
|
|
|
|
2012-08-04 10:47:31 +00:00
|
|
|
def CLIP_default_settings_from_track(clip, track, framenr):
|
2012-01-26 15:04:25 +00:00
|
|
|
settings = clip.tracking.settings
|
|
|
|
|
|
|
|
width = clip.size[0]
|
|
|
|
height = clip.size[1]
|
|
|
|
|
2012-08-04 10:47:31 +00:00
|
|
|
marker = track.markers.find_frame(framenr, False)
|
|
|
|
pattern_bb = marker.pattern_bound_box
|
|
|
|
|
|
|
|
pattern = Vector(pattern_bb[1]) - Vector(pattern_bb[0])
|
|
|
|
search = marker.search_max - marker.search_min
|
2012-01-26 15:04:25 +00:00
|
|
|
|
2012-04-08 13:11:25 +00:00
|
|
|
pattern[0] = pattern[0] * width
|
|
|
|
pattern[1] = pattern[1] * height
|
2012-01-26 15:04:25 +00:00
|
|
|
|
2012-04-08 13:11:25 +00:00
|
|
|
search[0] = search[0] * width
|
|
|
|
search[1] = search[1] * height
|
2012-01-26 15:04:25 +00:00
|
|
|
|
|
|
|
settings.default_correlation_min = track.correlation_min
|
|
|
|
settings.default_pattern_size = max(pattern[0], pattern[1])
|
|
|
|
settings.default_search_size = max(search[0], search[1])
|
|
|
|
settings.default_frames_limit = track.frames_limit
|
|
|
|
settings.default_pattern_match = track.pattern_match
|
|
|
|
settings.default_margin = track.margin
|
2012-08-04 10:47:31 +00:00
|
|
|
settings.default_motion_model = track.motion_model
|
|
|
|
settings.use_default_brute = track.use_brute
|
|
|
|
settings.use_default_normalization = track.use_normalization
|
|
|
|
settings.use_default_mask = track.use_mask
|
2012-01-26 15:33:16 +00:00
|
|
|
settings.use_default_red_channel = track.use_red_channel
|
|
|
|
settings.use_default_green_channel = track.use_green_channel
|
|
|
|
settings.use_default_blue_channel = track.use_blue_channel
|
2014-02-19 18:58:37 +06:00
|
|
|
settings.default_weight = track.weight
|
2012-01-26 15:04:25 +00:00
|
|
|
|
|
|
|
|
2015-02-13 02:17:23 +11:00
|
|
|
class CLIP_OT_filter_tracks(bpy.types.Operator):
|
2015-02-16 17:14:29 +05:00
|
|
|
"""Filter tracks which has weirdly looking spikes in motion curves"""
|
2015-02-13 02:17:23 +11:00
|
|
|
bl_label = "Filter Tracks"
|
|
|
|
bl_idname = "clip.filter_tracks"
|
|
|
|
bl_options = {'UNDO', 'REGISTER'}
|
|
|
|
|
2018-07-11 22:18:09 +02:00
|
|
|
track_threshold: FloatProperty(
|
2018-06-26 19:41:37 +02:00
|
|
|
name="Track Threshold",
|
|
|
|
description="Filter Threshold to select problematic tracks",
|
|
|
|
default=5.0,
|
|
|
|
)
|
2015-02-13 02:17:23 +11:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _filter_values(context, threshold):
|
|
|
|
|
|
|
|
def get_marker_coordinates_in_pixels(clip_size, track, frame_number):
|
|
|
|
marker = track.markers.find_frame(frame_number)
|
|
|
|
return Vector((marker.co[0] * clip_size[0], marker.co[1] * clip_size[1]))
|
|
|
|
|
|
|
|
def marker_velocity(clip_size, track, frame):
|
|
|
|
marker_a = get_marker_coordinates_in_pixels(clip_size, track, frame)
|
|
|
|
marker_b = get_marker_coordinates_in_pixels(clip_size, track, frame - 1)
|
|
|
|
return marker_a - marker_b
|
|
|
|
|
|
|
|
scene = context.scene
|
|
|
|
frame_start = scene.frame_start
|
|
|
|
frame_end = scene.frame_end
|
|
|
|
clip = context.space_data.clip
|
|
|
|
clip_size = clip.size[:]
|
|
|
|
|
|
|
|
bpy.ops.clip.clean_tracks(frames=10, action='DELETE_TRACK')
|
|
|
|
|
|
|
|
tracks_to_clean = set()
|
|
|
|
|
|
|
|
for frame in range(frame_start, frame_end + 1):
|
|
|
|
|
|
|
|
# Find tracks with markers in both this frame and the previous one.
|
|
|
|
relevant_tracks = [
|
2018-06-26 19:41:37 +02:00
|
|
|
track for track in clip.tracking.tracks
|
|
|
|
if (track.markers.find_frame(frame) and
|
|
|
|
track.markers.find_frame(frame - 1))
|
|
|
|
]
|
2015-02-13 02:17:23 +11:00
|
|
|
|
|
|
|
if not relevant_tracks:
|
|
|
|
continue
|
|
|
|
|
|
|
|
# Get average velocity and deselect track.
|
|
|
|
average_velocity = Vector((0.0, 0.0))
|
|
|
|
for track in relevant_tracks:
|
|
|
|
track.select = False
|
|
|
|
average_velocity += marker_velocity(clip_size, track, frame)
|
|
|
|
if len(relevant_tracks) >= 1:
|
|
|
|
average_velocity = average_velocity / len(relevant_tracks)
|
|
|
|
|
|
|
|
# Then find all markers that behave differently than the average.
|
|
|
|
for track in relevant_tracks:
|
|
|
|
track_velocity = marker_velocity(clip_size, track, frame)
|
|
|
|
distance = (average_velocity - track_velocity).length
|
|
|
|
|
|
|
|
if distance > threshold:
|
|
|
|
tracks_to_clean.add(track)
|
|
|
|
|
|
|
|
for track in tracks_to_clean:
|
|
|
|
track.select = True
|
|
|
|
return len(tracks_to_clean)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
|
|
|
space = context.space_data
|
|
|
|
return (space.type == 'CLIP_EDITOR') and space.clip
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
num_tracks = self._filter_values(context, self.track_threshold)
|
|
|
|
self.report({'INFO'}, "Identified %d problematic tracks" % num_tracks)
|
|
|
|
return {'FINISHED'}
|
|
|
|
|
|
|
|
|
|
|
|
class CLIP_OT_set_active_clip(bpy.types.Operator):
|
|
|
|
bl_label = "Set Active Clip"
|
|
|
|
bl_idname = "clip.set_active_clip"
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
|
|
|
space = context.space_data
|
2017-08-14 11:46:00 +02:00
|
|
|
return space.type == 'CLIP_EDITOR' and space.clip
|
2015-02-13 02:17:23 +11:00
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
clip = context.space_data.clip
|
|
|
|
scene = context.scene
|
|
|
|
scene.active_clip = clip
|
|
|
|
scene.render.resolution_x = clip.size[0]
|
|
|
|
scene.render.resolution_y = clip.size[1]
|
|
|
|
return {'FINISHED'}
|
|
|
|
|
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
class CLIP_OT_track_to_empty(Operator):
|
|
|
|
"""Create an Empty object which will be copying movement of active track"""
|
|
|
|
|
|
|
|
bl_idname = "clip.track_to_empty"
|
2011-11-15 12:20:58 +00:00
|
|
|
bl_label = "Link Empty to Track"
|
2011-11-07 12:55:18 +00:00
|
|
|
bl_options = {'UNDO', 'REGISTER'}
|
|
|
|
|
2015-06-07 17:40:39 +10:00
|
|
|
@staticmethod
|
|
|
|
def _link_track(context, clip, tracking_object, track):
|
2011-11-07 12:55:18 +00:00
|
|
|
sc = context.space_data
|
|
|
|
constraint = None
|
|
|
|
ob = None
|
|
|
|
|
|
|
|
ob = bpy.data.objects.new(name=track.name, object_data=None)
|
2018-08-15 16:10:09 -03:00
|
|
|
context.collection.objects.link(ob)
|
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
|
|
|
ob.select_set(action='SELECT')
|
2018-07-24 11:18:45 +02:00
|
|
|
context.view_layer.objects.active = ob
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
for con in ob.constraints:
|
|
|
|
if con.type == 'FOLLOW_TRACK':
|
|
|
|
constraint = con
|
|
|
|
break
|
|
|
|
|
|
|
|
if constraint is None:
|
|
|
|
constraint = ob.constraints.new(type='FOLLOW_TRACK')
|
|
|
|
|
2012-02-09 10:24:44 +00:00
|
|
|
constraint.use_active_clip = False
|
2011-11-07 12:55:18 +00:00
|
|
|
constraint.clip = sc.clip
|
|
|
|
constraint.track = track.name
|
2011-11-14 06:41:42 +00:00
|
|
|
constraint.use_3d_position = False
|
2012-01-04 09:19:39 +00:00
|
|
|
constraint.object = tracking_object.name
|
2012-01-17 17:57:20 +00:00
|
|
|
constraint.camera = CLIP_camera_for_clip(context, clip)
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2017-08-14 11:46:00 +02:00
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
|
|
|
space = context.space_data
|
|
|
|
return space.type == 'CLIP_EDITOR' and space.clip
|
|
|
|
|
2011-11-15 12:20:58 +00:00
|
|
|
def execute(self, context):
|
|
|
|
sc = context.space_data
|
|
|
|
clip = sc.clip
|
2012-01-04 09:19:39 +00:00
|
|
|
tracking_object = clip.tracking.objects.active
|
2011-11-15 12:20:58 +00:00
|
|
|
|
2012-01-04 09:19:39 +00:00
|
|
|
for track in tracking_object.tracks:
|
2011-11-15 12:20:58 +00:00
|
|
|
if CLIP_track_view_selected(sc, track):
|
2012-01-17 17:57:20 +00:00
|
|
|
self._link_track(context, clip, tracking_object, track)
|
2011-11-15 12:20:58 +00:00
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
return {'FINISHED'}
|
|
|
|
|
|
|
|
|
2011-11-21 17:05:27 +00:00
|
|
|
class CLIP_OT_bundles_to_mesh(Operator):
|
|
|
|
"""Create vertex cloud using coordinates of reconstructed tracks"""
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2011-11-21 17:05:27 +00:00
|
|
|
bl_idname = "clip.bundles_to_mesh"
|
|
|
|
bl_label = "3D Markers to Mesh"
|
2011-11-07 12:55:18 +00:00
|
|
|
bl_options = {'UNDO', 'REGISTER'}
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
|
|
|
sc = context.space_data
|
2011-11-16 16:38:37 +00:00
|
|
|
return (sc.type == 'CLIP_EDITOR') and sc.clip
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
def execute(self, context):
|
2011-11-24 21:59:43 +00:00
|
|
|
from bpy_extras.io_utils import unpack_list
|
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
sc = context.space_data
|
|
|
|
clip = sc.clip
|
2012-01-04 09:19:39 +00:00
|
|
|
tracking_object = clip.tracking.objects.active
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
new_verts = []
|
|
|
|
|
2014-02-26 19:40:04 +06:00
|
|
|
scene = context.scene
|
|
|
|
camera = scene.camera
|
|
|
|
matrix = Matrix.Identity(4)
|
|
|
|
if camera:
|
|
|
|
reconstruction = tracking_object.reconstruction
|
|
|
|
framenr = scene.frame_current - clip.frame_start + 1
|
2014-02-27 08:38:14 +11:00
|
|
|
reconstructed_matrix = reconstruction.cameras.matrix_from_frame(framenr)
|
2018-08-12 15:01:26 +10:00
|
|
|
matrix = camera.matrix_world @ reconstructed_matrix.inverted()
|
2014-02-26 19:40:04 +06:00
|
|
|
|
2012-01-04 09:19:39 +00:00
|
|
|
for track in tracking_object.tracks:
|
2018-03-22 09:31:33 +01:00
|
|
|
if track.has_bundle and track.select:
|
2011-11-07 12:55:18 +00:00
|
|
|
new_verts.append(track.bundle)
|
|
|
|
|
|
|
|
if new_verts:
|
2018-03-21 12:30:50 +01:00
|
|
|
mesh = bpy.data.meshes.new(name="Tracks")
|
2011-11-07 12:55:18 +00:00
|
|
|
mesh.vertices.add(len(new_verts))
|
|
|
|
mesh.vertices.foreach_set("co", unpack_list(new_verts))
|
2018-03-21 12:30:50 +01:00
|
|
|
ob = bpy.data.objects.new(name="Tracks", object_data=mesh)
|
|
|
|
ob.matrix_world = matrix
|
2018-08-15 16:10:09 -03:00
|
|
|
context.collection.objects.link(ob)
|
|
|
|
ob.select_set('SELECT')
|
2018-07-24 11:18:45 +02:00
|
|
|
context.view_layer.objects.active = ob
|
2018-03-21 12:30:50 +01:00
|
|
|
else:
|
|
|
|
self.report({'WARNING'}, "No usable tracks selected")
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
return {'FINISHED'}
|
|
|
|
|
|
|
|
|
|
|
|
class CLIP_OT_delete_proxy(Operator):
|
|
|
|
"""Delete movie clip proxy files from the hard drive"""
|
|
|
|
|
|
|
|
bl_idname = "clip.delete_proxy"
|
|
|
|
bl_label = "Delete Proxy"
|
2011-11-19 20:14:57 +00:00
|
|
|
bl_options = {'REGISTER'}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
2011-11-16 11:52:31 +00:00
|
|
|
if context.space_data.type != 'CLIP_EDITOR':
|
|
|
|
return False
|
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
sc = context.space_data
|
|
|
|
|
|
|
|
return sc.clip
|
|
|
|
|
|
|
|
def invoke(self, context, event):
|
|
|
|
wm = context.window_manager
|
|
|
|
|
|
|
|
return wm.invoke_confirm(self, event)
|
|
|
|
|
2015-06-07 17:40:39 +10:00
|
|
|
@staticmethod
|
|
|
|
def _rmproxy(abspath):
|
2011-11-24 21:59:43 +00:00
|
|
|
import shutil
|
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
if not os.path.exists(abspath):
|
|
|
|
return
|
|
|
|
|
|
|
|
if os.path.isdir(abspath):
|
|
|
|
shutil.rmtree(abspath)
|
|
|
|
else:
|
|
|
|
os.remove(abspath)
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
sc = context.space_data
|
|
|
|
clip = sc.clip
|
|
|
|
if clip.use_proxy_custom_directory:
|
|
|
|
proxydir = clip.proxy.directory
|
|
|
|
else:
|
|
|
|
clipdir = os.path.dirname(clip.filepath)
|
2011-12-22 03:56:21 +00:00
|
|
|
proxydir = os.path.join(clipdir, "BL_proxy")
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
clipfile = os.path.basename(clip.filepath)
|
|
|
|
proxy = os.path.join(proxydir, clipfile)
|
|
|
|
absproxy = bpy.path.abspath(proxy)
|
|
|
|
|
2018-08-21 11:29:28 -03:00
|
|
|
# proxy_<quality>[_undistorted]
|
2011-11-07 12:55:18 +00:00
|
|
|
for x in (25, 50, 75, 100):
|
2011-12-22 03:56:21 +00:00
|
|
|
d = os.path.join(absproxy, "proxy_%d" % x)
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
self._rmproxy(d)
|
2011-12-22 03:56:21 +00:00
|
|
|
self._rmproxy(d + "_undistorted")
|
|
|
|
self._rmproxy(os.path.join(absproxy, "proxy_%d.avi" % x))
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2011-12-22 03:56:21 +00:00
|
|
|
tc = ("free_run.blen_tc",
|
|
|
|
"interp_free_run.blen_tc",
|
|
|
|
"record_run.blen_tc")
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
for x in tc:
|
|
|
|
self._rmproxy(os.path.join(absproxy, x))
|
|
|
|
|
2018-08-21 11:29:28 -03:00
|
|
|
# Remove proxy per-clip directory.
|
2011-11-07 12:55:18 +00:00
|
|
|
try:
|
|
|
|
os.rmdir(absproxy)
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
2018-08-21 11:29:28 -03:00
|
|
|
# Remove [custom] proxy directory if empty.
|
2011-11-07 12:55:18 +00:00
|
|
|
try:
|
|
|
|
absdir = bpy.path.abspath(proxydir)
|
|
|
|
os.rmdir(absdir)
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
return {'FINISHED'}
|
|
|
|
|
|
|
|
|
|
|
|
class CLIP_OT_set_viewport_background(Operator):
|
2012-02-08 04:37:37 +00:00
|
|
|
"""Set current movie clip as a camera background in 3D view-port """ \
|
2018-06-26 19:41:37 +02:00
|
|
|
"""(works only when a 3D view-port is visible)"""
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
bl_idname = "clip.set_viewport_background"
|
|
|
|
bl_label = "Set as Background"
|
2011-11-19 20:14:57 +00:00
|
|
|
bl_options = {'REGISTER'}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
|
|
|
if context.space_data.type != 'CLIP_EDITOR':
|
|
|
|
return False
|
|
|
|
|
|
|
|
sc = context.space_data
|
|
|
|
|
|
|
|
return sc.clip
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
sc = context.space_data
|
2018-08-15 16:10:09 -03:00
|
|
|
CLIP_set_viewport_background(context, sc.clip, sc.clip_user)
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
return {'FINISHED'}
|
|
|
|
|
|
|
|
|
|
|
|
class CLIP_OT_constraint_to_fcurve(Operator):
|
2018-08-21 11:29:28 -03:00
|
|
|
"""Create F-Curves for object which will copy """ \
|
|
|
|
"""object's movement caused by this constraint"""
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
bl_idname = "clip.constraint_to_fcurve"
|
|
|
|
bl_label = "Constraint to F-Curve"
|
|
|
|
bl_options = {'UNDO', 'REGISTER'}
|
|
|
|
|
|
|
|
def _bake_object(self, scene, ob):
|
|
|
|
con = None
|
|
|
|
clip = None
|
|
|
|
sfra = None
|
|
|
|
efra = None
|
|
|
|
frame_current = scene.frame_current
|
|
|
|
matrices = []
|
|
|
|
|
2012-02-08 04:37:37 +00:00
|
|
|
# Find constraint which would be converting
|
2011-11-07 12:55:18 +00:00
|
|
|
# TODO: several camera solvers and track followers would fail,
|
2012-02-08 04:37:37 +00:00
|
|
|
# but can't think about real work-flow where it'll be useful
|
2011-11-07 12:55:18 +00:00
|
|
|
for x in ob.constraints:
|
2012-01-04 08:43:28 +00:00
|
|
|
if x.type in {'CAMERA_SOLVER', 'FOLLOW_TRACK', 'OBJECT_SOLVER'}:
|
2011-11-07 12:55:18 +00:00
|
|
|
con = x
|
|
|
|
|
|
|
|
if not con:
|
2011-11-20 11:44:32 +00:00
|
|
|
self.report({'ERROR'},
|
2012-10-08 08:28:05 +00:00
|
|
|
"Motion Tracking constraint to be converted not found")
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2011-11-20 11:44:32 +00:00
|
|
|
return {'CANCELLED'}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2018-08-21 11:29:28 -03:00
|
|
|
# Get clip used for parenting.
|
2011-11-07 12:55:18 +00:00
|
|
|
if con.use_active_clip:
|
|
|
|
clip = scene.active_clip
|
|
|
|
else:
|
|
|
|
clip = con.clip
|
|
|
|
|
|
|
|
if not clip:
|
2011-11-20 11:44:32 +00:00
|
|
|
self.report({'ERROR'},
|
2012-10-08 08:28:05 +00:00
|
|
|
"Movie clip to use tracking data from isn't set")
|
2011-11-20 11:44:32 +00:00
|
|
|
|
|
|
|
return {'CANCELLED'}
|
|
|
|
|
|
|
|
if con.type == 'FOLLOW_TRACK' and con.use_3d_position:
|
|
|
|
mat = ob.matrix_world.copy()
|
|
|
|
ob.constraints.remove(con)
|
|
|
|
ob.matrix_world = mat
|
|
|
|
|
|
|
|
return {'FINISHED'}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2018-08-21 11:29:28 -03:00
|
|
|
# Find start and end frames.
|
2011-11-07 12:55:18 +00:00
|
|
|
for track in clip.tracking.tracks:
|
|
|
|
if sfra is None:
|
|
|
|
sfra = track.markers[0].frame
|
|
|
|
else:
|
|
|
|
sfra = min(sfra, track.markers[0].frame)
|
|
|
|
|
|
|
|
if efra is None:
|
|
|
|
efra = track.markers[-1].frame
|
|
|
|
else:
|
|
|
|
efra = max(efra, track.markers[-1].frame)
|
|
|
|
|
|
|
|
if sfra is None or efra is None:
|
2011-11-08 01:32:34 +00:00
|
|
|
return
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2018-08-21 11:29:28 -03:00
|
|
|
# Store object matrices.
|
2011-11-08 01:32:34 +00:00
|
|
|
for x in range(sfra, efra + 1):
|
2011-11-07 12:55:18 +00:00
|
|
|
scene.frame_set(x)
|
|
|
|
matrices.append(ob.matrix_world.copy())
|
|
|
|
|
|
|
|
ob.animation_data_create()
|
|
|
|
|
2018-08-21 11:29:28 -03:00
|
|
|
# Apply matrices on object and insert key-frames.
|
2011-11-07 12:55:18 +00:00
|
|
|
i = 0
|
2011-11-08 01:32:34 +00:00
|
|
|
for x in range(sfra, efra + 1):
|
2011-11-07 12:55:18 +00:00
|
|
|
scene.frame_set(x)
|
|
|
|
ob.matrix_world = matrices[i]
|
|
|
|
|
|
|
|
ob.keyframe_insert("location")
|
|
|
|
|
|
|
|
if ob.rotation_mode == 'QUATERNION':
|
|
|
|
ob.keyframe_insert("rotation_quaternion")
|
|
|
|
else:
|
|
|
|
ob.keyframe_insert("rotation_euler")
|
|
|
|
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
ob.constraints.remove(con)
|
|
|
|
|
|
|
|
scene.frame_set(frame_current)
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
scene = context.scene
|
2011-12-22 03:56:21 +00:00
|
|
|
# XXX, should probably use context.selected_editable_objects
|
|
|
|
# since selected objects can be from a lib or in hidden layer!
|
2011-11-07 12:55:18 +00:00
|
|
|
for ob in scene.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
|
|
|
if ob.select_set(action='SELECT'):
|
2011-11-07 12:55:18 +00:00
|
|
|
self._bake_object(scene, ob)
|
|
|
|
|
|
|
|
return {'FINISHED'}
|
2011-11-23 17:30:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CLIP_OT_setup_tracking_scene(Operator):
|
|
|
|
"""Prepare scene for compositing 3D objects into this footage"""
|
2018-08-21 11:30:15 -03:00
|
|
|
# TODO: it will be great to integrate with other engines (other than Cycles)
|
2011-11-23 17:30:47 +00:00
|
|
|
|
|
|
|
bl_idname = "clip.setup_tracking_scene"
|
|
|
|
bl_label = "Setup Tracking Scene"
|
|
|
|
bl_options = {'UNDO', 'REGISTER'}
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
|
|
|
sc = context.space_data
|
|
|
|
|
|
|
|
if sc.type != 'CLIP_EDITOR':
|
|
|
|
return False
|
|
|
|
|
|
|
|
clip = sc.clip
|
|
|
|
|
|
|
|
return clip and clip.tracking.reconstruction.is_valid
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _setupScene(context):
|
|
|
|
scene = context.scene
|
|
|
|
scene.active_clip = context.space_data.clip
|
2018-08-21 11:30:15 -03:00
|
|
|
scene.render.use_motion_blur = True
|
2011-11-23 17:30:47 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _setupWorld(context):
|
|
|
|
scene = context.scene
|
|
|
|
world = scene.world
|
|
|
|
|
|
|
|
if not world:
|
|
|
|
world = bpy.data.worlds.new(name="World")
|
|
|
|
scene.world = world
|
|
|
|
|
2018-08-21 11:30:15 -03:00
|
|
|
# Having AO enabled is nice for shadow catcher.
|
2011-11-23 17:30:47 +00:00
|
|
|
world.light_settings.use_ambient_occlusion = True
|
|
|
|
world.light_settings.distance = 1.0
|
2015-04-22 16:26:00 +10:00
|
|
|
if hasattr(scene, "cycles"):
|
|
|
|
world.light_settings.ao_factor = 0.05
|
2011-11-23 17:30:47 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _findOrCreateCamera(context):
|
|
|
|
scene = context.scene
|
|
|
|
|
|
|
|
if scene.camera:
|
|
|
|
return scene.camera
|
|
|
|
|
|
|
|
cam = bpy.data.cameras.new(name="Camera")
|
|
|
|
camob = bpy.data.objects.new(name="Camera", object_data=cam)
|
2018-08-21 11:30:15 -03:00
|
|
|
scene.collection.objects.link(camob)
|
2011-11-23 17:30:47 +00:00
|
|
|
|
|
|
|
scene.camera = camob
|
|
|
|
|
2018-08-12 15:01:26 +10:00
|
|
|
camob.matrix_local = (
|
|
|
|
Matrix.Translation((7.481, -6.508, 5.344)) @
|
|
|
|
Matrix.Rotation(0.815, 4, 'Z') @
|
|
|
|
Matrix.Rotation(0.011, 4, 'Y') @
|
|
|
|
Matrix.Rotation(1.109, 4, 'X')
|
|
|
|
)
|
2011-11-23 17:30:47 +00:00
|
|
|
|
|
|
|
return camob
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _setupCamera(context):
|
2011-12-11 15:48:15 +00:00
|
|
|
sc = context.space_data
|
|
|
|
clip = sc.clip
|
|
|
|
tracking = clip.tracking
|
|
|
|
|
2011-11-23 17:30:47 +00:00
|
|
|
camob = CLIP_OT_setup_tracking_scene._findOrCreateCamera(context)
|
2011-12-11 15:48:15 +00:00
|
|
|
cam = camob.data
|
2011-11-23 17:30:47 +00:00
|
|
|
|
2018-08-21 11:30:15 -03:00
|
|
|
# Remove all constraints to be sure motion is fine.
|
2011-11-23 17:30:47 +00:00
|
|
|
camob.constraints.clear()
|
|
|
|
|
2018-08-21 11:30:15 -03:00
|
|
|
# Append camera solver constraint.
|
2011-11-23 17:30:47 +00:00
|
|
|
con = camob.constraints.new(type='CAMERA_SOLVER')
|
|
|
|
con.use_active_clip = True
|
|
|
|
con.influence = 1.0
|
|
|
|
|
2011-12-11 15:48:15 +00:00
|
|
|
cam.sensor_width = tracking.camera.sensor_width
|
|
|
|
cam.lens = tracking.camera.focal_length
|
|
|
|
|
2011-11-23 17:30:47 +00:00
|
|
|
@staticmethod
|
|
|
|
def _setupViewport(context):
|
|
|
|
sc = context.space_data
|
2018-08-15 16:10:09 -03:00
|
|
|
CLIP_set_viewport_background(context, sc.clip, sc.clip_user)
|
2011-11-23 17:30:47 +00:00
|
|
|
|
|
|
|
@staticmethod
|
2017-11-22 10:52:39 -02:00
|
|
|
def _setupViewLayers(context):
|
2011-11-23 17:30:47 +00:00
|
|
|
scene = context.scene
|
2017-11-22 10:52:39 -02:00
|
|
|
view_layers = scene.view_layers
|
2011-11-23 17:30:47 +00:00
|
|
|
|
2017-11-22 10:52:39 -02:00
|
|
|
if not view_layers.get("Foreground"):
|
|
|
|
if len(view_layers) == 1:
|
|
|
|
fg = view_layers[0]
|
2011-11-23 17:30:47 +00:00
|
|
|
fg.name = 'Foreground'
|
|
|
|
else:
|
2017-11-22 10:52:39 -02:00
|
|
|
fg = view_layers.new("Foreground")
|
2011-11-23 17:30:47 +00:00
|
|
|
|
2014-09-11 20:00:24 +06:00
|
|
|
fg.use_sky = True
|
2011-11-23 17:30:47 +00:00
|
|
|
|
2017-11-22 10:52:39 -02:00
|
|
|
if not view_layers.get("Background"):
|
|
|
|
bg = view_layers.new("Background")
|
2018-08-21 11:30:15 -03:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def createCollection(context, collection_name):
|
|
|
|
def collection_in_collection(collection, collection_to_query):
|
|
|
|
"""Return true if collection is in any of the children or """
|
|
|
|
"""grandchildren of collection_to_query"""
|
|
|
|
for child in collection_to_query.children:
|
|
|
|
if collection == child:
|
|
|
|
return True
|
|
|
|
|
|
|
|
if collection_in_collection(collection, child):
|
|
|
|
return True
|
|
|
|
|
|
|
|
master_collection = context.scene.collection
|
|
|
|
collection = bpy.data.collections.get(collection_name)
|
|
|
|
|
|
|
|
if collection.library:
|
|
|
|
# We need a local collection instead.
|
|
|
|
collection = None
|
|
|
|
|
|
|
|
if not collection:
|
|
|
|
collection = bpy.data.collections.new(name=collection_name)
|
|
|
|
master_collection.children.link(collection)
|
|
|
|
else:
|
|
|
|
# see if collection is in the scene
|
|
|
|
if not collection_in_collection(collection, master_collection):
|
|
|
|
master_collection.children.link(collection)
|
|
|
|
|
|
|
|
def _setupCollections(self, context):
|
|
|
|
def setup_collection_recursively(collections, collection_name, attr_name):
|
|
|
|
for collection in collections:
|
|
|
|
if collection.collection.name == collection_name:
|
|
|
|
setattr(collection, attr_name, True)
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
setup_collection_recursively(collection.children, collection_name, attr_name)
|
|
|
|
|
|
|
|
collection = context.collection
|
|
|
|
collections = context.scene.collection.children
|
|
|
|
vlayers = context.scene.view_layers
|
|
|
|
|
|
|
|
if len(collections) == 1:
|
|
|
|
collections[0].name = "foreground"
|
|
|
|
|
|
|
|
self.createCollection(context, "foreground")
|
|
|
|
self.createCollection(context, "background")
|
|
|
|
|
|
|
|
# rendersettings
|
|
|
|
setup_collection_recursively(
|
|
|
|
vlayers["Foreground"].collections[0].children,
|
|
|
|
"background",
|
|
|
|
"holdout")
|
|
|
|
|
|
|
|
setup_collection_recursively(
|
|
|
|
vlayers["Background"].collections[0].children,
|
|
|
|
"foreground",
|
|
|
|
"indirect_only")
|
2011-11-23 17:30:47 +00:00
|
|
|
|
2014-06-02 13:12:01 +06:00
|
|
|
@staticmethod
|
|
|
|
def _wipeDefaultNodes(tree):
|
|
|
|
if len(tree.nodes) != 2:
|
|
|
|
return False
|
|
|
|
types = [node.type for node in tree.nodes]
|
|
|
|
types.sort()
|
|
|
|
|
|
|
|
if types[0] == 'COMPOSITE' and types[1] == 'R_LAYERS':
|
|
|
|
while tree.nodes:
|
|
|
|
tree.nodes.remove(tree.nodes[0])
|
|
|
|
|
2011-11-23 17:30:47 +00:00
|
|
|
@staticmethod
|
|
|
|
def _findNode(tree, type):
|
|
|
|
for node in tree.nodes:
|
|
|
|
if node.type == type:
|
|
|
|
return node
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _findOrCreateNode(tree, type):
|
|
|
|
node = CLIP_OT_setup_tracking_scene._findNode(tree, type)
|
|
|
|
|
|
|
|
if not node:
|
|
|
|
node = tree.nodes.new(type=type)
|
|
|
|
|
|
|
|
return node
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _needSetupNodes(context):
|
|
|
|
scene = context.scene
|
|
|
|
tree = scene.node_tree
|
|
|
|
|
|
|
|
if not tree:
|
|
|
|
# No compositor node tree found, time to create it!
|
|
|
|
return True
|
|
|
|
|
|
|
|
for node in tree.nodes:
|
|
|
|
if node.type in {'MOVIECLIP', 'MOVIEDISTORTION'}:
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _offsetNodes(tree):
|
|
|
|
for a in tree.nodes:
|
|
|
|
for b in tree.nodes:
|
|
|
|
if a != b and a.location == b.location:
|
|
|
|
b.location += Vector((40.0, 20.0))
|
|
|
|
|
|
|
|
def _setupNodes(self, context):
|
|
|
|
if not self._needSetupNodes(context):
|
2018-08-21 11:30:15 -03:00
|
|
|
# Compositor nodes were already setup or even changes already
|
|
|
|
# do nothing to prevent nodes damage.
|
2011-11-23 17:30:47 +00:00
|
|
|
return
|
|
|
|
|
2018-08-21 11:30:15 -03:00
|
|
|
# Enable backdrop for all compositor spaces.
|
2011-11-23 17:30:47 +00:00
|
|
|
def setup_space(space):
|
|
|
|
space.show_backdrop = True
|
|
|
|
|
2012-01-05 16:57:15 +00:00
|
|
|
CLIP_spaces_walk(context, True, 'NODE_EDITOR', 'NODE_EDITOR',
|
2012-07-04 21:41:05 +00:00
|
|
|
setup_space)
|
2011-11-23 17:30:47 +00:00
|
|
|
|
|
|
|
sc = context.space_data
|
|
|
|
scene = context.scene
|
|
|
|
scene.use_nodes = True
|
|
|
|
tree = scene.node_tree
|
|
|
|
clip = sc.clip
|
|
|
|
|
|
|
|
need_stabilization = False
|
|
|
|
|
2014-06-02 13:12:01 +06:00
|
|
|
# Remove all the nodes if they came from default node setup.
|
2018-08-21 11:30:15 -03:00
|
|
|
# This is simplest way to make it so final node setup is correct.
|
2014-06-02 13:12:01 +06:00
|
|
|
self._wipeDefaultNodes(tree)
|
|
|
|
|
2018-08-21 11:30:15 -03:00
|
|
|
# Create nodes.
|
2013-04-11 13:25:05 +00:00
|
|
|
rlayer_fg = self._findOrCreateNode(tree, 'CompositorNodeRLayers')
|
|
|
|
rlayer_bg = tree.nodes.new(type='CompositorNodeRLayers')
|
|
|
|
composite = self._findOrCreateNode(tree, 'CompositorNodeComposite')
|
2011-11-23 17:30:47 +00:00
|
|
|
|
2013-04-11 13:25:05 +00:00
|
|
|
movieclip = tree.nodes.new(type='CompositorNodeMovieClip')
|
|
|
|
distortion = tree.nodes.new(type='CompositorNodeMovieDistortion')
|
2011-11-23 17:30:47 +00:00
|
|
|
|
|
|
|
if need_stabilization:
|
2013-04-11 13:25:05 +00:00
|
|
|
stabilize = tree.nodes.new(type='CompositorNodeStabilize2D')
|
|
|
|
|
|
|
|
scale = tree.nodes.new(type='CompositorNodeScale')
|
2018-08-21 11:30:15 -03:00
|
|
|
shadowcatcher = tree.nodes.new(type='CompositorNodeAlphaOver')
|
2013-04-11 13:25:05 +00:00
|
|
|
alphaover = tree.nodes.new(type='CompositorNodeAlphaOver')
|
|
|
|
viewer = tree.nodes.new(type='CompositorNodeViewer')
|
2011-11-23 17:30:47 +00:00
|
|
|
|
2018-08-21 11:30:15 -03:00
|
|
|
# Setup nodes.
|
2011-11-23 17:30:47 +00:00
|
|
|
movieclip.clip = clip
|
|
|
|
|
|
|
|
distortion.clip = clip
|
|
|
|
distortion.distortion_type = 'UNDISTORT'
|
|
|
|
|
|
|
|
if need_stabilization:
|
|
|
|
stabilize.clip = clip
|
|
|
|
|
|
|
|
scale.space = 'RENDER_SIZE'
|
|
|
|
|
|
|
|
rlayer_bg.scene = scene
|
|
|
|
rlayer_bg.layer = "Background"
|
|
|
|
|
|
|
|
rlayer_fg.scene = scene
|
|
|
|
rlayer_fg.layer = "Foreground"
|
|
|
|
|
2018-08-21 11:30:15 -03:00
|
|
|
# Create links.
|
2012-07-04 21:41:05 +00:00
|
|
|
tree.links.new(movieclip.outputs["Image"], distortion.inputs["Image"])
|
2011-11-23 17:30:47 +00:00
|
|
|
|
|
|
|
if need_stabilization:
|
2012-07-04 21:41:05 +00:00
|
|
|
tree.links.new(distortion.outputs["Image"],
|
2012-10-08 08:28:05 +00:00
|
|
|
stabilize.inputs["Image"])
|
2012-07-04 21:41:05 +00:00
|
|
|
tree.links.new(stabilize.outputs["Image"], scale.inputs["Image"])
|
2011-11-23 17:30:47 +00:00
|
|
|
else:
|
2012-07-04 21:41:05 +00:00
|
|
|
tree.links.new(distortion.outputs["Image"], scale.inputs["Image"])
|
2011-11-23 17:30:47 +00:00
|
|
|
|
2018-08-21 11:30:15 -03:00
|
|
|
tree.links.new(scale.outputs["Image"], shadowcatcher.inputs[1])
|
2011-11-23 17:30:47 +00:00
|
|
|
|
2018-08-21 11:30:15 -03:00
|
|
|
tree.links.new(rlayer_bg.outputs["Image"], shadowcatcher.inputs[2])
|
2011-11-23 17:30:47 +00:00
|
|
|
|
2018-08-21 11:30:15 -03:00
|
|
|
tree.links.new(rlayer_fg.outputs["Image"], alphaover.inputs[2])
|
2011-11-23 17:30:47 +00:00
|
|
|
|
2018-08-21 11:30:15 -03:00
|
|
|
tree.links.new(shadowcatcher.outputs["Image"], alphaover.inputs[1])
|
2011-11-23 17:30:47 +00:00
|
|
|
|
2012-07-04 21:41:05 +00:00
|
|
|
tree.links.new(alphaover.outputs["Image"], composite.inputs["Image"])
|
|
|
|
tree.links.new(alphaover.outputs["Image"], viewer.inputs["Image"])
|
2011-11-23 17:30:47 +00:00
|
|
|
|
2018-08-21 11:30:15 -03:00
|
|
|
# Place nodes.
|
2011-11-23 17:30:47 +00:00
|
|
|
movieclip.location = Vector((-300.0, 350.0))
|
|
|
|
|
|
|
|
distortion.location = movieclip.location
|
|
|
|
distortion.location += Vector((200.0, 0.0))
|
|
|
|
|
|
|
|
if need_stabilization:
|
|
|
|
stabilize.location = distortion.location
|
|
|
|
stabilize.location += Vector((200.0, 0.0))
|
|
|
|
|
|
|
|
scale.location = stabilize.location
|
|
|
|
scale.location += Vector((200.0, 0.0))
|
|
|
|
else:
|
|
|
|
scale.location = distortion.location
|
|
|
|
scale.location += Vector((200.0, 0.0))
|
|
|
|
|
|
|
|
rlayer_bg.location = movieclip.location
|
|
|
|
rlayer_bg.location -= Vector((0.0, 350.0))
|
|
|
|
|
|
|
|
rlayer_fg.location = rlayer_bg.location
|
|
|
|
rlayer_fg.location -= Vector((0.0, 500.0))
|
|
|
|
|
2018-08-21 11:30:15 -03:00
|
|
|
shadowcatcher.location = scale.location
|
|
|
|
shadowcatcher.location += Vector((250.0, 0.0))
|
2011-11-23 17:30:47 +00:00
|
|
|
|
2018-08-21 11:30:15 -03:00
|
|
|
alphaover.location = shadowcatcher.location
|
|
|
|
alphaover.location += Vector((250.0, -250.0))
|
2011-11-23 17:30:47 +00:00
|
|
|
|
|
|
|
composite.location = alphaover.location
|
2018-08-21 11:30:15 -03:00
|
|
|
composite.location += Vector((300.0, -100.0))
|
2011-11-23 17:30:47 +00:00
|
|
|
|
|
|
|
viewer.location = composite.location
|
|
|
|
composite.location += Vector((0.0, 200.0))
|
|
|
|
|
2018-08-21 11:30:15 -03:00
|
|
|
# Ensure no nodes were created on the position of existing node.
|
2011-11-23 17:30:47 +00:00
|
|
|
self._offsetNodes(tree)
|
|
|
|
|
2015-04-22 16:26:00 +10:00
|
|
|
if hasattr(scene, "cycles"):
|
2013-04-11 13:29:51 +00:00
|
|
|
scene.cycles.film_transparent = True
|
2013-04-11 13:25:05 +00:00
|
|
|
|
2011-11-23 17:30:47 +00:00
|
|
|
@staticmethod
|
2018-08-15 16:10:09 -03:00
|
|
|
def _createMesh(collection, name, vertices, faces):
|
2012-04-08 13:11:25 +00:00
|
|
|
from bpy_extras.io_utils import unpack_list
|
2011-11-24 21:59:43 +00:00
|
|
|
|
2011-11-23 17:30:47 +00:00
|
|
|
mesh = bpy.data.meshes.new(name=name)
|
|
|
|
|
|
|
|
mesh.vertices.add(len(vertices))
|
|
|
|
mesh.vertices.foreach_set("co", unpack_list(vertices))
|
|
|
|
|
2012-03-27 09:10:05 +00:00
|
|
|
nbr_loops = len(faces)
|
|
|
|
nbr_polys = nbr_loops // 4
|
|
|
|
mesh.loops.add(nbr_loops)
|
|
|
|
mesh.polygons.add(nbr_polys)
|
2011-11-23 17:30:47 +00:00
|
|
|
|
2012-03-27 09:10:05 +00:00
|
|
|
mesh.polygons.foreach_set("loop_start", range(0, nbr_loops, 4))
|
|
|
|
mesh.polygons.foreach_set("loop_total", (4,) * nbr_polys)
|
|
|
|
mesh.loops.foreach_set("vertex_index", faces)
|
|
|
|
|
|
|
|
mesh.update()
|
2011-11-23 17:30:47 +00:00
|
|
|
|
|
|
|
ob = bpy.data.objects.new(name=name, object_data=mesh)
|
2018-08-15 16:10:09 -03:00
|
|
|
collection.objects.link(ob)
|
2011-11-23 17:30:47 +00:00
|
|
|
|
|
|
|
return ob
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _getPlaneVertices(half_size, z):
|
|
|
|
|
|
|
|
return [(-half_size, -half_size, z),
|
2014-09-21 15:55:12 +06:00
|
|
|
(half_size, -half_size, z),
|
2011-11-23 17:30:47 +00:00
|
|
|
(half_size, half_size, z),
|
2014-09-21 15:55:12 +06:00
|
|
|
(-half_size, half_size, z)]
|
2011-11-23 17:30:47 +00:00
|
|
|
|
2018-08-15 16:10:09 -03:00
|
|
|
def _createGround(self, collection):
|
2011-11-23 17:30:47 +00:00
|
|
|
vertices = self._getPlaneVertices(4.0, 0.0)
|
2012-03-27 09:10:05 +00:00
|
|
|
faces = [0, 1, 2, 3]
|
2011-11-23 17:30:47 +00:00
|
|
|
|
2018-08-15 16:10:09 -03:00
|
|
|
ob = self._createMesh(collection, "Ground", vertices, faces)
|
2011-11-23 17:30:47 +00:00
|
|
|
ob["is_ground"] = True
|
|
|
|
|
|
|
|
return ob
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _findGround(context):
|
|
|
|
scene = context.scene
|
|
|
|
|
|
|
|
for ob in scene.objects:
|
|
|
|
if ob.type == 'MESH' and "is_ground" in ob:
|
|
|
|
return ob
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
@staticmethod
|
2018-06-27 14:41:53 +02:00
|
|
|
def _createLight(scene):
|
|
|
|
light = bpy.data.lights.new(name="Light", type='POINT')
|
|
|
|
lightob = bpy.data.objects.new(name="Light", object_data=light)
|
2011-11-23 17:30:47 +00:00
|
|
|
|
2018-06-27 14:41:53 +02:00
|
|
|
lightob.matrix_local = Matrix.Translation((4.076, 1.005, 5.904))
|
2011-11-23 17:30:47 +00:00
|
|
|
|
2018-06-27 14:41:53 +02:00
|
|
|
return lightob
|
2011-11-23 17:30:47 +00:00
|
|
|
|
2018-08-15 16:10:09 -03:00
|
|
|
def _createSampleObject(self, collection):
|
2011-11-23 17:30:47 +00:00
|
|
|
vertices = self._getPlaneVertices(1.0, -1.0) + \
|
|
|
|
self._getPlaneVertices(1.0, 1.0)
|
2012-03-27 09:10:05 +00:00
|
|
|
faces = (0, 1, 2, 3,
|
|
|
|
4, 7, 6, 5,
|
|
|
|
0, 4, 5, 1,
|
|
|
|
1, 5, 6, 2,
|
|
|
|
2, 6, 7, 3,
|
|
|
|
3, 7, 4, 0)
|
2011-11-23 17:30:47 +00:00
|
|
|
|
2018-08-15 16:10:09 -03:00
|
|
|
return self._createMesh(collection, "Cube", vertices, faces)
|
2011-11-23 17:30:47 +00:00
|
|
|
|
|
|
|
def _setupObjects(self, context):
|
|
|
|
|
2018-08-21 11:30:15 -03:00
|
|
|
def setup_shadow_catcher_objects(collection):
|
|
|
|
"""Make all the newly created and the old objects of a collection """ \
|
|
|
|
"""to be properly setup for shadow catch"""
|
|
|
|
for ob in collection.objects:
|
|
|
|
ob.cycles.is_shadow_catcher = True
|
|
|
|
for child in collection.children:
|
|
|
|
setup_shadow_catcher_collection(child)
|
2011-11-23 17:30:47 +00:00
|
|
|
|
2018-08-21 11:30:15 -03:00
|
|
|
scene = context.scene
|
|
|
|
fg_coll = bpy.data.collections["foreground", None]
|
|
|
|
bg_coll = bpy.data.collections["background", None]
|
2011-11-23 17:30:47 +00:00
|
|
|
|
2018-08-21 11:30:15 -03:00
|
|
|
# Ensure all lights are active on foreground and background.
|
2018-06-27 14:41:53 +02:00
|
|
|
has_light = False
|
2011-11-23 17:30:47 +00:00
|
|
|
has_mesh = False
|
|
|
|
for ob in scene.objects:
|
2018-06-27 14:41:53 +02:00
|
|
|
if ob.type == 'LIGHT':
|
|
|
|
has_light = True
|
2011-11-23 17:30:47 +00:00
|
|
|
elif ob.type == 'MESH' and "is_ground" not in ob:
|
|
|
|
has_mesh = True
|
|
|
|
|
2018-08-21 11:30:15 -03:00
|
|
|
# Create sample light if there is no lights in the scene.
|
2018-06-27 14:41:53 +02:00
|
|
|
if not has_light:
|
|
|
|
light = self._createLight(scene)
|
2018-08-21 11:30:15 -03:00
|
|
|
fg_coll.objects.link(light)
|
|
|
|
bg_coll.objects.link(light)
|
2011-11-23 17:30:47 +00:00
|
|
|
|
2018-08-21 11:30:15 -03:00
|
|
|
# Create sample object if there's no meshes in the scene.
|
2011-11-23 17:30:47 +00:00
|
|
|
if not has_mesh:
|
2018-08-21 11:30:15 -03:00
|
|
|
ob = self._createSampleObject(fg_coll)
|
2011-11-23 17:30:47 +00:00
|
|
|
|
2018-08-21 11:30:15 -03:00
|
|
|
# Create ground object if needed.
|
2011-11-23 17:30:47 +00:00
|
|
|
ground = self._findGround(context)
|
|
|
|
if not ground:
|
2018-08-21 11:30:15 -03:00
|
|
|
ground = self._createGround(bg_coll)
|
2011-11-23 17:30:47 +00:00
|
|
|
|
2018-08-21 11:30:15 -03:00
|
|
|
# And set everything on background layer to shadow catcher.
|
|
|
|
if hasattr(scene, "cycles"):
|
|
|
|
self.setup_shadow_catcher_collection(bg_coll)
|
2011-11-23 17:30:47 +00:00
|
|
|
|
|
|
|
def execute(self, context):
|
2014-06-02 12:46:55 +06:00
|
|
|
scene = context.scene
|
|
|
|
current_active_layer = scene.active_layer
|
|
|
|
|
2011-11-23 17:30:47 +00:00
|
|
|
self._setupScene(context)
|
|
|
|
self._setupWorld(context)
|
|
|
|
self._setupCamera(context)
|
|
|
|
self._setupViewport(context)
|
2017-11-22 10:52:39 -02:00
|
|
|
self._setupViewLayers(context)
|
2018-08-21 11:30:15 -03:00
|
|
|
self._setupCollections(context)
|
2011-11-23 17:30:47 +00:00
|
|
|
self._setupNodes(context)
|
|
|
|
self._setupObjects(context)
|
|
|
|
|
|
|
|
return {'FINISHED'}
|
2012-01-26 15:04:25 +00:00
|
|
|
|
2012-02-04 11:12:18 +00:00
|
|
|
|
2012-01-26 15:04:25 +00:00
|
|
|
class CLIP_OT_track_settings_as_default(Operator):
|
2012-01-30 20:41:36 +00:00
|
|
|
"""Copy tracking settings from active track to default settings"""
|
2012-01-26 15:04:25 +00:00
|
|
|
|
|
|
|
bl_idname = "clip.track_settings_as_default"
|
|
|
|
bl_label = "Track Settings As Default"
|
|
|
|
bl_options = {'UNDO', 'REGISTER'}
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
|
|
|
sc = context.space_data
|
|
|
|
|
|
|
|
if sc.type != 'CLIP_EDITOR':
|
|
|
|
return False
|
|
|
|
|
|
|
|
clip = sc.clip
|
|
|
|
|
|
|
|
return clip and clip.tracking.tracks.active
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
sc = context.space_data
|
|
|
|
clip = sc.clip
|
|
|
|
|
2012-08-04 10:47:31 +00:00
|
|
|
track = clip.tracking.tracks.active
|
|
|
|
framenr = context.scene.frame_current - clip.frame_start + 1
|
|
|
|
|
|
|
|
CLIP_default_settings_from_track(clip, track, framenr)
|
2012-01-26 15:04:25 +00:00
|
|
|
|
|
|
|
return {'FINISHED'}
|
2015-02-13 02:17:23 +11:00
|
|
|
|
|
|
|
|
|
|
|
class CLIP_OT_track_settings_to_track(bpy.types.Operator):
|
|
|
|
"""Copy tracking settings from active track to selected tracks"""
|
|
|
|
|
|
|
|
bl_label = "Copy Track Settings"
|
|
|
|
bl_idname = "clip.track_settings_to_track"
|
|
|
|
bl_options = {'UNDO', 'REGISTER'}
|
|
|
|
|
|
|
|
_attrs_track = (
|
|
|
|
"correlation_min",
|
|
|
|
"frames_limit",
|
|
|
|
"pattern_match",
|
|
|
|
"margin",
|
|
|
|
"motion_model",
|
|
|
|
"use_brute",
|
|
|
|
"use_normalization",
|
|
|
|
"use_mask",
|
|
|
|
"use_red_channel",
|
|
|
|
"use_green_channel",
|
|
|
|
"use_blue_channel",
|
|
|
|
"weight"
|
2018-06-26 19:41:37 +02:00
|
|
|
)
|
2015-02-13 02:17:23 +11:00
|
|
|
|
|
|
|
_attrs_marker = (
|
|
|
|
"pattern_corners",
|
|
|
|
"search_min",
|
|
|
|
"search_max",
|
2018-06-26 19:41:37 +02:00
|
|
|
)
|
2015-02-13 02:17:23 +11:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
|
|
|
space = context.space_data
|
|
|
|
if space.type != 'CLIP_EDITOR':
|
|
|
|
return False
|
|
|
|
clip = space.clip
|
|
|
|
return clip and clip.tracking.tracks.active
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
space = context.space_data
|
|
|
|
clip = space.clip
|
|
|
|
track = clip.tracking.tracks.active
|
|
|
|
|
|
|
|
framenr = context.scene.frame_current - clip.frame_start + 1
|
|
|
|
marker = track.markers.find_frame(framenr, False)
|
|
|
|
|
|
|
|
for t in clip.tracking.tracks:
|
|
|
|
if t.select and t != track:
|
|
|
|
marker_selected = t.markers.find_frame(framenr, False)
|
|
|
|
for attr in self._attrs_track:
|
|
|
|
setattr(t, attr, getattr(track, attr))
|
|
|
|
for attr in self._attrs_marker:
|
|
|
|
setattr(marker_selected, attr, getattr(marker, attr))
|
|
|
|
|
|
|
|
return {'FINISHED'}
|
2017-03-18 20:03:24 +11:00
|
|
|
|
|
|
|
|
|
|
|
classes = (
|
|
|
|
CLIP_OT_bundles_to_mesh,
|
|
|
|
CLIP_OT_constraint_to_fcurve,
|
|
|
|
CLIP_OT_delete_proxy,
|
|
|
|
CLIP_OT_filter_tracks,
|
|
|
|
CLIP_OT_set_active_clip,
|
|
|
|
CLIP_OT_set_viewport_background,
|
|
|
|
CLIP_OT_setup_tracking_scene,
|
|
|
|
CLIP_OT_track_settings_as_default,
|
|
|
|
CLIP_OT_track_settings_to_track,
|
|
|
|
CLIP_OT_track_to_empty,
|
2017-03-25 11:07:05 +11:00
|
|
|
)
|