I’ve been downloading a bunch of items from other 3D model sites to use in my SH3D project. They either originated as obj. files or I converted them in Blender, but I can’t get the obj. files to recognize or connect with the textures in the mtl. Files.
I’ve uploaded one of the model files here for examination.
I’m new to 3D modelling, but I understand the obj. file is just describing the form of the object while the mtl. Holds all the other data for it. I noticed that there are spaces in the name in the object file, “mtllib Star Trek Tricorder MK VII.mtl”, but I think there’s got to be more to the problem than this? Can anyone shed some light here, please? Thanks!
Netherlands
Joined: Apr 8, 2022
Post Count: 1176
Status:
Offline
Re: Can’t get my obj. files to connect with textures in the mtl. Files.
The materials in the mtl file have no mappings to the texture images. Fortunately you have a model with clear material names that you can connect to the correct texure image.
Edit the mtl file and for each block that matches an image name add the line "map_Kd imagename.png" to the end of the block. For example:
newmtl Screen Ns 250.000000 Ka 1.000000 1.000000 1.000000 Kd 0.800000 0.800000 0.800000 Ks 0.500000 0.500000 0.500000 Ke 0.000000 0.000000 0.000000 Ni 1.000000 d 1.000000 illum 2
becomes:
newmtl Screen Ns 250.000000 Ka 1.000000 1.000000 1.000000 Kd 0.800000 0.800000 0.800000 Ks 0.500000 0.500000 0.500000 Ke 0.000000 0.000000 0.000000 Ni 1.000000 d 1.000000 illum 2 map_Kd Screen.png
There are 44 materials listed in the obj file but you only have 16 texture images. So start with adding the map_Kd lines for those 16 images and import the object in Sweet Home 3D. The other materials are just colors so you will have to select and set a color for those yourself in the modify object dialog. With the 16 textures mapped it should start to look like the model you want. It is mentioned on the sketchfab site that some details are missing, probably the missing correct color settings.
I noticed that some textures are just images of a color square. You might consider changing the material in Sweet Home 3D from that texture to a similar color. It will reduce the size of your object and it wil render much faster.
On the dodecagon.nl site there is a manual about changing material names and one that explains the MTL file. You might want to read those to understand what you are doing with materials.
---------------------------------------- Dodecagon.nl 800+ 3D models, manuals, and projects
Joined: Nov 3, 2024
Post Count: 41
Status:
Offline
Re: Can’t get my obj. files to connect with textures in the mtl. Files.
Hey, I just finished with that object and it worked great! There was only a single instance where something didn't take and I'm pretty sure it's because it was a lighting affect that SW3D really wasn't designed to do. I'm pretty excited about this and am going to go practice on a bunch of other objects I couldn't get to work. Thanks!
Joined: Nov 3, 2024
Post Count: 41
Status:
Offline
Re: Can’t get my obj. files to connect with textures in the mtl. Files.
I have a new object I'm working on but this one looks different. I assembled the textures in Blender and exported the obj. & mtl. files along with the original files in this folder, but it looks like it only has one material name and I'm not sure why as I'd assigned all the textures. Can this still be modified to work?
newmtl Material.001 Ka 1.000000 1.000000 1.000000 Kd 0.800000 0.800000 0.800000 Ks 0.500000 0.500000 0.500000 Ke 0.000000 0.000000 0.000000 Ni 1.450000 d 1.000000 illum 2 map_Kd DefaultMaterial_Base_Color.png
The object is very small when you import it. It seems like width and depth are 0 and the height is 0.1. Modify it and check "Keep proportions". Set the height to 10 or 15 and the width and depth will adapt proportionally. ETA: It's good practise to place the texture files in the same directory as the obj and mtl files. That way you don't need a path in the mtl file. A path can make the file unreadable on a different system. On top of that the current set path (a user directory) doesn't exist on someone elses computer. And about the map_* lines: "map_Kd" is the only texture mapping recognized by Sweet Home 3D. You can view the texture files and choose the one that offers the most "normal" texture. In this case that was the image DefaultMaterial_Base_Color.png.
---------------------------------------- Dodecagon.nl 800+ 3D models, manuals, and projects
----------------------------------------
[Edit 1 times,
last edit by Keet at Dec 12, 2024, 6:37:49 PM]
Joined: Nov 3, 2024
Post Count: 41
Status:
Offline
Re: Can’t get my obj. files to connect with textures in the mtl. Files.
It's a tiny object but enlarging it did work fine. The object imports as just white. I checked the obj. file but can't find a line for the name of the object, which I usually make sure is the same in the mtl. file to make the connection. I just see the lines...
mtllib Hypospray.mtl o hypo_lo at the top.
I thought the name always came after usemtl at the top?
Netherlands
Joined: Apr 8, 2022
Post Count: 1176
Status:
Offline
Re: Can’t get my obj. files to connect with textures in the mtl. Files.
It's a tiny object but enlarging it did work fine. The object imports as just white. I checked the obj. file but can't find a line for the name of the object, which I usually make sure is the same in the mtl. file to make the connection. I just see the lines...
mtllib Hypospray.mtl o hypo_lo at the top.
I thought the name always came after usemtl at the top?
This is not and export from Sweet Home 3D. But the line "mtllib Hypospray.mtl" is correct, it sets the reference to the mtl file. As in my previous post: the problem is in the mtl file, not the obj file.
Perform the changes I noted and import the object. If you export it again you will see that there is no "o ..." line but now a "g ..." line in the obj file. And directly below that the line with usemtl. An obj file is 'read' from top to bottom according to the specifications. "usemtl" indicates that from that point on the material as indicated must be used for the faces that follow (f lines). Until the next usemtl is encountered to switch to that material. The Sweet Home 3D export just sets the "usemtl" line directly afte the group line (g "). Because Sweet Home 3D always groups by material that makes a better 'human readable' format, much easier than for example a Blender export.
---------------------------------------- Dodecagon.nl 800+ 3D models, manuals, and projects
----------------------------------------
[Edit 1 times,
last edit by Keet at Dec 12, 2024, 6:47:48 PM]
Joined: Nov 3, 2024
Post Count: 41
Status:
Offline
Re: Can’t get my obj. files to connect with textures in the mtl. Files.
Got it. I must have done something wrong before but it's working now. I didn't realize those texture samples with different shapes on them would work out so well inside SH3D. That was a nice surprise, considering how much trouble I've had with book covers & spines. Now that I know it works that way, I'll apply it to a bunch of these other files I have.