diff --git a/Assets/plugins/import_gltf.js b/Assets/plugins/import_gltf.js new file mode 100644 index 00000000..d7afa4cf --- /dev/null +++ b/Assets/plugins/import_gltf.js @@ -0,0 +1,55 @@ + +Module = {} +Module["instantiateWasm"] = function(imports, successCallback) { + let wasmbin = Krom.loadBlob("data/plugins/import_gltf.wasm"); + let module = new WebAssembly.Module(wasmbin); + let inst = new WebAssembly.Instance(module, imports); + successCallback(inst); + return inst.exports; +}; + +// emscripten-generated glue +var a;a=a||("undefined"!=typeof Module?Module:{});var g,f={};for(g in a)a.hasOwnProperty(g)&&(f[g]=a[g]);var k,h="./this.program";k=function(n){return"function"==typeof readbuffer?new Uint8Array(readbuffer(n)):("object"==typeof(n=read(n,"binary"))||m("Assertion failed: undefined"),n)},"undefined"!=typeof print&&("undefined"==typeof console&&(console={}),console.log=print,console.warn=console.error="undefined"!=typeof printErr?printErr:print);var q,n=a.print||console.log.bind(console),p=a.printErr||console.warn.bind(console);for(g in f)f.hasOwnProperty(g)&&(a[g]=f[g]);f=null,a.thisProgram&&(h=a.thisProgram),a.wasmBinary&&(q=a.wasmBinary),"object"!=typeof WebAssembly&&p("no native wasm support detected");var r,x,y,z,A,u=new WebAssembly.Table({initial:3,maximum:3,element:"anyfunc"}),v=!1;function w(n){return 0; - var bufferViews: Array; - var buffers: Array; - var meshes: Array; -} - -typedef TAccessor = { - var bufferView: Int; - var componentType: Int; - var count: Int; - var max: Array; - var min: Array; - var type: String; -} - -typedef TBufferView = { - var buffer: Int; - var byteLength: Int; - var byteOffset: Int; - var target: Int; -} - -typedef TBuffer = { - var byteLength: Int; - var uri: String; -} - -typedef TMesh = { - var name: String; - var primitives: Array; -} - -typedef TPrimitive = { - var attributes: TAttributes; - var indices: Int; -} - -typedef TAttributes = { - var POSITION: Null; - var NORMAL: Null; - var TANGENT: Null; - var TEXCOORD_0: Null; -} diff --git a/Sources/arm/io/ImportGltf.hx b/Sources/arm/io/ImportGltf.hx deleted file mode 100644 index b8561088..00000000 --- a/Sources/arm/io/ImportGltf.hx +++ /dev/null @@ -1,16 +0,0 @@ -package arm.io; - -import kha.Blob; -import iron.data.Data; -import arm.format.GltfParser; - -class ImportGltf { - - public static function run(path: String) { - Data.getBlob(path, function(b: Blob) { - var obj = new GltfParser(b); - ImportMesh.makeMesh(obj, path); - Data.deleteBlob(path); - }); - } -} diff --git a/Sources/arm/io/ImportMesh.hx b/Sources/arm/io/ImportMesh.hx index 18ad19bc..14115b5d 100644 --- a/Sources/arm/io/ImportMesh.hx +++ b/Sources/arm/io/ImportMesh.hx @@ -40,7 +40,9 @@ class ImportMesh { else { var ext = path.substr(path.lastIndexOf(".") + 1); var importer = Path.meshImporters.get(ext); - importer(path, function() {}); + importer(path, function(mesh: Dynamic) { + ImportMesh.makeMesh(mesh, path); + }); } if (Context.mergedObject != null) { diff --git a/Sources/arm/sys/Path.hx b/Sources/arm/sys/Path.hx index 80e6e55c..cfcc7003 100644 --- a/Sources/arm/sys/Path.hx +++ b/Sources/arm/sys/Path.hx @@ -14,7 +14,7 @@ class Path { public static var meshFormats = ["obj", "fbx", "stl", "blend"]; public static var textureFormats = ["jpg", "jpeg", "png", "tga", "bmp", "psd", "gif", "hdr"]; - public static var meshImporters = new Map(Void->Void)->Void>(); + public static var meshImporters = new Map(Dynamic->Void)->Void>(); public static var textureImporters = new Map(kha.Image->Void)->Void>(); public static function data(): String {