Skip to content

Commit d98adb7

Browse files
author
Huabing.Xu
committed
Merge pull request #10 from dabingnn/mesh3d_work
Mesh3d work
2 parents 300eb4e + 946283b commit d98adb7

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

cocos/3d/CCSprite3D.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,10 @@ bool Sprite3D::loadFromObj(const std::string& path)
129129
return true;
130130
}
131131

132-
Sprite3D::Sprite3D(): _partcount(0), _mesh(nullptr)
132+
Sprite3D::Sprite3D()
133+
: _partcount(0)
134+
, _mesh(nullptr)
135+
, _blend(BlendFunc::DISABLE)
133136
{
134137
}
135138

@@ -237,9 +240,9 @@ void Sprite3D::onDraw(const Matrix &transform, bool transformUpdated)
237240
{
238241
glEnable(GL_DEPTH_TEST);
239242
glEnable(GL_CULL_FACE);
243+
GL::blendFunc(_blend.src, _blend.dst);
240244
// ********** Base Draw *************
241245

242-
243246
Color4F color(getDisplayedColor());
244247
color.a = getDisplayedOpacity() / 255.0f;
245248

@@ -308,5 +311,18 @@ void Sprite3D::onDraw(const Matrix &transform, bool transformUpdated)
308311

309312
}
310313

314+
void Sprite3D::setBlendFunc(const BlendFunc &blendFunc)
315+
{
316+
if(_blend.src != blendFunc.src || _blend.dst != blendFunc.dst)
317+
{
318+
_blend = blendFunc;
319+
}
320+
}
321+
322+
const BlendFunc& Sprite3D::getBlendFunc() const
323+
{
324+
return _blend;
325+
}
326+
311327

312328
NS_CC_END

cocos/3d/CCSprite3D.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "base/ccTypes.h"
99
#include "2d/CCNode.h"
10+
#include "2d/CCProtocols.h"
1011

1112
#include "renderer/CCCustomCommand.h"
1213

@@ -16,23 +17,18 @@ class GLProgramState;
1617
class Mesh;
1718
class Texture2D;
1819

19-
class Sprite3D : public Node
20+
class Sprite3D : public Node, public BlendProtocol
2021
{
2122
public:
2223
static Sprite3D* create(const std::string &modelPath);
2324
static Sprite3D* create(const std::string &modelPath, const std::string &texturePath);
24-
//static Sprite3D* create(Mesh* mesh, const std::string& texturePath);
25-
//todo add if we need multitexture in the sprite3d
26-
//static Sprite3D* create(const std::string &modelPath, const std::vector<std::string> &texturePath);
27-
//static Sprite3D* create(const std::string &modelPath, const std::vector<std::string> &texturePath);
28-
29-
int getMeshPartCount() const;
30-
31-
Mesh* getMesh() const { return _mesh; }
3225

3326
void setTexture(const std::string& texFile);
3427
//void setTexture(Texture2D* texture);
35-
28+
29+
virtual void setBlendFunc(const BlendFunc &blendFunc) override;
30+
virtual const BlendFunc &getBlendFunc() const override;
31+
3632
protected:
3733
Sprite3D();
3834
virtual ~Sprite3D();
@@ -47,6 +43,10 @@ class Sprite3D : public Node
4743

4844
virtual GLProgram* getDefGLProgram(bool textured = true);
4945

46+
int getMeshPartCount() const;
47+
48+
Mesh* getMesh() const { return _mesh; }
49+
5050
CustomCommand _customCommand;
5151
Mesh *_mesh;
5252

@@ -59,7 +59,8 @@ class Sprite3D : public Node
5959
//Sprite3DEffect* _effect;
6060

6161
std::string _path;
62-
62+
63+
BlendFunc _blend;
6364

6465
};
6566

0 commit comments

Comments
 (0)