Soft Body, joint

Post Reply
ENGine
Posts: 15
Joined: Thu Feb 26, 2015 7:04 am

Soft Body, joint

Post by ENGine »

Hi, all.

I want to create the simple deformation object. It will look like the wall which is deformed by shells.
Thus, it must be static soft body object.

Here is I'm creating Soft Body:

Code: Select all

- (id) initMeshToSoftBodyConverter:(BOOL)_static World:(ibWorld*)_world Name:(NSString*)_name SceneNode:(iSceneNode*)_node Entity:(iEntity*)_entity {
    
    self = [super init];
    
    world = _world;
    m_softBodyWorldInfo.air_density = (btScalar)1.2;
    m_softBodyWorldInfo.m_gravity = btVector3(0, 0, 0); //_world.world->getGravity();
    m_softBodyWorldInfo.m_dispatcher = _world.dispatcher;
    m_softBodyWorldInfo.m_sparsesdf.Reset();
    m_softBodyWorldInfo.m_broadphase = _world.broadPhase;
    m_softBodyWorldInfo.m_sparsesdf.Initialize();
    
    staticSoftBoby = nil; dynamicSoftBody = nil;
    if (_static) {
        staticSoftBoby = new StaticMeshToSoftBodyConverter(&m_softBodyWorldInfo);
        staticSoftBoby->addEntity(_entity.ent);
        psb = staticSoftBoby->createSoftBodyFromTrimesh();
    } else {
        dynamicSoftBody = new AnimatedMeshToSoftBodyConverter(&m_softBodyWorldInfo);
        dynamicSoftBody->addEntity(_entity.ent);
        psb = dynamicSoftBody->createSoftBodyFromTrimesh();
    }
    
    btSoftBody::Material *pm=psb->appendMaterial();
    pm->m_kLST = 0.1;
    psb->m_cfg.piterations = 2;
    psb->m_cfg.kDF = 0.5;
    psb->m_cfg.collisions |= btSoftBody::fCollision::VF_SS;
    psb->generateClusters(0);
    psb->randomizeConstraints();
    psb->setTotalMass(100,true);
    
    psb->setUserPointer((__bridge void *)_name);
    btSoftRigidDynamicsWorld *softWorld = (btSoftRigidDynamicsWorld *)_world.world;
    softWorld->addSoftBody(psb);
    
    return self;
}
I was trying to play with gravity there, but my soft body flies immediately. If I understood right, I have to add Joint.
BodyA - static ground floor;

Code: Select all

    btSoftBody::LJoint::Specs ls;
    ls.cfm = 1;
    ls.erp = 1;
    ls.position = btVector3(1, 0, 1);
    softbody->appendLinearJoint(ls,BodyA);

Code: Select all

    btSoftBody::AJoint::Specs aspecs;
    aspecs.cfm = 1;
    aspecs.erp = 1;
    aspecs.axis = btVector3(0,1,0);
    softbody->appendAngularJoint(aspecs,BodyA);
I was playing with params of these joints. But there is no right result.
Maybe I'm doing something wrong. Please, help.

P.S. Using of Soft Body is decreasing very much FPS. Also if there is another way to create deformation wall.
Thanks.
ENGine
Posts: 15
Joined: Thu Feb 26, 2015 7:04 am

Re: Soft Body, joint

Post by ENGine »

Here is a short video: https://www.dropbox.com/s/dg41r9ok67k5g ... y.mov?dl=0
Thus, I created the Soft Body object:

Code: Select all

m_softBodyWorldInfo.air_density = (btScalar)1.2;
    m_softBodyWorldInfo.m_gravity = btVector3(0, 0, 0); //_world.world->getGravity();
    m_softBodyWorldInfo.m_dispatcher = _world.dispatcher;
    m_softBodyWorldInfo.m_sparsesdf.Reset();
    m_softBodyWorldInfo.m_broadphase = _world.broadPhase;
    m_softBodyWorldInfo.m_sparsesdf.Initialize();
    
    staticSoftBoby = nil; dynamicSoftBody = nil;
    if (_static) {
        staticSoftBoby = new StaticMeshToSoftBodyConverter(&m_softBodyWorldInfo);
        staticSoftBoby->addEntity(_entity.ent);
        psb = staticSoftBoby->createSoftBodyFromTrimesh();
    } else {
        dynamicSoftBody = new AnimatedMeshToSoftBodyConverter(&m_softBodyWorldInfo);
        dynamicSoftBody->addEntity(_entity.ent);
        psb = dynamicSoftBody->createSoftBodyFromTrimesh();
    }
    
    btSoftBody::Material *pm=psb->appendMaterial();
    pm->m_kLST = 0.1;
    psb->m_cfg.piterations = 2;
    psb->m_cfg.kDF = 0.5;
    psb->m_cfg.collisions |= btSoftBody::fCollision::VF_SS;
    psb->generateClusters(0);
    psb->randomizeConstraints();
    psb->setTotalMass(100,true);
    
    psb->setUserPointer((__bridge void *)_name);
    btSoftRigidDynamicsWorld *softWorld = (btSoftRigidDynamicsWorld *)_world.world;
    softWorld->addSoftBody(psb);
And I can't clear why it's flying. What is wrong? Thanks.
ENGine
Posts: 15
Joined: Thu Feb 26, 2015 7:04 am

Re: Soft Body, joint

Post by ENGine »

It seems to me that: m_softBodyWorldInfo.m_maxDisplacement = 0; has solved my problem.
but after the collision soft object is broken into pieces.

default: http://joxi.net/l2ZlkNLI8QQE7r
after collision: http://joxi.net/gmvbWqYfxRRqbm
Post Reply