29#include "2d/CCCameraBackgroundBrush.h"
30#include "3d/CCSprite3DMaterial.h"
31#include "3d/CCMotionStreak3D.h"
33#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
36#include "../testResource.h"
40Sprite3DTests::Sprite3DTests()
88 Sprite3DMaterial::releaseCachedMaterial();
98 auto orc = cocos2d::Sprite3D::create(
"Sprite3DTest/orc.c3b");
100 orc->setPositionNormalized(Vec2(.5f, .3f));
101 orc->setPositionZ(40);
102 orc->setRotation3D(Vec3(0.0f, 180.0f, 0.0f));
103 orc->setGlobalZOrder(-1);
107 auto ship = Sprite3D::create(
"Sprite3DTest/boss1.obj");
109 ship->setTexture(
"Sprite3DTest/boss.png");
110 ship->setPositionNormalized(Vec2(.5f, .5f));
111 ship->setRotation3D(Vec3(90.0f, 0.0f, 0.0f));
112 ship->setForceDepthWrite(
true);
119 return "Force Depth Write Error Test";
124 return "Ship should always appear behind orc";
134 auto s = Sprite3D::create();
135 s->setPositionNormalized(Vec2(.5f, .5f));
136 auto l = Label::create();
137 l->setString(
"Test");
144 return "Testing Sprite3D Container";
149 return "Sprite3D can act as containers for 2D objects";
160 auto listener = EventListenerTouchAllAtOnce::create();
162 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener,
this);
164 auto s = Director::getInstance()->getWinSize();
178 auto sprite = Sprite3D::create(
"Sprite3DTest/boss1.obj");
179 sprite->setScale(3.f);
180 sprite->setTexture(
"Sprite3DTest/boss.png");
188 sprite->setPosition(Vec2(p.x, p.y));
190 ActionInterval* action;
191 float random = CCRANDOM_0_1();
194 action = ScaleBy::create(3, 2);
195 else if (random < 0.40)
196 action = RotateBy::create(3, 360);
197 else if (random < 0.60)
198 action = Blink::create(1, 3);
199 else if (random < 0.8)
200 action = TintBy::create(2, 0, -255, -255);
202 action = FadeOut::create(2);
203 auto action_back = action->reverse();
204 auto seq = Sequence::create(action, action_back,
nullptr);
206 sprite->runAction(RepeatForever::create(seq));
211 for (
auto touch : touches)
213 auto location = touch->getLocation();
221 return "Testing Sprite3D";
226 return "Tap screen to add more sprites";
240 Size visibleSize = Director::getInstance()->getVisibleSize();
243 auto camera = Camera::createPerspective(60, visibleSize.width / visibleSize.height, 0.1f, 200);
244 camera->setCameraFlag(CameraFlag::USER1);
247 auto cylinder = Sprite3D::create(
"Sprite3DTest/cylinder.c3b");
248 auto mat = Sprite3DMaterial::createWithFilename(
"Sprite3DTest/UVAnimation.material");
249 _state = mat->getTechniqueByIndex(0)->getPassByIndex(0)->getProgramState();
250 cylinder->setMaterial(mat);
252 this->addChild(cylinder);
253 this->setCameraMask(2);
254 this->addChild(camera);
257 cylinder->setPosition3D(Vec3(0.0f, -15.0f, -50.0f));
258 cylinder->setRotation3D(Vec3(-90.0f, 0.0f, 0.0f));
263#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
267 auto mat = Sprite3DMaterial::createWithFilename(
"Sprite3DTest/UVAnimation.material");
269 cylinder->setMaterial(mat);
270 _state = mat->getTechniqueByIndex(0)->getPassByIndex(0)->getProgramState();
279#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
286 return "Testing UV Animation";
297 static bool fade_in =
true;
312 auto offsetLoc =
_state->getUniformLocation(
"offset");
313 auto durationLoc =
_state->getUniformLocation(
"duration");
325 Size visibleSize = Director::getInstance()->getVisibleSize();
327 auto listener = EventListenerTouchAllAtOnce::create();
331 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener,
this);
333 auto layer = Layer::create();
336 _camera = Camera::createPerspective(60, visibleSize.width / visibleSize.height, 0.1f, 200);
337 _camera->setCameraFlag(CameraFlag::USER1);
338 _camera->setPosition3D(Vec3(0.0f, 20.0f, 25.0f));
339 _camera->setRotation3D(Vec3(-60.0f, 0.0f, 0.0f));
342 _plane = Sprite3D::create(
"Sprite3DTest/plane.c3t");
343 _plane->setRotation3D(Vec3(90.0f, 0.0f, 0.0f));
346 auto mat = Sprite3DMaterial::createWithFilename(
"Sprite3DTest/FakeShadow.material");
347 _state = mat->getTechniqueByIndex(0)->getPassByIndex(0)->getProgramState();
351 auto location =
_state->getUniformLocation(
"u_model_matrix");
352 auto transform =
_plane->getNodeToWorldTransform();
353 _state->setUniform(location, transform.m,
sizeof(transform.m));
358 _orc = Sprite3D::create(
"Sprite3DTest/orc.c3b");
359 _orc->setScale(0.2f);
360 _orc->setRotation3D(Vec3(0.0f, 180.0f, 0.0f));
361 _orc->setPosition3D(Vec3(0.0f, 0.0f, 10.0f));
363 location =
_state->getUniformLocation(
"u_target_pos");
365 layer->addChild(
_orc);
367 layer->setCameraMask(2);
371#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
375 auto mat = Sprite3DMaterial::createWithFilename(
"Sprite3DTest/FakeShadow.material");
376 _state = mat->getTechniqueByIndex(0)->getPassByIndex(0)->getProgramState();
378 backend::UniformLocation loc =
_state->getUniformLocation(
"u_model_matrix");
379 auto trans =
_plane->getNodeToWorldTransform();
380 _state->setUniform(loc, &trans,
sizeof(trans));
381 loc =
_state->getUniformLocation(
"u_target_pos");
382 auto pos =
_orc->getPosition3D();
383 _state->setUniform(loc, &pos,
sizeof(pos));
392#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
399 return "fake shadow effect";
404 return "touch the screen to move around";
409 _orc->setPositionX(
_orc->getPositionX() + value);
421 Vec3 curPos =
_orc->getPosition3D();
425 newFaceDir.normalize();
427 _orc->getNodeToWorldTransform().getUpVector(&up);
430 Vec3::cross(-newFaceDir, up, &right);
432 Vec3 pos = Vec3(0, 0, 0);
444 mat.m[8] = newFaceDir.x;
445 mat.m[9] = newFaceDir.y;
446 mat.m[10] = newFaceDir.z;
453 _orc->setAdditionalTransform(&mat);
461 Vec3 curPos =
_orc->getPosition3D();
464 newFaceDir.normalize();
465 Vec3 offset = newFaceDir * 25.0f * elapsedTime;
467 _orc->setPosition3D(curPos);
471 auto location =
_state->getUniformLocation(
"u_target_pos");
472 auto position =
_orc->getPosition3D();
473 _state->setUniform(location, &position,
sizeof(position));
478 Vec3 curPos =
_orc->getPosition3D();
480 _orc->getNodeToWorldTransform().getForwardVector(&curFaceDir);
481 curFaceDir = -curFaceDir;
482 curFaceDir.normalize();
485 newFaceDir.normalize();
486 float cosAngle = std::fabs(Vec3::dot(curFaceDir, newFaceDir) - 1.0f);
487 float dist = curPos.distanceSquared(
_targetPos);
490 if (cosAngle <= 0.01f)
497 if (cosAngle > 0.01f)
506 return (state & bit) == bit;
520 for (
auto &item : touches)
523 auto location = touch->getLocationInView();
528 Vec3 nearP(location.x, location.y, -1.0f), farP(location.x, location.y, 1.0f);
530 auto size = Director::getInstance()->getWinSize();
531 nearP =
_camera->unproject(nearP);
532 farP =
_camera->unproject(farP);
533 Vec3 dir(farP - nearP);
535 float ndd = Vec3::dot(Vec3(0, 1, 0), dir);
538 float ndo = Vec3::dot(Vec3(0, 1, 0), nearP);
539 dist = (0 - ndo) / ndd;
540 Vec3 p = nearP + dist * dir;
564 Size visibleSize = Director::getInstance()->getVisibleSize();
565 auto _camera = Camera::createPerspective(60, visibleSize.width / visibleSize.height, 0.1f, 200);
566 _camera->setCameraFlag(CameraFlag::USER1);
568 auto teapot = Sprite3D::create(
"Sprite3DTest/teapot.c3b");
569 auto mat = Sprite3DMaterial::createWithFilename(
"Sprite3DTest/BasicToon.material");
570 _state = mat->getTechniqueByIndex(0)->getPassByIndex(0)->getProgramState();
571 teapot->setMaterial(mat);
573 teapot->setPosition3D(Vec3(0.0f, -5.0f, -20.0f));
574 teapot->setRotation3D(Vec3(-90.0f, 180.0f, 0.0f));
575 auto rotate_action = RotateBy::create(1.5f, Vec3(0.0f, 30.0f, 0.0f));
576 teapot->runAction(RepeatForever::create(rotate_action));
580#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
584 auto mat = Sprite3DMaterial::createWithFilename(
"Sprite3DTest/BasicToon.material");
585 _state = mat->getTechniqueByIndex(0)->getPassByIndex(0)->getProgramState();
586 teapot->setMaterial(mat);
595#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
602 return "basic toon shader test";
619 Size visibleSize = Director::getInstance()->getVisibleSize();
620 _camera = Camera::createPerspective(60, visibleSize.width / visibleSize.height, 0.1f, 200);
621 _camera->setCameraFlag(CameraFlag::USER1);
622 _camera->setPosition3D(Vec3(0.0f, 25.0f, 15.0f));
623 _camera->setRotation3D(Vec3(-35.0f, 0.0f, 0.0f));
624 auto LightMapScene = Sprite3D::create(
"Sprite3DTest/LightMapScene.c3b");
625 LightMapScene->setScale(0.1f);
626 addChild(LightMapScene);
631 auto light = PointLight::create(Vec3(35, 75, -20.5), Color3B(255, 255, 255), 150);
634 auto ambient = AmbientLight::create(Color3B(55, 55, 55));
638 auto listener = EventListenerTouchAllAtOnce::create();
640 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener,
this);
648 return "light map test";
653 return "drag the screen to move around";
658 if (touches.size() == 1)
660 float delta = Director::getInstance()->getDeltaTime();
661 auto touch = touches[0];
662 auto location = touch->getLocation();
663 auto PreviousLocation = touch->getPreviousLocation();
664 Point newPos = PreviousLocation - location;
668 _camera->getNodeToWorldTransform().getForwardVector(&cameraDir);
669 cameraDir.normalize();
671 _camera->getNodeToWorldTransform().getRightVector(&cameraRightDir);
672 cameraRightDir.normalize();
673 cameraRightDir.y = 0;
674 Vec3 cameraPos =
_camera->getPosition3D();
675 cameraPos += cameraDir * newPos.y*delta;
676 cameraPos += cameraRightDir * newPos.x*delta;
677 _camera->setPosition3D(cameraPos);
688 auto s = Director::getInstance()->getWinSize();
690 auto sprite1 = Sprite3D::create(
"Sprite3DTest/boss1.obj");
692 sprite1->setScale(4.f);
693 sprite1->setTexture(
"Sprite3DTest/boss.png");
694 sprite1->setPosition(Vec2(s.width / 2, s.height / 2));
698 sprite1->runAction(RepeatForever::create(RotateBy::create(3.0f, 360.0f)));
700 auto sprite2 = Sprite3D::create(
"Sprite3DTest/boss1.obj");
702 sprite2->setScale(4.f);
703 sprite2->setTexture(
"Sprite3DTest/boss.png");
704 sprite2->setPosition(Vec2(s.width / 2, s.height / 2));
705 sprite2->setAnchorPoint(Vec2(0.5f, 0.5f));
709 sprite2->runAction(RepeatForever::create(RotateBy::create(3.0f, -360.0f)));
713 auto listener1 = EventListenerTouchOneByOne::create();
714 listener1->setSwallowTouches(
true);
716 listener1->onTouchBegan = [](Touch* touch, Event* event) {
717 auto target =
static_cast<Sprite3D*
>(
event->getCurrentTarget());
719 Rect rect = target->getBoundingBox();
720 if (rect.containsPoint(touch->getLocation()))
722 log(
"sprite3d began... x = %f, y = %f", touch->getLocation().x, touch->getLocation().y);
723 target->setOpacity(100);
729 listener1->onTouchMoved = [](Touch* touch, Event* event) {
730 auto target =
static_cast<Sprite3D*
>(
event->getCurrentTarget());
731 target->setPosition(target->getPosition() + touch->getDelta());
734 listener1->onTouchEnded = [=](Touch* touch, Event* event) {
735 auto target =
static_cast<Sprite3D*
>(
event->getCurrentTarget());
736 log(
"sprite3d onTouchesEnded.. ");
737 target->setOpacity(255);
740 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener1, sprite1);
741 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener1->clone(), sprite2);
747 return "Testing Sprite3D Touch in 2D";
752 return "Tap Sprite3D and Drag";
757 auto s = Director::getInstance()->getWinSize();
760 auto listener = EventListenerTouchAllAtOnce::create();
762 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener,
this);
763#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
767 auto material = Sprite3DMaterial::createWithFilename(
"Sprite3DTest/outline.material");
768 material->setTechnique(
"outline_noneskinned");
771 sprite->setMaterial(material->clone());
781#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
788 return "Testing Sprite3D";
792 return "Sprite3d with effects";
798 auto sprite = Sprite3D::create(
"Sprite3DTest/boss1.obj");
799 auto material = Sprite3DMaterial::createWithFilename(
"Sprite3DTest/outline.material");
800 material->setTechnique(
"outline_noneskinned");
801 sprite->setMaterial(material);
802 sprite->setScale(6.f);
803 Director::getInstance()->getTextureCache()->removeUnusedTextures();
808 sprite->setPosition(Vec2(p.x, p.y));
810 ActionInterval* action;
811 float random = CCRANDOM_0_1();
814 action = ScaleBy::create(3, 2);
815 else if (random < 0.40)
816 action = RotateBy::create(3, 360);
817 else if (random < 0.60)
818 action = Blink::create(1, 3);
819 else if (random < 0.8)
820 action = TintBy::create(2, 0, -255, -255);
822 action = FadeOut::create(2);
823 auto action_back = action->reverse();
824 auto seq = Sequence::create(action, action_back,
nullptr);
826 sprite->runAction(RepeatForever::create(seq));
832 for (
auto touch : touches)
834 auto location = touch->getLocation();
842 _paths.push_back(
"Sprite3DTest/girl.c3b");
843 _paths.push_back(
"Sprite3DTest/orc.c3b");
844 _paths.push_back(
"Sprite3DTest/ReskinGirl.c3b");
845 _paths.push_back(
"Sprite3DTest/axe.c3b");
847 TTFConfig ttfConfig(
"fonts/arial.ttf", 15);
848 auto label1 = Label::createWithTTF(ttfConfig,
"AsyncLoad Sprite3D");
851 auto s = Director::getInstance()->getWinSize();
852 item1->setPosition(s.width * .5f, s.height * .8f);
854 auto pMenu1 = Menu::create(item1,
nullptr);
855 pMenu1->setPosition(Vec2(0.0f, 0.0f));
856 this->addChild(pMenu1, 10);
858 auto node = Node::create();
860 this->addChild(node);
871 return "Testing Sprite3D::createAsync";
881 AsyncTaskPool::getInstance()->stopTasks(AsyncTaskPool::TaskType::TASK_IO);
883 auto node = getChildByTag(101);
884 node->removeAllChildren();
887 Sprite3DCache::getInstance()->removeAllSprite3DData();
889 for (
const auto& path :
_paths) {
896 long index = (long)param;
897 auto node = getChildByTag(101);
898 auto s = Director::getInstance()->getWinSize();
899 float width = s.width /
_paths.size();
900 Vec2 point(width * (0.5f + index), s.height / 2.f);
901 sprite->setPosition(point);
902 node->addChild(sprite);
908 auto listener = EventListenerTouchAllAtOnce::create();
910 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener,
this);
913 MenuItemFont::setFontName(
"fonts/arial.ttf");
914 MenuItemFont::setFontSize(15);
917 _menuItem->setColor(Color3B(0, 200, 20));
918 auto menu = Menu::create(
_menuItem, NULL);
919 menu->setPosition(Vec2::ZERO);
925 auto s = Director::getInstance()->getWinSize();
930 return "Testing Sprite3D";
934 return "Tap screen to add more sprite3D";
939 std::string fileName =
"Sprite3DTest/orc.c3b";
940 auto sprite = Sprite3D::create(fileName);
942 sprite->setRotation3D(Vec3(0.0f, 180.0f, 0.0f));
943 sprite->setPosition(Vec2(p.x, p.y));
947 auto animation = Animation3D::create(fileName);
950 auto animate = Animate3D::create(animation);
951 bool inverse = (std::rand() % 3 == 0);
953 int rand2 = std::rand();
957 speed = animate->getSpeed() + CCRANDOM_0_1();
959 else if (rand2 % 3 == 2)
961 speed = animate->getSpeed() - 0.5 * CCRANDOM_0_1();
963 animate->setSpeed(inverse ? -speed : speed);
964 animate->setTag(110);
966 auto repeat = RepeatForever::create(animate);
968 sprite->runAction(repeat);
975 return "None Quality";
977 return "Low Quality";
979 return "High Quality";
994 RepeatForever* repAction =
dynamic_cast<RepeatForever*
>(iter->getActionByTag(110));
995 Animate3D* animate3D =
dynamic_cast<Animate3D*
>(repAction->getInnerAction());
1002 for (
auto touch : touches)
1004 auto location = touch->getLocation();
1012 auto listener = EventListenerTouchAllAtOnce::create();
1014 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener,
this);
1016 auto s = Director::getInstance()->getWinSize();
1019#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
1021 [
this](EventCustom*)
1023 auto material = Sprite3DMaterial::createWithFilename(
"Sprite3DTest/outline.material");
1024 material->setTechnique(
"outline_skinned");
1027 sprite->setMaterial(material->clone());
1036#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
1042 return "Testing Sprite3D for skinned outline";
1046 return "Tap screen to add more sprite3D";
1052 std::string fileName =
"Sprite3DTest/orc.c3b";
1053 auto sprite = Sprite3D::create(fileName);
1055 auto material = Sprite3DMaterial::createWithFilename(
"Sprite3DTest/outline.material");
1056 material->setTechnique(
"outline_skinned");
1057 sprite->setMaterial(material);
1059 sprite->setScale(3);
1060 sprite->setRotation3D(Vec3(0.0f, 180.0f, 0.0f));
1062 sprite->setPosition(Vec2(p.x, p.y));
1064 auto animation = Animation3D::create(fileName);
1067 auto animate = Animate3D::create(animation);
1068 bool inverse = (std::rand() % 3 == 0);
1070 int rand2 = std::rand();
1074 speed = animate->getSpeed() + CCRANDOM_0_1();
1076 else if (rand2 % 3 == 2)
1078 speed = animate->getSpeed() - 0.5 * CCRANDOM_0_1();
1080 animate->setSpeed(inverse ? -speed : speed);
1082 sprite->runAction(RepeatForever::create(animate));
1088 for (
auto touch : touches)
1090 auto location = touch->getLocation();
1100 , _elapseTransTime(0.f)
1101 , _moveAction(nullptr)
1105 auto listener = EventListenerTouchAllAtOnce::create();
1107 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener,
this);
1115 CC_SAFE_RELEASE(
_hurt);
1116 CC_SAFE_RELEASE(
_swim);
1121 return "Testing Animate3D";
1126 return "Touch to beat the tortoise";
1154 std::string fileName =
"Sprite3DTest/tortoise.c3b";
1155 auto sprite = Sprite3D::create(fileName);
1156 sprite->setScale(0.1f);
1157 auto s = Director::getInstance()->getWinSize();
1158 sprite->setPosition(Vec2(s.width * 4.f / 5.f, s.height / 2.f));
1161 auto animation = Animation3D::create(fileName);
1164 auto animate = Animate3D::create(animation, 0.f, 1.933f);
1165 _swim = RepeatForever::create(animate);
1166 sprite->runAction(
_swim);
1169 _hurt = Animate3D::create(animation, 1.933f, 2.8f);
1174 _moveAction = MoveTo::create(4.f, Vec2(s.width / 5.f, s.height / 2.f));
1178 sprite->runAction(seq);
1183 auto s = Director::getInstance()->getWinSize();
1184 _sprite->stopActionByTag(100);
1185 auto inverse = MoveTo::create(4.f, Vec2(s.width -
_sprite->getPositionX(), s.height / 2.f));
1189 auto rot = RotateBy::create(1.f, Vec3(0.f, 180.f, 0.f));
1205 for (
auto touch : touches)
1207 auto location = touch->getLocation();
1211 float len = (
_sprite->getPosition() - location).length();
1221 auto delay = DelayTime::create(
_hurt->getDuration() - Animate3D::getTransitionTime());
1236 auto s = Director::getInstance()->getWinSize();
1239 auto listener = EventListenerTouchAllAtOnce::create();
1241 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener,
this);
1245 return "Testing Sprite3D Attachment";
1249 return "touch to switch weapon";
1254 std::string fileName =
"Sprite3DTest/orc.c3b";
1255 auto sprite = Sprite3D::create(fileName);
1256 sprite->setScale(5);
1257 sprite->setRotation3D(Vec3(0.0f, 180.0f, 0.0f));
1259 sprite->setPosition(Vec2(p.x, p.y));
1262 auto sp = Sprite3D::create(
"Sprite3DTest/axe.c3b");
1263 sprite->getAttachNode(
"Bip001 R Hand")->addChild(sp);
1265 auto animation = Animation3D::create(fileName);
1268 auto animate = Animate3D::create(animation);
1270 sprite->runAction(RepeatForever::create(animate));
1280 _sprite->removeAllAttachNode();
1284 auto sp = Sprite3D::create(
"Sprite3DTest/axe.c3b");
1285 _sprite->getAttachNode(
"Bip001 R Hand")->addChild(sp);
1293 auto s = Director::getInstance()->getWinSize();
1296 auto listener = EventListenerTouchAllAtOnce::create();
1298 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener,
this);
1299 TTFConfig ttfConfig(
"fonts/arial.ttf", 20);
1300 auto label1 = Label::createWithTTF(ttfConfig,
"Hair");
1302 auto label2 = Label::createWithTTF(ttfConfig,
"Glasses");
1304 auto label3 = Label::createWithTTF(ttfConfig,
"Coat");
1306 auto label4 = Label::createWithTTF(ttfConfig,
"Pants");
1308 auto label5 = Label::createWithTTF(ttfConfig,
"Shoes");
1320 auto pMenu1 = Menu::create(item1, item2, item3, item4, item5,
nullptr);
1321 pMenu1->setPosition(Vec2(0.0f, 0.0f));
1322 this->addChild(pMenu1, 10);
1327 long index = (long)(((MenuItemLabel*)sender)->getUserData());
1337 return "Testing Sprite3D Reskin";
1346 std::string fileName =
"Sprite3DTest/ReskinGirl.c3b";
1347 auto sprite = Sprite3D::create(fileName);
1348 sprite->setScale(4);
1349 sprite->setRotation3D(Vec3(0.0f, 0.0f, 0.0f));
1351 sprite->setPosition(Vec2(p.x, p.y - 60));
1352 auto animation = Animation3D::create(fileName);
1355 auto animate = Animate3D::create(animation);
1357 sprite->runAction(RepeatForever::create(animate));
1362 body.push_back(
"Girl_UpperBody01");
1363 body.push_back(
"Girl_UpperBody02");
1366 pants.push_back(
"Girl_LowerBody01");
1367 pants.push_back(
"Girl_LowerBody02");
1370 shoes.push_back(
"Girl_Shoes01");
1371 shoes.push_back(
"Girl_Shoes02");
1374 hair.push_back(
"Girl_Hair01");
1375 hair.push_back(
"Girl_Hair02");
1378 face.push_back(
"Girl_Face01");
1379 face.push_back(
"Girl_Face02");
1382 hand.push_back(
"Girl_Hand01");
1383 hand.push_back(
"Girl_Hand02");
1386 glasses.push_back(
"");
1387 glasses.push_back(
"Girl_Glasses01");
1400 for (ssize_t i = 0; i <
_sprite->getMeshCount(); i++) {
1401 auto mesh =
_sprite->getMeshByIndex(
static_cast<int>(i));
1402 bool isVisible =
false;
1410 _sprite->getMeshByIndex(
static_cast<int>(i))->setVisible(isVisible);
1416 auto listener = EventListenerTouchAllAtOnce::create();
1420 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener,
this);
1421 auto s = Director::getInstance()->getWinSize();
1425 MenuItemFont::setFontName(
"fonts/arial.ttf");
1426 MenuItemFont::setFontSize(65);
1428 decrease->setColor(Color3B(0, 200, 20));
1430 increase->setColor(Color3B(0, 200, 20));
1432 auto menu = Menu::create(decrease, increase,
nullptr);
1433 menu->alignItemsHorizontally();
1434 menu->setPosition(Vec2(s.width / 2, s.height - 65));
1437 TTFConfig ttfCount(
"fonts/Marker Felt.ttf", 30);
1448 return "OBB Collision Performance Test";
1456 Vec3 extents = Vec3(10, 10, 10);
1457 AABB aabb(-extents, extents);
1458 auto obb = OBB(aabb);
1459 obb._center = Vec3(p.x, p.y, 0);
1460 _obb.push_back(obb);
1465 for (
const auto& touch : touches)
1467 auto location = touch->getLocationInView();
1468 auto obbSize =
_obb.size();
1474 for (
decltype(obbSize) i = 0; i < obbSize; i++)
1476 if (ray.intersects(
_obb[i]))
1493 for (
const auto& touch : touches)
1495 auto location = touch->getLocation();
1496 auto obbSize =
_obb.size();
1498 for (
decltype(obbSize) i = 0; i < obbSize; i++)
1501 _obb[i]._center = Vec3(location.x, location.y, 0);
1509 sprintf(szText,
"%lu cubes",
static_cast<unsigned long>(
_obb.size()));
1516 Mat4 mat =
_sprite->getNodeToWorldTransform();
1519 _obbt.transform(mat);
1521 Vec3 corners[8] = {};
1522 _obbt.getCorners(corners);
1523 _drawDebug->drawCube(corners, Color4F(0, 0, 1, 1));
1525 if (
_obb.size() > 0)
1528 auto obbSize =
_obb.size();
1529 for (
decltype(obbSize) i = 0; i < obbSize; i++)
1531 Vec3 corners[8] = {};
1532 _obb[i].getCorners(corners);
1533 _drawOBB->drawCube(corners,
_obbt.intersects(
_obb[i]) ? Color4F(1, 0, 0, 1) : Color4F(0, 1, 0, 1));
1546 std::string fileName =
"Sprite3DTest/tortoise.c3b";
1547 auto sprite = Sprite3D::create(fileName);
1548 AABB aabb = sprite->getAABB();
1552 sprite->setScale(0.1f);
1553 auto s = Director::getInstance()->getWinSize();
1554 sprite->setPosition(Vec2(s.width * 4.f / 5.f, s.height / 2.f));
1557 auto animation = Animation3D::create(fileName);
1560 auto animate = Animate3D::create(animation, 0.f, 1.933f);
1561 sprite->runAction(RepeatForever::create(animate));
1564 _moveAction = MoveTo::create(4.f, Vec2(s.width / 5.f, s.height / 2.f));
1568 sprite->runAction(seq);
1578 auto s = Director::getInstance()->getWinSize();
1579 _sprite->stopActionByTag(100);
1580 auto inverse = MoveTo::create(4.f, Vec2(s.width -
_sprite->getPositionX(), s.height / 2.f));
1584 auto rot = RotateBy::create(1.0f, Vec3(0.f, 180.f, 0.f));
1597 for (
int i = 0; i < value; i++)
1599 Vec2 randompos = Vec2(CCRANDOM_0_1() * Director::getInstance()->getWinSize().width, CCRANDOM_0_1() * Director::getInstance()->getWinSize().height);
1600 Vec3 extents = Vec3(10, 10, 10);
1601 AABB aabb(-extents, extents);
1602 auto obb = OBB(aabb);
1603 obb._center = Vec3(randompos.x, randompos.y, 0);
1604 _obb.push_back(obb);
1615 if (
_obb.size() >= 10)
1627 assert(viewport->width != 0.0f && viewport->height != 0.0f);
1628 Vec4 screen(src->x / viewport->width, ((viewport->height - src->y)) / viewport->height, src->z, 1.0f);
1630 screen.x = screen.x * 2.0f - 1.0f;
1631 screen.y = screen.y * 2.0f - 1.0f;
1632 screen.z = screen.z * 2.0f - 1.0f;
1634 viewProjection.getInversed().transformVector(screen, &screen);
1636 if (screen.w != 0.0f)
1638 screen.x /= screen.w;
1639 screen.y /= screen.w;
1640 screen.z /= screen.w;
1643 dst->set(screen.x, screen.y, screen.z);
1648 auto dir = Director::getInstance();
1649 auto view = dir->getWinSize();
1650 auto mat = dir->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
1652 Vec3 src = Vec3(location.x, location.y, -1);
1654 unproject(mat, &view, &src, &nearPoint);
1656 src = Vec3(location.x, location.y, 1);
1661 Vec3::subtract(farPoint, nearPoint, &direction);
1662 direction.normalize();
1664 ray->_origin = nearPoint;
1665 ray->_direction = direction;
1670 , _mirrorSprite(nullptr)
1672 auto s = Director::getInstance()->getWinSize();
1677 return "Sprite3D Mirror Test";
1686 std::string fileName =
"Sprite3DTest/orc.c3b";
1687 auto sprite = Sprite3D::create(fileName);
1688 sprite->setScale(5);
1689 sprite->setRotation3D(Vec3(0.0f, 180.0f, 0.0f));
1691 sprite->setPosition(Vec2(p.x - 80, p.y));
1694 auto sp = Sprite3D::create(
"Sprite3DTest/axe.c3b");
1695 sprite->getAttachNode(
"Bip001 R Hand")->addChild(sp);
1697 auto animation = Animation3D::create(fileName);
1700 auto animate = Animate3D::create(animation);
1702 sprite->runAction(RepeatForever::create(animate));
1708 sprite = Sprite3D::create(fileName);
1709 sprite->setScale(5);
1710 sprite->setScaleX(-5);
1711 sprite->setCullFace(CullFaceSide::FRONT);
1712 sprite->setRotation3D(Vec3(0.0f, 180.0f, 0.0f));
1714 sprite->setPosition(Vec2(p.x + 80, p.y));
1717 sp = Sprite3D::create(
"Sprite3DTest/axe.c3b");
1718 sprite->getAttachNode(
"Bip001 R Hand")->addChild(sp);
1720 animation = Animation3D::create(fileName);
1723 auto animate = Animate3D::create(animation);
1725 sprite->runAction(RepeatForever::create(animate));
1731 : _arcSpeed(CC_DEGREES_TO_RADIANS(90))
1735 auto s = Director::getInstance()->getWinSize();
1741 return "Test Rotation With Quaternion";
1750 std::string fileName =
"Sprite3DTest/tortoise.c3b";
1751 auto sprite = Sprite3D::create(fileName);
1752 sprite->setScale(0.1f);
1753 auto s = Director::getInstance()->getWinSize();
1757 auto animation = Animation3D::create(fileName);
1760 auto animate = Animate3D::create(animation, 0.f, 1.933f);
1761 sprite->runAction(RepeatForever::create(animate));
1768 const float pi = (float)M_PI;
1772 auto s = Director::getInstance()->getWinSize();
1776 Quaternion::createFromAxisAngle(Vec3(0.f, 0.f, 1.f),
_accAngle - pi * 0.5f, &quat);
1777 _sprite->setRotationQuat(quat);
1783 auto s = Director::getInstance()->getWinSize();
1788 auto itemPrev = MenuItemImage::create(
"Images/b1.png",
"Images/b2.png",
1796 auto itemNext = MenuItemImage::create(
"Images/f1.png",
"Images/f2.png",
1804 auto menu = Menu::create(itemPrev, itemNext,
nullptr);
1805 menu->alignItemsHorizontally();
1806 menu->setScale(0.5);
1807 menu->setAnchorPoint(Vec2(0.0f, 0.0f));
1808 menu->setPosition(Vec2(s.width / 2, 70.0f));
1810 _label = Label::create();
1811 _label->setPosition(s.width * 0.5f, s.height * 0.8f);
1817 auto camera = Camera::createPerspective(40, s.width / s.height, 0.01f, 1000.f);
1818 camera->setCameraFlag(CameraFlag::USER1);
1819 camera->setPosition3D(Vec3(0.f, 30.f, 100.f));
1820 camera->lookAt(Vec3(0.f, 0.f, 0.f));
1828 return "Use Case For 2D + 3D";
1838 removeChildByTag(101);
1840 auto s = Director::getInstance()->getWinSize();
1844 std::string filename =
"Sprite3DTest/girl.c3b";
1845 auto sprite = Sprite3D::create(filename);
1846 sprite->setScale(0.15f);
1847 auto animation = Animation3D::create(filename);
1850 auto animate = Animate3D::create(animation);
1851 sprite->runAction(RepeatForever::create(animate));
1854 auto circleBack = Sprite3D::create();
1855 auto circle = Sprite::create(
"Sprite3DTest/circle.png");
1856 circleBack->setScale(0.5f);
1857 circleBack->addChild(circle);
1858 circle->runAction(RepeatForever::create(RotateBy::create(3, Vec3(0.f, 0.f, 360.f))));
1860 circleBack->setRotation3D(Vec3(-90.0f, -90.0f, 0.0f));
1862 auto pos = sprite->getPosition3D();
1863 circleBack->setPosition3D(Vec3(pos.x, pos.y, pos.z - 1));
1865 sprite->setOpacity(250);
1866 sprite->setCameraMask(2);
1867 circleBack->setCameraMask(2);
1869 circleBack->setTag(2);
1871 auto node = Node::create();
1872 node->addChild(sprite);
1873 node->addChild(circleBack);
1882 auto layer = LayerColor::create(Color4B(0, 0, 100, 255), s.width / 2.f, s.height / 2.f);
1883 layer->setPosition(s.width * 0.25f, s.height * 0.25f);
1884 layer->setGlobalZOrder(-1);
1887 std::string filename =
"Sprite3DTest/girl.c3b";
1888 auto sprite = Sprite3D::create(filename);
1889 sprite->setScale(0.5f);
1890 auto animation = Animation3D::create(filename);
1893 auto animate = Animate3D::create(animation);
1894 sprite->runAction(RepeatForever::create(animate));
1896 sprite->setPosition(s.width * 0.25f, s.height * 0.125f);
1897 layer->addChild(sprite);
1899 TTFConfig ttfConfig(
"fonts/arial.ttf", 15);
1900 auto label1 = Label::createWithTTF(ttfConfig,
"Message");
1902 auto label2 = Label::createWithTTF(ttfConfig,
"Message");
1905 item1->setPosition(Vec2(s.width * 0.5f - item1->getContentSize().width * 0.5f, s.height * 0.5f - item1->getContentSize().height));
1906 item2->setPosition(Vec2(s.width * 0.5f - item1->getContentSize().width * 0.5f, s.height * 0.5f - item1->getContentSize().height * 2.f));
1908 auto pMenu1 = Menu::create(item1, item2,
nullptr);
1909 pMenu1->setPosition(Vec2(0.0f, 0.0f));
1910 layer->addChild(pMenu1);
1918 auto layer = getChildByTag(101);
1919 auto message = layer->getChildByTag(102);
1921 layer->removeChild(message);
1925 auto s = layer->getContentSize();
1926 auto messagelayer = LayerColor::create(Color4B(100, 100, 0, 255));
1927 messagelayer->setContentSize(Size(s.width * 0.5f, s.height * 0.5f));
1928 messagelayer->setPosition(Vec2(s.width * 0.25f, s.height * 0.25f));
1929 auto label = Label::create();
1930 label->setString(
"This Message Layer \n Should Be On Top");
1931 label->setPosition(Vec2(s.width * 0.25f, s.height * 0.25f));
1932 messagelayer->addChild(label);
1933 messagelayer->setTag(102);
1934 layer->addChild(messagelayer);
1942 static float accAngle = 0.f;
1943 accAngle += delta * CC_DEGREES_TO_RADIANS(60);
1945 float radius = 30.f;
1946 float x = cosf(accAngle) * radius, z = sinf(accAngle) * radius;
1948 auto node = getChildByTag(101);
1949 auto sprite3d = node->getChildByTag(3);
1950 auto circle = node->getChildByTag(2);
1952 sprite3d->setPositionX(x);
1953 sprite3d->setPositionZ(z);
1954 circle->setPositionX(x);
1955 circle->setPositionZ(z);
1964 auto s = Director::getInstance()->getWinSize();
1966 auto itemPrev = MenuItemImage::create(
"Images/b1.png",
"Images/b2.png",
1979 auto itemNext = MenuItemImage::create(
"Images/f1.png",
"Images/f2.png",
1984 if (tIndex >=
static_cast<int>(
_sprites.size()))
1992 auto menu = Menu::create(itemPrev, itemNext,
nullptr);
1993 menu->alignItemsHorizontally();
1994 menu->setScale(0.5f);
1995 menu->setAnchorPoint(Vec2(0.0f, 0.0f));
1996 menu->setPosition(Vec2(s.width / 2, 70.0f));
2003 return "Node Animation Test";
2007 return "Jumping animation";
2012 auto s = Director::getInstance()->getWinSize();
2015 std::string fileName =
"Sprite3DTest/ball.c3b";
2016 auto sprite = Sprite3D::create(fileName);
2017 sprite->setRotation3D(Vec3(0.0f, 180.0f, 0.0f));
2018 sprite->setScale(3);
2019 sprite->setPosition(Vec2(s.width / 2.f, s.height / 3.f));
2020 sprite->setTexture(
"Sprite3DTest/teapot.png");
2022 auto light1 = PointLight::create(Vec3(s.width * 0.2f, s.height * 0.8f, 100.0f), Color3B(200, 200, 200), 10000.0f);
2024 auto light2 = AmbientLight::create(Color3B(100, 100, 100));
2027 auto animation = Animation3D::create(fileName);
2030 auto animate = Animate3D::create(animation);
2031 auto act = RepeatForever::create(animate);
2033 sprite->runAction(act);
2039 fileName =
"Sprite3DTest/orc_jump.c3t";
2040 sprite = Sprite3D::create(fileName);
2041 sprite->setRotation3D(Vec3(0.0f, 180.0f, 0.0f));
2042 sprite->setScale(3);
2043 sprite->setPosition(Vec2(s.width / 2.f, s.height / 3.f));
2044 sprite->setVisible(
false);
2045 animation = Animation3D::create(fileName);
2048 auto animate = Animate3D::create(animation);
2049 auto act = RepeatForever::create(animate);
2051 sprite->runAction(act);
2058 _textureCube(nullptr),
2062 auto s = Director::getInstance()->getWinSize();
2068#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
2079 return "CubeMap & Skybox Test";
2089 Size visibleSize = Director::getInstance()->getVisibleSize();
2090 _camera = Camera::createPerspective(60, visibleSize.width / visibleSize.height, 10, 1000);
2091 _camera->setPosition3D(Vec3(0.f, 0.f, 50.f));
2092 _camera->setCameraFlag(CameraFlag::USER1);
2094 auto listener = EventListenerTouchAllAtOnce::create();
2096 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener,
this);
2099 _teapot = Sprite3D::create(
"Sprite3DTest/teapot.c3b");
2103 _textureCube = TextureCube::create(
"Sprite3DTest/skybox/left.jpg",
"Sprite3DTest/skybox/right.jpg",
2104 "Sprite3DTest/skybox/top.jpg",
"Sprite3DTest/skybox/bottom.jpg",
2105 "Sprite3DTest/skybox/front.jpg",
"Sprite3DTest/skybox/back.jpg");
2110 Texture2D::TexParams tRepeatParams;
2111 tRepeatParams.magFilter = backend::SamplerFilter::LINEAR;
2112 tRepeatParams.minFilter = backend::SamplerFilter::LINEAR;
2113 tRepeatParams.sAddressMode = backend::SamplerAddressMode::CLAMP_TO_EDGE;
2114 tRepeatParams.tAddressMode = backend::SamplerAddressMode::CLAMP_TO_EDGE;
2118 auto mat = Sprite3DMaterial::createWithFilename(
"Sprite3DTest/CubeMap.material");
2119 auto state = mat->getTechniqueByIndex(0)->getPassByIndex(0)->getProgramState();
2123 auto cubeTexLoc = state->getUniformLocation(
"u_cubeTex");
2124 state->setTexture(cubeTexLoc, 0,
_textureCube->getBackendTexture());
2126 _teapot->setPosition3D(Vec3(0.0f, -5.0f, 0.0f));
2127 _teapot->setRotation3D(Vec3(-90.0f, 180.0f, 0.0f));
2129 auto rotate_action = RotateBy::create(1.5, Vec3(0.0f, 30.0f, 0.0f));
2130 _teapot->runAction(RepeatForever::create(rotate_action));
2145#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
2147 [
this](EventCustom*)
2150 _textureCube = TextureCube::create(
"Sprite3DTest/skybox/left.jpg",
"Sprite3DTest/skybox/right.jpg",
2151 "Sprite3DTest/skybox/top.jpg",
"Sprite3DTest/skybox/bottom.jpg",
2152 "Sprite3DTest/skybox/front.jpg",
"Sprite3DTest/skybox/back.jpg");
2156 Texture2D::TexParams tRepeatParams;
2157 tRepeatParams.magFilter = backend::SamplerFilter::LINEAR;
2158 tRepeatParams.minFilter = backend::SamplerFilter::LINEAR;
2159 tRepeatParams.sAddressMode = backend::SamplerAddressMode::CLAMP_TO_EDGE;
2160 tRepeatParams.tAddressMode = backend::SamplerAddressMode::CLAMP_TO_EDGE;
2163 auto mat = Sprite3DMaterial::createWithFilename(
"Sprite3DTest/CubeMap.material");
2164 auto state = mat->getTechniqueByIndex(0)->getPassByIndex(0)->getProgramState();
2168 auto cubeTexLoc = state->getUniformLocation(
"u_cubeTex");
2169 state->setTexture(cubeTexLoc, 0,
_textureCube->getBackendTexture());
2180 auto touch = touches[0];
2181 auto delta = touch->getDelta();
2183 static float _angle = 0.f;
2184 _angle -= CC_DEGREES_TO_RADIANS(delta.x);
2185 _camera->setPosition3D(Vec3(50.0f * sinf(_angle), 0.0f, 50.0f * cosf(_angle)));
2186 _camera->lookAt(Vec3(0.0f, 0.0f, 0.0f), Vec3(0.0f, 1.0f, 0.0f));
2194 auto s = Director::getInstance()->getWinSize();
2195 auto sprite = Sprite3D::create(
"Sprite3DTest/boss1.obj");
2196 sprite->setScale(3.f);
2197 sprite->setTexture(
"Sprite3DTest/boss.png");
2199 sprite->setPosition(Vec2(s.width / 2, s.height / 2));
2202 TTFConfig ttfConfig(
"fonts/arial.ttf", 15);
2203 auto label1 = Label::createWithTTF(ttfConfig,
"switch shader");
2206 item1->setPosition(Vec2(s.width * 0.9f - item1->getContentSize().width * 0.5f, s.height * 0.5f - item1->getContentSize().height));
2208 auto pMenu1 = Menu::create(item1,
nullptr);
2209 pMenu1->setPosition(Vec2(0.0f, 0.0f));
2219 CC_SAFE_RELEASE_NULL(_programState);
2223 auto program = backend::Program::getBuiltinProgram(backend::ProgramType::POSITION_3D);
2224 _programState =
new backend::ProgramState(program);
2229 auto program = backend::Program::getBuiltinProgram(backend::ProgramType::POSITION_TEXTURE_3D);
2230 _programState =
new backend::ProgramState(program);
2232 _sprite->setProgramState(_programState);
2237 return "Issue9767: test setGLProgram";
2247 auto size = Director::getInstance()->getWinSize();
2248 auto stencil = Sprite::create(
"Images/close.png");
2249 auto clipSprite3D = ClippingNode::create();
2250 clipSprite3D->setStencil(stencil);
2251 this->addChild(clipSprite3D);
2252 clipSprite3D->setScale(3.0f);
2254 auto sprite3D = Sprite3D::create(
"Sprite3DTest/orc.c3b");
2255 sprite3D->setScale(1.0f);
2256 sprite3D->setRotation3D(Vec3(0.0f, 180.0f, 0.0f));
2257 clipSprite3D->addChild(sprite3D);
2259 clipSprite3D->setPosition(Vec2(size.width / 2, size.height / 2));
2261 auto seq = Sequence::create(ScaleTo::create(2.f, 3), ScaleTo::create(2.f, 0.5f), NULL);
2262 sprite3D->runAction(RepeatForever::create(seq));
2263 auto animation = Animation3D::create(
"Sprite3DTest/orc.c3b");
2264 auto animate = Animate3D::create(animation);
2265 sprite3D->runAction(RepeatForever::create(animate));
2266 sprite3D->setForce2DQueue(
true);
2276 return "Sprite3D Clipping Test";
2286 FileUtils::getInstance()->addSearchPath(
"Particle3D/materials");
2287 FileUtils::getInstance()->addSearchPath(
"Particle3D/scripts");
2289 auto s = Director::getInstance()->getWinSize();
2290 _sprite3d = Sprite3D::create(
"Sprite3DTest/ReskinGirl.c3b");
2291 _sprite3d->setPosition(Vec2(s.width / 2.0f, s.height / 3.0f));
2293 _sprite3d->setRotation3D(Vec3(0.0f, 90.0f, 0.0f));
2296 _sprite3d->getMeshByName(
"Girl_UpperBody02")->setVisible(
false);
2297 _sprite3d->getMeshByName(
"Girl_LowerBody02")->setVisible(
false);
2298 _sprite3d->getMeshByName(
"Girl_Shoes02")->setVisible(
false);
2299 _sprite3d->getMeshByName(
"Girl_Hair02")->setVisible(
false);
2301 auto rootps = PUParticleSystem3D::create(
"explosionSystem.pu");
2302 rootps->stopParticleSystem();
2303 rootps->setScale(4.0f);
2304 this->addChild(rootps, 0, 100);
2306 auto animation = Animation3D::create(
"Sprite3DTest/ReskinGirl.c3b");
2309 auto animate = Animate3D::create(animation);
2310 _sprite3d->runAction(RepeatForever::create(animate));
2313 animate->setKeyFrameUserInfo(275, valuemap0);
2315 auto listener = EventListenerCustom::create(Animate3DDisplayedNotification, [&](EventCustom* event)
2317 auto info = (Animate3D::Animate3DDisplayedEventInfo*)event->getUserData();
2318 auto node = getChildByTag(100);
2321 auto mat =
_sprite3d->getNodeToWorldTransform() *
_sprite3d->getSkeleton()->getBoneByName(
"Bip01 R Hand")->getWorldMat();
2322 node->setPosition3D(Vec3(mat.m[12] + 100, mat.m[13], mat.m[14]));
2323 ((PUParticleSystem3D*)node)->startParticleSystem();
2327 cocos2d::log(
"frame %d", info->frame);
2329 Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(listener, -1);
2339 return "Testing Animate3D Callback";
2350 auto s = Director::getInstance()->getWinSize();
2352 auto sprite = Sprite3D::create(
"Sprite3DTest/box_VertexCol.c3t");
2353 sprite->setPosition(Vec2(0.0f, 0.0f));
2354 sprite->setScale(1.0f);
2355 sprite->setCameraMask(2);
2356 auto mat = Sprite3DMaterial::createWithFilename(
"Sprite3DTest/VertexColor.material");
2357 sprite->setMaterial(mat);
2358 sprite->runAction(RepeatForever::create(RotateBy::create(1.0f, Vec3(10.0f, 50.0f, 10.0f))));
2360 this->addChild(sprite);
2363 auto camera = Camera::createPerspective(40, s.width / s.height, 0.01f, 1000.f);
2364 camera->setCameraFlag(CameraFlag::USER1);
2365 camera->setPosition3D(Vec3(0.0f, 0.0f, 10.f));
2366 camera->lookAt(Vec3(0.f, 0.f, 0.f));
2369#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
2373 auto mat = Sprite3DMaterial::createWithFilename(
"Sprite3DTest/VertexColor.material");
2374 sprite->setMaterial(mat);
2383#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
2390 return "Testing Vertex Color";
2400 TTFConfig ttfConfig(
"fonts/arial.ttf", 20);
2401 auto label1 = Label::createWithTTF(ttfConfig,
"Clear Mode");
2406 auto pMenu1 = Menu::create(item1,
nullptr);
2407 pMenu1->setPosition(Vec2(0.0f,0.0f));
2408 this->addChild(pMenu1, 10);
2411 auto s = Director::getInstance()->getWinSize();
2412 _camera = Camera::createPerspective(40, s.width / s.height, 0.01f, 1000.f);
2413 _camera->setCameraFlag(CameraFlag::USER1);
2414 _camera->setPosition3D(Vec3(0.f, 30.f, 100.f));
2415 _camera->lookAt(Vec3(0.f, 0.f, 0.f));
2418 auto sprite = Sprite3D::create(
"Sprite3DTest/orc.c3b");
2420 sprite->setCameraMask(2);
2422 _label = Label::createWithTTF(ttfConfig,
"Depth Clear Brush");
2429 auto brush =
_camera->getBackgroundBrush();
2430 CameraBackgroundBrush::BrushType type = CameraBackgroundBrush::BrushType::NONE;
2433 CCLOG(
"No brash found!");
2437 type = brush->getBrushType();
2440 if (type == CameraBackgroundBrush::BrushType::NONE)
2442 _camera->setBackgroundBrush(CameraBackgroundBrush::createDepthBrush(1.f));
2443 _label->setString(
"Depth Clear Brush");
2445 CCLOG(
"Background brush valid status is : %s",
_camera->isBrushValid() ?
"true" :
"false");
2447 else if (type == CameraBackgroundBrush::BrushType::DEPTH)
2449 _camera->setBackgroundBrush(CameraBackgroundBrush::createColorBrush(Color4F(1.f, 0.f, 0.f, 1.f), 1.f));
2450 _label->setString(
"Color Clear Brush");
2452 else if (type == CameraBackgroundBrush::BrushType::COLOR)
2454 _camera->setBackgroundBrush(CameraBackgroundBrush::createSkyboxBrush(
"Sprite3DTest/skybox/left.jpg",
"Sprite3DTest/skybox/right.jpg",
"Sprite3DTest/skybox/top.jpg",
"Sprite3DTest/skybox/bottom.jpg",
"Sprite3DTest/skybox/front.jpg",
"Sprite3DTest/skybox/back.jpg"));
2455 _label->setString(
"Skybox Clear Brush");
2457 else if (type == CameraBackgroundBrush::BrushType::SKYBOX)
2459 _camera->setBackgroundBrush(CameraBackgroundBrush::createNoneBrush());
2460 _label->setString(
"None Clear Brush");
2466 return "Camera Background Clear Brush";
2476 auto s = Director::getInstance()->getWinSize();
2478 auto camera = Camera::createPerspective(40, s.width / s.height, 0.01f, 1000.f);
2479 camera->setCameraFlag(CameraFlag::USER1);
2480 camera->setPosition3D(Vec3(0.f, 50.f, 200.f));
2481 camera->lookAt(Vec3(0.f, 0.f, 0.f));
2484 auto sprite = Sprite3D::create(
"Sprite3DTest/orc.c3b");
2485 sprite->setPosition(20.f, 0.f);
2488 auto streak = MotionStreak3D::create(1.0f, 1.0f, 5.f, Color3B(255, 255, 0),
"Images/Icon.png");
2499 return "MotionStreak3D Test";
2510 float angle = t * M_PI;
2513 _sprite->setPosition3D(Vec3(r * cosf(angle), 0, r * sinf(angle)));
2515 _streak->setSweepAxis(Vec3(cosf(angle), 0, sinf(angle)));
2520 auto s = Director::getInstance()->getWinSize();
2523 auto sprite = Sprite3D::create(
"Sprite3DTest/sphere.c3b");
2524 sprite->setPosition(Vec2(-30.0f, 0.0f));
2525 sprite->setRotation3D(Vec3(90.0f, 0.0f, 0.0f));
2526 sprite->setScale(2.0);
2527 sprite->setCameraMask(2);
2528 sprite->setTexture(
"Sprite3DTest/brickwork-texture.jpg");
2532 int maxAttributes = Configuration::getInstance()->getMaxAttributes();
2533 CCASSERT(maxAttributes > 8,
"attributes supported must be greater than 8");
2534 if (maxAttributes > 8)
2536 auto sprite = Sprite3D::create(
"Sprite3DTest/sphere_bumped.c3b");
2537 sprite->setPosition(Vec2(30.0f, 0.0f));
2538 sprite->setRotation3D(Vec3(90.0f, 0.0f, 0.0f));
2539 sprite->setScale(20.0);
2540 sprite->setCameraMask(2);
2541 sprite->setTexture(
"Sprite3DTest/brickwork-texture.jpg");
2546 auto camera = Camera::createPerspective(60.0, s.width / s.height, 1.0f, 1000.f);
2547 camera->setCameraFlag(CameraFlag::USER1);
2548 camera->setPosition3D(Vec3(0.f, 0.f, 100.f));
2549 camera->lookAt(Vec3(0.f, 0.f, 0.f));
2552 PointLight* light = PointLight::create(Vec3(0.0, 0.0, 0.0), Color3B(255, 255, 255), 1000);
2561 static float angle = 0.0f;
2562 static bool reverseDir =
false;
2563 static float radius = 100.0f;
2565 auto light =
static_cast<PointLight*
>(getChildByTag(100));
2566 light->setPosition3D(Vec3(radius * cos(angle), 0.0f, radius * sin(angle)));
2574 if (3.14159 < angle)
2586 return "NormalMapping Test";
2599 auto s = Director::getInstance()->getWinSize();
2601 auto camera = Camera::createPerspective(40, s.width / s.height, 0.01f, 1000.f);
2602 camera->setCameraFlag(CameraFlag::USER1);
2603 camera->setPosition3D(Vec3(0.f, 50.f, 200.f));
2604 camera->lookAt(Vec3(0.f, 0.f, 0.f));
2607 _sprite = Sprite3D::create(
"Sprite3DTest/orc.c3b");
2608 _sprite->setPosition(20.f, 0.f);
2609 _sprite->setRotation3D(Vec3(0.0f, 180.0f, 0.0f));
2620 TTFConfig ttfConfig(
"fonts/arial.ttf", 20);
2622 auto label1 = Label::createWithTTF(ttfConfig,
"Print Mesh Name");
2624 auto label2 = Label::createWithTTF(ttfConfig,
"Remove Used Texture");
2626 auto label3 = Label::createWithTTF(ttfConfig,
"Reset");
2633 auto pMenu1 = Menu::create(item1, item2, item3,
nullptr);
2634 pMenu1->setPosition(Vec2(0.0f, 0.0f));
2635 this->addChild(pMenu1, 10);
2641 return "Sprite3DPropertyTest Test";
2654 CCLOG(
"MeshName Begin");
2655 Vector<Mesh*> meshes =
_sprite->getMeshes();
2656 for(Mesh* mesh : meshes)
2658 log(
"MeshName: %s ", mesh->getName().c_str());
2660 CCLOG(
"MeshName End");
2666 Director::getInstance()->getTextureCache()->removeTexture(
_meshTex);
2682 Vector<Mesh*> meshes =
_sprite->getMeshes();
2683 for (Mesh* mesh : meshes)
2685 std::string file = mesh->getTextureFileName();
2686 Texture2D* cacheTex = Director::getInstance()->getTextureCache()->getTextureForKey(file);
2687 if (cacheTex ==
nullptr)
2689 unsigned char data[] = { 255, 0, 0, 255 };
2690 Image * image =
new (std::nothrow) Image();
2691 image->initWithRawData(data,
sizeof(data), 1, 1,
sizeof(
unsigned char));
2692 cacheTex = Director::getInstance()->getTextureCache()->addImage(image,
"/dummyTexture");
2695 mesh->setTexture(cacheTex, cocos2d::NTextureData::Usage::Diffuse,
false);
2704 auto s = Director::getInstance()->getWinSize();
2706 auto sprite = Sprite3D::create(
"Sprite3DTest/orc.c3b");
2708 int rcBefore = sprite->getMeshByIndex(0)->getTexture()->getReferenceCount();
2710 removeChild(sprite);
2712 cocos2d::log(
"Issue 16155: Ref count:%d. Run this test again. RC should be the same", rcBefore);
2717 return "Issue16155 Test";
2721 return "Should not leak texture. See console";
#define ADD_TEST_CASE(__className__)
cocos2d::Sprite3D * _sprite3d
virtual std::string title() const override
virtual std::string subtitle() const override
virtual void update(float dt) override
virtual std::string title() const override
cocos2d::MoveTo * _moveAction
virtual std::string subtitle() const override
void onTouchesEnded(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
cocos2d::Sprite3D * _sprite
cocos2d::Animate3D * _hurt
virtual ~AsyncLoadSprite3DTest()
std::vector< std::string > _paths
void menuCallback_asyncLoadSprite(cocos2d::Ref *sender)
virtual std::string title() const override
virtual std::string subtitle() const override
void asyncLoad_Callback(cocos2d::Sprite3D *sprite, void *param)
void addNewSpriteWithCoords(cocos2d::Vec2 p)
virtual std::string subtitle() const override
void onTouchesEnded(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
virtual std::string title() const override
cocos2d::Sprite3D * _sprite
CameraBackgroundClearTest()
void switch_CameraClearMode(cocos2d::Ref *sender)
virtual std::string subtitle() const override
virtual std::string title() const override
cocos2d::Camera * _camera
static cocos2d::DrawNode3D * create()
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string subtitle() const override
void menuCallback_SwitchShader(cocos2d::Ref *sender)
virtual std::string title() const override
cocos2d::Sprite3D * _sprite
virtual std::string subtitle() const override
cocos2d::MotionStreak3D * _streak
cocos2d::Sprite3D * _sprite
virtual std::string title() const override
virtual void update(float delta) override
virtual std::string subtitle() const override
virtual std::string title() const override
void addNewSpriteWithCoords(cocos2d::Vec2 p)
std::vector< cocos2d::Sprite3D * > _sprites
virtual void update(float delta) override
cocos2d::Sprite3D * _sprite
virtual std::string title() const override
void addNewSpriteWithCoords(cocos2d::Vec2 p)
virtual std::string subtitle() const override
virtual std::string title() const override
void addNewSpriteWithCoords(cocos2d::Vec2 p)
void onTouchesEnded(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
virtual std::string subtitle() const override
virtual std::string title() const override
Sprite3DBasicToonShaderTest()
virtual std::string subtitle() const override
virtual ~Sprite3DBasicToonShaderTest()
cocos2d::EventListenerCustom * _backToForegroundListener
cocos2d::backend::ProgramState * _state
virtual std::string title() const override
virtual std::string subtitle() const override
void addNewSpriteWithCoords(cocos2d::Vec2)
virtual std::string subtitle() const override
void onTouchesMoved(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
virtual std::string title() const override
cocos2d::TextureCube * _textureCube
cocos2d::Sprite3D * _teapot
cocos2d::Skybox * _skyBox
cocos2d::Camera * _camera
cocos2d::EventListenerCustom * _backToForegroundListener
cocos2d::EventListenerCustom * _backToForegroundListener
void addNewSpriteWithCoords(cocos2d::Vec2 p)
virtual std::string subtitle() const override
void onTouchesEnded(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
virtual std::string title() const override
virtual ~Sprite3DEffectTest()
std::vector< cocos2d::Sprite3D * > _sprites
virtual std::string subtitle() const override
virtual std::string title() const override
cocos2d::EventListenerCustom * _backToForegroundListener
bool isState(unsigned int state, unsigned int bit) const
void move3D(float elapsedTime)
virtual std::string title() const override
void Move(cocos2d::Ref *sender, int value)
cocos2d::Sprite3D * _plane
void onTouchesBegan(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
void updateState(float elapsedTime)
cocos2d::Camera * _camera
virtual std::string subtitle() const override
cocos2d::backend::ProgramState * _state
virtual ~Sprite3DFakeShadowTest()
void onTouchesEnded(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
void onTouchesMoved(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
void updateCamera(float fDelta)
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string subtitle() const override
cocos2d::Camera * _camera
virtual std::string title() const override
void onTouchesMoved(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
virtual ~Sprite3DLightMapTest()
void addNewSpriteWithCoords(cocos2d::Vec2 p)
cocos2d::Sprite3D * _mirrorSprite
cocos2d::Sprite3D * _sprite
virtual std::string subtitle() const override
virtual std::string title() const override
virtual void update(float dt) override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual ~Sprite3DNormalMappingTest()
Sprite3DNormalMappingTest()
virtual std::string subtitle() const override
void refreshSpriteRender()
virtual std::string title() const override
void resetTexture(cocos2d::Ref *sender)
void printMeshName(cocos2d::Ref *sender)
cocos2d::Texture2D * _meshTex
cocos2d::Sprite3D * _sprite
void removeUsedTexture(cocos2d::Ref *sender)
virtual void update(float delta) override
cocos2d::Sprite3D * _sprite
void onTouchesEnded(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
std::vector< std::string > _skins[(int) SkinType::MAX_TYPE]
virtual std::string title() const override
void menuCallback_reSkin(cocos2d::Ref *sender)
void addNewSpriteWithCoords(cocos2d::Vec2 p)
int _curSkin[(int) SkinType::MAX_TYPE]
virtual std::string subtitle() const override
virtual std::string title() const override
virtual ~Sprite3DTestDemo()
Sprite3DUVAnimationTest()
cocos2d::backend::ProgramState * _state
virtual std::string subtitle() const override
virtual std::string title() const override
virtual ~Sprite3DUVAnimationTest()
cocos2d::EventListenerCustom * _backToForegroundListener
void cylinderUpdate(float dt)
float _cylinder_texture_offset
cocos2d::EventListenerCustom * _backToForegroundListener
virtual ~Sprite3DVertexColorTest()
Sprite3DVertexColorTest()
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual ~Sprite3DWithSkinOutlineTest()
cocos2d::EventListenerCustom * _backToForegroundListener
virtual std::string subtitle() const override
void addNewSpriteWithCoords(cocos2d::Vec2 p)
std::vector< cocos2d::Sprite3D * > _sprites
void onTouchesEnded(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
Sprite3DWithSkinOutlineTest()
std::vector< cocos2d::Sprite3D * > _sprits
virtual std::string title() const override
void switchAnimationQualityCallback(cocos2d::Ref *sender)
std::string getAnimationQualityMessage() const
void addNewSpriteWithCoords(cocos2d::Vec2 p)
void onTouchesEnded(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
cocos2d::MenuItemFont * _menuItem
virtual std::string subtitle() const override
virtual std::string subtitle() const override
virtual std::string title() const override
std::string _useCaseTitles[(int) USECASE::MAX_CASE_NUM]
virtual void update(float delta) override
void menuCallback_Message(cocos2d::Ref *sender)
static cocos2d::Vec2 top()
static cocos2d::Vec2 bottom()
static cocos2d::Vec2 left()