Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

Cloth

Cloth is a modifier that displaces object vertices giving the effects of wind and gravity.

Example

Cloth

Instructions

  1. Import stack, modifier, 3D render engine library
    import com.as3dmod.ModifierStack;
    import com.as3dmod.modifiers.Cloth;
    import com.as3dmod.plugins.pv3d.LibraryPv3d;
  2. Declare stack
    private var stack :ModifierStack;
  3. Declare modifier
    private var modifier :Cloth;
  4. Initialize stack
    stack = new ModifierStack(lib3d, mesh);
    ParameterDefaultDescription
    lib3dNONE3D engine library
    meshNONE3D object
  5. Initialize modifier
    modifier = new Cloth(rigidity, friction);
    ParameterDefaultDescription
    rigidity1stretchy to rigid (0-1) cloth
    friction0air friction
  6. Add modifier to stack
    stack.addModifier(modifier);
  7. Set force, lock axis
    modifier.setForce(0.2, -0.2, -0.2);
    modifier.lockXMin();
  8. Apply
    stack.apply();

Code

package
{
    import com.as3dmod.ModifierStack;
    import com.as3dmod.modifiers.Cloth;
    import com.as3dmod.plugins.pv3d.LibraryPv3d;

    import flash.events.Event;

    import org.papervision3d.materials.WireframeMaterial;
    import org.papervision3d.objects.primitives.Plane;
    import org.papervision3d.view.BasicView;

    public class AS3DmodCloth extends BasicView
    {
        private var object   :Plane;
        private var stack    :ModifierStack;
        private var modifier :Cloth;

        public function AS3DmodCloth()
        {
            super();

            var material :WireframeMaterial = new WireframeMaterial(0x000000);
            material.doubleSided = true;

            object = new Plane(material, 500, 500, 10, 10);
            scene.addChild(object);

            stack = new ModifierStack(new LibraryPv3d(), object);

            modifier = new Cloth();
            stack.addModifier(modifier);

            modifier.setForce(0.2, -0.2, -0.2);
            modifier.lockXMin();

            startRendering();
        }

        protected override function onRenderTick(e:Event=null):void
        {
            stack.apply();

            super.onRenderTick(e);
        }
    }
}

Download

HomeMenu