| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*  multimesh.cpp                                                        */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       This file is part of:                           */ | 
					
						
							|  |  |  | /*                           GODOT ENGINE                                */ | 
					
						
							| 
									
										
										
										
											2017-08-27 14:16:55 +02:00
										 |  |  | /*                      https://godotengine.org                          */ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2022-01-03 21:27:34 +01:00
										 |  |  | /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur.                 */ | 
					
						
							|  |  |  | /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md).   */ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* Permission is hereby granted, free of charge, to any person obtaining */ | 
					
						
							|  |  |  | /* a copy of this software and associated documentation files (the       */ | 
					
						
							|  |  |  | /* "Software"), to deal in the Software without restriction, including   */ | 
					
						
							|  |  |  | /* without limitation the rights to use, copy, modify, merge, publish,   */ | 
					
						
							|  |  |  | /* distribute, sublicense, and/or sell copies of the Software, and to    */ | 
					
						
							|  |  |  | /* permit persons to whom the Software is furnished to do so, subject to */ | 
					
						
							|  |  |  | /* the following conditions:                                             */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* The above copyright notice and this permission notice shall be        */ | 
					
						
							|  |  |  | /* included in all copies or substantial portions of the Software.       */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ | 
					
						
							|  |  |  | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ | 
					
						
							|  |  |  | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ | 
					
						
							|  |  |  | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ | 
					
						
							|  |  |  | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ | 
					
						
							|  |  |  | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ | 
					
						
							|  |  |  | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2018-01-05 00:50:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | #include "multimesh.h"
 | 
					
						
							| 
									
										
										
										
											2020-02-13 11:37:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | #include "servers/rendering_server.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-14 00:37:42 -03:00
										 |  |  | #ifndef DISABLE_DEPRECATED
 | 
					
						
							| 
									
										
										
										
											2020-02-13 11:37:37 +01:00
										 |  |  | // Kept for compatibility from 3.x to 4.0.
 | 
					
						
							| 
									
										
										
										
											2019-09-14 00:37:42 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | void MultiMesh::_set_transform_array(const Vector<Vector3> &p_array) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (transform_format != TRANSFORM_3D) { | 
					
						
							| 
									
										
										
										
											2019-04-24 00:01:54 +10:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | 	const Vector<Vector3> &xforms = p_array; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	int len = xforms.size(); | 
					
						
							|  |  |  | 	ERR_FAIL_COND((len / 4) != instance_count); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (len == 0) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | 	const Vector3 *r = xforms.ptr(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < len / 4; i++) { | 
					
						
							| 
									
										
										
										
											2020-10-17 01:08:21 -04:00
										 |  |  | 		Transform3D t; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		t.basis[0] = r[i * 4 + 0]; | 
					
						
							|  |  |  | 		t.basis[1] = r[i * 4 + 1]; | 
					
						
							|  |  |  | 		t.basis[2] = r[i * 4 + 2]; | 
					
						
							|  |  |  | 		t.origin = r[i * 4 + 3]; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		set_instance_transform(i, t); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | Vector<Vector3> MultiMesh::_get_transform_array() const { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (transform_format != TRANSFORM_3D) { | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | 		return Vector<Vector3>(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-04-24 00:01:54 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (instance_count == 0) { | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | 		return Vector<Vector3>(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | 	Vector<Vector3> xforms; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	xforms.resize(instance_count * 4); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | 	Vector3 *w = xforms.ptrw(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < instance_count; i++) { | 
					
						
							| 
									
										
										
										
											2020-10-17 01:08:21 -04:00
										 |  |  | 		Transform3D t = get_instance_transform(i); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		w[i * 4 + 0] = t.basis[0]; | 
					
						
							|  |  |  | 		w[i * 4 + 1] = t.basis[1]; | 
					
						
							|  |  |  | 		w[i * 4 + 2] = t.basis[2]; | 
					
						
							|  |  |  | 		w[i * 4 + 3] = t.origin; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return xforms; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | void MultiMesh::_set_transform_2d_array(const Vector<Vector2> &p_array) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (transform_format != TRANSFORM_2D) { | 
					
						
							| 
									
										
										
										
											2019-04-24 00:01:54 +10:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-04-24 00:01:54 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | 	const Vector<Vector2> &xforms = p_array; | 
					
						
							| 
									
										
										
										
											2019-04-24 00:01:54 +10:00
										 |  |  | 	int len = xforms.size(); | 
					
						
							|  |  |  | 	ERR_FAIL_COND((len / 3) != instance_count); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (len == 0) { | 
					
						
							| 
									
										
										
										
											2019-04-24 00:01:54 +10:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-04-24 00:01:54 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | 	const Vector2 *r = xforms.ptr(); | 
					
						
							| 
									
										
										
										
											2019-04-24 00:01:54 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (int i = 0; i < len / 3; i++) { | 
					
						
							|  |  |  | 		Transform2D t; | 
					
						
							| 
									
										
										
										
											2022-04-24 16:59:24 -05:00
										 |  |  | 		t.columns[0] = r[i * 3 + 0]; | 
					
						
							|  |  |  | 		t.columns[1] = r[i * 3 + 1]; | 
					
						
							|  |  |  | 		t.columns[2] = r[i * 3 + 2]; | 
					
						
							| 
									
										
										
										
											2019-04-24 00:01:54 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		set_instance_transform_2d(i, t); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | Vector<Vector2> MultiMesh::_get_transform_2d_array() const { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (transform_format != TRANSFORM_2D) { | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | 		return Vector<Vector2>(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-04-24 00:01:54 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (instance_count == 0) { | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | 		return Vector<Vector2>(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-04-24 00:01:54 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | 	Vector<Vector2> xforms; | 
					
						
							| 
									
										
										
										
											2019-04-24 00:01:54 +10:00
										 |  |  | 	xforms.resize(instance_count * 3); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | 	Vector2 *w = xforms.ptrw(); | 
					
						
							| 
									
										
										
										
											2019-04-24 00:01:54 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (int i = 0; i < instance_count; i++) { | 
					
						
							|  |  |  | 		Transform2D t = get_instance_transform_2d(i); | 
					
						
							| 
									
										
										
										
											2022-04-24 16:59:24 -05:00
										 |  |  | 		w[i * 3 + 0] = t.columns[0]; | 
					
						
							|  |  |  | 		w[i * 3 + 1] = t.columns[1]; | 
					
						
							|  |  |  | 		w[i * 3 + 2] = t.columns[2]; | 
					
						
							| 
									
										
										
										
											2019-04-24 00:01:54 +10:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return xforms; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | void MultiMesh::_set_color_array(const Vector<Color> &p_array) { | 
					
						
							|  |  |  | 	const Vector<Color> &colors = p_array; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	int len = colors.size(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (len == 0) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-09-05 19:14:39 -03:00
										 |  |  | 	ERR_FAIL_COND(len != instance_count); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | 	const Color *r = colors.ptr(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < len; i++) { | 
					
						
							|  |  |  | 		set_instance_color(i, r[i]); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | Vector<Color> MultiMesh::_get_color_array() const { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (instance_count == 0 || !use_colors) { | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | 		return Vector<Color>(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | 	Vector<Color> colors; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	colors.resize(instance_count); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < instance_count; i++) { | 
					
						
							|  |  |  | 		colors.set(i, get_instance_color(i)); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return colors; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | void MultiMesh::_set_custom_data_array(const Vector<Color> &p_array) { | 
					
						
							|  |  |  | 	const Vector<Color> &custom_datas = p_array; | 
					
						
							| 
									
										
										
										
											2018-09-05 19:14:39 -03:00
										 |  |  | 	int len = custom_datas.size(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (len == 0) { | 
					
						
							| 
									
										
										
										
											2018-09-05 19:14:39 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-09-05 19:14:39 -03:00
										 |  |  | 	ERR_FAIL_COND(len != instance_count); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | 	const Color *r = custom_datas.ptr(); | 
					
						
							| 
									
										
										
										
											2018-09-05 19:14:39 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (int i = 0; i < len; i++) { | 
					
						
							|  |  |  | 		set_instance_custom_data(i, r[i]); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | Vector<Color> MultiMesh::_get_custom_data_array() const { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (instance_count == 0 || !use_custom_data) { | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | 		return Vector<Color>(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-09-05 19:14:39 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | 	Vector<Color> custom_datas; | 
					
						
							| 
									
										
										
										
											2018-09-05 19:14:39 -03:00
										 |  |  | 	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; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-02-13 11:37:37 +01:00
										 |  |  | #endif // DISABLE_DEPRECATED
 | 
					
						
							| 
									
										
										
										
											2019-09-14 00:37:42 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | void MultiMesh::set_buffer(const Vector<float> &p_buffer) { | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 	RS::get_singleton()->multimesh_set_buffer(multimesh, p_buffer); | 
					
						
							| 
									
										
										
										
											2019-09-14 00:37:42 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | Vector<float> MultiMesh::get_buffer() const { | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 	return RS::get_singleton()->multimesh_get_buffer(multimesh); | 
					
						
							| 
									
										
										
										
											2019-09-14 00:37:42 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void MultiMesh::set_mesh(const Ref<Mesh> &p_mesh) { | 
					
						
							|  |  |  | 	mesh = p_mesh; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!mesh.is_null()) { | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 		RenderingServer::get_singleton()->multimesh_set_mesh(multimesh, mesh->get_rid()); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 		RenderingServer::get_singleton()->multimesh_set_mesh(multimesh, RID()); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Ref<Mesh> MultiMesh::get_mesh() const { | 
					
						
							|  |  |  | 	return mesh; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MultiMesh::set_instance_count(int p_count) { | 
					
						
							| 
									
										
										
										
											2018-09-05 19:14:39 -03:00
										 |  |  | 	ERR_FAIL_COND(p_count < 0); | 
					
						
							| 
									
										
										
										
											2021-02-09 13:19:03 -03:00
										 |  |  | 	RenderingServer::get_singleton()->multimesh_allocate_data(multimesh, p_count, RS::MultimeshTransformFormat(transform_format), use_colors, use_custom_data); | 
					
						
							| 
									
										
										
										
											2018-09-05 19:14:39 -03:00
										 |  |  | 	instance_count = p_count; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | int MultiMesh::get_instance_count() const { | 
					
						
							| 
									
										
										
										
											2018-09-05 19:14:39 -03:00
										 |  |  | 	return instance_count; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-22 18:38:30 -03:00
										 |  |  | void MultiMesh::set_visible_instance_count(int p_count) { | 
					
						
							|  |  |  | 	ERR_FAIL_COND(p_count < -1); | 
					
						
							| 
									
										
										
										
											2019-09-14 00:37:42 -03:00
										 |  |  | 	ERR_FAIL_COND(p_count > instance_count); | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 	RenderingServer::get_singleton()->multimesh_set_visible_instances(multimesh, p_count); | 
					
						
							| 
									
										
										
										
											2019-04-22 18:38:30 -03:00
										 |  |  | 	visible_instance_count = p_count; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-22 18:38:30 -03:00
										 |  |  | int MultiMesh::get_visible_instance_count() const { | 
					
						
							|  |  |  | 	return visible_instance_count; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-17 01:08:21 -04:00
										 |  |  | void MultiMesh::set_instance_transform(int p_instance, const Transform3D &p_transform) { | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 	RenderingServer::get_singleton()->multimesh_instance_set_transform(multimesh, p_instance, p_transform); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-02-08 20:59:09 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | void MultiMesh::set_instance_transform_2d(int p_instance, const Transform2D &p_transform) { | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 	RenderingServer::get_singleton()->multimesh_instance_set_transform_2d(multimesh, p_instance, p_transform); | 
					
						
							| 
									
										
										
										
											2022-12-15 17:01:17 -08:00
										 |  |  | 	emit_changed(); | 
					
						
							| 
									
										
										
										
											2019-02-08 20:59:09 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-17 01:08:21 -04:00
										 |  |  | Transform3D MultiMesh::get_instance_transform(int p_instance) const { | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 	return RenderingServer::get_singleton()->multimesh_instance_get_transform(multimesh, p_instance); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-08 20:59:09 -08:00
										 |  |  | Transform2D MultiMesh::get_instance_transform_2d(int p_instance) const { | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 	return RenderingServer::get_singleton()->multimesh_instance_get_transform_2d(multimesh, p_instance); | 
					
						
							| 
									
										
										
										
											2019-02-08 20:59:09 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void MultiMesh::set_instance_color(int p_instance, const Color &p_color) { | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 	RenderingServer::get_singleton()->multimesh_instance_set_color(multimesh, p_instance, p_color); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | Color MultiMesh::get_instance_color(int p_instance) const { | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 	return RenderingServer::get_singleton()->multimesh_instance_get_color(multimesh, p_instance); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-05 19:14:39 -03:00
										 |  |  | void MultiMesh::set_instance_custom_data(int p_instance, const Color &p_custom_data) { | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 	RenderingServer::get_singleton()->multimesh_instance_set_custom_data(multimesh, p_instance, p_custom_data); | 
					
						
							| 
									
										
										
										
											2018-09-05 19:14:39 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-05 19:14:39 -03:00
										 |  |  | Color MultiMesh::get_instance_custom_data(int p_instance) const { | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 	return RenderingServer::get_singleton()->multimesh_instance_get_custom_data(multimesh, p_instance); | 
					
						
							| 
									
										
										
										
											2018-09-05 19:14:39 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-16 21:09:00 -05:00
										 |  |  | AABB MultiMesh::get_aabb() const { | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 	return RenderingServer::get_singleton()->multimesh_get_aabb(multimesh); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | RID MultiMesh::get_rid() const { | 
					
						
							|  |  |  | 	return multimesh; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-14 00:37:42 -03:00
										 |  |  | void MultiMesh::set_use_colors(bool p_enable) { | 
					
						
							| 
									
										
										
										
											2018-09-05 19:14:39 -03:00
										 |  |  | 	ERR_FAIL_COND(instance_count > 0); | 
					
						
							| 
									
										
										
										
											2019-09-14 00:37:42 -03:00
										 |  |  | 	use_colors = p_enable; | 
					
						
							| 
									
										
										
										
											2016-10-03 16:33:42 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-14 00:37:42 -03:00
										 |  |  | bool MultiMesh::is_using_colors() const { | 
					
						
							|  |  |  | 	return use_colors; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-14 00:37:42 -03:00
										 |  |  | void MultiMesh::set_use_custom_data(bool p_enable) { | 
					
						
							| 
									
										
										
										
											2018-09-05 19:14:39 -03:00
										 |  |  | 	ERR_FAIL_COND(instance_count > 0); | 
					
						
							| 
									
										
										
										
											2019-09-14 00:37:42 -03:00
										 |  |  | 	use_custom_data = p_enable; | 
					
						
							| 
									
										
										
										
											2018-09-05 19:14:39 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-14 00:37:42 -03:00
										 |  |  | bool MultiMesh::is_using_custom_data() const { | 
					
						
							|  |  |  | 	return use_custom_data; | 
					
						
							| 
									
										
										
										
											2018-09-05 19:14:39 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void MultiMesh::set_transform_format(TransformFormat p_transform_format) { | 
					
						
							| 
									
										
										
										
											2018-09-05 19:14:39 -03:00
										 |  |  | 	ERR_FAIL_COND(instance_count > 0); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	transform_format = p_transform_format; | 
					
						
							| 
									
										
										
										
											2016-10-03 16:33:42 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | MultiMesh::TransformFormat MultiMesh::get_transform_format() const { | 
					
						
							| 
									
										
										
										
											2016-10-03 16:33:42 -03:00
										 |  |  | 	return transform_format; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MultiMesh::_bind_methods() { | 
					
						
							| 
									
										
										
										
											2017-08-09 13:19:41 +02:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &MultiMesh::set_mesh); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_mesh"), &MultiMesh::get_mesh); | 
					
						
							| 
									
										
										
										
											2019-09-14 00:37:42 -03:00
										 |  |  | 	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); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	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); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_instance_count", "count"), &MultiMesh::set_instance_count); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_instance_count"), &MultiMesh::get_instance_count); | 
					
						
							| 
									
										
										
										
											2019-04-22 18:38:30 -03:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("set_visible_instance_count", "count"), &MultiMesh::set_visible_instance_count); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_visible_instance_count"), &MultiMesh::get_visible_instance_count); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("set_instance_transform", "instance", "transform"), &MultiMesh::set_instance_transform); | 
					
						
							| 
									
										
										
										
											2019-02-08 20:59:09 -08:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("set_instance_transform_2d", "instance", "transform"), &MultiMesh::set_instance_transform_2d); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("get_instance_transform", "instance"), &MultiMesh::get_instance_transform); | 
					
						
							| 
									
										
										
										
											2019-02-08 20:59:09 -08:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("get_instance_transform_2d", "instance"), &MultiMesh::get_instance_transform_2d); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("set_instance_color", "instance", "color"), &MultiMesh::set_instance_color); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_instance_color", "instance"), &MultiMesh::get_instance_color); | 
					
						
							| 
									
										
										
										
											2018-09-05 19:14:39 -03:00
										 |  |  | 	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); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("get_aabb"), &MultiMesh::get_aabb); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-14 00:37:42 -03:00
										 |  |  | 	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"); | 
					
						
							| 
									
										
										
											
												Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
											
										 
											2020-02-24 15:20:53 -03:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::PACKED_FLOAT32_ARRAY, "buffer", PROPERTY_HINT_NONE), "set_buffer", "get_buffer"); | 
					
						
							| 
									
										
										
										
											2019-09-14 00:37:42 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifndef DISABLE_DEPRECATED
 | 
					
						
							| 
									
										
										
										
											2020-02-13 11:37:37 +01:00
										 |  |  | 	// Kept for compatibility from 3.x to 4.0.
 | 
					
						
							| 
									
										
										
										
											2022-08-08 15:18:26 +03:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_set_transform_array", "array"), &MultiMesh::_set_transform_array); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_get_transform_array"), &MultiMesh::_get_transform_array); | 
					
						
							| 
									
										
										
										
											2022-08-08 15:18:26 +03:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_set_transform_2d_array", "array"), &MultiMesh::_set_transform_2d_array); | 
					
						
							| 
									
										
										
										
											2019-04-24 00:01:54 +10:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_get_transform_2d_array"), &MultiMesh::_get_transform_2d_array); | 
					
						
							| 
									
										
										
										
											2022-08-08 15:18:26 +03:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_set_color_array", "array"), &MultiMesh::_set_color_array); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_get_color_array"), &MultiMesh::_get_color_array); | 
					
						
							| 
									
										
										
										
											2022-08-08 15:18:26 +03:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_set_custom_data_array", "array"), &MultiMesh::_set_custom_data_array); | 
					
						
							| 
									
										
										
										
											2018-09-05 19:14:39 -03:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_get_custom_data_array"), &MultiMesh::_get_custom_data_array); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-17 19:10:18 -04:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR3_ARRAY, "transform_array", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "_set_transform_array", "_get_transform_array"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR2_ARRAY, "transform_2d_array", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "_set_transform_2d_array", "_get_transform_2d_array"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::PACKED_COLOR_ARRAY, "color_array", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "_set_color_array", "_get_color_array"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::PACKED_COLOR_ARRAY, "custom_data_array", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "_set_custom_data_array", "_get_custom_data_array"); | 
					
						
							| 
									
										
										
										
											2019-09-14 00:37:42 -03:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2020-02-13 11:37:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 17:45:01 +02:00
										 |  |  | 	BIND_ENUM_CONSTANT(TRANSFORM_2D); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(TRANSFORM_3D); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MultiMesh::MultiMesh() { | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 	multimesh = RenderingServer::get_singleton()->multimesh_create(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MultiMesh::~MultiMesh() { | 
					
						
							| 
									
										
										
										
											2022-12-12 12:42:37 -05:00
										 |  |  | 	ERR_FAIL_NULL(RenderingServer::get_singleton()); | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 	RenderingServer::get_singleton()->free(multimesh); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } |