* Added more doc files for epydoc and a test for the camera module.

* Moved public declarations in camera and lamp to a new file: bpy_types.h.
* Fixed minor bugs in material, rgbTuple and Lamp + other minor changes.
* Made part of the changes to conform to decided naming conventions.
This commit is contained in:
2003-06-24 07:21:17 +00:00
parent a0ea4df1ba
commit 06ee04fb05
25 changed files with 1330 additions and 1362 deletions

View File

@@ -0,0 +1,58 @@
# The Blender Module
"""
Here goes the Introduction to Blender Python
Let's see::
- What scripting is, why have it
- What is Python, links
- More about what scripting can give us
- Overview of the Blender Python modules
- Links to Blender, Blender Python, later: script lists
@author: The Blender Python Team
@requires: Blender 2.28 or newer, Python 2.? (2.0, 2.1, 2.2 ???) or newer
@version: 0.1
@see: U{www.blender.org<http://www.blender.org>}
@see: U{projects.blender.org<http://projects.blender.org>}
"""
def Set (request, data):
"""
Update settings in Blender
@type request: string
@param request: The setting to change:
- 'curframe': the current animation frame
@type data: int
@param data: The new value.
"""
def Get (request):
"""
Retrieve settings from Blender.
@type request: string
@param request: The setting data to be returned:
- 'curframe': the current animation frame
- 'curtime' : the current animation time
- 'staframe': the start frame of the animation
- 'endframe': the end frame of the animation
- 'filename': the name of the last file read or written
- 'version' : the Blender version number
@return: The requested data.
"""
def Redraw ():
"""
Redraw all 3D windows
"""
def ReleaseGlobalDict (bool = None):
"""
Define whether the global Python Interpreter dictionary should be cleared
after the script is run. Default is to clear (non-zero bool).
@type bool: an int, actually
@param bool: The flag to release (non-zero bool) or not (bool = 0) the dict.
if no argument is passed, this function simply returns the current
behavior.
@rtype: int
@return: A bool value (0 or 1) telling the current behavior.
"""

View File

@@ -9,8 +9,8 @@ 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
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
@@ -24,19 +24,19 @@ def New (type = 'persp', name = 'CamData'):
@param type: The Camera type: 'persp' or 'ortho'.
@type name: string
@param name: The Camera Data name.
@rtype: Camera
@rtype: Blender Camera
@return: The created Camera Data object.
"""
def Get (name = None):
"""
Get the Camera Data object(s).rom Blender.
Get the Camera Data object(s) from Blender.
@type name: string
@param name: The name of the Camera Data.
@rtype: Camera or a list of Cameras
@rtype: Blender Camera or a list of Blender Cameras
@return: It depends on the 'name' parameter:
- (name).The Camera Data object with the given name;
- (). A list with all Camera Data objects in the current Scene.
- (name): The Camera Data object with the given name;
- (): A list with all Camera Data objects in the current scene.
"""
class Camera:
@@ -45,42 +45,45 @@ class Camera:
======================
This object gives access to Camera-specific data in Blender.
@cvar name: The Camera Data name.
@cvar type: The type: 'persp':0 or 'ortho':1.
@cvar type: The Camera type: 'persp':0 or 'ortho':1.
@cvar mode: The mode flags: B{or'ed value}: 'showLimits':1, 'showMist':2.
@cvar lens: The lens value in [1.0, 250.0].
@cvar clipStart: The clip start value in [0.0, 100.0].
@cvar clipEnd: The clip end value in [1.0, 5000.0].
@cvar drawSize: The draw size value in [0.1, 10.0].
@warning: Most member variables assume values in some [Min, Max] interval.
When trying to set them, the given parameter will be clamped to lie in
that range: if val < Min, then val = Min, if val > Max, then val = Max.
"""
def getName(self):
def getName():
"""
Get the name of this Camera Data object.
@rtype: string
"""
def setName(self, name):
def setName(name):
"""
Set the name of this Camera Data object.
@type name: string
@param name: The new name.
"""
def getType(self):
def getType():
"""
Get this Camera's type.
@rtype: int
@return: 0 for 'persp' or 1 for 'ortho'.
"""
def setType(self, type):
def setType(type):
"""
Set this Camera's type.
@type type: string
@param type: The Camera type: 'persp' or 'ortho'.
"""
def getMode(self):
def getMode():
"""
Get this Camera's mode flags.
@rtype: int
@@ -88,10 +91,10 @@ class Camera:
resp. 01 and 10 in binary.
"""
def setMode(self, mode1 = None, mode2 = None):
def setMode(mode1 = None, mode2 = None):
"""
Set this Camera's mode flags. Mode strings given are turned 'on'.
Those not provided are turned 'off', so cam.setMode().- without
Those not provided are turned 'off', so cam.setMode() -- without
arguments -- turns off all mode flags for Camera cam.
@type mode1: string
@type mode2: string
@@ -99,58 +102,54 @@ class Camera:
@param mode2: A mode flag: 'showLimits' or 'showMist'.
"""
def getLens(self):
def getLens():
"""
Get the lens value.
@rtype: float
"""
def setLens(self, lens):
def setLens(lens):
"""
Set the lens value.
@type lens: float
@param lens: The new lens value.
@warning: The value will be clamped to the min/max limits of this variable.
"""
def getClipStart(self):
def getClipStart():
"""
Get the clip start value.
@rtype: float
"""
def setClipStart(self, clipStart):
def setClipStart(clipstart):
"""
Set the clip start value.
@type clipStart: float
@param clipStart: The new lens value.
@warning: The value will be clamped to the min/max limits of this variable.
@type clipstart: float
@param clipstart: The new lens value.
"""
def getClipEnd(self):
def getClipEnd():
"""
Get the clip end value.
@rtype: float
"""
def setClipEnd(self, clipEnd):
def setClipEnd(clipend):
"""
Set the clip end value.
@type clipEnd: float
@param clipEnd: The new clip end value.
@warning: The value will be clamped to the min/max limits of this variable.
@type clipend: float
@param clipend: The new clip end value.
"""
def getDrawSize(self):
def getDrawSize():
"""
Get the draw size value.
@rtype: float
"""
def setDrawSize(self, drawSize):
def setDrawSize(drawsize):
"""
Set the draw size value.
@type drawSize: float
@param drawSize: The new draw size value.
@warning: The value will be clamped to the min/max limits of this variable.
@type drawsize: float
@param drawsize: The new draw size value.
"""

