Tag Archive: 3d flash

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.