Hello - I have come across this OBJ export script from sourceforge:
http://sourceforge.net/projects/blenderobjex/
It does not work with Blender 2.26 for Windows. Can somebody get this to work with Blender 2.26 on Windows? I dont understand Python or scripting. What im after is to be able to export mesh, texture, and material data, and this script is supposed to do that. - Thank you.
Here is the contents of the script:
################################################################################
# $Id: blenderobjex.py,v 1.3 2002/02/02 11:41:55 rid Exp $
#
# blenderobjex - Blender Alias/Wavefront OBJ-File exporter
#
# Copyright (C) 2001-2002 Christoph Frick <rid@zefix.tv>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
################################################################################
import Blender210 as Blender
import GUI
import sys, os
def export( filename ):
scene = Blender.getCurrentScene();
objfile = open( filename+".obj", "w" );
mtlfile = open( filename+".mtl", "w" );
bfilename = os.path.basename(filename)
mapfile = open( filename+".map", "w" );
objfile.write( "# \n" );
objfile.write( "mtllib "+bfilename+".mtl\n");
objfile.write( "maplib "+bfilename+".map\n");
mtllib = {};
vs = {};
vns = {};
vts = {};
mats = {};
maps = {};
s_count = 1;
t_count = 1;
n_count = 1;
for name in scene.objects:
if Blender.isMesh( name ):
meshobj = Blender.getObject( name );
mesh = Blender.getMesh( meshobj.data );
for vertex in mesh.vertices:
v = "v %f %f %f" % (vertex[0],vertex[1],vertex[2]);
if not vs.has_key(v):
vs[v] = s_count;
s_count = s_count + 1;
objfile.write( v + "\n" );
for normal in mesh.normals:
vn = "vn %f %f %f" % (normal[0],normal[1],normal[2]);
if not vns.has_key(vn):
vns[vn] = n_count;
n_count = n_count +1;
objfile.write( vn + "\n" );
for texcoord in mesh.texcoords:
for tc in texcoord:
vt = "vt %f %f" % (tc[0],tc[1]);
if not vts.has_key(vt):
vts[vt] = t_count;
t_count = t_count +1;
objfile.write( vt + "\n" );
for material_name in meshobj.materials:
if not mats.has_key( material_name ):
material = Blender.getMaterial( material_name );
mtlfile.write( "newmtl %s\n" % (material_name) );
mtlfile.write( "Ka %f %f %f\n" % (material.Amb,material.Amb,material.Amb) );
mtlfile.write( "Kd %f %f %f\n" % (material.R,material.G,material.B) );
mtlfile.write( "Ks %f %f %f\n" % (material.SpecR,material.SpecG,material.SpecB) );
mtlfile.write( "Ns %f\n" % (material.Spec) );
mtlfile.write( "\n" );
mats[ material_name ] = 1;
if mesh.texture:
bmapname = os.path.basename(mesh.texture);
maps[ mesh.texture ] = bmapname;
mapfile.write( "newmap %s\nKa %s\n\n" % (bmapname,bmapname) );
lastmat = "";
for name in scene.objects:
if Blender.isMesh( name ):
meshobj = Blender.getObject( name );
mesh = Blender.getMesh( meshobj.data );
lastsmooth = -1;
facecount = 0;
if ( mesh.texture ):
objfile.write("usemap %s\n" % (maps[mesh.texture]) );
for face in mesh.faces:
if face[4] != lastsmooth:
objfile.write( "s %i\n" % face[4] );
lastsmooth = face[4];
if len(meshobj.materials) > 0 and lastmat != meshobj.materials[face[5]]:
lastmat = meshobj.materials[face[5]]
objfile.write( "usemtl %s\n"%(lastmat) );
objfile.write( "f " );
for i in range(4):
if i!=3 or face[3]:
x = "";
v = "v %f %f %f" % (mesh.vertices[face[i]][0],mesh.vertices[face[i]][1], mesh.vertices[face[i]][2]);
x = x + "%i/" % (vs[v]);
if len(mesh.texcoords):
tc = mesh.texcoords[facecount][i];
vt = "vt %f %f" % (tc[0],tc[1]);
x = x + "%d"%(vts[vt]);
x = x + "/";
vn = "vn %f %f %f" % (mesh.normals[face[i]][0],mesh.normals[face[i]][1], mesh.normals[face[i]][2]);
x = x + "%i"%(vns[vn]);
x = x + " ";
objfile.write( x );
objfile.write( "\n" );
facecount = facecount+1;
def callback(fs):
export(fs.filename)
fs = GUI.FileSelector()
fs.activate(callback, fs)