<?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>Raphael Wichmann &#187; displayobject3d</title>
	<atom:link href="http://www.rwichmann.com/tag/displayobject3d/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rwichmann.com</link>
	<description>ActionScript and other computer related stuff.</description>
	<lastBuildDate>Tue, 30 Aug 2011 10:58:12 +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>Creating Custom 3D DisplayObjects in Papervision &#8211; Part 3</title>
		<link>http://www.rwichmann.com/2009/05/27/creating-custom-3d-displayobjects-in-papervision-part-3/</link>
		<comments>http://www.rwichmann.com/2009/05/27/creating-custom-3d-displayobjects-in-papervision-part-3/#comments</comments>
		<pubDate>Wed, 27 May 2009 19:30:39 +0000</pubDate>
		<dc:creator>Raphael</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[displayobject3d]]></category>
		<category><![CDATA[mesh]]></category>
		<category><![CDATA[papervision]]></category>

		<guid isPermaLink="false">http://www.rwichmann.com/?p=217</guid>
		<description><![CDATA[Ok, now it&#8217;s getting really interesting! In the last posts you learned how to set up your own custom Papervision object and how to display textures on it. Now we are going to animate our object. The idea behind is pretty simple. You add an Event.ENTER_FRAME handler to your object and in every frame you [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, now it&#8217;s getting really interesting! In the last posts you learned how to set up your own custom Papervision object and how to display textures on it.</p>
<p>Now we are going to animate our object. The idea behind is pretty simple. You add an Event.ENTER_FRAME handler to your object and in every frame you add new vertices to your object, draw new triangles and if there are already enough triangles you remove the one you don&#8217;t need anymore.</p>
<p>In detail it will work like this: In every frame we create 2 new vertices and draw 2 new triangles with it. But to draw 2 triangels we need a minimum of 4 vertices. So we take the the last ones we added the frame before.<br />
In every frame we take slightly different coordinates so that or vertices are moving.<br />
Theres only one situation that is special. It is when we start our Event.ENTER_FRAME handler we don&#8217;t have 4 vertices. So we just add 2 vertices and wait for the next frame. And this is the code:</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> AnimatedMesh <span style="color: #000000;">&#40;</span>meshMaterial <span style="color: #000066; font-weight: bold;">:</span> MaterialObject3D<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">stage</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Stage</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span> meshMaterial<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; _stage = <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; _count = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; _width = <span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; _stage<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> onEnterFrame <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onEnterFrame <span style="color: #000000;">&#40;</span>event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> vertices <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Array</span> = geometry<span style="color: #000066; font-weight: bold;">.</span>vertices<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> faces <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Array</span> = geometry<span style="color: #000066; font-weight: bold;">.</span>faces<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> v1 <span style="color: #000066; font-weight: bold;">:</span> Vertex3D<span style="color: #000066; font-weight: bold;">,</span> v2 <span style="color: #000066; font-weight: bold;">:</span> Vertex3D<span style="color: #000066; font-weight: bold;">,</span> v3 <span style="color: #000066; font-weight: bold;">:</span> Vertex3D<span style="color: #000066; font-weight: bold;">,</span> v4 <span style="color: #000066; font-weight: bold;">:</span> Vertex3D<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> z<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = _count <span style="color: #000066; font-weight: bold;">*</span> _width<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>vertices<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> == <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; v1 = <span style="color: #0033ff; font-weight: bold;">new</span> Vertex3D<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> z <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; v2 = <span style="color: #0033ff; font-weight: bold;">new</span> Vertex3D<span style="color: #000000;">&#40;</span> _width<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> z <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; vertices<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span> v1<span style="color: #000066; font-weight: bold;">,</span> v2 <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">else</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; v1 = vertices<span style="color: #000000;">&#91;</span>vertices<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; v2 = vertices<span style="color: #000000;">&#91;</span>vertices<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; v3 = <span style="color: #0033ff; font-weight: bold;">new</span> Vertex3D<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> z <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; v4 = <span style="color: #0033ff; font-weight: bold;">new</span> Vertex3D<span style="color: #000000;">&#40;</span> _width<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> z <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; vertices<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span> v3<span style="color: #000066; font-weight: bold;">,</span> v4 <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> triangle1Vertices <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Array</span> = <span style="color: #000000;">&#91;</span> v1<span style="color: #000066; font-weight: bold;">,</span> v2<span style="color: #000066; font-weight: bold;">,</span> v3 <span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> triangle1Face <span style="color: #000066; font-weight: bold;">:</span> Triangle3D = <span style="color: #0033ff; font-weight: bold;">new</span> Triangle3D<span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">,</span> triangle1Vertices<span style="color: #000066; font-weight: bold;">,</span> material<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">null</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; faces<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span> triangle1Face <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> triangle2Vertices <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Array</span> = <span style="color: #000000;">&#91;</span> v2<span style="color: #000066; font-weight: bold;">,</span> v3<span style="color: #000066; font-weight: bold;">,</span> v4 <span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> triangle2Face <span style="color: #000066; font-weight: bold;">:</span> Triangle3D = <span style="color: #0033ff; font-weight: bold;">new</span> Triangle3D<span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">,</span> triangle2Vertices<span style="color: #000066; font-weight: bold;">,</span> material<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">null</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; faces<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span> triangle2Face <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; geometry<span style="color: #000066; font-weight: bold;">.</span>ready = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; _count<span style="color: #000066; font-weight: bold;">++;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>And the compiled SWF looks like this. If you try it for yourself and you just see a growing line, move your camera up.<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_custommesh_animated0_789106922"
			class="flashmovie"
			width="455"
			height="256">
	<param name="movie" value="/swf/custommesh_animated0.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/swf/custommesh_animated0.swf"
			name="fm_custommesh_animated0_789106922"
			width="455"
			height="256">
	<!--<![endif]-->
		<br />
<a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a><br />

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object><br />
Simply adding the same value to one axis is pretty boring. If you draw a circle with Sinus and Cosinus its getting better. I also deleted some vertices and faces if we have enough from them:</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> AnimatedMesh <span style="color: #000000;">&#40;</span>meshMaterial <span style="color: #000066; font-weight: bold;">:</span> MaterialObject3D<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">stage</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Stage</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span> meshMaterial<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; _stage = <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; _count = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; _segments = <span style="color: #000000; font-weight:bold;">40</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; _width = <span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; _radius = <span style="color: #000000; font-weight:bold;">300</span><span style="color: #000066; font-weight: bold;">;</span> <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; _stage<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> onEnterFrame <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span> &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onEnterFrame <span style="color: #000000;">&#40;</span>event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> vertices <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Array</span> = geometry<span style="color: #000066; font-weight: bold;">.</span>vertices<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> faces <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Array</span> = geometry<span style="color: #000066; font-weight: bold;">.</span>faces<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> v1 <span style="color: #000066; font-weight: bold;">:</span> Vertex3D<span style="color: #000066; font-weight: bold;">,</span> v2 <span style="color: #000066; font-weight: bold;">:</span> Vertex3D<span style="color: #000066; font-weight: bold;">,</span> v3 <span style="color: #000066; font-weight: bold;">:</span> Vertex3D<span style="color: #000066; font-weight: bold;">,</span> v4 <span style="color: #000066; font-weight: bold;">:</span> Vertex3D<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Number</span> = <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cos</span><span style="color: #000000;">&#40;</span> _count <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">8</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> _radius<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> z <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Number</span> = <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><span style="color: #000000;">&#40;</span> _count <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">8</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> _radius<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>vertices<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> == <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; v1 = <span style="color: #0033ff; font-weight: bold;">new</span> Vertex3D<span style="color: #000000;">&#40;</span> <span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span> z <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; v2 = <span style="color: #0033ff; font-weight: bold;">new</span> Vertex3D<span style="color: #000000;">&#40;</span> <span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">+</span> _width<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span> z <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; vertices<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span> v1<span style="color: #000066; font-weight: bold;">,</span> v2 <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">else</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; v1 = vertices<span style="color: #000000;">&#91;</span>vertices<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; v2 = vertices<span style="color: #000000;">&#91;</span>vertices<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; v3 = <span style="color: #0033ff; font-weight: bold;">new</span> Vertex3D<span style="color: #000000;">&#40;</span> <span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span> z <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; v4 = <span style="color: #0033ff; font-weight: bold;">new</span> Vertex3D<span style="color: #000000;">&#40;</span> <span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">+</span> _width<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span> z <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; vertices<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span> v3<span style="color: #000066; font-weight: bold;">,</span> v4 <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> triangle1Vertices <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Array</span> = <span style="color: #000000;">&#91;</span> v1<span style="color: #000066; font-weight: bold;">,</span> v2<span style="color: #000066; font-weight: bold;">,</span> v3 <span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> triangle1Face <span style="color: #000066; font-weight: bold;">:</span> Triangle3D = <span style="color: #0033ff; font-weight: bold;">new</span> Triangle3D<span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">,</span> triangle1Vertices<span style="color: #000066; font-weight: bold;">,</span> material<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">null</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; faces<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span> triangle1Face <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> triangle2Vertices <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Array</span> = <span style="color: #000000;">&#91;</span> v2<span style="color: #000066; font-weight: bold;">,</span> v3<span style="color: #000066; font-weight: bold;">,</span> v4 <span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> triangle2Face <span style="color: #000066; font-weight: bold;">:</span> Triangle3D = <span style="color: #0033ff; font-weight: bold;">new</span> Triangle3D<span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">,</span> triangle2Vertices<span style="color: #000066; font-weight: bold;">,</span> material<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">null</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; faces<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span> triangle2Face <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; geometry<span style="color: #000066; font-weight: bold;">.</span>ready = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; _count<span style="color: #000066; font-weight: bold;">++;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>_count <span style="color: #000066; font-weight: bold;">&gt;</span> _segments<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; vertices<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">splice</span><span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; faces<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">splice</span><span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>And the compiled SWF:<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_custommesh_animated1_36166745"
			class="flashmovie"
			width="455"
			height="256">
	<param name="movie" value="/swf/custommesh_animated1.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/swf/custommesh_animated1.swf"
			name="fm_custommesh_animated1_36166745"
			width="455"
			height="256">
	<!--<![endif]-->
		<br />
<a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a><br />

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object><br />
That&#8217;s a nice circle.<br />
If you change this line</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>to this line</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Number</span> = <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><span style="color: #000000;">&#40;</span> _count <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">5</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> _radius<span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>The result is this:<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_custommesh_animated2_1895892025"
			class="flashmovie"
			width="455"
			height="256">
	<param name="movie" value="/swf/custommesh_animated2.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/swf/custommesh_animated2.swf"
			name="fm_custommesh_animated2_1895892025"
			width="455"
			height="256">
	<!--<![endif]-->
		<br />
<a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a><br />

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object><br />
Now I just changed the material from WireFrameMaterial to ColorMaterial and I drew the whole scene to a BitmapData added a BlurFilter and a ColorTransform.<br />
Then you finally get this <img src='http://www.rwichmann.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_custommesh_final_1940580776"
			class="flashmovie"
			width="455"
			height="256">
	<param name="movie" value="/swf/custommesh_final.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/swf/custommesh_final.swf"
			name="fm_custommesh_final_1940580776"
			width="455"
			height="256">
	<!--<![endif]-->
		<br />
<a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a><br />

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>
I hope that helped you to understand the basic principle of animating objects in Papervision. If you got it you can do so many cool things with it. Imaging that you could code for examle a flying paper in the wind or a moving sea! Or you could transform spheres to planes or whatever you want.</p>
<p>I think it is great, I&#8217;m just waiting for my next project where I can make use of that! <img src='http://www.rwichmann.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.rwichmann.com/2009/05/27/creating-custom-3d-displayobjects-in-papervision-part-3/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Creating Custom 3D DisplayObjects in Papervision &#8211; Part 2</title>
		<link>http://www.rwichmann.com/2009/05/03/creating-custom-3d-displayobjects-in-papervision-part-2/</link>
		<comments>http://www.rwichmann.com/2009/05/03/creating-custom-3d-displayobjects-in-papervision-part-2/#comments</comments>
		<pubDate>Sun, 03 May 2009 10:07:35 +0000</pubDate>
		<dc:creator>Raphael</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[displayobject3d]]></category>
		<category><![CDATA[mesh]]></category>
		<category><![CDATA[papervision]]></category>

		<guid isPermaLink="false">http://www.rwichmann.com/?p=181</guid>
		<description><![CDATA[Ok, now that you know how to set up your own custom object in Papervision I&#8217;m going to show you how texture maps work. In the preceding Post we omitted the texture map in our face. So if you want to apply a BitmapMaterial to your object you won&#8217;t see the texture. So we need [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, now that you know how to set up your own custom object in Papervision I&#8217;m going to show you how texture maps work.</p>
<p>In the preceding Post we omitted the texture map in our face. So if you want to apply a BitmapMaterial to your object you won&#8217;t see the texture. So we need a texture map.</p>
<p>The first thing we are going to do is adding another triangle and making our object a rectangle. Something like the Plane primitive. A rectangle consists of a minimum of 2 triangles. So if we want to draw another triangle we need one more vertex.</p>
<p>Ok, so the code will look like this:</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> CustomTriangle <span style="color: #000000;">&#40;</span>triangleMaterial <span style="color: #000066; font-weight: bold;">:</span> MaterialObject3D<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span> triangleMaterial<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> v1 <span style="color: #000066; font-weight: bold;">:</span> Vertex3D = <span style="color: #0033ff; font-weight: bold;">new</span> Vertex3D<span style="color: #000000;">&#40;</span> <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> v2 <span style="color: #000066; font-weight: bold;">:</span> Vertex3D = <span style="color: #0033ff; font-weight: bold;">new</span> Vertex3D<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> v3 <span style="color: #000066; font-weight: bold;">:</span> Vertex3D = <span style="color: #0033ff; font-weight: bold;">new</span> Vertex3D<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> v4 <span style="color: #000066; font-weight: bold;">:</span> Vertex3D = <span style="color: #0033ff; font-weight: bold;">new</span> Vertex3D<span style="color: #000000;">&#40;</span> <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; geometry<span style="color: #000066; font-weight: bold;">.</span>vertices<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span> v1<span style="color: #000066; font-weight: bold;">,</span> v2<span style="color: #000066; font-weight: bold;">,</span> v3<span style="color: #000066; font-weight: bold;">,</span> v4 <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> triangleVertices1 <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Array</span> = <span style="color: #000000;">&#91;</span> v1<span style="color: #000066; font-weight: bold;">,</span> v2<span style="color: #000066; font-weight: bold;">,</span> v3 <span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> triangleFace1 <span style="color: #000066; font-weight: bold;">:</span> Triangle3D = <span style="color: #0033ff; font-weight: bold;">new</span> Triangle3D<span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">,</span> triangleVertices1<span style="color: #000066; font-weight: bold;">,</span> material <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; geometry<span style="color: #000066; font-weight: bold;">.</span>faces<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span> triangleFace1 <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> triangleVertices2 <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Array</span> = <span style="color: #000000;">&#91;</span> v1<span style="color: #000066; font-weight: bold;">,</span> v3<span style="color: #000066; font-weight: bold;">,</span> v4 <span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> triangleFace2 <span style="color: #000066; font-weight: bold;">:</span> Triangle3D = <span style="color: #0033ff; font-weight: bold;">new</span> Triangle3D<span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">,</span> triangleVertices2<span style="color: #000066; font-weight: bold;">,</span> material <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; geometry<span style="color: #000066; font-weight: bold;">.</span>faces<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span> triangleFace2 <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <br />
<br />
&nbsp; &nbsp; geometry<span style="color: #000066; font-weight: bold;">.</span>ready = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>We added another vertex and built another face. As you see we used the same vertices we used with our first face. That is pretty important to understand. The vertices are not bound to the triangles. We can use them with different triangles. They are just coordinates in our 3D space.</p>
<p>Ok, our new rectangle will look like this now. I applied a WireFrameMaterial to it because it is better to see the triangles we made:<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_custommesh_rectangle_355086468"
			class="flashmovie"
			width="455"
			height="256">
	<param name="movie" value="/swf/custommesh_rectangle.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/swf/custommesh_rectangle.swf"
			name="fm_custommesh_rectangle_355086468"
			width="455"
			height="256">
	<!--<![endif]-->
		<br />
<a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a><br />

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>Ok, now it is getting interesting. We have our object and we want to apply a BitmapMaterial to it. If you already tried that you would have realized that your object did not show the texture. That is because the texture maps were missing in our faces.</p>
<p>A texture map is basically the information about where to display which part of the texture in every face or triangle. So every triangle gets its own texture map. And because every triangle consists of 3 vertices our texture map will need 3 information about the position of the texture. The information is an instance of the NumberUV class which holds two properties. The u and the v. Which represent the horizontal and vertical axes of our texture. Think of them as x- and y-axes. Textures are always 2D so we don&#8217;t have a z-axis here.<br />
The u and v are numbers which go from 0 to 1. u=0 means the most left pixel of our texture and u=1 is the most right pixel in our texture. </p>
<p>Ok, so we take our first triangle which consists of these three vertices:</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6699cc; font-weight: bold;">var</span> triangleVertices1 <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Array</span> = <span style="color: #000000;">&#91;</span> v1<span style="color: #000066; font-weight: bold;">,</span> v2<span style="color: #000066; font-weight: bold;">,</span> v3 <span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>v1 is the vertex in the lower left corner. That means it should display the lower left corner of our texture. That represents u=0 and v=0. You might have noticed that the y-axis is flipped in Papervision.<br />
v2 is in the lower right corner which represents u=1 and v=0. v3 is on the upper right corner and so it gets u=1 and v=1.</p>
<p>In code this will look like this:</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6699cc; font-weight: bold;">var</span> triangleTextureMap1 <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Array</span> = <span style="color: #000000;">&#91;</span> <span style="color: #0033ff; font-weight: bold;">new</span> NumberUV<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">new</span> NumberUV<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">new</span> NumberUV<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>Ok, now we need to pass our triangle the texturemap.<br />
Before:</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6699cc; font-weight: bold;">var</span> triangleFace1 <span style="color: #000066; font-weight: bold;">:</span> Triangle3D = <span style="color: #0033ff; font-weight: bold;">new</span> Triangle3D<span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">,</span> triangleVertices1<span style="color: #000066; font-weight: bold;">,</span> material <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>After:</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6699cc; font-weight: bold;">var</span> triangleFace1 <span style="color: #000066; font-weight: bold;">:</span> Triangle3D = <span style="color: #0033ff; font-weight: bold;">new</span> Triangle3D<span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">,</span> triangleVertices1<span style="color: #000066; font-weight: bold;">,</span> material<span style="color: #000066; font-weight: bold;">,</span> triangleTextureMap1 <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>Ok, so we have to do the same for our second triangle. I hope it is clear now how to handle the second texturemap. Our class will look like this now:</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> CustomTriangle <span style="color: #000000;">&#40;</span>triangleMaterial <span style="color: #000066; font-weight: bold;">:</span> MaterialObject3D<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span> triangleMaterial<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> v1 <span style="color: #000066; font-weight: bold;">:</span> Vertex3D = <span style="color: #0033ff; font-weight: bold;">new</span> Vertex3D<span style="color: #000000;">&#40;</span> <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> v2 <span style="color: #000066; font-weight: bold;">:</span> Vertex3D = <span style="color: #0033ff; font-weight: bold;">new</span> Vertex3D<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> v3 <span style="color: #000066; font-weight: bold;">:</span> Vertex3D = <span style="color: #0033ff; font-weight: bold;">new</span> Vertex3D<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> v4 <span style="color: #000066; font-weight: bold;">:</span> Vertex3D = <span style="color: #0033ff; font-weight: bold;">new</span> Vertex3D<span style="color: #000000;">&#40;</span> <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; geometry<span style="color: #000066; font-weight: bold;">.</span>vertices<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span> v1<span style="color: #000066; font-weight: bold;">,</span> v2<span style="color: #000066; font-weight: bold;">,</span> v3<span style="color: #000066; font-weight: bold;">,</span> v4 <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> triangleVertices1 <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Array</span> = <span style="color: #000000;">&#91;</span> v1<span style="color: #000066; font-weight: bold;">,</span> v2<span style="color: #000066; font-weight: bold;">,</span> v3 <span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> triangleTextureMap1 <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Array</span> = <span style="color: #000000;">&#91;</span> <span style="color: #0033ff; font-weight: bold;">new</span> NumberUV<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">new</span> NumberUV<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">new</span> NumberUV<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> triangleFace1 <span style="color: #000066; font-weight: bold;">:</span> Triangle3D = <span style="color: #0033ff; font-weight: bold;">new</span> Triangle3D<span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">,</span> triangleVertices1<span style="color: #000066; font-weight: bold;">,</span> material<span style="color: #000066; font-weight: bold;">,</span> triangleTextureMap1 <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; geometry<span style="color: #000066; font-weight: bold;">.</span>faces<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span> triangleFace1 <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> triangleVertices2 <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Array</span> = <span style="color: #000000;">&#91;</span> v1<span style="color: #000066; font-weight: bold;">,</span> v3<span style="color: #000066; font-weight: bold;">,</span> v4 <span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> triangleTextureMap2 <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Array</span> = <span style="color: #000000;">&#91;</span> <span style="color: #0033ff; font-weight: bold;">new</span> NumberUV<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">new</span> NumberUV<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">new</span> NumberUV<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> triangleFace2 <span style="color: #000066; font-weight: bold;">:</span> Triangle3D = <span style="color: #0033ff; font-weight: bold;">new</span> Triangle3D<span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">,</span> triangleVertices2<span style="color: #000066; font-weight: bold;">,</span> material<span style="color: #000066; font-weight: bold;">,</span> triangleTextureMap2 <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; geometry<span style="color: #000066; font-weight: bold;">.</span>faces<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span> triangleFace2 <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <br />
<br />
&nbsp; &nbsp; geometry<span style="color: #000066; font-weight: bold;">.</span>ready = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>And if you apply a BitmapMaterial from the outside to your object it will look like that:<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_custommesh_rectangle_tex_861296927"
			class="flashmovie"
			width="455"
			height="256">
	<param name="movie" value="/swf/custommesh_rectangle_tex.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/swf/custommesh_rectangle_tex.swf"
			name="fm_custommesh_rectangle_tex_861296927"
			width="455"
			height="256">
	<!--<![endif]-->
		<br />
<a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a><br />

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object><br />
It looks a bit distorted. This is because we should actually build up a rectangle with more than 2 triangles. The more you use the better the texture is rendered and the more your CPU needs to work.</p>
<p>We could also tell our texture map that we don&#8217;t want to display the whole texture. With your set of NumberUV instances you can practically tell every triangle to display a different part of your texture. Just use .5 instead of 1 to display only the lower left part of the texure for example. Let&#8217;s play around with the values and you will see what I mean.</p>
<p>Im changing the values of our first texture map like this:</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6699cc; font-weight: bold;">var</span> triangleTextureMap1 <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Array</span> = <span style="color: #000000;">&#91;</span> <span style="color: #0033ff; font-weight: bold;">new</span> NumberUV<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">new</span> NumberUV<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">new</span> NumberUV<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>I replaced the first with the last coordinate and the texture from our first triangle is rotated now:<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_custommesh_rectangle_tex_rot_1759609"
			class="flashmovie"
			width="455"
			height="256">
	<param name="movie" value="/swf/custommesh_rectangle_tex_rot.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/swf/custommesh_rectangle_tex_rot.swf"
			name="fm_custommesh_rectangle_tex_rot_1759609"
			width="455"
			height="256">
	<!--<![endif]-->
		<br />
<a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a><br />

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object><br />
It is just important for you to understand, that you can tell every triangle which part of the texture it should display.</p>
<p>Ok, thats it for now. In the next part we are going to animate our object.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rwichmann.com/2009/05/03/creating-custom-3d-displayobjects-in-papervision-part-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating Custom 3D DisplayObjects in Papervision &#8211; Part 1</title>
		<link>http://www.rwichmann.com/2009/04/08/creating-custom-3d-displayobjects-in-papervision-part-1/</link>
		<comments>http://www.rwichmann.com/2009/04/08/creating-custom-3d-displayobjects-in-papervision-part-1/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 12:01:24 +0000</pubDate>
		<dc:creator>Raphael</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[displayobject3d]]></category>
		<category><![CDATA[mesh]]></category>
		<category><![CDATA[papervision]]></category>

		<guid isPermaLink="false">http://www.rwichmann.com/?p=147</guid>
		<description><![CDATA[Have you ever thought of how to do these moving and transforming objects in Papervision? Click &#8220;Start&#8221; to see what I mean. 
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_custommesh_final_1343738381"
			class="flashmovie"
			width="455"
			height="256">
	<param name="movie" value="/swf/custommesh_final.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/swf/custommesh_final.swf"
			name="fm_custommesh_final_1343738381"
			width="455"
			height="256">
	<!--<![endif]-->
		 
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object> I did. My world was limited to the Papervision primitives and collada objects. Then I needed a growing and transforming object for my current project. [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever thought of how to do these moving and transforming objects in Papervision? Click &#8220;Start&#8221; to see what I mean.<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_custommesh_final_1520811930"
			class="flashmovie"
			width="455"
			height="256">
	<param name="movie" value="/swf/custommesh_final.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/swf/custommesh_final.swf"
			name="fm_custommesh_final_1520811930"
			width="455"
			height="256">
	<!--<![endif]-->
		<br />
<a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a><br />

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>I did. My world was limited to the Papervision primitives and collada objects. Then I needed a growing and transforming object for my current project. So I asked my friend Lars who already did things like that (he also created his own <a href="http://code.google.com/p/nd3d/" target="_blank">3D framework</a> by the way). He said that it is not that simple. I didn&#8217;t understand everything he was saying but had a rough idea in mind.</p>
<p>I found some information in the internet and set up my own custom object. Actually it is pretty much like drawing lines in ActionScript. You know this stuff:</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">shape<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span> 0xFF <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
shape<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">lineTo</span><span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
shape<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">lineTo</span><span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">100</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
shape<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">lineTo</span><span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>This will give you a blue triangle. That is easy.</p>
<p>Creating custom objects in a 3D world is pretty much the same.<br />
3D objects in Papervision are basically defined through vertices and faces. Vertices are something like Points in 3D Space. They are stored in an array called vertices and are instances of the Vertex3D class.</p>
<p>The faces are the triangles (polygons) you draw with your vertices. Easily spoken you take 3 vertices and build a triangle with them. You should know that every 3D Object is made out of triangles.<br />
And you also need tell your face how it should display a texture. If you just have a WireFrameMaterial or a ColorMaterial applied to your object you don&#8217;t need that necessarily. But you never know what kind of material people will use with your Object, so it is better to define it.</p>
<p>Let&#8217;s try that with a really simple custom 3D object. A triangle.<br />
I assume that you have basic Papervision knowledge and that you use Papervision 2.0 Great White.</p>
<p>Ok, this will look like this:</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #9900cc; font-weight: bold;">package</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> org<span style="color: #000066; font-weight: bold;">.</span>papervision3d<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>geom<span style="color: #000066; font-weight: bold;">.</span>TriangleMesh3D<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> org<span style="color: #000066; font-weight: bold;">.</span>papervision3d<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>geom<span style="color: #000066; font-weight: bold;">.</span>renderables<span style="color: #000066; font-weight: bold;">.</span>Triangle3D<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> org<span style="color: #000066; font-weight: bold;">.</span>papervision3d<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>geom<span style="color: #000066; font-weight: bold;">.</span>renderables<span style="color: #000066; font-weight: bold;">.</span>Vertex3D<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> org<span style="color: #000066; font-weight: bold;">.</span>papervision3d<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>math<span style="color: #000066; font-weight: bold;">.</span>NumberUV<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> org<span style="color: #000066; font-weight: bold;">.</span>papervision3d<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>proto<span style="color: #000066; font-weight: bold;">.</span>MaterialObject3D<span style="color: #000066; font-weight: bold;">;</span> &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> CustomTriangle <span style="color: #0033ff; font-weight: bold;">extends</span> TriangleMesh3D<br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> CustomTriangle <span style="color: #000000;">&#40;</span>triangleMaterial <span style="color: #000066; font-weight: bold;">:</span> MaterialObject3D<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span> triangleMaterial<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> v1 <span style="color: #000066; font-weight: bold;">:</span> Vertex3D = <span style="color: #0033ff; font-weight: bold;">new</span> Vertex3D<span style="color: #000000;">&#40;</span> <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> v2 <span style="color: #000066; font-weight: bold;">:</span> Vertex3D = <span style="color: #0033ff; font-weight: bold;">new</span> Vertex3D<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> v3 <span style="color: #000066; font-weight: bold;">:</span> Vertex3D = <span style="color: #0033ff; font-weight: bold;">new</span> Vertex3D<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; geometry<span style="color: #000066; font-weight: bold;">.</span>vertices<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span> v1<span style="color: #000066; font-weight: bold;">,</span> v2<span style="color: #000066; font-weight: bold;">,</span> v3 <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> triangleVertices <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Array</span> = <span style="color: #000000;">&#91;</span> v1<span style="color: #000066; font-weight: bold;">,</span> v2<span style="color: #000066; font-weight: bold;">,</span> v3 <span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> triangleFace <span style="color: #000066; font-weight: bold;">:</span> Triangle3D = <span style="color: #0033ff; font-weight: bold;">new</span> Triangle3D<span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">,</span> triangleVertices<span style="color: #000066; font-weight: bold;">,</span> material<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">null</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; geometry<span style="color: #000066; font-weight: bold;">.</span>faces<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span> triangleFace <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; geometry<span style="color: #000066; font-weight: bold;">.</span>ready = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Our custom object is extending the TriangleMesh3D class. If you take a look in the Papervision primitives classes you will see that they all extend this class.</p>
<p>Ok, so the constructor of the TriangleMesh3D needs 3 parameters. A material, a vertices array and a faces array. Our custom triangle requires a material as well so we push it to the super constructor. Then we give our super class 2 empty arrays which means something like: We don&#8217;t have any vertices and faces for you yet but you will get them very soon.</p>
<p>Let&#8217;s build the triangle. A triangle consits of 3 points and 1 shape. Here we will call it 3 vertices and 1 face. We create 3 instances of the Vertex3D class, give them the coordinates in 3D Space and push them in the vertices array which is a property of the geometry instance. The coordinates are pretty much the same as in our lineTo example earlier.</p>
<p>Now that we have 3 vertices we can make a face. In our lineTo example flash automatically connected the 3 points and draw a shape. Here we have to say with which vertices we want to create a face with. So basically we just choose 3 vertices push them in an array and pass them to our new instance of the Triangle3D class which represents the face. The Triangle3D class also needs a material. We just take the one of our displayobject. And it wants a texture map. I will explain that later for keeping things simple at this point it is null for now. As long as you don&#8217;t apply a texture material on the object you won&#8217;t need it.</p>
<p>So, here we go. Our first custom 3D Object:<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_custommesh_triangle_582471171"
			class="flashmovie"
			width="455"
			height="256">
	<param name="movie" value="/swf/custommesh_triangle.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/swf/custommesh_triangle.swf"
			name="fm_custommesh_triangle_582471171"
			width="455"
			height="256">
	<!--<![endif]-->
		<br />
<a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a><br />

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object><br />
Here is the code which does the Papervision setup:</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> init3D <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; _basicView = <span style="color: #0033ff; font-weight: bold;">new</span> BasicView<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">455</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">256</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> CameraType<span style="color: #000066; font-weight: bold;">.</span>FREE <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span> _basicView <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> onRender <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> material <span style="color: #000066; font-weight: bold;">:</span> ColorMaterial = <span style="color: #0033ff; font-weight: bold;">new</span> ColorMaterial<span style="color: #000000;">&#40;</span> 0xFF <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; material<span style="color: #000066; font-weight: bold;">.</span>doubleSided = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; _arrow = <span style="color: #0033ff; font-weight: bold;">new</span> CustomTriangle<span style="color: #000000;">&#40;</span> material <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; _basicView<span style="color: #000066; font-weight: bold;">.</span>scene<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span> _arrow <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onRender <span style="color: #000000;">&#40;</span>event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
<span style="color: #000000;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; _arrow<span style="color: #000066; font-weight: bold;">.</span>yaw<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; _basicView<span style="color: #000066; font-weight: bold;">.</span>singleRender<span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Ok, cool. So now you know how to set up your own custom Papervision DisplayObject. In the next part I&#8217;m going to show you how texturemaps work.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rwichmann.com/2009/04/08/creating-custom-3d-displayobjects-in-papervision-part-1/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

