Browse Source

Add defaultUnit methods to Cylinder and Disc (#795)

Arnaud Duforat 5 years ago
parent
commit
a7efc3348d
2 changed files with 35 additions and 0 deletions
  1. 18 0
      h3d/prim/Cylinder.hx
  2. 17 0
      h3d/prim/Disc.hx

+ 18 - 0
h3d/prim/Cylinder.hx

@@ -44,4 +44,22 @@ class Cylinder extends Quads {
 		}
 	}
 
+	/**
+	 * Get a default unit Cylinder with 
+	 * segs = 16, ray = 0.5, height = 1.0, centered = false
+	 * and add UVs to it. If it has not be cached, it is cached and subsequent
+	 * calls to this method will return Cylinder from cache.
+	 * @param segs Optional number of segments of the cylinder, default 16
+	 */
+	public static function defaultUnitCylinder(segs : Int = 16) {
+		var engine = h3d.Engine.getCurrent();
+		var c : Cylinder = @:privateAccess engine.resCache.get(Cylinder);
+		if( c != null )
+			return c;
+		c = new h3d.prim.Cylinder(segs, 0.5);
+		c.addUVs();
+		@:privateAccess engine.resCache.set(Cylinder, c);
+		return c;
+	}
+
 }

+ 17 - 0
h3d/prim/Disc.hx

@@ -32,4 +32,21 @@ class Disc extends Polygon {
 		uvs.push( new UV( 0.5, 0.5 ) );
 	}
 
+	/**
+	 * Get a default unit Disc with 
+	 * radius = 0.5, segments = 8, thetaStart = 0.0, thetaLength = Math.PI * 2
+	 * and add UVs to it. If it has not be cached, it is cached and subsequent
+	 * calls to this method will return Disc from cache.
+	 */
+	public static function defaultUnitDisc() {
+		var engine = h3d.Engine.getCurrent();
+		var d : Disc = @:privateAccess engine.resCache.get(Disc);
+		if( d != null )
+			return d;
+		d = new h3d.prim.Disc();
+		d.addUVs();
+		@:privateAccess engine.resCache.set(Disc, d);
+		return d;
+	}
+
 }