Mesh
using Autodesk.DesignScript.Geometry.Properties;
using Autodesk.DesignScript.Interfaces;
using Autodesk.DesignScript.Runtime;
using DynamoServices;
using ProtoGeometryGenerator;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Autodesk.DesignScript.Geometry
{
[GenerateFromInterface(typeof(IMeshEntity), typeof(IGeometryFactory), new Type[] {
})]
public class Mesh : DesignScriptEntity
{
public IEnumerable<double> VerticesAsThreeNumbers => (from x in MeshEntity.get_VerticesAsThreeNumbers()
select x * DesignScriptEntity.scaleFactor).ToArray();
public IEnumerable<double> EdgesAsSixNumbers => (from x in MeshEntity.get_EdgesAsSixNumbers()
select x * DesignScriptEntity.scaleFactor).ToArray();
public IEnumerable<double> TrianglesAsNineNumbers => (from x in MeshEntity.get_TrianglesAsNineNumbers()
select x * DesignScriptEntity.scaleFactor).ToArray();
internal IMeshEntity MeshEntity => HostImpl as IMeshEntity;
public IndexGroup[] FaceIndices => IndexGroup.Wrap(MeshEntity.get_FaceIndices());
[Scaling()]
public Vector[] VertexNormals {
get {
return Vector.Wrap((from x in (IEnumerable<IVectorEntity>)MeshEntity.get_VertexNormals()
select x.Scale(1 / DesignScriptEntity.scaleFactor)).ToArray());
}
}
public Point[] VertexPositions => Point.Wrap(MeshEntity.get_VertexPositions());
public int VertexCount => MeshEntity.get_VertexCount();
public int EdgeCount => MeshEntity.get_EdgeCount();
public int TriangleCount => MeshEntity.get_TriangleCount();
[Scaling()]
public double Volume {
get {
return MeshEntity.get_Volume() * Math.Pow(DesignScriptEntity.scaleFactor, 3);
}
}
[Scaling()]
public double Area {
get {
return MeshEntity.get_Area() * Math.Pow(DesignScriptEntity.scaleFactor, 2);
}
}
[SupressImportIntoVM]
[GenerateShadowing("FromJson", new Type[] {
typeof(string),
typeof(double)
})]
public static Mesh FromJson(string json)
{
return Wrap(HostFactory.Factory.MeshFromJson(json, DesignScriptEntity.scaleFactor));
}
[SupressImportIntoVM]
public virtual string ToJson()
{
return MeshEntity.MeshToJson(DesignScriptEntity.scaleFactor);
}
public override string ToString()
{
return "Mesh";
}
internal override void AppendTo(StringBuilder builder)
{
builder.Append("Mesh");
}
internal Mesh(IMeshEntity host)
: base(host)
{
}
public List<int> VertexIndicesByTri()
{
return MeshEntity.VertexIndicesByTri();
}
public Line[] Edges()
{
return Line.Wrap(MeshEntity.Edges());
}
public Surface[] Triangles()
{
return Surface.Wrap(MeshEntity.Triangles());
}
public BoundingBox BoundingBox()
{
return Autodesk.DesignScript.Geometry.BoundingBox.Wrap(MeshEntity.BoundingBox());
}
public Mesh[] Explode()
{
return Wrap(MeshEntity.Explode());
}
[Scaling()]
public Vector[] TriangleNormals()
{
return (from x in Vector.Wrap(MeshEntity.TriangleNormals())
select x.Scale(1 / DesignScriptEntity.scaleFactor)).ToArray();
}
public Point[] TriangleCentroids()
{
return Point.Wrap(MeshEntity.TriangleCentroids());
}
public Mesh BooleanUnion(Mesh tool)
{
return Wrap(MeshEntity.BooleanUnion(Unwrap(tool)));
}
public Mesh BooleanDifference(Mesh tool)
{
return Wrap(MeshEntity.BooleanDifference(Unwrap(tool)));
}
public Mesh BooleanIntersection(Mesh tool)
{
return Wrap(MeshEntity.BooleanIntersection(Unwrap(tool)));
}
public Mesh Repair()
{
return Wrap(MeshEntity.Repair());
}
public Mesh CloseCracks()
{
return Wrap(MeshEntity.CloseCracks());
}
public Mesh MakeWatertight()
{
return Wrap(MeshEntity.MakeWatertight());
}
public Mesh MakeHollow(int holeCount = 1, double holeRadius = 1.5, double wallThickness = 2, double solidResolution = 128, double meshResolution = 128)
{
return Wrap(MeshEntity.MakeHollow(holeCount, holeRadius, wallThickness, solidResolution, meshResolution));
}
public Mesh GenerateSupport(double baseHeight = 0.4, double baseDiameter = 8, double postDiameter = 3, double tipHeight = 1, double tipDiameter = 0.5)
{
return Wrap(MeshEntity.GenerateSupport(baseHeight, baseDiameter, postDiameter, tipHeight, tipDiameter));
}
public Mesh Reduce(double triangleCount)
{
return Wrap(MeshEntity.Reduce(triangleCount));
}
public Mesh Remesh()
{
return Wrap(MeshEntity.Remesh());
}
public Mesh Smooth(double scale = 4)
{
return Wrap(MeshEntity.Smooth(scale));
}
public Mesh PlaneCut(Plane plane, bool makeSolid = false)
{
return Wrap(MeshEntity.PlaneCut(Autodesk.DesignScript.Geometry.Plane.Unwrap(plane), makeSolid));
}
public PolyCurve[] Intersect(Plane intersectionPlane)
{
return PolyCurve.Wrap(MeshEntity.Intersect(Autodesk.DesignScript.Geometry.Plane.Unwrap(intersectionPlane)));
}
public Point Project(Point point, Vector dir)
{
return Point.Wrap(MeshEntity.Project(Point.Unwrap(point), Vector.Unwrap(dir)));
}
public Point Nearest(Point point)
{
return Point.Wrap(MeshEntity.Nearest(Point.Unwrap(point)));
}
public Mesh Mirror(Plane mirrorPlane)
{
return Wrap(MeshEntity.Mirror(Autodesk.DesignScript.Geometry.Plane.Unwrap(mirrorPlane)));
}
public Mesh Rotate(Vector axis, double degrees = 0)
{
return Wrap(MeshEntity.Rotate(Vector.Unwrap(axis), degrees));
}
public Mesh Scale(double scaleFactor = 1)
{
return Wrap(MeshEntity.Scale(scaleFactor));
}
public Mesh Scale(double x = 1, double y = 1, double z = 1)
{
return Wrap(MeshEntity.Scale(x, y, z));
}
public Mesh Translate(Vector vector)
{
return Wrap(MeshEntity.Translate(Vector.Unwrap(vector)));
}
public Mesh Translate(Vector vector, double distance = 0)
{
return Wrap(MeshEntity.Translate(Vector.Unwrap(vector), distance));
}
public Mesh Translate([Scaling()] double x = 0, [Scaling()] double y = 0, [Scaling()] double z = 0)
{
DesignScriptEntity.CheckArgsForAsmExtents(x, y, z);
return Wrap(MeshEntity.Translate(x / DesignScriptEntity.scaleFactor, y / DesignScriptEntity.scaleFactor, z / DesignScriptEntity.scaleFactor));
}
[SupressImportIntoVM]
public string MeshToJson(double scaleFactor)
{
return MeshEntity.MeshToJson(scaleFactor);
}
[IsVisibleInDynamoLibrary(false)]
[IsObsolete("mesh_bypointsfaceindices_deprecated", typeof(Resources))]
[Obsolete("This method is deprecated and will be removed in a future version of Dynamo. Use Mesh.ByPointsIndexGroups (Point[] points, IndexGroups : IndexGroup[]) instead")]
public static Mesh ByPointsFaceIndices(IEnumerable<Point> vertexPositions, IEnumerable<IndexGroup> indices)
{
LogWarningMessageEvents.OnLogInfoMessage(Resources.MeshPrecisionInfo);
return Wrap(HostFactory.Factory.MeshByPointsFaceIndices(Point.Unwrap(vertexPositions), IndexGroup.Unwrap(indices)));
}
public static Mesh ByPointsIndexGroups(IEnumerable<Point> points, IEnumerable<IndexGroup> indexGroups)
{
LogWarningMessageEvents.OnLogInfoMessage(Resources.MeshPrecisionInfo);
return Wrap(HostFactory.Factory.MeshByPointsIndexGroups(Point.Unwrap(points), IndexGroup.Unwrap(indexGroups)));
}
public static Mesh ByPointsIndices(IEnumerable<Point> points, IEnumerable<int> indices)
{
LogWarningMessageEvents.OnLogInfoMessage(Resources.MeshPrecisionInfo);
return Wrap(HostFactory.Factory.MeshByPointsIndices(Point.Unwrap(points), indices));
}
public static Mesh[] ImportFile(string fileName)
{
LogWarningMessageEvents.OnLogInfoMessage(Resources.MeshPrecisionInfo);
return Wrap(HostFactory.Factory.MeshImportFile(fileName));
}
public static string ExportMeshes(string filename, IEnumerable<Mesh> meshes)
{
LogWarningMessageEvents.OnLogInfoMessage(Resources.MeshPrecisionInfo);
return HostFactory.Factory.MeshExportMeshes(filename, Unwrap(meshes));
}
public static Mesh ByGeometry(Geometry inputGeometry, double tolerance = -1, int maxGridLines = 512)
{
LogWarningMessageEvents.OnLogInfoMessage(Resources.MeshPrecisionInfo);
return Wrap(HostFactory.Factory.MeshByGeometry(Geometry.Unwrap(inputGeometry), tolerance, maxGridLines));
}
[IsVisibleInDynamoLibrary(false)]
[IsObsolete("mesh_byverticesandindices_deprecated", typeof(Resources))]
[Obsolete("This method is deprecated and will be removed in a future version of Dynamo. Use Mesh.ByPointsIndices (Point[] points, Indices : int[]) instead")]
public static Mesh ByVerticesAndIndices(IEnumerable<Point> vertices, IEnumerable<int> indices)
{
LogWarningMessageEvents.OnLogInfoMessage(Resources.MeshPrecisionInfo);
return Wrap(HostFactory.Factory.MeshByVerticesAndIndices(Point.Unwrap(vertices), indices));
}
public static Mesh Plane([DefaultArgument("Autodesk.DesignScript.Geometry.Point.ByCoordinates(0, 0, 0)")] Point origin, [Scaling()] double xWidth = 1, [Scaling()] double yWidth = 1, int xDivisions = 0, int yDivisions = 0)
{
LogWarningMessageEvents.OnLogInfoMessage(Resources.MeshPrecisionInfo);
DesignScriptEntity.CheckArgsForAsmExtents(xWidth, yWidth);
return Wrap(HostFactory.Factory.MeshPlane(Point.Unwrap(origin), xWidth / DesignScriptEntity.scaleFactor, yWidth / DesignScriptEntity.scaleFactor, xDivisions, yDivisions));
}
public static Mesh Cuboid([DefaultArgument("Autodesk.DesignScript.Geometry.Point.ByCoordinates(0, 0, 0)")] Point origin, [Scaling()] double length = 1, [Scaling()] double width = 1, [Scaling()] double height = 1, int xDivisions = 0, int yDivisions = 0, int zDivisions = 0)
{
LogWarningMessageEvents.OnLogInfoMessage(Resources.MeshPrecisionInfo);
DesignScriptEntity.CheckArgsForAsmExtents(length, width, height);
return Wrap(HostFactory.Factory.MeshCuboid(Point.Unwrap(origin), length / DesignScriptEntity.scaleFactor, width / DesignScriptEntity.scaleFactor, height / DesignScriptEntity.scaleFactor, xDivisions, yDivisions, zDivisions));
}
public static Mesh Sphere([DefaultArgument("Autodesk.DesignScript.Geometry.Point.ByCoordinates(0, 0, 0)")] Point origin, [Scaling()] double radius = 1, int divisions = 0, bool icosphere = true)
{
LogWarningMessageEvents.OnLogInfoMessage(Resources.MeshPrecisionInfo);
DesignScriptEntity.CheckArgsForAsmExtents(radius);
return Wrap(HostFactory.Factory.MeshSphere(Point.Unwrap(origin), radius / DesignScriptEntity.scaleFactor, divisions, icosphere));
}
public static Mesh Cone([DefaultArgument("Autodesk.DesignScript.Geometry.Point.ByCoordinates(0, 0, 0)")] Point origin, [Scaling()] double baseRadius = 1, [Scaling()] double topRadius = 0, [Scaling()] double height = 1, int divisions = 0, bool cap = true)
{
LogWarningMessageEvents.OnLogInfoMessage(Resources.MeshPrecisionInfo);
DesignScriptEntity.CheckArgsForAsmExtents(baseRadius, topRadius, height);
return Wrap(HostFactory.Factory.MeshCone(Point.Unwrap(origin), baseRadius / DesignScriptEntity.scaleFactor, topRadius / DesignScriptEntity.scaleFactor, height / DesignScriptEntity.scaleFactor, divisions, cap));
}
public static Mesh ExtrudePolyCurve(PolyCurve polycurve, [Scaling()] double height, Vector direction, bool cap = false)
{
LogWarningMessageEvents.OnLogInfoMessage(Resources.MeshPrecisionInfo);
DesignScriptEntity.CheckArgsForAsmExtents(height);
return Wrap(HostFactory.Factory.MeshExtrudePolyCurve(PolyCurve.Unwrap(polycurve), height / DesignScriptEntity.scaleFactor, Vector.Unwrap(direction), cap));
}
internal static Mesh Wrap(IMeshEntity host)
{
if (host != null)
return new Mesh(host);
return null;
}
internal static Mesh[] Wrap(IMeshEntity[] hosts)
{
return hosts.Select(Wrap).ToArray();
}
internal static Mesh[][] Wrap(IMeshEntity[][] hosts)
{
return hosts.Select(Wrap).ToArray();
}
internal static IMeshEntity Unwrap(Mesh o)
{
return o.MeshEntity;
}
internal static IMeshEntity[] Unwrap(IEnumerable<Mesh> o)
{
return o.Select(Unwrap).ToArray();
}
internal static IMeshEntity[] Unwrap(Mesh[] o)
{
return o.Select(Unwrap).ToArray();
}
internal static IMeshEntity[][] Unwrap(Mesh[][] o)
{
return o.Select(Unwrap).ToArray();
}
}
}