Class MeshBuilder
- Namespace
- HelixToolkit.Geometry
- Assembly
- HelixToolkit.Geometry.dll
Builds MeshGeometry3D objects.
public sealed class MeshBuilder
- Inheritance
-
MeshBuilder
- Inherited Members
- Extension Methods
Remarks
Performance tips for MeshGeometry3D (http://msdn.microsoft.com/en-us/library/bb613553.aspx)
High impact: Mesh animation—changing the individual vertices of a mesh on a per-frame basis—is not always efficient in Windows Presentation Foundation (WPF). To minimize the performance impact of change notifications when each vertex is modified, detach the mesh from the visual tree before performing per-vertex modification. Once the mesh has been modified, reattach it to the visual tree. Also, try to minimize the size of meshes that will be animated in this way.
Medium impact: When a mesh is defined as abutting triangles with shared vertices and those vertices have the same position, normal, and texture coordinates, define each shared vertex only once and then define your triangles by index with TriangleIndices.
Low impact: To minimize the construction time of large collections in Windows Presentation Foundation (WPF), such as a MeshGeometry3D’s Positions, Normals, TextureCoordinates, and TriangleIndices, pre-size the collections before value population. If possible, pass the collections’ constructors prepopulated data structures such as arrays or Lists.
Constructors
MeshBuilder()
Initializes a new instance of the MeshBuilder class.
public MeshBuilder()
Remarks
Normal and texture coordinate generation are included.
MeshBuilder(bool, bool, bool)
Initializes a new instance of the MeshBuilder class.
public MeshBuilder(bool generateNormals = true, bool generateTexCoords = true, bool tangentSpace = false)
Parameters
generateNormalsboolGenerate normal vectors.
generateTexCoordsboolGenerate texture coordinates.
tangentSpaceboolGenerate tangents.
Properties
BiTangents
The Bi-Tangents.
public Vector3Collection? BiTangents { get; set; }
Property Value
CreateNormals
Gets or sets a value indicating whether to create normal vectors.
public bool CreateNormals { get; set; }
Property Value
- bool
trueif normal vectors should be created; otherwise,false.
CreateTextureCoordinates
Gets or sets a value indicating whether to create texture coordinates.
public bool CreateTextureCoordinates { get; set; }
Property Value
- bool
trueif texture coordinates should be created; otherwise,false.
HasNormals
Do we have Normals or not.
public bool HasNormals { get; }
Property Value
HasTangents
Do we have Tangents or not.
public bool HasTangents { get; }
Property Value
HasTexCoords
Do we have Texture Coordinates or not.
public bool HasTexCoords { get; }
Property Value
Normals
The normal vectors.
public Vector3Collection? Normals { get; set; }
Property Value
Positions
The positions.
public Vector3Collection Positions { get; set; }
Property Value
Tangents
The Tangents.
public Vector3Collection? Tangents { get; set; }
Property Value
TextureCoordinates
The texture coordinates.
public Vector2Collection? TextureCoordinates { get; set; }
Property Value
TriangleIndices
The triangle indices.
public IntCollection TriangleIndices { get; set; }
Property Value
Methods
AddArrow(Vector3, Vector3, float, float, int)
Adds an arrow to the mesh.
public void AddArrow(Vector3 point1, Vector3 point2, float diameter, float headLength = 3, int thetaDiv = 18)
Parameters
point1Vector3The start point.
point2Vector3The end point.
diameterfloatThe diameter of the arrow cylinder.
headLengthfloatLength of the head (relative to diameter).
thetaDivintThe number of divisions around the arrow.
AddBoundingBox(BoundingBox, float)
Adds the edges of a bounding box as pipes.
public void AddBoundingBox(BoundingBox boundingBox, float diameter)
Parameters
boundingBoxBoundingBoxThe bounding box.
diameterfloatThe diameter of the cylinders.
AddBox(BoundingBox, BoxFaces)
Adds a box aligned with the X, Y and Z axes.
public void AddBox(BoundingBox boundingBox, BoxFaces faces = BoxFaces.All)
Parameters
boundingBoxBoundingBoxThe bounding box.
facesBoxFacesThe faces to include.
AddBox(Vector3, Vector3, Vector3, float, float, float, BoxFaces)
Adds a box with the specified faces, aligned with the specified axes.
public void AddBox(Vector3 center, Vector3 x, Vector3 y, float xlength, float ylength, float zlength, BoxFaces faces = BoxFaces.All)
Parameters
centerVector3The center point of the box.
xVector3The x axis.
yVector3The y axis.
xlengthfloatThe length of the box along the X axis.
ylengthfloatThe length of the box along the Y axis.
zlengthfloatThe length of the box along the Z axis.
facesBoxFacesThe faces to include.
AddBox(Vector3, float, float, float)
Adds a box aligned with the X, Y and Z axes.
public void AddBox(Vector3 center, float xlength, float ylength, float zlength)
Parameters
centerVector3The center point of the box.
xlengthfloatThe length of the box along the X axis.
ylengthfloatThe length of the box along the Y axis.
zlengthfloatThe length of the box along the Z axis.
AddBox(Vector3, float, float, float, BoxFaces)
Adds a box with the specified faces, aligned with the X, Y and Z axes.
public void AddBox(Vector3 center, float xlength, float ylength, float zlength, BoxFaces faces)
Parameters
centerVector3The center point of the box.
xlengthfloatThe length of the box along the X axis.
ylengthfloatThe length of the box along the Y axis.
zlengthfloatThe length of the box along the Z axis.
facesBoxFacesThe faces to include.
AddCone(Vector3, Vector3, float, bool, int)
Adds a cone.
public void AddCone(Vector3 origin, Vector3 apex, float baseRadius, bool baseCap, int thetaDiv)
Parameters
originVector3The origin point.
apexVector3The apex point.
baseRadiusfloatThe base radius.
baseCapboolInclude a base cap if set to
true.thetaDivintThe theta div.
AddCone(Vector3, Vector3, float, float, float, bool, bool, int)
Adds a (possibly truncated) cone.
public void AddCone(Vector3 origin, Vector3 direction, float baseRadius, float topRadius, float height, bool baseCap, bool topCap, int thetaDiv)
Parameters
originVector3The origin.
directionVector3The direction (normalization not required).
baseRadiusfloatThe base radius.
topRadiusfloatThe top radius.
heightfloatThe height.
baseCapboolInclude a base cap if set to
true.topCapboolInclude the top cap if set to
true.thetaDivintThe number of divisions around the cone.
Remarks
AddCube(BoxFaces)
Add a Cube, only with specified Faces.
public void AddCube(BoxFaces faces = BoxFaces.All)
Parameters
facesBoxFacesThe Faces to create (default all Faces)
AddCubeFace(Vector3, Vector3, Vector3, float, float, float)
Adds a cube face.
public void AddCubeFace(Vector3 center, Vector3 normal, Vector3 up, float dist, float width, float height)
Parameters
centerVector3The center of the cube.
normalVector3The normal vector for the face.
upVector3The up vector for the face.
distfloatThe distance from the center of the cube to the face.
widthfloatThe width of the face.
heightfloatThe height of the face.
AddCylinder(Vector3, Vector3, float, int)
Adds a cylinder to the mesh.
public void AddCylinder(Vector3 p1, Vector3 p2, float diameter, int thetaDiv)
Parameters
p1Vector3The first point.
p2Vector3The second point.
diameterfloatThe diameters.
thetaDivintThe number of divisions around the cylinder.
Remarks
AddCylinder(Vector3, Vector3, float, int, bool, bool)
Adds a cylinder to the mesh.
public void AddCylinder(Vector3 p1, Vector3 p2, float radius = 1, int thetaDiv = 32, bool cap1 = true, bool cap2 = true)
Parameters
p1Vector3The first point.
p2Vector3The second point.
radiusfloatThe diameters.
thetaDivintThe number of divisions around the cylinder.
cap1boolThe first Cap.
cap2boolThe second Cap.
Remarks
AddDodecahedron(Vector3, Vector3, Vector3, float)
Generate a Dodecahedron
public void AddDodecahedron(Vector3 center, Vector3 forward, Vector3 up, float sideLength)
Parameters
centerVector3The Center of the Dodecahedron
forwardVector3The Direction to the first Point (normalized).
upVector3The Up-Dirextion (normalized, perpendicular to the forward Direction)
sideLengthfloatLength of the Edges of the Dodecahedron
Remarks
See: https://en.wikipedia.org/wiki/Dodecahedron https://en.wikipedia.org/wiki/Pentagon https://en.wikipedia.org/wiki/Isosceles_triangle
AddEdges(IList<Vector3>, IList<int>, float, int)
Adds a collection of edges as cylinders.
public void AddEdges(IList<Vector3> points, IList<int> edges, float diameter, int thetaDiv)
Parameters
pointsIList<Vector3>The points.
edgesIList<int>The edge indices.
diameterfloatThe diameter of the cylinders.
thetaDivintThe number of divisions around the cylinders.
AddEllipsoid(Vector3, float, float, float, int, int)
Adds an ellipsoid.
public void AddEllipsoid(Vector3 center, float radiusx, float radiusy, float radiusz, int thetaDiv = 20, int phiDiv = 10)
Parameters
centerVector3The center of the ellipsoid.
radiusxfloatThe x radius of the ellipsoid.
radiusyfloatThe y radius of the ellipsoid.
radiuszfloatThe z radius of the ellipsoid.
thetaDivintThe number of divisions around the ellipsoid.
phiDivintThe number of divisions from top to bottom of the ellipsoid.
AddExtrudedGeometry(IList<Vector2>, Vector3, Vector3, Vector3)
Adds an extruded surface of the specified curve.
public void AddExtrudedGeometry(IList<Vector2> points, Vector3 xaxis, Vector3 p0, Vector3 p1)
Parameters
pointsIList<Vector2>The 2D points describing the curve to extrude.
xaxisVector3The x-axis.
p0Vector3The start origin of the extruded surface.
p1Vector3The end origin of the extruded surface.
Remarks
The y-axis is determined by the cross product between the specified x-axis and the p1-origin vector.
AddExtrudedSegments(IList<Vector2>, Vector3, Vector3, Vector3)
Adds an extruded surface of the specified line segments.
public void AddExtrudedSegments(IList<Vector2> points, Vector3 axisX, Vector3 p0, Vector3 p1)
Parameters
pointsIList<Vector2>The 2D points describing the line segments to extrude. The number of points must be even.
axisXVector3The x-axis.
p0Vector3The start origin of the extruded surface.
p1Vector3The end origin of the extruded surface.
Remarks
The y-axis is determined by the cross product between the specified x-axis and the p1-origin vector.
AddFaceNX()
Add a Face in negative X-Direction.
public void AddFaceNX()
AddFaceNY()
Add a Face in negative Y-Direction.
public void AddFaceNY()
AddFaceNZ()
Add a Face in negative Z-Direction.
public void AddFaceNZ()
AddFacePX()
Add a Face in positive X-Direction.
public void AddFacePX()
AddFacePY()
Add a Face in positive Y-Direction.
public void AddFacePY()
AddFacePZ()
Add a Face in positive Z-Direction.
public void AddFacePZ()
AddLoftedGeometry(IList<IList<Vector3>>, IList<IList<Vector3>>, IList<IList<Vector2>>)
Adds a lofted surface.
public void AddLoftedGeometry(IList<IList<Vector3>> positionsList, IList<IList<Vector3>> normalList, IList<IList<Vector2>> textureCoordinateList)
Parameters
positionsListIList<IList<Vector3>>List of lofting sections.
normalListIList<IList<Vector3>>The normal list.
textureCoordinateListIList<IList<Vector2>>The texture coordinate list.
Remarks
AddNode(Vector3, Vector3, Vector2)
Adds a single node.
public void AddNode(Vector3 position, Vector3 normal, Vector2 textureCoordinate)
Parameters
positionVector3The position.
normalVector3The normal.
textureCoordinateVector2The texture coordinate.
AddOctahedron(Vector3, Vector3, Vector3, float, float)
Adds an octahedron.
public void AddOctahedron(Vector3 center, Vector3 forward, Vector3 up, float sideLength, float height)
Parameters
centerVector3The center.
forwardVector3The normal vector.
upVector3The up vector.
sideLengthfloatLength of the side.
heightfloatThe half height of the octahedron.
Remarks
See Octahedron.
AddPipe(Vector3, Vector3, float, float, int)
Adds a (possibly hollow) pipe.
public void AddPipe(Vector3 point1, Vector3 point2, float innerDiameter, float outerDiameter, int thetaDiv)
Parameters
point1Vector3The start point.
point2Vector3The end point.
innerDiameterfloatThe inner diameter.
outerDiameterfloatThe outer diameter.
thetaDivintThe number of divisions around the pipe.
AddPipes(IList<Vector3>, IList<int>, float, int)
Adds a collection of edges as cylinders.
public void AddPipes(IList<Vector3> points, IList<int> edges, float diameter = 1, int thetaDiv = 32)
Parameters
pointsIList<Vector3>The points.
edgesIList<int>The edge indices.
diameterfloatThe diameter of the cylinders.
thetaDivintThe number of divisions around the cylinders.
AddPolygon(IList<int>)
Adds a polygon specified by vertex index (uses a triangle fan).
public void AddPolygon(IList<int> vertexIndices)
Parameters
AddPolygon(IList<Vector2>, Vector3, Vector3, Vector3)
Adds a polygon.
public void AddPolygon(IList<Vector2> points, Vector3 axisX, Vector3 axisY, Vector3 origin)
Parameters
pointsIList<Vector2>The 2D points defining the polygon.
axisXVector3The x axis.
axisYVector3The y axis.
originVector3The origin.
AddPolygon(IList<Vector3>)
Adds a polygon.
public void AddPolygon(IList<Vector3> points)
Parameters
Remarks
If the number of points is greater than 4, a triangle fan is used.
AddPolygonByCuttingEars(IList<int>)
Adds a polygon defined by vertex indices (uses the cutting ears algorithm).
[Obsolete("Please use the faster version AddPolygon instead")]
public void AddPolygonByCuttingEars(IList<int> vertexIndices)
Parameters
AddPolygonByTriangulation(IList<int>)
Adds a polygon defined by vertex indices (uses the sweep line algorithm).
public void AddPolygonByTriangulation(IList<int> vertexIndices)
Parameters
AddPyramid(Vector3, Vector3, Vector3, float, float, bool)
Adds a pyramid.
public void AddPyramid(Vector3 center, Vector3 forward, Vector3 up, float sideLength, float height, bool closeBase = false)
Parameters
centerVector3The center.
forwardVector3The normal vector (normalized).
upVector3The 'up' vector (normalized).
sideLengthfloatLength of the sides of the pyramid.
heightfloatThe height of the pyramid.
closeBaseboolAdd triangles to the base of the pyramid or not.
AddPyramid(Vector3, float, float, bool)
Adds a pyramid.
public void AddPyramid(Vector3 center, float sideLength, float height, bool closeBase = false)
Parameters
centerVector3The center.
sideLengthfloatLength of the sides of the pyramid.
heightfloatThe height of the pyramid.
closeBaseboolAdd triangles to the base of the pyramid or not.
Remarks
AddQuad(IList<int>)
Adds a quad (exactely 4 indices)
public void AddQuad(IList<int> vertexIndices)
Parameters
AddQuad(Vector3, Vector3, Vector3, Vector3)
Adds a quadrilateral polygon.
public void AddQuad(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3)
Parameters
p0Vector3The first point.
p1Vector3The second point.
p2Vector3The third point.
p3Vector3The fourth point.
Remarks
AddQuad(Vector3, Vector3, Vector3, Vector3, Vector2, Vector2, Vector2, Vector2)
Adds a quadrilateral polygon.
public void AddQuad(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, Vector2 uv0, Vector2 uv1, Vector2 uv2, Vector2 uv3)
Parameters
p0Vector3The first point.
p1Vector3The second point.
p2Vector3The third point.
p3Vector3The fourth point.
uv0Vector2The first texture coordinate.
uv1Vector2The second texture coordinate.
uv2Vector2The third texture coordinate.
uv3Vector2The fourth texture coordinate.
Remarks
AddQuads(IList<Vector3>, IList<Vector3>?, IList<Vector2>?)
Adds a list of quadrilateral polygons.
public void AddQuads(IList<Vector3> quadPositions, IList<Vector3>? quadNormals, IList<Vector2>? quadTextureCoordinates)
Parameters
quadPositionsIList<Vector3>The points.
quadNormalsIList<Vector3>The normal vectors.
quadTextureCoordinatesIList<Vector2>The texture coordinates.
AddRectangularMesh(BoxFaces, int, int, float, float, bool, bool, bool)
Generates a rectangles mesh on the axis-aligned plane given by the box-face.
public void AddRectangularMesh(BoxFaces plane, int columns, int rows, float width, float height, bool flipTriangles = false, bool flipTexCoordsUAxis = false, bool flipTexCoordsVAxis = false)
Parameters
planeBoxFacesBox face which determines the plane the grid lies on.
columnsintwidth of the grid, i.e. horizontal resolution
rowsintheight of the grid, i.e. vertical resolution
widthfloattotal size in horizontal
heightfloattotal vertical size
flipTrianglesboolflips the triangle faces
flipTexCoordsUAxisboolflips the u-axis (horizontal) of the texture coords.
flipTexCoordsVAxisboolflips the v-axis (vertical) of the tex.coords.
AddRectangularMesh(IList<Vector3>, int)
Adds a rectangular mesh (m x n points).
public void AddRectangularMesh(IList<Vector3> points, int columns)
Parameters
pointsIList<Vector3>The one-dimensional array of points. The points are stored row-by-row.
columnsintThe number of columns in the rectangular mesh.
AddRectangularMesh(IList<Vector3>, int, bool)
Adds a rectangular mesh (m x n points).
public void AddRectangularMesh(IList<Vector3> points, int columns, bool flipTriangles = false)
Parameters
pointsIList<Vector3>The one-dimensional array of points. The points are stored row-by-row.
columnsintThe number of columns in the rectangular mesh.
flipTrianglesboolFlip the Triangles.
AddRectangularMesh(Vector3[,], Vector2[,]?, bool, bool)
Adds a rectangular mesh defined by a two-dimensional array of points.
public void AddRectangularMesh(Vector3[,] points, Vector2[,]? texCoords = null, bool closed0 = false, bool closed1 = false)
Parameters
pointsVector3[,]The points.
texCoordsVector2[,]The texture coordinates (optional).
closed0boolset to
trueif the mesh is closed in the first dimension.closed1boolset to
trueif the mesh is closed in the second dimension.
AddRectangularMeshTriangleIndices(int, int, int, bool)
Add triangle indices for a rectangular mesh.
public void AddRectangularMeshTriangleIndices(int index0, int rows, int columns, bool isSpherical = false)
Parameters
index0intThe index offset.
rowsintThe number of rows.
columnsintThe number of columns.
isSphericalboolset the flag to true to create a sphere mesh (triangles at top and bottom).
AddRectangularMeshTriangleIndices(int, int, int, bool, bool)
Adds triangular indices for a rectangular mesh.
public (int ActualRows, int ActualColumns) AddRectangularMeshTriangleIndices(int index0, int rows, int columns, bool rowsClosed, bool columnsClosed)
Parameters
index0intThe index 0.
rowsintThe rows.
columnsintThe columns.
rowsClosedboolTrue if rows are closed.
columnsClosedboolTrue if columns are closed.
Returns
AddRegularIcosahedron(Vector3, float, bool)
Adds a regular icosahedron.
public void AddRegularIcosahedron(Vector3 center, float radius, bool shareVertices)
Parameters
centerVector3The center.
radiusfloatThe radius.
shareVerticesboolShare vertices if set to
true.
Remarks
AddRevolvedGeometry(IList<Vector2>, IList<float>?, Vector3, Vector3, int)
Adds a surface of revolution.
public void AddRevolvedGeometry(IList<Vector2> points, IList<float>? textureValues, Vector3 origin, Vector3 direction, int thetaDiv)
Parameters
pointsIList<Vector2>The points (x coordinates are distance from the origin along the axis of revolution, y coordinates are radius, )
textureValuesIList<float>The v texture coordinates, one for each point in the
pointslist.originVector3The origin of the revolution axis.
directionVector3The direction of the revolution axis.
thetaDivintThe number of divisions around the mesh.
Remarks
AddSphere(Vector3, float, int, int)
Adds a sphere.
public void AddSphere(Vector3 center, float radius = 1, int thetaDiv = 32, int phiDiv = 32)
Parameters
centerVector3The center of the sphere.
radiusfloatThe radius of the sphere.
thetaDivintThe number of divisions around the sphere.
phiDivintThe number of divisions from top to bottom of the sphere.
AddSubdivisionSphere(Vector3, float, int)
Adds a sphere (by subdividing a regular icosahedron).
public void AddSubdivisionSphere(Vector3 center, float radius, int subdivisions)
Parameters
centerVector3The center of the sphere.
radiusfloatThe radius of the sphere.
subdivisionsintThe number of triangular subdivisions of the original icosahedron.
Remarks
See link.
AddSurfaceOfRevolution(Vector3, Vector3, IList<Vector2>, IList<int>, int, IList<float>?)
Adds a surface of revolution.
public void AddSurfaceOfRevolution(Vector3 origin, Vector3 axis, IList<Vector2> section, IList<int> sectionIndices, int thetaDiv = 36, IList<float>? textureValues = null)
Parameters
originVector3The origin.
axisVector3The axis.
sectionIList<Vector2>The points defining the curve to revolve.
sectionIndicesIList<int>The indices of the line segments of the section.
thetaDivintThe number of divisions.
textureValuesIList<float>The texture values.
AddTetrahedron(Vector3, Vector3, Vector3, float)
Add a tetrahedron.
public void AddTetrahedron(Vector3 center, Vector3 forward, Vector3 up, float sideLength)
Parameters
centerVector3The Center of Mass.
forwardVector3Direction to first Base-Point (in Base-Plane).
upVector3Up Vector.
sideLengthfloatThe Sidelength.
Remarks
See https://en.wikipedia.org/wiki/Tetrahedron and https://en.wikipedia.org/wiki/Equilateral_triangle.
AddTorus(float, float, int, int)
Adds a torus.
public void AddTorus(float torusDiameter, float tubeDiameter, int thetaDiv = 36, int phiDiv = 24)
Parameters
torusDiameterfloatThe diameter of the torus.
tubeDiameterfloatThe diameter of the torus "tube".
thetaDivintThe number of subdivisions around the torus.
phiDivintThe number of subdividions of the torus' "tube.
AddTriangle(IList<int>)
Adds a triangle (exactely 3 indices)
public void AddTriangle(IList<int> vertexIndices)
Parameters
AddTriangle(Vector3, Vector3, Vector3)
Adds a triangle.
public void AddTriangle(Vector3 p0, Vector3 p1, Vector3 p2)
Parameters
AddTriangle(Vector3, Vector3, Vector3, Vector2, Vector2, Vector2)
Adds a triangle.
public void AddTriangle(Vector3 p0, Vector3 p1, Vector3 p2, Vector2 uv0, Vector2 uv1, Vector2 uv2)
Parameters
p0Vector3The first point.
p1Vector3The second point.
p2Vector3The third point.
uv0Vector2The first texture coordinate.
uv1Vector2The second texture coordinate.
uv2Vector2The third texture coordinate.
AddTriangleFan(IList<int>)
Adds a triangle fan.
public void AddTriangleFan(IList<int> vertices)
Parameters
AddTriangleFan(IList<Vector3>, IList<Vector3>?, IList<Vector2>?)
Adds a triangle fan to the mesh
public void AddTriangleFan(IList<Vector3> fanPositions, IList<Vector3>? fanNormals = null, IList<Vector2>? fanTextureCoordinates = null)
Parameters
fanPositionsIList<Vector3>The points of the triangle fan.
fanNormalsIList<Vector3>The normal vectors of the triangle fan.
fanTextureCoordinatesIList<Vector2>The texture coordinates of the triangle fan.
AddTriangleStrip(IList<Vector3>, IList<Vector3>?, IList<Vector2>?)
Adds a triangle strip to the mesh.
public void AddTriangleStrip(IList<Vector3> stripPositions, IList<Vector3>? stripNormals = null, IList<Vector2>? stripTextureCoordinates = null)
Parameters
stripPositionsIList<Vector3>The points of the triangle strip.
stripNormalsIList<Vector3>The normal vectors of the triangle strip.
stripTextureCoordinatesIList<Vector2>The texture coordinates of the triangle strip.
Remarks
AddTriangles(IList<Vector3>, IList<Vector3>?, IList<Vector2>?)
Adds a list of triangles.
public void AddTriangles(IList<Vector3> trianglePositions, IList<Vector3>? triangleNormals = null, IList<Vector2>? triangleTextureCoordinates = null)
Parameters
trianglePositionsIList<Vector3>The points (the number of points must be a multiple of 3).
triangleNormalsIList<Vector3>The normal vectors (corresponding to the points).
triangleTextureCoordinatesIList<Vector2>The texture coordinates (corresponding to the points).
AddTube(IList<Vector3>, IList<float>?, IList<float>?, IList<Vector2>, Vector3?, bool, bool, bool, bool)
Adds a tube with a custom section.
public void AddTube(IList<Vector3> path, IList<float>? values, IList<float>? sectionScales, IList<Vector2> section, Vector3? sectionXAxis, bool isTubeClosed, bool isSectionClosed, bool frontCap = false, bool backCap = false)
Parameters
pathIList<Vector3>A list of points defining the centers of the tube.
valuesIList<float>The texture coordinate X values (optional).
sectionScalesIList<float>The scales of the section (optional).
sectionIList<Vector2>The section to extrude along the tube path.
sectionXAxisVector3?The initial alignment of the x-axis of the section into the 3D viewport
isTubeClosedboolIf the tube is closed set to
true.isSectionClosedboolif set to
true[is section closed].frontCapboolCreate a front Cap or not.
backCapboolCreate a back Cap or not.
AddTube(IList<Vector3>?, IList<float>?, IList<float>?, IList<float>?, IList<Vector2>, Vector3, bool, bool, bool, bool)
Adds a tube with a custom section.
Limitation: using xTextureCoordinates
with isTubeClosed = true
or isSectionClosed = true
will be incorrect texture at the last of mesh
public void AddTube(IList<Vector3>? path, IList<float>? sectionAngles, IList<float>? xTextureCoordinates, IList<float>? sectionScales, IList<Vector2> section, Vector3 sectionXAxis, bool isTubeClosed, bool isSectionClosed, bool frontCap = false, bool backCap = false)
Parameters
pathIList<Vector3>A list of points defining the centers of the tube.
sectionAnglesIList<float>The rotation of the section as it moves along the path, in radian.
xTextureCoordinatesIList<float>The texture coordinate X values (optional).
sectionScalesIList<float>The scales of the section (optional).
sectionIList<Vector2>The section to extrude along the tube path.
sectionXAxisVector3The initial alignment of the x-axis of the section into the 3D viewport
isTubeClosedboolIf the tube is closed set to
true.isSectionClosedboolif set to
true[is section closed].frontCapboolCreate a front Cap or not.
backCapboolCreate a back Cap or not.
AddTube(IList<Vector3>, IList<float>?, IList<float>?, int, bool, bool, bool)
Adds a tube with circle section.
public void AddTube(IList<Vector3> path, IList<float>? values, IList<float>? diameters, int thetaDiv, bool isTubeClosed, bool frontCap = false, bool backCap = false)
Parameters
pathIList<Vector3>A list of points defining the centers of the tube.
valuesIList<float>The texture coordinate X-values.
diametersIList<float>The diameters.
thetaDivintThe number of divisions around the tube.
isTubeClosedboolSet to true if the tube path is closed.
frontCapboolCreate a front Cap or not.
backCapboolCreate a back Cap or not.
AddTube(IList<Vector3>, float, int, bool, bool, bool)
Adds a tube with circle section.
public void AddTube(IList<Vector3> path, float diameter, int thetaDiv, bool isTubeClosed, bool frontCap = false, bool backCap = false)
Parameters
pathIList<Vector3>A list of points defining the centers of the tube.
diameterfloatThe diameter of the tube.
thetaDivintThe number of divisions around the tube.
isTubeClosedboolSet to true if the tube path is closed.
frontCapboolGenerate front Cap or not.
backCapboolGenerate back Cap or not.
Append(MeshBuilder?)
Appends the specified mesh.
public void Append(MeshBuilder? mesh)
Parameters
meshMeshBuilderThe mesh.
Append(MeshGeometry3D?)
Appends the specified mesh.
public void Append(MeshGeometry3D? mesh)
Parameters
meshMeshGeometry3DThe mesh.
Append(IList<Vector3>, IList<int>, IList<Vector3>?, IList<Vector2>?)
Appends the specified points and triangles.
public void Append(IList<Vector3> positionsToAppend, IList<int> triangleIndicesToAppend, IList<Vector3>? normalsToAppend = null, IList<Vector2>? textureCoordinatesToAppend = null)
Parameters
positionsToAppendIList<Vector3>The points to append.
triangleIndicesToAppendIList<int>The triangle indices to append.
normalsToAppendIList<Vector3>The normal vectors to append.
textureCoordinatesToAppendIList<Vector2>The texture coordinates to append.
AppendSphere(Vector3, float, int, int)
Tesselates the element and returns a MeshGeometry3D representing the tessellation based on the parameters given
public void AppendSphere(Vector3 center, float radius = 1, int thetaSteps = 64, int phiSteps = 64)
Parameters
ChamferCorner(Vector3, float, float, IList<Vector3>?)
Chamfers the specified corner (experimental code).
public void ChamferCorner(Vector3 p, float d, float eps = 1E-06, IList<Vector3>? chamferPoints = null)
Parameters
pVector3The corner point.
dfloatThe chamfer distance.
epsfloatThe corner search limit distance.
chamferPointsIList<Vector3>If this parameter is provided, the collection will be filled with the generated chamfer points.
CheckPerformanceLimits()
Checks the performance limits.
public void CheckPerformanceLimits()
Remarks
See MSDN. Try to keep mesh sizes under these limits: Positions : 20,001 point instances TriangleIndices : 60,003 integer instances
ComputeNormalsAndTangents(MeshFaces, bool)
Calculate the Normals and Tangents for all MeshFaces.
public void ComputeNormalsAndTangents(MeshFaces meshFaces, bool tangents = false)
Parameters
ComputeTangents(MeshFaces)
Calculate the Mesh's Tangents
public void ComputeTangents(MeshFaces meshFaces)
Parameters
meshFacesMeshFacesThe Faces of the Mesh
ComputeTangents(MeshGeometry3D)
Calculate the Tangents for a MeshGeometry3D.
public static void ComputeTangents(MeshGeometry3D meshGeometry)
Parameters
meshGeometryMeshGeometry3DThe MeshGeometry3D.
ComputeTangents(IList<Vector3>?, IList<Vector3>?, IList<Vector2>?, IList<int>, out IList<Vector3>, out IList<Vector3>)
Tangent Space computation for IndexedTriangle meshes Based on: http://www.terathon.com/code/tangent.html
public static void ComputeTangents(IList<Vector3>? positions, IList<Vector3>? normals, IList<Vector2>? textureCoordinates, IList<int> triangleIndices, out IList<Vector3> tangents, out IList<Vector3> bitangents)
Parameters
positionsIList<Vector3>normalsIList<Vector3>textureCoordinatesIList<Vector2>triangleIndicesIList<int>tangentsIList<Vector3>bitangentsIList<Vector3>
ComputeTangentsQuads(IList<Vector3>?, IList<Vector3>?, IList<Vector2>?, IList<int>, out IList<Vector3>, out IList<Vector3>)
Calculate the Tangents for a Quad.
public static void ComputeTangentsQuads(IList<Vector3>? positions, IList<Vector3>? normals, IList<Vector2>? textureCoordinates, IList<int> indices, out IList<Vector3> tangents, out IList<Vector3> bitangents)
Parameters
positionsIList<Vector3>The Positions.
normalsIList<Vector3>The Normals.
textureCoordinatesIList<Vector2>The TextureCoordinates.
indicesIList<int>The Indices.
tangentsIList<Vector3>The calculated Tangens.
bitangentsIList<Vector3>The calculated Bi-Tangens.
GetCircle(int, bool)
Gets a unit circle section with radius = 1, (cached).
public static IList<Vector2> GetCircle(int thetaDiv, bool closed = false)
Parameters
thetaDivintThe number of divisions.
closedboolIs the circle closed? If true, the last point will be in the same position as the first one.
Returns
GetCircleSegment(int, float, float)
Gets a unit circle segment section with radius = 1.
public static IList<Vector2> GetCircleSegment(int thetaDiv, float totalAngle = 6.2831855, float angleOffset = 0)
Parameters
thetaDivintThe number of division.
totalAnglefloatThe angle of the circle segment.
angleOffsetfloatThe angle-offset to use,in radian.
Returns
GetRectangle(float, float)
Get a rectangle section, (cached).
public static IList<Vector2> GetRectangle(float width, float height)
Parameters
Returns
Reset()
public void Reset()
Scale(float, float, float)
Scales the positions (and normal vectors).
public void Scale(float scaleX, float scaleY, float scaleZ)
Parameters
SubdivideLinear(bool)
Performs a linear subdivision of the mesh.
public void SubdivideLinear(bool barycentric = false)
Parameters
barycentricboolAdd a vertex in the center if set to
true.
ToMesh()
Converts the geometry to a MeshGeometry3D. All internal mesh builder data are directly assigned to the MeshGeometry3D without copying. User must call Reset() to reset and reuse the mesh builder object to create new meshes.
public MeshGeometry3D ToMesh()
Returns
- MeshGeometry3D
A mesh geometry.