Tag Archive: Papervision

I am making a very small 3d game (isometric view) using papervision3d. I needed some dynamic shadow element for some elements. I came across this very wonderful class that does the shadow casting from here. So I used ShadowCaster class to cast my shadows of my displayobject3d. I would need this following things for my purpose:
1) A do3d, target object whose shadow has to be created/rendered
2) A light source
3) A plane at which shadow would fall/render.
4) And of course our ShadowCaster class 😀

So i started playing with the shadowcaster class to get my hands dirty. I was trying to cast shadows of 4 plane on another surface plane. I created a light source. So here is how i was casting shadow with the code:

var blurr:BlurFilter = new BlurFilter(10, 10, 1);

shadowCaster_one = new ShadowCaster("plane1_shadow", 0x000000, BlendMode.MULTIPLY, 0.3, [blurr]);

shadowCaster_two = new ShadowCaster("plane2_shadow", 0x000000, BlendMode.MULTIPLY, 1, [blurr]);

shadowCaster_three = new ShadowCaster("plane3_shadow", 0x000000, BlendMode.MULTIPLY, 0.3, [blurr]);

shadowCaster_four = new ShadowCaster("plane4_shadow", 0x000000, BlendMode.MULTIPLY, 1, [blurr]);

Above I created 4 separate shadowcaster to cast on 4 separate plane.

override protected function onRenderTick(event:Event = null):void


shadowCaster_one.castModel(plane1, light, shadowPlane);
shadowCaster_two.castModel(plane2, light, shadowPlane);
shadowCaster_three.castModel(plane3, light, shadowPlane);
shadowCaster_four.castModel(plane4, light, shadowPlane);

Above I am rendering four shadows of four separate planes. I am rendering them on onRenderTick. Now its time to test it in browser.
1) Google chrome browser: Smooth run
2) Firefox: smooth run
3) Safari: smooth run
4) Opera: smooth run
5) Internet Explorer: FPS:1~0 (very very very very lag)

Yes there was very massive frame rate drop on internet explorer, interactive response was almost none. All other browser ran the game smoothly. Only one thing came to my mind:” Internet Explorer sucks”, but i knew that i had to optimize my code and for that i had to find the code that was consuming so much memory resource. My first suspect was shadow casting code at onRenderTick(), so i commented all shadow casting line and ran it again in internet explorer and yeah you guessed it correct that it ran smoothly. But i had to cast the shadows so i need to optimize this part. So i did some alteration:

First instead of adding those 4 planes directly to scene, i added them to one do3d.


Second, instead of creating 4 shadow caster, i created only one caster that would cast onto displayobject3d which has four planes as its children.
shadowCaster = new ShadowCaster("plane4_shadow", 0x000000, BlendMode.MULTIPLY, 1, [blurr]);


Then cast and render the shadow:

shadowCaster.castModel(shadowObjectContainer, light, shadowPlane);

This really optimized the performance and frame rate on internet explorer went up.

I am not claiming that this is the way to write. I am just sharing what i just faced and how i tackled it. I am still working on more better approach for optimization of my code and objective. But still i would say internet explorer sucks as only this browser showed massive drop on fps rate without any optimized code :D. But yeah i know writing efficient code makes life easier 😛


Yeah again i faced a little strange problem that i solved it. In my one of previous post i wrote about using movieclip with plane primitives of papervision and also accessing that movie. Now comes the main discussion of this post that is accessing movieclip from papervision plane.

Lets say i have attached a mouse listener to plane to which moviematerial is mapped. So when i click plane i want to do/manipulate the movieclip that is mapped to plane via moviematerial so code would look something like this:

