-
-
Notifications
You must be signed in to change notification settings - Fork 35.6k
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
[PropertyBinding] Support for '.' in node names, and unit tests. #10859
Conversation
beba25c
to
d5c89b5
Compare
I of course support this approach as we discussed it. I like the addition of the unit tests. :) Thanks for the contribution. |
@takahirox looks good? |
Looks good, but give me a time a bit to think if the limitation won't be any problems. |
d5c89b5
to
7f6be9e
Compare
Sorry I can't make a time to check in some days. Have you confirmed all the animation examples keep working with this change? |
No rush. Yeah the animation examples all look good. |
One way to ensure that this doesn't break in the future is contribute some complex glTF example to the Three.JS project that has some tricky to parse names. |
src/animation/PropertyBinding.js
Outdated
// Object on target node, and accessor. May contain only word characters, | ||
// and must be a member of the supportedObjectNames whitelist. Accessor may | ||
// contain any non-bracket characters. | ||
var objectRe = /(?:\.([\w-]+)(?:\[(.+)\])?)?/; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is confusing a bit because it accepts a name not in whitelist.
And this regex accepts bracket (, ), [, and so on
for accessor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whitelist isn't part of the regex because it needs to be enforced afterwards; updated the comment about the accessor to specify that only closing brackets are disallowed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant, it'd be helpful to write here the result is compared with the whilelist afterwards and why.
When I first read this comment, I thought the whilelist should be in the regex because
it mentions must be a member of the supportedObjectNames whitelist
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated: the comment by the regex now describes only the regex, and the comment by the whitelist checking describes that.
src/animation/PropertyBinding.js
Outdated
var matches = re.exec( trackName ); | ||
// Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-' | ||
// characters, but must begin and end with a word character. | ||
var nodeRe = /(\w(?:[\w-\.]*\w)?)?/; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but must begin and end with a word character
Why is this limitation necessary?
nodeName
is compared to .name
which is general strings so could begin and end with non-word character like -something-
https://github.com/donmccurdy/three.js/blob/d6bf94269463418204213dd4f7efdc417311cc24/src/animation/PropertyBinding.js#L198
https://github.com/donmccurdy/three.js/blob/d6bf94269463418204213dd4f7efdc417311cc24/src/animation/PropertyBinding.js#L229
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I thought that trailing '.' would break regex parsing but it seems fine. Fixed.
6a7d66f
to
7965393
Compare
@takahirox thumbs up? |
Yep, great work @donmccurdy ! |
Nice work guys! |
Fixes #10366, #10527.
Modifies the nodeName portion of the existing regex to allow
.
characters, and breaks the regex into parts to improve readability.The key limitation here: only objectNames in the whitelist (material, materials, bones) are supported. The whitelist is a strict requirement if we keep using regex: Given
foo.bar.baz
, we knowbaz
must be a property, but there is no way to tell in advance whetherbar
is an objectName or part of the nodeName.This is one of several solutions discussed in #10366, so if we're not happy with the regular expression + whitelist we can try another approach.
/cc @bhouston @richtr @takahirox