diff --git a/examples/rayPickingFilterExample.js b/examples/rayPickingFilterExample.js index aa1950c013..a373840e72 100644 --- a/examples/rayPickingFilterExample.js +++ b/examples/rayPickingFilterExample.js @@ -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); \ No newline at end of file + 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); \ No newline at end of file diff --git a/libraries/entities/src/EntityTreeElement.cpp b/libraries/entities/src/EntityTreeElement.cpp index 17f967fc1f..8944c95cbc 100644 --- a/libraries/entities/src/EntityTreeElement.cpp +++ b/libraries/entities/src/EntityTreeElement.cpp @@ -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; }