|
@@ -2305,9 +2305,9 @@ ConsoleMethod(Scene, getMotorJointMaxTorque, F32, 3, 3, "(jointId) Gets the max
|
|
|
ConsoleMethod(Scene, pickArea, const char*, 4, 9, "(startx/y, endx/y, [sceneGroupMask], [sceneLayerMask], [pickMode] ) Picks objects intersecting the specified area with optional group/layer masks.\n"
|
|
|
"@param startx/y The coordinates of the start point as either (\"x y\") or (x,y)\n"
|
|
|
"@param endx/y The coordinates of the end point as either (\"x y\") or (x,y)\n"
|
|
|
- "@param sceneGroupMask Optional scene group mask.\n"
|
|
|
- "@param sceneLayerMask Optional scene layer mask.\n"
|
|
|
- "@param pickMode Optional mode 'any', 'size' or 'collision' (default is 'size').\n"
|
|
|
+ "@param sceneGroupMask Optional scene group mask. (-1) or empty string selects all groups.\n"
|
|
|
+ "@param sceneLayerMask Optional scene layer mask. (-1) or empty string selects all layers.\n"
|
|
|
+ "@param pickMode Optional mode 'any', 'aabb', 'oobb' or 'collision' (default is 'oobb').\n"
|
|
|
"@return Returns list of object IDs.")
|
|
|
{
|
|
|
// Upper left and lower right bound.
|
|
@@ -2356,15 +2356,21 @@ ConsoleMethod(Scene, pickArea, const char*, 4, 9, "(startx/y, endx/y, [sceneGrou
|
|
|
// Calculate scene group mask.
|
|
|
U32 sceneGroupMask = MASK_ALL;
|
|
|
if ( (U32)argc > firstArg )
|
|
|
- sceneGroupMask = dAtoi(argv[firstArg]);
|
|
|
+ {
|
|
|
+ if ( *argv[firstArg] != 0 )
|
|
|
+ sceneGroupMask = dAtoi(argv[firstArg]);
|
|
|
+ }
|
|
|
|
|
|
// Calculate scene layer mask.
|
|
|
U32 sceneLayerMask = MASK_ALL;
|
|
|
if ( (U32)argc > (firstArg + 1) )
|
|
|
- sceneLayerMask = dAtoi(argv[firstArg + 1]);
|
|
|
+ {
|
|
|
+ if ( *argv[firstArg + 1] != 0 )
|
|
|
+ sceneLayerMask = dAtoi(argv[firstArg + 1]);
|
|
|
+ }
|
|
|
|
|
|
// Calculate pick mode.
|
|
|
- Scene::PickMode pickMode = Scene::PICK_SIZE;
|
|
|
+ Scene::PickMode pickMode = Scene::PICK_OOBB;
|
|
|
if ( (U32)argc > (firstArg + 2))
|
|
|
{
|
|
|
pickMode = Scene::getPickModeEnum(argv[firstArg + 2]);
|
|
@@ -2372,7 +2378,7 @@ ConsoleMethod(Scene, pickArea, const char*, 4, 9, "(startx/y, endx/y, [sceneGrou
|
|
|
if ( pickMode == Scene::PICK_INVALID )
|
|
|
{
|
|
|
Con::warnf("Scene::pickArea() - Invalid pick mode of %s", argv[firstArg + 2]);
|
|
|
- pickMode = Scene::PICK_SIZE;
|
|
|
+ pickMode = Scene::PICK_OOBB;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -2393,15 +2399,19 @@ ConsoleMethod(Scene, pickArea, const char*, 4, 9, "(startx/y, endx/y, [sceneGrou
|
|
|
// Perform query.
|
|
|
if ( pickMode == Scene::PICK_ANY )
|
|
|
{
|
|
|
- pWorldQuery->anyQueryArea( aabb );
|
|
|
+ pWorldQuery->anyQueryAABB( aabb );
|
|
|
}
|
|
|
- else if ( pickMode == Scene::PICK_SIZE )
|
|
|
+ else if ( pickMode == Scene::PICK_AABB )
|
|
|
{
|
|
|
- pWorldQuery->renderQueryArea( aabb );
|
|
|
+ pWorldQuery->aabbQueryAABB( aabb );
|
|
|
+ }
|
|
|
+ else if ( pickMode == Scene::PICK_OOBB )
|
|
|
+ {
|
|
|
+ pWorldQuery->oobbQueryAABB( aabb );
|
|
|
}
|
|
|
else if ( pickMode == Scene::PICK_COLLISION )
|
|
|
{
|
|
|
- pWorldQuery->fixtureQueryArea( aabb );
|
|
|
+ pWorldQuery->collisionQueryAABB( aabb );
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -2454,9 +2464,9 @@ ConsoleMethod(Scene, pickArea, const char*, 4, 9, "(startx/y, endx/y, [sceneGrou
|
|
|
ConsoleMethod(Scene, pickRay, const char*, 4, 9, "(startx/y, endx/y, [sceneGroupMask], [sceneLayerMask], [pickMode] ) Picks objects intersecting the specified ray with optional group/layer masks.\n"
|
|
|
"@param startx/y The coordinates of the start point as either (\"x y\") or (x,y)\n"
|
|
|
"@param endx/y The coordinates of the end point as either (\"x y\") or (x,y)\n"
|
|
|
- "@param sceneGroupMask Optional scene group mask.\n"
|
|
|
- "@param sceneLayerMask Optional scene layer mask.\n"
|
|
|
- "@param pickMode Optional mode 'any', 'size' or 'collision' (default is 'size').\n"
|
|
|
+ "@param sceneGroupMask Optional scene group mask. (-1) or empty string selects all groups.\n"
|
|
|
+ "@param sceneLayerMask Optional scene layer mask. (-1) or empty string selects all layers.\n"
|
|
|
+ "@param pickMode Optional mode 'any', 'aabb', 'oobb' or 'collision' (default is 'oobb').\n"
|
|
|
"@return Returns list of object IDs.")
|
|
|
{
|
|
|
// Upper left and lower right bound.
|
|
@@ -2505,15 +2515,21 @@ ConsoleMethod(Scene, pickRay, const char*, 4, 9, "(startx/y, endx/y, [sceneGroup
|
|
|
// Calculate scene group mask.
|
|
|
U32 sceneGroupMask = MASK_ALL;
|
|
|
if ( (U32)argc > firstArg )
|
|
|
- sceneGroupMask = dAtoi(argv[firstArg]);
|
|
|
+ {
|
|
|
+ if ( *argv[firstArg] != 0 )
|
|
|
+ sceneGroupMask = dAtoi(argv[firstArg]);
|
|
|
+ }
|
|
|
|
|
|
// Calculate scene layer mask.
|
|
|
U32 sceneLayerMask = MASK_ALL;
|
|
|
if ( (U32)argc > (firstArg + 1) )
|
|
|
- sceneLayerMask = dAtoi(argv[firstArg + 1]);
|
|
|
+ {
|
|
|
+ if ( *argv[firstArg + 1] != 0 )
|
|
|
+ sceneLayerMask = dAtoi(argv[firstArg + 1]);
|
|
|
+ }
|
|
|
|
|
|
// Calculate pick mode.
|
|
|
- Scene::PickMode pickMode = Scene::PICK_SIZE;
|
|
|
+ Scene::PickMode pickMode = Scene::PICK_OOBB;
|
|
|
if ( (U32)argc > (firstArg + 2))
|
|
|
{
|
|
|
pickMode = Scene::getPickModeEnum(argv[firstArg + 2]);
|
|
@@ -2521,7 +2537,7 @@ ConsoleMethod(Scene, pickRay, const char*, 4, 9, "(startx/y, endx/y, [sceneGroup
|
|
|
if ( pickMode == Scene::PICK_INVALID )
|
|
|
{
|
|
|
Con::warnf("Scene::pickRay() - Invalid pick mode of %s", argv[firstArg + 2]);
|
|
|
- pickMode = Scene::PICK_SIZE;
|
|
|
+ pickMode = Scene::PICK_OOBB;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -2537,13 +2553,17 @@ ConsoleMethod(Scene, pickRay, const char*, 4, 9, "(startx/y, endx/y, [sceneGroup
|
|
|
{
|
|
|
pWorldQuery->anyQueryRay( v1, v2 );
|
|
|
}
|
|
|
- else if ( pickMode == Scene::PICK_SIZE )
|
|
|
+ else if ( pickMode == Scene::PICK_AABB )
|
|
|
+ {
|
|
|
+ pWorldQuery->aabbQueryRay( v1, v2 );
|
|
|
+ }
|
|
|
+ else if ( pickMode == Scene::PICK_OOBB )
|
|
|
{
|
|
|
- pWorldQuery->renderQueryRay( v1, v2 );
|
|
|
+ pWorldQuery->oobbQueryRay( v1, v2 );
|
|
|
}
|
|
|
else if ( pickMode == Scene::PICK_COLLISION )
|
|
|
{
|
|
|
- pWorldQuery->fixtureQueryRay( v1, v2 );
|
|
|
+ pWorldQuery->collisionQueryRay( v1, v2 );
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -2599,67 +2619,71 @@ ConsoleMethod(Scene, pickRay, const char*, 4, 9, "(startx/y, endx/y, [sceneGroup
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
-ConsoleMethod(Scene, pickRayCollision, const char*, 4, 8, "(startx/y, endx/y, [sceneGroupMask], [sceneLayerMask] ) Picks objects with collision shapes intersecting the specified ray with optional group/layer masks.\n"
|
|
|
- "Unlike other pick methods, this returns the complete detail for each object encountered, returning the collision point, normal and fraction of the ray intersection.\n"
|
|
|
- "@param startx/y The coordinates of the start point as either (\"x y\") or (x,y)\n"
|
|
|
- "@param endx/y The coordinates of the end point as either (\"x y\") or (x,y)\n"
|
|
|
- "@param sceneGroupMask Optional scene group mask.\n"
|
|
|
- "@param sceneLayerMask Optional scene layer mask.\n"
|
|
|
- "@return Returns a list of objects in blocks of detail items where each block represents a single object and its collision detail in the format:"
|
|
|
- "<ObjectId PointX PointY NormalX NormalY RayFraction ShapeIndex> <ObjectId PointX PointY NormalX NormalY RayFraction ShapeIndex> <ObjectId PointX PointY NormalX NormalY RayFraction ShapeIndex> etc.\n")
|
|
|
+ConsoleMethod(Scene, pickPoint, const char*, 3, 7, "(x / y, [sceneGroupMask], [sceneLayerMask], [pickMode] ) Picks objects intersecting the specified point with optional group/layer masks.\n"
|
|
|
+ "@param x/y The coordinate of the point as either (\"x y\") or (x,y)\n"
|
|
|
+ "@param sceneGroupMask Optional scene group mask. (-1) or empty string selects all groups.\n"
|
|
|
+ "@param sceneLayerMask Optional scene layer mask. (-1) or empty string selects all layers.\n"
|
|
|
+ "@param pickMode Optional mode 'any', 'aabb', 'oobb' or 'collision' (default is 'ooabb').\n"
|
|
|
+ "@return Returns list of object IDs.")
|
|
|
{
|
|
|
- // Upper left and lower right bound.
|
|
|
- Vector2 v1, v2;
|
|
|
+ // The point.
|
|
|
+ Vector2 point;
|
|
|
|
|
|
// The index of the first optional parameter.
|
|
|
U32 firstArg;
|
|
|
|
|
|
- // Grab the number of elements in the first two parameters.
|
|
|
- U32 elementCount1 = Utility::mGetStringElementCount(argv[2]);
|
|
|
- U32 elementCount2 = 1;
|
|
|
- if (argc > 3)
|
|
|
- elementCount2 = Utility::mGetStringElementCount(argv[3]);
|
|
|
+ // Grab the number of elements in the first parameter.
|
|
|
+ U32 elementCount = Utility::mGetStringElementCount(argv[2]);
|
|
|
|
|
|
- // ("x1 y1 x2 y2")
|
|
|
- if ((elementCount1 == 4) && (argc < 9))
|
|
|
+ // ("x y")
|
|
|
+ if ((elementCount == 2) && (argc < 8))
|
|
|
{
|
|
|
- v1 = Utility::mGetStringElementVector(argv[2]);
|
|
|
- v2 = Utility::mGetStringElementVector(argv[2], 2);
|
|
|
+ point = Utility::mGetStringElementVector(argv[2]);
|
|
|
firstArg = 3;
|
|
|
}
|
|
|
|
|
|
- // ("x1 y1", "x2 y2")
|
|
|
- else if ((elementCount1 == 2) && (elementCount2 == 2) && (argc > 3) && (argc < 9))
|
|
|
+ // (x, y)
|
|
|
+ else if ((elementCount == 1) && (argc > 3))
|
|
|
{
|
|
|
- v1 = Utility::mGetStringElementVector(argv[2]);
|
|
|
- v2 = Utility::mGetStringElementVector(argv[3]);
|
|
|
+ point = Vector2(dAtof(argv[2]), dAtof(argv[3]));
|
|
|
firstArg = 4;
|
|
|
}
|
|
|
|
|
|
- // (x1, y1, x2, y2)
|
|
|
- else if (argc > 5)
|
|
|
- {
|
|
|
- v1 = Vector2(dAtof(argv[2]), dAtof(argv[3]));
|
|
|
- v2 = Vector2(dAtof(argv[4]), dAtof(argv[5]));
|
|
|
- firstArg = 6;
|
|
|
- }
|
|
|
-
|
|
|
// Invalid
|
|
|
else
|
|
|
{
|
|
|
- Con::warnf("Scene::pickRayCollision() - Invalid number of parameters!");
|
|
|
+ Con::warnf("Scene::pickPoint() - Invalid number of parameters!");
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
// Calculate scene group mask.
|
|
|
U32 sceneGroupMask = MASK_ALL;
|
|
|
if ( (U32)argc > firstArg )
|
|
|
- sceneGroupMask = dAtoi(argv[firstArg]);
|
|
|
+ {
|
|
|
+ if ( *argv[firstArg] != 0 )
|
|
|
+ sceneGroupMask = dAtoi(argv[firstArg]);
|
|
|
+ }
|
|
|
|
|
|
// Calculate scene layer mask.
|
|
|
U32 sceneLayerMask = MASK_ALL;
|
|
|
if ( (U32)argc > (firstArg + 1) )
|
|
|
- sceneLayerMask = dAtoi(argv[firstArg + 1]);
|
|
|
+ {
|
|
|
+ if ( *argv[firstArg + 1] != 0 )
|
|
|
+ sceneLayerMask = dAtoi(argv[firstArg + 1]);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Calculate pick mode.
|
|
|
+ Scene::PickMode pickMode = Scene::PICK_OOBB;
|
|
|
+ if ( (U32)argc > (firstArg + 2 ))
|
|
|
+ {
|
|
|
+ pickMode = Scene::getPickModeEnum(argv[firstArg + 2]);
|
|
|
+ }
|
|
|
+ if ( pickMode == Scene::PICK_INVALID )
|
|
|
+ {
|
|
|
+ Con::warnf("Scene::pickPoint() - Invalid pick mode of %s", argv[firstArg + 2]);
|
|
|
+ pickMode = Scene::PICK_OOBB;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
// Fetch world query and clear results.
|
|
|
WorldQuery* pWorldQuery = object->getWorldQuery( true );
|
|
@@ -2669,10 +2693,26 @@ ConsoleMethod(Scene, pickRayCollision, const char*, 4, 8, "(startx/y, endx/y, [s
|
|
|
pWorldQuery->setQueryFilter( queryFilter );
|
|
|
|
|
|
// Perform query.
|
|
|
- pWorldQuery->fixtureQueryRay( v1, v2 );
|
|
|
-
|
|
|
- // Sanity!
|
|
|
- AssertFatal( pWorldQuery->getIsRaycastQueryResult(), "Invalid non-ray-cast query result returned." );
|
|
|
+ if ( pickMode == Scene::PICK_ANY )
|
|
|
+ {
|
|
|
+ pWorldQuery->anyQueryPoint( point );
|
|
|
+ }
|
|
|
+ else if ( pickMode == Scene::PICK_AABB )
|
|
|
+ {
|
|
|
+ pWorldQuery->aabbQueryPoint( point );
|
|
|
+ }
|
|
|
+ else if ( pickMode == Scene::PICK_OOBB )
|
|
|
+ {
|
|
|
+ pWorldQuery->oobbQueryPoint( point );
|
|
|
+ }
|
|
|
+ else if ( pickMode == Scene::PICK_COLLISION )
|
|
|
+ {
|
|
|
+ pWorldQuery->collisionQueryPoint( point );
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ AssertFatal( false, "Unsupported pick mode." );
|
|
|
+ }
|
|
|
|
|
|
// Fetch result count.
|
|
|
const U32 resultCount = pWorldQuery->getQueryResultsCount();
|
|
@@ -2681,9 +2721,6 @@ ConsoleMethod(Scene, pickRayCollision, const char*, 4, 8, "(startx/y, endx/y, [s
|
|
|
if ( resultCount == 0 )
|
|
|
return NULL;
|
|
|
|
|
|
- // Sort ray-cast result.
|
|
|
- pWorldQuery->sortRaycastQueryResult();
|
|
|
-
|
|
|
// Fetch results.
|
|
|
typeWorldQueryResultVector& queryResults = pWorldQuery->getQueryResults();
|
|
|
|
|
@@ -2699,21 +2736,14 @@ ConsoleMethod(Scene, pickRayCollision, const char*, 4, 8, "(startx/y, endx/y, [s
|
|
|
// Add Picked Objects to List.
|
|
|
for ( U32 n = 0; n < resultCount; n++ )
|
|
|
{
|
|
|
- // Fetch query result.
|
|
|
- const WorldQueryResult& queryResult = queryResults[n];
|
|
|
-
|
|
|
- bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d %g %g %g %g %g %d ",
|
|
|
- queryResult.mpSceneObject->getId(),
|
|
|
- queryResult.mPoint.x, queryResult.mPoint.y,
|
|
|
- queryResult.mNormal.x, queryResult.mNormal.y,
|
|
|
- queryResult.mFraction,
|
|
|
- queryResult.mShapeIndex );
|
|
|
+ // Output Object ID.
|
|
|
+ bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d ", queryResults[n].mpSceneObject->getId() );
|
|
|
|
|
|
// Finish early if we run out of buffer space.
|
|
|
if ( bufferCount >= maxBufferSize )
|
|
|
{
|
|
|
// Warn.
|
|
|
- Con::warnf("Scene::pickRayCollision() - Too many items picked to return to scripts!");
|
|
|
+ Con::warnf("Scene::pickPoint() - Too many items picked to return to scripts!");
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -2727,11 +2757,12 @@ ConsoleMethod(Scene, pickRayCollision, const char*, 4, 8, "(startx/y, endx/y, [s
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
-ConsoleMethod(Scene, pickPoint, const char*, 3, 7, "(x / y, [sceneGroupMask], [sceneLayerMask], [pickMode] ) Picks objects intersecting the specified point with optional group/layer masks.\n"
|
|
|
+ConsoleMethod(Scene, pickCircle, const char*, 4, 8, "(x / y, radius, [sceneGroupMask], [sceneLayerMask], [pickMode] ) Picks objects intersecting the specified circle with optional group/layer masks.\n"
|
|
|
"@param x/y The coordinate of the point as either (\"x y\") or (x,y)\n"
|
|
|
- "@param sceneGroupMask Optional scene group mask.\n"
|
|
|
- "@param sceneLayerMask Optional scene layer mask.\n"
|
|
|
- "@param pickMode Optional mode 'any', 'size' or 'collision' (default is 'size').\n"
|
|
|
+ "@param radius The radius of the circle.\n"
|
|
|
+ "@param sceneGroupMask Optional scene group mask. (-1) or empty string selects all groups.\n"
|
|
|
+ "@param sceneLayerMask Optional scene layer mask. (-1) or empty string selects all layers.\n"
|
|
|
+ "@param pickMode Optional mode 'any', 'aabb', 'oobb' or 'collision' (default is 'ooabb').\n"
|
|
|
"@return Returns list of object IDs.")
|
|
|
{
|
|
|
// The point.
|
|
@@ -2764,18 +2795,34 @@ ConsoleMethod(Scene, pickPoint, const char*, 3, 7, "(x / y, [sceneGroupMask], [s
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
+ // Fetch radius.
|
|
|
+ const F32 radius = dAtof(argv[firstArg++]);
|
|
|
+
|
|
|
+ // Check radius.
|
|
|
+ if ( radius <= 0.0f )
|
|
|
+ {
|
|
|
+ Con::warnf( "Scene::pickCircle() Radius must be greater than zero." );
|
|
|
+ return StringTable->EmptyString;
|
|
|
+ }
|
|
|
+
|
|
|
// Calculate scene group mask.
|
|
|
U32 sceneGroupMask = MASK_ALL;
|
|
|
if ( (U32)argc > firstArg )
|
|
|
- sceneGroupMask = dAtoi(argv[firstArg]);
|
|
|
+ {
|
|
|
+ if ( *argv[firstArg] != 0 )
|
|
|
+ sceneGroupMask = dAtoi(argv[firstArg]);
|
|
|
+ }
|
|
|
|
|
|
// Calculate scene layer mask.
|
|
|
U32 sceneLayerMask = MASK_ALL;
|
|
|
if ( (U32)argc > (firstArg + 1) )
|
|
|
- sceneLayerMask = dAtoi(argv[firstArg + 1]);
|
|
|
+ {
|
|
|
+ if ( *argv[firstArg + 1] != 0 )
|
|
|
+ sceneLayerMask = dAtoi(argv[firstArg + 1]);
|
|
|
+ }
|
|
|
|
|
|
// Calculate pick mode.
|
|
|
- Scene::PickMode pickMode = Scene::PICK_SIZE;
|
|
|
+ Scene::PickMode pickMode = Scene::PICK_OOBB;
|
|
|
if ( (U32)argc > (firstArg + 2 ))
|
|
|
{
|
|
|
pickMode = Scene::getPickModeEnum(argv[firstArg + 2]);
|
|
@@ -2783,7 +2830,7 @@ ConsoleMethod(Scene, pickPoint, const char*, 3, 7, "(x / y, [sceneGroupMask], [s
|
|
|
if ( pickMode == Scene::PICK_INVALID )
|
|
|
{
|
|
|
Con::warnf("Scene::pickPoint() - Invalid pick mode of %s", argv[firstArg + 2]);
|
|
|
- pickMode = Scene::PICK_SIZE;
|
|
|
+ pickMode = Scene::PICK_OOBB;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -2797,15 +2844,19 @@ ConsoleMethod(Scene, pickPoint, const char*, 3, 7, "(x / y, [sceneGroupMask], [s
|
|
|
// Perform query.
|
|
|
if ( pickMode == Scene::PICK_ANY )
|
|
|
{
|
|
|
- pWorldQuery->anyQueryPoint( point );
|
|
|
+ pWorldQuery->anyQueryCircle( point, radius );
|
|
|
}
|
|
|
- else if ( pickMode == Scene::PICK_SIZE )
|
|
|
+ else if ( pickMode == Scene::PICK_AABB )
|
|
|
{
|
|
|
- pWorldQuery->renderQueryPoint( point );
|
|
|
+ pWorldQuery->aabbQueryCircle( point, radius );
|
|
|
+ }
|
|
|
+ else if ( pickMode == Scene::PICK_OOBB )
|
|
|
+ {
|
|
|
+ pWorldQuery->oobbQueryCircle( point, radius );
|
|
|
}
|
|
|
else if ( pickMode == Scene::PICK_COLLISION )
|
|
|
{
|
|
|
- pWorldQuery->fixtureQueryPoint( point );
|
|
|
+ pWorldQuery->collisionQueryCircle( point, radius );
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -2853,6 +2904,141 @@ ConsoleMethod(Scene, pickPoint, const char*, 3, 7, "(x / y, [sceneGroupMask], [s
|
|
|
return pBuffer;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+
|
|
|
+ConsoleMethod(Scene, pickRayCollision, const char*, 4, 8, "(startx/y, endx/y, [sceneGroupMask], [sceneLayerMask] ) Picks objects with collision shapes intersecting the specified ray with optional group/layer masks.\n"
|
|
|
+ "Unlike other pick methods, this returns the complete detail for each object encountered, returning the collision point, normal and fraction of the ray intersection.\n"
|
|
|
+ "@param startx/y The coordinates of the start point as either (\"x y\") or (x,y)\n"
|
|
|
+ "@param endx/y The coordinates of the end point as either (\"x y\") or (x,y)\n"
|
|
|
+ "@param sceneGroupMask Optional scene group mask. (-1) or empty string selects all groups.\n"
|
|
|
+ "@param sceneLayerMask Optional scene layer mask. (-1) or empty string selects all layers.\n"
|
|
|
+ "@return Returns a list of objects in blocks of detail items where each block represents a single object and its collision detail in the format:"
|
|
|
+ "<ObjectId PointX PointY NormalX NormalY RayFraction ShapeIndex> <ObjectId PointX PointY NormalX NormalY RayFraction ShapeIndex> <ObjectId PointX PointY NormalX NormalY RayFraction ShapeIndex> etc.\n")
|
|
|
+{
|
|
|
+ // Upper left and lower right bound.
|
|
|
+ Vector2 v1, v2;
|
|
|
+
|
|
|
+ // The index of the first optional parameter.
|
|
|
+ U32 firstArg;
|
|
|
+
|
|
|
+ // Grab the number of elements in the first two parameters.
|
|
|
+ U32 elementCount1 = Utility::mGetStringElementCount(argv[2]);
|
|
|
+ U32 elementCount2 = 1;
|
|
|
+ if (argc > 3)
|
|
|
+ elementCount2 = Utility::mGetStringElementCount(argv[3]);
|
|
|
+
|
|
|
+ // ("x1 y1 x2 y2")
|
|
|
+ if ((elementCount1 == 4) && (argc < 9))
|
|
|
+ {
|
|
|
+ v1 = Utility::mGetStringElementVector(argv[2]);
|
|
|
+ v2 = Utility::mGetStringElementVector(argv[2], 2);
|
|
|
+ firstArg = 3;
|
|
|
+ }
|
|
|
+
|
|
|
+ // ("x1 y1", "x2 y2")
|
|
|
+ else if ((elementCount1 == 2) && (elementCount2 == 2) && (argc > 3) && (argc < 9))
|
|
|
+ {
|
|
|
+ v1 = Utility::mGetStringElementVector(argv[2]);
|
|
|
+ v2 = Utility::mGetStringElementVector(argv[3]);
|
|
|
+ firstArg = 4;
|
|
|
+ }
|
|
|
+
|
|
|
+ // (x1, y1, x2, y2)
|
|
|
+ else if (argc > 5)
|
|
|
+ {
|
|
|
+ v1 = Vector2(dAtof(argv[2]), dAtof(argv[3]));
|
|
|
+ v2 = Vector2(dAtof(argv[4]), dAtof(argv[5]));
|
|
|
+ firstArg = 6;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Invalid
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Con::warnf("Scene::pickRayCollision() - Invalid number of parameters!");
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Calculate scene group mask.
|
|
|
+ U32 sceneGroupMask = MASK_ALL;
|
|
|
+ if ( (U32)argc > firstArg )
|
|
|
+ {
|
|
|
+ if ( *argv[firstArg] != 0 )
|
|
|
+ sceneGroupMask = dAtoi(argv[firstArg]);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Calculate scene layer mask.
|
|
|
+ U32 sceneLayerMask = MASK_ALL;
|
|
|
+ if ( (U32)argc > (firstArg + 1) )
|
|
|
+ {
|
|
|
+ if ( *argv[firstArg + 1] != 0 )
|
|
|
+ sceneLayerMask = dAtoi(argv[firstArg + 1]);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Fetch world query and clear results.
|
|
|
+ WorldQuery* pWorldQuery = object->getWorldQuery( true );
|
|
|
+
|
|
|
+ // Set filter.
|
|
|
+ WorldQueryFilter queryFilter( sceneLayerMask, sceneGroupMask, true, false, true, true );
|
|
|
+ pWorldQuery->setQueryFilter( queryFilter );
|
|
|
+
|
|
|
+ // Perform query.
|
|
|
+ pWorldQuery->collisionQueryRay( v1, v2 );
|
|
|
+
|
|
|
+ // Sanity!
|
|
|
+ AssertFatal( pWorldQuery->getIsRaycastQueryResult(), "Invalid non-ray-cast query result returned." );
|
|
|
+
|
|
|
+ // Fetch result count.
|
|
|
+ const U32 resultCount = pWorldQuery->getQueryResultsCount();
|
|
|
+
|
|
|
+ // Finish if no results.
|
|
|
+ if ( resultCount == 0 )
|
|
|
+ return NULL;
|
|
|
+
|
|
|
+ // Sort ray-cast result.
|
|
|
+ pWorldQuery->sortRaycastQueryResult();
|
|
|
+
|
|
|
+ // Fetch results.
|
|
|
+ typeWorldQueryResultVector& queryResults = pWorldQuery->getQueryResults();
|
|
|
+
|
|
|
+ // Set Max Buffer Size.
|
|
|
+ const U32 maxBufferSize = 4096;
|
|
|
+
|
|
|
+ // Create Returnable Buffer.
|
|
|
+ char* pBuffer = Con::getReturnBuffer(maxBufferSize);
|
|
|
+
|
|
|
+ // Set Buffer Counter.
|
|
|
+ U32 bufferCount = 0;
|
|
|
+
|
|
|
+ // Add Picked Objects to List.
|
|
|
+ for ( U32 n = 0; n < resultCount; n++ )
|
|
|
+ {
|
|
|
+ // Fetch query result.
|
|
|
+ const WorldQueryResult& queryResult = queryResults[n];
|
|
|
+
|
|
|
+ bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d %g %g %g %g %g %d ",
|
|
|
+ queryResult.mpSceneObject->getId(),
|
|
|
+ queryResult.mPoint.x, queryResult.mPoint.y,
|
|
|
+ queryResult.mNormal.x, queryResult.mNormal.y,
|
|
|
+ queryResult.mFraction,
|
|
|
+ queryResult.mShapeIndex );
|
|
|
+
|
|
|
+ // Finish early if we run out of buffer space.
|
|
|
+ if ( bufferCount >= maxBufferSize )
|
|
|
+ {
|
|
|
+ // Warn.
|
|
|
+ Con::warnf("Scene::pickRayCollision() - Too many items picked to return to scripts!");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Clear world query.
|
|
|
+ pWorldQuery->clearQuery();
|
|
|
+
|
|
|
+ // Return buffer.
|
|
|
+ return pBuffer;
|
|
|
+}
|
|
|
+
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
ConsoleMethod(Scene, setDebugOn, void, 3, 2 + DEBUG_MODE_COUNT, "(debugOptions) Sets Debug option(s) on.\n"
|