Problem using VectorVision with RenderLayers
July 13th, 2009

While developing a Papervision 3D site I stumbled across John Lindquists tutorial on RenderLayers. To optimize my code I chose to render part of the scene only once and the rest of the scene 30 times a second, this can be achieved using render layers. For more info regarding this visit the tutorial mentioned above. Anyway since the site I’m developing includes text I’ve been using VectorVision, now a part of the Papervision 3D package. This is where the problem occurs.
When using the Text3D Class in a RenderLayer the layer merges with the layer rendered in the previous frame, causing the problem seen in the picture above. The desired effect is obviously that the old layer should be wiped clean when a new frame is being rendered. Keep in mind though that this problem only occurs when rendering the scene using render layers. Rendering the entire scene using this syntax: renderer.renderScene(scene, camera, viewport); renders the scene without any problems. To recreate the bug launch the example below and press down the left key on the keyboard. This will render the left RenderLayer containing the text. The right layer containing a sphere is rendered by holding down the right key. The right layer renders correctly since it doesn’t contain any instances of the Text3D Class.
If there are any developers out there who can tell me why this is happening go ahead and write a comment. Or even better if a member of the Papervision 3D crew would take a look at the problem and provide a fix for this bug.
(This example of the bug is based on the example written by John Lindquist)
package { import flash.events.Event; import flash.events.KeyboardEvent; import flash.ui.Keyboard; import org.papervision3d.core.proto.MaterialObject3D; import org.papervision3d.lights.PointLight3D; import org.papervision3d.materials.shadematerials.FlatShadeMaterial; import org.papervision3d.objects.primitives.Sphere; import org.papervision3d.view.BasicView; import org.papervision3d.view.layer.ViewportLayer; import org.papervision3d.materials.special.Letter3DMaterial; import org.papervision3d.typography.Font3D; import org.papervision3d.typography.Text3D; import org.papervision3d.typography.fonts.HelveticaBold; [SWF(width="900", height="480", backgroundColor="#ffffff", frameRate="30")] public class RenderLayers extends BasicView { private var isLeftRendering:Boolean = false; private var isRightRendering:Boolean = false; private var rightSphere:Sphere; private var text3D:Text3D; private var rightLayers:Array = []; private var leftLayers:Array = []; public function RenderLayers() { super(900, 480, false, false); var light:PointLight3D = new PointLight3D(true); var rightSphereMaterial:MaterialObject3D = new FlatShadeMaterial(light, 0x00cc00, 0x111111, 10); rightSphere = new Sphere(rightSphereMaterial, 300); rightSphere.x = 500; //Adding text3D var letter3DMaterial:Letter3DMaterial=new Letter3DMaterial(0x666666); letter3DMaterial.doubleSided=true; var font3D:HelveticaBold = new HelveticaBold(); text3D = new Text3D("text3D",font3D,letter3DMaterial); text3D.name = "text3D"; text3D.x=-500; scene.addChild( text3D ); var leftSphereLayer:ViewportLayer = new ViewportLayer(viewport, text3D); viewport.containerSprite.addLayer(leftSphereLayer); leftLayers.push(leftSphereLayer); var rightSphereLayer:ViewportLayer = new ViewportLayer(viewport, rightSphere); viewport.containerSprite.addLayer(rightSphereLayer); rightLayers.push(rightSphereLayer); scene.addChild(rightSphere); //Render once so the text and sphere appear renderer.renderScene(scene, camera, viewport); startRendering(); stage.addEventListener(KeyboardEvent.KEY_DOWN, stage_keyDownHandler); stage.addEventListener(KeyboardEvent.KEY_UP, stage_keyUpHandler); } private function stage_keyDownHandler(event:KeyboardEvent):void { switch(event.keyCode) { case Keyboard.LEFT: isLeftRendering = true; break; case Keyboard.RIGHT: isRightRendering = true; break; } } private function stage_keyUpHandler(event:KeyboardEvent):void { switch(event.keyCode) { case Keyboard.LEFT: isLeftRendering = false; break; case Keyboard.RIGHT: isRightRendering = false; break; } } override protected function onRenderTick(event:Event = null):void { //The text and sphere are always rotating text3D.rotationX++; rightSphere.rotationX--; //But they're only rendered if their selected layer is rendered if(isLeftRendering) { //This is were the bug occurs renderer.renderLayers(scene, camera, viewport, leftLayers); //This renders the entire scene without problems //renderer.renderScene(scene, camera, viewport); } if(isRightRendering) { renderer.renderLayers(scene, camera, viewport, rightLayers); } } } }
Entry Filed under: Papervision 3D

1 Comment Add your own
1. jofo | January 22nd, 2010 at 16.47
Did you ever find a solution? I’m having the same problem with a model exported from blender with the as3 export plugin. I only found one other bug like this with a google search. that was about a dae model and had a solution that soubled the triangles. I can’t afford that If you hit on something, let me know
Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">
Trackback this post | Subscribe to the comments via RSS Feed