diff options
author | Jorge Bernal <jbernalmartinez@gmail.com> | 2015-03-22 20:13:53 +0300 |
---|---|---|
committer | Jorge Bernal <jbernalmartinez@gmail.com> | 2015-03-22 20:19:49 +0300 |
commit | e7d051043dc82c2991eb491e0630d9b1065934c3 (patch) | |
tree | 83e6c88e2ebdfca3ffb50814d66c525c5d5bb231 /source/gameengine | |
parent | 0b4a71b07245d5370a02fae4dbde9195c9c58881 (diff) |
BGE: New hysteresis offset to improve LOD level transitions
This change introduces a new hysteresis parameter that it will be added
or subtracted to/from the LOD distance to avoid popping when a LOD
object moves close to the LOD transition continuously.
Then, we have the following:
- a new LOD Hysteresis setting per scene (default 10%) which is located
in Scene context --> Level of Detail panel. This scene parameter also
will active/deactive the scene hysteresis.
- and a new LOD Hysteresis setting per object (default 10%) which is
located in Object context --> Levels of Detail panel. The LOD hysteresis
setting per object (if active) will overwrite the hysteresis setting per
scene value.
For the new blends: the hysteresis setting per scene would be active by
default and the per object would be inactive by default.
For the old blends: both hysteresis settings (per scene and per object)
would be inactive by default. A quick way to take advantage of this
feature for old blends would be to activate the hysteresis parameter in
the scene context -> Level of Detail panel
Reviewers: campbellbarton, kupoman, moguri
Reviewed By: kupoman, moguri
Subscribers: nonamejuju, lordodin
Differential Revision: https://developer.blender.org/D957
Diffstat (limited to 'source/gameengine')
-rw-r--r-- | source/gameengine/Converter/BL_BlenderDataConversion.cpp | 4 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_GameObject.cpp | 42 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_GameObject.h | 10 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_Scene.cpp | 13 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_Scene.h | 9 |
5 files changed, 76 insertions, 2 deletions
diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index cd2e2151034..7b5cc457ee6 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -1554,6 +1554,10 @@ static KX_GameObject *gameobject_from_blenderobject( } gameobj->AddLodMesh(BL_ConvertMesh(lodmesh, lodmatob, kxscene, converter, libloading)); } + if (blenderscene->gm.lodflag & SCE_LOD_USE_HYST) { + kxscene->SetLodHysteresis(true); + gameobj->SetLodHysteresisValue(blenderscene->gm.scehysteresis); + } } // for all objects: check whether they want to diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index c8fc64f4679..16dfe5bd9de 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -92,6 +92,8 @@ KX_GameObject::KX_GameObject( m_bDyna(false), m_layer(0), m_currentLodLevel(0), + m_previousLodLevel(0), + m_lodHysteresis(0), m_pBlenderObject(NULL), m_pBlenderGroupObject(NULL), m_bSuspendDynamics(false), @@ -784,6 +786,11 @@ void KX_GameObject::AddLodMesh(RAS_MeshObject* mesh) m_lodmeshes.push_back(mesh); } +void KX_GameObject::SetLodHysteresisValue(int hysteresis) +{ + m_lodHysteresis = hysteresis; +} + void KX_GameObject::UpdateLod(MT_Vector3 &cam_pos) { // Handle dupligroups @@ -804,14 +811,47 @@ void KX_GameObject::UpdateLod(MT_Vector3 &cam_pos) int level = 0; Object *bob = this->GetBlenderObject(); LodLevel *lod = (LodLevel*) bob->lodlevels.first; + KX_Scene *sce = this->GetScene(); + for (; lod; lod = lod->next, level++) { if (!lod->source || lod->source->type != OB_MESH) level--; - if (!lod->next || lod->next->distance * lod->next->distance > distance2) break; + if (!lod->next) break; + if (level == (this->m_previousLodLevel) || (level == (this->m_previousLodLevel + 1))) { + short hysteresis = 0; + if (sce->IsActivedLodHysteresis()) { + // if exists, LoD level hysteresis will override scene hysteresis + if (lod->next->flags & OB_LOD_USE_HYST) { + hysteresis = lod->next->obhysteresis; + } + else if (this->m_lodHysteresis != 0) { + hysteresis = m_lodHysteresis; + } + } + float hystvariance = MT_abs(lod->next->distance - lod->distance) * hysteresis / 100; + if ((lod->next->distance + hystvariance) * (lod->next->distance + hystvariance) > distance2) + break; + } + else if (level == (this->m_previousLodLevel - 1)) { + short hysteresis = 0; + if (sce->IsActivedLodHysteresis()) { + // if exists, LoD level hysteresis will override scene hysteresis + if (lod->next->flags & OB_LOD_USE_HYST) { + hysteresis = lod->next->obhysteresis; + } + else if (this->m_lodHysteresis != 0) { + hysteresis = m_lodHysteresis; + } + } + float hystvariance = MT_abs(lod->next->distance - lod->distance) * hysteresis / 100; + if ((lod->next->distance - hystvariance) * (lod->next->distance - hystvariance) > distance2) + break; + } } RAS_MeshObject *mesh = this->m_lodmeshes[level]; this->m_currentLodLevel = level; if (mesh != this->m_meshes[0]) { + this->m_previousLodLevel = level; this->GetScene()->ReplaceMesh(this, mesh, true, false); } } diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index 132e72c45e2..d9810b89c90 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -90,6 +90,8 @@ protected: std::vector<RAS_MeshObject*> m_meshes; std::vector<RAS_MeshObject*> m_lodmeshes; int m_currentLodLevel; + short m_previousLodLevel; + int m_lodHysteresis; SG_QList m_meshSlots; // head of mesh slots of this struct Object* m_pBlenderObject; struct Object* m_pBlenderGroupObject; @@ -805,6 +807,14 @@ public: ); /** + * Set lod hysteresis value + */ + void + SetLodHysteresisValue( + int hysteresis + ); + + /** * Updates the current lod level based on distance from camera. */ void diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 47510baa436..d9d07e78c17 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -156,7 +156,8 @@ KX_Scene::KX_Scene(class SCA_IInputDevice* keyboarddevice, m_networkDeviceInterface(ndi), m_active_camera(NULL), m_ueberExecutionPriority(0), - m_blenderScene(scene) + m_blenderScene(scene), + m_isActivedHysteresis(false) { m_suspendedtime = 0.0; m_suspendeddelta = 0.0; @@ -1763,6 +1764,16 @@ void KX_Scene::UpdateObjectLods(void) } } +void KX_Scene::SetLodHysteresis(bool active) +{ + m_isActivedHysteresis = active; +} + +bool KX_Scene::IsActivedLodHysteresis(void) +{ + return m_isActivedHysteresis; +} + void KX_Scene::UpdateObjectActivity(void) { if (m_activity_culling) { diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h index 2e1ee9f101d..19873daabb3 100644 --- a/source/gameengine/Ketsji/KX_Scene.h +++ b/source/gameengine/Ketsji/KX_Scene.h @@ -295,6 +295,11 @@ protected: KX_ObstacleSimulation* m_obstacleSimulation; + /** + * Does this scene active the LoD Hysteresis? + */ + bool m_isActivedHysteresis; + public: KX_Scene(class SCA_IInputDevice* keyboarddevice, class SCA_IInputDevice* mousedevice, @@ -546,6 +551,10 @@ public: // Update the mesh for objects based on level of detail settings void UpdateObjectLods(void); + + // Enable/disable LoD Hysteresis + void SetLodHysteresis(bool active); + bool IsActivedLodHysteresis(); // Update the activity box settings for objects in this scene, if needed. void UpdateObjectActivity(void); |