Netherlands
Joined: Apr 8, 2022
Post Count: 1366
Status:
Offline
A different way to change a material name
It is easy to change material names by editing the OBJ and MTL files. I described this in the manual "Change Materiasl Names" available on the dodecagon site. But there is a different way if you have a model(-part) with a single material. I always create furniture by first creating all the different parts as single objects so this "new" way is very usefull. It also has the advantage that it highly optimizes the object by merging the groups in the OBJ file into a single group. Since Sweet Home 3D internally processes OBJ files group-by-group this should increase efficiency a little bit. I will explain this using a regular box.
When you export a box the object file looks like this:
# # Generated by Sweet Home 3D - Fri Apr 04 10:09:46 CEST 2025 # http://www.sweethome3d.com/ # mtllib box.mtl g bottom_1 usemtl bottom v -45.7 0.0 -45.7 v 45.7 0.0 -45.7 v 45.7 0.0 45.7 v -45.7 0.0 45.7 vt 0.0 0.0 0 vt 1.0 0.0 0 vt 1.0 1.0 0 vt 0.0 1.0 0 vn 0.0 -1.0 0.0 f 1/1/1 2/2/1 3/3/1 f 1/1/1 3/3/1 4/4/1 g top_2 usemtl top v -45.7 91.4 -45.7 v -45.7 91.4 45.7 v 45.7 91.4 45.7 v 45.7 91.4 -45.7 vn 0.0 1.0 0.0 f 5/4/2 6/1/2 7/2/2 f 5/4/2 7/2/2 8/3/2 g left_3 usemtl left vn -1.0 0.0 0.0 f 1/1/3 4/2/3 6/3/3 f 1/1/3 6/3/3 5/4/3 g right_4 usemtl right vn 1.0 0.0 0.0 f 2/2/4 8/3/4 7/4/4 f 2/2/4 7/4/4 3/1/4 g back_5 usemtl back vn 0.0 0.0 -1.0 f 1/2/5 5/3/5 8/4/5 f 1/2/5 8/4/5 2/1/5 g front_6 usemtl front vn 0.0 0.0 1.0 f 3/2/6 7/3/6 6/4/6 f 3/2/6 6/4/6 4/1/6
It shows 6 groups each with a different material name. We already know that you can change the lines starting with "usemtl" and assign a different name for the group. If we want to have all groups use the same material we change all "usemtl" lines with that same material name. Then we edit the MTL file and change the first block to use that single material name by replacing the line "newmtl <materialname>" to the name we want the material to have and we remove all other blocks.
If you are sure you don't want to split the material names again you don't need 6 different groups, one group is sufficent. This is often the case if you create a part to use in a bigger model. To merge the 6 groups into a single group is rediculously easy. The MTL file is changed as before: set a material name on the first block and remove all other bloacks. The OBJ is a little different. You change the first "g " line with a line that gives the group a sensible name: "g partname". Then you change the line directly under it from "usemtl ..." to "usemtl MaterialName". That is also the first line starting with "usemtl ". And now you remove all other lines starting with "g " and "usemtl ". Save the OBJ and MTL files and import your object. If you export that box again it looks like this:
# # Generated by Sweet Home 3D - Fri Apr 04 10:26:46 CEST 2025 # http://www.sweethome3d.com/ # mtllib box.mtl g mybox_1_1 usemtl Box v -45.7 0.0 -45.7 v 45.7 0.0 -45.7 v 45.7 0.0 45.7 v -45.7 0.0 45.7 v -45.7 91.4 -45.7 v -45.7 91.4 45.7 v 45.7 91.4 45.7 v 45.7 91.4 -45.7 vt 0.0 0.0 0 vt 1.0 0.0 0 vt 1.0 1.0 0 vt 0.0 1.0 0 vn 0.0 -1.0 0.0 vn 0.0 1.0 0.0 vn -1.0 0.0 0.0 vn 1.0 0.0 0.0 vn 0.0 0.0 -1.0 vn 0.0 0.0 1.0 f 1/1/1 2/2/1 3/3/1 f 1/1/1 3/3/1 4/4/1 f 5/4/2 6/1/2 7/2/2 f 5/4/2 7/2/2 8/3/2 f 1/1/3 4/2/3 6/3/3 f 1/1/3 6/3/3 5/4/3 f 2/2/4 8/3/4 7/4/4 f 2/2/4 7/4/4 3/1/4 f 1/2/5 5/3/5 8/4/5 f 1/2/5 8/4/5 2/1/5 f 3/2/6 7/3/6 6/4/6 f 3/2/6 6/4/6 4/1/6
This is a single group with the material name "Box" and the number of lines is obviously less then the original export had. Imagine that you have a lot of parts to create a complex model and you do this with every part. You will get a highly optimized model that should process faster in Sweet Home 3D. This method works because groups ("g " lines) have no other purpose than to organize vertices in recognizable groups. Software like Sweet Home 3D and Blender don't really need the groups to represent the model. You could remove the first "g " line too and the object will still import in Sweet Home 3D. You only assign a name because it is usefull to recognize a part when you combine multiple created parts into a complex model. And of course you need the group if you want to add a deformation. The "Change Material Names" manual is updated and this method is added as an alternative option.
---------------------------------------- Dodecagon.nl 1000+ 3D models, manuals, and projects