Changeset View
Standalone View
doc/python_api/rst/bge.texture.rst
| Context not available. | |||||
| Video Texture (bge.texture) | Video Texture (bge.texture) | ||||
| =========================== | =========================== | ||||
| ***** | ************ | ||||
| Intro | Introduction | ||||
| ***** | ************ | ||||
| The bge.texture module allows you to manipulate textures during the game. | The bge.texture module allows you to manipulate textures during the game. | ||||
| Context not available. | |||||
| In addition, you can apply filters on the images before sending them to the GPU, allowing video effect: blue screen, color band, gray, normal map. | In addition, you can apply filters on the images before sending them to the GPU, allowing video effect: blue screen, color band, gray, normal map. | ||||
| bge.texture uses FFmpeg to load images and videos. All the formats and codecs that FFmpeg supports are supported by this module, including but not limited to:: | bge.texture uses FFmpeg to load images and videos. All the formats and codecs that FFmpeg supports are supported by this module, including but not limited to: | ||||
| * AVI | * AVI | ||||
| * Ogg | * Ogg | ||||
| Context not available. | |||||
| * JPG | * JPG | ||||
| The principle is simple: first you identify a texture on an existing object using | The principle is simple: first you identify a texture on an existing object using | ||||
| the :materialID: function, then you create a new texture with dynamic content | the :class:`~bge.texture.materialID` function, then you create a new texture with dynamic content | ||||
| and swap the two textures in the GPU. | and swap the two textures in the GPU. | ||||
| The GE is not aware of the substitution and continues to display the object as always, | The GE is not aware of the substitution and continues to display the object as always, | ||||
| Context not available. | |||||
| .. module:: bge.texture | .. module:: bge.texture | ||||
| .. include:: ../examples/bge.texture.py | |||||
| :start-line: 1 | |||||
| :end-line: 5 | |||||
| .. literalinclude:: ../examples/bge.texture.py | .. literalinclude:: ../examples/bge.texture.py | ||||
| :language: rest | :lines: 7- | ||||
| :lines: 2-4 | |||||
| .. literalinclude:: ../examples/bge.texture.py | |||||
| :lines: 6- | |||||
| .. literalinclude:: ../examples/bge.texture.1.py | |||||
| :language: rest | |||||
| :lines: 2-6 | |||||
| .. include:: ../examples/bge.texture.1.py | |||||
| :start-line: 1 | |||||
| :end-line: 6 | |||||
| .. literalinclude:: ../examples/bge.texture.1.py | .. literalinclude:: ../examples/bge.texture.1.py | ||||
| :lines: 8- | :lines: 8- | ||||
| ************* | |||||
| Video classes | |||||
| ************* | |||||
| .. class:: VideoFFmpeg(file [, capture=-1, rate=25.0, width=0, height=0]) | .. class:: VideoFFmpeg(file [, capture=-1, rate=25.0, width=0, height=0]) | ||||
| FFmpeg video source | FFmpeg video source. | ||||
| :arg file: Path to the video to load; if capture >= 0 on Windows, this parameter will not be used. | |||||
| :type file: str | |||||
| :arg capture: Capture device number; if >= 0, the corresponding webcam will be used. (optional) | |||||
| :type capture: int | |||||
| :arg rate: Capture rate. (optional, used only if capture >= 0) | |||||
| :type rate: float | |||||
| :arg width: Capture width. (optional, used only if capture >= 0) | |||||
| :type width: int | |||||
| :arg height: Capture height. (optional, used only if capture >= 0) | |||||
| :type height: int | |||||
| .. attribute:: status | .. attribute:: status | ||||
| video status | Video status. (readonly) | ||||
| :type: int | |||||
| :value: :data:`SOURCE_ERROR`, | |||||
| :data:`SOURCE_EMPTY`, | |||||
| :data:`SOURCE_READY`, | |||||
| :data:`SOURCE_PLAYING`, | |||||
| :data:`SOURCE_STOPPED` | |||||
| .. attribute:: range | .. attribute:: range | ||||
| replay range | Replay range. | ||||
| :type: sequence of two floats | |||||
| .. attribute:: repeat | .. attribute:: repeat | ||||
| repeat count, -1 for infinite repeat | Repeat count, -1 for infinite repeat. | ||||
| :type: int | :type: int | ||||
| .. attribute:: framerate | .. attribute:: framerate | ||||
| frame rate | Frame rate. | ||||
| :type: float | :type: float | ||||
| .. attribute:: valid | .. attribute:: valid | ||||
| Tells if an image is available | Tells if an image is available. (readonly) | ||||
| :type: bool | :type: bool | ||||
| .. attribute:: image | .. attribute:: image | ||||
| image data | Image data. (readonly) | ||||
| :type: :class:`~bgl.Buffer` or None | |||||
| .. attribute:: size | .. attribute:: size | ||||
| image size | Image size. (readonly) | ||||
| :type: tuple of two ints | |||||
| .. attribute:: scale | .. attribute:: scale | ||||
| fast scale of image (near neighbour) | Fast scale of image (near neighbour). | ||||
| :type: bool | |||||
| .. attribute:: flip | .. attribute:: flip | ||||
| flip image vertically | Flip image vertically. | ||||
| :type: bool | |||||
| .. attribute:: filter | .. attribute:: filter | ||||
| pixel filter | Pixel filter. | ||||
| :type: :class:`FilterBGR24`, | |||||
| :class:`FilterBlueScreen`, | |||||
| :class:`FilterColor`, | |||||
| :class:`FilterGray`, | |||||
| :class:`FilterLevel`, | |||||
| :class:`FilterNormal`, | |||||
| :class:`FilterRGB24`, | |||||
| :class:`FilterRGBA32` | |||||
| .. attribute:: preseek | .. attribute:: preseek | ||||
| number of frames of preseek | Number of frames of preseek. | ||||
| :type: int | :type: int | ||||
| .. attribute:: deinterlace | .. attribute:: deinterlace | ||||
| deinterlace image | Deinterlace image. | ||||
| :type: bool | :type: bool | ||||
| .. method:: play() | .. method:: play() | ||||
| Play (restart) video | Play (restart) video. | ||||
| :return: Whether the video was ready or stopped. | |||||
| :rtype: bool | |||||
| .. method:: pause() | .. method:: pause() | ||||
| pause video | Pause video. | ||||
| :return: Whether the video was playing. | |||||
| :rtype: bool | |||||
| .. method:: stop() | .. method:: stop() | ||||
| stop video (play will replay it from start) | Stop video (play will replay it from start). | ||||
| :return: Whether the video was playing. | |||||
| :rtype: bool | |||||
| .. method:: refresh() | .. method:: refresh() | ||||
| Refresh video - get its status | Refresh video - get its status. | ||||
| :return: The video's status (:data:`SOURCE_ERROR`, | |||||
| :data:`SOURCE_EMPTY`, | |||||
| :data:`SOURCE_READY`, | |||||
| :data:`SOURCE_PLAYING`, | |||||
| :data:`SOURCE_STOPPED`). | |||||
| :rtype: int | |||||
| ************* | |||||
| Image classes | |||||
| ************* | |||||
| .. class:: ImageFFmpeg(file) | .. class:: ImageFFmpeg(file) | ||||
| FFmpeg image source | FFmpeg image source. | ||||
| :arg file: Path to the image to load. | |||||
| :type file: str | |||||
| .. attribute:: status | .. attribute:: status | ||||
| video status | Image status. (readonly) | ||||
| :type: int | |||||
| :value: :data:`SOURCE_ERROR`, | |||||
| :data:`SOURCE_EMPTY`, | |||||
| :data:`SOURCE_READY`, | |||||
| :data:`SOURCE_PLAYING`, | |||||
| :data:`SOURCE_STOPPED` | |||||
| .. attribute:: valid | .. attribute:: valid | ||||
| Tells if an image is available | Tells if an image is available. (readonly) | ||||
| :type: bool | :type: bool | ||||
| .. attribute:: image | .. attribute:: image | ||||
| image data | Image data. (readonly) | ||||
| :type: :class:`~bgl.Buffer` or None | |||||
| .. attribute:: size | .. attribute:: size | ||||
| image size | Image size. (readonly) | ||||
| :type: tuple of two ints | |||||
| .. attribute:: scale | .. attribute:: scale | ||||
| fast scale of image (near neighbour) | Fast scale of image (near neighbour). | ||||
| :type: bool | |||||
| .. attribute:: flip | .. attribute:: flip | ||||
| flip image vertically | Flip image vertically. | ||||
| :type: bool | |||||
| .. attribute:: filter | .. attribute:: filter | ||||
| pixel filter | Pixel filter. | ||||
| :type: :class:`FilterBGR24`, | |||||
| :class:`FilterBlueScreen`, | |||||
| :class:`FilterColor`, | |||||
| :class:`FilterGray`, | |||||
| :class:`FilterLevel`, | |||||
| :class:`FilterNormal`, | |||||
| :class:`FilterRGB24`, | |||||
| :class:`FilterRGBA32` | |||||
| .. method:: refresh() | .. method:: refresh() | ||||
| Refresh image, i.e. load it | Refresh image, i.e. load it. | ||||
| :return: the video's status (:data:`SOURCE_ERROR`, | |||||
| :data:`SOURCE_EMPTY`, | |||||
| :data:`SOURCE_READY`, | |||||
| :data:`SOURCE_PLAYING`, | |||||
| :data:`SOURCE_STOPPED`) | |||||
| :rtype: int | |||||
| .. method:: reload([newname]) | .. method:: reload([newname]) | ||||
| Reload image, i.e. reopen it | Reload image, i.e. reopen it. | ||||
| :arg newname: Path to a new image. (optional) | |||||
| :type newname: str | |||||
| .. class:: ImageBuff() | .. class:: ImageBuff(width, height[, color, scale]) | ||||
| Image source from image buffer | Image source from image buffer. | ||||
| :arg width: Width of the image. | |||||
| :type width: int | |||||
| :arg height: Height of the image. | |||||
| :type height: int | |||||
| :arg color: Image uses color data. (optional) | |||||
| :type color: bool | |||||
hg1: That is wrong. The value is a python integer converted to an unsigned char 0-255 (black to… | |||||
Not Done Inline ActionsWhoops, yes, you're right, I mixed up "b" parsing arguments with bools... Matpi: Whoops, yes, you're right, I mixed up "b" parsing arguments with bools... | |||||
| :arg scale: Image uses scaling. (optional) | |||||
| :type scale: bool | |||||
| .. attribute:: filter | .. attribute:: filter | ||||
| pixel filter | Pixel filter. | ||||
| :type: :class:`FilterBGR24`, | |||||
| :class:`FilterBlueScreen`, | |||||
| :class:`FilterColor`, | |||||
| :class:`FilterGray`, | |||||
| :class:`FilterLevel`, | |||||
| :class:`FilterNormal`, | |||||
| :class:`FilterRGB24`, | |||||
| :class:`FilterRGBA32` | |||||
| .. attribute:: flip | .. attribute:: flip | ||||
| flip image vertically | Flip image vertically. | ||||
| :type: bool | |||||
| .. attribute:: image | .. attribute:: image | ||||
| image data | Image data. (readonly) | ||||
| :type: :class:`~bgl.Buffer` or None | |||||
| .. method:: load(imageBuffer, width, height) | .. method:: load(imageBuffer, width, height) | ||||
| Load image from buffer | Load image from buffer. | ||||
| .. method:: plot(imageBuffer, width, height, positionX, positionY) | :arg imageBuffer: Buffer to load the image from. | ||||
| :type imageBuffer: :class:`bgl.Buffer` or Python object implementing the buffer protocol (f.ex. bytes) | |||||
| update image buffer | :arg width: Width of the image to load. | ||||
| :type width: int | |||||
| :arg height: Height of the image to load. | |||||
| :type height: int | |||||
| .. method:: plot(imageBuffer, width, height, positionX, positionY[, mode=1000]) | |||||
Not Done Inline ActionspositionY [, mode=IMB_BLEND_COPY]) or positionY, [mode=IMB_BLEND_COPY]) will look better. hg1: positionY [, mode=IMB_BLEND_COPY]) or positionY, [mode=IMB_BLEND_COPY]) will look better. | |||||
Not Done Inline ActionsDon't agree here: this is the standard way to do it, look for example at os.getenv (took python 2.7 API because it uses nearly the same theme as Blender API doc). Matpi: Don't agree here: this is the standard way to do it, look for example at [[ https://docs.python. | |||||
Not Done Inline ActionsOk, changed it to key=default_value to reflect Blender's standard. Matpi: Ok, changed it to key=default_value to reflect Blender's standard. | |||||
Not Done Inline ActionsYes I know, but for me it looks ugly. Maybe it is better to remove the square bracket. I looked into the Blender API and I don't find any methods which are using square bracket for optional arguments. hg1: Yes I know, but for me it looks ugly. Maybe it is better to remove the square bracket. I looked… | |||||
Not Done Inline ActionsSorry, I answered but forgot to submit my answer... :-/ I actually discussed with Campbell, and he told me that in Blender the "defaults" solution is in use rather than the "square brackets" one. My last diff shows that change. Sorry again for the inconvenience. Matpi: Sorry, I answered but forgot to submit my answer... :-/
I actually discussed with Campbell… | |||||
| Update image buffer. | |||||
| :arg imageBuffer: Buffer to load the new data from. | |||||
| :type imageBuffer: :class:`bgl.Buffer`, :class:`ImageBuff` or Python object implementing the buffer protocol (f.ex. bytes) | |||||
| :arg width: Width of the data to load. | |||||
| :type width: int | |||||
| :arg height: Height of the data to load. | |||||
| :type height: int | |||||
| :arg positionX: Left boundary of the region to be drawn on. | |||||
| :type positionX: int | |||||
| :arg positionY: Upper boundary of the region to be drawn on. | |||||
| :type positionY: int | |||||
| :arg mode: Drawing mode (:data:`IMB_BLEND_MIX`, | |||||
| :data:`IMB_BLEND_ADD`, | |||||
| :data:`IMB_BLEND_SUB`, | |||||
| :data:`IMB_BLEND_MUL`, | |||||
| :data:`IMB_BLEND_LIGHTEN`, | |||||
| :data:`IMB_BLEND_DARKEN`, | |||||
| :data:`IMB_BLEND_ERASE_ALPHA`, | |||||
| :data:`IMB_BLEND_ADD_ALPHA`, | |||||
| :data:`IMB_BLEND_OVERLAY`, | |||||
| :data:`IMB_BLEND_HARDLIGHT`, | |||||
| :data:`IMB_BLEND_COLORBURN`, | |||||
| :data:`IMB_BLEND_LINEARBURN`, | |||||
| :data:`IMB_BLEND_COLORDODGE`, | |||||
| :data:`IMB_BLEND_SCREEN`, | |||||
| :data:`IMB_BLEND_SOFTLIGHT`, | |||||
| :data:`IMB_BLEND_PINLIGHT`, | |||||
| :data:`IMB_BLEND_VIVIDLIGHT`, | |||||
| :data:`IMB_BLEND_LINEARLIGHT`, | |||||
| :data:`IMB_BLEND_DIFFERENCE`, | |||||
| :data:`IMB_BLEND_EXCLUSION`, | |||||
| :data:`IMB_BLEND_HUE`, | |||||
| :data:`IMB_BLEND_SATURATION`, | |||||
| :data:`IMB_BLEND_LUMINOSITY`, | |||||
| :data:`IMB_BLEND_COLOR`, | |||||
| :data:`IMB_BLEND_COPY`, | |||||
| :data:`IMB_BLEND_COPY_RGB`, | |||||
| :data:`IMB_BLEND_COPY_ALPHA`). (optional) | |||||
Not Done Inline ActionsI hope you know, if you don't make a list, sphinx will align vertical text still horizontal. The output will look like this.
hg1: I hope you know, if you don't make a list, sphinx will align vertical text still horizontal. | |||||
Not Done Inline ActionsYes, I know, but lists aren't supported into arguments AFAIK (look at the compiled doc for 2.74 -> nothing shown). The only way I found was to make a simple list, even if horizontal. But I'd be very happy to find a way to make vertical lists... Matpi: Yes, I know, but lists aren't supported into arguments AFAIK (look at the compiled doc for 2.74… | |||||
| :type mode: int | |||||
| .. attribute:: scale | .. attribute:: scale | ||||
| fast scale of image (near neighbour) | Fast scale of image (near neighbour). | ||||
| :type: bool | |||||
| .. attribute:: size | .. attribute:: size | ||||
| image size | Image size. (readonly) | ||||
| :type: tuple of two ints | |||||
| .. attribute:: valid | .. attribute:: valid | ||||
| bool to tell if an image is available | Tells if an image is available. (readonly) | ||||
| :type: bool | |||||
| .. class:: ImageMirror(scene) | .. class:: ImageMirror(scene, observer, mirror[, material]) | ||||
| Image source from mirror | Image source from mirror. | ||||
| :arg scene: Scene in which the image has to be taken. | |||||
| :type scene: :class:`~bge.types.KX_Scene` | |||||
| :arg observer: Reference object for the mirror (the object from which the mirror has to be looked at, for example a camera). | |||||
| :type observer: :class:`~bge.types.KX_GameObject` | |||||
| :arg mirror: Object holding the mirror. | |||||
| :type mirror: :class:`~bge.types.KX_GameObject` | |||||
| :arg material: ID of the mirror's material to be used for mirroring. (optional) | |||||
| :type material: int | |||||
| .. attribute:: alpha | .. attribute:: alpha | ||||
| use alpha in texture | Use alpha in texture. | ||||
| :type: bool | |||||
| .. attribute:: background | .. attribute:: background | ||||
| background color | Background color. | ||||
| :type: sequence of four integers in [0, 255] | |||||
| .. attribute:: capsize | .. attribute:: capsize | ||||
| size of render area | Size of render area. | ||||
| :type: sequence of two ints | |||||
| .. attribute:: clip | .. attribute:: clip | ||||
| clipping distance | Clipping distance. | ||||
| :type: float in [0.01, 5000.0] | |||||
| .. attribute:: filter | .. attribute:: filter | ||||
| pixel filter | Pixel filter. | ||||
| :type: :class:`FilterBGR24`, | |||||
| :class:`FilterBlueScreen`, | |||||
| :class:`FilterColor`, | |||||
| :class:`FilterGray`, | |||||
| :class:`FilterLevel`, | |||||
| :class:`FilterNormal`, | |||||
| :class:`FilterRGB24`, | |||||
| :class:`FilterRGBA32` | |||||
| .. attribute:: flip | .. attribute:: flip | ||||
| flip image vertically | Flip image vertically. | ||||
| :type: bool | |||||
| .. attribute:: image | .. attribute:: image | ||||
| image data | Image data. (readonly) | ||||
| :type: :class:`~bgl.Buffer` or None | |||||
Not Done Inline ActionsThe attribute image returns a integer list [r,g,b,a]. Range: 0 to 255. hg1: The attribute image returns a integer list [r,g,b,a]. Range: 0 to 255.
| |||||
Not Done Inline ActionsDon't agree, look ImageBase.cpp/Image_getImage or test. Or am I completely wrong? Matpi: Don't agree, look ImageBase.cpp/Image_getImage or test. Or am I completely wrong? | |||||
Not Done Inline ActionsYes you are right, it now prints out Buffer(GL_BYTE, [...]). In previous it returns only a list in the printout. hg1: Yes you are right, it now prints out Buffer(GL_BYTE, [...]). In previous it returns only a list… | |||||
| .. method:: refresh(imageMirror) | .. method:: refresh() | ||||
| Refresh image - invalidate its current content | Refresh image - invalidate its current content. | ||||
| .. attribute:: scale | .. attribute:: scale | ||||
| fast scale of image (near neighbour) | Fast scale of image (near neighbour). | ||||
| :type: bool | |||||
| .. attribute:: size | .. attribute:: size | ||||
| image size | Image size (readonly). | ||||
| :type: tuple of two ints | |||||
| .. attribute:: valid | .. attribute:: valid | ||||
| bool to tell if an image is available | Tells if an image is available. (readonly) | ||||
| :type: bool | |||||
| .. attribute:: whole | .. attribute:: whole | ||||
| use whole viewport to render | Use whole viewport to render. | ||||
| :type: bool | |||||
| .. class:: ImageMix() | .. class:: ImageMix | ||||
| Image mixer | Image mixer. | ||||
| .. attribute:: filter | .. attribute:: filter | ||||
| pixel filter | Pixel filter. | ||||
| :type: :class:`FilterBGR24`, | |||||
| :class:`FilterBlueScreen`, | |||||
| :class:`FilterColor`, | |||||
| :class:`FilterGray`, | |||||
| :class:`FilterLevel`, | |||||
| :class:`FilterNormal`, | |||||
| :class:`FilterRGB24`, | |||||
| :class:`FilterRGBA32` | |||||
| .. attribute:: flip | .. attribute:: flip | ||||
| flip image vertically | Flip image vertically. | ||||
| .. method:: getSource(imageMix) | :type: bool | ||||
| get image source | |||||
| .. method:: getWeight(imageMix) | |||||
| get image source weight | |||||
| .. method:: getSource(id) | |||||
| Get image source. | |||||
| :arg id: Identifier of the source to get. | |||||
| :type id: str | |||||
| :return: Image source. | |||||
| :rtype: :class:`VideoFFmpeg`, | |||||
| :class:`ImageFFmpeg`, | |||||
| :class:`ImageBuff`, | |||||
| :class:`ImageMirror`, | |||||
| :class:`ImageMix`, | |||||
| :class:`ImageRender`, | |||||
| :class:`ImageViewport` | |||||
| .. method:: getWeight(id) | |||||
| Get image source weight. | |||||
| :arg id: Identifier of the source. | |||||
| :type id: str | |||||
| :return: Weight of the source. | |||||
| :rtype: int | |||||
| .. attribute:: image | .. attribute:: image | ||||
| image data | Image data. (readonly) | ||||
| :type: :class:`~bgl.Buffer` or None | |||||
| .. method:: refresh(imageMix) | .. method:: refresh() | ||||
| Refresh image - invalidate its current content | Refresh image - invalidate its current content. | ||||
| .. attribute:: scale | .. attribute:: scale | ||||
| fast scale of image (near neighbour) | Fast scale of image (near neighbour). | ||||
| .. method:: setSource(imageMix) | :type: bool | ||||
| set image source | .. attribute:: size | ||||
| .. method:: setWeight(imageMix) | |||||
| set image source weight | Image size. (readonly) | ||||
| :type: tuple of two ints | |||||
| .. method:: setSource(id, image) | |||||
| Set image source - all sources must have the same size. | |||||
| :arg id: Identifier of the source to set. | |||||
| :type id: str | |||||
| :arg image: Image source. | |||||
| :type image: :class:`VideoFFmpeg`, | |||||
| :class:`ImageFFmpeg`, | |||||
| :class:`ImageBuff`, | |||||
| :class:`ImageMirror`, | |||||
| :class:`ImageMix`, | |||||
| :class:`ImageRender`, | |||||
| :class:`ImageViewport` | |||||
| .. method:: setWeight(id, weight) | |||||
| Set image source weight - the sum of the weights should be 256 to get full color intensity in the output. | |||||
| :arg id: Identifier of the source. | |||||
| :type id: str | |||||
| :arg weight: Weight of the source. | |||||
| :type weight: int | |||||
| .. attribute:: valid | .. attribute:: valid | ||||
| bool to tell if an image is available | Tells if an image is available. (readonly) | ||||
| :type: bool | |||||
| .. class:: ImageRender(scene, camera) | .. class:: ImageRender(scene, camera) | ||||
| Image source from render | Image source from render. | ||||
| :arg scene: Scene in which the image has to be taken. | |||||
| :type scene: :class:`~bge.types.KX_Scene` | |||||
| :arg camera: Camera from which the image has to be taken. | |||||
| :type camera: :class:`~bge.types.KX_Camera` | |||||
| .. attribute:: alpha | .. attribute:: alpha | ||||
| use alpha in texture | Use alpha in texture. | ||||
| :type: bool | |||||
| .. attribute:: background | .. attribute:: background | ||||
| background color | Background color. | ||||
| :type: sequence of four integers in [0, 255] | |||||
| .. attribute:: capsize | .. attribute:: capsize | ||||
| size of render area | Size of render area. | ||||
| :type: sequence of two ints | |||||
| .. attribute:: filter | .. attribute:: filter | ||||
| pixel filter | Pixel filter. | ||||
| :type: :class:`FilterBGR24`, | |||||
| :class:`FilterBlueScreen`, | |||||
| :class:`FilterColor`, | |||||
| :class:`FilterGray`, | |||||
| :class:`FilterLevel`, | |||||
| :class:`FilterNormal`, | |||||
| :class:`FilterRGB24`, | |||||
| :class:`FilterRGBA32` | |||||
| .. attribute:: flip | .. attribute:: flip | ||||
| flip image vertically | Flip image vertically. | ||||
| :type: bool | |||||
| .. attribute:: image | .. attribute:: image | ||||
| image data | Image data. (readonly) | ||||
| :type: :class:`~bgl.Buffer` or None | |||||
| .. method:: refresh(imageRender) | .. method:: refresh() | ||||
| Refresh image - invalidate its current content | Refresh image - invalidate its current content. | ||||
| .. attribute:: scale | .. attribute:: scale | ||||
| fast scale of image (near neighbour) | Fast scale of image (near neighbour). | ||||
| :type: bool | |||||
| .. attribute:: size | .. attribute:: size | ||||
| image size | Image size. (readonly) | ||||
| :type: tuple of two ints | |||||
| .. attribute:: valid | .. attribute:: valid | ||||
| bool to tell if an image is available | Tells if an image is available. (readonly) | ||||
| :type: bool | |||||
| .. attribute:: whole | .. attribute:: whole | ||||
| use whole viewport to render | Use whole viewport to render. | ||||
| :type: bool | |||||
| .. attribute:: depth | .. attribute:: depth | ||||
| use depth component of render as array of float - not suitable for texture source, | Use depth component of render as array of float - not suitable for texture source, | ||||
| should only be used with bge.texture.imageToArray(mode='F') | should only be used with bge.texture.imageToArray(mode='F'). | ||||
| :type: bool | |||||
| .. attribute:: zbuff | .. attribute:: zbuff | ||||
| use depth component of render as grey scale color - suitable for texture source | Use depth component of render as grey scale color - suitable for texture source. | ||||
| :type: bool | |||||
| .. class:: ImageViewport() | .. class:: ImageViewport | ||||
| Image source from viewport | Image source from viewport. | ||||
| .. attribute:: alpha | .. attribute:: alpha | ||||
| use alpha in texture | Use alpha in texture. | ||||
| :type: bool | |||||
| .. attribute:: capsize | .. attribute:: capsize | ||||
| size of viewport area being captured | Size of viewport area being captured. | ||||
| :type: sequence of two ints | |||||
| .. attribute:: filter | .. attribute:: filter | ||||
| pixel filter | Pixel filter. | ||||
| :type: :class:`FilterBGR24`, | |||||
| :class:`FilterBlueScreen`, | |||||
| :class:`FilterColor`, | |||||
| :class:`FilterGray`, | |||||
| :class:`FilterLevel`, | |||||
| :class:`FilterNormal`, | |||||
| :class:`FilterRGB24`, | |||||
| :class:`FilterRGBA32` | |||||
| .. attribute:: flip | .. attribute:: flip | ||||
| flip image vertically | Flip image vertically. | ||||
| :type: bool | |||||
| .. attribute:: image | .. attribute:: image | ||||
| image data | Image data. (readonly) | ||||
| :type: :class:`~bgl.Buffer` or None | |||||
| .. attribute:: position | .. attribute:: position | ||||
| upper left corner of captured area | Upper left corner of the captured area. | ||||
| :type: sequence of two ints | |||||
| .. method:: refresh(imageViewport) | .. method:: refresh() | ||||
| Refresh image - invalidate its current content | Refresh image - invalidate its current content. | ||||
| .. attribute:: scale | .. attribute:: scale | ||||
| fast scale of image (near neighbour) | Fast scale of image (near neighbour). | ||||
| :type: bool | |||||
| .. attribute:: size | .. attribute:: size | ||||
| image size | Image size. (readonly) | ||||
| :type: tuple of two ints | |||||
| .. attribute:: valid | .. attribute:: valid | ||||
| bool to tell if an image is available | Tells if an image is available. (readonly) | ||||
| :type: bool | |||||
| .. attribute:: whole | .. attribute:: whole | ||||
| use whole viewport to capture | Use whole viewport to capture. | ||||
| :type: bool | |||||
| .. attribute:: depth | .. attribute:: depth | ||||
| use depth component of viewport as array of float - not suitable for texture source, | Use depth component of viewport as array of float - not suitable for texture source, | ||||
| should only be used with bge.texture.imageToArray(mode='F') | should only be used with bge.texture.imageToArray(mode='F'). | ||||
| :type: bool | |||||
| .. attribute:: zbuff | .. attribute:: zbuff | ||||
| use depth component of viewport as grey scale color - suitable for texture source | Use depth component of viewport as grey scale color - suitable for texture source. | ||||
| :type: bool | |||||
| *************** | |||||
| Texture classes | |||||
| *************** | |||||
| .. class:: Texture(gameObj) | .. class:: Texture(gameObj[, materialID, textureID, textureObj]) | ||||
| Texture objects | Texture object. | ||||
| :arg gameObj: Game object to be created a video texture on. | |||||
| :type gameObj: :class:`~bge.types.KX_GameObject` | |||||
| :arg materialID: Material ID. (optional) | |||||
| :type materialID: int | |||||
| :arg textureID: Texture ID. (optional) | |||||
| :type textureID: int | |||||
| :arg textureObj: Texture object with shared bindId. (optional) | |||||
| :type textureObj: :class:`Texture` | |||||
| .. attribute:: bindId | .. attribute:: bindId | ||||
| OpenGL Bind Name | OpenGL Bind Name. (readonly) | ||||
| :type: int | |||||
| .. method:: close(texture) | .. method:: close() | ||||
| Close dynamic texture and restore original | Close dynamic texture and restore original. | ||||
| .. attribute:: mipmap | .. attribute:: mipmap | ||||
| mipmap texture | Mipmap texture. | ||||
| :type: bool | |||||
| .. method:: refresh(texture) | .. method:: refresh(refresh_source=True[, ts=-1.0]) | ||||
| Refresh texture from source | Refresh texture from source. | ||||
| :arg refresh_source: Whether to also refresh the image source of the texture. | |||||
| :type refresh_source: bool | |||||
| :arg ts: If the texture controls a VideoFFmpeg object: | |||||
| timestamp (in seconds from the start of the movie) of the frame to be loaded; this can be | |||||
| used for video-sound synchonization by passing :attr:`~bge.types.KX_SoundActuator.time` to it. | |||||
| :type ts: float | |||||
| .. attribute:: source | .. attribute:: source | ||||
| source of texture | Source of texture. | ||||
| :type: :class:`VideoFFmpeg`, | |||||
| :class:`ImageFFmpeg`, | |||||
| :class:`ImageBuff`, | |||||
| :class:`ImageMirror`, | |||||
| :class:`ImageMix`, | |||||
| :class:`ImageRender`, | |||||
| :class:`ImageViewport` | |||||
| ************** | |||||
| Filter classes | |||||
| ************** | |||||
| .. class:: FilterBGR24() | |||||
| Source filter BGR24 objects | .. class:: FilterBGR24 | ||||
| .. class:: FilterBlueScreen() | Source filter BGR24. | ||||
| Filter for Blue Screen objects | .. class:: FilterBlueScreen | ||||
| Filter for Blue Screen. The RGB channels of the color are left unchanged, while the output alpha is obtained as follows: | |||||
| * if the square of the euclidian distance between the RGB color and the filter's reference color is smaller than the filter's lower limit, | |||||
| the output alpha is set to 0; | |||||
| * if that square is bigger than the filter's upper limit, the output alpha is set to 255; | |||||
| * otherwise the output alpha is linarly extrapoled between 0 and 255 in the interval of the limits. | |||||
| .. attribute:: color | .. attribute:: color | ||||
| blue screen color | Reference color. | ||||
| :type: sequence of three ints | |||||
| :default: (0, 0, 255) | |||||
| .. attribute:: limits | .. attribute:: limits | ||||
| blue screen color limits | Reference color limits. | ||||
| :type: sequence of two ints | |||||
| :default: (64, 64) | |||||
| .. attribute:: previous | .. attribute:: previous | ||||
| previous pixel filter | Previous pixel filter. | ||||
| :type: :class:`FilterBGR24`, | |||||
| :class:`FilterBlueScreen`, | |||||
| :class:`FilterColor`, | |||||
| :class:`FilterGray`, | |||||
| :class:`FilterLevel`, | |||||
| :class:`FilterNormal`, | |||||
| :class:`FilterRGB24`, | |||||
| :class:`FilterRGBA32` | |||||
| .. class:: FilterColor() | .. class:: FilterColor | ||||
| Filter for color calculations | Filter for color calculations. The output color is obtained by multiplying the reduced 4x4 matrix with the input color | ||||
| and adding the remaining column to the result. | |||||
| .. attribute:: matrix | .. attribute:: matrix | ||||
| matrix [4][5] for color calculation | Matrix [4][5] for color calculation. | ||||
| :type: sequence of four sequences of five ints | |||||
| :default: ((256, 0, 0, 0, 0), (0, 256, 0, 0, 0), (0, 0, 256, 0, 0), (0, 0, 0, 256, 0)) | |||||
| .. attribute:: previous | .. attribute:: previous | ||||
| previous pixel filter | Previous pixel filter. | ||||
| :type: :class:`FilterBGR24`, | |||||
| :class:`FilterBlueScreen`, | |||||
| :class:`FilterColor`, | |||||
| :class:`FilterGray`, | |||||
| :class:`FilterLevel`, | |||||
| :class:`FilterNormal`, | |||||
| :class:`FilterRGB24`, | |||||
| :class:`FilterRGBA32` | |||||
| .. class:: FilterGray() | .. class:: FilterGray | ||||
| Filter for gray scale effect | Filter for gray scale effect. Proportions of R, G and B contributions in the output gray scale are 28:151:77. | ||||
| .. attribute:: previous | .. attribute:: previous | ||||
| previous pixel filter | Previous pixel filter. | ||||
| .. class:: FilterLevel() | :type: :class:`FilterBGR24`, | ||||
| :class:`FilterBlueScreen`, | |||||
| Filter for levels calculations | :class:`FilterColor`, | ||||
| :class:`FilterGray`, | |||||
| :class:`FilterLevel`, | |||||
| :class:`FilterNormal`, | |||||
| :class:`FilterRGB24`, | |||||
| :class:`FilterRGBA32` | |||||
| .. class:: FilterLevel | |||||
| Filter for levels calculations. Each output color component is obtained as follows: | |||||
| * if it is smaller than its corresponding min value, it is set to 0; | |||||
| * if it is bigger than its corresponding max value, it is set to 255; | |||||
| * Otherwise it is linearly extrapoled between 0 and 255 in the (min, max) interval. | |||||
| .. attribute:: levels | .. attribute:: levels | ||||
| levels matrix [4] (min, max) | Levels matrix [4] (min, max). | ||||
| :type: sequence of four sequences of two ints | |||||
| :default: ((0, 255), (0, 255), (0, 255), (0, 255)) | |||||
| .. attribute:: previous | .. attribute:: previous | ||||
| previous pixel filter | Previous pixel filter. | ||||
| :type: :class:`FilterBGR24`, | |||||
| :class:`FilterBlueScreen`, | |||||
| :class:`FilterColor`, | |||||
| :class:`FilterGray`, | |||||
| :class:`FilterLevel`, | |||||
| :class:`FilterNormal`, | |||||
| :class:`FilterRGB24`, | |||||
| :class:`FilterRGBA32` | |||||
| .. class:: FilterNormal() | .. class:: FilterNormal | ||||
| Filter for Blue Screen objects | Normal map filter. | ||||
| .. attribute:: colorIdx | .. attribute:: colorIdx | ||||
| index of color used to calculate normal (0 - red, 1 - green, 2 - blue) | Index of color used to calculate normal (0 - red, 1 - green, 2 - blue, 3 - alpha). | ||||
| :type: int in [0, 3] | |||||
| :default: 0 | |||||
| .. attribute:: depth | .. attribute:: depth | ||||
| depth of relief | Depth of relief. | ||||
| :type: float | |||||
| :default: 4.0 | |||||
| .. attribute:: previous | .. attribute:: previous | ||||
| previous pixel filter | Previous pixel filter. | ||||
| :type: :class:`FilterBGR24`, | |||||
| :class:`FilterBlueScreen`, | |||||
| :class:`FilterColor`, | |||||
| :class:`FilterGray`, | |||||
| :class:`FilterLevel`, | |||||
| :class:`FilterNormal`, | |||||
| :class:`FilterRGB24`, | |||||
| :class:`FilterRGBA32` | |||||
| .. class:: FilterRGB24() | .. class:: FilterRGB24 | ||||
| Returns a new input filter object to be used with :class:`ImageBuff` object when the image passed | Returns a new input filter object to be used with :class:`ImageBuff` object when the image passed | ||||
| to the ImageBuff.load() function has the 3-bytes pixel format BGR. | to the :meth:`ImageBuff.load` function has the 3-bytes pixel format BGR. | ||||
| .. class:: FilterRGBA32() | .. class:: FilterRGBA32 | ||||
| Source filter RGBA32 objects | Source filter RGBA32. | ||||
| ********* | |||||
| Functions | |||||
| ********* | |||||
| .. function:: getLastError() | .. function:: getLastError() | ||||
| Last error that occurred in a bge.texture function. | Last error that occurred in a bge.texture function. | ||||
| :return: the description of the last error occurred in a bge.texture function. | :return: The description of the last error occurred in a bge.texture function. | ||||
| :rtype: string | :rtype: str | ||||
| .. function:: imageToArray(image,mode) | .. function:: imageToArray(image, mode) | ||||
| Returns a :class:`~bgl.buffer` corresponding to the current image stored in a texture source object. | Returns a :class:`~bgl.Buffer` corresponding to the current image stored in a texture source object. | ||||
| :arg image: Image source object. | :arg image: Image source object. | ||||
| :type image: object of type :class:`VideoFFmpeg`, :class:`ImageFFmpeg`, :class:`ImageBuff`, :class:`ImageMix`, :class:`ImageRender`, :class:`ImageMirror` or :class:`ImageViewport` | :type image: :class:`VideoFFmpeg`, | ||||
| :arg mode: optional argument representing the pixel format. | :class:`ImageFFmpeg`, | ||||
| You can use the characters R, G, B for the 3 color channels, A for the alpha channel, | :class:`ImageBuff`, | ||||
| 0 to force a fixed 0 color channel and 1 to force a fixed 255 color channel. | :class:`ImageMix`, | ||||
| Example: "BGR" will return 3 bytes per pixel with the Blue, Green and Red channels in that order. | :class:`ImageRender`, | ||||
| "RGB1" will return 4 bytes per pixel with the Red, Green, Blue channels in that order and the alpha channel forced to 255. | :class:`ImageMirror`, | ||||
| A special mode "F" allows to return the image as an array of float. This mode should only be used to retrieve | :class:`ImageViewport` | ||||
| the depth buffer of the ImageViewport and ImageRender object. | :arg mode: Optional argument representing the pixel format. | ||||
| The default mode is "RGBA". | You can use the characters R, G, B for the 3 color channels, A for the alpha channel, | ||||
| 0 to force a fixed 0 color channel and 1 to force a fixed 255 color channel. | |||||
| Example: "BGR" will return 3 bytes per pixel with the Blue, Green and Red channels in that order. | |||||
| :type mode: string | "RGB1" will return 4 bytes per pixel with the Red, Green, Blue channels in that order and the alpha channel forced to 255. | ||||
| :rtype: :class:`~bgl.buffer` | A special mode "F" allows to return the image as an array of float. This mode should only be used to retrieve | ||||
| :return: A object representing the image as one dimensional array of bytes of size (pixel_size*width*height), | the depth buffer of the class:`ImageViewport` and :class:`ImageRender` objects. | ||||
| line by line starting from the bottom of the image. The pixel size and format is determined by the mode | The default mode is "RGBA". | ||||
Not Done Inline ActionsThe resulting output looks really terrible (also the original). Maybe you can improve the readability with a list. hg1: The resulting output looks really terrible (also the original). Maybe you can improve the… | |||||
Not Done Inline ActionsAs said above, lists are problematic. But you're right, this part should be made better. Matpi: As said above, lists are problematic. But you're right, this part should be made better. | |||||
| parameter. For mode 'F', the array is a one dimensional array of float of size (width*height). | :type mode: str | ||||
| .. function:: materialID(object,name) | :return: An object representing the image as one dimensional array of bytes of size (pixel_size*width*height), | ||||
| line by line starting from the bottom of the image. The pixel size and format is determined by the mode | |||||
| parameter. For mode 'F', the array is a one dimensional array of float of size (width*height). | |||||
| :rtype: :class:`~bgl.Buffer` | |||||
| .. function:: materialID(object, name) | |||||
| Returns a numeric value that can be used in :class:`Texture` to create a dynamic texture. | Returns a numeric value that can be used in :class:`Texture` to create a dynamic texture. | ||||
| The value corresponds to an internal material number that uses the texture identified | The value corresponds to an internal material number that uses the texture identified | ||||
| by name. name is a string representing a texture name with IM prefix if you want to | by name. name is a string representing a texture name with ``IM`` prefix if you want to | ||||
| identify the texture directly. This method works for basic tex face and for material, | identify the texture directly. This method works for basic tex face and for material, | ||||
| provided the material has a texture channel using that particular texture in first | provided the material has a texture channel using that particular texture in first | ||||
| position of the texture stack. name can also have MA prefix if you want to identify | position of the texture stack. name can also have ``MA`` prefix if you want to identify | ||||
| the texture by material. In that case the material must have a texture channel in first | the texture by material. In that case the material must have a texture channel in first | ||||
| position. | position. | ||||
| If the object has no material that matches name, it generates a runtime error. Use try/except to catch the exception. | If the object has no material that matches name, it generates a runtime error. Use try/except to catch the exception. | ||||
| Ex: bge.texture.materialID(obj, 'IMvideo.png') | Ex: ``bge.texture.materialID(obj, 'IMvideo.png')`` | ||||
| :arg object: the game object that uses the texture you want to make dynamic | :arg object: The game object that uses the texture you want to make dynamic. | ||||
| :type object: game object | :type object: :class:`~bge.types.KX_GameObject` | ||||
| :arg name: name of the texture/material you want to make dynamic. | :arg name: Name of the texture/material you want to make dynamic. | ||||
| :type name: string | :type name: str | ||||
| :rtype: integer | |||||
| :return: The internal material number. | |||||
| :rtype: int | |||||
| .. function:: setLogFile(filename) | .. function:: setLogFile(filename) | ||||
| Context not available. | |||||
| of the messages on the Python console. Only the runtime errors specific to the VideoTexture module | of the messages on the Python console. Only the runtime errors specific to the VideoTexture module | ||||
| are written in that file, ordinary runtime time errors are not written. | are written in that file, ordinary runtime time errors are not written. | ||||
| :arg filename: name of error log file | :arg filename: Name of the error log file. | ||||
| :type filename: string | :type filename: str | ||||
| :rtype: integer | |||||
| :return: -1 if the parameter name is invalid (not of type string), else 0. | |||||
| :rtype: int | |||||
| ********* | |||||
| Constants | |||||
| ********* | |||||
| FFmpeg video and image statuses | |||||
| +++++++++++++++++++++++++++++++ | |||||
| .. data:: SOURCE_ERROR | |||||
| :type: int | |||||
| :value: -1 | |||||
| .. data:: SOURCE_EMPTY | |||||
| :type: int | |||||
| :value: 0 | |||||
| .. data:: SOURCE_READY | |||||
| :type: int | |||||
| :value: 1 | |||||
| .. data:: SOURCE_PLAYING | |||||
| :type: int | |||||
| :value: 2 | |||||
| .. data:: SOURCE_STOPPED | |||||
| :type: int | |||||
| :value: 3 | |||||
| Image blending modes | |||||
| ++++++++++++++++++++ | |||||
| .. data:: IMB_BLEND_MIX | |||||
| :type: int | |||||
| :value: 0 | |||||
| .. data:: IMB_BLEND_ADD | |||||
| :type: int | |||||
| :value: 1 | |||||
| .. data:: IMB_BLEND_SUB | |||||
| :type: int | |||||
| :value: 2 | |||||
| .. data:: IMB_BLEND_MUL | |||||
| :type: int | |||||
| :value: 3 | |||||
| .. data:: IMB_BLEND_LIGHTEN | |||||
| :type: int | |||||
| :value: 4 | |||||
| .. data:: IMB_BLEND_DARKEN | |||||
| :type: int | |||||
| :value: 5 | |||||
| .. data:: IMB_BLEND_ERASE_ALPHA | |||||
| :type: int | |||||
| :value: 6 | |||||
| .. data:: IMB_BLEND_ADD_ALPHA | |||||
| :type: int | |||||
| :value: 7 | |||||
| .. data:: IMB_BLEND_OVERLAY | |||||
| :type: int | |||||
| :value: 8 | |||||
| .. data:: IMB_BLEND_HARDLIGHT | |||||
| :type: int | |||||
| :value: 9 | |||||
| .. data:: IMB_BLEND_COLORBURN | |||||
| :type: int | |||||
| :value: 10 | |||||
| .. data:: IMB_BLEND_LINEARBURN | |||||
| :type: int | |||||
| :value: 11 | |||||
| .. data:: IMB_BLEND_COLORDODGE | |||||
| :type: int | |||||
| :value: 12 | |||||
| .. data:: IMB_BLEND_SCREEN | |||||
| :type: int | |||||
| :value: 13 | |||||
| .. data:: IMB_BLEND_SOFTLIGHT | |||||
| :type: int | |||||
| :value: 14 | |||||
| .. data:: IMB_BLEND_PINLIGHT | |||||
| :type: int | |||||
| :value: 15 | |||||
| .. data:: IMB_BLEND_VIVIDLIGHT | |||||
| :type: int | |||||
| :value: 16 | |||||
| .. data:: IMB_BLEND_LINEARLIGHT | |||||
| :type: int | |||||
| :value: 17 | |||||
| .. data:: IMB_BLEND_DIFFERENCE | |||||
| :type: int | |||||
| :value: 18 | |||||
| .. data:: IMB_BLEND_EXCLUSION | |||||
| :type: int | |||||
| :value: 19 | |||||
| .. data:: IMB_BLEND_HUE | |||||
| :type: int | |||||
| :value: 20 | |||||
| .. data:: IMB_BLEND_SATURATION | |||||
| :type: int | |||||
| :value: 21 | |||||
| .. data:: IMB_BLEND_LUMINOSITY | |||||
| :type: int | |||||
| :value: 22 | |||||
| .. data:: IMB_BLEND_COLOR | |||||
| :type: int | |||||
| :value: 23 | |||||
| .. data:: IMB_BLEND_COPY | |||||
| :type: int | |||||
| :value: 1000 | |||||
| .. data:: IMB_BLEND_COPY_RGB | |||||
| :type: int | |||||
| :value: 1001 | |||||
| .. data:: IMB_BLEND_COPY_ALPHA | |||||
| :type: int | |||||
| :value: 1002 | |||||
| Context not available. | |||||
That is wrong. The value is a python integer converted to an unsigned char 0-255 (black to white).