From 3a350e11aebf7614e858ef83f64e6bc0444c5536 Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Thu, 19 Jun 2014 14:05:38 +0800 Subject: [PATCH] Add Lua binding for Animation3D and Animate3D ,and add related test case --- .../project.pbxproj | 4 +- .../src/Sprite3DTest/Sprite3DTest.lua | 56 ++++++++++++++++++- tools/tolua/cocos2dx.ini | 6 +- 3 files changed, 61 insertions(+), 5 deletions(-) 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 00c00b34d2..3aa43b7a1c 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 @@ -889,7 +889,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; SKIP_INSTALL = YES; - USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/../../../.. $(SRCROOT)/../../.. $(SRCROOT)/../../../base $(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"; + 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"; }; name = Debug; }; @@ -922,7 +922,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; SKIP_INSTALL = YES; - USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/../../../.. $(SRCROOT)/../../.. $(SRCROOT)/../../../base $(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"; + 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"; VALIDATE_PRODUCT = YES; }; name = Release; diff --git a/tests/lua-tests/src/Sprite3DTest/Sprite3DTest.lua b/tests/lua-tests/src/Sprite3DTest/Sprite3DTest.lua index 78effa2d15..c1952acf71 100644 --- a/tests/lua-tests/src/Sprite3DTest/Sprite3DTest.lua +++ b/tests/lua-tests/src/Sprite3DTest/Sprite3DTest.lua @@ -22,7 +22,7 @@ function Sprite3DBasicTest.addNewSpriteWithCoords(parent,x,y) parent:addChild(sprite) sprite:setPosition(cc.p(x,y)) - local random = math.random(0, 1) + local random = math.random() local action = nil if random < 0.2 then action = cc.ScaleBy:create(3,2) @@ -58,6 +58,59 @@ function Sprite3DBasicTest.create() return layer end +---------------------------------------- +----Sprite3DWithSkinTest +---------------------------------------- +local Sprite3DWithSkinTest = {} +Sprite3DWithSkinTest.__index = Sprite3DWithSkinTest + +function Sprite3DWithSkinTest.onTouchesEnd(touches, event) + for i = 1,table.getn(touches) do + local location = touches[i]:getLocation() + Sprite3DWithSkinTest.addNewSpriteWithCoords(Helper.currentLayer, location.x, location.y ) + end +end + +function Sprite3DWithSkinTest.addNewSpriteWithCoords(parent,x,y) + local sprite = cc.Sprite3D:create("Sprite3DTest/girl.c3t") + sprite:setRotation3D({x = -90.0, y = 0.0, z = 0.0}) + sprite:setPosition(cc.p(x, y)) + parent:addChild(sprite) + + local animation = cc.Animation3D:getOrCreate("Sprite3DTest/girl.c3t") + if nil ~= animation then + local animate = cc.Animate3D:create(animation) + if math.random() < (1/3) then + animate:setPlayBack(true) + end + + local rand2 = math.random() + if rand2 < 1/3 then + animate:setSpeed(animate:getSpeed() + math.random()) + elseif rand2 < 2/3 then + animate:setSpeed(animate:getSpeed() - 0.5 * math.random()) + end + + sprite:runAction(cc.RepeatForever:create(animate)) + end +end + +function Sprite3DWithSkinTest.create() + local layer = cc.Layer:create() + Helper.initWithLayer(layer) + Helper.titleLabel:setString("Testing Sprite3D for animation from c3t") + Helper.subtitleLabel:setString("Tap screen to add more sprite3D") + + local listener = cc.EventListenerTouchAllAtOnce:create() + listener:registerScriptHandler(Sprite3DWithSkinTest.onTouchesEnd,cc.Handler.EVENT_TOUCHES_ENDED ) + + local eventDispatcher = layer:getEventDispatcher() + eventDispatcher:addEventListenerWithSceneGraphPriority(listener, layer) + + Sprite3DWithSkinTest.addNewSpriteWithCoords(layer, size.width / 2, size.height / 2) + return layer +end + function Sprite3DTest() local scene = cc.Scene:create() @@ -65,6 +118,7 @@ function Sprite3DTest() Helper.createFunctionTable = { Sprite3DBasicTest.create, + Sprite3DWithSkinTest.create, } scene:addChild(Sprite3DBasicTest.create()) diff --git a/tools/tolua/cocos2dx.ini b/tools/tolua/cocos2dx.ini index 0f4d733d71..6a2a9cd6e6 100644 --- a/tools/tolua/cocos2dx.ini +++ b/tools/tolua/cocos2dx.ini @@ -22,7 +22,7 @@ cxxgenerator_headers = 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/cocos2d.h %(cocosdir)s/cocos/audio/include/SimpleAudioEngine.h %(cocosdir)s/cocos/ui/CCProtectedNode.h +headers = %(cocosdir)s/cocos/cocos2d.h %(cocosdir)s/cocos/audio/include/SimpleAudioEngine.h %(cocosdir)s/cocos/ui/CCProtectedNode.h %(cocosdir)s/cocos/3d/CCAnimation3D.h %(cocosdir)s/cocos/3d/CCAnimate3D.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*$". @@ -127,7 +127,9 @@ skip = Node::[setGLServerState description getUserObject .*UserData getGLServerS LabelTTF::[*], LabelBMFont::[*], Mesh::[create], - Sprite3D::[getSkin] + Sprite3D::[getSkin], + Animation3D::[getBoneCurveByName], + Animation3DCache::[*] rename_functions = SpriteFrameCache::[addSpriteFramesWithFile=addSpriteFrames getSpriteFrameByName=getSpriteFrame], ProgressTimer::[setReverseProgress=setReverseDirection],