[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [57952] branches/soc-2013-bge/source/ gameengine/Ketsji: The level of detail system now works in the game engine with group instances .

Daniel Stokes kupomail at gmail.com
Wed Jul 3 05:18:47 CEST 2013


Revision: 57952
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57952
Author:   kupoman
Date:     2013-07-03 03:18:44 +0000 (Wed, 03 Jul 2013)
Log Message:
-----------
The level of detail system now works in the game engine with group instances. This required the game engine to reimplement some of the level of detail logic, but not too much.

Modified Paths:
--------------
    branches/soc-2013-bge/source/gameengine/Ketsji/KX_GameObject.cpp
    branches/soc-2013-bge/source/gameengine/Ketsji/KX_GameObject.h
    branches/soc-2013-bge/source/gameengine/Ketsji/KX_Scene.cpp

Modified: branches/soc-2013-bge/source/gameengine/Ketsji/KX_GameObject.cpp
===================================================================
--- branches/soc-2013-bge/source/gameengine/Ketsji/KX_GameObject.cpp	2013-07-03 01:20:32 UTC (rev 57951)
+++ branches/soc-2013-bge/source/gameengine/Ketsji/KX_GameObject.cpp	2013-07-03 03:18:44 UTC (rev 57952)
@@ -716,14 +716,31 @@
 	m_meshes.clear();
 }
 
-void KX_GameObject::UpdateLod(float cam_pos[3])
+void KX_GameObject::UpdateLod(MT_Vector3 &cam_pos)
 {
+	if (this->m_pInstanceObjects) {
+		KX_GameObject * instob;
+		int count = this->m_pInstanceObjects->GetCount();
+		for (int i = 0; i < count; i++) {
+			instob = (KX_GameObject*)this->m_pInstanceObjects->GetValue(i);
+			instob->UpdateLod(cam_pos);
+		}
+	}
+
 	if (this->m_lodmeshes.empty()) return;
 
-	Object* bob = this->GetBlenderObject();
-	if (BKE_object_lod_update(bob, cam_pos)) {
-		LodLevel* lod = bob->currentlod;
-		RAS_MeshObject* mesh = this->m_lodmeshes[lod->level];
+	MT_Vector3 delta = this->NodeGetWorldPosition() - cam_pos;
+	float distance2 = delta.dot(delta);
+
+	Object *bob = this->GetBlenderObject();
+	LodLevel *lod = (LodLevel*) bob->lodlevels.first;
+	for (int i = 0; lod; lod = lod->next, i++) {
+		if (!lod->next || lod->next->distance * lod->next->distance > distance2) break;
+	}
+
+	RAS_MeshObject *mesh = this->m_lodmeshes[lod->level];
+
+	if (mesh != this->m_meshes[0]) {
 		this->GetScene()->ReplaceMesh(this, mesh, true, false);
 	}
 }

Modified: branches/soc-2013-bge/source/gameengine/Ketsji/KX_GameObject.h
===================================================================
--- branches/soc-2013-bge/source/gameengine/Ketsji/KX_GameObject.h	2013-07-03 01:20:32 UTC (rev 57951)
+++ branches/soc-2013-bge/source/gameengine/Ketsji/KX_GameObject.h	2013-07-03 03:18:44 UTC (rev 57952)
@@ -772,7 +772,7 @@
 	 */
 		void
 	UpdateLod(
-		float cam_pos[3]
+		MT_Vector3 &cam_pos
 	);
 
 	/**

Modified: branches/soc-2013-bge/source/gameengine/Ketsji/KX_Scene.cpp
===================================================================
--- branches/soc-2013-bge/source/gameengine/Ketsji/KX_Scene.cpp	2013-07-03 01:20:32 UTC (rev 57951)
+++ branches/soc-2013-bge/source/gameengine/Ketsji/KX_Scene.cpp	2013-07-03 03:18:44 UTC (rev 57952)
@@ -1647,8 +1647,7 @@
 void KX_Scene::UpdateObjectLods(void)
 {
 	KX_GameObject* gameobj;
-	float cam_pos[3];
-	this->m_active_camera->NodeGetWorldPosition().getValue(cam_pos);
+	MT_Vector3 cam_pos = this->m_active_camera->NodeGetWorldPosition();
 
 	for (int i = 0; i < this->GetObjectList()->GetCount(); i++) {
 		gameobj = (KX_GameObject*) GetObjectList()->GetValue(i);




More information about the Bf-blender-cvs mailing list