2003-07-12 18:02:54 +00:00
|
|
|
# Blender.Image module and the Image PyType object
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
The Blender.Image submodule.
|
|
|
|
|
|
|
|
|
|
Image
|
|
|
|
|
=====
|
|
|
|
|
|
2005-02-09 05:19:24 +00:00
|
|
|
B{New}: L{Image.setFilename}.
|
New scripts:
- hotkeys, obdatacopier and renameobjectbyblock, all from Jean-Michel Soler (jms);
- bevel_center by Loic Berthe, suggested for inclusion by jms;
- doc_browser, by Daniel Dunbar (Zr)
Thanks to them for the new contributions!
(I included doc_browser at 'Misc' because only users interested in script writing would actually use it, but it could also be under 'Help'. Opinions?)
BPython related:
- Added scriptlink methods to object, lamp, camera and world.
- Object: added object.makeTrack and object.clearTrack (old track method).
- sys: made sys.exists(path) return 0 for not found; 1 for file, 2 for dir and -1 for neither.
- doc updates and fixes.
- made ONLOAD event work. G.f's SCENESCRIPT bit was being zeroed in set_app_data.
- Blender: updated functions Load and Save to support the builtin importers and exporters besides .blend (dxf, videoscape, vrml 1.0, stl, ...)
- Draw: added mouse wheel events.
- Scene: added scene.play to play back animations (like ALT+A and SHIFT+ALT+A). Makes a good counter, too, when the 'win' attribute is set to a space that doesn't "animate".
The scene.play() addition and the fix to ONLOAD scriptlinks is part of the work for a Blender demo mode. It already works, but I'll still add support for Radiosity calculations and fix a thing in main(): it executes onload scripts too early (BIF_Init), giving funny results in alt+a animations and renderings when firing up Blender. Loading after the program is up has no such problems. When I finish I'll post examples of demo mode scripts.
2004-07-03 05:17:04 +00:00
|
|
|
|
2003-07-12 18:02:54 +00:00
|
|
|
This module provides access to B{Image} objects in Blender.
|
|
|
|
|
|
|
|
|
|
Example::
|
|
|
|
|
import Blender
|
|
|
|
|
from Blender import Image
|
|
|
|
|
#
|
|
|
|
|
image = Image.Load("/path/to/my/image.png") # load an image file
|
|
|
|
|
print "Image from", image.getFilename(),
|
|
|
|
|
print "loaded to obj", image.getName())
|
|
|
|
|
image.setXRep(4) # set x tiling factor
|
|
|
|
|
image.setYRep(2) # set y tiling factor
|
|
|
|
|
print "All Images available now:", Image.Get()
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def Load (filename):
|
|
|
|
|
"""
|
|
|
|
|
Load the image called 'filename' into an Image object.
|
|
|
|
|
@type filename: string
|
|
|
|
|
@param filename: The full path to the image file.
|
|
|
|
|
@rtype: Blender Image
|
|
|
|
|
@return: A Blender Image object with the data from I{filename}.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def New (name):
|
|
|
|
|
"""
|
|
|
|
|
Create a new Image object (not implemented yet!).
|
|
|
|
|
@type name: string
|
|
|
|
|
@param name: The name of the new Image object.
|
|
|
|
|
@rtype: Blender Image
|
|
|
|
|
@return: A new Blender Image object.
|
|
|
|
|
@warn: This function wasn't implemented yet. It simply returns None.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def Get (name = None):
|
|
|
|
|
"""
|
|
|
|
|
Get the Image object(s) from Blender.
|
|
|
|
|
@type name: string
|
|
|
|
|
@param name: The name of the Image object.
|
|
|
|
|
@rtype: Blender Image or a list of Blender Images
|
|
|
|
|
@return: It depends on the I{name} parameter:
|
|
|
|
|
- (name): The Image object called I{name}, None if not found;
|
|
|
|
|
- (): A list with all Image objects in the current scene.
|
|
|
|
|
"""
|
|
|
|
|
|
2005-12-13 00:00:11 +00:00
|
|
|
def GetCurrent ():
|
|
|
|
|
"""
|
|
|
|
|
Get the currently displayed Image from Blenders UV/Image window.
|
|
|
|
|
When multiple images are displayed, the last active UV/Image windows image is used.
|
|
|
|
|
@rtype: Blender Image
|
|
|
|
|
@return: The Current Blender Image, If there is no current image it returns None.
|
|
|
|
|
"""
|
2003-07-12 18:02:54 +00:00
|
|
|
|
|
|
|
|
class Image:
|
|
|
|
|
"""
|
|
|
|
|
The Image object
|
|
|
|
|
================
|
2003-07-30 21:15:41 +00:00
|
|
|
This object gives access to Images in Blender.
|
2005-06-15 06:22:26 +00:00
|
|
|
@ivar name: The name of this Image object.
|
|
|
|
|
@ivar filename: The filename (path) to the image file loaded into this Image
|
2003-07-12 18:02:54 +00:00
|
|
|
object.
|
2005-06-15 06:22:26 +00:00
|
|
|
@ivar size: The [width, height] dimensions of the image (in pixels).
|
|
|
|
|
@ivar depth: The pixel depth of the image.
|
|
|
|
|
@ivar xrep: Texture tiling: the number of repetitions in the x (horizontal)
|
2003-07-12 18:02:54 +00:00
|
|
|
axis.
|
2005-06-15 06:22:26 +00:00
|
|
|
@ivar yrep: Texture tiling: the number of repetitions in the y (vertical)
|
2003-07-12 18:02:54 +00:00
|
|
|
axis.
|
2005-06-15 06:22:26 +00:00
|
|
|
@ivar bindcode: Texture's bind code (readonly).
|
2003-07-12 18:02:54 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def getName():
|
|
|
|
|
"""
|
|
|
|
|
Get the name of this Image object.
|
|
|
|
|
@rtype: string
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def getFilename():
|
|
|
|
|
"""
|
|
|
|
|
Get the filename of the image file loaded into this Image object.
|
|
|
|
|
@rtype: string
|
|
|
|
|
"""
|
|
|
|
|
|
2003-07-30 21:15:41 +00:00
|
|
|
def getSize():
|
|
|
|
|
"""
|
|
|
|
|
Get the [width, height] dimensions (in pixels) of this image.
|
|
|
|
|
@rtype: list of 2 ints
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def getDepth():
|
|
|
|
|
"""
|
|
|
|
|
Get the pixel depth of this image.
|
|
|
|
|
@rtype: int
|
|
|
|
|
"""
|
|
|
|
|
|
2005-05-22 18:43:29 +00:00
|
|
|
def getPixelF(x, y):
|
2005-04-30 19:30:35 +00:00
|
|
|
"""
|
|
|
|
|
Get the the colors of the current pixel in the form [r,g,b,a].
|
2005-05-22 18:43:29 +00:00
|
|
|
Returned values are floats normalized to 0.0 - 1.0.
|
2005-04-30 19:30:35 +00:00
|
|
|
Pixel coordinates are in the range from 0 to N-1. See L{getMaxXY}
|
|
|
|
|
@returns: [ r, g, b, a]
|
|
|
|
|
@rtype: list of 4 floats
|
|
|
|
|
@type x: int
|
|
|
|
|
@type y: int
|
|
|
|
|
@param x: the x coordinate of pixel.
|
|
|
|
|
@param y: the y coordinate of pixel.
|
|
|
|
|
"""
|
Patch #2758 Update of image module.
New Image methods from Austin Benesh:
- getPixelI(x, y)
- getMinXY()
- setPixelF(x, y, [r, g, b, a])
- setPixelI(x, y, [r, g, b, a])
- save()
sorry for the delay.
Thanks.
2005-08-10 17:50:18 +00:00
|
|
|
def getPixelI(x, y):
|
|
|
|
|
"""
|
|
|
|
|
Get the the colors of the current pixel in the form [r,g,b,a].
|
|
|
|
|
Returned values are ints normalized to 0 - 255.
|
|
|
|
|
Pixel coordinates are in the range from 0 to N-1. See L{getMaxXY}
|
|
|
|
|
@returns: [ r, g, b, a]
|
|
|
|
|
@rtype: list of 4 ints
|
|
|
|
|
@type x: int
|
|
|
|
|
@type y: int
|
|
|
|
|
@param x: the x coordinate of pixel.
|
|
|
|
|
@param y: the y coordinate of pixel.
|
|
|
|
|
"""
|
2005-04-30 19:30:35 +00:00
|
|
|
|
|
|
|
|
def getMaxXY():
|
|
|
|
|
"""
|
|
|
|
|
Get the x & y size for the image. Image coordinates range from 0 to size-1.
|
|
|
|
|
@returns: [x, y]
|
|
|
|
|
@rtype: list of 2 ints
|
|
|
|
|
"""
|
|
|
|
|
|
Patch #2758 Update of image module.
New Image methods from Austin Benesh:
- getPixelI(x, y)
- getMinXY()
- setPixelF(x, y, [r, g, b, a])
- setPixelI(x, y, [r, g, b, a])
- save()
sorry for the delay.
Thanks.
2005-08-10 17:50:18 +00:00
|
|
|
def getMinXY():
|
|
|
|
|
"""
|
|
|
|
|
Get the x & y origin for the image. Image coordinates range from 0 to size-1.
|
|
|
|
|
@returns: [x, y]
|
|
|
|
|
@rtype: list of 2 ints
|
|
|
|
|
"""
|
|
|
|
|
|
2003-07-12 18:02:54 +00:00
|
|
|
def getXRep():
|
|
|
|
|
"""
|
|
|
|
|
Get the number of repetitions in the x (horizontal) axis for this Image.
|
|
|
|
|
This is for texture tiling.
|
|
|
|
|
@rtype: int
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def getYRep():
|
|
|
|
|
"""
|
|
|
|
|
Get the number of repetitions in the y (vertical) axis for this Image.
|
|
|
|
|
This is for texture tiling.
|
|
|
|
|
@rtype: int
|
|
|
|
|
"""
|
2004-07-18 15:54:17 +00:00
|
|
|
|
|
|
|
|
def getBindCode():
|
|
|
|
|
"""
|
BPython:
- Blender.Window: added function GetPerspMatrix() (Tom Musgrave's patch, thanks);
- added Chris Want's patch to tell argc, argv to the Python interpreter (thanks, Hos);
- Blender.Image: added image.glFree() to free textures bound by the recently added
image.glLoad() (both suggested by Campbell Barton -- thanks, with these Blender can
be used to load textures for scripts);
- Blender.Sound: removed for now at least a few get/set methods of vars that can't be
accessed via interface;
- renamed Get/makeActive to Get/setCurrent in Blender.World (actually added alias for
now), same in Blender.Sound: renamed makeActive to setCurrent. Stephen Swaney
pointed this some weeks ago, we should stick to one naming convention.
- added documentation for Sound and Window.Theme modules and the other added
functions, made other small updates.
- Blender.Object: made 'worldspace' become the default output of .getMatrix and .mat/.matrix:
after reading a discussion on blender.org's Python forum where eeshlo mentioned the
pre 2.34 default was worldspace, I took a better look at Blender's relevant code,
confirmed, talked to Theeth about this and as he suggested am changing the default
back to 'worldspace'.
2004-10-20 05:51:24 +00:00
|
|
|
Get the Image's bindcode. This is for texture loading using BGL calls.
|
|
|
|
|
See, for example, L{BGL.glBindTexture} and L{glLoad}.
|
2004-07-18 15:54:17 +00:00
|
|
|
@rtype: int
|
|
|
|
|
"""
|
|
|
|
|
|
2004-05-25 10:36:58 +00:00
|
|
|
def reload():
|
|
|
|
|
"""
|
|
|
|
|
Reloads this image from the filesystem. If used within a loop you need to
|
|
|
|
|
redraw the Window to see the change in the image, e.g. with
|
|
|
|
|
Window.RedrawAll().
|
|
|
|
|
@warn: if the image file is corrupt or still being written, it will be
|
|
|
|
|
replaced by a blank image in Blender, but no error will be returned.
|
|
|
|
|
@returns: None
|
|
|
|
|
"""
|
2003-07-12 18:02:54 +00:00
|
|
|
|
BPython:
- Blender.Window: added function GetPerspMatrix() (Tom Musgrave's patch, thanks);
- added Chris Want's patch to tell argc, argv to the Python interpreter (thanks, Hos);
- Blender.Image: added image.glFree() to free textures bound by the recently added
image.glLoad() (both suggested by Campbell Barton -- thanks, with these Blender can
be used to load textures for scripts);
- Blender.Sound: removed for now at least a few get/set methods of vars that can't be
accessed via interface;
- renamed Get/makeActive to Get/setCurrent in Blender.World (actually added alias for
now), same in Blender.Sound: renamed makeActive to setCurrent. Stephen Swaney
pointed this some weeks ago, we should stick to one naming convention.
- added documentation for Sound and Window.Theme modules and the other added
functions, made other small updates.
- Blender.Object: made 'worldspace' become the default output of .getMatrix and .mat/.matrix:
after reading a discussion on blender.org's Python forum where eeshlo mentioned the
pre 2.34 default was worldspace, I took a better look at Blender's relevant code,
confirmed, talked to Theeth about this and as he suggested am changing the default
back to 'worldspace'.
2004-10-20 05:51:24 +00:00
|
|
|
def glLoad():
|
|
|
|
|
"""
|
|
|
|
|
Load this image's data into OpenGL texture memory, if it is not already
|
|
|
|
|
loaded (image.bindcode is 0 if it is not loaded yet).
|
|
|
|
|
@note: Usually you don't need to call this method. It is only necessary
|
|
|
|
|
if you want to draw textured objects in the Scripts window and the
|
|
|
|
|
image's bind code is zero at that moment, otherwise Blender itself can
|
|
|
|
|
take care of binding / unbinding textures. Calling this method for an
|
|
|
|
|
image with nonzero bind code simply returns the image's bind code value
|
|
|
|
|
(see L{getBindCode}).
|
|
|
|
|
@rtype: int
|
|
|
|
|
@returns: the texture's bind code.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def glFree():
|
|
|
|
|
"""
|
|
|
|
|
Delete this image's data from OpenGL texture memory, only (the image itself
|
|
|
|
|
is not removed from Blender's memory). Internally, glDeleteTextures (see
|
|
|
|
|
L{BGL.glDeleteTextures}) is used, but this method also updates Blender's
|
|
|
|
|
Image object so that its bind code is set to 0. See also L{Image.glLoad},
|
|
|
|
|
L{Image.getBindCode}.
|
|
|
|
|
"""
|
|
|
|
|
|
2003-07-12 18:02:54 +00:00
|
|
|
def setName(name):
|
|
|
|
|
"""
|
|
|
|
|
Set the name of this Image object.
|
|
|
|
|
@type name: string
|
|
|
|
|
@param name: The new name.
|
|
|
|
|
"""
|
|
|
|
|
|
2005-02-09 05:19:24 +00:00
|
|
|
def setFilename(name):
|
|
|
|
|
"""
|
|
|
|
|
Change the filename of this Image object.
|
|
|
|
|
@type name: string
|
|
|
|
|
@param name: The new full filename.
|
|
|
|
|
@warn: use this with caution and note that the filename is truncated if
|
|
|
|
|
larger than 160 characters.
|
|
|
|
|
"""
|
|
|
|
|
|
2003-07-12 18:02:54 +00:00
|
|
|
def setXRep(xrep):
|
|
|
|
|
"""
|
|
|
|
|
Texture tiling: set the number of x repetitions for this Image.
|
|
|
|
|
@type xrep: int
|
|
|
|
|
@param xrep: The new value in [1, 16].
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def setYRep(yrep):
|
|
|
|
|
"""
|
|
|
|
|
Texture tiling: set the number of y repetitions for this Image.
|
|
|
|
|
@type yrep: int
|
|
|
|
|
@param yrep: The new value in [1, 16].
|
|
|
|
|
"""
|
Patch #2758 Update of image module.
New Image methods from Austin Benesh:
- getPixelI(x, y)
- getMinXY()
- setPixelF(x, y, [r, g, b, a])
- setPixelI(x, y, [r, g, b, a])
- save()
sorry for the delay.
Thanks.
2005-08-10 17:50:18 +00:00
|
|
|
|
|
|
|
|
def setPixelF(x, y, (r, g, b,a )):
|
|
|
|
|
"""
|
|
|
|
|
Set the the colors of the current pixel in the form [r,g,b,a].
|
|
|
|
|
Color values must be floats in the range 0.0 - 1.0.
|
|
|
|
|
Pixel coordinates are in the range from 0 to N-1. See L{getMaxXY}
|
|
|
|
|
@type x: int
|
|
|
|
|
@type y: int
|
|
|
|
|
@type r: float
|
|
|
|
|
@type g: float
|
|
|
|
|
@type b: float
|
|
|
|
|
@type a: float
|
|
|
|
|
@returns: nothing
|
|
|
|
|
@rtype: none
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def setPixelI(x, y, (r, g, b, a)):
|
|
|
|
|
"""
|
|
|
|
|
Set the the colors of the current pixel in the form [r,g,b,a].
|
|
|
|
|
Color values must be ints in the range 0 - 255.
|
|
|
|
|
Pixel coordinates are in the range from 0 to N-1. See L{getMaxXY}
|
|
|
|
|
@type x: int
|
|
|
|
|
@type y: int
|
|
|
|
|
@type r: int
|
|
|
|
|
@type g: int
|
|
|
|
|
@type b: int
|
|
|
|
|
@type a: int
|
|
|
|
|
@returns: nothing
|
|
|
|
|
@rtype: none
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def save():
|
|
|
|
|
"""
|
|
|
|
|
Saves the current image.
|
|
|
|
|
@returns: nothing
|
|
|
|
|
@rtype: none
|
|
|
|
|
"""
|