package org.papervision3d.objects.primitives { import org.papervision3d.Papervision3D; import org.papervision3d.core.geom.*; import org.papervision3d.core.geom.renderables.Triangle3D; import org.papervision3d.core.geom.renderables.Vertex3D; import org.papervision3d.core.math.NumberUV; import org.papervision3d.core.proto.*; /** * The Cylinder class lets you create and display Cylinders. *
* The Cylinder is divided in vertical and horizontal segment, the smallest combination is two vertical and three horizontal segments. */ public class Cylinder extends TriangleMesh3D { /** * Number of segments horizontally. Defaults to 8. */ public var segmentsW :Number; /** * Number of segments vertically. Defaults to 6. */ public var segmentsH :Number; /** * Default radius of Cylinder if not defined. */ static public const DEFAULT_RADIUS :Number = 100; /** * Default height if not defined. */ static public const DEFAULT_HEIGHT :Number = 100; /** * Default scale of Cylinder texture if not defined. */ static public const DEFAULT_SCALE :Number = 1; /** * Default value of gridX if not defined. */ static public const DEFAULT_SEGMENTSW :Number = 8; /** * Default value of gridY if not defined. */ static public const DEFAULT_SEGMENTSH :Number = 6; /** * Minimum value of gridX. */ static public const MIN_SEGMENTSW :Number = 3; /** * Minimum value of gridY. */ static public const MIN_SEGMENTSH :Number = 1; // ___________________________________________________________________________________________________ // N E W // NN NN EEEEEE WW WW // NNN NN EE WW WW WW // NNNNNN EEEE WWWWWWWW // NN NNN EE WWW WWW // NN NN EEEEEE WW WW /** * Create a new Cylinder object. * * @param material A MaterialObject3D object that contains the material properties of the object. * * @param radius [optional] - Desired radius. * * @param segmentsW [optional] - Number of segments horizontally. Defaults to 8. * * @param segmentsH [optional] - Number of segments vertically. Defaults to 6. * * @param topRadius [optional] - An optional parameter for con- or diverging cylinders. * * @param topFace [optional] - An optional parameter specifying if the top face of the cylinder should be drawn. * * @param bottomFace [optional] - An optional parameter specifying if the bottom face of the cylinder should be drawn. * */ public function Cylinder( material:MaterialObject3D=null, radius:Number=100, height:Number=100, segmentsW:int=8, segmentsH:int=6, topRadius:Number=-1, topFace:Boolean=true, bottomFace:Boolean=true ) { super( material, new Array(), new Array(), null ); this.segmentsW = Math.max( MIN_SEGMENTSW, segmentsW || DEFAULT_SEGMENTSW); // Defaults to 8 this.segmentsH = Math.max( MIN_SEGMENTSH, segmentsH || DEFAULT_SEGMENTSH); // Defaults to 6 if (radius==0) radius = DEFAULT_RADIUS; // Defaults to 100 if (height==0) height = DEFAULT_HEIGHT; // Defaults to 100 if (topRadius==-1) topRadius = radius; var scale :Number = DEFAULT_SCALE; buildCylinder( radius, height, topRadius, topFace, bottomFace ); } private function buildCylinder( fRadius:Number, fHeight:Number, fTopRadius:Number, fTopFace:Boolean, fBottomFace:Boolean ):void { var matInstance:MaterialObject3D = material; var i:Number, j:Number, k:Number; var iHor:Number = Math.max(MIN_SEGMENTSW, this.segmentsW); var iVer:Number = Math.max(MIN_SEGMENTSH, this.segmentsH); var aVertice:Array = this.geometry.vertices; var aFace:Array = this.geometry.faces; var aVtc:Array = new Array(); for (j=0;j<(iVer+1);j++) { // vertical var fRad1:Number = Number(j/iVer); var fZ:Number = fHeight*(j/(iVer+0))-fHeight/2;//-fRadius*Math.cos(fRad1*Math.PI); var fRds:Number = fTopRadius+(fRadius-fTopRadius)*(1-j/(iVer));//*Math.sin(fRad1*Math.PI); var aRow:Array = new Array(); var oVtx:Vertex3D; for (i=0;i