开发者

How can I load a Papervision/Flex application (SWF) as a material on a Papervision plane?

开发者 https://www.devze.com 2023-02-19 17:55 出处:网络
I am trying tobuild a portfolio application similar to the used by Whitevoid. I am using Flex 4 and Papervision3D 2. I have everything working except for one issue. When I try to load an external SWF

I am trying to build a portfolio application similar to the used by Whitevoid. I am using Flex 4 and Papervision3D 2. I have everything working except for one issue. When I try to load an external SWF as a material on one of the planes, I can see any native Flex or Flash components in their correct positions, but the papervision objects are not being rendered properly. It looks like the viewport is not being set in the nested swf. I have posted my code for loading the swf below.

private function loadMovie(path:String=""):void
{
    loader = new Loader();
    request = new URLRequest(path);

    loader.contentLoaderInfo.addEventListener(Event.INIT, addMaterial);

    loader.load(request);
}

private function addMaterial(e:Event):void
{
 开发者_StackOverflow社区   movie = new MovieClip();
    movie.addChild(e.target.content);
    var width:Number = 0;
    var height:Number = 0;
    width = loader.contentLoaderInfo.width;
    height = loader.contentLoaderInfo.height;

    //calculate the aspect ratio of the swf
    var matAR:Number = width/height;

    if (matAR > aspectRatio)
    {
        plane.scaleY = aspectRatio / matAR;
    }
    else if (matAR < aspectRatio)
    {
        plane.scaleX = matAR / aspectRatio;
    }

    var mat:MovieMaterial = new MovieMaterial(movie, false, true, false, new Rectangle(0, 0, width, height));

    mat.interactive = true;
    mat.smooth = true;
    plane.material = mat;
}

Below I have posted two pictures. The first is a shot of the application running by itself. The second is the application as a MovieMaterial on a Plane. You can see how the button created as a spark object in the mxml stays in the correct position, but papervision sphere (which is rotating) is in the wrong location. Is there something I am missing here?

How can I load a Papervision/Flex application (SWF) as a material on a Papervision plane?

How can I load a Papervision/Flex application (SWF) as a material on a Papervision plane?


Man. I haven't seen that site in a while. Still one of the cooler PV projects...

What do you mean by:

I cannot properly see the scene rendered in Papervision

You say you can see the components in their appropriate positions, as in: you have a plane with what looks like the intended file loading up? But I'm guessing that you can't interact with it.

As far as I know, and I've spent a reasonable amount of time trying to make something similar work, the MovieMaterial (which I assume you're using) draws a Bitmap of whatever contents exist in your MovieClip, and if you set it to animated=true, then it will render out a series of bitmaps - equating animation. What it's not doing, is displaying an actual MovieClip (or SWF) on the plane. So you may see your components, but this is how:

MovieMaterial.as line 137

// ______________________________________________________________________ CREATE BITMAP

        /**
        * 
        * @param    asset
        * @return
        */
        protected function createBitmapFromSprite( asset:DisplayObject ):BitmapData
        {
            // Set the new movie reference
            movie = asset;

            // initialize the bitmap since it's new
            initBitmap( movie );

            // Draw
            drawBitmap();

            // Call super.createBitmap to centralize the bitmap specific code.
            // Here only MovieClip specific code, all bitmap code (maxUVs, AUTO_MIP_MAP, correctBitmap) in BitmapMaterial.
            bitmap = super.createBitmap( bitmap );

            return bitmap;
        }

Note in the WhiteVoid you never actually interact with a movie until it "lands" = he's very likely swapping in a Movie on top of the bitmap textured plane.

The part that you are interacting with is probably another plane that holds the "button" that simply becomes visible on mouseover.

I think PV1.0 had access to real swfs as a material but this changed in 2.0. Sadly. Hopefully Molehill will.

cheers

0

精彩评论

暂无评论...
验证码 换一张
取 消