summaryrefslogtreecommitdiff
path: root/scene/resources/multimesh.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources/multimesh.cpp')
-rw-r--r--scene/resources/multimesh.cpp257
1 files changed, 123 insertions, 134 deletions
diff --git a/scene/resources/multimesh.cpp b/scene/resources/multimesh.cpp
index ee831f36f5..f71cf383e5 100644
--- a/scene/resources/multimesh.cpp
+++ b/scene/resources/multimesh.cpp
@@ -29,22 +29,27 @@
/*************************************************************************/
#include "multimesh.h"
-#include "servers/visual_server.h"
-void MultiMesh::_set_transform_array(const PoolVector<Vector3> &p_array) {
- if (transform_format != TRANSFORM_3D)
+#include "servers/rendering_server.h"
+
+#ifndef DISABLE_DEPRECATED
+// Kept for compatibility from 3.x to 4.0.
+
+void MultiMesh::_set_transform_array(const Vector<Vector3> &p_array) {
+ if (transform_format != TRANSFORM_3D) {
return;
+ }
- const PoolVector<Vector3> &xforms = p_array;
+ const Vector<Vector3> &xforms = p_array;
int len = xforms.size();
ERR_FAIL_COND((len / 4) != instance_count);
- if (len == 0)
+ if (len == 0) {
return;
+ }
- PoolVector<Vector3>::Read r = xforms.read();
+ const Vector3 *r = xforms.ptr();
for (int i = 0; i < len / 4; i++) {
-
Transform t;
t.basis[0] = r[i * 4 + 0];
t.basis[1] = r[i * 4 + 1];
@@ -55,21 +60,21 @@ void MultiMesh::_set_transform_array(const PoolVector<Vector3> &p_array) {
}
}
-PoolVector<Vector3> MultiMesh::_get_transform_array() const {
-
- if (transform_format != TRANSFORM_3D)
- return PoolVector<Vector3>();
+Vector<Vector3> MultiMesh::_get_transform_array() const {
+ if (transform_format != TRANSFORM_3D) {
+ return Vector<Vector3>();
+ }
- if (instance_count == 0)
- return PoolVector<Vector3>();
+ if (instance_count == 0) {
+ return Vector<Vector3>();
+ }
- PoolVector<Vector3> xforms;
+ Vector<Vector3> xforms;
xforms.resize(instance_count * 4);
- PoolVector<Vector3>::Write w = xforms.write();
+ Vector3 *w = xforms.ptrw();
for (int i = 0; i < instance_count; i++) {
-
Transform t = get_instance_transform(i);
w[i * 4 + 0] = t.basis[0];
w[i * 4 + 1] = t.basis[1];
@@ -80,21 +85,21 @@ PoolVector<Vector3> MultiMesh::_get_transform_array() const {
return xforms;
}
-void MultiMesh::_set_transform_2d_array(const PoolVector<Vector2> &p_array) {
-
- if (transform_format != TRANSFORM_2D)
+void MultiMesh::_set_transform_2d_array(const Vector<Vector2> &p_array) {
+ if (transform_format != TRANSFORM_2D) {
return;
+ }
- const PoolVector<Vector2> &xforms = p_array;
+ const Vector<Vector2> &xforms = p_array;
int len = xforms.size();
ERR_FAIL_COND((len / 3) != instance_count);
- if (len == 0)
+ if (len == 0) {
return;
+ }
- PoolVector<Vector2>::Read r = xforms.read();
+ const Vector2 *r = xforms.ptr();
for (int i = 0; i < len / 3; i++) {
-
Transform2D t;
t.elements[0] = r[i * 3 + 0];
t.elements[1] = r[i * 3 + 1];
@@ -104,21 +109,21 @@ void MultiMesh::_set_transform_2d_array(const PoolVector<Vector2> &p_array) {
}
}
-PoolVector<Vector2> MultiMesh::_get_transform_2d_array() const {
-
- if (transform_format != TRANSFORM_2D)
- return PoolVector<Vector2>();
+Vector<Vector2> MultiMesh::_get_transform_2d_array() const {
+ if (transform_format != TRANSFORM_2D) {
+ return Vector<Vector2>();
+ }
- if (instance_count == 0)
- return PoolVector<Vector2>();
+ if (instance_count == 0) {
+ return Vector<Vector2>();
+ }
- PoolVector<Vector2> xforms;
+ Vector<Vector2> xforms;
xforms.resize(instance_count * 3);
- PoolVector<Vector2>::Write w = xforms.write();
+ Vector2 *w = xforms.ptrw();
for (int i = 0; i < instance_count; i++) {
-
Transform2D t = get_instance_transform_2d(i);
w[i * 3 + 0] = t.elements[0];
w[i * 3 + 1] = t.elements[1];
@@ -128,196 +133,183 @@ PoolVector<Vector2> MultiMesh::_get_transform_2d_array() const {
return xforms;
}
-void MultiMesh::_set_color_array(const PoolVector<Color> &p_array) {
-
- const PoolVector<Color> &colors = p_array;
+void MultiMesh::_set_color_array(const Vector<Color> &p_array) {
+ const Vector<Color> &colors = p_array;
int len = colors.size();
- if (len == 0)
+ if (len == 0) {
return;
+ }
ERR_FAIL_COND(len != instance_count);
- PoolVector<Color>::Read r = colors.read();
+ const Color *r = colors.ptr();
for (int i = 0; i < len; i++) {
-
set_instance_color(i, r[i]);
}
}
-PoolVector<Color> MultiMesh::_get_color_array() const {
-
- if (instance_count == 0 || color_format == COLOR_NONE)
- return PoolVector<Color>();
+Vector<Color> MultiMesh::_get_color_array() const {
+ if (instance_count == 0 || !use_colors) {
+ return Vector<Color>();
+ }
- PoolVector<Color> colors;
+ Vector<Color> colors;
colors.resize(instance_count);
for (int i = 0; i < instance_count; i++) {
-
colors.set(i, get_instance_color(i));
}
return colors;
}
-void MultiMesh::_set_custom_data_array(const PoolVector<Color> &p_array) {
-
- const PoolVector<Color> &custom_datas = p_array;
+void MultiMesh::_set_custom_data_array(const Vector<Color> &p_array) {
+ const Vector<Color> &custom_datas = p_array;
int len = custom_datas.size();
- if (len == 0)
+ if (len == 0) {
return;
+ }
ERR_FAIL_COND(len != instance_count);
- PoolVector<Color>::Read r = custom_datas.read();
+ const Color *r = custom_datas.ptr();
for (int i = 0; i < len; i++) {
-
set_instance_custom_data(i, r[i]);
}
}
-PoolVector<Color> MultiMesh::_get_custom_data_array() const {
-
- if (instance_count == 0 || custom_data_format == CUSTOM_DATA_NONE)
- return PoolVector<Color>();
+Vector<Color> MultiMesh::_get_custom_data_array() const {
+ if (instance_count == 0 || !use_custom_data) {
+ return Vector<Color>();
+ }
- PoolVector<Color> custom_datas;
+ Vector<Color> custom_datas;
custom_datas.resize(instance_count);
for (int i = 0; i < instance_count; i++) {
-
custom_datas.set(i, get_instance_custom_data(i));
}
return custom_datas;
}
-void MultiMesh::set_mesh(const Ref<Mesh> &p_mesh) {
+#endif // DISABLE_DEPRECATED
+void MultiMesh::set_buffer(const Vector<float> &p_buffer) {
+ RS::get_singleton()->multimesh_set_buffer(multimesh, p_buffer);
+}
+
+Vector<float> MultiMesh::get_buffer() const {
+ return RS::get_singleton()->multimesh_get_buffer(multimesh);
+}
+
+void MultiMesh::set_mesh(const Ref<Mesh> &p_mesh) {
mesh = p_mesh;
- if (!mesh.is_null())
- VisualServer::get_singleton()->multimesh_set_mesh(multimesh, mesh->get_rid());
- else
- VisualServer::get_singleton()->multimesh_set_mesh(multimesh, RID());
+ if (!mesh.is_null()) {
+ RenderingServer::get_singleton()->multimesh_set_mesh(multimesh, mesh->get_rid());
+ } else {
+ RenderingServer::get_singleton()->multimesh_set_mesh(multimesh, RID());
+ }
}
Ref<Mesh> MultiMesh::get_mesh() const {
-
return mesh;
}
void MultiMesh::set_instance_count(int p_count) {
ERR_FAIL_COND(p_count < 0);
- VisualServer::get_singleton()->multimesh_allocate(multimesh, p_count, VS::MultimeshTransformFormat(transform_format), VS::MultimeshColorFormat(color_format), VS::MultimeshCustomDataFormat(custom_data_format));
+ RenderingServer::get_singleton()->multimesh_allocate(multimesh, p_count, RS::MultimeshTransformFormat(transform_format), use_colors, use_custom_data);
instance_count = p_count;
}
-int MultiMesh::get_instance_count() const {
+int MultiMesh::get_instance_count() const {
return instance_count;
}
void MultiMesh::set_visible_instance_count(int p_count) {
ERR_FAIL_COND(p_count < -1);
- VisualServer::get_singleton()->multimesh_set_visible_instances(multimesh, p_count);
+ ERR_FAIL_COND(p_count > instance_count);
+ RenderingServer::get_singleton()->multimesh_set_visible_instances(multimesh, p_count);
visible_instance_count = p_count;
}
-int MultiMesh::get_visible_instance_count() const {
+int MultiMesh::get_visible_instance_count() const {
return visible_instance_count;
}
void MultiMesh::set_instance_transform(int p_instance, const Transform &p_transform) {
-
- VisualServer::get_singleton()->multimesh_instance_set_transform(multimesh, p_instance, p_transform);
+ RenderingServer::get_singleton()->multimesh_instance_set_transform(multimesh, p_instance, p_transform);
}
void MultiMesh::set_instance_transform_2d(int p_instance, const Transform2D &p_transform) {
-
- VisualServer::get_singleton()->multimesh_instance_set_transform_2d(multimesh, p_instance, p_transform);
+ RenderingServer::get_singleton()->multimesh_instance_set_transform_2d(multimesh, p_instance, p_transform);
}
Transform MultiMesh::get_instance_transform(int p_instance) const {
-
- return VisualServer::get_singleton()->multimesh_instance_get_transform(multimesh, p_instance);
+ return RenderingServer::get_singleton()->multimesh_instance_get_transform(multimesh, p_instance);
}
Transform2D MultiMesh::get_instance_transform_2d(int p_instance) const {
-
- return VisualServer::get_singleton()->multimesh_instance_get_transform_2d(multimesh, p_instance);
+ return RenderingServer::get_singleton()->multimesh_instance_get_transform_2d(multimesh, p_instance);
}
void MultiMesh::set_instance_color(int p_instance, const Color &p_color) {
-
- VisualServer::get_singleton()->multimesh_instance_set_color(multimesh, p_instance, p_color);
+ RenderingServer::get_singleton()->multimesh_instance_set_color(multimesh, p_instance, p_color);
}
-Color MultiMesh::get_instance_color(int p_instance) const {
- return VisualServer::get_singleton()->multimesh_instance_get_color(multimesh, p_instance);
+Color MultiMesh::get_instance_color(int p_instance) const {
+ return RenderingServer::get_singleton()->multimesh_instance_get_color(multimesh, p_instance);
}
void MultiMesh::set_instance_custom_data(int p_instance, const Color &p_custom_data) {
-
- VisualServer::get_singleton()->multimesh_instance_set_custom_data(multimesh, p_instance, p_custom_data);
-}
-Color MultiMesh::get_instance_custom_data(int p_instance) const {
-
- return VisualServer::get_singleton()->multimesh_instance_get_custom_data(multimesh, p_instance);
+ RenderingServer::get_singleton()->multimesh_instance_set_custom_data(multimesh, p_instance, p_custom_data);
}
-void MultiMesh::set_as_bulk_array(const PoolVector<float> &p_array) {
-
- VisualServer::get_singleton()->multimesh_set_as_bulk_array(multimesh, p_array);
+Color MultiMesh::get_instance_custom_data(int p_instance) const {
+ return RenderingServer::get_singleton()->multimesh_instance_get_custom_data(multimesh, p_instance);
}
AABB MultiMesh::get_aabb() const {
-
- return VisualServer::get_singleton()->multimesh_get_aabb(multimesh);
+ return RenderingServer::get_singleton()->multimesh_get_aabb(multimesh);
}
RID MultiMesh::get_rid() const {
-
return multimesh;
}
-void MultiMesh::set_color_format(ColorFormat p_color_format) {
-
+void MultiMesh::set_use_colors(bool p_enable) {
ERR_FAIL_COND(instance_count > 0);
- color_format = p_color_format;
+ use_colors = p_enable;
}
-MultiMesh::ColorFormat MultiMesh::get_color_format() const {
-
- return color_format;
+bool MultiMesh::is_using_colors() const {
+ return use_colors;
}
-void MultiMesh::set_custom_data_format(CustomDataFormat p_custom_data_format) {
-
+void MultiMesh::set_use_custom_data(bool p_enable) {
ERR_FAIL_COND(instance_count > 0);
- custom_data_format = p_custom_data_format;
+ use_custom_data = p_enable;
}
-MultiMesh::CustomDataFormat MultiMesh::get_custom_data_format() const {
-
- return custom_data_format;
+bool MultiMesh::is_using_custom_data() const {
+ return use_custom_data;
}
void MultiMesh::set_transform_format(TransformFormat p_transform_format) {
-
ERR_FAIL_COND(instance_count > 0);
transform_format = p_transform_format;
}
-MultiMesh::TransformFormat MultiMesh::get_transform_format() const {
+MultiMesh::TransformFormat MultiMesh::get_transform_format() const {
return transform_format;
}
void MultiMesh::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &MultiMesh::set_mesh);
ClassDB::bind_method(D_METHOD("get_mesh"), &MultiMesh::get_mesh);
- ClassDB::bind_method(D_METHOD("set_color_format", "format"), &MultiMesh::set_color_format);
- ClassDB::bind_method(D_METHOD("get_color_format"), &MultiMesh::get_color_format);
- ClassDB::bind_method(D_METHOD("set_custom_data_format", "format"), &MultiMesh::set_custom_data_format);
- ClassDB::bind_method(D_METHOD("get_custom_data_format"), &MultiMesh::get_custom_data_format);
+ ClassDB::bind_method(D_METHOD("set_use_colors", "enable"), &MultiMesh::set_use_colors);
+ ClassDB::bind_method(D_METHOD("is_using_colors"), &MultiMesh::is_using_colors);
+ ClassDB::bind_method(D_METHOD("set_use_custom_data", "enable"), &MultiMesh::set_use_custom_data);
+ ClassDB::bind_method(D_METHOD("is_using_custom_data"), &MultiMesh::is_using_custom_data);
ClassDB::bind_method(D_METHOD("set_transform_format", "format"), &MultiMesh::set_transform_format);
ClassDB::bind_method(D_METHOD("get_transform_format"), &MultiMesh::get_transform_format);
@@ -333,9 +325,21 @@ void MultiMesh::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_instance_color", "instance"), &MultiMesh::get_instance_color);
ClassDB::bind_method(D_METHOD("set_instance_custom_data", "instance", "custom_data"), &MultiMesh::set_instance_custom_data);
ClassDB::bind_method(D_METHOD("get_instance_custom_data", "instance"), &MultiMesh::get_instance_custom_data);
- ClassDB::bind_method(D_METHOD("set_as_bulk_array", "array"), &MultiMesh::set_as_bulk_array);
ClassDB::bind_method(D_METHOD("get_aabb"), &MultiMesh::get_aabb);
+ ClassDB::bind_method(D_METHOD("get_buffer"), &MultiMesh::get_buffer);
+ ClassDB::bind_method(D_METHOD("set_buffer", "buffer"), &MultiMesh::set_buffer);
+
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "transform_format", PROPERTY_HINT_ENUM, "2D,3D"), "set_transform_format", "get_transform_format");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_colors"), "set_use_colors", "is_using_colors");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_custom_data"), "set_use_custom_data", "is_using_custom_data");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "instance_count", PROPERTY_HINT_RANGE, "0,16384,1,or_greater"), "set_instance_count", "get_instance_count");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "visible_instance_count", PROPERTY_HINT_RANGE, "-1,16384,1,or_greater"), "set_visible_instance_count", "get_visible_instance_count");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "Mesh"), "set_mesh", "get_mesh");
+ ADD_PROPERTY(PropertyInfo(Variant::PACKED_FLOAT32_ARRAY, "buffer", PROPERTY_HINT_NONE), "set_buffer", "get_buffer");
+
+#ifndef DISABLE_DEPRECATED
+ // Kept for compatibility from 3.x to 4.0.
ClassDB::bind_method(D_METHOD("_set_transform_array"), &MultiMesh::_set_transform_array);
ClassDB::bind_method(D_METHOD("_get_transform_array"), &MultiMesh::_get_transform_array);
ClassDB::bind_method(D_METHOD("_set_transform_2d_array"), &MultiMesh::_set_transform_2d_array);
@@ -345,40 +349,25 @@ void MultiMesh::_bind_methods() {
ClassDB::bind_method(D_METHOD("_set_custom_data_array"), &MultiMesh::_set_custom_data_array);
ClassDB::bind_method(D_METHOD("_get_custom_data_array"), &MultiMesh::_get_custom_data_array);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "color_format", PROPERTY_HINT_ENUM, "None,Byte,Float"), "set_color_format", "get_color_format");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "transform_format", PROPERTY_HINT_ENUM, "2D,3D"), "set_transform_format", "get_transform_format");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "custom_data_format", PROPERTY_HINT_ENUM, "None,Byte,Float"), "set_custom_data_format", "get_custom_data_format");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "instance_count", PROPERTY_HINT_RANGE, "0,16384,1,or_greater"), "set_instance_count", "get_instance_count");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "visible_instance_count", PROPERTY_HINT_RANGE, "-1,16384,1,or_greater"), "set_visible_instance_count", "get_visible_instance_count");
- ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "Mesh"), "set_mesh", "get_mesh");
- ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR3_ARRAY, "transform_array", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_transform_array", "_get_transform_array");
- ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR2_ARRAY, "transform_2d_array", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_transform_2d_array", "_get_transform_2d_array");
- ADD_PROPERTY(PropertyInfo(Variant::POOL_COLOR_ARRAY, "color_array", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_color_array", "_get_color_array");
- ADD_PROPERTY(PropertyInfo(Variant::POOL_COLOR_ARRAY, "custom_data_array", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_custom_data_array", "_get_custom_data_array");
+ ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR3_ARRAY, "transform_array", PROPERTY_HINT_NONE, "", 0), "_set_transform_array", "_get_transform_array");
+ ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR2_ARRAY, "transform_2d_array", PROPERTY_HINT_NONE, "", 0), "_set_transform_2d_array", "_get_transform_2d_array");
+ ADD_PROPERTY(PropertyInfo(Variant::PACKED_COLOR_ARRAY, "color_array", PROPERTY_HINT_NONE, "", 0), "_set_color_array", "_get_color_array");
+ ADD_PROPERTY(PropertyInfo(Variant::PACKED_COLOR_ARRAY, "custom_data_array", PROPERTY_HINT_NONE, "", 0), "_set_custom_data_array", "_get_custom_data_array");
+#endif
BIND_ENUM_CONSTANT(TRANSFORM_2D);
BIND_ENUM_CONSTANT(TRANSFORM_3D);
-
- BIND_ENUM_CONSTANT(COLOR_NONE);
- BIND_ENUM_CONSTANT(COLOR_8BIT);
- BIND_ENUM_CONSTANT(COLOR_FLOAT);
-
- BIND_ENUM_CONSTANT(CUSTOM_DATA_NONE);
- BIND_ENUM_CONSTANT(CUSTOM_DATA_8BIT);
- BIND_ENUM_CONSTANT(CUSTOM_DATA_FLOAT);
}
MultiMesh::MultiMesh() {
-
- multimesh = VisualServer::get_singleton()->multimesh_create();
- color_format = COLOR_NONE;
- custom_data_format = CUSTOM_DATA_NONE;
+ multimesh = RenderingServer::get_singleton()->multimesh_create();
+ use_colors = false;
+ use_custom_data = false;
transform_format = TRANSFORM_2D;
visible_instance_count = -1;
instance_count = 0;
}
MultiMesh::~MultiMesh() {
-
- VisualServer::get_singleton()->free(multimesh);
+ RenderingServer::get_singleton()->free(multimesh);
}