소스 검색

Fix cast return values;

bjorn 1 개월 전
부모
커밋
512eedf518
3개의 변경된 파일47개의 추가작업 그리고 7개의 파일을 삭제
  1. 30 2
      api/init.lua
  2. 2 2
      api/lovr/physics/World/raycast.lua
  3. 15 3
      api/lovr/physics/World/shapecast.lua

+ 30 - 2
api/init.lua

@@ -43581,7 +43581,7 @@ return {
               description = "Traces a ray through the world and calls a function for each collider that was hit.\n\nThe callback can be left off, in which case the closest hit will be returned.",
               key = "World:raycast",
               module = "lovr.physics",
-              notes = "The callback function is passed a collider, a shape, a world-space point, a world-space normal, and a fraction:\n\n    function(collider, shape, x, y, z, nx, ny, nz, fraction)\n      return fraction\n    end\n\nThe callback can return a fraction value used to limit the range of further hits.  For example:\n\n- Returning 0.0 will abort the raycast and ignore all other hits.\n- Returning 1.0 will call the callback for all hits.\n- Returning `fraction` will return successively closer hits.\n\nRaycasts will hit sensors and sleeping colliders, but will not hit disabled colliders.",
+              notes = "The callback function is passed a collider, a shape, a world-space point, a world-space normal, a triangle index, and a fraction:\n\n    function(collider, shape, x, y, z, nx, ny, nz, tri, fraction)\n      return fraction\n    end\n\nThe callback can return a fraction value used to limit the range of further hits.  For example:\n\n- Returning 0.0 will abort the raycast and ignore all other hits.\n- Returning 1.0 will call the callback for all hits.\n- Returning `fraction` will return successively closer hits.\n\nRaycasts will hit sensors and sleeping colliders, but will not hit disabled colliders.",
               related = {
                 "Shape:raycast",
                 "World:shapecast",
@@ -44171,7 +44171,7 @@ return {
               description = "Moves a shape from a starting point to an endpoint and returns any colliders it touches along its path.\n\nThis is similar to a raycast, but with a `Shape` instead of a point.",
               key = "World:shapecast",
               module = "lovr.physics",
-              notes = "The callback function is passed a collider, a shape, a world-space point, a world-space normal, and a fraction:\n\n    function(collider, shape, x, y, z, nx, ny, nz, fraction)\n      return fraction\n    end\n\nThe callback can return a fraction value used to limit the range of further hits.  For example:\n\n- Returning 0.0 will abort the shapecast and ignore all other hits.\n- Returning 1.0 will call the callback for all hits.\n- Returning `fraction` will return successively closer hits.\n\nShapecasts will hit sensors and sleeping colliders, but will not hit disabled colliders.",
+              notes = "The callback function is passed a collider, a shape, a world-space point, a world-space normal, a triangle index (for mesh shapes), and a fraction:\n\n    function(collider, shape, x, y, z, nx, ny, nz, fraction)\n      return fraction\n    end\n\nThe callback can return a fraction value used to limit the range of further hits.  For example:\n\n- Returning 0.0 will abort the shapecast and ignore all other hits.\n- Returning 1.0 will call the callback for all hits.\n- Returning `fraction` will return successively closer hits.\n\nShapecasts will hit sensors and sleeping colliders, but will not hit disabled colliders.",
               related = {
                 "World:raycast",
                 "World:overlapShape",
@@ -44279,6 +44279,10 @@ return {
                           name = "nz",
                           type = "number"
                         },
+                        {
+                          name = "triangle",
+                          type = "number"
+                        },
                         {
                           name = "fraction",
                           type = "number"
@@ -44360,6 +44364,10 @@ return {
                           name = "nz",
                           type = "number"
                         },
+                        {
+                          name = "triangle",
+                          type = "number"
+                        },
                         {
                           name = "fraction",
                           type = "number"
@@ -44480,6 +44488,16 @@ return {
                       name = "nz",
                       type = "number",
                       description = "The z component of the normal vector."
+                    },
+                    {
+                      name = "triangle",
+                      type = "number",
+                      description = "The triangle that was hit, or `nil` if a MeshShape was not hit."
+                    },
+                    {
+                      name = "fraction",
+                      type = "number",
+                      description = "The fraction along the ray where the impact occurred."
                     }
                   }
                 },
@@ -44552,6 +44570,16 @@ return {
                       name = "nz",
                       type = "number",
                       description = "The z component of the normal vector."
+                    },
+                    {
+                      name = "triangle",
+                      type = "number",
+                      description = "The triangle that was hit, or `nil` if a MeshShape was not hit."
+                    },
+                    {
+                      name = "fraction",
+                      type = "number",
+                      description = "The fraction along the ray where the impact occurred."
                     }
                   }
                 }

+ 2 - 2
api/lovr/physics/World/raycast.lua

@@ -158,9 +158,9 @@ return {
   },
   notes = [[
     The callback function is passed a collider, a shape, a world-space point, a world-space normal,
-    and a fraction:
+    a triangle index, and a fraction:
 
-        function(collider, shape, x, y, z, nx, ny, nz, fraction)
+        function(collider, shape, x, y, z, nx, ny, nz, tri, fraction)
           return fraction
         end
 

+ 15 - 3
api/lovr/physics/World/shapecast.lua

@@ -106,6 +106,10 @@ return {
           name = 'nz',
           type = 'number'
         },
+        {
+          name = 'triangle',
+          type = 'number'
+        },
         {
           name = 'fraction',
           type = 'number'
@@ -153,6 +157,14 @@ return {
     nz = {
       type = 'number',
       description = 'The z component of the normal vector.'
+    },
+    triangle = {
+      type = 'number',
+      description = 'The triangle that was hit, or `nil` if a MeshShape was not hit.'
+    },
+    fraction = {
+      type = 'number',
+      description = 'The fraction along the ray where the impact occurred.'
     }
   },
   variants = {
@@ -166,16 +178,16 @@ return {
     },
     {
       arguments = { 'shape', 'x1', 'y1', 'z1', 'x2', 'y2', 'z2', 'angle', 'ax', 'ay', 'az', 'filter' },
-      returns = { 'collider', 'shape', 'x', 'y', 'z', 'nx', 'ny', 'nz' }
+      returns = { 'collider', 'shape', 'x', 'y', 'z', 'nx', 'ny', 'nz', 'triangle', 'fraction' }
     },
     {
       arguments = { 'shape', 'position', 'destination', 'orientation', 'filter' },
-      returns = { 'collider', 'shape', 'x', 'y', 'z', 'nx', 'ny', 'nz' }
+      returns = { 'collider', 'shape', 'x', 'y', 'z', 'nx', 'ny', 'nz', 'triangle', 'fraction' }
     }
   },
   notes = [[
     The callback function is passed a collider, a shape, a world-space point, a world-space normal,
-    and a fraction:
+    a triangle index (for mesh shapes), and a fraction:
 
         function(collider, shape, x, y, z, nx, ny, nz, fraction)
           return fraction