main.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // ../../make --run
  2. /// include "../../sources/libs/asim.h"
  3. let body: any;
  4. function main() {
  5. let ops: iron_window_options_t = {
  6. title : "Empty",
  7. width : 1280,
  8. height : 720,
  9. x : -1,
  10. y : -1,
  11. features : window_features_t.RESIZABLE | window_features_t.MINIMIZABLE | window_features_t.MAXIMIZABLE,
  12. mode : iron_window_mode_t.WINDOW,
  13. frequency : 60,
  14. vsync : true,
  15. depth_bits : 32
  16. };
  17. sys_start(ops);
  18. ready();
  19. }
  20. function render_commands() {
  21. render_path_set_target("", null, null, gpu_clear_t.COLOR | gpu_clear_t.DEPTH, 0xff6495ed, 1.0);
  22. render_path_draw_meshes("mesh");
  23. }
  24. function ready() {
  25. render_path_commands = render_commands;
  26. let scene: scene_t = {
  27. name : "Scene",
  28. objects : [
  29. {name : "Cube", type : "mesh_object", data_ref : "cube.arm/Cube", material_ref : "MyMaterial", visible : true, spawn : true},
  30. {name : "Sphere", type : "mesh_object", data_ref : "sphere.arm/Sphere", material_ref : "MyMaterial", visible : true, spawn : true},
  31. {name : "Camera", type : "camera_object", data_ref : "MyCamera", visible : true, spawn : true}
  32. ],
  33. camera_datas : [ {name : "MyCamera", near_plane : 0.1, far_plane : 100.0, fov : 0.85} ],
  34. camera_ref : "Camera",
  35. material_datas :
  36. [ {name : "MyMaterial", shader : "MyShader", contexts : [ {name : "mesh", bind_textures : [ {name : "my_texture", file : "texture.k"} ]} ]} ],
  37. shader_datas : [ {
  38. name : "MyShader",
  39. contexts : [ {
  40. name : "mesh",
  41. vertex_shader : "mesh.vert",
  42. fragment_shader : "mesh.frag",
  43. compare_mode : "less",
  44. cull_mode : "clockwise",
  45. depth_write : true,
  46. vertex_elements : [ {name : "pos", data : "short4norm"}, {name : "nor", data : "short2norm"}, {name : "tex", data : "short2norm"} ],
  47. constants : [ {name : "WVP", type : "mat4", link : "_world_view_proj_matrix"} ],
  48. texture_units : [ {name : "my_texture"} ]
  49. } ]
  50. } ]
  51. };
  52. map_set(data_cached_scene_raws, scene.name, scene);
  53. // Instantiate scene
  54. scene_create(scene);
  55. scene_ready();
  56. }
  57. function scene_ready() {
  58. // Set camera
  59. let t: transform_t = scene_camera.base.transform;
  60. t.loc = vec4_create(0, -10, 0);
  61. t.rot = quat_from_to(vec4_create(0, 0, 1), vec4_create(0, -1, 0));
  62. transform_build_matrix(t);
  63. sys_notify_on_update(scene_update);
  64. let cube: object_t = scene_get_child("Cube");
  65. let mesh: mesh_object_t = cube.ext;
  66. asim_world_create();
  67. body = asim_body_create(1, 1, 1, 1, 1, 0, 0, 5, null, null, 1);
  68. asim_body_create(0, 1, 1, 1, 1, 0, 0, 0, mesh.data.vertex_arrays[0].values, mesh.data.index_array, mesh.data.scale_pos);
  69. }
  70. function scene_update(_: any) {
  71. asim_world_update(sys_delta());
  72. camera_update();
  73. if (keyboard_started("space")) {
  74. asim_body_sync_transform(body, vec4_create(0, 0, 5), quat_create(0, 0, 0, 1));
  75. }
  76. let sphere: object_t = scene_get_child("Sphere");
  77. let t: transform_t = sphere.transform;
  78. asim_body_get_pos(body, ADDRESS(t.loc));
  79. transform_build_matrix(t);
  80. }
  81. ////
  82. type config_t = {
  83. server: string;
  84. };
  85. let config_raw: config_t;
  86. function strings_check_internet_connection(): string {
  87. return "";
  88. }
  89. function console_error(s: string) {}
  90. function console_info(s: string) {}
  91. function plugin_embed() {}
  92. function tr(id: string, vars: map_t<string, string> = null): string {
  93. return id;
  94. }
  95. let pipes_offset: i32;
  96. function pipes_get_constant_location(s: string): i32 {
  97. return 0;
  98. }