From d9420ea7e2739e3a0f0857503da7e29efe52ae0b Mon Sep 17 00:00:00 2001 From: Sebastian Dunkel Date: Wed, 14 Jul 2021 15:24:17 +0200 Subject: [PATCH] fixed unit registry creation in js bindings (#1272) --- source/JsMaterialX/JsMaterialXCore/JsUnit.cpp | 9 ++++++++- source/JsMaterialX/JsMaterialXGenShader/JsGenContext.cpp | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/source/JsMaterialX/JsMaterialXCore/JsUnit.cpp b/source/JsMaterialX/JsMaterialXCore/JsUnit.cpp index 26d6de3d55..b57f53fe84 100644 --- a/source/JsMaterialX/JsMaterialXCore/JsUnit.cpp +++ b/source/JsMaterialX/JsMaterialXCore/JsUnit.cpp @@ -13,6 +13,9 @@ namespace ems = emscripten; namespace mx = MaterialX; +// The following 3 functions should not be necessary, but due to unexpected behaviour of emscripten, +// it reports signature mismatches if the functions are bound directly + mx::LinearUnitConverterPtr LinearUnitConverterCreate(mx::UnitTypeDefPtr unitTypeDef) { return mx::LinearUnitConverter::create(unitTypeDef); } @@ -21,6 +24,10 @@ mx::UnitConverterPtr UnitConverterRegistryGetUnitConverter(mx::UnitConverterRegi return registry.getUnitConverter(def); } +mx::UnitConverterRegistryPtr UnitConverterRegistrycreate() { + return mx::UnitConverterRegistry::create(); +} + EMSCRIPTEN_BINDINGS(unit) { @@ -53,7 +60,7 @@ EMSCRIPTEN_BINDINGS(unit) ems::class_("UnitConverterRegistry") .smart_ptr>("UnitConverterRegistry") .smart_ptr>("UnitConverterRegistry") - .class_function("create", &mx::UnitConverterRegistry::create) + .class_function("create", &UnitConverterRegistrycreate) .function("addUnitConverter", &mx::UnitConverterRegistry::addUnitConverter) .function("removeUnitConverter", &mx::UnitConverterRegistry::removeUnitConverter) .function("getUnitConverter", &UnitConverterRegistryGetUnitConverter) diff --git a/source/JsMaterialX/JsMaterialXGenShader/JsGenContext.cpp b/source/JsMaterialX/JsMaterialXGenShader/JsGenContext.cpp index 5900da3241..e1201e56c9 100644 --- a/source/JsMaterialX/JsMaterialXGenShader/JsGenContext.cpp +++ b/source/JsMaterialX/JsMaterialXGenShader/JsGenContext.cpp @@ -5,6 +5,7 @@ #include "../Helpers.h" +#include #include #include #include @@ -50,7 +51,7 @@ mx::DocumentPtr loadStandardLibraries(mx::GenContext& context) mx::DocumentPtr stdLib; mx::LinearUnitConverterPtr _distanceUnitConverter; mx::StringVec _distanceUnitOptions; - mx::UnitConverterRegistryPtr unitRegistry; + mx::UnitConverterRegistryPtr unitRegistry(mx::UnitConverterRegistry::create()); mx::FilePathVec libraryFolders = { "libraries" }; mx::FileSearchPath searchPath; searchPath.append("/");