Show objects with matching collision groups

Hi everyone,

here’s a simple script to show objects which have intersecting collision masks and groups in the engine, which also have matching physics type (i.e Static<->Dynamic, rather than Static<->Static). Simple run it once to show a new drop down menu in the Physics Properties.

# ##### BEGIN GPL LICENSE BLOCK ######
# This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
import bpy




bl_info = {
    "name": "Show Physics Relations",
    "description": "Displays GameObjects whose masks and groups intersect.",
    "author": "Angus Hollands",
    "version": (1, 0, 1),
    "blender": (2, 71, 0),
    "api": 56945,
    "location": "PROPERTIES_EDITOR &gt; PHYSICS &gt; MATCHING_COLLIDERS",
    "warning": "",
    "wiki_url": "",
    "tracker_url": "",
    "category": "Game Engine"}




def mask_intersection(mask, group):
    for m, g in zip(mask, group):
        if m and g:
            return True
    
    return False


    
@bpy.app.handlers.persistent
def update(scene):
    obj = scene.objects.active
    obj.matching_colliders.clear()


    obj_game = obj.game


    no_physics_set = {'NO_COLLISION', 'NAVMESH', 'OCCLUDE'}
    no_collision_when_equal = ('STATIC', 'SENSOR')




    for other in scene.objects:
        if other == obj:
            continue


        other_game = other.game


        obj_collision_type = obj_game.physics_type
        other_collision_type = other_game.physics_type


        if not mask_intersection(other_game.collision_mask, obj_game.collision_group):
            continue


        if not mask_intersection(obj_game.collision_mask, other_game.collision_group):
            continue


        # Same physics type
        if obj_collision_type == other_collision_type:
            if obj_collision_type in no_collision_when_equal:
                continue


        if no_physics_set.intersection((obj_collision_type, other_collision_type)):
            continue


        entry = obj.matching_colliders.add()
        entry.name = other.name




def draw(self, context):
    layout = self.layout


    obj = context.object


    layout.label("Matching Colliders")
    layout.template_list("OBJECT_UL_physics_matching_colliders", "collider_matches", obj, "matching_colliders", obj,
                         "matching_collider")




class GroupItem(bpy.types.PropertyGroup):
    pass




class OBJECT_UL_physics_matching_colliders(bpy.types.UIList):


    def draw_item(self, context, layout, data, item, icon_value, active_data, active_propname):
        obj = item
        icon = 'OBJECT_DATA'


        if self.layout_type in {'GRID'}:
            layout.alignment = 'CENTER'


        layout.label(text=obj.name, icon=icon)




def register():
    bpy.utils.register_module(__name__)
    bpy.types.Object.matching_colliders = bpy.props.CollectionProperty(type=GroupItem)
    bpy.types.Object.matching_collider = bpy.props.IntProperty()


    bpy.types.PHYSICS_PT_game_physics.append(draw)
    bpy.app.handlers.scene_update_pre.append(update)




def unregister():
    bpy.types.PHYSICS_PT_game_physics.remove(draw)
    bpy.utils.unregister_module(__name__)
    bpy.app.handlers.scene_update_pre.remove(update)


    
if __name__ == "__main__":
    register()

Alternatively, here’s an add-on version.
physics_relations.zip (3.75 KB)


Updated to provide add-on, and consider the physics type

Nice work!

Nice- its these litle things that need to trickle into the trunk versions!

Great job agoose77

I discovered collision group and mask recently but I found little information about it

Fixed rather large oversight, due to use of sets.