1. Sprite3DBasicTest Sprite3D 两种基本创建方式
(1). 直接使用一个带有素材的obj (3dmax对象)
Sprite3D::create("sprite3dTest/scene01.obj");
(2). 使用不带素材的对象,自己设置素材
auto sprite = Sprite3D::create("Sprite3DTest/boss1.obj");
sprite->setScale(3.f);
sprite->setTexture("Sprite3DTest/boss.png");
(3)
auto sprite = EffectSprite3D::createFromObjFileAndTexture("Sprite3DTest/boss1.obj", "Sprite3DTest/boss.png");
2. Sprite3DHitTest 拖拽
(1) 点击 在onTouchBegan 中设置透明度 target->setOpacity(100);
放手在 onTouchEnded中还原透明度 target->setOpacity(255);
(2) 移动 onTouchMoved
target->setPosition(target->getPosition() + touch->getDelta());
(3) addEventListenerWithSceneGraphPriority 更具sprite的z order决定丢用先后
3. Sprite3DEffectTest 一些shader 的运用例子
将具体实现封装到了Effect3DOutline中
4.加载3dmax导出的文件,使用fbx-conv.exe转化
std::string fileName = "Sprite3DTest/orc.c3b";
auto sprite = EffectSprite3D::create(fileName);
5. Sprite3DWithSkinOutlineTest shader特效在c3b的运用
6. Animate3DTest 动画的播放和切换 小乌龟的demo
(1) 同一个c3b既可以创建sprite也可以创建action
std::string fileName ="Sprite3DTest/tortoise.c3b";
auto sprite = Sprite3D::create(fileName);
sprite->setScale(0.1f);
auto s =Director::getInstance()->getWinSize();
sprite->setPosition(Vec2(s.width *4.f / 5.f, s.height /2.f));
addChild(sprite);
_sprite = sprite;
auto animation = Animation3D::create(fileName);
(2) animation 可以通过 时间来分拆,这个时间是在3Dmax中定义的
if (animation)
{ //2个动画的时间不同,这些在3Dmax中定义
auto animate = Animate3D::create(animation, 0.f,1.933f);
_swim = RepeatForever::create(animate);
sprite->runAction(_swim);
_swim->retain();
_hurt = Animate3D::create(animation,1.933f, 2.8f);
_hurt->retain();
_state = State::SWIMMING;
}
(3)乌龟游到尽头 调用 reachEndCallBack
通过reverse获得相反的action
auto inverse = (MoveTo*)_moveAction->reverse();
沿y轴180度转向
auto rot = RotateBy::create(1.f, Vec3(0.f, 180.f, 0.f));
(4)在onTouchesEnded中实现播放乌龟的 hurt动作 ,但是这里没法实现hurt动作的结束回调,所以采用_hurt->getDuration()
来获得其结束时间,并且做一个renewCallBack来回到_swim 动作
auto delay = DelayTime::create(_hurt->getDuration() - Animate3D::getTransitionTime());
auto seq = Sequence::create(delay, CallFunc::create(CC_CALLBACK_0(Animate3DTest::renewCallBack, this)), nullptr);
疑问? Animate3D::getTransitionTime() 用来干嘛
为啥会用void Animate3DTest::update(float dt) 来维护一个中间状态 HURT_TO_SWIMMING 和SWIMMING_TO_HURT
7. AttachmentTest 装武器
获取某个骨骼,Bip001 R Hand是在3Dmax定义的
auto sp = Sprite3D::create("Sprite3DTest/axe.c3b");
sprite->getAttachNode("Bip001 R Hand")->addChild(sp);
点击后去掉附加节点
_sprite->removeAllAttachNode();
8. Sprite3DReskinTest 皮肤换装, 动态更换材质(mesh)
(1)字号字体
TTFConfig ttfConfig("fonts/arial.ttf", 20);
auto label1 = Label::createWithTTF(ttfConfig,"Hair");
应该是在3dm中定义好了mesh的名称?
_girlPants[0]= "Girl_LowerBody01";
_girlPants[1]= "Girl_LowerBody02";
_girlUpperBody[0] = "Girl_UpperBody01";
_girlUpperBody[1] = "Girl_UpperBody02";
_girlShoes[0] = "Girl_Shoes01";
_girlShoes[1] = "Girl_Shoes02";
_girlHair[0]= "Girl_Hair01";
_girlHair[1]= "Girl_Hair02";
(2) 初始化的时候隐藏备选的部分,点击切换的时候再 交换显示
auto girlPants = sprite->getMeshByName(_girlPants[1]);
if(girlPants)
{
girlPants->setVisible(false);
}
9.Sprite3DWithOBBPerfromanceTest 包围盒与3D模型碰撞的实现
?
10.Sprite3DMirrorTest 3D模型的镜像
?
常用总结:
1. 3d 纬度的朝向设置
sprite->setRotation3D(Vec3(0,180,0));
2. sprite->setEffect() 添加特效
3.sprite->getAttachNode("Bip001 R Hand") 获取某个骨骼
4. sprite->getMeshByName(_girlPants[1]); 获取材质
参考 Cocos2d-x 3.3 的3D开发功能介绍 http://cn.cocos2d-x.org/tutorial/show?id=1582