@dfelinto(pto): nope, it would need to *stay* in camera view when panning and dollying around :)
Daniel Salazar 3Developer.com On Tue, Apr 26, 2011 at 12:58 PM, Dalai Felinto <[email protected]> wrote: >> Below you can find some code for (...) Lock camera to view. > Isn't this what Ctrl+Alt+Numpad0 do? (align camera to view -- which > even takes care of non-perspective views) > > On my understanding what people are ranting is for the lack of options > to move while "inside" the camera mode. > > -- > Dalai > > 2011/4/26 bartius crouch <[email protected]>: >>> Also a lock camera to view option would be great so we can just move >>> the camera like we move any other viewport >> >> Like Campbell said, that isn't very hard to do in python. Below you can find >> some code for it. >> Copy the text below into the text-editor, Run Script (alt+P), go to 3d-view, >> search (spacebar) for Lock camera to view. >> >> >> >> import bpy >> import mathutils >> >> >> class ModalOperator(bpy.types.Operator): >> '''Move camera along with the viewport''' >> bl_idname = "view3d.lock_camera" >> bl_label = "Lock camera to view" >> >> @classmethod >> def poll(cls, context): >> camera = context.scene.camera >> if not camera: >> return(False) >> return(camera.name in context.scene.objects) >> >> def modal(self, context, event): >> camera = context.scene.camera >> rv3d = context.space_data.region_3d >> >> # rotation + location >> camera.matrix_world = rv3d.view_matrix.copy().inverted() >> >> # override location to take view_distance into account >> rotation = rv3d.view_matrix.copy().to_3x3().inverted() >> z_normal = mathutils.Vector([0.0, 0.0, 1.0]) * rotation >> camera.location = rv3d.view_location + (rv3d.view_distance * >> z_normal) >> >> # handle events >> if event.type in ['LEFTMOUSE', 'NUMPAD_ENTER', 'RET']: >> context.area.header_text_set() >> return {'FINISHED'} >> elif event.type == 'ESC': >> camera.matrix_world = self.camera_matrix >> context.area.header_text_set() >> return {'CANCELLED'} >> >> return {'PASS_THROUGH'} >> >> def invoke(self, context, event): >> context.window_manager.modal_handler_add(self) >> self.camera_matrix = context.scene.camera.matrix_world.copy() >> context.space_data.region_3d.view_perspective = 'PERSP' >> context.area.header_text_set("ESC to cancel, ENTER or LMB to >> confirm") >> return {'RUNNING_MODAL'} >> >> >> def register(): >> bpy.utils.register_class(ModalOperator) >> >> >> def unregister(): >> bpy.utils.unregister_class(ModalOperator) >> >> >> if __name__ == "__main__": >> register() > _______________________________________________ > Bf-committers mailing list > [email protected] > http://lists.blender.org/mailman/listinfo/bf-committers > _______________________________________________ Bf-committers mailing list [email protected] http://lists.blender.org/mailman/listinfo/bf-committers
