The ammo/bullet API allows you to assign physics objects to groups and have them collide according to a mask. This can also be used with raycasting although none of this is exposed in the PlayCanvas API.
A project that shows how to use the groups can be found here: https://playcanvas.com/project/519294/overview/physics-mask
The minified code from Virtual Voodoo for the raycast is here:
var n = new Ammo.btVector3
, t = new Ammo.btVector3
, e = function(n, t, e) {
this.entity = n,
this.point = t,
this.normal = e
};
pc.RigidBodyComponentSystem.prototype.raycastFiltered = function(o, i, r, a) {
n.setValue(o.x, o.y, o.z),
t.setValue(i.x, i.y, i.z);
var l = new Ammo.ClosestRayResultCallback(n,t);
l.set_m_collisionFilterGroup(r),
l.set_m_collisionFilterMask(a),
this.app.systems.rigidbody.dynamicsWorld.rayTest(n, t, l);
var s = null;
if (l.hasHit()) {
var u = l.get_m_collisionObject()
, c = Ammo.castObject(u, Ammo.btRigidBody)
, m = l.get_m_hitPointWorld()
, d = l.get_m_hitNormalWorld();
c && (s = new e(c.entity,new pc.Vec3(m.x(),m.y(),m.z()),new pc.Vec3(d.x(),d.y(),d.z())))
}
return Ammo.destroy(l),
s
}