diff --git a/doc/classes/SurfaceTool.xml b/doc/classes/SurfaceTool.xml
index 576587a5df49..a8bd068b1ce0 100644
--- a/doc/classes/SurfaceTool.xml
+++ b/doc/classes/SurfaceTool.xml
@@ -93,7 +93,7 @@
- Commits the data to the same format used by [method ArrayMesh.add_surface_from_arrays]. This way you can further process the mesh data using the [ArrayMesh] API.
+ Commits the data to the same format used by [method ArrayMesh.add_surface_from_arrays], [method ImporterMesh.add_surface], and [method create_from_arrays]. This way you can further process the mesh data using the [ArrayMesh] or [ImporterMesh] APIs.
@@ -104,6 +104,14 @@
Creates a vertex array from an existing [Mesh].
+
+
+
+
+
+ Creates this SurfaceTool from existing vertex arrays such as returned by [method commit_to_arrays], [method Mesh.surface_get_arrays], [method Mesh.surface_get_blend_shape_arrays], [method ImporterMesh.get_surface_arrays], and [method ImporterMesh.get_surface_blend_shape_arrays]. [param primitive_type] controls the type of mesh data, defaulting to [constant Mesh.PRIMITIVE_TRIANGLES].
+
+
diff --git a/scene/resources/3d/importer_mesh.cpp b/scene/resources/3d/importer_mesh.cpp
index 952e99608d1a..375efcb22782 100644
--- a/scene/resources/3d/importer_mesh.cpp
+++ b/scene/resources/3d/importer_mesh.cpp
@@ -1139,7 +1139,7 @@ Error ImporterMesh::lightmap_unwrap_cached(const Transform3D &p_base_transform,
s.material = get_surface_material(i);
s.name = get_surface_name(i);
- SurfaceTool::create_vertex_array_from_triangle_arrays(arrays, s.vertices, &s.format);
+ SurfaceTool::create_vertex_array_from_arrays(arrays, s.vertices, &s.format);
PackedVector3Array rvertices = arrays[Mesh::ARRAY_VERTEX];
int vc = rvertices.size();
diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp
index f766d1d2c79e..73f3009fd1f8 100644
--- a/scene/resources/mesh.cpp
+++ b/scene/resources/mesh.cpp
@@ -2086,7 +2086,7 @@ Error ArrayMesh::lightmap_unwrap_cached(const Transform3D &p_base_transform, flo
Array arrays = surface_get_arrays(i);
s.material = surface_get_material(i);
- SurfaceTool::create_vertex_array_from_triangle_arrays(arrays, s.vertices, &s.format);
+ SurfaceTool::create_vertex_array_from_arrays(arrays, s.vertices, &s.format);
PackedVector3Array rvertices = arrays[Mesh::ARRAY_VERTEX];
int vc = rvertices.size();
diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp
index 06d53e4e2ff5..9f2fad410c0e 100644
--- a/scene/resources/surface_tool.cpp
+++ b/scene/resources/surface_tool.cpp
@@ -802,7 +802,7 @@ void SurfaceTool::_create_list(const Ref &p_existing, int p_surface, Local
const uint32_t SurfaceTool::custom_mask[RS::ARRAY_CUSTOM_COUNT] = { Mesh::ARRAY_FORMAT_CUSTOM0, Mesh::ARRAY_FORMAT_CUSTOM1, Mesh::ARRAY_FORMAT_CUSTOM2, Mesh::ARRAY_FORMAT_CUSTOM3 };
const uint32_t SurfaceTool::custom_shift[RS::ARRAY_CUSTOM_COUNT] = { Mesh::ARRAY_FORMAT_CUSTOM0_SHIFT, Mesh::ARRAY_FORMAT_CUSTOM1_SHIFT, Mesh::ARRAY_FORMAT_CUSTOM2_SHIFT, Mesh::ARRAY_FORMAT_CUSTOM3_SHIFT };
-void SurfaceTool::create_vertex_array_from_triangle_arrays(const Array &p_arrays, LocalVector &ret, uint64_t *r_format) {
+void SurfaceTool::create_vertex_array_from_arrays(const Array &p_arrays, LocalVector &ret, uint64_t *r_format) {
ret.clear();
Vector varr = p_arrays[RS::ARRAY_VERTEX];
@@ -932,7 +932,7 @@ void SurfaceTool::create_vertex_array_from_triangle_arrays(const Array &p_arrays
}
void SurfaceTool::_create_list_from_arrays(Array arr, LocalVector *r_vertex, LocalVector *r_index, uint64_t &lformat) {
- create_vertex_array_from_triangle_arrays(arr, *r_vertex, &lformat);
+ create_vertex_array_from_arrays(arr, *r_vertex, &lformat);
ERR_FAIL_COND(r_vertex->size() == 0);
//indices
@@ -949,9 +949,9 @@ void SurfaceTool::_create_list_from_arrays(Array arr, LocalVector *r_ver
}
}
-void SurfaceTool::create_from_triangle_arrays(const Array &p_arrays) {
+void SurfaceTool::create_from_arrays(const Array &p_arrays, Mesh::PrimitiveType p_primitive_type) {
clear();
- primitive = Mesh::PRIMITIVE_TRIANGLES;
+ primitive = p_primitive_type;
_create_list_from_arrays(p_arrays, &vertex_array, &index_array, format);
for (int j = 0; j < RS::ARRAY_CUSTOM_COUNT; j++) {
@@ -961,6 +961,10 @@ void SurfaceTool::create_from_triangle_arrays(const Array &p_arrays) {
}
}
+void SurfaceTool::create_from_triangle_arrays(const Array &p_arrays) {
+ create_from_arrays(p_arrays, Mesh::PRIMITIVE_TRIANGLES);
+}
+
void SurfaceTool::create_from(const Ref &p_existing, int p_surface) {
ERR_FAIL_NULL_MSG(p_existing, "First argument in SurfaceTool::create_from() must be a valid object of type Mesh");
@@ -1377,6 +1381,7 @@ void SurfaceTool::_bind_methods() {
ClassDB::bind_method(D_METHOD("clear"), &SurfaceTool::clear);
ClassDB::bind_method(D_METHOD("create_from", "existing", "surface"), &SurfaceTool::create_from);
+ ClassDB::bind_method(D_METHOD("create_from_arrays", "arrays", "primitive_type"), &SurfaceTool::create_from_arrays, DEFVAL(Mesh::PRIMITIVE_TRIANGLES));
ClassDB::bind_method(D_METHOD("create_from_blend_shape", "existing", "surface", "blend_shape"), &SurfaceTool::create_from_blend_shape);
ClassDB::bind_method(D_METHOD("append_from", "existing", "surface", "transform"), &SurfaceTool::append_from);
ClassDB::bind_method(D_METHOD("commit", "existing", "flags"), &SurfaceTool::commit, DEFVAL(Variant()), DEFVAL(0));
diff --git a/scene/resources/surface_tool.h b/scene/resources/surface_tool.h
index 9dfb298b9e6e..a072df5bee8e 100644
--- a/scene/resources/surface_tool.h
+++ b/scene/resources/surface_tool.h
@@ -219,7 +219,8 @@ class SurfaceTool : public RefCounted {
LocalVector &get_vertex_array() { return vertex_array; }
void create_from_triangle_arrays(const Array &p_arrays);
- static void create_vertex_array_from_triangle_arrays(const Array &p_arrays, LocalVector &ret, uint64_t *r_format = nullptr);
+ void create_from_arrays(const Array &p_arrays, Mesh::PrimitiveType p_primitive_type = Mesh::PRIMITIVE_TRIANGLES);
+ static void create_vertex_array_from_arrays(const Array &p_arrays, LocalVector &ret, uint64_t *r_format = nullptr);
Array commit_to_arrays();
void create_from(const Ref &p_existing, int p_surface);
void create_from_blend_shape(const Ref &p_existing, int p_surface, const String &p_blend_shape_name);