真实两足骨骼物理模拟

发布于 2024-11-06 19:12:36 字数 261 浏览 6 评论 0原文

我希望利用子弹物理或类似的物理引擎来创建具有两条腿的类人身体的逼真骨骼模拟。也就是说,在两条“腿”的顶部创建一个由圆形质量组成的“身体”的模拟,其中每条腿由通过 3 个关节连接的 3 个实体块组成,每个关节都有一定的自由度和有限的运动范围。每个方向,类似于人类的臀部、膝盖和脚踝。

我的目标是建立一个真实的模型,因此只有当所有关节都正确平衡时它才会“站立”,否则就会掉落。

对于现有教程或资源的任何指示、建议或指示,我们将不胜感激!这看起来像是从头开始做的大量工作......

I wish to utilize bullet-physics or similar physical-engine to create a realistic skeleton simulation of human-like body with two legs. That is, create a simulation of "a body" made of round mass on top of two "legs", where each leg is made of 3 solid pieces connected through 3 joints and each joint have some degrees of freedom and a limited movement range in each direction, similar to human hip, knee and ankle.

I aim for a realistic model, and hence it will 'stand' only if all joints are balanced correctly and it will fall otherwise.

Any directions, suggestion or pointers to existing tutorials or resources is appreciated! This looks like an awful lot of work doing from scratch...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

南七夏 2024-11-13 19:12:36

查看 OpenSim 项目 (opensim.stanford.edu),生物力学界广泛使用该项目来研究人体运动,例如临床应用。在 OpenSim 中,人体模型通常由肌肉驱动,而不仅仅是由关节处的扭矩驱动。

OpenSim 构建在 Simbody 多体动力学库之上。请参阅 Simbody 中的示例,了解人形模型的运行情况: https://github.com/simbody/simbody/blob/master/Simbody/examples/JaredsDude.cpp

Check out the OpenSim project (opensim.stanford.edu), which is heavily used by the biomechanics community to study human movement for, e.g., clinical applications. In OpenSim, the human models are often actuated by muscles, not simply by torques at the joints.

OpenSim is built on top of the Simbody multibody dynamics library. See this example from Simbody to hit the ground running with a model of a humanoid: https://github.com/simbody/simbody/blob/master/Simbody/examples/JaredsDude.cpp.

故笙诉离歌 2024-11-13 19:12:36

我目前正在研究类似的代码。我的方法是使用子弹物理布娃娃演示作为起点。它有一个布娃娃,身体各部分通过关节连接。

然后,我使用 Bullet 物理动态控制演示来学习弯曲关节。目前具有挑战性的部分是设置所有参数。

我建议您学习如何创建两个通过约束连接的刚体,然后激活约束电机来弯曲关节。

以下是我正在使用的一些代码,用于了解刚体和约束在 Bullet 物理中的工作原理。该代码创建两个通过铰链约束连接的块。更新函数随着时间的推移缓慢地弯曲铰链约束。

现在我已经得到了这个,我将回到布娃娃并调整关节。

class Simple
{
private:
    btScalar targetAngle;

    btCollisionShape* alphaCollisionShape;
    btCollisionShape* bravoCollisionShape;
    btRigidBody* alphaRigidBody;
    btRigidBody* bravoRigidBody;
    btHingeConstraint* hingeConstraint;

    btDynamicsWorld* dynamicsWorld;

public:
    ~Simple( void )
    {
    }

    btRigidBody* createRigidBody( btCollisionShape* collisionShape, 
                  btScalar mass, 
                  const btTransform& transform ) const
    {
    // calculate inertia
    btVector3 localInertia( 0.0f, 0.0f, 0.0f );
    collisionShape->calculateLocalInertia( mass, localInertia );    

    // create motion state
    btDefaultMotionState* defaultMotionState 
        = new btDefaultMotionState( transform );

    // create rigid body
    btRigidBody::btRigidBodyConstructionInfo rigidBodyConstructionInfo( 
        mass, defaultMotionState, collisionShape, localInertia );
    btRigidBody* rigidBody = new btRigidBody( rigidBodyConstructionInfo );      

    return rigidBody;
    }

    void Init( btDynamicsWorld* dynamicsWorld )
    {
    this->targetAngle = 0.0f;

    this->dynamicsWorld = dynamicsWorld;

    // create collision shapes
    const btVector3 alphaBoxHalfExtents( 0.5f, 0.5f, 0.5f );
    alphaCollisionShape = new btBoxShape( alphaBoxHalfExtents );

    //
    const btVector3 bravoBoxHalfExtents( 0.5f, 0.5f, 0.5f );
    bravoCollisionShape = new btBoxShape( bravoBoxHalfExtents );

    // create alpha rigid body
    const btScalar alphaMass = 10.0f;
    btTransform alphaTransform;
    alphaTransform.setIdentity();
    const btVector3 alphaOrigin( 54.0f, 0.5f, 50.0f );  
    alphaTransform.setOrigin( alphaOrigin );
    alphaRigidBody = createRigidBody( alphaCollisionShape, alphaMass, alphaTransform );
    dynamicsWorld->addRigidBody( alphaRigidBody );

    // create bravo rigid body
    const btScalar bravoMass = 1.0f;
    btTransform bravoTransform;
    bravoTransform.setIdentity();
    const btVector3 bravoOrigin( 56.0f, 0.5f, 50.0f );  
    bravoTransform.setOrigin( bravoOrigin );
    bravoRigidBody = createRigidBody( bravoCollisionShape, bravoMass, bravoTransform );
    dynamicsWorld->addRigidBody( bravoRigidBody );

    // create a constraint
    const btVector3 pivotInA( 1.0f, 0.0f, 0.0f );   
    const btVector3 pivotInB( -1.0f, 0.0f, 0.0f );
    btVector3 axisInA( 0.0f, 1.0f, 0.0f );
    btVector3 axisInB( 0.0f, 1.0f, 0.0f );
    bool useReferenceFrameA = false;
    hingeConstraint = new btHingeConstraint( 
        *alphaRigidBody,
        *bravoRigidBody,
        pivotInA,
        pivotInB,
        axisInA,
        axisInB,
        useReferenceFrameA );

    // set constraint limit
    const btScalar low = -M_PI;
    const btScalar high = M_PI;
    hingeConstraint->setLimit( low, high );

    // add constraint to the world
    const bool isDisableCollisionsBetweenLinkedBodies = false;
    dynamicsWorld->addConstraint( hingeConstraint, 
                      isDisableCollisionsBetweenLinkedBodies );
    }

    void Update( float deltaTime )
    {
    alphaRigidBody->activate();
    bravoRigidBody->activate();

    bool isEnableMotor = true;
    btScalar maxMotorImpulse = 1.0f; // 1.0f / 8.0f is about the minimum

    hingeConstraint->enableMotor( isEnableMotor );
    hingeConstraint->setMaxMotorImpulse( maxMotorImpulse );

    targetAngle += 0.1f * deltaTime;
    hingeConstraint->setMotorTarget( targetAngle, deltaTime );  
    }

};

I'm working on similar code at the moment. My approach is use the Bullet Physics Rag Doll Demo as a starting point. It has a rag doll with body parts connected by joints.

I'm then using the Bullet Physics Dynamic Control Demo to learn to bend the joints. The challenging part at the moment is setting all the parameters.

I suggest you learn how to create two rigid bodies connected by a constraint and then to activate the constraint motor to bend the joint.

The following is some code that I'm working with to learn how rigid bodies and constraints work in Bullet Physics. The code creates two blocks connected by a hinge constraint. The update function bends the hinge constraint slowly over time.

Now that I've got this I'll be going back to the Rag Doll and adjusting the joints.

class Simple
{
private:
    btScalar targetAngle;

    btCollisionShape* alphaCollisionShape;
    btCollisionShape* bravoCollisionShape;
    btRigidBody* alphaRigidBody;
    btRigidBody* bravoRigidBody;
    btHingeConstraint* hingeConstraint;

    btDynamicsWorld* dynamicsWorld;

public:
    ~Simple( void )
    {
    }

    btRigidBody* createRigidBody( btCollisionShape* collisionShape, 
                  btScalar mass, 
                  const btTransform& transform ) const
    {
    // calculate inertia
    btVector3 localInertia( 0.0f, 0.0f, 0.0f );
    collisionShape->calculateLocalInertia( mass, localInertia );    

    // create motion state
    btDefaultMotionState* defaultMotionState 
        = new btDefaultMotionState( transform );

    // create rigid body
    btRigidBody::btRigidBodyConstructionInfo rigidBodyConstructionInfo( 
        mass, defaultMotionState, collisionShape, localInertia );
    btRigidBody* rigidBody = new btRigidBody( rigidBodyConstructionInfo );      

    return rigidBody;
    }

    void Init( btDynamicsWorld* dynamicsWorld )
    {
    this->targetAngle = 0.0f;

    this->dynamicsWorld = dynamicsWorld;

    // create collision shapes
    const btVector3 alphaBoxHalfExtents( 0.5f, 0.5f, 0.5f );
    alphaCollisionShape = new btBoxShape( alphaBoxHalfExtents );

    //
    const btVector3 bravoBoxHalfExtents( 0.5f, 0.5f, 0.5f );
    bravoCollisionShape = new btBoxShape( bravoBoxHalfExtents );

    // create alpha rigid body
    const btScalar alphaMass = 10.0f;
    btTransform alphaTransform;
    alphaTransform.setIdentity();
    const btVector3 alphaOrigin( 54.0f, 0.5f, 50.0f );  
    alphaTransform.setOrigin( alphaOrigin );
    alphaRigidBody = createRigidBody( alphaCollisionShape, alphaMass, alphaTransform );
    dynamicsWorld->addRigidBody( alphaRigidBody );

    // create bravo rigid body
    const btScalar bravoMass = 1.0f;
    btTransform bravoTransform;
    bravoTransform.setIdentity();
    const btVector3 bravoOrigin( 56.0f, 0.5f, 50.0f );  
    bravoTransform.setOrigin( bravoOrigin );
    bravoRigidBody = createRigidBody( bravoCollisionShape, bravoMass, bravoTransform );
    dynamicsWorld->addRigidBody( bravoRigidBody );

    // create a constraint
    const btVector3 pivotInA( 1.0f, 0.0f, 0.0f );   
    const btVector3 pivotInB( -1.0f, 0.0f, 0.0f );
    btVector3 axisInA( 0.0f, 1.0f, 0.0f );
    btVector3 axisInB( 0.0f, 1.0f, 0.0f );
    bool useReferenceFrameA = false;
    hingeConstraint = new btHingeConstraint( 
        *alphaRigidBody,
        *bravoRigidBody,
        pivotInA,
        pivotInB,
        axisInA,
        axisInB,
        useReferenceFrameA );

    // set constraint limit
    const btScalar low = -M_PI;
    const btScalar high = M_PI;
    hingeConstraint->setLimit( low, high );

    // add constraint to the world
    const bool isDisableCollisionsBetweenLinkedBodies = false;
    dynamicsWorld->addConstraint( hingeConstraint, 
                      isDisableCollisionsBetweenLinkedBodies );
    }

    void Update( float deltaTime )
    {
    alphaRigidBody->activate();
    bravoRigidBody->activate();

    bool isEnableMotor = true;
    btScalar maxMotorImpulse = 1.0f; // 1.0f / 8.0f is about the minimum

    hingeConstraint->enableMotor( isEnableMotor );
    hingeConstraint->setMaxMotorImpulse( maxMotorImpulse );

    targetAngle += 0.1f * deltaTime;
    hingeConstraint->setMotorTarget( targetAngle, deltaTime );  
    }

};
情绪 2024-11-13 19:12:36

刚刚找到了 Hase & 的“利用三维全身神经肌肉骨骼模型进行人体运动的计算机模拟研究”。 Yamazaki (2002),提供

提出了一种由神经元系统和肌肉骨骼系统组成的具有三维全身结构的模型,以精确模拟人体行走运动。人体动力学由14个刚性连杆系统和60个肌肉模型来表征

Just found "Computer Simulation Study of Human Locomotion with a Three-Dimensional Entire-Body Neuro-Musculo-Skeletal Model" by Hase & Yamazaki (2002), which provide

A model having a three-dimensional entire-body structure and consisting of both the neuronal system and the musculo-skeletal system was proposed to precisely simulate human walking motion. The dynamics of the human body was represented by a 14-rigid-link system and 60 muscular models

夜光 2024-11-13 19:12:36

毫无疑问,从头开始做会很困难。我不知道你的目标是什么。但你不必重新设计轮子。您看过虚幻引擎吗?您可能会在那里找到可以重复使用的东西。许多游戏都是建立在这个引擎之上的。

Doing from scratch will be hard, no doubt about it. I don't know what your goal is. But you don't have to redesign the wheel. Have you taken a look at the Unreal Engine? You might find something to reuse there. Many games are built on the top of this engine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文