From a20681aa210a894c527c4e2059c364880b2521cc Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Tue, 2 Jun 2015 18:37:57 +0800 Subject: [PATCH 1/4] Add Lua-bindings for NavMesh --- build/cocos2d_tests.xcodeproj/project.pbxproj | 4 + cocos/scripting/lua-bindings/CMakeLists.txt | 5 + .../manual/cocos2d/lua_cocos2dx_manual.cpp | 159 ++++++ .../lua_cocos2dx_navmesh_conversions.cpp | 216 ++++++++ .../lua_cocos2dx_navmesh_conversions.h | 50 ++ .../navmesh/lua_cocos2dx_navmesh_manual.cpp | 148 ++++++ .../navmesh/lua_cocos2dx_navmesh_manual.h | 57 +++ .../lua-bindings/proj.android/Android.mk | 8 + .../project.pbxproj | 48 +- .../proj.win32/libluacocos2d.vcxproj | 10 +- .../proj.win32/libluacocos2d.vcxproj.filters | 21 + .../project/Classes/lua_module_register.h | 5 + .../proj.win32/lua-tests.win32.vcxproj | 19 +- .../lua-tests/src/NavMeshTest/NavMeshTest.lua | 465 ++++++++++++++++++ tests/lua-tests/src/mainMenu.lua | 6 + tools/bindings-generator | 2 +- .../runtime-src/Classes/lua_module_register.h | 4 + tools/tolua/cocos2dx_3d.ini | 2 +- tools/tolua/cocos2dx_navmesh.ini | 66 +++ tools/tolua/genbindings.py | 31 +- 20 files changed, 1299 insertions(+), 27 deletions(-) create mode 100644 cocos/scripting/lua-bindings/manual/navmesh/lua_cocos2dx_navmesh_conversions.cpp create mode 100644 cocos/scripting/lua-bindings/manual/navmesh/lua_cocos2dx_navmesh_conversions.h create mode 100644 cocos/scripting/lua-bindings/manual/navmesh/lua_cocos2dx_navmesh_manual.cpp create mode 100644 cocos/scripting/lua-bindings/manual/navmesh/lua_cocos2dx_navmesh_manual.h create mode 100644 tests/lua-tests/src/NavMeshTest/NavMeshTest.lua create mode 100644 tools/tolua/cocos2dx_navmesh.ini diff --git a/build/cocos2d_tests.xcodeproj/project.pbxproj b/build/cocos2d_tests.xcodeproj/project.pbxproj index 2d6b5cad3d..b38c10b28e 100644 --- a/build/cocos2d_tests.xcodeproj/project.pbxproj +++ b/build/cocos2d_tests.xcodeproj/project.pbxproj @@ -40,6 +40,7 @@ /* Begin PBXBuildFile section */ 1502702D1AD3BDBC0089CD03 /* TerrainTest in Resources */ = {isa = PBXBuildFile; fileRef = B603F1B31AC8FBFB00A9579C /* TerrainTest */; }; 1502702E1AD3BDC90089CD03 /* TerrainTest in Resources */ = {isa = PBXBuildFile; fileRef = B603F1B31AC8FBFB00A9579C /* TerrainTest */; }; + 150983E11B1C514B007F3818 /* NavMesh in Resources */ = {isa = PBXBuildFile; fileRef = B61E90CA1B12B74B00BE69EA /* NavMesh */; }; 150F918819DA409E00B89F57 /* lua_test_bindings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 150F918619DA409E00B89F57 /* lua_test_bindings.cpp */; }; 150F918919DA409F00B89F57 /* lua_test_bindings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 150F918619DA409E00B89F57 /* lua_test_bindings.cpp */; }; 1531B2501AE013DE0075DB94 /* Test.html in Resources */ = {isa = PBXBuildFile; fileRef = 29AFEF6619ACCAA000F6B10A /* Test.html */; }; @@ -64,6 +65,7 @@ 15B914491B15721400C6B95B /* Shaders3D in Resources */ = {isa = PBXBuildFile; fileRef = B2507B6A192589AF00FA4972 /* Shaders3D */; }; 15B9144A1B15A18C00C6B95B /* Materials in Resources */ = {isa = PBXBuildFile; fileRef = 5046AB5A1AF2C4180060550B /* Materials */; }; 15B9144B1B15A18C00C6B95B /* Shaders3D in Resources */ = {isa = PBXBuildFile; fileRef = B2507B6A192589AF00FA4972 /* Shaders3D */; }; + 15BF83C71B1D9E8900D518FA /* NavMesh in Resources */ = {isa = PBXBuildFile; fileRef = B61E90CA1B12B74B00BE69EA /* NavMesh */; }; 15C64825165F3934007D4F18 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15C64824165F3934007D4F18 /* OpenGL.framework */; }; 15C64827165F394E007D4F18 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15C64826165F394E007D4F18 /* QuartzCore.framework */; }; 15C64829165F396B007D4F18 /* OpenAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15C64828165F396B007D4F18 /* OpenAL.framework */; }; @@ -4465,6 +4467,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 150983E11B1C514B007F3818 /* NavMesh in Resources */, 15B914491B15721400C6B95B /* Shaders3D in Resources */, 15B914481B156A3700C6B95B /* Materials in Resources */, 1531B2501AE013DE0075DB94 /* Test.html in Resources */, @@ -4514,6 +4517,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 15BF83C71B1D9E8900D518FA /* NavMesh in Resources */, 15B9144A1B15A18C00C6B95B /* Materials in Resources */, 15B9144B1B15A18C00C6B95B /* Shaders3D in Resources */, 1531B2511AE013F00075DB94 /* Test.html in Resources */, diff --git a/cocos/scripting/lua-bindings/CMakeLists.txt b/cocos/scripting/lua-bindings/CMakeLists.txt index 00e298040d..288e0485b3 100644 --- a/cocos/scripting/lua-bindings/CMakeLists.txt +++ b/cocos/scripting/lua-bindings/CMakeLists.txt @@ -19,11 +19,13 @@ include_directories( ${cocos_root}/cocos/platform ${cocos_root}/cocos/audio/include ${cocos_root}/cocos/physics3d + ${cocos_root}/cocos/navmesh manual manual/extension manual/cocostudio manual/ui manual/cocos2d + manual/navmesh auto ) @@ -110,6 +112,8 @@ set(lua_bindings_manual_files manual/video/lua_cocos2dx_experimental_video_manual.cpp manual/audioengine/lua_cocos2dx_audioengine_manual.cpp manual/physics3d/lua_cocos2dx_physics3d_manual.cpp + manual/navmesh/lua_cocos2dx_navmesh_conversions.cpp + manual/navmesh/lua_cocos2dx_navmesh_manual.cpp ) set(lua_bindings_auto_files @@ -128,6 +132,7 @@ set(lua_bindings_auto_files auto/lua_cocos2dx_ui_auto.cpp auto/lua_cocos2dx_audioengine_auto.cpp auto/lua_cocos2dx_physics3d_auto.cpp + auto/lua_cocos2dx_navmesh_auto.cpp ) if(MACOSX) diff --git a/cocos/scripting/lua-bindings/manual/cocos2d/lua_cocos2dx_manual.cpp b/cocos/scripting/lua-bindings/manual/cocos2d/lua_cocos2dx_manual.cpp index 39903bb965..abf67858bd 100644 --- a/cocos/scripting/lua-bindings/manual/cocos2d/lua_cocos2dx_manual.cpp +++ b/cocos/scripting/lua-bindings/manual/cocos2d/lua_cocos2dx_manual.cpp @@ -2530,6 +2530,159 @@ tolua_lerror: #endif //CC_USE_PHYSICS +#if CC_USE_NAVMESH +#include "navmesh/CCNavMesh.h" +int lua_cocos2dx_Scene_setNavMeshDebugCamera(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::Scene* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"cc.Scene",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::Scene*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Scene_setNavMeshDebugCamera'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + cocos2d::Camera* arg0; + + ok &= luaval_to_object(tolua_S, 2, "cc.Camera",&arg0, "cc.Scene:setNavMeshDebugCamera"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Scene_setNavMeshDebugCamera'", nullptr); + return 0; + } + cobj->setNavMeshDebugCamera(arg0); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Scene:setNavMeshDebugCamera",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Scene_setNavMeshDebugCamera'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_Scene_setNavMesh(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::Scene* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"cc.Scene",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::Scene*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Scene_setNavMesh'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + cocos2d::NavMesh* arg0; + + ok &= luaval_to_object(tolua_S, 2, "cc.NavMesh",&arg0, "cc.Scene:setNavMesh"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Scene_setNavMesh'", nullptr); + return 0; + } + cobj->setNavMesh(arg0); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Scene:setNavMesh",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Scene_setNavMesh'.",&tolua_err); +#endif + + return 0; +} + +int lua_cocos2dx_Scene_getNavMesh(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::Scene* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"cc.Scene",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::Scene*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Scene_getNavMesh'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 0) + { + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Scene_getNavMesh'", nullptr); + return 0; + } + cocos2d::NavMesh* ret = cobj->getNavMesh(); + object_to_luaval(tolua_S, "cc.NavMesh",(cocos2d::NavMesh*)ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Scene:getNavMesh",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Scene_getNavMesh'.",&tolua_err); +#endif + + return 0; +} + +#endif //#if CC_USE_NAVMESH + static int tolua_cocos2d_Spawn_create(lua_State* tolua_S) { if (NULL == tolua_S) @@ -4771,6 +4924,12 @@ static void extendScene(lua_State* tolua_S) tolua_function(tolua_S, "getPhysics3DWorld", lua_cocos2dx_Scene_getPhysics3DWorld); tolua_function(tolua_S, "setPhysics3DDebugCamera", lua_cocos2dx_Scene_setPhysics3DDebugCamera); #endif + +#if CC_USE_NAVMESH + tolua_function(tolua_S, "setNavMeshDebugCamera", lua_cocos2dx_Scene_setNavMeshDebugCamera); + tolua_function(tolua_S, "setNavMesh", lua_cocos2dx_Scene_setNavMesh); + tolua_function(tolua_S, "getNavMesh", lua_cocos2dx_Scene_getNavMesh); +#endif } lua_pop(tolua_S, 1); } diff --git a/cocos/scripting/lua-bindings/manual/navmesh/lua_cocos2dx_navmesh_conversions.cpp b/cocos/scripting/lua-bindings/manual/navmesh/lua_cocos2dx_navmesh_conversions.cpp new file mode 100644 index 0000000000..65a9288c5f --- /dev/null +++ b/cocos/scripting/lua-bindings/manual/navmesh/lua_cocos2dx_navmesh_conversions.cpp @@ -0,0 +1,216 @@ +/**************************************************************************** + Copyright (c) 2013-2014 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + 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 "lua_cocos2dx_navmesh_conversions.h" +#include "base/ccConfig.h" +#if CC_USE_NAVMESH + +#include "LuaBasicConversions.h" +#include "navmesh/CCNavMeshAgent.h" + +#if COCOS2D_DEBUG >=1 +extern void luaval_to_native_err(lua_State* L,const char* msg,tolua_Error* err, const char* funcName); +#endif + +bool luaval_to_navmeshagentparam(lua_State* L, int lo, cocos2d::NavMeshAgentParam* outValue , const char* funcName) +{ + if (nullptr == L || nullptr == outValue) + return false; + + bool ok = true; + + tolua_Error tolua_err; + if (!tolua_istable(L, lo, 0, &tolua_err) ) + { +#if COCOS2D_DEBUG >=1 + luaval_to_native_err(L,"#ferror:",&tolua_err,funcName); +#endif + ok = false; + } + + if (ok) + { + lua_pushstring(L, "radius"); + lua_gettable(L,lo); + outValue->radius = lua_isnumber(L, -1)? (float)lua_tonumber(L, -1) : 0.6; + lua_pop(L,1); + + lua_pushstring(L, "height"); + lua_gettable(L,lo); + outValue->height = lua_isnumber(L, -1)?(float)lua_tonumber(L, -1) : 2.0; + lua_pop(L,1); + + lua_pushstring(L, "maxAcceleration"); + lua_gettable(L, lo); + outValue->maxAcceleration = lua_isnumber(L, -1)?(float)lua_tonumber(L, -1) : 8.0; + lua_pop(L, 1); + + + lua_pushstring(L, "maxSpeed"); + lua_gettable(L, lo); + outValue->maxSpeed = lua_isnumber(L, -1)?(float)lua_tonumber(L, -1) : 3.5; + lua_pop(L, 1); + + lua_pushstring(L, "collisionQueryRange"); + lua_gettable(L, lo); + outValue->collisionQueryRange = lua_isnumber(L, -1)?(float)lua_tonumber(L, -1) : outValue->radius * 12.0; + lua_pop(L, 1); + + lua_pushstring(L, "pathOptimizationRange"); + lua_gettable(L, lo); + outValue->pathOptimizationRange = lua_isnumber(L, -1)?(float)lua_tonumber(L, -1) : outValue->radius * 30.0; + lua_pop(L, 1); + + lua_pushstring(L, "separationWeight"); + lua_gettable(L, lo); + outValue->separationWeight = lua_isnumber(L, -1)?(float)lua_tonumber(L, -1) : 2.0; + lua_pop(L, 1); + + lua_pushstring(L, "updateFlags"); + lua_gettable(L, lo); + outValue->updateFlags = lua_isnumber(L, -1)?(unsigned char)lua_tonumber(L, -1) : DT_CROWD_ANTICIPATE_TURNS | DT_CROWD_OPTIMIZE_VIS | DT_CROWD_OPTIMIZE_TOPO | DT_CROWD_OBSTACLE_AVOIDANCE; + lua_pop(L, 1); + + lua_pushstring(L, "obstacleAvoidanceType"); + lua_gettable(L, lo); + outValue->obstacleAvoidanceType = lua_isnumber(L, -1)?(unsigned char)lua_tonumber(L, -1) : 3; + lua_pop(L, 1); + + lua_pushstring(L, "queryFilterType"); + lua_gettable(L, lo); + outValue->queryFilterType = lua_isnumber(L, -1)?(unsigned char)lua_tonumber(L, -1) : 0; + lua_pop(L, 1); + + return true; + } + + return false; +} + +bool luaval_to_offmeshlinkdata(lua_State* L, int lo, cocos2d::OffMeshLinkData* outValue , const char* funcName = "") +{ + if (nullptr == L || nullptr == outValue) + return false; + + bool ok = true; + + tolua_Error tolua_err; + if (!tolua_istable(L, lo, 0, &tolua_err) ) + { +#if COCOS2D_DEBUG >=1 + luaval_to_native_err(L,"#ferror:",&tolua_err,funcName); +#endif + ok = false; + } + + if (ok) + { + lua_pushstring(L, "startPosition"); + lua_gettable(L,lo); + ok &= luaval_to_vec3(L, lua_gettop(L), &outValue->startPosition); + if(!ok) + { + lua_pop(L, 1); + return false; + } + lua_pop(L,1); + + lua_pushstring(L, "endPosition"); + ok &= luaval_to_vec3(L, lua_gettop(L), &outValue->endPosition); + if(!ok) + { + lua_pop(L, 1); + return false; + } + lua_pop(L,1); + return true; + } + + return false; +} + +void navmeshagentparam_to_luaval(lua_State* L,const cocos2d::NavMeshAgentParam& inValue) +{ + if (nullptr == L) + return; + + lua_newtable(L); + + lua_pushstring(L, "radius"); + lua_pushnumber(L, (lua_Number)inValue.radius); + lua_rawset(L, -3); + + lua_pushstring(L, "height"); + lua_pushnumber(L, (lua_Number)inValue.height); + lua_rawset(L, -3); + + lua_pushstring(L, "maxAcceleration"); + lua_pushnumber(L, (lua_Number)inValue.maxAcceleration); + lua_rawset(L, -3); + + lua_pushstring(L, "maxSpeed"); + lua_pushnumber(L, (lua_Number)inValue.maxSpeed); + lua_rawset(L, -3); + + lua_pushstring(L, "collisionQueryRange"); + lua_pushnumber(L, (lua_Number)inValue.collisionQueryRange); + lua_rawset(L, -3); + + lua_pushstring(L, "pathOptimizationRange"); + lua_pushnumber(L, (lua_Number)inValue.pathOptimizationRange); + lua_rawset(L, -3); + + lua_pushstring(L, "separationWeight"); + lua_pushnumber(L, (lua_Number)inValue.separationWeight); + lua_rawset(L, -3); + + lua_pushstring(L, "updateFlags"); + lua_pushnumber(L, (lua_Number)inValue.updateFlags); + lua_rawset(L, -3); + + lua_pushstring(L, "obstacleAvoidanceType"); + lua_pushnumber(L, (lua_Number)inValue.obstacleAvoidanceType); + lua_rawset(L, -3); + + lua_pushstring(L, "queryFilterType"); + lua_pushnumber(L, (lua_Number)inValue.queryFilterType); + lua_rawset(L, -3); +} + +void offmeshlinkdata_to_luaval(lua_State* L,const cocos2d::OffMeshLinkData& inValue) +{ + if (nullptr == L) + return; + + lua_newtable(L); + lua_pushstring(L, "startPosition"); + vec3_to_luaval(L, inValue.startPosition); + lua_rawset(L, -3); + + lua_pushstring(L, "endPosition"); + vec3_to_luaval(L, inValue.endPosition); + lua_rawset(L, -3); +} + +#endif \ No newline at end of file diff --git a/cocos/scripting/lua-bindings/manual/navmesh/lua_cocos2dx_navmesh_conversions.h b/cocos/scripting/lua-bindings/manual/navmesh/lua_cocos2dx_navmesh_conversions.h new file mode 100644 index 0000000000..8809902eab --- /dev/null +++ b/cocos/scripting/lua-bindings/manual/navmesh/lua_cocos2dx_navmesh_conversions.h @@ -0,0 +1,50 @@ +/**************************************************************************** + Copyright (c) 2013-2015 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + 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. + ****************************************************************************/ +#ifndef __COCOS_SCRIPTING_LUA_BINDING_MANUAL_NAVMESH_LUA_NAVMESH_CONVERSIONS_H__ +#define __COCOS_SCRIPTING_LUA_BINDING_MANUAL_NAVMESH_LUA_NAVMESH_CONVERSIONS_H__ + +#if CC_USE_NAVMESH + +extern "C" { +#include "lua.h" +#include "tolua++.h" +} + +#include "tolua_fix.h" + +namespace cocos2d +{ + struct NavMeshAgentParam; + struct OffMeshLinkData; +} + +extern bool luaval_to_navmeshagentparam(lua_State* L, int lo, cocos2d::NavMeshAgentParam* outValue , const char* funcName = ""); +extern bool luaval_to_offmeshlinkdata(lua_State* L, int lo, cocos2d::OffMeshLinkData* outValue , const char* funcName = ""); + +extern void navmeshagentparam_to_luaval(lua_State* L,const cocos2d::NavMeshAgentParam& inValue); +extern void offmeshlinkdata_to_luaval(lua_State* L,const cocos2d::OffMeshLinkData& inValue); + + +#endif // #if CC_USE_NAVMESH +#endif // __COCOS_SCRIPTING_LUA_BINDING_MANUAL_NAVMESH_LUA_NAVMESH_CONVERSIONS_H__ diff --git a/cocos/scripting/lua-bindings/manual/navmesh/lua_cocos2dx_navmesh_manual.cpp b/cocos/scripting/lua-bindings/manual/navmesh/lua_cocos2dx_navmesh_manual.cpp new file mode 100644 index 0000000000..d398d49e61 --- /dev/null +++ b/cocos/scripting/lua-bindings/manual/navmesh/lua_cocos2dx_navmesh_manual.cpp @@ -0,0 +1,148 @@ +/**************************************************************************** + Copyright (c) 2014 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + 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" +#if CC_USE_NAVMESH +#include "lua_cocos2dx_navmesh_manual.h" +#include "lua_cocos2dx_navmesh_auto.hpp" +#include "tolua_fix.h" +#include "LuaBasicConversions.h" +#include "CCLuaEngine.h" +#include "navmesh/CCNavMesh.h" + + +int lua_cocos2dx_navmesh_NavMeshAgent_move(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::NavMeshAgent* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"cc.NavMeshAgent",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::NavMeshAgent*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_navmesh_NavMeshAgent_move'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + cocos2d::Vec3 arg0; + + ok &= luaval_to_vec3(tolua_S, 2, &arg0, "cc.NavMeshAgent:move"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_navmesh_NavMeshAgent_move'", nullptr); + return 0; + } + cobj->move(arg0); + lua_settop(tolua_S, 1); + return 1; + } + if (argc == 2) + { + cocos2d::Vec3 arg0; + LUA_FUNCTION handler; + + ok &= luaval_to_vec3(tolua_S, 2, &arg0, "cc.NavMeshAgent:move"); + +#if COCOS2D_DEBUG >= 1 + if (!toluafix_isfunction(tolua_S,3,"LUA_FUNCTION",0,&tolua_err)) { + goto tolua_lerror; + } +#endif + handler = toluafix_ref_function(tolua_S, 3, 0); + + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_navmesh_NavMeshAgent_move'", nullptr); + return 0; + } + cobj->move(arg0, [=](cocos2d::NavMeshAgent *agent, float totalTimeAfterMove){ + object_to_luaval(tolua_S, "cc.NavMeshAgent",(cocos2d::NavMeshAgent*)agent); + tolua_pushnumber(tolua_S, (lua_Number)totalTimeAfterMove); + LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 2); + }); + ScriptHandlerMgr::getInstance()->addCustomHandler((void*)cobj, handler); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.NavMeshAgent:move",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_navmesh_NavMeshAgent_move'.",&tolua_err); +#endif + + return 0; +} + + +static void extendNavMeshAgent(lua_State* L) +{ + lua_pushstring(L, "cc.NavMeshAgent"); + lua_rawget(L, LUA_REGISTRYINDEX); + if (lua_istable(L,-1)) + { + tolua_function(L, "move", lua_cocos2dx_navmesh_NavMeshAgent_move); + } + lua_pop(L, 1); +} + +static int register_all_navmesh_manual(lua_State* L) +{ + if (nullptr == L) + return 0; + + extendNavMeshAgent(L); + + return 1; +} + +int register_navmesh_module(lua_State* L) +{ + lua_getglobal(L, "_G"); + if (lua_istable(L,-1))//stack:...,_G, + { + register_all_cocos2dx_navmesh(L); + register_all_navmesh_manual(L); + } + lua_pop(L, 1); + return 1; +} + +#endif \ No newline at end of file diff --git a/cocos/scripting/lua-bindings/manual/navmesh/lua_cocos2dx_navmesh_manual.h b/cocos/scripting/lua-bindings/manual/navmesh/lua_cocos2dx_navmesh_manual.h new file mode 100644 index 0000000000..0eac75bba7 --- /dev/null +++ b/cocos/scripting/lua-bindings/manual/navmesh/lua_cocos2dx_navmesh_manual.h @@ -0,0 +1,57 @@ +/**************************************************************************** + Copyright (c) 2014 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + 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. + ****************************************************************************/ +#ifndef COCOS_SCRIPTING_LUA_BINDINGS_MANUAL_PHYSICS3D_LUA_COCOS2DX_NAVMESH_MANUAL_H__ +#define COCOS_SCRIPTING_LUA_BINDINGS_MANUAL_PHYSICS3D_LUA_COCOS2DX_NAVMESH_MANUAL_H__ + +#if CC_USE_NAVMESH + +#ifdef __cplusplus +extern "C" { +#endif +#include "tolua++.h" +#ifdef __cplusplus +} +#endif + + +/** + * @addtogroup lua + * @{ + */ + +/** + * Call this function can import the lua bindings for the navmesh module. + * After registering, we could call the related navmesh code conveniently in the lua. + * If you don't want to use the navmesh module in the lua, you only don't call this registering function. + * If you don't register the navmesh module, the package size would become smaller . + * The current mechanism,this function is called in the lua_module_register.h + */ + +TOLUA_API int register_navmesh_module(lua_State* L); + +// end group +/// @} + +#endif // #if CC_USE_NAVMESH +#endif // #ifndef COCOS_SCRIPTING_LUA_BINDINGS_MANUAL_PHYSICS3D_LUA_COCOS2DX_NAVMESH_MANUAL_H__ diff --git a/cocos/scripting/lua-bindings/proj.android/Android.mk b/cocos/scripting/lua-bindings/proj.android/Android.mk index a0ab181509..8b6f7e02b1 100644 --- a/cocos/scripting/lua-bindings/proj.android/Android.mk +++ b/cocos/scripting/lua-bindings/proj.android/Android.mk @@ -120,6 +120,11 @@ LOCAL_SRC_FILES += ../manual/extension/lua_cocos2dx_extension_manual.cpp \ LOCAL_SRC_FILES += ../manual/physics3d/lua_cocos2dx_physics3d_manual.cpp \ ../auto/lua_cocos2dx_physics3d_auto.cpp \ +#navmesh +LOCAL_SRC_FILES += ../manual/navmesh/lua_cocos2dx_navmesh_conversions.cpp \ + ../manual/navmesh/lua_cocos2dx_navmesh_manual.cpp \ + ../auto/lua_cocos2dx_navmesh_auto.cpp \ + LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../../external/lua/tolua \ $(LOCAL_PATH)/../../../../external/lua/luajit/include \ $(LOCAL_PATH)/../../../2d \ @@ -131,6 +136,7 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../../external/lua/tolua \ $(LOCAL_PATH)/../../../editor-support/spine \ $(LOCAL_PATH)/../../../ui \ $(LOCAL_PATH)/../../../physics3d \ + $(LOCAL_PATH)/../../../navmesh \ $(LOCAL_PATH)/../../../../extensions \ $(LOCAL_PATH)/../auto \ $(LOCAL_PATH)/../manual \ @@ -144,6 +150,7 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../../external/lua/tolua \ $(LOCAL_PATH)/../manual/cocosbuilder \ $(LOCAL_PATH)/../manual/spine \ $(LOCAL_PATH)/../manual/ui \ + $(LOCAL_PATH)/../manual/navmesh \ $(LOCAL_PATH)/../../../../external/xxtea \ $(LOCAL_PATH)/../../../.. \ $(LOCAL_PATH)/../../../../external/lua @@ -162,6 +169,7 @@ LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../../../external/lua/tolua \ $(LOCAL_PATH)/../manual/spine \ $(LOCAL_PATH)/../manual/extension \ $(LOCAL_PATH)/../manual/ui \ + $(LOCAL_PATH)/../manual/navmesh \ $(LOCAL_PATH)/../../../.. LOCAL_WHOLE_STATIC_LIBRARIES := cocos2d_lua_android_static diff --git a/cocos/scripting/lua-bindings/proj.ios_mac/cocos2d_lua_bindings.xcodeproj/project.pbxproj b/cocos/scripting/lua-bindings/proj.ios_mac/cocos2d_lua_bindings.xcodeproj/project.pbxproj index 585030e6b9..d1009dc4f3 100644 --- a/cocos/scripting/lua-bindings/proj.ios_mac/cocos2d_lua_bindings.xcodeproj/project.pbxproj +++ b/cocos/scripting/lua-bindings/proj.ios_mac/cocos2d_lua_bindings.xcodeproj/project.pbxproj @@ -11,6 +11,18 @@ 150906F119D556C8002C4D97 /* lua_cocos2dx_audioengine_auto.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 3E2BDB0419C5E5FE0055CDCD /* lua_cocos2dx_audioengine_auto.hpp */; }; 150906F219D556CE002C4D97 /* lua_cocos2dx_audioengine_manual.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3E2BDB0819C5E6100055CDCD /* lua_cocos2dx_audioengine_manual.cpp */; }; 150906F319D556D1002C4D97 /* lua_cocos2dx_audioengine_manual.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E2BDB0919C5E6100055CDCD /* lua_cocos2dx_audioengine_manual.h */; }; + 150983D01B1C0554007F3818 /* lua_cocos2dx_navmesh_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 150983CE1B1C0554007F3818 /* lua_cocos2dx_navmesh_auto.cpp */; }; + 150983D11B1C0554007F3818 /* lua_cocos2dx_navmesh_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 150983CE1B1C0554007F3818 /* lua_cocos2dx_navmesh_auto.cpp */; }; + 150983D21B1C0554007F3818 /* lua_cocos2dx_navmesh_auto.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 150983CF1B1C0554007F3818 /* lua_cocos2dx_navmesh_auto.hpp */; }; + 150983D31B1C0554007F3818 /* lua_cocos2dx_navmesh_auto.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 150983CF1B1C0554007F3818 /* lua_cocos2dx_navmesh_auto.hpp */; }; + 150983D71B1C3F3E007F3818 /* lua_cocos2dx_navmesh_manual.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 150983D51B1C3F3E007F3818 /* lua_cocos2dx_navmesh_manual.cpp */; }; + 150983D81B1C3F3E007F3818 /* lua_cocos2dx_navmesh_manual.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 150983D51B1C3F3E007F3818 /* lua_cocos2dx_navmesh_manual.cpp */; }; + 150983D91B1C3F3E007F3818 /* lua_cocos2dx_navmesh_manual.h in Headers */ = {isa = PBXBuildFile; fileRef = 150983D61B1C3F3E007F3818 /* lua_cocos2dx_navmesh_manual.h */; }; + 150983DA1B1C3F3E007F3818 /* lua_cocos2dx_navmesh_manual.h in Headers */ = {isa = PBXBuildFile; fileRef = 150983D61B1C3F3E007F3818 /* lua_cocos2dx_navmesh_manual.h */; }; + 150983DD1B1C4860007F3818 /* lua_cocos2dx_navmesh_conversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 150983DB1B1C4860007F3818 /* lua_cocos2dx_navmesh_conversions.cpp */; }; + 150983DE1B1C4860007F3818 /* lua_cocos2dx_navmesh_conversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 150983DB1B1C4860007F3818 /* lua_cocos2dx_navmesh_conversions.cpp */; }; + 150983DF1B1C4860007F3818 /* lua_cocos2dx_navmesh_conversions.h in Headers */ = {isa = PBXBuildFile; fileRef = 150983DC1B1C4860007F3818 /* lua_cocos2dx_navmesh_conversions.h */; }; + 150983E01B1C4860007F3818 /* lua_cocos2dx_navmesh_conversions.h in Headers */ = {isa = PBXBuildFile; fileRef = 150983DC1B1C4860007F3818 /* lua_cocos2dx_navmesh_conversions.h */; }; 15415A7019A71768004F1E71 /* lua_cocos2dx_extension_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AACE74C18BC45C200215002 /* lua_cocos2dx_extension_auto.cpp */; }; 15415A7119A71782004F1E71 /* lua_cocos2dx_extension_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AACE74C18BC45C200215002 /* lua_cocos2dx_extension_auto.cpp */; }; 15415A7219A718FB004F1E71 /* lua_cocos2dx_3d_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1516227F19A0F3E3006099B8 /* lua_cocos2dx_3d_auto.cpp */; }; @@ -278,6 +290,12 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 150983CE1B1C0554007F3818 /* lua_cocos2dx_navmesh_auto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lua_cocos2dx_navmesh_auto.cpp; sourceTree = ""; }; + 150983CF1B1C0554007F3818 /* lua_cocos2dx_navmesh_auto.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = lua_cocos2dx_navmesh_auto.hpp; sourceTree = ""; }; + 150983D51B1C3F3E007F3818 /* lua_cocos2dx_navmesh_manual.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = lua_cocos2dx_navmesh_manual.cpp; path = navmesh/lua_cocos2dx_navmesh_manual.cpp; sourceTree = ""; }; + 150983D61B1C3F3E007F3818 /* lua_cocos2dx_navmesh_manual.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = lua_cocos2dx_navmesh_manual.h; path = navmesh/lua_cocos2dx_navmesh_manual.h; sourceTree = ""; }; + 150983DB1B1C4860007F3818 /* lua_cocos2dx_navmesh_conversions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = lua_cocos2dx_navmesh_conversions.cpp; path = navmesh/lua_cocos2dx_navmesh_conversions.cpp; sourceTree = ""; }; + 150983DC1B1C4860007F3818 /* lua_cocos2dx_navmesh_conversions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = lua_cocos2dx_navmesh_conversions.h; path = navmesh/lua_cocos2dx_navmesh_conversions.h; sourceTree = ""; }; 1516227F19A0F3E3006099B8 /* lua_cocos2dx_3d_auto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lua_cocos2dx_3d_auto.cpp; sourceTree = ""; }; 1516228019A0F3E3006099B8 /* lua_cocos2dx_3d_auto.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = lua_cocos2dx_3d_auto.hpp; sourceTree = ""; }; 1540AF55193EC30500717D8E /* xxtea.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = xxtea.cpp; sourceTree = ""; }; @@ -448,6 +466,17 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 150983D41B1C3F2D007F3818 /* navmesh */ = { + isa = PBXGroup; + children = ( + 150983DB1B1C4860007F3818 /* lua_cocos2dx_navmesh_conversions.cpp */, + 150983DC1B1C4860007F3818 /* lua_cocos2dx_navmesh_conversions.h */, + 150983D51B1C3F3E007F3818 /* lua_cocos2dx_navmesh_manual.cpp */, + 150983D61B1C3F3E007F3818 /* lua_cocos2dx_navmesh_manual.h */, + ); + name = navmesh; + sourceTree = ""; + }; 1540AF54193EC30500717D8E /* xxtea */ = { isa = PBXGroup; children = ( @@ -593,6 +622,8 @@ 1AACE74818BC45C200215002 /* auto */ = { isa = PBXGroup; children = ( + 150983CE1B1C0554007F3818 /* lua_cocos2dx_navmesh_auto.cpp */, + 150983CF1B1C0554007F3818 /* lua_cocos2dx_navmesh_auto.hpp */, 15A561E31B00A09A005D4720 /* lua_cocos2dx_physics3d_auto.cpp */, 15A561E41B00A09A005D4720 /* lua_cocos2dx_physics3d_auto.hpp */, 15C9A10C1AE4972500C15443 /* lua_cocos2dx_experimental_webview_auto.cpp */, @@ -631,6 +662,7 @@ 1AACE75B18BC45C200215002 /* manual */ = { isa = PBXGroup; children = ( + 150983D41B1C3F2D007F3818 /* navmesh */, 15A561E91B00A3D0005D4720 /* physics3d */, 3E2BDB0719C5E6100055CDCD /* audioengine */, 158C128419A0FA1300781A76 /* 3d */, @@ -839,8 +871,10 @@ 15C1C2ED19874CBE00A46ACC /* CCLuaObjcBridge.h in Headers */, 15C1C2EE19874CBE00A46ACC /* tolua_fix.h in Headers */, 155C7E2019A71CCC00F08B25 /* LuaSkeletonAnimation.h in Headers */, + 150983D91B1C3F3E007F3818 /* lua_cocos2dx_navmesh_manual.h in Headers */, 1595523C1A25E1C5001E9FC9 /* lua_cocos2dx_csloader_auto.hpp in Headers */, 15415AB719A71A53004F1E71 /* io.h in Headers */, + 150983DF1B1C4860007F3818 /* lua_cocos2dx_navmesh_conversions.h in Headers */, 566F016119B5EB0F00FCA620 /* CustomGUIReader.h in Headers */, 15C1C2DC19874B4400A46ACC /* xxtea.h in Headers */, 15415AD319A71A53004F1E71 /* timeout.h in Headers */, @@ -852,6 +886,7 @@ 15C1C2D8198749BC00A46ACC /* lua_cocos2dx_manual.hpp in Headers */, 155C7E0819A71C7B00F08B25 /* lua_cocos2dx_extension_manual.h in Headers */, 155C7E1819A71CB300F08B25 /* lua_xml_http_request.h in Headers */, + 150983D21B1C0554007F3818 /* lua_cocos2dx_navmesh_auto.hpp in Headers */, 155C7DFC19A71C5300F08B25 /* lua_cocos2dx_coco_studio_manual.hpp in Headers */, 15C1C2D9198749BC00A46ACC /* lua_cocos2dx_physics_manual.hpp in Headers */, 15C1C2DA198749BC00A46ACC /* LuaScriptHandlerMgr.h in Headers */, @@ -869,6 +904,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + 150983E01B1C4860007F3818 /* lua_cocos2dx_navmesh_conversions.h in Headers */, 15EFA64D198B3342000C57D3 /* lauxlib.h in Headers */, 15415AA819A71A53004F1E71 /* auxiliar.h in Headers */, 155C7E1119A71C9F00F08B25 /* lua_extensions.h in Headers */, @@ -904,6 +940,7 @@ 155C7E0D19A71C9300F08B25 /* lua_cocos2dx_network_manual.h in Headers */, 15EFA63F198B32BB000C57D3 /* Cocos2dxLuaLoader.h in Headers */, 15EFA640198B32BB000C57D3 /* LuaBasicConversions.h in Headers */, + 150983D31B1C0554007F3818 /* lua_cocos2dx_navmesh_auto.hpp in Headers */, 15415AB419A71A53004F1E71 /* inet.h in Headers */, 15EFA641198B32BB000C57D3 /* CCLuaObjcBridge.h in Headers */, 15EFA642198B32BB000C57D3 /* tolua_fix.h in Headers */, @@ -919,6 +956,7 @@ 15C9A1131AE4973400C15443 /* lua_cocos2dx_experimental_webview_manual.hpp in Headers */, 15EFA62E198B3220000C57D3 /* lua_cocos2dx_manual.hpp in Headers */, 15C9A10F1AE4972500C15443 /* lua_cocos2dx_experimental_webview_auto.hpp in Headers */, + 150983DA1B1C3F3E007F3818 /* lua_cocos2dx_navmesh_manual.h in Headers */, 15EFA62F198B3220000C57D3 /* lua_cocos2dx_physics_manual.hpp in Headers */, 155C7E0919A71C8500F08B25 /* lua_cocos2dx_extension_manual.h in Headers */, 155C7E1919A71CB500F08B25 /* lua_xml_http_request.h in Headers */, @@ -1009,6 +1047,7 @@ 15415A7319A718FB004F1E71 /* lua_cocos2dx_cocosbuilder_auto.cpp in Sources */, 150906F219D556CE002C4D97 /* lua_cocos2dx_audioengine_manual.cpp in Sources */, 15415A7519A718FB004F1E71 /* lua_cocos2dx_experimental_video_auto.cpp in Sources */, + 150983DD1B1C4860007F3818 /* lua_cocos2dx_navmesh_conversions.cpp in Sources */, 15B5754F1A6F4D1500041C20 /* lua-cocos-studio-conversions.cpp in Sources */, 15415A7619A718FB004F1E71 /* lua_cocos2dx_ui_auto.cpp in Sources */, 15415A7719A718FB004F1E71 /* lua_cocos2dx_spine_auto.cpp in Sources */, @@ -1020,6 +1059,7 @@ 15415ACD19A71A53004F1E71 /* tcp.c in Sources */, 15AC69DB1987710400D17520 /* tolua_map.c in Sources */, 15415AD519A71A53004F1E71 /* udp.c in Sources */, + 150983D01B1C0554007F3818 /* lua_cocos2dx_navmesh_auto.cpp in Sources */, 15415ADD19A71A53004F1E71 /* usocket.c in Sources */, 15AC69DC1987710400D17520 /* tolua_push.c in Sources */, 15AC69DD1987710400D17520 /* tolua_to.c in Sources */, @@ -1060,6 +1100,7 @@ 155C7E2219A71CD300F08B25 /* lua_cocos2dx_experimental_video_manual.cpp in Sources */, 155C7DFA19A71C4C00F08B25 /* lua_cocos2dx_coco_studio_manual.cpp in Sources */, 155C7E2619A71CDD00F08B25 /* lua_cocos2dx_ui_manual.cpp in Sources */, + 150983D71B1C3F3E007F3818 /* lua_cocos2dx_navmesh_manual.cpp in Sources */, 15415A7019A71768004F1E71 /* lua_cocos2dx_extension_auto.cpp in Sources */, 155C7DF619A71C3E00F08B25 /* lua_cocos2dx_cocosdenshion_manual.cpp in Sources */, 15415AA519A71A53004F1E71 /* auxiliar.c in Sources */, @@ -1094,12 +1135,14 @@ 15415AC219A71A53004F1E71 /* options.c in Sources */, 15EFA645198B32DB000C57D3 /* xxtea.cpp in Sources */, 15EFA632198B328B000C57D3 /* CCLuaBridge.cpp in Sources */, + 150983D11B1C0554007F3818 /* lua_cocos2dx_navmesh_auto.cpp in Sources */, 15EFA633198B328B000C57D3 /* CCLuaEngine.cpp in Sources */, 155C7DEE19A71BFC00F08B25 /* lua_cocos2dx_experimental_video_auto.cpp in Sources */, 15EFA634198B328B000C57D3 /* CCLuaStack.cpp in Sources */, 15EFA635198B328B000C57D3 /* CCLuaValue.cpp in Sources */, 15EFA636198B328B000C57D3 /* Cocos2dxLuaLoader.cpp in Sources */, 155C7DEB19A71BE900F08B25 /* lua_cocos2dx_cocosbuilder_auto.cpp in Sources */, + 150983DE1B1C4860007F3818 /* lua_cocos2dx_navmesh_conversions.cpp in Sources */, 15EFA637198B328B000C57D3 /* LuaBasicConversions.cpp in Sources */, 15EFA638198B328B000C57D3 /* CCLuaObjcBridge.mm in Sources */, 155C7E1719A71CAF00F08B25 /* lua_xml_http_request.cpp in Sources */, @@ -1137,6 +1180,7 @@ 15C9A10E1AE4972500C15443 /* lua_cocos2dx_experimental_webview_auto.cpp in Sources */, 15415AAA19A71A53004F1E71 /* buffer.c in Sources */, 155C7E2319A71CD500F08B25 /* lua_cocos2dx_experimental_video_manual.cpp in Sources */, + 150983D81B1C3F3E007F3818 /* lua_cocos2dx_navmesh_manual.cpp in Sources */, 155C7DFB19A71C4E00F08B25 /* lua_cocos2dx_coco_studio_manual.cpp in Sources */, 155C7E2719A71CDE00F08B25 /* lua_cocos2dx_ui_manual.cpp in Sources */, 15415AB619A71A53004F1E71 /* io.c in Sources */, @@ -1192,7 +1236,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; SKIP_INSTALL = YES; - USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/../../../.. $(SRCROOT)/../../.. $(SRCROOT)/../../../base $(SRCROOT)/../../../3d $(SRCROOT)/../../../2d $(SRCROOT)/../../../deprecated $(SRCROOT)/../../../physics $(SRCROOT)/../../../math/kazmath $(SRCROOT)/../../../2d/platform $(SRCROOT)/../../../audio/include $(SRCROOT)/../../../editor-support $(SRCROOT)/../../../editor-support/spine $(SRCROOT)/../../../editor-support/cocostudio $(SRCROOT)/../../../editor-support/cocosbuilder $(SRCROOT)/../../../ui $(SRCROOT)/../../../storage $(SRCROOT)/../../../../extensions $(SRCROOT)/../../../../external $(SRCROOT)/../../../../external/chipmunk/include/chipmunk $(SRCROOT)/../../../../external/lua $(SRCROOT)/../../../../external/lua/luajit/include $(SRCROOT)/../../../../external/lua/tolua $(SRCROOT)/../../../editor-support/cocostudio/ActionTimeline $(SRCROOT)/../../../physics3d"; + USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/../../../.. $(SRCROOT)/../../.. $(SRCROOT)/../../../base $(SRCROOT)/../../../3d $(SRCROOT)/../../../2d $(SRCROOT)/../../../deprecated $(SRCROOT)/../../../physics $(SRCROOT)/../../../math/kazmath $(SRCROOT)/../../../2d/platform $(SRCROOT)/../../../audio/include $(SRCROOT)/../../../editor-support $(SRCROOT)/../../../editor-support/spine $(SRCROOT)/../../../editor-support/cocostudio $(SRCROOT)/../../../editor-support/cocosbuilder $(SRCROOT)/../../../ui $(SRCROOT)/../../../storage $(SRCROOT)/../../../../extensions $(SRCROOT)/../../../../external $(SRCROOT)/../../../../external/chipmunk/include/chipmunk $(SRCROOT)/../../../../external/lua $(SRCROOT)/../../../../external/lua/luajit/include $(SRCROOT)/../../../../external/lua/tolua $(SRCROOT)/../../../editor-support/cocostudio/ActionTimeline $(SRCROOT)/../../../physics3d $(SRCROOT)/../../../navmesh"; }; name = Debug; }; @@ -1226,7 +1270,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; SKIP_INSTALL = YES; - USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/../../../.. $(SRCROOT)/../../.. $(SRCROOT)/../../../base $(SRCROOT)/../../../3d $(SRCROOT)/../../../2d $(SRCROOT)/../../../deprecated $(SRCROOT)/../../../physics $(SRCROOT)/../../../math/kazmath $(SRCROOT)/../../../2d/platform $(SRCROOT)/../../../audio/include $(SRCROOT)/../../../editor-support $(SRCROOT)/../../../editor-support/spine $(SRCROOT)/../../../editor-support/cocostudio $(SRCROOT)/../../../editor-support/cocosbuilder $(SRCROOT)/../../../ui $(SRCROOT)/../../../storage $(SRCROOT)/../../../../extensions $(SRCROOT)/../../../../external $(SRCROOT)/../../../../external/chipmunk/include/chipmunk $(SRCROOT)/../../../../external/lua $(SRCROOT)/../../../../external/lua/luajit/include $(SRCROOT)/../../../../external/lua/tolua $(SRCROOT)/../../../editor-support/cocostudio/ActionTimeline $(SRCROOT)/../../../physics3d"; + USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/../../../.. $(SRCROOT)/../../.. $(SRCROOT)/../../../base $(SRCROOT)/../../../3d $(SRCROOT)/../../../2d $(SRCROOT)/../../../deprecated $(SRCROOT)/../../../physics $(SRCROOT)/../../../math/kazmath $(SRCROOT)/../../../2d/platform $(SRCROOT)/../../../audio/include $(SRCROOT)/../../../editor-support $(SRCROOT)/../../../editor-support/spine $(SRCROOT)/../../../editor-support/cocostudio $(SRCROOT)/../../../editor-support/cocosbuilder $(SRCROOT)/../../../ui $(SRCROOT)/../../../storage $(SRCROOT)/../../../../extensions $(SRCROOT)/../../../../external $(SRCROOT)/../../../../external/chipmunk/include/chipmunk $(SRCROOT)/../../../../external/lua $(SRCROOT)/../../../../external/lua/luajit/include $(SRCROOT)/../../../../external/lua/tolua $(SRCROOT)/../../../editor-support/cocostudio/ActionTimeline $(SRCROOT)/../../../physics3d $(SRCROOT)/../../../navmesh"; VALIDATE_PRODUCT = YES; }; name = Release; diff --git a/cocos/scripting/lua-bindings/proj.win32/libluacocos2d.vcxproj b/cocos/scripting/lua-bindings/proj.win32/libluacocos2d.vcxproj index b2999ebed5..26423fa7d1 100644 --- a/cocos/scripting/lua-bindings/proj.win32/libluacocos2d.vcxproj +++ b/cocos/scripting/lua-bindings/proj.win32/libluacocos2d.vcxproj @@ -41,6 +41,7 @@ + @@ -68,6 +69,8 @@ + + @@ -113,6 +116,7 @@ + @@ -140,6 +144,8 @@ + + @@ -273,7 +279,7 @@ Disabled - $(EngineRoot);$(EngineRoot)cocos\2d;$(EngineRoot)cocos\base;$(EngineRoot)cocos\3d;$(EngineRoot)cocos\physics3d;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos\ui;$(EngineRoot)external;$(EngineRoot)external\lua;$(EngineRoot)external\lua\tolua;$(EngineRoot)external\lua\luajit\include;$(EngineRoot)external\libwebsockets\win32\include;$(EngineRoot)extensions;$(EngineRoot)cocos\editor-support;$(EngineRoot)cocos\editor-support\cocostudio;$(EngineRoot)cocos\editor-support\cocostudio\ActionTimeline;$(EngineRoot)cocos\editor-support\spine;$(EngineRoot)cocos\editor-support\cocosbuilder;$(EngineRoot)cocos\scripting\lua-bindings\manual;$(EngineRoot)cocos\scripting\lua-bindings\auto;$(EngineRoot)cocos\scripting\lua-bindings\manual\extension;$(EngineRoot)cocos\scripting\lua-bindings\manual\cocostudio;$(EngineRoot)cocos\scripting\lua-bindings\manual\ui;$(EngineRoot)cocos\scripting\lua-bindings\manual\cocos2d;%(AdditionalIncludeDirectories) + $(EngineRoot);$(EngineRoot)cocos\2d;$(EngineRoot)cocos\base;$(EngineRoot)cocos\3d;$(EngineRoot)cocos\physics3d;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos\ui;$(EngineRoot)cocos\navmesh;$(EngineRoot)external;$(EngineRoot)external\lua;$(EngineRoot)external\lua\tolua;$(EngineRoot)external\lua\luajit\include;$(EngineRoot)external\libwebsockets\win32\include;$(EngineRoot)extensions;$(EngineRoot)cocos\editor-support;$(EngineRoot)cocos\editor-support\cocostudio;$(EngineRoot)cocos\editor-support\cocostudio\ActionTimeline;$(EngineRoot)cocos\editor-support\spine;$(EngineRoot)cocos\editor-support\cocosbuilder;$(EngineRoot)cocos\scripting\lua-bindings\manual;$(EngineRoot)cocos\scripting\lua-bindings\auto;$(EngineRoot)cocos\scripting\lua-bindings\manual\extension;$(EngineRoot)cocos\scripting\lua-bindings\manual\cocostudio;$(EngineRoot)cocos\scripting\lua-bindings\manual\ui;$(EngineRoot)cocos\scripting\lua-bindings\manual\cocos2d;$(EngineRoot)cocos\scripting\lua-bindings\manual\navmesh;%(AdditionalIncludeDirectories) WIN32;_WINDOWS;_DEBUG;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;CC_ENABLE_BULLET_INTEGRATION=1;%(PreprocessorDefinitions) false EnableFastChecks @@ -305,7 +311,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\lua\luajit\prebuilt\win32\*.*" "$ MinSpace true - $(EngineRoot);$(EngineRoot)cocos\base;$(EngineRoot)cocos;$(EngineRoot)external\lua\tolua;$(EngineRoot)external\lua\luajit\include;$(EngineRoot)external\lua;$(EngineRoot)cocos\scripting\lua-bindings\auto;$(EngineRoot)cocos\scripting\lua-bindings\manual;$(EngineRoot)cocos\2d;$(EngineRoot)cocos\3d;$(EngineRoot)cocos\scripting\lua-bindings\manual\extension;$(EngineRoot)cocos\scripting\lua-bindings\manual\cocostudio;$(EngineRoot)cocos\scripting\lua-bindings\manual\ui;$(EngineRoot)cocos\scripting\lua-bindings\manual\cocos2d;$(EngineRoot)extensions;$(EngineRoot)cocos\editor-support;$(EngineRoot)cocos\editor-support\cocostudio;$(EngineRoot)cocos\editor-support\cocostudio\ActionTimeline;$(EngineRoot)cocos\editor-support\spine;$(EngineRoot)cocos\editor-support\cocosbuilder;$(EngineRoot)cocos\audio\include;$(EngineRoot)external\libwebsockets\win32\include;$(EngineRoot)cocos\ui;$(EngineRoot)cocos\physics3d;$(EngineRoot)external;%(AdditionalIncludeDirectories) + $(EngineRoot);$(EngineRoot)cocos\base;$(EngineRoot)cocos;$(EngineRoot)external\lua\tolua;$(EngineRoot)external\lua\luajit\include;$(EngineRoot)external\lua;$(EngineRoot)cocos\scripting\lua-bindings\auto;$(EngineRoot)cocos\scripting\lua-bindings\manual;$(EngineRoot)cocos\2d;$(EngineRoot)cocos\3d;$(EngineRoot)cocos\scripting\lua-bindings\manual\extension;$(EngineRoot)cocos\scripting\lua-bindings\manual\cocostudio;$(EngineRoot)cocos\scripting\lua-bindings\manual\ui;$(EngineRoot)cocos\scripting\lua-bindings\manual\cocos2d;$(EngineRoot)cocos\scripting\lua-bindings\manual\navmesh;$(EngineRoot)extensions;$(EngineRoot)cocos\editor-support;$(EngineRoot)cocos\editor-support\cocostudio;$(EngineRoot)cocos\editor-support\cocostudio\ActionTimeline;$(EngineRoot)cocos\editor-support\spine;$(EngineRoot)cocos\editor-support\cocosbuilder;$(EngineRoot)cocos\audio\include;$(EngineRoot)external\libwebsockets\win32\include;$(EngineRoot)cocos\ui;$(EngineRoot)cocos\physics3d;$(EngineRoot)cocos\navmesh;$(EngineRoot)external;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;LIBLUA_EXPORTS;_CRT_SECURE_NO_WARNINGS;CC_ENABLE_BULLET_INTEGRATION=1;%(PreprocessorDefinitions) MultiThreadedDLL true diff --git a/cocos/scripting/lua-bindings/proj.win32/libluacocos2d.vcxproj.filters b/cocos/scripting/lua-bindings/proj.win32/libluacocos2d.vcxproj.filters index 6c4950e6bc..c996ce41aa 100644 --- a/cocos/scripting/lua-bindings/proj.win32/libluacocos2d.vcxproj.filters +++ b/cocos/scripting/lua-bindings/proj.win32/libluacocos2d.vcxproj.filters @@ -76,6 +76,9 @@ {3934b26e-18b0-465a-a89e-69a3417d107e} + + {fa8be49e-8b79-4dc5-8f28-febde1347eda} + @@ -282,6 +285,15 @@ manual\physics3d + + auto + + + manual\navmesh + + + manual\navmesh + @@ -494,6 +506,15 @@ manual\physics3d + + auto + + + manual\navmesh + + + manual\navmesh + diff --git a/tests/lua-tests/project/Classes/lua_module_register.h b/tests/lua-tests/project/Classes/lua_module_register.h index 446d0a0950..2b65b91fd7 100644 --- a/tests/lua-tests/project/Classes/lua_module_register.h +++ b/tests/lua-tests/project/Classes/lua_module_register.h @@ -11,6 +11,7 @@ #include "3d/lua_cocos2dx_3d_manual.h" #include "audioengine/lua_cocos2dx_audioengine_manual.h" #include "physics3d/lua_cocos2dx_physics3d_manual.h" +#include "navmesh/lua_cocos2dx_navmesh_manual.h" int lua_module_register(lua_State* L) @@ -28,6 +29,10 @@ int lua_module_register(lua_State* L) #if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION register_physics3d_module(L); #endif + +#if CC_USE_NAVMESH + register_navmesh_module(L); +#endif return 1; } diff --git a/tests/lua-tests/project/proj.win32/lua-tests.win32.vcxproj b/tests/lua-tests/project/proj.win32/lua-tests.win32.vcxproj index 054c4e89fa..f0a60ad7db 100644 --- a/tests/lua-tests/project/proj.win32/lua-tests.win32.vcxproj +++ b/tests/lua-tests/project/proj.win32/lua-tests.win32.vcxproj @@ -160,18 +160,25 @@ xcopy "$(OutDir)..\*.dll" "$(OutDir)" /D /Y - xcopy "$(ProjectDir)..\..\res" "$(OutDir)res" /D /E /I /F /Y -xcopy "$(ProjectDir)..\..\src" "$(OutDir)src" /D /E /I /F /Y -xcopy "$(ProjectDir)..\..\..\..\tests\cpp-tests\Resources" "$(OutDir)res" /D /E /I /F /Y -xcopy "$(ProjectDir)..\..\..\..\cocos\scripting\lua-bindings\script" "$(OutDir)src\cocos" /D /E /I /F /Y -xcopy "$(ProjectDir)..\..\..\..\external\lua\luasocket\script" "$(OutDir)script" /D /E /I /F /Y -xcopy "$(OutDir)..\*.dll" "$(OutDir)" /D /Y + + copy files + + xcopy "$(ProjectDir)..\..\res" "$(OutDir)res" /D /E /I /F /Y +xcopy "$(ProjectDir)..\..\src" "$(OutDir)src" /D /E /I /F /Y +xcopy "$(ProjectDir)..\..\..\..\tests\cpp-tests\Resources" "$(OutDir)res" /D /E /I /F /Y +xcopy "$(ProjectDir)..\..\..\..\cocos\scripting\lua-bindings\script" "$(OutDir)src\cocos" /D /E /I /F /Y +xcopy "$(ProjectDir)..\..\..\..\external\lua\luasocket\script" "$(OutDir)script" /D /E /I /F /Y +xcopy "$(OutDir)..\*.dll" "$(OutDir)" /D /Y + + + xxx.txt + diff --git a/tests/lua-tests/src/NavMeshTest/NavMeshTest.lua b/tests/lua-tests/src/NavMeshTest/NavMeshTest.lua new file mode 100644 index 0000000000..cd4fcb16ae --- /dev/null +++ b/tests/lua-tests/src/NavMeshTest/NavMeshTest.lua @@ -0,0 +1,465 @@ +local AgentUserData = +{ + time = 0 +} + +local function jump(v1, v2, height, t) + local out = {} + out.x = v1.x + t * (v2.x - v1.x) + out.y = v1.y + t * (v2.y - v1.y) + out.z = v1.z + t * (v2.z - v1.z) + out.y = out.y + height * math.sin(math.pi * t) + return out +end + +local actionManager = cc.Director:getInstance():getActionManager() + +---------------------------------------- +----NavMeshBaseTestDemo +---------------------------------------- +local NavMeshBaseTestDemo = class("NavMeshBaseTestDemo", function () + -- body + local layer = cc.Layer:create() + return layer +end) + +function NavMeshBaseTestDemo:ctor() + + Helper.initWithLayer(self) + Helper.titleLabel:setString(self:title()) + Helper.subtitleLabel:setString(self:subtitle()) + + local function onNodeEvent(event) + if "enter" == event then + self:onEnter() + elseif "exit" == event then + self:onExit() + end + end + + self:registerScriptHandler(onNodeEvent) +end + +function NavMeshBaseTestDemo:title() + return "Physics3D Test" +end + +function NavMeshBaseTestDemo:subtitle() + return "" +end + +function NavMeshBaseTestDemo:onEnter() + local scene = cc.Director:getInstance():getRunningScene() + if nil ~= scene then + self._angle = 0.0 + self._agents = {} + self._agentNode = nil + self._resumeFlag = false + local size = cc.Director:getInstance():getWinSize() + self._camera = cc.Camera:createPerspective(30.0, size.width / size.height, 1.0, 1000.0) + self._camera:setPosition3D(cc.vec3(0.0, 50.0, 100.0)) + self._camera:lookAt(cc.vec3(0.0, 0.0, 0.0), cc.vec3(0.0, 1.0, 0.0)) + self._camera:setCameraFlag(cc.CameraFlag.USER1) + self:addChild(self._camera) + + self:registerTouchEvent() + + self:initScene() + + self:scheduleUpdateWithPriorityLua(function(dt) + + if #self._agents == 0 then + return + end + + if not self._resumeFlag then + self._resumeFlag = true + actionManager:resumeTarget(self._agentNode) + end + + local currentVelocity = nil + local speed = 0 + for i = 1, #self._agents do + currentVelocity = self._agents[i][1]:getCurrentVelocity() + speed = math.sqrt(currentVelocity.x * currentVelocity.x + currentVelocity.y * currentVelocity.y + currentVelocity.z * currentVelocity.z) * 0.2 + if speed < 0 then + speed = 0.0 + end + self._agents[i][2]:setSpeed(speed) + end + end, 0) + + self:extend() + end +end + +function NavMeshBaseTestDemo:onExit() + self:unscheduleUpdate() +end + +function NavMeshBaseTestDemo:registerTouchEvent() + +end + +function NavMeshBaseTestDemo:extend() + +end + +function NavMeshBaseTestDemo:initScene() + local scene = cc.Director:getInstance():getRunningScene() + scene:getPhysics3DWorld():setDebugDrawEnable(false) + + local trianglesList = cc.Bundle3D:getTrianglesList("NavMesh/scene.obj") + + local rbDes = {} + rbDes.mass = 0.0 + rbDes.shape = cc.Physics3DShape:createMesh(trianglesList, math.floor(#trianglesList / 3)) + local rigidBody = cc.Physics3DRigidBody:create(rbDes) + local component = cc.Physics3DComponent:create(rigidBody) + local sprite = cc.Sprite3D:create("NavMesh/scene.obj") + sprite:addComponent(component) + sprite:setCameraMask(cc.CameraFlag.USER1) + self:addChild(sprite) + scene:setPhysics3DDebugCamera(self._camera) + + local navMesh = cc.NavMesh:create("NavMesh/all_tiles_tilecache.bin", "NavMesh/geomset.txt") + navMesh:setDebugDrawEnable(true) + scene:setNavMesh(navMesh) + scene:setNavMeshDebugCamera(self._camera) + + local ambientLight = cc.AmbientLight:create(cc.c3b(64, 64, 64)) + ambientLight:setCameraMask(cc.CameraFlag.USER1) + self:addChild(ambientLight) + + local dirLight = cc.DirectionLight:create(cc.vec3(1.2, -1.1, 0.5), cc.c3b(255, 255, 255)) + dirLight:setCameraMask(cc.CameraFlag.USER1) + self:addChild(dirLight) +end + +function NavMeshBaseTestDemo:createAgent(pos) + local filePath = "Sprite3DTest/girl.c3b" + + local navMeshAgentParam = {} + navMeshAgentParam.radius = 2.0 + navMeshAgentParam.height = 8.0 + navMeshAgentParam.maxSpeed = 8.0 + + local agent = cc.NavMeshAgent:create(navMeshAgentParam) + local agentNode = cc.Sprite3D:create(filePath) + agent:setOrientationRefAxes(cc.vec3(-1.0, 0.0, 1.0)) + agent.userdata = 0.0 + agentNode:setScale(0.05) + agentNode:addComponent(agent) + + local scene = cc.Director:getInstance():getRunningScene() + local node = cc.Node:create() + node:addChild(agentNode) + node:setPosition3D(pos) + node:setCameraMask(cc.CameraFlag.USER1) + scene:addChild(node) + + local animation = cc.Animation3D:create(filePath) + local animate = cc.Animate3D:create(animation) + if nil ~= animate then + agentNode:runAction(cc.RepeatForever:create(animate)) + animate:setSpeed(0.0) + end + + -- if nil == self._agentNode then + -- self._agentNode = agentNode + -- end + + self._agents[#self._agents + 1] = {agent, animate} +end + +function NavMeshBaseTestDemo:createObstacle(pos) + local scene = cc.Director:getInstance():getRunningScene() + local obstacle = cc.NavMeshObstacle:create(2.0, 8.0) + local obstacleNode = cc.Sprite3D:create("Sprite3DTest/cylinder.c3b") + obstacleNode:setPosition3D(cc.vec3(pos.x, pos.y -0.5, pos.z)) + obstacleNode:setRotation3D(cc.vec3(-90.0, 0.0, 0.0)) + obstacleNode:setScale(0.3) + obstacleNode:addComponent(obstacle) + obstacleNode:setCameraMask(cc.CameraFlag.USER1) + scene:addChild(obstacleNode) +end + +function NavMeshBaseTestDemo:moveAgents(des) + if #self._agents == 0 then + return + end + + local agent = nil + for i = 1, #self._agents do + self._agents[i][1]:move(des, function (agent, totalTimeAfterMove) + local data = agent.userdata + if agent:isOnOffMeshLink() then + agent:setAutoTraverseOffMeshLink(false) + agent:setAutoOrientation(false) + + local linkdata = agent:getCurrentOffMeshLinkData() + + agent:getOwner():setPosition3D(jump(linkdata.startPosition, linkdata.endPosition, 10.0, data)) + local dir = cc.vec3(linkdata.endPosition.x - linkdata.startPosition.x, linkdata.endPosition.y - linkdata.startPosition.y, linkdata.endPosition.z - linkdata.startPosition.z) + dir.y = 0.0 + dir = cc.vec3normalize(dir) + local axes = cc.vec3(0.0, 0.0, 0.0) + local refAxes = cc.vec3(-1.0, 0.0, 1.0) + refAxes = cc.vec3normalize(refAxes) + + axes = vec3_cross(refAxes, dir, axes) + + local angle = refAxes.x * dir.x + refAxes.y * dir.y + refAxes.z * dir.z + + local quaternion = cc.quaternion_createFromAxisAngle(axes, math.acos(angle)) + + agent:getOwner():setRotationQuat(quaternion) + agent.userdata = agent.userdata + 0.01 + if 1.0 < agent.userdata then + agent:completeOffMeshLink() + agent:setAutoOrientation(true) + agent.userdata = 0.0 + end + end + end) + end +end + + +---------------------------------------- +----NavMeshBaseTestDemo +---------------------------------------- + +local NavMeshBasicTestDemo = class("NavMeshBasicTestDemo", NavMeshBaseTestDemo) + +function NavMeshBasicTestDemo:title() + return "Navigation Mesh Test" +end + +function NavMeshBasicTestDemo:subtitle() + return "Basic Test" +end + +function NavMeshBasicTestDemo:registerTouchEvent() + local listener = cc.EventListenerTouchAllAtOnce:create() + listener:registerScriptHandler(function(touches, event) + self._needMoveAgents = true + end,cc.Handler.EVENT_TOUCHES_BEGAN) + + listener:registerScriptHandler(function(touches, event) + + if #touches > 0 and self._camera ~= nil then + local touch = touches[1] + local delta = touch:getDelta() + + self._angle = self._angle - delta.x * math.pi / 180.0 + self._camera:setPosition3D(cc.vec3(100.0 * math.sin(self._angle), 50.0, 100.0 * math.cos(self._angle))) + self._camera:lookAt(cc.vec3(0.0, 0.0, 0.0), cc.vec3(0.0, 1.0, 0.0)) + + if (delta.x * delta.x + delta.y * delta.y) > 16 then + self._needMoveAgents = false + end + end + end, cc.Handler.EVENT_TOUCHES_MOVED) + + listener:registerScriptHandler(function(touches, event) + if not self._needMoveAgents then + return + end + local physicsWorld = cc.Director:getInstance():getRunningScene():getPhysics3DWorld() + if #touches > 0 then + local touch = touches[1] + local location = touch:getLocationInView() + local nearP = cc.vec3(location.x, location.y, 0.0) + local farP = cc.vec3(location.x, location.y, 1.0) + + local size = cc.Director:getInstance():getWinSize() + nearP = self._camera:unproject(size, nearP, nearP) + farP = self._camera:unproject(size, farP, farP) + + local hitResult = {} + local ret = false + ret, hitResult = physicsWorld:rayCast(nearP, farP, hitResult) + self:moveAgents(hitResult.hitPosition) + end + end, cc.Handler.EVENT_TOUCHES_ENDED) + + local eventDispatcher = self:getEventDispatcher() + eventDispatcher:addEventListenerWithSceneGraphPriority(listener, self) +end + +function NavMeshBasicTestDemo:extend() + local ttfConfig = {} + ttfConfig.fontFilePath = "fonts/arial.ttf" + ttfConfig.fontSize = 15 + local debugLabel = cc.Label:createWithTTF(ttfConfig,"Debug Draw ON") + local menuItem = cc.MenuItemLabel:create(debugLabel) + menuItem:registerScriptTapHandler(function (tag, sender) + local scene = cc.Director:getInstance():getRunningScene() + local enabledDebug = not scene:getNavMesh():isDebugDrawEnabled() + scene:getNavMesh():setDebugDrawEnable(enabledDebug) + + if enabledDebug then + debugLabel:setString("DebugDraw ON") + else + debugLabel:setString("DebugDraw OFF") + end + end) + + menuItem:setAnchorPoint(cc.p(0.0, 1.0)) + menuItem:setPosition(cc.p(VisibleRect:left().x, VisibleRect:top().y - 100)) + local menu = cc.Menu:create(menuItem) + menu:setPosition(cc.p(0.0, 0.0)) + self:addChild(menu) + + local hitResult = {} + local ret = false + local physicsWorld = cc.Director:getInstance():getRunningScene():getPhysics3DWorld() + ret, hitResult = physicsWorld:rayCast(cc.vec3(0.0, 50.0, 0.0), cc.vec3(0.0, -50.0, 0.0), hitResult) + self:createAgent(hitResult.hitPosition) +end +---------------------------------------- +----NavMeshAdvanceTestDemo +---------------------------------------- + +local NavMeshAdvanceTestDemo = class("NavMeshAdvanceTestDemo", NavMeshBaseTestDemo) + +function NavMeshAdvanceTestDemo:title() + return "Navigation Mesh Test" +end + +function NavMeshAdvanceTestDemo:subtitle() + return "Advance Test" +end + +function NavMeshAdvanceTestDemo:registerTouchEvent() + local listener = cc.EventListenerTouchAllAtOnce:create() + listener:registerScriptHandler(function(touches, event) + self._needMoveAgents = true + end,cc.Handler.EVENT_TOUCHES_BEGAN) + + listener:registerScriptHandler(function(touches, event) + + if #touches > 0 and self._camera ~= nil then + local touch = touches[1] + local delta = touch:getDelta() + + self._angle = self._angle - delta.x * math.pi / 180.0 + self._camera:setPosition3D(cc.vec3(100.0 * math.sin(self._angle), 50.0, 100.0 * math.cos(self._angle))) + self._camera:lookAt(cc.vec3(0.0, 0.0, 0.0), cc.vec3(0.0, 1.0, 0.0)) + + if (delta.x * delta.x + delta.y * delta.y) > 16 then + self._needMoveAgents = false + end + end + end, cc.Handler.EVENT_TOUCHES_MOVED) + + listener:registerScriptHandler(function(touches, event) + if not self._needMoveAgents then + return + end + local physicsWorld = cc.Director:getInstance():getRunningScene():getPhysics3DWorld() + if #touches > 0 then + local touch = touches[1] + local location = touch:getLocationInView() + local nearP = cc.vec3(location.x, location.y, 0.0) + local farP = cc.vec3(location.x, location.y, 1.0) + + local size = cc.Director:getInstance():getWinSize() + nearP = self._camera:unproject(size, nearP, nearP) + farP = self._camera:unproject(size, farP, farP) + + local hitResult = {} + local ret = false + ret, hitResult = physicsWorld:rayCast(nearP, farP, hitResult) + self:moveAgents(hitResult.hitPosition) + end + end, cc.Handler.EVENT_TOUCHES_ENDED) + + local eventDispatcher = self:getEventDispatcher() + eventDispatcher:addEventListenerWithSceneGraphPriority(listener, self) +end + +function NavMeshAdvanceTestDemo:extend() + local ttfConfig = {} + ttfConfig.fontFilePath = "fonts/arial.ttf" + ttfConfig.fontSize = 15 + local obstacleLabel = cc.Label:createWithTTF(ttfConfig,"Create Obstacle") + local menuItem0 = cc.MenuItemLabel:create(obstacleLabel) + menuItem0:registerScriptTapHandler(function (tag, sender) + local scene = cc.Director:getInstance():getRunningScene() + local x = math.random(-50, 50) + print("x value is ", x) + local z = math.random(-50.0, 50.0) + print("z value is ", z) + + local hitResult = {} + local ret = false + ret, hitResult = scene:getPhysics3DWorld():rayCast(cc.vec3(x, 50.0, z), cc.vec3(x, -50.0, z), hitResult) + self:createObstacle(hitResult.hitPosition) + end) + menuItem0:setAnchorPoint(cc.p(0.0, 1.0)) + menuItem0:setPosition(cc.p(VisibleRect:left().x, VisibleRect:top().y - 50)) + + local agentLabel = cc.Label:createWithTTF(ttfConfig,"Create Agent") + local menuItem1 = cc.MenuItemLabel:create(agentLabel) + menuItem1:registerScriptTapHandler(function (tag, sender) + local scene = cc.Director:getInstance():getRunningScene() + local x = math.random(-50, 50) + local z = math.random(-50.0, 50.0) + + local hitResult = {} + local ret = false + ret, hitResult = scene:getPhysics3DWorld():rayCast(cc.vec3(x, 50.0, z), cc.vec3(x, -50.0, z), hitResult) + self:createAgent(hitResult.hitPosition) + end) + menuItem1:setAnchorPoint(cc.p(0.0, 1.0)) + menuItem1:setPosition(cc.p(VisibleRect:left().x, VisibleRect:top().y - 100)) + + local debugLabel = cc.Label:createWithTTF(ttfConfig,"Debug Draw ON") + local menuItem2 = cc.MenuItemLabel:create(debugLabel) + menuItem2:registerScriptTapHandler(function (tag, sender) + local scene = cc.Director:getInstance():getRunningScene() + local enabledDebug = not scene:getNavMesh():isDebugDrawEnabled() + scene:getNavMesh():setDebugDrawEnable(enabledDebug) + + if enabledDebug then + debugLabel:setString("DebugDraw ON") + else + debugLabel:setString("DebugDraw OFF") + end + end) + menuItem2:setAnchorPoint(cc.p(0.0, 1.0)) + menuItem2:setPosition(cc.p(VisibleRect:left().x, VisibleRect:top().y - 150)) + + local menu = cc.Menu:create(menuItem0, menuItem1, menuItem2) + menu:setPosition(cc.p(0.0, 0.0)) + self:addChild(menu) + + local hitResult = {} + local ret = false + local physicsWorld = cc.Director:getInstance():getRunningScene():getPhysics3DWorld() + ret,hitResult = physicsWorld:rayCast(cc.vec3(0.0, 50.0, 0.0), cc.vec3(0.0, -50.0, 0.0), hitResult) + + self:createAgent(hitResult.hitPosition) +end + +---------------------------------------- +----NavMeshTest +---------------------------------------- +function NavMeshTest() + Helper.usePhysics = true + + local scene = cc.Scene:createWithPhysics() + + Helper.createFunctionTable = + { + NavMeshBasicTestDemo.create, + NavMeshAdvanceTestDemo.create, + } + + scene:addChild(NavMeshBasicTestDemo.create()) + scene:addChild(CreateBackMenuItem()) + + return scene +end \ No newline at end of file diff --git a/tests/lua-tests/src/mainMenu.lua b/tests/lua-tests/src/mainMenu.lua index cf62be51d0..fa3e41e09f 100644 --- a/tests/lua-tests/src/mainMenu.lua +++ b/tests/lua-tests/src/mainMenu.lua @@ -63,6 +63,7 @@ require "SpritePolygonTest/SpritePolygonTest" require "Physics3DTest/Physics3DTest" require "Scene3DTest/Scene3DTest" require "MaterialSystemTest/MaterialSystemTest" +require "NavMeshTest/NavMeshTest" local LINE_SPACE = 40 @@ -115,6 +116,7 @@ local _allTests = { { isSupported = true, name = "MenuTest" , create_func = MenuTestMain }, { isSupported = true, name = "MotionStreakTest" , create_func = MotionStreakTest }, { isSupported = false, name = "MutiTouchTest" , create_func= MutiTouchTestMain }, + { isSupported = true, name = "NavMeshTest" , create_func = NavMeshTest }, { isSupported = true, name = "NewEventDispatcherTest" , create_func = NewEventDispatcherTest }, { isSupported = true, name = "NodeTest" , create_func = CocosNodeTest }, { isSupported = true, name = "OpenGLTest" , create_func= OpenGLTestMain }, @@ -216,6 +218,10 @@ function CreateTestMenu() testMenuItem:setEnabled(false) end + if obj.name == "NavMeshTest" and nil == cc.NavMesh then + testMenuItem:setEnabled(false) + end + testMenuItem:registerScriptTapHandler(menuCallback) testMenuItem:setPosition(cc.p(s.width / 2, (s.height - (index) * LINE_SPACE))) MainMenu:addChild(testMenuItem, index + 10000, index + 10000) diff --git a/tools/bindings-generator b/tools/bindings-generator index 3407739ca2..adcf841746 160000 --- a/tools/bindings-generator +++ b/tools/bindings-generator @@ -1 +1 @@ -Subproject commit 3407739ca2e73f380304e4d7b76ba0fc0127f6f7 +Subproject commit adcf8417464f2c5f9d73740fad334130ef874cfc diff --git a/tools/simulator/frameworks/runtime-src/Classes/lua_module_register.h b/tools/simulator/frameworks/runtime-src/Classes/lua_module_register.h index 253fffd927..8b11795f75 100755 --- a/tools/simulator/frameworks/runtime-src/Classes/lua_module_register.h +++ b/tools/simulator/frameworks/runtime-src/Classes/lua_module_register.h @@ -11,6 +11,7 @@ #include "3d/lua_cocos2dx_3d_manual.h" #include "audioengine/lua_cocos2dx_audioengine_manual.h" #include "physics3d/lua_cocos2dx_physics3d_manual.h" +#include "navmesh/lua_cocos2dx_navmesh_manual.h" static int lua_module_register(lua_State* L) { @@ -26,6 +27,9 @@ static int lua_module_register(lua_State* L) register_audioengine_module(L); #if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION register_physics3d_module(L); +#endif +#if CC_USE_NAVMESH + register_navmesh_module(L); #endif return 1; } diff --git a/tools/tolua/cocos2dx_3d.ini b/tools/tolua/cocos2dx_3d.ini index 95cb26d185..2c891f4b7b 100644 --- a/tools/tolua/cocos2dx_3d.ini +++ b/tools/tolua/cocos2dx_3d.ini @@ -42,7 +42,7 @@ skip = Mesh::[create getAABB getVertexBuffer hasVertexAttrib getSkin getMeshInde BillBoard::[draw], Sprite3DCache::[addSprite3DData getSpriteData], Terrain::[lookForIndicesLODSkrit lookForIndicesLOD insertIndicesLOD insertIndicesLODSkirt getIntersectionPoint getAABB getQuadTree create ^getHeight$], - Bundle3D::[calculateAABB loadMeshDatas getTrianglesList] + Bundle3D::[calculateAABB loadMeshDatas getTrianglesList loadObj] rename_functions = diff --git a/tools/tolua/cocos2dx_navmesh.ini b/tools/tolua/cocos2dx_navmesh.ini new file mode 100644 index 0000000000..8a27c81985 --- /dev/null +++ b/tools/tolua/cocos2dx_navmesh.ini @@ -0,0 +1,66 @@ +[cocos2dx_navmesh] +# the prefix to be added to the generated functions. You might or might not use this in your own +# templates +prefix = cocos2dx_navmesh + +# create a target namespace (in javascript, this would create some code like the equiv. to `ns = ns || {}`) +# all classes will be embedded in that namespace +target_namespace = cc + +macro_judgement = #if CC_USE_NAVMESH + +android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.8/include +android_flags = -D_SIZE_T_DEFINED_ + +clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include +clang_flags = -nostdinc -x c++ -std=c++11 -D CC_USE_NAVMESH + +win32_clang_flags = -U __SSE__ + +cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/platform/android -I%(cocosdir)s/external -I%(cocosdir)s/external/recast/Detour -I%(cocosdir)s/external/recast/DetourCrowd -I%(cocosdir)s/external/recast/DetourTileCache -I%(cocosdir)s/external/recast/DebugUtils -I%(cocosdir)s/external/recast/fastlz -I%(cocosdir)s/external/recast/Recast -I%(cocosdir)s/external/lua/luajit/include -I%(cocosdir)s/external/lua/tolua -I%(cocosdir)s/cocos/scripting/lua-bindings/manual + +cocos_flags = -DANDROID + +cxxgenerator_headers = + +# extra arguments for clang +extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s %(extra_flags)s + +# what headers to parse +headers = %(cocosdir)s/cocos/navmesh/CCNavMesh.h %(cocosdir)s/cocos/scripting/lua-bindings/manual/navmesh/lua_cocos2dx_navmesh_conversions.h + +# what classes to produce code for. You can use regular expressions here. When testing the regular +# expression, it will be enclosed in "^$", like this: "^Menu*$". +classes = NavMesh NavMeshAgent NavMeshObstacle + +# what should we skip? in the format ClassName::[function function] +# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also +# regular expressions, they will not be surrounded by "^$". If you want to skip a whole class, just +# add a single "*" as functions. See bellow for several examples. A special class name is "*", which +# will apply to all class names. This is a convenience wildcard to be able to skip similar named +# functions from all classes. + +skip = NavMesh::[findPath], + NavMeshObstacle::[setRadius setHeight], + NavMeshAgent::[move] + +rename_functions = + +rename_classes = + +# for all class names, should we remove something when registering in the target VM? +remove_prefix = + +# classes for which there will be no "parent" lookup +classes_have_no_parents = + +# base classes which will be skipped when their sub-classes found them. +base_classes_to_skip = + +# classes that create no constructor +# Set is special and we will use a hand-written constructor +abstract_classes = + +# Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'. +script_control_cpp = no + diff --git a/tools/tolua/genbindings.py b/tools/tolua/genbindings.py index da62efb385..b0ce3da8f9 100755 --- a/tools/tolua/genbindings.py +++ b/tools/tolua/genbindings.py @@ -134,21 +134,22 @@ def main(): output_dir = '%s/cocos/scripting/lua-bindings/auto' % project_root cmd_args = {'cocos2dx.ini' : ('cocos2d-x', 'lua_cocos2dx_auto'), \ - 'cocos2dx_extension.ini' : ('cocos2dx_extension', 'lua_cocos2dx_extension_auto'), \ - 'cocos2dx_ui.ini' : ('cocos2dx_ui', 'lua_cocos2dx_ui_auto'), \ - 'cocos2dx_studio.ini' : ('cocos2dx_studio', 'lua_cocos2dx_studio_auto'), \ - 'cocos2dx_spine.ini' : ('cocos2dx_spine', 'lua_cocos2dx_spine_auto'), \ - 'cocos2dx_physics.ini' : ('cocos2dx_physics', 'lua_cocos2dx_physics_auto'), \ - 'cocos2dx_experimental_video.ini' : ('cocos2dx_experimental_video', 'lua_cocos2dx_experimental_video_auto'), \ - 'cocos2dx_experimental.ini' : ('cocos2dx_experimental', 'lua_cocos2dx_experimental_auto'), \ - 'cocos2dx_controller.ini' : ('cocos2dx_controller', 'lua_cocos2dx_controller_auto'), \ - 'cocos2dx_cocosbuilder.ini': ('cocos2dx_cocosbuilder', 'lua_cocos2dx_cocosbuilder_auto'), \ - 'cocos2dx_cocosdenshion.ini': ('cocos2dx_cocosdenshion', 'lua_cocos2dx_cocosdenshion_auto'), \ - 'cocos2dx_3d.ini': ('cocos2dx_3d', 'lua_cocos2dx_3d_auto'), \ - 'cocos2dx_audioengine.ini': ('cocos2dx_audioengine', 'lua_cocos2dx_audioengine_auto'), \ - 'cocos2dx_csloader.ini' : ('cocos2dx_csloader', 'lua_cocos2dx_csloader_auto'), \ - 'cocos2dx_experimental_webview.ini' : ('cocos2dx_experimental_webview', 'lua_cocos2dx_experimental_webview_auto'), \ - 'cocos2dx_physics3d.ini' : ('cocos2dx_physics3d', 'lua_cocos2dx_physics3d_auto'), \ + # 'cocos2dx_extension.ini' : ('cocos2dx_extension', 'lua_cocos2dx_extension_auto'), \ + # 'cocos2dx_ui.ini' : ('cocos2dx_ui', 'lua_cocos2dx_ui_auto'), \ + # 'cocos2dx_studio.ini' : ('cocos2dx_studio', 'lua_cocos2dx_studio_auto'), \ + # 'cocos2dx_spine.ini' : ('cocos2dx_spine', 'lua_cocos2dx_spine_auto'), \ + # 'cocos2dx_physics.ini' : ('cocos2dx_physics', 'lua_cocos2dx_physics_auto'), \ + # 'cocos2dx_experimental_video.ini' : ('cocos2dx_experimental_video', 'lua_cocos2dx_experimental_video_auto'), \ + # 'cocos2dx_experimental.ini' : ('cocos2dx_experimental', 'lua_cocos2dx_experimental_auto'), \ + # 'cocos2dx_controller.ini' : ('cocos2dx_controller', 'lua_cocos2dx_controller_auto'), \ + # 'cocos2dx_cocosbuilder.ini': ('cocos2dx_cocosbuilder', 'lua_cocos2dx_cocosbuilder_auto'), \ + # 'cocos2dx_cocosdenshion.ini': ('cocos2dx_cocosdenshion', 'lua_cocos2dx_cocosdenshion_auto'), \ + # 'cocos2dx_3d.ini': ('cocos2dx_3d', 'lua_cocos2dx_3d_auto'), \ + # 'cocos2dx_audioengine.ini': ('cocos2dx_audioengine', 'lua_cocos2dx_audioengine_auto'), \ + # 'cocos2dx_csloader.ini' : ('cocos2dx_csloader', 'lua_cocos2dx_csloader_auto'), \ + # 'cocos2dx_experimental_webview.ini' : ('cocos2dx_experimental_webview', 'lua_cocos2dx_experimental_webview_auto'), \ + # 'cocos2dx_physics3d.ini' : ('cocos2dx_physics3d', 'lua_cocos2dx_physics3d_auto'), \ + 'cocos2dx_navmesh.ini' : ('cocos2dx_navmesh', 'lua_cocos2dx_navmesh_auto'), \ } target = 'lua' generator_py = '%s/generator.py' % cxx_generator_root From 0cccd6e7652c3f362802fe1cdd1cbe9fc8807592 Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Wed, 3 Jun 2015 18:12:21 +0800 Subject: [PATCH 2/4] Fix compile error on the Linux and update the test cases --- .../lua_cocos2dx_navmesh_conversions.cpp | 2 +- .../lua-tests/src/NavMeshTest/NavMeshTest.lua | 113 ++++++++---------- tests/lua-tests/src/helper.lua | 69 +++++++++++ 3 files changed, 120 insertions(+), 64 deletions(-) diff --git a/cocos/scripting/lua-bindings/manual/navmesh/lua_cocos2dx_navmesh_conversions.cpp b/cocos/scripting/lua-bindings/manual/navmesh/lua_cocos2dx_navmesh_conversions.cpp index 65a9288c5f..e8a1fb49dc 100644 --- a/cocos/scripting/lua-bindings/manual/navmesh/lua_cocos2dx_navmesh_conversions.cpp +++ b/cocos/scripting/lua-bindings/manual/navmesh/lua_cocos2dx_navmesh_conversions.cpp @@ -108,7 +108,7 @@ bool luaval_to_navmeshagentparam(lua_State* L, int lo, cocos2d::NavMeshAgentPara return false; } -bool luaval_to_offmeshlinkdata(lua_State* L, int lo, cocos2d::OffMeshLinkData* outValue , const char* funcName = "") +bool luaval_to_offmeshlinkdata(lua_State* L, int lo, cocos2d::OffMeshLinkData* outValue , const char* funcName) { if (nullptr == L || nullptr == outValue) return false; diff --git a/tests/lua-tests/src/NavMeshTest/NavMeshTest.lua b/tests/lua-tests/src/NavMeshTest/NavMeshTest.lua index cd4fcb16ae..a83a17397d 100644 --- a/tests/lua-tests/src/NavMeshTest/NavMeshTest.lua +++ b/tests/lua-tests/src/NavMeshTest/NavMeshTest.lua @@ -19,19 +19,21 @@ local actionManager = cc.Director:getInstance():getActionManager() ---------------------------------------- local NavMeshBaseTestDemo = class("NavMeshBaseTestDemo", function () -- body - local layer = cc.Layer:create() - return layer + local scene = cc.Scene:createWithPhysics() + return scene end) function NavMeshBaseTestDemo:ctor() - Helper.initWithLayer(self) - Helper.titleLabel:setString(self:title()) - Helper.subtitleLabel:setString(self:subtitle()) + TestCastScene.initWithLayer(self) + TestCastScene.titleLabel:setString(self:title()) + TestCastScene.subtitleLabel:setString(self:subtitle()) + + self:init() local function onNodeEvent(event) if "enter" == event then - self:onEnter() + -- self:onEnter() elseif "exit" == event then self:onExit() end @@ -48,49 +50,43 @@ function NavMeshBaseTestDemo:subtitle() return "" end -function NavMeshBaseTestDemo:onEnter() - local scene = cc.Director:getInstance():getRunningScene() - if nil ~= scene then - self._angle = 0.0 - self._agents = {} - self._agentNode = nil - self._resumeFlag = false - local size = cc.Director:getInstance():getWinSize() - self._camera = cc.Camera:createPerspective(30.0, size.width / size.height, 1.0, 1000.0) - self._camera:setPosition3D(cc.vec3(0.0, 50.0, 100.0)) - self._camera:lookAt(cc.vec3(0.0, 0.0, 0.0), cc.vec3(0.0, 1.0, 0.0)) - self._camera:setCameraFlag(cc.CameraFlag.USER1) - self:addChild(self._camera) +function NavMeshBaseTestDemo:init() + self._angle = 0.0 + self._agents = {} + local size = cc.Director:getInstance():getWinSize() + self._camera = cc.Camera:createPerspective(30.0, size.width / size.height, 1.0, 1000.0) + self._camera:setPosition3D(cc.vec3(0.0, 50.0, 100.0)) + self._camera:lookAt(cc.vec3(0.0, 0.0, 0.0), cc.vec3(0.0, 1.0, 0.0)) + self._camera:setCameraFlag(cc.CameraFlag.USER1) + self:addChild(self._camera) - self:registerTouchEvent() + self:registerTouchEvent() - self:initScene() + self:initScene() - self:scheduleUpdateWithPriorityLua(function(dt) + self:scheduleUpdateWithPriorityLua(function(dt) + if #self._agents == 0 then + return + end - if #self._agents == 0 then - return + if not self._resumeFlag and nil ~= self._agentNode then + self._resumeFlag = true + actionManager:resumeTarget(self._agentNode) + end + + local currentVelocity = nil + local speed = 0 + for i = 1, #self._agents do + currentVelocity = self._agents[i][1]:getCurrentVelocity() + speed = math.sqrt(currentVelocity.x * currentVelocity.x + currentVelocity.y * currentVelocity.y + currentVelocity.z * currentVelocity.z) * 0.2 + if speed < 0 then + speed = 0.0 end + self._agents[i][2]:setSpeed(speed) + end + end, 0) - if not self._resumeFlag then - self._resumeFlag = true - actionManager:resumeTarget(self._agentNode) - end - - local currentVelocity = nil - local speed = 0 - for i = 1, #self._agents do - currentVelocity = self._agents[i][1]:getCurrentVelocity() - speed = math.sqrt(currentVelocity.x * currentVelocity.x + currentVelocity.y * currentVelocity.y + currentVelocity.z * currentVelocity.z) * 0.2 - if speed < 0 then - speed = 0.0 - end - self._agents[i][2]:setSpeed(speed) - end - end, 0) - - self:extend() - end + self:extend() end function NavMeshBaseTestDemo:onExit() @@ -106,8 +102,7 @@ function NavMeshBaseTestDemo:extend() end function NavMeshBaseTestDemo:initScene() - local scene = cc.Director:getInstance():getRunningScene() - scene:getPhysics3DWorld():setDebugDrawEnable(false) + self:getPhysics3DWorld():setDebugDrawEnable(false) local trianglesList = cc.Bundle3D:getTrianglesList("NavMesh/scene.obj") @@ -120,12 +115,12 @@ function NavMeshBaseTestDemo:initScene() sprite:addComponent(component) sprite:setCameraMask(cc.CameraFlag.USER1) self:addChild(sprite) - scene:setPhysics3DDebugCamera(self._camera) + self:setPhysics3DDebugCamera(self._camera) local navMesh = cc.NavMesh:create("NavMesh/all_tiles_tilecache.bin", "NavMesh/geomset.txt") navMesh:setDebugDrawEnable(true) - scene:setNavMesh(navMesh) - scene:setNavMeshDebugCamera(self._camera) + self:setNavMesh(navMesh) + self:setNavMeshDebugCamera(self._camera) local ambientLight = cc.AmbientLight:create(cc.c3b(64, 64, 64)) ambientLight:setCameraMask(cc.CameraFlag.USER1) @@ -151,12 +146,11 @@ function NavMeshBaseTestDemo:createAgent(pos) agentNode:setScale(0.05) agentNode:addComponent(agent) - local scene = cc.Director:getInstance():getRunningScene() local node = cc.Node:create() node:addChild(agentNode) node:setPosition3D(pos) node:setCameraMask(cc.CameraFlag.USER1) - scene:addChild(node) + self:addChild(node) local animation = cc.Animation3D:create(filePath) local animate = cc.Animate3D:create(animation) @@ -165,15 +159,10 @@ function NavMeshBaseTestDemo:createAgent(pos) animate:setSpeed(0.0) end - -- if nil == self._agentNode then - -- self._agentNode = agentNode - -- end - self._agents[#self._agents + 1] = {agent, animate} end function NavMeshBaseTestDemo:createObstacle(pos) - local scene = cc.Director:getInstance():getRunningScene() local obstacle = cc.NavMeshObstacle:create(2.0, 8.0) local obstacleNode = cc.Sprite3D:create("Sprite3DTest/cylinder.c3b") obstacleNode:setPosition3D(cc.vec3(pos.x, pos.y -0.5, pos.z)) @@ -181,7 +170,7 @@ function NavMeshBaseTestDemo:createObstacle(pos) obstacleNode:setScale(0.3) obstacleNode:addComponent(obstacle) obstacleNode:setCameraMask(cc.CameraFlag.USER1) - scene:addChild(obstacleNode) + self:addChild(obstacleNode) end function NavMeshBaseTestDemo:moveAgents(des) @@ -266,7 +255,7 @@ function NavMeshBasicTestDemo:registerTouchEvent() if not self._needMoveAgents then return end - local physicsWorld = cc.Director:getInstance():getRunningScene():getPhysics3DWorld() + local physicsWorld = self:getPhysics3DWorld() if #touches > 0 then local touch = touches[1] local location = touch:getLocationInView() @@ -314,7 +303,7 @@ function NavMeshBasicTestDemo:extend() local hitResult = {} local ret = false - local physicsWorld = cc.Director:getInstance():getRunningScene():getPhysics3DWorld() + local physicsWorld = self:getPhysics3DWorld() ret, hitResult = physicsWorld:rayCast(cc.vec3(0.0, 50.0, 0.0), cc.vec3(0.0, -50.0, 0.0), hitResult) self:createAgent(hitResult.hitPosition) end @@ -358,7 +347,7 @@ function NavMeshAdvanceTestDemo:registerTouchEvent() if not self._needMoveAgents then return end - local physicsWorld = cc.Director:getInstance():getRunningScene():getPhysics3DWorld() + local physicsWorld = self:getPhysics3DWorld() if #touches > 0 then local touch = touches[1] local location = touch:getLocationInView() @@ -450,15 +439,13 @@ end function NavMeshTest() Helper.usePhysics = true - local scene = cc.Scene:createWithPhysics() - - Helper.createFunctionTable = + TestCastScene.createFunctionTable = { NavMeshBasicTestDemo.create, NavMeshAdvanceTestDemo.create, } - scene:addChild(NavMeshBasicTestDemo.create()) + local scene = NavMeshBasicTestDemo.create() scene:addChild(CreateBackMenuItem()) return scene diff --git a/tests/lua-tests/src/helper.lua b/tests/lua-tests/src/helper.lua index a3b95a2536..bf20656cf0 100644 --- a/tests/lua-tests/src/helper.lua +++ b/tests/lua-tests/src/helper.lua @@ -141,3 +141,72 @@ function createTestLayer(title, subtitle) Helper.subtitleLabel:setString(subTitleStr) return layer end + +TestCastScene = { + index = 1, + createFunctioinTable = nil, + titleLabel = nil, + subtitleLabel = nil +} + +function TestCastScene.nextAction() + TestCastScene.index = TestCastScene.index + 1 + if TestCastScene.index > table.getn(TestCastScene.createFunctionTable) then + TestCastScene.index = 1 + end + + return TestCastScene.newScene() +end + +function TestCastScene.backAction() + TestCastScene.index = TestCastScene.index - 1 + if TestCastScene.index == 0 then + TestCastScene.index = table.getn(TestCastScene.createFunctionTable) + end + + return TestCastScene.newScene() +end + +function TestCastScene.restartAction() + return TestCastScene.newScene() +end + +function TestCastScene.newScene() + local scene = TestCastScene.createFunctionTable[TestCastScene.index]() + scene:addChild(CreateBackMenuItem()) + cc.Director:getInstance():replaceScene(scene) +end + +function TestCastScene.initWithLayer(scene) + local size = cc.Director:getInstance():getWinSize() + TestCastScene.titleLabel = cc.Label:createWithTTF("", s_arialPath, 28) + TestCastScene.titleLabel:setAnchorPoint(cc.p(0.5, 0.5)) + scene:addChild(TestCastScene.titleLabel, 1) + TestCastScene.titleLabel:setPosition(size.width / 2, size.height - 50) + + TestCastScene.subtitleLabel = cc.Label:createWithTTF("", s_thonburiPath, 16) + TestCastScene.subtitleLabel:setAnchorPoint(cc.p(0.5, 0.5)) + scene:addChild(TestCastScene.subtitleLabel, 1) + TestCastScene.subtitleLabel:setPosition(size.width / 2, size.height - 80) + + -- menu + local item1 = cc.MenuItemImage:create(s_pPathB1, s_pPathB2) + local item2 = cc.MenuItemImage:create(s_pPathR1, s_pPathR2) + local item3 = cc.MenuItemImage:create(s_pPathF1, s_pPathF2) + item1:registerScriptTapHandler(TestCastScene.backAction) + item2:registerScriptTapHandler(TestCastScene.restartAction) + item3:registerScriptTapHandler(TestCastScene.nextAction) + + local menu = cc.Menu:create() + menu:addChild(item1) + menu:addChild(item2) + menu:addChild(item3) + menu:setPosition(cc.p(0, 0)) + item1:setPosition(cc.p(size.width / 2 - item2:getContentSize().width * 2, item2:getContentSize().height / 2)) + item2:setPosition(cc.p(size.width / 2, item2:getContentSize().height / 2)) + item3:setPosition(cc.p(size.width / 2 + item2:getContentSize().width * 2, item2:getContentSize().height / 2)) + scene:addChild(menu, 1) + + local background = cc.Layer:create() + scene:addChild(background, -10) +end From e20a35508a610acbc27ab2fb05c16ff12711d727 Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Tue, 16 Jun 2015 11:38:16 +0800 Subject: [PATCH 3/4] Update the bindings-generator --- tools/bindings-generator | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/bindings-generator b/tools/bindings-generator index adcf841746..b384d93865 160000 --- a/tools/bindings-generator +++ b/tools/bindings-generator @@ -1 +1 @@ -Subproject commit adcf8417464f2c5f9d73740fad334130ef874cfc +Subproject commit b384d93865d9a9499eed7f6f4b961a58c067fec0 From 2da760b6559ded9e0c6473cc7da2583c7a8fa108 Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Wed, 17 Jun 2015 09:49:31 +0800 Subject: [PATCH 4/4] Update the NavMesh test case --- .../lua-tests/src/NavMeshTest/NavMeshTest.lua | 25 ++++++---------- tools/tolua/genbindings.py | 30 +++++++++---------- 2 files changed, 24 insertions(+), 31 deletions(-) diff --git a/tests/lua-tests/src/NavMeshTest/NavMeshTest.lua b/tests/lua-tests/src/NavMeshTest/NavMeshTest.lua index a83a17397d..baa67b2b3b 100644 --- a/tests/lua-tests/src/NavMeshTest/NavMeshTest.lua +++ b/tests/lua-tests/src/NavMeshTest/NavMeshTest.lua @@ -33,7 +33,7 @@ function NavMeshBaseTestDemo:ctor() local function onNodeEvent(event) if "enter" == event then - -- self:onEnter() + self:onEnter() elseif "exit" == event then self:onExit() end @@ -89,6 +89,14 @@ function NavMeshBaseTestDemo:init() self:extend() end +function NavMeshBaseTestDemo:onEnter() + local hitResult = {} + local ret = false + local physicsWorld = self:getPhysics3DWorld() + ret, hitResult = physicsWorld:rayCast(cc.vec3(0.0, 50.0, 0.0), cc.vec3(0.0, -50.0, 0.0), hitResult) + self:createAgent(hitResult.hitPosition) +end + function NavMeshBaseTestDemo:onExit() self:unscheduleUpdate() end @@ -300,12 +308,6 @@ function NavMeshBasicTestDemo:extend() local menu = cc.Menu:create(menuItem) menu:setPosition(cc.p(0.0, 0.0)) self:addChild(menu) - - local hitResult = {} - local ret = false - local physicsWorld = self:getPhysics3DWorld() - ret, hitResult = physicsWorld:rayCast(cc.vec3(0.0, 50.0, 0.0), cc.vec3(0.0, -50.0, 0.0), hitResult) - self:createAgent(hitResult.hitPosition) end ---------------------------------------- ----NavMeshAdvanceTestDemo @@ -378,9 +380,7 @@ function NavMeshAdvanceTestDemo:extend() menuItem0:registerScriptTapHandler(function (tag, sender) local scene = cc.Director:getInstance():getRunningScene() local x = math.random(-50, 50) - print("x value is ", x) local z = math.random(-50.0, 50.0) - print("z value is ", z) local hitResult = {} local ret = false @@ -424,13 +424,6 @@ function NavMeshAdvanceTestDemo:extend() local menu = cc.Menu:create(menuItem0, menuItem1, menuItem2) menu:setPosition(cc.p(0.0, 0.0)) self:addChild(menu) - - local hitResult = {} - local ret = false - local physicsWorld = cc.Director:getInstance():getRunningScene():getPhysics3DWorld() - ret,hitResult = physicsWorld:rayCast(cc.vec3(0.0, 50.0, 0.0), cc.vec3(0.0, -50.0, 0.0), hitResult) - - self:createAgent(hitResult.hitPosition) end ---------------------------------------- diff --git a/tools/tolua/genbindings.py b/tools/tolua/genbindings.py index b0ce3da8f9..8cf9b50d8a 100755 --- a/tools/tolua/genbindings.py +++ b/tools/tolua/genbindings.py @@ -134,21 +134,21 @@ def main(): output_dir = '%s/cocos/scripting/lua-bindings/auto' % project_root cmd_args = {'cocos2dx.ini' : ('cocos2d-x', 'lua_cocos2dx_auto'), \ - # 'cocos2dx_extension.ini' : ('cocos2dx_extension', 'lua_cocos2dx_extension_auto'), \ - # 'cocos2dx_ui.ini' : ('cocos2dx_ui', 'lua_cocos2dx_ui_auto'), \ - # 'cocos2dx_studio.ini' : ('cocos2dx_studio', 'lua_cocos2dx_studio_auto'), \ - # 'cocos2dx_spine.ini' : ('cocos2dx_spine', 'lua_cocos2dx_spine_auto'), \ - # 'cocos2dx_physics.ini' : ('cocos2dx_physics', 'lua_cocos2dx_physics_auto'), \ - # 'cocos2dx_experimental_video.ini' : ('cocos2dx_experimental_video', 'lua_cocos2dx_experimental_video_auto'), \ - # 'cocos2dx_experimental.ini' : ('cocos2dx_experimental', 'lua_cocos2dx_experimental_auto'), \ - # 'cocos2dx_controller.ini' : ('cocos2dx_controller', 'lua_cocos2dx_controller_auto'), \ - # 'cocos2dx_cocosbuilder.ini': ('cocos2dx_cocosbuilder', 'lua_cocos2dx_cocosbuilder_auto'), \ - # 'cocos2dx_cocosdenshion.ini': ('cocos2dx_cocosdenshion', 'lua_cocos2dx_cocosdenshion_auto'), \ - # 'cocos2dx_3d.ini': ('cocos2dx_3d', 'lua_cocos2dx_3d_auto'), \ - # 'cocos2dx_audioengine.ini': ('cocos2dx_audioengine', 'lua_cocos2dx_audioengine_auto'), \ - # 'cocos2dx_csloader.ini' : ('cocos2dx_csloader', 'lua_cocos2dx_csloader_auto'), \ - # 'cocos2dx_experimental_webview.ini' : ('cocos2dx_experimental_webview', 'lua_cocos2dx_experimental_webview_auto'), \ - # 'cocos2dx_physics3d.ini' : ('cocos2dx_physics3d', 'lua_cocos2dx_physics3d_auto'), \ + 'cocos2dx_extension.ini' : ('cocos2dx_extension', 'lua_cocos2dx_extension_auto'), \ + 'cocos2dx_ui.ini' : ('cocos2dx_ui', 'lua_cocos2dx_ui_auto'), \ + 'cocos2dx_studio.ini' : ('cocos2dx_studio', 'lua_cocos2dx_studio_auto'), \ + 'cocos2dx_spine.ini' : ('cocos2dx_spine', 'lua_cocos2dx_spine_auto'), \ + 'cocos2dx_physics.ini' : ('cocos2dx_physics', 'lua_cocos2dx_physics_auto'), \ + 'cocos2dx_experimental_video.ini' : ('cocos2dx_experimental_video', 'lua_cocos2dx_experimental_video_auto'), \ + 'cocos2dx_experimental.ini' : ('cocos2dx_experimental', 'lua_cocos2dx_experimental_auto'), \ + 'cocos2dx_controller.ini' : ('cocos2dx_controller', 'lua_cocos2dx_controller_auto'), \ + 'cocos2dx_cocosbuilder.ini': ('cocos2dx_cocosbuilder', 'lua_cocos2dx_cocosbuilder_auto'), \ + 'cocos2dx_cocosdenshion.ini': ('cocos2dx_cocosdenshion', 'lua_cocos2dx_cocosdenshion_auto'), \ + 'cocos2dx_3d.ini': ('cocos2dx_3d', 'lua_cocos2dx_3d_auto'), \ + 'cocos2dx_audioengine.ini': ('cocos2dx_audioengine', 'lua_cocos2dx_audioengine_auto'), \ + 'cocos2dx_csloader.ini' : ('cocos2dx_csloader', 'lua_cocos2dx_csloader_auto'), \ + 'cocos2dx_experimental_webview.ini' : ('cocos2dx_experimental_webview', 'lua_cocos2dx_experimental_webview_auto'), \ + 'cocos2dx_physics3d.ini' : ('cocos2dx_physics3d', 'lua_cocos2dx_physics3d_auto'), \ 'cocos2dx_navmesh.ini' : ('cocos2dx_navmesh', 'lua_cocos2dx_navmesh_auto'), \ } target = 'lua'