diff --git a/cocos/3d/CCSprite3D.cpp b/cocos/3d/CCSprite3D.cpp index fae0687f8b..13f0470c63 100644 --- a/cocos/3d/CCSprite3D.cpp +++ b/cocos/3d/CCSprite3D.cpp @@ -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(); diff --git a/cocos/3d/CCSprite3D.h b/cocos/3d/CCSprite3D.h index 0be8465c1c..cec60085c7 100644 --- a/cocos/3d/CCSprite3D.h +++ b/cocos/3d/CCSprite3D.h @@ -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); diff --git a/cocos/renderer/CCRenderer.cpp b/cocos/renderer/CCRenderer.cpp index b5bc86dac6..ec98446b11 100644 --- a/cocos/renderer/CCRenderer.cpp +++ b/cocos/renderer/CCRenderer.cpp @@ -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) diff --git a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp index f02b4f8b2c..1f05acf883 100644 --- a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp +++ b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp @@ -68,7 +68,8 @@ static std::function 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"; +} //------------------------------------------------------------------ // diff --git a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h index 6271a3b50d..d321ac29d8 100644 --- a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h +++ b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h @@ -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: