package com.mrdoob.pv3d_phunky.objects { import org.papervision3d.core.*; import org.papervision3d.core.proto.*; import org.papervision3d.core.geom.*; import org.papervision3d.core.geom.renderables.Vertex3D; import org.papervision3d.core.geom.renderables.Triangle3D; import flash.display.BitmapData; public class Pyramid extends TriangleMesh3D { public var segmentsS :Number; public var segmentsT :Number; public var segmentsH :Number; static public var DEFAULT_SIZE :Number = 500; static public var DEFAULT_SCALE :Number = 1; static public var DEFAULT_SEGMENTS :Number = 1; public function Pyramid( material:MaterialObject3D=null, width:Number=500, depth:Number=500, height:Number=500, segmentsS:Number=1, segmentsT:Number=1, segmentsH:Number=1, initObject:Object=null ) { super( material, new Array(), new Array(), null, initObject ); var scale :Number = DEFAULT_SCALE; if( ! height ) { if( width ) scale = width; if( material && material.bitmap ) { width = material.bitmap.width * scale; height = material.bitmap.height * scale; } else { width = DEFAULT_SIZE * scale; height = DEFAULT_SIZE * scale; } } if( ! depth ) { if( width ) scale = width; width = DEFAULT_SIZE * scale; depth = DEFAULT_SIZE * scale; } buildCube( width, height, depth ); } private function buildCube( fWidth:Number, fHeight:Number, fDepth:Number ):void { var vertices :Array = this.geometry.vertices; var faces :Array = this.geometry.faces; vertices.push( new Vertex3D( 0, 0, -(fDepth/2) ) ); vertices.push( new Vertex3D( -(fWidth/2), 0, (fDepth/2) ) ); vertices.push( new Vertex3D( (fWidth/2), 0, (fDepth/2) ) ); vertices.push( new Vertex3D( 0, -(fWidth/2), 0 ) ); faces.push( new Triangle3D( this, [ vertices[0], vertices[3], vertices[1] ], null, [ 1, 1, 1 ] ) ); faces.push( new Triangle3D( this, [ vertices[1], vertices[3], vertices[2] ], null, [ 1, 1, 1 ] ) ); faces.push( new Triangle3D( this, [ vertices[2], vertices[3], vertices[0] ], null, [ 1, 1, 1 ] ) ); faces.push( new Triangle3D( this, [ vertices[2], vertices[0], vertices[1] ], null, [ 1, 1, 1 ] ) ); this.geometry.ready = true; } } }