Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update JavaScript bindings to 1.38 #1181

Merged
merged 2 commits into from
May 6, 2021

Conversation

frericp
Copy link
Collaborator

@frericp frericp commented May 3, 2021

Update #1184

This PR updates the existing JS bindings to work with v1.38 of MaterialX:

  • Remove deprecated functions
  • Update JS boilerplate code and tests

In addition to that, the build process has been improved a bit:

  • Compile binding files in parallel
  • Express dependencies to Core and XmlIo packages properly, to enable parallel builds
  • Use additional flags to produce smaller builds
  • Fix a small issue in the root CMake file to find the Emscripten SDK automatically if the parameter is not provided.

@@ -113,6 +108,9 @@ extern "C"
ems::function("DEFAULT_TYPE_STRING", ems::optional_override([]() {
return mx::DEFAULT_TYPE_STRING;
}));
ems::function("EMPTY_STRING", ems::optional_override([]() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea why these constants are exposed as functions and not via
https://emscripten.org/docs/api_reference/bind.h.html?highlight=bind%20h#constants
?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. I've put it on the todo list.

api.isValidName = Module.isValidName;
api.incrementName = Module.incrementName;

api.getVersionIntegers = function() {
var vec = Module.getVersionIntegers();
return vecToArray(vec);
};

// TODO: Do we really need to map such helper functions? JS already has a String.split method.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should and add this as a point when we review/adjust the general implementation approach

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing to keep in mind is that the separator string indicates any character can be used as the separator, whereas I think the JS versoin is an exact match of the entire string.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JS version can take a string (in which case it looks for an exact match) or a regex. The latter can be used to achieve the same result, e.g. with str.split(/[characters_to_search_for]/).

Independent of this particular function, the idea is to provide an interface that feels as native as possible to JS developers, e.g. by using the JS Array interface instead of C++ vectors. We will probably need to evaluate and discuss a couple examples like this on the way.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, it is better to use native interfaces and as you say visit specific functions like these to see if they are useful to add. Some native utilities we're added to convert from MaterialX types to native types for the Python implementation if this is of interest.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bernardkwok The PR is currently not passing the checks due to some linting issues. Since we will most likely change/remove this code soon anyway, is there a way to ignore JS linting for now? If not, I can disable the failing check manually in the affected files.

I tried ignoring this in the codacy check but I will try to disable more. It's been a bit finicky in that I have tried to restart the check manually but it may only kick in on the next push to this PR.

source/JsMaterialX/test/codeExamples.spec.js Outdated Show resolved Hide resolved
Copy link

@bernardkwok bernardkwok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good so far. I don't recall if the original mappings included all the apis found in C++. A second pass could be required for completeness.

api.isValidName = Module.isValidName;
api.incrementName = Module.incrementName;

api.getVersionIntegers = function() {
var vec = Module.getVersionIntegers();
return vecToArray(vec);
};

// TODO: Do we really need to map such helper functions? JS already has a String.split method.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing to keep in mind is that the separator string indicates any character can be used as the separator, whereas I think the JS versoin is an exact match of the entire string.

@frericp
Copy link
Collaborator Author

frericp commented May 4, 2021

A second pass could be required for completeness.

Definitely, the bindings are currently not complete. As we discussed before, the way they are done might not be ideal, which is why we would like to look into how to improve that as a first step. Once this has been figured out, we can aim for full coverage.

@frericp
Copy link
Collaborator Author

frericp commented May 4, 2021

@bernardkwok The PR is currently not passing the checks due to some linting issues. Since we will most likely change/remove this code soon anyway, is there a way to ignore JS linting for now? If not, I can disable the failing check manually in the affected files.

@frericp frericp force-pushed the adsk_contrib/updateJsBindings branch from 69638de to dcf5860 Compare May 5, 2021 14:04
@frericp frericp merged commit 5b11321 into adsk_contrib/dev May 6, 2021
@frericp frericp deleted the adsk_contrib/updateJsBindings branch May 6, 2021 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants