import_usdc.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. let a = Krom_import_usdc;
  2. class R {
  3. get buffer() { return Krom_import_usdc._buffer(); }
  4. }
  5. let r = new R();
  6. // import_usdc.js
  7. let import_usdc = function(path) {
  8. let b = data_get_blob(path);
  9. let buf_off = a._init(b.byteLength); //// Allocate r.buffer
  10. let buf = new Uint8Array(r.buffer, buf_off, b.byteLength);
  11. let bbuf = new Uint8Array(b);
  12. for (let i = 0; i < b.byteLength; ++i) {
  13. buf[i] = bbuf[i];
  14. }
  15. a._parse();
  16. let vertex_count = a._get_vertex_count();
  17. let index_count = a._get_index_count();
  18. let inda = new Uint32Array(r.buffer, a._get_indices(), index_count);
  19. let posa = new Int16Array(r.buffer, a._get_positions(), vertex_count * 4);
  20. let nora = new Int16Array(r.buffer, a._get_normals(), vertex_count * 2);
  21. let texa = new Int16Array(r.buffer, a._get_uvs(), vertex_count * 2);
  22. let name = path.split("\\").pop().split("/").pop().split(".").shift();
  23. // a._destroy(); //// Destroys r.buffer
  24. data_delete_blob(path);
  25. return {
  26. name: name,
  27. posa: posa,
  28. nora: nora,
  29. texa: texa,
  30. inda: inda,
  31. scale_pos: a._get_scale_pos(),
  32. scale_tex: 1.0
  33. };
  34. }
  35. let plugin = plugin_create();
  36. let formats = path_mesh_formats;
  37. let importers = path_mesh_importers;
  38. formats.push("usdc");
  39. importers.set("usdc", import_usdc);
  40. plugin.delete = function() {
  41. formats.splice(formats.indexOf("usdc"), 1);
  42. importers.delete("usdc");
  43. };