rasterizer.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. /**************************************************************************/
  2. /* rasterizer.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "rasterizer.h"
  31. #include "core/os/os.h"
  32. #include "core/print_string.h"
  33. #if defined(DEBUG_ENABLED) && defined(TOOLS_ENABLED)
  34. #include "core/project_settings.h"
  35. #endif
  36. Rasterizer *(*Rasterizer::_create_func)() = nullptr;
  37. Rasterizer *Rasterizer::create() {
  38. return _create_func();
  39. }
  40. RasterizerStorage *RasterizerStorage::base_singleton = nullptr;
  41. RasterizerStorage::RasterizerStorage() {
  42. base_singleton = this;
  43. }
  44. bool RasterizerStorage::material_uses_tangents(RID p_material) {
  45. return false;
  46. }
  47. bool RasterizerStorage::material_uses_ensure_correct_normals(RID p_material) {
  48. return false;
  49. }
  50. void RasterizerStorage::InterpolationData::notify_free_multimesh(RID p_rid) {
  51. // print_line("free multimesh " + itos(p_rid.get_id()));
  52. // if the instance was on any of the lists, remove
  53. multimesh_interpolate_update_list.erase_multiple_unordered(p_rid);
  54. multimesh_transform_update_lists[0].erase_multiple_unordered(p_rid);
  55. multimesh_transform_update_lists[1].erase_multiple_unordered(p_rid);
  56. }
  57. void RasterizerStorage::update_interpolation_tick(bool p_process) {
  58. // detect any that were on the previous transform list that are no longer active,
  59. // we should remove them from the interpolate list
  60. for (unsigned int n = 0; n < _interpolation_data.multimesh_transform_update_list_prev->size(); n++) {
  61. const RID &rid = (*_interpolation_data.multimesh_transform_update_list_prev)[n];
  62. bool active = true;
  63. // no longer active? (either the instance deleted or no longer being transformed)
  64. MMInterpolator *mmi = _multimesh_get_interpolator(rid);
  65. if (mmi && !mmi->on_transform_update_list) {
  66. active = false;
  67. mmi->on_interpolate_update_list = false;
  68. // make sure the most recent transform is set
  69. // copy data rather than use Pool = function?
  70. mmi->_data_interpolated = mmi->_data_curr;
  71. // and that both prev and current are the same, just in case of any interpolations
  72. mmi->_data_prev = mmi->_data_curr;
  73. // make sure are updated one more time to ensure the AABBs are correct
  74. //_instance_queue_update(instance, true);
  75. }
  76. if (!mmi) {
  77. active = false;
  78. }
  79. if (!active) {
  80. _interpolation_data.multimesh_interpolate_update_list.erase(rid);
  81. }
  82. }
  83. if (p_process) {
  84. for (unsigned int i = 0; i < _interpolation_data.multimesh_transform_update_list_curr->size(); i++) {
  85. const RID &rid = (*_interpolation_data.multimesh_transform_update_list_curr)[i];
  86. MMInterpolator *mmi = _multimesh_get_interpolator(rid);
  87. if (mmi) {
  88. // reset for next tick
  89. mmi->on_transform_update_list = false;
  90. mmi->_data_prev = mmi->_data_curr;
  91. }
  92. } // for n
  93. }
  94. // if any have left the transform list, remove from the interpolate list
  95. // we maintain a mirror list for the transform updates, so we can detect when an instance
  96. // is no longer being transformed, and remove it from the interpolate list
  97. SWAP(_interpolation_data.multimesh_transform_update_list_curr, _interpolation_data.multimesh_transform_update_list_prev);
  98. // prepare for the next iteration
  99. _interpolation_data.multimesh_transform_update_list_curr->clear();
  100. }
  101. void RasterizerStorage::update_interpolation_frame(bool p_process) {
  102. if (p_process) {
  103. // Only need 32 bit for interpolation, don't use real_t
  104. float f = Engine::get_singleton()->get_physics_interpolation_fraction();
  105. for (unsigned int c = 0; c < _interpolation_data.multimesh_interpolate_update_list.size(); c++) {
  106. const RID &rid = _interpolation_data.multimesh_interpolate_update_list[c];
  107. // We could use the TransformInterpolator here to slerp transforms, but that might be too expensive,
  108. // so just using a Basis lerp for now.
  109. MMInterpolator *mmi = _multimesh_get_interpolator(rid);
  110. if (mmi) {
  111. // make sure arrays are correct size
  112. DEV_ASSERT(mmi->_data_prev.size() == mmi->_data_curr.size());
  113. if (mmi->_data_interpolated.size() < mmi->_data_curr.size()) {
  114. mmi->_data_interpolated.resize(mmi->_data_curr.size());
  115. }
  116. DEV_ASSERT(mmi->_data_interpolated.size() >= mmi->_data_curr.size());
  117. DEV_ASSERT((mmi->_data_curr.size() % mmi->_stride) == 0);
  118. int num = mmi->_data_curr.size() / mmi->_stride;
  119. PoolVector<float>::Read r_prev = mmi->_data_prev.read();
  120. PoolVector<float>::Read r_curr = mmi->_data_curr.read();
  121. PoolVector<float>::Write w = mmi->_data_interpolated.write();
  122. const float *pf_prev = r_prev.ptr();
  123. const float *pf_curr = r_curr.ptr();
  124. float *pf_int = w.ptr();
  125. bool use_lerp = mmi->quality == 0;
  126. // temporary transform (needed for swizzling)
  127. // (transform prev, curr and result)
  128. Transform tp, tc, tr;
  129. // Test for cache friendliness versus doing branchless
  130. for (int n = 0; n < num; n++) {
  131. // Transform
  132. if (use_lerp) {
  133. for (int i = 0; i < mmi->_vf_size_xform; i++) {
  134. float a = pf_prev[i];
  135. float b = pf_curr[i];
  136. pf_int[i] = (a + ((b - a) * f));
  137. }
  138. } else {
  139. // Silly swizzling, this will slow things down. no idea why it is using this format
  140. // .. maybe due to the shader.
  141. tp.basis.elements[0][0] = pf_prev[0];
  142. tp.basis.elements[0][1] = pf_prev[1];
  143. tp.basis.elements[0][2] = pf_prev[2];
  144. tp.basis.elements[1][0] = pf_prev[4];
  145. tp.basis.elements[1][1] = pf_prev[5];
  146. tp.basis.elements[1][2] = pf_prev[6];
  147. tp.basis.elements[2][0] = pf_prev[8];
  148. tp.basis.elements[2][1] = pf_prev[9];
  149. tp.basis.elements[2][2] = pf_prev[10];
  150. tp.origin.x = pf_prev[3];
  151. tp.origin.y = pf_prev[7];
  152. tp.origin.z = pf_prev[11];
  153. tc.basis.elements[0][0] = pf_curr[0];
  154. tc.basis.elements[0][1] = pf_curr[1];
  155. tc.basis.elements[0][2] = pf_curr[2];
  156. tc.basis.elements[1][0] = pf_curr[4];
  157. tc.basis.elements[1][1] = pf_curr[5];
  158. tc.basis.elements[1][2] = pf_curr[6];
  159. tc.basis.elements[2][0] = pf_curr[8];
  160. tc.basis.elements[2][1] = pf_curr[9];
  161. tc.basis.elements[2][2] = pf_curr[10];
  162. tc.origin.x = pf_curr[3];
  163. tc.origin.y = pf_curr[7];
  164. tc.origin.z = pf_curr[11];
  165. TransformInterpolator::interpolate_transform(tp, tc, tr, f);
  166. pf_int[0] = tr.basis.elements[0][0];
  167. pf_int[1] = tr.basis.elements[0][1];
  168. pf_int[2] = tr.basis.elements[0][2];
  169. pf_int[4] = tr.basis.elements[1][0];
  170. pf_int[5] = tr.basis.elements[1][1];
  171. pf_int[6] = tr.basis.elements[1][2];
  172. pf_int[8] = tr.basis.elements[2][0];
  173. pf_int[9] = tr.basis.elements[2][1];
  174. pf_int[10] = tr.basis.elements[2][2];
  175. pf_int[3] = tr.origin.x;
  176. pf_int[7] = tr.origin.y;
  177. pf_int[11] = tr.origin.z;
  178. }
  179. pf_prev += mmi->_vf_size_xform;
  180. pf_curr += mmi->_vf_size_xform;
  181. pf_int += mmi->_vf_size_xform;
  182. // Color
  183. if (mmi->_vf_size_color == 1) {
  184. const uint8_t *p8_prev = (const uint8_t *)pf_prev;
  185. const uint8_t *p8_curr = (const uint8_t *)pf_curr;
  186. uint8_t *p8_int = (uint8_t *)pf_int;
  187. _interpolate_RGBA8(p8_prev, p8_curr, p8_int, f);
  188. pf_prev += 1;
  189. pf_curr += 1;
  190. pf_int += 1;
  191. } else if (mmi->_vf_size_color == 4) {
  192. for (int i = 0; i < 4; i++) {
  193. pf_int[i] = pf_prev[i] + ((pf_curr[i] - pf_prev[i]) * f);
  194. }
  195. pf_prev += 4;
  196. pf_curr += 4;
  197. pf_int += 4;
  198. }
  199. // Custom Data
  200. if (mmi->_vf_size_data == 1) {
  201. const uint8_t *p8_prev = (const uint8_t *)pf_prev;
  202. const uint8_t *p8_curr = (const uint8_t *)pf_curr;
  203. uint8_t *p8_int = (uint8_t *)pf_int;
  204. _interpolate_RGBA8(p8_prev, p8_curr, p8_int, f);
  205. pf_prev += 1;
  206. pf_curr += 1;
  207. pf_int += 1;
  208. } else if (mmi->_vf_size_data == 4) {
  209. for (int i = 0; i < 4; i++) {
  210. pf_int[i] = pf_prev[i] + ((pf_curr[i] - pf_prev[i]) * f);
  211. }
  212. pf_prev += 4;
  213. pf_curr += 4;
  214. pf_int += 4;
  215. }
  216. }
  217. _multimesh_set_as_bulk_array(rid, mmi->_data_interpolated);
  218. // make sure AABBs are constantly up to date through the interpolation?
  219. // NYI
  220. }
  221. } // for n
  222. }
  223. }
  224. RID RasterizerStorage::multimesh_create() {
  225. return _multimesh_create();
  226. }
  227. void RasterizerStorage::multimesh_allocate(RID p_multimesh, int p_instances, VS::MultimeshTransformFormat p_transform_format, VS::MultimeshColorFormat p_color_format, VS::MultimeshCustomDataFormat p_data) {
  228. MMInterpolator *mmi = _multimesh_get_interpolator(p_multimesh);
  229. if (mmi) {
  230. mmi->_transform_format = p_transform_format;
  231. mmi->_color_format = p_color_format;
  232. mmi->_data_format = p_data;
  233. mmi->_num_instances = p_instances;
  234. mmi->_vf_size_xform = p_transform_format == VS::MULTIMESH_TRANSFORM_3D ? 12 : 8;
  235. switch (p_color_format) {
  236. default: {
  237. mmi->_vf_size_color = 0;
  238. } break;
  239. case VS::MULTIMESH_COLOR_8BIT: {
  240. mmi->_vf_size_color = 1;
  241. } break;
  242. case VS::MULTIMESH_COLOR_FLOAT: {
  243. mmi->_vf_size_color = 4;
  244. } break;
  245. }
  246. switch (p_data) {
  247. default: {
  248. mmi->_vf_size_data = 0;
  249. } break;
  250. case VS::MULTIMESH_CUSTOM_DATA_8BIT: {
  251. mmi->_vf_size_data = 1;
  252. } break;
  253. case VS::MULTIMESH_CUSTOM_DATA_FLOAT: {
  254. mmi->_vf_size_data = 4;
  255. } break;
  256. }
  257. mmi->_stride = mmi->_vf_size_xform + mmi->_vf_size_color + mmi->_vf_size_data;
  258. int size_in_floats = p_instances * mmi->_stride;
  259. mmi->_data_curr.resize(size_in_floats);
  260. mmi->_data_prev.resize(size_in_floats);
  261. mmi->_data_interpolated.resize(size_in_floats);
  262. }
  263. return _multimesh_allocate(p_multimesh, p_instances, p_transform_format, p_color_format, p_data);
  264. }
  265. int RasterizerStorage::multimesh_get_instance_count(RID p_multimesh) const {
  266. return _multimesh_get_instance_count(p_multimesh);
  267. }
  268. void RasterizerStorage::multimesh_set_mesh(RID p_multimesh, RID p_mesh) {
  269. _multimesh_set_mesh(p_multimesh, p_mesh);
  270. }
  271. void RasterizerStorage::multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform &p_transform) {
  272. MMInterpolator *mmi = _multimesh_get_interpolator(p_multimesh);
  273. if (mmi) {
  274. if (mmi->interpolated) {
  275. ERR_FAIL_COND(p_index >= mmi->_num_instances);
  276. ERR_FAIL_COND(mmi->_vf_size_xform != 12);
  277. PoolVector<float>::Write w = mmi->_data_curr.write();
  278. int start = p_index * mmi->_stride;
  279. float *ptr = w.ptr();
  280. ptr += start;
  281. const Transform &t = p_transform;
  282. ptr[0] = t.basis.elements[0][0];
  283. ptr[1] = t.basis.elements[0][1];
  284. ptr[2] = t.basis.elements[0][2];
  285. ptr[3] = t.origin.x;
  286. ptr[4] = t.basis.elements[1][0];
  287. ptr[5] = t.basis.elements[1][1];
  288. ptr[6] = t.basis.elements[1][2];
  289. ptr[7] = t.origin.y;
  290. ptr[8] = t.basis.elements[2][0];
  291. ptr[9] = t.basis.elements[2][1];
  292. ptr[10] = t.basis.elements[2][2];
  293. ptr[11] = t.origin.z;
  294. _multimesh_add_to_interpolation_lists(p_multimesh, *mmi);
  295. #if defined(DEBUG_ENABLED) && defined(TOOLS_ENABLED)
  296. if (!Engine::get_singleton()->is_in_physics_frame()) {
  297. static int32_t warn_count = 0;
  298. warn_count++;
  299. if (((warn_count % 2048) == 0) && GLOBAL_GET("debug/settings/physics_interpolation/enable_warnings")) {
  300. WARN_PRINT("[Physics interpolation] MultiMesh interpolation is being triggered from outside physics process, this might lead to issues (possibly benign).");
  301. }
  302. }
  303. #endif
  304. return;
  305. }
  306. }
  307. _multimesh_instance_set_transform(p_multimesh, p_index, p_transform);
  308. }
  309. void RasterizerStorage::multimesh_instance_set_transform_2d(RID p_multimesh, int p_index, const Transform2D &p_transform) {
  310. _multimesh_instance_set_transform_2d(p_multimesh, p_index, p_transform);
  311. }
  312. void RasterizerStorage::multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color) {
  313. MMInterpolator *mmi = _multimesh_get_interpolator(p_multimesh);
  314. if (mmi) {
  315. if (mmi->interpolated) {
  316. ERR_FAIL_COND(p_index >= mmi->_num_instances);
  317. ERR_FAIL_COND(mmi->_vf_size_color == 0);
  318. PoolVector<float>::Write w = mmi->_data_curr.write();
  319. int start = (p_index * mmi->_stride) + mmi->_vf_size_xform;
  320. float *ptr = w.ptr();
  321. ptr += start;
  322. if (mmi->_vf_size_color == 4) {
  323. for (int n = 0; n < 4; n++) {
  324. ptr[n] = p_color.components[n];
  325. }
  326. } else {
  327. #ifdef DEV_ENABLED
  328. // The options are currently 4, 1, or zero, but just in case this changes in future...
  329. ERR_FAIL_COND(mmi->_vf_size_color != 1);
  330. #endif
  331. uint32_t *pui = (uint32_t *)ptr;
  332. *pui = p_color.to_rgba32();
  333. }
  334. _multimesh_add_to_interpolation_lists(p_multimesh, *mmi);
  335. return;
  336. }
  337. }
  338. _multimesh_instance_set_color(p_multimesh, p_index, p_color);
  339. }
  340. void RasterizerStorage::multimesh_instance_set_custom_data(RID p_multimesh, int p_index, const Color &p_color) {
  341. MMInterpolator *mmi = _multimesh_get_interpolator(p_multimesh);
  342. if (mmi) {
  343. if (mmi->interpolated) {
  344. ERR_FAIL_COND(p_index >= mmi->_num_instances);
  345. ERR_FAIL_COND(mmi->_vf_size_data == 0);
  346. PoolVector<float>::Write w = mmi->_data_curr.write();
  347. int start = (p_index * mmi->_stride) + mmi->_vf_size_xform + mmi->_vf_size_color;
  348. float *ptr = w.ptr();
  349. ptr += start;
  350. if (mmi->_vf_size_data == 4) {
  351. for (int n = 0; n < 4; n++) {
  352. ptr[n] = p_color.components[n];
  353. }
  354. } else {
  355. #ifdef DEV_ENABLED
  356. // The options are currently 4, 1, or zero, but just in case this changes in future...
  357. ERR_FAIL_COND(mmi->_vf_size_data != 1);
  358. #endif
  359. uint32_t *pui = (uint32_t *)ptr;
  360. *pui = p_color.to_rgba32();
  361. }
  362. _multimesh_add_to_interpolation_lists(p_multimesh, *mmi);
  363. return;
  364. }
  365. }
  366. _multimesh_instance_set_custom_data(p_multimesh, p_index, p_color);
  367. }
  368. RID RasterizerStorage::multimesh_get_mesh(RID p_multimesh) const {
  369. return _multimesh_get_mesh(p_multimesh);
  370. }
  371. Transform RasterizerStorage::multimesh_instance_get_transform(RID p_multimesh, int p_index) const {
  372. return _multimesh_instance_get_transform(p_multimesh, p_index);
  373. }
  374. Transform2D RasterizerStorage::multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const {
  375. return _multimesh_instance_get_transform_2d(p_multimesh, p_index);
  376. }
  377. Color RasterizerStorage::multimesh_instance_get_color(RID p_multimesh, int p_index) const {
  378. return _multimesh_instance_get_color(p_multimesh, p_index);
  379. }
  380. Color RasterizerStorage::multimesh_instance_get_custom_data(RID p_multimesh, int p_index) const {
  381. return _multimesh_instance_get_custom_data(p_multimesh, p_index);
  382. }
  383. void RasterizerStorage::multimesh_set_physics_interpolated(RID p_multimesh, bool p_interpolated) {
  384. MMInterpolator *mmi = _multimesh_get_interpolator(p_multimesh);
  385. if (mmi) {
  386. mmi->interpolated = p_interpolated;
  387. }
  388. }
  389. void RasterizerStorage::multimesh_set_physics_interpolation_quality(RID p_multimesh, int p_quality) {
  390. ERR_FAIL_COND((p_quality < 0) || (p_quality > 1));
  391. MMInterpolator *mmi = _multimesh_get_interpolator(p_multimesh);
  392. if (mmi) {
  393. mmi->quality = p_quality;
  394. }
  395. }
  396. void RasterizerStorage::multimesh_instance_reset_physics_interpolation(RID p_multimesh, int p_index) {
  397. MMInterpolator *mmi = _multimesh_get_interpolator(p_multimesh);
  398. if (mmi) {
  399. ERR_FAIL_INDEX(p_index, mmi->_num_instances);
  400. PoolVector<float>::Write w = mmi->_data_prev.write();
  401. PoolVector<float>::Read r = mmi->_data_curr.read();
  402. int start = p_index * mmi->_stride;
  403. for (int n = 0; n < mmi->_stride; n++) {
  404. w[start + n] = r[start + n];
  405. }
  406. }
  407. }
  408. void RasterizerStorage::_multimesh_add_to_interpolation_lists(RID p_multimesh, MMInterpolator &r_mmi) {
  409. if (!r_mmi.on_interpolate_update_list) {
  410. r_mmi.on_interpolate_update_list = true;
  411. _interpolation_data.multimesh_interpolate_update_list.push_back(p_multimesh);
  412. }
  413. if (!r_mmi.on_transform_update_list) {
  414. r_mmi.on_transform_update_list = true;
  415. _interpolation_data.multimesh_transform_update_list_curr->push_back(p_multimesh);
  416. }
  417. }
  418. void RasterizerStorage::multimesh_set_as_bulk_array_interpolated(RID p_multimesh, const PoolVector<float> &p_array, const PoolVector<float> &p_array_prev) {
  419. MMInterpolator *mmi = _multimesh_get_interpolator(p_multimesh);
  420. if (mmi) {
  421. ERR_FAIL_COND_MSG(p_array.size() != mmi->_data_curr.size(), vformat("Array for current frame should have %d elements, got %d instead.", mmi->_data_curr.size(), p_array.size()));
  422. ERR_FAIL_COND_MSG(p_array_prev.size() != mmi->_data_prev.size(), vformat("Array for previous frame should have %d elements, got %d instead.", mmi->_data_prev.size(), p_array_prev.size()));
  423. // We are assuming that mmi->interpolated is the case,
  424. // (can possibly assert this?)
  425. // even if this flag hasn't been set - just calling this function suggests
  426. // interpolation is desired.
  427. mmi->_data_prev = p_array_prev;
  428. mmi->_data_curr = p_array;
  429. _multimesh_add_to_interpolation_lists(p_multimesh, *mmi);
  430. #if defined(DEBUG_ENABLED) && defined(TOOLS_ENABLED)
  431. if (!Engine::get_singleton()->is_in_physics_frame()) {
  432. static int32_t warn_count = 0;
  433. warn_count++;
  434. if (((warn_count % 2048) == 0) && GLOBAL_GET("debug/settings/physics_interpolation/enable_warnings")) {
  435. WARN_PRINT("[Physics interpolation] MultiMesh interpolation is being triggered from outside physics process, this might lead to issues (possibly benign).");
  436. }
  437. }
  438. #endif
  439. }
  440. }
  441. void RasterizerStorage::multimesh_set_as_bulk_array(RID p_multimesh, const PoolVector<float> &p_array) {
  442. MMInterpolator *mmi = _multimesh_get_interpolator(p_multimesh);
  443. if (mmi) {
  444. if (mmi->interpolated) {
  445. ERR_FAIL_COND_MSG(p_array.size() != mmi->_data_curr.size(), vformat("Array should have %d elements, got %d instead.", mmi->_data_curr.size(), p_array.size()));
  446. mmi->_data_curr = p_array;
  447. _multimesh_add_to_interpolation_lists(p_multimesh, *mmi);
  448. #if defined(DEBUG_ENABLED) && defined(TOOLS_ENABLED)
  449. if (!Engine::get_singleton()->is_in_physics_frame()) {
  450. static int32_t warn_count = 0;
  451. warn_count++;
  452. if (((warn_count % 2048) == 0) && GLOBAL_GET("debug/settings/physics_interpolation/enable_warnings")) {
  453. WARN_PRINT("[Physics interpolation] MultiMesh interpolation is being triggered from outside physics process, this might lead to issues (possibly benign).");
  454. }
  455. }
  456. #endif
  457. return;
  458. }
  459. }
  460. _multimesh_set_as_bulk_array(p_multimesh, p_array);
  461. }
  462. void RasterizerStorage::multimesh_set_visible_instances(RID p_multimesh, int p_visible) {
  463. _multimesh_set_visible_instances(p_multimesh, p_visible);
  464. }
  465. int RasterizerStorage::multimesh_get_visible_instances(RID p_multimesh) const {
  466. return _multimesh_get_visible_instances(p_multimesh);
  467. }
  468. AABB RasterizerStorage::multimesh_get_aabb(RID p_multimesh) const {
  469. return _multimesh_get_aabb(p_multimesh);
  470. }