-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
100 lines (81 loc) · 3.01 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
bl_info = {
"name": "POVCam",
"blender": (4, 1, 1),
"version": (2, 24, 23),
"category": "3D View",
"author": "Kent Edoloverio",
"location": "3D View > POVCam",
"description": "Adds a camera based on the current point of view",
"warning": "",
"wiki_url": "",
"tracker_url": "",
}
import bpy
from bpy.types import Panel, Operator
class POVCamera:
def __init__(self):
self.camera_data = bpy.data.cameras.new(name="Camera")
self.camera_object = bpy.data.objects.new(name="Camera", object_data=self.camera_data)
bpy.context.scene.collection.objects.link(self.camera_object)
def set_active_camera(self):
bpy.context.scene.camera = self.camera_object
def set_camera_to_point_of_view(self):
for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
for region in area.regions:
if region.type == 'WINDOW':
for space in area.spaces:
if space.type == 'VIEW_3D':
override = {
'area': area,
'region': region,
'space_data': space,
'region_data': space.region_3d,
'edit_object': self.camera_object,
'object': self.camera_object,
'active_object': self.camera_object,
'selected_objects': [self.camera_object],
'selected_editable_objects': [self.camera_object],
}
bpy.ops.view3d.camera_to_view(override)
return {'FINISHED'}
class POVCam_op_Add_camera(Operator):
bl_idname = "object.append_camera"
bl_label = "ADD CAMERA"
def execute(self, context):
camera_manager = POVCamera()
camera_manager.set_active_camera()
camera_manager.set_camera_to_point_of_view()
return {'FINISHED'}
class POVCam_pl_Camera(Panel):
bl_label = "POVCam"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "POVCam"
bl_options = {'HEADER_LAYOUT_EXPAND'}
def draw(self, context):
layout = self.layout
col = layout.column(align=True)
col.enabled = True
col.scale_x = 2.0
col.scale_y = 2.0
col.operator("object.append_camera", icon="OUTLINER_OB_CAMERA")
col.label(text="SUPPORT ME ON:")
op = self.layout.operator(
'wm.url_open',
text='KO-FI',
icon='URL'
)
op.url = 'https://ko-fi.com/kents_workof_art'
classes = (
POVCam_op_Add_camera,
POVCam_pl_Camera,
)
def register():
for cls in classes:
bpy.utils.register_class(cls)
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)
if __name__ == "__main__":
register()