mirror of https://github.com/axmolengine/axmol.git
Update Sprite3DCubeMap test case
This commit is contained in:
parent
f54512a618
commit
921981833e
|
@ -2056,6 +2056,47 @@ bool luaval_to_quaternion(lua_State* L,int lo,cocos2d::Quaternion* outValue, con
|
|||
return ok;
|
||||
}
|
||||
|
||||
bool luaval_to_texparams(lua_State* L,int lo,cocos2d::Texture2D::TexParams* 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, "minFilter");
|
||||
lua_gettable(L, lo);
|
||||
outValue->minFilter = lua_isnil(L, -1) ? 0 : lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_pushstring(L, "magFilter");
|
||||
lua_gettable(L, lo);
|
||||
outValue->magFilter = lua_isnil(L, -1) ? 0 : lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_pushstring(L, "wrapS");
|
||||
lua_gettable(L, lo);
|
||||
outValue->wrapS = lua_isnil(L, -1) ? 0 : lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_pushstring(L, "wrapT");
|
||||
lua_gettable(L, lo);
|
||||
outValue->wrapT = lua_isnil(L, -1) ? 0 : lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
void vec2_array_to_luaval(lua_State* L,const cocos2d::Vec2* points, int count)
|
||||
{
|
||||
if (NULL == L)
|
||||
|
@ -3020,3 +3061,24 @@ void quaternion_to_luaval(lua_State* L,const cocos2d::Quaternion& inValue)
|
|||
lua_pushnumber(L, (lua_Number) inValue.w); /* L: table key value*/
|
||||
lua_rawset(L, -3);
|
||||
}
|
||||
|
||||
void texParams_to_luaval(lua_State* L, const cocos2d::Texture2D::TexParams& inValue)
|
||||
{
|
||||
if (nullptr == L)
|
||||
return;
|
||||
|
||||
lua_newtable(L); /* L: table */
|
||||
|
||||
lua_pushstring(L, "minFilter"); /* L: table key */
|
||||
lua_pushnumber(L, (lua_Number) inValue.minFilter); /* L: table key value*/
|
||||
lua_rawset(L, -3); /* table[key] = value, L: table */
|
||||
lua_pushstring(L, "magFilter"); /* L: table key */
|
||||
lua_pushnumber(L, (lua_Number) inValue.magFilter); /* L: table key value*/
|
||||
lua_rawset(L, -3);
|
||||
lua_pushstring(L, "wrapS"); /* L: table key */
|
||||
lua_pushnumber(L, (lua_Number) inValue.wrapS); /* L: table key value*/
|
||||
lua_rawset(L, -3);
|
||||
lua_pushstring(L, "wrapT"); /* L: table key */
|
||||
lua_pushnumber(L, (lua_Number) inValue.wrapT); /* L: table key value*/
|
||||
lua_rawset(L, -3);
|
||||
}
|
||||
|
|
|
@ -759,6 +759,18 @@ extern bool luaval_to_std_vector_ushort(lua_State* L, int lo, std::vector<unsign
|
|||
*/
|
||||
extern bool luaval_to_quaternion(lua_State* L,int lo,cocos2d::Quaternion* outValue, const char* funcName = "");
|
||||
|
||||
/**
|
||||
* Get a cocos2d::Texture2D::TexParams object value from the given accpetable index of stack.
|
||||
* If the value at the given accpetable index of stack is a table it returns true, otherwise returns false.
|
||||
* If the table has the `minFilter`, `magFilter`, `wrapS` and `wrapT` keys and the corresponding values are not nil, this function would assign the values to the corresponding members of outValue.Otherwise, the value of members of outValue would be 0.
|
||||
* @param L the current lua_State.
|
||||
* @param lo the given accpetable index of stack.
|
||||
* @param outValue the pointer to a cocos2d::Quaternion object which stores the values from the Lua table.
|
||||
* @param funcName the name of calling function, it is used for error output in the debug model.
|
||||
* @return true if the value at the given accpetable index of stack is a table, otherwise return false.
|
||||
*/
|
||||
extern bool luaval_to_texparams(lua_State* L,int lo,cocos2d::Texture2D::TexParams* outValue, const char* funcName = "");
|
||||
|
||||
/**@}**/
|
||||
|
||||
// from native
|
||||
|
@ -1195,6 +1207,15 @@ void ccvector_ushort_to_luaval(lua_State* L, const std::vector<unsigned short>&
|
|||
*/
|
||||
void quaternion_to_luaval(lua_State* L,const cocos2d::Quaternion& inValue);
|
||||
|
||||
/**
|
||||
* Push a table converted from a cocos2d::Texture2D::TexParams object into the Lua stack.
|
||||
* The format of table as follows: {minFilter=numberValue1, magFilter=numberValue2, wrapS=numberValue3, wrapT=numberValue4}
|
||||
*
|
||||
* @param L the current lua_State.
|
||||
* @param inValue a cocos2d::Texture2D::TexParams object.
|
||||
*/
|
||||
void texParams_to_luaval(lua_State* L, const cocos2d::Texture2D::TexParams& inValue);
|
||||
|
||||
// end group
|
||||
/// @}
|
||||
#endif //__COCOS2DX_SCRIPTING_LUA_COCOS2DXSUPPORT_LUABAISCCONVERSIONS_H__
|
||||
|
|
|
@ -1025,70 +1025,147 @@ function AsyncLoadSprite3DTest:onEnter()
|
|||
end
|
||||
|
||||
function AsyncLoadSprite3DTest:onExit()
|
||||
end
|
||||
|
||||
----------------------------------------
|
||||
----Sprite3DCubeTexture
|
||||
----------------------------------------
|
||||
local Sprite3DCubeMap = {}
|
||||
Sprite3DCubeMap.__index = Sprite3DCubeMap
|
||||
local Sprite3DCubeMapTest = class("Sprite3DCubeMapTest", function ()
|
||||
local layer = cc.Layer:create()
|
||||
Helper.initWithLayer(layer)
|
||||
return layer
|
||||
end)
|
||||
|
||||
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
|
||||
function Sprite3DCubeMapTest:ctor()
|
||||
-- body
|
||||
self:init()
|
||||
self._textureCube = nil
|
||||
self._skyBox = nil
|
||||
self._teapot = nil
|
||||
end
|
||||
|
||||
state:setUniformTexture("u_cubeTex", texCube:getName())
|
||||
function Sprite3DCubeMapTest:init()
|
||||
Helper.titleLabel:setString(self:title())
|
||||
Helper.subtitleLabel:setString(self:subtitle())
|
||||
|
||||
teapot:setGLProgramState(state)
|
||||
teapot:setCameraMask(2)
|
||||
self:registerScriptHandler(function (event)
|
||||
if event == "enter" then
|
||||
self:onEnter()
|
||||
elseif event == "exit" then
|
||||
self:onExit()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
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)
|
||||
function Sprite3DCubeMapTest:title()
|
||||
return "CubeMap & Skybox Test"
|
||||
end
|
||||
|
||||
local skybox = cc.Skybox:create()
|
||||
skybox:setTexture(texCube)
|
||||
layer:addChild(skybox)
|
||||
function Sprite3DCubeMapTest:subtitle()
|
||||
return ""
|
||||
end
|
||||
|
||||
return layer
|
||||
>>>>>>> 4ea27173daf6b04cf0b917faa7911dde448cbdca
|
||||
function Sprite3DCubeMapTest:onEnter()
|
||||
local s = cc.Director:getInstance():getWinSize()
|
||||
self:addNewSpriteWithCoords(cc.p(s.width / 2, s.height / 2))
|
||||
end
|
||||
|
||||
function Sprite3DCubeMapTest:onExit()
|
||||
local targetPlatform = cc.Application:getInstance():getTargetPlatform()
|
||||
if targetPlatform == cc.PLATFORM_OS_ANDROID or targetPlatform == cc.PLATFORM_OS_WINRT or targetPlatform == cc.PLATFORM_OS_WP8 then
|
||||
cc.Director:getInstance():getEventDispatcher():removeEventListener(self._backToForegroundListener)
|
||||
end
|
||||
end
|
||||
|
||||
function Sprite3DCubeMapTest:addNewSpriteWithCoords(pos)
|
||||
local visibleSize = cc.Director:getInstance():getVisibleSize()
|
||||
local camera = cc.Camera:createPerspective(60, visibleSize.width / visibleSize.height, 0.1, 200)
|
||||
camera:setCameraFlag(cc.CameraFlag.USER1)
|
||||
--create a teapot
|
||||
self._teapot = cc.Sprite3D:create("Sprite3DTest/teapot.c3b")
|
||||
|
||||
local shader = cc.GLProgram:createWithFilenames("Sprite3DTest/cube_map.vert", "Sprite3DTest/cube_map.frag")
|
||||
local state = cc.GLProgramState:create(shader)
|
||||
|
||||
self._textureCube = 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")
|
||||
|
||||
--set texture parameters
|
||||
local tRepeatParams = { magFilter=gl.NEAREST , minFilter=gl.NEAREST , wrapS=gl.MIRRORED_REPEAT , wrapT=gl.MIRRORED_REPEAT }
|
||||
self._textureCube:setTexParameters(tRepeatParams)
|
||||
|
||||
--pass the texture sampler to our custom shader
|
||||
state:setUniformTexture("u_cubeTex", self._textureCube)
|
||||
|
||||
self._teapot:setGLProgramState(state)
|
||||
self._teapot:setPosition3D(cc.vec3(0, -5, -20))
|
||||
self._teapot:setRotation3D(cc.vec3(-90, 180, 0))
|
||||
|
||||
local rotate_action = cc.RotateBy:create(1.5, cc.vec3(0, 30, 0))
|
||||
self._teapot:runAction(cc.RepeatForever:create(rotate_action))
|
||||
|
||||
--pass mesh's attribute to shader
|
||||
|
||||
local attributeNames =
|
||||
{
|
||||
"a_position",
|
||||
"a_color",
|
||||
"a_texCoord",
|
||||
"a_texCoord1",
|
||||
"a_texCoord2",
|
||||
"a_texCoord3",
|
||||
"a_normal",
|
||||
"a_blendWeight",
|
||||
"a_blendIndex",
|
||||
}
|
||||
|
||||
local offset = 0
|
||||
local attributeCount = self._teapot:getMesh():getMeshVertexAttribCount()
|
||||
for i = 1, attributeCount do
|
||||
local meshattribute = self._teapot:getMesh():getMeshVertexAttribute(i - 1)
|
||||
state:setVertexAttribPointer(attributeNames[meshattribute.vertexAttrib+1],
|
||||
meshattribute.size,
|
||||
meshattribute.type,
|
||||
false,
|
||||
self._teapot:getMesh():getVertexSizeInBytes(),
|
||||
offset)
|
||||
offset = offset + meshattribute.attribSizeBytes
|
||||
end
|
||||
|
||||
self:addChild(self._teapot)
|
||||
self:addChild(camera)
|
||||
|
||||
self:setCameraMask(2)
|
||||
|
||||
--config skybox
|
||||
self._skyBox = cc.Skybox:create()
|
||||
|
||||
self._skyBox:setTexture(self._textureCube)
|
||||
self:addChild(self._skyBox)
|
||||
|
||||
local targetPlatform = cc.Application:getInstance():getTargetPlatform()
|
||||
if targetPlatform == cc.PLATFORM_OS_ANDROID or targetPlatform == cc.PLATFORM_OS_WINRT or targetPlatform == cc.PLATFORM_OS_WP8 then
|
||||
self._backToForegroundListener = cc.EventListenerCustom:create("event_renderer_recreated", function (eventCustom)
|
||||
|
||||
local state = self._teapot:getGLProgramState()
|
||||
local glProgram = state:getGLProgram()
|
||||
glProgramreset()
|
||||
glProgram:initWithFilenames("Sprite3DTest/cube_map.vert", "Sprite3DTest/cube_map.frag")
|
||||
glProgram:link()
|
||||
glProgram:updateUniforms()
|
||||
|
||||
self._textureCube:reloadTexture()
|
||||
|
||||
local tRepeatParams = { magFilter=gl.NEAREST , minFilter=gl.NEAREST , wrapS=gl.MIRRORED_REPEAT , wrapT=gl.MIRRORED_REPEAT }
|
||||
self._textureCube:setTexParameters(tRepeatParams)
|
||||
state:setUniformTexture("u_cubeTex", self._textureCube)
|
||||
|
||||
self._skyBox:reload()
|
||||
self._skyBox:setTexture(self._textureCube)
|
||||
end)
|
||||
cc.Director:getInstance():getEventDispatcher():addEventListenerWithFixedPriority(self._backToForegroundListener, -1)
|
||||
end
|
||||
end
|
||||
|
||||
function Sprite3DTest()
|
||||
|
@ -1105,7 +1182,7 @@ function Sprite3DTest()
|
|||
Sprite3DWithOBBPerfromanceTest.create,
|
||||
Sprite3DMirrorTest.create,
|
||||
AsyncLoadSprite3DTest.create,
|
||||
Sprite3DCubeMap.create,
|
||||
Sprite3DCubeMapTest.create,
|
||||
}
|
||||
|
||||
scene:addChild(Sprite3DBasicTest.create())
|
||||
|
|
|
@ -26,7 +26,7 @@ headers = %(cocosdir)s/cocos/cocos2d.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 = Animate3D Sprite3D Animation3D Skeleton3D ^Mesh$ AttachNode BillBoard Sprite3DCache
|
||||
classes = Animate3D Sprite3D Animation3D Skeleton3D ^Mesh$ AttachNode BillBoard Sprite3DCache TextureCube Skybox
|
||||
|
||||
# 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
|
||||
|
|
Loading…
Reference in New Issue