mirror of
https://github.com/eliasstepanik/OSCADSharpDotnet7.git
synced 2026-01-11 13:38:33 +00:00
Added some constructors for common ways to create simple solids
This commit is contained in:
parent
152a63ee77
commit
03ea1c3cb6
@ -13,11 +13,7 @@ namespace OSCADSharp.ConsoleTests
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
OSCADObject cube = new Cube()
|
||||
{
|
||||
Size = new Vector3(15, 15, 15),
|
||||
Center = false
|
||||
};
|
||||
OSCADObject cube = new Cube(new Vector3(15, 15, 15));
|
||||
|
||||
cube = cube.Color("Red")
|
||||
.Mirror(1, 0, 0)
|
||||
@ -26,28 +22,18 @@ namespace OSCADSharp.ConsoleTests
|
||||
.Scale(1, 1, 2)
|
||||
.Translate(10, 5, 2);
|
||||
|
||||
OSCADObject cylinder = new Cylinder()
|
||||
{
|
||||
Diameter = 35.4,
|
||||
Height = 50.8
|
||||
}.Translate(10, 5, 2);
|
||||
OSCADObject cylinder = new Cylinder(35.4, 50.8).Translate(10, 5, 2);
|
||||
|
||||
var combined = cube.Intersection(cylinder).Color("Blue");
|
||||
combined = cube.Clone().Mirror(0, 0, 1).Union(combined);
|
||||
|
||||
var text = new Text3D()
|
||||
{
|
||||
Text = "Hello!"
|
||||
}.Translate(-30, 0, 0);
|
||||
var text = new Text3D("Hello").Translate(-30, 0, 0);
|
||||
|
||||
combined = text.Union(combined);
|
||||
|
||||
string script = combined.ToString();
|
||||
string script = text.ToString();
|
||||
|
||||
File.WriteAllLines("test.scad", new string[] { script.ToString() });
|
||||
|
||||
Console.WriteLine(script);
|
||||
Console.ReadKey();
|
||||
File.WriteAllLines("test.scad", new string[] { script.ToString() });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,6 +25,27 @@ namespace OSCADSharp.Solids
|
||||
public bool Center { get; set; } = false;
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
/// <summary>
|
||||
/// Creates a new cube object with the default initialization values
|
||||
/// </summary>
|
||||
public Cube()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new Cube object
|
||||
/// </summary>
|
||||
/// <param name="size">The Size of the cube in terms of X/Y/Z dimensions</param>
|
||||
/// <param name="center">Indicates whether the cube should be centered on the origin</param>
|
||||
public Cube(Vector3 size = null, bool center = false)
|
||||
{
|
||||
this.Size = size ?? new Vector3(1, 1, 1);
|
||||
this.Center = center;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Overrides
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("cube(size = [{0}, {1}, {2}], center = {3});",
|
||||
@ -39,5 +60,6 @@ namespace OSCADSharp.Solids
|
||||
Center = this.Center
|
||||
};
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,6 +95,27 @@ namespace OSCADSharp.Solids
|
||||
public int Resolution { get; set; } = 0;
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
/// <summary>
|
||||
/// Creates a cylinder with the default initialization values
|
||||
/// </summary>
|
||||
public Cylinder()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a cylinder with the specified diameter and centering
|
||||
/// </summary>
|
||||
/// <param name="diameter">Diameter of the cylinder</param>
|
||||
/// <param name="center">Determines whether the cylinder should be centered on the z-axis, if false the base will start on the Z axis</param>
|
||||
public Cylinder(double diameter = 2, double height = 1, bool center = false)
|
||||
{
|
||||
this.Diameter = diameter;
|
||||
this.Center = center;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Overrides
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("cylinder($fn = {0}, $fa = {1}, $fs = {2}, h = {3}, r1 = {4}, r2 = {5}, center = {6});",
|
||||
@ -115,5 +136,6 @@ namespace OSCADSharp.Solids
|
||||
Center = this.Center
|
||||
};
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,6 +44,25 @@ namespace OSCADSharp.Solids
|
||||
public int Resolution { get; set; } = 0;
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
/// <summary>
|
||||
/// Creates a sphere with the default initialization values
|
||||
/// </summary>
|
||||
public Sphere()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a sphere of the specified diameter
|
||||
/// </summary>
|
||||
/// <param name="diameter">Diameter of the sphere</param>
|
||||
public Sphere(double diameter)
|
||||
{
|
||||
this.Diameter = diameter;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Overrides
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("sphere($fn = {0}, $fa = {1}, $fs = {2}, r = {3});",
|
||||
@ -61,5 +80,6 @@ namespace OSCADSharp.Solids
|
||||
Radius = this.Radius
|
||||
};
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@ namespace OSCADSharp
|
||||
/// </summary>
|
||||
public class Text3D : OSCADObject
|
||||
{
|
||||
#region Attributes
|
||||
/// <summary>
|
||||
/// Text to display
|
||||
/// </summary>
|
||||
@ -56,20 +57,31 @@ namespace OSCADSharp
|
||||
/// The language of the text. Default is "en".
|
||||
/// </summary>
|
||||
public string Language { get; set; }
|
||||
|
||||
|
||||
#endregion
|
||||
#region Constructors
|
||||
/// <summary>
|
||||
/// Used for subdividing the curved path segments provided by freetype
|
||||
/// ($fn in OpenSCAD)
|
||||
/// Creates 3d text with the default parameters
|
||||
/// if the text is not specified, text will say "Text"
|
||||
/// </summary>
|
||||
/// TODO: Implement Resolution
|
||||
// public int? Resolution { get; set; } = 0;
|
||||
public Text3D()
|
||||
{
|
||||
this.Text = "Text";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The script of the text. Default is "latin".
|
||||
/// </summary>
|
||||
/// TODO: Implement Script
|
||||
// public string Script { get; set; }
|
||||
/// Creates 3d text with the specified text to create
|
||||
/// </summary>
|
||||
/// <param name="text">Text to display</param>
|
||||
/// <param name="size">Font size for the text</param>
|
||||
public Text3D(string text, uint? size = null)
|
||||
{
|
||||
this.Text = text;
|
||||
this.Size = size;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Overrides
|
||||
public override OSCADObject Clone()
|
||||
{
|
||||
return new Text3D()
|
||||
@ -113,5 +125,6 @@ namespace OSCADSharp
|
||||
var formatter = new BlockFormatter(String.Format("linear_extrude(height = {0})", 1), sb.ToString());
|
||||
return formatter.ToString();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user