actionscript-3cubeflash-cs4papervision3d

Add a movieclip on a 3d cube and have interaction with it


I created a rotating cube using the below code and add bitmaps as sides of the cube. I was wondering if it's possibly to assign movie clips as sides of the cube so I can have some interaction with them.

    import flash.events.Event;
    import flash.display.Bitmap;
    import flash.display.BitmapData;

    import org.papervision3d.cameras.CameraType;
    import org.papervision3d.materials.BitmapMaterial;
    import org.papervision3d.materials.ColorMaterial;
    import org.papervision3d.materials.WireframeMaterial;
    import org.papervision3d.materials.utils.MaterialsList;
    import org.papervision3d.objects.primitives.Cube;
    import org.papervision3d.view.BasicView;

            var cube : Cube;                    
            var basicview : BasicView = new BasicView(640, 480, true, false, CameraType.FREE); 
            addChild(basicview);
            var logo : Logo = new Logo( 0,0); //Bitmapdata (jpeg) exported as class Logo from library   
            var matFront : BitmapMaterial = new BitmapMaterial(logo);
            var matBack : BitmapMaterial = new BitmapMaterial(logo); 

            var ml : MaterialsList = new MaterialsList(); 

            ml.addMaterial(matFront, "front"); 
            ml.addMaterial(matBack, "back"); 
            ml.addMaterial(new ColorMaterial(0x551F92),"right"); 
            ml.addMaterial(new ColorMaterial(0x431872),"bottom"); 
            ml.addMaterial(new ColorMaterial(0x341359),"top"); 
            ml.addMaterial(new ColorMaterial(0x7429C7),"left"); 

            cube = new Cube(ml,200,200,200,5,5,5); 

            basicview.scene.addChild(cube); 
            basicview.camera.fov = 20;          

            addEventListener(Event.ENTER_FRAME, enterFrame);                
            function enterFrame(e:Event) : void
            {
                cube.yaw((320-mouseX)*0.01); 
                cube.pitch((240-mouseY)*0.01); 
            }
            basicview.singleRender(); 
        }

UPDATE

I add this

var matFront : MovieMaterial = new MovieMaterial(new MV(),false,true);
matFront.interactive = true ;

MV is just a square with this code

package Scripts {

    import flash.display.MovieClip;
    import flash.events.*;

    public class MV extends MovieClip
    {
        public function MV( ) 
        {
            buttonMode = true;
            addEventListener(MouseEvent.CLICK,traceFunction);
        }
        private function traceFunction(ev:MouseEvent) {
            trace("clicked");
        }
    }
}

Why I have not any interaction when I click the side with the movie clip?

UPDATE 2

Ok I find it I had to add this line

basicview.viewport.interactive = true;

But why I have interaction even when the side of the movieclip isn't visible.

How can I avoid it?


Solution

  • Yes it is possible, you have to create Materials from the MovieClips you want to use, to do just that take a look at the classes MovieMaterial and MovieAssetMaterial inside the papervision3d materials Package.