mirror of https://github.com/axmolengine/axmol.git
add 3d test case(skybox and texture cube) for lua project
This commit is contained in:
parent
0587122ccc
commit
52280e6376
|
@ -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"
|
||||
|
|
|
@ -2871,6 +2871,174 @@ int lua_register_cocos2dx_3d_BillBoard(lua_State* tolua_S)
|
|||
g_typeCast["BillBoard"] = "cc.BillBoard";
|
||||
return 1;
|
||||
}
|
||||
|
||||
int lua_cocos2dx_3d_TextureCube_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.TextureCube", 0, &tolua_err)) goto tolua_lerror;
|
||||
#endif
|
||||
|
||||
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<cocos2d::TextureCube>(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<cocos2d::Skybox>(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<cocos2d::TextureCube>(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);
|
||||
|
@ -2885,6 +3053,8 @@ TOLUA_API int register_all_cocos2dx_3d(lua_State* 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;
|
||||
|
|
|
@ -919,6 +919,71 @@ 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()
|
||||
|
||||
|
@ -932,6 +997,7 @@ function Sprite3DTest()
|
|||
Sprite3DReskinTest.create,
|
||||
Sprite3DWithOBBPerfromanceTest.create,
|
||||
Sprite3DMirrorTest.create,
|
||||
Sprite3DCubeMap.create,
|
||||
}
|
||||
|
||||
scene:addChild(Sprite3DBasicTest.create())
|
||||
|
|
Loading…
Reference in New Issue