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

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

  This module provides *Scene* manipulation routines.

  Example::

    from Blender import Scene

    curscene = Scene.getCurrent()
    ob = curscene.getChildren()[0]       # first object
    newscene = Scene.New('testscene')
    cam = curscene.getCurrentCamera()    # get current camera object
    newscene.link(ob)                    # link 'ob' to Scene
    newscene.link(cam)
    newscene.makeCurrent()               # make current Scene
"""  
import _Blender.Scene as _Scene

from Object import Object
import shadow

class Scene(shadow.shadowEx):
	"""Wrapper for Scene DataBlock 
"""
	def link(self, object):
		"""Links Object 'object' into Scene 'self'."""
		# This is a strange workaround; Python does not release 
		# 'self' (and thus self._object) when an exception in the C API occurs. 
		# Therefore, we catch that exception and do it ourselves..
		# Maybe Python 2.2 is able to resolve this reference dependency ?
		try:
			return self._object.link(object._object)
		except:
			del self._object
			raise 

	def unlink(self, object):
		"""Unlinks (deletes) Object 'object' from Scene."""
		ret = self._object.unlink(object._object)
		return ret

	def copy(self, duplicate_objects = 1):	
		"""Returns a copy of itself.

The optional argument defines, how the Scene's children objects are
duplicated::

  0: Link Objects
  1: Link Object data
  2: Full Copy"""
		return Scene(self._object.copy(duplicate_objects))

	def update(self):
		"""Updates scene 'self'.
  This function explicitely resorts the base list of a newly created object
  hierarchy."""
		return self._object.update()

	def makeCurrent(self):
		"""Makes 'self' the current Scene"""
		return self._object.makeCurrent()

	def frameSettings(self, start = None, end = None, current = None):
		"""Sets or retrieves the Scene's frame settings.
If the frame arguments are specified, they are set.
A tuple (start, end, current) is returned in any case."""
		if start and end and current:
			return self._object.frameSettings(start, end, current)
		else:
			return self._object.frameSettings()

	def currentFrame(self, frame = None):
		"""If 'frame' is given, the current frame is set and returned in any case"""
		if frame:
			return self._object.frameSettings(-1, -1, frame)
		return self._object.frameSettings()[2]

	def startFrame(self, frame = None):
		"""If 'frame' is given, the start frame is set and returned in any case"""
		if frame:
			return self._object.frameSettings(frame, -1, -1)
		return self._object.frameSettings()[0]

	def endFrame(self, frame = None):
		"""If 'frame' is given, the end frame is set and returned in any case"""
		if frame:
			return self._object.frameSettings(-1, frame, -1)
		return self._object.frameSettings()[1]

	def getChildren(self):
		"""Returns a list of the Scene's children Objects"""
		return shadow._List(self._object.getChildren(), Object)

	def getCurrentCamera(self):
		"""Returns current active camera Object"""
		cam = self._object.getCurrentCamera()
		if cam:
			return Object(cam)

	def setCurrentCamera(self, object):
		"""Sets the current active camera Object 'object'"""
		return self._object.setCurrentCamera(object._object)

	def getRenderdir(self):
		"""Returns directory where rendered images are saved to"""
		return self._object.getRenderdir(self._object)

	def getBackbufdir(self):	
		"""Returns the Backbuffer images location"""
		return self._object.getBackbufdir(self._object)

# Module methods

def New(name = 'Scene'):
	"""Creates and returns new Scene with (optionally given) name"""
	return Scene(_Scene.New(name))

def get(name = None):
	"""Returns a Scene object with name 'name' if given, None if not existing,
or a list of all Scenes otherwise."""
	if name:
		ob = _Scene.get(name)
		if ob:
			return Scene(ob)
		else:
			return None
	else:
		return shadow._List(_Scene.get(), Scene)

Get = get  # emulation

def getCurrent():
	"""Returns the currently active Scene"""
	sc = Scene(_Scene.getCurrent())
	return sc

def unlink(scene):
	"""Removes the Scene 'scene' from Blender"""
	if scene._object.name == _Scene.getCurrent().name:
		raise SystemError, "current Scene can not be removed!"
	for ob in scene.getChildren():
		scene.unlink(ob)
	return _Scene.unlink(scene._object)