mirror of https://github.com/axmolengine/axmol.git
asdasd
This commit is contained in:
parent
32395f8e90
commit
73014e8be3
|
@ -1,27 +1,27 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
Copyright (c) 2012 cocos2d-x.org
|
Copyright (c) 2012 cocos2d-x.org
|
||||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
The above copyright notice and this permission notice shall be included in
|
||||||
all copies or substantial portions of the Software.
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "Sprite3DTest.h"
|
#include "Sprite3DTest.h"
|
||||||
#include "3d/CCAnimation3D.h"
|
#include "3d/CCAnimation3D.h"
|
||||||
|
@ -53,6 +53,8 @@ static std::function<Layer*()> createFunctions[] =
|
||||||
// 3DEffect use custom shader which is not supported on WP8/WinRT yet.
|
// 3DEffect use custom shader which is not supported on WP8/WinRT yet.
|
||||||
CL(Sprite3DEffectTest),
|
CL(Sprite3DEffectTest),
|
||||||
CL(Sprite3DUVAnimationTest),
|
CL(Sprite3DUVAnimationTest),
|
||||||
|
CL(Sprite3DFakeShadowTest),
|
||||||
|
CL(Sprite3DBasicToonShaderTest),
|
||||||
#endif
|
#endif
|
||||||
CL(Sprite3DWithSkinTest),
|
CL(Sprite3DWithSkinTest),
|
||||||
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WP8) && (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WP8) && (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
|
||||||
|
@ -100,7 +102,7 @@ static Layer* restartSpriteTestAction()
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
|
|
||||||
Sprite3DTestDemo::Sprite3DTestDemo(void)
|
Sprite3DTestDemo::Sprite3DTestDemo(void)
|
||||||
: BaseTest()
|
: BaseTest()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,8 +173,8 @@ void Sprite3DBasicTest::addNewSpriteWithCoords(Vec2 p)
|
||||||
//int x = (idx%5) * 85;
|
//int x = (idx%5) * 85;
|
||||||
//int y = (idx/5) * 121;
|
//int y = (idx/5) * 121;
|
||||||
|
|
||||||
// //option 1: load a obj that contain the texture in it
|
// //option 1: load a obj that contain the texture in it
|
||||||
// auto sprite = Sprite3D::create("sprite3dTest/scene01.obj");
|
// auto sprite = Sprite3D::create("sprite3dTest/scene01.obj");
|
||||||
|
|
||||||
//option 2: load obj and assign the texture
|
//option 2: load obj and assign the texture
|
||||||
auto sprite = Sprite3D::create("Sprite3DTest/boss1.obj");
|
auto sprite = Sprite3D::create("Sprite3DTest/boss1.obj");
|
||||||
|
@ -270,8 +272,8 @@ Sprite3DUVAnimationTest::Sprite3DUVAnimationTest()
|
||||||
//create the second texture for cylinder
|
//create the second texture for cylinder
|
||||||
auto shining_texture = Director::getInstance()->getTextureCache()->addImage("Sprite3DTest/caustics.png");
|
auto shining_texture = Director::getInstance()->getTextureCache()->addImage("Sprite3DTest/caustics.png");
|
||||||
Texture2D::TexParams tRepeatParams;//set texture parameters
|
Texture2D::TexParams tRepeatParams;//set texture parameters
|
||||||
tRepeatParams.magFilter = GL_NEAREST;
|
tRepeatParams.magFilter = GL_LINEAR;
|
||||||
tRepeatParams.minFilter = GL_NEAREST;
|
tRepeatParams.minFilter = GL_LINEAR;
|
||||||
tRepeatParams.wrapS = GL_REPEAT;
|
tRepeatParams.wrapS = GL_REPEAT;
|
||||||
tRepeatParams.wrapT = GL_REPEAT;
|
tRepeatParams.wrapT = GL_REPEAT;
|
||||||
shining_texture->setTexParameters(tRepeatParams);
|
shining_texture->setTexParameters(tRepeatParams);
|
||||||
|
@ -445,7 +447,7 @@ EffectSprite3D* EffectSprite3D::create(const std::string &path)
|
||||||
}
|
}
|
||||||
|
|
||||||
EffectSprite3D::EffectSprite3D()
|
EffectSprite3D::EffectSprite3D()
|
||||||
: _defaultEffect(nullptr)
|
: _defaultEffect(nullptr)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -532,11 +534,11 @@ bool Effect3DOutline::init()
|
||||||
}
|
}
|
||||||
|
|
||||||
Effect3DOutline::Effect3DOutline()
|
Effect3DOutline::Effect3DOutline()
|
||||||
: _outlineWidth(1.0f)
|
: _outlineWidth(1.0f)
|
||||||
, _outlineColor(1, 1, 1)
|
, _outlineColor(1, 1, 1)
|
||||||
, _sprite(nullptr)
|
, _sprite(nullptr)
|
||||||
{
|
{
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||||
_backToForegroundListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED,
|
_backToForegroundListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED,
|
||||||
[this](EventCustom*)
|
[this](EventCustom*)
|
||||||
{
|
{
|
||||||
|
@ -553,7 +555,7 @@ Effect3DOutline::Effect3DOutline()
|
||||||
|
|
||||||
Effect3DOutline::~Effect3DOutline()
|
Effect3DOutline::~Effect3DOutline()
|
||||||
{
|
{
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||||
Director::getInstance()->getEventDispatcher()->removeEventListener(_backToForegroundListener);
|
Director::getInstance()->getEventDispatcher()->removeEventListener(_backToForegroundListener);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -613,7 +615,6 @@ void Effect3DOutline::setTarget(EffectSprite3D *sprite)
|
||||||
(void*)offset);
|
(void*)offset);
|
||||||
offset += meshvertexattrib.attribSizeBytes;
|
offset += meshvertexattrib.attribSizeBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
Color4F color(_sprite->getDisplayedColor());
|
Color4F color(_sprite->getDisplayedColor());
|
||||||
color.a = _sprite->getDisplayedOpacity() / 255.0f;
|
color.a = _sprite->getDisplayedOpacity() / 255.0f;
|
||||||
_glProgramState->setUniformVec4("u_color", Vec4(color.r, color.g, color.b, color.a));
|
_glProgramState->setUniformVec4("u_color", Vec4(color.r, color.g, color.b, color.a));
|
||||||
|
@ -673,7 +674,6 @@ void EffectSprite3D::draw(cocos2d::Renderer *renderer, const cocos2d::Mat4 &tran
|
||||||
CustomCommand &cc = std::get<2>(effect);
|
CustomCommand &cc = std::get<2>(effect);
|
||||||
cc.func = CC_CALLBACK_0(Effect3D::draw,std::get<1>(effect),transform);
|
cc.func = CC_CALLBACK_0(Effect3D::draw,std::get<1>(effect),transform);
|
||||||
renderer->addCommand(&cc);
|
renderer->addCommand(&cc);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!_defaultEffect)
|
if(!_defaultEffect)
|
||||||
|
@ -900,11 +900,11 @@ void Sprite3DWithSkinOutlineTest::onTouchesEnded(const std::vector<Touch*>& touc
|
||||||
}
|
}
|
||||||
|
|
||||||
Animate3DTest::Animate3DTest()
|
Animate3DTest::Animate3DTest()
|
||||||
: _hurt(nullptr)
|
: _hurt(nullptr)
|
||||||
, _swim(nullptr)
|
, _swim(nullptr)
|
||||||
, _sprite(nullptr)
|
, _sprite(nullptr)
|
||||||
, _moveAction(nullptr)
|
, _moveAction(nullptr)
|
||||||
, _elapseTransTime(0.f)
|
, _elapseTransTime(0.f)
|
||||||
{
|
{
|
||||||
addSprite3D();
|
addSprite3D();
|
||||||
|
|
||||||
|
@ -1035,8 +1035,8 @@ void Animate3DTest::onTouchesEnded(const std::vector<Touch*>& touches, Event* ev
|
||||||
}
|
}
|
||||||
|
|
||||||
AttachmentTest::AttachmentTest()
|
AttachmentTest::AttachmentTest()
|
||||||
: _hasWeapon(false)
|
: _hasWeapon(false)
|
||||||
, _sprite(nullptr)
|
, _sprite(nullptr)
|
||||||
{
|
{
|
||||||
auto s = Director::getInstance()->getWinSize();
|
auto s = Director::getInstance()->getWinSize();
|
||||||
addNewSpriteWithCoords( Vec2(s.width/2, s.height/2) );
|
addNewSpriteWithCoords( Vec2(s.width/2, s.height/2) );
|
||||||
|
@ -1092,7 +1092,7 @@ void AttachmentTest::onTouchesEnded(const std::vector<Touch*>& touches, Event* e
|
||||||
_hasWeapon = !_hasWeapon;
|
_hasWeapon = !_hasWeapon;
|
||||||
}
|
}
|
||||||
Sprite3DReskinTest::Sprite3DReskinTest()
|
Sprite3DReskinTest::Sprite3DReskinTest()
|
||||||
: _sprite(nullptr)
|
: _sprite(nullptr)
|
||||||
{
|
{
|
||||||
auto s = Director::getInstance()->getWinSize();
|
auto s = Director::getInstance()->getWinSize();
|
||||||
addNewSpriteWithCoords( Vec2(s.width/2, s.height/2) );
|
addNewSpriteWithCoords( Vec2(s.width/2, s.height/2) );
|
||||||
|
@ -1102,38 +1102,69 @@ Sprite3DReskinTest::Sprite3DReskinTest()
|
||||||
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
||||||
TTFConfig ttfConfig("fonts/arial.ttf", 20);
|
TTFConfig ttfConfig("fonts/arial.ttf", 20);
|
||||||
auto label1 = Label::createWithTTF(ttfConfig,"Hair");
|
auto label1 = Label::createWithTTF(ttfConfig,"Hair");
|
||||||
auto item1 = MenuItemLabel::create(label1,CC_CALLBACK_1(Sprite3DReskinTest::menuCallback_reSkin,this) );
|
auto item1 = MenuItemLabel::create(label1,CC_CALLBACK_1(Sprite3DReskinTest::menuCallback_switchHair,this) );
|
||||||
auto label2 = Label::createWithTTF(ttfConfig,"Glasses");
|
auto label2 = Label::createWithTTF(ttfConfig,"Glasses");
|
||||||
auto item2 = MenuItemLabel::create(label2, CC_CALLBACK_1(Sprite3DReskinTest::menuCallback_reSkin,this) );
|
auto item2 = MenuItemLabel::create(label2, CC_CALLBACK_1(Sprite3DReskinTest::menuCallback_switchGlasses,this) );
|
||||||
auto label3 = Label::createWithTTF(ttfConfig,"Coat");
|
auto label3 = Label::createWithTTF(ttfConfig,"Coat");
|
||||||
auto item3 = MenuItemLabel::create(label3,CC_CALLBACK_1(Sprite3DReskinTest::menuCallback_reSkin,this) );
|
auto item3 = MenuItemLabel::create(label3,CC_CALLBACK_1(Sprite3DReskinTest::menuCallback_switchCoat,this) );
|
||||||
auto label4 = Label::createWithTTF(ttfConfig,"Pants");
|
auto label4 = Label::createWithTTF(ttfConfig,"Pants");
|
||||||
auto item4 = MenuItemLabel::create(label4, CC_CALLBACK_1(Sprite3DReskinTest::menuCallback_reSkin,this) );
|
auto item4 = MenuItemLabel::create(label4, CC_CALLBACK_1(Sprite3DReskinTest::menuCallback_switchPants,this) );
|
||||||
auto label5 = Label::createWithTTF(ttfConfig,"Shoes");
|
auto label5 = Label::createWithTTF(ttfConfig,"Shoes");
|
||||||
auto item5 = MenuItemLabel::create(label5,CC_CALLBACK_1(Sprite3DReskinTest::menuCallback_reSkin,this) );
|
auto item5 = MenuItemLabel::create(label5,CC_CALLBACK_1(Sprite3DReskinTest::menuCallback_switchShoes,this) );
|
||||||
item1->setPosition( Vec2(VisibleRect::left().x+50, VisibleRect::bottom().y+item1->getContentSize().height*4 ) );
|
item1->setPosition( Vec2(VisibleRect::left().x+50, VisibleRect::bottom().y+item1->getContentSize().height*4 ) );
|
||||||
item2->setPosition( Vec2(VisibleRect::left().x+50, VisibleRect::bottom().y+item1->getContentSize().height *5 ) );
|
item2->setPosition( Vec2(VisibleRect::left().x+50, VisibleRect::bottom().y+item1->getContentSize().height *5 ) );
|
||||||
item3->setPosition( Vec2(VisibleRect::left().x+50, VisibleRect::bottom().y+item1->getContentSize().height*6 ) );
|
item3->setPosition( Vec2(VisibleRect::left().x+50, VisibleRect::bottom().y+item1->getContentSize().height*6 ) );
|
||||||
item4->setPosition( Vec2(VisibleRect::left().x+50, VisibleRect::bottom().y+item1->getContentSize().height *7 ) );
|
item4->setPosition( Vec2(VisibleRect::left().x+50, VisibleRect::bottom().y+item1->getContentSize().height *7 ) );
|
||||||
item5->setPosition( Vec2(VisibleRect::left().x+50, VisibleRect::bottom().y+item1->getContentSize().height *8 ) );
|
item5->setPosition( Vec2(VisibleRect::left().x+50, VisibleRect::bottom().y+item1->getContentSize().height *8 ) );
|
||||||
item1->setUserData((void*)SkinType::HAIR);
|
|
||||||
item2->setUserData((void*)SkinType::GLASSES);
|
|
||||||
item3->setUserData((void*)SkinType::UPPER_BODY);
|
|
||||||
item4->setUserData((void*)SkinType::PANTS);
|
|
||||||
item5->setUserData((void*)SkinType::SHOES);
|
|
||||||
auto pMenu1 = CCMenu::create(item1, item2, item3, item4, item5, nullptr);
|
auto pMenu1 = CCMenu::create(item1, item2, item3, item4, item5, nullptr);
|
||||||
pMenu1->setPosition(Vec2(0,0));
|
pMenu1->setPosition(Vec2(0,0));
|
||||||
this->addChild(pMenu1, 10);
|
this->addChild(pMenu1, 10);
|
||||||
|
|
||||||
}
|
}
|
||||||
void Sprite3DReskinTest::menuCallback_reSkin(Ref* sender)
|
void Sprite3DReskinTest::menuCallback_switchHair(Ref* sender)
|
||||||
{
|
{
|
||||||
long index = (long)(((MenuItemLabel*)sender)->getUserData());
|
std::string str = _curSkin[SkinType::HAIR];
|
||||||
if (index < (int)SkinType::MAX_TYPE)
|
if (str == "Girl_Hair01")
|
||||||
{
|
_curSkin[SkinType::HAIR] = "Girl_Hair02";
|
||||||
_curSkin[index] = (_curSkin[index] + 1) % _skins[index].size();
|
else
|
||||||
|
_curSkin[SkinType::HAIR] = "Girl_Hair01";
|
||||||
|
applyCurSkin();
|
||||||
|
}
|
||||||
|
void Sprite3DReskinTest::menuCallback_switchGlasses(Ref* sender)
|
||||||
|
{
|
||||||
|
std::string str = _curSkin[SkinType::GLASSES];
|
||||||
|
if (str == "Girl_Glasses01")
|
||||||
|
_curSkin[SkinType::GLASSES] = "";
|
||||||
|
else
|
||||||
|
_curSkin[SkinType::GLASSES] = "Girl_Glasses01";
|
||||||
|
applyCurSkin();
|
||||||
|
}
|
||||||
|
void Sprite3DReskinTest::menuCallback_switchCoat(Ref* sender)
|
||||||
|
{
|
||||||
|
std::string str = _curSkin[SkinType::UPPER_BODY];
|
||||||
|
if (str == "Girl_UpperBody01")
|
||||||
|
_curSkin[SkinType::UPPER_BODY] = "Girl_UpperBody02";
|
||||||
|
else
|
||||||
|
_curSkin[SkinType::UPPER_BODY] = "Girl_UpperBody01";
|
||||||
|
applyCurSkin();
|
||||||
|
}
|
||||||
|
void Sprite3DReskinTest::menuCallback_switchPants(Ref* sender)
|
||||||
|
{
|
||||||
|
std::string str = _curSkin[SkinType::PANTS];
|
||||||
|
if (str == "Girl_LowerBody01")
|
||||||
|
_curSkin[SkinType::PANTS] = "Girl_LowerBody02";
|
||||||
|
else
|
||||||
|
_curSkin[SkinType::PANTS] = "Girl_LowerBody01";
|
||||||
|
applyCurSkin();
|
||||||
|
}
|
||||||
|
void Sprite3DReskinTest::menuCallback_switchShoes(Ref* sender)
|
||||||
|
{
|
||||||
|
std::string strShoes = _curSkin[SkinType::SHOES];
|
||||||
|
if (strShoes == "Girl_Shoes01")
|
||||||
|
_curSkin[SkinType::SHOES] = "Girl_Shoes02";
|
||||||
|
else
|
||||||
|
_curSkin[SkinType::SHOES] = "Girl_Shoes01";
|
||||||
applyCurSkin();
|
applyCurSkin();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Sprite3DReskinTest::title() const
|
std::string Sprite3DReskinTest::title() const
|
||||||
|
@ -1162,36 +1193,13 @@ void Sprite3DReskinTest::addNewSpriteWithCoords(Vec2 p)
|
||||||
}
|
}
|
||||||
_sprite = sprite;
|
_sprite = sprite;
|
||||||
|
|
||||||
auto& body = _skins[(int)SkinType::UPPER_BODY];
|
_curSkin[SkinType::UPPER_BODY] = "Girl_UpperBody01";
|
||||||
body.push_back("Girl_UpperBody01");
|
_curSkin[SkinType::PANTS] = "Girl_LowerBody01";
|
||||||
body.push_back("Girl_UpperBody02");
|
_curSkin[SkinType::SHOES] = "Girl_Shoes01";
|
||||||
|
_curSkin[SkinType::HAIR] = "Girl_Hair01";
|
||||||
auto& pants = _skins[(int)SkinType::PANTS];
|
_curSkin[SkinType::FACE] = "Girl_Face01";
|
||||||
pants.push_back("Girl_LowerBody01");
|
_curSkin[SkinType::HAND] = "Girl_Hand01";
|
||||||
pants.push_back("Girl_LowerBody02");
|
_curSkin[SkinType::GLASSES] = "";
|
||||||
|
|
||||||
auto& shoes = _skins[(int)SkinType::SHOES];
|
|
||||||
shoes.push_back("Girl_Shoes01");
|
|
||||||
shoes.push_back("Girl_Shoes02");
|
|
||||||
|
|
||||||
auto& hair = _skins[(int)SkinType::HAIR];
|
|
||||||
hair.push_back("Girl_Hair01");
|
|
||||||
hair.push_back("Girl_Hair02");
|
|
||||||
|
|
||||||
auto& face = _skins[(int)SkinType::FACE];
|
|
||||||
face.push_back("Girl_Face01");
|
|
||||||
face.push_back("Girl_Face02");
|
|
||||||
|
|
||||||
auto& hand = _skins[(int)SkinType::HAND];
|
|
||||||
hand.push_back("Girl_Hand01");
|
|
||||||
hand.push_back("Girl_Hand02");
|
|
||||||
|
|
||||||
auto& glasses = _skins[(int)SkinType::GLASSES];
|
|
||||||
glasses.push_back("");
|
|
||||||
glasses.push_back("Girl_Glasses01");
|
|
||||||
|
|
||||||
memset(_curSkin, 0, (int)SkinType::MAX_TYPE * sizeof(int));
|
|
||||||
|
|
||||||
applyCurSkin();
|
applyCurSkin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1204,8 +1212,8 @@ void Sprite3DReskinTest::applyCurSkin()
|
||||||
for (ssize_t i = 0; i < _sprite->getMeshCount(); i++) {
|
for (ssize_t i = 0; i < _sprite->getMeshCount(); i++) {
|
||||||
auto mesh = _sprite->getMeshByIndex(static_cast<int>(i));
|
auto mesh = _sprite->getMeshByIndex(static_cast<int>(i));
|
||||||
bool isVisible = false;
|
bool isVisible = false;
|
||||||
for (int j = 0; j < (int)SkinType::MAX_TYPE; j++) {
|
for (auto& it : _curSkin) {
|
||||||
if (mesh->getName() == _skins[j].at(_curSkin[j]))
|
if (mesh->getName() == it.second)
|
||||||
{
|
{
|
||||||
isVisible = true;
|
isVisible = true;
|
||||||
break;
|
break;
|
||||||
|
@ -1473,8 +1481,8 @@ void Sprite3DWithOBBPerfromanceTest::calculateRayByLocationInView(Ray* ray, cons
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprite3DMirrorTest::Sprite3DMirrorTest()
|
Sprite3DMirrorTest::Sprite3DMirrorTest()
|
||||||
: _sprite(nullptr)
|
: _sprite(nullptr)
|
||||||
, _mirrorSprite(nullptr)
|
, _mirrorSprite(nullptr)
|
||||||
{
|
{
|
||||||
auto s = Director::getInstance()->getWinSize();
|
auto s = Director::getInstance()->getWinSize();
|
||||||
addNewSpriteWithCoords( Vec2(s.width/2, s.height/2) );
|
addNewSpriteWithCoords( Vec2(s.width/2, s.height/2) );
|
||||||
|
@ -1533,3 +1541,101 @@ void Sprite3DMirrorTest::addNewSpriteWithCoords(Vec2 p)
|
||||||
}
|
}
|
||||||
_mirrorSprite = sprite;
|
_mirrorSprite = sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Sprite3DFakeShadowTest::Sprite3DFakeShadowTest()
|
||||||
|
{
|
||||||
|
Size visibleSize = Director::getInstance()->getVisibleSize();
|
||||||
|
auto _camera = Camera::createPerspective(60,visibleSize.width/visibleSize.height,0.1,200);
|
||||||
|
_camera->setCameraFlag(CameraFlag::USER1);
|
||||||
|
_camera->setPositionY(3);
|
||||||
|
auto plane = Sprite3D::create("Sprite3DTest/plane.c3t");
|
||||||
|
plane->setRotation3D(Vec3(90,0,0));
|
||||||
|
auto shader =GLProgram::createWithFilenames("Sprite3DTest/simple_shadow.vert","Sprite3DTest/simple_shadow.frag");
|
||||||
|
auto state = GLProgramState::create(shader);
|
||||||
|
plane->setGLProgramState(state);
|
||||||
|
//pass mesh's attribute to shader
|
||||||
|
long offset = 0;
|
||||||
|
auto attributeCount = plane->getMesh()->getMeshVertexAttribCount();
|
||||||
|
for (auto i = 0; i < attributeCount; i++) {
|
||||||
|
auto meshattribute = plane->getMesh()->getMeshVertexAttribute(i);
|
||||||
|
state->setVertexAttribPointer(s_attributeNames[meshattribute.vertexAttrib],
|
||||||
|
meshattribute.size,
|
||||||
|
meshattribute.type,
|
||||||
|
GL_FALSE,
|
||||||
|
plane->getMesh()->getVertexSizeInBytes(),
|
||||||
|
(GLvoid*)offset);
|
||||||
|
offset += meshattribute.attribSizeBytes;
|
||||||
|
}
|
||||||
|
state->setUniformMat4("u_model_matrix",plane->getNodeToWorldTransform());
|
||||||
|
auto shadowTexture = Director::getInstance()->getTextureCache()->addImage("Sprite3DTest/shadowCircle.png");
|
||||||
|
Texture2D::TexParams tRepeatParams;//set texture parameters
|
||||||
|
tRepeatParams.magFilter = GL_LINEAR;
|
||||||
|
tRepeatParams.minFilter = GL_LINEAR;
|
||||||
|
tRepeatParams.wrapS = GL_CLAMP_TO_EDGE;
|
||||||
|
tRepeatParams.wrapT = GL_CLAMP_TO_EDGE;
|
||||||
|
shadowTexture->setTexParameters(tRepeatParams);
|
||||||
|
state->setUniformTexture("u_shadowTexture",shadowTexture);
|
||||||
|
this->addChild(plane);
|
||||||
|
|
||||||
|
auto orc = Sprite3D::create("Sprite3DTest/orc.c3b");
|
||||||
|
orc->setScale(0.2);
|
||||||
|
orc->setPosition3D(Vec3(0,0,-10));
|
||||||
|
plane->getGLProgramState()->setUniformVec3("u_target_pos",orc->getPosition3D());
|
||||||
|
this->addChild(orc);
|
||||||
|
this->addChild(_camera);
|
||||||
|
this->setCameraMask(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Sprite3DFakeShadowTest::title() const
|
||||||
|
{
|
||||||
|
return "fake shadow effect";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Sprite3DFakeShadowTest::subtitle() const
|
||||||
|
{
|
||||||
|
return "fake shadow effect";
|
||||||
|
}
|
||||||
|
|
||||||
|
//the basic toon shader test
|
||||||
|
Sprite3DBasicToonShaderTest::Sprite3DBasicToonShaderTest()
|
||||||
|
{
|
||||||
|
Size visibleSize = Director::getInstance()->getVisibleSize();
|
||||||
|
auto _camera = Camera::createPerspective(60,visibleSize.width/visibleSize.height,0.1,200);
|
||||||
|
_camera->setCameraFlag(CameraFlag::USER1);
|
||||||
|
// create a teapot
|
||||||
|
auto teapot = Sprite3D::create("Sprite3DTest/teapot.c3b");
|
||||||
|
//create and set our custom shader
|
||||||
|
auto shader =GLProgram::createWithFilenames("Sprite3DTest/toon.vert","Sprite3DTest/toon.frag");
|
||||||
|
auto state = GLProgramState::create(shader);
|
||||||
|
teapot->setGLProgramState(state);
|
||||||
|
teapot->setPosition3D(Vec3(0,-5,-20));
|
||||||
|
teapot->setRotation3D(Vec3(-90,180,0));
|
||||||
|
auto rotate_action = RotateBy::create(3,Vec3(0,30,0));
|
||||||
|
teapot->runAction(RepeatForever::create(rotate_action));
|
||||||
|
//pass mesh's attribute to shader
|
||||||
|
long offset = 0;
|
||||||
|
auto attributeCount = teapot->getMesh()->getMeshVertexAttribCount();
|
||||||
|
for (auto i = 0; i < attributeCount; i++) {
|
||||||
|
auto meshattribute = teapot->getMesh()->getMeshVertexAttribute(i);
|
||||||
|
state->setVertexAttribPointer(s_attributeNames[meshattribute.vertexAttrib],
|
||||||
|
meshattribute.size,
|
||||||
|
meshattribute.type,
|
||||||
|
GL_FALSE,
|
||||||
|
teapot->getMesh()->getVertexSizeInBytes(),
|
||||||
|
(GLvoid*)offset);
|
||||||
|
offset += meshattribute.attribSizeBytes;
|
||||||
|
}
|
||||||
|
addChild(teapot);
|
||||||
|
addChild(_camera);
|
||||||
|
setCameraMask(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Sprite3DBasicToonShaderTest::title() const
|
||||||
|
{
|
||||||
|
return "basic toon shader test";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Sprite3DBasicToonShaderTest::subtitle() const
|
||||||
|
{
|
||||||
|
return " ";
|
||||||
|
}
|
||||||
|
|
|
@ -81,6 +81,24 @@ protected:
|
||||||
float _shining_duraion;
|
float _shining_duraion;
|
||||||
GLProgramState * _state;
|
GLProgramState * _state;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Sprite3DFakeShadowTest : public Sprite3DTestDemo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CREATE_FUNC(Sprite3DFakeShadowTest);
|
||||||
|
Sprite3DFakeShadowTest();
|
||||||
|
virtual std::string title() const override;
|
||||||
|
virtual std::string subtitle() const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Sprite3DBasicToonShaderTest : public Sprite3DTestDemo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CREATE_FUNC(Sprite3DBasicToonShaderTest);
|
||||||
|
Sprite3DBasicToonShaderTest();
|
||||||
|
virtual std::string title() const override;
|
||||||
|
virtual std::string subtitle() const override;
|
||||||
|
};
|
||||||
class EffectSprite3D;
|
class EffectSprite3D;
|
||||||
|
|
||||||
class Effect3D : public Ref
|
class Effect3D : public Ref
|
||||||
|
@ -120,7 +138,7 @@ protected:
|
||||||
float _outlineWidth;
|
float _outlineWidth;
|
||||||
//weak reference
|
//weak reference
|
||||||
EffectSprite3D* _sprite;
|
EffectSprite3D* _sprite;
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||||
EventListenerCustom* _backToForegroundListener;
|
EventListenerCustom* _backToForegroundListener;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -268,8 +286,11 @@ public:
|
||||||
virtual std::string subtitle() const override;
|
virtual std::string subtitle() const override;
|
||||||
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);
|
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);
|
||||||
void addNewSpriteWithCoords(Vec2 p);
|
void addNewSpriteWithCoords(Vec2 p);
|
||||||
|
void menuCallback_switchHair(Ref* sender);
|
||||||
void menuCallback_reSkin(Ref* sender);
|
void menuCallback_switchGlasses(Ref* sender);
|
||||||
|
void menuCallback_switchCoat(Ref* sender);
|
||||||
|
void menuCallback_switchPants(Ref* sender);
|
||||||
|
void menuCallback_switchShoes(Ref* sender);
|
||||||
protected:
|
protected:
|
||||||
void applyCurSkin();
|
void applyCurSkin();
|
||||||
|
|
||||||
|
@ -282,11 +303,8 @@ protected:
|
||||||
FACE,
|
FACE,
|
||||||
HAND,
|
HAND,
|
||||||
GLASSES,
|
GLASSES,
|
||||||
MAX_TYPE,
|
|
||||||
};
|
};
|
||||||
|
std::map<SkinType, std::string> _curSkin;
|
||||||
std::vector<std::string> _skins[(int)SkinType::MAX_TYPE]; //all skins
|
|
||||||
int _curSkin[(int)SkinType::MAX_TYPE]; //current skin index
|
|
||||||
cocos2d::Sprite3D* _sprite;
|
cocos2d::Sprite3D* _sprite;
|
||||||
};
|
};
|
||||||
class Sprite3DWithOBBPerfromanceTest : public Sprite3DTestDemo
|
class Sprite3DWithOBBPerfromanceTest : public Sprite3DTestDemo
|
||||||
|
|
Loading…
Reference in New Issue