2
# -*- coding: utf-8 -*-
4
# Phatch - Photo Batch Processor
5
# Copyright (C) 2009 Juho Vepsäläinen, www.stani.be
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program. If not, see http://www.gnu.org/licenses/
20
# Phatch recommends SPE (http://pythonide.stani.be) for editing python files.
23
from optparse import OptionParser
24
from preview import Preview, PreviewGenerator
25
from test_actions import system_path
28
class BlenderPreviewGenerator(PreviewGenerator):
31
def __init__(self, preview_object):
33
self.preview_objects = (preview_object, )
35
# FIXME: should introspect this properly from existing objects!
36
self.preview_objects = ('Book', 'Box', 'Can', 'Cd', 'Lcd',
40
for preview_object in self.preview_objects:
41
options = self.options
42
options['Object'] = [preview_object]
43
options['Render Width'] = ['128px']
44
options['Render Height'] = ['128px']
46
output_path = self.get_output_path(preview_object)
48
blender_preview = self.previewer(self.action, options, output_path)
49
blender_preview.execute()
52
class ObjectPreview(Preview):
54
def get_preview_filename(self, name, choice):
55
return choice['Object'].lower()
58
class ObjectPreviewGenerator(BlenderPreviewGenerator):
59
previewer = ObjectPreview
60
option_name = 'object'
62
def get_output_path(self, preview_object):
63
return system_path(self.base_path + self.option_name)
66
class RotationPreview(Preview):
68
def get_preview_filename(self, name, choice):
69
hori_rot = choice['Horizontal Rotation']
70
vert_rot = choice['Vertical Rotation']
72
return 'hori_' + str(hori_rot) + '_vert_' + str(vert_rot)
75
class RotationPreviewGenerator(BlenderPreviewGenerator):
76
previewer = RotationPreview
77
option_name = 'rotation'
79
'Horizontal Rotation': [-60, -30, 0, 30, 60],
80
'Vertical Rotation': [0, 30, 60],
83
def get_output_path(self, preview_object):
84
return system_path(self.base_path + self.option_name + '/' +
85
preview_object.lower())
88
class BlenderPreviewApp(OptionParser):
91
self.option_parser = OptionParser()
93
self.option_parser.add_option('-b', '--object', default='',
94
help='Object for which to render previews. If no object is '\
95
'provided it generates previews for all objects automatically.')
96
self.option_parser.add_option('-o', '--objectpreview',
97
action='store_false', help="Don't generate object previews.")
98
self.option_parser.add_option('-r', '--rotationpreview',
99
action='store_false', help="Don't generate rotation previews.")
102
options, args = self.option_parser.parse_args()
103
blender_ob = options.object
105
if options.objectpreview is None:
106
object_preview_generator = ObjectPreviewGenerator(blender_ob)
107
object_preview_generator.generate()
109
if options.rotationpreview is None:
110
rotation_preview_generator = RotationPreviewGenerator(blender_ob)
111
rotation_preview_generator.generate()
114
if __name__ == '__main__':
115
blender_preview = BlenderPreviewApp()
116
blender_preview.run()