private function planePressed(event:InteractiveScene3DEvent):void{
var moviemc=event.target.material.movie as Movieclip;
// do manipulation or changes on moviemc

the above snippet works, i mean u can access the movieclip on above do the later changes to it if u want.

But lets say there is no listener attached to the plane but later in program cycle i want to modify the movieclip attached to plane like applying blurr filter to it. Then i would do something like this:

var mc=my_papervision_plane.material.movie as Movieclip;
//apply blurr filter to mc

Well the above code didn’t work for me. In previous above event handler i traced event.target and it traced plane object, so it seems like ‘.material’ returned MaterialObject3D so i have to first downcast it to MovieMaterial separately and then try to access movie property on it. Here is the error:

So here is how is the stupid solution 😀

var mat=my_papervision_plane.material as MovieMaterial;
if(mat){//just being safe
var mc=mat.movie as Movieclip;

So that worked. But still i didn’t had to do that inside my event handler when i was accessing via even.target, maybe i am missing something out. Right now i am going through docs of papervision.


Busy Busy with stacks of projects on hand. I am learning lotsa things while working on them. I love learning new stuffs and programming is my passion. So one project i am working on is flash web page. So i thought to make a 3D flash site with some cool effects. I chose papervision 3D for my project. I am happy with the outcome till now.

But anyway i am here to share some small problems that i face during the development and how i solved it. There must be newbies like me out there who might face this problem :D. So here i’l share how i faced a problem regarding playing movieclip animation mapped to 3d object on papervision 3d.
I had never used movieclip on my previous papervision projects, rather i used bitmaps for graphics. In my current 3d flash site project i was required to use some movieclips also. I opened the papervision documentation and found something called MovieMaterial for creating a texture from my movieclip instance in fla file. Using MovieMaterial is simillar to using ColorMaterial and BitmapFileMaterial. Here i will just be talking about MovieMaterial.
MovieMaterial creates a texture from movieclip to be mapped to 3d object like cube. So i created a MovieMaterial :

materialFront = new MovieMaterial(movieclip_instance1);
materialFront.smooth = true;

movieclip_instance1 is a instance of movieclip in fla library. So i am getting material/texture from the moviclip. So i created other materials for other faces of cube. Then i added all materials to the MaterialList:

cubeMaterials:MaterialsList = new MaterialsList();
cubeMaterials.addMaterial (materialFront, "front" );
cubeMaterials.addMaterial (materialBack, "back" );
cubeMaterials.addMaterial(materialTop , "top" );
cubeMaterials.addMaterial materialBottom, "bottom" );
cubeMaterials.addMaterial(materialLeft, "left" );
cubeMaterials.addMaterial(materialRight, "right" );

Now i just used this matriallist to the cube:

cuboid = new Cube(cubeMaterials, 750, 5, 500, 10, 10, 10);

So movieclip is mapped to all the faces of cube. So this is done. But those movieclips that i mapped were just a single graphics, it didn’t have frame animations inside movieclip. So i mapped a movieclip having animation into it to cube using same above steps and codes but viola, movieclip animation wasn’t playing, just first frame was getting rendered at the face of cube. So this was quite a problem for me because i wanted to render movieclip animation for giving nice effects.

I just googled on this topic and found the solution. I went to papervision documenation again and opened the MovieMaterial doc and looked at the constructor parameters. The last parameter in the MovieMaterial constructor specifies the additional properties associated with the movieclip. Default value is false. So i modified a line of code:

materialFront = new MovieMaterial(movieclip_instance1, true, true);

The second parameter specifies whether movieclip is transparent . Last parameter is what i needed to solve my problem, I passed it true saying i have animation into my movieclip and i want it to play when rendered. So viola movieclip animation was playing and i had a stupid grin on my face 😀


Yesterday i was writing a 3d Carousel Gallery of videos and Photos. All functions were coded and working properly, only interaction with items was yet to be coded. So i started writing codes for interaction with items on my 3d gallery. So interaction handling wasn’t very big deal. i got it working in few minutes. My interaction function was when i click item which is at the face of camera then new bigger version of that image appears from back to the front and back gallery shifts back a little and fades a little (some nice animation). I did use Planes and BitmapFileMaterial to map texture to plane.
So that was working fine but i noticed that when i move mouse over items then buttonmode icon wasn’t coming. So i did write item.buttonMode=true; and “viola” there isn’t any such property called buttonMode for 3D primitives and materials in papervision. So i opened the papervision documentation and went through the methods and property but no success. Then after exploring docs for some more time i stumbled into viewport object and found something very gold :D.

There was a property for viewport:


so i put it in my scene initialization routine and got it running. and Bingo i got my buttonMode when moving mouse over my items.

Well that satisfied my application need and i am happy :D.