Mapping a Webcam-Image in Realtime

Hello all,

I’d like to know how to reload an Image automatically.
Like: Theres a plane with the image “…/cam.jpg” mapped onto
On MouseMove I’d like to reload the picture (which has changed)
And map it onto the plane again.

(Intention: I’ll mount the cam on the mouse, so i have a 2D-Augmented reality :wink: )

Thanks a lot for your solutions and python-examples :slight_smile:

in 2.34 it would be a pain or you simply cannot

[directly you cannot, there is no methods which replace textures, you may be able to make a hack that does it however [which would be a pain]]

so, don’t try it [please], save your sanity, and if it is really necescary write your own graphics api that allows you to

funny idea :slight_smile:

but as zerod said, it seems almost impossible with blender.

i was looking around in python using print dir(The module)
and i found replace, when i was at getMesh and get Texture or something, i tryed it and it dident work thought :frowning:

You should be able to do this:

import Blender
import GameLogic

gobj = GameLogic.getCurrentController().getOwner()
# Assumes mesh name == object name... very bad
bme = Blender.NMesh.GetRaw([2:])
# Get Image handle for first face
ima = bme.faces[0].image


Hmmm, i will try this.
The last thing i tried was exactly the ‘NMEsh’-Method, but i gave up frustrated. The other thing is, that the pictures from the cam are updated only once per second… Welll, let’s see.


hmm,i cant get it to work, can you show an example if you have one alien-xmp?

OK, I posted webcam.blend to BlenderSources. :wink:

Read the readme, you have to create a webcam.jpg file that can be updated.

I don’t have a real webcam, I’m just drawing in GIMP and then saving it. If you have a real webcam, it is probably capturing at eg 640x480 - you will need to resize/crop/letterbox to get to a valid texture (size must be a power of two)

I’m not exactly sure when Image.reload() was added, I’m testing in 2.34, and it won’t work in blenderplayer.

it dosent work in 2.25 But 2.34 it Does :slight_smile:
This is cool.


it worked. Once

THX a lot.
It woked at the first try, the image changed.
I started it once again and i had the first Bluescreen on my Laptop ever. but just for a glance of a second, then all went dark…

Since Friday i didn’t dare to turn on my Comp again. But today, tried again,
no update :frowning:

No matter, it looks fine.

Now, the plan is:

  • Get ARToolkit-Documentation (looked fine at a glance, Image via DirectX)

  • get a live-pic without saving (DirectX, Open GL) into Blender

    So long, Rubi

Nice feature.

Here it flashes a bit when the image gets replaced. Also the performance drops on very frequent reloads. But neverless new possibilities!


I know… if you know that eg the webcam is only updating once per second, you can drop the reload frequency.

… Man I never knewthe Blender Module was avaible in GE…I never saw it in the 2.34 GE docs

I justed realized if reload is possible then Bump Mapping is possible as well! Just take all the 3d information, image location/name, get PIL running with it calculate the pixels and just write over file and reload.

thats an icky way

why not just learn glsl, get a gfx card capable of it, and use tuhopuu2?

check out

OMG the Blender module works in the game engine again!

But does it work when you save a standalone runtime?

[EDIT] No it doesn’t, if you try to import Blender in a script running in the BlenderPlayer, it gives the error “No module named Blender.”

Wiseman isn’t it possible like python modules, to script a path to the module and include it with the runtime?? :-?
This is what I did with some Python codes inside blender. I used py2exe to find out what kinds of modules where needed to run the python program scripts inside blender’s engine. Then at the beginning script the path to the python modules that you want to include in your game. It works well, only you need to convert the modules into pyo files (just make them pyc and when blender imports them they will be turned into pyo) :smiley:

JD-multi: No it isn’t, because there is no path to the Blender module, it’s a part of Blender.exe.