-
-
Notifications
You must be signed in to change notification settings - Fork 36k
MTLLoader improvements #8689
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
MTLLoader improvements #8689
Conversation
Make sure MaterialCreator.baseUrl is not undefined if no path/texture path is set.
…RL if not explicitly set with setPath or setTexturePath. The URL parameter to .parse(text, url) is passed in if you use .load(). For external use it is optional and preserves earlier behavior if not passed in.
…y setting easier to read.
… with bump map. This might change behavior for bad materials that define 'map_kd' multiple times.
That last logic is dangerous though... What if the real path was |
Hmm, not sure what you mean with that example. You'll be calling .load() with a .mtl reference, not a .png. I guess that was a typo? In cases where user call either or both The only case where this auto resolve does change behavior is this file structure;
If you called Could you describe a directory/file setup where you suspect the code might do the wrong thing when it was working with the previous code? I cant think of one. Edit: Did you mean this? loader.setPath("images/");
loader.load("images/test.mtl");
// would fetch "images/images/test.mtl" and textures from "undefined{textureRef]"
// youd have to set
loader.setBaseUrl("/images/");
// for "images/images/test.mtl" and textures from "images/{textureRef]" |
I'll study the code thoroughly tomorrow 😇 |
ok, let me know if you find a failure case. We can also remove the auto resolve, it just seems a lot easier for the end user. With the auto resolve the only case where you would need to call |
Btw. should also fix not to prefix base path to the found texture ref if its a absolute URL. This would mangle and break it. Simple |
Hmm, I just have the feeling that the auto resolve will create problems at some point and we'll spend a lot of time trying to make sure it works in all the possible cases. We've been in similar situations before and the solution was always to let the user control that. Everything else looks great though! |
Alright. I'll remove it and document that |
Add documentation to load and other important functions. Remove now redundant call to .setBaseUrl in obj/mtl loader example. setPath is enough if the .mtl and textures have the same base path (documented).
@mrdoob there we go. Auto resolve removed. Added bunch of documentation. Fixed breaking parsed absolute URLs. And fixed deprecation warnings in the obj + mtl loader example. |
examples/js/loaders/MTLLoader.js
Outdated
|
||
}, | ||
|
||
_resolveURL: function ( url ) { |
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.
Almost there!
We have also been trying to move away from these kind of public methods whenever possible (people would start using them and get mad when they get removed).
Considering that this method is mainly used inside THREE.MTLLoader.MaterialCreator
we could just define it locally.
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.
Yeh, updated.
examples/js/loaders/MTLLoader.js
Outdated
return ''; | ||
|
||
// Absolute URL | ||
if ( url.toLowerCase().indexOf('http://') === 0 || url.toLowerCase().indexOf('https://') === 0 ) { |
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.
How about... if ( /^https?:\/\//i.test( url ) )
?
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.
Hmm, I'm somehow hesitant to create regexps on the spot my self, but the function is not called that often ;) If you'd prefer it i can change it, gimme a sec.
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.
Done, it is a lot cleaner to read, toLowerCase is not free either so meh :)
Sweet! |
Thanks! |
setBaseUrl
in favor ofsetTexturePath
.path
is set but.texturePath
is not, select.path
to be passed into MaterialCreator.If neither is set, try to auto detect base path from .mtl source URL. the(reverted).load()
function now passes the source URL into.parse()
.setBaseUrl
but the value is still set.I think auto detecting the texture base path is pretty neat. You can go from this
to