space_view3d_stored_view: T52259 + fix wrong camera location on create
This commit is contained in:
parent
00b84551cf
commit
e3fa74306f
|
@ -70,11 +70,10 @@ class POV(StoredView):
|
|||
if region3d.view_perspective == 'CAMERA':
|
||||
stored_view.camera_type = view3d.camera.type # type : 'CAMERA' or 'MESH'
|
||||
stored_view.camera_name = view3d.camera.name # store string instead of object
|
||||
stored_view.camera_pointer = view3d.camera.as_pointer()
|
||||
if view3d.lock_object is not None:
|
||||
stored_view.lock_object_name = view3d.lock_object.name # idem
|
||||
stored_view.lock_object_pointer = view3d.lock_object.as_pointer() # idem
|
||||
|
||||
else:
|
||||
stored_view.lock_object_name = ""
|
||||
stored_view.lock_cursor = view3d.lock_cursor
|
||||
stored_view.cursor_location = view3d.cursor_location
|
||||
|
||||
|
@ -94,39 +93,18 @@ class POV(StoredView):
|
|||
view3d.cursor_location = stored_view.cursor_location
|
||||
|
||||
if stored_view.perspective == "CAMERA":
|
||||
cam = self._get_object(stored_view.camera_name, stored_view.camera_pointer)
|
||||
if cam:
|
||||
# in case the camera is found by pointer, update name
|
||||
stored_view.camera_name = cam.name
|
||||
view3d.camera = cam
|
||||
else:
|
||||
# TODO: camera object not found
|
||||
pass
|
||||
|
||||
if stored_view.lock_object_name != "":
|
||||
lock_obj = self._get_object(stored_view.lock_object_name, stored_view.lock_object_pointer)
|
||||
lock_obj = self._get_object(stored_view.lock_object_name)
|
||||
if lock_obj:
|
||||
# in case the lock object is found by pointer, update name
|
||||
stored_view.lock_object_name = lock_obj.name
|
||||
view3d.lock_object = lock_obj
|
||||
else:
|
||||
# TODO: handle lock object not found
|
||||
pass
|
||||
cam = self._get_object(stored_view.camera_name)
|
||||
if cam:
|
||||
view3d.camera = cam
|
||||
|
||||
@staticmethod
|
||||
def _get_object(name, pointer=None):
|
||||
obj = None
|
||||
try:
|
||||
obj = bpy.data.objects[name]
|
||||
except:
|
||||
if pointer:
|
||||
scene_objects = bpy.data.objects
|
||||
for o in scene_objects:
|
||||
p = o.as_pointer()
|
||||
if p == pointer:
|
||||
obj = o
|
||||
break
|
||||
return obj
|
||||
return bpy.data.objects.get(name)
|
||||
|
||||
@staticmethod
|
||||
def is_modified(context, stored_view):
|
||||
|
@ -350,29 +328,29 @@ class DataStore():
|
|||
def sanitize_data(scene):
|
||||
|
||||
def check_objects_references(mode, list):
|
||||
for key, item in list.items():
|
||||
to_remove = []
|
||||
for i, list_item in enumerate(list.items()):
|
||||
key, item = list_item
|
||||
if mode == 'POV' or mode == 'VIEWS':
|
||||
if mode == 'VIEWS':
|
||||
item = item.pov
|
||||
|
||||
if item.perspective == "CAMERA":
|
||||
try:
|
||||
camera = bpy.data.objects[item.camera_name]
|
||||
item.camera_pointer = camera.as_pointer()
|
||||
except:
|
||||
|
||||
camera = bpy.data.objects.get(item.camera_name)
|
||||
if camera is None:
|
||||
try: # pick a default camera TODO: ask to pick?
|
||||
camera = bpy.data.cameras[0]
|
||||
item.camera_name = camera.name
|
||||
item.camera_pointer = camera.as_pointer()
|
||||
except: # couldn't find a camera in the scene
|
||||
list.remove(key) # TODO: create one instead?
|
||||
pass
|
||||
|
||||
if item.lock_object_name != "":
|
||||
try: # get object from name string
|
||||
object = bpy.data.objects[item.lock_object_name]
|
||||
item.lock_object_pointer = object.as_pointer()
|
||||
except:
|
||||
item.lock_object_name = ""
|
||||
obj = bpy.data.objects.get(item.lock_object_name)
|
||||
if obj is None and camera is None:
|
||||
to_remove.append(i)
|
||||
|
||||
for i in reversed(to_remove):
|
||||
list.remove(i)
|
||||
|
||||
modes = ['POV', 'VIEW', 'DISPLAY', 'LAYERS']
|
||||
for mode in modes:
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
# gpl authors: nfloyd, Francesco Siddi
|
||||
|
||||
import bpy
|
||||
from bpy.props import (
|
||||
IntProperty,
|
||||
StringProperty,
|
||||
)
|
||||
from bpy.props import IntProperty
|
||||
from bpy.types import Operator
|
||||
from .core import (
|
||||
stored_view_factory,
|
||||
|
@ -66,28 +63,27 @@ class VIEW3D_New_Camera_to_View(Operator):
|
|||
bl_label = "New Camera To View"
|
||||
bl_description = "Add a new Active Camera and align it to this view"
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return (
|
||||
context.space_data is not None and
|
||||
context.space_data.type == 'VIEW_3D' and
|
||||
context.space_data.region_3d.view_perspective != 'CAMERA'
|
||||
)
|
||||
|
||||
def execute(self, context):
|
||||
try:
|
||||
# check for operator's poll (there is no active object, for instance)
|
||||
if bpy.ops.object.mode_set.poll():
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
|
||||
bpy.ops.object.camera_add(view_align=True)
|
||||
cam = bpy.context.active_object
|
||||
bpy.ops.view3d.object_as_camera()
|
||||
bpy.ops.view3d.camera_to_view()
|
||||
if bpy.ops.object.mode_set.poll():
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
|
||||
# this will name the Camera Object
|
||||
if 'View_Camera' not in context.scene.objects:
|
||||
cam.name = "View_Camera"
|
||||
else:
|
||||
cam.name = "View_Camera.000"
|
||||
bpy.ops.object.camera_add()
|
||||
cam = context.active_object
|
||||
cam.name = "View_Camera"
|
||||
# make active camera by hand
|
||||
context.scene.camera = cam
|
||||
|
||||
return {'FINISHED'}
|
||||
except:
|
||||
self.report({'WARNING'},
|
||||
"Operation Cancelled. New Camera to View failed to add a new camera")
|
||||
return {'CANCELLED'}
|
||||
bpy.ops.view3d.camera_to_view()
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
# Camera marker & switcher by Fsiddi
|
||||
|
@ -96,50 +92,48 @@ class SetSceneCamera(Operator):
|
|||
bl_label = "Set Scene Camera"
|
||||
bl_description = "Set chosen camera as the scene's active camera"
|
||||
|
||||
chosen_camera = StringProperty()
|
||||
select_chosen = False
|
||||
hide_others = False
|
||||
|
||||
def execute(self, context):
|
||||
chosen_camera = bpy.data.objects.get(self.chosen_camera, None)
|
||||
chosen_camera = context.active_object
|
||||
scene = context.scene
|
||||
if not chosen_camera:
|
||||
self.report({'ERROR'}, "Camera %s not found.")
|
||||
return {'CANCELLED'}
|
||||
|
||||
if self.select_chosen:
|
||||
if context.mode == 'OBJECT':
|
||||
for o in context.selected_objects:
|
||||
o.select = False
|
||||
chosen_camera.select = True
|
||||
scene.objects.active = chosen_camera
|
||||
if self.hide_others:
|
||||
for c in [o for o in scene.objects if o.type == 'CAMERA']:
|
||||
c.hide = (c != chosen_camera)
|
||||
scene.camera = chosen_camera
|
||||
bpy.context.scene.objects.active = chosen_camera
|
||||
bpy.ops.object.select_all(action='TOGGLE')
|
||||
bpy.ops.object.select_all(action='DESELECT')
|
||||
chosen_camera.select = True
|
||||
return {'FINISHED'}
|
||||
|
||||
def invoke(self, context, event):
|
||||
if event.ctrl:
|
||||
self.select_chosen = True
|
||||
self.hide_others = True
|
||||
|
||||
return self.execute(context)
|
||||
|
||||
|
||||
class PreviewSceneCamera(Operator):
|
||||
bl_idname = "cameraselector.preview_scene_camera"
|
||||
bl_label = "Preview Camera"
|
||||
bl_description = "Preview chosen camera and make scene's active camera"
|
||||
|
||||
def execute(self, context):
|
||||
chosen_camera = context.active_object
|
||||
bpy.ops.view3d.object_as_camera()
|
||||
bpy.ops.object.select_all(action="DESELECT")
|
||||
chosen_camera.select = True
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
class AddCameraMarker(Operator):
|
||||
bl_idname = "cameraselector.add_camera_marker"
|
||||
bl_label = "Add Camera Marker"
|
||||
bl_description = "Add a timeline marker bound to chosen camera"
|
||||
|
||||
chosen_camera = StringProperty()
|
||||
|
||||
def execute(self, context):
|
||||
chosen_camera = bpy.data.objects.get(self.chosen_camera, None)
|
||||
chosen_camera = context.active_object
|
||||
scene = context.scene
|
||||
if not chosen_camera:
|
||||
self.report({'WARNING'}, "Camera %s not found. Operation Cancelled")
|
||||
return {'CANCELLED'}
|
||||
|
||||
current_frame = scene.frame_current
|
||||
marker = None
|
||||
|
@ -153,7 +147,7 @@ class AddCameraMarker(Operator):
|
|||
# current frame is already bound to the camera.
|
||||
return {'CANCELLED'}
|
||||
|
||||
marker_name = "F_%02d_%s" % (current_frame, self.chosen_camera)
|
||||
marker_name = "F_%02d_%s" % (current_frame, chosen_camera.name)
|
||||
if marker and (marker.frame == current_frame):
|
||||
# Reuse existing marker at current frame to avoid
|
||||
# overlapping bound markers.
|
||||
|
|
|
@ -38,9 +38,7 @@ class POVData(PropertyGroup):
|
|||
perspective_matrix_md5 = StringProperty()
|
||||
camera_name = StringProperty()
|
||||
camera_type = StringProperty()
|
||||
camera_pointer = IntProperty()
|
||||
lock_object_name = StringProperty()
|
||||
lock_object_pointer = IntProperty()
|
||||
|
||||
|
||||
class LayersData(PropertyGroup):
|
||||
|
@ -71,11 +69,7 @@ class DisplayData(PropertyGroup):
|
|||
grid_lines = IntProperty()
|
||||
grid_scale = FloatProperty()
|
||||
grid_subdivisions = IntProperty()
|
||||
material_mode = EnumProperty(
|
||||
items=[('TEXTURE_FACE', '', ''),
|
||||
('MULTITEXTURE', '', ''),
|
||||
('GLSL', '', '')]
|
||||
)
|
||||
material_mode = StringProperty()
|
||||
show_textured_solid = BoolProperty()
|
||||
quad_view = BoolProperty()
|
||||
lock_rotation = BoolProperty()
|
||||
|
|
|
@ -170,7 +170,7 @@ class VIEW3D_PT_properties_stored_views(Panel):
|
|||
col.prop_enum(stored_views, "mode", 'VIEW')
|
||||
row = layout.row(align=True)
|
||||
row.operator("view3d.camera_to_view", text="Camera To view")
|
||||
row.operator("stored_views.newcamera", text="New Camera To view")
|
||||
row.operator("stored_views.newcamera")
|
||||
|
||||
row = col.row(align=True)
|
||||
row.prop_enum(stored_views, "mode", 'POV')
|
||||
|
@ -252,12 +252,12 @@ class VIEW3D_PT_properties_stored_views(Panel):
|
|||
if len(cameras) > 0:
|
||||
for camera in cameras:
|
||||
row = layout.row(align=True)
|
||||
btn = row.operator("cameraselector.set_scene_camera",
|
||||
row.context_pointer_set("active_object", camera)
|
||||
row.operator("cameraselector.set_scene_camera",
|
||||
text=camera.name, icon='OUTLINER_DATA_CAMERA')
|
||||
btn.chosen_camera = camera.name
|
||||
|
||||
btn = row.operator("cameraselector.add_camera_marker",
|
||||
row.operator("cameraselector.preview_scene_camera",
|
||||
text='', icon='RESTRICT_VIEW_OFF')
|
||||
row.operator("cameraselector.add_camera_marker",
|
||||
text='', icon='MARKER')
|
||||
btn.chosen_camera = camera.name
|
||||
else:
|
||||
layout.label("No cameras in this scene")
|
||||
|
|
Loading…
Reference in New Issue