diff --git a/wasm/Makefile b/wasm/Makefile new file mode 100644 index 00000000..b0d4a71b --- /dev/null +++ b/wasm/Makefile @@ -0,0 +1,5 @@ +# for release +EMCC_FLAGS=-Os + +all: + emcc --bind -s ASSERTIONS=1 -o tinyobjloader.js -O0 -I../ tinyobjloader.cc diff --git a/wasm/README.md b/wasm/README.md new file mode 100644 index 00000000..c165d670 --- /dev/null +++ b/wasm/README.md @@ -0,0 +1,7 @@ +# Status + +Experimental + +## Immplementation + +Use Embind https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html to write C++ binding. diff --git a/wasm/index.html b/wasm/index.html new file mode 100644 index 00000000..f79ecffc --- /dev/null +++ b/wasm/index.html @@ -0,0 +1,59 @@ + + + + + + + diff --git a/wasm/tinyobjloader.cc b/wasm/tinyobjloader.cc new file mode 100644 index 00000000..ff3213c8 --- /dev/null +++ b/wasm/tinyobjloader.cc @@ -0,0 +1,40 @@ +#ifdef __EMSCRIPTEN__ +#include +#else +#error "Need to compile with emcc" +#endif + +#define TINYOBJLOADER_USE_DOUBLE +#define TINYOBJLOADER_USE_MAPBOX_EARCUT +#define TINYOBJLOADER_IMPLEMENTATION +#include "tiny_obj_loader.h" + + +#ifdef __EMSCRIPTEN__ +EMSCRIPTEN_BINDINGS(tinyobj) +{ + emscripten::class_("ObjReaderConfig") + .constructor<>() + .property("triangulation_method", &tinyobj::ObjReaderConfig::triangulation_method) + .property("vertex_color", &tinyobj::ObjReaderConfig::vertex_color) + .property("mtl_search_path", &tinyobj::ObjReaderConfig::mtl_search_path) + ; + + emscripten::class_("attrib_t") + .constructor<>() + .function("GetVertices", &tinyobj::attrib_t::GetVertices) + ; + + emscripten::class_("ObjReader") + .constructor<>() + //.function("ParseFromFile", &tinyobj::ObjReader::ParseFromFile) // TODO + .function("ParseFromString", &tinyobj::ObjReader::ParseFromString) + .function("Valid", &tinyobj::ObjReader::Valid) + .function("GetAttrib", &tinyobj::ObjReader::GetAttrib) + .function("GetShapes", &tinyobj::ObjReader::GetShapes) + ; + + emscripten::register_vector("vector"); + emscripten::register_vector("vector"); +} +#endif