Added logic to blacklist entities from raypicking

This commit is contained in:
ericrius1 2015-12-24 11:59:47 -08:00
parent 390dce4613
commit 8e7dfc07c0
2 changed files with 67 additions and 45 deletions

View file

@ -1,50 +1,72 @@
var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(Camera.getOrientation())));
var whiteListBox = Entities.addEntity({
type: "Box",
color: {
red: 10,
green: 200,
blue: 10
},
dimensions: {
x: .2,
y: .2,
z: .2
},
position: center
});
var blackListBox = Entities.addEntity({
type: "Box",
color: {
red: 100,
green: 10,
blue: 10
},
dimensions: {
x: .2,
y: .2,
z: .2
},
position: Vec3.sum(center, {x: 0, y: .3, z: 0})
});
//
// rayPickingFilterExample.js
// examples
//
// Created by Eric Levin on 12/24/2015
// Copyright 2015 High Fidelity, Inc.
//
// This is an example script that demonstrates the use of filtering entities for ray picking
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
function castRay(event) {
var pickRay = Camera.computePickRay(event.x, event.y);
var pickResults = Entities.findRayIntersection(pickRay, true, [], [blackListBox]);
var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(Camera.getOrientation())));
if(pickResults.intersects) {
print("INTERSECTION");
}
var whiteListBox = Entities.addEntity({
type: "Box",
color: {
red: 10,
green: 200,
blue: 10
},
dimensions: {
x: 0.2,
y: 0.2,
z: 0.2
},
position: center
});
}
var blackListBox = Entities.addEntity({
type: "Box",
color: {
red: 100,
green: 10,
blue: 10
},
dimensions: {
x: 0.2,
y: 0.2,
z: 0.2
},
position: Vec3.sum(center, {
x: 0,
y: 0.3,
z: 0
})
});
function cleanup() {
Entities.deleteEntity(whiteListBox);
Entities.deleteEntity(blackListBox);
}
Script.scriptEnding.connect(cleanup);
Controller.mousePressEvent.connect(castRay);
function castRay(event) {
var pickRay = Camera.computePickRay(event.x, event.y);
// In this example every entity will be pickable except the entities in the blacklist array
// the third arg is the whitelist array,a nd the fourth and final is the blacklist array
var pickResults = Entities.findRayIntersection(pickRay, true, [], [blackListBox]);
// With below example, only entities adde dto whitelist will be pickable
// var pickResults = Entities.findRayIntersection(pickRay, true, [whiteListBox], []);
if (pickResults.intersects) {
print("INTERSECTION!");
}
}
function cleanup() {
Entities.deleteEntity(whiteListBox);
Entities.deleteEntity(blackListBox);
}
Script.scriptEnding.connect(cleanup);
Controller.mousePressEvent.connect(castRay);

View file

@ -522,7 +522,7 @@ bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, con
int entityNumber = 0;
bool somethingIntersected = false;
forEachEntity([&](EntityItemPointer entity) {
if (entityIdsToInclude.size() > 0 && !entityIdsToInclude.contains(entity->getID())) {
if ( (entityIdsToInclude.size() > 0 && !entityIdsToInclude.contains(entity->getID())) || (entityIDsToDiscard.size() > 0 && entityIDsToDiscard.contains(entity->getID())) ) {
return;
}