Skip to content

Commit f9d7e24

Browse files
youle31panzergame
authored andcommitted
UPBGE: Implement physics and logic object activity culling.
The activity culling helps to disable the physics or logic of an object depending of its distance to the nearest camera. From user side options were added in both UI and python API to control this feature. In UI the activity culling is put in three level, scene, camera, object. The two first level are enabled as default and the last disabled. Also the object panel expose option to enabled physics or logic culling with a different radius. In python the attribute activityCulling is added to these three levels and KX_GameObject receive four attributes to enabled physics and logic culling and controlling their radius. In internal sources the activity culling info are stored into KX_GameObject::ActivityCullingInfo which is owned by in KX_GameObject::m_activityCullingInfo. To suspend logic we suspend from SCA_IObject calling Suspend and Resume but in the same time we need to suspend animation as they are independant of logic and that it will be hard to control them when the object doesn't run its logic. To do so BL_ActionManager implement a suspend flag which disallow any task creation in KX_Scene::UpdateAnimations. Thanks for youle's work on this.
1 parent f874e52 commit f9d7e24

File tree

27 files changed

+496
-126
lines changed

27 files changed

+496
-126
lines changed

doc/python_api/rst/bge_types/bge.types.KX_Camera.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ base class --- :class:`KX_GameObject`
8383

8484
:type: boolean
8585

86+
.. attribute:: activityCulling
87+
88+
True if this camera is used to compute object distance for object activity culling.
89+
90+
:type: boolean
91+
8692
.. attribute:: projection_matrix
8793

8894
This camera's 4x4 projection matrix.

doc/python_api/rst/bge_types/bge.types.KX_GameObject.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,32 @@ base class --- :class:`SCA_IObject`
300300

301301
:type: boolean
302302

303+
.. attribute:: physicsCulling
304+
305+
True if the object suspends its physics depending on its nearest distance to any camera.
306+
307+
:type: boolean
308+
309+
.. attribute:: logicCulling
310+
311+
True if the object suspends its logic and animation depending on its nearest distance to any camera.
312+
313+
:type: boolean
314+
315+
.. attribute:: physicsCullingRadius
316+
317+
Suspend object's physics if this radius is smaller than its nearest distance to any camera
318+
and :data:`physicsCulling` set to `True`.
319+
320+
:type: float
321+
322+
.. attribute:: logicCullingRadius
323+
324+
Suspend object's logic and animation if this radius is smaller than its nearest distance to any camera
325+
and :data:`logicCulling` set to `True`.
326+
327+
:type: float
328+
303329
.. attribute:: position
304330

305331
The object's position. [x, y, z] On write: local position, on read: world position

doc/python_api/rst/bge_types/bge.types.KX_Scene.rst

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,12 @@ base class --- :class:`EXP_PyObjectPlus`
113113

114114
:type: boolean
115115

116-
.. attribute:: activity_culling
116+
.. attribute:: activityCulling
117117

118-
True if the scene is activity culling.
118+
True if the scene allow object activity culling.
119119

120120
:type: boolean
121121

122-
.. attribute:: activity_culling_radius
123-
124-
The distance outside which to do activity culling. Measured in manhattan distance.
125-
126-
:type: float
127-
128122
.. attribute:: dbvt_culling
129123

130124
True when Dynamic Bounding box Volume Tree is set (read-only).

release/datafiles/locale

Submodule locale updated from 507eacd to 68c9db0

release/scripts/addons

Submodule addons updated from ff8ef5c to 29f2b2f

release/scripts/startup/bl_ui/properties_data_camera.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ def draw(self, context):
151151
col.prop(cam, "lod_factor", text="Distance Factor")
152152

153153

154-
class DATA_PT_frustum_culling(CameraButtonsPanel, Panel):
155-
bl_label = "Frustum Culling"
154+
class DATA_PT_culling(CameraButtonsPanel, Panel):
155+
bl_label = "Culling"
156156
COMPAT_ENGINES = {'BLENDER_GAME'}
157157

158158
@classmethod
@@ -163,9 +163,16 @@ def draw(self, context):
163163
layout = self.layout
164164
cam = context.camera
165165

166-
row = layout.row()
167-
row.prop(cam, "show_frustum")
168-
row.prop(cam, "override_culling")
166+
split = layout.split()
167+
168+
col = split.column()
169+
col.label(text="Frustum Culling:")
170+
col.prop(cam, "show_frustum")
171+
col.prop(cam, "override_culling")
172+
173+
col = split.column()
174+
col.label(text="Object Activity:")
175+
col.prop(cam, "use_object_activity_culling")
169176

170177

