Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Camera.py « Blender « modules « python « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 33f615fc0da57079fc327a168b5ebda9bb1fba8a (plain)
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
"""The Blender Camera module

This module provides access to **Camera** objects in Blender

Example::

  from Blender import Camera, Object, Scene
  c = Camera.New('ortho')      # create new ortho camera data
  c.lens = 35.0                # set lens value
  cur = Scene.getCurrent()     # get current Scene
  ob = Object.New('Camera')    # make camera object
  ob.link(c)                   # link camera data with this object
  cur.link(ob)                 # link object into scene
  cur.setCurrentCamera(ob)     # make this camera the active
"""

import shadow
import _Blender.Camera as _Camera


class Camera(shadow.hasIPO):
	"""Wrapper for Camera DataBlock

  Attributes

    lens      -- The lens value

    clipStart -- The clipping start of the view frustum

    clipEnd   -- The end clipping plane of the view frustum

    type      -- The camera type:
                 0: perspective camera,
			     1: orthogonal camera     - (see Types)
  
    mode      -- Drawing mode; see Modes
"""

	_emulation = {'Lens'   : "lens",
	              'ClSta'  : "clipStart",
				  'ClEnd'  : "clipEnd",
				 } 

	Types = {'persp' : 0,
			 'ortho' : 1,
			} 

	Modes = {'showLimits' : 1,
			 'showMist'   : 2,
			} 

	def __init__(self, object):
		self._object = object

	def getType(self):
		"""Returns camera type: "ortho" or "persp" """
		if self.type == self.Types['ortho']:
			return 'ortho'
		else:
			return 'persp'

	def setType(self, type):
		"""Sets Camera type to 'type' which must be one of ["persp", "ortho"]"""
		self._object.type = self.Types[type]

	def setMode(self, *modes):
		"""Sets Camera modes *the nice way*, instead of direct access
of the 'mode' member. 
This function takes a variable number of string arguments of the types 
listed in self.Modes.


Example::

  c = Camera.New()
  c.setMode('showMist', 'showLimits')
"""  
		flags = 0
		try:
			for a in modes:
				flags |= self.Modes[a]
		except:
			raise TypeError, "mode must be one of %s" % self.Modes.keys()
		self.mode = flags

	def __repr__(self):
		return "[Camera \"%s\"]" % self.name

def New(type = 'persp'):
	"""Creates new camera Object and returns it. 'type', if specified,
must be one of Types"""
	cam = Camera(_Camera.New())
	cam.setType(type)
	return cam

def get(name = None):
	"""Returns the Camera with name 'name', if given. Otherwise, a list
of all Cameras is returned"""
	if name:
		return Camera(_Camera.get(name))
	else:
		return shadow._List(_Camera.get(), Camera)
	
Get = get  # emulation