<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Andy&#039;s BloG &#124; Andreas Hamberg &#124; Hemsida, blog samt portfolio. &#187; Papervision 3D</title>
	<atom:link href="http://www.andreashamberg.com/category/papervision-3d/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.andreashamberg.com</link>
	<description>Andreas Hambergs blog om webbdesign, printdesign, teckning, politik, riksdagsvalet 2007 samt personliga portfolio.</description>
	<lastBuildDate>Fri, 11 Nov 2011 10:17:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Problem using VectorVision with RenderLayers</title>
		<link>http://www.andreashamberg.com/2009/07/13/problem-using-vectorvision-with-renderlayers/</link>
		<comments>http://www.andreashamberg.com/2009/07/13/problem-using-vectorvision-with-renderlayers/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 15:13:43 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Papervision 3D]]></category>

		<guid isPermaLink="false">http://www.andreashamberg.com/?p=55</guid>
		<description><![CDATA[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. [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.andreashamberg.com/wp-content/uploads/2009/07/text3D.jpg" alt="text3D" title="text3D" width="514" height="430" class="alignnone size-full wp-image-62" /><br />
While developing a Papervision 3D site I stumbled across <a href="http://pv3d.org/2009/03/30/renderlayers-selective-rendering/">John Lindquists tutorial</a> 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&#8217;m developing includes text I&#8217;ve been using VectorVision, now a part of the Papervision 3D package. This is where the problem occurs.</p>
<p>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&#8217;t contain any instances of the Text3D Class.</p>
<p>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.</p>
<p>(This <a title="Papervision 3D using VectorVision with RenderLayer example" href="http://www.andreashamberg.com/flash/" target="_blank">example</a> of the bug is based on the example written by John Lindquist)</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">Event</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">KeyboardEvent</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.ui</span>.<span style="color: #004993;">Keyboard</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> org.papervision3d.core.proto.MaterialObject3D;
	<span style="color: #0033ff; font-weight: bold;">import</span> org.papervision3d.lights.PointLight3D;
	<span style="color: #0033ff; font-weight: bold;">import</span> org.papervision3d.materials.shadematerials.FlatShadeMaterial;
	<span style="color: #0033ff; font-weight: bold;">import</span> org.papervision3d.objects.primitives.Sphere;
	<span style="color: #0033ff; font-weight: bold;">import</span> org.papervision3d.view.BasicView;
	<span style="color: #0033ff; font-weight: bold;">import</span> org.papervision3d.view.layer.ViewportLayer;
	<span style="color: #0033ff; font-weight: bold;">import</span> org.papervision3d.materials.special.Letter3DMaterial;
	<span style="color: #0033ff; font-weight: bold;">import</span> org.papervision3d.typography.Font3D;
	<span style="color: #0033ff; font-weight: bold;">import</span> org.papervision3d.typography.Text3D;
	<span style="color: #0033ff; font-weight: bold;">import</span> org.papervision3d.typography.fonts.HelveticaBold;
&nbsp;
	<span style="color: #000000;">&#91;</span>SWF<span style="color: #000000;">&#40;</span><span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;900&quot;</span>, <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;480&quot;</span>, <span style="color: #004993;">backgroundColor</span>=<span style="color: #990000;">&quot;#ffffff&quot;</span>, <span style="color: #004993;">frameRate</span>=<span style="color: #990000;">&quot;30&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> RenderLayers extends BasicView
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> isLeftRendering<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = <span style="color: #0033ff; font-weight: bold;">false</span>;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> isRightRendering<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = <span style="color: #0033ff; font-weight: bold;">false</span>;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> rightSphere<span style="color: #000000; font-weight: bold;">:</span>Sphere;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> text3D<span style="color: #000000; font-weight: bold;">:</span>Text3D;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> rightLayers<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span>;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> leftLayers<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span>;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> RenderLayers<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">900</span>, <span style="color: #000000; font-weight:bold;">480</span>, <span style="color: #0033ff; font-weight: bold;">false</span>, <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> light<span style="color: #000000; font-weight: bold;">:</span>PointLight3D = <span style="color: #0033ff; font-weight: bold;">new</span> PointLight3D<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #6699cc; font-weight: bold;">var</span> rightSphereMaterial<span style="color: #000000; font-weight: bold;">:</span>MaterialObject3D = <span style="color: #0033ff; font-weight: bold;">new</span> FlatShadeMaterial<span style="color: #000000;">&#40;</span>light, 0x00cc00, 0x111111, <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span>;
			rightSphere = <span style="color: #0033ff; font-weight: bold;">new</span> Sphere<span style="color: #000000;">&#40;</span>rightSphereMaterial, <span style="color: #000000; font-weight:bold;">300</span><span style="color: #000000;">&#41;</span>;
			rightSphere.<span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">500</span>;
&nbsp;
			<span style="color: #009900;">//Adding text3D</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> letter3DMaterial<span style="color: #000000; font-weight: bold;">:</span>Letter3DMaterial=<span style="color: #0033ff; font-weight: bold;">new</span> Letter3DMaterial<span style="color: #000000;">&#40;</span>0x666666<span style="color: #000000;">&#41;</span>;
			letter3DMaterial.doubleSided=<span style="color: #0033ff; font-weight: bold;">true</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> font3D<span style="color: #000000; font-weight: bold;">:</span>HelveticaBold = <span style="color: #0033ff; font-weight: bold;">new</span> HelveticaBold<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			text3D = <span style="color: #0033ff; font-weight: bold;">new</span> Text3D<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;text3D&quot;</span>,font3D,letter3DMaterial<span style="color: #000000;">&#41;</span>;
			text3D.<span style="color: #004993;">name</span> = <span style="color: #990000;">&quot;text3D&quot;</span>;
			text3D.<span style="color: #004993;">x</span>=<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">500</span>;
			scene.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span> text3D <span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #6699cc; font-weight: bold;">var</span> leftSphereLayer<span style="color: #000000; font-weight: bold;">:</span>ViewportLayer = <span style="color: #0033ff; font-weight: bold;">new</span> ViewportLayer<span style="color: #000000;">&#40;</span>viewport, text3D<span style="color: #000000;">&#41;</span>;
			viewport.containerSprite.addLayer<span style="color: #000000;">&#40;</span>leftSphereLayer<span style="color: #000000;">&#41;</span>;
			leftLayers.<span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>leftSphereLayer<span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #6699cc; font-weight: bold;">var</span> rightSphereLayer<span style="color: #000000; font-weight: bold;">:</span>ViewportLayer = <span style="color: #0033ff; font-weight: bold;">new</span> ViewportLayer<span style="color: #000000;">&#40;</span>viewport, rightSphere<span style="color: #000000;">&#41;</span>;
			viewport.containerSprite.addLayer<span style="color: #000000;">&#40;</span>rightSphereLayer<span style="color: #000000;">&#41;</span>;
			rightLayers.<span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>rightSphereLayer<span style="color: #000000;">&#41;</span>;
&nbsp;
			scene.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>rightSphere<span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #009900;">//Render once so the text and sphere appear</span>
			renderer.renderScene<span style="color: #000000;">&#40;</span>scene, camera, viewport<span style="color: #000000;">&#41;</span>;
&nbsp;
			startRendering<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">KeyboardEvent</span>.<span style="color: #004993;">KEY_DOWN</span>, stage_keyDownHandler<span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">KeyboardEvent</span>.<span style="color: #004993;">KEY_UP</span>, stage_keyUpHandler<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> stage_keyDownHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">KeyboardEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">switch</span><span style="color: #000000;">&#40;</span>event.<span style="color: #004993;">keyCode</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #004993;">Keyboard</span>.<span style="color: #004993;">LEFT</span><span style="color: #000000; font-weight: bold;">:</span>
					isLeftRendering = <span style="color: #0033ff; font-weight: bold;">true</span>;
					<span style="color: #0033ff; font-weight: bold;">break</span>;
&nbsp;
				<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #004993;">Keyboard</span>.<span style="color: #004993;">RIGHT</span><span style="color: #000000; font-weight: bold;">:</span>
					isRightRendering = <span style="color: #0033ff; font-weight: bold;">true</span>;
					<span style="color: #0033ff; font-weight: bold;">break</span>;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> stage_keyUpHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">KeyboardEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">switch</span><span style="color: #000000;">&#40;</span>event.<span style="color: #004993;">keyCode</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #004993;">Keyboard</span>.<span style="color: #004993;">LEFT</span><span style="color: #000000; font-weight: bold;">:</span>
					isLeftRendering = <span style="color: #0033ff; font-weight: bold;">false</span>;
					<span style="color: #0033ff; font-weight: bold;">break</span>;
&nbsp;
				<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #004993;">Keyboard</span>.<span style="color: #004993;">RIGHT</span><span style="color: #000000; font-weight: bold;">:</span>
					isRightRendering = <span style="color: #0033ff; font-weight: bold;">false</span>;
					<span style="color: #0033ff; font-weight: bold;">break</span>;
			<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		override <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> onRenderTick<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Event</span> = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #009900;">//The text and sphere are always rotating</span>
			text3D.rotationX<span style="color: #000000; font-weight: bold;">++</span>;
			rightSphere.rotationX<span style="color: #000000; font-weight: bold;">--</span>;
&nbsp;
			<span style="color: #009900;">//But they're only rendered if their selected layer is rendered</span>
			<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>isLeftRendering<span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #009900;">//This is were the bug occurs</span>
				renderer.renderLayers<span style="color: #000000;">&#40;</span>scene, camera, viewport, leftLayers<span style="color: #000000;">&#41;</span>;
				<span style="color: #009900;">//This renders the entire scene without problems</span>
				<span style="color: #009900;">//renderer.renderScene(scene, camera, viewport);</span>
			<span style="color: #000000;">&#125;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>isRightRendering<span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				renderer.renderLayers<span style="color: #000000;">&#40;</span>scene, camera, viewport, rightLayers<span style="color: #000000;">&#41;</span>;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.andreashamberg.com/2009/07/13/problem-using-vectorvision-with-renderlayers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

