stephengold / Libbulletjme

A JNI interface to Bullet Physics and V-HACD
https://stephengold.github.io/Libbulletjme/lbj-en/English/overview.html
Other
84 stars 10 forks source link

SoftBody Endless Fall down #2

Closed waveware4ai closed 4 years ago

waveware4ai commented 4 years ago

Can you check if this is a bug I found that the 'PhysicsSoftBody Object' kept falling and never stopped Below is my code ... Always thank you for a good project !!! 👍

public class BulletTestSoftBodyProblem { public static void main(String[] args) { PhysicsSoftSpace space = new PhysicsSoftSpace(new Vector3f(-10f, -10f, -10f), new Vector3f(10f, 10f, 10f), PhysicsSpace.BroadphaseType.DBVT);

    PhysicsRigidBody    floor = new PhysicsRigidBody(new PlaneCollisionShape(new Plane(Vector3f.UNIT_Y, 0f)), 0f);
    floor.setPhysicsLocation(new Vector3f(0, 0, 0));
    space.addCollisionObject(floor);

    PhysicsRigidBody    rbody = new PhysicsRigidBody(new BoxCollisionShape(0.2f), 1f);
    rbody.setPhysicsLocation(new Vector3f(+1, 1, 0));
    space.addCollisionObject(rbody);

    PhysicsSoftBody     sbody = new PhysicsSoftBody(); // <--- here !!
    NativeSoftBodyUtil.appendFromNativeMesh(mesh(), sbody);
    sbody.setPhysicsLocation(new Vector3f(-1, 1, 0));
    space.addCollisionObject(sbody);

    for (int i = 0; i < 1000; i++)
    {
        try { space.update(0.03f, 0); Thread.sleep(10); } catch (Exception _) {}

        Vector3f rpos = rbody.getPhysicsLocation(null); // rigid body position
        Vector3f spos = sbody.getPhysicsLocation(null); // soft  body position
        System.out.println("[Rigid Cube] " + rpos + " vs " + "[Soft Cube] " + spos);
    }
}

static IndexedMesh mesh()
{
    float[]vrt = cube_vert;
    int[][]ind = cube_indi;

    List VRT = new ArrayList();
    for (int i = 0; i < vrt.length; i+=3)
    {
        VRT.add(new Vector3f((float)vrt[i], (float)vrt[i+1], (float)vrt[i+2]));
    }

    List IND = new ArrayList();
    for (int i = 0; i < ind.length; i++)
    {
        int i0 = ind[i][0];
        int i1 = ind[i][1];
        int i2 = ind[i][2];
        IND.add(i0);
        IND.add(i1);
        IND.add(i2);
    }

    Vector3f[]vvv = new Vector3f[VRT.size()];
    for (int i = 0; i < vvv.length; i++) vvv[i] = (Vector3f) VRT.get(i);
    int     []iii = new int[IND.size()];
    for (int i = 0; i < iii.length; i++) iii[i] = (Integer) IND.get(i);
    IndexedMesh im = new IndexedMesh(vvv, iii);

    return im;
}

static float[]cube_vert = null; // cube vertex array
static int[][]cube_indi = null; // cube vertex indices
static
{
    float s = 0.2f;
    float[]v0 = new float[] { -s,  +s,  +s };
    float[]v1 = new float[] { +s,  +s,  +s };
    float[]v2 = new float[] { +s,  -s,  +s };
    float[]v3 = new float[] { -s,  -s,  +s };
    float[]v4 = new float[] { -s,  +s,  -s };
    float[]v5 = new float[] { +s,  +s,  -s };
    float[]v6 = new float[] { +s,  -s,  -s };
    float[]v7 = new float[] { -s,  -s,  -s };
    float[][]vv = new float[][] { v0, v1, v2, v3, v4, v5, v6, v7 };
    cube_vert = new float[8*3];
    for (int i = 0; i < 8; i++) 
    { 
        cube_vert[i*3+0] = vv[i][0];  
        cube_vert[i*3+1] = vv[i][1]; 
        cube_vert[i*3+2] = vv[i][2]; 
    }

    int  []p0 = new int[] {0, 1, 2 };
    int  []p1 = new int[] {0, 2, 3 };
    int  []p2 = new int[] {4, 7, 6 };
    int  []p3 = new int[] {4, 6, 5 };
    int  []p4 = new int[] {0, 4, 5 };
    int  []p5 = new int[] {0, 5, 1 };
    int  []p6 = new int[] {3, 2, 6 };
    int  []p7 = new int[] {3, 6, 7 };
    int  []p8 = new int[] {1, 5, 6 };
    int  []p9 = new int[] {1, 6, 2 };
    int  []p10= new int[] {0, 3, 7 };
    int  []p11= new int[] {0, 7, 4 };
    int[][]pp = new int[][] { p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11 };
    cube_indi = pp;
}

}

