Static Methodmigueldeicaza.swiftgodot 0.45.0SwiftGodot
getTriangleBarycentricCoords(point:a:b:c:)
Returns a Vector3
containing weights based on how close a 3D position (point
) is to a triangle’s different vertices (a
, b
and c
). This is useful for interpolating between the data of different vertices in a triangle. One example use case is using this to smoothly rotate over a mesh instead of relying solely on face normals.
static func getTriangleBarycentricCoords(point: Vector3, a: Vector3, b: Vector3, c: Vector3) -> Vector3
Here is a more detailed explanation of barycentric coordinates.
Other members in extension
Type members
static func buildBoxPlanes(extents: Vector3
) -> VariantCollection<Plane> Returns an array with 6
Plane
s that describe the sides of a box centered at the origin. The box size is defined byextents
, which represents one (positive) corner of the box (i.e. half its actual size).static func buildCapsulePlanes(radius: Double, height: Double, sides: Int32, lats: Int32, axis: Vector3.Axis
) -> VariantCollection<Plane> Returns an array of
Plane
s closely bounding a faceted capsule centered at the origin with radiusradius
and heightheight
. The parametersides
defines how many planes will be generated for the side part of the capsule, whereaslats
gives the number of latitudinal steps at the bottom and top of the capsule. The parameteraxis
describes the axis along which the capsule is oriented (0 for X, 1 for Y, 2 for Z).static func buildCylinderPlanes(radius: Double, height: Double, sides: Int32, axis: Vector3.Axis
) -> VariantCollection<Plane> Returns an array of
Plane
s closely bounding a faceted cylinder centered at the origin with radiusradius
and heightheight
. The parametersides
defines how many planes will be generated for the round part of the cylinder. The parameteraxis
describes the axis along which the cylinder is oriented (0 for X, 1 for Y, 2 for Z).static func clipPolygon(points: PackedVector3Array, plane: Plane
) -> PackedVector3Array Clips the polygon defined by the points in
points
against theplane
and returns the points of the clipped polygon.static func computeConvexMeshPoints(planes: VariantCollection<Plane>
) -> PackedVector3Array Calculates and returns all the vertex points of a convex shape defined by an array of
planes
.static func getClosestPointToSegment(point: Vector3, s1: Vector3, s2: Vector3
) -> Vector3 Returns the 3D point on the 3D segment (
s1
,s2
) that is closest topoint
. The returned point will always be inside the specified segment.static func getClosestPointToSegmentUncapped(point: Vector3, s1: Vector3, s2: Vector3
) -> Vector3 Returns the 3D point on the 3D line defined by (
s1
,s2
) that is closest topoint
. The returned point can be inside the segment (s1
,s2
) or outside of it, i.e. somewhere on the line extending from the segment.static func getClosestPointsBetweenSegments(p1: Vector3, p2: Vector3, q1: Vector3, q2: Vector3
) -> PackedVector3Array Given the two 3D segments (
p1
,p2
) and (q1
,q2
), finds those two points on the two segments that are closest to each other. Returns aPackedVector3Array
that contains this point on (p1
,p2
) as well the accompanying point on (q1
,q2
).static func rayIntersectsTriangle(from: Vector3, dir: Vector3, a: Vector3, b: Vector3, c: Vector3
) -> Variant Tests if the 3D ray starting at
from
with the direction ofdir
intersects the triangle specified bya
,b
andc
. If yes, returns the point of intersection asVector3
. If no intersection takes place, returnsnull
.static func segmentIntersectsConvex(from: Vector3, to: Vector3, planes: VariantCollection<Plane>
) -> PackedVector3Array Given a convex hull defined though the
Plane
s in the arrayplanes
, tests if the segment (from
,to
) intersects with that hull. If an intersection is found, returns aPackedVector3Array
containing the point the intersection and the hull’s normal. Otherwise, returns an empty array.static func segmentIntersectsCylinder(from: Vector3, to: Vector3, height: Double, radius: Double
) -> PackedVector3Array Checks if the segment (
from
,to
) intersects the cylinder with heightheight
that is centered at the origin and has radiusradius
. If no, returns an emptyPackedVector3Array
. If an intersection takes place, the returned array contains the point of intersection and the cylinder’s normal at the point of intersection.static func segmentIntersectsSphere(from: Vector3, to: Vector3, spherePosition: Vector3, sphereRadius: Double
) -> PackedVector3Array Checks if the segment (
from
,to
) intersects the sphere that is located atspherePosition
and has radiussphereRadius
. If no, returns an emptyPackedVector3Array
. If yes, returns aPackedVector3Array
containing the point of intersection and the sphere’s normal at the point of intersection.static func segmentIntersectsTriangle(from: Vector3, to: Vector3, a: Vector3, b: Vector3, c: Vector3
) -> Variant Tests if the segment (
from
,to
) intersects the trianglea
,b
,c
. If yes, returns the point of intersection asVector3
. If no intersection takes place, returnsnull
.class var godotClassName: StringName