我armature 骨骼动画绑定 到box2d 获取不到形状

我参考了cocostudio 上的GameDemo例子

先建立一个世界

CCSize s = CCDirector::sharedDirector()->getVisibleSize();

m_world = new b2World(b2Vec2(0.0f, 0.0f));
m_world->SetAllowSleeping(true);
m_world->SetContinuousPhysics(true);
m_world->SetContactListener(this);

// 再建立一个地板
//地板body
b2Body* ground = NULL;
b2BodyDef bd;
ground = m_world->CreateBody(&bd);

//地板 ---定义边缘形状
b2EdgeShape shape;

//底部
shape.Set(b2Vec2(0, -1),b2Vec2(s.width/RATIO, -1));
ground->CreateFixture(&shape, 0.0f);
setDebug(true);

//一个人物的armature

b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
bodyDef.linearVelocity = b2Vec2(10, 0);
b2Body* body = m_world->CreateBody(&bodyDef);

b2Fixture *fixture = body->GetFixtureList();
if(fixture != NULL)
{
fixture->SetUserData(player);
b2Filter filter = fixture->GetFilterData();
filter.categoryBits = HERO;
filter.groupIndex = PLAYER_GROUPINDEX;
fixture->SetFilterData(filter);
}

我每次运行的时候我的armature都会穿过 我划的那条线,不会产生碰撞,请问这事什么原因呢? 是因为我没有成功获取骨骼的shape吗?

是不是还有一种方法
,通过下面的方法,把骨骼动画中的每一块都做成一个body,然后连接起来,到底是用哪种方法呢?

const Map<std::string, Bone*>& map = armature2->getBoneDic();//得到骨骼字典
for(const auto& element : map)//遍历字典
{
Bone *bone = element.second;
ColliderDetector *detector = bone->getColliderDetector();

    if (!detector)//如否没有碰撞 跳过 继续遍历   
        continue;  
    //得到碰撞框列表   
    const cocos2d::Vector<ColliderBody*>& bodyList = detector->getColliderBodyList();  

    for (const auto& object : bodyList)  
    {  
        //得到一个碰撞框   
        ColliderBody *body = static_cast<ColliderBody*>(object);  
        //一个碰撞框包含的所有顶点   
        const std::vector<Point> &vertexList = body->getCalculatedVertexList();  

        float minx = 0, miny = 0, maxx = 0, maxy = 0;  
         int length = (int)vertexList.size();//顶点个数   
        for (int i = 0; i<length; i++)  
        {  
            Point vertex = vertexList.at(i);  
            if (i == 0)  
            {  
                minx = maxx = vertex.x;//起点和终点 是 第一个点   
                miny = maxy = vertex.y;  
            }  
            else//遍历所有点 得到4个最值   
            {  
                minx = vertex.x < minx ? vertex.x : minx;  
                miny = vertex.y < miny ? vertex.y : miny;  
                maxx = vertex.x > maxx ? vertex.x : maxx;  
                maxy = vertex.y > maxy ? vertex.y : maxy;  
            }  
        }  
        Rect temp = Rect(minx, miny, maxx - minx, maxy - miny);//组成一个包含所有顶点的矩形   

        if (temp.intersectsRect(rect))  
        {  
            //子弹矩形在碰撞区域内 碰撞框不可见   
            armature2->setVisible(false);  
        }  
    }

我用第一种方法人物armature 和 我手动画的那条地板相碰的时候会 透视过地板。

我在世界里 建了个球

role = CCSprite::create(“CloseNormal.png”);
CCSize size = role->getContentSize();
role->setPosition(ccp(900, 600));

//将物理世界的精灵创建Box2D物体
b2BodyDef bodyDef;  
bodyDef.type = b2_dynamicBody;  
bodyDef.userData = role;  
bodyDef.position.Set(600 / RATIO, 1000 / RATIO);  
b2Body* body = m_world->CreateBody(&bodyDef);  

//定义形状
b2PolygonShape spriteShape; 
spriteShape.SetAsBox(size.width / 2 / RATIO, size.height / 2 / RATIO); 

//创建一个夹具的对象
b2FixtureDef fixDef;  
fixDef.shape = &spriteShape;  
fixDef.density = 10.0f;
body->CreateFixture(&fixDef);  

addChild(role,400);  

然后我建了一个骨骼动画

Armature* as = Armature::create(“hero1”);

                  b2BodyDef bodyDef;
        bodyDef.type = b2_dynamicBody;
        bodyDef.position.Set(600/RATIO, 300/RATIO);
        b2Body* body = m_world->CreateBody(&bodyDef);

        as->setBody(body);

b2Filter filter;
//filter.categoryBits = HERO;
//filter.maskBits = 2;
body->ResetMassData();
for (b2Fixture* shapes = getBody()->GetFixtureList(); shapes; shapes = shapes->GetNext())
{
shapes->SetSensor(false);
shapes->SetDensity(0.5f / CC_CONTENT_SCALE_FACTOR());
shapes->SetRestitution(0.0f);
shapes->SetFriction(0.2f);
shapes->SetDensity(1.0f);
shapes->SetFilterData(filter);
}
body->SetUserData(as);

这个球和我的骨骼 运行到重合的时候 并不执行碰撞,而是相互透过。

armature的shape获取方法是armature-》getshapelist()

看了源代码,好像只有box2d才能用到那个api,我用的是chipmunk,被条件编译了