bool Physics3DTestDemo::init()
{
    if (!TestCase::init()) return false;
    
    if (initWithPhysics())
    {
        getPhysics3DWorld()->setDebugDrawEnable(false);
        
        physicsScene = this;
        Size size = Director::getInstance()->getWinSize();
        _camera = Camera::createPerspective(30.0f, size.width / size.height, 1.0f, 1000.0f);
        _camera->setPosition3D(Vec3(0.0f, 50.0f, 100.0f));
        _camera->lookAt(Vec3(0.0f, 0.0f, 0.0f), Vec3(0.0f, 1.0f, 0.0f));
        _camera->setCameraFlag(CameraFlag::USER1);
        this->addChild(_camera);
        
        auto listener = EventListenerTouchAllAtOnce::create();
        listener->onTouchesBegan = CC_CALLBACK_2(Physics3DTestDemo::onTouchesBegan, this);
        listener->onTouchesMoved = CC_CALLBACK_2(Physics3DTestDemo::onTouchesMoved, this);
        listener->onTouchesEnded = CC_CALLBACK_2(Physics3DTestDemo::onTouchesEnded, this);
        _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
        
        TTFConfig ttfConfig("fonts/arial.ttf", 10);
        auto label = Label::createWithTTF(ttfConfig,"DebugDraw OFF");
        auto menuItem = MenuItemLabel::create(label, [=](Ref *ref){
            if (getPhysics3DWorld()->isDebugDrawEnabled()){
                getPhysics3DWorld()->setDebugDrawEnable(false);
                label->setString("DebugDraw OFF");
            }else{
                getPhysics3DWorld()->setDebugDrawEnable(true);
                label->setString("DebugDraw ON");
            }
        });

        auto menu = Menu::create(menuItem, nullptr);
        menu->setPosition(Vec2::ZERO);
        menuItem->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT);
        menuItem->setPosition( Vec2(VisibleRect::left().x, VisibleRect::top().y-50) );
        this->addChild(menu);

        _angle = 0.0f;
        return true;
    }
    physicsScene = nullptr;
    return false;
}
void Physics3DComponent::onEnter()
{
    Component::onEnter();
    
    if (_physics3DObj->getPhysicsWorld() == nullptr && _owner)
    {
        auto scene = _owner->getScene();
        if (scene)
            addToPhysicsWorld(scene->getPhysics3DWorld());
    }
}