View File

@@ -0,0 +1,319 @@
# Blender.Lamp module and the Lamp PyType object
"""
The Blender.Lamp submodule
This module provides control over B{Lamp Data} objects in Blender.
Example::
from Blender import Lamp
l = Lamp.New('Spot') # create new 'Spot' lamp data
l.setMode('square', 'shadow') # set these two lamp mode flags
ob = Object.New('Lamp') # create new lamp object
ob.link(l) # link lamp obj with lamp data
"""
def New (type = 'Lamp', name = 'LampData'):
"""
Create a new Lamp Data object.
@type type: string
@param type: The Lamp type: 'Lamp', 'Sun', 'Spot' or 'Hemi'.
@type name: string
@param name: The Lamp Data name.
@rtype: Blender Lamp
@return: The created Lamp Data object.
"""
def Get (name = None):
"""
Get the Lamp Data object(s) from Blender.
@type name: string
@param name: The name of the Lamp Data.
@rtype: Blender Lamp or a list of Blender Lamps
@return: It depends on the 'name' parameter:
- (name): The Lamp Data object with the given name;
- (): A list with all Lamp Data objects in the current scene.
"""
class Lamp:
"""
The Lamp Data object
====================
This object gives access to Lamp-specific data in Blender.
@cvar name: The Lamp Data name.
@cvar type: The Lamp type (see the Types dict).
@cvar Types: The Types dictionary.
- 'Lamp': 0
- 'Sun' : 1
- 'Spot': 2
- 'Hemi': 3
@cvar mode: The mode flags: B{or'ed value} of the flags in the Modes dict.
@cvar Modes: The Modes dictionary.
- 'Shadows'
- 'Halo'
- 'Layer'
- 'Quad'
- 'Negative'
- 'OnlyShadow'
- 'Sphere'
- 'Square'
@cvar samples: The number of shadow map samples in [1, 16].
@cvar bufferSize: The size of the shadow buffer in [512, 5120].
@cvar haloStep: Volumetric halo sampling frequency in [0, 12].
@cvar energy: The intensity of the light in [0.0, 10.0].
@cvar dist: The distance value in [0.1, 5000.0].
@cvar spotSize: The angle of the spot beam in degrees in [1.0, 180.0].
@cvar spotBlend: The softness of the spot edge in [0.0, 1.0].
@cvar clipStart: The shadow map clip start in [0.1, 1000.0].
@cvar clipEnd: The shadow map clip end in [1.0, 5000.0].
@cvar bias: The shadow map sampling bias in [0.01, 5.00].
@cvar softness: The size of the shadow sample area in [1.0, 100.0].
@cvar haloInt: The intensity of the spot halo in [0.0, 5.0].
@cvar quad1: Light intensity value 1 for a Quad lamp in [0.0, 1.0].
@cvar quad2: Light intensity value 2 for a Quad lamp in [0.0, 1.0].
@cvar col: The color of the light, with each rgb component in [0.0, 1.0].
This is an rgb tuple whose values can be accessed in many ways:
- as a tuple: lamp.col, lamp.col[0], same for 1 and 2.
- as a dictionary: lamp.col['R'], same for 'G' and 'B'.
- as an object: lamp.col.R, same for G and B.
@warning: Most member variables assume values in some [Min, Max] interval.
When trying to set them, the given parameter will be clamped to lie in
that range: if val < Min, then val = Min, if val > Max, then val = Max.
"""
def getName():
"""
Get the name of this Lamp Data object.
@rtype: string
"""
def setName(name):
"""
Set the name of this Lamp Data object.
@type name: string
@param name: The new name.
"""
def getType():
"""
Get this Lamp's type.
@rtype: int
"""
def setType(type):
"""
Set this Lamp's type.
@type type: string
@param type: The Lamp type: 'Lamp', 'Sun', 'Spot' or 'Hemi'.
"""
def getMode():
"""
Get this Lamp's mode flags.
@rtype: int
@return: B{OR'ed value}. Use the Modes dictionary to check which flags
are 'on'.
Example::
flags = mylamp.getMode()
if flags & mylamp.Modes['Shadows']:
print "This lamp produces shadows"
else:
print "The 'Shadows' flag is off"
"""
def setMode(m = None, m2 = None, m3 = None, m4 = None,
m5 = None, m6 = None, m7 = None, m8 = None):
"""
Set this Lamp's mode flags. Mode strings given are turned 'on'.
Those not provided are turned 'off', so lamp.setMode() -- without
arguments -- turns off all mode flags for Lamp lamp.
@type m: string
@param m: A mode flag. From 1 to 8 can be set at the same time.
"""
def getSamples():
"""
Get this lamp's samples value.
@rtype: int
"""
def setSamples(samples):
"""
Set the samples value.
@type samples: int
@param samples: The new samples value.
"""
def getBufferSize():
"""
Get this lamp's buffer size.
@rtype: int
"""
def setBufferSize(bufsize):
"""
Set the buffer size value.
@type bufsize: int
@param bufsize: The new buffer size value.
"""
def getHaloStep():
"""
Get this lamp's halo step value.
@rtype: int
"""
def setHaloStep(hastep):
"""
Set the halo step value.
@type hastep: int
@param hastep: The new halo step value.
"""
def getEnergy():
"""
Get this lamp's energy intensity value.
@rtype: float
"""
def setEnergy(energy):
"""
Set the energy intensity value.
@type energy: float
@param energy: The new energy value.
"""
def getDist():
"""
Get this lamp's distance value.
@rtype: float
"""
def setDist(distance):
"""
Set the distance value.
@type distance: float
@param distance: The new distance value.
"""
def getSpotSize():
"""
Get this lamp's spot size value.
@rtype: float
"""
def setSpotSize(spotsize):
"""
Set the spot size value.
@type spotsize: float
@param spotsize: The new spot size value.
"""
def getSpotBlend():
"""
Get this lamp's spot blend value.
@rtype: float
"""
def setSpotBlend(spotblend):
"""
Set the spot blend value.
@type spotblend: float
@param spotblend: The new spot blend value.
"""
def getClipStart():
"""
Get this lamp's clip start value.
@rtype: float
"""
def setClipStart(clipstart):
"""
Set the clip start value.
@type clipstart: float
@param clipstart: The new clip start value.
"""
def getClipEnd():
"""
Get this lamp's clip end value.
@rtype: float
"""
def setClipEnd(clipend):
"""
Set the clip end value.
@type clipend: float
@param clipend: The new clip end value.
"""
def getBias():
"""
Get this lamp's bias value.
@rtype: float
"""
def setBias(bias):
"""
Set the bias value.
@type bias: float
@param bias: The new bias value.
"""
def getSoftness():
"""
Get this lamp's softness value.
@rtype: float
"""
def setSoftness(softness):
"""
Set the softness value.
@type softness: float
@param softness: The new softness value.
"""
def getHaloInt():
"""
Get this lamp's halo intensity value.
@rtype: float
"""
def setHaloInt(haloint):
"""
Set the halo intensity value.
@type haloint: float
@param haloint: The new halo intensity value.
"""
def getQuad1():
"""
Get this lamp's quad 1 value.
@rtype: float
@warning: this only applies to Lamps with the 'Quad' flag on.
"""
def setQuad1(quad1):
"""
Set the quad 1 value.
@type quad1: float
@warning: this only applies to Lamps with the 'Quad' flag on.
"""
def getQuad2():
"""
Get this lamp's quad 2 value.
@rtype: float
@warning: this only applies to Lamps with the 'Quad' flag on.
"""
def setQuad2(quad2):
"""
Set the quad 2 value.
@type quad2: float
@param quad2: The new quad 2 value.
@warning: this only applies to Lamps with the 'Quad' flag on.
"""

View File

@@ -0,0 +1,137 @@
# Blender.Camera module and Camera PyType test file
# This also works with Lamp and Material, simply uncomment the right
# line below
MODULE = "Camera"
#MODULE = "Lamp"
#MODULE = "Material"
BPY_OBJECT = MODULE
LONG_STRING = "Supercalifragilisticspialidous"
import types, sys
import Blender
exec ("from Blender import %s" % MODULE)
def PRINT_HEADER(header, sep):
print "\n", sep * 79
print header
print sep * 79
def PRINT_UNDERLINED(str):
print "\n", str
print "-" * len(str)
def PRINT_AND_RM(arg, branch, d):
for a in arg:
if a in d:
d.remove(a)
print "\n%s.%s:" % (branch, a),
exec("print %s.%s" % (branch, a))
PRINT_HEADER("Testing the Blender.%s module" % MODULE, '=')
exec ("Module_dir = dir (%s)" % MODULE)
print "\ndir (%s):" % MODULE
print Module_dir
PRINT_AND_RM (["__name__", "__doc__"], MODULE, Module_dir)
for item in Module_dir:
hooked = 0
branch = "%s.%s" % (MODULE, item)
PRINT_HEADER(branch, "-")
exec ("item_type = type (%s)" % branch)
print item_type
exec ("sub_dir = dir(%s)" % branch)
PRINT_AND_RM (["__name__", "__doc__"], branch, sub_dir)
if item_type == types.BuiltinFunctionType:
PRINT_UNDERLINED ("Executing %s:" % branch)
exec ("result = %s()" % branch)
print "Returned value is: ", result
if item in ["Get", "get"] and not hooked:
if len(result):
obj = result[0]
hooked = 1
if hooked:
PRINT_HEADER(obj, "=")
exec ("obj_dir = dir(obj)")
print "\ndir():"
print obj_dir
methods = []
member_vars = []
for item in obj_dir:
exec ("item_type = type (obj.%s)" % item)
if item_type == types.BuiltinMethodType:
methods.append(item)
else:
member_vars.append(item)
PRINT_HEADER("%s Methods" % BPY_OBJECT, '-')
if methods: print methods
else: print "XXX No methods found in %s" % BPY_OBJECT
PRINT_HEADER("%s Member Variables" % BPY_OBJECT, '-')
if member_vars:
for m in member_vars:
PRINT_UNDERLINED(m)
exec ("mvalue = obj.%s" % m)
exec ("mtype = type (obj.%s)" % m)
mtype = str(mtype).split("'")[1]
print "%s: %s" % (mtype, mvalue)
M = m[0].upper() + m[1:]
setM = "set%s" % M
getM = "get%s" % M
if setM in methods:
print "There is a .%s() method." % setM
methods.remove(setM)
if mtype == 'str':
try:
print "Trying to set string to %s" % LONG_STRING
exec("obj.%s('%s')" % (setM, LONG_STRING))
exec("get_str = obj.%s()" % getM)
print "It returned:", get_str
len_str = len(get_str)
if len_str < 100:
print "It correctly clamped the string to %s chars." % len_str
except:
PRINT_HEADER("FAILED in .%s()" % setM, "X")
print sys.exc_info()[0]
elif mtype == 'float':
try:
exec("obj.%s(%d)" % (setM, -999999))
exec("result = obj.%s()" % getM)
print "%s's minimum value is %f" % (m, result)
exec("obj.%s(%d)" % (setM, 999999))
exec("result = obj.%s()" % getM)
print "%s's maximum value is %f" % (m, result)
except:
PRINT_HEADER("FAILED in %s or %s" % (setM, getM), "X")
print sys.exc_info()[0]
elif mtype == 'int':
try:
dict = M+"s"
if dict in member_vars:
exec("key = obj.%s.keys()[1]" % dict)
exec("obj.%s('%s')" % (setM, key))
exec("result = obj.%s()" % getM)
except:
PRINT_HEADER("FAILED in %s or %s" % (setM, getM), "X")
print sys.exc_info()[0]
if getM in methods:
print "There is a .%s() method." % getM,
methods.remove(getM)
exec("result = obj.%s()" % getM)
print "It returned:", result
else: print "XXX No member variables found in %s" % BPY_OBJECT
else: # the module .Get() function found nothing
PRINT_HEADER("Failed trying to %s.Get() a %s object"
% (MODULE, BPY_OBJECT), 'X')