[Bf-blender-cvs] [225027c] master: BGE - new read-only attribute in KX_GameObject python api (LOD level)

Pierluigi Grassi noreply at git.blender.org
Sun Mar 15 17:26:43 CET 2015


Commit: 225027ce5dea3785626908b58b01fb3959cf8362
Author: Pierluigi Grassi
Date:   Sun Mar 15 17:26:11 2015 +0100
Branches: master
https://developer.blender.org/rB225027ce5dea3785626908b58b01fb3959cf8362

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

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

Reviewers: dfelinto, kupoman, moguri

Reviewed By: kupoman, moguri

Subscribers: lordloki

Projects: #game_engine

Differential Revision: https://developer.blender.org/D978

===================================================================

M	doc/python_api/rst/bge_types/bge.types.KX_GameObject.rst
M	source/gameengine/Ketsji/KX_GameObject.cpp
M	source/gameengine/Ketsji/KX_GameObject.h

===================================================================

diff --git a/doc/python_api/rst/bge_types/bge.types.KX_GameObject.rst b/doc/python_api/rst/bge_types/bge.types.KX_GameObject.rst
index ebde93f..8d6996d 100644
--- a/doc/python_api/rst/bge_types/bge.types.KX_GameObject.rst
+++ b/doc/python_api/rst/bge_types/bge.types.KX_GameObject.rst
@@ -432,6 +432,12 @@ base class --- :class:`SCA_IObject`
       If true, the object's and children's debug properties will be displayed on screen.
 
       :type: boolean
+      
+   .. attribute:: currentLodLevel
+
+      The index of the level of detail (LOD) currently used by this object (read-only).
+
+      :type: int
 
    .. method:: endObject()
 
diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp
index 8d22c91..71af263 100644
--- a/source/gameengine/Ketsji/KX_GameObject.cpp
+++ b/source/gameengine/Ketsji/KX_GameObject.cpp
@@ -91,6 +91,7 @@ KX_GameObject::KX_GameObject(
     : SCA_IObject(),
       m_bDyna(false),
       m_layer(0),
+      m_currentLodLevel(0),
       m_pBlenderObject(NULL),
       m_pBlenderGroupObject(NULL),
       m_bSuspendDynamics(false),
@@ -794,7 +795,7 @@ void KX_GameObject::UpdateLod(MT_Vector3 &cam_pos)
 	}
 
 	RAS_MeshObject *mesh = this->m_lodmeshes[level];
-
+	this->m_currentLodLevel = level;
 	if (mesh != this->m_meshes[0]) {
 		this->GetScene()->ReplaceMesh(this, mesh, true, false);
 	}
@@ -1927,6 +1928,7 @@ PyMethodDef KX_GameObject::Methods[] = {
 };
 
 PyAttributeDef KX_GameObject::Attributes[] = {
+	KX_PYATTRIBUTE_INT_RO("currentLodLevel", KX_GameObject, m_currentLodLevel),
 	KX_PYATTRIBUTE_RO_FUNCTION("name",		KX_GameObject, pyattr_get_name),
 	KX_PYATTRIBUTE_RO_FUNCTION("parent",	KX_GameObject, pyattr_get_parent),
 	KX_PYATTRIBUTE_RO_FUNCTION("groupMembers",	KX_GameObject, pyattr_get_group_members),
diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h
index 5800cbc..7d1a934 100644
--- a/source/gameengine/Ketsji/KX_GameObject.h
+++ b/source/gameengine/Ketsji/KX_GameObject.h
@@ -88,6 +88,7 @@ protected:
 	int									m_layer;
 	std::vector<RAS_MeshObject*>		m_meshes;
 	std::vector<RAS_MeshObject*>		m_lodmeshes;
+	int                                 m_currentLodLevel;
 	SG_QList							m_meshSlots;	// head of mesh slots of this 
 	struct Object*						m_pBlenderObject;
 	struct Object*						m_pBlenderGroupObject;




More information about the Bf-blender-cvs mailing list