Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SoftBody Endless Fall down #2

Closed
waveware4ai opened this issue Jun 3, 2020 · 9 comments
Closed

SoftBody Endless Fall down #2

waveware4ai opened this issue Jun 3, 2020 · 9 comments

Comments

@waveware4ai
Copy link

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
Copy link
Owner

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

@waveware4ai
Copy link
Author

waveware4ai commented Jun 3, 2020 via email

@stephengold
Copy link
Owner

stephengold commented Jun 3, 2020

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
Copy link
Author

waveware4ai commented Jun 3, 2020 via email

@waveware4ai
Copy link
Author

@stephengold
Copy link
Owner

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
Copy link
Owner

@waveware4ai Has your issue been solved?

@waveware4ai
Copy link
Author

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants