OBJ + MTL export File

OBJ + MTL export File

Who can help.
When i use OBJ + MTL export script i need a # before the last line in the mtl-file. Otherwise i can't import it to mObject.

So last line should look like this:
# WaveFront *.obj file (generated by Cheetah3D)

mtllib test.mtl

g Ebene
v -0.500000 0.480631 -0.137819
v -0.500000 -0.480631 0.137819

.....

usemtl Material
f 2/4/1 4/3/1 3/2/1 1/1/1

#usemtl default

Can anyone post a modified Version of the script:


function main(doc){
var path=OS.runSavePanel("obj");
if(path==null){
return;
}

var file=new File(path);
var lastpathcomp=file.lastPathComponent();
var dir=file.directory();
var comps= lastpathcomp.split(/\./);
var objpath=dir+"/"+comps[0]+".obj";
var mtlpath=dir+"/"+comps[0]+".mtl";

doc.saveToFile(objpath,"obj");
doc.saveToFile(mtlpath,"mtl");
}


THX
 
hi,

I think you want to change line 'usemtl default' to '#usemtl default' for .obj file that Cheetah3D exported.

if so, code will be ..

Code:
function main(doc){
    var path=OS.runSavePanel("obj");
    if(path==null){
    return;
    }

    var file=new File(path);
    var lastpathcomp=file.lastPathComponent();
    var dir=file.directory();
    var comps= lastpathcomp.split(/\./);
    var objpath=dir+"/"+comps[0]+".obj";
    var mtlpath=dir+"/"+comps[0]+".mtl";

    doc.saveToFile(objpath,"obj");
    doc.saveToFile(mtlpath,"mtl");

    // comment out 'usemtl default'
    var objfile = new File(objpath);
    var objfile_mod = new File(objpath.replace(/\.obj$/, ".obj_bk"));
    objfile.open(READ_MODE);
    objfile_mod.open(WRITE_MODE);
    var line = objfile.readln();
    while( line != -1) {
        if (line.match("usemtl default")) {
            line = line.replace("usemtl default", "#usemtl default");
        }
        objfile_mod.writeln(line);
        line = objfile.readln();
    }
    objfile.close();
    objfile_mod.close();
    OS.system("rm \""+objpath+"\"");
    OS.system("mv \""+objpath.replace(/\.obj$/, ".obj_bk")+"\" \""+objpath+"\"");
}

please replace OBJ+MTL export.js code to this, and test it.

Best

tg_jp, Hiroto
 
:smile: :smile: :smile: :smile: :smile: :smile:

:icon_thumbup: :icon_thumbup: :icon_thumbup: :icon_thumbup: :icon_thumbup:


YOU ArE THE BEST


WORKS


GREAT AND MANY THANKS
 
Back
Top