Modify loaded model material

Hi
How can i change a loaded model material properties like emission?
I’m trying to highlight an object on mouse collision:

...
picked = self.picker_handler.get_entry(0).get_into_node_path()
picked_name = picked.get_name()
print("picked:", picked_name)
mat = picked.find_all_materials().get_material(0)
print(mat)
mat.set_emission(VBase4(0.5, 0.5, 0.5, 1))
print(mat)

I get neither error nor any effect on object. even picked.set_color(VBase4(1, 1, 1, 1)) has no effect. why?
Thanks.

Do you have a light in the scene? Materials describe how light behaves when it hits the surface of an object; if you don’t have a light applied, the material won’t take effect.

D’oh! no i haven’t any lights.
I baked my textures on blender already and my scene looks pretty enlightened, so i though like default camera there would be a default light on Panda.
I’ll try that with lights.

By the way i have an issue on transparent materials loaded from blender. they are transparent but they have a thin white line around them like:
or



How can i fix this?

This is a classic alpha blending issue. You have to tell Panda which transparency mode to use. You can use setTransparency(MAlpha) for simple transparency, MBinary for perfect transparency without semitransparency, MDual for a smarter version of MAlpha, or MMultisample for alpha-to-coverage transparency.

This is equivalent to switching to the “Blender Game” mode at the top bar in Blender, going to your material settings, and changing “Alpha Blend” under “Game Settings”.

I’ve added a point light beside the ambient light but still there is no visible highlight?!

For transparency, where i should use set_transparency() method?
I’ve tried on self.render.set_transparency() and self.model.set_transparency()(which is my loaded scene from blender) with MAlpha or MDual, but there is no change. so should it be set on every object in the scene separately?

I’m guessing there is already a transparency attribute set in the .egg file; to override it, add an override number as second argument to setPriority, ie. setTransparency(MDual, 1). Or just edit the .egg file to change the setting, or change it in Blender.

Yeah, you were right. now my transparency issue got solved.

But what can i do about modifying an object material of loaded scene?
While this methods gives me None:

mat = picked_object.get_material()

This method returns the material:

picked_object.find_all_materials().get_material(0)

But changing the returned material properties has no visible effect. i guess the returned material is not the same reference of the rendered material.

You can on the returned node call set_material with an override value in order to override the material that is already assigned.

Nope, even set_material didn’t work :frowning:

picked.set_material(mat, 1)

But after i set material this way the picked.get_material() returns previously set mat while before it returned None.
Anyway is there any sample of modifying material on loaded external model? maybe there is something wrong with my egg file.