2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2014-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
|
|
2022-07-10 09:47:41 +08:00
|
|
|
https://axis-project.github.io/
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
#include "platform/CCPlatformConfig.h"
|
|
|
|
#include "base/ccConfig.h"
|
2022-07-16 10:43:05 +08:00
|
|
|
#if AX_USE_3D_PHYSICS && AX_ENABLE_BULLET_INTEGRATION
|
2022-07-12 21:31:54 +08:00
|
|
|
# include "scripting/lua-bindings/manual/physics3d/lua_axis_physics3d_manual.h"
|
|
|
|
# include "scripting/lua-bindings/auto/lua_axis_physics3d_auto.hpp"
|
2021-12-25 10:04:45 +08:00
|
|
|
# include "scripting/lua-bindings/manual/tolua_fix.h"
|
|
|
|
# include "scripting/lua-bindings/manual/LuaBasicConversions.h"
|
|
|
|
# include "scripting/lua-bindings/manual/CCLuaEngine.h"
|
|
|
|
# include "physics3d/CCPhysics3D.h"
|
|
|
|
|
|
|
|
bool luaval_to_Physics3DRigidBodyDes(lua_State* L,
|
|
|
|
int lo,
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Physics3DRigidBodyDes* outValue,
|
2021-12-25 10:04:45 +08:00
|
|
|
const char* funcName)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
if (nullptr == L || nullptr == outValue)
|
|
|
|
return false;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
bool ok = true;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
tolua_Error tolua_err;
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!tolua_istable(L, lo, 0, &tolua_err))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-07-19 15:34:26 +08:00
|
|
|
# if AXIS_DEBUG >= 1
|
2021-12-25 10:04:45 +08:00
|
|
|
luaval_to_native_err(L, "#ferror:", &tolua_err, funcName);
|
|
|
|
# endif
|
2019-11-23 20:27:39 +08:00
|
|
|
ok = false;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
if (ok)
|
|
|
|
{
|
|
|
|
lua_pushstring(L, "mass");
|
|
|
|
lua_gettable(L, lo);
|
|
|
|
outValue->mass = lua_isnil(L, -1) ? 0.0f : (float)lua_tonumber(L, -1);
|
|
|
|
lua_pop(L, 1);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_pushstring(L, "localInertia");
|
|
|
|
lua_gettable(L, lo);
|
|
|
|
if (!lua_istable(L, -1))
|
|
|
|
{
|
2022-07-11 17:50:21 +08:00
|
|
|
outValue->localInertia = axis::Vec3(0.0, 0.0, 0.0);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
luaval_to_vec3(L, lua_gettop(L), &outValue->localInertia);
|
|
|
|
}
|
|
|
|
lua_pop(L, 1);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_pushstring(L, "shape");
|
|
|
|
lua_gettable(L, lo);
|
2022-07-12 21:31:54 +08:00
|
|
|
if (!tolua_isusertype(L, -1, "ax.Physics3DShape", 0, &tolua_err))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
outValue->shape = nullptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-07-11 17:50:21 +08:00
|
|
|
outValue->shape = static_cast<axis::Physics3DShape*>(tolua_tousertype(L, lua_gettop(L), nullptr));
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
lua_pop(L, 1);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_pushstring(L, "originalTransform");
|
|
|
|
lua_gettable(L, lo);
|
|
|
|
if (!lua_istable(L, -1))
|
|
|
|
{
|
2022-07-11 17:50:21 +08:00
|
|
|
outValue->originalTransform = axis::Mat4();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
luaval_to_mat4(L, lua_gettop(L), &outValue->originalTransform);
|
|
|
|
}
|
|
|
|
lua_pop(L, 1);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_pushstring(L, "disableSleep");
|
|
|
|
lua_gettable(L, lo);
|
|
|
|
outValue->disableSleep = lua_isnil(L, -1) ? false : lua_toboolean(L, -1);
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
bool luaval_to_Physics3DWorld_HitResult(lua_State* L,
|
|
|
|
int lo,
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Physics3DWorld::HitResult* outValue,
|
2021-12-25 10:04:45 +08:00
|
|
|
const char* funcName)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
if (nullptr == L || nullptr == outValue)
|
|
|
|
return false;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
bool ok = true;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
tolua_Error tolua_err;
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!tolua_istable(L, lo, 0, &tolua_err))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-07-19 15:34:26 +08:00
|
|
|
# if AXIS_DEBUG >= 1
|
2021-12-25 10:04:45 +08:00
|
|
|
luaval_to_native_err(L, "#ferror:", &tolua_err, funcName);
|
|
|
|
# endif
|
2019-11-23 20:27:39 +08:00
|
|
|
ok = false;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
if (ok)
|
|
|
|
{
|
|
|
|
lua_pushstring(L, "hitPosition");
|
|
|
|
lua_gettable(L, lo);
|
|
|
|
if (!lua_istable(L, -1))
|
|
|
|
{
|
2022-07-11 17:50:21 +08:00
|
|
|
outValue->hitPosition = axis::Vec3();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
luaval_to_vec3(L, lua_gettop(L), &(outValue->hitPosition));
|
|
|
|
}
|
|
|
|
lua_pop(L, 1);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_pushstring(L, "hitNormal");
|
|
|
|
lua_gettable(L, lo);
|
|
|
|
if (!lua_istable(L, -1))
|
|
|
|
{
|
2022-07-11 17:50:21 +08:00
|
|
|
outValue->hitNormal = axis::Vec3();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
luaval_to_vec3(L, lua_gettop(L), &(outValue->hitNormal));
|
|
|
|
}
|
|
|
|
lua_pop(L, 1);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_pushstring(L, "hitObj");
|
|
|
|
lua_gettable(L, lo);
|
2022-07-12 21:31:54 +08:00
|
|
|
if (!tolua_isusertype(L, -1, "ax.Physics3DObject", 0, &tolua_err))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
outValue->hitObj = nullptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-07-11 17:50:21 +08:00
|
|
|
outValue->hitObj = static_cast<axis::Physics3DObject*>(tolua_tousertype(L, lua_gettop(L), nullptr));
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
void Physics3DWorld_HitResult_to_luaval(lua_State* L, const axis::Physics3DWorld::HitResult& hitResult)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (nullptr == L)
|
2019-11-23 20:27:39 +08:00
|
|
|
return;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_newtable(L);
|
|
|
|
lua_pushstring(L, "hitPosition");
|
|
|
|
vec3_to_luaval(L, hitResult.hitPosition);
|
|
|
|
lua_rawset(L, -3);
|
|
|
|
lua_pushstring(L, "hitNormal");
|
|
|
|
vec3_to_luaval(L, hitResult.hitNormal);
|
|
|
|
lua_rawset(L, -3);
|
|
|
|
lua_pushstring(L, "hitObj");
|
|
|
|
if (nullptr == hitResult.hitObj)
|
|
|
|
{
|
|
|
|
lua_pushnil(L);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
object_to_luaval<axis::Physics3DObject>(L, "ax.Physics3DObject", hitResult.hitObj);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
lua_rawset(L, -3);
|
|
|
|
}
|
|
|
|
|
2022-07-12 21:31:54 +08:00
|
|
|
int lua_axis_physics3d_PhysicsMeshRenderer_create(lua_State* L)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
int argc = 0;
|
|
|
|
bool ok = true;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-19 15:34:26 +08:00
|
|
|
# if AXIS_DEBUG >= 1
|
2019-11-23 20:27:39 +08:00
|
|
|
tolua_Error tolua_err;
|
2021-12-25 10:04:45 +08:00
|
|
|
# endif
|
|
|
|
|
2022-07-19 15:34:26 +08:00
|
|
|
# if AXIS_DEBUG >= 1
|
2022-07-12 21:31:54 +08:00
|
|
|
if (!tolua_isusertable(L, 1, "ax.PhysicsMeshRenderer", 0, &tolua_err))
|
2021-12-25 10:04:45 +08:00
|
|
|
goto tolua_lerror;
|
|
|
|
# endif
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
argc = lua_gettop(L) - 1;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
if (argc == 2)
|
|
|
|
{
|
|
|
|
std::string arg0;
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Physics3DRigidBodyDes arg1;
|
2022-07-12 21:31:54 +08:00
|
|
|
ok &= luaval_to_std_string(L, 2, &arg0, "ax.PhysicsMeshRenderer:create");
|
|
|
|
ok &= luaval_to_Physics3DRigidBodyDes(L, 3, &arg1, "ax.PhysicsMeshRenderer:create");
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!ok)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_error(L, "invalid arguments in function 'lua_axis_physics3d_PhysicsMeshRenderer_create'", nullptr);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::PhysicsMeshRenderer* ret = axis::PhysicsMeshRenderer::create(arg0, &arg1);
|
2022-07-12 21:31:54 +08:00
|
|
|
object_to_luaval<axis::PhysicsMeshRenderer>(L, "ax.PhysicsMeshRenderer", (axis::PhysicsMeshRenderer*)ret);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (argc == 3)
|
|
|
|
{
|
|
|
|
std::string arg0;
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Physics3DRigidBodyDes arg1;
|
|
|
|
axis::Vec3 arg2;
|
2022-07-12 21:31:54 +08:00
|
|
|
ok &= luaval_to_std_string(L, 2, &arg0, "ax.PhysicsMeshRenderer:create");
|
|
|
|
ok &= luaval_to_Physics3DRigidBodyDes(L, 3, &arg1, "ax.PhysicsMeshRenderer:create");
|
|
|
|
ok &= luaval_to_vec3(L, 4, &arg2, "ax.PhysicsMeshRenderer:create");
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!ok)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_error(L, "invalid arguments in function 'lua_axis_physics3d_PhysicsMeshRenderer_create'", nullptr);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::PhysicsMeshRenderer* ret = axis::PhysicsMeshRenderer::create(arg0, &arg1, arg2);
|
2022-07-12 21:31:54 +08:00
|
|
|
object_to_luaval<axis::PhysicsMeshRenderer>(L, "ax.PhysicsMeshRenderer", (axis::PhysicsMeshRenderer*)ret);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (argc == 4)
|
|
|
|
{
|
|
|
|
std::string arg0;
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Physics3DRigidBodyDes arg1;
|
|
|
|
axis::Vec3 arg2;
|
|
|
|
axis::Quaternion arg3;
|
2022-07-12 21:31:54 +08:00
|
|
|
ok &= luaval_to_std_string(L, 2, &arg0, "ax.PhysicsMeshRenderer:create");
|
|
|
|
ok &= luaval_to_Physics3DRigidBodyDes(L, 3, &arg1, "ax.PhysicsMeshRenderer:create");
|
|
|
|
ok &= luaval_to_vec3(L, 4, &arg2, "ax.PhysicsMeshRenderer:create");
|
2019-11-23 20:27:39 +08:00
|
|
|
ok &= luaval_to_quaternion(L, 5, &arg3);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!ok)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_error(L, "invalid arguments in function 'lua_axis_physics3d_PhysicsMeshRenderer_create'", nullptr);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::PhysicsMeshRenderer* ret = axis::PhysicsMeshRenderer::create(arg0, &arg1, arg2, arg3);
|
2022-07-12 21:31:54 +08:00
|
|
|
object_to_luaval<axis::PhysicsMeshRenderer>(L, "ax.PhysicsMeshRenderer", (axis::PhysicsMeshRenderer*)ret);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2022-07-12 21:31:54 +08:00
|
|
|
luaL_error(L, "%s has wrong number of arguments: %d, was expecting %d\n ", "ax.PhysicsMeshRenderer:create", argc, 2);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
2022-07-19 15:34:26 +08:00
|
|
|
# if AXIS_DEBUG >= 1
|
2019-11-23 20:27:39 +08:00
|
|
|
tolua_lerror:
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_error(L, "#ferror in function 'lua_axis_physics3d_PhysicsMeshRenderer_create'.", &tolua_err);
|
2021-12-25 10:04:45 +08:00
|
|
|
# endif
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-07-05 14:48:46 +08:00
|
|
|
void extendPhysicsMeshRenderer(lua_State* L)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
lua_pushstring(L, "ax.PhysicsMeshRenderer");
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_rawget(L, LUA_REGISTRYINDEX);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (lua_istable(L, -1))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_function(L, "create", lua_axis_physics3d_PhysicsMeshRenderer_create);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
|
2022-07-12 21:31:54 +08:00
|
|
|
int lua_axis_physics3d_Physics3DRigidBody_create(lua_State* L)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
int argc = 0;
|
|
|
|
bool ok = true;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-19 15:34:26 +08:00
|
|
|
# if AXIS_DEBUG >= 1
|
2019-11-23 20:27:39 +08:00
|
|
|
tolua_Error tolua_err;
|
2021-12-25 10:04:45 +08:00
|
|
|
# endif
|
|
|
|
|
2022-07-19 15:34:26 +08:00
|
|
|
# if AXIS_DEBUG >= 1
|
2022-07-12 21:31:54 +08:00
|
|
|
if (!tolua_isusertable(L, 1, "ax.Physics3DRigidBody", 0, &tolua_err))
|
2021-12-25 10:04:45 +08:00
|
|
|
goto tolua_lerror;
|
|
|
|
# endif
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
argc = lua_gettop(L) - 1;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
if (argc == 1)
|
|
|
|
{
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Physics3DRigidBodyDes arg0;
|
2022-07-12 21:31:54 +08:00
|
|
|
ok &= luaval_to_Physics3DRigidBodyDes(L, 2, &arg0, "ax.Physics3DRigidBody:create");
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!ok)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_error(L, "invalid arguments in function 'lua_axis_physics3d_Physics3DRigidBody_create'", nullptr);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Physics3DRigidBody* ret = axis::Physics3DRigidBody::create(&arg0);
|
2022-07-12 21:31:54 +08:00
|
|
|
object_to_luaval<axis::Physics3DRigidBody>(L, "ax.Physics3DRigidBody", (axis::Physics3DRigidBody*)ret);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2022-07-12 21:31:54 +08:00
|
|
|
luaL_error(L, "%s has wrong number of arguments: %d, was expecting %d\n ", "ax.Physics3DRigidBody:create", argc, 1);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
2022-07-19 15:34:26 +08:00
|
|
|
# if AXIS_DEBUG >= 1
|
2019-11-23 20:27:39 +08:00
|
|
|
tolua_lerror:
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_error(L, "#ferror in function 'lua_axis_physics3d_Physics3DRigidBody_create'.", &tolua_err);
|
2021-12-25 10:04:45 +08:00
|
|
|
# endif
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void extendPhysics3DRigidBody(lua_State* L)
|
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
lua_pushstring(L, "ax.Physics3DRigidBody");
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_rawget(L, LUA_REGISTRYINDEX);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (lua_istable(L, -1))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_function(L, "create", lua_axis_physics3d_Physics3DRigidBody_create);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
|
2022-07-12 21:31:54 +08:00
|
|
|
int lua_axis_physics3d_Physics3DComponent_create(lua_State* L)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
int argc = 0;
|
|
|
|
bool ok = true;
|
2022-07-19 15:34:26 +08:00
|
|
|
# if AXIS_DEBUG >= 1
|
2019-11-23 20:27:39 +08:00
|
|
|
tolua_Error tolua_err;
|
2021-12-25 10:04:45 +08:00
|
|
|
# endif
|
|
|
|
|
2022-07-19 15:34:26 +08:00
|
|
|
# if AXIS_DEBUG >= 1
|
2022-07-12 21:31:54 +08:00
|
|
|
if (!tolua_isusertable(L, 1, "ax.Physics3DComponent", 0, &tolua_err))
|
2021-12-25 10:04:45 +08:00
|
|
|
goto tolua_lerror;
|
|
|
|
# endif
|
|
|
|
|
|
|
|
argc = lua_gettop(L) - 1;
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if (argc == 1)
|
|
|
|
{
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Physics3DObject* arg0;
|
2022-07-12 21:31:54 +08:00
|
|
|
ok &= luaval_to_object<axis::Physics3DObject>(L, 2, "ax.Physics3DObject", &arg0);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Physics3DComponent* ret = axis::Physics3DComponent::create(arg0);
|
2022-07-12 21:31:54 +08:00
|
|
|
object_to_luaval<axis::Physics3DComponent>(L, "ax.Physics3DComponent",
|
2022-07-11 17:50:21 +08:00
|
|
|
(axis::Physics3DComponent*)ret);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} while (0);
|
2021-12-25 10:04:45 +08:00
|
|
|
ok = true;
|
2019-11-23 20:27:39 +08:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if (argc == 2)
|
|
|
|
{
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Physics3DObject* arg0;
|
2022-07-12 21:31:54 +08:00
|
|
|
ok &= luaval_to_object<axis::Physics3DObject>(L, 2, "ax.Physics3DObject", &arg0);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Vec3 arg1;
|
2022-07-12 21:31:54 +08:00
|
|
|
ok &= luaval_to_vec3(L, 3, &arg1, "ax.Physics3DComponent:create");
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Physics3DComponent* ret = axis::Physics3DComponent::create(arg0, arg1);
|
2022-07-12 21:31:54 +08:00
|
|
|
object_to_luaval<axis::Physics3DComponent>(L, "ax.Physics3DComponent",
|
2022-07-11 17:50:21 +08:00
|
|
|
(axis::Physics3DComponent*)ret);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} while (0);
|
2021-12-25 10:04:45 +08:00
|
|
|
ok = true;
|
2019-11-23 20:27:39 +08:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if (argc == 3)
|
|
|
|
{
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Physics3DObject* arg0;
|
2022-07-12 21:31:54 +08:00
|
|
|
ok &= luaval_to_object<axis::Physics3DObject>(L, 2, "ax.Physics3DObject", &arg0);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Vec3 arg1;
|
2022-07-12 21:31:54 +08:00
|
|
|
ok &= luaval_to_vec3(L, 3, &arg1, "ax.Physics3DComponent:create");
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Quaternion arg2;
|
2019-11-23 20:27:39 +08:00
|
|
|
ok &= luaval_to_quaternion(L, 4, &arg2);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Physics3DComponent* ret = axis::Physics3DComponent::create(arg0, arg1, arg2);
|
2022-07-12 21:31:54 +08:00
|
|
|
object_to_luaval<axis::Physics3DComponent>(L, "ax.Physics3DComponent",
|
2022-07-11 17:50:21 +08:00
|
|
|
(axis::Physics3DComponent*)ret);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} while (0);
|
2021-12-25 10:04:45 +08:00
|
|
|
ok = true;
|
2019-11-23 20:27:39 +08:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if (argc == 0)
|
|
|
|
{
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Physics3DComponent* ret = axis::Physics3DComponent::create();
|
2022-07-12 21:31:54 +08:00
|
|
|
object_to_luaval<axis::Physics3DComponent>(L, "ax.Physics3DComponent",
|
2022-07-11 17:50:21 +08:00
|
|
|
(axis::Physics3DComponent*)ret);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} while (0);
|
2021-12-25 10:04:45 +08:00
|
|
|
ok = true;
|
2022-07-12 21:31:54 +08:00
|
|
|
luaL_error(L, "%s has wrong number of arguments: %d, was expecting %d", "ax.Physics3DComponent:create", argc, 0);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
2022-07-19 15:34:26 +08:00
|
|
|
# if AXIS_DEBUG >= 1
|
2019-11-23 20:27:39 +08:00
|
|
|
tolua_lerror:
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_error(L, "#ferror in function 'lua_axis_physics3d_Physics3DComponent_create'.", &tolua_err);
|
2021-12-25 10:04:45 +08:00
|
|
|
# endif
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void extendPhysics3DComponent(lua_State* L)
|
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
lua_pushstring(L, "ax.Physics3DComponent");
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_rawget(L, LUA_REGISTRYINDEX);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (lua_istable(L, -1))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_function(L, "create", lua_axis_physics3d_Physics3DComponent_create);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
|
2022-07-12 21:31:54 +08:00
|
|
|
int lua_axis_physics3d_Physics3DWorld_rayCast(lua_State* L)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
int argc = 0;
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Physics3DWorld* cobj = nullptr;
|
2021-12-25 10:04:45 +08:00
|
|
|
bool ok = true;
|
|
|
|
|
2022-07-19 15:34:26 +08:00
|
|
|
# if AXIS_DEBUG >= 1
|
2019-11-23 20:27:39 +08:00
|
|
|
tolua_Error tolua_err;
|
2021-12-25 10:04:45 +08:00
|
|
|
# endif
|
|
|
|
|
2022-07-19 15:34:26 +08:00
|
|
|
# if AXIS_DEBUG >= 1
|
2022-07-12 21:31:54 +08:00
|
|
|
if (!tolua_isusertype(L, 1, "ax.Physics3DWorld", 0, &tolua_err))
|
2021-12-25 10:04:45 +08:00
|
|
|
goto tolua_lerror;
|
|
|
|
# endif
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
cobj = (axis::Physics3DWorld*)tolua_tousertype(L, 1, 0);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-19 15:34:26 +08:00
|
|
|
# if AXIS_DEBUG >= 1
|
2019-11-23 20:27:39 +08:00
|
|
|
if (!cobj)
|
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_error(L, "invalid 'cobj' in function 'lua_axis_physics3d_Physics3DWorld_rayCast'", nullptr);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
# endif
|
|
|
|
|
|
|
|
argc = lua_gettop(L) - 1;
|
2019-11-23 20:27:39 +08:00
|
|
|
if (argc == 3)
|
|
|
|
{
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Vec3 arg0;
|
|
|
|
axis::Vec3 arg1;
|
|
|
|
axis::Physics3DWorld::HitResult arg2;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-12 21:31:54 +08:00
|
|
|
ok &= luaval_to_vec3(L, 2, &arg0, "ax.Physics3DWorld:rayCast");
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-12 21:31:54 +08:00
|
|
|
ok &= luaval_to_vec3(L, 3, &arg1, "ax.Physics3DWorld:rayCast");
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-12 21:31:54 +08:00
|
|
|
ok &= luaval_to_Physics3DWorld_HitResult(L, 4, &arg2, "ax.Physics3DWorld:rayCast");
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!ok)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_error(L, "invalid arguments in function 'lua_axis_physics3d_Physics3DWorld_rayCast'", nullptr);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
bool ret = cobj->rayCast(arg0, arg1, &arg2);
|
2021-12-25 10:04:45 +08:00
|
|
|
tolua_pushboolean(L, (bool)ret);
|
2019-11-23 20:27:39 +08:00
|
|
|
Physics3DWorld_HitResult_to_luaval(L, arg2);
|
|
|
|
return 2;
|
|
|
|
}
|
2022-07-12 21:31:54 +08:00
|
|
|
luaL_error(L, "%s has wrong number of arguments: %d, was expecting %d \n", "ax.Physics3DWorld:rayCast", argc, 3);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-19 15:34:26 +08:00
|
|
|
# if AXIS_DEBUG >= 1
|
2019-11-23 20:27:39 +08:00
|
|
|
tolua_lerror:
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_error(L, "#ferror in function 'lua_axis_physics3d_Physics3DWorld_rayCast'.", &tolua_err);
|
2021-12-25 10:04:45 +08:00
|
|
|
# endif
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void extendPhysics3DWorld(lua_State* L)
|
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
lua_pushstring(L, "ax.Physics3DWorld");
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_rawget(L, LUA_REGISTRYINDEX);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (lua_istable(L, -1))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_function(L, "rayCast", lua_axis_physics3d_Physics3DWorld_rayCast);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
|
2022-07-12 21:31:54 +08:00
|
|
|
int lua_axis_physics3d_Physics3DShape_createMesh(lua_State* L)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
int argc = 0;
|
|
|
|
bool ok = true;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-19 15:34:26 +08:00
|
|
|
# if AXIS_DEBUG >= 1
|
2019-11-23 20:27:39 +08:00
|
|
|
tolua_Error tolua_err;
|
2021-12-25 10:04:45 +08:00
|
|
|
# endif
|
|
|
|
|
2022-07-19 15:34:26 +08:00
|
|
|
# if AXIS_DEBUG >= 1
|
2022-07-12 21:31:54 +08:00
|
|
|
if (!tolua_isusertable(L, 1, "ax.Physics3DShape", 0, &tolua_err))
|
2021-12-25 10:04:45 +08:00
|
|
|
goto tolua_lerror;
|
|
|
|
# endif
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
argc = lua_gettop(L) - 1;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
if (argc == 2)
|
|
|
|
{
|
|
|
|
std::vector<Vec3> arg0;
|
|
|
|
int arg1;
|
2022-07-12 21:31:54 +08:00
|
|
|
ok &= luaval_to_std_vector_vec3(L, 2, &arg0, "ax.Physics3DShape:createMesh");
|
|
|
|
ok &= luaval_to_int32(L, 3, (int*)&arg1, "ax.Physics3DShape:createMesh");
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!ok)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_error(L, "invalid arguments in function 'lua_axis_physics3d_Physics3DShape_createMesh'", nullptr);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Physics3DShape* ret = axis::Physics3DShape::createMesh(&arg0[0], arg1);
|
2022-07-12 21:31:54 +08:00
|
|
|
object_to_luaval<axis::Physics3DShape>(L, "ax.Physics3DShape", (axis::Physics3DShape*)ret);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2022-07-12 21:31:54 +08:00
|
|
|
luaL_error(L, "%s has wrong number of arguments: %d, was expecting %d\n ", "ax.Physics3DShape:createMesh", argc, 2);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
2022-07-19 15:34:26 +08:00
|
|
|
# if AXIS_DEBUG >= 1
|
2019-11-23 20:27:39 +08:00
|
|
|
tolua_lerror:
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_error(L, "#ferror in function 'lua_axis_physics3d_Physics3DShape_createMesh'.", &tolua_err);
|
2021-12-25 10:04:45 +08:00
|
|
|
# endif
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-07-12 21:31:54 +08:00
|
|
|
int lua_axis_physics3d_Physics3DShape_createHeightfield(lua_State* L)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
int argc = 0;
|
|
|
|
bool ok = true;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-19 15:34:26 +08:00
|
|
|
# if AXIS_DEBUG >= 1
|
2019-11-23 20:27:39 +08:00
|
|
|
tolua_Error tolua_err;
|
2021-12-25 10:04:45 +08:00
|
|
|
# endif
|
|
|
|
|
2022-07-19 15:34:26 +08:00
|
|
|
# if AXIS_DEBUG >= 1
|
2022-07-12 21:31:54 +08:00
|
|
|
if (!tolua_isusertable(L, 1, "ax.Physics3DShape", 0, &tolua_err))
|
2021-12-25 10:04:45 +08:00
|
|
|
goto tolua_lerror;
|
|
|
|
# endif
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
argc = lua_gettop(L) - 1;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
if (argc == 8)
|
|
|
|
{
|
|
|
|
int arg0;
|
|
|
|
int arg1;
|
|
|
|
std::vector<float> arg2;
|
|
|
|
double arg3;
|
|
|
|
double arg4;
|
|
|
|
double arg5;
|
|
|
|
bool arg6;
|
|
|
|
bool arg7;
|
2022-07-12 21:31:54 +08:00
|
|
|
ok &= luaval_to_int32(L, 2, (int*)&arg0, "ax.Physics3DShape:createHeightfield");
|
|
|
|
ok &= luaval_to_int32(L, 3, (int*)&arg1, "ax.Physics3DShape:createHeightfield");
|
|
|
|
ok &= luaval_to_std_vector_float(L, 4, &arg2, "ax.Physics3DShape:createHeightfield");
|
|
|
|
ok &= luaval_to_number(L, 5, &arg3, "ax.Physics3DShape:createHeightfield");
|
|
|
|
ok &= luaval_to_number(L, 6, &arg4, "ax.Physics3DShape:createHeightfield");
|
|
|
|
ok &= luaval_to_number(L, 7, &arg5, "ax.Physics3DShape:createHeightfield");
|
|
|
|
ok &= luaval_to_boolean(L, 8, &arg6, "ax.Physics3DShape:createHeightfield");
|
|
|
|
ok &= luaval_to_boolean(L, 9, &arg7, "ax.Physics3DShape:createHeightfield");
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!ok)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_error(L, "invalid arguments in function 'lua_axis_physics3d_Physics3DShape_createHeightfield'",
|
2021-12-25 10:04:45 +08:00
|
|
|
nullptr);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Physics3DShape* ret = axis::Physics3DShape::createHeightfield(arg0, arg1, &arg2[0], (float)arg3,
|
2021-12-25 10:04:45 +08:00
|
|
|
(float)arg4, (float)arg5, arg6, arg7);
|
2022-07-12 21:31:54 +08:00
|
|
|
object_to_luaval<axis::Physics3DShape>(L, "ax.Physics3DShape", (axis::Physics3DShape*)ret);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (argc == 9)
|
|
|
|
{
|
|
|
|
int arg0;
|
|
|
|
int arg1;
|
|
|
|
std::vector<float> arg2;
|
|
|
|
double arg3;
|
|
|
|
double arg4;
|
|
|
|
double arg5;
|
|
|
|
bool arg6;
|
|
|
|
bool arg7;
|
|
|
|
bool arg8;
|
2022-07-12 21:31:54 +08:00
|
|
|
ok &= luaval_to_int32(L, 2, (int*)&arg0, "ax.Physics3DShape:createHeightfield");
|
|
|
|
ok &= luaval_to_int32(L, 3, (int*)&arg1, "ax.Physics3DShape:createHeightfield");
|
|
|
|
ok &= luaval_to_std_vector_float(L, 4, &arg2, "ax.Physics3DShape:createHeightfield");
|
|
|
|
ok &= luaval_to_number(L, 5, &arg3, "ax.Physics3DShape:createHeightfield");
|
|
|
|
ok &= luaval_to_number(L, 6, &arg4, "ax.Physics3DShape:createHeightfield");
|
|
|
|
ok &= luaval_to_number(L, 7, &arg5, "ax.Physics3DShape:createHeightfield");
|
|
|
|
ok &= luaval_to_boolean(L, 8, &arg6, "ax.Physics3DShape:createHeightfield");
|
|
|
|
ok &= luaval_to_boolean(L, 9, &arg7, "ax.Physics3DShape:createHeightfield");
|
|
|
|
ok &= luaval_to_boolean(L, 10, &arg8, "ax.Physics3DShape:createHeightfield");
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!ok)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_error(L, "invalid arguments in function 'lua_axis_physics3d_Physics3DShape_createHeightfield'",
|
2021-12-25 10:04:45 +08:00
|
|
|
nullptr);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Physics3DShape* ret = axis::Physics3DShape::createHeightfield(
|
2021-12-25 10:04:45 +08:00
|
|
|
arg0, arg1, &arg2[0], (float)arg3, (float)arg4, (float)arg5, arg6, arg7, arg8);
|
2022-07-12 21:31:54 +08:00
|
|
|
object_to_luaval<axis::Physics3DShape>(L, "ax.Physics3DShape", (axis::Physics3DShape*)ret);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2022-07-12 21:31:54 +08:00
|
|
|
luaL_error(L, "%s has wrong number of arguments: %d, was expecting %d\n ", "ax.Physics3DShape:createHeightfield",
|
2021-12-25 10:04:45 +08:00
|
|
|
argc, 8);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
2022-07-19 15:34:26 +08:00
|
|
|
# if AXIS_DEBUG >= 1
|
2019-11-23 20:27:39 +08:00
|
|
|
tolua_lerror:
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_error(L, "#ferror in function 'lua_axis_physics3d_Physics3DShape_createHeightfield'.", &tolua_err);
|
2021-12-25 10:04:45 +08:00
|
|
|
# endif
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-07-12 21:31:54 +08:00
|
|
|
int lua_axis_physics3d_Physics3DShape_createCompoundShape(lua_State* L)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
int argc = 0;
|
|
|
|
bool ok = true;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
tolua_Error tolua_err;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-19 15:34:26 +08:00
|
|
|
# if AXIS_DEBUG >= 1
|
2022-07-12 21:31:54 +08:00
|
|
|
if (!tolua_isusertable(L, 1, "ax.Physics3DShape", 0, &tolua_err))
|
2021-12-25 10:04:45 +08:00
|
|
|
goto tolua_lerror;
|
|
|
|
# endif
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
argc = lua_gettop(L) - 1;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
if (argc == 1)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
std::vector<std::pair<axis::Physics3DShape*, axis::Mat4>> shapes;
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!tolua_istable(L, 2, 0, &tolua_err))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-07-19 15:34:26 +08:00
|
|
|
# if AXIS_DEBUG >= 1
|
2022-07-12 21:31:54 +08:00
|
|
|
luaval_to_native_err(L, "#ferror:", &tolua_err, "ax.Physics3DShape:createCompoundShape");
|
2021-12-25 10:04:45 +08:00
|
|
|
# endif
|
2019-11-23 20:27:39 +08:00
|
|
|
ok = false;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
if (ok)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
size_t len = lua_objlen(L, 2);
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Physics3DShape* shape = nullptr;
|
|
|
|
axis::Mat4 mat;
|
2019-11-23 20:27:39 +08:00
|
|
|
for (size_t i = 0; i < len; i++)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
lua_pushnumber(L, i + 1);
|
|
|
|
lua_gettable(L, 2);
|
2019-11-23 20:27:39 +08:00
|
|
|
if (lua_istable(L, -1))
|
|
|
|
{
|
|
|
|
lua_pushnumber(L, 1);
|
|
|
|
lua_gettable(L, -2);
|
2022-07-12 21:31:54 +08:00
|
|
|
luaval_to_object(L, lua_gettop(L), "ax.Physics3DShape", &shape);
|
2021-12-25 10:04:45 +08:00
|
|
|
lua_pop(L, 1);
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_pushnumber(L, 2);
|
|
|
|
lua_gettable(L, -2);
|
|
|
|
luaval_to_mat4(L, lua_gettop(L), &mat);
|
2021-12-25 10:04:45 +08:00
|
|
|
lua_pop(L, 1);
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
shapes.push_back(std::make_pair(shape, mat));
|
|
|
|
}
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Physics3DShape* ret = axis::Physics3DShape::createCompoundShape(shapes);
|
2022-07-12 21:31:54 +08:00
|
|
|
object_to_luaval<axis::Physics3DShape>(L, "ax.Physics3DShape", (axis::Physics3DShape*)ret);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2022-07-12 21:31:54 +08:00
|
|
|
luaL_error(L, "%s has wrong number of arguments: %d, was expecting %d\n ", "ax.Physics3DShape:createCompoundShape",
|
2021-12-25 10:04:45 +08:00
|
|
|
argc, 1);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
2022-07-19 15:34:26 +08:00
|
|
|
# if AXIS_DEBUG >= 1
|
2019-11-23 20:27:39 +08:00
|
|
|
tolua_lerror:
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_error(L, "#ferror in function 'lua_axis_physics3d_Physics3DShape_createCompoundShape'.", &tolua_err);
|
2021-12-25 10:04:45 +08:00
|
|
|
# endif
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void extendPhysics3DShape(lua_State* L)
|
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
lua_pushstring(L, "ax.Physics3DShape");
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_rawget(L, LUA_REGISTRYINDEX);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (lua_istable(L, -1))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_function(L, "createMesh", lua_axis_physics3d_Physics3DShape_createMesh);
|
|
|
|
tolua_function(L, "createHeightfield", lua_axis_physics3d_Physics3DShape_createHeightfield);
|
|
|
|
tolua_function(L, "createCompoundShape", lua_axis_physics3d_Physics3DShape_createCompoundShape);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
void CollisionPoint_to_luaval(lua_State* L, const axis::Physics3DCollisionInfo::CollisionPoint& collisionPoint)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (nullptr == L)
|
2019-11-23 20:27:39 +08:00
|
|
|
return;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
lua_newtable(L);
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_pushstring(L, "localPositionOnA");
|
|
|
|
vec3_to_luaval(L, collisionPoint.localPositionOnA);
|
|
|
|
lua_rawset(L, -3);
|
|
|
|
lua_pushstring(L, "worldPositionOnA");
|
|
|
|
vec3_to_luaval(L, collisionPoint.worldPositionOnA);
|
|
|
|
lua_rawset(L, -3);
|
|
|
|
lua_pushstring(L, "localPositionOnB");
|
|
|
|
vec3_to_luaval(L, collisionPoint.localPositionOnB);
|
|
|
|
lua_rawset(L, -3);
|
|
|
|
lua_pushstring(L, "worldPositionOnB");
|
|
|
|
vec3_to_luaval(L, collisionPoint.worldPositionOnB);
|
|
|
|
lua_rawset(L, -3);
|
|
|
|
lua_pushstring(L, "worldNormalOnB");
|
|
|
|
vec3_to_luaval(L, collisionPoint.worldNormalOnB);
|
|
|
|
lua_rawset(L, -3);
|
|
|
|
}
|
|
|
|
|
2022-07-12 21:31:54 +08:00
|
|
|
int lua_axis_physics3d_Physics3DObject_setCollisionCallback(lua_State* L)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
int argc = 0;
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Physics3DObject* cobj = nullptr;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-19 15:34:26 +08:00
|
|
|
# if AXIS_DEBUG >= 1
|
2019-11-23 20:27:39 +08:00
|
|
|
tolua_Error tolua_err;
|
2021-12-25 10:04:45 +08:00
|
|
|
# endif
|
|
|
|
|
2022-07-19 15:34:26 +08:00
|
|
|
# if AXIS_DEBUG >= 1
|
2022-07-12 21:31:54 +08:00
|
|
|
if (!tolua_isusertype(L, 1, "ax.Physics3DObject", 0, &tolua_err))
|
2021-12-25 10:04:45 +08:00
|
|
|
goto tolua_lerror;
|
|
|
|
# endif
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
cobj = (axis::Physics3DObject*)tolua_tousertype(L, 1, 0);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-19 15:34:26 +08:00
|
|
|
# if AXIS_DEBUG >= 1
|
2019-11-23 20:27:39 +08:00
|
|
|
if (!cobj)
|
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_error(L, "invalid 'cobj' in function 'lua_axis_physics3d_Physics3DObject_setCollisionCallback'",
|
2021-12-25 10:04:45 +08:00
|
|
|
nullptr);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
# endif
|
|
|
|
|
|
|
|
argc = lua_gettop(L) - 1;
|
2019-11-23 20:27:39 +08:00
|
|
|
if (argc == 1)
|
|
|
|
{
|
2022-07-19 15:34:26 +08:00
|
|
|
# if AXIS_DEBUG >= 1
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!toluafix_isfunction(L, 2, "LUA_FUNCTION", 0, &tolua_err))
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
goto tolua_lerror;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
# endif
|
|
|
|
LUA_FUNCTION handler = toluafix_ref_function(L, 2, 0);
|
2022-07-11 17:50:21 +08:00
|
|
|
cobj->setCollisionCallback([=](const axis::Physics3DCollisionInfo& ci) {
|
2021-11-15 19:05:08 +08:00
|
|
|
auto stack = LuaEngine::getInstance()->getLuaStack();
|
|
|
|
auto Ls = stack->getLuaState();
|
|
|
|
lua_newtable(Ls);
|
|
|
|
lua_pushstring(Ls, "objA");
|
2019-11-23 20:27:39 +08:00
|
|
|
if (nullptr == ci.objA)
|
|
|
|
{
|
2021-11-15 19:05:08 +08:00
|
|
|
lua_pushnil(Ls);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
object_to_luaval(Ls, "ax.Physics3DObject", ci.objA);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-11-15 19:05:08 +08:00
|
|
|
lua_rawset(Ls, -3);
|
|
|
|
lua_pushstring(Ls, "objB");
|
2019-11-23 20:27:39 +08:00
|
|
|
if (nullptr == ci.objB)
|
|
|
|
{
|
2021-11-15 19:05:08 +08:00
|
|
|
lua_pushnil(Ls);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
object_to_luaval(Ls, "ax.Physics3DObject", ci.objB);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-11-15 19:05:08 +08:00
|
|
|
lua_rawset(Ls, -3);
|
|
|
|
lua_pushstring(Ls, "collisionPointList");
|
2019-11-23 20:27:39 +08:00
|
|
|
if (ci.collisionPointList.empty())
|
|
|
|
{
|
2021-11-15 19:05:08 +08:00
|
|
|
lua_pushnil(Ls);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int vecIndex = 1;
|
2021-11-15 19:05:08 +08:00
|
|
|
lua_newtable(Ls);
|
2019-11-23 20:27:39 +08:00
|
|
|
for (const auto& value : ci.collisionPointList)
|
|
|
|
{
|
2021-11-15 19:05:08 +08:00
|
|
|
lua_pushnumber(Ls, vecIndex);
|
|
|
|
CollisionPoint_to_luaval(Ls, value);
|
|
|
|
lua_rawset(Ls, -3);
|
2019-11-23 20:27:39 +08:00
|
|
|
++vecIndex;
|
|
|
|
}
|
|
|
|
}
|
2021-11-15 19:05:08 +08:00
|
|
|
lua_rawset(Ls, -3);
|
|
|
|
stack->executeFunctionByHandler(handler, 1);
|
2019-11-23 20:27:39 +08:00
|
|
|
});
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
ScriptHandlerMgr::getInstance()->addCustomHandler((void*)cobj, handler);
|
|
|
|
return 0;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
luaL_error(L, "%s has wrong number of arguments: %d, was expecting %d \n",
|
2022-07-12 21:31:54 +08:00
|
|
|
"ax.Physics3DObject:setCollisionCallback", argc, 1);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-19 15:34:26 +08:00
|
|
|
# if AXIS_DEBUG >= 1
|
2019-11-23 20:27:39 +08:00
|
|
|
tolua_lerror:
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_error(L, "#ferror in function 'lua_axis_physics3d_Physics3DObject_setCollisionCallback'.", &tolua_err);
|
2021-12-25 10:04:45 +08:00
|
|
|
# endif
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void extendPhysics3DObject(lua_State* L)
|
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
lua_pushstring(L, "ax.Physics3DObject");
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_rawget(L, LUA_REGISTRYINDEX);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (lua_istable(L, -1))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_function(L, "setCollisionCallback", lua_axis_physics3d_Physics3DObject_setCollisionCallback);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int register_all_physics3d_manual(lua_State* L)
|
|
|
|
{
|
|
|
|
if (nullptr == L)
|
|
|
|
return 0;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-05 14:48:46 +08:00
|
|
|
extendPhysicsMeshRenderer(L);
|
2019-11-23 20:27:39 +08:00
|
|
|
extendPhysics3DRigidBody(L);
|
|
|
|
extendPhysics3DComponent(L);
|
|
|
|
extendPhysics3DWorld(L);
|
|
|
|
extendPhysics3DShape(L);
|
|
|
|
extendPhysics3DObject(L);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int register_physics3d_module(lua_State* L)
|
|
|
|
{
|
|
|
|
lua_getglobal(L, "_G");
|
2021-12-25 10:04:45 +08:00
|
|
|
if (lua_istable(L, -1)) // stack:...,_G,
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
register_all_axis_physics3d(L);
|
2019-11-23 20:27:39 +08:00
|
|
|
register_all_physics3d_manual(L);
|
|
|
|
}
|
|
|
|
lua_pop(L, 1);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|