mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 22:39:18 +02:00
Added logic to blacklist entities from raypicking
This commit is contained in:
parent
390dce4613
commit
8e7dfc07c0
2 changed files with 67 additions and 45 deletions
|
@ -1,50 +1,72 @@
|
||||||
var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(Camera.getOrientation())));
|
//
|
||||||
|
// rayPickingFilterExample.js
|
||||||
var whiteListBox = Entities.addEntity({
|
// examples
|
||||||
type: "Box",
|
//
|
||||||
color: {
|
// Created by Eric Levin on 12/24/2015
|
||||||
red: 10,
|
// Copyright 2015 High Fidelity, Inc.
|
||||||
green: 200,
|
//
|
||||||
blue: 10
|
// This is an example script that demonstrates the use of filtering entities for ray picking
|
||||||
},
|
//
|
||||||
dimensions: {
|
// Distributed under the Apache License, Version 2.0.
|
||||||
x: .2,
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
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})
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
function castRay(event) {
|
var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(Camera.getOrientation())));
|
||||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
|
||||||
var pickResults = Entities.findRayIntersection(pickRay, true, [], [blackListBox]);
|
|
||||||
|
|
||||||
if(pickResults.intersects) {
|
var whiteListBox = Entities.addEntity({
|
||||||
print("INTERSECTION");
|
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);
|
function castRay(event) {
|
||||||
Controller.mousePressEvent.connect(castRay);
|
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);
|
|
@ -522,7 +522,7 @@ bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, con
|
||||||
int entityNumber = 0;
|
int entityNumber = 0;
|
||||||
bool somethingIntersected = false;
|
bool somethingIntersected = false;
|
||||||
forEachEntity([&](EntityItemPointer entity) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue