Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # returns a 2d array of all faces of the `mesh` with the transform `mesh_transform` that are in `radius` of the given `position`
- # each array in the returned array corresponds to a surface of the mesh
- static func get_faces_near_radius(mesh : Mesh, mesh_transform : Transform, position : Vector3, radius := 1.0) -> Array:
- var surface_faces := []
- for surface in mesh.get_surface_count():
- var faces := PoolIntArray()
- var mesh_tool := MeshDataTool.new()
- mesh_tool.create_from_surface(mesh, 0)
- for face in mesh_tool.get_face_count():
- for vertex in 3:
- var vertex_position := mesh_tool.get_vertex(mesh_tool.get_face_vertex(face, vertex))
- if mesh_transform.xform(vertex_position).distance_to(position) < radius:
- faces.append(face)
- break
- surface_faces.append(faces)
- return surface_faces
- # returns a copy of the given `mesh` with `surface_faces` removed
- static func remove_faces_from_mesh(mesh : Mesh, surface_faces : Array) -> ArrayMesh:
- var new_mesh := ArrayMesh.new()
- for surface in mesh.get_surface_count():
- var surface_tool := SurfaceTool.new()
- surface_tool.begin(Mesh.PRIMITIVE_TRIANGLES)
- var mesh_tool := MeshDataTool.new()
- mesh_tool.create_from_surface(mesh, surface)
- for face in mesh_tool.get_face_count():
- if not Array(surface_faces[surface]).has(face):
- for face_vertex in 3:
- var vertex := mesh_tool.get_face_vertex(face, face_vertex)
- surface_tool.add_uv(mesh_tool.get_vertex_uv(vertex))
- surface_tool.add_normal(mesh_tool.get_vertex_normal(vertex))
- surface_tool.add_vertex(mesh_tool.get_vertex(vertex))
- surface_tool.commit(new_mesh)
- return new_mesh
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement