MinieExamples/src/main/java/jme3utilities/minie/test/TestSoftBody.java
/**
     * Add a static pole with a rectangular flag.
     */
Add a static pole with a rectangular flag.
Add a static pole with a rectangular flag .
private void addPoleAndFlag() {
        float radius = 0.06f;
        float height = 4f;
        CollisionShape shape = new CylinderCollisionShape(radius, height,
                PhysicsSpace.AXIS_Y);
        PhysicsRigidBody polePrb
                = new PhysicsRigidBody(shape, PhysicsBody.massForStatic);
        ColorRGBA color = new ColorRGBA(0.7f, 0.7f, 1f, 1f);
        Material material = MyAsset.createShadedMaterial(assetManager, color);
        polePrb.setDebugMaterial(material);
        polePrb.setDebugMeshNormals(DebugMeshNormals.Smooth);
        physicsSpace.addCollisionObject(polePrb);
        int xLines = 20;
        int zLines = 2 * xLines; 
        float width = 2f;
        float spacing = width / zLines;
        Mesh mesh = new ClothGrid(xLines, zLines, spacing);
        PhysicsSoftBody flagPsb = new PhysicsSoftBody();
        NativeSoftBodyUtil.appendFromTriMesh(mesh, flagPsb);
        flagPsb.setMargin(0.1f);
        flagPsb.setMass(mass);
        Vector3f wind = new Vector3f(2.5f, 0f, -0.5f);
        flagPsb.setWindVelocity(wind);
        SoftBodyConfig config = flagPsb.getSoftConfig();
        config.set(Sbcp.Damping, 0.01f);
        config.set(Sbcp.Drag, 0.5f);
        config.set(Sbcp.Lift, 1);
        config.setAerodynamics(Aero.F_TwoSidedLiftDrag);
        config.setPositionIterations(3);
        SoftBodyMaterial softMaterial = flagPsb.getSoftMaterial();
        softMaterial.setAngularStiffness(0f);
        Material logoMaterial = findMaterial("logo");
        flagPsb.setDebugMaterial(logoMaterial);
        flagPsb.setDebugMeshInitListener(flagDmiListener);
        flagPsb.setDebugMeshNormals(DebugMeshNormals.Smooth);
        Quaternion rotation = new Quaternion();
        rotation.fromAngles(FastMath.HALF_PI, 0f, 0f);
        flagPsb.applyRotation(rotation);
        flagPsb.setPhysicsLocation(new Vector3f(1f, 1.5f, 0f));
        physicsSpace.addCollisionObject(flagPsb);
        /*
         * Add 2 anchors that join the flag to the pole.
         */
        boolean allowCollisions = true;
        int nodeIndex = 0; 
        Vector3f initialLocation = flagPsb.nodeLocation(nodeIndex, null);
        Anchor anchor0 = new Anchor(flagPsb, nodeIndex, polePrb,
                initialLocation, allowCollisions);
        physicsSpace.addJoint(anchor0);
        nodeIndex = xLines - 1; 
        flagPsb.nodeLocation(nodeIndex, initialLocation);
        Anchor anchor1 = new Anchor(flagPsb, nodeIndex, polePrb,
                initialLocation, allowCollisions);
        physicsSpace.addJoint(anchor1);
    }
private void addPoleAndFlag ( ) { float radius = 0.06f ; float height = 4f ; CollisionShape shape = new CylinderCollisionShape ( radius , height , PhysicsSpace . AXIS_Y ) ; PhysicsRigidBody polePrb = new PhysicsRigidBody ( shape , PhysicsBody . massForStatic ) ; ColorRGBA color = new ColorRGBA ( 0.7f , 0.7f , 1f , 1f ) ; Material material = MyAsset . createShadedMaterial ( assetManager , color ) ; polePrb . setDebugMaterial ( material ) ; polePrb . setDebugMeshNormals ( DebugMeshNormals . Smooth ) ; physicsSpace . addCollisionObject ( polePrb ) ; int xLines = 20 ; int zLines = 2 * xLines ; float width = 2f ; float spacing = width / zLines ; Mesh mesh = new ClothGrid ( xLines , zLines , spacing ) ; PhysicsSoftBody flagPsb = new PhysicsSoftBody ( ) ; NativeSoftBodyUtil . appendFromTriMesh ( mesh , flagPsb ) ; flagPsb . setMargin ( 0.1f ) ; flagPsb . setMass ( mass ) ; Vector3f wind = new Vector3f ( 2.5f , 0f , - 0.5f ) ; flagPsb . setWindVelocity ( wind ) ; SoftBodyConfig config = flagPsb . getSoftConfig ( ) ; config . set ( Sbcp . Damping , 0.01f ) ; config . set ( Sbcp . Drag , 0.5f ) ; config . set ( Sbcp . Lift , 1 ) ; config . setAerodynamics ( Aero . F_TwoSidedLiftDrag ) ; config . setPositionIterations ( 3 ) ; SoftBodyMaterial softMaterial = flagPsb . getSoftMaterial ( ) ; softMaterial . setAngularStiffness ( 0f ) ; Material logoMaterial = findMaterial ( "logo" ) ; flagPsb . setDebugMaterial ( logoMaterial ) ; flagPsb . setDebugMeshInitListener ( flagDmiListener ) ; flagPsb . setDebugMeshNormals ( DebugMeshNormals . Smooth ) ; Quaternion rotation = new Quaternion ( ) ; rotation . fromAngles ( FastMath . HALF_PI , 0f , 0f ) ; flagPsb . applyRotation ( rotation ) ; flagPsb . setPhysicsLocation ( new Vector3f ( 1f , 1.5f , 0f ) ) ; physicsSpace . addCollisionObject ( flagPsb ) ; /*
         * Add 2 anchors that join the flag to the pole.
         */ boolean allowCollisions = true ; int nodeIndex = 0 ; Vector3f initialLocation = flagPsb . nodeLocation ( nodeIndex , null ) ; Anchor anchor0 = new Anchor ( flagPsb , nodeIndex , polePrb , initialLocation , allowCollisions ) ; physicsSpace . addJoint ( anchor0 ) ; nodeIndex = xLines - 1 ; flagPsb . nodeLocation ( nodeIndex , initialLocation ) ; Anchor anchor1 = new Anchor ( flagPsb , nodeIndex , polePrb , initialLocation , allowCollisions ) ; physicsSpace . addJoint ( anchor1 ) ; }
Add a static pole with a rectangular flag.
Add a static pole with a rectangular flag .
// 2x as wide as it is tall
 // upper left corner of flag
 // lower left corner of flag
