From 52280e637684627215eb7dc7031299a9bd4809c7 Mon Sep 17 00:00:00 2001 From: zhukaixy Date: Fri, 20 Mar 2015 17:53:05 +0800 Subject: [PATCH] add 3d test case(skybox and texture cube) for lua project --- cocos/cocos2d.h | 2 + .../auto/lua_cocos2dx_3d_auto.cpp | 218 ++++++++++++++++-- .../src/Sprite3DTest/Sprite3DTest.lua | 68 +++++- 3 files changed, 263 insertions(+), 25 deletions(-) diff --git a/cocos/cocos2d.h b/cocos/cocos2d.h index 4ce3defc65..48d53380df 100644 --- a/cocos/cocos2d.h +++ b/cocos/cocos2d.h @@ -285,6 +285,8 @@ THE SOFTWARE. #include "3d/CCBillBoard.h" #include "3d/CCFrustum.h" #include "3d/CCPlane.h" +#include "3d/CCTextureCube.h" +#include "3d/CCSkybox.h" // Deprecated include #include "deprecated/CCDictionary.h" diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_3d_auto.cpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_3d_auto.cpp index 9968e1800a..e500da44bb 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_3d_auto.cpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_3d_auto.cpp @@ -1293,14 +1293,14 @@ int lua_cocos2dx_3d_Sprite3D_createAsync(lua_State* tolua_S) if (!ok) { break; } std::function arg2; do { - // Lambda binding for lua is not supported. - assert(false); - } while(0) - ; + // Lambda binding for lua is not supported. + assert(false); + } while(0) + ; if (!ok) { break; } void* arg3; #pragma warning NO CONVERSION TO NATIVE FOR void* - ok = false; + ok = false; if (!ok) { break; } cocos2d::Sprite3D::createAsync(arg0, arg1, arg2, arg3); lua_settop(tolua_S, 1); @@ -1317,14 +1317,14 @@ int lua_cocos2dx_3d_Sprite3D_createAsync(lua_State* tolua_S) if (!ok) { break; } std::function arg1; do { - // Lambda binding for lua is not supported. - assert(false); - } while(0) - ; + // Lambda binding for lua is not supported. + assert(false); + } while(0) + ; if (!ok) { break; } void* arg2; #pragma warning NO CONVERSION TO NATIVE FOR void* - ok = false; + ok = false; if (!ok) { break; } cocos2d::Sprite3D::createAsync(arg0, arg1, arg2); lua_settop(tolua_S, 1); @@ -2871,22 +2871,192 @@ int lua_register_cocos2dx_3d_BillBoard(lua_State* tolua_S) g_typeCast["BillBoard"] = "cc.BillBoard"; return 1; } -TOLUA_API int register_all_cocos2dx_3d(lua_State* tolua_S) + +int lua_cocos2dx_3d_TextureCube_create(lua_State* tolua_S) { - tolua_open(tolua_S); - - tolua_module(tolua_S,"cc",0); - tolua_beginmodule(tolua_S,"cc"); + int argc = 0; + bool ok = true; +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif - lua_register_cocos2dx_3d_Animate3D(tolua_S); - lua_register_cocos2dx_3d_Sprite3D(tolua_S); - lua_register_cocos2dx_3d_AttachNode(tolua_S); - lua_register_cocos2dx_3d_BillBoard(tolua_S); - lua_register_cocos2dx_3d_Animation3D(tolua_S); - lua_register_cocos2dx_3d_Skeleton3D(tolua_S); - lua_register_cocos2dx_3d_Mesh(tolua_S); +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertable(tolua_S, 1, "cc.TextureCube", 0, &tolua_err)) goto tolua_lerror; +#endif - tolua_endmodule(tolua_S); - return 1; + argc = lua_gettop(tolua_S) - 1; + + do + { + if (argc == 6) + { + std::string positive_x; + ok &= luaval_to_std_string(tolua_S, 2, &positive_x, "cc.TextureCube:create"); + if (!ok) { break; } + + std::string negative_x; + ok &= luaval_to_std_string(tolua_S, 3, &negative_x, "cc.TextureCube:create"); + if (!ok){ break; } + + std::string positive_y; + ok &= luaval_to_std_string(tolua_S, 4, &positive_y, "cc.TextureCube:create"); + if (!ok) { break; } + + std::string negative_y; + ok &= luaval_to_std_string(tolua_S, 5, &negative_y, "cc.TextureCube:create"); + if (!ok){ break; } + + std::string positive_z; + ok &= luaval_to_std_string(tolua_S, 6, &positive_z, "cc.TextureCube:create"); + if (!ok) { break; } + + std::string negative_z; + ok &= luaval_to_std_string(tolua_S, 7, &negative_z, "cc.TextureCube:create"); + if (!ok){ break; } + + cocos2d::TextureCube* ret = cocos2d::TextureCube::create(positive_x, negative_x, + positive_y, negative_y, + positive_z, negative_z); + object_to_luaval(tolua_S, "cc.TextureCube", (cocos2d::TextureCube*)ret); + return 1; + } + } while (0); + + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d", "cc.TextureCube:create", argc, 6); + return 0; +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(tolua_S, "#ferror in function 'lua_cocos2dx_3d_TextureCube_create'.", &tolua_err); +#endif + return 0; +} + +int lua_register_cocos2dx_3d_TextureCube(lua_State* tolua_S) +{ + tolua_usertype(tolua_S, "cc.TextureCube"); + tolua_cclass(tolua_S, "TextureCube", "cc.TextureCube", "cc.Texture2D", nullptr); + + tolua_beginmodule(tolua_S, "TextureCube"); + tolua_function(tolua_S, "create", lua_cocos2dx_3d_TextureCube_create); + tolua_endmodule(tolua_S); + std::string typeName = typeid(cocos2d::TextureCube).name(); + g_luaType[typeName] = "cc.TextureCube"; + g_typeCast["TextureCube"] = "cc.TextureCube"; + return 1; +} + +int lua_cocos2dx_3d_Skybox_create(lua_State* tolua_S) +{ + int argc = 0; + bool ok = true; +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertable(tolua_S, 1, "cc.Skybox", 0, &tolua_err)) goto tolua_lerror; +#endif + + argc = lua_gettop(tolua_S) - 1; + + do + { + if (argc == 0) + { + cocos2d::Skybox* ret = cocos2d::Skybox::create(); + object_to_luaval(tolua_S, "cc.Skybox", (cocos2d::Skybox*)ret); + return 1; + } + } while (0); + + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d", "cc.Skybox:create", argc, 0); + return 0; +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(tolua_S, "#ferror in function 'lua_cocos2dx_3d_Skybox_create'.", &tolua_err); +#endif + return 0; +} + +int lua_cocos2dx_3d_Skybox_setTexture(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::Skybox* 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.Skybox", 0, &tolua_err)) goto tolua_lerror; +#endif + cobj = (cocos2d::Skybox*)tolua_tousertype(tolua_S, 1, 0); +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S, "invalid 'cobj' in function 'lua_cocos2dx_3d_Skybox_setTexture'", nullptr); + return 0; + } +#endif + argc = lua_gettop(tolua_S) - 1; + do{ + if (argc == 1) + { + cocos2d::TextureCube* arg0; + ok &= luaval_to_object(tolua_S, 2, "cc.TextureCube", &arg0); + + if (!ok) { break; } + cobj->setTexture(arg0); + lua_settop(tolua_S, 1); + return 1; + } + } while (0); + + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Skybox:setTexture", argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(tolua_S, "#ferror in function 'lua_cocos2dx_3d_Skybox_setTexture'.", &tolua_err); +#endif + + return 0; +} + +int lua_register_cocos2dx_3d_Skybox(lua_State* tolua_S) +{ + tolua_usertype(tolua_S, "cc.Skybox"); + tolua_cclass(tolua_S, "Skybox", "cc.Skybox", "cc.Node", nullptr); + + tolua_beginmodule(tolua_S, "Skybox"); + tolua_function(tolua_S, "create", lua_cocos2dx_3d_Skybox_create); + tolua_function(tolua_S, "setTexture", lua_cocos2dx_3d_Skybox_setTexture); + tolua_endmodule(tolua_S); + + std::string typeName = typeid(cocos2d::Skybox).name(); + g_luaType[typeName] = "cc.Skybox"; + g_typeCast["Skybox"] = "cc.Skybox"; + return 1; +} + +TOLUA_API int register_all_cocos2dx_3d(lua_State* tolua_S) +{ + tolua_open(tolua_S); + + tolua_module(tolua_S,"cc",0); + tolua_beginmodule(tolua_S,"cc"); + + lua_register_cocos2dx_3d_Animate3D(tolua_S); + lua_register_cocos2dx_3d_Sprite3D(tolua_S); + lua_register_cocos2dx_3d_AttachNode(tolua_S); + lua_register_cocos2dx_3d_BillBoard(tolua_S); + lua_register_cocos2dx_3d_Animation3D(tolua_S); + lua_register_cocos2dx_3d_Skeleton3D(tolua_S); + lua_register_cocos2dx_3d_Mesh(tolua_S); + lua_register_cocos2dx_3d_TextureCube(tolua_S); + lua_register_cocos2dx_3d_Skybox(tolua_S); + + tolua_endmodule(tolua_S); + return 1; } diff --git a/tests/lua-tests/src/Sprite3DTest/Sprite3DTest.lua b/tests/lua-tests/src/Sprite3DTest/Sprite3DTest.lua index bb95144f61..efdf34dbb4 100644 --- a/tests/lua-tests/src/Sprite3DTest/Sprite3DTest.lua +++ b/tests/lua-tests/src/Sprite3DTest/Sprite3DTest.lua @@ -919,10 +919,75 @@ function Sprite3DMirrorTest.create() return layer end + +---------------------------------------- +----Sprite3DCubeTexture +---------------------------------------- +local Sprite3DCubeMap = {} +Sprite3DCubeMap.__index = Sprite3DCubeMap + +function Sprite3DCubeMap.create() +local layer = cc.Layer:create() +Helper.initWithLayer(layer) +Helper.titleLabel:setString("Sprite3D CubeMap/Skybox Test") + +local visSize = cc.Director:getInstance():getVisibleSize() +local camera = cc.Camera:createPerspective(68, visSize.width / visSize.height, 0.1, 200) +camera:setCameraFlag(2) +layer:addChild(camera) + +local fileName = "Sprite3DTest/teapot.c3b" +local teapot = cc.Sprite3D:create(fileName) +teapot:setPosition3D({x = 0, y = -5, z = -20}) +teapot:setRotation3D({x = -90, y = 180, z = 0}) + +local texCube = cc.TextureCube:create("Sprite3DTest/skybox/left.jpg", "Sprite3DTest/skybox/right.jpg", + "Sprite3DTest/skybox/top.jpg", "Sprite3DTest/skybox/bottom.jpg", + "Sprite3DTest/skybox/front.jpg", "Sprite3DTest/skybox/back.jpg"); + +local program = cc.GLProgram:createWithFilenames("Sprite3DTest/cube_map.vert", "Sprite3DTest/cube_map.frag") +local state = cc.GLProgramState:create(program) + +attriNames = { + "a_position", "a_color", + "a_texCoord", "a_texCoord1", "a_texCoord2", "a_texCoord3", + "a_normal", "a_blendWeight", "a_blendIndex" + } + +--pass mesh's attribute to shader +local offset = 0 +local attributeCount = teapot:getMesh():getMeshVertexAttribCount() +for i = 0, attributeCount-1 do + local meshattribute = teapot:getMesh():getMeshVertexAttribute(i) + state:setVertexAttribPointer(attriNames[meshattribute.vertexAttrib+1], + meshattribute.size, + meshattribute.type, + false, + teapot:getMesh():getVertexSizeInBytes(), + offset); + offset = offset + meshattribute.attribSizeBytes +end + +state:setUniformTexture("u_cubeTex", texCube:getName()) + +teapot:setGLProgramState(state) +teapot:setCameraMask(2) + +local rotate_action = cc.RotateBy:create(1.5, { x = 0.0, y = 30.0, z = 0.0}) +teapot:runAction(cc.RepeatForever:create(rotate_action)); +layer:addChild(teapot) + +local skybox = cc.Skybox:create() +skybox:setTexture(texCube) +layer:addChild(skybox) + +return layer +end + function Sprite3DTest() local scene = cc.Scene:create() - Helper.createFunctionTable = + Helper.createFunctionTable = { Sprite3DBasicTest.create, Sprite3DHitTest.create, @@ -932,6 +997,7 @@ function Sprite3DTest() Sprite3DReskinTest.create, Sprite3DWithOBBPerfromanceTest.create, Sprite3DMirrorTest.create, + Sprite3DCubeMap.create, } scene:addChild(Sprite3DBasicTest.create())