Home > as3mod > Applying modifiers to 3D objects in Papervision3D using AS3Mod

Applying modifiers to 3D objects in Papervision3D using AS3Mod

December 9th, 2008

I have been meaning to dig into the as3mod library for a while now but never had the time because I was working on a project. Finally I found some time and dove right into it! At first, I had no idea what I was getting into, but as I read deeper into the classes and devoured the documentation, stuff started to make sense. So much that I decided to build a very simple demonstration of the different modifiers available:

The modifiers are really simple to apply to any 3d object including collada files!! Below is the document class used in the example. If you go through it, I’m sure you’ll pick up pretty fast.

You’re gonna nee d to grab the as3mod library found here and the latest version of papervision3d here.

package
{
    import com.as3dmod.IModifier;
    import com.as3dmod.ModifierStack;
    import com.as3dmod.modifiers.Bend;
    import com.as3dmod.modifiers.Bloat;
    import com.as3dmod.modifiers.Noise;
    import com.as3dmod.modifiers.Perlin;
    import com.as3dmod.modifiers.Skew;
    import com.as3dmod.modifiers.Taper;
    import com.as3dmod.modifiers.Twist;
    import com.as3dmod.plugins.pv3d.LibraryPv3d;
    import com.as3dmod.util.ModConstant;
    import com.as3dmod.util.Phase;
   
    import flash.events.Event;
   
    import org.papervision3d.materials.ColorMaterial;
    import org.papervision3d.materials.WireframeMaterial;
    import org.papervision3d.materials.special.CompositeMaterial;
    import org.papervision3d.materials.utils.MaterialsList;
    import org.papervision3d.objects.primitives.Cube;
    import org.papervision3d.view.BasicView;

    public class SimpleMod extends BasicView
    {
        private var cube:Cube;
        private var modStack:ModifierStack;
        private var bend:Bend;
        private var bendPhase:Phase;
        private var perlin:Perlin;
        private var noise:Noise;
        private var skew:Skew;
        private var skewPhase:Phase;
        private var taper:Taper;
        private var taperPhase:Phase;
        private var twist:Twist;
        private var twistPhase:Phase;
        private var bloat:Bloat;
        private var bloatPhase:Phase;
       
        public function SimpleMod()
        {
            camera.z = -1500;
           
            cerateCube();
            addModifiers();
            configureComboBox();
            startRendering();
        }
       
        private function cerateCube():void
        {
            var colorMat:ColorMaterial = new ColorMaterial(0x00FF00);
            var wireMat:WireframeMaterial = new WireframeMaterial(0xFFFFFF);
            var compositeMat:CompositeMaterial = new CompositeMaterial();
            compositeMat.addMaterial(colorMat);
            compositeMat.addMaterial(wireMat);
           
            var materialsList:MaterialsList = new MaterialsList({ all:compositeMat });
           
            cube = new Cube(materialsList, 500, 500, 1000, 10, 10, 10);
           
            scene.addChild(cube);
        }
       
        private function addModifiers():void
        {
            modStack = new ModifierStack(new LibraryPv3d, cube);
           
            bend = new Bend(0.5, 0.5);
            bendPhase = new Phase();
           
            skew = new Skew(0);
            skewPhase = new Phase();
           
            taper = new Taper(3);
            taper.setFalloff(0.2, 0.5);
            taper.power = 6;
            taperPhase = new Phase();
           
            twist = new Twist(Math.PI / 2);
            twistPhase = new Phase();
           
            perlin = new Perlin(3);
            perlin.setFalloff(1, 0);
           
            noise = new Noise(25);
            noise.constraintAxes(ModConstant.X | ModConstant.Y);
           
            bloat = new Bloat();
        }
       
        private function configureComboBox():void
        {
            modifierCB.addItem({label:"Bend", data:bend});
            modifierCB.addItem({label:"Skew", data:skew});
            modifierCB.addItem({label:"Taper", data:taper});
            modifierCB.addItem({label:"Twist", data:twist});
            modifierCB.addItem({label:"Perlin", data:perlin});
            modifierCB.addItem({label:"Noise", data:noise});
            modifierCB.addItem({label:"Bloat", data:bloat});
            modifierCB.addEventListener(Event.CHANGE, changeHandler);
        }
       
        private function changeHandler($event:Event):void
        {
            modStack.clear();
            modStack.addModifier(modifierCB.selectedItem.data as IModifier);
        }
       
        override protected function onRenderTick(event:Event=null):void
        {
            super.onRenderTick(event);
           
            cube.yaw(.5);
             
            bendPhase.value += 0.05;
            bend.force = bendPhase.phasedValue * .5;
           
            skewPhase.value += 0.05;
            skew.force = skewPhase.phasedValue * 100;
           
            taperPhase.value += 0.05;
            taper.force = taperPhase.absPhasedValue * 2;
           
            twistPhase.value += 0.05;
            twist.angle = Math.PI / 8 * twistPhase.phasedValue;
           
            modStack.apply();
        }
    }
}

Enjoy!!

as3mod ,

  1. RooTShell
    January 28th, 2009 at 03:04 | #1

    Thank you so much for the demo and the source…

    I really appreciate it. Will download the demo and keep it as a reference so I can look at it before doing animations with AS3Dmod that I think is a fantastic library.

    Take care

  2. April 19th, 2009 at 12:41 | #2

    Thanks for this nice tutorial
    Really useful!

  3. May 7th, 2009 at 04:19 | #3

    Thanx a lot! Def. could use this in a project i’m working on. Like RootShell said it…Fantastic

  4. desgraci
    July 5th, 2009 at 06:30 | #4

    the falloff property was removed, know how to make it work in the last version of the as3mod?

  5. desgraci
    July 5th, 2009 at 06:31 | #5

    or it is from pv3d only, sry for 2ble post

  1. No trackbacks yet.
Comments are closed.