2004-06-14 20:51:09 +00:00
|
|
|
#!BPY
|
2004-06-21 12:01:23 +00:00
|
|
|
|
2004-06-14 20:51:09 +00:00
|
|
|
"""
|
|
|
|
Name: 'Wavefront (.obj)...'
|
2005-06-12 05:54:15 +00:00
|
|
|
Blender: 237
|
2004-06-14 20:51:09 +00:00
|
|
|
Group: 'Import'
|
2005-10-11 02:32:58 +00:00
|
|
|
Tooltip: 'Load a Wavefront OBJ File, Shift: batch import all dir.'
|
2004-06-14 20:51:09 +00:00
|
|
|
"""
|
2004-06-07 01:34:15 +00:00
|
|
|
|
2006-03-29 18:25:42 +00:00
|
|
|
__author__= "Campbell Barton"
|
|
|
|
__url__= ["blender", "elysiun"]
|
|
|
|
__version__= "1.0"
|
2004-11-07 16:31:13 +00:00
|
|
|
|
2006-03-29 18:25:42 +00:00
|
|
|
__bpydoc__= """\
|
2004-11-07 16:31:13 +00:00
|
|
|
This script imports OBJ files to Blender.
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
|
|
|
|
Run this script from "File->Import" menu and then load the desired OBJ file.
|
|
|
|
"""
|
|
|
|
|
2004-06-10 03:27:46 +00:00
|
|
|
# $Id$
|
|
|
|
#
|
2004-06-14 20:51:09 +00:00
|
|
|
# --------------------------------------------------------------------------
|
2005-06-12 05:54:15 +00:00
|
|
|
# OBJ Import v1.0 by Campbell Barton (AKA Ideasman)
|
2004-06-14 20:51:09 +00:00
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
# ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# ***** END GPL LICENCE BLOCK *****
|
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
#==============================================#
|
2005-06-12 05:54:15 +00:00
|
|
|
# Return directory, where the file is #
|
2004-06-14 20:51:09 +00:00
|
|
|
#==============================================#
|
2005-06-12 05:54:15 +00:00
|
|
|
def stripFile(path):
|
2006-03-29 18:25:42 +00:00
|
|
|
lastSlash= max(path.rfind('\\'), path.rfind('/'))
|
2005-06-12 05:54:15 +00:00
|
|
|
if lastSlash != -1:
|
2006-03-29 18:25:42 +00:00
|
|
|
path= path[:lastSlash]
|
2005-06-12 05:54:15 +00:00
|
|
|
return '%s%s' % (path, sys.sep)
|
2004-06-14 20:51:09 +00:00
|
|
|
|
|
|
|
#==============================================#
|
|
|
|
# Strips the slashes from the back of a string #
|
|
|
|
#==============================================#
|
|
|
|
def stripPath(path):
|
2005-05-30 02:26:40 +00:00
|
|
|
return path.split('/')[-1].split('\\')[-1]
|
2004-09-18 21:04:23 +00:00
|
|
|
|
2004-06-14 20:51:09 +00:00
|
|
|
#====================================================#
|
|
|
|
# Strips the prefix off the name before writing #
|
|
|
|
#====================================================#
|
2005-06-12 05:54:15 +00:00
|
|
|
def stripExt(name): # name is a string
|
2006-03-29 18:25:42 +00:00
|
|
|
index= name.rfind('.')
|
2005-10-11 02:32:58 +00:00
|
|
|
if index != -1:
|
|
|
|
return name[ : index ]
|
|
|
|
else:
|
|
|
|
return name
|
2004-06-14 20:51:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
from Blender import *
|
2006-05-09 13:20:18 +00:00
|
|
|
import BPyImage # use for comprehensiveImageLoad
|
|
|
|
import BPyMesh # use for ngon
|
2005-10-11 02:32:58 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
import os
|
|
|
|
except:
|
|
|
|
# So we know if os exists.
|
|
|
|
print 'Module "os" not found, install python to enable comprehensive image finding and batch loading.'
|
2006-03-29 18:25:42 +00:00
|
|
|
os= None
|
2005-10-11 02:32:58 +00:00
|
|
|
|
|
|
|
|
2004-06-21 12:01:23 +00:00
|
|
|
#==================================================================================#
|
|
|
|
# This function sets textures defined in .mtl file #
|
|
|
|
#==================================================================================#
|
2005-07-11 02:41:08 +00:00
|
|
|
def loadMaterialImage(mat, img_fileName, type, meshDict, dir):
|
2006-03-29 18:25:42 +00:00
|
|
|
TEX_ON_FLAG= NMesh.FaceModes['TEX']
|
2004-09-18 21:04:23 +00:00
|
|
|
|
2006-03-29 18:25:42 +00:00
|
|
|
texture= Texture.New(type)
|
2004-09-18 21:04:23 +00:00
|
|
|
texture.setType('Image')
|
BPython bug fixes:
- #2646 reported by Campbell: Python/Fileselector (moving from fileselector called by script to another space caused script to hang around open but not accessible)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2646&group_id=9
- #2676 reported by Wim Van Hoydonck: 2.37 python scripts gui: event 8 ignored (thanks Ton for discussing / pointing what to do, Ken Hughes for also working on a fix)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2676&group_id=9
- gui-less scripts with calls to progress bar inside fileselector callbacks didn't return to the previous space on exit (staying on Scripts win), requiring an event to do so (mouse movement, for example). Quick fix for now, will rework a little after 2.37a for a better alternative, not needing to move to the Scripts win at all.
- added syntax colors access to Window.Theme module.
Scripts:
- updates by Jean-Michel Soler: svg2obj (svg paths import), tex2uvbaker, fixfromarmature;
- updates by Campbell Barton: obj import / export, console;
- tiny: converted vrml97 export to unix line endings;
- updates in ac3d exporter, help browser, save theme.
Thanks all mentioned above.
2005-06-11 05:30:14 +00:00
|
|
|
|
2005-07-11 02:41:08 +00:00
|
|
|
# Absolute path - c:\.. etc would work here
|
2006-03-29 18:25:42 +00:00
|
|
|
image= BPyImage.comprehensiveImageLoad(img_fileName, dir)
|
2005-07-11 02:41:08 +00:00
|
|
|
|
BPython bug fixes:
- #2646 reported by Campbell: Python/Fileselector (moving from fileselector called by script to another space caused script to hang around open but not accessible)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2646&group_id=9
- #2676 reported by Wim Van Hoydonck: 2.37 python scripts gui: event 8 ignored (thanks Ton for discussing / pointing what to do, Ken Hughes for also working on a fix)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2676&group_id=9
- gui-less scripts with calls to progress bar inside fileselector callbacks didn't return to the previous space on exit (staying on Scripts win), requiring an event to do so (mouse movement, for example). Quick fix for now, will rework a little after 2.37a for a better alternative, not needing to move to the Scripts win at all.
- added syntax colors access to Window.Theme module.
Scripts:
- updates by Jean-Michel Soler: svg2obj (svg paths import), tex2uvbaker, fixfromarmature;
- updates by Campbell Barton: obj import / export, console;
- tiny: converted vrml97 export to unix line endings;
- updates in ac3d exporter, help browser, save theme.
Thanks all mentioned above.
2005-06-11 05:30:14 +00:00
|
|
|
if image:
|
2006-03-29 18:25:42 +00:00
|
|
|
texture.image= image
|
2005-06-12 05:54:15 +00:00
|
|
|
|
2004-09-18 21:04:23 +00:00
|
|
|
# adds textures to faces (Textured/Alt-Z mode)
|
|
|
|
# Only apply the diffuse texture to the face if the image has not been set with the inline usemat func.
|
2005-06-12 05:54:15 +00:00
|
|
|
if image and type == 'Kd':
|
2005-10-11 02:32:58 +00:00
|
|
|
for meshPair in meshDict.itervalues():
|
BPython bug fixes:
- #2646 reported by Campbell: Python/Fileselector (moving from fileselector called by script to another space caused script to hang around open but not accessible)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2646&group_id=9
- #2676 reported by Wim Van Hoydonck: 2.37 python scripts gui: event 8 ignored (thanks Ton for discussing / pointing what to do, Ken Hughes for also working on a fix)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2676&group_id=9
- gui-less scripts with calls to progress bar inside fileselector callbacks didn't return to the previous space on exit (staying on Scripts win), requiring an event to do so (mouse movement, for example). Quick fix for now, will rework a little after 2.37a for a better alternative, not needing to move to the Scripts win at all.
- added syntax colors access to Window.Theme module.
Scripts:
- updates by Jean-Michel Soler: svg2obj (svg paths import), tex2uvbaker, fixfromarmature;
- updates by Campbell Barton: obj import / export, console;
- tiny: converted vrml97 export to unix line endings;
- updates in ac3d exporter, help browser, save theme.
Thanks all mentioned above.
2005-06-11 05:30:14 +00:00
|
|
|
for f in meshPair[0].faces:
|
2005-06-12 05:54:15 +00:00
|
|
|
#print meshPair[0].materials[f.mat].name, mat.name
|
BPython bug fixes:
- #2646 reported by Campbell: Python/Fileselector (moving from fileselector called by script to another space caused script to hang around open but not accessible)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2646&group_id=9
- #2676 reported by Wim Van Hoydonck: 2.37 python scripts gui: event 8 ignored (thanks Ton for discussing / pointing what to do, Ken Hughes for also working on a fix)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2676&group_id=9
- gui-less scripts with calls to progress bar inside fileselector callbacks didn't return to the previous space on exit (staying on Scripts win), requiring an event to do so (mouse movement, for example). Quick fix for now, will rework a little after 2.37a for a better alternative, not needing to move to the Scripts win at all.
- added syntax colors access to Window.Theme module.
Scripts:
- updates by Jean-Michel Soler: svg2obj (svg paths import), tex2uvbaker, fixfromarmature;
- updates by Campbell Barton: obj import / export, console;
- tiny: converted vrml97 export to unix line endings;
- updates in ac3d exporter, help browser, save theme.
Thanks all mentioned above.
2005-06-11 05:30:14 +00:00
|
|
|
if meshPair[0].materials[f.mat].name == mat.name:
|
|
|
|
# the inline usemat command overides the material Image
|
|
|
|
if not f.image:
|
2005-06-12 05:54:15 +00:00
|
|
|
f.mode |= TEX_ON_FLAG
|
2006-03-29 18:25:42 +00:00
|
|
|
f.image= image
|
2005-06-12 05:54:15 +00:00
|
|
|
|
2004-09-18 21:04:23 +00:00
|
|
|
# adds textures for materials (rendering)
|
BPython bug fixes:
- #2646 reported by Campbell: Python/Fileselector (moving from fileselector called by script to another space caused script to hang around open but not accessible)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2646&group_id=9
- #2676 reported by Wim Van Hoydonck: 2.37 python scripts gui: event 8 ignored (thanks Ton for discussing / pointing what to do, Ken Hughes for also working on a fix)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2676&group_id=9
- gui-less scripts with calls to progress bar inside fileselector callbacks didn't return to the previous space on exit (staying on Scripts win), requiring an event to do so (mouse movement, for example). Quick fix for now, will rework a little after 2.37a for a better alternative, not needing to move to the Scripts win at all.
- added syntax colors access to Window.Theme module.
Scripts:
- updates by Jean-Michel Soler: svg2obj (svg paths import), tex2uvbaker, fixfromarmature;
- updates by Campbell Barton: obj import / export, console;
- tiny: converted vrml97 export to unix line endings;
- updates in ac3d exporter, help browser, save theme.
Thanks all mentioned above.
2005-06-11 05:30:14 +00:00
|
|
|
elif type == 'Ka':
|
2005-07-11 02:41:08 +00:00
|
|
|
mat.setTexture(0, texture, Texture.TexCo.UV, Texture.MapTo.CMIR) # TODO- Add AMB to BPY API
|
BPython bug fixes:
- #2646 reported by Campbell: Python/Fileselector (moving from fileselector called by script to another space caused script to hang around open but not accessible)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2646&group_id=9
- #2676 reported by Wim Van Hoydonck: 2.37 python scripts gui: event 8 ignored (thanks Ton for discussing / pointing what to do, Ken Hughes for also working on a fix)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2676&group_id=9
- gui-less scripts with calls to progress bar inside fileselector callbacks didn't return to the previous space on exit (staying on Scripts win), requiring an event to do so (mouse movement, for example). Quick fix for now, will rework a little after 2.37a for a better alternative, not needing to move to the Scripts win at all.
- added syntax colors access to Window.Theme module.
Scripts:
- updates by Jean-Michel Soler: svg2obj (svg paths import), tex2uvbaker, fixfromarmature;
- updates by Campbell Barton: obj import / export, console;
- tiny: converted vrml97 export to unix line endings;
- updates in ac3d exporter, help browser, save theme.
Thanks all mentioned above.
2005-06-11 05:30:14 +00:00
|
|
|
elif type == 'Kd':
|
2004-09-18 21:04:23 +00:00
|
|
|
mat.setTexture(1, texture, Texture.TexCo.UV, Texture.MapTo.COL)
|
BPython bug fixes:
- #2646 reported by Campbell: Python/Fileselector (moving from fileselector called by script to another space caused script to hang around open but not accessible)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2646&group_id=9
- #2676 reported by Wim Van Hoydonck: 2.37 python scripts gui: event 8 ignored (thanks Ton for discussing / pointing what to do, Ken Hughes for also working on a fix)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2676&group_id=9
- gui-less scripts with calls to progress bar inside fileselector callbacks didn't return to the previous space on exit (staying on Scripts win), requiring an event to do so (mouse movement, for example). Quick fix for now, will rework a little after 2.37a for a better alternative, not needing to move to the Scripts win at all.
- added syntax colors access to Window.Theme module.
Scripts:
- updates by Jean-Michel Soler: svg2obj (svg paths import), tex2uvbaker, fixfromarmature;
- updates by Campbell Barton: obj import / export, console;
- tiny: converted vrml97 export to unix line endings;
- updates in ac3d exporter, help browser, save theme.
Thanks all mentioned above.
2005-06-11 05:30:14 +00:00
|
|
|
elif type == 'Ks':
|
2004-09-18 21:04:23 +00:00
|
|
|
mat.setTexture(2, texture, Texture.TexCo.UV, Texture.MapTo.SPEC)
|
2005-07-11 02:41:08 +00:00
|
|
|
|
|
|
|
elif type == 'Bump': # New Additions
|
|
|
|
mat.setTexture(3, texture, Texture.TexCo.UV, Texture.MapTo.NOR)
|
|
|
|
elif type == 'D':
|
|
|
|
mat.setTexture(4, texture, Texture.TexCo.UV, Texture.MapTo.ALPHA)
|
|
|
|
elif type == 'refl':
|
|
|
|
mat.setTexture(5, texture, Texture.TexCo.UV, Texture.MapTo.REF)
|
2006-05-09 13:20:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
#===============================================================================#
|
|
|
|
# This gets a mat or creates one of the requested name if none exist. #
|
|
|
|
#===============================================================================#
|
|
|
|
def getMat(matName, materialDict):
|
|
|
|
# Make a new mat
|
|
|
|
try: return materialDict[matName]
|
|
|
|
except: pass # Better do any exception
|
|
|
|
|
|
|
|
try: return materialDict[matName.lower()]
|
|
|
|
except: pass
|
|
|
|
|
|
|
|
# Do we realy need to keep the dict up to date?, not realy but keeps consuistant.
|
|
|
|
mat= materialDict[matName]= Material.New(matName)
|
|
|
|
return mat
|
|
|
|
|
2004-06-14 20:51:09 +00:00
|
|
|
|
|
|
|
#==================================================================================#
|
|
|
|
# This function loads materials from .mtl file (have to be defined in obj file) #
|
|
|
|
#==================================================================================#
|
2006-05-09 13:20:18 +00:00
|
|
|
def load_mtl(dir, IMPORT_USE_EXISTING_MTL, mtl_file, meshDict, materialDict):
|
|
|
|
|
2006-03-29 18:25:42 +00:00
|
|
|
mtl_file= stripPath(mtl_file)
|
|
|
|
mtl_fileName= dir + mtl_file
|
BPython bug fixes:
- #2646 reported by Campbell: Python/Fileselector (moving from fileselector called by script to another space caused script to hang around open but not accessible)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2646&group_id=9
- #2676 reported by Wim Van Hoydonck: 2.37 python scripts gui: event 8 ignored (thanks Ton for discussing / pointing what to do, Ken Hughes for also working on a fix)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2676&group_id=9
- gui-less scripts with calls to progress bar inside fileselector callbacks didn't return to the previous space on exit (staying on Scripts win), requiring an event to do so (mouse movement, for example). Quick fix for now, will rework a little after 2.37a for a better alternative, not needing to move to the Scripts win at all.
- added syntax colors access to Window.Theme module.
Scripts:
- updates by Jean-Michel Soler: svg2obj (svg paths import), tex2uvbaker, fixfromarmature;
- updates by Campbell Barton: obj import / export, console;
- tiny: converted vrml97 export to unix line endings;
- updates in ac3d exporter, help browser, save theme.
Thanks all mentioned above.
2005-06-11 05:30:14 +00:00
|
|
|
|
2004-09-18 21:04:23 +00:00
|
|
|
try:
|
|
|
|
fileLines= open(mtl_fileName, 'r').readlines()
|
BPython bug fixes:
- #2646 reported by Campbell: Python/Fileselector (moving from fileselector called by script to another space caused script to hang around open but not accessible)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2646&group_id=9
- #2676 reported by Wim Van Hoydonck: 2.37 python scripts gui: event 8 ignored (thanks Ton for discussing / pointing what to do, Ken Hughes for also working on a fix)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2676&group_id=9
- gui-less scripts with calls to progress bar inside fileselector callbacks didn't return to the previous space on exit (staying on Scripts win), requiring an event to do so (mouse movement, for example). Quick fix for now, will rework a little after 2.37a for a better alternative, not needing to move to the Scripts win at all.
- added syntax colors access to Window.Theme module.
Scripts:
- updates by Jean-Michel Soler: svg2obj (svg paths import), tex2uvbaker, fixfromarmature;
- updates by Campbell Barton: obj import / export, console;
- tiny: converted vrml97 export to unix line endings;
- updates in ac3d exporter, help browser, save theme.
Thanks all mentioned above.
2005-06-11 05:30:14 +00:00
|
|
|
except IOError:
|
|
|
|
print '\tunable to open referenced material file: "%s"' % mtl_fileName
|
2004-09-18 21:04:23 +00:00
|
|
|
return
|
|
|
|
|
2005-06-12 05:54:15 +00:00
|
|
|
try:
|
|
|
|
lIdx=0
|
|
|
|
while lIdx < len(fileLines):
|
2006-03-29 18:25:42 +00:00
|
|
|
l= fileLines[lIdx].split()
|
2005-06-12 05:54:15 +00:00
|
|
|
|
|
|
|
# Detect a line that will be ignored
|
2006-01-29 19:17:53 +00:00
|
|
|
if len(l) == 0 or l[0].startswith('#'):
|
2005-06-12 05:54:15 +00:00
|
|
|
pass
|
|
|
|
elif l[0] == 'newmtl':
|
2006-03-29 18:25:42 +00:00
|
|
|
currentMat= getMat('_'.join(l[1:]), materialDict) # Material should alredy exist.
|
2005-06-12 05:54:15 +00:00
|
|
|
elif l[0] == 'Ka':
|
2005-10-11 02:32:58 +00:00
|
|
|
currentMat.setMirCol((float(l[1]), float(l[2]), float(l[3])))
|
2005-06-12 05:54:15 +00:00
|
|
|
elif l[0] == 'Kd':
|
2005-10-11 02:32:58 +00:00
|
|
|
currentMat.setRGBCol((float(l[1]), float(l[2]), float(l[3])))
|
2005-06-12 05:54:15 +00:00
|
|
|
elif l[0] == 'Ks':
|
2005-10-11 02:32:58 +00:00
|
|
|
currentMat.setSpecCol((float(l[1]), float(l[2]), float(l[3])))
|
2005-06-12 05:54:15 +00:00
|
|
|
elif l[0] == 'Ns':
|
|
|
|
currentMat.setHardness( int((float(l[1])*0.51)) )
|
2005-07-11 02:41:08 +00:00
|
|
|
elif l[0] == 'Ni': # Refraction index
|
|
|
|
currentMat.setIOR( max(1, min(float(l[1]), 3))) # Between 1 and 3
|
2005-06-12 05:54:15 +00:00
|
|
|
elif l[0] == 'd':
|
|
|
|
currentMat.setAlpha(float(l[1]))
|
|
|
|
elif l[0] == 'Tr':
|
|
|
|
currentMat.setAlpha(float(l[1]))
|
|
|
|
elif l[0] == 'map_Ka':
|
2006-03-29 18:25:42 +00:00
|
|
|
img_fileName= ' '.join(l[1:])
|
2005-07-11 02:41:08 +00:00
|
|
|
loadMaterialImage(currentMat, img_fileName, 'Ka', meshDict, dir)
|
2005-06-12 05:54:15 +00:00
|
|
|
elif l[0] == 'map_Ks':
|
2006-03-29 18:25:42 +00:00
|
|
|
img_fileName= ' '.join(l[1:])
|
2005-07-11 02:41:08 +00:00
|
|
|
loadMaterialImage(currentMat, img_fileName, 'Ks', meshDict, dir)
|
2005-06-12 05:54:15 +00:00
|
|
|
elif l[0] == 'map_Kd':
|
2006-03-29 18:25:42 +00:00
|
|
|
img_fileName= ' '.join(l[1:])
|
2005-07-11 02:41:08 +00:00
|
|
|
loadMaterialImage(currentMat, img_fileName, 'Kd', meshDict, dir)
|
|
|
|
|
|
|
|
# new additions
|
|
|
|
elif l[0] == 'map_Bump': # Bumpmap
|
2006-03-29 18:25:42 +00:00
|
|
|
img_fileName= ' '.join(l[1:])
|
2005-07-11 02:41:08 +00:00
|
|
|
loadMaterialImage(currentMat, img_fileName, 'Bump', meshDict, dir)
|
|
|
|
elif l[0] == 'map_D': # Alpha map - Dissolve
|
2006-03-29 18:25:42 +00:00
|
|
|
img_fileName= ' '.join(l[1:])
|
2005-07-11 02:41:08 +00:00
|
|
|
loadMaterialImage(currentMat, img_fileName, 'D', meshDict, dir)
|
|
|
|
|
|
|
|
elif l[0] == 'refl': # Reflectionmap
|
2006-03-29 18:25:42 +00:00
|
|
|
img_fileName= ' '.join(l[1:])
|
2005-07-11 02:41:08 +00:00
|
|
|
loadMaterialImage(currentMat, img_fileName, 'refl', meshDict, dir)
|
|
|
|
|
2005-06-12 05:54:15 +00:00
|
|
|
lIdx+=1
|
|
|
|
except:
|
2005-10-11 02:32:58 +00:00
|
|
|
print '\tERROR: Unable to parse MTL file: "%s"' % mtl_file
|
|
|
|
return
|
|
|
|
print '\tUsing MTL: "%s"' % mtl_file
|
2004-06-14 20:51:09 +00:00
|
|
|
|
|
|
|
#==================================================================================#
|
|
|
|
# This loads data from .obj file #
|
|
|
|
#==================================================================================#
|
2006-06-03 07:46:56 +00:00
|
|
|
def load_obj(\
|
|
|
|
file,\
|
|
|
|
IMPORT_MTL=1,\
|
|
|
|
IMPORT_USE_EXISTING_MTL=0,\
|
|
|
|
IMPORT_CONSTRAIN_BOUNDS=0.0,\
|
|
|
|
IMPORT_ROTATE_X90=0,\
|
|
|
|
IMPORT_EDGES=1,\
|
|
|
|
IMPORT_SMOOTH_ALL=0,\
|
|
|
|
IMPORT_FGON=1,\
|
|
|
|
IMPORT_SMOOTH_GROUPS=0,\
|
|
|
|
IMPORT_MTL_SPLIT=0,\
|
|
|
|
IMPORT_AS_INSTANCE=0):
|
|
|
|
|
2006-03-29 18:25:42 +00:00
|
|
|
global currentMesh,\
|
|
|
|
currentUsedVertList,\
|
|
|
|
currentUsedVertListSmoothGroup,\
|
|
|
|
meshDict,\
|
|
|
|
contextMeshMatIdx,\
|
|
|
|
currentMaterialMeshMapping
|
2005-10-11 02:32:58 +00:00
|
|
|
|
|
|
|
print '\nImporting OBJ file: "%s"' % file
|
|
|
|
|
2006-03-29 18:25:42 +00:00
|
|
|
time1= sys.time()
|
BPython bug fixes:
- #2646 reported by Campbell: Python/Fileselector (moving from fileselector called by script to another space caused script to hang around open but not accessible)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2646&group_id=9
- #2676 reported by Wim Van Hoydonck: 2.37 python scripts gui: event 8 ignored (thanks Ton for discussing / pointing what to do, Ken Hughes for also working on a fix)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2676&group_id=9
- gui-less scripts with calls to progress bar inside fileselector callbacks didn't return to the previous space on exit (staying on Scripts win), requiring an event to do so (mouse movement, for example). Quick fix for now, will rework a little after 2.37a for a better alternative, not needing to move to the Scripts win at all.
- added syntax colors access to Window.Theme module.
Scripts:
- updates by Jean-Michel Soler: svg2obj (svg paths import), tex2uvbaker, fixfromarmature;
- updates by Campbell Barton: obj import / export, console;
- tiny: converted vrml97 export to unix line endings;
- updates in ac3d exporter, help browser, save theme.
Thanks all mentioned above.
2005-06-11 05:30:14 +00:00
|
|
|
|
2005-06-12 05:54:15 +00:00
|
|
|
# Deselect all objects in the scene.
|
|
|
|
# do this first so we dont have to bother, with objects we import
|
|
|
|
for ob in Scene.GetCurrent().getChildren():
|
2006-03-29 18:25:42 +00:00
|
|
|
ob.sel= 0
|
2005-06-12 05:54:15 +00:00
|
|
|
|
2006-03-29 18:25:42 +00:00
|
|
|
TEX_OFF_FLAG= ~NMesh.FaceModes['TEX']
|
BPython bug fixes:
- #2646 reported by Campbell: Python/Fileselector (moving from fileselector called by script to another space caused script to hang around open but not accessible)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2646&group_id=9
- #2676 reported by Wim Van Hoydonck: 2.37 python scripts gui: event 8 ignored (thanks Ton for discussing / pointing what to do, Ken Hughes for also working on a fix)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2676&group_id=9
- gui-less scripts with calls to progress bar inside fileselector callbacks didn't return to the previous space on exit (staying on Scripts win), requiring an event to do so (mouse movement, for example). Quick fix for now, will rework a little after 2.37a for a better alternative, not needing to move to the Scripts win at all.
- added syntax colors access to Window.Theme module.
Scripts:
- updates by Jean-Michel Soler: svg2obj (svg paths import), tex2uvbaker, fixfromarmature;
- updates by Campbell Barton: obj import / export, console;
- tiny: converted vrml97 export to unix line endings;
- updates in ac3d exporter, help browser, save theme.
Thanks all mentioned above.
2005-06-11 05:30:14 +00:00
|
|
|
|
2006-05-09 13:20:18 +00:00
|
|
|
# Used for bounds scaling
|
|
|
|
global BOUNDS
|
|
|
|
BOUNDS= 0.0
|
|
|
|
|
2004-09-18 21:04:23 +00:00
|
|
|
# Get the file name with no path or .obj
|
2006-03-29 18:25:42 +00:00
|
|
|
fileName= stripExt( stripPath(file) )
|
2004-09-11 13:45:17 +00:00
|
|
|
|
2006-03-29 18:25:42 +00:00
|
|
|
mtl_fileName= [] # Support multiple mtl files if needed.
|
2004-09-18 21:04:23 +00:00
|
|
|
|
2006-03-29 18:25:42 +00:00
|
|
|
DIR= stripFile(file)
|
2005-06-12 05:54:15 +00:00
|
|
|
|
2006-03-29 18:25:42 +00:00
|
|
|
tempFile= open(file, 'r')
|
|
|
|
fileLines= tempFile.readlines()
|
2005-06-12 05:54:15 +00:00
|
|
|
tempFile.close()
|
2006-01-29 19:17:53 +00:00
|
|
|
del tempFile
|
2006-03-29 18:25:42 +00:00
|
|
|
uvMapList= [] # store tuple uv pairs here
|
2005-10-11 02:32:58 +00:00
|
|
|
|
2004-09-18 21:04:23 +00:00
|
|
|
# This dummy vert makes life a whole lot easier-
|
|
|
|
# pythons index system then aligns with objs, remove later
|
2006-03-29 18:25:42 +00:00
|
|
|
vertList= [] # Could havea vert but since this is a placeholder theres no Point
|
BPython bug fixes:
- #2646 reported by Campbell: Python/Fileselector (moving from fileselector called by script to another space caused script to hang around open but not accessible)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2646&group_id=9
- #2676 reported by Wim Van Hoydonck: 2.37 python scripts gui: event 8 ignored (thanks Ton for discussing / pointing what to do, Ken Hughes for also working on a fix)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2676&group_id=9
- gui-less scripts with calls to progress bar inside fileselector callbacks didn't return to the previous space on exit (staying on Scripts win), requiring an event to do so (mouse movement, for example). Quick fix for now, will rework a little after 2.37a for a better alternative, not needing to move to the Scripts win at all.
- added syntax colors access to Window.Theme module.
Scripts:
- updates by Jean-Michel Soler: svg2obj (svg paths import), tex2uvbaker, fixfromarmature;
- updates by Campbell Barton: obj import / export, console;
- tiny: converted vrml97 export to unix line endings;
- updates in ac3d exporter, help browser, save theme.
Thanks all mentioned above.
2005-06-11 05:30:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Store all imported images in a dict, names are key
|
2006-03-29 18:25:42 +00:00
|
|
|
imageDict= {}
|
BPython bug fixes:
- #2646 reported by Campbell: Python/Fileselector (moving from fileselector called by script to another space caused script to hang around open but not accessible)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2646&group_id=9
- #2676 reported by Wim Van Hoydonck: 2.37 python scripts gui: event 8 ignored (thanks Ton for discussing / pointing what to do, Ken Hughes for also working on a fix)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2676&group_id=9
- gui-less scripts with calls to progress bar inside fileselector callbacks didn't return to the previous space on exit (staying on Scripts win), requiring an event to do so (mouse movement, for example). Quick fix for now, will rework a little after 2.37a for a better alternative, not needing to move to the Scripts win at all.
- added syntax colors access to Window.Theme module.
Scripts:
- updates by Jean-Michel Soler: svg2obj (svg paths import), tex2uvbaker, fixfromarmature;
- updates by Campbell Barton: obj import / export, console;
- tiny: converted vrml97 export to unix line endings;
- updates in ac3d exporter, help browser, save theme.
Thanks all mentioned above.
2005-06-11 05:30:14 +00:00
|
|
|
|
|
|
|
# This stores the index that the current mesh has for the current material.
|
|
|
|
# if the mesh does not have the material then set -1
|
2006-03-29 18:25:42 +00:00
|
|
|
contextMeshMatIdx= -1
|
BPython bug fixes:
- #2646 reported by Campbell: Python/Fileselector (moving from fileselector called by script to another space caused script to hang around open but not accessible)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2646&group_id=9
- #2676 reported by Wim Van Hoydonck: 2.37 python scripts gui: event 8 ignored (thanks Ton for discussing / pointing what to do, Ken Hughes for also working on a fix)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2676&group_id=9
- gui-less scripts with calls to progress bar inside fileselector callbacks didn't return to the previous space on exit (staying on Scripts win), requiring an event to do so (mouse movement, for example). Quick fix for now, will rework a little after 2.37a for a better alternative, not needing to move to the Scripts win at all.
- added syntax colors access to Window.Theme module.
Scripts:
- updates by Jean-Michel Soler: svg2obj (svg paths import), tex2uvbaker, fixfromarmature;
- updates by Campbell Barton: obj import / export, console;
- tiny: converted vrml97 export to unix line endings;
- updates in ac3d exporter, help browser, save theme.
Thanks all mentioned above.
2005-06-11 05:30:14 +00:00
|
|
|
|
2004-09-21 09:09:58 +00:00
|
|
|
|
2006-03-29 18:25:42 +00:00
|
|
|
currentImg= None # Null image is a string, otherwise this should be set to an image object.\
|
2006-01-29 19:17:53 +00:00
|
|
|
if IMPORT_SMOOTH_ALL:
|
2006-03-29 18:25:42 +00:00
|
|
|
currentSmooth= True
|
2006-01-29 19:17:53 +00:00
|
|
|
else:
|
2006-03-29 18:25:42 +00:00
|
|
|
currentSmooth= False
|
2004-09-21 09:09:58 +00:00
|
|
|
|
BPython bug fixes:
- #2646 reported by Campbell: Python/Fileselector (moving from fileselector called by script to another space caused script to hang around open but not accessible)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2646&group_id=9
- #2676 reported by Wim Van Hoydonck: 2.37 python scripts gui: event 8 ignored (thanks Ton for discussing / pointing what to do, Ken Hughes for also working on a fix)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2676&group_id=9
- gui-less scripts with calls to progress bar inside fileselector callbacks didn't return to the previous space on exit (staying on Scripts win), requiring an event to do so (mouse movement, for example). Quick fix for now, will rework a little after 2.37a for a better alternative, not needing to move to the Scripts win at all.
- added syntax colors access to Window.Theme module.
Scripts:
- updates by Jean-Michel Soler: svg2obj (svg paths import), tex2uvbaker, fixfromarmature;
- updates by Campbell Barton: obj import / export, console;
- tiny: converted vrml97 export to unix line endings;
- updates in ac3d exporter, help browser, save theme.
Thanks all mentioned above.
2005-06-11 05:30:14 +00:00
|
|
|
# Store a list of unnamed names
|
2006-03-29 18:25:42 +00:00
|
|
|
currentUnnamedGroupIdx= 1
|
|
|
|
currentUnnamedObjectIdx= 1
|
BPython bug fixes:
- #2646 reported by Campbell: Python/Fileselector (moving from fileselector called by script to another space caused script to hang around open but not accessible)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2646&group_id=9
- #2676 reported by Wim Van Hoydonck: 2.37 python scripts gui: event 8 ignored (thanks Ton for discussing / pointing what to do, Ken Hughes for also working on a fix)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2676&group_id=9
- gui-less scripts with calls to progress bar inside fileselector callbacks didn't return to the previous space on exit (staying on Scripts win), requiring an event to do so (mouse movement, for example). Quick fix for now, will rework a little after 2.37a for a better alternative, not needing to move to the Scripts win at all.
- added syntax colors access to Window.Theme module.
Scripts:
- updates by Jean-Michel Soler: svg2obj (svg paths import), tex2uvbaker, fixfromarmature;
- updates by Campbell Barton: obj import / export, console;
- tiny: converted vrml97 export to unix line endings;
- updates in ac3d exporter, help browser, save theme.
Thanks all mentioned above.
2005-06-11 05:30:14 +00:00
|
|
|
|
2006-03-29 18:25:42 +00:00
|
|
|
quadList= (0, 1, 2, 3)
|
2004-09-21 09:09:58 +00:00
|
|
|
|
2006-03-29 18:25:42 +00:00
|
|
|
faceQuadVList= [None, None, None, None]
|
|
|
|
faceTriVList= [None, None, None]
|
2005-06-12 05:54:15 +00:00
|
|
|
|
2004-09-21 09:09:58 +00:00
|
|
|
#==================================================================================#
|
|
|
|
# Load all verts first (texture verts too) #
|
|
|
|
#==================================================================================#
|
BPython bug fixes:
- #2646 reported by Campbell: Python/Fileselector (moving from fileselector called by script to another space caused script to hang around open but not accessible)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2646&group_id=9
- #2676 reported by Wim Van Hoydonck: 2.37 python scripts gui: event 8 ignored (thanks Ton for discussing / pointing what to do, Ken Hughes for also working on a fix)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2676&group_id=9
- gui-less scripts with calls to progress bar inside fileselector callbacks didn't return to the previous space on exit (staying on Scripts win), requiring an event to do so (mouse movement, for example). Quick fix for now, will rework a little after 2.37a for a better alternative, not needing to move to the Scripts win at all.
- added syntax colors access to Window.Theme module.
Scripts:
- updates by Jean-Michel Soler: svg2obj (svg paths import), tex2uvbaker, fixfromarmature;
- updates by Campbell Barton: obj import / export, console;
- tiny: converted vrml97 export to unix line endings;
- updates in ac3d exporter, help browser, save theme.
Thanks all mentioned above.
2005-06-11 05:30:14 +00:00
|
|
|
print '\tfile length: %d' % len(fileLines)
|
2006-01-29 19:17:53 +00:00
|
|
|
# Ignore normals and comments.
|
2006-03-29 18:25:42 +00:00
|
|
|
fileLines= [lsplit for l in fileLines if not l.startswith('vn') if not l.startswith('#') for lsplit in (l.split(),) if lsplit]
|
2006-05-09 13:20:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
if IMPORT_CONSTRAIN_BOUNDS == 0.0:
|
|
|
|
if IMPORT_ROTATE_X90:
|
|
|
|
def Vert(x,y,z):
|
|
|
|
return NMesh.Vert(x,-z,y) # rotate 90 about the x axis.
|
|
|
|
else:
|
|
|
|
Vert= NMesh.Vert
|
|
|
|
else:
|
|
|
|
# Adding a vert also sets the bounds.
|
|
|
|
if IMPORT_ROTATE_X90:
|
|
|
|
def Vert(x,y,z):
|
|
|
|
global BOUNDS
|
|
|
|
BOUNDS= max(BOUNDS, x,y,z)
|
|
|
|
return NMesh.Vert(x,-z,y) # Rotate X90 Deg.
|
|
|
|
else:
|
|
|
|
def Vert(x,y,z):
|
|
|
|
global BOUNDS
|
|
|
|
BOUNDS= max(BOUNDS, x,y,z)
|
|
|
|
return NMesh.Vert(x,y,z)
|
|
|
|
|
2006-04-11 00:00:07 +00:00
|
|
|
try:
|
|
|
|
vertList= [Vert(float(l[1]), float(l[2]), float(l[3]) ) for l in fileLines if l[0] == 'v']
|
|
|
|
except ValueError:
|
|
|
|
# What??? Maya 7 uses "6,45" instead of "6.45"
|
|
|
|
vertList= [Vert(float(l[1].replace(',', '.')), float(l[2].replace(',', '.')), float(l[3].replace(',', '.')) ) for l in fileLines if l[0] == 'v']
|
2006-05-09 13:20:18 +00:00
|
|
|
|
|
|
|
|
2006-04-11 00:00:07 +00:00
|
|
|
try:
|
|
|
|
uvMapList= [(float(l[1]), float(l[2])) for l in fileLines if l[0] == 'vt']
|
|
|
|
except ValueError:
|
|
|
|
# Same amazement as above. call that a float?
|
|
|
|
uvMapList= [(float(l[1].replace(',', '.')), float(l[2].replace(',', '.'))) for l in fileLines if l[0] == 'vt']
|
|
|
|
|
2006-03-29 18:25:42 +00:00
|
|
|
if IMPORT_SMOOTH_GROUPS:
|
|
|
|
smoothingGroups= dict([('_'.join(l[1:]), None) for l in fileLines if l[0] == 's' ])
|
|
|
|
else:
|
|
|
|
smoothingGroups= {}
|
2006-05-09 13:20:18 +00:00
|
|
|
|
|
|
|
print '\tvert:%i texverts:%i smoothgroups:%i' % (len(vertList), len(uvMapList), len(smoothingGroups))
|
2006-01-29 19:17:53 +00:00
|
|
|
|
|
|
|
# Replace filelines, Excluding v excludes "v ", "vn " and "vt "
|
|
|
|
# Remove any variables we may have created.
|
|
|
|
try: del _dummy
|
|
|
|
except: pass
|
|
|
|
try: del _x
|
|
|
|
except: pass
|
|
|
|
try: del _y
|
|
|
|
except: pass
|
|
|
|
try: del _z
|
|
|
|
except: pass
|
|
|
|
try: del lsplit
|
|
|
|
except: pass
|
|
|
|
del Vert
|
|
|
|
|
2006-02-04 03:44:21 +00:00
|
|
|
|
2006-01-29 19:17:53 +00:00
|
|
|
# With negative values this is used a lot. make faster access.
|
2006-03-29 18:25:42 +00:00
|
|
|
len_uvMapList= len(uvMapList)
|
|
|
|
len_vertList= len(vertList)
|
BPython bug fixes:
- #2646 reported by Campbell: Python/Fileselector (moving from fileselector called by script to another space caused script to hang around open but not accessible)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2646&group_id=9
- #2676 reported by Wim Van Hoydonck: 2.37 python scripts gui: event 8 ignored (thanks Ton for discussing / pointing what to do, Ken Hughes for also working on a fix)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2676&group_id=9
- gui-less scripts with calls to progress bar inside fileselector callbacks didn't return to the previous space on exit (staying on Scripts win), requiring an event to do so (mouse movement, for example). Quick fix for now, will rework a little after 2.37a for a better alternative, not needing to move to the Scripts win at all.
- added syntax colors access to Window.Theme module.
Scripts:
- updates by Jean-Michel Soler: svg2obj (svg paths import), tex2uvbaker, fixfromarmature;
- updates by Campbell Barton: obj import / export, console;
- tiny: converted vrml97 export to unix line endings;
- updates in ac3d exporter, help browser, save theme.
Thanks all mentioned above.
2005-06-11 05:30:14 +00:00
|
|
|
|
2005-06-12 05:54:15 +00:00
|
|
|
# Only want unique keys anyway
|
2006-03-29 18:25:42 +00:00
|
|
|
smoothingGroups['(null)']= None # Make sure we have at least 1.
|
|
|
|
smoothingGroups= smoothingGroups.keys()
|
2006-05-09 13:20:18 +00:00
|
|
|
|
2005-06-12 05:54:15 +00:00
|
|
|
|
|
|
|
# Add materials to Blender for later is in teh OBJ
|
2006-05-09 13:20:18 +00:00
|
|
|
|
|
|
|
# Keep this out of the dict for easy accsess.
|
|
|
|
if IMPORT_MTL:
|
|
|
|
materialDict= {}
|
|
|
|
|
|
|
|
if IMPORT_USE_EXISTING_MTL:
|
|
|
|
# Add existing materials to the dict./
|
|
|
|
for mat in Material.Get():
|
|
|
|
mat_name= mat.name.lower()
|
|
|
|
|
|
|
|
# Try add the name without the .001
|
|
|
|
if\
|
|
|
|
len(mat_name)>4 and\
|
|
|
|
mat_name[-4]=='.' and\
|
|
|
|
mat_name[-3:].isdigit():
|
|
|
|
materialDict[mat_name[-4:]]= mat
|
|
|
|
|
|
|
|
# Add the lower name
|
|
|
|
materialDict[mat_name]= mat
|
|
|
|
|
|
|
|
currentMat= nullMat= getMat('(null)', materialDict)
|
|
|
|
# Add all new materials allong the way...
|
2005-06-12 05:54:15 +00:00
|
|
|
|
|
|
|
|
2006-04-10 21:42:18 +00:00
|
|
|
# Make a list of all unused vert indices that we can copy from
|
2006-03-29 18:25:42 +00:00
|
|
|
VERT_USED_LIST= [-1]*len_vertList
|
2004-09-21 09:09:58 +00:00
|
|
|
|
|
|
|
# Here we store a boolean list of which verts are used or not
|
|
|
|
# no we know weather to add them to the current mesh
|
2006-04-10 21:42:18 +00:00
|
|
|
# This is an issue with global vertex indices being translated to per mesh indices
|
2004-09-21 09:09:58 +00:00
|
|
|
# like blenders, we start with a dummy just like the vert.
|
|
|
|
# -1 means unused, any other value refers to the local mesh index of the vert.
|
|
|
|
|
2005-06-12 05:54:15 +00:00
|
|
|
# currentObjectName has a char in front of it that determins weather its a group or object.
|
2004-09-21 09:09:58 +00:00
|
|
|
# We ignore it when naming the object.
|
2006-03-29 18:25:42 +00:00
|
|
|
currentObjectName= 'unnamed_obj_0' # If we cant get one, use this
|
2005-06-12 05:54:15 +00:00
|
|
|
|
2006-03-29 18:25:42 +00:00
|
|
|
if IMPORT_MTL_SPLIT:
|
|
|
|
currentObjectName_real= currentObjectName
|
|
|
|
|
|
|
|
#meshDict= {} # The 3 variables below are stored in a tuple within this dict for each mesh
|
|
|
|
currentMesh= NMesh.GetRaw() # The NMesh representation of the OBJ group/Object
|
|
|
|
#currentUsedVertList= {} # A Dict of smooth groups, each smooth group has a list of used verts and they are generated on demand so as to save memory.
|
2006-04-10 21:42:18 +00:00
|
|
|
currentMaterialMeshMapping= {} # Used to store material indices so we dont have to search the mesh for materials every time.
|
2005-06-12 05:54:15 +00:00
|
|
|
|
|
|
|
# Every mesh has a null smooth group, this is used if there are no smooth groups in the OBJ file.
|
|
|
|
# and when for faces where no smooth group is used.
|
2006-03-29 18:25:42 +00:00
|
|
|
currentSmoothGroup= '(null)' # The Name of the current smooth group
|
2005-06-12 05:54:15 +00:00
|
|
|
|
|
|
|
# For direct accsess to the Current Meshes, Current Smooth Groups- Used verts.
|
|
|
|
# This is of course context based and changes on the fly.
|
|
|
|
# Set the initial '(null)' Smooth group, every mesh has one.
|
2006-03-29 18:25:42 +00:00
|
|
|
currentUsedVertListSmoothGroup= VERT_USED_LIST[:]
|
2006-01-29 19:17:53 +00:00
|
|
|
currentUsedVertList= {currentSmoothGroup: currentUsedVertListSmoothGroup }
|
2005-06-12 05:54:15 +00:00
|
|
|
|
|
|
|
# 0:NMesh, 1:SmoothGroups[UsedVerts[0,0,0,0]], 2:materialMapping['matname':matIndexForThisNMesh]
|
2006-03-29 18:25:42 +00:00
|
|
|
meshDict= {currentObjectName: (currentMesh, currentUsedVertList, currentMaterialMeshMapping) }
|
2005-06-12 05:54:15 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
# Only show the bad uv error once
|
2006-03-29 18:25:42 +00:00
|
|
|
badObjUvs= 0
|
|
|
|
badObjFaceVerts= 0
|
|
|
|
badObjFaceTexCo= 0
|
BPython bug fixes:
- #2646 reported by Campbell: Python/Fileselector (moving from fileselector called by script to another space caused script to hang around open but not accessible)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2646&group_id=9
- #2676 reported by Wim Van Hoydonck: 2.37 python scripts gui: event 8 ignored (thanks Ton for discussing / pointing what to do, Ken Hughes for also working on a fix)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2676&group_id=9
- gui-less scripts with calls to progress bar inside fileselector callbacks didn't return to the previous space on exit (staying on Scripts win), requiring an event to do so (mouse movement, for example). Quick fix for now, will rework a little after 2.37a for a better alternative, not needing to move to the Scripts win at all.
- added syntax colors access to Window.Theme module.
Scripts:
- updates by Jean-Michel Soler: svg2obj (svg paths import), tex2uvbaker, fixfromarmature;
- updates by Campbell Barton: obj import / export, console;
- tiny: converted vrml97 export to unix line endings;
- updates in ac3d exporter, help browser, save theme.
Thanks all mentioned above.
2005-06-11 05:30:14 +00:00
|
|
|
|
2005-06-12 05:54:15 +00:00
|
|
|
|
2006-04-10 21:42:18 +00:00
|
|
|
#currentMesh.verts.append(vertList[0]) # So we can sync with OBJ indices where 1 is the first item.
|
2006-01-29 19:17:53 +00:00
|
|
|
if len_uvMapList > 1:
|
2005-06-12 05:54:15 +00:00
|
|
|
currentMesh.hasFaceUV(1) # Turn UV's on if we have ANY texture coords in this obj file.
|
BPython bug fixes:
- #2646 reported by Campbell: Python/Fileselector (moving from fileselector called by script to another space caused script to hang around open but not accessible)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2646&group_id=9
- #2676 reported by Wim Van Hoydonck: 2.37 python scripts gui: event 8 ignored (thanks Ton for discussing / pointing what to do, Ken Hughes for also working on a fix)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2676&group_id=9
- gui-less scripts with calls to progress bar inside fileselector callbacks didn't return to the previous space on exit (staying on Scripts win), requiring an event to do so (mouse movement, for example). Quick fix for now, will rework a little after 2.37a for a better alternative, not needing to move to the Scripts win at all.
- added syntax colors access to Window.Theme module.
Scripts:
- updates by Jean-Michel Soler: svg2obj (svg paths import), tex2uvbaker, fixfromarmature;
- updates by Campbell Barton: obj import / export, console;
- tiny: converted vrml97 export to unix line endings;
- updates in ac3d exporter, help browser, save theme.
Thanks all mentioned above.
2005-06-11 05:30:14 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
|
2006-03-29 18:25:42 +00:00
|
|
|
|
|
|
|
# Heres the code that gets a mesh, creating a new one if needed.
|
|
|
|
# may_exist is used to avoid a dict looup.
|
|
|
|
# if the mesh is unnamed then we generate a new name and dont bother looking
|
|
|
|
# to see if its alredy there.
|
|
|
|
def obj_getmesh(may_exist):
|
|
|
|
global currentMesh,\
|
|
|
|
currentUsedVertList,\
|
|
|
|
currentUsedVertListSmoothGroup,\
|
|
|
|
meshDict,\
|
|
|
|
contextMeshMatIdx,\
|
|
|
|
currentMaterialMeshMapping
|
|
|
|
|
|
|
|
#print 'getting mesh,', currentObjectName
|
|
|
|
|
|
|
|
# If we havnt written to this mesh before then do so.
|
|
|
|
# if we have then we'll just keep appending to it, this is required for soem files.
|
|
|
|
|
|
|
|
# If we are new, or we are not yet in the list of added meshes
|
|
|
|
# then make us new mesh.
|
|
|
|
if (not may_exist) or (not meshDict.has_key(currentObjectName)):
|
|
|
|
currentMesh= NMesh.GetRaw()
|
|
|
|
|
|
|
|
currentUsedVertList= {}
|
|
|
|
|
|
|
|
# SmoothGroup is a string
|
|
|
|
########currentSmoothGroup= '(null)' # From examplesm changing the g/o shouldent change the smooth group.
|
|
|
|
currentUsedVertList[currentSmoothGroup]= currentUsedVertListSmoothGroup= VERT_USED_LIST[:]
|
|
|
|
|
|
|
|
currentMaterialMeshMapping= {}
|
|
|
|
meshDict[currentObjectName]= (currentMesh, currentUsedVertList, currentMaterialMeshMapping)
|
|
|
|
currentMesh.hasFaceUV(1)
|
|
|
|
contextMeshMatIdx= -1
|
|
|
|
|
|
|
|
else:
|
|
|
|
# Since we have this in Blender then we will check if the current Mesh has the material.
|
|
|
|
# set the contextMeshMatIdx to the meshs index but only if we have it.
|
|
|
|
currentMesh, currentUsedVertList, currentMaterialMeshMapping= meshDict[currentObjectName]
|
|
|
|
#getMeshMaterialIndex(currentMesh, currentMat)
|
|
|
|
|
2006-05-09 13:20:18 +00:00
|
|
|
if IMPORT_MTL:
|
|
|
|
try:
|
|
|
|
contextMeshMatIdx= currentMaterialMeshMapping[currentMat.name] #getMeshMaterialIndex(currentMesh, currentMat)
|
|
|
|
except KeyError:
|
|
|
|
contextMeshMatIdx -1
|
2006-03-29 18:25:42 +00:00
|
|
|
|
|
|
|
# For new meshes switch smoothing groups to null
|
|
|
|
########currentSmoothGroup= '(null)' # From examplesm changing the g/o shouldent change the smooth group.
|
|
|
|
try:
|
|
|
|
currentUsedVertListSmoothGroup= currentUsedVertList[currentSmoothGroup]
|
|
|
|
except:
|
|
|
|
currentUsedVertList[currentSmoothGroup]= currentUsedVertListSmoothGroup= VERT_USED_LIST[:]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-09-21 09:09:58 +00:00
|
|
|
#==================================================================================#
|
|
|
|
# Load all faces into objects, main loop #
|
|
|
|
#==================================================================================#
|
2006-03-29 18:25:42 +00:00
|
|
|
lIdx= 0
|
|
|
|
EDGE_FGON_FLAG= NMesh.EdgeFlags['FGON']
|
|
|
|
EDGE_DRAW_FLAG= NMesh.EdgeFlags['EDGEDRAW']
|
|
|
|
|
2006-04-27 23:22:04 +00:00
|
|
|
REL_VERT_COUNT= REL_TVERT_COUNT=0
|
2006-03-31 13:07:27 +00:00
|
|
|
|
2006-02-04 03:44:21 +00:00
|
|
|
while lIdx < len(fileLines):
|
2006-03-29 18:25:42 +00:00
|
|
|
l= fileLines[lIdx]
|
2006-02-04 03:44:21 +00:00
|
|
|
#for l in fileLines:
|
2006-01-29 19:17:53 +00:00
|
|
|
if len(l) == 0:
|
|
|
|
continue
|
2005-10-11 02:32:58 +00:00
|
|
|
# FACE
|
2006-03-31 13:07:27 +00:00
|
|
|
elif l[0] == 'v':
|
2006-04-27 23:22:04 +00:00
|
|
|
REL_VERT_COUNT+=1
|
2006-03-31 13:07:27 +00:00
|
|
|
elif l[0] == 'vt':
|
2006-04-27 23:22:04 +00:00
|
|
|
REL_TVERT_COUNT+=1
|
2006-03-31 13:07:27 +00:00
|
|
|
|
2006-04-27 23:22:04 +00:00
|
|
|
elif l[0] == 'f' or l[0] == 'fo': # fo is not standard. saw it used once.
|
2005-10-11 02:32:58 +00:00
|
|
|
# Make a face with the correct material.
|
|
|
|
# Add material to mesh
|
2006-05-09 13:20:18 +00:00
|
|
|
if IMPORT_MTL:
|
|
|
|
if contextMeshMatIdx == -1:
|
|
|
|
tmpMatLs= currentMesh.materials
|
|
|
|
if len(tmpMatLs) == 16:
|
|
|
|
contextMeshMatIdx= 0 # Use first material
|
|
|
|
print 'material overflow, attempting to use > 16 materials. defaulting to first.'
|
|
|
|
else:
|
|
|
|
contextMeshMatIdx= len(tmpMatLs)
|
|
|
|
currentMaterialMeshMapping[currentMat.name]= contextMeshMatIdx
|
|
|
|
currentMesh.addMaterial(currentMat)
|
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
# Set up vIdxLs : Verts
|
|
|
|
# Set up vtIdxLs : UV
|
|
|
|
# Start with a dummy objects so python accepts OBJs 1 is the first index.
|
2006-03-29 18:25:42 +00:00
|
|
|
vIdxLs= []
|
|
|
|
vtIdxLs= []
|
2005-10-11 02:32:58 +00:00
|
|
|
|
2006-03-29 18:25:42 +00:00
|
|
|
fHasUV= len_uvMapList # Assume the face has a UV until it sho it dosent, if there are no UV coords then this will start as 0.
|
2006-02-04 03:44:21 +00:00
|
|
|
|
|
|
|
# Support stupid multiline faces
|
|
|
|
# not an obj spec but some objs exist that do this.
|
|
|
|
# f 1 2 3 \
|
|
|
|
# 4 5 6 \
|
|
|
|
# ..... instead of the more common and sane.
|
|
|
|
# f 1 2 3 4 5 6
|
|
|
|
#
|
|
|
|
# later lines are not modified, just skepped by advancing "lIdx"
|
|
|
|
while l[-1] == '\\':
|
|
|
|
l.pop()
|
|
|
|
lIdx+=1
|
|
|
|
l.extend(fileLines[lIdx])
|
|
|
|
# Done supporting crappy obj faces over multiple lines.
|
|
|
|
|
2006-05-09 13:20:18 +00:00
|
|
|
|
2006-02-04 03:44:21 +00:00
|
|
|
for v in l:
|
2006-05-09 13:20:18 +00:00
|
|
|
if not v.startswith('f'): # Only the first v will be f, any better ways to skip it?
|
2006-02-04 03:44:21 +00:00
|
|
|
# OBJ files can have // or / to seperate vert/texVert/normal
|
|
|
|
# this is a bit of a pain but we must deal with it.
|
2006-03-29 18:25:42 +00:00
|
|
|
objVert= v.split('/')
|
2006-02-04 03:44:21 +00:00
|
|
|
|
|
|
|
# Vert Index - OBJ supports negative index assignment (like python)
|
2006-03-29 18:25:42 +00:00
|
|
|
index= int(objVert[0])-1
|
2006-05-09 13:20:18 +00:00
|
|
|
|
2006-04-10 21:42:18 +00:00
|
|
|
# Account for negative indices.
|
2006-02-04 03:44:21 +00:00
|
|
|
if index < 0:
|
2006-04-27 23:22:04 +00:00
|
|
|
# Assume negative verts are relative.
|
|
|
|
index= REL_VERT_COUNT+index+1
|
2006-02-04 03:44:21 +00:00
|
|
|
|
|
|
|
vIdxLs.append(index)
|
|
|
|
if fHasUV:
|
|
|
|
# UV
|
2006-03-29 18:25:42 +00:00
|
|
|
index= 0 # Dummy var
|
2006-02-04 03:44:21 +00:00
|
|
|
if len(objVert) == 1:
|
2006-03-29 18:25:42 +00:00
|
|
|
index= vIdxLs[-1]
|
2006-02-04 03:44:21 +00:00
|
|
|
elif objVert[1]: # != '' # Its possible that theres no texture vert just he vert and normal eg 1//2
|
2006-03-29 18:25:42 +00:00
|
|
|
index= int(objVert[1])-1
|
2006-02-04 03:44:21 +00:00
|
|
|
if index < 0:
|
2006-04-27 23:22:04 +00:00
|
|
|
# Assume negative verts are relative
|
|
|
|
index= REL_TVERT_COUNT+index+1
|
2006-02-04 03:44:21 +00:00
|
|
|
|
|
|
|
if len_uvMapList > index:
|
|
|
|
vtIdxLs.append(index) # Seperate UV coords
|
|
|
|
else:
|
|
|
|
# BAD FILE, I have found this so I account for it.
|
|
|
|
# INVALID UV COORD
|
|
|
|
# Could ignore this- only happens with 1 in 1000 files.
|
|
|
|
badObjFaceTexCo +=1
|
|
|
|
vtIdxLs.append(1)
|
2005-10-11 02:32:58 +00:00
|
|
|
|
2006-03-29 18:25:42 +00:00
|
|
|
fHasUV= 0
|
2006-02-04 03:44:21 +00:00
|
|
|
|
|
|
|
# Dont add a UV to the face if its larger then the UV coord list
|
|
|
|
# The OBJ file would have to be corrupt or badly written for thi to happen
|
|
|
|
# but account for it anyway.
|
|
|
|
if len(vtIdxLs) > 0:
|
|
|
|
if vtIdxLs[-1] > len_uvMapList:
|
2006-03-29 18:25:42 +00:00
|
|
|
fHasUV= 0
|
2006-02-04 03:44:21 +00:00
|
|
|
|
|
|
|
badObjUvs +=1 # ERROR, Cont
|
2006-03-29 18:25:42 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
# Quads only, we could import quads using the method below but it polite to import a quad as a quad.
|
2006-01-29 19:17:53 +00:00
|
|
|
#print lIdx, len(vIdxLs), len(currentUsedVertListSmoothGroup)
|
|
|
|
#print fileLines[lIdx]
|
2006-03-29 18:25:42 +00:00
|
|
|
|
|
|
|
# Add all the verts we need,
|
|
|
|
# dont edd edge verts if were not importing them.
|
|
|
|
face_vert_count= len(vIdxLs)
|
|
|
|
if (not IMPORT_EDGES) and face_vert_count == 2:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
# Add the verts that arnt alredy added.
|
|
|
|
for i in vIdxLs:
|
|
|
|
if currentUsedVertListSmoothGroup[i] == -1:
|
|
|
|
v= vertList[i]
|
|
|
|
currentMesh.verts.append(v)
|
|
|
|
currentUsedVertListSmoothGroup[i]= len(currentMesh.verts)-1
|
|
|
|
|
|
|
|
if face_vert_count == 2:
|
|
|
|
if IMPORT_EDGES and vIdxLs[0]!=vIdxLs[1]:
|
2006-01-29 19:17:53 +00:00
|
|
|
# Edge
|
2006-03-29 18:25:42 +00:00
|
|
|
currentMesh.addEdge(\
|
|
|
|
currentMesh.verts[currentUsedVertListSmoothGroup[vIdxLs[0]]],\
|
|
|
|
currentMesh.verts[currentUsedVertListSmoothGroup[vIdxLs[0]]])
|
|
|
|
|
|
|
|
elif face_vert_count == 4:
|
2004-09-21 09:09:58 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
# Have found some files where wach face references the same vert
|
|
|
|
# - This causes a bug and stopts the import so lets check here
|
|
|
|
if vIdxLs[0] == vIdxLs[1] or\
|
|
|
|
vIdxLs[0] == vIdxLs[2] or\
|
|
|
|
vIdxLs[0] == vIdxLs[3] or\
|
|
|
|
vIdxLs[1] == vIdxLs[2] or\
|
|
|
|
vIdxLs[1] == vIdxLs[3] or\
|
|
|
|
vIdxLs[2] == vIdxLs[3]:
|
|
|
|
badObjFaceVerts+=1
|
|
|
|
else:
|
2005-06-12 05:54:15 +00:00
|
|
|
for i in quadList: # quadList == [0,1,2,3]
|
2006-03-29 18:25:42 +00:00
|
|
|
faceQuadVList[i]= currentMesh.verts[currentUsedVertListSmoothGroup[vIdxLs[i]]]
|
BPython bug fixes:
- #2646 reported by Campbell: Python/Fileselector (moving from fileselector called by script to another space caused script to hang around open but not accessible)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2646&group_id=9
- #2676 reported by Wim Van Hoydonck: 2.37 python scripts gui: event 8 ignored (thanks Ton for discussing / pointing what to do, Ken Hughes for also working on a fix)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2676&group_id=9
- gui-less scripts with calls to progress bar inside fileselector callbacks didn't return to the previous space on exit (staying on Scripts win), requiring an event to do so (mouse movement, for example). Quick fix for now, will rework a little after 2.37a for a better alternative, not needing to move to the Scripts win at all.
- added syntax colors access to Window.Theme module.
Scripts:
- updates by Jean-Michel Soler: svg2obj (svg paths import), tex2uvbaker, fixfromarmature;
- updates by Campbell Barton: obj import / export, console;
- tiny: converted vrml97 export to unix line endings;
- updates in ac3d exporter, help browser, save theme.
Thanks all mentioned above.
2005-06-11 05:30:14 +00:00
|
|
|
|
2006-03-29 18:25:42 +00:00
|
|
|
f= NMesh.Face(faceQuadVList)
|
2004-09-18 21:04:23 +00:00
|
|
|
# UV MAPPING
|
|
|
|
if fHasUV:
|
2006-03-29 18:25:42 +00:00
|
|
|
f.uv= [uvMapList[ vtIdxLs[0] ],uvMapList[ vtIdxLs[1] ],uvMapList[ vtIdxLs[2] ],uvMapList[ vtIdxLs[3] ]]
|
2005-06-12 05:54:15 +00:00
|
|
|
if currentImg:
|
2006-03-29 18:25:42 +00:00
|
|
|
f.image= currentImg
|
BPython bug fixes:
- #2646 reported by Campbell: Python/Fileselector (moving from fileselector called by script to another space caused script to hang around open but not accessible)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2646&group_id=9
- #2676 reported by Wim Van Hoydonck: 2.37 python scripts gui: event 8 ignored (thanks Ton for discussing / pointing what to do, Ken Hughes for also working on a fix)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2676&group_id=9
- gui-less scripts with calls to progress bar inside fileselector callbacks didn't return to the previous space on exit (staying on Scripts win), requiring an event to do so (mouse movement, for example). Quick fix for now, will rework a little after 2.37a for a better alternative, not needing to move to the Scripts win at all.
- added syntax colors access to Window.Theme module.
Scripts:
- updates by Jean-Michel Soler: svg2obj (svg paths import), tex2uvbaker, fixfromarmature;
- updates by Campbell Barton: obj import / export, console;
- tiny: converted vrml97 export to unix line endings;
- updates in ac3d exporter, help browser, save theme.
Thanks all mentioned above.
2005-06-11 05:30:14 +00:00
|
|
|
else:
|
2005-06-12 05:54:15 +00:00
|
|
|
f.mode &= TEX_OFF_FLAG
|
2006-05-09 13:20:18 +00:00
|
|
|
if IMPORT_MTL:
|
|
|
|
f.mat= contextMeshMatIdx
|
2006-03-29 18:25:42 +00:00
|
|
|
f.smooth= currentSmooth
|
2005-06-12 05:54:15 +00:00
|
|
|
currentMesh.faces.append(f) # move the face onto the mesh
|
2005-10-11 02:32:58 +00:00
|
|
|
|
2006-03-29 18:25:42 +00:00
|
|
|
elif face_vert_count == 3: # This handles tri's and fans, dont use fans anymore.
|
|
|
|
for i in range(face_vert_count-2):
|
2005-10-11 02:32:58 +00:00
|
|
|
if vIdxLs[0] == vIdxLs[i+1] or\
|
|
|
|
vIdxLs[0] == vIdxLs[i+2] or\
|
|
|
|
vIdxLs[i+1] == vIdxLs[i+2]:
|
|
|
|
badObjFaceVerts+=1
|
|
|
|
else:
|
|
|
|
for k, j in [(0,0), (1,i+1), (2,i+2)]:
|
2006-03-29 18:25:42 +00:00
|
|
|
faceTriVList[k]= currentMesh.verts[currentUsedVertListSmoothGroup[vIdxLs[j]]]
|
2005-06-12 05:54:15 +00:00
|
|
|
|
2006-03-29 18:25:42 +00:00
|
|
|
f= NMesh.Face(faceTriVList)
|
2005-06-12 05:54:15 +00:00
|
|
|
|
|
|
|
# UV MAPPING
|
|
|
|
if fHasUV:
|
2006-03-29 18:25:42 +00:00
|
|
|
f.uv= [uvMapList[vtIdxLs[0]], uvMapList[vtIdxLs[i+1]], uvMapList[vtIdxLs[i+2]]]
|
2005-06-12 05:54:15 +00:00
|
|
|
if currentImg:
|
2006-03-29 18:25:42 +00:00
|
|
|
f.image= currentImg
|
2005-06-12 05:54:15 +00:00
|
|
|
else:
|
|
|
|
f.mode &= TEX_OFF_FLAG
|
2006-05-09 13:20:18 +00:00
|
|
|
if IMPORT_MTL:
|
|
|
|
f.mat= contextMeshMatIdx
|
2006-03-29 18:25:42 +00:00
|
|
|
f.smooth= currentSmooth
|
BPython bug fixes:
- #2646 reported by Campbell: Python/Fileselector (moving from fileselector called by script to another space caused script to hang around open but not accessible)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2646&group_id=9
- #2676 reported by Wim Van Hoydonck: 2.37 python scripts gui: event 8 ignored (thanks Ton for discussing / pointing what to do, Ken Hughes for also working on a fix)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2676&group_id=9
- gui-less scripts with calls to progress bar inside fileselector callbacks didn't return to the previous space on exit (staying on Scripts win), requiring an event to do so (mouse movement, for example). Quick fix for now, will rework a little after 2.37a for a better alternative, not needing to move to the Scripts win at all.
- added syntax colors access to Window.Theme module.
Scripts:
- updates by Jean-Michel Soler: svg2obj (svg paths import), tex2uvbaker, fixfromarmature;
- updates by Campbell Barton: obj import / export, console;
- tiny: converted vrml97 export to unix line endings;
- updates in ac3d exporter, help browser, save theme.
Thanks all mentioned above.
2005-06-11 05:30:14 +00:00
|
|
|
currentMesh.faces.append(f) # move the face onto the mesh
|
2006-03-29 18:25:42 +00:00
|
|
|
|
|
|
|
elif face_vert_count > 4: # NGons.
|
2006-04-10 21:42:18 +00:00
|
|
|
# we need to map indices to uv coords.
|
2006-03-29 18:25:42 +00:00
|
|
|
currentMeshRelativeIdxs= [currentUsedVertListSmoothGroup[i] for i in vIdxLs]
|
|
|
|
|
|
|
|
if fHasUV:
|
|
|
|
vert2UvMapping=dict( [ (currentMeshRelativeIdxs[i],vtIdxLs[i]) for i in xrange(face_vert_count)] )
|
|
|
|
|
2006-04-10 21:42:18 +00:00
|
|
|
ngon_face_indices= BPyMesh.ngon(currentMesh, currentMeshRelativeIdxs)
|
|
|
|
|
2006-03-29 18:25:42 +00:00
|
|
|
|
|
|
|
# At the moment scanfill always makes tri's but dont count on it
|
2006-04-10 21:42:18 +00:00
|
|
|
for fillFace in ngon_face_indices:
|
2006-03-29 18:25:42 +00:00
|
|
|
f= NMesh.Face([currentMesh.verts[currentMeshRelativeIdxs[i]] for i in fillFace])
|
|
|
|
|
|
|
|
if fHasUV:
|
|
|
|
f.uv= [uvMapList[vert2UvMapping[currentMeshRelativeIdxs[i]]] for i in fillFace]
|
|
|
|
if currentImg:
|
|
|
|
f.image= currentImg
|
|
|
|
else:
|
|
|
|
f.mode &= TEX_OFF_FLAG
|
2006-05-09 13:20:18 +00:00
|
|
|
if IMPORT_MTL:
|
|
|
|
f.mat= contextMeshMatIdx
|
2006-03-29 18:25:42 +00:00
|
|
|
f.smooth= currentSmooth
|
|
|
|
currentMesh.faces.append(f) # move the face onto the mesh
|
|
|
|
|
|
|
|
# Set fgon flag.
|
|
|
|
if IMPORT_FGON:
|
|
|
|
edgeUsers={}
|
2006-04-10 21:42:18 +00:00
|
|
|
for fillFace in ngon_face_indices:
|
2006-03-29 18:25:42 +00:00
|
|
|
for i in xrange(len(fillFace)): # Should always be 3
|
|
|
|
i1= currentMeshRelativeIdxs[fillFace[i]]
|
|
|
|
i2= currentMeshRelativeIdxs[fillFace[i-1]]
|
|
|
|
|
|
|
|
# Sort the pair so thet always match.
|
|
|
|
if i1>i2: i1,i2=i2,i1
|
|
|
|
|
|
|
|
try:
|
|
|
|
edgeUsers[i1,i2]+= 1
|
|
|
|
except:
|
|
|
|
edgeUsers[i1,i2]= 0
|
|
|
|
|
|
|
|
for edgeVerts, users in edgeUsers.iteritems():
|
|
|
|
if users:
|
|
|
|
ed= currentMesh.addEdge(\
|
|
|
|
currentMesh.verts[edgeVerts[0]],\
|
|
|
|
currentMesh.verts[edgeVerts[1]])
|
|
|
|
|
|
|
|
ed.flag|= EDGE_FGON_FLAG
|
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
# FACE SMOOTHING
|
2006-03-29 18:25:42 +00:00
|
|
|
elif l[0] == 's' and IMPORT_SMOOTH_GROUPS:
|
2005-10-11 02:32:58 +00:00
|
|
|
# No value? then turn on.
|
|
|
|
if len(l) == 1:
|
2006-03-29 18:25:42 +00:00
|
|
|
currentSmooth= True
|
|
|
|
currentSmoothGroup= '(null)'
|
2005-10-11 02:32:58 +00:00
|
|
|
else:
|
2006-01-29 19:17:53 +00:00
|
|
|
if l[1] == 'off': # We all have a null group so dont need to try, will try anyway to avoid code duplication.
|
|
|
|
if not IMPORT_SMOOTH_ALL:
|
2006-03-29 18:25:42 +00:00
|
|
|
currentSmooth= False
|
|
|
|
currentSmoothGroup= '(null)'
|
2005-10-11 02:32:58 +00:00
|
|
|
else:
|
2006-03-29 18:25:42 +00:00
|
|
|
currentSmooth= True
|
|
|
|
currentSmoothGroup= '_'.join(l[1:])
|
2006-01-29 19:17:53 +00:00
|
|
|
try:
|
2006-03-29 18:25:42 +00:00
|
|
|
currentUsedVertListSmoothGroup= currentUsedVertList[currentSmoothGroup]
|
2006-01-29 19:17:53 +00:00
|
|
|
except KeyError:
|
2006-03-29 18:25:42 +00:00
|
|
|
currentUsedVertList[currentSmoothGroup]= currentUsedVertListSmoothGroup= VERT_USED_LIST[:]
|
2006-01-29 19:17:53 +00:00
|
|
|
|
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
# OBJECT / GROUP
|
|
|
|
elif l[0] == 'o' or l[0] == 'g':
|
|
|
|
|
|
|
|
# Forget about the current image
|
2006-03-29 18:25:42 +00:00
|
|
|
currentImg= None
|
2005-10-11 02:32:58 +00:00
|
|
|
|
|
|
|
# This makes sure that if an object and a group have the same name then
|
|
|
|
# they are not put into the same object.
|
|
|
|
|
|
|
|
# Only make a new group.object name if the verts in the existing object have been used, this is obscure
|
|
|
|
# but some files face groups seperating verts and faces which results in silly things. (no groups have names.)
|
2006-03-29 18:25:42 +00:00
|
|
|
if len(l) == 1:
|
2005-10-11 02:32:58 +00:00
|
|
|
# Make a new empty name
|
|
|
|
if l[0] == 'g': # Make a blank group name
|
2006-03-29 18:25:42 +00:00
|
|
|
currentObjectName= 'unnamed_grp_%.4d' % currentUnnamedGroupIdx
|
2005-10-11 02:32:58 +00:00
|
|
|
currentUnnamedGroupIdx +=1
|
|
|
|
else: # is an object.
|
2006-03-29 18:25:42 +00:00
|
|
|
currentObjectName= 'unnamed_ob_%.4d' % currentUnnamedObjectIdx
|
2005-10-11 02:32:58 +00:00
|
|
|
currentUnnamedObjectIdx +=1
|
2006-03-29 18:25:42 +00:00
|
|
|
may_exist= False # we know the model is new.
|
|
|
|
else: # No name given
|
|
|
|
currentObjectName= '_'.join(l[1:])
|
|
|
|
may_exist= True
|
2005-10-11 02:32:58 +00:00
|
|
|
|
2006-03-29 18:25:42 +00:00
|
|
|
if IMPORT_MTL_SPLIT:
|
|
|
|
currentObjectName_real= currentObjectName
|
|
|
|
currentObjectName += '_'+currentMat.name
|
2005-10-11 02:32:58 +00:00
|
|
|
|
2006-03-29 18:25:42 +00:00
|
|
|
obj_getmesh(may_exist)
|
2006-01-29 19:17:53 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
|
|
|
|
# MATERIAL
|
2006-05-09 13:20:18 +00:00
|
|
|
elif l[0] == 'usemtl' and IMPORT_MTL:
|
2005-10-11 02:32:58 +00:00
|
|
|
if len(l) == 1 or l[1] == '(null)':
|
2006-03-29 18:25:42 +00:00
|
|
|
currentMat= nullMat # We know we have a null mat.
|
2005-10-11 02:32:58 +00:00
|
|
|
else:
|
2006-05-09 13:20:18 +00:00
|
|
|
currentMat= getMat('_'.join(l[1:]), materialDict)
|
2005-10-11 02:32:58 +00:00
|
|
|
try:
|
2006-03-29 18:25:42 +00:00
|
|
|
contextMeshMatIdx= currentMaterialMeshMapping[currentMat.name]
|
2005-10-11 02:32:58 +00:00
|
|
|
except KeyError:
|
2006-03-29 18:25:42 +00:00
|
|
|
contextMeshMatIdx= -1 #getMeshMaterialIndex(currentMesh, currentMat)
|
|
|
|
|
|
|
|
# Check if we are splitting by material.
|
|
|
|
if IMPORT_MTL_SPLIT:
|
2006-04-27 23:22:04 +00:00
|
|
|
currentObjectName= '%s_%s' % (currentObjectName_real, currentMat.name)
|
2006-03-29 18:25:42 +00:00
|
|
|
obj_getmesh(True)
|
|
|
|
|
BPython bug fixes:
- #2646 reported by Campbell: Python/Fileselector (moving from fileselector called by script to another space caused script to hang around open but not accessible)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2646&group_id=9
- #2676 reported by Wim Van Hoydonck: 2.37 python scripts gui: event 8 ignored (thanks Ton for discussing / pointing what to do, Ken Hughes for also working on a fix)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2676&group_id=9
- gui-less scripts with calls to progress bar inside fileselector callbacks didn't return to the previous space on exit (staying on Scripts win), requiring an event to do so (mouse movement, for example). Quick fix for now, will rework a little after 2.37a for a better alternative, not needing to move to the Scripts win at all.
- added syntax colors access to Window.Theme module.
Scripts:
- updates by Jean-Michel Soler: svg2obj (svg paths import), tex2uvbaker, fixfromarmature;
- updates by Campbell Barton: obj import / export, console;
- tiny: converted vrml97 export to unix line endings;
- updates in ac3d exporter, help browser, save theme.
Thanks all mentioned above.
2005-06-11 05:30:14 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
# IMAGE
|
|
|
|
elif l[0] == 'usemat' or l[0] == 'usemap':
|
|
|
|
if len(l) == 1 or l[1] == '(null)' or l[1] == 'off':
|
2006-03-29 18:25:42 +00:00
|
|
|
currentImg= None
|
2005-10-11 02:32:58 +00:00
|
|
|
else:
|
|
|
|
# Load an image.
|
2006-03-29 18:25:42 +00:00
|
|
|
newImgName= stripPath(' '.join(l[1:])) # Use space since its a file name.
|
BPython bug fixes:
- #2646 reported by Campbell: Python/Fileselector (moving from fileselector called by script to another space caused script to hang around open but not accessible)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2646&group_id=9
- #2676 reported by Wim Van Hoydonck: 2.37 python scripts gui: event 8 ignored (thanks Ton for discussing / pointing what to do, Ken Hughes for also working on a fix)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2676&group_id=9
- gui-less scripts with calls to progress bar inside fileselector callbacks didn't return to the previous space on exit (staying on Scripts win), requiring an event to do so (mouse movement, for example). Quick fix for now, will rework a little after 2.37a for a better alternative, not needing to move to the Scripts win at all.
- added syntax colors access to Window.Theme module.
Scripts:
- updates by Jean-Michel Soler: svg2obj (svg paths import), tex2uvbaker, fixfromarmature;
- updates by Campbell Barton: obj import / export, console;
- tiny: converted vrml97 export to unix line endings;
- updates in ac3d exporter, help browser, save theme.
Thanks all mentioned above.
2005-06-11 05:30:14 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
try:
|
|
|
|
# Assume its alredy set in the dict (may or maynot be loaded)
|
2006-03-29 18:25:42 +00:00
|
|
|
currentImg= imageDict[newImgName]
|
2005-10-11 02:32:58 +00:00
|
|
|
|
|
|
|
except KeyError: # Not in dict, add for first time.
|
|
|
|
# Image has not been added, Try and load the image
|
2006-03-29 18:25:42 +00:00
|
|
|
currentImg= BPyImage.comprehensiveImageLoad(newImgName, DIR) # Use join in case of spaces
|
|
|
|
imageDict[newImgName]= currentImg
|
2005-10-11 02:32:58 +00:00
|
|
|
# These may be None, thats okay.
|
2004-09-21 09:09:58 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
# MATERIAL FILE
|
2006-03-29 18:25:42 +00:00
|
|
|
elif l[0] == 'mtllib' and IMPORT_MTL and len(l)>1:
|
|
|
|
mtl_fileName.append(' '.join(l[1:]) ) # Support for multiple MTL's
|
2006-02-04 03:44:21 +00:00
|
|
|
lIdx+=1
|
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
# Applies material properties to materials alredy on the mesh as well as Textures.
|
2006-01-29 19:17:53 +00:00
|
|
|
if IMPORT_MTL:
|
|
|
|
for mtl in mtl_fileName:
|
2006-05-09 13:20:18 +00:00
|
|
|
load_mtl(DIR, IMPORT_USE_EXISTING_MTL, mtl, meshDict, materialDict)
|
|
|
|
|
|
|
|
# Get a new scale factor if set as an option
|
|
|
|
SCALE=1.0
|
|
|
|
if IMPORT_CONSTRAIN_BOUNDS != 0.0:
|
|
|
|
while (BOUNDS*SCALE) > IMPORT_CONSTRAIN_BOUNDS:
|
|
|
|
SCALE/=10
|
2005-10-11 02:32:58 +00:00
|
|
|
|
2006-03-29 18:25:42 +00:00
|
|
|
importedObjects= []
|
2006-06-03 07:46:56 +00:00
|
|
|
|
|
|
|
scn= Scene.GetCurrent()
|
|
|
|
|
|
|
|
# DeSelect all
|
|
|
|
for ob in scn.getChildren():
|
|
|
|
ob.sel=0
|
|
|
|
|
|
|
|
# Create objects for each mesh.
|
2005-10-11 02:32:58 +00:00
|
|
|
for mk, me in meshDict.iteritems():
|
2006-03-29 18:25:42 +00:00
|
|
|
nme= me[0]
|
2005-05-30 02:26:40 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
# Ignore no vert meshes.
|
|
|
|
if not nme.verts: # == []
|
|
|
|
continue
|
2006-05-09 13:20:18 +00:00
|
|
|
|
2006-06-03 07:46:56 +00:00
|
|
|
ob= Object.New('Mesh', fileName)
|
|
|
|
nme.name= mk
|
|
|
|
ob.link(nme)
|
2006-05-09 13:20:18 +00:00
|
|
|
ob.setSize(SCALE, SCALE, SCALE)
|
2006-06-03 07:46:56 +00:00
|
|
|
importedObjects.append(ob)
|
|
|
|
|
|
|
|
Layers= scn.Layers
|
|
|
|
if IMPORT_AS_INSTANCE:
|
|
|
|
# Create a group for this import.
|
|
|
|
group_scn= Scene.New(fileName)
|
|
|
|
for ob in importedObjects:
|
|
|
|
group_scn.link(ob) # dont worry about the layers
|
|
|
|
|
|
|
|
grp= Group.New(fileName)
|
|
|
|
grp.objects= importedObjects
|
2006-05-09 13:20:18 +00:00
|
|
|
|
2006-06-03 07:46:56 +00:00
|
|
|
grp_ob= Object.New('Empty', fileName)
|
|
|
|
grp_ob.enableDupGroup= True
|
|
|
|
grp_ob.DupGroup= grp
|
|
|
|
scn.link(grp_ob)
|
|
|
|
grp_ob.Layers= Layers
|
|
|
|
grp_ob.sel= 1
|
|
|
|
|
|
|
|
else:
|
|
|
|
# Select all imported objects.
|
|
|
|
for ob in importedObjects:
|
|
|
|
scn.link(ob)
|
|
|
|
ob.Layers= Layers
|
|
|
|
ob.sel= 1
|
|
|
|
|
2005-05-30 02:26:40 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
if badObjUvs > 0:
|
|
|
|
print '\tERROR: found %d faces with badly formatted UV coords. everything else went okay.' % badObjUvs
|
2005-06-12 05:54:15 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
if badObjFaceVerts > 0:
|
|
|
|
print '\tERROR: found %d faces reusing the same vertex. everything else went okay.' % badObjFaceVerts
|
|
|
|
|
|
|
|
if badObjFaceTexCo > 0:
|
|
|
|
print '\tERROR: found %d faces with invalit texture coords. everything else went okay.' % badObjFaceTexCo
|
|
|
|
|
|
|
|
|
|
|
|
print "obj import time: ", sys.time() - time1
|
2006-01-29 19:17:53 +00:00
|
|
|
|
|
|
|
def load_obj_ui(file):
|
2005-10-11 02:32:58 +00:00
|
|
|
|
2006-03-29 18:25:42 +00:00
|
|
|
IMPORT_DIR= Draw.Create(0)
|
|
|
|
IMPORT_NEW_SCENE= Draw.Create(0)
|
2006-05-09 13:20:18 +00:00
|
|
|
IMPORT_MTL= Draw.Create(1)
|
|
|
|
IMPORT_USE_EXISTING_MTL= Draw.Create(1)
|
|
|
|
|
|
|
|
IMPORT_CONSTRAIN_BOUNDS= Draw.Create(10.0)
|
|
|
|
IMPORT_ROTATE_X90= Draw.Create(1)
|
2006-03-29 18:25:42 +00:00
|
|
|
IMPORT_EDGES= Draw.Create(1)
|
|
|
|
IMPORT_SMOOTH_ALL= Draw.Create(1)
|
|
|
|
IMPORT_FGON= Draw.Create(1)
|
|
|
|
IMPORT_SMOOTH_GROUPS= Draw.Create(0)
|
|
|
|
IMPORT_MTL_SPLIT= Draw.Create(0)
|
2006-06-03 07:46:56 +00:00
|
|
|
IMPORT_AS_INSTANCE= Draw.Create(0)
|
2005-10-11 02:32:58 +00:00
|
|
|
|
2006-01-29 19:17:53 +00:00
|
|
|
# Get USER Options
|
2006-03-29 18:25:42 +00:00
|
|
|
pup_block= [\
|
2006-01-29 19:17:53 +00:00
|
|
|
('All *.obj\'s in dir', IMPORT_DIR, 'Import all obj files in this dir (avoid overlapping data with "Create scene")'),\
|
2006-05-09 13:20:18 +00:00
|
|
|
('Create Scene', IMPORT_NEW_SCENE, 'Imports each obj into its own scene, named from the file'),\
|
2006-06-03 07:46:56 +00:00
|
|
|
('Group Instance', IMPORT_AS_INSTANCE, 'Import objects into a new scene and group, creating an instance in the current scene.'),\
|
2006-05-09 13:20:18 +00:00
|
|
|
'Materials...',\
|
|
|
|
('Import (*.mtl)', IMPORT_MTL, 'Imports material settings and images from the obj\'s .mtl file'),\
|
|
|
|
('Re-Use Existing', IMPORT_USE_EXISTING_MTL, 'Use materials from the current blend where names match.'),\
|
2006-01-29 19:17:53 +00:00
|
|
|
'Geometry...',\
|
2006-05-09 13:20:18 +00:00
|
|
|
('Size Constraint:', IMPORT_CONSTRAIN_BOUNDS, 0.0, 1000.0, 'Scale the model by factors of 10 until it reacehs the size constraint.'),\
|
|
|
|
('Rotate X90', IMPORT_ROTATE_X90, 'Rotate X-Up to Blenders Z-Up'),\
|
2006-01-29 19:17:53 +00:00
|
|
|
('Edges', IMPORT_EDGES, 'Import faces with 2 verts as in edge'),\
|
|
|
|
('Smooths all faces', IMPORT_SMOOTH_ALL, 'Smooth all faces even if they are not in a smoothing group'),\
|
2006-03-29 18:25:42 +00:00
|
|
|
('Create FGons', IMPORT_FGON, 'Import faces with more then 4 verts as fgons.'),\
|
|
|
|
('Smooth Groups', IMPORT_SMOOTH_GROUPS, 'Only Share verts within smooth groups. (Warning, Hogs Memory)'),\
|
|
|
|
('Split by Material', IMPORT_MTL_SPLIT, 'Import each material into a seperate mesh (Avoids >16 meterials per mesh problem)'),\
|
2006-01-29 19:17:53 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
if not os:
|
2006-05-09 13:20:18 +00:00
|
|
|
pup_block.pop(0) # Make sure this is the IMPORT_DIR option that requires OS
|
2005-10-11 02:32:58 +00:00
|
|
|
|
2006-04-27 23:22:04 +00:00
|
|
|
if not Draw.PupBlock('Import OBJ...', pup_block):
|
2006-01-29 19:17:53 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
Window.WaitCursor(1)
|
2005-10-11 02:32:58 +00:00
|
|
|
Window.DrawProgressBar(0, '')
|
2006-03-29 18:25:42 +00:00
|
|
|
time= sys.time()
|
2006-01-29 19:17:53 +00:00
|
|
|
|
2006-03-29 18:25:42 +00:00
|
|
|
IMPORT_DIR= IMPORT_DIR.val
|
|
|
|
IMPORT_NEW_SCENE= IMPORT_NEW_SCENE.val
|
2006-05-09 13:20:18 +00:00
|
|
|
IMPORT_MTL= IMPORT_MTL.val
|
|
|
|
IMPORT_USE_EXISTING_MTL= IMPORT_USE_EXISTING_MTL.val
|
|
|
|
|
|
|
|
IMPORT_CONSTRAIN_BOUNDS= IMPORT_CONSTRAIN_BOUNDS.val
|
|
|
|
IMPORT_ROTATE_X90= IMPORT_ROTATE_X90.val
|
2006-03-29 18:25:42 +00:00
|
|
|
IMPORT_EDGES= IMPORT_EDGES.val
|
|
|
|
IMPORT_SMOOTH_ALL= IMPORT_SMOOTH_ALL.val
|
|
|
|
IMPORT_FGON= IMPORT_FGON.val
|
|
|
|
IMPORT_SMOOTH_GROUPS= IMPORT_SMOOTH_GROUPS.val
|
|
|
|
IMPORT_MTL_SPLIT= IMPORT_MTL_SPLIT.val
|
2006-06-03 07:46:56 +00:00
|
|
|
IMPORT_AS_INSTANCE= IMPORT_AS_INSTANCE.val
|
2006-04-27 23:22:04 +00:00
|
|
|
orig_scene= Scene.GetCurrent()
|
2006-01-29 19:17:53 +00:00
|
|
|
|
2006-05-09 13:20:18 +00:00
|
|
|
# Dont do material split if we dont import material
|
|
|
|
if not IMPORT_MTL:
|
|
|
|
IMPORT_MTL_SPLIT=0
|
|
|
|
|
|
|
|
|
2006-03-29 18:25:42 +00:00
|
|
|
obj_dir= stripFile(file)
|
2006-01-29 19:17:53 +00:00
|
|
|
if IMPORT_DIR:
|
2006-03-29 18:25:42 +00:00
|
|
|
obj_files= [(obj_dir,f) for f in os.listdir(obj_dir) if f.lower().endswith('obj')]
|
2006-01-29 19:17:53 +00:00
|
|
|
else:
|
2006-03-29 18:25:42 +00:00
|
|
|
obj_files= [(obj_dir,stripPath(file))]
|
2006-01-29 19:17:53 +00:00
|
|
|
|
2006-03-29 18:25:42 +00:00
|
|
|
obj_len= len(obj_files)
|
|
|
|
count= 0
|
2006-01-29 19:17:53 +00:00
|
|
|
for d, f in obj_files:
|
|
|
|
count+= 1
|
|
|
|
if not sys.exists(d+f):
|
|
|
|
print 'Error: "%s%s" does not exist' % (d,f)
|
|
|
|
else:
|
|
|
|
if IMPORT_NEW_SCENE:
|
2006-03-29 18:25:42 +00:00
|
|
|
scn= Scene.New('.'.join(f.split('.')[0:-1]))
|
2006-01-29 19:17:53 +00:00
|
|
|
scn.makeCurrent()
|
|
|
|
|
|
|
|
Window.DrawProgressBar((float(count)/obj_len) - 0.01, '%s: %i of %i' % (f, count, obj_len))
|
2006-06-03 07:46:56 +00:00
|
|
|
load_obj(d+f, IMPORT_MTL, IMPORT_USE_EXISTING_MTL, IMPORT_CONSTRAIN_BOUNDS, IMPORT_ROTATE_X90, IMPORT_EDGES, IMPORT_SMOOTH_ALL, IMPORT_FGON, IMPORT_SMOOTH_GROUPS, IMPORT_MTL_SPLIT, IMPORT_AS_INSTANCE)
|
2006-01-29 19:17:53 +00:00
|
|
|
|
|
|
|
|
2006-04-27 23:22:04 +00:00
|
|
|
orig_scene.makeCurrent() # We can leave them in there new scene.
|
2005-10-11 02:32:58 +00:00
|
|
|
Window.DrawProgressBar(1, '')
|
2006-01-29 19:17:53 +00:00
|
|
|
Window.WaitCursor(0)
|
|
|
|
|
2006-04-27 23:22:04 +00:00
|
|
|
print 'Total obj import "%s" dir: %.2f' % (obj_dir, sys.time() - time)
|
2006-02-04 03:44:21 +00:00
|
|
|
|
2004-11-30 02:27:46 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
def main():
|
2006-04-27 23:22:04 +00:00
|
|
|
Window.FileSelector(load_obj_ui, 'Import a Wavefront OBJ', '*.obj')
|
BPython bug fixes:
- #2646 reported by Campbell: Python/Fileselector (moving from fileselector called by script to another space caused script to hang around open but not accessible)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2646&group_id=9
- #2676 reported by Wim Van Hoydonck: 2.37 python scripts gui: event 8 ignored (thanks Ton for discussing / pointing what to do, Ken Hughes for also working on a fix)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2676&group_id=9
- gui-less scripts with calls to progress bar inside fileselector callbacks didn't return to the previous space on exit (staying on Scripts win), requiring an event to do so (mouse movement, for example). Quick fix for now, will rework a little after 2.37a for a better alternative, not needing to move to the Scripts win at all.
- added syntax colors access to Window.Theme module.
Scripts:
- updates by Jean-Michel Soler: svg2obj (svg paths import), tex2uvbaker, fixfromarmature;
- updates by Campbell Barton: obj import / export, console;
- tiny: converted vrml97 export to unix line endings;
- updates in ac3d exporter, help browser, save theme.
Thanks all mentioned above.
2005-06-11 05:30:14 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
if __name__ == '__main__':
|
2006-04-27 23:22:04 +00:00
|
|
|
main()
|