Merge pull request #2112 from SunDaw/pick-rb-node-mask

Add mask option to pick RB node and physicsworld
This commit is contained in:
Lubos Lenco 2021-02-20 09:05:03 +01:00 committed by GitHub
commit a25c5a744b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 5 deletions

View file

@ -12,12 +12,13 @@ class PickObjectNode extends LogicNode {
override function get(from: Int): Dynamic {
var coords: Vec4 = inputs[0].get();
var mask: Int = inputs[1].get();
if (coords == null) return null;
#if arm_physics
var physics = armory.trait.physics.PhysicsWorld.active;
var rb = physics.pickClosest(coords.x, coords.y);
var rb = physics.pickClosest(coords.x, coords.y, mask);
if (rb == null) return null;
if (from == 0) { // Object

View file

@ -324,12 +324,12 @@ class PhysicsWorld extends Trait {
}
}
public function pickClosest(inputX: Float, inputY: Float): RigidBody {
public function pickClosest(inputX: Float, inputY: Float, group: Int = 0x00000001, mask = 0xFFFFFFFF): RigidBody {
var camera = iron.Scene.active.camera;
var start = new Vec4();
var end = new Vec4();
RayCaster.getDirection(start, end, inputX, inputY, camera);
var hit = rayCast(camera.transform.world.getLoc(), end);
var hit = rayCast(camera.transform.world.getLoc(), end, group, mask);
var rb = (hit != null) ? hit.rb : null;
return rb;
}

View file

@ -1,8 +1,19 @@
from arm.logicnode.arm_nodes import *
class PickObjectNode(ArmLogicTreeNode):
"""Pickes the rigid body in the given location using the screen
coordinates (2D)."""
"""Picks the rigid body in the given location using the screen
coordinates (2D).
@seeNode Mask
@input Screen Coords: the location at which to pick, in screen
coordinates
@input Mask: a bit mask value to specify which
objects are considered
@output RB: the object that was hit
@output Hit: the hit position in world coordinates
"""
bl_idname = 'LNPickObjectNode'
bl_label = 'Pick RB'
arm_section = 'ray'
@ -11,6 +22,7 @@ class PickObjectNode(ArmLogicTreeNode):
def init(self, context):
super(PickObjectNode, self).init(context)
self.add_input('NodeSocketVector', 'Screen Coords')
self.add_input('NodeSocketInt', 'Mask', default_value=1)
self.add_output('ArmNodeSocketObject', 'RB')
self.add_output('NodeSocketVector', 'Hit')