23 lines
672 B
GDScript3
23 lines
672 B
GDScript3
|
@tool class_name PlaneConvexDecompose
|
||
|
|
||
|
static func from(plane: Mesh, depth: float) -> Array[CollisionShape3D]:
|
||
|
var vertices: Array[Vector3] = [Vector3.ZERO, Vector3.ZERO, Vector3.ZERO]
|
||
|
var colliders: Array[CollisionShape3D] = []
|
||
|
var i: int = 0
|
||
|
for vertex in plane.get_faces():
|
||
|
vertices[i] = vertex
|
||
|
i += 1
|
||
|
if i >= 3:
|
||
|
i = 0
|
||
|
var shape := ConvexPolygonShape3D.new()
|
||
|
shape.points = [
|
||
|
vertices[0], vertices[1], vertices[2],
|
||
|
vertices[0] - Vector3.UP*depth,
|
||
|
vertices[1] - Vector3.UP*depth,
|
||
|
vertices[2] - Vector3.UP*depth
|
||
|
]
|
||
|
var collider := CollisionShape3D.new()
|
||
|
collider.shape = shape
|
||
|
colliders.push_back(collider)
|
||
|
return colliders
|