2011-07-06 07:26:04 +00:00
|
|
|
"""
|
2012-01-23 19:53:23 +00:00
|
|
|
Texture Replacement
|
|
|
|
+++++++++++++++++++
|
2011-07-06 07:26:04 +00:00
|
|
|
Example of how to replace a texture in game with an external image.
|
BGE: bge.texture API documentation enhancement
This patch attempts to improve and review the documentation of bge.texture, as requested in the [[ http://wiki.blender.org/index.php/Dev:2.5/Source/Development/Todo/GameEngine#Video_Texture | TODO list ]].
More specifically, it
- fixes the rst syntax, including titles of the examples bge.texture.py and bge.texture.1.py;
- adds, standardizes and reviews description of the API elements, particularly signatures, types, etc.
- adds SOURCE_* constants to the doc
- splits the doc into thematical parts (Video, Image, Texture, and Filter Classes, Functions, Constants).
Notes:
- The parameter "mode" of ImageBuff.plot has to be described better. Actually, the whole set of IMB_BLEND_* constants (from IMB_imbuf.h) should be exposed to Python. I'll do that in a future diff, and complete the doc at the same moment (adding those IMB_BLEND_* constants to the Constants part of this doc).
- The option of using webcams in VideoFFmpeg is still particularly not well documented. I am planning to make a proposal about fixing T18634 (and its corresponding TODO in the list) by integrating OpenCV in the BGE (and Blender?). The idea would then probably be to add a new class, f.ex. ImageWebcam, making this functionnality more specialized. So for now I don't think it is worth to document that part much.
This patch fixes T44284 too.
Reviewers: moguri, kupoman, campbellbarton, panzergame, lordloki
Reviewed By: panzergame, lordloki
Subscribers: hg1
Projects: #game_engine, #game_python, #documentation
Maniphest Tasks: T44284
Differential Revision: https://developer.blender.org/D1352
2015-07-06 09:11:40 +00:00
|
|
|
``createTexture()`` and ``removeTexture()`` are to be called from a
|
|
|
|
module Python Controller.
|
2011-07-06 07:26:04 +00:00
|
|
|
"""
|
|
|
|
from bge import logic
|
2011-07-29 01:24:03 +00:00
|
|
|
from bge import texture
|
|
|
|
|
2011-07-06 07:26:04 +00:00
|
|
|
|
|
|
|
def createTexture(cont):
|
|
|
|
"""Create a new Dynamic Texture"""
|
2011-11-24 19:36:12 +00:00
|
|
|
obj = cont.owner
|
2011-07-29 01:24:03 +00:00
|
|
|
|
2011-07-06 07:26:04 +00:00
|
|
|
# get the reference pointer (ID) of the internal texture
|
2011-11-24 19:36:12 +00:00
|
|
|
ID = texture.materialID(obj, 'IMoriginal.png')
|
2011-07-29 01:24:03 +00:00
|
|
|
|
|
|
|
# create a texture object
|
2011-11-24 19:36:12 +00:00
|
|
|
object_texture = texture.Texture(obj, ID)
|
2011-07-29 01:24:03 +00:00
|
|
|
|
2011-07-06 07:26:04 +00:00
|
|
|
# create a new source with an external image
|
|
|
|
url = logic.expandPath("//newtexture.jpg")
|
|
|
|
new_source = texture.ImageFFmpeg(url)
|
2011-07-29 01:24:03 +00:00
|
|
|
|
2011-07-06 07:26:04 +00:00
|
|
|
# the texture has to be stored in a permanent Python object
|
|
|
|
logic.texture = object_texture
|
2011-07-29 01:24:03 +00:00
|
|
|
|
2011-07-06 07:26:04 +00:00
|
|
|
# update/replace the texture
|
|
|
|
logic.texture.source = new_source
|
|
|
|
logic.texture.refresh(False)
|
|
|
|
|
2011-07-29 01:24:03 +00:00
|
|
|
|
2011-07-06 07:26:04 +00:00
|
|
|
def removeTexture(cont):
|
|
|
|
"""Delete the Dynamic Texture, reversing back the final to its original state."""
|
|
|
|
try:
|
|
|
|
del logic.texture
|
|
|
|
except:
|
|
|
|
pass
|