From 18d06015c6ad1992ef23578a10ed2f37f167ab6e Mon Sep 17 00:00:00 2001 From: songchengjiang Date: Tue, 2 Sep 2014 11:24:19 +0800 Subject: [PATCH 1/2] Added More Models Code optimization --- cocos/3d/CCBillBoard.cpp | 7 +-- cocos/renderer/CCRenderer.cpp | 2 +- .../Classes/Sprite3DTest/Sprite3DTest.cpp | 54 +++++++++++++------ 3 files changed, 43 insertions(+), 20 deletions(-) diff --git a/cocos/3d/CCBillBoard.cpp b/cocos/3d/CCBillBoard.cpp index 62279374e2..f4c5004324 100644 --- a/cocos/3d/CCBillBoard.cpp +++ b/cocos/3d/CCBillBoard.cpp @@ -93,12 +93,13 @@ BillBorad* BillBorad::create() void BillBorad::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) { auto camera = Camera::getVisitingCamera(); - if (memcmp(_preViewMat.m, camera->getViewMatrix().m, sizeof(float) * 16) != 0) + const Mat4 &viewMat = camera->getViewMatrix(); + if (memcmp(_preViewMat.m, viewMat.m, sizeof(float) * 16) != 0) { Mat4 viewInverseMat = camera->getInverseViewMatrix(); viewInverseMat.m[12] = viewInverseMat.m[13] = viewInverseMat.m[14] = 0; - Mat4 modelViewMat = camera->getViewMatrix() * transform; - _preViewMat = camera->getViewMatrix(); + Mat4 modelViewMat = viewMat * transform; + _preViewMat = viewMat; _zDepthInView = -modelViewMat.m[14]; _mv = viewInverseMat; } diff --git a/cocos/renderer/CCRenderer.cpp b/cocos/renderer/CCRenderer.cpp index 8b06f4fa41..71e8f0ee7e 100644 --- a/cocos/renderer/CCRenderer.cpp +++ b/cocos/renderer/CCRenderer.cpp @@ -459,7 +459,7 @@ void Renderer::render() //Process render commands //draw transparent objects here, do not batch for transparent objects - if (_transparentRenderGroups.size()) + if (0 < _transparentRenderGroups.size()) { _transparentRenderGroups.sort(); glEnable(GL_DEPTH_TEST); diff --git a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp index 7d85db66cf..1d471013e9 100644 --- a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp +++ b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp @@ -1538,7 +1538,6 @@ BillBoardTest::BillBoardTest() auto layer3D=Layer::create(); addChild(layer3D,0); _layerBillBorad=layer3D; - DrawNode3D* line =DrawNode3D::create(); auto s = Director::getInstance()->getWinSize(); if (_camera == nullptr) { @@ -1551,8 +1550,8 @@ BillBoardTest::BillBoardTest() { std::string fileName = "Sprite3DTest/orc.c3b"; auto sprite = Sprite3D::create(fileName); - sprite->setScale(3); sprite->setRotation3D(Vec3(0,180,0)); + sprite->setScale(2.0f); _layerBillBorad->addChild(sprite); //test attach auto sp = Sprite3D::create("Sprite3DTest/axe.c3b"); @@ -1564,6 +1563,43 @@ BillBoardTest::BillBoardTest() sprite->runAction(RepeatForever::create(animate)); } } + + { + std::string fileName = "Sprite3DTest/orc.c3b"; + auto sprite = Sprite3D::create(fileName); + sprite->setRotation3D(Vec3(0,180,0)); + sprite->setPosition3D(Vec3(100.0f, 0.0f, 0.0f)); + sprite->setScale(2.0f); + _layerBillBorad->addChild(sprite); + //test attach + auto sp = Sprite3D::create("Sprite3DTest/axe.c3b"); + sprite->getAttachNode("Bip001 R Hand")->addChild(sp); + auto animation = Animation3D::create(fileName); + if (animation) + { + auto animate = Animate3D::create(animation); + sprite->runAction(RepeatForever::create(animate)); + } + } + + { + std::string fileName = "Sprite3DTest/orc.c3b"; + auto sprite = Sprite3D::create(fileName); + sprite->setRotation3D(Vec3(0,180,0)); + sprite->setPosition3D(Vec3(-100.0f, 0.0f, 0.0f)); + sprite->setScale(2.0f); + _layerBillBorad->addChild(sprite); + //test attach + auto sp = Sprite3D::create("Sprite3DTest/axe.c3b"); + sprite->getAttachNode("Bip001 R Hand")->addChild(sp); + auto animation = Animation3D::create(fileName); + if (animation) + { + auto animate = Animate3D::create(animation); + sprite->runAction(RepeatForever::create(animate)); + } + } + addNewBillBoradWithCoords(Vec3(20,5,0)); addNewBillBoradWithCoords(Vec3(60,5,0)); addNewBillBoradWithCoords(Vec3(100,5,0)); @@ -1577,20 +1613,6 @@ BillBoardTest::BillBoardTest() _camera->setPosition3D(Vec3(0, 130, 230)); _camera->lookAt(Vec3(0,0,100), Vec3(0,1,0)); - //for( int j =-20; j<=20 ;j++) - //{ - // line->drawLine(Vec3(-100, 0, 5*j),Vec3(100,0,5*j),Color4F(0,1,0,1)); - //} - ////draw z - //for( int j =-20; j<=20 ;j++) - //{ - // line->drawLine(Vec3(5*j, 0, -100),Vec3(5*j,0,100),Color4F(0,1,0,1)); - //} - ////draw y - ////line->drawLine(Vec3(0, -50, 0),Vec3(0,0,0),Color4F(0,0.5,0,1)); - ////line->drawLine(Vec3(0, 0, 0),Vec3(0,50,0),Color4F(0,1,0,1)); - //_layerBillBorad->addChild(line); - TTFConfig ttfConfig("fonts/arial.ttf", 20); auto label1 = Label::createWithTTF(ttfConfig,"rotate+"); auto menuItem1 = MenuItemLabel::create(label1, CC_CALLBACK_1(BillBoardTest::rotateCameraCallback,this,10)); From 8a88ba6142b3fafb8e7dcf474ddaf75be4b77a6d Mon Sep 17 00:00:00 2001 From: songchengjiang Date: Tue, 2 Sep 2014 11:50:09 +0800 Subject: [PATCH 2/2] Tab Format --- cocos/3d/CCBillBoard.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/3d/CCBillBoard.cpp b/cocos/3d/CCBillBoard.cpp index f4c5004324..7d7523772e 100644 --- a/cocos/3d/CCBillBoard.cpp +++ b/cocos/3d/CCBillBoard.cpp @@ -93,7 +93,7 @@ BillBorad* BillBorad::create() void BillBorad::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) { auto camera = Camera::getVisitingCamera(); - const Mat4 &viewMat = camera->getViewMatrix(); + const Mat4 &viewMat = camera->getViewMatrix(); if (memcmp(_preViewMat.m, viewMat.m, sizeof(float) * 16) != 0) { Mat4 viewInverseMat = camera->getInverseViewMatrix();