mirror of https://github.com/axmolengine/axmol.git
Add support for creating empty sprite3D
This commit is contained in:
parent
45562f3203
commit
4335328e3d
|
@ -48,10 +48,23 @@ NS_CC_BEGIN
|
|||
|
||||
std::string s_attributeNames[] = {GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::ATTRIBUTE_NAME_COLOR, GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::ATTRIBUTE_NAME_TEX_COORD1, GLProgram::ATTRIBUTE_NAME_TEX_COORD2,GLProgram::ATTRIBUTE_NAME_TEX_COORD3,GLProgram::ATTRIBUTE_NAME_NORMAL, GLProgram::ATTRIBUTE_NAME_BLEND_WEIGHT, GLProgram::ATTRIBUTE_NAME_BLEND_INDEX};
|
||||
|
||||
Sprite3D* Sprite3D::create()
|
||||
{
|
||||
//
|
||||
auto sprite = new (std::nothrow) Sprite3D();
|
||||
if (sprite && sprite->init())
|
||||
{
|
||||
sprite->autorelease();
|
||||
return sprite;
|
||||
}
|
||||
CC_SAFE_DELETE(sprite);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Sprite3D* Sprite3D::create(const std::string &modelPath)
|
||||
{
|
||||
if (modelPath.length() < 4)
|
||||
CCASSERT(false, "improper name specified when creating Sprite3D");
|
||||
CCASSERT(false, "invalid filename for Sprite3D");
|
||||
|
||||
auto sprite = new (std::nothrow) Sprite3D();
|
||||
if (sprite && sprite->initWithFile(modelPath))
|
||||
|
@ -241,6 +254,15 @@ Sprite3D::~Sprite3D()
|
|||
removeAllAttachNode();
|
||||
}
|
||||
|
||||
bool Sprite3D::init()
|
||||
{
|
||||
if(Node::init())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Sprite3D::initWithFile(const std::string &path)
|
||||
{
|
||||
_meshes.clear();
|
||||
|
|
|
@ -50,6 +50,13 @@ struct NodeData;
|
|||
class CC_DLL Sprite3D : public Node, public BlendProtocol
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Creates an empty sprite3D without 3D model and texture.
|
||||
*
|
||||
* @return An autoreleased sprite3D object.
|
||||
*/
|
||||
static Sprite3D* create();
|
||||
|
||||
/** creates a Sprite3D*/
|
||||
static Sprite3D* create(const std::string &modelPath);
|
||||
|
||||
|
@ -138,6 +145,9 @@ CC_CONSTRUCTOR_ACCESS:
|
|||
|
||||
Sprite3D();
|
||||
virtual ~Sprite3D();
|
||||
|
||||
bool init();
|
||||
|
||||
bool initWithFile(const std::string &path);
|
||||
|
||||
bool initFrom(const NodeDatas& nodedatas, const MeshDatas& meshdatas, const MaterialDatas& materialdatas);
|
||||
|
|
|
@ -328,10 +328,7 @@ void Renderer::addCommand(RenderCommand* command, int renderQueue)
|
|||
CCASSERT(renderQueue >=0, "Invalid render queue");
|
||||
CCASSERT(command->getType() != RenderCommand::Type::UNKNOWN_COMMAND, "Invalid Command Type");
|
||||
|
||||
// if(command->isTransparent())
|
||||
// _transparentRenderGroups.push_back(command);
|
||||
// else
|
||||
_renderGroups[renderQueue].push_back(command);
|
||||
_renderGroups[renderQueue].push_back(command);
|
||||
}
|
||||
|
||||
void Renderer::pushGroup(int renderQueueID)
|
||||
|
|
|
@ -68,7 +68,8 @@ static std::function<Layer*()> createFunctions[] =
|
|||
CL(Sprite3DReskinTest),
|
||||
CL(Sprite3DWithOBBPerfromanceTest),
|
||||
CL(Sprite3DMirrorTest),
|
||||
CL(QuaternionTest)
|
||||
CL(QuaternionTest),
|
||||
CL(Sprite3DEmptyTest)
|
||||
};
|
||||
|
||||
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
|
||||
|
@ -154,6 +155,30 @@ void Sprite3DTestDemo::backCallback(Ref* sender)
|
|||
s->release();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Sprite3DEmptyTest
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
Sprite3DEmptyTest::Sprite3DEmptyTest()
|
||||
{
|
||||
auto s = Sprite3D::create();
|
||||
s->setNormalizedPosition(Vec2(.5,.5));
|
||||
auto l = Label::create();
|
||||
l->setString("Test");
|
||||
s->addChild(l);
|
||||
addChild(s);
|
||||
}
|
||||
|
||||
std::string Sprite3DEmptyTest::title() const
|
||||
{
|
||||
return "Testing Sprite3D Container";
|
||||
}
|
||||
|
||||
std::string Sprite3DEmptyTest::subtitle() const
|
||||
{
|
||||
return "Sprite3D can act as containers for 2D objects";
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
|
|
|
@ -54,6 +54,15 @@ public:
|
|||
virtual void onEnter() override;
|
||||
};
|
||||
|
||||
class Sprite3DEmptyTest : public Sprite3DTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Sprite3DEmptyTest);
|
||||
Sprite3DEmptyTest();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
class Sprite3DBasicTest : public Sprite3DTestDemo
|
||||
{
|
||||
public:
|
||||
|
|
Loading…
Reference in New Issue