diff options
author | Daniel Stokes <kupomail@gmail.com> | 2013-12-18 02:42:47 +0400 |
---|---|---|
committer | kupoman <kupomail@gmail.com> | 2013-12-18 05:03:27 +0400 |
commit | e9e08a1d12594eab0e341049fc252ff8578e9333 (patch) | |
tree | ac7c15959b03398babb68058f3824c2a4dbff5b7 /source/gameengine/Ketsji/KX_GameObject.cpp | |
parent | 173f7a3d30db8cba95656bf03dc842b9300c2436 (diff) |
Game Engine: Level of detail support and tools
Levels of detail can be added and modified in the object panel. The object
panel also contains new tools for generating levels of detail, setting up
levels of detail based on object names (useful for importing), and
clearing an object's level of detail settings. This is meant as a game
engine feature, though the level of details settings can be previewed in
the viewport.
Reviewed By: moguri, nexyon, brecht
Differential Revision: http://developer.blender.org/D109
Diffstat (limited to 'source/gameengine/Ketsji/KX_GameObject.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_GameObject.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index d3b5a987138..8b7e6667fae 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -71,6 +71,8 @@ typedef unsigned long uint_ptr; #include "NG_NetworkScene.h" //Needed for sendMessage() #include "KX_ObstacleSimulation.h" +#include "BKE_object.h" + #include "BL_ActionManager.h" #include "BL_Action.h" @@ -732,6 +734,43 @@ void KX_GameObject::RemoveMeshes() m_meshes.clear(); } +void KX_GameObject::AddLodMesh(RAS_MeshObject* mesh) +{ + m_lodmeshes.push_back(mesh); +} + +void KX_GameObject::UpdateLod(MT_Vector3 &cam_pos) +{ + // Handle dupligroups + 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; + + MT_Vector3 delta = this->NodeGetWorldPosition() - cam_pos; + float distance2 = delta.length2(); + + int level = 0; + Object *bob = this->GetBlenderObject(); + LodLevel *lod = (LodLevel*) bob->lodlevels.first; + for (; lod; lod = lod->next, level++) { + if (!lod->source) level--; + if (!lod->next || lod->next->distance * lod->next->distance > distance2) break; + } + + RAS_MeshObject *mesh = this->m_lodmeshes[level]; + + if (mesh != this->m_meshes[0]) { + this->GetScene()->ReplaceMesh(this, mesh, true, false); + } +} + void KX_GameObject::UpdateTransform() { // HACK: saves function call for dynamic object, they are handled differently |