You know I’m a fan of the Papervision BasicView, it’s just such a good entry point into Papervision – so easy to work with, and you can even extend it for your document class.
But how cool would it be if you could have something as simple as a BasicView, but that automatically created a reflection on the ground? Very cool! That’s how!
Which is exactly why I made a ReflectionView. You can pretty much just replace your BasicView with this new class.
At the moment it only works with reflections on an xz plane (ie the floor).
There are only two new things you need to consider :
surfaceHeight
This is the y position of the floor. You need to make sure none of your objects go underneath this or it’ll look weird!
setReflectionColor()
This function adjusts the color transform for the reflection by settings mutlipliers and offsets for red, green and blue, just like the colorTransform property of MovieClips.
By default this is set to darken the reflection but you can use it to lighten or even colorise it.
It’s very alpha, but very simple and very quick!
You can also add blur to the reflection by adding a filter to the reflection viewport :
viewportReflection.filters = [new BlurFilter(4,4,1)];
And if you want it to actually be transparent (if you’re using a floor plane for example) you can also add a ColorMatrixFilter to the viewportReflection filters.
I’m looking at improved effects to this with Andy’s help but I thought I’d at least get a basic version out there for you to play with.
Basic cube source code here :
package { import flash.events.Event; import org.papervision3d.cameras.Camera3D; import org.papervision3d.core.effects.view.ReflectionView; import org.papervision3d.materials.ColorMaterial; import org.papervision3d.materials.utils.MaterialsList; import org.papervision3d.objects.primitives.Cube; [SWF (width="640", height="480", backgroundColor="0x000000", frameRate="30")] public class ReflectionCubeSimple extends ReflectionView { private var cube : Cube; public function ReflectionCubeSimple() { super(640,480,false, false); //the height of the reflection plane surfaceHeight = -100; initCube(); camera.z = -400; addEventListener(Event.ENTER_FRAME, enterFrame); } public function initCube() : void { // create a materials list for the cube. var ml : MaterialsList = new MaterialsList(); ml.addMaterial(new ColorMaterial(0x880000), "all"); ml.addMaterial(new ColorMaterial(0x660000),"right"); ml.addMaterial(new ColorMaterial(0x440000),"bottom"); ml.addMaterial(new ColorMaterial(0xdd0000),"top"); ml.addMaterial(new ColorMaterial(0xdd0000),"left"); cube = new Cube(ml,100,100,100); // add the cube to the scene scene.addChild(cube); } public function enterFrame(e:Event) : void { // rotate the cube dependent on the mouse position cube.yaw((320-mouseX)*0.05); cube.y=(120-(mouseY/2)); if(cube.y<0) cube.y = 0; singleRender(); } } }
(Cue about a million CoverFlow type effects…
)
Related posts:



Looks sweet!
Excellent work !
looks great. is there any plan for the creation of some sort of falloff
Thanks guys!
Mark, next on my list is to create fall-off and even culling, so I’m currently studying the renderers.
cheers!
Seb
I tried use it in a project, but it looks like the reflection is not sync with the objects. It looks like the reflection has one frame delay.
Hi Thijs,
I suspect this may be to do with a bug in the DisplayObject rotation methods… are you adjusting your objects using rotationX, Y, Z etc? Could I see the code?
Seb
Yes, I do use rotationY
Yes this is a bug not related to ReflectionView, currently your actual main display will be getting updated a frame late. There are several workarounds :
1) Switch rotationY for a relative rotation using yaw();
or
2) Add yaw(0) after all your updates on your object;
or
3) Wait until we fix the rotation bug.
Would love to see how you’re getting along with this though.
cheers!
Seb
I did the first option with a relative rotation using yaw():
public function get rotation():Number
{
return this._rotation;
}
public function set rotation(value:Number ):void
{
this.yaw(value – this._rotation);
this._rotation = value;
}
And it works great. Thanks!
That’s great Thijs! So can we see…?
Really weird things happen when I change the pitch or tilt of the camera. It looks like the reflection surface also changes.
But rotating the camera using rotationX works ok.
Hi Thijs, that sounds weird, I’ve never seen that… do you have code I can test?
cheers
Seb
Hi Seb, first i would thank you for your great work!
But i have the same issue like Thijs. You can see an example of my
problem under http://www.trackx.de/flash/3d/refelction.html. Use your left
Mouse Button to orbit.
sorry, wrong url… right url is: http://www.trackx.de/flash/3d/reflection.html
cheers trackx
Yeah that is weird! Pretty sure it’s to do with the new camera stuff… can u send me the code and I’ll investigate.
cheers!
Seb
I’ve been searching for tutorials on getting nice reflections and I haven’t found any (yet). I love what you’ve done, its awesome! One question where can the classe(s) be obtained?
Of course I could always check out the latest SVN….
If you had smilies I would use the embarassed one!
OK so now I get this error…
1195: Attempted access of inaccessible method yaw through a reference with static type org.papervision3d.objects.primitives:Cube.
If I comment the line out it works fine. I guess the camera.yaw method has been revised?
Its still seriously cool to just be able to add reflections though. Thanks a lot!
Hi gordee,
yes there are some major reworkings at the moment to DisplayObject3D rotations. I’ll wait for all of them to be completed and then make sure ReflectionView still works.
Seb
OK I’ve uploaded a new ReflectionView to the svn server and this should fix the rotation problems. The DisplayObject3D rotation system (which Camera3D inherits) is undergoing some major revisions at the moment, so please let me know if this breaks again.
BTW the ReflectionView currently only works if you use the new pitch, roll and yaw properties of your camera, which replace rotationX, rotationY and rotationZ respectively.
cheers!
Seb
Excellent, thx for fixing that issue.
Hi…first of all: great work… I was working on one myself but this looks gooood…
One issue: I use MovieMaterials for my planes. The movieclips i use for my materials have events on them (mouseover and click). These events fail as soon as I use the ReflectionView…
Is this a known issue????
Hi Wink,
ah thanks for that, I’m surprised it doesn’t work but then I didn’t actually test it. So to be clear, the events on the non-reflected version stop working?
Seb
Hi Seb…
Exactly…The ‘original’ non reflected items stop working…
I am also checking out if it is me… changing the surfaceHeight seems to be off influence….
surfaceHeight = -100 — there is some interacting. But very irregular. Sometimes it works, sometimes it doesn’t
surfaceHeight = – 300 — no interaction at all
Wink
ok I’ll look into this now. Thanks so much for letting me know!
Hey Seb,
I’ve got a bunch of MovieMaterials that are working fine (interactivity wise), but my reflection is off. It’s as if the Reflection’s Camera’s Pitch and Z are off. It’s weird. I can send you code if you would like.
Thanks,
Seantron
Hi Seantron,
yes please do send me code, and I’ll check it out.
The DisplayObject3D rotation refactoring seems to be screwing this up, so I’ll see what I can do.
cheers!
Seb
Hi Seb…
any luck with the ‘bug’ or what it is…?
Hi Wink, yes as I suspected it’s to do with the new rotation stuff… but I’m on it…
cheers!
Seb
nice thinking behind that class mate.
do you think there is any way the reflection can be tapered off the further away it is from the main object?
Hi Paul,
yes there are several ways to do this, mostly involving layers. I will be integrating this in to reflection view at some point!
cheers!
Seb
Hi, I’ve been using you ReflectionView for a while and it’s wonderful!.
I had some problems setting it up, thought: I have to manually set its size to the size defined by the stage, because if not, the projection of the reflection does not match the original projection. Maybe you need to trap the resize events, or recompute the projection on every frame?
thanks in advance!
Hi, I was looking for something like that, but where dit it go? its not in the ‘view’-folder. Am i looking in the wrong place?
thanks,
maik
Hi Maik,
it’s inorg.papervision3d.core.effects.view.ReflectionView – maybe we should move it to view – what do you think?
Seb
Hey Seb great work!!
I’m curious where you’re at with that interactivity bug. I’m having the same issue, but using BasicView it works fine. If you need any more info or code, or anything I can do just let me know! Thanks and great work so far!
awesome! thanx for the demo!
Hi Seb…
I see there is a problem with interaction. Just found it out and now read it here…
I also encounter this: I am not able to change my surfaceHeight. It stays 0….No matter what value I try to give it…..very strange… If I change it in the class it works…
With kind regards. Wink
I found something out.
I placed surfaceHeight = -300; above the line super(etc..etc);
If I place it under the super() line, the surfaceHeigt works fine..
BUT!!!!
If I do NOT!!! set a value for surfaceHeight. I DO have interactivity. If I set a value for surfaceHeight, my interactivity is GONE!
I do not know if you allready knew that…just found it out. Can it be that the reflection is layered “over” the original???
Interactivity and surfaceHeight are connected. I
Hi guys,
I’ve made some changes to ReflectionView (and in fact IteractiveSceneManager) which hopefully should fix these problems.
There still seems to be a little weirdness with interactivity and rendering multiple viewports (ReflectionView is basically just 2 viewports) but we’re looking into this now…
cheers!
Seb
Hi
After revision 686-687, all interactivity in my project is gone!
Before today’s update, I had interactivity (I was receiving OVER events every time I moved the mouse over an interactive object, and random OUT events, never receiving MOVE events even if I registered for them)
But since today’s update, I don’t receive any event at all!!