Page MenuHome

BGE: Extend Python API for KX_BlenderMaterial (specular, diffuse…)
ClosedPublic

Authored by Porteries Tristan (panzergame) on May 14 2015, 8:52 PM.

Details

Diff Detail

Repository
rB Blender
Branch
ge_python_material

Event Timeline

Porteries Tristan (panzergame) retitled this revision from to BGE : Fix forgetting of material diffuse, specular color ect… in KX_BlenderMaterial..
Porteries Tristan (panzergame) updated this object.

The tilte "BGE : Fix forgetting of material diffuse, specular color ect… in KX_BlenderMaterial" sounds bad for me.
For me "BGE : Fix: Add forgotten material API for diffuse, specular color ect… in KX_BlenderMaterial" sounds better.
Talk to agoose77 about a better title.

I only style and code checked it. I don't make a compile or other tests.

doc/python_api/rst/bge_types/bge.types.KX_BlenderMaterial.rst
96

I think 0.0 and 1.0 looks better for float

source/gameengine/Ketsji/KX_BlenderMaterial.cpp
1036

CHECK_PYTHON_FLOAT_NON_ZERO implicate the it checks for values higher ten zero.
I think CHECK_PYTHON_FLOAT_LOWER_ZERO or CHECK_PYTHON_FLOAT_NON_NEGATIVE fits better.
I prefer CHECK_PYTHON_FLOAT_NON_NEGATIVE.
Ask agoose77.

1037

0.0f

The tilte "BGE : Fix forgetting of material diffuse, specular color ect… in KX_BlenderMaterial" sounds bad for me.
For me "BGE : Fix: Add forgotten material API for diffuse, specular color ect… in KX_BlenderMaterial" sounds better.
Talk to agoose77 about a better title.

I only style and code checked it. I don't make a compile or other tests.

Better title: "BGE: Extend Python API for KX_BlenderMaterial (specular, diffuse ...)"

source/gameengine/Ketsji/KX_BlenderMaterial.cpp
945

"repeting" -> "repeating"

Porteries Tristan (panzergame) retitled this revision from BGE : Fix forgetting of material diffuse, specular color ect… in KX_BlenderMaterial. to BGE: Extend Python API for KX_BlenderMaterial (specular, diffuse…).May 16 2015, 10:10 PM
Porteries Tristan (panzergame) edited edge metadata.

Fix macro name, comment, range check and doc, and add a check for Material to avoid crash in blenderplayer.

Mitchell Stokes (moguri) requested changes to this revision.May 17 2015, 12:33 AM
Mitchell Stokes (moguri) edited edge metadata.

You should have left the material check in it's own patch instead of combining it with this one. Also, I don't know if @Campbell Barton (campbellbarton) will approve of the macro usage since I want to say there was some talk about not using these kinds of macros on the mailing list some time back. I'm not too keen on it myself, but I see not wanting to duplicate the code. I also don't like that a user can set a material property and silently have it do nothing. In other words, we shouldn't fail silently if we don't have a material. But, this also makes me wonder why we even allow the material to be NULL. It really should point to the default material. I'll probably have to talk more with @Dalai Felinto (dfelinto) about this.

This revision now requires changes to proceed.May 17 2015, 12:33 AM

Hmm, looks like Phabricator was messing with me and the material check isn't in this patch as well. The other issues still stand. Another issue I see is that the docs are rather useless. Can we copy some UI strings from the material RNA to use as docs?

Campbell Barton (campbellbarton) requested changes to this revision.May 18 2015, 1:27 PM
Campbell Barton (campbellbarton) edited edge metadata.
Campbell Barton (campbellbarton) added inline comments.
source/gameengine/Ketsji/KX_BlenderMaterial.cpp
1036–1040

With some of the Blender 2.4x API we had errors raised if the values were outside the range and it was very problematic.

The problem is, if you calculate a value, float-precision can mean you get outside the range by some small margin. And theres no really good way to figure out what a reasonable epsilon might be.

In practice scripts ended up having to hard code the clamp limits before assigning any calculated values... at that point its just causing annoyance.

Another issue is when limits are wrong or change, you introduce breakage.

Just clamp the input, if clamping is making development confusing, (silently hiding problems) we can always have some debug option a script author can enable, which wants when a value is set out of range (and clamped).

doc/python_api/rst/bge_types/bge.types.KX_BlenderMaterial.rst
122–133

Why not use mathutils.Color ?

Porteries Tristan (panzergame) marked 3 inline comments as done.May 19 2015, 10:54 PM
Porteries Tristan (panzergame) added inline comments.
doc/python_api/rst/bge_types/bge.types.KX_BlenderMaterial.rst
122–133

There are nothing in the BGE to support Color python type.

Porteries Tristan (panzergame) edited edge metadata.

Remove error macro, replace range out check by a clamp.

The RNA strings for diffuse_color and specular_color aren't too helpful (although I at least prefer their wording), but the strings for the other attributes (alpha, emit, hardness, specular_intensity, diffuse_intensity) look good.

doc/python_api/rst/bge_types/bge.types.KX_BlenderMaterial.rst
122–133

This can be added.

source/gameengine/Ketsji/KX_BlenderMaterial.cpp
1071–1074

just clamp the value

source/gameengine/Ketsji/KX_BlenderMaterial.cpp
1071–1074

Also for integers ?

doc/python_api/rst/bge_types/bge.types.KX_BlenderMaterial.rst
122–133

If i implement mathutils color for KX_BlenderMaterial i will have to also impelement it in object color, in KX_VertexProxy ect… to keep it consistent.

Porteries Tristan (panzergame) edited edge metadata.

Add rna doc comment, clamp hardness value.

source/gameengine/Ketsji/KX_BlenderMaterial.cpp
1205

To be consistent with Blender, the emit value should be clamped to FLT_MAX.

Remove blender material check. Indeed we have a futur commited fix for this.

Update to current trunk.

Mitchell Stokes (moguri) edited edge metadata.

Looks good to me pending an okay from Campbell.

source/gameengine/Ketsji/KX_BlenderMaterial.h
107

Very minor nit-pick, but I prefer function definitions to be in the source file, and not the header file.

Porteries Tristan (panzergame) edited edge metadata.

Move function GetBLMaterial to KX_BlenderMaterial.cpp.

Porteries Tristan (panzergame) marked 3 inline comments as done.Jun 4 2015, 6:11 PM
Porteries Tristan (panzergame) added inline comments.
source/gameengine/Ketsji/KX_BlenderMaterial.cpp
1205

In the UI doc it says that emit range is [0, 2].

source/gameengine/Ketsji/KX_BlenderMaterial.cpp
1205

Emit [0, 2] and the colors [0, 1] are only soft limited to this ranges, the hard limit range is [0 ,FLT_MAX].
http://www.blender.org/api/blender_python_api_2_74_5/bpy.types.Material.html?highlight=emit#bpy.types.Material.emit

doc/python_api/rst/bge_types/bge.types.KX_BlenderMaterial.rst
122–133

+1 for using mathutils.Color where we use colours. It may be more work to make the existing code consistent, but I don't think that should stand in the way of doing the right thing.

Support mathutils Color type.

Fix color type in doc.

This revision is now accepted and ready to land.Jul 3 2015, 10:11 AM
Thomas Szepe (hg1) edited edge metadata.