Explorar o código

Model:getTriangles; World:newMeshCollider(Model);

These were missing from v0.15.0.
bjorn %!s(int64=3) %!d(string=hai) anos
pai
achega
ee05ea3006
Modificáronse 3 ficheiros con 527 adicións e 32 borrados
  1. 474 25
      api/init.lua
  2. 31 0
      api/lovr/graphics/Model/getTriangles.lua
  3. 22 7
      api/lovr/physics/World/newMeshCollider.lua

+ 474 - 25
api/init.lua

@@ -6787,6 +6787,35 @@ return {
                 "Model:getNodeCount"
               }
             },
+            {
+              name = "getTriangles",
+              summary = "Get a list of the triangles in the Model.",
+              description = "Returns 2 tables containing mesh data for the Model.\n\nThe first table is a list of vertex positions and contains 3 numbers for the x, y, and z coordinate of each vertex.  The second table is a list of triangles and contains 1-based indices into the first table representing the first, second, and third vertices that make up each triangle.\n\nThe vertex positions will be affected by node transforms.",
+              key = "Model:getTriangles",
+              module = "lovr.graphics",
+              related = {
+                "Model:getAABB",
+                "World:newMeshCollider",
+                "lovr.audio.setGeometry"
+              },
+              variants = {
+                {
+                  arguments = {},
+                  returns = {
+                    {
+                      name = "vertices",
+                      type = "table",
+                      description = "A flat table of numbers containing vertex positions."
+                    },
+                    {
+                      name = "indices",
+                      type = "table",
+                      description = "A flat table of numbers containing triangle vertex indices."
+                    }
+                  }
+                }
+              }
+            },
             {
               name = "hasJoints",
               summary = "Check if a Model has joints.",
@@ -16970,7 +16999,13 @@ return {
                     {
                       name = "x",
                       type = "number",
-                      description = "A number to add to each component."
+                      description = "A value to add to x component."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value to add to y component.",
+                      default = "x"
                     }
                   },
                   returns = {
@@ -17008,6 +17043,27 @@ return {
                       description = "The distance to `u`."
                     }
                   }
+                },
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "A value of x component to measure distance to."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value of y component to measure distance to."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "distance",
+                      type = "number",
+                      description = "The distance to `u`."
+                    }
+                  }
                 }
               }
             },
@@ -17044,7 +17100,13 @@ return {
                     {
                       name = "x",
                       type = "number",
-                      description = "The number to divide each component by."
+                      description = "A value to divide x component by."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value to divide y component by.",
+                      default = "x"
                     }
                   },
                   returns = {
@@ -17063,7 +17125,7 @@ return {
               description = "Returns the dot product between this vector and another one.",
               key = "Vec2:dot",
               module = "lovr.math",
-              notes = "This is computed as:\n\n    dot = v.x * u.x + v.y * u.y + v.z * u.z\n\nThe vectors are not normalized before computing the dot product.",
+              notes = "This is computed as:\n\n    dot = v.x * u.x + v.y * u.y\n\nThe vectors are not normalized before computing the dot product.",
               variants = {
                 {
                   arguments = {
@@ -17080,6 +17142,27 @@ return {
                       description = "The dot product between `v` and `u`."
                     }
                   }
+                },
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "A value of x component to compute the dot product with."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value of y component to compute the dot product with."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "dot",
+                      type = "number",
+                      description = "The dot product between `v` and `u`."
+                    }
+                  }
                 }
               }
             },
@@ -17118,16 +17201,26 @@ return {
               },
               variants = {
                 {
-                  arguments = {
+                  arguments = {},
+                  returns = {
                     {
-                      name = "u",
+                      name = "v",
                       type = "Vec2",
-                      description = "The vector to lerp towards."
+                      description = "The original vector, containing the new lerped values."
+                    }
+                  }
+                },
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "A value of x component to lerp towards."
                     },
                     {
-                      name = "t",
+                      name = "y",
                       type = "number",
-                      description = "The lerping parameter."
+                      description = "A value of y component to lerp towards."
                     }
                   },
                   returns = {
@@ -17173,7 +17266,13 @@ return {
                     {
                       name = "x",
                       type = "number",
-                      description = "The number to multiply each component by."
+                      description = "A value to multiply x component by."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value to multiply y component by.",
+                      default = "x"
                     }
                   },
                   returns = {
@@ -17292,7 +17391,13 @@ return {
                     {
                       name = "x",
                       type = "number",
-                      description = "A number to subtract from each component."
+                      description = "A value to subtract from x component."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value to subtract from y component.",
+                      default = "x"
                     }
                   },
                   returns = {
@@ -17382,7 +17487,19 @@ return {
                     {
                       name = "x",
                       type = "number",
-                      description = "A number to add to each component."
+                      description = "A value to add to x component."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value to add to y component.",
+                      default = "x"
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "A value to add to z component.",
+                      default = "x"
                     }
                   },
                   returns = {
@@ -17418,6 +17535,32 @@ return {
                       description = "The original vector, with the cross product as its values."
                     }
                   }
+                },
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "A value of x component to compute cross product with."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value of y component to compute cross product with."
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "A value of z component to compute cross product with."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "v",
+                      type = "Vec3",
+                      description = "The original vector, with the cross product as its values."
+                    }
+                  }
                 }
               },
               related = {
@@ -17449,6 +17592,32 @@ return {
                       description = "The distance to `u`."
                     }
                   }
+                },
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "A value of x component to measure distance to."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value of y component to measure distance to."
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "A value of z component to measure distance to."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "distance",
+                      type = "number",
+                      description = "The distance to `u`."
+                    }
+                  }
                 }
               }
             },
@@ -17485,7 +17654,19 @@ return {
                     {
                       name = "x",
                       type = "number",
-                      description = "The number to divide each component by."
+                      description = "A value to divide x component by."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value to divide y component by.",
+                      default = "x"
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "A value to divide z component by.",
+                      default = "x"
                     }
                   },
                   returns = {
@@ -17521,6 +17702,32 @@ return {
                       description = "The dot product between `v` and `u`."
                     }
                   }
+                },
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "A value of x component to compute the dot product with."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value of y component to compute the dot product with."
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "A value of z component to compute the dot product with."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "dot",
+                      type = "number",
+                      description = "The dot product between `v` and `u`."
+                    }
+                  }
                 }
               },
               related = {
@@ -17581,6 +17788,37 @@ return {
                       description = "The original vector, containing the new lerped values."
                     }
                   }
+                },
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "A value of x component to lerp towards."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value of y component to lerp towards."
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "A value of z component to lerp towards."
+                    },
+                    {
+                      name = "t",
+                      type = "number",
+                      description = "The lerping parameter."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "v",
+                      type = "Vec3",
+                      description = "The original vector, containing the new lerped values."
+                    }
+                  }
                 }
               }
             },
@@ -17617,7 +17855,19 @@ return {
                     {
                       name = "x",
                       type = "number",
-                      description = "The number to multiply each component by."
+                      description = "A value to multiply x component by."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value to multiply y component by.",
+                      default = "x"
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "A value to multiply z component by.",
+                      default = "x"
                     }
                   },
                   returns = {
@@ -17758,7 +18008,19 @@ return {
                     {
                       name = "x",
                       type = "number",
-                      description = "A number to subtract from each component."
+                      description = "A value to subtract from x component."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value to subtract from y component.",
+                      default = "x"
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "A value to subtract from z component.",
+                      default = "x"
                     }
                   },
                   returns = {
@@ -17853,7 +18115,25 @@ return {
                     {
                       name = "x",
                       type = "number",
-                      description = "A number to add to each component."
+                      description = "A value to add to x component."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value to add to y component.",
+                      default = "x"
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "A value to add to z component.",
+                      default = "x"
+                    },
+                    {
+                      name = "w",
+                      type = "number",
+                      description = "A value to add to w component.",
+                      default = "x"
                     }
                   },
                   returns = {
@@ -17891,6 +18171,37 @@ return {
                       description = "The distance to `u`."
                     }
                   }
+                },
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "A value of x component to measure distance to."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value of y component to measure distance to."
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "A value of z component to measure distance to."
+                    },
+                    {
+                      name = "w",
+                      type = "number",
+                      description = "A value of w component to measure distance to."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "distance",
+                      type = "number",
+                      description = "The distance to `u`."
+                    }
+                  }
                 }
               }
             },
@@ -17927,7 +18238,25 @@ return {
                     {
                       name = "x",
                       type = "number",
-                      description = "The number to divide each component by."
+                      description = "A value to divide x component by."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value to divide y component by.",
+                      default = "x"
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "A value to divide z component by.",
+                      default = "x"
+                    },
+                    {
+                      name = "w",
+                      type = "number",
+                      description = "A value to divide w component by.",
+                      default = "x"
                     }
                   },
                   returns = {
@@ -17963,6 +18292,37 @@ return {
                       description = "The dot product between `v` and `u`."
                     }
                   }
+                },
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "A value of x component to compute the dot product with."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value of y component to compute the dot product with."
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "A value of z component to compute the dot product with."
+                    },
+                    {
+                      name = "w",
+                      type = "number",
+                      description = "A value of w component to compute the dot product with."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "dot",
+                      type = "number",
+                      description = "The dot product between `v` and `u`."
+                    }
+                  }
                 }
               }
             },
@@ -18020,6 +18380,42 @@ return {
                       description = "The original vector, containing the new lerped values."
                     }
                   }
+                },
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "A value of x component to lerp towards."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value of y component to lerp towards."
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "A value of z component to lerp towards."
+                    },
+                    {
+                      name = "w",
+                      type = "number",
+                      description = "A value of w component to lerp towards."
+                    },
+                    {
+                      name = "t",
+                      type = "number",
+                      description = "The lerping parameter."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "v",
+                      type = "Vec4",
+                      description = "The original vector, containing the new lerped values."
+                    }
+                  }
                 }
               }
             },
@@ -18056,7 +18452,25 @@ return {
                     {
                       name = "x",
                       type = "number",
-                      description = "The number to multiply each component by."
+                      description = "A value to multiply x component by."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value to multiply y component by.",
+                      default = "x"
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "A value to multiply z component by.",
+                      default = "x"
+                    },
+                    {
+                      name = "w",
+                      type = "number",
+                      description = "A value to multiply w component by.",
+                      default = "x"
                     }
                   },
                   returns = {
@@ -18161,23 +18575,23 @@ return {
               key = "Vec4:sub",
               module = "lovr.math",
               related = {
-                "Vec2:add",
-                "Vec2:mul",
-                "Vec2:div"
+                "Vec4:add",
+                "Vec4:mul",
+                "Vec4:div"
               },
               variants = {
                 {
                   arguments = {
                     {
                       name = "u",
-                      type = "Vec2",
+                      type = "Vec4",
                       description = "The other vector."
                     }
                   },
                   returns = {
                     {
                       name = "v",
-                      type = "Vec2",
+                      type = "Vec4",
                       description = "The original vector."
                     }
                   }
@@ -18187,13 +18601,31 @@ return {
                     {
                       name = "x",
                       type = "number",
-                      description = "A number to subtract from each component."
+                      description = "A value to subtract from x component."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value to subtract from y component.",
+                      default = "x"
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "A value to subtract from z component.",
+                      default = "x"
+                    },
+                    {
+                      name = "w",
+                      type = "number",
+                      description = "A value to subtract from w component.",
+                      default = "x"
                     }
                   },
                   returns = {
                     {
                       name = "v",
-                      type = "Vec2",
+                      type = "Vec4",
                       description = "The original vector."
                     }
                   }
@@ -23312,7 +23744,8 @@ return {
                 "World:newBoxCollider",
                 "World:newCapsuleCollider",
                 "World:newCylinderCollider",
-                "World:newSphereCollider"
+                "World:newSphereCollider",
+                "Model:getTriangles"
               },
               variants = {
                 {
@@ -23335,6 +23768,22 @@ return {
                       description = "The new Collider."
                     }
                   }
+                },
+                {
+                  arguments = {
+                    {
+                      name = "model",
+                      type = "Model",
+                      description = "A Model to use for the mesh data.  Similar to calling `Model:getTriangles` and passing it to this function, but has better performance."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "collider",
+                      type = "Collider",
+                      description = "The new Collider."
+                    }
+                  }
                 }
               }
             },

+ 31 - 0
api/lovr/graphics/Model/getTriangles.lua

@@ -0,0 +1,31 @@
+return {
+  summary = 'Get a list of the triangles in the Model.',
+  description = [[
+    Returns 2 tables containing mesh data for the Model.
+
+    The first table is a list of vertex positions and contains 3 numbers for the x, y, and z
+    coordinate of each vertex.  The second table is a list of triangles and contains 1-based indices
+    into the first table representing the first, second, and third vertices that make up each
+    triangle.
+
+    The vertex positions will be affected by node transforms.
+  ]],
+  arguments = {},
+  returns = {
+    {
+      name = 'vertices',
+      type = 'table',
+      description = 'A flat table of numbers containing vertex positions.'
+    },
+    {
+      name = 'indices',
+      type = 'table',
+      description = 'A flat table of numbers containing triangle vertex indices.'
+    }
+  },
+  related = {
+    'Model:getAABB',
+    'World:newMeshCollider',
+    'lovr.audio.setGeometry'
+  }
+}

+ 22 - 7
api/lovr/physics/World/newMeshCollider.lua

@@ -3,32 +3,47 @@ return {
   summary = 'Add a Collider with a MeshShape to the World.',
   description = 'Adds a new Collider to the World with a MeshShape already attached.',
   arguments = {
-    {
-      name = 'vertices',
+    vertices = {
       type = 'table',
       description = 'The table of vertices in the mesh.  Each vertex is a table with 3 numbers.'
     },
-    {
-      name = 'indices',
+    indices = {
       type = 'table',
       description = [[
         A table of triangle indices representing how the vertices are connected in the Mesh.
       ]]
+    },
+    model = {
+      type = 'Model',
+      description = [[
+        A Model to use for the mesh data.  Similar to calling `Model:getTriangles` and passing it to
+        this function, but has better performance.
+      ]]
     }
   },
   returns = {
-    {
-      name = 'collider',
+    collider = {
       type = 'Collider',
       description = 'The new Collider.'
     }
   },
+  variants = {
+    {
+      arguments = { 'vertices', 'indices' },
+      returns = { 'collider' }
+    },
+    {
+      arguments = { 'model' },
+      returns = { 'collider' }
+    }
+  },
   related = {
     'Collider',
     'World:newCollider',
     'World:newBoxCollider',
     'World:newCapsuleCollider',
     'World:newCylinderCollider',
-    'World:newSphereCollider'
+    'World:newSphereCollider',
+    'Model:getTriangles'
   }
 }