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

[PropertyBinding] Support for '.' in node names, and unit tests. #10859

Merged
merged 4 commits into from
Feb 26, 2017

Conversation

donmccurdy
Copy link
Collaborator

@donmccurdy donmccurdy commented Feb 22, 2017

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 know baz must be a property, but there is no way to tell in advance whether bar 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

@bhouston
Copy link
Contributor

I of course support this approach as we discussed it. I like the addition of the unit tests. :) Thanks for the contribution.

@mrdoob
Copy link
Owner

mrdoob commented Feb 22, 2017

@takahirox looks good?

@takahirox
Copy link
Collaborator

Looks good, but give me a time a bit to think if the limitation won't be any problems.

@takahirox
Copy link
Collaborator

Sorry I can't make a time to check in some days.

@donmccurdy

Have you confirmed all the animation examples keep working with this change?
If so, I think we can go ahead.

@donmccurdy
Copy link
Collaborator Author

No rush. Yeah the animation examples all look good.

@bhouston
Copy link
Contributor

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.

@donmccurdy
Copy link
Collaborator Author

Added the example in #10527, with dots in bone names, from the gltf-test repo. Open to more complex alternatives.

// 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-]+)(?:\[(.+)\])?)?/;
Copy link
Collaborator

@takahirox takahirox Feb 25, 2017

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.

https://github.com/mrdoob/three.js/pull/10859/files#diff-14b4c2603b1dc7cb6fcb5805222d9dcdR125

And this regex accepts bracket (, ), [, and so on for accessor.

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 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.

Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

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)?)?/;
Copy link
Collaborator

@takahirox takahirox Feb 25, 2017

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

Copy link
Collaborator Author

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.

@donmccurdy donmccurdy force-pushed the test-parsetrackname branch 2 times, most recently from 6a7d66f to 7965393 Compare February 26, 2017 00:06
@mrdoob
Copy link
Owner

mrdoob commented Feb 26, 2017

@takahirox thumbs up?

@takahirox
Copy link
Collaborator

Yep, great work @donmccurdy !

@mrdoob mrdoob merged commit 9ac27da into mrdoob:dev Feb 26, 2017
@mrdoob
Copy link
Owner

mrdoob commented Feb 26, 2017

Nice work guys!

@donmccurdy donmccurdy deleted the test-parsetrackname branch March 17, 2017 18:54
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.

4 participants