GeometryInstancesSpatialQueries.kl¶
Types¶
GeometryInstancesSpatialQuery (object)¶
Query object returned by GeometryInstancesSpatialQueries.beginSpatialQuery.
Methods¶
GeometryInstancesSpatialQuery ( in GeometryInstancesSpatialQuery other ) | |
GeometryInstancesSpatialQuery ( in Ref<GeometryInstancesSpatialQueries> queryCache ) | |
GeometryInstancesSpatialQuery () | |
GeometryInstancesSpatialQuery | clone ? () |
getClosest ! ( in Vec3 position, in Scalar maxUnscaledDistance, io Size geometryKey, io GeometryLocation location ) | |
raycast ! ( in Ray ray, in Boolean doubleSided, in Scalar coneThreshold, in Scalar maxDistance, io Size geometryKey, io GeometryLocation location ) |
GeometryInstancesSpatialQueries (object)¶
The GeometryInstancesSpatialQueries object enables to issue spatial queries (raycast, getClosest) to a group of many geometry instances (Geometry - transform pairs) while ensuring scalability.
Adding a new geometry instance is done in two steps. First, the GeometryInstancesSpatialQueries.createInstance function will return a new key associated to the geometry instance to be added. Then, that key needs to be passed back to the GeometryInstancesSpatialQueries.updateInstance function when updating geometry instance’s information. Changes will be detected and an incremental update will be performed when calling GeometryInstancesSpatialQueries.prepareForSpatialQueries.
The geometry instance key is used to identify a geometry instance for all the methods, like knowing which one was hit by a raycast.
Members¶
_GeometryInstanceSpatialQueriesData[] | data | |
IndexPool | dataPoolIndices | |
_GeometrySpatialQueryData[Geometry] | geometryData | |
SpatialAccelerationChooser | acceleration | |
Boolean | dirtyAcceleration | |
FewObjectsRecyclingAllocator | queryAllocator | |
StatisticsAutoRegisterMember | autoStats |
/*
** Example: GeometryInstancesSpatialQueries
*/
require Geometry;
operator entry() {
//Add a 10X10 point grid (XZ), centered at origin
Points points = Points();
points.addPlane( Xfo(), 10, 10, 11, 11 );//10X10 points grid
points.defaultPointSize = 0.5;
Xfo pointsXfo;
//Add a 10X10 lines grid (XZ), centered at X=20
Lines lines = Lines();
lines.addGrid( Xfo(), 10, 1, 10, 9, 1, 9 );//10X10 lines grid
lines.raycastThickness = 0.5;
Xfo linesXfo;
linesXfo.tr = Vec3(20, 0, 0);
//Add a 10X10 mesh plane (XZ), centered at X=40
PolygonMesh mesh = PolygonMesh();
mesh.addPlane( Xfo(), 10, 10, 9, 9);//10X10 polygon plane
Xfo meshXfo;
meshXfo.tr = Vec3(40, 0, 0);
//Create instances and set their initial values
GeometryInstancesSpatialQueries instances();
Size meshKey = instances.createInstance();
Size linesKey = instances.createInstance();
Size pointsKey = instances.createInstance();
instances.updateInstance( meshKey, mesh, meshXfo );
instances.updateInstance( pointsKey, points, pointsXfo );
instances.updateInstance( linesKey, lines, linesXfo );
//Prepare for issuing one query at each 4 units along the X axis
instances.prepareForSpatialQueries( 20, true, null );
for( Size i = 0; i < 20; ++i ) {
GeometryLocation location;
Size geometryKey;
instances.raycast( Ray( Vec3(i*4.0f, 5, 0), Vec3(0.0, -1.0, 0.0) ), true, 0, SCALAR_INFINITE, geometryKey, location );
if( location.isValid() ) {
Vec3 worldPosition = instances.getWorldPositionAtLocation(geometryKey, location);
if( geometryKey == meshKey )
report( "Mesh hit at " + worldPosition);
else if( geometryKey == linesKey )
report( "Lines hit at " + worldPosition );
else if( geometryKey == pointsKey )
report( "Points hit at " + worldPosition);
}
}
}
/*
** Output:
Points hit at {x:+0.0,y:+0.25,z:+0.0}
Points hit at {x:+4.0,y:+0.25,z:+0.0}
Lines hit at {x:+16.0,y:+0.0,z:+0.0}
Lines hit at {x:+20.0,y:+0.0,z:+0.0}
Lines hit at {x:+24.0,y:+0.0,z:+0.0}
Mesh hit at {x:+36.0,y:+0.0,z:+0.0}
Mesh hit at {x:+40.0,y:+0.0,z:-1.013278e-7}
Mesh hit at {x:+44.0,y:+0.0,z:-2.980232e-8}
*/
Methods¶
GeometryInstancesSpatialQueries ( in GeometryInstancesSpatialQueries other ) | |
GeometryInstancesSpatialQueries () | |
Ref<GeometryInstancesSpatialQuery> | beginSpatialQuery ? () |
GeometryInstancesSpatialQueries | clone ? () |
Size | createInstance ! () |
endSpatialQuery ? ( in Ref<GeometryInstancesSpatialQuery> query ) | |
getClosest ? ( in Vec3 position, in Scalar maxUnscaledDistance, io Size geometryKey, io GeometryLocation location ) | |
Ref<Geometry> | getInstanceGeometry ? ( in Size geometryKey ) |
Mat44 | getInstanceTransform ? ( in Size geometryKey ) |
Vec3 | getWorldPositionAtLocation ? ( in Size geometryKey, in GeometryLocation location ) |
prepareForSpatialQueries ? ( in Size approximateNumberOfQueries, in Boolean prepareIndividualGeometries, in GenericValueContainer options ) | |
raycast ? ( in Ray ray, in Boolean doubleSided, in Scalar coneThreshold, in Scalar maxDistance, io Size geometryKey, io GeometryLocation location ) | |
removeInstance ! ( in Size geometryKey ) | |
updateInstance ! ( in Size geometryKey, in Ref<Geometry> geometry, in Mat44 transform ) | |
updateInstance ! ( in Size geometryKey, in Ref<Geometry> geometry, in Xfo transform ) |