Replace textures

I have a model that I want to change the texture of in-game. This is my script so far:


from Blender import Texture, Image, Material 

# 1. Get material | 2. Get all textures: 
male_material = Material.Get("male_material") 
male_textures = male_material.getTextures() 
 
# Name textures: 
skin = male_textures[0] 
pants = male_textures[1] 
 
pants_tex = Texture.Get("Pants") 
pants_tex.setType("Image") 
pants_img = Image.Load("new_texture.png") 
pants_tex.image = pants_img 
#print male_material.MTex().mapto ... how to I set the "Map to" (UV, ORCO, DISP)?
 
male_material.setTexture(1, pants_tex) 

The script does apply the new texture, but not before I’ve gone out and into the game again. (It sets the texture, but it doesn’t update it, like I want it to.)

Also, see the commented like (MTex thing). How do I do that?

I’ve been trying to solve this issue for a long time now, but with no luck. I really hope someone could help me.

The problem is in your very first line of code. Unfortunately, the GE can’t access the “blender” module for some reason.

Thanks, J09, but how can I do it then? This is really a big part of my game, so I can’t just skip it, unfortunately.

Any help is appreciated.

this function (from the rasterizer) looks very interesting for your problem (i don`t know what it exacly does)
setMaterialSettings
or
setMaterialMode
and maybe in the poly proxy

http://www.tutorialsforblender3d.com/GameModule/RasterizerModule.html

That doesn’t seem to be related to textures. Thanks anyway.

Anyone else who may have a solution?

My recommendation is to get an svn build of Blender and use the VideoTexture module. It is intended for, well, video textures, but it can also handle images. So, you can use it to change textures.

http://wiki.blender.org/index.php/GameEngineDev/VideoTexture

Thanks, Moguri. Will the VideoTexture be in the next version of Blender? If so, do you know when it’s going to be released?

Yes, VideoTexture will be in the next release of Blender, but I have no idea when that is going to be.