New findEntitiesExample


#1

Ok, here a new findEntitiesExample. Because the one i have in the dev version is broken. It would be nice to see this example back on http://jsref.docs.highfidelity.com/docs/template Mabye need a few small adjustments for the docs page.

This example find all entities in a radius of 10 meters around your avatar position and returns the ID of every entity in array format.

Run this example script from inside entity.

(function(){ 
    this.clickDownOnEntity = function(entityID, mouseEvent) {     
        var foundEntitiesArray = Entities.findEntities(MyAvatar.position, 10);
        print("found this many entities: "+ foundEntitiesArray.length);
        
        for (var i = 0; i < foundEntitiesArray.length; i++) {
            print("   foundEntities[" + i + "].id:" + foundEntitiesArray[i]);
        }        
    }
})

Is it possible to get the entities list from within an entity script? If so how is it done?
#2

I would imagine it will always find skyboxes that are around your center point as the find is spatial. The c++ code appears to be using an octree based bounding box search - very nice!


#3

The reply is for this topic ? https://forums.highfidelity.com/t/findentities-find-objects-outside-search-sphere/10893

Anyway, the center of the skybox is furthr away from the search sphere. that you not would expect to find it.

Other question is iffindentities is always going to find entities you not see because lod etc. ? Important to know for my next project. Otherwise, am screwed :open_mouth:


#4

@Richardus.Raymaker

when using AC scripts to try to findEntities using the Entity Viewer, you may need to increase the LOD for the viewer or it might miss small /far away stuff.

LODManager.getOctreeSizeScale() returns 13107200 at the default LOD for me, so that may be a good place to start.

so something like this to set up… (as an AC script)

EntityViewer.setPosition(basePosition);
EntityViewer.setKeyholeRadius(16000);
EntityViewer.setVoxelSizeScale(13107200) 
var octreeQueryInterval = Script.setInterval(function(){EntityViewer.queryOctree()}, 1000);

tbh i don’t know a lot about why the voxel size numbers are the way they are, there’s some related code in OctreeUtils.cpp, or maybe @ZappoMan can help explain when you get there!

best