MTL Import

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 02 February 2013   #1
MTL Import

The thing that always bugged me is that, while CINEMA 4D's OBJ importer does a good job reading the geometry data from an .obj file, it ignores the .mtl file, so we have to set all the textures and material properties manually. Takes too much time.

So here's a quick MTL parser, written in Python. Not 100% complete and maybe not the most elegant code. I implemented it using information I found on the Wikipedia article about the Wavefront OBJ format, which seems to be either incomplete or not entirely correct. But it works OK and already saves quite some time The materials have to be finetuned after import, but it's already better than nothing.

It reads and assigns the following from an .mtl file and transfers the values to materials:
  • Ambient color
  • Specular color
  • Specular coefficient
  • Transparency
  • Diffuse map
  • Ambient map
  • Bump map
  • Alpha map (since 1.1)

Shouldn't be too hard for interested people to extend the functionality.

Download from my site:
http://www.c4d-jack.de/site/en/down...import-mtl.html

Crytek Sponza, before:


Crytek Sponza, after:

Last edited by c4d-jack : 02 February 2013 at 08:55 AM.
 
Old 02 February 2013   #2
Great time saver. Nice wok done!
 
Old 02 February 2013   #3
Just updated it to version 1.1.
It now supports alpha maps (masks), too.


Last edited by c4d-jack : 02 February 2013 at 01:44 PM.
 
Old 02 February 2013   #4
Danke !!!
A very great time saver !
__________________
_________________
serge-mustu.de
 
Old 02 February 2013   #5
Great work!!!

This is something I have wanted for a long time.

Thank you,
Frank
 
Old 02 February 2013   #6
Thank you very much!
highly appreciated.
s
 
Old 02 February 2013   #7
Fantastic! C4D has needed this forever! Thanks!
__________________
----end of line
 
Old 02 February 2013   #8
I have tried it on an OBJ file created in Modo. After running the script everything is transparent which isn't a problem as it's easy to turn off. However the materials aren't there and says they are missing even though they are residing in the same folder. There's a weird path which doesn't correspond to any paths and it doesn't show which texture goes where. I guess it comes down to how the .mtl file was created in the first place. Any thoughts on how I can get over this

all the best

Richard
 
Old 02 February 2013   #9
Hey Frank, awesome. Vielen Dank!
__________________
____
Cinema 4D Studio MSA, Zbrush, CS6, 3DCoat, Moi
Twitter: @holgerbiebrach
www.c4dStuff.com

HB_ModellingBundle
 
Old 02 February 2013   #10
Originally Posted by rsquires: I have tried it on an OBJ file created in Modo. After running the script everything is transparent which isn't a problem as it's easy to turn off.

I also noticed, that materials from many MTL come out transparent even though it makes no sense. The problem is: That is correct. The MTL file contains a transparency value of 1.0, which (according to the Wikipedia article) means 100% transparent.
I can imagine that some applications mean to interpret that as 100% opaque, but since there is no way to recognize that from the MTL file, I can't help it.

Originally Posted by rsquires: However the materials aren't there and says they are missing even though they are residing in the same folder. There's a weird path which doesn't correspond to any paths and it doesn't show which texture goes where.

You mean the textures, right? Well, the path is taken directly from the MTL file, and should be relative to the MTL file. Open the file with a text editor and take a look (the relevant lines start with "map_").
If a program exports MTL files with wrong paths, then I can't help it.

Originally Posted by rsquires: I guess it comes down to how the .mtl file was created in the first place. Any thoughts on how I can get over this

MTL is just a very old, rather crappy and definitely outdated format. The script should simply help with getting the basic colors and textures assigned. Don't expect any high-end ready-to-render materials to come out of it.

+ + +

Oh, yeah, and in the meantime it was updated to version 1.1.1, so make sure you are using the latest version (some bugfixes).
 
Old 02 February 2013   #11
Originally Posted by c4d-jack: I also noticed, that materials from many MTL come out transparent even though it makes no sense. The problem is: That is correct. The MTL file contains a transparency value of 1.0, which (according to the Wikipedia article) means 100% transparent.
I can imagine that some applications mean to interpret that as 100% opaque, but since there is no way to recognize that from the MTL file, I can't help it.


You mean the textures, right? Well, the path is taken directly from the MTL file, and should be relative to the MTL file. Open the file with a text editor and take a look (the relevant lines start with "map_").
If a program exports MTL files with wrong paths, then I can't help it.


MTL is just a very old, rather crappy and definitely outdated format. The script should simply help with getting the basic colors and textures assigned. Don't expect any high-end ready-to-render materials to come out of it.

+ + +

Oh, yeah, and in the meantime it was updated to version 1.1.1, so make sure you are using the latest version (some bugfixes).


Cheers mate. Thanks for letting it out in the wild
 
Old 02 February 2013   #12
Thanks a lot! works great.

odo
 
Old 03 March 2013   #13
I just uploaded a mini update from 1.1.1 to 1.1.2:
Problems with UTF8 encoded filenames have been fixed.

Download, as usual, from my website.

Last edited by c4d-jack : 03 March 2013 at 09:48 AM.
 
Old 06 June 2013   #14
Thanks a lot for providing this. Always wanted an importer for C4D that works for my Poser stuff and can be extended one day for Vray for C4D. I have to start programing again...
 
Old 06 June 2013   #15
You're welcome, I'm glad you can use it.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 09:05 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.