new Face()
Creates a new BRep face.
Members
-
:Array.<PD.Point>
boundary
-
A sequential list of points defining the outer boundary.
Type
- Array.<PD.Point>
-
:THREE.Color|null
color
-
Stores the color of the face if different to the shape.
Type
- THREE.Color | null
-
:PD.FACET
faceType
-
The role that this face plays within the larger shape.
Type
-
:Array.<Array.<PD.Point>>
holes
-
A list of internal holes, each as a sequential list of points defining the inner boundary.
Type
- Array.<Array.<PD.Point>>
-
:boolean
isFace <readonly>
-
A flag identifying this object as a BRep face.
Type
- boolean
-
:THREE.Plane
plane
-
The plane equation of the BRep face.
NOTE: Faces use the value of
THREE.Plane#constantas a flag to indicate whether the face is planar or curved. if the constant is notNaN, the face is planar. Otherwise it is assumed to be curved. As a result, you should always check theplane.constantproperty before using the plane equation. You can do this quickly using thePD.BRep.Face#isPlanarandPD.BRep.Face#isCurvedmethods.Type
- THREE.Plane
-
:Array.<PD.Point>|null
triangles
-
A list of triangles that define the face's tessellated surface.
This is a flat array where each consecutive triplet of points form a separate triangle. Triangles are stored using the same point objects as used in the boundary and holes arrays. In fact, apart from some particular cases where the tesselation process may need to create a new interpolated vertex, they will almost always be references to the exact same point objects that define the outer and/or inner boundaries.
Type
- Array.<PD.Point> | null
Methods
-
addHole(vertices)
-
Adds a new hole to the face if it is planar.
NOTE 1: It is important that the
verticesarray contain only points created using theaddVertex()or related methods. This is because faces use themeshIndexproperty of each point in many of their operations, which is set to the appropriate value when the host BRep iterates itsvertexList. If a point is not in the vertex list, it will very likely have an invalidmeshIndexvalue, causing the operation to not work correctly.NOTE 2: This method only adds holes in planar faces. Inserting holes in curved faces using a contour of points is not currently supported. To add a hole to a curved face, you must modify the triangles that make up the surface to accommodate the hole.
Parameters:
Name Type Description verticesArray.<PD.Point> | Array.<Array.<PD.Point>> An array of points or an array of arrays of points.
Returns:
Returns true if one or more holes were added.
- Type
- boolean
-
asQuad(v1, v2, v3, v4 [, color] [, normal])
-
Provides a fast way of creating a simple quadrilateral face.
A face can be of any shape and contain any number of internal holes. This flexibility requires tests, checks and sometimes complex calculations to triangulate its surface and compute an appropriate plane equation.
However,
PD.ShellandPD.BRepobjects sometimes need to add a large number of simple triangles and quads to form a complex 3D form. This method offers a fast way of reusing existing faces for that purpose by completely defining and finalising the face in one call so that no further tests, checks or calculations are required.Parameters:
Name Type Argument Description v1PD.Point The first quad point, in model coordinates.
v2PD.Point The second quad point, in model coordinates.
v3PD.Point The third quad point, in model coordinates.
v4PD.Point The fourth quad point, in model coordinates.
colorTHREE.Color | number <optional>
An optional color value to assign the face.
normalTHREE.Vector3 <optional>
An optional normalised direction vector.
Returns:
Returns this face to support method chaining.
- Type
- PD.BRep.Face
-
asTriangle(v1, v2, v3 [, color] [, normal])
-
Provides a fast way of creating a simple triangular face.
A face can be of any shape and contain any number of internal holes. This flexibility requires tests, checks and sometimes complex calculations to triangulate its surface and compute an appropriate plane equation.
However,
PD.ShellandPD.BRepobjects sometimes need to add a large number of simple triangles and quads to form a complex 3D form. This method offers a fast way of reusing existing faces for that purpose by completely defining and finalising the face in one call so that no further tests, checks or calculations are required.Parameters:
Name Type Argument Description v1PD.Point The first triangle point, in model coordinates.
v2PD.Point The second triangle point, in model coordinates.
v3PD.Point The third triangle point, in model coordinates.
colorTHREE.Color | number <optional>
An optional color value to assign the face.
normalTHREE.Vector3 <optional>
An optional normalised direction vector.
Returns:
Returns this face to support method chaining.
- Type
- PD.BRep.Face
-
asTriangleFan(vertices [, color] [, normal])
-
Provides a fast way of creating a convex polygonal face.
This method computes the plane equation from the given vertices and arranges surface triangles using a triangle fan, as shown below. You should only use this method if you know that the vertices form a planar convex polygon.
_.3--------2_ _.-'' \ / \_ 4'' \ / \_ \ ' . | / \_ \ ' . \ / _.1 5--..__ '. / __..--'' ''-0-''A face can be of any shape and contain any number of internal holes. This flexibility requires tests, checks and sometimes complex calculations to triangulate its surface and compute an appropriate plane equation.
However,
PD.ShellandPD.BRepobjects sometimes need to add a large number of simple triangles and quads to form a complex 3D form. This method offers a fast way of reusing existing faces for that purpose by completely defining and finalising the face in one call so that no further tests, checks or calculations are required.Parameters:
Name Type Argument Description verticesArray.<PD.Point> Three or more vertices to create the face from.
colorTHREE.Color | number <optional>
An optional color value to assign the face.
normalTHREE.Vector3 <optional>
An optional normalised direction vector.
Returns:
Returns this face to support method chaining.
- Type
- PD.BRep.Face
-
asTriangleFanFromApex(vertices, apex [, color] [, normal])
-
Provides a fast way of creating a simple polygonal face.
This method computes the plane equation from the given vertices and arranges surface triangles using a triangle fan that radiates around the given apex, as shown below. You should only use this method if you know that the vertices form a simple planar polygon.
_.3--------2_ _.-'' \ __/ \_ 4''_ _ \ / \_ \ ' ' - o - . _ \_ \ | ' ' _.1 5--..__ | __..--'' ''-0-''A face can be of any shape and contain any number of internal holes. This flexibility requires tests, checks and sometimes complex calculations to triangulate its surface and compute an appropriate plane equation.
However,
PD.ShellandPD.BRepobjects sometimes need to add a large number of simple triangles and quads to form a complex 3D form. This method offers a fast way of reusing existing faces for that purpose by completely defining and finalising the face in one call so that no further tests, checks or calculations are required.Parameters:
Name Type Argument Description verticesArray.<PD.Point> Two or more vertices to create the face from.
apexPD.POint The apex point somewhere inside the polygonal boundary.
colorTHREE.Color | number <optional>
An optional color value to assign the face.
normalTHREE.Vector3 <optional>
An optional normalised direction vector.
Returns:
Returns this face to support method chaining.
- Type
- PD.BRep.Face
-
bothPointsOnSameBoundaryXY(point1, point2 [, tolerance])
-
Determines if the given points are on or close to the same face boundary in the XY plane.
Parameters:
Name Type Argument Description point1THREE.Vector3 The first point to to check if on boundary.
point2THREE.Vector3 The second point to to check if on boundary.
tolerancenumber <optional>
The distance threshold to define closeness, defaults to 1e-3.
Returns:
Returns true if both points on the same boundary in the XY plane, otherwise false.
- Type
- boolean
-
computeArea()
-
Calculates the surface area of the face, in metres squared (m2).
Returns:
Returns the surface area in metres squared (m2).
- Type
- number
-
computeBoundaryIntersectionPointXY(from, to, target)
-
Computes the first intersection point, if any, between the give line segment and any of the boundary segments on the polygon.
Parameters:
Name Type Description fromTHREE.Vector3 The first point in the line.
toTHREE.Vector3 The second point in the line.
targetTHREE.Vector3 The vector to receive the intersection point, may be the same as
to.Returns:
Returns true if an intersection point was found and
targetwas updated.- Type
- boolean
-
computeBoundingEdgesFromTriangles()
-
Analyzes the triangles in the face and computes those edges that are not shared with adjacent triangles.
Only call this method after all faces and vertices have been added, and if you are sure that all vertices used in the face triangles are also in the
PD.BRep#vertexListarray. If you are unsure, call thePD.BRep#validateVertexListmethod first.The resulting edges can be used to create bounding edge loops or for creating wireframes or edge highlighting.
Returns:
Returns an array of open edges, each in the form [p1, p2].
- Type
- Array.<Array.<PD.Point>>
-
computeBounds(min, max)
-
Computes the bounding extents of the face and updates the arguments.
Unlike a
PD.Polygon, faces do not store their own extents. Thus, this method is used to update the given arguments if any point in this face is outside their existing range.NOTE: This method changes values within the
minandmaxparameters.Parameters:
Name Type Description minTHREE.Vector3 The point to receive the minimum extent.
maxTHREE.Vector3 The point to receive the maximum extent.
Returns:
Returns true if min/max were set.
- Type
- boolean
-
computeClosestPointOnBoundary(point, target)
-
Computes the closest point that lies on the boundary of the face.
Parameters:
Name Type Description pointTHREE.Vector3 The point to check if on boundary.
targetTHREE.Vector3 The vector to receive the closest point, may be the same as
point.Returns:
Returns true if a closest point was found.
- Type
- boolean
-
computeClosestPointOnBoundaryXY(point, target)
-
Computes the closest point that lies on the boundary of the face in the XY plane.
Parameters:
Name Type Description pointTHREE.Vector3 The point to check if on boundary.
targetTHREE.Vector3 The vector to receive the closest point, may be the same as
point.Returns:
Returns true if a closest point was found.
- Type
- boolean
-
computeGeometricCenter(center)
-
Computes the geometric center of the face.
NOTE: This method changes values within the
centerparameter.Parameters:
Name Type Description centerTHREE.Vector3 The point to receive the center position.
Returns:
Returns true if the center point was computed and set.
- Type
- boolean
-
computePerimeter()
-
Calculates the total perimeter length of the face, in millimetres.
Returns:
Returns the total perimeter length in millimetres (mm).
- Type
- number
-
computePlaneEquation( [makePlanar])
-
Calculates the plane equation of the face.
This method uses Newell's Method to compute the surface normal. If the surface is tagged as non-planar (where
plane.constant == NaN), then the plane equation will not be calculated. However, you can passtruefor themakePlanarargument to set the face as planar and calculate its plane equationParameters:
Name Type Argument Description makePlanarboolean <optional>
An optional flag to set the face as planar and calculate a plane equation.
Returns:
Returns true if a valid plane equation was calculated or false if non-planar, there were insufficient points or they are all co-linear.
- Type
- boolean
-
computePlaneIntersectionPoints(plane, intersection, results)
-
Computes all the intersection points between this face boundary and hole line segments with the given plane.
This method cycles through all the boundary and hole lines within the face, or its triangles if non-planar, computing the intersection points with the given plane and storing them in the
resultsarray.Parameters:
Name Type Description planeTHREE.Plane The plane to intersection all faces with.
intersectionTHREE.Vector3 The point to temporarily store intersection points.
resultsArray.<THREE.Vector3> The array to the resulting intersection points to.
Returns:
Returns the array of intersection points.
- Type
- Array.<THREE.Vector3>
-
computeSliceProfile(polygon, indexer [, results])
-
Determines any sliced lines that the given polygon makes across this face.
The
indexeris used to store unique [x,y,z] vector arrays defining the end points of each slice line. Slice lines are then stored as arrays of two (2) vertex indices in theresultsarray.+ |\ | \ | \ | \ | \ | \ _+---o---\---+. _.-' | \ \ 2 '. _.-' + \ + '. +' 1 \ \ | __..+ '. \ __o.--'' '. __..--'' | '+'' \ | \ | \ | \ | \| +Parameters:
Name Type Argument Description polygonPD.Polygon The polygon defining the cutting plane.
indexerPD.Indexer The indexer to add unique [x,y,z] vector arrays to.
resultsArray.<Array.<number>> <optional>
An array of edges to add any intersection lines to.
Returns:
Returns the
resultsarray or a newly created array, containing [index1,index2,face] entries.- Type
- Array.<Array>
-
computeVertexNormals()
-
Computes the averaged normal of all triangulated vertices used to define the surface of a curved face.
Returns:
Returns true if this face is curved and the triangle vertex normals were updated.
- Type
- boolean
-
copyDashedLinesToPolyMesh(mesh, size)
-
Adds the outline as architectural-style extended lines to the given mesh.
NOTE: This method does NOT reuse any shared vertices that may have already been added to the mesh.
Parameters:
Name Type Description meshPD.PolyMesh The dynamic mesh to add the drafting to.
sizenumber The size of line dashes, in model coordinates.
Returns:
Returns true if geometry was added to the mesh.
- Type
- boolean
-
copyDraftingLinesToPolyMesh(mesh, size)
-
Adds the outline as architectural-style extended lines to the given mesh.
NOTE: This method does NOT reuse any shared vertices that may have already been added to the mesh.
Parameters:
Name Type Description meshPD.PolyMesh The dynamic mesh to add the drafting to.
sizenumber The size of the extended overrun, in model coordinates.
Returns:
Returns true if geometry was added to the mesh.
- Type
- boolean
-
copyOutlineToPolyMesh(mesh)
-
Adds the outline of the face to the given mesh.
NOTE: This method does NOT reuse any shared vertices that may have already been added to the mesh.
Parameters:
Name Type Description meshPD.PolyMesh The dynamic mesh to add the outline to.
Returns:
Returns true if geometry was added to the mesh.
- Type
- boolean
-
copySharedDraftingLinesToPolyMesh(mesh, size)
-
Adds an architectural-style extended outline to the given mesh using shared vertex indices.
NOTE: This method checks each vertex to see if it has already been added to the mesh. Thus, it must be called only after all vertex indexes have been cleared/reset.
Parameters:
Name Type Description meshPD.PolyMesh The dynamic mesh to add the drafting to.
sizenumber The size of the extended overrun, in model coordinates.
Returns:
Returns true if geometry was added to the mesh.
- Type
- boolean
-
copySharedOutlineToPolyMesh(mesh)
-
Adds a face outline to the given mesh using shared vertex indices.
NOTE: This method checks each vertex to see if it has already been added to the mesh. Thus, it must be called only after all vertex indexes have been cleared/reset.
Parameters:
Name Type Description meshPD.PolyMesh The dynamic mesh to add the outline to.
Returns:
Returns true if geometry was added to the mesh.
- Type
- boolean
-
copySurfaceToPolyMesh(mesh [, noColor])
-
Add face surface triangles to the given mesh.
NOTE: This method clears and resets mesh vertex indexes and checks each vertex to see if it has already been added to the mesh. Once this method has been called, it is safe to use the
PD.BRep.Face#copySharedOutlineToPolyMeshandPD.BRep.Face#copySharedDraftingLinesToPolyMeshmethods which also check each vertex to see if it has already been added to the mesh.Parameters:
Name Type Argument Description meshPD.PolyMesh The dynamic mesh to add the polygon to.
noColorboolean <optional>
When true, the surface color is not set, defaults to false.
Returns:
Returns true if geometry was added to the mesh.
- Type
- boolean
-
copyToPolyMesh(mesh [, noOutline] [, noColor])
-
Adds the face to the given dynamic mesh.
This methods first calls the
PD.BRep.Face#copySharedOutlineToPolyMeshmethod and, if outlines are being rendered, either thePD.BRep.Face#copySharedOutlineToPolyMeshorPD.BRep.Face#copySharedDraftingLinesToPolyMeshmethods. This means that it makes its best efforts to reuse any vertices that may have already been added to the mesh rather that adding them more than once.Parameters:
Name Type Argument Description meshPD.PolyMesh The dynamic mesh to add the polygon to.
noOutlineboolean <optional>
When true, boundary outlines are not included, defaults to false.
noColorboolean <optional>
When true, the surface color is not set, defaults to false.
Returns:
Returns true if geometry was added to the mesh.
- Type
- boolean
-
fromClipperPaths(paths, plane [, brep] [, offset] [, quaternion])
-
Converts one or more 2D ClipperLib paths back into a BRep face.
As ClipperLib works with 2D {X,Y} objects, they must be transformed from the XY cartesian plane back into 3D space. This method uses the the given plane equation normal to compute a quaternion to rotate points from the XY plane. This quaternion is applied to each point in the paths, which is more computationally expensive than using the axis of greatest surface exposure, but better retains the orientation and winding order of points.
Using quaternions to rotate the points to and from the XY plane results in the 2D rotated positions always align correctly with their 3D positions on the surface of the plane. However, if polygons have slightly different plane equations or their points are not all exactly co-planar, then small cumulative inaccuracies can build up over multiple conversions, far more than the with axis-based conversion. Thus, use this method only if you know that the plane equations you are using are consistent across all faces.
If no plane equation is given, the XY plane is assumed (Z=0). If a number is given in place of the plane equation, then that number is used a Z-axis offset in the XY plane (Z = toNumber(plane)). An optional offset can be given to move the 3D points along the plane normal by the given amount, which can be useful to avoid surface Z-fighting.
If you have already computed the quaternion to rotate the points to/from the XY plane, you can provide it as the last argument to avoid it having to be computed again.
Parameters:
Name Type Argument Description pathsArray One or more ClipperLib paths containing {X,Y} Clipper points.
planeTHREE.Plane | number The plane equation to project points onto or a Z-axis height.
brepPD.BRep <optional>
An optional shell to reuse vertices from.
offsetnumber <optional>
An offset value from the plane in its axial direction.
quaternionTHREE.Quaternion <optional>
An optional quaternion to use rather than computing it.
Returns:
Returns this BRep face to support method chaining.
- Type
- PD.Polyline
-
fromJSON(data, vertices)
-
Safely copy properties from a source object.
See the
PD.Base#fromJSONmethod for more details.NOTE: You should avoid calling this method directly on faces unless you really know what you are doing. You should use the host BRep
PD.BRep#fromJSONmethod instead. This is because vertices in this method are imported as their index within the host BRep'sPD.BRep#vertexListrather than their position, normal and uv coordinates. This makes it absolutely necessary that the host BRep vertex list has already been loaded before this method can reference them via theverticesargument.Override this method in derived classes to read additional properties, but call
super.fromJSON(data);at the top of the method.Parameters:
Name Type Description dataobject The source object containing data to copy.
verticesArray.<PD.Point> The list of vertices that vertex array reference.
Returns:
Returns this face to support method chaining.
- Type
- PD.BRep.Face
Example
// Overriding this method. class MyFace extends PD.BRep.Face { /// ... fromJSON(data, vertices) { super.fromJSON(data, vertices); if ('extraData' in data) { this.extraData = PD.Utils.toIntegerInRange(data.extraData, this.extraData, 0, 16); } if ('evenMoreData' in data) { this.evenMoreData = PD.Utils.toNumber(data.evenMoreData, this.evenMoreData); } return this; }; /// ... }; -
hasContent()
-
Determines whether or not the face has valid content.
Returns:
Returns true if the face has a boundary and/or triangles.
- Type
- boolean
-
intersectRay(ray, target)
-
Determines the intersection point between a ray and this face.
Parameters:
Name Type Description rayTHREE.Ray The ray to intersect the face with.
targetTHREE.Vector3 The vector to receive the intersection point.
Returns:
Return
trueif the face was intersected, orfalseif not.- Type
- boolean
-
isCurved()
-
Determines whether or not the face is curved and does not have a valid plane equation.
When a face is curved, the normals of each of its individual vertices will used when it is meshed rather than its plane equation normal. The
normalcomponent of its plane equation will still be calculated from its vertices, but theconstantcomponent will be set toNaNto indicate that it is curved and has no single plane equation. This can sometimes allow for some small optimisations where flat and curved faces can share vertices, with the vertex normal being computed only for the curved face. Unless they are two parts of a continuously curved surface, two curved faces should not share vertices unless the normals at each vertex are equal.A curved face requires its
PD.BRep.Face#trianglesarray to define the curve, and that it be generated as part of the face creation process. This is because the face class has no knowledge of the equations to use for the curve or how to tesselate it. This is the role of the host application or generator class.Returns:
Returns true if the face is curved and/or non-planar.
- Type
- boolean
-
isInsideFrustum(frustum, intersect)
-
Determines whether or not the polygon is inside the given frustum.
Parameters:
Name Type Description frustumTHREE.Frustum The frustum to check if inside.
intersectboolean Whether to also check for intersection selection.
Returns:
Returns true if inside, otherwise false.
- Type
- boolean
-
isPlanar()
-
Determines whether or not the face is planar and has a valid plane equation.
When a face is flat, the
normalcomponent of its plane equation will be used for all vertices when it is meshed rather than their individual vertex normals. This can sometimes allow for small optimisations where planar faces can share vertices with curved surfaces. An example of this would be the flat top and bottom faces of a cylinder sharing vertices with the curved side face. In this case, the vertex normals are computed only for the curved face, which will used those normals directly, whilst the planar top and bottom faces will use only the share position data, with their plane normals being used instead of the vertex normals.For the same reason, flat planar faces can share vertices with any number of other flat planar faces as their vertex normals are ignored in favour of the plane equation normal. Also, if the
PD.BRep.Face#trianglesarray is empty, the face will be automatically tessellated based on its outer boundary and any holes it contains.Returns:
Returns true if the face is planar and has a valid plane equation.
- Type
- boolean
-
isPointInside(point [, selecting])
-
Determines whether or not the given point is within the surface of this face.
As triangles in a planar face are assumed to all share the same surface normal, this calculation can be reasonably fast. This method also correctly handles points that are inside internal holes/contours.
When the
selectingargument is true, only the outer boundary of the face is tested as this allows for subsequent drilling down into holes and openings. This means that triangle intersection is not used when selecting a face.Parameters:
Name Type Argument Description pointTHREE.Vector3 The point to to check if inside.
selectingboolean <optional>
Whether or not this is being use to select a face, defaults to false.
Returns:
Returns true if inside, otherwise false.
- Type
- boolean
-
isPointInsideHole(point, index)
-
Determines whether or not the given point is within an internal hole.
This method only works for planar faces which have at least one hole. Its sums the signed angle between the given point and each line segment of the given contour boundary. If the total angle is near zero, then the point must be outside. If near 360, it must be inside.
Parameters:
Name Type Description pointTHREE.Vector3 The point to to check if inside.
indexnumber The index of the contour within the polyline.
Returns:
Returns true if inside, otherwise false.
- Type
- boolean
-
isPointOnBoundary(point [, tolerance])
-
Determines if the given point is on or close to the face boundary.
Parameters:
Name Type Argument Description pointTHREE.Vector3 The point to to check if inside.
tolerancenumber <optional>
The distance threshold to define closeness, defaults to 1e-3.
Returns:
Returns true if on boundary, otherwise false.
- Type
- boolean
-
isPointOnBoundaryXY(point [, tolerance])
-
Determines if the given point lies on or close to the face boundary in the XY plane.
Parameters:
Name Type Argument Description pointTHREE.Vector3 The point to to check if inside.
tolerancenumber <optional>
The distance threshold to define closeness, defaults to 1e-3.
Returns:
Returns true if on boundary in the XY plane, otherwise false.
- Type
- boolean
-
naiveTrimToPlane(brep, plane)
-
Naively trims a convex face to the given plane.
This method is much simpler and, as the name indicates, more naive than the
splitByPlanemethods as it is intended for use only with concave faces and to re-use existing faces and vertices at the plane intersection points rather than creating new ones.+ |\ | \ | \ | \ | \ | \ +--------------+ -\ - + | | \ \ . | face + \ + . | \ \ | . +------------------+ | - - + \ | \ | \ | \ | \ | \| <--- + planeParameters:
Name Type Description brepPD.BRep The parent BRep in case new vertices are required.
planeTHREE.Plane The plane to clip the face with.
Returns:
Returns true if face is valid and all or part in front.
- Type
- boolean
-
resetMeshIndexes()
-
Resets the
PD.Point#meshIndexproperty of all vertices to -1.Returns:
Returns this face to support method chaining.
- Type
- PD.BRep.Face
-
reverse()
-
Reverses the order of vertices as well as the surface normal and plane equation.
Returns:
Returns this face to support method chaining.
- Type
- PD.BRep.Face
-
setBoundary(vertices)
-
Sets the outer boundary of the face if it is planar.
NOTE 1: It is important that the
verticesarray contain only points created using theaddVertex()or related methods. This is because faces use themeshIndexproperty of each point in many of their operations, which is set to the appropriate value when the host BRep iterates itsvertexList. If a point is not in the vertex list, it will very likely have an invalidmeshIndexvalue, causing the operation to not work correctly.Parameters:
Name Type Description verticesArray.<PD.Point> An array of points or an array of arrays of points.
Returns:
Returns true the boundary was set.
- Type
- boolean
-
shareWithShell(shell [, reverse])
-
Adds the face to the given shell.
NOTE: This method is intended for quickly sharing faces with element and junction shells for selection purposes rather than replicating entire shapes. As a result, the shell facets will share the BRep vertices rather than creating new copies.
Parameters:
Name Type Argument Default Description shellPD.Shell The shell to add the face to.
reverseboolean <optional>
false If true, the face orientation will be reversed, defaults to false.
Returns:
Returns the newly added facet or
nullif the face was invalid.- Type
- PD.Polygon
-
splitByPlane(brep, plane, frontFaces, rearFaces)
-
Splits a face into one or more faces by the given plane.
+ |\ | \ | \ | \ | \ | \ _+---+---\----+ _.-' | \ \ 2 \ _.-' + \ + \ +' 1 \ \ | _.+ '. \ __+.--'' '. __..--'' | '+'' \ | \ | \ | \ | \| +Given a plane and two arrays, this method splits this face into areas that are on either side of the plane. The areas on each side are added to the two arrays. If either of the arrays are not given, the faces to be added to that side will be ignored.
NOTE: This method reuses vertices and faces already in the BRep, so must only be used between calls to
reuseStart()andreuseEnd().Parameters:
Name Type Description brepPD.BRep The BRep to add new points and faces to.
planeTHREE.Plane The plane to clip the face with.
frontFacesArray.<PD.BRep.Face> The list to store areas in front of the plane (same direction as surface normal).
rearFacesArray.<PD.BRep.Face> The list to store areas behind the plane (opposite direction to surface normal).
Returns:
Returns true if face is valid and was either in front, behind or split.
- Type
- boolean
-
splitByPlaneOnlyIfConvex(brep, plane, frontFaces, rearFaces)
-
Splits a face into one or more faces by the given plane.
+ |\ | \ | \ | \ | \ | \ _+---+---\----+ _.-' | \ \ 2 \ _.-' + \ + \ +' 1 \ \ | _.+ '. \ __+.--'' '. __..--'' | '+'' \ | \ | \ | \ | \| +Given a plane and two arrays, this method splits this face into areas that are on either side of the plane. The areas on each side are added to the two arrays. If either of the arrays are not given, the faces to be added to that side will be ignored.
NOTE: This method reuses vertices and faces already in the BRep, so must only be used between calls to
reuseStart()andreuseEnd().Parameters:
Name Type Description brepPD.BRep The BRep to add new points and faces to.
planeTHREE.Plane The plane to clip the face with.
frontFacesArray.<PD.BRep.Face> The list to store areas in front of the plane (same direction as surface normal).
rearFacesArray.<PD.BRep.Face> The list to store areas behind the plane (opposite direction to surface normal).
Returns:
Returns true if face is valid and was either in front, behind or split.
- Type
- boolean
-
tesselate(brep)
-
Tessellates a face using the robust LibTess algorithm.
Parameters:
Name Type Description brepPD.BRep The BRep this face belongs to.
Returns:
Returns a flat array of points from the given face, where each consecutive triplet forms a triangle.
- Type
- Array
-
toClipperPaths( [clipCache])
-
Converts face boundary and holes into 2D
ClipperLib.Patharrays.As ClipperLib works with 2D {X,Y} objects, a 3D face must be transformed from its 3D orientation to a flat cartesian plane. This method uses the face's plane equation normal to compute a quaternion that rotates the face onto the XY plane. This quaternion is applied to each point in the face, which is more computationally expensive than using the axis of greatest surface exposure, but better retains the orientation and winding order of points.
Using quaternions to rotate the points to and from the XY plane results in the 2D rotated positions always align correctly with their 3D positions on the surface of the plane. However, if faces have slightly different plane equations or their points are not all exactly co-planar, then small cumulative inaccuracies can build up over multiple conversions, far more than the with axis-based conversion. Thus, use this method only if you know that the plane equations you are using are consistent across all faces.
Parameters:
Name Type Argument Description clipCachePD.Clipper.Cache <optional>
An optional cache for reusing 2D clipper points.
Returns:
Returns an array of one or more
ClipperLib.Patharrays, each containing {X,Y} Clipper points for the outer boundary and any holes within it.- Type
- Array
-
toClipperPathsByAxis( [axis] [, clipCache])
-
Converts the outer boundary and holes of a face into 2D
ClipperLib.Patharrays using the axis of greatest surface exposure.As ClipperLib works with 2D {X,Y} objects, the 3D face must be translated into a 2D cartesian plane. This method uses the given axis or, if no axis is given, the calculated axis for the face.
Converting to 2D and then back to 3D in the axis with the largest surface exposure involves only a small amount of maths so is very quick and accuracy is more than acceptable. It is required when performing operations on multiple shapes that may not be on exactly the same plane - or on faces whose points may not all be exactly co-planar - as positions will be very stable even after multiple conversions. However, if the plane normal is not exactly aligned with one of the cartesian axis, then the 2D point positions will be skewed slightly compared to their positions on the surface of the plane.
Using quaternions to rotate the points to and from the XY plane results in the 2D rotated positions always aligning correctly with their 3D positions on the surface of the plane. However, if faces have slightly different plane equations or their points are not all exactly co-planar, then small cumulative inaccuracies can build up over multiple conversions, far more than when using the axis-based conversion implemented in this method.
Parameters:
Name Type Argument Description axisPD.AXIS <optional>
The axis to use when converting, defaults to
this.axis.clipCachePD.Clipper.Cache <optional>
An optional cache for reusing 2D clipper points.
Returns:
Returns an array of one or more
ClipperLib.Patharrays, each containing {X,Y} Clipper points.- Type
- Array
-
toJSON( [data])
-
Converts the face to a simple POJO for conversion to JSON.
This method is used to copy, store and save the data for a face, so the returned object must have all the properties required to be able to rebuild this instance in its entirety when passed to the class constructor.
NOTE: You should avoid calling this method directly on faces unless you really know what you are doing. You should use the host BRep
PD.BRep#toJSONmethod instead. This is because vertices in this method are exported as their index within the host BRep'sPD.BRep#vertexListrather than their position, normal and uv coordinates. This makes it absolutely necessary that thePD.BRep#validateVertexListmethod on the the host BRep has been called immediately prior in order to have properly set thePD.Point#meshIndexvalues on each vertex for export.Override this method in derived classes to add additional properties, but call
data = super.toJSON(data);at the top of the method, as shown in the example below.Parameters:
Name Type Argument Description dataobject <optional>
An optional parent object to append this data to.
Returns:
Returns a Plain Old Javascript Object (POJO).
- Type
- object
Example
// Overriding this method. class MyFace extends PD.BRep.Face { /// ... toJSON(data) { data = super.toJSON(data); data.extraData = this.extraData; data.evenMoreData = this.evenMoreData; return data; }; /// ... }; -
update(brep)
-
Computes the plane equation and surface triangulation.
A valid
surfaceargument is required so that any new interpolated vertices created during the tesselation process can be drawn from and stored in the pool of reusable vertices forming the surface.Parameters:
Name Type Description brepPD.BRep The BRep this face belongs to.
Returns:
Returns this face to support method chaining.
- Type
- PD.BRep.Face
-
addSharedContourDraftingLinesToPolyMesh(contour, mesh, size, closed) <static>
-
Joins an array of points with architectural-style extended lines in the given mesh.
NOTE: This method checks each vertex to see if it has already been added to the mesh. Thus, it must be called only after all vertex indexes have been cleared/reset.
Parameters:
Name Type Description contourArray.<PD.Point> The sequential list of points to add.
meshPD.PolyMesh The dynamic mesh to add the drafting lines to.
sizenumber The size of the extended overrun, in model coordinates.
closedboolean Whether or not to join the last point to the first.
-
addSharedContourOutlineToPolyMesh(contour, mesh [, closed]) <static>
-
Joins an array of points with lines in the given mesh.
NOTE: This method checks each vertex to see if it has already been added to the mesh. Thus, it must be called only after all vertex indexes have been cleared/reset.
Parameters:
Name Type Argument Description contourArray.<PD.Point> The sequential list of points to add.
meshPD.PolyMesh The dynamic mesh to add the drafting lines to.
closedboolean <optional>
Whether or not to join the last point to the first, defaults to false.