forked from spiderbit/canta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_view_theme
executable file
·155 lines (121 loc) · 4.2 KB
/
run_view_theme
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#! /usr/bin/python -O
# -*- coding: utf-8 -*-
#
# CANTA Theme Editor - An editor for themes used in CANTA
# Copyright (C) 2008 A. Kattner
#
# 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 3 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, see <http://www.gnu.org/licenses/>.
import sys
import os
import soya
import soya.pudding.ext.fpslabel
import soya.cube
import soya.sphere
import getopt
from canta.theme.theme_manager import ThemeManager
from canta.theme.editor import Editor
try:
import psyco
psyco.full()
except ImportError:
print '+ Canta + Warning: Psyco not found. Performance will not be optimized.'
pass
from canta.display.core_init import CoreInit
def usage():
print "\n| CANTA Theme Viewer"
print "| USAGE: python <theme name> <res x> <res y> <fs>"
print "| - theme name: the name of the directory where the theme files are stored"
print "| - res x: resolution, e.g. 1024"
print "| - res y: resolution, e.g. 768"
print "| - fs: fullscreen 1 or 0\n|"
print "| Example: python run_view_theme.py mozart 1024 768 0"
def main():
if len(sys.argv) != 5:
usage()
sys.exit(2)
# app dir:
app_dir = os.path.dirname(sys.argv[0])
# theme name:
theme_name = sys.argv[1]
# app name:
APP_NAME = 'Canta Theme Viewer'
# version:
VERSION = '0.1'
RESIZEABLE = True
# DEBUG flag:
DEBUG = False
# get platform info:
PLATFORM = sys.platform
# on Windows systems:
if 'win32' in PLATFORM:
import PIL.PngImagePlugin
import PIL.JpegImagePlugin
window_title = APP_NAME + ' ' + VERSION
res_x = int(sys.argv[2])
res_y = int(sys.argv[3])
fs = int(sys.argv[4])
soya.init(title=window_title, width=res_x, height=res_y, \
fullscreen=fs, resizeable=RESIZEABLE)
# Enable/disable soya's auto (blender model) importer:
soya.AUTO_EXPORTERS_ENABLED = True
theme_path = os.path.join(app_dir, 'media', 'themes', \
theme_name, 'media')
soya.path.append(theme_path)
scene = soya.World()
light = soya.Light(scene)
light.set_xyz(0.0, 7.7, 17.0)
light.cast_shadow = True
camera = soya.Camera(scene)
moveable = True
rotating = False
if moveable:
from canta.cameras.movable_camera import MovableCamera
camera = MovableCamera(app_dir, scene, DEBUG)
if rotating:
from canta.cameras.spinning_camera import SpinningCamera
cube = soya.Body(scene, soya.cube.Cube().to_model())
cube.visible = True
camera = SpinningCamera(scene, cube)
#camera = soya.TravelingCamera(scene)
camera.set_xyz(0.0, 0.0, 15.0)
# camera.fov = 90.0
# camera.ortho = True
# camera.set_xyz(-0.5, -0.5, 4.0)
# camera.rotate_y(-90.0)
# camera.set_xyz(0.0, -0.5, 7.0)
# Create the editor world.
world = Editor(scene, camera)
# load the theme config settings:
theme_mgr = ThemeManager(world)
theme_dir = os.path.join(app_dir, 'media', 'themes', theme_name)
theme_mgr.get_theme(theme_name, theme_dir)
theme_mgr.show_theme(theme_name)
# TEST OBJECTS
# wall_model = soya.World()
# wall_face = soya.Face(wall_model, [
# soya.Vertex(wall_model, -5.0, 0.0, -5.0),
# soya.Vertex(wall_model, -5.0, 0.0, 5.0),
# soya.Vertex(wall_model, 5.0, 0.0, 5.0),
# soya.Vertex(wall_model, 5.0, 0.0, -5.0),
# ])
# wall_face.double_sided = 1
# wall = soya.Body(world, wall_model.to_model())
# wall.set_xyz(0.0, 0.0, 0.0)
# cube = soya.Body(scene, soya.cube.Cube().to_model())
# sphere = soya.Body(scene, soya.sphere.Sphere().to_model())
# world.filename = "theme"
# world.save()
soya.set_root_widget(camera)
soya.MainLoop(scene).main_loop()
if __name__ == '__main__': main()