Skip to content

Commit

Permalink
fixed unit registry creation in js bindings (#1272)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdunkel authored Jul 14, 2021
1 parent 18fefa8 commit d9420ea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 8 additions & 1 deletion source/JsMaterialX/JsMaterialXCore/JsUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -21,6 +24,10 @@ mx::UnitConverterPtr UnitConverterRegistryGetUnitConverter(mx::UnitConverterRegi
return registry.getUnitConverter(def);
}

mx::UnitConverterRegistryPtr UnitConverterRegistrycreate() {
return mx::UnitConverterRegistry::create();
}

EMSCRIPTEN_BINDINGS(unit)
{

Expand Down Expand Up @@ -53,7 +60,7 @@ EMSCRIPTEN_BINDINGS(unit)
ems::class_<mx::UnitConverterRegistry>("UnitConverterRegistry")
.smart_ptr<std::shared_ptr<mx::UnitConverterRegistry>>("UnitConverterRegistry")
.smart_ptr<std::shared_ptr<const mx::UnitConverterRegistry>>("UnitConverterRegistry")
.class_function("create", &mx::UnitConverterRegistry::create)
.class_function("create", &UnitConverterRegistrycreate)
.function("addUnitConverter", &mx::UnitConverterRegistry::addUnitConverter)
.function("removeUnitConverter", &mx::UnitConverterRegistry::removeUnitConverter)
.function("getUnitConverter", &UnitConverterRegistryGetUnitConverter)
Expand Down
3 changes: 2 additions & 1 deletion source/JsMaterialX/JsMaterialXGenShader/JsGenContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "../Helpers.h"

#include <MaterialXCore/Unit.h>
#include <MaterialXGenShader/GenContext.h>
#include <MaterialXGenShader/ShaderGenerator.h>
#include <MaterialXGenShader/DefaultColorManagementSystem.h>
Expand Down Expand Up @@ -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("/");
Expand Down

0 comments on commit d9420ea

Please sign in to comment.