Page MenuHome

BGE - new read-only attribute in KX_GameObject python api (LOD level)
ClosedPublic

Authored by Pierluigi Grassi (pgi) on Jan 8 2015, 6:26 PM.

Details

Summary

Added a new "current_lod_level" property to the python api of KX_GameObject. The property returns the current lod level of the game object. The purpose of the property is activate logic routines only when an object is at a certain lod-distance from the camera, avoiding to separately recomputing the same distance in the logic script. Usage in python script might look like:

owner = bge.logic.getCurrentController().owner
lod_level = owner.currentLodLevel
if lod_level == 0: ...do something
else: ... object might be too distant

Diff Detail

Repository
rB Blender

Event Timeline

Pierluigi Grassi (pgi) retitled this revision from to BGE - new read-only attribute in KX_GameObject python api (LOD level).
Pierluigi Grassi (pgi) updated this object.

Looks good to me, just needs documentation.

If I recall correctly, you can update the file doc/rst/bge.types.KX_GameObject.rst, and then figure out how to build the documentation to test it. I don't remember this process very well, but I am pretty sure it involves the sphinx scripts in doc/python_api.

Mitchell Stokes (moguri) requested changes to this revision.Jan 9 2015, 4:52 AM
Mitchell Stokes (moguri) edited edge metadata.

While I'd really like to do PEP8 naming, we should be consistent with naming and use "currentLodLevel".

This revision now requires changes to proceed.Jan 9 2015, 4:52 AM
Pierluigi Grassi (pgi) updated this object.
Pierluigi Grassi (pgi) edited edge metadata.

I have update the name of the variables, now the python attribute is currentLodLevel. I will update the doc as soon as I find a way to make the script work.

Pierluigi Grassi (pgi) edited edge metadata.

Python api doc for the new attribute.

Looks like you might have screwed up Differential a bit, try uploading a diff that contains all of your changes for this (docs and the Python attribute). Currently it is only showing the doc change.

Added a new diff file that is the sum of doc + code.

Mitchell Stokes (moguri) edited edge metadata.

This is a minor nitpick, but shouldn't the "lod" in the docs be either "Lod" or "LOD"?

This revision is now accepted and ready to land.Jan 14 2015, 6:06 PM

Yes, being an acronym LOD should be capitalized.
The doc should really be written by someone who actually speaks english (I just pretend to). For example, I would have loved to say what happens when there is no LOD (the value remains zero) but the sentence I wrote tried to kill me, so I gave up.

I believe I have been spelling it out in many user facing strings as "level of detail", and as "LoD" when I need to abbreviate it to save space. I vote for using "level of detail" in the documentation string (e.g. "index of the level of detail currently").

Pierluigi Grassi (pgi) edited edge metadata.

Doc update, I voted for the explicit proposal too.

Daniel Stokes (kupoman) edited edge metadata.

Looks good to me. I'm busy this evening, but I can try to land this tomorrow.

Mitchell Stokes (moguri) requested changes to this revision.Jan 26 2015, 8:58 AM
Mitchell Stokes (moguri) edited edge metadata.

Something I just noticed is that you should be using the KX_PYATTRIBUTE_INT_RO macro rather than KX_PYATTRIBUTE_RO_FUNCTION. This would mean adding less code (you don't have to create the function). I believe it should look like this:

KX_PYATTRIBUTE_INT_RO("currentLodLevel", KX_GameObject, m_currentLodLevel);

This revision now requires changes to proceed.Jan 26 2015, 8:58 AM
Pierluigi Grassi (pgi) edited edge metadata.

Patch updated (against latest sources in the repo).

Mitchell Stokes (moguri) edited edge metadata.
This revision is now accepted and ready to land.Jan 26 2015, 5:35 PM
This revision was automatically updated to reflect the committed changes.