visual_server.cpp 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259
  1. /*************************************************************************/
  2. /* visual_server.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2018 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 "method_bind_ext.gen.inc"
  32. #include "project_settings.h"
  33. VisualServer *VisualServer::singleton = NULL;
  34. VisualServer *(*VisualServer::create_func)() = NULL;
  35. VisualServer *VisualServer::get_singleton() {
  36. return singleton;
  37. }
  38. VisualServer *VisualServer::create() {
  39. ERR_FAIL_COND_V(singleton, NULL);
  40. if (create_func)
  41. return create_func();
  42. return NULL;
  43. }
  44. RID VisualServer::texture_create_from_image(const Ref<Image> &p_image, uint32_t p_flags) {
  45. ERR_FAIL_COND_V(!p_image.is_valid(), RID());
  46. RID texture = texture_create();
  47. texture_allocate(texture, p_image->get_width(), p_image->get_height(), p_image->get_format(), p_flags); //if it has mipmaps, use, else generate
  48. ERR_FAIL_COND_V(!texture.is_valid(), texture);
  49. texture_set_data(texture, p_image);
  50. return texture;
  51. }
  52. Array VisualServer::_texture_debug_usage_bind() {
  53. List<TextureInfo> list;
  54. texture_debug_usage(&list);
  55. Array arr;
  56. for (const List<TextureInfo>::Element *E = list.front(); E; E = E->next()) {
  57. Dictionary dict;
  58. dict["texture"] = E->get().texture;
  59. dict["size"] = E->get().size;
  60. dict["format"] = E->get().format;
  61. dict["bytes"] = E->get().bytes;
  62. dict["path"] = E->get().path;
  63. arr.push_back(dict);
  64. }
  65. return arr;
  66. }
  67. Array VisualServer::_shader_get_param_list_bind(RID p_shader) const {
  68. List<PropertyInfo> l;
  69. shader_get_param_list(p_shader, &l);
  70. return convert_property_list(&l);
  71. }
  72. static Array to_array(const Vector<ObjectID> &ids) {
  73. Array a;
  74. a.resize(ids.size());
  75. for (int i = 0; i < ids.size(); ++i) {
  76. a[i] = ids[i];
  77. }
  78. return a;
  79. }
  80. Array VisualServer::_instances_cull_aabb_bind(const AABB &p_aabb, RID p_scenario) const {
  81. Vector<ObjectID> ids = instances_cull_aabb(p_aabb, p_scenario);
  82. return to_array(ids);
  83. }
  84. Array VisualServer::_instances_cull_ray_bind(const Vector3 &p_from, const Vector3 &p_to, RID p_scenario) const {
  85. Vector<ObjectID> ids = instances_cull_ray(p_from, p_to, p_scenario);
  86. return to_array(ids);
  87. }
  88. Array VisualServer::_instances_cull_convex_bind(const Array &p_convex, RID p_scenario) const {
  89. Vector<Plane> planes;
  90. for (int i = 0; i < p_convex.size(); ++i) {
  91. Variant v = p_convex[i];
  92. ERR_FAIL_COND_V(v.get_type() != Variant::PLANE, Array());
  93. planes.push_back(v);
  94. }
  95. Vector<ObjectID> ids = instances_cull_convex(planes, p_scenario);
  96. return to_array(ids);
  97. }
  98. RID VisualServer::get_test_texture() {
  99. if (test_texture.is_valid()) {
  100. return test_texture;
  101. };
  102. #define TEST_TEXTURE_SIZE 256
  103. PoolVector<uint8_t> test_data;
  104. test_data.resize(TEST_TEXTURE_SIZE * TEST_TEXTURE_SIZE * 3);
  105. {
  106. PoolVector<uint8_t>::Write w = test_data.write();
  107. for (int x = 0; x < TEST_TEXTURE_SIZE; x++) {
  108. for (int y = 0; y < TEST_TEXTURE_SIZE; y++) {
  109. Color c;
  110. int r = 255 - (x + y) / 2;
  111. if ((x % (TEST_TEXTURE_SIZE / 8)) < 2 || (y % (TEST_TEXTURE_SIZE / 8)) < 2) {
  112. c.r = y;
  113. c.g = r;
  114. c.b = x;
  115. } else {
  116. c.r = r;
  117. c.g = x;
  118. c.b = y;
  119. }
  120. w[(y * TEST_TEXTURE_SIZE + x) * 3 + 0] = uint8_t(CLAMP(c.r * 255, 0, 255));
  121. w[(y * TEST_TEXTURE_SIZE + x) * 3 + 1] = uint8_t(CLAMP(c.g * 255, 0, 255));
  122. w[(y * TEST_TEXTURE_SIZE + x) * 3 + 2] = uint8_t(CLAMP(c.b * 255, 0, 255));
  123. }
  124. }
  125. }
  126. Ref<Image> data = memnew(Image(TEST_TEXTURE_SIZE, TEST_TEXTURE_SIZE, false, Image::FORMAT_RGB8, test_data));
  127. test_texture = texture_create_from_image(data);
  128. return test_texture;
  129. }
  130. void VisualServer::_free_internal_rids() {
  131. if (test_texture.is_valid())
  132. free(test_texture);
  133. if (white_texture.is_valid())
  134. free(white_texture);
  135. if (test_material.is_valid())
  136. free(test_material);
  137. }
  138. RID VisualServer::_make_test_cube() {
  139. PoolVector<Vector3> vertices;
  140. PoolVector<Vector3> normals;
  141. PoolVector<float> tangents;
  142. PoolVector<Vector3> uvs;
  143. int vtx_idx = 0;
  144. #define ADD_VTX(m_idx) \
  145. vertices.push_back(face_points[m_idx]); \
  146. normals.push_back(normal_points[m_idx]); \
  147. tangents.push_back(normal_points[m_idx][1]); \
  148. tangents.push_back(normal_points[m_idx][2]); \
  149. tangents.push_back(normal_points[m_idx][0]); \
  150. tangents.push_back(1.0); \
  151. uvs.push_back(Vector3(uv_points[m_idx * 2 + 0], uv_points[m_idx * 2 + 1], 0)); \
  152. vtx_idx++;
  153. for (int i = 0; i < 6; i++) {
  154. Vector3 face_points[4];
  155. Vector3 normal_points[4];
  156. float uv_points[8] = { 0, 0, 0, 1, 1, 1, 1, 0 };
  157. for (int j = 0; j < 4; j++) {
  158. float v[3];
  159. v[0] = 1.0;
  160. v[1] = 1 - 2 * ((j >> 1) & 1);
  161. v[2] = v[1] * (1 - 2 * (j & 1));
  162. for (int k = 0; k < 3; k++) {
  163. if (i < 3)
  164. face_points[j][(i + k) % 3] = v[k];
  165. else
  166. face_points[3 - j][(i + k) % 3] = -v[k];
  167. }
  168. normal_points[j] = Vector3();
  169. normal_points[j][i % 3] = (i >= 3 ? -1 : 1);
  170. }
  171. //tri 1
  172. ADD_VTX(0);
  173. ADD_VTX(1);
  174. ADD_VTX(2);
  175. //tri 2
  176. ADD_VTX(2);
  177. ADD_VTX(3);
  178. ADD_VTX(0);
  179. }
  180. RID test_cube = mesh_create();
  181. Array d;
  182. d.resize(VS::ARRAY_MAX);
  183. d[VisualServer::ARRAY_NORMAL] = normals;
  184. d[VisualServer::ARRAY_TANGENT] = tangents;
  185. d[VisualServer::ARRAY_TEX_UV] = uvs;
  186. d[VisualServer::ARRAY_VERTEX] = vertices;
  187. PoolVector<int> indices;
  188. indices.resize(vertices.size());
  189. for (int i = 0; i < vertices.size(); i++)
  190. indices.set(i, i);
  191. d[VisualServer::ARRAY_INDEX] = indices;
  192. mesh_add_surface_from_arrays(test_cube, PRIMITIVE_TRIANGLES, d);
  193. /*
  194. test_material = fixed_material_create();
  195. //material_set_flag(material, MATERIAL_FLAG_BILLBOARD_TOGGLE,true);
  196. fixed_material_set_texture( test_material, FIXED_MATERIAL_PARAM_DIFFUSE, get_test_texture() );
  197. fixed_material_set_param( test_material, FIXED_MATERIAL_PARAM_SPECULAR_EXP, 70 );
  198. fixed_material_set_param( test_material, FIXED_MATERIAL_PARAM_EMISSION, Color(0.2,0.2,0.2) );
  199. fixed_material_set_param( test_material, FIXED_MATERIAL_PARAM_DIFFUSE, Color(1, 1, 1) );
  200. fixed_material_set_param( test_material, FIXED_MATERIAL_PARAM_SPECULAR, Color(1,1,1) );
  201. */
  202. mesh_surface_set_material(test_cube, 0, test_material);
  203. return test_cube;
  204. }
  205. RID VisualServer::make_sphere_mesh(int p_lats, int p_lons, float p_radius) {
  206. PoolVector<Vector3> vertices;
  207. PoolVector<Vector3> normals;
  208. for (int i = 1; i <= p_lats; i++) {
  209. double lat0 = Math_PI * (-0.5 + (double)(i - 1) / p_lats);
  210. double z0 = Math::sin(lat0);
  211. double zr0 = Math::cos(lat0);
  212. double lat1 = Math_PI * (-0.5 + (double)i / p_lats);
  213. double z1 = Math::sin(lat1);
  214. double zr1 = Math::cos(lat1);
  215. for (int j = p_lons; j >= 1; j--) {
  216. double lng0 = 2 * Math_PI * (double)(j - 1) / p_lons;
  217. double x0 = Math::cos(lng0);
  218. double y0 = Math::sin(lng0);
  219. double lng1 = 2 * Math_PI * (double)(j) / p_lons;
  220. double x1 = Math::cos(lng1);
  221. double y1 = Math::sin(lng1);
  222. Vector3 v[4] = {
  223. Vector3(x1 * zr0, z0, y1 * zr0),
  224. Vector3(x1 * zr1, z1, y1 * zr1),
  225. Vector3(x0 * zr1, z1, y0 * zr1),
  226. Vector3(x0 * zr0, z0, y0 * zr0)
  227. };
  228. #define ADD_POINT(m_idx) \
  229. normals.push_back(v[m_idx]); \
  230. vertices.push_back(v[m_idx] * p_radius);
  231. ADD_POINT(0);
  232. ADD_POINT(1);
  233. ADD_POINT(2);
  234. ADD_POINT(2);
  235. ADD_POINT(3);
  236. ADD_POINT(0);
  237. }
  238. }
  239. RID mesh = mesh_create();
  240. Array d;
  241. d.resize(VS::ARRAY_MAX);
  242. d[ARRAY_VERTEX] = vertices;
  243. d[ARRAY_NORMAL] = normals;
  244. mesh_add_surface_from_arrays(mesh, PRIMITIVE_TRIANGLES, d);
  245. return mesh;
  246. }
  247. RID VisualServer::get_white_texture() {
  248. if (white_texture.is_valid())
  249. return white_texture;
  250. PoolVector<uint8_t> wt;
  251. wt.resize(16 * 3);
  252. {
  253. PoolVector<uint8_t>::Write w = wt.write();
  254. for (int i = 0; i < 16 * 3; i++)
  255. w[i] = 255;
  256. }
  257. Ref<Image> white = memnew(Image(4, 4, 0, Image::FORMAT_RGB8, wt));
  258. white_texture = texture_create();
  259. texture_allocate(white_texture, 4, 4, Image::FORMAT_RGB8);
  260. texture_set_data(white_texture, white);
  261. return white_texture;
  262. }
  263. #define SMALL_VEC2 Vector2(0.00001, 0.00001)
  264. #define SMALL_VEC3 Vector3(0.00001, 0.00001, 0.00001)
  265. 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) {
  266. PoolVector<uint8_t>::Write vw = r_vertex_array.write();
  267. PoolVector<uint8_t>::Write iw;
  268. if (r_index_array.size()) {
  269. iw = r_index_array.write();
  270. }
  271. int max_bone = 0;
  272. for (int ai = 0; ai < VS::ARRAY_MAX; ai++) {
  273. if (!(p_format & (1 << ai))) // no array
  274. continue;
  275. switch (ai) {
  276. case VS::ARRAY_VERTEX: {
  277. if (p_format & VS::ARRAY_FLAG_USE_2D_VERTICES) {
  278. PoolVector<Vector2> array = p_arrays[ai];
  279. ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
  280. PoolVector<Vector2>::Read read = array.read();
  281. const Vector2 *src = read.ptr();
  282. // setting vertices means regenerating the AABB
  283. Rect2 aabb;
  284. if (p_format & ARRAY_COMPRESS_VERTEX) {
  285. for (int i = 0; i < p_vertex_array_len; i++) {
  286. uint16_t vector[2] = { Math::make_half_float(src[i].x), Math::make_half_float(src[i].y) };
  287. copymem(&vw[p_offsets[ai] + i * p_stride], vector, sizeof(uint16_t) * 2);
  288. if (i == 0) {
  289. aabb = Rect2(src[i], SMALL_VEC2); //must have a bit of size
  290. } else {
  291. aabb.expand_to(src[i]);
  292. }
  293. }
  294. } else {
  295. for (int i = 0; i < p_vertex_array_len; i++) {
  296. float vector[2] = { src[i].x, src[i].y };
  297. copymem(&vw[p_offsets[ai] + i * p_stride], vector, sizeof(float) * 2);
  298. if (i == 0) {
  299. aabb = Rect2(src[i], SMALL_VEC2); //must have a bit of size
  300. } else {
  301. aabb.expand_to(src[i]);
  302. }
  303. }
  304. }
  305. r_aabb = AABB(Vector3(aabb.position.x, aabb.position.y, 0), Vector3(aabb.size.x, aabb.size.y, 0));
  306. } else {
  307. PoolVector<Vector3> array = p_arrays[ai];
  308. ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
  309. PoolVector<Vector3>::Read read = array.read();
  310. const Vector3 *src = read.ptr();
  311. // setting vertices means regenerating the AABB
  312. AABB aabb;
  313. if (p_format & ARRAY_COMPRESS_VERTEX) {
  314. for (int i = 0; i < p_vertex_array_len; i++) {
  315. 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) };
  316. copymem(&vw[p_offsets[ai] + i * p_stride], vector, sizeof(uint16_t) * 4);
  317. if (i == 0) {
  318. aabb = AABB(src[i], SMALL_VEC3);
  319. } else {
  320. aabb.expand_to(src[i]);
  321. }
  322. }
  323. } else {
  324. for (int i = 0; i < p_vertex_array_len; i++) {
  325. float vector[3] = { src[i].x, src[i].y, src[i].z };
  326. copymem(&vw[p_offsets[ai] + i * p_stride], vector, sizeof(float) * 3);
  327. if (i == 0) {
  328. aabb = AABB(src[i], SMALL_VEC3);
  329. } else {
  330. aabb.expand_to(src[i]);
  331. }
  332. }
  333. }
  334. r_aabb = aabb;
  335. }
  336. } break;
  337. case VS::ARRAY_NORMAL: {
  338. ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::POOL_VECTOR3_ARRAY, ERR_INVALID_PARAMETER);
  339. PoolVector<Vector3> array = p_arrays[ai];
  340. ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
  341. PoolVector<Vector3>::Read read = array.read();
  342. const Vector3 *src = read.ptr();
  343. // setting vertices means regenerating the AABB
  344. if (p_format & ARRAY_COMPRESS_NORMAL) {
  345. for (int i = 0; i < p_vertex_array_len; i++) {
  346. int8_t vector[4] = {
  347. (int8_t)CLAMP(src[i].x * 127, -128, 127),
  348. (int8_t)CLAMP(src[i].y * 127, -128, 127),
  349. (int8_t)CLAMP(src[i].z * 127, -128, 127),
  350. 0,
  351. };
  352. copymem(&vw[p_offsets[ai] + i * p_stride], vector, 4);
  353. }
  354. } else {
  355. for (int i = 0; i < p_vertex_array_len; i++) {
  356. float vector[3] = { src[i].x, src[i].y, src[i].z };
  357. copymem(&vw[p_offsets[ai] + i * p_stride], vector, 3 * 4);
  358. }
  359. }
  360. } break;
  361. case VS::ARRAY_TANGENT: {
  362. ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::POOL_REAL_ARRAY, ERR_INVALID_PARAMETER);
  363. PoolVector<real_t> array = p_arrays[ai];
  364. ERR_FAIL_COND_V(array.size() != p_vertex_array_len * 4, ERR_INVALID_PARAMETER);
  365. PoolVector<real_t>::Read read = array.read();
  366. const real_t *src = read.ptr();
  367. if (p_format & ARRAY_COMPRESS_TANGENT) {
  368. for (int i = 0; i < p_vertex_array_len; i++) {
  369. uint8_t xyzw[4] = {
  370. (uint8_t)CLAMP(src[i * 4 + 0] * 127, -128, 127),
  371. (uint8_t)CLAMP(src[i * 4 + 1] * 127, -128, 127),
  372. (uint8_t)CLAMP(src[i * 4 + 2] * 127, -128, 127),
  373. (uint8_t)CLAMP(src[i * 4 + 3] * 127, -128, 127)
  374. };
  375. copymem(&vw[p_offsets[ai] + i * p_stride], xyzw, 4);
  376. }
  377. } else {
  378. for (int i = 0; i < p_vertex_array_len; i++) {
  379. float xyzw[4] = {
  380. src[i * 4 + 0],
  381. src[i * 4 + 1],
  382. src[i * 4 + 2],
  383. src[i * 4 + 3]
  384. };
  385. copymem(&vw[p_offsets[ai] + i * p_stride], xyzw, 4 * 4);
  386. }
  387. }
  388. } break;
  389. case VS::ARRAY_COLOR: {
  390. ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::POOL_COLOR_ARRAY, ERR_INVALID_PARAMETER);
  391. PoolVector<Color> array = p_arrays[ai];
  392. ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
  393. PoolVector<Color>::Read read = array.read();
  394. const Color *src = read.ptr();
  395. if (p_format & ARRAY_COMPRESS_COLOR) {
  396. for (int i = 0; i < p_vertex_array_len; i++) {
  397. uint8_t colors[4];
  398. for (int j = 0; j < 4; j++) {
  399. colors[j] = CLAMP(int((src[i][j]) * 255.0), 0, 255);
  400. }
  401. copymem(&vw[p_offsets[ai] + i * p_stride], colors, 4);
  402. }
  403. } else {
  404. for (int i = 0; i < p_vertex_array_len; i++) {
  405. copymem(&vw[p_offsets[ai] + i * p_stride], &src[i], 4 * 4);
  406. }
  407. }
  408. } break;
  409. case VS::ARRAY_TEX_UV: {
  410. 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);
  411. PoolVector<Vector2> array = p_arrays[ai];
  412. ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
  413. PoolVector<Vector2>::Read read = array.read();
  414. const Vector2 *src = read.ptr();
  415. if (p_format & ARRAY_COMPRESS_TEX_UV) {
  416. for (int i = 0; i < p_vertex_array_len; i++) {
  417. uint16_t uv[2] = { Math::make_half_float(src[i].x), Math::make_half_float(src[i].y) };
  418. copymem(&vw[p_offsets[ai] + i * p_stride], uv, 2 * 2);
  419. }
  420. } else {
  421. for (int i = 0; i < p_vertex_array_len; i++) {
  422. float uv[2] = { src[i].x, src[i].y };
  423. copymem(&vw[p_offsets[ai] + i * p_stride], uv, 2 * 4);
  424. }
  425. }
  426. } break;
  427. case VS::ARRAY_TEX_UV2: {
  428. 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);
  429. PoolVector<Vector2> array = p_arrays[ai];
  430. ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
  431. PoolVector<Vector2>::Read read = array.read();
  432. const Vector2 *src = read.ptr();
  433. if (p_format & ARRAY_COMPRESS_TEX_UV2) {
  434. for (int i = 0; i < p_vertex_array_len; i++) {
  435. uint16_t uv[2] = { Math::make_half_float(src[i].x), Math::make_half_float(src[i].y) };
  436. copymem(&vw[p_offsets[ai] + i * p_stride], uv, 2 * 2);
  437. }
  438. } else {
  439. for (int i = 0; i < p_vertex_array_len; i++) {
  440. float uv[2] = { src[i].x, src[i].y };
  441. copymem(&vw[p_offsets[ai] + i * p_stride], uv, 2 * 4);
  442. }
  443. }
  444. } break;
  445. case VS::ARRAY_WEIGHTS: {
  446. ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::POOL_REAL_ARRAY, ERR_INVALID_PARAMETER);
  447. PoolVector<real_t> array = p_arrays[ai];
  448. ERR_FAIL_COND_V(array.size() != p_vertex_array_len * VS::ARRAY_WEIGHTS_SIZE, ERR_INVALID_PARAMETER);
  449. PoolVector<real_t>::Read read = array.read();
  450. const real_t *src = read.ptr();
  451. if (p_format & ARRAY_COMPRESS_WEIGHTS) {
  452. for (int i = 0; i < p_vertex_array_len; i++) {
  453. uint16_t data[VS::ARRAY_WEIGHTS_SIZE];
  454. for (int j = 0; j < VS::ARRAY_WEIGHTS_SIZE; j++) {
  455. data[j] = CLAMP(src[i * VS::ARRAY_WEIGHTS_SIZE + j] * 65535, 0, 65535);
  456. }
  457. copymem(&vw[p_offsets[ai] + i * p_stride], data, 2 * 4);
  458. }
  459. } else {
  460. for (int i = 0; i < p_vertex_array_len; i++) {
  461. float data[VS::ARRAY_WEIGHTS_SIZE];
  462. for (int j = 0; j < VS::ARRAY_WEIGHTS_SIZE; j++) {
  463. data[j] = src[i * VS::ARRAY_WEIGHTS_SIZE + j];
  464. }
  465. copymem(&vw[p_offsets[ai] + i * p_stride], data, 4 * 4);
  466. }
  467. }
  468. } break;
  469. case VS::ARRAY_BONES: {
  470. 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);
  471. PoolVector<int> array = p_arrays[ai];
  472. ERR_FAIL_COND_V(array.size() != p_vertex_array_len * VS::ARRAY_WEIGHTS_SIZE, ERR_INVALID_PARAMETER);
  473. PoolVector<int>::Read read = array.read();
  474. const int *src = read.ptr();
  475. if (!(p_format & ARRAY_FLAG_USE_16_BIT_BONES)) {
  476. for (int i = 0; i < p_vertex_array_len; i++) {
  477. uint8_t data[VS::ARRAY_WEIGHTS_SIZE];
  478. for (int j = 0; j < VS::ARRAY_WEIGHTS_SIZE; j++) {
  479. data[j] = CLAMP(src[i * VS::ARRAY_WEIGHTS_SIZE + j], 0, 255);
  480. max_bone = MAX(data[j], max_bone);
  481. }
  482. copymem(&vw[p_offsets[ai] + i * p_stride], data, 4);
  483. }
  484. } else {
  485. for (int i = 0; i < p_vertex_array_len; i++) {
  486. uint16_t data[VS::ARRAY_WEIGHTS_SIZE];
  487. for (int j = 0; j < VS::ARRAY_WEIGHTS_SIZE; j++) {
  488. data[j] = src[i * VS::ARRAY_WEIGHTS_SIZE + j];
  489. max_bone = MAX(data[j], max_bone);
  490. }
  491. copymem(&vw[p_offsets[ai] + i * p_stride], data, 2 * 4);
  492. }
  493. }
  494. } break;
  495. case VS::ARRAY_INDEX: {
  496. ERR_FAIL_COND_V(p_index_array_len <= 0, ERR_INVALID_DATA);
  497. ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::POOL_INT_ARRAY, ERR_INVALID_PARAMETER);
  498. PoolVector<int> indices = p_arrays[ai];
  499. ERR_FAIL_COND_V(indices.size() == 0, ERR_INVALID_PARAMETER);
  500. ERR_FAIL_COND_V(indices.size() != p_index_array_len, ERR_INVALID_PARAMETER);
  501. /* determine whether using 16 or 32 bits indices */
  502. PoolVector<int>::Read read = indices.read();
  503. const int *src = read.ptr();
  504. for (int i = 0; i < p_index_array_len; i++) {
  505. if (p_vertex_array_len < (1 << 16)) {
  506. uint16_t v = src[i];
  507. copymem(&iw[i * 2], &v, 2);
  508. } else {
  509. uint32_t v = src[i];
  510. copymem(&iw[i * 4], &v, 4);
  511. }
  512. }
  513. } break;
  514. default: {
  515. ERR_FAIL_V(ERR_INVALID_DATA);
  516. }
  517. }
  518. }
  519. if (p_format & VS::ARRAY_FORMAT_BONES) {
  520. //create AABBs for each detected bone
  521. int total_bones = max_bone + 1;
  522. bool first = r_bone_aabb.size() == 0;
  523. r_bone_aabb.resize(total_bones);
  524. if (first) {
  525. for (int i = 0; i < total_bones; i++) {
  526. r_bone_aabb[i].size = Vector3(-1, -1, -1); //negative means unused
  527. }
  528. }
  529. PoolVector<Vector3> vertices = p_arrays[VS::ARRAY_VERTEX];
  530. PoolVector<int> bones = p_arrays[VS::ARRAY_BONES];
  531. PoolVector<float> weights = p_arrays[VS::ARRAY_WEIGHTS];
  532. bool any_valid = false;
  533. if (vertices.size() && bones.size() == vertices.size() * 4 && weights.size() == bones.size()) {
  534. int vs = vertices.size();
  535. PoolVector<Vector3>::Read rv = vertices.read();
  536. PoolVector<int>::Read rb = bones.read();
  537. PoolVector<float>::Read rw = weights.read();
  538. AABB *bptr = r_bone_aabb.ptrw();
  539. for (int i = 0; i < vs; i++) {
  540. Vector3 v = rv[i];
  541. for (int j = 0; j < 4; j++) {
  542. int idx = rb[i * 4 + j];
  543. float w = rw[i * 4 + j];
  544. if (w == 0)
  545. continue; //break;
  546. ERR_FAIL_INDEX_V(idx, total_bones, ERR_INVALID_DATA);
  547. if (bptr->size.x < 0) {
  548. //first
  549. bptr[idx] = AABB(v, SMALL_VEC3);
  550. any_valid = true;
  551. } else {
  552. bptr[idx].expand_to(v);
  553. }
  554. }
  555. }
  556. }
  557. if (!any_valid && first) {
  558. r_bone_aabb.clear();
  559. }
  560. }
  561. return OK;
  562. }
  563. 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) {
  564. ERR_FAIL_INDEX(p_primitive, VS::PRIMITIVE_MAX);
  565. ERR_FAIL_COND(p_arrays.size() != VS::ARRAY_MAX);
  566. uint32_t format = 0;
  567. // validation
  568. int index_array_len = 0;
  569. int array_len = 0;
  570. for (int i = 0; i < p_arrays.size(); i++) {
  571. if (p_arrays[i].get_type() == Variant::NIL)
  572. continue;
  573. format |= (1 << i);
  574. if (i == VS::ARRAY_VERTEX) {
  575. Variant var = p_arrays[i];
  576. switch (var.get_type()) {
  577. case Variant::POOL_VECTOR2_ARRAY: {
  578. PoolVector<Vector2> v2 = var;
  579. array_len = v2.size();
  580. } break;
  581. case Variant::POOL_VECTOR3_ARRAY: {
  582. PoolVector<Vector3> v3 = var;
  583. array_len = v3.size();
  584. } break;
  585. default: {
  586. Array v = var;
  587. array_len = v.size();
  588. } break;
  589. }
  590. array_len = PoolVector3Array(p_arrays[i]).size();
  591. ERR_FAIL_COND(array_len == 0);
  592. } else if (i == VS::ARRAY_INDEX) {
  593. index_array_len = PoolIntArray(p_arrays[i]).size();
  594. }
  595. }
  596. ERR_FAIL_COND((format & VS::ARRAY_FORMAT_VERTEX) == 0); // mandatory
  597. if (p_blend_shapes.size()) {
  598. //validate format for morphs
  599. for (int i = 0; i < p_blend_shapes.size(); i++) {
  600. uint32_t bsformat = 0;
  601. Array arr = p_blend_shapes[i];
  602. for (int j = 0; j < arr.size(); j++) {
  603. if (arr[j].get_type() != Variant::NIL)
  604. bsformat |= (1 << j);
  605. }
  606. ERR_FAIL_COND((bsformat) != (format & (VS::ARRAY_FORMAT_INDEX - 1)));
  607. }
  608. }
  609. uint32_t offsets[VS::ARRAY_MAX];
  610. int total_elem_size = 0;
  611. for (int i = 0; i < VS::ARRAY_MAX; i++) {
  612. offsets[i] = 0; //reset
  613. if (!(format & (1 << i))) // no array
  614. continue;
  615. int elem_size = 0;
  616. switch (i) {
  617. case VS::ARRAY_VERTEX: {
  618. Variant arr = p_arrays[0];
  619. if (arr.get_type() == Variant::POOL_VECTOR2_ARRAY) {
  620. elem_size = 2;
  621. p_compress_format |= ARRAY_FLAG_USE_2D_VERTICES;
  622. } else if (arr.get_type() == Variant::POOL_VECTOR3_ARRAY) {
  623. p_compress_format &= ~ARRAY_FLAG_USE_2D_VERTICES;
  624. elem_size = 3;
  625. } else {
  626. elem_size = (p_compress_format & ARRAY_FLAG_USE_2D_VERTICES) ? 2 : 3;
  627. }
  628. if (p_compress_format & ARRAY_COMPRESS_VERTEX) {
  629. elem_size *= sizeof(int16_t);
  630. } else {
  631. elem_size *= sizeof(float);
  632. }
  633. if (elem_size == 6) {
  634. //had to pad
  635. elem_size = 8;
  636. }
  637. } break;
  638. case VS::ARRAY_NORMAL: {
  639. if (p_compress_format & ARRAY_COMPRESS_NORMAL) {
  640. elem_size = sizeof(uint32_t);
  641. } else {
  642. elem_size = sizeof(float) * 3;
  643. }
  644. } break;
  645. case VS::ARRAY_TANGENT: {
  646. if (p_compress_format & ARRAY_COMPRESS_TANGENT) {
  647. elem_size = sizeof(uint32_t);
  648. } else {
  649. elem_size = sizeof(float) * 4;
  650. }
  651. } break;
  652. case VS::ARRAY_COLOR: {
  653. if (p_compress_format & ARRAY_COMPRESS_COLOR) {
  654. elem_size = sizeof(uint32_t);
  655. } else {
  656. elem_size = sizeof(float) * 4;
  657. }
  658. } break;
  659. case VS::ARRAY_TEX_UV: {
  660. if (p_compress_format & ARRAY_COMPRESS_TEX_UV) {
  661. elem_size = sizeof(uint32_t);
  662. } else {
  663. elem_size = sizeof(float) * 2;
  664. }
  665. } break;
  666. case VS::ARRAY_TEX_UV2: {
  667. if (p_compress_format & ARRAY_COMPRESS_TEX_UV2) {
  668. elem_size = sizeof(uint32_t);
  669. } else {
  670. elem_size = sizeof(float) * 2;
  671. }
  672. } break;
  673. case VS::ARRAY_WEIGHTS: {
  674. if (p_compress_format & ARRAY_COMPRESS_WEIGHTS) {
  675. elem_size = sizeof(uint16_t) * 4;
  676. } else {
  677. elem_size = sizeof(float) * 4;
  678. }
  679. } break;
  680. case VS::ARRAY_BONES: {
  681. PoolVector<int> bones = p_arrays[VS::ARRAY_BONES];
  682. int max_bone = 0;
  683. {
  684. int bc = bones.size();
  685. PoolVector<int>::Read r = bones.read();
  686. for (int j = 0; j < bc; j++) {
  687. max_bone = MAX(r[j], max_bone);
  688. }
  689. }
  690. if (max_bone > 255) {
  691. p_compress_format |= ARRAY_FLAG_USE_16_BIT_BONES;
  692. elem_size = sizeof(uint16_t) * 4;
  693. } else {
  694. p_compress_format &= ~ARRAY_FLAG_USE_16_BIT_BONES;
  695. elem_size = sizeof(uint32_t);
  696. }
  697. } break;
  698. case VS::ARRAY_INDEX: {
  699. if (index_array_len <= 0) {
  700. ERR_PRINT("index_array_len==NO_INDEX_ARRAY");
  701. break;
  702. }
  703. /* determine whether using 16 or 32 bits indices */
  704. if (array_len >= (1 << 16)) {
  705. elem_size = 4;
  706. } else {
  707. elem_size = 2;
  708. }
  709. offsets[i] = elem_size;
  710. continue;
  711. } break;
  712. default: {
  713. ERR_FAIL();
  714. }
  715. }
  716. offsets[i] = total_elem_size;
  717. total_elem_size += elem_size;
  718. }
  719. uint32_t mask = (1 << ARRAY_MAX) - 1;
  720. format |= (~mask) & p_compress_format; //make the full format
  721. int array_size = total_elem_size * array_len;
  722. PoolVector<uint8_t> vertex_array;
  723. vertex_array.resize(array_size);
  724. int index_array_size = offsets[VS::ARRAY_INDEX] * index_array_len;
  725. PoolVector<uint8_t> index_array;
  726. index_array.resize(index_array_size);
  727. AABB aabb;
  728. Vector<AABB> bone_aabb;
  729. Error err = _surface_set_data(p_arrays, format, offsets, total_elem_size, vertex_array, array_len, index_array, index_array_len, aabb, bone_aabb);
  730. if (err) {
  731. ERR_EXPLAIN("Invalid array format for surface");
  732. ERR_FAIL_COND(err != OK);
  733. }
  734. Vector<PoolVector<uint8_t> > blend_shape_data;
  735. for (int i = 0; i < p_blend_shapes.size(); i++) {
  736. PoolVector<uint8_t> vertex_array_shape;
  737. vertex_array_shape.resize(array_size);
  738. PoolVector<uint8_t> noindex;
  739. AABB laabb;
  740. Error err = _surface_set_data(p_blend_shapes[i], format & ~ARRAY_FORMAT_INDEX, offsets, total_elem_size, vertex_array_shape, array_len, noindex, 0, laabb, bone_aabb);
  741. aabb.merge_with(laabb);
  742. if (err) {
  743. ERR_EXPLAIN("Invalid blend shape array format for surface");
  744. ERR_FAIL_COND(err != OK);
  745. }
  746. blend_shape_data.push_back(vertex_array_shape);
  747. }
  748. mesh_add_surface(p_mesh, format, p_primitive, vertex_array, array_len, index_array, index_array_len, aabb, blend_shape_data, bone_aabb);
  749. }
  750. 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 {
  751. uint32_t offsets[ARRAY_MAX];
  752. int total_elem_size = 0;
  753. for (int i = 0; i < VS::ARRAY_MAX; i++) {
  754. offsets[i] = 0; //reset
  755. if (!(p_format & (1 << i))) // no array
  756. continue;
  757. int elem_size = 0;
  758. switch (i) {
  759. case VS::ARRAY_VERTEX: {
  760. if (p_format & ARRAY_FLAG_USE_2D_VERTICES) {
  761. elem_size = 2;
  762. } else {
  763. elem_size = 3;
  764. }
  765. if (p_format & ARRAY_COMPRESS_VERTEX) {
  766. elem_size *= sizeof(int16_t);
  767. } else {
  768. elem_size *= sizeof(float);
  769. }
  770. if (elem_size == 6) {
  771. elem_size = 8;
  772. }
  773. } break;
  774. case VS::ARRAY_NORMAL: {
  775. if (p_format & ARRAY_COMPRESS_NORMAL) {
  776. elem_size = sizeof(uint32_t);
  777. } else {
  778. elem_size = sizeof(float) * 3;
  779. }
  780. } break;
  781. case VS::ARRAY_TANGENT: {
  782. if (p_format & ARRAY_COMPRESS_TANGENT) {
  783. elem_size = sizeof(uint32_t);
  784. } else {
  785. elem_size = sizeof(float) * 4;
  786. }
  787. } break;
  788. case VS::ARRAY_COLOR: {
  789. if (p_format & ARRAY_COMPRESS_COLOR) {
  790. elem_size = sizeof(uint32_t);
  791. } else {
  792. elem_size = sizeof(float) * 4;
  793. }
  794. } break;
  795. case VS::ARRAY_TEX_UV: {
  796. if (p_format & ARRAY_COMPRESS_TEX_UV) {
  797. elem_size = sizeof(uint32_t);
  798. } else {
  799. elem_size = sizeof(float) * 2;
  800. }
  801. } break;
  802. case VS::ARRAY_TEX_UV2: {
  803. if (p_format & ARRAY_COMPRESS_TEX_UV2) {
  804. elem_size = sizeof(uint32_t);
  805. } else {
  806. elem_size = sizeof(float) * 2;
  807. }
  808. } break;
  809. case VS::ARRAY_WEIGHTS: {
  810. if (p_format & ARRAY_COMPRESS_WEIGHTS) {
  811. elem_size = sizeof(uint16_t) * 4;
  812. } else {
  813. elem_size = sizeof(float) * 4;
  814. }
  815. } break;
  816. case VS::ARRAY_BONES: {
  817. if (p_format & ARRAY_FLAG_USE_16_BIT_BONES) {
  818. elem_size = sizeof(uint16_t) * 4;
  819. } else {
  820. elem_size = sizeof(uint32_t);
  821. }
  822. } break;
  823. case VS::ARRAY_INDEX: {
  824. if (p_index_len <= 0) {
  825. ERR_PRINT("index_array_len==NO_INDEX_ARRAY");
  826. break;
  827. }
  828. /* determine whether using 16 or 32 bits indices */
  829. if (p_vertex_len >= (1 << 16)) {
  830. elem_size = 4;
  831. } else {
  832. elem_size = 2;
  833. }
  834. offsets[i] = elem_size;
  835. continue;
  836. } break;
  837. default: {
  838. ERR_FAIL_V(Array());
  839. }
  840. }
  841. offsets[i] = total_elem_size;
  842. total_elem_size += elem_size;
  843. }
  844. Array ret;
  845. ret.resize(VS::ARRAY_MAX);
  846. PoolVector<uint8_t>::Read r = p_vertex_data.read();
  847. for (int i = 0; i < VS::ARRAY_MAX; i++) {
  848. if (!(p_format & (1 << i)))
  849. continue;
  850. switch (i) {
  851. case VS::ARRAY_VERTEX: {
  852. if (p_format & ARRAY_FLAG_USE_2D_VERTICES) {
  853. PoolVector<Vector2> arr_2d;
  854. arr_2d.resize(p_vertex_len);
  855. if (p_format & ARRAY_COMPRESS_VERTEX) {
  856. PoolVector<Vector2>::Write w = arr_2d.write();
  857. for (int j = 0; j < p_vertex_len; j++) {
  858. const uint16_t *v = (const uint16_t *)&r[j * total_elem_size + offsets[i]];
  859. w[j] = Vector2(Math::halfptr_to_float(&v[0]), Math::halfptr_to_float(&v[1]));
  860. }
  861. } else {
  862. PoolVector<Vector2>::Write w = arr_2d.write();
  863. for (int j = 0; j < p_vertex_len; j++) {
  864. const float *v = (const float *)&r[j * total_elem_size + offsets[i]];
  865. w[j] = Vector2(v[0], v[1]);
  866. }
  867. }
  868. ret[i] = arr_2d;
  869. } else {
  870. PoolVector<Vector3> arr_3d;
  871. arr_3d.resize(p_vertex_len);
  872. if (p_format & ARRAY_COMPRESS_VERTEX) {
  873. PoolVector<Vector3>::Write w = arr_3d.write();
  874. for (int j = 0; j < p_vertex_len; j++) {
  875. const uint16_t *v = (const uint16_t *)&r[j * total_elem_size + offsets[i]];
  876. w[j] = Vector3(Math::halfptr_to_float(&v[0]), Math::halfptr_to_float(&v[1]), Math::halfptr_to_float(&v[2]));
  877. }
  878. } else {
  879. PoolVector<Vector3>::Write w = arr_3d.write();
  880. for (int j = 0; j < p_vertex_len; j++) {
  881. const float *v = (const float *)&r[j * total_elem_size + offsets[i]];
  882. w[j] = Vector3(v[0], v[1], v[2]);
  883. }
  884. }
  885. ret[i] = arr_3d;
  886. }
  887. } break;
  888. case VS::ARRAY_NORMAL: {
  889. PoolVector<Vector3> arr;
  890. arr.resize(p_vertex_len);
  891. if (p_format & ARRAY_COMPRESS_NORMAL) {
  892. PoolVector<Vector3>::Write w = arr.write();
  893. const float multiplier = 1.f / 127.f;
  894. for (int j = 0; j < p_vertex_len; j++) {
  895. const int8_t *v = (const int8_t *)&r[j * total_elem_size + offsets[i]];
  896. w[j] = Vector3(float(v[0]) * multiplier, float(v[1]) * multiplier, float(v[2]) * multiplier);
  897. }
  898. } else {
  899. PoolVector<Vector3>::Write w = arr.write();
  900. for (int j = 0; j < p_vertex_len; j++) {
  901. const float *v = (const float *)&r[j * total_elem_size + offsets[i]];
  902. w[j] = Vector3(v[0], v[1], v[2]);
  903. }
  904. }
  905. ret[i] = arr;
  906. } break;
  907. case VS::ARRAY_TANGENT: {
  908. PoolVector<float> arr;
  909. arr.resize(p_vertex_len * 4);
  910. if (p_format & ARRAY_COMPRESS_TANGENT) {
  911. PoolVector<float>::Write w = arr.write();
  912. for (int j = 0; j < p_vertex_len; j++) {
  913. const int8_t *v = (const int8_t *)&r[j * total_elem_size + offsets[i]];
  914. for (int k = 0; k < 4; k++) {
  915. w[j * 4 + k] = float(v[k] / 127.0);
  916. }
  917. }
  918. } else {
  919. PoolVector<float>::Write w = arr.write();
  920. for (int j = 0; j < p_vertex_len; j++) {
  921. const float *v = (const float *)&r[j * total_elem_size + offsets[i]];
  922. for (int k = 0; k < 4; k++) {
  923. w[j * 4 + k] = v[k];
  924. }
  925. }
  926. }
  927. ret[i] = arr;
  928. } break;
  929. case VS::ARRAY_COLOR: {
  930. PoolVector<Color> arr;
  931. arr.resize(p_vertex_len);
  932. if (p_format & ARRAY_COMPRESS_COLOR) {
  933. PoolVector<Color>::Write w = arr.write();
  934. for (int j = 0; j < p_vertex_len; j++) {
  935. const uint8_t *v = (const uint8_t *)&r[j * total_elem_size + offsets[i]];
  936. w[j] = Color(float(v[0] / 255.0), float(v[1] / 255.0), float(v[2] / 255.0), float(v[3] / 255.0));
  937. }
  938. } else {
  939. PoolVector<Color>::Write w = arr.write();
  940. for (int j = 0; j < p_vertex_len; j++) {
  941. const float *v = (const float *)&r[j * total_elem_size + offsets[i]];
  942. w[j] = Color(v[0], v[1], v[2], v[3]);
  943. }
  944. }
  945. ret[i] = arr;
  946. } break;
  947. case VS::ARRAY_TEX_UV: {
  948. PoolVector<Vector2> arr;
  949. arr.resize(p_vertex_len);
  950. if (p_format & ARRAY_COMPRESS_TEX_UV) {
  951. PoolVector<Vector2>::Write w = arr.write();
  952. for (int j = 0; j < p_vertex_len; j++) {
  953. const uint16_t *v = (const uint16_t *)&r[j * total_elem_size + offsets[i]];
  954. w[j] = Vector2(Math::halfptr_to_float(&v[0]), Math::halfptr_to_float(&v[1]));
  955. }
  956. } else {
  957. PoolVector<Vector2>::Write w = arr.write();
  958. for (int j = 0; j < p_vertex_len; j++) {
  959. const float *v = (const float *)&r[j * total_elem_size + offsets[i]];
  960. w[j] = Vector2(v[0], v[1]);
  961. }
  962. }
  963. ret[i] = arr;
  964. } break;
  965. case VS::ARRAY_TEX_UV2: {
  966. PoolVector<Vector2> arr;
  967. arr.resize(p_vertex_len);
  968. if (p_format & ARRAY_COMPRESS_TEX_UV2) {
  969. PoolVector<Vector2>::Write w = arr.write();
  970. for (int j = 0; j < p_vertex_len; j++) {
  971. const uint16_t *v = (const uint16_t *)&r[j * total_elem_size + offsets[i]];
  972. w[j] = Vector2(Math::halfptr_to_float(&v[0]), Math::halfptr_to_float(&v[1]));
  973. }
  974. } else {
  975. PoolVector<Vector2>::Write w = arr.write();
  976. for (int j = 0; j < p_vertex_len; j++) {
  977. const float *v = (const float *)&r[j * total_elem_size + offsets[i]];
  978. w[j] = Vector2(v[0], v[1]);
  979. }
  980. }
  981. ret[i] = arr;
  982. } break;
  983. case VS::ARRAY_WEIGHTS: {
  984. PoolVector<float> arr;
  985. arr.resize(p_vertex_len * 4);
  986. if (p_format & ARRAY_COMPRESS_WEIGHTS) {
  987. PoolVector<float>::Write w = arr.write();
  988. for (int j = 0; j < p_vertex_len; j++) {
  989. const uint16_t *v = (const uint16_t *)&r[j * total_elem_size + offsets[i]];
  990. for (int k = 0; k < 4; k++) {
  991. w[j * 4 + k] = float(v[k] / 65535.0);
  992. }
  993. }
  994. } else {
  995. PoolVector<float>::Write w = arr.write();
  996. for (int j = 0; j < p_vertex_len; j++) {
  997. const float *v = (const float *)&r[j * total_elem_size + offsets[i]];
  998. for (int k = 0; k < 4; k++) {
  999. w[j * 4 + k] = v[k];
  1000. }
  1001. }
  1002. }
  1003. ret[i] = arr;
  1004. } break;
  1005. case VS::ARRAY_BONES: {
  1006. PoolVector<int> arr;
  1007. arr.resize(p_vertex_len * 4);
  1008. if (p_format & ARRAY_FLAG_USE_16_BIT_BONES) {
  1009. PoolVector<int>::Write w = arr.write();
  1010. for (int j = 0; j < p_vertex_len; j++) {
  1011. const uint16_t *v = (const uint16_t *)&r[j * total_elem_size + offsets[i]];
  1012. for (int k = 0; k < 4; k++) {
  1013. w[j * 4 + k] = v[k];
  1014. }
  1015. }
  1016. } else {
  1017. PoolVector<int>::Write w = arr.write();
  1018. for (int j = 0; j < p_vertex_len; j++) {
  1019. const uint8_t *v = (const uint8_t *)&r[j * total_elem_size + offsets[i]];
  1020. for (int k = 0; k < 4; k++) {
  1021. w[j * 4 + k] = v[k];
  1022. }
  1023. }
  1024. }
  1025. ret[i] = arr;
  1026. } break;
  1027. case VS::ARRAY_INDEX: {
  1028. /* determine whether using 16 or 32 bits indices */
  1029. PoolVector<uint8_t>::Read ir = p_index_data.read();
  1030. PoolVector<int> arr;
  1031. arr.resize(p_index_len);
  1032. if (p_vertex_len < (1 << 16)) {
  1033. PoolVector<int>::Write w = arr.write();
  1034. for (int j = 0; j < p_index_len; j++) {
  1035. const uint16_t *v = (const uint16_t *)&ir[j * 2];
  1036. w[j] = *v;
  1037. }
  1038. } else {
  1039. PoolVector<int>::Write w = arr.write();
  1040. for (int j = 0; j < p_index_len; j++) {
  1041. const int *v = (const int *)&ir[j * 4];
  1042. w[j] = *v;
  1043. }
  1044. }
  1045. ret[i] = arr;
  1046. } break;
  1047. default: {
  1048. ERR_FAIL_V(ret);
  1049. }
  1050. }
  1051. }
  1052. return ret;
  1053. }
  1054. Array VisualServer::mesh_surface_get_arrays(RID p_mesh, int p_surface) const {
  1055. PoolVector<uint8_t> vertex_data = mesh_surface_get_array(p_mesh, p_surface);
  1056. ERR_FAIL_COND_V(vertex_data.size() == 0, Array());
  1057. int vertex_len = mesh_surface_get_array_len(p_mesh, p_surface);
  1058. PoolVector<uint8_t> index_data = mesh_surface_get_index_array(p_mesh, p_surface);
  1059. int index_len = mesh_surface_get_array_index_len(p_mesh, p_surface);
  1060. uint32_t format = mesh_surface_get_format(p_mesh, p_surface);
  1061. return _get_array_from_surface(format, vertex_data, vertex_len, index_data, index_len);
  1062. }
  1063. Array VisualServer::mesh_surface_get_blend_shape_arrays(RID p_mesh, int p_surface) const {
  1064. Vector<PoolVector<uint8_t> > blend_shape_data = mesh_surface_get_blend_shapes(p_mesh, p_surface);
  1065. if (blend_shape_data.size() > 0) {
  1066. int vertex_len = mesh_surface_get_array_len(p_mesh, p_surface);
  1067. PoolVector<uint8_t> index_data = mesh_surface_get_index_array(p_mesh, p_surface);
  1068. int index_len = mesh_surface_get_array_index_len(p_mesh, p_surface);
  1069. uint32_t format = mesh_surface_get_format(p_mesh, p_surface);
  1070. Array blend_shape_array;
  1071. blend_shape_array.resize(blend_shape_data.size());
  1072. for (int i = 0; i < blend_shape_data.size(); i++) {
  1073. blend_shape_array.set(i, _get_array_from_surface(format, blend_shape_data[i], vertex_len, index_data, index_len));
  1074. }
  1075. return blend_shape_array;
  1076. } else {
  1077. return Array();
  1078. }
  1079. }
  1080. Array VisualServer::_mesh_surface_get_skeleton_aabb_bind(RID p_mesh, int p_surface) const {
  1081. Vector<AABB> vec = VS::get_singleton()->mesh_surface_get_skeleton_aabb(p_mesh, p_surface);
  1082. Array arr;
  1083. for (int i = 0; i < vec.size(); i++) {
  1084. arr[i] = vec[i];
  1085. }
  1086. return arr;
  1087. }
  1088. void VisualServer::_bind_methods() {
  1089. ClassDB::bind_method(D_METHOD("force_sync"), &VisualServer::sync);
  1090. ClassDB::bind_method(D_METHOD("force_draw", "swap_buffers"), &VisualServer::draw, DEFVAL(true));
  1091. // "draw" and "sync" are deprecated duplicates of "force_draw" and "force_sync"
  1092. // FIXME: Add deprecation messages using GH-4397 once available, and retire
  1093. // once the warnings have been enabled for a full release cycle
  1094. ClassDB::bind_method(D_METHOD("sync"), &VisualServer::sync);
  1095. ClassDB::bind_method(D_METHOD("draw", "swap_buffers"), &VisualServer::draw, DEFVAL(true));
  1096. ClassDB::bind_method(D_METHOD("texture_create"), &VisualServer::texture_create);
  1097. ClassDB::bind_method(D_METHOD("texture_create_from_image", "image", "flags"), &VisualServer::texture_create_from_image, DEFVAL(TEXTURE_FLAGS_DEFAULT));
  1098. ClassDB::bind_method(D_METHOD("texture_allocate", "texture", "width", "height", "format", "flags"), &VisualServer::texture_allocate, DEFVAL(TEXTURE_FLAGS_DEFAULT));
  1099. ClassDB::bind_method(D_METHOD("texture_set_data", "texture", "image", "cube_side"), &VisualServer::texture_set_data, DEFVAL(CUBEMAP_LEFT));
  1100. 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", "cube_side"), &VisualServer::texture_set_data_partial, DEFVAL(CUBEMAP_LEFT));
  1101. ClassDB::bind_method(D_METHOD("texture_get_data", "texture", "cube_side"), &VisualServer::texture_get_data, DEFVAL(CUBEMAP_LEFT));
  1102. ClassDB::bind_method(D_METHOD("texture_set_flags", "texture", "flags"), &VisualServer::texture_set_flags);
  1103. ClassDB::bind_method(D_METHOD("texture_get_flags", "texture"), &VisualServer::texture_get_flags);
  1104. ClassDB::bind_method(D_METHOD("texture_get_format", "texture"), &VisualServer::texture_get_format);
  1105. ClassDB::bind_method(D_METHOD("texture_get_texid", "texture"), &VisualServer::texture_get_texid);
  1106. ClassDB::bind_method(D_METHOD("texture_get_width", "texture"), &VisualServer::texture_get_width);
  1107. ClassDB::bind_method(D_METHOD("texture_get_height", "texture"), &VisualServer::texture_get_height);
  1108. ClassDB::bind_method(D_METHOD("texture_set_size_override", "texture", "width", "height"), &VisualServer::texture_set_size_override);
  1109. ClassDB::bind_method(D_METHOD("texture_set_path", "texture", "path"), &VisualServer::texture_set_path);
  1110. ClassDB::bind_method(D_METHOD("texture_get_path", "texture"), &VisualServer::texture_get_path);
  1111. ClassDB::bind_method(D_METHOD("texture_set_shrink_all_x2_on_set_data", "shrink"), &VisualServer::texture_set_shrink_all_x2_on_set_data);
  1112. ClassDB::bind_method(D_METHOD("texture_debug_usage"), &VisualServer::_texture_debug_usage_bind);
  1113. ClassDB::bind_method(D_METHOD("textures_keep_original", "enable"), &VisualServer::textures_keep_original);
  1114. #ifndef _3D_DISABLED
  1115. ClassDB::bind_method(D_METHOD("sky_create"), &VisualServer::sky_create);
  1116. ClassDB::bind_method(D_METHOD("sky_set_texture", "sky", "cube_map", "radiance_size"), &VisualServer::sky_set_texture);
  1117. #endif
  1118. ClassDB::bind_method(D_METHOD("shader_create"), &VisualServer::shader_create);
  1119. ClassDB::bind_method(D_METHOD("shader_set_code", "shader", "code"), &VisualServer::shader_set_code);
  1120. ClassDB::bind_method(D_METHOD("shader_get_code", "shader"), &VisualServer::shader_get_code);
  1121. ClassDB::bind_method(D_METHOD("shader_get_param_list", "shader"), &VisualServer::_shader_get_param_list_bind);
  1122. ClassDB::bind_method(D_METHOD("shader_set_default_texture_param", "shader", "name", "texture"), &VisualServer::shader_set_default_texture_param);
  1123. ClassDB::bind_method(D_METHOD("shader_get_default_texture_param", "shader", "name"), &VisualServer::shader_get_default_texture_param);
  1124. ClassDB::bind_method(D_METHOD("material_create"), &VisualServer::material_create);
  1125. ClassDB::bind_method(D_METHOD("material_set_shader", "shader_material", "shader"), &VisualServer::material_set_shader);
  1126. ClassDB::bind_method(D_METHOD("material_get_shader", "shader_material"), &VisualServer::material_get_shader);
  1127. ClassDB::bind_method(D_METHOD("material_set_param", "material", "parameter", "value"), &VisualServer::material_set_param);
  1128. ClassDB::bind_method(D_METHOD("material_get_param", "material", "parameter"), &VisualServer::material_get_param);
  1129. ClassDB::bind_method(D_METHOD("material_set_render_priority", "material", "priority"), &VisualServer::material_set_render_priority);
  1130. ClassDB::bind_method(D_METHOD("material_set_line_width", "material", "width"), &VisualServer::material_set_line_width);
  1131. ClassDB::bind_method(D_METHOD("material_set_next_pass", "material", "next_material"), &VisualServer::material_set_next_pass);
  1132. ClassDB::bind_method(D_METHOD("mesh_create"), &VisualServer::mesh_create);
  1133. ClassDB::bind_method(D_METHOD("mesh_add_surface_from_arrays", "mesh", "primtive", "arrays", "blend_shapes", "compress_format"), &VisualServer::mesh_add_surface_from_arrays, DEFVAL(Array()), DEFVAL(ARRAY_COMPRESS_DEFAULT));
  1134. ClassDB::bind_method(D_METHOD("mesh_set_blend_shape_count", "mesh", "amount"), &VisualServer::mesh_set_blend_shape_count);
  1135. ClassDB::bind_method(D_METHOD("mesh_get_blend_shape_count", "mesh"), &VisualServer::mesh_get_blend_shape_count);
  1136. ClassDB::bind_method(D_METHOD("mesh_set_blend_shape_mode", "mesh", "mode"), &VisualServer::mesh_set_blend_shape_mode);
  1137. ClassDB::bind_method(D_METHOD("mesh_get_blend_shape_mode", "mesh"), &VisualServer::mesh_get_blend_shape_mode);
  1138. ClassDB::bind_method(D_METHOD("mesh_surface_set_material", "mesh", "surface", "material"), &VisualServer::mesh_surface_set_material);
  1139. ClassDB::bind_method(D_METHOD("mesh_surface_get_material", "mesh", "surface"), &VisualServer::mesh_surface_get_material);
  1140. ClassDB::bind_method(D_METHOD("mesh_surface_get_array_len", "mesh", "surface"), &VisualServer::mesh_surface_get_array_len);
  1141. ClassDB::bind_method(D_METHOD("mesh_surface_get_array_index_len", "mesh", "surface"), &VisualServer::mesh_surface_get_array_index_len);
  1142. ClassDB::bind_method(D_METHOD("mesh_surface_get_array", "mesh", "surface"), &VisualServer::mesh_surface_get_array);
  1143. ClassDB::bind_method(D_METHOD("mesh_surface_get_index_array", "mesh", "surface"), &VisualServer::mesh_surface_get_index_array);
  1144. ClassDB::bind_method(D_METHOD("mesh_surface_get_arrays", "mesh", "surface"), &VisualServer::mesh_surface_get_arrays);
  1145. ClassDB::bind_method(D_METHOD("mesh_surface_get_blend_shape_arrays", "mesh", "surface"), &VisualServer::mesh_surface_get_blend_shape_arrays);
  1146. ClassDB::bind_method(D_METHOD("mesh_surface_get_format", "mesh", "surface"), &VisualServer::mesh_surface_get_format);
  1147. ClassDB::bind_method(D_METHOD("mesh_surface_get_primitive_type", "mesh", "surface"), &VisualServer::mesh_surface_get_primitive_type);
  1148. ClassDB::bind_method(D_METHOD("mesh_surface_get_aabb", "mesh", "surface"), &VisualServer::mesh_surface_get_aabb);
  1149. ClassDB::bind_method(D_METHOD("mesh_surface_get_skeleton_aabb", "mesh", "surface"), &VisualServer::_mesh_surface_get_skeleton_aabb_bind);
  1150. ClassDB::bind_method(D_METHOD("mesh_remove_surface", "mesh", "index"), &VisualServer::mesh_remove_surface);
  1151. ClassDB::bind_method(D_METHOD("mesh_get_surface_count", "mesh"), &VisualServer::mesh_get_surface_count);
  1152. ClassDB::bind_method(D_METHOD("mesh_set_custom_aabb", "mesh", "aabb"), &VisualServer::mesh_set_custom_aabb);
  1153. ClassDB::bind_method(D_METHOD("mesh_get_custom_aabb", "mesh"), &VisualServer::mesh_get_custom_aabb);
  1154. ClassDB::bind_method(D_METHOD("mesh_clear", "mesh"), &VisualServer::mesh_clear);
  1155. ClassDB::bind_method(D_METHOD("multimesh_allocate", "multimesh", "instances", "transform_format", "color_format", "custom_data_format"), &VisualServer::multimesh_allocate, DEFVAL(MULTIMESH_CUSTOM_DATA_NONE));
  1156. ClassDB::bind_method(D_METHOD("multimesh_get_instance_count", "multimesh"), &VisualServer::multimesh_get_instance_count);
  1157. ClassDB::bind_method(D_METHOD("multimesh_set_mesh", "multimesh", "mesh"), &VisualServer::multimesh_set_mesh);
  1158. ClassDB::bind_method(D_METHOD("multimesh_instance_set_transform", "multimesh", "index", "transform"), &VisualServer::multimesh_instance_set_transform);
  1159. ClassDB::bind_method(D_METHOD("multimesh_instance_set_transform_2d", "multimesh", "index", "transform"), &VisualServer::multimesh_instance_set_transform_2d);
  1160. ClassDB::bind_method(D_METHOD("multimesh_instance_set_color", "multimesh", "index", "color"), &VisualServer::multimesh_instance_set_color);
  1161. ClassDB::bind_method(D_METHOD("multimesh_instance_set_custom_data", "multimesh", "index", "custom_data"), &VisualServer::multimesh_instance_set_custom_data);
  1162. ClassDB::bind_method(D_METHOD("multimesh_get_mesh", "multimesh"), &VisualServer::multimesh_get_mesh);
  1163. ClassDB::bind_method(D_METHOD("multimesh_get_aabb", "multimesh"), &VisualServer::multimesh_get_aabb);
  1164. ClassDB::bind_method(D_METHOD("multimesh_instance_get_transform", "multimesh", "index"), &VisualServer::multimesh_instance_get_transform);
  1165. ClassDB::bind_method(D_METHOD("multimesh_instance_get_transform_2d", "multimesh", "index"), &VisualServer::multimesh_instance_get_transform_2d);
  1166. ClassDB::bind_method(D_METHOD("multimesh_instance_get_color", "multimesh", "index"), &VisualServer::multimesh_instance_get_color);
  1167. ClassDB::bind_method(D_METHOD("multimesh_instance_get_custom_data", "multimesh", "index"), &VisualServer::multimesh_instance_get_custom_data);
  1168. ClassDB::bind_method(D_METHOD("multimesh_set_visible_instances", "multimesh", "visible"), &VisualServer::multimesh_set_visible_instances);
  1169. ClassDB::bind_method(D_METHOD("multimesh_get_visible_instances", "multimesh"), &VisualServer::multimesh_get_visible_instances);
  1170. ClassDB::bind_method(D_METHOD("multimesh_set_as_bulk_array", "multimesh", "array"), &VisualServer::multimesh_set_as_bulk_array);
  1171. #ifndef _3D_DISABLED
  1172. ClassDB::bind_method(D_METHOD("immediate_create"), &VisualServer::immediate_create);
  1173. ClassDB::bind_method(D_METHOD("immediate_begin", "immediate", "primitive", "texture"), &VisualServer::immediate_begin, DEFVAL(RID()));
  1174. ClassDB::bind_method(D_METHOD("immediate_vertex", "immediate", "vertex"), &VisualServer::immediate_vertex);
  1175. ClassDB::bind_method(D_METHOD("immediate_vertex_2d", "immediate", "vertex"), &VisualServer::immediate_vertex_2d);
  1176. ClassDB::bind_method(D_METHOD("immediate_normal", "immediate", "normal"), &VisualServer::immediate_normal);
  1177. ClassDB::bind_method(D_METHOD("immediate_tangent", "immediate", "tangent"), &VisualServer::immediate_tangent);
  1178. ClassDB::bind_method(D_METHOD("immediate_color", "immediate", "color"), &VisualServer::immediate_color);
  1179. ClassDB::bind_method(D_METHOD("immediate_uv", "immediate", "tex_uv"), &VisualServer::immediate_uv);
  1180. ClassDB::bind_method(D_METHOD("immediate_uv2", "immediate", "tex_uv"), &VisualServer::immediate_uv2);
  1181. ClassDB::bind_method(D_METHOD("immediate_end", "immediate"), &VisualServer::immediate_end);
  1182. ClassDB::bind_method(D_METHOD("immediate_clear", "immediate"), &VisualServer::immediate_clear);
  1183. ClassDB::bind_method(D_METHOD("immediate_set_material", "immediate", "material"), &VisualServer::immediate_set_material);
  1184. ClassDB::bind_method(D_METHOD("immediate_get_material", "immediate"), &VisualServer::immediate_get_material);
  1185. #endif
  1186. ClassDB::bind_method(D_METHOD("skeleton_create"), &VisualServer::skeleton_create);
  1187. ClassDB::bind_method(D_METHOD("skeleton_allocate", "skeleton", "bones", "is_2d_skeleton"), &VisualServer::skeleton_allocate, DEFVAL(false));
  1188. ClassDB::bind_method(D_METHOD("skeleton_get_bone_count", "skeleton"), &VisualServer::skeleton_get_bone_count);
  1189. ClassDB::bind_method(D_METHOD("skeleton_bone_set_transform", "skeleton", "bone", "transform"), &VisualServer::skeleton_bone_set_transform);
  1190. ClassDB::bind_method(D_METHOD("skeleton_bone_get_transform", "skeleton", "bone"), &VisualServer::skeleton_bone_get_transform);
  1191. ClassDB::bind_method(D_METHOD("skeleton_bone_set_transform_2d", "skeleton", "bone", "transform"), &VisualServer::skeleton_bone_set_transform_2d);
  1192. ClassDB::bind_method(D_METHOD("skeleton_bone_get_transform_2d", "skeleton", "bone"), &VisualServer::skeleton_bone_get_transform_2d);
  1193. #ifndef _3D_DISABLED
  1194. ClassDB::bind_method(D_METHOD("directional_light_create"), &VisualServer::directional_light_create);
  1195. ClassDB::bind_method(D_METHOD("omni_light_create"), &VisualServer::omni_light_create);
  1196. ClassDB::bind_method(D_METHOD("spot_light_create"), &VisualServer::spot_light_create);
  1197. ClassDB::bind_method(D_METHOD("light_set_color", "light", "color"), &VisualServer::light_set_color);
  1198. ClassDB::bind_method(D_METHOD("light_set_param", "light", "param", "value"), &VisualServer::light_set_param);
  1199. ClassDB::bind_method(D_METHOD("light_set_shadow", "light", "enabled"), &VisualServer::light_set_shadow);
  1200. ClassDB::bind_method(D_METHOD("light_set_shadow_color", "light", "color"), &VisualServer::light_set_shadow_color);
  1201. ClassDB::bind_method(D_METHOD("light_set_projector", "light", "texture"), &VisualServer::light_set_projector);
  1202. ClassDB::bind_method(D_METHOD("light_set_negative", "light", "enable"), &VisualServer::light_set_negative);
  1203. ClassDB::bind_method(D_METHOD("light_set_cull_mask", "light", "mask"), &VisualServer::light_set_cull_mask);
  1204. ClassDB::bind_method(D_METHOD("light_set_reverse_cull_face_mode", "light", "enabled"), &VisualServer::light_set_reverse_cull_face_mode);
  1205. ClassDB::bind_method(D_METHOD("light_omni_set_shadow_mode", "light", "mode"), &VisualServer::light_omni_set_shadow_mode);
  1206. ClassDB::bind_method(D_METHOD("light_omni_set_shadow_detail", "light", "detail"), &VisualServer::light_omni_set_shadow_detail);
  1207. ClassDB::bind_method(D_METHOD("light_directional_set_shadow_mode", "light", "mode"), &VisualServer::light_directional_set_shadow_mode);
  1208. ClassDB::bind_method(D_METHOD("light_directional_set_blend_splits", "light", "enable"), &VisualServer::light_directional_set_blend_splits);
  1209. ClassDB::bind_method(D_METHOD("light_directional_set_shadow_depth_range_mode", "light", "range_mode"), &VisualServer::light_directional_set_shadow_depth_range_mode);
  1210. ClassDB::bind_method(D_METHOD("reflection_probe_create"), &VisualServer::reflection_probe_create);
  1211. ClassDB::bind_method(D_METHOD("reflection_probe_set_update_mode", "probe", "mode"), &VisualServer::reflection_probe_set_update_mode);
  1212. ClassDB::bind_method(D_METHOD("reflection_probe_set_intensity", "probe", "intensity"), &VisualServer::reflection_probe_set_intensity);
  1213. ClassDB::bind_method(D_METHOD("reflection_probe_set_interior_ambient", "probe", "color"), &VisualServer::reflection_probe_set_interior_ambient);
  1214. ClassDB::bind_method(D_METHOD("reflection_probe_set_interior_ambient_energy", "probe", "energy"), &VisualServer::reflection_probe_set_interior_ambient_energy);
  1215. ClassDB::bind_method(D_METHOD("reflection_probe_set_interior_ambient_probe_contribution", "probe", "contrib"), &VisualServer::reflection_probe_set_interior_ambient_probe_contribution);
  1216. ClassDB::bind_method(D_METHOD("reflection_probe_set_max_distance", "probe", "distance"), &VisualServer::reflection_probe_set_max_distance);
  1217. ClassDB::bind_method(D_METHOD("reflection_probe_set_extents", "probe", "extents"), &VisualServer::reflection_probe_set_extents);
  1218. ClassDB::bind_method(D_METHOD("reflection_probe_set_origin_offset", "probe", "offset"), &VisualServer::reflection_probe_set_origin_offset);
  1219. ClassDB::bind_method(D_METHOD("reflection_probe_set_as_interior", "probe", "enable"), &VisualServer::reflection_probe_set_as_interior);
  1220. ClassDB::bind_method(D_METHOD("reflection_probe_set_enable_box_projection", "probe", "enable"), &VisualServer::reflection_probe_set_enable_box_projection);
  1221. ClassDB::bind_method(D_METHOD("reflection_probe_set_enable_shadows", "probe", "enable"), &VisualServer::reflection_probe_set_enable_shadows);
  1222. ClassDB::bind_method(D_METHOD("reflection_probe_set_cull_mask", "probe", "layers"), &VisualServer::reflection_probe_set_cull_mask);
  1223. ClassDB::bind_method(D_METHOD("gi_probe_create"), &VisualServer::gi_probe_create);
  1224. ClassDB::bind_method(D_METHOD("gi_probe_set_bounds", "probe", "bounds"), &VisualServer::gi_probe_set_bounds);
  1225. ClassDB::bind_method(D_METHOD("gi_probe_get_bounds", "probe"), &VisualServer::gi_probe_get_bounds);
  1226. ClassDB::bind_method(D_METHOD("gi_probe_set_cell_size", "probe", "range"), &VisualServer::gi_probe_set_cell_size);
  1227. ClassDB::bind_method(D_METHOD("gi_probe_get_cell_size", "probe"), &VisualServer::gi_probe_get_cell_size);
  1228. ClassDB::bind_method(D_METHOD("gi_probe_set_to_cell_xform", "xform"), &VisualServer::gi_probe_set_to_cell_xform);
  1229. ClassDB::bind_method(D_METHOD("gi_probe_get_to_cell_xform"), &VisualServer::gi_probe_get_to_cell_xform);
  1230. ClassDB::bind_method(D_METHOD("gi_probe_set_dynamic_data", "data"), &VisualServer::gi_probe_set_dynamic_data);
  1231. ClassDB::bind_method(D_METHOD("gi_probe_get_dynamic_data"), &VisualServer::gi_probe_get_dynamic_data);
  1232. ClassDB::bind_method(D_METHOD("gi_probe_set_dynamic_range", "range"), &VisualServer::gi_probe_set_dynamic_range);
  1233. ClassDB::bind_method(D_METHOD("gi_probe_get_dynamic_range"), &VisualServer::gi_probe_get_dynamic_range);
  1234. ClassDB::bind_method(D_METHOD("gi_probe_set_energy", "energy"), &VisualServer::gi_probe_set_energy);
  1235. ClassDB::bind_method(D_METHOD("gi_probe_get_energy"), &VisualServer::gi_probe_get_energy);
  1236. ClassDB::bind_method(D_METHOD("gi_probe_set_bias", "bias"), &VisualServer::gi_probe_set_bias);
  1237. ClassDB::bind_method(D_METHOD("gi_probe_get_bias"), &VisualServer::gi_probe_get_bias);
  1238. ClassDB::bind_method(D_METHOD("gi_probe_set_normal_bias", "bias"), &VisualServer::gi_probe_set_normal_bias);
  1239. ClassDB::bind_method(D_METHOD("gi_probe_get_normal_bias"), &VisualServer::gi_probe_get_normal_bias);
  1240. ClassDB::bind_method(D_METHOD("gi_probe_set_propagation", "propagation"), &VisualServer::gi_probe_set_propagation);
  1241. ClassDB::bind_method(D_METHOD("gi_probe_get_propagation"), &VisualServer::gi_probe_get_propagation);
  1242. ClassDB::bind_method(D_METHOD("gi_probe_set_interior", "enable"), &VisualServer::gi_probe_set_interior);
  1243. ClassDB::bind_method(D_METHOD("gi_probe_is_interior"), &VisualServer::gi_probe_is_interior);
  1244. ClassDB::bind_method(D_METHOD("gi_probe_set_compress", "enable"), &VisualServer::gi_probe_set_compress);
  1245. ClassDB::bind_method(D_METHOD("gi_probe_is_compressed"), &VisualServer::gi_probe_is_compressed);
  1246. ClassDB::bind_method(D_METHOD("lightmap_capture_create"), &VisualServer::lightmap_capture_create);
  1247. ClassDB::bind_method(D_METHOD("lightmap_capture_set_bounds", "capture", "bounds"), &VisualServer::lightmap_capture_set_bounds);
  1248. ClassDB::bind_method(D_METHOD("lightmap_capture_get_bounds", "capture"), &VisualServer::lightmap_capture_get_bounds);
  1249. ClassDB::bind_method(D_METHOD("lightmap_capture_set_octree", "capture", "octree"), &VisualServer::lightmap_capture_set_octree);
  1250. ClassDB::bind_method(D_METHOD("lightmap_capture_set_octree_cell_transform", "capture", "xform"), &VisualServer::lightmap_capture_set_octree_cell_transform);
  1251. ClassDB::bind_method(D_METHOD("lightmap_capture_get_octree_cell_transform", "capture"), &VisualServer::lightmap_capture_get_octree_cell_transform);
  1252. ClassDB::bind_method(D_METHOD("lightmap_capture_set_octree_cell_subdiv", "capture", "subdiv"), &VisualServer::lightmap_capture_set_octree_cell_subdiv);
  1253. ClassDB::bind_method(D_METHOD("lightmap_capture_get_octree_cell_subdiv", "capture"), &VisualServer::lightmap_capture_get_octree_cell_subdiv);
  1254. ClassDB::bind_method(D_METHOD("lightmap_capture_get_octree", "capture"), &VisualServer::lightmap_capture_get_octree);
  1255. ClassDB::bind_method(D_METHOD("lightmap_capture_set_energy", "capture", "energy"), &VisualServer::lightmap_capture_set_energy);
  1256. ClassDB::bind_method(D_METHOD("lightmap_capture_get_energy", "capture"), &VisualServer::lightmap_capture_get_energy);
  1257. #endif
  1258. ClassDB::bind_method(D_METHOD("particles_create"), &VisualServer::particles_create);
  1259. ClassDB::bind_method(D_METHOD("particles_set_emitting", "particles", "emitting"), &VisualServer::particles_set_emitting);
  1260. ClassDB::bind_method(D_METHOD("particles_get_emitting", "particles"), &VisualServer::particles_get_emitting);
  1261. ClassDB::bind_method(D_METHOD("particles_set_amount", "particles", "amount"), &VisualServer::particles_set_amount);
  1262. ClassDB::bind_method(D_METHOD("particles_set_lifetime", "particles", "lifetime"), &VisualServer::particles_set_lifetime);
  1263. ClassDB::bind_method(D_METHOD("particles_set_one_shot", "particles", "one_shot"), &VisualServer::particles_set_one_shot);
  1264. ClassDB::bind_method(D_METHOD("particles_set_pre_process_time", "particles", "time"), &VisualServer::particles_set_pre_process_time);
  1265. ClassDB::bind_method(D_METHOD("particles_set_explosiveness_ratio", "particles", "ratio"), &VisualServer::particles_set_explosiveness_ratio);
  1266. ClassDB::bind_method(D_METHOD("particles_set_randomness_ratio", "particles", "ratio"), &VisualServer::particles_set_randomness_ratio);
  1267. ClassDB::bind_method(D_METHOD("particles_set_custom_aabb", "particles", "aabb"), &VisualServer::particles_set_custom_aabb);
  1268. ClassDB::bind_method(D_METHOD("particles_set_speed_scale", "particles", "scale"), &VisualServer::particles_set_speed_scale);
  1269. ClassDB::bind_method(D_METHOD("particles_set_use_local_coordinates", "particles", "enable"), &VisualServer::particles_set_use_local_coordinates);
  1270. ClassDB::bind_method(D_METHOD("particles_set_process_material", "particles", "material"), &VisualServer::particles_set_process_material);
  1271. ClassDB::bind_method(D_METHOD("particles_set_fixed_fps", "particles", "fps"), &VisualServer::particles_set_fixed_fps);
  1272. ClassDB::bind_method(D_METHOD("particles_set_fractional_delta", "particles", "enable"), &VisualServer::particles_set_fractional_delta);
  1273. ClassDB::bind_method(D_METHOD("particles_restart", "particles"), &VisualServer::particles_restart);
  1274. ClassDB::bind_method(D_METHOD("particles_set_draw_order", "particles", "order"), &VisualServer::particles_set_draw_order);
  1275. ClassDB::bind_method(D_METHOD("particles_set_draw_passes", "particles", "count"), &VisualServer::particles_set_draw_passes);
  1276. ClassDB::bind_method(D_METHOD("particles_set_draw_pass_mesh", "particles", "pass", "mesh"), &VisualServer::particles_set_draw_pass_mesh);
  1277. ClassDB::bind_method(D_METHOD("particles_get_current_aabb", "particles"), &VisualServer::particles_get_current_aabb);
  1278. ClassDB::bind_method(D_METHOD("particles_set_emission_transform", "particles", "transform"), &VisualServer::particles_set_emission_transform);
  1279. ClassDB::bind_method(D_METHOD("camera_create"), &VisualServer::camera_create);
  1280. ClassDB::bind_method(D_METHOD("camera_set_perspective", "camera", "fovy_degrees", "z_near", "z_far"), &VisualServer::camera_set_perspective);
  1281. ClassDB::bind_method(D_METHOD("camera_set_orthogonal", "camera", "size", "z_near", "z_far"), &VisualServer::camera_set_orthogonal);
  1282. ClassDB::bind_method(D_METHOD("camera_set_transform", "camera", "transform"), &VisualServer::camera_set_transform);
  1283. ClassDB::bind_method(D_METHOD("camera_set_cull_mask", "camera", "layers"), &VisualServer::camera_set_cull_mask);
  1284. ClassDB::bind_method(D_METHOD("camera_set_environment", "camera", "env"), &VisualServer::camera_set_environment);
  1285. ClassDB::bind_method(D_METHOD("camera_set_use_vertical_aspect", "camera", "enable"), &VisualServer::camera_set_use_vertical_aspect);
  1286. ClassDB::bind_method(D_METHOD("viewport_create"), &VisualServer::viewport_create);
  1287. ClassDB::bind_method(D_METHOD("viewport_set_use_arvr", "viewport", "use_arvr"), &VisualServer::viewport_set_use_arvr);
  1288. ClassDB::bind_method(D_METHOD("viewport_set_size", "viewport", "width", "height"), &VisualServer::viewport_set_size);
  1289. ClassDB::bind_method(D_METHOD("viewport_set_active", "viewport", "active"), &VisualServer::viewport_set_active);
  1290. ClassDB::bind_method(D_METHOD("viewport_set_parent_viewport", "viewport", "parent_viewport"), &VisualServer::viewport_set_parent_viewport);
  1291. ClassDB::bind_method(D_METHOD("viewport_attach_to_screen", "viewport", "rect", "screen"), &VisualServer::viewport_attach_to_screen, DEFVAL(Rect2()), DEFVAL(0));
  1292. ClassDB::bind_method(D_METHOD("viewport_detach", "viewport"), &VisualServer::viewport_detach);
  1293. ClassDB::bind_method(D_METHOD("viewport_set_update_mode", "viewport", "update_mode"), &VisualServer::viewport_set_update_mode);
  1294. ClassDB::bind_method(D_METHOD("viewport_set_vflip", "viewport", "enabled"), &VisualServer::viewport_set_vflip);
  1295. ClassDB::bind_method(D_METHOD("viewport_set_clear_mode", "viewport", "clear_mode"), &VisualServer::viewport_set_clear_mode);
  1296. ClassDB::bind_method(D_METHOD("viewport_get_texture", "viewport"), &VisualServer::viewport_get_texture);
  1297. ClassDB::bind_method(D_METHOD("viewport_set_hide_scenario", "viewport", "hidden"), &VisualServer::viewport_set_hide_scenario);
  1298. ClassDB::bind_method(D_METHOD("viewport_set_hide_canvas", "viewport", "hidden"), &VisualServer::viewport_set_hide_canvas);
  1299. ClassDB::bind_method(D_METHOD("viewport_set_disable_environment", "viewport", "disabled"), &VisualServer::viewport_set_disable_environment);
  1300. ClassDB::bind_method(D_METHOD("viewport_set_disable_3d", "viewport", "disabled"), &VisualServer::viewport_set_disable_3d);
  1301. ClassDB::bind_method(D_METHOD("viewport_attach_camera", "viewport", "camera"), &VisualServer::viewport_attach_camera);
  1302. ClassDB::bind_method(D_METHOD("viewport_set_scenario", "viewport", "scenario"), &VisualServer::viewport_set_scenario);
  1303. ClassDB::bind_method(D_METHOD("viewport_attach_canvas", "viewport", "canvas"), &VisualServer::viewport_attach_canvas);
  1304. ClassDB::bind_method(D_METHOD("viewport_remove_canvas", "viewport", "canvas"), &VisualServer::viewport_remove_canvas);
  1305. ClassDB::bind_method(D_METHOD("viewport_set_canvas_transform", "viewport", "canvas", "offset"), &VisualServer::viewport_set_canvas_transform);
  1306. ClassDB::bind_method(D_METHOD("viewport_set_transparent_background", "viewport", "enabled"), &VisualServer::viewport_set_transparent_background);
  1307. ClassDB::bind_method(D_METHOD("viewport_set_global_canvas_transform", "viewport", "transform"), &VisualServer::viewport_set_global_canvas_transform);
  1308. ClassDB::bind_method(D_METHOD("viewport_set_canvas_layer", "viewport", "canvas", "layer"), &VisualServer::viewport_set_canvas_layer);
  1309. ClassDB::bind_method(D_METHOD("viewport_set_shadow_atlas_size", "viewport", "size"), &VisualServer::viewport_set_shadow_atlas_size);
  1310. ClassDB::bind_method(D_METHOD("viewport_set_shadow_atlas_quadrant_subdivision", "viewport", "quadrant", "subdivision"), &VisualServer::viewport_set_shadow_atlas_quadrant_subdivision);
  1311. ClassDB::bind_method(D_METHOD("viewport_set_msaa", "viewport", "msaa"), &VisualServer::viewport_set_msaa);
  1312. ClassDB::bind_method(D_METHOD("viewport_set_hdr", "viewport", "enabled"), &VisualServer::viewport_set_hdr);
  1313. ClassDB::bind_method(D_METHOD("viewport_set_usage", "viewport", "usage"), &VisualServer::viewport_set_usage);
  1314. ClassDB::bind_method(D_METHOD("viewport_get_render_info", "viewport", "info"), &VisualServer::viewport_get_render_info);
  1315. ClassDB::bind_method(D_METHOD("viewport_set_debug_draw", "viewport", "draw"), &VisualServer::viewport_set_debug_draw);
  1316. ClassDB::bind_method(D_METHOD("environment_create"), &VisualServer::environment_create);
  1317. ClassDB::bind_method(D_METHOD("environment_set_background", "env", "bg"), &VisualServer::environment_set_background);
  1318. ClassDB::bind_method(D_METHOD("environment_set_sky", "env", "sky"), &VisualServer::environment_set_sky);
  1319. ClassDB::bind_method(D_METHOD("environment_set_sky_custom_fov", "env", "scale"), &VisualServer::environment_set_sky_custom_fov);
  1320. ClassDB::bind_method(D_METHOD("environment_set_bg_color", "env", "color"), &VisualServer::environment_set_bg_color);
  1321. ClassDB::bind_method(D_METHOD("environment_set_bg_energy", "env", "energy"), &VisualServer::environment_set_bg_energy);
  1322. ClassDB::bind_method(D_METHOD("environment_set_canvas_max_layer", "env", "max_layer"), &VisualServer::environment_set_canvas_max_layer);
  1323. 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));
  1324. ClassDB::bind_method(D_METHOD("environment_set_dof_blur_near", "env", "enable", "distance", "transition", "far_amount", "quality"), &VisualServer::environment_set_dof_blur_near);
  1325. ClassDB::bind_method(D_METHOD("environment_set_dof_blur_far", "env", "enable", "distance", "transition", "far_amount", "quality"), &VisualServer::environment_set_dof_blur_far);
  1326. ClassDB::bind_method(D_METHOD("environment_set_glow", "env", "enable", "level_flags", "intensity", "strength", "bloom_threshold", "blend_mode", "hdr_bleed_threshold", "hdr_bleed_scale", "bicubic_upscale"), &VisualServer::environment_set_glow);
  1327. 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);
  1328. ClassDB::bind_method(D_METHOD("environment_set_adjustment", "env", "enable", "brightness", "contrast", "saturation", "ramp"), &VisualServer::environment_set_adjustment);
  1329. ClassDB::bind_method(D_METHOD("environment_set_ssr", "env", "enable", "max_steps", "fade_in", "fade_out", "depth_tolerance", "roughness"), &VisualServer::environment_set_ssr);
  1330. ClassDB::bind_method(D_METHOD("environment_set_ssao", "env", "enable", "radius", "intensity", "radius2", "intensity2", "bias", "light_affect", "color", "quality", "blur", "bilateral_sharpness"), &VisualServer::environment_set_ssao);
  1331. ClassDB::bind_method(D_METHOD("environment_set_fog", "env", "enable", "color", "sun_color", "sun_amount"), &VisualServer::environment_set_fog);
  1332. ClassDB::bind_method(D_METHOD("environment_set_fog_depth", "env", "enable", "depth_begin", "depth_curve", "transmit", "transmit_curve"), &VisualServer::environment_set_fog_depth);
  1333. ClassDB::bind_method(D_METHOD("environment_set_fog_height", "env", "enable", "min_height", "max_height", "height_curve"), &VisualServer::environment_set_fog_height);
  1334. ClassDB::bind_method(D_METHOD("scenario_create"), &VisualServer::scenario_create);
  1335. ClassDB::bind_method(D_METHOD("scenario_set_debug", "scenario", "debug_mode"), &VisualServer::scenario_set_debug);
  1336. ClassDB::bind_method(D_METHOD("scenario_set_environment", "scenario", "environment"), &VisualServer::scenario_set_environment);
  1337. ClassDB::bind_method(D_METHOD("scenario_set_reflection_atlas_size", "scenario", "p_size", "subdiv"), &VisualServer::scenario_set_reflection_atlas_size);
  1338. ClassDB::bind_method(D_METHOD("scenario_set_fallback_environment", "scenario", "environment"), &VisualServer::scenario_set_fallback_environment);
  1339. #ifndef _3D_DISABLED
  1340. ClassDB::bind_method(D_METHOD("instance_create2", "base", "scenario"), &VisualServer::instance_create2);
  1341. ClassDB::bind_method(D_METHOD("instance_create"), &VisualServer::instance_create);
  1342. ClassDB::bind_method(D_METHOD("instance_set_base", "instance", "base"), &VisualServer::instance_set_base);
  1343. ClassDB::bind_method(D_METHOD("instance_set_scenario", "instance", "scenario"), &VisualServer::instance_set_scenario);
  1344. ClassDB::bind_method(D_METHOD("instance_set_layer_mask", "instance", "mask"), &VisualServer::instance_set_layer_mask);
  1345. ClassDB::bind_method(D_METHOD("instance_set_transform", "instance", "transform"), &VisualServer::instance_set_transform);
  1346. ClassDB::bind_method(D_METHOD("instance_attach_object_instance_id", "instance", "id"), &VisualServer::instance_attach_object_instance_id);
  1347. ClassDB::bind_method(D_METHOD("instance_set_blend_shape_weight", "instance", "shape", "weight"), &VisualServer::instance_set_blend_shape_weight);
  1348. ClassDB::bind_method(D_METHOD("instance_set_surface_material", "instance", "surface", "material"), &VisualServer::instance_set_surface_material);
  1349. ClassDB::bind_method(D_METHOD("instance_set_visible", "instance", "visible"), &VisualServer::instance_set_visible);
  1350. ClassDB::bind_method(D_METHOD("instance_set_use_lightmap", "instance", "lightmap_instance", "lightmap"), &VisualServer::instance_set_use_lightmap);
  1351. ClassDB::bind_method(D_METHOD("instance_set_custom_aabb", "instance", "aabb"), &VisualServer::instance_set_custom_aabb);
  1352. ClassDB::bind_method(D_METHOD("instance_attach_skeleton", "instance", "skeleton"), &VisualServer::instance_attach_skeleton);
  1353. ClassDB::bind_method(D_METHOD("instance_set_exterior", "instance", "enabled"), &VisualServer::instance_set_exterior);
  1354. ClassDB::bind_method(D_METHOD("instance_set_extra_visibility_margin", "instance", "margin"), &VisualServer::instance_set_extra_visibility_margin);
  1355. ClassDB::bind_method(D_METHOD("instance_geometry_set_flag", "instance", "flag", "enabled"), &VisualServer::instance_geometry_set_flag);
  1356. ClassDB::bind_method(D_METHOD("instance_geometry_set_cast_shadows_setting", "instance", "shadow_casting_setting"), &VisualServer::instance_geometry_set_cast_shadows_setting);
  1357. ClassDB::bind_method(D_METHOD("instance_geometry_set_material_override", "instance", "material"), &VisualServer::instance_geometry_set_material_override);
  1358. ClassDB::bind_method(D_METHOD("instance_geometry_set_draw_range", "instance", "min", "max", "min_margin", "max_margin"), &VisualServer::instance_geometry_set_draw_range);
  1359. ClassDB::bind_method(D_METHOD("instance_geometry_set_as_instance_lod", "instance", "as_lod_of_instance"), &VisualServer::instance_geometry_set_as_instance_lod);
  1360. ClassDB::bind_method(D_METHOD("instances_cull_aabb", "aabb", "scenario"), &VisualServer::_instances_cull_aabb_bind, DEFVAL(RID()));
  1361. ClassDB::bind_method(D_METHOD("instances_cull_ray", "from", "to", "scenario"), &VisualServer::_instances_cull_ray_bind, DEFVAL(RID()));
  1362. ClassDB::bind_method(D_METHOD("instances_cull_convex", "convex", "scenario"), &VisualServer::_instances_cull_convex_bind, DEFVAL(RID()));
  1363. #endif
  1364. ClassDB::bind_method(D_METHOD("canvas_create"), &VisualServer::canvas_create);
  1365. ClassDB::bind_method(D_METHOD("canvas_set_item_mirroring", "canvas", "item", "mirroring"), &VisualServer::canvas_set_item_mirroring);
  1366. ClassDB::bind_method(D_METHOD("canvas_set_modulate", "canvas", "color"), &VisualServer::canvas_set_modulate);
  1367. ClassDB::bind_method(D_METHOD("canvas_item_create"), &VisualServer::canvas_item_create);
  1368. ClassDB::bind_method(D_METHOD("canvas_item_set_parent", "item", "parent"), &VisualServer::canvas_item_set_parent);
  1369. ClassDB::bind_method(D_METHOD("canvas_item_set_visible", "item", "visible"), &VisualServer::canvas_item_set_visible);
  1370. ClassDB::bind_method(D_METHOD("canvas_item_set_light_mask", "item", "mask"), &VisualServer::canvas_item_set_light_mask);
  1371. ClassDB::bind_method(D_METHOD("canvas_item_set_transform", "item", "transform"), &VisualServer::canvas_item_set_transform);
  1372. ClassDB::bind_method(D_METHOD("canvas_item_set_clip", "item", "clip"), &VisualServer::canvas_item_set_clip);
  1373. ClassDB::bind_method(D_METHOD("canvas_item_set_distance_field_mode", "item", "enabled"), &VisualServer::canvas_item_set_distance_field_mode);
  1374. ClassDB::bind_method(D_METHOD("canvas_item_set_custom_rect", "item", "use_custom_rect", "rect"), &VisualServer::canvas_item_set_custom_rect, DEFVAL(Rect2()));
  1375. ClassDB::bind_method(D_METHOD("canvas_item_set_modulate", "item", "color"), &VisualServer::canvas_item_set_modulate);
  1376. ClassDB::bind_method(D_METHOD("canvas_item_set_self_modulate", "item", "color"), &VisualServer::canvas_item_set_self_modulate);
  1377. ClassDB::bind_method(D_METHOD("canvas_item_set_draw_behind_parent", "item", "enabled"), &VisualServer::canvas_item_set_draw_behind_parent);
  1378. 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));
  1379. ClassDB::bind_method(D_METHOD("canvas_item_add_polyline", "item", "points", "colors", "width", "antialiased"), &VisualServer::canvas_item_add_polyline, DEFVAL(1.0), DEFVAL(false));
  1380. ClassDB::bind_method(D_METHOD("canvas_item_add_rect", "item", "rect", "color"), &VisualServer::canvas_item_add_rect);
  1381. ClassDB::bind_method(D_METHOD("canvas_item_add_circle", "item", "pos", "radius", "color"), &VisualServer::canvas_item_add_circle);
  1382. 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()));
  1383. 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));
  1384. 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()));
  1385. 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()));
  1386. 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));
  1387. ClassDB::bind_method(D_METHOD("canvas_item_add_triangle_array", "item", "indices", "points", "colors", "uvs", "bones", "weights", "texture", "count", "normal_map"), &VisualServer::canvas_item_add_triangle_array, DEFVAL(Vector<Point2>()), DEFVAL(Vector<int>()), DEFVAL(Vector<float>()), DEFVAL(RID()), DEFVAL(-1), DEFVAL(RID()));
  1388. ClassDB::bind_method(D_METHOD("canvas_item_add_mesh", "item", "mesh", "texture", "normal_map"), &VisualServer::canvas_item_add_mesh, DEFVAL(RID()));
  1389. ClassDB::bind_method(D_METHOD("canvas_item_add_multimesh", "item", "mesh", "texture", "normal_map"), &VisualServer::canvas_item_add_multimesh, DEFVAL(RID()));
  1390. ClassDB::bind_method(D_METHOD("canvas_item_add_particles", "item", "particles", "texture", "normal_map", "h_frames", "v_frames"), &VisualServer::canvas_item_add_particles);
  1391. ClassDB::bind_method(D_METHOD("canvas_item_add_set_transform", "item", "transform"), &VisualServer::canvas_item_add_set_transform);
  1392. ClassDB::bind_method(D_METHOD("canvas_item_add_clip_ignore", "item", "ignore"), &VisualServer::canvas_item_add_clip_ignore);
  1393. ClassDB::bind_method(D_METHOD("canvas_item_set_sort_children_by_y", "item", "enabled"), &VisualServer::canvas_item_set_sort_children_by_y);
  1394. ClassDB::bind_method(D_METHOD("canvas_item_set_z_index", "item", "z_index"), &VisualServer::canvas_item_set_z_index);
  1395. ClassDB::bind_method(D_METHOD("canvas_item_set_z_as_relative_to_parent", "item", "enabled"), &VisualServer::canvas_item_set_z_as_relative_to_parent);
  1396. ClassDB::bind_method(D_METHOD("canvas_item_set_copy_to_backbuffer", "item", "enabled", "rect"), &VisualServer::canvas_item_set_copy_to_backbuffer);
  1397. ClassDB::bind_method(D_METHOD("canvas_item_clear", "item"), &VisualServer::canvas_item_clear);
  1398. ClassDB::bind_method(D_METHOD("canvas_item_set_draw_index", "item", "index"), &VisualServer::canvas_item_set_draw_index);
  1399. ClassDB::bind_method(D_METHOD("canvas_item_set_material", "item", "material"), &VisualServer::canvas_item_set_material);
  1400. ClassDB::bind_method(D_METHOD("canvas_item_set_use_parent_material", "item", "enabled"), &VisualServer::canvas_item_set_use_parent_material);
  1401. ClassDB::bind_method(D_METHOD("canvas_light_create"), &VisualServer::canvas_light_create);
  1402. ClassDB::bind_method(D_METHOD("canvas_light_attach_to_canvas", "light", "canvas"), &VisualServer::canvas_light_attach_to_canvas);
  1403. ClassDB::bind_method(D_METHOD("canvas_light_set_enabled", "light", "enabled"), &VisualServer::canvas_light_set_enabled);
  1404. ClassDB::bind_method(D_METHOD("canvas_light_set_scale", "light", "scale"), &VisualServer::canvas_light_set_scale);
  1405. ClassDB::bind_method(D_METHOD("canvas_light_set_transform", "light", "transform"), &VisualServer::canvas_light_set_transform);
  1406. ClassDB::bind_method(D_METHOD("canvas_light_set_texture", "light", "texture"), &VisualServer::canvas_light_set_texture);
  1407. ClassDB::bind_method(D_METHOD("canvas_light_set_texture_offset", "light", "offset"), &VisualServer::canvas_light_set_texture_offset);
  1408. ClassDB::bind_method(D_METHOD("canvas_light_set_color", "light", "color"), &VisualServer::canvas_light_set_color);
  1409. ClassDB::bind_method(D_METHOD("canvas_light_set_height", "light", "height"), &VisualServer::canvas_light_set_height);
  1410. ClassDB::bind_method(D_METHOD("canvas_light_set_energy", "light", "energy"), &VisualServer::canvas_light_set_energy);
  1411. ClassDB::bind_method(D_METHOD("canvas_light_set_z_range", "light", "min_z", "max_z"), &VisualServer::canvas_light_set_z_range);
  1412. ClassDB::bind_method(D_METHOD("canvas_light_set_layer_range", "light", "min_layer", "max_layer"), &VisualServer::canvas_light_set_layer_range);
  1413. ClassDB::bind_method(D_METHOD("canvas_light_set_item_cull_mask", "light", "mask"), &VisualServer::canvas_light_set_item_cull_mask);
  1414. ClassDB::bind_method(D_METHOD("canvas_light_set_item_shadow_cull_mask", "light", "mask"), &VisualServer::canvas_light_set_item_shadow_cull_mask);
  1415. ClassDB::bind_method(D_METHOD("canvas_light_set_mode", "light", "mode"), &VisualServer::canvas_light_set_mode);
  1416. ClassDB::bind_method(D_METHOD("canvas_light_set_shadow_enabled", "light", "enabled"), &VisualServer::canvas_light_set_shadow_enabled);
  1417. ClassDB::bind_method(D_METHOD("canvas_light_set_shadow_buffer_size", "light", "size"), &VisualServer::canvas_light_set_shadow_buffer_size);
  1418. ClassDB::bind_method(D_METHOD("canvas_light_set_shadow_gradient_length", "light", "length"), &VisualServer::canvas_light_set_shadow_gradient_length);
  1419. ClassDB::bind_method(D_METHOD("canvas_light_set_shadow_filter", "light", "filter"), &VisualServer::canvas_light_set_shadow_filter);
  1420. ClassDB::bind_method(D_METHOD("canvas_light_set_shadow_color", "light", "color"), &VisualServer::canvas_light_set_shadow_color);
  1421. ClassDB::bind_method(D_METHOD("canvas_light_set_shadow_smooth", "light", "smooth"), &VisualServer::canvas_light_set_shadow_smooth);
  1422. ClassDB::bind_method(D_METHOD("canvas_light_occluder_create"), &VisualServer::canvas_light_occluder_create);
  1423. ClassDB::bind_method(D_METHOD("canvas_light_occluder_attach_to_canvas", "occluder", "canvas"), &VisualServer::canvas_light_occluder_attach_to_canvas);
  1424. ClassDB::bind_method(D_METHOD("canvas_light_occluder_set_enabled", "occluder", "enabled"), &VisualServer::canvas_light_occluder_set_enabled);
  1425. ClassDB::bind_method(D_METHOD("canvas_light_occluder_set_polygon", "occluder", "polygon"), &VisualServer::canvas_light_occluder_set_polygon);
  1426. ClassDB::bind_method(D_METHOD("canvas_light_occluder_set_transform", "occluder", "transform"), &VisualServer::canvas_light_occluder_set_transform);
  1427. ClassDB::bind_method(D_METHOD("canvas_light_occluder_set_light_mask", "occluder", "mask"), &VisualServer::canvas_light_occluder_set_light_mask);
  1428. ClassDB::bind_method(D_METHOD("canvas_occluder_polygon_create"), &VisualServer::canvas_occluder_polygon_create);
  1429. ClassDB::bind_method(D_METHOD("canvas_occluder_polygon_set_shape", "occluder_polygon", "shape", "closed"), &VisualServer::canvas_occluder_polygon_set_shape);
  1430. ClassDB::bind_method(D_METHOD("canvas_occluder_polygon_set_shape_as_lines", "occluder_polygon", "shape"), &VisualServer::canvas_occluder_polygon_set_shape_as_lines);
  1431. ClassDB::bind_method(D_METHOD("canvas_occluder_polygon_set_cull_mode", "occluder_polygon", "mode"), &VisualServer::canvas_occluder_polygon_set_cull_mode);
  1432. ClassDB::bind_method(D_METHOD("black_bars_set_margins", "left", "top", "right", "bottom"), &VisualServer::black_bars_set_margins);
  1433. ClassDB::bind_method(D_METHOD("black_bars_set_images", "left", "top", "right", "bottom"), &VisualServer::black_bars_set_images);
  1434. ClassDB::bind_method(D_METHOD("free_rid", "rid"), &VisualServer::free); // shouldn't conflict with Object::free()
  1435. ClassDB::bind_method(D_METHOD("request_frame_drawn_callback", "where", "method", "userdata"), &VisualServer::request_frame_drawn_callback);
  1436. ClassDB::bind_method(D_METHOD("has_changed"), &VisualServer::has_changed);
  1437. ClassDB::bind_method(D_METHOD("init"), &VisualServer::init);
  1438. ClassDB::bind_method(D_METHOD("finish"), &VisualServer::finish);
  1439. ClassDB::bind_method(D_METHOD("get_render_info", "info"), &VisualServer::get_render_info);
  1440. #ifndef _3D_DISABLED
  1441. ClassDB::bind_method(D_METHOD("make_sphere_mesh", "latitudes", "longitudes", "radius"), &VisualServer::make_sphere_mesh);
  1442. ClassDB::bind_method(D_METHOD("get_test_cube"), &VisualServer::get_test_cube);
  1443. #endif
  1444. ClassDB::bind_method(D_METHOD("get_test_texture"), &VisualServer::get_test_texture);
  1445. ClassDB::bind_method(D_METHOD("get_white_texture"), &VisualServer::get_white_texture);
  1446. ClassDB::bind_method(D_METHOD("set_boot_image", "image", "color", "scale"), &VisualServer::set_boot_image);
  1447. ClassDB::bind_method(D_METHOD("set_default_clear_color", "color"), &VisualServer::set_default_clear_color);
  1448. ClassDB::bind_method(D_METHOD("has_feature", "feature"), &VisualServer::has_feature);
  1449. ClassDB::bind_method(D_METHOD("has_os_feature", "feature"), &VisualServer::has_os_feature);
  1450. ClassDB::bind_method(D_METHOD("set_debug_generate_wireframes", "generate"), &VisualServer::set_debug_generate_wireframes);
  1451. BIND_CONSTANT(NO_INDEX_ARRAY);
  1452. BIND_CONSTANT(ARRAY_WEIGHTS_SIZE);
  1453. BIND_CONSTANT(CANVAS_ITEM_Z_MIN);
  1454. BIND_CONSTANT(CANVAS_ITEM_Z_MAX);
  1455. BIND_CONSTANT(MAX_GLOW_LEVELS);
  1456. BIND_CONSTANT(MAX_CURSORS);
  1457. BIND_CONSTANT(MATERIAL_RENDER_PRIORITY_MIN);
  1458. BIND_CONSTANT(MATERIAL_RENDER_PRIORITY_MAX);
  1459. BIND_ENUM_CONSTANT(CUBEMAP_LEFT);
  1460. BIND_ENUM_CONSTANT(CUBEMAP_RIGHT);
  1461. BIND_ENUM_CONSTANT(CUBEMAP_BOTTOM);
  1462. BIND_ENUM_CONSTANT(CUBEMAP_TOP);
  1463. BIND_ENUM_CONSTANT(CUBEMAP_FRONT);
  1464. BIND_ENUM_CONSTANT(CUBEMAP_BACK);
  1465. BIND_ENUM_CONSTANT(TEXTURE_FLAG_MIPMAPS);
  1466. BIND_ENUM_CONSTANT(TEXTURE_FLAG_REPEAT);
  1467. BIND_ENUM_CONSTANT(TEXTURE_FLAG_FILTER);
  1468. BIND_ENUM_CONSTANT(TEXTURE_FLAG_ANISOTROPIC_FILTER);
  1469. BIND_ENUM_CONSTANT(TEXTURE_FLAG_CONVERT_TO_LINEAR);
  1470. BIND_ENUM_CONSTANT(TEXTURE_FLAG_MIRRORED_REPEAT);
  1471. BIND_ENUM_CONSTANT(TEXTURE_FLAG_CUBEMAP);
  1472. BIND_ENUM_CONSTANT(TEXTURE_FLAG_USED_FOR_STREAMING);
  1473. BIND_ENUM_CONSTANT(TEXTURE_FLAGS_DEFAULT);
  1474. BIND_ENUM_CONSTANT(SHADER_SPATIAL);
  1475. BIND_ENUM_CONSTANT(SHADER_CANVAS_ITEM);
  1476. BIND_ENUM_CONSTANT(SHADER_PARTICLES);
  1477. BIND_ENUM_CONSTANT(SHADER_MAX);
  1478. BIND_ENUM_CONSTANT(ARRAY_VERTEX);
  1479. BIND_ENUM_CONSTANT(ARRAY_NORMAL);
  1480. BIND_ENUM_CONSTANT(ARRAY_TANGENT);
  1481. BIND_ENUM_CONSTANT(ARRAY_COLOR);
  1482. BIND_ENUM_CONSTANT(ARRAY_TEX_UV);
  1483. BIND_ENUM_CONSTANT(ARRAY_TEX_UV2);
  1484. BIND_ENUM_CONSTANT(ARRAY_BONES);
  1485. BIND_ENUM_CONSTANT(ARRAY_WEIGHTS);
  1486. BIND_ENUM_CONSTANT(ARRAY_INDEX);
  1487. BIND_ENUM_CONSTANT(ARRAY_MAX);
  1488. BIND_ENUM_CONSTANT(ARRAY_FORMAT_VERTEX);
  1489. BIND_ENUM_CONSTANT(ARRAY_FORMAT_NORMAL);
  1490. BIND_ENUM_CONSTANT(ARRAY_FORMAT_TANGENT);
  1491. BIND_ENUM_CONSTANT(ARRAY_FORMAT_COLOR);
  1492. BIND_ENUM_CONSTANT(ARRAY_FORMAT_TEX_UV);
  1493. BIND_ENUM_CONSTANT(ARRAY_FORMAT_TEX_UV2);
  1494. BIND_ENUM_CONSTANT(ARRAY_FORMAT_BONES);
  1495. BIND_ENUM_CONSTANT(ARRAY_FORMAT_WEIGHTS);
  1496. BIND_ENUM_CONSTANT(ARRAY_FORMAT_INDEX);
  1497. BIND_ENUM_CONSTANT(ARRAY_COMPRESS_VERTEX);
  1498. BIND_ENUM_CONSTANT(ARRAY_COMPRESS_NORMAL);
  1499. BIND_ENUM_CONSTANT(ARRAY_COMPRESS_TANGENT);
  1500. BIND_ENUM_CONSTANT(ARRAY_COMPRESS_COLOR);
  1501. BIND_ENUM_CONSTANT(ARRAY_COMPRESS_TEX_UV);
  1502. BIND_ENUM_CONSTANT(ARRAY_COMPRESS_TEX_UV2);
  1503. BIND_ENUM_CONSTANT(ARRAY_COMPRESS_BONES);
  1504. BIND_ENUM_CONSTANT(ARRAY_COMPRESS_WEIGHTS);
  1505. BIND_ENUM_CONSTANT(ARRAY_COMPRESS_INDEX);
  1506. BIND_ENUM_CONSTANT(ARRAY_FLAG_USE_2D_VERTICES);
  1507. BIND_ENUM_CONSTANT(ARRAY_FLAG_USE_16_BIT_BONES);
  1508. BIND_ENUM_CONSTANT(ARRAY_COMPRESS_DEFAULT);
  1509. BIND_ENUM_CONSTANT(PRIMITIVE_POINTS);
  1510. BIND_ENUM_CONSTANT(PRIMITIVE_LINES);
  1511. BIND_ENUM_CONSTANT(PRIMITIVE_LINE_STRIP);
  1512. BIND_ENUM_CONSTANT(PRIMITIVE_LINE_LOOP);
  1513. BIND_ENUM_CONSTANT(PRIMITIVE_TRIANGLES);
  1514. BIND_ENUM_CONSTANT(PRIMITIVE_TRIANGLE_STRIP);
  1515. BIND_ENUM_CONSTANT(PRIMITIVE_TRIANGLE_FAN);
  1516. BIND_ENUM_CONSTANT(PRIMITIVE_MAX);
  1517. BIND_ENUM_CONSTANT(BLEND_SHAPE_MODE_NORMALIZED);
  1518. BIND_ENUM_CONSTANT(BLEND_SHAPE_MODE_RELATIVE);
  1519. BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL);
  1520. BIND_ENUM_CONSTANT(LIGHT_OMNI);
  1521. BIND_ENUM_CONSTANT(LIGHT_SPOT);
  1522. BIND_ENUM_CONSTANT(LIGHT_PARAM_ENERGY);
  1523. BIND_ENUM_CONSTANT(LIGHT_PARAM_SPECULAR);
  1524. BIND_ENUM_CONSTANT(LIGHT_PARAM_RANGE);
  1525. BIND_ENUM_CONSTANT(LIGHT_PARAM_ATTENUATION);
  1526. BIND_ENUM_CONSTANT(LIGHT_PARAM_SPOT_ANGLE);
  1527. BIND_ENUM_CONSTANT(LIGHT_PARAM_SPOT_ATTENUATION);
  1528. BIND_ENUM_CONSTANT(LIGHT_PARAM_CONTACT_SHADOW_SIZE);
  1529. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_MAX_DISTANCE);
  1530. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_SPLIT_1_OFFSET);
  1531. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_SPLIT_2_OFFSET);
  1532. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_SPLIT_3_OFFSET);
  1533. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_NORMAL_BIAS);
  1534. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_BIAS);
  1535. BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_BIAS_SPLIT_SCALE);
  1536. BIND_ENUM_CONSTANT(LIGHT_PARAM_MAX);
  1537. BIND_ENUM_CONSTANT(LIGHT_OMNI_SHADOW_DUAL_PARABOLOID);
  1538. BIND_ENUM_CONSTANT(LIGHT_OMNI_SHADOW_CUBE);
  1539. BIND_ENUM_CONSTANT(LIGHT_OMNI_SHADOW_DETAIL_VERTICAL);
  1540. BIND_ENUM_CONSTANT(LIGHT_OMNI_SHADOW_DETAIL_HORIZONTAL);
  1541. BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL);
  1542. BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS);
  1543. BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS);
  1544. BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_STABLE);
  1545. BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_OPTIMIZED);
  1546. BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_DISABLED);
  1547. BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_ONCE);
  1548. BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_WHEN_VISIBLE);
  1549. BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_ALWAYS);
  1550. BIND_ENUM_CONSTANT(VIEWPORT_CLEAR_ALWAYS);
  1551. BIND_ENUM_CONSTANT(VIEWPORT_CLEAR_NEVER);
  1552. BIND_ENUM_CONSTANT(VIEWPORT_CLEAR_ONLY_NEXT_FRAME);
  1553. BIND_ENUM_CONSTANT(VIEWPORT_MSAA_DISABLED);
  1554. BIND_ENUM_CONSTANT(VIEWPORT_MSAA_2X);
  1555. BIND_ENUM_CONSTANT(VIEWPORT_MSAA_4X);
  1556. BIND_ENUM_CONSTANT(VIEWPORT_MSAA_8X);
  1557. BIND_ENUM_CONSTANT(VIEWPORT_MSAA_16X);
  1558. BIND_ENUM_CONSTANT(VIEWPORT_USAGE_2D);
  1559. BIND_ENUM_CONSTANT(VIEWPORT_USAGE_2D_NO_SAMPLING);
  1560. BIND_ENUM_CONSTANT(VIEWPORT_USAGE_3D);
  1561. BIND_ENUM_CONSTANT(VIEWPORT_USAGE_3D_NO_EFFECTS);
  1562. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_OBJECTS_IN_FRAME);
  1563. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_VERTICES_IN_FRAME);
  1564. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_MATERIAL_CHANGES_IN_FRAME);
  1565. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_SHADER_CHANGES_IN_FRAME);
  1566. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_SURFACE_CHANGES_IN_FRAME);
  1567. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_DRAW_CALLS_IN_FRAME);
  1568. BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_MAX);
  1569. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_DISABLED);
  1570. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_UNSHADED);
  1571. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_OVERDRAW);
  1572. BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_WIREFRAME);
  1573. BIND_ENUM_CONSTANT(SCENARIO_DEBUG_DISABLED);
  1574. BIND_ENUM_CONSTANT(SCENARIO_DEBUG_WIREFRAME);
  1575. BIND_ENUM_CONSTANT(SCENARIO_DEBUG_OVERDRAW);
  1576. BIND_ENUM_CONSTANT(SCENARIO_DEBUG_SHADELESS);
  1577. BIND_ENUM_CONSTANT(INSTANCE_NONE);
  1578. BIND_ENUM_CONSTANT(INSTANCE_MESH);
  1579. BIND_ENUM_CONSTANT(INSTANCE_MULTIMESH);
  1580. BIND_ENUM_CONSTANT(INSTANCE_IMMEDIATE);
  1581. BIND_ENUM_CONSTANT(INSTANCE_PARTICLES);
  1582. BIND_ENUM_CONSTANT(INSTANCE_LIGHT);
  1583. BIND_ENUM_CONSTANT(INSTANCE_REFLECTION_PROBE);
  1584. BIND_ENUM_CONSTANT(INSTANCE_GI_PROBE);
  1585. BIND_ENUM_CONSTANT(INSTANCE_LIGHTMAP_CAPTURE);
  1586. BIND_ENUM_CONSTANT(INSTANCE_MAX);
  1587. BIND_ENUM_CONSTANT(INSTANCE_GEOMETRY_MASK);
  1588. BIND_ENUM_CONSTANT(INSTANCE_FLAG_USE_BAKED_LIGHT);
  1589. BIND_ENUM_CONSTANT(INSTANCE_FLAG_REDRAW_FRAME_IF_VISIBLE);
  1590. BIND_ENUM_CONSTANT(INSTANCE_FLAG_MAX);
  1591. BIND_ENUM_CONSTANT(SHADOW_CASTING_SETTING_OFF);
  1592. BIND_ENUM_CONSTANT(SHADOW_CASTING_SETTING_ON);
  1593. BIND_ENUM_CONSTANT(SHADOW_CASTING_SETTING_DOUBLE_SIDED);
  1594. BIND_ENUM_CONSTANT(SHADOW_CASTING_SETTING_SHADOWS_ONLY);
  1595. BIND_ENUM_CONSTANT(NINE_PATCH_STRETCH);
  1596. BIND_ENUM_CONSTANT(NINE_PATCH_TILE);
  1597. BIND_ENUM_CONSTANT(NINE_PATCH_TILE_FIT);
  1598. BIND_ENUM_CONSTANT(CANVAS_LIGHT_MODE_ADD);
  1599. BIND_ENUM_CONSTANT(CANVAS_LIGHT_MODE_SUB);
  1600. BIND_ENUM_CONSTANT(CANVAS_LIGHT_MODE_MIX);
  1601. BIND_ENUM_CONSTANT(CANVAS_LIGHT_MODE_MASK);
  1602. BIND_ENUM_CONSTANT(CANVAS_LIGHT_FILTER_NONE);
  1603. BIND_ENUM_CONSTANT(CANVAS_LIGHT_FILTER_PCF3);
  1604. BIND_ENUM_CONSTANT(CANVAS_LIGHT_FILTER_PCF5);
  1605. BIND_ENUM_CONSTANT(CANVAS_LIGHT_FILTER_PCF7);
  1606. BIND_ENUM_CONSTANT(CANVAS_LIGHT_FILTER_PCF9);
  1607. BIND_ENUM_CONSTANT(CANVAS_LIGHT_FILTER_PCF13);
  1608. BIND_ENUM_CONSTANT(CANVAS_OCCLUDER_POLYGON_CULL_DISABLED);
  1609. BIND_ENUM_CONSTANT(CANVAS_OCCLUDER_POLYGON_CULL_CLOCKWISE);
  1610. BIND_ENUM_CONSTANT(CANVAS_OCCLUDER_POLYGON_CULL_COUNTER_CLOCKWISE);
  1611. BIND_ENUM_CONSTANT(INFO_OBJECTS_IN_FRAME);
  1612. BIND_ENUM_CONSTANT(INFO_VERTICES_IN_FRAME);
  1613. BIND_ENUM_CONSTANT(INFO_MATERIAL_CHANGES_IN_FRAME);
  1614. BIND_ENUM_CONSTANT(INFO_SHADER_CHANGES_IN_FRAME);
  1615. BIND_ENUM_CONSTANT(INFO_SURFACE_CHANGES_IN_FRAME);
  1616. BIND_ENUM_CONSTANT(INFO_DRAW_CALLS_IN_FRAME);
  1617. BIND_ENUM_CONSTANT(INFO_USAGE_VIDEO_MEM_TOTAL);
  1618. BIND_ENUM_CONSTANT(INFO_VIDEO_MEM_USED);
  1619. BIND_ENUM_CONSTANT(INFO_TEXTURE_MEM_USED);
  1620. BIND_ENUM_CONSTANT(INFO_VERTEX_MEM_USED);
  1621. BIND_ENUM_CONSTANT(FEATURE_SHADERS);
  1622. BIND_ENUM_CONSTANT(FEATURE_MULTITHREADED);
  1623. BIND_ENUM_CONSTANT(MULTIMESH_TRANSFORM_2D);
  1624. BIND_ENUM_CONSTANT(MULTIMESH_TRANSFORM_3D);
  1625. BIND_ENUM_CONSTANT(MULTIMESH_COLOR_NONE);
  1626. BIND_ENUM_CONSTANT(MULTIMESH_COLOR_8BIT);
  1627. BIND_ENUM_CONSTANT(MULTIMESH_COLOR_FLOAT);
  1628. BIND_ENUM_CONSTANT(REFLECTION_PROBE_UPDATE_ONCE);
  1629. BIND_ENUM_CONSTANT(REFLECTION_PROBE_UPDATE_ALWAYS);
  1630. BIND_ENUM_CONSTANT(PARTICLES_DRAW_ORDER_INDEX);
  1631. BIND_ENUM_CONSTANT(PARTICLES_DRAW_ORDER_LIFETIME);
  1632. BIND_ENUM_CONSTANT(PARTICLES_DRAW_ORDER_VIEW_DEPTH);
  1633. BIND_ENUM_CONSTANT(ENV_BG_CLEAR_COLOR);
  1634. BIND_ENUM_CONSTANT(ENV_BG_COLOR);
  1635. BIND_ENUM_CONSTANT(ENV_BG_SKY);
  1636. BIND_ENUM_CONSTANT(ENV_BG_COLOR_SKY);
  1637. BIND_ENUM_CONSTANT(ENV_BG_CANVAS);
  1638. BIND_ENUM_CONSTANT(ENV_BG_KEEP);
  1639. BIND_ENUM_CONSTANT(ENV_BG_MAX);
  1640. BIND_ENUM_CONSTANT(ENV_DOF_BLUR_QUALITY_LOW);
  1641. BIND_ENUM_CONSTANT(ENV_DOF_BLUR_QUALITY_MEDIUM);
  1642. BIND_ENUM_CONSTANT(ENV_DOF_BLUR_QUALITY_HIGH);
  1643. BIND_ENUM_CONSTANT(GLOW_BLEND_MODE_ADDITIVE);
  1644. BIND_ENUM_CONSTANT(GLOW_BLEND_MODE_SCREEN);
  1645. BIND_ENUM_CONSTANT(GLOW_BLEND_MODE_SOFTLIGHT);
  1646. BIND_ENUM_CONSTANT(GLOW_BLEND_MODE_REPLACE);
  1647. BIND_ENUM_CONSTANT(ENV_TONE_MAPPER_LINEAR);
  1648. BIND_ENUM_CONSTANT(ENV_TONE_MAPPER_REINHARDT);
  1649. BIND_ENUM_CONSTANT(ENV_TONE_MAPPER_FILMIC);
  1650. BIND_ENUM_CONSTANT(ENV_TONE_MAPPER_ACES);
  1651. BIND_ENUM_CONSTANT(ENV_SSAO_QUALITY_LOW);
  1652. BIND_ENUM_CONSTANT(ENV_SSAO_QUALITY_MEDIUM);
  1653. BIND_ENUM_CONSTANT(ENV_SSAO_QUALITY_HIGH);
  1654. BIND_ENUM_CONSTANT(ENV_SSAO_BLUR_DISABLED);
  1655. BIND_ENUM_CONSTANT(ENV_SSAO_BLUR_1x1);
  1656. BIND_ENUM_CONSTANT(ENV_SSAO_BLUR_2x2);
  1657. BIND_ENUM_CONSTANT(ENV_SSAO_BLUR_3x3);
  1658. ADD_SIGNAL(MethodInfo("frame_pre_draw"));
  1659. ADD_SIGNAL(MethodInfo("frame_post_draw"));
  1660. }
  1661. 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) {
  1662. ERR_FAIL_COND(p_margins.size() != 4);
  1663. //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);
  1664. }
  1665. void VisualServer::_camera_set_orthogonal(RID p_camera, float p_size, float p_z_near, float p_z_far) {
  1666. camera_set_orthogonal(p_camera, p_size, p_z_near, p_z_far);
  1667. }
  1668. void VisualServer::mesh_add_surface_from_mesh_data(RID p_mesh, const Geometry::MeshData &p_mesh_data) {
  1669. PoolVector<Vector3> vertices;
  1670. PoolVector<Vector3> normals;
  1671. for (int i = 0; i < p_mesh_data.faces.size(); i++) {
  1672. const Geometry::MeshData::Face &f = p_mesh_data.faces[i];
  1673. for (int j = 2; j < f.indices.size(); j++) {
  1674. #define _ADD_VERTEX(m_idx) \
  1675. vertices.push_back(p_mesh_data.vertices[f.indices[m_idx]]); \
  1676. normals.push_back(f.plane.normal);
  1677. _ADD_VERTEX(0);
  1678. _ADD_VERTEX(j - 1);
  1679. _ADD_VERTEX(j);
  1680. }
  1681. }
  1682. Array d;
  1683. d.resize(VS::ARRAY_MAX);
  1684. d[ARRAY_VERTEX] = vertices;
  1685. d[ARRAY_NORMAL] = normals;
  1686. mesh_add_surface_from_arrays(p_mesh, PRIMITIVE_TRIANGLES, d);
  1687. }
  1688. void VisualServer::mesh_add_surface_from_planes(RID p_mesh, const PoolVector<Plane> &p_planes) {
  1689. Geometry::MeshData mdata = Geometry::build_convex_mesh(p_planes);
  1690. mesh_add_surface_from_mesh_data(p_mesh, mdata);
  1691. }
  1692. void VisualServer::immediate_vertex_2d(RID p_immediate, const Vector2 &p_vertex) {
  1693. immediate_vertex(p_immediate, Vector3(p_vertex.x, p_vertex.y, 0));
  1694. }
  1695. RID VisualServer::instance_create2(RID p_base, RID p_scenario) {
  1696. RID instance = instance_create();
  1697. instance_set_base(instance, p_base);
  1698. instance_set_scenario(instance, p_scenario);
  1699. return instance;
  1700. }
  1701. VisualServer::VisualServer() {
  1702. //ERR_FAIL_COND(singleton);
  1703. singleton = this;
  1704. GLOBAL_DEF("rendering/vram_compression/import_s3tc", true);
  1705. GLOBAL_DEF("rendering/vram_compression/import_etc", false);
  1706. GLOBAL_DEF("rendering/vram_compression/import_etc2", true);
  1707. GLOBAL_DEF("rendering/vram_compression/import_pvrtc", false);
  1708. GLOBAL_DEF("rendering/quality/directional_shadow/size", 4096);
  1709. GLOBAL_DEF("rendering/quality/directional_shadow/size.mobile", 2048);
  1710. GLOBAL_DEF("rendering/quality/shadow_atlas/size", 4096);
  1711. GLOBAL_DEF("rendering/quality/shadow_atlas/size.mobile", 2048);
  1712. 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"));
  1713. GLOBAL_DEF("rendering/quality/shadow_atlas/quadrant_0_subdiv", 1);
  1714. GLOBAL_DEF("rendering/quality/shadow_atlas/quadrant_1_subdiv", 2);
  1715. GLOBAL_DEF("rendering/quality/shadow_atlas/quadrant_2_subdiv", 3);
  1716. GLOBAL_DEF("rendering/quality/shadow_atlas/quadrant_3_subdiv", 4);
  1717. 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"));
  1718. 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"));
  1719. 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"));
  1720. 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"));
  1721. GLOBAL_DEF("rendering/quality/shadows/filter_mode", 1);
  1722. GLOBAL_DEF("rendering/quality/shadows/filter_mode.mobile", 0);
  1723. 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"));
  1724. GLOBAL_DEF("rendering/quality/reflections/texture_array_reflections", true);
  1725. GLOBAL_DEF("rendering/quality/reflections/texture_array_reflections.mobile", false);
  1726. GLOBAL_DEF("rendering/quality/reflections/high_quality_ggx", true);
  1727. GLOBAL_DEF("rendering/quality/reflections/high_quality_ggx.mobile", false);
  1728. GLOBAL_DEF("rendering/quality/shading/force_vertex_shading", false);
  1729. GLOBAL_DEF("rendering/quality/shading/force_vertex_shading.mobile", true);
  1730. GLOBAL_DEF("rendering/quality/depth_prepass/enable", true);
  1731. GLOBAL_DEF("rendering/quality/depth_prepass/disable_for_vendors", "PowerVR,Mali,Adreno");
  1732. }
  1733. VisualServer::~VisualServer() {
  1734. singleton = NULL;
  1735. }