content/hifi-public/james/debug/testFindEntities.js
Dale Glass 0d14e5a379 Initial data.
Needs a lot of cleanup. Data has been de-duplicated, and where identical copies existed, one of them
has been replaced with a symlink.

Some files have been excluded, such as binaries, installers and debug dumps. Some of that may still
be present.
2022-02-13 18:59:11 +01:00

58 lines
No EOL
1.6 KiB
JavaScript

var totalTime = 0;
var lastUpdate = 0;
var UPDATE_INTERVAL = 1 / 5; // 5fps
Agent.isAvatar = true;
function searchForEntitiesToResetToOriginalPosition(searchOrigin, objectName, searchRadius) {
var ids = Entities.findEntities(searchOrigin, searchRadius);
EntityViewer.setPosition(searchOrigin);
EntityViewer.setKeyholeRadius(searchRadius);
EntityViewer.queryOctree();
print(objectName + " search found " + ids.length + " at " + JSON.stringify(searchOrigin));
ids.forEach(function(id) {
print('ENTITY ID FOUND::' + id);
})
var objects = [];
var i;
var entityID;
var name;
for (i = 0; i < ids.length; i++) {
entityID = ids[i];
name = Entities.getEntityProperties(entityID, "name").name;
print('ENTITY NAME IS:: ' + name);
if (name === objectName) {
//we found an object to reset
objects.push(entityID);
}
}
return objects;
}
function update(deltaTime) {
if (!Entities.serversExist() || !Entities.canRez()) {
return;
}
totalTime += deltaTime;
// We don't want to edit the entity EVERY update cycle, because that's just a lot
// of wasted bandwidth and extra effort on the server for very little visual gain
if (totalTime - lastUpdate > UPDATE_INTERVAL) {
var any = searchForEntitiesToResetToOriginalPosition({
x: 100,
y: 100,
z: 100
},
"ANY", 100);
lastUpdate = totalTime;
}
}
Script.update.connect(update);