result . . . [Rigid Cube] (1.0278512, -0.017536394, 0.25851533) vs [Soft Cube] (-2.5757184, -565.5575, -0.2820301) [Rigid Cube] (1.0277523, -0.017890645, 0.25878102) vs [Soft Cube] (-2.57684, -568.72144, -0.28341308) [Rigid Cube] (1.0278698, -0.016414547, 0.25919935) vs [Soft Cube] (-2.5779958, -571.8943, -0.28479832) [Rigid Cube] (1.0281138, -0.015941579, 0.25943175) vs [Soft Cube] (-2.5791693, -575.07605, -0.28621972) [Rigid Cube] (1.0285553, -0.017206488, 0.25978068) vs [Soft Cube] (-2.58034, -578.2667, -0.28759184) [Rigid Cube] (1.02916, -0.017807819, 0.25984636) vs [Soft Cube] (-2.5815368, -581.4661, -0.2889949) [Rigid Cube] (1.0297773, -0.016683284, 0.25992036) vs [Soft Cube] (-2.582777, -584.67456, -0.29037392) . . .

stephengold commented 4 years ago

Thanks for reporting this issue. I'll investigate and try to advise you.

waveware4ai commented 4 years ago
    p{margin-top:0;margin-bottom:0}

Thanks for your reply.

This move is capture file ...

Have a nice day !

--------- 원본 메일 ---------

    보낸사람: Stephen Gold <notifications@github.com>
    받는사람: stephengold/Libbulletjme <Libbulletjme@noreply.github.com>

        참조: waveware4ai <14mhz@hanmail.net>, Author <author@noreply.github.com>

    날짜: 20.06.04 00:46 GMT +0900
    제목: Re: [stephengold/Libbulletjme] SoftBody Endless Fall down (#2)

Thanks for reporting this issue. I'll investigate and try to advise you.

—You are receiving this because you authored the thread.Reply to this email directly, view it on GitHub, or unsubscribe.

stephengold commented 4 years ago

According to my tests, Bullet implements soft-versus-rigid collisions only for rigid bodies with 3-D convex shapes. I therefore advise replacing the PlaneCollisionShape with a (large) 3-D convex shape such as a BoxCollisionShape, CylinderCollisionShape, or HullCollisionShape.

waveware4ai commented 4 years ago
    p{margin-top:0;margin-bottom:0}

Thanks your fast replay :-)

I was replace code, then test again. but, this time happened two cude fall down.

I did try CylinderCollisionShape, this has a also result ...

code below that ...

----- replaced BoxCollisionShape {        PhysicsRigidBody    floor = new PhysicsRigidBody(new BoxCollisionShape(1000f, 0.01f, 1000f));        floor.setPhysicsLocation(new Vector3f(0, 0, 0));        space.addCollisionObject(floor);}----- replaced HullCollisionShape{        PhysicsRigidBody    floor = new PhysicsRigidBody(new HullCollisionShape(1000f, 0, 1000f, 1000f, 0, -1000f, -1000f, 0, 1000f, -1000f, 0, -1000f, 1000f, 0, 1000f, -1000f, 0, 1000f, 1000f, 0, 1000f, -1000f, 0, 1000f));        floor.setPhysicsLocation(new Vector3f(0, 0, 0));        space.addCollisionObject(floor);}how can i do ? have a nice day !!! --------- 원본 메일 ---------

    보낸사람: Stephen Gold <notifications@github.com>
    받는사람: stephengold/Libbulletjme <Libbulletjme@noreply.github.com>

        참조: waveware4ai <14mhz@hanmail.net>, Author <author@noreply.github.com>

    날짜: 20.06.04 02:19 GMT +0900
    제목: Re: [stephengold/Libbulletjme] SoftBody Endless Fall down (#2)

According to my tests, Bullet implements soft-versus-rigid collisions only for rigid bodies with 3-D convex shapes. I therefore advise replacing the PlaneCollisionShape with a (large) 3-D convex shape such as a BoxCollisionShape, 'CylinderCollisionShape, or HullCollisionShape`.

—You are receiving this because you authored the thread.Reply to this email directly, view it on GitHub, or unsubscribe.

waveware4ai commented 4 years ago

This is movie clip replaced BoxCollisionShape https://mega.nz/file/scoURK7a#koQ2TisBUeVHNrSiT1LyWjb8vwHpAaFugW_VUZRde7c

replaced HullCollisionShape https://mega.nz/file/wcoAWA5T#lEXDMwAOMQVmTa1HwVc4AxsSOH5v-7_VFPdUlDGAY1k

stephengold commented 4 years ago

The hull shape you created has zero thickness, making it 2-D rather than 3-D. The box shape you created has a total thickness of 0.02, making it far too thin for a 30-millisecond timestep with gravity=9.81

Again, I recommend using a 3-D convex shape for the floor.

Also, try reducing the timestep from 0.03 second to a smaller value, such as 0.003 second, or else reducing gravity so that the boxes don't fall so fast.

stephengold commented 4 years ago

@waveware4ai Has your issue been solved?

waveware4ai commented 4 years ago

Hello stephengold~ I did solved for your help. I forgot to setting floor mass to zero. There is nothing error just now ... I m very thanks to you.

below is changed code

PhysicsRigidBody floor = new PhysicsRigidBody(new BoxCollisionShape(1000f, 0.01f, 1000f)); floor.setMass(0); <-- my mistake static mass zero !!!

stephengold commented 4 years ago

Good catch! I'm glad it's working for you now.