[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [57899] branches/soc-2013-bge/source: Starting support for mesh and material levels of detail in the game engine .
Daniel Stokes
kupomail at gmail.com
Mon Jul 1 11:12:40 CEST 2013
Revision: 57899
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57899
Author: kupoman
Date: 2013-07-01 09:12:40 +0000 (Mon, 01 Jul 2013)
Log Message:
-----------
Starting support for mesh and material levels of detail in the game engine. They work for simple cases, but break in more advanced usage such as dupligroups.
Modified Paths:
--------------
branches/soc-2013-bge/source/blender/makesdna/DNA_object_types.h
branches/soc-2013-bge/source/gameengine/Converter/BL_BlenderDataConversion.cpp
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_KetsjiEngine.cpp
branches/soc-2013-bge/source/gameengine/Ketsji/KX_Scene.cpp
branches/soc-2013-bge/source/gameengine/Ketsji/KX_Scene.h
Modified: branches/soc-2013-bge/source/blender/makesdna/DNA_object_types.h
===================================================================
--- branches/soc-2013-bge/source/blender/makesdna/DNA_object_types.h 2013-07-01 09:10:05 UTC (rev 57898)
+++ branches/soc-2013-bge/source/blender/makesdna/DNA_object_types.h 2013-07-01 09:12:40 UTC (rev 57899)
@@ -105,7 +105,8 @@
typedef struct LodLevel {
struct LodLevel *next, *prev;
struct Object *source;
- char use_mesh, use_mat, use_logic, pad;
+ char level; /* for BGE usage to handle lookups */
+ char use_mesh, use_mat, use_logic;
float distance;
} LodLevel;
Modified: branches/soc-2013-bge/source/gameengine/Converter/BL_BlenderDataConversion.cpp
===================================================================
--- branches/soc-2013-bge/source/gameengine/Converter/BL_BlenderDataConversion.cpp 2013-07-01 09:10:05 UTC (rev 57898)
+++ branches/soc-2013-bge/source/gameengine/Converter/BL_BlenderDataConversion.cpp 2013-07-01 09:12:40 UTC (rev 57899)
@@ -96,6 +96,7 @@
#include "KX_SoftBodyDeformer.h"
//#include "BL_ArmatureController.h"
#include "BLI_utildefines.h"
+#include "BLI_listbase.h"
#include "BlenderWorldInfo.h"
#include "KX_KetsjiEngine.h"
@@ -1076,8 +1077,12 @@
RAS_MeshObject *meshobj;
int lightlayer = blenderobj ? blenderobj->lay:(1<<20)-1; // all layers if no object.
- if ((meshobj = converter->FindGameMesh(mesh/*, ob->lay*/)) != NULL)
- return meshobj;
+ if ((meshobj = converter->FindGameMesh(mesh/*, ob->lay*/)) != NULL) {
+ STR_String bge_name = meshobj->GetName();
+ STR_String blender_name = ((Mesh*)blenderobj->data)->id.name+2;
+ if (bge_name == blender_name)
+ return meshobj;
+ }
// Get DerivedMesh data
DerivedMesh *dm = CDDM_from_mesh(mesh, blenderobj);
DM_ensure_tessface(dm);
@@ -1989,6 +1994,23 @@
// set transformation
gameobj->AddMesh(meshobj);
+
+ if (BLI_countlist(&ob->lodlevels) > 1) {
+ LodLevel *lod = ((LodLevel*)ob->lodlevels.first)->next;
+ Mesh* lodmesh = mesh;
+ Object* lodmatob = ob;
+ gameobj->AddLodMesh(meshobj);
+ for (int i = 1; lod; lod = lod->next, i++) {
+ lod->level = i;
+ if (lod->use_mesh) {
+ lodmesh = static_cast<Mesh*>(lod->source->data);
+ }
+ if (lod->use_mat) {
+ lodmatob = lod->source;
+ }
+ gameobj->AddLodMesh(BL_ConvertMesh(lodmesh, lodmatob, kxscene, converter, libloading));
+ }
+ }
// for all objects: check whether they want to
// respond to updates
Modified: branches/soc-2013-bge/source/gameengine/Ketsji/KX_GameObject.cpp
===================================================================
--- branches/soc-2013-bge/source/gameengine/Ketsji/KX_GameObject.cpp 2013-07-01 09:10:05 UTC (rev 57898)
+++ branches/soc-2013-bge/source/gameengine/Ketsji/KX_GameObject.cpp 2013-07-01 09:12:40 UTC (rev 57899)
@@ -70,6 +70,8 @@
#include "NG_NetworkScene.h" //Needed for sendMessage()
#include "KX_ObstacleSimulation.h"
+#include "BKE_object.h"
+
#include "BL_ActionManager.h"
#include "PyObjectPlus.h" /* python stuff */
@@ -714,6 +716,18 @@
m_meshes.clear();
}
+void KX_GameObject::UpdateLod(float cam_pos[3])
+{
+ 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];
+ this->GetScene()->ReplaceMesh(this, mesh, true, false);
+ }
+}
+
void KX_GameObject::UpdateTransform()
{
// HACK: saves function call for dynamic object, they are handled differently
Modified: branches/soc-2013-bge/source/gameengine/Ketsji/KX_GameObject.h
===================================================================
--- branches/soc-2013-bge/source/gameengine/Ketsji/KX_GameObject.h 2013-07-01 09:10:05 UTC (rev 57898)
+++ branches/soc-2013-bge/source/gameengine/Ketsji/KX_GameObject.h 2013-07-01 09:12:40 UTC (rev 57899)
@@ -88,6 +88,7 @@
STR_String m_text;
int m_layer;
std::vector<RAS_MeshObject*> m_meshes;
+ std::vector<RAS_MeshObject*> m_lodmeshes;
SG_QList m_meshSlots; // head of mesh slots of this
struct Object* m_pBlenderObject;
struct Object* m_pBlenderGroupObject;
@@ -756,6 +757,25 @@
}
/**
+ * Add a level of detail mesh to the object. These should
+ * be added in order.
+ */
+ void
+ AddLodMesh(
+ RAS_MeshObject* mesh
+ ) {
+ m_lodmeshes.push_back(mesh);
+ }
+
+ /**
+ * Updates the current lod level based on distance from camera.
+ */
+ void
+ UpdateLod(
+ float cam_pos[3]
+ );
+
+ /**
* Pick out a mesh associated with the integer 'num'.
*/
RAS_MeshObject*
Modified: branches/soc-2013-bge/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
===================================================================
--- branches/soc-2013-bge/source/gameengine/Ketsji/KX_KetsjiEngine.cpp 2013-07-01 09:10:05 UTC (rev 57898)
+++ branches/soc-2013-bge/source/gameengine/Ketsji/KX_KetsjiEngine.cpp 2013-07-01 09:12:40 UTC (rev 57899)
@@ -324,6 +324,9 @@
// pass the scene's worldsettings to the rasterizer
SetWorldSettings(scene->GetWorldInfo());
+ // update levels of detail
+ scene->UpdateObjectLods();
+
// shadow buffers
if (i == 0) {
RenderShadowBuffers(scene);
@@ -894,6 +897,9 @@
// this is now done incrementatlly in KX_Scene::CalculateVisibleMeshes
//scene->UpdateMeshTransformations();
+ // update levels of detail
+ scene->UpdateObjectLods();
+
// shadow buffers
RenderShadowBuffers(scene);
Modified: branches/soc-2013-bge/source/gameengine/Ketsji/KX_Scene.cpp
===================================================================
--- branches/soc-2013-bge/source/gameengine/Ketsji/KX_Scene.cpp 2013-07-01 09:10:05 UTC (rev 57898)
+++ branches/soc-2013-bge/source/gameengine/Ketsji/KX_Scene.cpp 2013-07-01 09:12:40 UTC (rev 57899)
@@ -1644,6 +1644,18 @@
}
}
+void KX_Scene::UpdateObjectLods(void)
+{
+ KX_GameObject* gameobj;
+ float cam_pos[3];
+ this->m_active_camera->NodeGetWorldPosition().getValue(cam_pos);
+
+ for (int i = 0; i < this->GetObjectList()->GetCount(); i++) {
+ gameobj = (KX_GameObject*) GetObjectList()->GetValue(i);
+ gameobj->UpdateLod(cam_pos);
+ }
+}
+
void KX_Scene::UpdateObjectActivity(void)
{
if (m_activity_culling) {
Modified: branches/soc-2013-bge/source/gameengine/Ketsji/KX_Scene.h
===================================================================
--- branches/soc-2013-bge/source/gameengine/Ketsji/KX_Scene.h 2013-07-01 09:10:05 UTC (rev 57898)
+++ branches/soc-2013-bge/source/gameengine/Ketsji/KX_Scene.h 2013-07-01 09:12:40 UTC (rev 57899)
@@ -544,6 +544,9 @@
// Resume a suspended scene.
void Resume();
+
+ // Update the mesh for objects based on level of detail settings
+ void UpdateObjectLods(void);
// Update the activity box settings for objects in this scene, if needed.
void UpdateObjectActivity(void);
More information about the Bf-blender-cvs
mailing list