171178
class DATA_PT_camera_stereoscopy(CameraButtonsPanel, Panel):
@@ -365,7 +372,7 @@ def draw_display_safe_settings(layout, safe_data, settings):
365372
DATA_PT_lens,
366373
DATA_PT_camera,
367374
DATA_PT_levels_of_detail,
368-
DATA_PT_frustum_culling,
375+
DATA_PT_culling,
369376
DATA_PT_camera_stereoscopy,
370377
DATA_PT_camera_dof,
371378
DATA_PT_camera_display,

release/scripts/startup/bl_ui/properties_game.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,12 +526,19 @@ def draw(self, context):
526526
sub = col.row()
527527
sub.prop(gs, "deactivation_time", text="Time")
528528

529-
col = layout.column()
529+
split = layout.split()
530+
531+
col = split.column()
532+
col.label(text="Culling:")
530533
col.prop(gs, "use_occlusion_culling", text="Occlusion Culling")
531534
sub = col.column()
532535
sub.active = gs.use_occlusion_culling
533536
sub.prop(gs, "occlusion_culling_resolution", text="Resolution")
534537

538+
col = split.column()
539+
col.label(text="Object Activity:")
540+
col.prop(gs, "use_activity_culling")
541+
535542
else:
536543
split = layout.split()
537544

@@ -901,6 +908,33 @@ def draw(self, context):
901908
layout.label(text="Predefined Bound:")
902909
layout.prop(game, "predefined_bound", "")
903910

911+
class OBJECT_PT_activity_culling(ObjectButtonsPanel, Panel):
912+
bl_label = "Activity Culling"
913+
COMPAT_ENGINES = {'BLENDER_GAME'}
914+
915+
@classmethod
916+
def poll(cls, context):
917+
ob = context.object
918+
return context.scene.render.engine in cls.COMPAT_ENGINES and ob.type not in {'CAMERA'}
919+
920+
def draw(self, context):
921+
layout = self.layout
922+
activity = context.object.game.activity_culling
923+
924+
split = layout.split()
925+
926+
col = split.column()
927+
col.prop(activity, "use_physics", text="Physics")
928+
sub = col.column()
929+
sub.active = activity.use_physics
930+
sub.prop(activity, "physics_radius")
931+
932+
col = split.column()
933+
col.prop(activity, "use_logic", text="Logic")
934+
sub = col.column()
935+
sub.active = activity.use_logic
936+
sub.prop(activity, "logic_radius")
937+
904938
class OBJECT_PT_levels_of_detail(ObjectButtonsPanel, Panel):
905939
bl_label = "Levels of Detail"
906940
COMPAT_ENGINES = {'BLENDER_GAME'}
@@ -968,6 +1002,7 @@ def draw(self, context):
9681002
DATA_PT_shadow_game,
9691003
OBJECT_MT_lod_tools,
9701004
OBJECT_MT_culling,
1005+
OBJECT_PT_activity_culling,
9711006
OBJECT_PT_levels_of_detail,
9721007
)
9731008

source/blender/blenkernel/intern/camera.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ void BKE_camera_init(Camera *cam)
7171
cam->drawsize = 0.5f;
7272
cam->ortho_scale = 6.0;
7373
cam->flag |= CAM_SHOWPASSEPARTOUT;
74+
cam->gameflag = GAME_CAM_OBJECT_ACTIVITY_CULLING;
7475
cam->passepartalpha = 0.5f;
7576
cam->lodfactor = 1.0f;
7677

source/blender/blenkernel/intern/scene.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ void BKE_scene_init(Scene *sce)
784784

785785
sce->gm.gravity = 9.8f;
786786
sce->gm.physicsEngine = WOPHY_BULLET;
787-
sce->gm.mode = 32; //XXX ugly harcoding, still not sure we should drop mode. 32 == 1 << 5 == use_occlusion_culling
787+
sce->gm.mode = WO_ACTIVITY_CULLING | WO_DBVT_CULLING;
788788
sce->gm.occlusionRes = 128;
789789
sce->gm.ticrate = 60;
790790
sce->gm.maxlogicstep = 5;

source/blender/blenloader/intern/versioning_upbge.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "DNA_screen_types.h"
4646
#include "DNA_mesh_types.h"
4747
#include "DNA_material_types.h"
48+
#include "DNA_world_types.h"
4849

4950
#include "BKE_main.h"
5051

@@ -253,4 +254,14 @@ void blo_do_versions_upbge(FileData *fd, Library *lib, Main *main)
253254
}
254255
}
255256
}
257+
258+
if (!MAIN_VERSION_UPBGE_ATLEAST(main, 2, 2)) {
259+
for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
260+
scene->gm.mode |= WO_ACTIVITY_CULLING;
261+
}
262+
263+
for (Camera *camera = main->camera.first; camera; camera = camera->id.next) {
264+
camera->gameflag |= GAME_CAM_OBJECT_ACTIVITY_CULLING;
265+
}
266+
}
256267
}

0 commit comments

Comments
 (0)