[Papervision3D] how to make a triangle or circle without ASE/DAE (AS2)

Tim Knip tim.knip at gmail.com
Sun Apr 15 17:55:48 EDT 2007


Updated the Pyramid class to use UV coords (texturing).

Things could be better I guess (see Pyramid#init).

Greets,
Tim

<code>
/*
 *  PAPER    ON   ERVIS  NPAPER ISION  PE  IS ON  PERVI IO  APER  SI  PA
 *  AP  VI  ONPA  RV  IO PA     SI  PA ER  SI NP PE     ON AP  VI ION AP
 *  PERVI  ON  PE VISIO  APER   IONPA  RV  IO PA  RVIS  NP PE  IS ONPAPE
 *  ER     NPAPER IS     PE     ON  PE  ISIO  AP     IO PA ER  SI NP PER
 *  RV     PA  RV SI     ERVISI NP  ER   IO   PE VISIO  AP  VISI  PA  RV3D
 *  ______________________________________________________________________
 *  papervision3d.org � blog.papervision3d.org � osflash.org/papervision3d
 */

/*
 * Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */

 // ______________________________________________________________________
//

import org.papervision3d.core.geom.Face3D;
import org.papervision3d.core.geom.Vertex3D;
import org.papervision3d.core.NumberUV;
import org.papervision3d.core.proto.CameraObject3D;
import org.papervision3d.core.proto.MaterialObject3D;
import org.papervision3d.core.proto.SceneObject3D;
import org.papervision3d.objects.Mesh;
import org.papervision3d.objects.Points;

/**
 *
 *
 */
class org.papervision3d.objects.Pyramid extends Mesh
{
	private var _radius:Number;
	
	public function Pyramid( material:MaterialObject3D, radius:Number,
initObject:Object )
	{
		super(material, null, null, initObject);
	
		this._radius = radius || 100;
		
		init();
	}
	
	private function init():Void
	{
		var numSides:Number = 3;
		var ang:Number = (Math.PI * 2) / numSides;
		
		var x0:Number = 0;
		var y0:Number = 0;
		
		var verts:Array = this.vertices;
		var faces:Array = this.faces;
		var uv:Array = new Array();
		
		for( var i:Number = 0; i < numSides; i++ )
		{
			var x1:Number = Math.cos( i * ang ) * this._radius;
			var y1:Number = Math.sin( i * ang ) * this._radius;				
			verts.push( new Vertex3D(x1, y1) );
		}
		
		verts.push( new Vertex3D( 0, 0, this._radius ) );
		
		// uvs
		uv[0] = [new NumberUV(), new NumberUV(0.5, 1), new NumberUV(1,0)];
		uv[1] = [new NumberUV(), new NumberUV(0.5, 1), new NumberUV(1,0)];
		uv[2] = [new NumberUV(), new NumberUV(0.5, 1), new NumberUV(1,0)];
		uv[3] = [new NumberUV(), new NumberUV(0.5, 1), new NumberUV(1,0)];
		
		var material:MaterialObject3D = this.material;
		
		faces.push( new Face3D( [verts[0], verts[1], verts[3]], material, uv[0]) );
		faces.push( new Face3D( [verts[1], verts[2], verts[3]], material, uv[1]) );
		faces.push( new Face3D( [verts[2], verts[0], verts[3]], material, uv[2]) );
		faces.push( new Face3D( [verts[2], verts[1], verts[0]], material, uv[3]) );
	}
}
</code>



More information about the Papervision3D mailing list