mirror of
https://github.com/eliasstepanik/OSCADSharpDotnet7.git
synced 2026-01-24 11:38:29 +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)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
OSCADObject cube = new Cube()
|
OSCADObject cube = new Cube(new Vector3(15, 15, 15));
|
||||||
{
|
|
||||||
Size = new Vector3(15, 15, 15),
|
|
||||||
Center = false
|
|
||||||
};
|
|
||||||
|
|
||||||
cube = cube.Color("Red")
|
cube = cube.Color("Red")
|
||||||
.Mirror(1, 0, 0)
|
.Mirror(1, 0, 0)
|
||||||
@ -26,28 +22,18 @@ namespace OSCADSharp.ConsoleTests
|
|||||||
.Scale(1, 1, 2)
|
.Scale(1, 1, 2)
|
||||||
.Translate(10, 5, 2);
|
.Translate(10, 5, 2);
|
||||||
|
|
||||||
OSCADObject cylinder = new Cylinder()
|
OSCADObject cylinder = new Cylinder(35.4, 50.8).Translate(10, 5, 2);
|
||||||
{
|
|
||||||
Diameter = 35.4,
|
|
||||||
Height = 50.8
|
|
||||||
}.Translate(10, 5, 2);
|
|
||||||
|
|
||||||
var combined = cube.Intersection(cylinder).Color("Blue");
|
var combined = cube.Intersection(cylinder).Color("Blue");
|
||||||
combined = cube.Clone().Mirror(0, 0, 1).Union(combined);
|
combined = cube.Clone().Mirror(0, 0, 1).Union(combined);
|
||||||
|
|
||||||
var text = new Text3D()
|
var text = new Text3D("Hello").Translate(-30, 0, 0);
|
||||||
{
|
|
||||||
Text = "Hello!"
|
|
||||||
}.Translate(-30, 0, 0);
|
|
||||||
|
|
||||||
combined = text.Union(combined);
|
combined = text.Union(combined);
|
||||||
|
|
||||||
string script = combined.ToString();
|
string script = text.ToString();
|
||||||
|
|
||||||
File.WriteAllLines("test.scad", new string[] { script.ToString() });
|
File.WriteAllLines("test.scad", new string[] { script.ToString() });
|
||||||
|
|
||||||
Console.WriteLine(script);
|
|
||||||
Console.ReadKey();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,6 +25,27 @@ namespace OSCADSharp.Solids
|
|||||||
public bool Center { get; set; } = false;
|
public bool Center { get; set; } = false;
|
||||||
#endregion
|
#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()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return String.Format("cube(size = [{0}, {1}, {2}], center = {3});",
|
return String.Format("cube(size = [{0}, {1}, {2}], center = {3});",
|
||||||
@ -39,5 +60,6 @@ namespace OSCADSharp.Solids
|
|||||||
Center = this.Center
|
Center = this.Center
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -95,6 +95,27 @@ namespace OSCADSharp.Solids
|
|||||||
public int Resolution { get; set; } = 0;
|
public int Resolution { get; set; } = 0;
|
||||||
#endregion
|
#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()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return String.Format("cylinder($fn = {0}, $fa = {1}, $fs = {2}, h = {3}, r1 = {4}, r2 = {5}, center = {6});",
|
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
|
Center = this.Center
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -44,6 +44,25 @@ namespace OSCADSharp.Solids
|
|||||||
public int Resolution { get; set; } = 0;
|
public int Resolution { get; set; } = 0;
|
||||||
#endregion
|
#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()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return String.Format("sphere($fn = {0}, $fa = {1}, $fs = {2}, r = {3});",
|
return String.Format("sphere($fn = {0}, $fa = {1}, $fs = {2}, r = {3});",
|
||||||
@ -61,5 +80,6 @@ namespace OSCADSharp.Solids
|
|||||||
Radius = this.Radius
|
Radius = this.Radius
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,7 @@ namespace OSCADSharp
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class Text3D : OSCADObject
|
public class Text3D : OSCADObject
|
||||||
{
|
{
|
||||||
|
#region Attributes
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Text to display
|
/// Text to display
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -57,19 +58,30 @@ namespace OSCADSharp
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string Language { get; set; }
|
public string Language { get; set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
#region Constructors
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used for subdividing the curved path segments provided by freetype
|
/// Creates 3d text with the default parameters
|
||||||
/// ($fn in OpenSCAD)
|
/// if the text is not specified, text will say "Text"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// TODO: Implement Resolution
|
public Text3D()
|
||||||
// public int? Resolution { get; set; } = 0;
|
{
|
||||||
|
this.Text = "Text";
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The script of the text. Default is "latin".
|
/// Creates 3d text with the specified text to create
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// TODO: Implement Script
|
/// <param name="text">Text to display</param>
|
||||||
// public string Script { get; set; }
|
/// <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()
|
public override OSCADObject Clone()
|
||||||
{
|
{
|
||||||
return new Text3D()
|
return new Text3D()
|
||||||
@ -113,5 +125,6 @@ namespace OSCADSharp
|
|||||||
var formatter = new BlockFormatter(String.Format("linear_extrude(height = {0})", 1), sb.ToString());
|
var formatter = new BlockFormatter(String.Format("linear_extrude(height = {0})", 1), sb.ToString());
|
||||||
return formatter.ToString();
|
return formatter.ToString();
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user