visual_server.cpp 119 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610
  1. /*************************************************************************/
  2. /* visual_server.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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 "visual_server.h"
  31. #include "core/method_bind_ext.gen.inc"
  32. #include "core/project_settings.h"
  33. VisualServer *VisualServer::singleton = nullptr;
  34. VisualServer *(*VisualServer::create_func)() = nullptr;
  35. VisualServer *VisualServer::get_singleton() {
  36. return singleton;
  37. }
  38. VisualServer *VisualServer::create() {
  39. ERR_FAIL_COND_V(singleton, nullptr);
  40. if (create_func) {
  41. return create_func();
  42. }
  43. return nullptr;
  44. }
  45. RID VisualServer::texture_create_from_image(const Ref<Image> &p_image, uint32_t p_flags) {
  46. ERR_FAIL_COND_V(!p_image.is_valid(), RID());
  47. RID texture = texture_create();
  48. texture_allocate(texture, p_image->get_width(), p_image->get_height(), 0, p_image->get_format(), VS::TEXTURE_TYPE_2D, p_flags); //if it has mipmaps, use, else generate
  49. ERR_FAIL_COND_V(!texture.is_valid(), texture);
  50. texture_set_data(texture, p_image);
  51. return texture;
  52. }
  53. Array VisualServer::_texture_debug_usage_bind() {
  54. List<TextureInfo> list;
  55. texture_debug_usage(&list);
  56. Array arr;
  57. for (const List<TextureInfo>::Element *E = list.front(); E; E = E->next()) {
  58. Dictionary dict;
  59. dict["texture"] = E->get().texture;
  60. dict["width"] = E->get().width;
  61. dict["height"] = E->get().height;
  62. dict["depth"] = E->get().depth;
  63. dict["format"] = E->get().format;
  64. dict["bytes"] = E->get().bytes;
  65. dict["path"] = E->get().path;
  66. arr.push_back(dict);
  67. }
  68. return arr;
  69. }
  70. Array VisualServer::_shader_get_param_list_bind(RID p_shader) const {
  71. List<PropertyInfo> l;
  72. shader_get_param_list(p_shader, &l);
  73. return convert_property_list(&l);
  74. }
  75. static Array to_array(const Vector<ObjectID> &ids) {
  76. Array a;
  77. a.resize(ids.size());
  78. for (int i = 0; i < ids.size(); ++i) {
  79. a[i] = ids[i];
  80. }
  81. return a;
  82. }
  83. Array VisualServer::_instances_cull_aabb_bind(const AABB &p_aabb, RID p_scenario) const {
  84. Vector<ObjectID> ids = instances_cull_aabb(p_aabb, p_scenario);
  85. return to_array(ids);
  86. }
  87. Array VisualServer::_instances_cull_ray_bind(const Vector3 &p_from, const Vector3 &p_to, RID p_scenario) const {
  88. Vector<ObjectID> ids = instances_cull_ray(p_from, p_to, p_scenario);
  89. return to_array(ids);
  90. }
  91. Array VisualServer::_instances_cull_convex_bind(const Array &p_convex, RID p_scenario) const {
  92. Vector<Plane> planes;
  93. for (int i = 0; i < p_convex.size(); ++i) {
  94. Variant v = p_convex[i];
  95. ERR_FAIL_COND_V(v.get_type() != Variant::PLANE, Array());
  96. planes.push_back(v);
  97. }
  98. Vector<ObjectID> ids = instances_cull_convex(planes, p_scenario);
  99. return to_array(ids);
  100. }
  101. RID VisualServer::get_test_texture() {
  102. if (test_texture.is_valid()) {
  103. return test_texture;
  104. };
  105. #define TEST_TEXTURE_SIZE 256
  106. PoolVector<uint8_t> test_data;
  107. test_data.resize(TEST_TEXTURE_SIZE * TEST_TEXTURE_SIZE * 3);
  108. {
  109. PoolVector<uint8_t>::Write w = test_data.write();
  110. for (int x = 0; x < TEST_TEXTURE_SIZE; x++) {
  111. for (int y = 0; y < TEST_TEXTURE_SIZE; y++) {
  112. Color c;
  113. int r = 255 - (x + y) / 2;
  114. if ((x % (TEST_TEXTURE_SIZE / 8)) < 2 || (y % (TEST_TEXTURE_SIZE / 8)) < 2) {
  115. c.r = y;
  116. c.g = r;
  117. c.b = x;
  118. } else {
  119. c.r = r;
  120. c.g = x;
  121. c.b = y;
  122. }
  123. w[(y * TEST_TEXTURE_SIZE + x) * 3 + 0] = uint8_t(CLAMP(c.r * 255, 0, 255));
  124. w[(y * TEST_TEXTURE_SIZE + x) * 3 + 1] = uint8_t(CLAMP(c.g * 255, 0, 255));
  125. w[(y * TEST_TEXTURE_SIZE + x) * 3 + 2] = uint8_t(CLAMP(c.b * 255, 0, 255));
  126. }
  127. }
  128. }
  129. Ref<Image> data = memnew(Image(TEST_TEXTURE_SIZE, TEST_TEXTURE_SIZE, false, Image::FORMAT_RGB8, test_data));
  130. test_texture = texture_create_from_image(data);
  131. return test_texture;
  132. }
  133. void VisualServer::_free_internal_rids() {
  134. if (test_texture.is_valid()) {
  135. free(test_texture);
  136. }
  137. if (white_texture.is_valid()) {
  138. free(white_texture);
  139. }
  140. if (test_material.is_valid()) {
  141. free(test_material);
  142. }
  143. }
  144. RID VisualServer::_make_test_cube() {
  145. PoolVector<Vector3> vertices;
  146. PoolVector<Vector3> normals;
  147. PoolVector<float> tangents;
  148. PoolVector<Vector3> uvs;
  149. #define ADD_VTX(m_idx) \
  150. vertices.push_back(face_points[m_idx]); \
  151. normals.push_back(normal_points[m_idx]); \
  152. tangents.push_back(normal_points[m_idx][1]); \
  153. tangents.push_back(normal_points[m_idx][2]); \
  154. tangents.push_back(normal_points[m_idx][0]); \
  155. tangents.push_back(1.0); \
  156. uvs.push_back(Vector3(uv_points[m_idx * 2 + 0], uv_points[m_idx * 2 + 1], 0));
  157. for (int i = 0; i < 6; i++) {
  158. Vector3 face_points[4];
  159. Vector3 normal_points[4];
  160. float uv_points[8] = { 0, 0, 0, 1, 1, 1, 1, 0 };
  161. for (int j = 0; j < 4; j++) {
  162. float v[3];
  163. v[0] = 1.0;
  164. v[1] = 1 - 2 * ((j >> 1) & 1);
  165. v[2] = v[1] * (1 - 2 * (j & 1));
  166. for (int k = 0; k < 3; k++) {
  167. if (i < 3) {
  168. face_points[j][(i + k) % 3] = v[k];
  169. } else {
  170. face_points[3 - j][(i + k) % 3] = -v[k];
  171. }
  172. }
  173. normal_points[j] = Vector3();
  174. normal_points[j][i % 3] = (i >= 3 ? -1 : 1);
  175. }
  176. //tri 1
  177. ADD_VTX(0);
  178. ADD_VTX(1);
  179. ADD_VTX(2);
  180. //tri 2
  181. ADD_VTX(2);
  182. ADD_VTX(3);
  183. ADD_VTX(0);
  184. }
  185. RID test_cube = mesh_create();
  186. Array d;
  187. d.resize(VS::ARRAY_MAX);
  188. d[VisualServer::ARRAY_NORMAL] = normals;
  189. d[VisualServer::ARRAY_TANGENT] = tangents;
  190. d[VisualServer::ARRAY_TEX_UV] = uvs;
  191. d[VisualServer::ARRAY_VERTEX] = vertices;
  192. PoolVector<int> indices;
  193. indices.resize(vertices.size());
  194. for (int i = 0; i < vertices.size(); i++) {
  195. indices.set(i, i);
  196. }
  197. d[VisualServer::ARRAY_INDEX] = indices;
  198. mesh_add_surface_from_arrays(test_cube, PRIMITIVE_TRIANGLES, d);
  199. /*
  200. test_material = fixed_material_create();
  201. //material_set_flag(material, MATERIAL_FLAG_BILLBOARD_TOGGLE,true);
  202. fixed_material_set_texture( test_material, FIXED_MATERIAL_PARAM_DIFFUSE, get_test_texture() );
  203. fixed_material_set_param( test_material, FIXED_MATERIAL_PARAM_SPECULAR_EXP, 70 );
  204. fixed_material_set_param( test_material, FIXED_MATERIAL_PARAM_EMISSION, Color(0.2,0.2,0.2) );
  205. fixed_material_set_param( test_material, FIXED_MATERIAL_PARAM_DIFFUSE, Color(1, 1, 1) );
  206. fixed_material_set_param( test_material, FIXED_MATERIAL_PARAM_SPECULAR, Color(1,1,1) );
  207. */
  208. mesh_surface_set_material(test_cube, 0, test_material);
  209. return test_cube;
  210. }
  211. RID VisualServer::make_sphere_mesh(int p_lats, int p_lons, float p_radius) {
  212. PoolVector<Vector3> vertices;
  213. PoolVector<Vector3> normals;
  214. for (int i = 1; i <= p_lats; i++) {
  215. double lat0 = Math_PI * (-0.5 + (double)(i - 1) / p_lats);
  216. double z0 = Math::sin(lat0);
  217. double zr0 = Math::cos(lat0);
  218. double lat1 = Math_PI * (-0.5 + (double)i / p_lats);
  219. double z1 = Math::sin(lat1);
  220. double zr1 = Math::cos(lat1);
  221. for (int j = p_lons; j >= 1; j--) {
  222. double lng0 = 2 * Math_PI * (double)(j - 1) / p_lons;
  223. double x0 = Math::cos(lng0);
  224. double y0 = Math::sin(lng0);
  225. double lng1 = 2 * Math_PI * (double)(j) / p_lons;
  226. double x1 = Math::cos(lng1);
  227. double y1 = Math::sin(lng1);
  228. Vector3 v[4] = {
  229. Vector3(x1 * zr0, z0, y1 * zr0),
  230. Vector3(x1 * zr1, z1, y1 * zr1),
  231. Vector3(x0 * zr1, z1, y0 * zr1),
  232. Vector3(x0 * zr0, z0, y0 * zr0)
  233. };
  234. #define ADD_POINT(m_idx) \
  235. normals.push_back(v[m_idx]); \
  236. vertices.push_back(v[m_idx] * p_radius);
  237. ADD_POINT(0);
  238. ADD_POINT(1);
  239. ADD_POINT(2);
  240. ADD_POINT(2);
  241. ADD_POINT(3);
  242. ADD_POINT(0);
  243. }
  244. }
  245. RID mesh = mesh_create();
  246. Array d;
  247. d.resize(VS::ARRAY_MAX);
  248. d[ARRAY_VERTEX] = vertices;
  249. d[ARRAY_NORMAL] = normals;
  250. mesh_add_surface_from_arrays(mesh, PRIMITIVE_TRIANGLES, d);
  251. return mesh;
  252. }
  253. RID VisualServer::get_white_texture() {
  254. if (white_texture.is_valid()) {
  255. return white_texture;
  256. }
  257. PoolVector<uint8_t> wt;
  258. wt.resize(16 * 3);
  259. {
  260. PoolVector<uint8_t>::Write w = wt.write();
  261. for (int i = 0; i < 16 * 3; i++) {
  262. w[i] = 255;
  263. }
  264. }
  265. Ref<Image> white = memnew(Image(4, 4, 0, Image::FORMAT_RGB8, wt));
  266. white_texture = texture_create();
  267. texture_allocate(white_texture, 4, 4, 0, Image::FORMAT_RGB8, TEXTURE_TYPE_2D);
  268. texture_set_data(white_texture, white);
  269. return white_texture;
  270. }
  271. #define SMALL_VEC2 Vector2(0.00001, 0.00001)
  272. #define SMALL_VEC3 Vector3(0.00001, 0.00001, 0.00001)
  273. // Maps normalized vector to an octohedron projected onto the cartesian plane
  274. // Resulting 2D vector in range [-1, 1]
  275. // See http://jcgt.org/published/0003/02/01/ for details
  276. Vector2 VisualServer::norm_to_oct(const Vector3 v) {
  277. const float invL1Norm = (1.0f) / (Math::absf(v.x) + Math::absf(v.y) + Math::absf(v.z));
  278. Vector2 res;
  279. if (v.z < 0.0f) {
  280. res.x = (1.0f - Math::absf(v.y * invL1Norm)) * SGN(v.x);
  281. res.y = (1.0f - Math::absf(v.x * invL1Norm)) * SGN(v.y);
  282. } else {
  283. res.x = v.x * invL1Norm;
  284. res.y = v.y * invL1Norm;
  285. }
  286. return res;
  287. }
  288. // Maps normalized tangent vector to an octahedron projected onto the cartesian plane
  289. // Encodes the tangent vector sign in the second componenet of the returned Vector2 for use in shaders
  290. // high_precision specifies whether the encoding will be 32 bit (true) or 16 bit (false)
  291. // Resulting 2D vector in range [-1, 1]
  292. // See http://jcgt.org/published/0003/02/01/ for details
  293. Vector2 VisualServer::tangent_to_oct(const Vector3 v, const float sign, const bool high_precision) {
  294. float bias = high_precision ? 1.0f / 32767 : 1.0f / 127;
  295. Vector2 res = norm_to_oct(v);
  296. res.y = res.y * 0.5f + 0.5f;
  297. res.y = MAX(res.y, bias) * SGN(sign);
  298. return res;
  299. }
  300. // Convert Octohedron-mapped normalized vector back to Cartesian
  301. // Assumes normalized format (elements of v within range [-1, 1])
  302. Vector3 VisualServer::oct_to_norm(const Vector2 v) {
  303. Vector3 res(v.x, v.y, 1 - (Math::absf(v.x) + Math::absf(v.y)));
  304. float t = MAX(-res.z, 0.0f);
  305. res.x += t * -SGN(res.x);
  306. res.y += t * -SGN(res.y);
  307. return res;
  308. }
  309. // Convert Octohedron-mapped normalized tangent vector back to Cartesian
  310. // out_sign provides the direction for the original cartesian tangent
  311. // Assumes normalized format (elements of v within range [-1, 1])
  312. Vector3 VisualServer::oct_to_tangent(const Vector2 v, float *out_sign) {
  313. Vector2 v_decompressed = v;
  314. v_decompressed.y = Math::absf(v_decompressed.y) * 2 - 1;
  315. Vector3 res = oct_to_norm(v_decompressed);
  316. *out_sign = SGN(v[1]);
  317. return res;
  318. }
  319. Error VisualServer::_surface_set_data(Array p_arrays, uint32_t p_format, uint32_t *p_offsets, uint32_t *p_stride, PoolVector<uint8_t> &r_vertex_array, int p_vertex_array_len, PoolVector<uint8_t> &r_index_array, int p_index_array_len, AABB &r_aabb, Vector<AABB> &r_bone_aabb) {
  320. PoolVector<uint8_t>::Write vw = r_vertex_array.write();
  321. PoolVector<uint8_t>::Write iw;
  322. if (r_index_array.size()) {
  323. iw = r_index_array.write();
  324. }
  325. int max_bone = 0;
  326. for (int ai = 0; ai < VS::ARRAY_MAX; ai++) {
  327. if (!(p_format & (1 << ai))) { // no array
  328. continue;
  329. }
  330. switch (ai) {
  331. case VS::ARRAY_VERTEX: {
  332. if (p_format & VS::ARRAY_FLAG_USE_2D_VERTICES) {
  333. PoolVector<Vector2> array = p_arrays[ai];
  334. ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
  335. PoolVector<Vector2>::Read read = array.read();
  336. const Vector2 *src = read.ptr();
  337. // setting vertices means regenerating the AABB
  338. Rect2 aabb;
  339. if (p_format & ARRAY_COMPRESS_VERTEX) {
  340. for (int i = 0; i < p_vertex_array_len; i++) {
  341. uint16_t vector[2] = { Math::make_half_float(src[i].x), Math::make_half_float(src[i].y) };
  342. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], vector, sizeof(uint16_t) * 2);
  343. if (i == 0) {
  344. aabb = Rect2(src[i], SMALL_VEC2); //must have a bit of size
  345. } else {
  346. aabb.expand_to(src[i]);
  347. }
  348. }
  349. } else {
  350. for (int i = 0; i < p_vertex_array_len; i++) {
  351. float vector[2] = { src[i].x, src[i].y };
  352. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], vector, sizeof(float) * 2);
  353. if (i == 0) {
  354. aabb = Rect2(src[i], SMALL_VEC2); //must have a bit of size
  355. } else {
  356. aabb.expand_to(src[i]);
  357. }
  358. }
  359. }
  360. r_aabb = AABB(Vector3(aabb.position.x, aabb.position.y, 0), Vector3(aabb.size.x, aabb.size.y, 0));
  361. } else {
  362. PoolVector<Vector3> array = p_arrays[ai];
  363. ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
  364. PoolVector<Vector3>::Read read = array.read();
  365. const Vector3 *src = read.ptr();
  366. // setting vertices means regenerating the AABB
  367. AABB aabb;
  368. if (p_format & ARRAY_COMPRESS_VERTEX) {
  369. for (int i = 0; i < p_vertex_array_len; i++) {
  370. uint16_t vector[4] = { Math::make_half_float(src[i].x), Math::make_half_float(src[i].y), Math::make_half_float(src[i].z), Math::make_half_float(1.0) };
  371. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], vector, sizeof(uint16_t) * 4);
  372. if (i == 0) {
  373. aabb = AABB(src[i], SMALL_VEC3);
  374. } else {
  375. aabb.expand_to(src[i]);
  376. }
  377. }
  378. } else {
  379. for (int i = 0; i < p_vertex_array_len; i++) {
  380. float vector[3] = { src[i].x, src[i].y, src[i].z };
  381. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], vector, sizeof(float) * 3);
  382. if (i == 0) {
  383. aabb = AABB(src[i], SMALL_VEC3);
  384. } else {
  385. aabb.expand_to(src[i]);
  386. }
  387. }
  388. }
  389. r_aabb = aabb;
  390. }
  391. } break;
  392. case VS::ARRAY_NORMAL: {
  393. ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::POOL_VECTOR3_ARRAY, ERR_INVALID_PARAMETER);
  394. PoolVector<Vector3> array = p_arrays[ai];
  395. ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
  396. PoolVector<Vector3>::Read read = array.read();
  397. const Vector3 *src = read.ptr();
  398. // setting vertices means regenerating the AABB
  399. if (p_format & ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
  400. if ((p_format & ARRAY_COMPRESS_NORMAL) && (p_format & ARRAY_FORMAT_TANGENT) && (p_format & ARRAY_COMPRESS_TANGENT)) {
  401. for (int i = 0; i < p_vertex_array_len; i++) {
  402. Vector2 res = norm_to_oct(src[i]);
  403. int8_t vector[2] = {
  404. (int8_t)CLAMP(res.x * 127, -128, 127),
  405. (int8_t)CLAMP(res.y * 127, -128, 127),
  406. };
  407. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], vector, 2);
  408. }
  409. } else {
  410. for (int i = 0; i < p_vertex_array_len; i++) {
  411. Vector2 res = norm_to_oct(src[i]);
  412. int16_t vector[2] = {
  413. (int16_t)CLAMP(res.x * 32767, -32768, 32767),
  414. (int16_t)CLAMP(res.y * 32767, -32768, 32767),
  415. };
  416. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], vector, 4);
  417. }
  418. }
  419. } else {
  420. if (p_format & ARRAY_COMPRESS_NORMAL) {
  421. for (int i = 0; i < p_vertex_array_len; i++) {
  422. int8_t vector[4] = {
  423. (int8_t)CLAMP(src[i].x * 127, -128, 127),
  424. (int8_t)CLAMP(src[i].y * 127, -128, 127),
  425. (int8_t)CLAMP(src[i].z * 127, -128, 127),
  426. 0,
  427. };
  428. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], vector, 4);
  429. }
  430. } else {
  431. for (int i = 0; i < p_vertex_array_len; i++) {
  432. float vector[3] = { src[i].x, src[i].y, src[i].z };
  433. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], vector, 3 * 4);
  434. }
  435. }
  436. }
  437. } break;
  438. case VS::ARRAY_TANGENT: {
  439. ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::POOL_REAL_ARRAY, ERR_INVALID_PARAMETER);
  440. PoolVector<real_t> array = p_arrays[ai];
  441. ERR_FAIL_COND_V(array.size() != p_vertex_array_len * 4, ERR_INVALID_PARAMETER);
  442. PoolVector<real_t>::Read read = array.read();
  443. const real_t *src = read.ptr();
  444. if (p_format & ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
  445. if (p_format & ARRAY_COMPRESS_TANGENT) {
  446. for (int i = 0; i < p_vertex_array_len; i++) {
  447. Vector3 source(src[i * 4 + 0], src[i * 4 + 1], src[i * 4 + 2]);
  448. Vector2 res = tangent_to_oct(source, src[i * 4 + 3], false);
  449. int8_t vector[2] = {
  450. (int8_t)CLAMP(res.x * 127, -128, 127),
  451. (int8_t)CLAMP(res.y * 127, -128, 127)
  452. };
  453. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], vector, 2);
  454. }
  455. } else {
  456. for (int i = 0; i < p_vertex_array_len; i++) {
  457. Vector3 source(src[i * 4 + 0], src[i * 4 + 1], src[i * 4 + 2]);
  458. Vector2 res = tangent_to_oct(source, src[i * 4 + 3], true);
  459. int16_t vector[2] = {
  460. (int16_t)CLAMP(res.x * 32767, -32768, 32767),
  461. (int16_t)CLAMP(res.y * 32767, -32768, 32767)
  462. };
  463. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], vector, 4);
  464. }
  465. }
  466. } else {
  467. if (p_format & ARRAY_COMPRESS_TANGENT) {
  468. for (int i = 0; i < p_vertex_array_len; i++) {
  469. int8_t xyzw[4] = {
  470. (int8_t)CLAMP(src[i * 4 + 0] * 127, -128, 127),
  471. (int8_t)CLAMP(src[i * 4 + 1] * 127, -128, 127),
  472. (int8_t)CLAMP(src[i * 4 + 2] * 127, -128, 127),
  473. (int8_t)CLAMP(src[i * 4 + 3] * 127, -128, 127)
  474. };
  475. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], xyzw, 4);
  476. }
  477. } else {
  478. for (int i = 0; i < p_vertex_array_len; i++) {
  479. float xyzw[4] = {
  480. src[i * 4 + 0],
  481. src[i * 4 + 1],
  482. src[i * 4 + 2],
  483. src[i * 4 + 3]
  484. };
  485. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], xyzw, 4 * 4);
  486. }
  487. }
  488. }
  489. } break;
  490. case VS::ARRAY_COLOR: {
  491. ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::POOL_COLOR_ARRAY, ERR_INVALID_PARAMETER);
  492. PoolVector<Color> array = p_arrays[ai];
  493. ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
  494. PoolVector<Color>::Read read = array.read();
  495. const Color *src = read.ptr();
  496. if (p_format & ARRAY_COMPRESS_COLOR) {
  497. for (int i = 0; i < p_vertex_array_len; i++) {
  498. uint8_t colors[4];
  499. for (int j = 0; j < 4; j++) {
  500. colors[j] = CLAMP(int((src[i][j]) * 255.0), 0, 255);
  501. }
  502. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], colors, 4);
  503. }
  504. } else {
  505. for (int i = 0; i < p_vertex_array_len; i++) {
  506. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], &src[i], 4 * 4);
  507. }
  508. }
  509. } break;
  510. case VS::ARRAY_TEX_UV: {
  511. ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::POOL_VECTOR3_ARRAY && p_arrays[ai].get_type() != Variant::POOL_VECTOR2_ARRAY, ERR_INVALID_PARAMETER);
  512. PoolVector<Vector2> array = p_arrays[ai];
  513. ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
  514. PoolVector<Vector2>::Read read = array.read();
  515. const Vector2 *src = read.ptr();
  516. if (p_format & ARRAY_COMPRESS_TEX_UV) {
  517. for (int i = 0; i < p_vertex_array_len; i++) {
  518. uint16_t uv[2] = { Math::make_half_float(src[i].x), Math::make_half_float(src[i].y) };
  519. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], uv, 2 * 2);
  520. }
  521. } else {
  522. for (int i = 0; i < p_vertex_array_len; i++) {
  523. float uv[2] = { src[i].x, src[i].y };
  524. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], uv, 2 * 4);
  525. }
  526. }
  527. } break;
  528. case VS::ARRAY_TEX_UV2: {
  529. ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::POOL_VECTOR3_ARRAY && p_arrays[ai].get_type() != Variant::POOL_VECTOR2_ARRAY, ERR_INVALID_PARAMETER);
  530. PoolVector<Vector2> array = p_arrays[ai];
  531. ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
  532. PoolVector<Vector2>::Read read = array.read();
  533. const Vector2 *src = read.ptr();
  534. if (p_format & ARRAY_COMPRESS_TEX_UV2) {
  535. for (int i = 0; i < p_vertex_array_len; i++) {
  536. uint16_t uv[2] = { Math::make_half_float(src[i].x), Math::make_half_float(src[i].y) };
  537. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], uv, 2 * 2);
  538. }
  539. } else {
  540. for (int i = 0; i < p_vertex_array_len; i++) {
  541. float uv[2] = { src[i].x, src[i].y };
  542. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], uv, 2 * 4);
  543. }
  544. }
  545. } break;
  546. case VS::ARRAY_WEIGHTS: {
  547. ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::POOL_REAL_ARRAY, ERR_INVALID_PARAMETER);
  548. PoolVector<real_t> array = p_arrays[ai];
  549. ERR_FAIL_COND_V(array.size() != p_vertex_array_len * VS::ARRAY_WEIGHTS_SIZE, ERR_INVALID_PARAMETER);
  550. PoolVector<real_t>::Read read = array.read();
  551. const real_t *src = read.ptr();
  552. if (p_format & ARRAY_COMPRESS_WEIGHTS) {
  553. for (int i = 0; i < p_vertex_array_len; i++) {
  554. uint16_t data[VS::ARRAY_WEIGHTS_SIZE];
  555. for (int j = 0; j < VS::ARRAY_WEIGHTS_SIZE; j++) {
  556. data[j] = CLAMP(src[i * VS::ARRAY_WEIGHTS_SIZE + j] * 65535, 0, 65535);
  557. }
  558. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], data, 2 * 4);
  559. }
  560. } else {
  561. for (int i = 0; i < p_vertex_array_len; i++) {
  562. float data[VS::ARRAY_WEIGHTS_SIZE];
  563. for (int j = 0; j < VS::ARRAY_WEIGHTS_SIZE; j++) {
  564. data[j] = src[i * VS::ARRAY_WEIGHTS_SIZE + j];
  565. }
  566. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], data, 4 * 4);
  567. }
  568. }
  569. } break;
  570. case VS::ARRAY_BONES: {
  571. ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::POOL_INT_ARRAY && p_arrays[ai].get_type() != Variant::POOL_REAL_ARRAY, ERR_INVALID_PARAMETER);
  572. PoolVector<int> array = p_arrays[ai];
  573. ERR_FAIL_COND_V(array.size() != p_vertex_array_len * VS::ARRAY_WEIGHTS_SIZE, ERR_INVALID_PARAMETER);
  574. PoolVector<int>::Read read = array.read();
  575. const int *src = read.ptr();
  576. if (!(p_format & ARRAY_FLAG_USE_16_BIT_BONES)) {
  577. for (int i = 0; i < p_vertex_array_len; i++) {
  578. uint8_t data[VS::ARRAY_WEIGHTS_SIZE];
  579. for (int j = 0; j < VS::ARRAY_WEIGHTS_SIZE; j++) {
  580. data[j] = CLAMP(src[i * VS::ARRAY_WEIGHTS_SIZE + j], 0, 255);
  581. max_bone = MAX(data[j], max_bone);
  582. }
  583. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], data, 4);
  584. }
  585. } else {
  586. for (int i = 0; i < p_vertex_array_len; i++) {
  587. uint16_t data[VS::ARRAY_WEIGHTS_SIZE];
  588. for (int j = 0; j < VS::ARRAY_WEIGHTS_SIZE; j++) {
  589. data[j] = src[i * VS::ARRAY_WEIGHTS_SIZE + j];
  590. max_bone = MAX(data[j], max_bone);
  591. }
  592. memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], data, 2 * 4);
  593. }
  594. }
  595. } break;
  596. case VS::ARRAY_INDEX: {
  597. ERR_FAIL_COND_V(p_index_array_len <= 0, ERR_INVALID_DATA);
  598. ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::POOL_INT_ARRAY, ERR_INVALID_PARAMETER);
  599. PoolVector<int> indices = p_arrays[ai];
  600. ERR_FAIL_COND_V(indices.size() == 0, ERR_INVALID_PARAMETER);
  601. ERR_FAIL_COND_V(indices.size() != p_index_array_len, ERR_INVALID_PARAMETER);
  602. /* determine whether using 16 or 32 bits indices */
  603. PoolVector<int>::Read read = indices.read();
  604. const int *src = read.ptr();
  605. for (int i = 0; i < p_index_array_len; i++) {
  606. if (p_vertex_array_len < (1 << 16)) {
  607. uint16_t v = src[i];
  608. memcpy(&iw[i * 2], &v, 2);
  609. } else {
  610. uint32_t v = src[i];
  611. memcpy(&iw[i * 4], &v, 4);
  612. }
  613. }
  614. } break;
  615. default: {
  616. ERR_FAIL_V(ERR_INVALID_DATA);
  617. }
  618. }
  619. }
  620. if (p_format & VS::ARRAY_FORMAT_BONES) {
  621. //create AABBs for each detected bone
  622. int total_bones = max_bone + 1;
  623. bool first = r_bone_aabb.size() == 0;
  624. r_bone_aabb.resize(total_bones);
  625. if (first) {
  626. for (int i = 0; i < total_bones; i++) {
  627. r_bone_aabb.write[i].size = Vector3(-1, -1, -1); //negative means unused
  628. }
  629. }
  630. PoolVector<Vector3> vertices = p_arrays[VS::ARRAY_VERTEX];
  631. PoolVector<int> bones = p_arrays[VS::ARRAY_BONES];
  632. PoolVector<float> weights = p_arrays[VS::ARRAY_WEIGHTS];
  633. bool any_valid = false;
  634. if (vertices.size() && bones.size() == vertices.size() * 4 && weights.size() == bones.size()) {
  635. int vs = vertices.size();
  636. PoolVector<Vector3>::Read rv = vertices.read();
  637. PoolVector<int>::Read rb = bones.read();
  638. PoolVector<float>::Read rw = weights.read();
  639. AABB *bptr = r_bone_aabb.ptrw();
  640. for (int i = 0; i < vs; i++) {
  641. Vector3 v = rv[i];
  642. for (int j = 0; j < 4; j++) {
  643. int idx = rb[i * 4 + j];
  644. float w = rw[i * 4 + j];
  645. if (w == 0) {
  646. continue; //break;
  647. }
  648. ERR_FAIL_INDEX_V(idx, total_bones, ERR_INVALID_DATA);
  649. if (bptr[idx].size.x < 0) {
  650. //first
  651. bptr[idx] = AABB(v, SMALL_VEC3);
  652. any_valid = true;
  653. } else {
  654. bptr[idx].expand_to(v);
  655. }
  656. }
  657. }
  658. }
  659. if (!any_valid && first) {
  660. r_bone_aabb.clear();
  661. }
  662. }
  663. return OK;
  664. }
  665. uint32_t VisualServer::mesh_surface_get_format_offset(uint32_t p_format, int p_vertex_len, int p_index_len, int p_array_index) const {
  666. uint32_t offsets[ARRAY_MAX];
  667. mesh_surface_make_offsets_from_format(p_format, p_vertex_len, p_index_len, offsets);
  668. return offsets[p_array_index];
  669. }
  670. uint32_t VisualServer::mesh_surface_get_format_stride(uint32_t p_format, int p_vertex_len, int p_index_len) const {
  671. uint32_t offsets[ARRAY_MAX];
  672. return mesh_surface_make_offsets_from_format(p_format, p_vertex_len, p_index_len, offsets);
  673. }
  674. uint32_t VisualServer::mesh_surface_make_offsets_from_format(uint32_t p_format, int p_vertex_len, int p_index_len, uint32_t *r_offsets) const {
  675. int total_elem_size = 0;
  676. for (int i = 0; i < VS::ARRAY_MAX; i++) {
  677. r_offsets[i] = 0; //reset
  678. if (!(p_format & (1 << i))) { // no array
  679. continue;
  680. }
  681. int elem_size = 0;
  682. switch (i) {
  683. case VS::ARRAY_VERTEX: {
  684. if (p_format & ARRAY_FLAG_USE_2D_VERTICES) {
  685. elem_size = 2;
  686. } else {
  687. elem_size = 3;
  688. }
  689. if (p_format & ARRAY_COMPRESS_VERTEX) {
  690. elem_size *= sizeof(int16_t);
  691. } else {
  692. elem_size *= sizeof(float);
  693. }
  694. if (elem_size == 6) {
  695. elem_size = 8;
  696. }
  697. } break;
  698. case VS::ARRAY_NORMAL: {
  699. if (p_format & ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
  700. // normal will always be oct32 (4 byte) encoded
  701. // UNLESS tangent exists and is also compressed
  702. // then it will be oct16 encoded along with tangent
  703. if ((p_format & ARRAY_COMPRESS_NORMAL) && (p_format & ARRAY_FORMAT_TANGENT) && (p_format & ARRAY_COMPRESS_TANGENT)) {
  704. elem_size = sizeof(uint8_t) * 2;
  705. } else {
  706. elem_size = sizeof(uint16_t) * 2;
  707. }
  708. } else {
  709. if (p_format & ARRAY_COMPRESS_NORMAL) {
  710. elem_size = sizeof(uint32_t);
  711. } else {
  712. elem_size = sizeof(float) * 3;
  713. }
  714. }
  715. } break;
  716. case VS::ARRAY_TANGENT: {
  717. if (p_format & ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
  718. if (p_format & ARRAY_COMPRESS_TANGENT) {
  719. elem_size = sizeof(uint8_t) * 2;
  720. } else {
  721. elem_size = sizeof(uint16_t) * 2;
  722. }
  723. } else {
  724. if (p_format & ARRAY_COMPRESS_TANGENT) {
  725. elem_size = sizeof(uint32_t);
  726. } else {
  727. elem_size = sizeof(float) * 4;
  728. }
  729. }
  730. } break;
  731. case VS::ARRAY_COLOR: {
  732. if (p_format & ARRAY_COMPRESS_COLOR) {
  733. elem_size = sizeof(uint32_t);
  734. } else {
  735. elem_size = sizeof(float) * 4;
  736. }
  737. } break;
  738. case VS::ARRAY_TEX_UV: {
  739. if (p_format & ARRAY_COMPRESS_TEX_UV) {
  740. elem_size = sizeof(uint32_t);
  741. } else {
  742. elem_size = sizeof(float) * 2;
  743. }
  744. } break;
  745. case VS::ARRAY_TEX_UV2: {
  746. if (p_format & ARRAY_COMPRESS_TEX_UV2) {
  747. elem_size = sizeof(uint32_t);
  748. } else {
  749. elem_size = sizeof(float) * 2;
  750. }
  751. } break;
  752. case VS::ARRAY_WEIGHTS: {
  753. if (p_format & ARRAY_COMPRESS_WEIGHTS) {
  754. elem_size = sizeof(uint16_t) * 4;
  755. } else {
  756. elem_size = sizeof(float) * 4;
  757. }
  758. } break;
  759. case VS::ARRAY_BONES: {
  760. if (p_format & ARRAY_FLAG_USE_16_BIT_BONES) {
  761. elem_size = sizeof(uint16_t) * 4;
  762. } else {
  763. elem_size = sizeof(uint32_t);
  764. }
  765. } break;
  766. case VS::ARRAY_INDEX: {
  767. if (p_index_len <= 0) {
  768. ERR_PRINT("index_array_len==NO_INDEX_ARRAY");
  769. break;
  770. }
  771. /* determine whether using 16 or 32 bits indices */
  772. if (p_vertex_len >= (1 << 16)) {
  773. elem_size = 4;
  774. } else {
  775. elem_size = 2;
  776. }
  777. r_offsets[i] = elem_size;
  778. continue;
  779. }
  780. default: {
  781. ERR_FAIL_V(0);
  782. }
  783. }
  784. r_offsets[i] = total_elem_size;
  785. total_elem_size += elem_size;
  786. }
  787. return total_elem_size;
  788. }
  789. void VisualServer::mesh_add_surface_from_arrays(RID p_mesh, PrimitiveType p_primitive, const Array &p_arrays, const Array &p_blend_shapes, uint32_t p_compress_format) {
  790. ERR_FAIL_INDEX(p_primitive, VS::PRIMITIVE_MAX);
  791. ERR_FAIL_COND(p_arrays.size() != VS::ARRAY_MAX);
  792. bool use_split_stream = GLOBAL_GET("rendering/mesh_storage/split_stream");
  793. uint32_t format = 0;
  794. // validation
  795. int index_array_len = 0;
  796. int array_len = 0;
  797. for (int i = 0; i < p_arrays.size(); i++) {
  798. if (p_arrays[i].get_type() == Variant::NIL) {
  799. continue;
  800. }
  801. format |= (1 << i);
  802. if (i == VS::ARRAY_VERTEX) {
  803. Variant var = p_arrays[i];
  804. switch (var.get_type()) {
  805. case Variant::POOL_VECTOR2_ARRAY: {
  806. PoolVector<Vector2> v2 = var;
  807. } break;
  808. case Variant::POOL_VECTOR3_ARRAY: {
  809. PoolVector<Vector3> v3 = var;
  810. } break;
  811. default: {
  812. Array v = var;
  813. } break;
  814. }
  815. array_len = PoolVector3Array(p_arrays[i]).size();
  816. ERR_FAIL_COND(array_len == 0);
  817. } else if (i == VS::ARRAY_INDEX) {
  818. index_array_len = PoolIntArray(p_arrays[i]).size();
  819. }
  820. }
  821. ERR_FAIL_COND((format & VS::ARRAY_FORMAT_VERTEX) == 0); // mandatory
  822. if (p_blend_shapes.size()) {
  823. //validate format for morphs
  824. for (int i = 0; i < p_blend_shapes.size(); i++) {
  825. uint32_t bsformat = 0;
  826. Array arr = p_blend_shapes[i];
  827. for (int j = 0; j < arr.size(); j++) {
  828. if (arr[j].get_type() != Variant::NIL) {
  829. bsformat |= (1 << j);
  830. }
  831. }
  832. ERR_FAIL_COND((bsformat) != (format & (VS::ARRAY_FORMAT_INDEX - 1)));
  833. }
  834. }
  835. uint32_t offsets[VS::ARRAY_MAX];
  836. uint32_t strides[VS::ARRAY_MAX];
  837. int attributes_base_offset = 0;
  838. int attributes_stride = 0;
  839. int positions_stride = 0;
  840. for (int i = 0; i < VS::ARRAY_MAX; i++) {
  841. offsets[i] = 0; //reset
  842. if (!(format & (1 << i))) { // no array
  843. continue;
  844. }
  845. int elem_size = 0;
  846. switch (i) {
  847. case VS::ARRAY_VERTEX: {
  848. Variant arr = p_arrays[0];
  849. if (arr.get_type() == Variant::POOL_VECTOR2_ARRAY) {
  850. elem_size = 2;
  851. p_compress_format |= ARRAY_FLAG_USE_2D_VERTICES;
  852. } else if (arr.get_type() == Variant::POOL_VECTOR3_ARRAY) {
  853. p_compress_format &= ~ARRAY_FLAG_USE_2D_VERTICES;
  854. elem_size = 3;
  855. } else {
  856. elem_size = (p_compress_format & ARRAY_FLAG_USE_2D_VERTICES) ? 2 : 3;
  857. }
  858. if (p_compress_format & ARRAY_COMPRESS_VERTEX) {
  859. elem_size *= sizeof(int16_t);
  860. } else {
  861. elem_size *= sizeof(float);
  862. }
  863. if (elem_size == 6) {
  864. //had to pad
  865. elem_size = 8;
  866. }
  867. offsets[i] = 0;
  868. positions_stride = elem_size;
  869. if (use_split_stream) {
  870. attributes_base_offset = elem_size * array_len;
  871. } else {
  872. attributes_base_offset = elem_size;
  873. }
  874. } break;
  875. case VS::ARRAY_NORMAL: {
  876. if (p_compress_format & ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
  877. // normal will always be oct32 (4 byte) encoded
  878. // UNLESS tangent exists and is also compressed
  879. // then it will be oct16 encoded along with tangent
  880. if ((p_compress_format & ARRAY_COMPRESS_NORMAL) && (format & ARRAY_FORMAT_TANGENT) && (p_compress_format & ARRAY_COMPRESS_TANGENT)) {
  881. elem_size = sizeof(uint8_t) * 2;
  882. } else {
  883. elem_size = sizeof(uint16_t) * 2;
  884. }
  885. } else {
  886. if (p_compress_format & ARRAY_COMPRESS_NORMAL) {
  887. elem_size = sizeof(uint32_t);
  888. } else {
  889. elem_size = sizeof(float) * 3;
  890. }
  891. }
  892. offsets[i] = attributes_base_offset + attributes_stride;
  893. attributes_stride += elem_size;
  894. } break;
  895. case VS::ARRAY_TANGENT: {
  896. if (p_compress_format & ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
  897. if (p_compress_format & ARRAY_COMPRESS_TANGENT) {
  898. elem_size = sizeof(uint8_t) * 2;
  899. } else {
  900. elem_size = sizeof(uint16_t) * 2;
  901. }
  902. } else {
  903. if (p_compress_format & ARRAY_COMPRESS_TANGENT) {
  904. elem_size = sizeof(uint32_t);
  905. } else {
  906. elem_size = sizeof(float) * 4;
  907. }
  908. }
  909. offsets[i] = attributes_base_offset + attributes_stride;
  910. attributes_stride += elem_size;
  911. } break;
  912. case VS::ARRAY_COLOR: {
  913. if (p_compress_format & ARRAY_COMPRESS_COLOR) {
  914. elem_size = sizeof(uint32_t);
  915. } else {
  916. elem_size = sizeof(float) * 4;
  917. }
  918. offsets[i] = attributes_base_offset + attributes_stride;
  919. attributes_stride += elem_size;
  920. } break;
  921. case VS::ARRAY_TEX_UV: {
  922. if (p_compress_format & ARRAY_COMPRESS_TEX_UV) {
  923. elem_size = sizeof(uint32_t);
  924. } else {
  925. elem_size = sizeof(float) * 2;
  926. }
  927. offsets[i] = attributes_base_offset + attributes_stride;
  928. attributes_stride += elem_size;
  929. } break;
  930. case VS::ARRAY_TEX_UV2: {
  931. if (p_compress_format & ARRAY_COMPRESS_TEX_UV2) {
  932. elem_size = sizeof(uint32_t);
  933. } else {
  934. elem_size = sizeof(float) * 2;
  935. }
  936. offsets[i] = attributes_base_offset + attributes_stride;
  937. attributes_stride += elem_size;
  938. } break;
  939. case VS::ARRAY_WEIGHTS: {
  940. if (p_compress_format & ARRAY_COMPRESS_WEIGHTS) {
  941. elem_size = sizeof(uint16_t) * 4;
  942. } else {
  943. elem_size = sizeof(float) * 4;
  944. }
  945. offsets[i] = attributes_base_offset + attributes_stride;
  946. attributes_stride += elem_size;
  947. } break;
  948. case VS::ARRAY_BONES: {
  949. PoolVector<int> bones = p_arrays[VS::ARRAY_BONES];
  950. int max_bone = 0;
  951. {
  952. int bc = bones.size();
  953. PoolVector<int>::Read r = bones.read();
  954. for (int j = 0; j < bc; j++) {
  955. max_bone = MAX(r[j], max_bone);
  956. }
  957. }
  958. if (max_bone > 255) {
  959. p_compress_format |= ARRAY_FLAG_USE_16_BIT_BONES;
  960. elem_size = sizeof(uint16_t) * 4;
  961. } else {
  962. p_compress_format &= ~ARRAY_FLAG_USE_16_BIT_BONES;
  963. elem_size = sizeof(uint32_t);
  964. }
  965. offsets[i] = attributes_base_offset + attributes_stride;
  966. attributes_stride += elem_size;
  967. } break;
  968. case VS::ARRAY_INDEX: {
  969. if (index_array_len <= 0) {
  970. ERR_PRINT("index_array_len==NO_INDEX_ARRAY");
  971. break;
  972. }
  973. /* determine whether using 16 or 32 bits indices */
  974. if (array_len >= (1 << 16)) {
  975. elem_size = 4;
  976. } else {
  977. elem_size = 2;
  978. }
  979. offsets[i] = elem_size;
  980. continue;
  981. }
  982. default: {
  983. ERR_FAIL();
  984. }
  985. }
  986. }
  987. if (use_split_stream) {
  988. strides[VS::ARRAY_VERTEX] = positions_stride;
  989. for (int i = 1; i < VS::ARRAY_MAX - 1; i++) {
  990. strides[i] = attributes_stride;
  991. }
  992. } else {
  993. for (int i = 0; i < VS::ARRAY_MAX - 1; i++) {
  994. strides[i] = positions_stride + attributes_stride;
  995. }
  996. }
  997. uint32_t mask = (1 << ARRAY_MAX) - 1;
  998. format |= (~mask) & p_compress_format; //make the full format
  999. int array_size = (positions_stride + attributes_stride) * array_len;
  1000. PoolVector<uint8_t> vertex_array;
  1001. vertex_array.resize(array_size);
  1002. int index_array_size = offsets[VS::ARRAY_INDEX] * index_array_len;
  1003. PoolVector<uint8_t> index_array;
  1004. index_array.resize(index_array_size);
  1005. AABB aabb;
  1006. Vector<AABB> bone_aabb;
  1007. Error err = _surface_set_data(p_arrays, format, offsets, strides, vertex_array, array_len, index_array, index_array_len, aabb, bone_aabb);
  1008. ERR_FAIL_COND_MSG(err, "Invalid array format for surface.");
  1009. Vector<PoolVector<uint8_t>> blend_shape_data;
  1010. for (int i = 0; i < p_blend_shapes.size(); i++) {
  1011. PoolVector<uint8_t> vertex_array_shape;
  1012. vertex_array_shape.resize(array_size);
  1013. PoolVector<uint8_t> noindex;
  1014. AABB laabb;
  1015. Error err2 = _surface_set_data(p_blend_shapes[i], format & ~ARRAY_FORMAT_INDEX, offsets, strides, vertex_array_shape, array_len, noindex, 0, laabb, bone_aabb);
  1016. aabb.merge_with(laabb);
  1017. ERR_FAIL_COND_MSG(err2 != OK, "Invalid blend shape array format for surface.");
  1018. blend_shape_data.push_back(vertex_array_shape);
  1019. }
  1020. mesh_add_surface(p_mesh, format, p_primitive, vertex_array, array_len, index_array, index_array_len, aabb, blend_shape_data, bone_aabb);
  1021. }
  1022. Array VisualServer::_get_array_from_surface(uint32_t p_format, PoolVector<uint8_t> p_vertex_data, int p_vertex_len, PoolVector<uint8_t> p_index_data, int p_index_len) const {
  1023. uint32_t offsets[ARRAY_MAX];
  1024. int total_elem_size = 0;
  1025. for (int i = 0; i < VS::ARRAY_MAX; i++) {
  1026. offsets[i] = 0; //reset
  1027. if (!(p_format & (1 << i))) { // no array
  1028. continue;
  1029. }
  1030. int elem_size = 0;
  1031. switch (i) {
  1032. case VS::ARRAY_VERTEX: {
  1033. if (p_format & ARRAY_FLAG_USE_2D_VERTICES) {
  1034. elem_size = 2;
  1035. } else {
  1036. elem_size = 3;
  1037. }
  1038. if (p_format & ARRAY_COMPRESS_VERTEX) {
  1039. elem_size *= sizeof(int16_t);
  1040. } else {
  1041. elem_size *= sizeof(float);
  1042. }
  1043. if (elem_size == 6) {
  1044. elem_size = 8;
  1045. }
  1046. } break;
  1047. case VS::ARRAY_NORMAL: {
  1048. if (p_format & ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
  1049. // normal will always be oct32 (4 byte) encoded
  1050. // UNLESS tangent exists and is also compressed
  1051. // then it will be oct16 encoded along with tangent
  1052. if ((p_format & ARRAY_COMPRESS_NORMAL) && (p_format & ARRAY_FORMAT_TANGENT) && (p_format & ARRAY_COMPRESS_TANGENT)) {
  1053. elem_size = sizeof(uint8_t) * 2;
  1054. } else {
  1055. elem_size = sizeof(uint16_t) * 2;
  1056. }
  1057. } else {
  1058. if (p_format & ARRAY_COMPRESS_NORMAL) {
  1059. elem_size = sizeof(uint32_t);
  1060. } else {
  1061. elem_size = sizeof(float) * 3;
  1062. }
  1063. }
  1064. } break;
  1065. case VS::ARRAY_TANGENT: {
  1066. if (p_format & ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
  1067. if (p_format & ARRAY_COMPRESS_TANGENT) {
  1068. elem_size = sizeof(uint8_t) * 2;
  1069. } else {
  1070. elem_size = sizeof(uint16_t) * 2;
  1071. }
  1072. } else {
  1073. if (p_format & ARRAY_COMPRESS_TANGENT) {
  1074. elem_size = sizeof(uint32_t);
  1075. } else {
  1076. elem_size = sizeof(float) * 4;
  1077. }
  1078. }
  1079. } break;
  1080. case VS::ARRAY_COLOR: {
  1081. if (p_format & ARRAY_COMPRESS_COLOR) {
  1082. elem_size = sizeof(uint32_t);
  1083. } else {
  1084. elem_size = sizeof(float) * 4;
  1085. }
  1086. } break;
  1087. case VS::ARRAY_TEX_UV: {
  1088. if (p_format & ARRAY_COMPRESS_TEX_UV) {
  1089. elem_size = sizeof(uint32_t);
  1090. } else {
  1091. elem_size = sizeof(float) * 2;
  1092. }
  1093. } break;
  1094. case VS::ARRAY_TEX_UV2: {
  1095. if (p_format & ARRAY_COMPRESS_TEX_UV2) {
  1096. elem_size = sizeof(uint32_t);
  1097. } else {
  1098. elem_size = sizeof(float) * 2;
  1099. }
  1100. } break;
  1101. case VS::ARRAY_WEIGHTS: {
  1102. if (p_format & ARRAY_COMPRESS_WEIGHTS) {
  1103. elem_size = sizeof(uint16_t) * 4;
  1104. } else {
  1105. elem_size = sizeof(float) * 4;
  1106. }
  1107. } break;
  1108. case VS::ARRAY_BONES: {
  1109. if (p_format & ARRAY_FLAG_USE_16_BIT_BONES) {
  1110. elem_size = sizeof(uint16_t) * 4;
  1111. } else {
  1112. elem_size = sizeof(uint32_t);
  1113. }
  1114. } break;
  1115. case VS::ARRAY_INDEX: {
  1116. if (p_index_len <= 0) {
  1117. ERR_PRINT("index_array_len==NO_INDEX_ARRAY");
  1118. break;
  1119. }
  1120. /* determine whether using 16 or 32 bits indices */
  1121. if (p_vertex_len >= (1 << 16)) {
  1122. elem_size = 4;
  1123. } else {
  1124. elem_size = 2;
  1125. }
  1126. offsets[i] = elem_size;
  1127. continue;
  1128. }
  1129. default: {
  1130. ERR_FAIL_V(Array());
  1131. }
  1132. }
  1133. offsets[i] = total_elem_size;
  1134. total_elem_size += elem_size;
  1135. }
  1136. Array ret;
  1137. ret.resize(VS::ARRAY_MAX);
  1138. PoolVector<uint8_t>::Read r = p_vertex_data.read();
  1139. for (int i = 0; i < VS::ARRAY_MAX; i++) {
  1140. if (!(p_format & (1 << i))) {
  1141. continue;
  1142. }
  1143. switch (i) {
  1144. case VS::ARRAY_VERTEX: {
  1145. if (p_format & ARRAY_FLAG_USE_2D_VERTICES) {
  1146. PoolVector<Vector2> arr_2d;
  1147. arr_2d.resize(p_vertex_len);
  1148. if (p_format & ARRAY_COMPRESS_VERTEX) {
  1149. PoolVector<Vector2>::Write w = arr_2d.write();
  1150. for (int j = 0; j < p_vertex_len; j++) {
  1151. const uint16_t *v = (const uint16_t *)&r[j * total_elem_size + offsets[i]];
  1152. w[j] = Vector2(Math::halfptr_to_float(&v[0]), Math::halfptr_to_float(&v[1]));
  1153. }
  1154. } else {
  1155. PoolVector<Vector2>::Write w = arr_2d.write();
  1156. for (int j = 0; j < p_vertex_len; j++) {
  1157. const float *v = (const float *)&r[j * total_elem_size + offsets[i]];
  1158. w[j] = Vector2(v[0], v[1]);
  1159. }
  1160. }
  1161. ret[i] = arr_2d;
  1162. } else {
  1163. PoolVector<Vector3> arr_3d;
  1164. arr_3d.resize(p_vertex_len);
  1165. if (p_format & ARRAY_COMPRESS_VERTEX) {
  1166. PoolVector<Vector3>::Write w = arr_3d.write();
  1167. for (int j = 0; j < p_vertex_len; j++) {
  1168. const uint16_t *v = (const uint16_t *)&r[j * total_elem_size + offsets[i]];
  1169. w[j] = Vector3(Math::halfptr_to_float(&v[0]), Math::halfptr_to_float(&v[1]), Math::halfptr_to_float(&v[2]));
  1170. }
  1171. } else {
  1172. PoolVector<Vector3>::Write w = arr_3d.write();
  1173. for (int j = 0; j < p_vertex_len; j++) {
  1174. const float *v = (const float *)&r[j * total_elem_size + offsets[i]];
  1175. w[j] = Vector3(v[0], v[1], v[2]);
  1176. }
  1177. }
  1178. ret[i] = arr_3d;
  1179. }
  1180. } break;
  1181. case VS::ARRAY_NORMAL: {
  1182. PoolVector<Vector3> arr;
  1183. arr.resize(p_vertex_len);
  1184. if (p_format & ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
  1185. if (p_format & ARRAY_COMPRESS_NORMAL && (p_format & ARRAY_FORMAT_TANGENT) && (p_format & ARRAY_COMPRESS_TANGENT)) {
  1186. PoolVector<Vector3>::Write w = arr.write();
  1187. for (int j = 0; j < p_vertex_len; j++) {
  1188. const int8_t *n = (const int8_t *)&r[j * total_elem_size + offsets[i]];
  1189. Vector2 enc(n[0] / 127.0f, n[1] / 127.0f);
  1190. w[j] = oct_to_norm(enc);
  1191. }
  1192. } else {
  1193. PoolVector<Vector3>::Write w = arr.write();
  1194. for (int j = 0; j < p_vertex_len; j++) {
  1195. const int16_t *n = (const int16_t *)&r[j * total_elem_size + offsets[i]];
  1196. Vector2 enc(n[0] / 32767.0f, n[1] / 32767.0f);
  1197. w[j] = oct_to_norm(enc);
  1198. }
  1199. }
  1200. } else {
  1201. if (p_format & ARRAY_COMPRESS_NORMAL) {
  1202. PoolVector<Vector3>::Write w = arr.write();
  1203. const float multiplier = 1.f / 127.f;
  1204. for (int j = 0; j < p_vertex_len; j++) {
  1205. const int8_t *v = (const int8_t *)&r[j * total_elem_size + offsets[i]];
  1206. w[j] = Vector3(float(v[0]) * multiplier, float(v[1]) * multiplier, float(v[2]) * multiplier);
  1207. }
  1208. } else {
  1209. PoolVector<Vector3>::Write w = arr.write();
  1210. for (int j = 0; j < p_vertex_len; j++) {
  1211. const float *v = (const float *)&r[j * total_elem_size + offsets[i]];
  1212. w[j] = Vector3(v[0], v[1], v[2]);
  1213. }
  1214. }
  1215. }
  1216. ret[i] = arr;
  1217. } break;
  1218. case VS::ARRAY_TANGENT: {
  1219. PoolVector<float> arr;
  1220. arr.resize(p_vertex_len * 4);
  1221. if (p_format & ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
  1222. if (p_format & ARRAY_COMPRESS_TANGENT) {
  1223. PoolVector<float>::Write w = arr.write();
  1224. for (int j = 0; j < p_vertex_len; j++) {
  1225. const int8_t *t = (const int8_t *)&r[j * total_elem_size + offsets[i]];
  1226. Vector2 enc(t[0] / 127.0f, t[1] / 127.0f);
  1227. Vector3 dec = oct_to_tangent(enc, &w[j * 4 + 3]);
  1228. w[j * 4 + 0] = dec.x;
  1229. w[j * 4 + 1] = dec.y;
  1230. w[j * 4 + 2] = dec.z;
  1231. }
  1232. } else {
  1233. PoolVector<float>::Write w = arr.write();
  1234. for (int j = 0; j < p_vertex_len; j++) {
  1235. const int16_t *t = (const int16_t *)&r[j * total_elem_size + offsets[i]];
  1236. Vector2 enc(t[0] / 32767.0f, t[1] / 32767.0f);
  1237. Vector3 dec = oct_to_tangent(enc, &w[j * 4 + 3]);
  1238. w[j * 4 + 0] = dec.x;
  1239. w[j * 4 + 1] = dec.y;
  1240. w[j * 4 + 2] = dec.z;
  1241. }
  1242. }
  1243. } else {
  1244. if (p_format & ARRAY_COMPRESS_TANGENT) {
  1245. PoolVector<float>::Write w = arr.write();
  1246. for (int j = 0; j < p_vertex_len; j++) {
  1247. const int8_t *v = (const int8_t *)&r[j * total_elem_size + offsets[i]];
  1248. for (int k = 0; k < 4; k++) {
  1249. w[j * 4 + k] = float(v[k] / 127.0);
  1250. }
  1251. }
  1252. } else {
  1253. PoolVector<float>::Write w = arr.write();
  1254. for (int j = 0; j < p_vertex_len; j++) {
  1255. const float *v = (const float *)&r[j * total_elem_size + offsets[i]];
  1256. for (int k = 0; k < 4; k++) {
  1257. w[j * 4 + k] = v[k];
  1258. }
  1259. }
  1260. }
  1261. }
  1262. ret[i] = arr;
  1263. } break;
  1264. case VS::ARRAY_COLOR: {
  1265. PoolVector<Color> arr;
  1266. arr.resize(p_vertex_len);
  1267. if (p_format & ARRAY_COMPRESS_COLOR) {
  1268. PoolVector<Color>::Write w = arr.write();
  1269. for (int j = 0; j < p_vertex_len; j++) {
  1270. const uint8_t *v = (const uint8_t *)&r[j * total_elem_size + offsets[i]];
  1271. w[j] = Color(float(v[0] / 255.0), float(v[1] / 255.0), float(v[2] / 255.0), float(v[3] / 255.0));
  1272. }
  1273. } else {
  1274. PoolVector<Color>::Write w = arr.write();
  1275. for (int j = 0; j < p_vertex_len; j++) {
  1276. const float *v = (const float *)&r[j * total_elem_size + offsets[i]];
  1277. w[j] = Color(v[0], v[1], v[2], v[3]);
  1278. }
  1279. }
  1280. ret[i] = arr;
  1281. } break;
  1282. case VS::ARRAY_TEX_UV: {
  1283. PoolVector<Vector2> arr;
  1284. arr.resize(p_vertex_len);
  1285. if (p_format & ARRAY_COMPRESS_TEX_UV) {
  1286. PoolVector<Vector2>::Write w = arr.write();
  1287. for (int j = 0; j < p_vertex_len; j++) {
  1288. const uint16_t *v = (const uint16_t *)&r[j * total_elem_size + offsets[i]];
  1289. w[j] = Vector2(Math::halfptr_to_float(&v[0]), Math::halfptr_to_float(&v[1]));
  1290. }
  1291. } else {
  1292. PoolVector<Vector2>::Write w = arr.write();
  1293. for (int j = 0; j < p_vertex_len; j++) {
  1294. const float *v = (const float *)&r[j * total_elem_size + offsets[i]];
  1295. w[j] = Vector2(v[0], v[1]);
  1296. }
  1297. }
  1298. ret[i] = arr;
  1299. } break;
  1300. case VS::ARRAY_TEX_UV2: {
  1301. PoolVector<Vector2> arr;
  1302. arr.resize(p_vertex_len);
  1303. if (p_format & ARRAY_COMPRESS_TEX_UV2) {
  1304. PoolVector<Vector2>::Write w = arr.write();
  1305. for (int j = 0; j < p_vertex_len; j++) {
  1306. const uint16_t *v = (const uint16_t *)&r[j * total_elem_size + offsets[i]];
  1307. w[j] = Vector2(Math::halfptr_to_float(&v[0]), Math::halfptr_to_float(&v[1]));
  1308. }
  1309. } else {
  1310. PoolVector<Vector2>::Write w = arr.write();
  1311. for (int j = 0; j < p_vertex_len; j++) {
  1312. const float *v = (const float *)&r[j * total_elem_size + offsets[i]];
  1313. w[j] = Vector2(v[0], v[1]);
  1314. }
  1315. }
  1316. ret[i] = arr;
  1317. } break;
  1318. case VS::ARRAY_WEIGHTS: {
  1319. PoolVector<float> arr;
  1320. arr.resize(p_vertex_len * 4);
  1321. if (p_format & ARRAY_COMPRESS_WEIGHTS) {
  1322. PoolVector<float>::Write w = arr.write();
  1323. for (int j = 0; j < p_vertex_len; j++) {
  1324. const uint16_t *v = (const uint16_t *)&r[j * total_elem_size + offsets[i]];
  1325. for (int k = 0; k < 4; k++) {
  1326. w[j * 4 + k] = float(v[k] / 65535.0);
  1327. }
  1328. }
  1329. } else {
  1330. PoolVector<float>::Write w = arr.write();
  1331. for (int j = 0; j < p_vertex_len; j++) {
  1332. const float *v = (const float *)&r[j * total_elem_size + offsets[i]];
  1333. for (int k = 0; k < 4; k++) {
  1334. w[j * 4 + k] = v[k];
  1335. }
  1336. }
  1337. }
  1338. ret[i] = arr;
  1339. } break;
  1340. case VS::ARRAY_BONES: {
  1341. PoolVector<int> arr;
  1342. arr.resize(p_vertex_len * 4);
  1343. if (p_format & ARRAY_FLAG_USE_16_BIT_BONES) {
  1344. PoolVector<int>::Write w = arr.write();
  1345. for (int j = 0; j < p_vertex_len; j++) {
  1346. const uint16_t *v = (const uint16_t *)&r[j * total_elem_size + offsets[i]];
  1347. for (int k = 0; k < 4; k++) {
  1348. w[j * 4 + k] = v[k];
  1349. }
  1350. }
  1351. } else {
  1352. PoolVector<int>::Write w = arr.write();
  1353. for (int j = 0; j < p_vertex_len; j++) {
  1354. const uint8_t *v = (const uint8_t *)&r[j * total_elem_size + offsets[i]];
  1355. for (int k = 0; k < 4; k++) {
  1356. w[j * 4 + k] = v[k];
  1357. }
  1358. }
  1359. }
  1360. ret[i] = arr;
  1361. } break;
  1362. case VS::ARRAY_INDEX: {
  1363. /* determine whether using 16 or 32 bits indices */
  1364. PoolVector<uint8_t>::Read ir = p_index_data.read();
  1365. PoolVector<int> arr;
  1366. arr.resize(p_index_len);
  1367. if (p_vertex_len < (1 << 16)) {
  1368. PoolVector<int>::Write w = arr.write();
  1369. for (int j = 0; j < p_index_len; j++) {
  1370. const uint16_t *v = (const uint16_t *)&ir[j * 2];
  1371. w[j] = *v;
  1372. }
  1373. } else {
  1374. PoolVector<int>::Write w = arr.write();
  1375. for (int j = 0; j < p_index_len; j++) {
  1376. const int *v = (const int *)&ir[j * 4];
  1377. w[j] = *v;
  1378. }
  1379. }
  1380. ret[i] = arr;
  1381. } break;
  1382. default: {
  1383. ERR_FAIL_V(ret);
  1384. }
  1385. }
  1386. }
  1387. return ret;
  1388. }
  1389. Array VisualServer::mesh_surface_get_arrays(RID p_mesh, int p_surface) const {
  1390. PoolVector<uint8_t> vertex_data = mesh_surface_get_array(p_mesh, p_surface);
  1391. ERR_FAIL_COND_V(vertex_data.size() == 0, Array());
  1392. int vertex_len = mesh_surface_get_array_len(p_mesh, p_surface);
  1393. PoolVector<uint8_t> index_data = mesh_surface_get_index_array(p_mesh, p_surface);
  1394. int index_len = mesh_surface_get_array_index_len(p_mesh, p_surface);
  1395. uint32_t format = mesh_surface_get_format(p_mesh, p_surface);
  1396. return _get_array_from_surface(format, vertex_data, vertex_len, index_data, index_len);
  1397. }
  1398. Array VisualServer::mesh_surface_get_blend_shape_arrays(RID p_mesh, int p_surface) const {
  1399. Vector<PoolVector<uint8_t>> blend_shape_data = mesh_surface_get_blend_shapes(p_mesh, p_surface);
  1400. if (blend_shape_data.size() > 0) {
  1401. int vertex_len = mesh_surface_get_array_len(p_mesh, p_surface);
  1402. PoolVector<uint8_t> index_data = mesh_surface_get_index_array(p_mesh, p_surface);
  1403. int index_len = mesh_surface_get_array_index_len(p_mesh, p_surface);
  1404. uint32_t format = mesh_surface_get_format(p_mesh, p_surface);
  1405. Array blend_shape_array;
  1406. blend_shape_array.resize(blend_shape_data.size());
  1407. for (int i = 0; i < blend_shape_data.size(); i++) {
  1408. blend_shape_array.set(i, _get_array_from_surface(format, blend_shape_data[i], vertex_len, index_data, index_len));
  1409. }
  1410. return blend_shape_array;
  1411. } else {
  1412. return Array();
  1413. }
  1414. }
  1415. Array VisualServer::_mesh_surface_get_skeleton_aabb_bind(RID p_mesh, int p_surface) const {
  1416. Vector<AABB> vec = VS::get_singleton()->mesh_surface_get_skeleton_aabb(p_mesh, p_surface);
  1417. Array arr;
  1418. for (int i = 0; i < vec.size(); i++) {
  1419. arr[i] = vec[i];
  1420. }
  1421. return arr;
  1422. }
  1423. void VisualServer::_bind_methods() {
  1424. ClassDB::bind_method(D_METHOD("force_sync"), &VisualServer::sync);
  1425. ClassDB::bind_method(D_METHOD("force_draw", "swap_buffers", "frame_step"), &VisualServer::draw, DEFVAL(true), DEFVAL(0.0));
  1426. // "draw" and "sync" are deprecated duplicates of "force_draw" and "force_sync"
  1427. // FIXME: Add deprecation messages using GH-4397 once available, and retire
  1428. // once the warnings have been enabled for a full release cycle
  1429. ClassDB::bind_method(D_METHOD("sync"), &VisualServer::sync);
  1430. ClassDB::bind_method(D_METHOD("draw", "swap_buffers", "frame_step"), &VisualServer::draw, DEFVAL(true), DEFVAL(0.0));
  1431. ClassDB::bind_method(D_METHOD("texture_create"), &VisualServer::texture_create);
  1432. ClassDB::bind_method(D_METHOD("texture_create_from_image", "image", "flags"), &VisualServer::texture_create_from_image, DEFVAL(TEXTURE_FLAGS_DEFAULT));
  1433. ClassDB::bind_method(D_METHOD("texture_allocate", "texture", "width", "height", "depth_3d", "format", "type", "flags"), &VisualServer::texture_allocate, DEFVAL(TEXTURE_FLAGS_DEFAULT));
  1434. ClassDB::bind_method(D_METHOD("texture_set_data", "texture", "image", "layer"), &VisualServer::texture_set_data, DEFVAL(0));
  1435. ClassDB::bind_method(D_METHOD("texture_set_data_partial", "texture", "image", "src_x", "src_y", "src_w", "src_h", "dst_x", "dst_y", "dst_mip", "layer"), &VisualServer::texture_set_data_partial, DEFVAL(0));
  1436. ClassDB::bind_method(D_METHOD("texture_get_data", "texture", "cube_side"), &VisualServer::texture_get_data, DEFVAL(CUBEMAP_LEFT));
  1437. ClassDB::bind_method(D_METHOD("texture_set_flags", "texture", "flags"), &VisualServer::texture_set_flags);
  1438. ClassDB::bind_method(D_METHOD("texture_get_flags", "texture"), &VisualServer::texture_get_flags);
  1439. ClassDB::bind_method(D_METHOD("texture_get_format", "texture"), &VisualServer::texture_get_format);
  1440. ClassDB::bind_method(D_METHOD("texture_get_type", "texture"), &VisualServer::texture_get_type);
  1441. ClassDB::bind_method(D_METHOD("texture_get_texid", "texture"), &VisualServer::texture_get_texid);
  1442. ClassDB::bind_method(D_METHOD("texture_get_width", "texture"), &VisualServer::texture_get_width);
  1443. ClassDB::bind_method(D_METHOD("texture_get_height", "texture"), &VisualServer::texture_get_height);
  1444. ClassDB::bind_method(D_METHOD("texture_get_depth", "texture"), &VisualServer::texture_get_depth);
  1445. ClassDB::bind_method(D_METHOD("texture_set_size_override", "texture", "width", "height", "depth"), &VisualServer::texture_set_size_override);
  1446. ClassDB::bind_method(D_METHOD("texture_set_path", "texture", "path"), &VisualServer::texture_set_path);
  1447. ClassDB::bind_method(D_METHOD("texture_get_path", "texture"), &VisualServer::texture_get_path);
  1448. ClassDB::bind_method(D_METHOD("texture_set_shrink_all_x2_on_set_data", "shrink"), &VisualServer::texture_set_shrink_all_x2_on_set_data);
  1449. ClassDB::bind_method(D_METHOD("texture_bind", "texture", "number"), &VisualServer::texture_bind);
  1450. ClassDB::bind_method(D_METHOD("texture_debug_usage"), &VisualServer::_texture_debug_usage_bind);
  1451. ClassDB::bind_method(D_METHOD("textures_keep_original", "enable"), &VisualServer::textures_keep_original);
  1452. #ifndef _3D_DISABLED
  1453. ClassDB::bind_method(D_METHOD("sky_create"), &VisualServer::sky_create);
  1454. ClassDB::bind_method(D_METHOD("sky_set_texture", "sky", "cube_map", "radiance_size"), &VisualServer::sky_set_texture);
  1455. #endif
  1456. ClassDB::bind_method(D_METHOD("shader_create"), &VisualServer::shader_create);
  1457. ClassDB::bind_method(D_METHOD("shader_set_code", "shader", "code"), &VisualServer::shader_set_code);
  1458. ClassDB::bind_method(D_METHOD("shader_get_code", "shader"), &VisualServer::shader_get_code);
  1459. ClassDB::bind_method(D_METHOD("shader_get_param_list", "shader"), &VisualServer::_shader_get_param_list_bind);
  1460. ClassDB::bind_method(D_METHOD("shader_set_default_texture_param", "shader", "name", "texture"), &VisualServer::shader_set_default_texture_param);
  1461. ClassDB::bind_method(D_METHOD("shader_get_default_texture_param", "shader", "name"), &VisualServer::shader_get_default_texture_param);
  1462. ClassDB::bind_method(D_METHOD("material_create"), &VisualServer::material_create);
  1463. ClassDB::bind_method(D_METHOD("material_set_shader", "shader_material", "shader"), &VisualServer::material_set_shader);
  1464. ClassDB::bind_method(D_METHOD("material_get_shader", "shader_material"), &VisualServer::material_get_shader);
  1465. ClassDB::bind_method(D_METHOD("material_set_param", "material", "parameter", "value"), &VisualServer::material_set_param);
  1466. ClassDB::bind_method(D_METHOD("material_get_param", "material", "parameter"), &VisualServer::material_get_param);
  1467. ClassDB::bind_method(D_METHOD("material_get_param_default", "material", "parameter"), &VisualServer::material_get_param_default);
  1468. ClassDB::bind_method(D_METHOD("material_set_render_priority", "material", "priority"), &VisualServer::material_set_render_priority);
  1469. ClassDB::bind_method(D_METHOD("material_set_line_width", "material", "width"), &VisualServer::material_set_line_width);
  1470. ClassDB::bind_method(D_METHOD("material_set_next_pass", "material", "next_material"), &VisualServer::material_set_next_pass);
  1471. ClassDB::bind_method(D_METHOD("mesh_create"), &VisualServer::mesh_create);
  1472. ClassDB::bind_method(D_METHOD("mesh_surface_get_format_offset", "format", "vertex_len", "index_len", "array_index"), &VisualServer::mesh_surface_get_format_offset);
  1473. ClassDB::bind_method(D_METHOD("mesh_surface_get_format_stride", "format", "vertex_len", "index_len"), &VisualServer::mesh_surface_get_format_stride);
  1474. ClassDB::bind_method(D_METHOD("mesh_add_surface_from_arrays", "mesh", "primitive", "arrays", "blend_shapes", "compress_format"), &VisualServer::mesh_add_surface_from_arrays, DEFVAL(Array()), DEFVAL(ARRAY_COMPRESS_DEFAULT));
  1475. ClassDB::bind_method(D_METHOD("mesh_set_blend_shape_count", "mesh", "amount"), &VisualServer::mesh_set_blend_shape_count);
  1476. ClassDB::bind_method(D_METHOD("mesh_get_blend_shape_count", "mesh"), &VisualServer::mesh_get_blend_shape_count);
  1477. ClassDB::bind_method(D_METHOD("mesh_set_blend_shape_mode", "mesh", "mode"), &VisualServer::mesh_set_blend_shape_mode);
  1478. ClassDB::bind_method(D_METHOD("mesh_get_blend_shape_mode", "mesh"), &VisualServer::mesh_get_blend_shape_mode);
  1479. ClassDB::bind_method(D_METHOD("mesh_surface_update_region", "mesh", "surface", "offset", "data"), &VisualServer::mesh_surface_update_region);
  1480. ClassDB::bind_method(D_METHOD("mesh_surface_set_material", "mesh", "surface", "material"), &VisualServer::mesh_surface_set_material);
  1481. ClassDB::bind_method(D_METHOD("mesh_surface_get_material", "mesh", "surface"), &VisualServer::mesh_surface_get_material);
  1482. ClassDB::bind_method(D_METHOD("mesh_surface_get_array_len", "mesh", "surface"), &VisualServer::mesh_surface_get_array_len);
  1483. ClassDB::bind_method(D_METHOD("mesh_surface_get_array_index_len", "mesh", "surface"), &VisualServer::mesh_surface_get_array_index_len);
  1484. ClassDB::bind_method(D_METHOD("mesh_surface_get_array", "mesh", "surface"), &VisualServer::mesh_surface_get_array);
  1485. ClassDB::bind_method(D_METHOD("mesh_surface_get_index_array", "mesh", "surface"), &VisualServer::mesh_surface_get_index_array);
  1486. ClassDB::bind_method(D_METHOD("mesh_surface_get_arrays", "mesh", "surface"), &VisualServer::mesh_surface_get_arrays);
  1487. ClassDB::bind_method(D_METHOD("mesh_surface_get_blend_shape_arrays", "mesh", "surface"), &VisualServer::mesh_surface_get_blend_shape_arrays);
  1488. ClassDB::bind_method(D_METHOD("mesh_surface_get_format", "mesh", "surface"), &VisualServer::mesh_surface_get_format);
  1489. ClassDB::bind_method(D_METHOD("mesh_surface_get_primitive_type", "mesh", "surface"), &VisualServer::mesh_surface_get_primitive_type);
  1490. ClassDB::bind_method(D_METHOD("mesh_surface_get_aabb", "mesh", "surface"), &VisualServer::mesh_surface_get_aabb);
  1491. ClassDB::bind_method(D_METHOD("mesh_surface_get_skeleton_aabb", "mesh", "surface"), &VisualServer::_mesh_surface_get_skeleton_aabb_bind);
  1492. ClassDB::bind_method(D_METHOD("mesh_remove_surface", "mesh", "index"), &VisualServer::mesh_remove_surface);
  1493. ClassDB::bind_method(D_METHOD("mesh_get_surface_count", "mesh"), &VisualServer::mesh_get_surface_count);
  1494. ClassDB::bind_method(D_METHOD("mesh_set_custom_aabb", "mesh", "aabb"), &VisualServer::mesh_set_custom_aabb);
  1495. ClassDB::bind_method(D_METHOD("mesh_get_custom_aabb", "mesh"), &VisualServer::mesh_get_custom_aabb);
  1496. ClassDB::bind_method(D_METHOD("mesh_clear", "mesh"), &VisualServer::mesh_clear);
  1497. ClassDB::bind_method(D_METHOD("multimesh_create"), &VisualServer::multimesh_create);
  1498. ClassDB::bind_method(D_METHOD("multimesh_allocate", "multimesh", "instances", "transform_format", "color_format", "custom_data_format"), &VisualServer::multimesh_allocate, DEFVAL(MULTIMESH_CUSTOM_DATA_NONE));
  1499. ClassDB::bind_method(D_METHOD("multimesh_get_instance_count", "multimesh"), &VisualServer::multimesh_get_instance_count);
  1500. ClassDB::bind_method(D_METHOD("multimesh_set_mesh", "multimesh", "mesh"), &VisualServer::multimesh_set_mesh);
  1501. ClassDB::bind_method(D_METHOD("multimesh_instance_set_transform", "multimesh", "index", "transform"), &VisualServer::multimesh_instance_set_transform);
  1502. ClassDB::bind_method(D_METHOD("multimesh_instance_set_transform_2d", "multimesh", "index", "transform"), &VisualServer::multimesh_instance_set_transform_2d);
  1503. ClassDB::bind_method(D_METHOD("multimesh_instance_set_color", "multimesh", "index", "color"), &VisualServer::multimesh_instance_set_color);
  1504. ClassDB::bind_method(D_METHOD("multimesh_instance_set_custom_data", "multimesh", "index", "custom_data"), &VisualServer::multimesh_instance_set_custom_data);
  1505. ClassDB::bind_method(D_METHOD("multimesh_get_mesh", "multimesh"), &VisualServer::multimesh_get_mesh);
  1506. ClassDB::bind_method(D_METHOD("multimesh_get_aabb", "multimesh"), &VisualServer::multimesh_get_aabb);
  1507. ClassDB::bind_method(D_METHOD("multimesh_instance_get_transform", "multimesh", "index"), &VisualServer::multimesh_instance_get_transform);
  1508. ClassDB::bind_method(D_METHOD("multimesh_instance_get_transform_2d", "multimesh", "index"), &VisualServer::multimesh_instance_get_transform_2d);
  1509. ClassDB::bind_method(D_METHOD("multimesh_instance_get_color", "multimesh", "index"), &VisualServer::multimesh_instance_get_color);
  1510. ClassDB::bind_method(D_METHOD("multimesh_instance_get_custom_data", "multimesh", "index"), &VisualServer::multimesh_instance_get_custom_data);
  1511. ClassDB::bind_method(D_METHOD("multimesh_set_visible_instances", "multimesh", "visible"), &VisualServer::multimesh_set_visible_instances);
  1512. ClassDB::bind_method(D_METHOD("multimesh_get_visible_instances", "multimesh"), &VisualServer::multimesh_get_visible_instances);
  1513. ClassDB::bind_method(D_METHOD("multimesh_set_as_bulk_array", "multimesh", "array"), &VisualServer::multimesh_set_as_bulk_array);
  1514. #ifndef _3D_DISABLED
  1515. ClassDB::bind_method(D_METHOD("immediate_create"), &VisualServer::immediate_create);
  1516. ClassDB::bind_method(D_METHOD("immediate_begin", "immediate", "primitive", "texture"), &VisualServer::immediate_begin, DEFVAL(RID()));
  1517. ClassDB::bind_method(D_METHOD("immediate_vertex", "immediate", "vertex"), &VisualServer::immediate_vertex);
  1518. ClassDB::bind_method(D_METHOD("immediate_vertex_2d", "immediate", "vertex"), &VisualServer::immediate_vertex_2d);
  1519. ClassDB::bind_method(D_METHOD("immediate_normal", "immediate", "normal"), &VisualServer::immediate_normal);
  1520. ClassDB::bind_method(D_METHOD("immediate_tangent", "immediate", "tangent"), &VisualServer::immediate_tangent);
  1521. ClassDB::bind_method(D_METHOD("immediate_color", "immediate", "color"), &VisualServer::immediate_color);
  1522. ClassDB::bind_method(D_METHOD("immediate_uv", "immediate", "tex_uv"), &VisualServer::immediate_uv);
  1523. ClassDB::bind_method(D_METHOD("immediate_uv2", "immediate", "tex_uv"), &VisualServer::immediate_uv2);
  1524. ClassDB::bind_method(D_METHOD("immediate_end", "immediate"), &VisualServer::immediate_end);
  1525. ClassDB::bind_method(D_METHOD("immediate_clear", "immediate"), &VisualServer::immediate_clear);
  1526. ClassDB::bind_method(D_METHOD("immediate_set_material", "immediate", "material"), &VisualServer::immediate_set_material);
  1527. ClassDB::bind_method(D_METHOD("immediate_get_material", "immediate"), &VisualServer::immediate_get_material);
  1528. #endif
  1529. ClassDB::bind_method(D_METHOD("skeleton_create"), &VisualServer::skeleton_create);
  1530. ClassDB::bind_method(D_METHOD("skeleton_allocate", "skeleton", "bones", "is_2d_skeleton"), &VisualServer::skeleton_allocate, DEFVAL(false));
  1531. ClassDB::bind_method(D_METHOD("skeleton_get_bone_count", "skeleton"), &VisualServer::skeleton_get_bone_count);
  1532. ClassDB::bind_method(D_METHOD("skeleton_bone_set_transform", "skeleton", "bone", "transform"), &VisualServer::skeleton_bone_set_transform);
  1533. ClassDB::bind_method(D_METHOD("skeleton_bone_get_transform", "skeleton", "bone"), &VisualServer::skeleton_bone_get_transform);
  1534. ClassDB::bind_method(D_METHOD("skeleton_bone_set_transform_2d", "skeleton", "bone", "transform"), &VisualServer::skeleton_bone_set_transform_2d);
  1535. ClassDB::bind_method(D_METHOD("skeleton_bone_get_transform_2d", "skeleton", "bone"), &VisualServer::skeleton_bone_get_transform_2d);
  1536. #ifndef _3D_DISABLED
  1537. ClassDB::bind_method(D_METHOD("directional_light_create"), &VisualServer::directional_light_create);
  1538. ClassDB::bind_method(D_METHOD("omni_light_create"), &VisualServer::omni_light_create);
  1539. ClassDB::bind_method(D_METHOD("spot_light_create"), &VisualServer::spot_light_create);
  1540. ClassDB::bind_method(D_METHOD("light_set_color", "light", "color"), &VisualServer::light_set_color);
  1541. ClassDB::bind_method(D_METHOD("light_set_param", "light", "param", "value"), &VisualServer::light_set_param);
  1542. ClassDB::bind_method(D_METHOD("light_set_shadow", "light", "enabled"), &VisualServer::light_set_shadow);
  1543. ClassDB::bind_method(D_METHOD("light_set_shadow_color", "light", "color"), &VisualServer::light_set_shadow_color);
  1544. ClassDB::bind_method(D_METHOD("light_set_projector", "light", "texture"), &VisualServer::light_set_projector);
  1545. ClassDB::bind_method(D_METHOD("light_set_negative", "light", "enable"), &VisualServer::light_set_negative);
  1546. ClassDB::bind_method(D_METHOD("light_set_cull_mask", "light", "mask"), &VisualServer::light_set_cull_mask);
  1547. ClassDB::bind_method(D_METHOD("light_set_reverse_cull_face_mode", "light", "enabled"), &VisualServer::light_set_reverse_cull_face_mode);
  1548. ClassDB::bind_method(D_METHOD("light_set_use_gi", "light", "enabled"), &VisualServer::light_set_use_gi);
  1549. ClassDB::bind_method(D_METHOD("light_set_bake_mode", "light", "bake_mode"), &VisualServer::light_set_bake_mode);
  1550. ClassDB::bind_method(D_METHOD("light_omni_set_shadow_mode", "light", "mode"), &VisualServer::light_omni_set_shadow_mode);
  1551. ClassDB::bind_method(D_METHOD("light_omni_set_shadow_detail", "light", "detail"), &VisualServer::light_omni_set_shadow_detail);
  1552. ClassDB::bind_method(D_METHOD("light_directional_set_shadow_mode", "light", "mode"), &VisualServer::light_directional_set_shadow_mode);
  1553. ClassDB::bind_method(D_METHOD("light_directional_set_blend_splits", "light", "enable"), &VisualServer::light_directional_set_blend_splits);
  1554. ClassDB::bind_method(D_METHOD("light_directional_set_shadow_depth_range_mode", "light", "range_mode"), &VisualServer::light_directional_set_shadow_depth_range_mode);
  1555. ClassDB::bind_method(D_METHOD("reflection_probe_create"), &VisualServer::reflection_probe_create);
  1556. ClassDB::bind_method(D_METHOD("reflection_probe_set_update_mode", "probe", "mode"), &VisualServer::reflection_probe_set_update_mode);
  1557. ClassDB::bind_method(D_METHOD("reflection_probe_set_intensity", "probe", "intensity"), &VisualServer::reflection_probe_set_intensity);
  1558. ClassDB::bind_method(D_METHOD("reflection_probe_set_interior_ambient", "probe", "color"), &VisualServer::reflection_probe_set_interior_ambient);
  1559. ClassDB::bind_method(D_METHOD("reflection_probe_set_interior_ambient_energy", "probe", "energy"), &VisualServer::reflection_probe_set_interior_ambient_energy);
  1560. ClassDB::bind_method(D_METHOD("reflection_probe_set_interior_ambient_probe_contribution", "probe", "contrib"), &VisualServer::reflection_probe_set_interior_ambient_probe_contribution);
  1561. ClassDB::bind_method(D_METHOD("reflection_probe_set_max_distance", "probe", "distance"), &VisualServer::reflection_probe_set_max_distance);
  1562. ClassDB::bind_method(D_METHOD("reflection_probe_set_extents", "probe", "extents"), &VisualServer::reflection_probe_set_extents);
  1563. ClassDB::bind_method(D_METHOD("reflection_probe_set_origin_offset", "probe", "offset"), &VisualServer::reflection_probe_set_origin_offset);
  1564. ClassDB::bind_method(D_METHOD("reflection_probe_set_as_interior", "probe", "enable"), &VisualServer::reflection_probe_set_as_interior);
  1565. ClassDB::bind_method(D_METHOD("reflection_probe_set_enable_box_projection", "probe", "enable"), &VisualServer::reflection_probe_set_enable_box_projection);
  1566. ClassDB::bind_method(D_METHOD("reflection_probe_set_enable_shadows", "probe", "enable"), &VisualServer::reflection_probe_set_enable_shadows);
  1567. ClassDB::bind_method(D_METHOD("reflection_probe_set_cull_mask", "probe", "layers"), &VisualServer::reflection_probe_set_cull_mask);
  1568. ClassDB::bind_method(D_METHOD("gi_probe_create"), &VisualServer::gi_probe_create);
  1569. ClassDB::bind_method(D_METHOD("gi_probe_set_bounds", "probe", "bounds"), &VisualServer::gi_probe_set_bounds);
  1570. ClassDB::bind_method(D_METHOD("gi_probe_get_bounds", "probe"), &VisualServer::gi_probe_get_bounds);
  1571. ClassDB::bind_method(D_METHOD("gi_probe_set_cell_size", "probe", "range"), &VisualServer::gi_probe_set_cell_size);
  1572. ClassDB::bind_method(D_METHOD("gi_probe_get_cell_size", "probe"), &VisualServer::gi_probe_get_cell_size);
  1573. ClassDB::bind_method(D_METHOD("gi_probe_set_to_cell_xform", "probe", "xform"), &VisualServer::gi_probe_set_to_cell_xform);
  1574. ClassDB::bind_method(D_METHOD("gi_probe_get_to_cell_xform", "probe"), &VisualServer::gi_probe_get_to_cell_xform);
  1575. ClassDB::bind_method(D_METHOD("gi_probe_set_dynamic_data", "probe", "data"), &VisualServer::gi_probe_set_dynamic_data);
  1576. ClassDB::bind_method(D_METHOD("gi_probe_get_dynamic_data", "probe"), &VisualServer::gi_probe_get_dynamic_data);
  1577. ClassDB::bind_method(D_METHOD("gi_probe_set_dynamic_range", "probe", "range"), &VisualServer::gi_probe_set_dynamic_range);
  1578. ClassDB::bind_method(D_METHOD("gi_probe_get_dynamic_range", "probe"), &VisualServer::gi_probe_get_dynamic_range);
  1579. ClassDB::bind_method(D_METHOD("gi_probe_set_energy", "probe", "energy"), &VisualServer::gi_probe_set_energy);
  1580. ClassDB::bind_method(D_METHOD("gi_probe_get_energy", "probe"), &VisualServer::gi_probe_get_energy);
  1581. ClassDB::bind_method(D_METHOD("gi_probe_set_bias", "probe", "bias"), &VisualServer::gi_probe_set_bias);
  1582. ClassDB::bind_method(D_METHOD("gi_probe_get_bias", "probe"), &VisualServer::gi_probe_get_bias);
  1583. ClassDB::bind_method(D_METHOD("gi_probe_set_normal_bias", "probe", "bias"), &VisualServer::gi_probe_set_normal_bias);
  1584. ClassDB::bind_method(D_METHOD("gi_probe_get_normal_bias", "probe"), &VisualServer::gi_probe_get_normal_bias);
  1585. ClassDB::bind_method(D_METHOD("gi_probe_set_propagation", "probe", "propagation"), &VisualServer::gi_probe_set_propagation);
  1586. ClassDB::bind_method(D_METHOD("gi_probe_get_propagation", "probe"), &VisualServer::gi_probe_get_propagation);
  1587. ClassDB::bind_method(D_METHOD("gi_probe_set_interior", "probe", "enable"), &VisualServer::gi_probe_set_interior);
  1588. ClassDB::bind_method(D_METHOD("gi_probe_is_interior", "probe"), &VisualServer::gi_probe_is_interior);
  1589. ClassDB::bind_method(D_METHOD("gi_probe_set_compress", "probe", "enable"), &VisualServer::gi_probe_set_compress);
  1590. ClassDB::bind_method(D_METHOD("gi_probe_is_compressed", "probe"), &VisualServer::gi_probe_is_compressed);
  1591. ClassDB::bind_method(D_METHOD("lightmap_capture_create"), &VisualServer::lightmap_capture_create);
  1592. ClassDB::bind_method(D_METHOD("lightmap_capture_set_bounds", "capture", "bounds"), &VisualServer::lightmap_capture_set_bounds);
  1593. ClassDB::bind_method(D_METHOD("lightmap_capture_get_bounds", "capture"), &VisualServer::lightmap_capture_get_bounds);
  1594. ClassDB::bind_method(D_METHOD("lightmap_capture_set_octree", "capture", "octree"), &VisualServer::lightmap_capture_set_octree);
  1595. ClassDB::bind_method(D_METHOD("lightmap_capture_set_octree_cell_transform", "capture", "xform"), &VisualServer::lightmap_capture_set_octree_cell_transform);
  1596. ClassDB::bind_method(D_METHOD("lightmap_capture_get_octree_cell_transform", "capture"), &VisualServer::lightmap_capture_get_octree_cell_transform);
  1597. ClassDB::bind_method(D_METHOD("lightmap_capture_set_octree_cell_subdiv", "capture", "subdiv"), &VisualServer::lightmap_capture_set_octree_cell_subdiv);
  1598. ClassDB::bind_method(D_METHOD("lightmap_capture_get_octree_cell_subdiv", "capture"), &VisualServer::lightmap_capture_get_octree_cell_subdiv);
  1599. ClassDB::bind_method(D_METHOD("lightmap_capture_get_octree", "capture"), &VisualServer::lightmap_capture_get_octree);
  1600. ClassDB::bind_method(D_METHOD("lightmap_capture_set_energy", "capture", "energy"), &VisualServer::lightmap_capture_set_energy);
  1601. ClassDB::bind_method(D_METHOD("lightmap_capture_get_energy", "capture"), &VisualServer::lightmap_capture_get_energy);
  1602. ClassDB::bind_method(D_METHOD("lightmap_capture_set_interior", "capture", "interior"), &VisualServer::lightmap_capture_set_interior);
  1603. ClassDB::bind_method(D_METHOD("lightmap_capture_is_interior", "capture"), &VisualServer::lightmap_capture_is_interior);
  1604. #endif
  1605. ClassDB::bind_method(D_METHOD("particles_create"), &VisualServer::particles_create);
  1606. ClassDB::bind_method(D_METHOD("particles_set_emitting", "particles", "emitting"), &VisualServer::particles_set_emitting);
  1607. ClassDB::bind_method(D_METHOD("particles_get_emitting", "particles"), &VisualServer::particles_get_emitting);
  1608. ClassDB::bind_method(D_METHOD("particles_set_amount", "particles", "amount"), &VisualServer::particles_set_amount);
  1609. ClassDB::bind_method(D_METHOD("particles_set_lifetime", "particles", "lifetime"), &VisualServer::particles_set_lifetime);
  1610. ClassDB::bind_method(D_METHOD("particles_set_one_shot", "particles", "one_shot"), &VisualServer::particles_set_one_shot);
  1611. ClassDB::bind_method(D_METHOD("particles_set_pre_process_time", "particles", "time"), &VisualServer::particles_set_pre_process_time);
  1612. ClassDB::bind_method(D_METHOD("particles_set_explosiveness_ratio", "particles", "ratio"), &VisualServer::particles_set_explosiveness_ratio);
  1613. ClassDB::bind_method(D_METHOD("particles_set_randomness_ratio", "particles", "ratio"), &VisualServer::particles_set_randomness_ratio);
  1614. ClassDB::bind_method(D_METHOD("particles_set_custom_aabb", "particles", "aabb"), &VisualServer::particles_set_custom_aabb);
  1615. ClassDB::bind_method(D_METHOD("particles_set_speed_scale", "particles", "scale"), &VisualServer::particles_set_speed_scale);
  1616. ClassDB::bind_method(D_METHOD("particles_set_use_local_coordinates", "particles", "enable"), &VisualServer::particles_set_use_local_coordinates);
  1617. ClassDB::bind_method(D_METHOD("particles_set_process_material", "particles", "material"), &VisualServer::particles_set_process_material);
  1618. ClassDB::bind_method(D_METHOD("particles_set_fixed_fps", "particles", "fps"), &VisualServer::particles_set_fixed_fps);
  1619. ClassDB::bind_method(D_METHOD("particles_set_fractional_delta", "particles", "enable"), &VisualServer::particles_set_fractional_delta);
  1620. ClassDB::bind_method(D_METHOD("particles_is_inactive", "particles"), &VisualServer::particles_is_inactive);
  1621. ClassDB::bind_method(D_METHOD("particles_request_process", "particles"), &VisualServer::particles_request_process);
  1622. ClassDB::bind_method(D_METHOD("particles_restart", "particles"), &VisualServer::particles_restart);
  1623. ClassDB::bind_method(D_METHOD("particles_set_draw_order", "particles", "order"), &VisualServer::particles_set_draw_order);
  1624. ClassDB::bind_method(D_METHOD("particles_set_draw_passes", "particles", "count"), &VisualServer::particles_set_draw_passes);
  1625. ClassDB::bind_method(D_METHOD("particles_set_draw_pass_mesh", "particles", "pass", "mesh"), &VisualServer::particles_set_draw_pass_mesh);
  1626. ClassDB::bind_method(D_METHOD("particles_get_current_aabb", "particles"), &VisualServer::particles_get_current_aabb);
  1627. ClassDB::bind_method(D_METHOD("particles_set_emission_transform", "particles", "transform"), &VisualServer::particles_set_emission_transform);
  1628. ClassDB::bind_method(D_METHOD("camera_create"), &VisualServer::camera_create);
  1629. ClassDB::bind_method(D_METHOD("camera_set_perspective", "camera", "fovy_degrees", "z_near", "z_far"), &VisualServer::camera_set_perspective);
  1630. ClassDB::bind_method(D_METHOD("camera_set_orthogonal", "camera", "size", "z_near", "z_far"), &VisualServer::camera_set_orthogonal);
  1631. ClassDB::bind_method(D_METHOD("camera_set_frustum", "camera", "size", "offset", "z_near", "z_far"), &VisualServer::camera_set_frustum);
  1632. ClassDB::bind_method(D_METHOD("camera_set_transform", "camera", "transform"), &VisualServer::camera_set_transform);
  1633. ClassDB::bind_method(D_METHOD("camera_set_cull_mask", "camera", "layers"), &VisualServer::camera_set_cull_mask);
  1634. ClassDB::bind_method(D_METHOD("camera_set_environment", "camera", "env"), &VisualServer::camera_set_environment);
  1635. ClassDB::bind_method(D_METHOD("camera_set_use_vertical_aspect", "camera", "enable"), &VisualServer::camera_set_use_vertical_aspect);
  1636. ClassDB::bind_method(D_METHOD("viewport_create"), &VisualServer::viewport_create);
  1637. ClassDB::bind_method(D_METHOD("viewport_set_use_arvr", "viewport", "use_arvr"), &VisualServer::viewport_set_use_arvr);
  1638. ClassDB::bind_method(D_METHOD("viewport_set_size", "viewport", "width", "height"), &VisualServer::viewport_set_size);
  1639. ClassDB::bind_method(D_METHOD("viewport_set_active", "viewport", "active"), &VisualServer::viewport_set_active);
  1640. ClassDB::bind_method(D_METHOD("viewport_set_parent_viewport", "viewport", "parent_viewport"), &VisualServer::viewport_set_parent_viewport);
  1641. ClassDB::bind_method(D_METHOD("viewport_attach_to_screen", "viewport", "rect", "screen"), &VisualServer::viewport_attach_to_screen, DEFVAL(Rect2()), DEFVAL(0));
  1642. ClassDB::bind_method(D_METHOD("viewport_set_render_direct_to_screen", "viewport", "enabled"), &VisualServer::viewport_set_render_direct_to_screen);
  1643. ClassDB::bind_method(D_METHOD("viewport_detach", "viewport"), &VisualServer::viewport_detach);
  1644. ClassDB::bind_method(D_METHOD("viewport_set_update_mode", "viewport", "update_mode"), &VisualServer::viewport_set_update_mode);
  1645. ClassDB::bind_method(D_METHOD("viewport_set_vflip", "viewport", "enabled"), &VisualServer::viewport_set_vflip);
  1646. ClassDB::bind_method(D_METHOD("viewport_set_clear_mode", "viewport", "clear_mode"), &VisualServer::viewport_set_clear_mode);
  1647. ClassDB::bind_method(D_METHOD("viewport_get_texture", "viewport"), &VisualServer::viewport_get_texture);
  1648. ClassDB::bind_method(D_METHOD("viewport_set_hide_scenario", "viewport", "hidden"), &VisualServer::viewport_set_hide_scenario);
  1649. ClassDB::bind_method(D_METHOD("viewport_set_hide_canvas", "viewport", "hidden"), &VisualServer::viewport_set_hide_canvas);
  1650. ClassDB::bind_method(D_METHOD("viewport_set_disable_environment", "viewport", "disabled"), &VisualServer::viewport_set_disable_environment);
  1651. ClassDB::bind_method(D_METHOD("viewport_set_disable_3d", "viewport", "disabled"), &VisualServer::viewport_set_disable_3d);
  1652. ClassDB::bind_method(D_METHOD("viewport_attach_camera", "viewport", "camera"), &VisualServer::viewport_attach_camera);
  1653. ClassDB::bind_method(D_METHOD("viewport_set_scenario", "viewport", "scenario"), &VisualServer::viewport_set_scenario);
  1654. ClassDB::bind_method(D_METHOD("viewport_attach_canvas", "viewport", "canvas"), &VisualServer::viewport_attach_canvas);
  1655. ClassDB::bind_method(D_METHOD("viewport_remove_canvas", "viewport", "canvas"), &VisualServer::viewport_remove_canvas);
  1656. ClassDB::bind_method(D_METHOD("viewport_set_canvas_transform", "viewport", "canvas", "offset"), &VisualServer::viewport_set_canvas_transform);
  1657. ClassDB::bind_method(D_METHOD("viewport_set_transparent_background", "viewport", "enabled"), &VisualServer::viewport_set_transparent_background);
  1658. ClassDB::bind_method(D_METHOD("viewport_set_global_canvas_transform", "viewport", "transform"), &VisualServer::viewport_set_global_canvas_transform);
  1659. ClassDB::bind_method(D_METHOD("viewport_set_canvas_stacking", "viewport", "canvas", "layer", "sublayer"), &VisualServer::viewport_set_canvas_stacking);
  1660. ClassDB::bind_method(D_METHOD("viewport_set_shadow_atlas_size", "viewport", "size"), &VisualServer::viewport_set_shadow_atlas_size);
  1661. ClassDB::bind_method(D_METHOD("viewport_set_shadow_atlas_quadrant_subdivision", "viewport", "quadrant", "subdivision"), &VisualServer::viewport_set_shadow_atlas_quadrant_subdivision);
  1662. ClassDB::bind_method(D_METHOD("viewport_set_msaa", "viewport", "msaa"), &VisualServer::viewport_set_msaa);
  1663. ClassDB::bind_method(D_METHOD("viewport_set_use_fxaa", "viewport", "fxaa"), &VisualServer::viewport_set_use_fxaa);
  1664. ClassDB::bind_method(D_METHOD("viewport_set_use_debanding", "viewport", "debanding"), &VisualServer::viewport_set_use_debanding);
  1665. ClassDB::bind_method(D_METHOD("viewport_set_hdr", "viewport", "enabled"), &VisualServer::viewport_set_hdr);
  1666. ClassDB::bind_method(D_METHOD("viewport_set_usage", "viewport", "usage"), &VisualServer::viewport_set_usage);
  1667. ClassDB::bind_method(D_METHOD("viewport_get_render_info", "viewport", "info"), &VisualServer::viewport_get_render_info);
  1668. ClassDB::bind_method(D_METHOD("viewport_set_debug_draw", "viewport", "draw"), &VisualServer::viewport_set_debug_draw);
  1669. ClassDB::bind_method(D_METHOD("environment_create"), &VisualServer::environment_create);
  1670. ClassDB::bind_method(D_METHOD("environment_set_background", "env", "bg"), &VisualServer::environment_set_background);
  1671. ClassDB::bind_method(D_METHOD("environment_set_sky", "env", "sky"), &VisualServer::environment_set_sky);
  1672. ClassDB::bind_method(D_METHOD("environment_set_sky_custom_fov", "env", "scale"), &VisualServer::environment_set_sky_custom_fov);
  1673. ClassDB::bind_method(D_METHOD("environment_set_sky_orientation", "env", "orientation"), &VisualServer::environment_set_sky_orientation);
  1674. ClassDB::bind_method(D_METHOD("environment_set_bg_color", "env", "color"), &VisualServer::environment_set_bg_color);
  1675. ClassDB::bind_method(D_METHOD("environment_set_bg_energy", "env", "energy"), &VisualServer::environment_set_bg_energy);
  1676. ClassDB::bind_method(D_METHOD("environment_set_canvas_max_layer", "env", "max_layer"), &VisualServer::environment_set_canvas_max_layer);
  1677. ClassDB::bind_method(D_METHOD("environment_set_ambient_light", "env", "color", "energy", "sky_contibution"), &VisualServer::environment_set_ambient_light, DEFVAL(1.0), DEFVAL(0.0));
  1678. ClassDB::bind_method(D_METHOD("environment_set_dof_blur_near", "env", "enable", "distance", "transition", "far_amount", "quality"), &VisualServer::environment_set_dof_blur_near);
  1679. ClassDB::bind_method(D_METHOD("environment_set_dof_blur_far", "env", "enable", "distance", "transition", "far_amount", "quality"), &VisualServer::environment_set_dof_blur_far);
  1680. ClassDB::bind_method(D_METHOD("environment_set_glow", "env", "enable", "level_flags", "intensity", "strength", "bloom_threshold", "blend_mode", "hdr_bleed_threshold", "hdr_bleed_scale", "hdr_luminance_cap", "bicubic_upscale"), &VisualServer::environment_set_glow);
  1681. ClassDB::bind_method(D_METHOD("environment_set_tonemap", "env", "tone_mapper", "exposure", "white", "auto_exposure", "min_luminance", "max_luminance", "auto_exp_speed", "auto_exp_grey"), &VisualServer::environment_set_tonemap);
  1682. ClassDB::bind_method(D_METHOD("environment_set_adjustment", "env", "enable", "brightness", "contrast", "saturation", "ramp"), &VisualServer::environment_set_adjustment);
  1683. ClassDB::bind_method(D_METHOD("environment_set_ssr", "env", "enable", "max_steps", "fade_in", "fade_out", "depth_tolerance", "roughness"), &VisualServer::environment_set_ssr);
  1684. ClassDB::bind_method(D_METHOD("environment_set_ssao", "env", "enable", "radius", "intensity", "radius2", "intensity2", "bias", "light_affect", "ao_channel_affect", "color", "quality", "blur", "bilateral_sharpness"), &VisualServer::environment_set_ssao);
  1685. ClassDB::bind_method(D_METHOD("environment_set_fog", "env", "enable", "color", "sun_color", "sun_amount"), &VisualServer::environment_set_fog);
  1686. ClassDB::bind_method(D_METHOD("environment_set_fog_depth", "env", "enable", "depth_begin", "depth_end", "depth_curve", "transmit", "transmit_curve"), &VisualServer::environment_set_fog_depth);
  1687. ClassDB::bind_method(D_METHOD("environment_set_fog_height", "env", "enable", "min_height", "max_height", "height_curve"), &VisualServer::environment_set_fog_height);
  1688. ClassDB::bind_method(D_METHOD("scenario_create"), &VisualServer::scenario_create);
  1689. ClassDB::bind_method(D_METHOD("scenario_set_debug", "scenario", "debug_mode"), &VisualServer::scenario_set_debug);
  1690. ClassDB::bind_method(D_METHOD("scenario_set_environment", "scenario", "environment"), &VisualServer::scenario_set_environment);
  1691. ClassDB::bind_method(D_METHOD("scenario_set_reflection_atlas_size", "scenario", "size", "subdiv"), &VisualServer::scenario_set_reflection_atlas_size);
  1692. ClassDB::bind_method(D_METHOD("scenario_set_fallback_environment", "scenario", "environment"), &VisualServer::scenario_set_fallback_environment);
  1693. #ifndef _3D_DISABLED
  1694. ClassDB::bind_method(D_METHOD("instance_create2", "base", "scenario"), &VisualServer::instance_create2);
  1695. ClassDB::bind_method(D_METHOD("instance_create"), &VisualServer::instance_create);
  1696. ClassDB::bind_method(D_METHOD("instance_set_base", "instance", "base"), &VisualServer::instance_set_base);
  1697. ClassDB::bind_method(D_METHOD("instance_set_scenario", "instance", "scenario"), &VisualServer::instance_set_scenario);
  1698. ClassDB::bind_method(D_METHOD("instance_set_layer_mask", "instance", "mask"), &VisualServer::instance_set_layer_mask);
  1699. ClassDB::bind_method(D_METHOD("instance_set_transform", "instance", "transform"), &VisualServer::instance_set_transform);
  1700. ClassDB::bind_method(D_METHOD("instance_attach_object_instance_id", "instance", "id"), &VisualServer::instance_attach_object_instance_id);
  1701. ClassDB::bind_method(D_METHOD("instance_set_blend_shape_weight", "instance", "shape", "weight"), &VisualServer::instance_set_blend_shape_weight);
  1702. ClassDB::bind_method(D_METHOD("instance_set_surface_material", "instance", "surface", "material"), &VisualServer::instance_set_surface_material);
  1703. ClassDB::bind_method(D_METHOD("instance_set_visible", "instance", "visible"), &VisualServer::instance_set_visible);
  1704. ClassDB::bind_method(D_METHOD("instance_set_use_lightmap", "instance", "lightmap_instance", "lightmap", "lightmap_slice", "lightmap_uv_rect"), &VisualServer::instance_set_use_lightmap, DEFVAL(-1), DEFVAL(Rect2(0, 0, 1, 1)));
  1705. ClassDB::bind_method(D_METHOD("instance_set_custom_aabb", "instance", "aabb"), &VisualServer::instance_set_custom_aabb);
  1706. ClassDB::bind_method(D_METHOD("instance_attach_skeleton", "instance", "skeleton"), &VisualServer::instance_attach_skeleton);
  1707. ClassDB::bind_method(D_METHOD("instance_set_exterior", "instance", "enabled"), &VisualServer::instance_set_exterior);
  1708. ClassDB::bind_method(D_METHOD("instance_set_extra_visibility_margin", "instance", "margin"), &VisualServer::instance_set_extra_visibility_margin);
  1709. ClassDB::bind_method(D_METHOD("instance_geometry_set_flag", "instance", "flag", "enabled"), &VisualServer::instance_geometry_set_flag);
  1710. ClassDB::bind_method(D_METHOD("instance_geometry_set_cast_shadows_setting", "instance", "shadow_casting_setting"), &VisualServer::instance_geometry_set_cast_shadows_setting);
  1711. ClassDB::bind_method(D_METHOD("instance_geometry_set_material_override", "instance", "material"), &VisualServer::instance_geometry_set_material_override);
  1712. ClassDB::bind_method(D_METHOD("instance_geometry_set_draw_range", "instance", "min", "max", "min_margin", "max_margin"), &VisualServer::instance_geometry_set_draw_range);
  1713. ClassDB::bind_method(D_METHOD("instance_geometry_set_as_instance_lod", "instance", "as_lod_of_instance"), &VisualServer::instance_geometry_set_as_instance_lod);
  1714. ClassDB::bind_method(D_METHOD("instances_cull_aabb", "aabb", "scenario"), &VisualServer::_instances_cull_aabb_bind, DEFVAL(RID()));
  1715. ClassDB::bind_method(D_METHOD("instances_cull_ray", "from", "to", "scenario"), &VisualServer::_instances_cull_ray_bind, DEFVAL(RID()));
  1716. ClassDB::bind_method(D_METHOD("instances_cull_convex", "convex", "scenario"), &VisualServer::_instances_cull_convex_bind, DEFVAL(RID()));
  1717. #endif
  1718. ClassDB::bind_method(D_METHOD("canvas_create"), &VisualServer::canvas_create);
  1719. ClassDB::bind_method(D_METHOD("canvas_set_item_mirroring", "canvas", "item", "mirroring"), &VisualServer::canvas_set_item_mirroring);
  1720. ClassDB::bind_method(D_METHOD("canvas_set_modulate", "canvas", "color"), &VisualServer::canvas_set_modulate);
  1721. ClassDB::bind_method(D_METHOD("canvas_item_create"), &VisualServer::canvas_item_create);
  1722. ClassDB::bind_method(D_METHOD("canvas_item_set_parent", "item", "parent"), &VisualServer::canvas_item_set_parent);
  1723. ClassDB::bind_method(D_METHOD("canvas_item_set_visible", "item", "visible"), &VisualServer::canvas_item_set_visible);
  1724. ClassDB::bind_method(D_METHOD("canvas_item_set_light_mask", "item", "mask"), &VisualServer::canvas_item_set_light_mask);
  1725. ClassDB::bind_method(D_METHOD("canvas_item_set_transform", "item", "transform"), &VisualServer::canvas_item_set_transform);
  1726. ClassDB::bind_method(D_METHOD("canvas_item_set_clip", "item", "clip"), &VisualServer::canvas_item_set_clip);
  1727. ClassDB::bind_method(D_METHOD("canvas_item_set_distance_field_mode", "item", "enabled"), &VisualServer::canvas_item_set_distance_field_mode);
  1728. ClassDB::bind_method(D_METHOD("canvas_item_set_custom_rect", "item", "use_custom_rect", "rect"), &VisualServer::canvas_item_set_custom_rect, DEFVAL(Rect2()));
  1729. ClassDB::bind_method(D_METHOD("canvas_item_set_modulate", "item", "color"), &VisualServer::canvas_item_set_modulate);
  1730. ClassDB::bind_method(D_METHOD("canvas_item_set_self_modulate", "item", "color"), &VisualServer::canvas_item_set_self_modulate);
  1731. ClassDB::bind_method(D_METHOD("canvas_item_set_draw_behind_parent", "item", "enabled"), &VisualServer::canvas_item_set_draw_behind_parent);
  1732. ClassDB::bind_method(D_METHOD("canvas_item_add_line", "item", "from", "to", "color", "width", "antialiased"), &VisualServer::canvas_item_add_line, DEFVAL(1.0), DEFVAL(false));
  1733. ClassDB::bind_method(D_METHOD("canvas_item_add_polyline", "item", "points", "colors", "width", "antialiased"), &VisualServer::canvas_item_add_polyline, DEFVAL(1.0), DEFVAL(false));
  1734. ClassDB::bind_method(D_METHOD("canvas_item_add_rect", "item", "rect", "color"), &VisualServer::canvas_item_add_rect);
  1735. ClassDB::bind_method(D_METHOD("canvas_item_add_circle", "item", "pos", "radius", "color"), &VisualServer::canvas_item_add_circle);
  1736. ClassDB::bind_method(D_METHOD("canvas_item_add_texture_rect", "item", "rect", "texture", "tile", "modulate", "transpose", "normal_map"), &VisualServer::canvas_item_add_texture_rect, DEFVAL(false), DEFVAL(Color(1, 1, 1)), DEFVAL(false), DEFVAL(RID()));
  1737. ClassDB::bind_method(D_METHOD("canvas_item_add_texture_rect_region", "item", "rect", "texture", "src_rect", "modulate", "transpose", "normal_map", "clip_uv"), &VisualServer::canvas_item_add_texture_rect_region, DEFVAL(Color(1, 1, 1)), DEFVAL(false), DEFVAL(RID()), DEFVAL(true));
  1738. ClassDB::bind_method(D_METHOD("canvas_item_add_nine_patch", "item", "rect", "source", "texture", "topleft", "bottomright", "x_axis_mode", "y_axis_mode", "draw_center", "modulate", "normal_map"), &VisualServer::canvas_item_add_nine_patch, DEFVAL(NINE_PATCH_STRETCH), DEFVAL(NINE_PATCH_STRETCH), DEFVAL(true), DEFVAL(Color(1, 1, 1)), DEFVAL(RID()));
  1739. ClassDB::bind_method(D_METHOD("canvas_item_add_primitive", "item", "points", "colors", "uvs", "texture", "width", "normal_map"), &VisualServer::canvas_item_add_primitive, DEFVAL(1.0), DEFVAL(RID()));
  1740. ClassDB::bind_method(D_METHOD("canvas_item_add_polygon", "item", "points", "colors", "uvs", "texture", "normal_map", "antialiased"), &VisualServer::canvas_item_add_polygon, DEFVAL(Vector<Point2>()), DEFVAL(RID()), DEFVAL(RID()), DEFVAL(false));
  1741. ClassDB::bind_method(D_METHOD("canvas_item_add_triangle_array", "item", "indices", "points", "colors", "uvs", "bones", "weights", "texture", "count", "normal_map", "antialiased", "antialiasing_use_indices"), &VisualServer::canvas_item_add_triangle_array, DEFVAL(Vector<Point2>()), DEFVAL(Vector<int>()), DEFVAL(Vector<float>()), DEFVAL(RID()), DEFVAL(-1), DEFVAL(RID()), DEFVAL(false), DEFVAL(false));
  1742. ClassDB::bind_method(D_METHOD("canvas_item_add_mesh", "item", "mesh", "transform", "modulate", "texture", "normal_map"), &VisualServer::canvas_item_add_mesh, DEFVAL(Transform2D()), DEFVAL(Color(1, 1, 1)), DEFVAL(RID()), DEFVAL(RID()));
  1743. ClassDB::bind_method(D_METHOD("canvas_item_add_multimesh", "item", "mesh", "texture", "normal_map"), &VisualServer::canvas_item_add_multimesh, DEFVAL(RID()));
  1744. ClassDB::bind_method(D_METHOD("canvas_item_add_particles", "item", "particles", "texture", "normal_map"), &VisualServer::canvas_item_add_particles);
  1745. ClassDB::bind_method(D_METHOD("canvas_item_add_set_transform", "item", "transform"), &VisualServer::canvas_item_add_set_transform);
  1746. ClassDB::bind_method(D_METHOD("canvas_item_add_clip_ignore", "item", "ignore"), &VisualServer::canvas_item_add_clip_ignore);
  1747. ClassDB::bind_method(D_METHOD("canvas_item_set_sort_children_by_y", "item", "enabled"), &VisualServer::canvas_item_set_sort_children_by_y);
  1748. ClassDB::bind_method(D_METHOD("canvas_item_set_z_index", "item", "z_index"), &VisualServer::canvas_item_set_z_index);
  1749. ClassDB::bind_method(D_METHOD("canvas_item_set_z_as_relative_to_parent", "item", "enabled"), &VisualServer::canvas_item_set_z_as_relative_to_parent);
  1750. ClassDB::bind_method(D_METHOD("canvas_item_set_copy_to_backbuffer", "item", "enabled", "rect"), &VisualServer::canvas_item_set_copy_to_backbuffer);
  1751. ClassDB::bind_method(D_METHOD("canvas_item_clear", "item"), &VisualServer::canvas_item_clear);
  1752. ClassDB::bind_method(D_METHOD("canvas_item_set_draw_index", "item", "index"), &VisualServer::canvas_item_set_draw_index);
  1753. ClassDB::bind_method(D_METHOD("canvas_item_set_material", "item", "material"), &VisualServer::canvas_item_set_material);
  1754. ClassDB::bind_method(D_METHOD("canvas_item_set_use_parent_material", "item", "enabled"), &VisualServer::canvas_item_set_use_parent_material);
  1755. ClassDB::bind_method(D_METHOD("canvas_light_create"), &VisualServer::canvas_light_create);
  1756. ClassDB::bind_method(D_METHOD("canvas_light_attach_to_canvas", "light", "canvas"), &VisualServer::canvas_light_attach_to_canvas);
  1757. ClassDB::bind_method(D_METHOD("canvas_light_set_enabled", "light", "enabled"), &VisualServer::canvas_light_set_enabled);
  1758. ClassDB::bind_method(D_METHOD("canvas_light_set_scale", "light", "scale"), &VisualServer::canvas_light_set_scale);
  1759. ClassDB::bind_method(D_METHOD("canvas_light_set_transform", "light", "transform"), &VisualServer::canvas_light_set_transform);
  1760. ClassDB::bind_method(D_METHOD("canvas_light_set_texture", "light", "texture"), &VisualServer::canvas_light_set_texture);
  1761. ClassDB::bind_method(D_METHOD("canvas_light_set_texture_offset", "light", "offset"), &VisualServer::canvas_light_set_texture_offset);
  1762. ClassDB::bind_method(D_METHOD("canvas_light_set_color", "light", "color"), &VisualServer::canvas_light_set_color);
  1763. ClassDB::bind_method(D_METHOD("canvas_light_set_height", "light", "height"), &VisualServer::canvas_light_set_height);
  1764. ClassDB::bind_method(D_METHOD("canvas_light_set_energy", "light", "energy"), &VisualServer::canvas_light_set_energy);
  1765. ClassDB::bind_method(D_METHOD("canvas_light_set_z_range", "light", "min_z", "max_z"), &VisualServer::canvas_light_set_z_range);
  1766. ClassDB::bind_method(D_METHOD("canvas_light_set_layer_range", "light", "min_layer", "max_layer"), &VisualServer::canvas_light_set_layer_range);
  1767. ClassDB::bind_method(D_METHOD("canvas_light_set_item_cull_mask", "light", "mask"), &VisualServer::canvas_light_set_item_cull_mask);
  1768. ClassDB::bind_method(D_METHOD("canvas_light_set_item_shadow_cull_mask", "light", "mask"), &VisualServer::canvas_light_set_item_shadow_cull_mask);
  1769. ClassDB::bind_method(D_METHOD("canvas_light_set_mode", "light", "mode"), &VisualServer::canvas_light_set_mode);
  1770. ClassDB::bind_method(D_METHOD("canvas_light_set_shadow_enabled", "light", "enabled"), &VisualServer::canvas_light_set_shadow_enabled);
  1771. ClassDB::bind_method(D_METHOD("canvas_light_set_shadow_buffer_size", "light", "size"), &VisualServer::canvas_light_set_shadow_buffer_size);
  1772. ClassDB::bind_method(D_METHOD("canvas_light_set_shadow_gradient_length", "light", "length"), &VisualServer::canvas_light_set_shadow_gradient_length);
  1773. ClassDB::bind_method(D_METHOD("canvas_light_set_shadow_filter", "light", "filter"), &VisualServer::canvas_light_set_shadow_filter);
  1774. ClassDB::bind_method(D_METHOD("canvas_light_set_shadow_color", "light", "color"), &VisualServer::canvas_light_set_shadow_color);
  1775. ClassDB::bind_method(D_METHOD("canvas_light_set_shadow_smooth", "light", "smooth"), &VisualServer::canvas_light_set_shadow_smooth);
  1776. ClassDB::bind_method(D_METHOD("canvas_light_occluder_create"), &VisualServer::canvas_light_occluder_create);
  1777. ClassDB::bind_method(D_METHOD("canvas_light_occluder_attach_to_canvas", "occluder", "canvas"), &VisualServer::canvas_light_occluder_attach_to_canvas);
  1778. ClassDB::bind_method(D_METHOD("canvas_light_occluder_set_enabled", "occluder", "enabled"), &VisualServer::canvas_light_occluder_set_enabled);
  1779. ClassDB::bind_method(D_METHOD("canvas_light_occluder_set_polygon", "occluder", "polygon"), &VisualServer::canvas_light_occluder_set_polygon);
  1780. ClassDB::bind_method(D_METHOD("canvas_light_occluder_set_transform", "occluder", "transform"), &VisualServer::canvas_light_occluder_set_transform);
  1781. ClassDB::bind_method(D_METHOD("canvas_light_occluder_set_light_mask", "occluder", "mask"), &VisualServer::canvas_light_occluder_set_light_mask);
  1782. ClassDB::bind_method(D_METHOD("canvas_occluder_polygon_create"), &VisualServer::canvas_occluder_polygon_create);
  1783. ClassDB::bind_method(D_METHOD("canvas_occluder_polygon_set_shape", "occluder_polygon", "shape", "closed"), &VisualServer::canvas_occluder_polygon_set_shape);
  1784. ClassDB::bind_method(D_METHOD("canvas_occluder_polygon_set_shape_as_lines", "occluder_polygon", "shape"), &VisualServer::canvas_occluder_polygon_set_shape_as_lines);
  1785. ClassDB::bind_method(D_METHOD("canvas_occluder_polygon_set_cull_mode", "occluder_polygon", "mode"), &VisualServer::canvas_occluder_polygon_set_cull_mode);
  1786. ClassDB::bind_method(D_METHOD("black_bars_set_margins", "left", "top", "right", "bottom"), &VisualServer::black_bars_set_margins);
  1787. ClassDB::bind_method(D_METHOD("black_bars_set_images", "left", "top", "right", "bottom"), &VisualServer::black_bars_set_images);
  1788. ClassDB::bind_method(D_METHOD("free_rid", "rid"), &VisualServer::free); // shouldn't conflict with Object::free()
  1789. ClassDB::bind_method(D_METHOD("request_frame_drawn_callback", "where", "method", "userdata"), &VisualServer::request_frame_drawn_callback);
  1790. ClassDB::bind_method(D_METHOD("has_changed"), &VisualServer::has_changed);
  1791. ClassDB::bind_method(D_METHOD("init"), &VisualServer::init);
  1792. ClassDB::bind_method(D_METHOD("finish"), &VisualServer::finish);
  1793. ClassDB::bind_method(D_METHOD("get_render_info", "info"), &VisualServer::get_render_info);
  1794. ClassDB::bind_method(D_METHOD("get_video_adapter_name"), &VisualServer::get_video_adapter_name);
  1795. ClassDB::bind_method(D_METHOD("get_video_adapter_vendor"), &VisualServer::get_video_adapter_vendor);
  1796. #ifndef _3D_DISABLED
  1797. ClassDB::bind_method(D_METHOD("make_sphere_mesh", "latitudes", "longitudes", "radius"), &VisualServer::make_sphere_mesh);
  1798. ClassDB::bind_method(D_METHOD("get_test_cube"), &VisualServer::get_test_cube);
  1799. #endif
  1800. ClassDB::bind_method(D_METHOD("get_test_texture"), &VisualServer::get_test_texture);
  1801. ClassDB::bind_method(D_METHOD("get_white_texture"), &VisualServer::get_white_texture);
  1802. ClassDB::bind_method(D_METHOD("set_boot_image", "image", "color", "scale", "use_filter"), &VisualServer::set_boot_image, DEFVAL(true));
  1803. ClassDB::bind_method(D_METHOD("set_default_clear_color", "color"), &VisualServer::set_default_clear_color);
  1804. ClassDB::bind_method(D_METHOD("set_shader_time_scale", "scale"), &VisualServer::set_shader_time_scale);
  1805. ClassDB::bind_method(D_METHOD("has_feature", "feature"), &VisualServer::has_feature);
  1806. ClassDB::bind_method(D_METHOD("has_os_feature", "feature"), &VisualServer::has_os_feature);
  1807. ClassDB::bind_method(D_METHOD("set_debug_generate_wireframes", "generate"), &VisualServer::set_debug_generate_wireframes);
  1808. ClassDB::bind_method(D_METHOD("is_render_loop_enabled"), &VisualServer::is_render_loop_enabled);
  1809. ClassDB::bind_method(D_METHOD("set_render_loop_enabled", "enabled"), &VisualServer::set_render_loop_enabled);
  1810. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "render_loop_enabled"), "set_render_loop_enabled", "is_render_loop_enabled");
  1811. BIND_CONSTANT(NO_INDEX_ARRAY);
  1812. BIND_CONSTANT(ARRAY_WEIGHTS_SIZE);
  1813. BIND_CONSTANT(CANVAS_ITEM_Z_MIN);
  1814. BIND_CONSTANT(CANVAS_ITEM_Z_MAX);
  1815. BIND_CONSTANT(MAX_GLOW_LEVELS);
  1816. BIND_CONSTANT(MAX_CURSORS);
  1817. BIND_CONSTANT(MATERIAL_RENDER_PRIORITY_MIN);
  1818. BIND_CONSTANT(MATERIAL_RENDER_PRIORITY_MAX);
  1819. BIND_ENUM_CONSTANT(CUBEMAP_LEFT);
  1820. BIND_ENUM_CONSTANT(CUBEMAP_RIGHT);
  1821. BIND_ENUM_CONSTANT(CUBEMAP_BOTTOM);
  1822. BIND_ENUM_CONSTANT(CUBEMAP_TOP);
  1823. BIND_ENUM_CONSTANT(CUBEMAP_FRONT);
  1824. BIND_ENUM_CONSTANT(CUBEMAP_BACK);
  1825. BIND_ENUM_CONSTANT(TEXTURE_TYPE_2D);
  1826. BIND_ENUM_CONSTANT(TEXTURE_TYPE_CUBEMAP);
  1827. BIND_ENUM_CONSTANT(TEXTURE_TYPE_2D_ARRAY);
  1828. BIND_ENUM_CONSTANT(TEXTURE_TYPE_3D);
  1829. BIND_ENUM_CONSTANT(TEXTURE_FLAG_MIPMAPS);
  1830. BIND_ENUM_CONSTANT(TEXTURE_FLAG_REPEAT);
  1831. BIND_ENUM_CONSTANT(TEXTURE_FLAG_FILTER);
  1832. BIND_ENUM_CONSTANT(TEXTURE_FLAG_ANISOTROPIC_FILTER);
  1833. BIND_ENUM_CONSTANT(TEXTURE_FLAG_CONVERT_TO_LINEAR);
  1834. BIND_ENUM_CONSTANT(TEXTURE_FLAG_MIRRORED_REPEAT);
  1835. BIND_ENUM_CONSTANT(TEXTURE_FLAG_USED_FOR_STREAMING);
  1836. BIND_ENUM_CONSTANT(TEXTURE_FLAGS_DEFAULT);
  1837. BIND_ENUM_CONSTANT(SHADER_SPATIAL);
  1838. BIND_ENUM_CONSTANT(SHADER_CANVAS_ITEM);
  1839. BIND_ENUM_CONSTANT(SHADER_PARTICLES);
  1840. BIND_ENUM_CONSTANT(SHADER_MAX);
  1841. BIND_ENUM_CONSTANT(ARRAY_VERTEX);
  1842. BIND_ENUM_CONSTANT(ARRAY_NORMAL);
  1843. BIND_ENUM_CONSTANT(ARRAY_TANGENT);
  1844. BIND_ENUM_CONSTANT(ARRAY_COLOR);
  1845. BIND_ENUM_CONSTANT(ARRAY_TEX_UV);
  1846. BIND_ENUM_CONSTANT(ARRAY_TEX_UV2);
  1847. BIND_ENUM_CONSTANT(ARRAY_BONES);
  1848. BIND_ENUM_CONSTANT(ARRAY_WEIGHTS);
  1849. BIND_ENUM_CONSTANT(ARRAY_INDEX);
  1850. BIND_ENUM_CONSTANT(ARRAY_MAX);
  1851. BIND_ENUM_CONSTANT(ARRAY_FORMAT_VERTEX);
  1852. BIND_ENUM_CONSTANT(ARRAY_FORMAT_NORMAL);
  1853. BIND_ENUM_CONSTANT(ARRAY_FORMAT_TANGENT);
  1854. BIND_ENUM_CONSTANT(ARRAY_FORMAT_COLOR);
  1855. BIND_ENUM_CONSTANT(ARRAY_FORMAT_TEX_UV);
  1856. BIND_ENUM_CONSTANT(ARRAY_FORMAT_TEX_UV2);
  1857. BIND_ENUM_CONSTANT(ARRAY_FORMAT_BONES);
  1858. BIND_ENUM_CONSTANT(ARRAY_FORMAT_WEIGHTS);
  1859. BIND_ENUM_CONSTANT(ARRAY_FORMAT_INDEX);
  1860. BIND_ENUM_CONSTANT(ARRAY_COMPRESS_VERTEX);
  1861. BIND_ENUM_CONSTANT(ARRAY_COMPRESS_NORMAL);
  1862. BIND_ENUM_CONSTANT(ARRAY_COMPRESS_TANGENT);
  1863. BIND_ENUM_CONSTANT(ARRAY_COMPRESS_COLOR);
  1864. BIND_ENUM_CONSTANT(ARRAY_COMPRESS_TEX_UV);
  1865. BIND_ENUM_CONSTANT(ARRAY_COMPRESS_TEX_UV2);
  1866. BIND_ENUM_CONSTANT(ARRAY_COMPRESS_BONES);
  1867. BIND_ENUM_CONSTANT(ARRAY_COMPRESS_WEIGHTS);
  1868. BIND_ENUM_CONSTANT(ARRAY_COMPRESS_INDEX);
  1869. BIND_ENUM_CONSTANT(ARRAY_FLAG_USE_2D_VERTICES);
  1870. BIND_ENUM_CONSTANT(ARRAY_FLAG_USE_16_BIT_BONES);
  1871. BIND_ENUM_CONSTANT(ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION);
  1872. BIND_ENUM_CONSTANT(ARRAY_COMPRESS_DEFAULT);
  1873. BIND_ENUM_CONSTANT(PRIMITIVE_POINTS);
  1874. BIND_ENUM_CONSTANT(PRIMITIVE_LINES);
  1875. BIND_ENUM_CONSTANT(PRIMITIVE_LINE_STRIP);
  1876. BIND_ENUM_CONSTANT(PRIMITIVE_LINE_LOOP);
  1877. BIND_ENUM_CONSTANT(PRIMITIVE_TRIANGLES);
  1878. BIND_ENUM_CONSTANT(PRIMITIVE_TRIANGLE_STRIP);
  1879. BIND_ENUM_CONSTANT(PRIMITIVE_TRIANGLE_FAN);
  1880. BIND_ENUM_CONSTANT(PRIMITIVE_MAX);
  1881. BIND_ENUM_CONSTANT(BLEND_SHAPE_MODE_NORMALIZED);
  1882. BIND_ENUM_CONSTANT(BLEND_SHAPE_MODE_RELATIVE);
  1883. BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL);
  1884. BIND_ENUM_CONSTANT(LIGHT_OMNI);
  1885. BIND_ENUM_CONSTANT(LIGHT_SPOT);
  1886. BIND_ENUM_CONSTANT(LIGHT_PARAM_ENERGY);
  1887. BIND_ENUM_CONSTANT(LIGHT_PARAM_INDIRECT_ENERGY);
  1888. BIND_ENUM_CONSTANT(LIGHT_PARAM_SIZE);
  1889. BIND_ENUM_CONSTANT(LIGHT_PARAM_SPECULAR);
  1890. BIND_ENUM_CONSTANT(LIGHT_PARAM_RANGE);
  1891. BIND_ENUM_CONSTANT(LIGHT_PARAM_ATTENUATION);
  1892. BIND_ENUM_CONSTANT(LIGHT_PARAM_SPOT_ANGLE);
  1893. BIND_ENUM_CONSTANT(LIGHT_PARAM_SPOT_ATTENUATION);
  1894. BIND_ENUM_CONSTANT(LIGHT_PARAM_CONTACT_SHADOW_SIZE);
  1895. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_MAX_DISTANCE);
  1896. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_SPLIT_1_OFFSET);
  1897. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_SPLIT_2_OFFSET);
  1898. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_SPLIT_3_OFFSET);
  1899. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_NORMAL_BIAS);
  1900. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_BIAS);
  1901. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_BIAS_SPLIT_SCALE);
  1902. BIND_ENUM_CONSTANT(LIGHT_PARAM_MAX);
  1903. BIND_ENUM_CONSTANT(LIGHT_BAKE_DISABLED);
  1904. BIND_ENUM_CONSTANT(LIGHT_BAKE_INDIRECT);
  1905. BIND_ENUM_CONSTANT(LIGHT_BAKE_ALL);
  1906. BIND_ENUM_CONSTANT(LIGHT_OMNI_SHADOW_DUAL_PARABOLOID);
  1907. BIND_ENUM_CONSTANT(LIGHT_OMNI_SHADOW_CUBE);
  1908. BIND_ENUM_CONSTANT(LIGHT_OMNI_SHADOW_DETAIL_VERTICAL);
  1909. BIND_ENUM_CONSTANT(LIGHT_OMNI_SHADOW_DETAIL_HORIZONTAL);
  1910. BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL);
  1911. BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS);
  1912. BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS);
  1913. BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_STABLE);
  1914. BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_OPTIMIZED);
  1915. BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_DISABLED);
  1916. BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_ONCE);
  1917. BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_WHEN_VISIBLE);
  1918. BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_ALWAYS);
  1919. BIND_ENUM_CONSTANT(VIEWPORT_CLEAR_ALWAYS);
  1920. BIND_ENUM_CONSTANT(VIEWPORT_CLEAR_NEVER);
  1921. BIND_ENUM_CONSTANT(VIEWPORT_CLEAR_ONLY_NEXT_FRAME);
  1922. BIND_ENUM_CONSTANT(VIEWPORT_MSAA_DISABLED);
  1923. BIND_ENUM_CONSTANT(VIEWPORT_MSAA_2X);
  1924. BIND_ENUM_CONSTANT(VIEWPORT_MSAA_4X);
  1925. BIND_ENUM_CONSTANT(VIEWPORT_MSAA_8X);
  1926. BIND_ENUM_CONSTANT(VIEWPORT_MSAA_16X);
  1927. BIND_ENUM_CONSTANT(VIEWPORT_MSAA_EXT_2X);
  1928. BIND_ENUM_CONSTANT(VIEWPORT_MSAA_EXT_4X);
  1929. BIND_ENUM_CONSTANT(VIEWPORT_USAGE_2D);
  1930. BIND_ENUM_CONSTANT(VIEWPORT_USAGE_2D_NO_SAMPLING);
  1931. BIND_ENUM_CONSTANT(VIEWPORT_USAGE_3D);
  1932. BIND_ENUM_CONSTANT(VIEWPORT_USAGE_3D_NO_EFFECTS);
  1933. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_OBJECTS_IN_FRAME);
  1934. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_VERTICES_IN_FRAME);
  1935. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_MATERIAL_CHANGES_IN_FRAME);
  1936. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_SHADER_CHANGES_IN_FRAME);
  1937. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_SURFACE_CHANGES_IN_FRAME);
  1938. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_DRAW_CALLS_IN_FRAME);
  1939. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_2D_ITEMS_IN_FRAME);
  1940. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_2D_DRAW_CALLS_IN_FRAME);
  1941. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_MAX);
  1942. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_DISABLED);
  1943. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_UNSHADED);
  1944. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_OVERDRAW);
  1945. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_WIREFRAME);
  1946. BIND_ENUM_CONSTANT(SCENARIO_DEBUG_DISABLED);
  1947. BIND_ENUM_CONSTANT(SCENARIO_DEBUG_WIREFRAME);
  1948. BIND_ENUM_CONSTANT(SCENARIO_DEBUG_OVERDRAW);
  1949. BIND_ENUM_CONSTANT(SCENARIO_DEBUG_SHADELESS);
  1950. BIND_ENUM_CONSTANT(INSTANCE_NONE);
  1951. BIND_ENUM_CONSTANT(INSTANCE_MESH);
  1952. BIND_ENUM_CONSTANT(INSTANCE_MULTIMESH);
  1953. BIND_ENUM_CONSTANT(INSTANCE_IMMEDIATE);
  1954. BIND_ENUM_CONSTANT(INSTANCE_PARTICLES);
  1955. BIND_ENUM_CONSTANT(INSTANCE_LIGHT);
  1956. BIND_ENUM_CONSTANT(INSTANCE_REFLECTION_PROBE);
  1957. BIND_ENUM_CONSTANT(INSTANCE_GI_PROBE);
  1958. BIND_ENUM_CONSTANT(INSTANCE_LIGHTMAP_CAPTURE);
  1959. BIND_ENUM_CONSTANT(INSTANCE_MAX);
  1960. BIND_ENUM_CONSTANT(INSTANCE_GEOMETRY_MASK);
  1961. BIND_ENUM_CONSTANT(INSTANCE_FLAG_USE_BAKED_LIGHT);
  1962. BIND_ENUM_CONSTANT(INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE);
  1963. BIND_ENUM_CONSTANT(INSTANCE_FLAG_MAX);
  1964. BIND_ENUM_CONSTANT(SHADOW_CASTING_SETTING_OFF);
  1965. BIND_ENUM_CONSTANT(SHADOW_CASTING_SETTING_ON);
  1966. BIND_ENUM_CONSTANT(SHADOW_CASTING_SETTING_DOUBLE_SIDED);
  1967. BIND_ENUM_CONSTANT(SHADOW_CASTING_SETTING_SHADOWS_ONLY);
  1968. BIND_ENUM_CONSTANT(NINE_PATCH_STRETCH);
  1969. BIND_ENUM_CONSTANT(NINE_PATCH_TILE);
  1970. BIND_ENUM_CONSTANT(NINE_PATCH_TILE_FIT);
  1971. BIND_ENUM_CONSTANT(CANVAS_LIGHT_MODE_ADD);
  1972. BIND_ENUM_CONSTANT(CANVAS_LIGHT_MODE_SUB);
  1973. BIND_ENUM_CONSTANT(CANVAS_LIGHT_MODE_MIX);
  1974. BIND_ENUM_CONSTANT(CANVAS_LIGHT_MODE_MASK);
  1975. BIND_ENUM_CONSTANT(CANVAS_LIGHT_FILTER_NONE);
  1976. BIND_ENUM_CONSTANT(CANVAS_LIGHT_FILTER_PCF3);
  1977. BIND_ENUM_CONSTANT(CANVAS_LIGHT_FILTER_PCF5);
  1978. BIND_ENUM_CONSTANT(CANVAS_LIGHT_FILTER_PCF7);
  1979. BIND_ENUM_CONSTANT(CANVAS_LIGHT_FILTER_PCF9);
  1980. BIND_ENUM_CONSTANT(CANVAS_LIGHT_FILTER_PCF13);
  1981. BIND_ENUM_CONSTANT(CANVAS_OCCLUDER_POLYGON_CULL_DISABLED);
  1982. BIND_ENUM_CONSTANT(CANVAS_OCCLUDER_POLYGON_CULL_CLOCKWISE);
  1983. BIND_ENUM_CONSTANT(CANVAS_OCCLUDER_POLYGON_CULL_COUNTER_CLOCKWISE);
  1984. BIND_ENUM_CONSTANT(INFO_OBJECTS_IN_FRAME);
  1985. BIND_ENUM_CONSTANT(INFO_VERTICES_IN_FRAME);
  1986. BIND_ENUM_CONSTANT(INFO_MATERIAL_CHANGES_IN_FRAME);
  1987. BIND_ENUM_CONSTANT(INFO_SHADER_CHANGES_IN_FRAME);
  1988. BIND_ENUM_CONSTANT(INFO_SURFACE_CHANGES_IN_FRAME);
  1989. BIND_ENUM_CONSTANT(INFO_DRAW_CALLS_IN_FRAME);
  1990. BIND_ENUM_CONSTANT(INFO_2D_ITEMS_IN_FRAME);
  1991. BIND_ENUM_CONSTANT(INFO_2D_DRAW_CALLS_IN_FRAME);
  1992. BIND_ENUM_CONSTANT(INFO_USAGE_VIDEO_MEM_TOTAL);
  1993. BIND_ENUM_CONSTANT(INFO_VIDEO_MEM_USED);
  1994. BIND_ENUM_CONSTANT(INFO_TEXTURE_MEM_USED);
  1995. BIND_ENUM_CONSTANT(INFO_VERTEX_MEM_USED);
  1996. BIND_ENUM_CONSTANT(FEATURE_SHADERS);
  1997. BIND_ENUM_CONSTANT(FEATURE_MULTITHREADED);
  1998. BIND_ENUM_CONSTANT(MULTIMESH_TRANSFORM_2D);
  1999. BIND_ENUM_CONSTANT(MULTIMESH_TRANSFORM_3D);
  2000. BIND_ENUM_CONSTANT(MULTIMESH_COLOR_NONE);
  2001. BIND_ENUM_CONSTANT(MULTIMESH_COLOR_8BIT);
  2002. BIND_ENUM_CONSTANT(MULTIMESH_COLOR_FLOAT);
  2003. BIND_ENUM_CONSTANT(MULTIMESH_CUSTOM_DATA_NONE);
  2004. BIND_ENUM_CONSTANT(MULTIMESH_CUSTOM_DATA_8BIT);
  2005. BIND_ENUM_CONSTANT(MULTIMESH_CUSTOM_DATA_FLOAT);
  2006. BIND_ENUM_CONSTANT(REFLECTION_PROBE_UPDATE_ONCE);
  2007. BIND_ENUM_CONSTANT(REFLECTION_PROBE_UPDATE_ALWAYS);
  2008. BIND_ENUM_CONSTANT(PARTICLES_DRAW_ORDER_INDEX);
  2009. BIND_ENUM_CONSTANT(PARTICLES_DRAW_ORDER_LIFETIME);
  2010. BIND_ENUM_CONSTANT(PARTICLES_DRAW_ORDER_VIEW_DEPTH);
  2011. BIND_ENUM_CONSTANT(ENV_BG_CLEAR_COLOR);
  2012. BIND_ENUM_CONSTANT(ENV_BG_COLOR);
  2013. BIND_ENUM_CONSTANT(ENV_BG_SKY);
  2014. BIND_ENUM_CONSTANT(ENV_BG_COLOR_SKY);
  2015. BIND_ENUM_CONSTANT(ENV_BG_CANVAS);
  2016. BIND_ENUM_CONSTANT(ENV_BG_KEEP);
  2017. BIND_ENUM_CONSTANT(ENV_BG_MAX);
  2018. BIND_ENUM_CONSTANT(ENV_DOF_BLUR_QUALITY_LOW);
  2019. BIND_ENUM_CONSTANT(ENV_DOF_BLUR_QUALITY_MEDIUM);
  2020. BIND_ENUM_CONSTANT(ENV_DOF_BLUR_QUALITY_HIGH);
  2021. BIND_ENUM_CONSTANT(GLOW_BLEND_MODE_ADDITIVE);
  2022. BIND_ENUM_CONSTANT(GLOW_BLEND_MODE_SCREEN);
  2023. BIND_ENUM_CONSTANT(GLOW_BLEND_MODE_SOFTLIGHT);
  2024. BIND_ENUM_CONSTANT(GLOW_BLEND_MODE_REPLACE);
  2025. BIND_ENUM_CONSTANT(ENV_TONE_MAPPER_LINEAR);
  2026. BIND_ENUM_CONSTANT(ENV_TONE_MAPPER_REINHARD);
  2027. BIND_ENUM_CONSTANT(ENV_TONE_MAPPER_FILMIC);
  2028. BIND_ENUM_CONSTANT(ENV_TONE_MAPPER_ACES);
  2029. BIND_ENUM_CONSTANT(ENV_SSAO_QUALITY_LOW);
  2030. BIND_ENUM_CONSTANT(ENV_SSAO_QUALITY_MEDIUM);
  2031. BIND_ENUM_CONSTANT(ENV_SSAO_QUALITY_HIGH);
  2032. BIND_ENUM_CONSTANT(ENV_SSAO_BLUR_DISABLED);
  2033. BIND_ENUM_CONSTANT(ENV_SSAO_BLUR_1x1);
  2034. BIND_ENUM_CONSTANT(ENV_SSAO_BLUR_2x2);
  2035. BIND_ENUM_CONSTANT(ENV_SSAO_BLUR_3x3);
  2036. ADD_SIGNAL(MethodInfo("frame_pre_draw"));
  2037. ADD_SIGNAL(MethodInfo("frame_post_draw"));
  2038. }
  2039. void VisualServer::_canvas_item_add_style_box(RID p_item, const Rect2 &p_rect, const Rect2 &p_source, RID p_texture, const Vector<float> &p_margins, const Color &p_modulate) {
  2040. ERR_FAIL_COND(p_margins.size() != 4);
  2041. //canvas_item_add_style_box(p_item,p_rect,p_source,p_texture,Vector2(p_margins[0],p_margins[1]),Vector2(p_margins[2],p_margins[3]),true,p_modulate);
  2042. }
  2043. void VisualServer::_camera_set_orthogonal(RID p_camera, float p_size, float p_z_near, float p_z_far) {
  2044. camera_set_orthogonal(p_camera, p_size, p_z_near, p_z_far);
  2045. }
  2046. void VisualServer::mesh_add_surface_from_mesh_data(RID p_mesh, const Geometry::MeshData &p_mesh_data) {
  2047. PoolVector<Vector3> vertices;
  2048. PoolVector<Vector3> normals;
  2049. for (int i = 0; i < p_mesh_data.faces.size(); i++) {
  2050. const Geometry::MeshData::Face &f = p_mesh_data.faces[i];
  2051. for (int j = 2; j < f.indices.size(); j++) {
  2052. #define _ADD_VERTEX(m_idx) \
  2053. vertices.push_back(p_mesh_data.vertices[f.indices[m_idx]]); \
  2054. normals.push_back(f.plane.normal);
  2055. _ADD_VERTEX(0);
  2056. _ADD_VERTEX(j - 1);
  2057. _ADD_VERTEX(j);
  2058. }
  2059. }
  2060. Array d;
  2061. d.resize(VS::ARRAY_MAX);
  2062. d[ARRAY_VERTEX] = vertices;
  2063. d[ARRAY_NORMAL] = normals;
  2064. mesh_add_surface_from_arrays(p_mesh, PRIMITIVE_TRIANGLES, d);
  2065. }
  2066. void VisualServer::mesh_add_surface_from_planes(RID p_mesh, const PoolVector<Plane> &p_planes) {
  2067. Geometry::MeshData mdata = Geometry::build_convex_mesh(p_planes);
  2068. mesh_add_surface_from_mesh_data(p_mesh, mdata);
  2069. }
  2070. void VisualServer::immediate_vertex_2d(RID p_immediate, const Vector2 &p_vertex) {
  2071. immediate_vertex(p_immediate, Vector3(p_vertex.x, p_vertex.y, 0));
  2072. }
  2073. RID VisualServer::instance_create2(RID p_base, RID p_scenario) {
  2074. RID instance = instance_create();
  2075. instance_set_base(instance, p_base);
  2076. instance_set_scenario(instance, p_scenario);
  2077. // instance_create2 is used mainly by editor instances.
  2078. // These should not be culled by the portal system when it is active, so we set their mode to global,
  2079. // for frustum culling only.
  2080. instance_set_portal_mode(instance, VisualServer::INSTANCE_PORTAL_MODE_GLOBAL);
  2081. return instance;
  2082. }
  2083. bool VisualServer::is_render_loop_enabled() const {
  2084. return render_loop_enabled;
  2085. }
  2086. void VisualServer::set_render_loop_enabled(bool p_enabled) {
  2087. render_loop_enabled = p_enabled;
  2088. }
  2089. VisualServer::VisualServer() {
  2090. //ERR_FAIL_COND(singleton);
  2091. singleton = this;
  2092. GLOBAL_DEF_RST("rendering/vram_compression/import_bptc", false);
  2093. GLOBAL_DEF_RST("rendering/vram_compression/import_s3tc", true);
  2094. GLOBAL_DEF_RST("rendering/vram_compression/import_etc", false);
  2095. GLOBAL_DEF_RST("rendering/vram_compression/import_etc2", true);
  2096. GLOBAL_DEF_RST("rendering/vram_compression/import_pvrtc", false);
  2097. GLOBAL_DEF("rendering/lossless_compression/force_png", false);
  2098. GLOBAL_DEF("rendering/lossless_compression/webp_compression_level", 2);
  2099. ProjectSettings::get_singleton()->set_custom_property_info("rendering/lossless_compression/webp_compression_level", PropertyInfo(Variant::INT, "rendering/lossless_compression/webp_compression_level", PROPERTY_HINT_RANGE, "0,9,1"));
  2100. GLOBAL_DEF("rendering/limits/time/time_rollover_secs", 3600);
  2101. ProjectSettings::get_singleton()->set_custom_property_info("rendering/limits/time/time_rollover_secs", PropertyInfo(Variant::REAL, "rendering/limits/time/time_rollover_secs", PROPERTY_HINT_RANGE, "0,10000,1,or_greater"));
  2102. GLOBAL_DEF_RST("rendering/quality/directional_shadow/size", 4096);
  2103. GLOBAL_DEF("rendering/quality/directional_shadow/size.mobile", 2048);
  2104. ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/directional_shadow/size", PropertyInfo(Variant::INT, "rendering/quality/directional_shadow/size", PROPERTY_HINT_RANGE, "256,16384"));
  2105. GLOBAL_DEF_RST("rendering/quality/shadow_atlas/size", 4096);
  2106. GLOBAL_DEF("rendering/quality/shadow_atlas/size.mobile", 2048);
  2107. ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/shadow_atlas/size", PropertyInfo(Variant::INT, "rendering/quality/shadow_atlas/size", PROPERTY_HINT_RANGE, "256,16384"));
  2108. GLOBAL_DEF_RST("rendering/quality/shadow_atlas/cubemap_size", 512);
  2109. ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/shadow_atlas/cubemap_size", PropertyInfo(Variant::INT, "rendering/quality/shadow_atlas/cubemap_size", PROPERTY_HINT_RANGE, "64,16384"));
  2110. GLOBAL_DEF("rendering/quality/shadow_atlas/quadrant_0_subdiv", 1);
  2111. GLOBAL_DEF("rendering/quality/shadow_atlas/quadrant_1_subdiv", 2);
  2112. GLOBAL_DEF("rendering/quality/shadow_atlas/quadrant_2_subdiv", 3);
  2113. GLOBAL_DEF("rendering/quality/shadow_atlas/quadrant_3_subdiv", 4);
  2114. ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/shadow_atlas/quadrant_0_subdiv", PropertyInfo(Variant::INT, "rendering/quality/shadow_atlas/quadrant_0_subdiv", PROPERTY_HINT_ENUM, "Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"));
  2115. ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/shadow_atlas/quadrant_1_subdiv", PropertyInfo(Variant::INT, "rendering/quality/shadow_atlas/quadrant_1_subdiv", PROPERTY_HINT_ENUM, "Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"));
  2116. ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/shadow_atlas/quadrant_2_subdiv", PropertyInfo(Variant::INT, "rendering/quality/shadow_atlas/quadrant_2_subdiv", PROPERTY_HINT_ENUM, "Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"));
  2117. ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/shadow_atlas/quadrant_3_subdiv", PropertyInfo(Variant::INT, "rendering/quality/shadow_atlas/quadrant_3_subdiv", PROPERTY_HINT_ENUM, "Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"));
  2118. GLOBAL_DEF("rendering/quality/shadows/filter_mode", 1);
  2119. GLOBAL_DEF("rendering/quality/shadows/filter_mode.mobile", 0);
  2120. ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/shadows/filter_mode", PropertyInfo(Variant::INT, "rendering/quality/shadows/filter_mode", PROPERTY_HINT_ENUM, "Disabled,PCF5,PCF13"));
  2121. GLOBAL_DEF("rendering/quality/reflections/texture_array_reflections", true);
  2122. GLOBAL_DEF("rendering/quality/reflections/texture_array_reflections.mobile", false);
  2123. GLOBAL_DEF("rendering/quality/reflections/high_quality_ggx", true);
  2124. GLOBAL_DEF("rendering/quality/reflections/high_quality_ggx.mobile", false);
  2125. GLOBAL_DEF("rendering/quality/reflections/irradiance_max_size", 128);
  2126. ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/reflections/irradiance_max_size", PropertyInfo(Variant::INT, "rendering/quality/reflections/irradiance_max_size", PROPERTY_HINT_RANGE, "32,2048"));
  2127. GLOBAL_DEF("rendering/quality/shading/force_vertex_shading", false);
  2128. GLOBAL_DEF("rendering/quality/shading/force_vertex_shading.mobile", true);
  2129. GLOBAL_DEF("rendering/quality/shading/force_lambert_over_burley", false);
  2130. GLOBAL_DEF("rendering/quality/shading/force_lambert_over_burley.mobile", true);
  2131. GLOBAL_DEF("rendering/quality/shading/force_blinn_over_ggx", false);
  2132. GLOBAL_DEF("rendering/quality/shading/force_blinn_over_ggx.mobile", true);
  2133. GLOBAL_DEF("rendering/mesh_storage/split_stream", false);
  2134. GLOBAL_DEF("rendering/quality/depth_prepass/enable", true);
  2135. GLOBAL_DEF("rendering/quality/depth_prepass/disable_for_vendors", "PowerVR,Mali,Adreno,Apple");
  2136. GLOBAL_DEF("rendering/quality/filters/anisotropic_filter_level", 4);
  2137. ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/filters/anisotropic_filter_level", PropertyInfo(Variant::INT, "rendering/quality/filters/anisotropic_filter_level", PROPERTY_HINT_RANGE, "1,16,1"));
  2138. GLOBAL_DEF("rendering/quality/filters/use_nearest_mipmap_filter", false);
  2139. GLOBAL_DEF("rendering/quality/skinning/software_skinning_fallback", true);
  2140. GLOBAL_DEF("rendering/quality/skinning/force_software_skinning", false);
  2141. const char *sz_balance_render_tree = "rendering/quality/spatial_partitioning/render_tree_balance";
  2142. GLOBAL_DEF(sz_balance_render_tree, 0.0f);
  2143. ProjectSettings::get_singleton()->set_custom_property_info(sz_balance_render_tree, PropertyInfo(Variant::REAL, sz_balance_render_tree, PROPERTY_HINT_RANGE, "0.0,1.0,0.01"));
  2144. GLOBAL_DEF_RST("rendering/2d/options/use_software_skinning", true);
  2145. GLOBAL_DEF_RST("rendering/2d/options/ninepatch_mode", 1);
  2146. ProjectSettings::get_singleton()->set_custom_property_info("rendering/2d/options/ninepatch_mode", PropertyInfo(Variant::INT, "rendering/2d/options/ninepatch_mode", PROPERTY_HINT_ENUM, "Fixed,Scaling"));
  2147. GLOBAL_DEF_RST("rendering/2d/opengl/batching_send_null", 0);
  2148. ProjectSettings::get_singleton()->set_custom_property_info("rendering/2d/opengl/batching_send_null", PropertyInfo(Variant::INT, "rendering/2d/opengl/batching_send_null", PROPERTY_HINT_ENUM, "Default (On),Off,On"));
  2149. GLOBAL_DEF_RST("rendering/2d/opengl/batching_stream", 0);
  2150. ProjectSettings::get_singleton()->set_custom_property_info("rendering/2d/opengl/batching_stream", PropertyInfo(Variant::INT, "rendering/2d/opengl/batching_stream", PROPERTY_HINT_ENUM, "Default (Off),Off,On"));
  2151. GLOBAL_DEF_RST("rendering/2d/opengl/legacy_orphan_buffers", 0);
  2152. ProjectSettings::get_singleton()->set_custom_property_info("rendering/2d/opengl/legacy_orphan_buffers", PropertyInfo(Variant::INT, "rendering/2d/opengl/legacy_orphan_buffers", PROPERTY_HINT_ENUM, "Default (On),Off,On"));
  2153. GLOBAL_DEF_RST("rendering/2d/opengl/legacy_stream", 0);
  2154. ProjectSettings::get_singleton()->set_custom_property_info("rendering/2d/opengl/legacy_stream", PropertyInfo(Variant::INT, "rendering/2d/opengl/legacy_stream", PROPERTY_HINT_ENUM, "Default (On),Off,On"));
  2155. GLOBAL_DEF("rendering/batching/options/use_batching", true);
  2156. GLOBAL_DEF_RST("rendering/batching/options/use_batching_in_editor", true);
  2157. GLOBAL_DEF("rendering/batching/options/single_rect_fallback", false);
  2158. GLOBAL_DEF("rendering/batching/parameters/max_join_item_commands", 16);
  2159. GLOBAL_DEF("rendering/batching/parameters/colored_vertex_format_threshold", 0.25f);
  2160. GLOBAL_DEF("rendering/batching/lights/scissor_area_threshold", 1.0f);
  2161. GLOBAL_DEF("rendering/batching/lights/max_join_items", 32);
  2162. GLOBAL_DEF("rendering/batching/parameters/batch_buffer_size", 16384);
  2163. GLOBAL_DEF("rendering/batching/parameters/item_reordering_lookahead", 4);
  2164. GLOBAL_DEF("rendering/batching/debug/flash_batching", false);
  2165. GLOBAL_DEF("rendering/batching/debug/diagnose_frame", false);
  2166. GLOBAL_DEF("rendering/gles2/compatibility/disable_half_float", false);
  2167. GLOBAL_DEF("rendering/gles2/compatibility/enable_high_float.Android", false);
  2168. GLOBAL_DEF("rendering/batching/precision/uv_contract", false);
  2169. GLOBAL_DEF("rendering/batching/precision/uv_contract_amount", 100);
  2170. ProjectSettings::get_singleton()->set_custom_property_info("rendering/batching/parameters/max_join_item_commands", PropertyInfo(Variant::INT, "rendering/batching/parameters/max_join_item_commands", PROPERTY_HINT_RANGE, "0,65535"));
  2171. ProjectSettings::get_singleton()->set_custom_property_info("rendering/batching/parameters/colored_vertex_format_threshold", PropertyInfo(Variant::REAL, "rendering/batching/parameters/colored_vertex_format_threshold", PROPERTY_HINT_RANGE, "0.0,1.0,0.01"));
  2172. ProjectSettings::get_singleton()->set_custom_property_info("rendering/batching/parameters/batch_buffer_size", PropertyInfo(Variant::INT, "rendering/batching/parameters/batch_buffer_size", PROPERTY_HINT_RANGE, "1024,65535,1024"));
  2173. ProjectSettings::get_singleton()->set_custom_property_info("rendering/batching/lights/scissor_area_threshold", PropertyInfo(Variant::REAL, "rendering/batching/lights/scissor_area_threshold", PROPERTY_HINT_RANGE, "0.0,1.0"));
  2174. ProjectSettings::get_singleton()->set_custom_property_info("rendering/batching/lights/max_join_items", PropertyInfo(Variant::INT, "rendering/batching/lights/max_join_items", PROPERTY_HINT_RANGE, "0,512"));
  2175. ProjectSettings::get_singleton()->set_custom_property_info("rendering/batching/parameters/item_reordering_lookahead", PropertyInfo(Variant::INT, "rendering/batching/parameters/item_reordering_lookahead", PROPERTY_HINT_RANGE, "0,256"));
  2176. ProjectSettings::get_singleton()->set_custom_property_info("rendering/batching/precision/uv_contract_amount", PropertyInfo(Variant::INT, "rendering/batching/precision/uv_contract_amount", PROPERTY_HINT_RANGE, "0,10000"));
  2177. }
  2178. VisualServer::~VisualServer() {
  2179. singleton = nullptr;
  2180. }