GameLogick + Blender.Material

Hi.

I’m total newbie at Blender Python (and python itself) so i need your help
Please take a look at my script:


import GameLogic
import Blender
from Blender import Material

cont = GameLogic.getCurrentController()
ray = cont.getSensor("CamRay")
object = ray.getHitObject()

pos = object.getPosition()
pos[1] = pos[1] - 0.1
object.setPosition(pos)

mesh = object.getMesh()
matName = mesh.getMaterialName(0)
material = Material.Get(matName)
material.setRGBCol([ 1.0, 1.0, 1.0]) #don't work
material.rgbCol = [1.0, 1.0, 1.0] # .. either

So it works with my camera ray sensor. When camera looks at the box in “game” box is moved… That works, but there are problem with modifying material, thats for sure. All i want (yet) is to highlight object witch is pointed by camera. How to do that properly? :confused:

Thanks.

Somebody should make sticky title: “Don’t mix Blender API and GameBlender API” - unless you know what you are doing. No offence to you, but it’s just a common mistake.

Materials are not accessible via Python in GameBlender. You can make plugin in C/C++, that will access them, or modify and recompile Blender sources - but these are hard tasks for beginners.

Thanks for knowladge indeed.

Coding games using Direct3D, for example, Material to be set for D3D device has property sutch as Emissive color. Using that it’s quite easy to make mesh highlight. How to do that in BGE?

I found “KX_VertexProxy-class” but I am not sure is it (vertex color) gonna work when using textures. (?)

Any suggestions?

Hello
Qnother sticky post could be:
“Many features are already available and are as easy as to enable a button” :slight_smile:
I presume that to “programers” it’s more “fun” to code everything?!
Yes Vertex Colors work in the game engine
Here’s an old tut maybe useful
http://otothecleaner.free.fr/tutorials/VertexColours/ColourPower1/vertexcolours1.html
Bye

The simplest way is to use Object IPO - there are curves ColR, ColG ColB, ColA and you can use them to change object colour - IPO actuator.

Vertex colours are usable too, especially if you need to highlight part of object.

Both solutions work with textures too. Just try it and you will see.

Thanks for replays!

I’m gonna try IPOs.

I managed to do this using “for v in range(mesh.getVertexArrayLength(0)): …” by changing vertex colors, but i guess IPO method would be much faster :confused: