Raycast and collision filtering

I almost finished implementing my (technical) POC.

But, I need to process raycasts through a group of objects! Everything about that it’s welcome.
I’m reading the code and bullet API. the bullet Lib implements two features: mask & group…
++

I implemented a work-around : I call recursivly the RayCast to ignore the group of object.

But I found the code, and group/mask are implemented ! !? bullet-group and Bullet-mask is mapped to collision_collections:

In UI Blender3d :

I will try collision collection in blender and effects in Armory3d .

Armory3D set group and mask with the same value, therefore we can’t use layer collision matrix

which objects can collide with which Layers.

So, I found …

BulletAPI > RayResultCallback :

  • short int m_collisionFilterGroup
  • short int m_collisionFilterMask

Accordingly in the Haxebullet Port > btCollisionWorld.h
but not in Haxe definitions

I changed two files:

# haxebullet > Sources/bullet/Bt.hx
@:native('Ammo.RayResultCallback')
extern class RayResultCallback {
    public function hasHit():Bool;
    public function new():Void;
    public function get_m_collisionFilterGroup():Int;
    public function set_m_collisionFilterGroup(g:Int):Void;
    public function get_m_collisionFilterMask():Int;
    public function set_m_collisionFilterMask(m:Int):Void;
    public function get_m_collisionObject():CollisionObject;
}
# Armory3d > PhysicsWorld.rayCast()

	public function rayCast(from:Vec4, to:Vec4, group:Int=0x00000001,mask=0xFFFFFFFF):Hit {
		var rayFrom = vec1;
		var rayTo = vec2;
		rayFrom.setValue(from.x, from.y, from.z);
		rayTo.setValue(to.x, to.y, to.z);

		var rayCallback = new bullet.Bt.ClosestRayResultCallback(rayFrom, rayTo);
		rayCallback.set_m_collisionFilterGroup(group);
		rayCallback.set_m_collisionFilterMask(mask);
(...)

The first try works! I’m testing more cases…

2 Likes

Blender3d is too basic, we can set groups but not the mask :(!

I implemented the UI in the add-on. But I don’t know how to create the same look and feel of Collections panel (see bellow) !?


ArmorySDK\armory\blender\arm\props.py
ArmorySDK\armory\blender\arm\props_ui.py

4 Likes

I found with the Blender3D documentation but it’s so hard: now, the collision filter mask is set by a “layer picker” :


    bpy.types.Object.arm_rb_collision_filter_mask = bpy.props.BoolVectorProperty(
        name="Collision Filter Mask",
        default=(True, False, False,False,False,False, False, False,False,False,False, False, False,False,False,False, False, False,False,False),
        size=20,
        subtype='LAYER')

I edited the exporter.py and everything works in Armory3D.

I could add the mask in the physicRayCast Node and I will create pull-requests!!

omg! I’m so happy. :smile:
That’s one small step for [a] coder, one giant leap for game creators :partying_face:

4 Likes

I pushed the code

I’m implementing Node integration of the feature :
->

3 Likes

Pretty good seeing your progress! :grinning: is in your plans creating a PR so we can get those goodies in the official repo? :thinking: :+1:

Hello,

I found an issue in official SDK : Convex hull shape isn’t processed in target C++ (Windows)…!?:upside_down_face:
deepkeras

But everything is ok for “collision filter mask”.

I created PRs :


EDIT : Merged!

3 Likes

I still don’t understand how to make raycast ignore an object, I tried setting object colliosion filter mask to certain layer and set this layer in mask in rayCast(), but still don’t work properly. Is it possible for you to update Physics_raycast example with this new feature.

Edit: nvm, I got it, the object you want ray cast to ignore set it collision mask to 2nd

1 Like

Voila, see attachment below :

colision-filter.blend (697.1 KB)

1 Like

Changing object’s collision filter mask using code during runtime using:

Scene.active.getChild("object").getTrait(RigidBody).mask = 2;

doesn’t work, any idea?

You have to update or destroy/create the nested bullet object (body).

Edit: why? This is strange operation.

First, I need to raycast to get object, than I need to raycast behind the object and get it loc, for example in my city building sim game, I need to raycast and check if ray hitted building, if it do than cast another ray to the ground and then update the building position to hit loc on plane every frame, but doing so the building is blocking the raycast from reaching the ground, so i need to above, or some other way.

Here, how it is working:


How it should be working:

(notice, cube doesn’t move unless cursor is on ground, in first gif, but cube move even when cursor is on cube in second gif)
(In second gif, cube’s collision filter mask is set to 2, this is what I hope to do with above code).
Maybe, I can just keep it the way it is.

You have to create two groups:

  • the ground in “group 1”
  • buildings in “group 2”

Accordingly, you can hit the “group 1” (ground) with the bitmask x10000.
And if you use the gravity on buildings set the mask 1 & 2 in the physic panel.

1 Like

Aight!, thanks!, got it working!

@Marc For some reason, the collision filter mask options are not showing for me in the rigid body tab? and any scene with a rigid body object throws errors? made a thread about it here with a screenshot of the error - Getting errors relating to rigid body collision masks?. Any ideas why this is happening? all the files are installed correctly, it just doesnt seem to work for me?

I figured it out. start.py was not updating in my scripts folder, had to manually copy and paste it. :slight_smile:

Now do I need to check twice for an object have both the physical collision and raycast detection?

image

I thought the “Trigger” button was to differ/toggle this :thinking:

You have to set collision filter mask even if you don’t needs raycast.

When armory engine adds an rigid body to bullet’s world, it is set group and mask.
And each frame bullet applies the rigid body’s collision mask.

I’m sorry but I’m not sure I understand.

If I keep the same setup here (only checking in collection filter), the game is working normally, only without the raycast function. Is it the expected behavior?

By default, when adding new objects, shouldn’t all raycast groups be enabled?
At first look, I don’t see a practical use of this function if before a single option toggle collision and raycast.

Wouldn’t it be better to put a button to switch whether or not the object would be detected by the raycast?