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
|
|
|
|
2004-11-07 16:31:13 +00:00
|
|
|
__author__ = "Campbell Barton"
|
|
|
|
__url__ = ["blender", "elysiun"]
|
2005-06-12 05:54:15 +00:00
|
|
|
__version__ = "1.0"
|
2004-11-07 16:31:13 +00:00
|
|
|
|
|
|
|
__bpydoc__ = """\
|
|
|
|
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):
|
|
|
|
lastSlash = max(path.rfind('\\'), path.rfind('/'))
|
|
|
|
if lastSlash != -1:
|
|
|
|
path = path[:lastSlash]
|
|
|
|
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
|
2005-10-11 02:32:58 +00:00
|
|
|
index = name.rfind('.')
|
|
|
|
if index != -1:
|
|
|
|
return name[ : index ]
|
|
|
|
else:
|
|
|
|
return name
|
2004-06-14 20:51:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
from Blender import *
|
2005-06-12 05:54:15 +00:00
|
|
|
|
2004-06-21 12:01:23 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
|
|
|
|
# Adds a slash to the end of a path if its not there.
|
|
|
|
def addSlash(path):
|
|
|
|
if path.endswith('\\') or path.endswith('/'):
|
|
|
|
return path
|
|
|
|
return path + sys.sep
|
|
|
|
|
|
|
|
|
|
|
|
def getExt(name):
|
|
|
|
index = name.rfind('.')
|
|
|
|
if index != -1:
|
|
|
|
return name[index+1:]
|
|
|
|
return name
|
|
|
|
|
|
|
|
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.'
|
|
|
|
os = None
|
|
|
|
|
|
|
|
#===========================================================================#
|
|
|
|
# Comprehansive image loader, will search and find the image #
|
|
|
|
# Will return a blender image or none if the image is missing #
|
|
|
|
#===========================================================================#
|
|
|
|
def comprehansiveImageLoad(imagePath, filePath):
|
|
|
|
|
|
|
|
# When we have the file load it with this. try/except niceness.
|
|
|
|
def imageLoad(path):
|
|
|
|
try:
|
|
|
|
img = Image.Load(path)
|
|
|
|
print '\t\tImage loaded "%s"' % path
|
|
|
|
return img
|
|
|
|
except:
|
|
|
|
print '\t\tImage failed loading "%s", mabe its not a format blender can read.' % (path)
|
|
|
|
return None
|
|
|
|
|
|
|
|
# Image formats blender can read
|
|
|
|
IMAGE_EXT = ['jpg', 'jpeg', 'png', 'tga', 'bmp', 'rgb', 'sgi', 'bw', 'iff', 'lbm', # Blender Internal
|
|
|
|
'gif', 'psd', 'tif', 'tiff', 'pct', 'pict', 'pntg', 'qtif'] # Quacktime, worth a try.
|
|
|
|
|
2005-07-11 02:41:08 +00:00
|
|
|
|
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
|
|
|
|
print '\tAttempting to load "%s"' % imagePath
|
|
|
|
if sys.exists(imagePath):
|
|
|
|
print '\t\tFile found where expected.'
|
|
|
|
return imageLoad(imagePath)
|
|
|
|
|
|
|
|
imageFileName = stripPath(imagePath) # image path only
|
|
|
|
imageFileName_lower = imageFileName.lower() # image path only
|
|
|
|
imageFileName_noext = stripExt(imageFileName) # With no extension.
|
|
|
|
imageFileName_noext_lower = stripExt(imageFileName_lower) # With no extension.
|
|
|
|
imageFilePath = stripFile(imagePath)
|
|
|
|
|
|
|
|
# Remove relative path from image path
|
|
|
|
if imageFilePath.startswith('./') or imageFilePath.startswith('.\\'):
|
|
|
|
imageFilePath = imageFilePath[2:]
|
|
|
|
|
|
|
|
|
|
|
|
# Attempt to load from obj path.
|
|
|
|
tmpPath = stripFile(filePath) + stripFile(imageFilePath)
|
|
|
|
if sys.exists(tmpPath):
|
|
|
|
print '\t\tFile found in obj dir.'
|
|
|
|
return imageLoad(imagePath)
|
|
|
|
|
|
|
|
# OS NEEDED IF WE GO ANY FURTHER.
|
|
|
|
if not os:
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
# We have os.
|
|
|
|
# GATHER PATHS.
|
|
|
|
paths = {} # Store possible paths we may use, dict for no doubles.
|
|
|
|
tmpPath = addSlash(sys.expandpath('//')) # Blenders path
|
|
|
|
if sys.exists(tmpPath):
|
|
|
|
print '\t\tSearching in %s' % tmpPath
|
|
|
|
paths[tmpPath] = [os.listdir(tmpPath)] # Orig name for loading
|
|
|
|
paths[tmpPath].append([f.lower() for f in paths[tmpPath][0]]) # Lower case list.
|
|
|
|
paths[tmpPath].append([stripExt(f) for f in paths[tmpPath][1]]) # Lower case no ext
|
|
|
|
|
|
|
|
tmpPath = imageFilePath
|
|
|
|
if sys.exists(tmpPath):
|
|
|
|
print '\t\tSearching in %s' % tmpPath
|
|
|
|
paths[tmpPath] = [os.listdir(tmpPath)] # Orig name for loading
|
|
|
|
paths[tmpPath].append([f.lower() for f in paths[tmpPath][0]]) # Lower case list.
|
|
|
|
paths[tmpPath].append([stripExt(f) for f in paths[tmpPath][1]]) # Lower case no ext
|
|
|
|
|
|
|
|
tmpPath = stripFile(filePath)
|
|
|
|
if sys.exists(tmpPath):
|
|
|
|
print '\t\tSearching in %s' % tmpPath
|
|
|
|
paths[tmpPath] = [os.listdir(tmpPath)] # Orig name for loading
|
|
|
|
paths[tmpPath].append([f.lower() for f in paths[tmpPath][0]]) # Lower case list.
|
|
|
|
paths[tmpPath].append([stripExt(f) for f in paths[tmpPath][1]]) # Lower case no ext
|
|
|
|
|
|
|
|
tmpPath = addSlash(Get('texturesdir'))
|
|
|
|
if tmpPath and sys.exists(tmpPath):
|
|
|
|
print '\t\tSearching in %s' % tmpPath
|
|
|
|
paths[tmpPath] = [os.listdir(tmpPath)] # Orig name for loading
|
|
|
|
paths[tmpPath].append([f.lower() for f in paths[tmpPath][0]]) # Lower case list.
|
|
|
|
paths[tmpPath].append([stripExt(f) for f in paths[tmpPath][1]]) # Lower case no ext
|
|
|
|
|
|
|
|
# Add path if relative image patrh was given.
|
|
|
|
for k in paths.iterkeys():
|
|
|
|
tmpPath = k + imageFilePath
|
|
|
|
if sys.exists(tmpPath):
|
|
|
|
paths[tmpPath] = [os.listdir(tmpPath)] # Orig name for loading
|
|
|
|
paths[tmpPath].append([f.lower() for f in paths[tmpPath][0]]) # Lower case list.
|
|
|
|
paths[tmpPath].append([stripExt(f) for f in paths[tmpPath][1]]) # Lower case no ext
|
|
|
|
# DONE
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
for path, files in paths.iteritems():
|
|
|
|
|
|
|
|
if sys.exists(path + imageFileName):
|
|
|
|
return imageLoad(path + imageFileName)
|
|
|
|
|
|
|
|
# If the files not there then well do a case insensitive seek.
|
|
|
|
filesOrigCase = files[0]
|
|
|
|
filesLower = files[1]
|
|
|
|
filesLowerNoExt = files[2]
|
|
|
|
|
|
|
|
# We are going to try in index the file directly, if its not there just keep on
|
|
|
|
index = None
|
|
|
|
try:
|
|
|
|
# Is it just a case mismatch?
|
|
|
|
index = filesLower.index(imageFileName_lower)
|
|
|
|
except:
|
|
|
|
try:
|
|
|
|
# Have the extensions changed?
|
|
|
|
index = filesLowerNoExt.index(imageFileName_noext_lower)
|
|
|
|
|
|
|
|
ext = getExt( filesLower[index] ) # Get the extension of the file that matches all but ext.
|
|
|
|
|
|
|
|
# Check that the ext is useable eg- not a 3ds file :)
|
|
|
|
if ext.lower() not in IMAGE_EXT:
|
|
|
|
index = None
|
|
|
|
|
|
|
|
except:
|
|
|
|
index = None
|
|
|
|
|
|
|
|
if index != None:
|
|
|
|
tmpPath = path + filesOrigCase[index]
|
|
|
|
img = imageLoad( tmpPath )
|
|
|
|
if img != None:
|
|
|
|
print '\t\tImage Found "%s"' % tmpPath
|
|
|
|
return img
|
|
|
|
|
|
|
|
|
|
|
|
# IMAGE NOT FOUND IN ANY OF THE DIRS!, DO A RECURSIVE SEARCH.
|
|
|
|
print '\t\tImage Not Found in any of the dirs, doing a recusrive search'
|
|
|
|
for path in paths.iterkeys():
|
|
|
|
# Were not going to use files
|
|
|
|
|
|
|
|
|
|
|
|
#------------------
|
|
|
|
# finds the file starting at the root.
|
|
|
|
# def findImage(findRoot, imagePath):
|
|
|
|
#W---------------
|
|
|
|
|
|
|
|
# ROOT, DIRS, FILES
|
|
|
|
pathWalk = os.walk(path)
|
|
|
|
pathList = [True]
|
|
|
|
|
|
|
|
matchList = [] # Store a list of (match, size), choose the biggest.
|
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
pathList = pathWalk.next()
|
|
|
|
except:
|
|
|
|
break
|
|
|
|
|
|
|
|
for file in pathList[2]:
|
|
|
|
file_lower = file.lower()
|
|
|
|
# FOUND A MATCH
|
|
|
|
if (file_lower == imageFileName_lower) or\
|
|
|
|
(stripExt(file_lower) == imageFileName_noext_lower and getExt(file_lower) in IMAGE_EXT):
|
|
|
|
name = pathList[0] + sys.sep + file
|
|
|
|
size = os.path.getsize(name)
|
|
|
|
print '\t\t\tfound:', name
|
|
|
|
matchList.append( (name, size) )
|
|
|
|
|
|
|
|
if matchList:
|
|
|
|
# Sort by file size
|
|
|
|
matchList.sort(lambda A, B: cmp(B[1], A[1]) )
|
|
|
|
|
|
|
|
print '\t\tFound "%s"' % matchList[0][0]
|
|
|
|
|
|
|
|
# Loop through all we have found
|
|
|
|
img = None
|
|
|
|
for match in matchList:
|
|
|
|
img = imageLoad(match[0]) # 0 - first, 0 - pathname
|
|
|
|
if img != None:
|
|
|
|
break
|
|
|
|
return img
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# No go.
|
|
|
|
print '\t\tImage Not Found "%s"' % imagePath
|
2005-07-11 02:41:08 +00:00
|
|
|
return None
|
2004-06-21 12:01:23 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#==================================================================================#
|
|
|
|
# This function sets textures defined in .mtl file #
|
|
|
|
#==================================================================================#
|
|
|
|
# ___ Replaced by comprehensive imahge get
|
|
|
|
|
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):
|
2005-06-12 05:54:15 +00:00
|
|
|
TEX_ON_FLAG = NMesh.FaceModes['TEX']
|
2004-09-18 21:04:23 +00:00
|
|
|
|
|
|
|
texture = Texture.New(type)
|
|
|
|
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
|
2005-10-11 02:32:58 +00:00
|
|
|
image = comprehansiveImageLoad(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:
|
|
|
|
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
|
|
|
|
f.image = image
|
|
|
|
|
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)
|
|
|
|
|
2004-06-14 20:51:09 +00:00
|
|
|
|
|
|
|
#==================================================================================#
|
|
|
|
# This function loads materials from .mtl file (have to be defined in obj file) #
|
|
|
|
#==================================================================================#
|
2005-06-12 05:54:15 +00:00
|
|
|
def load_mtl(dir, mtl_file, meshDict, materialDict):
|
2004-09-18 21:04:23 +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
|
|
|
#===============================================================================#
|
|
|
|
# This gets a mat or creates one of the requested name if none exist. #
|
|
|
|
#===============================================================================#
|
2005-06-12 05:54:15 +00:00
|
|
|
def getMat(matName, materialDict):
|
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
|
|
|
# Make a new mat
|
|
|
|
try:
|
2005-06-12 05:54:15 +00:00
|
|
|
return materialDict[matName]
|
2005-07-11 02:41:08 +00:00
|
|
|
#except NameError or KeyError:
|
|
|
|
except: # Better do any exception
|
2005-06-12 05:54:15 +00:00
|
|
|
# Do we realy need to keep the dict up to date?, not realy but keeps consuistant.
|
|
|
|
materialDict[matName] = Material.New(matName)
|
|
|
|
return materialDict[matName]
|
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
|
|
|
|
|
|
|
mtl_file = stripPath(mtl_file)
|
2004-09-18 21:04:23 +00:00
|
|
|
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):
|
|
|
|
l = fileLines[lIdx].split()
|
|
|
|
|
|
|
|
# Detect a line that will be ignored
|
|
|
|
if len(l) == 0:
|
|
|
|
pass
|
|
|
|
elif l[0] == '#' or len(l) == 0:
|
|
|
|
pass
|
|
|
|
elif l[0] == 'newmtl':
|
|
|
|
currentMat = getMat('_'.join(l[1:]), materialDict) # Material should alredy exist.
|
|
|
|
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':
|
2005-07-11 02:41:08 +00:00
|
|
|
img_fileName = ' '.join(l[1:])
|
|
|
|
loadMaterialImage(currentMat, img_fileName, 'Ka', meshDict, dir)
|
2005-06-12 05:54:15 +00:00
|
|
|
elif l[0] == 'map_Ks':
|
2005-07-11 02:41:08 +00:00
|
|
|
img_fileName = ' '.join(l[1:])
|
|
|
|
loadMaterialImage(currentMat, img_fileName, 'Ks', meshDict, dir)
|
2005-06-12 05:54:15 +00:00
|
|
|
elif l[0] == 'map_Kd':
|
2005-07-11 02:41:08 +00:00
|
|
|
img_fileName = ' '.join(l[1:])
|
|
|
|
loadMaterialImage(currentMat, img_fileName, 'Kd', meshDict, dir)
|
|
|
|
|
|
|
|
# new additions
|
|
|
|
elif l[0] == 'map_Bump': # Bumpmap
|
|
|
|
img_fileName = ' '.join(l[1:])
|
|
|
|
loadMaterialImage(currentMat, img_fileName, 'Bump', meshDict, dir)
|
|
|
|
elif l[0] == 'map_D': # Alpha map - Dissolve
|
|
|
|
img_fileName = ' '.join(l[1:])
|
|
|
|
loadMaterialImage(currentMat, img_fileName, 'D', meshDict, dir)
|
|
|
|
|
|
|
|
elif l[0] == 'refl': # Reflectionmap
|
|
|
|
img_fileName = ' '.join(l[1:])
|
|
|
|
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
|
2005-05-30 02:26:40 +00:00
|
|
|
#===========================================================================#
|
|
|
|
# Returns unique name of object/mesh (preserve overwriting existing meshes) #
|
|
|
|
#===========================================================================#
|
2004-09-18 21:04:23 +00:00
|
|
|
def getUniqueName(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
|
|
|
newName = name
|
2004-09-18 21:04:23 +00:00
|
|
|
uniqueInt = 0
|
|
|
|
while 1:
|
|
|
|
try:
|
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
|
|
|
ob = Object.Get(newName)
|
2004-09-18 21:04:23 +00:00
|
|
|
# Okay, this is working, so lets make a new 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
|
|
|
newName = '%s.%d' % (name, uniqueInt)
|
2004-09-18 21:04:23 +00:00
|
|
|
uniqueInt +=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
|
|
|
except AttributeError:
|
|
|
|
if newName not in NMesh.GetNames():
|
|
|
|
return newName
|
2004-11-30 02:27:46 +00:00
|
|
|
else:
|
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
|
|
|
newName = '%s.%d' % (name, uniqueInt)
|
2004-11-30 02:27:46 +00:00
|
|
|
uniqueInt +=1
|
2004-06-14 20:51:09 +00:00
|
|
|
|
|
|
|
#==================================================================================#
|
|
|
|
# This loads data from .obj file #
|
|
|
|
#==================================================================================#
|
|
|
|
def load_obj(file):
|
2005-10-11 02:32:58 +00:00
|
|
|
|
|
|
|
print '\nImporting OBJ file: "%s"' % file
|
|
|
|
|
2004-09-18 21:04:23 +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():
|
|
|
|
ob.sel = 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
|
|
|
TEX_OFF_FLAG = ~NMesh.FaceModes['TEX']
|
|
|
|
|
2004-09-18 21:04:23 +00:00
|
|
|
# Get the file name with no path or .obj
|
2005-06-12 05:54:15 +00:00
|
|
|
fileName = stripExt( stripPath(file) )
|
2004-09-11 13:45:17 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
mtl_fileName = [] # Support multiple mtl files if needed.
|
2004-09-18 21:04:23 +00:00
|
|
|
|
2005-06-12 05:54:15 +00:00
|
|
|
DIR = stripFile(file)
|
|
|
|
|
|
|
|
tempFile = open(file, 'r')
|
|
|
|
fileLines = tempFile.readlines()
|
|
|
|
tempFile.close()
|
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
|
|
|
uvMapList = [] # store tuple uv pairs here
|
|
|
|
|
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
|
2005-10-11 02:32:58 +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
|
|
|
|
imageDict = {}
|
|
|
|
|
|
|
|
# This stores the index that the current mesh has for the current material.
|
|
|
|
# if the mesh does not have the material then set -1
|
|
|
|
contextMeshMatIdx = -1
|
|
|
|
|
|
|
|
# Keep this out of the dict for easy accsess.
|
2005-10-11 02:32:58 +00:00
|
|
|
nullMat = Material.New('(null)')
|
2004-09-21 09:09:58 +00:00
|
|
|
|
2004-09-18 21:04:23 +00:00
|
|
|
currentMat = nullMat # Use this mat.
|
2005-06-12 05:54:15 +00:00
|
|
|
currentImg = None # Null image is a string, otherwise this should be set to an image object.\
|
|
|
|
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
|
2005-06-12 05:54:15 +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
|
|
|
|
|
|
|
quadList = (0, 1, 2, 3)
|
2004-09-21 09:09:58 +00:00
|
|
|
|
2005-06-12 05:54:15 +00:00
|
|
|
faceQuadVList = [None, None, None, None]
|
|
|
|
faceTriVList = [None, None, None]
|
|
|
|
|
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
|
|
|
nonVertFileLines = []
|
2005-06-12 05:54:15 +00:00
|
|
|
smoothingGroups = {}
|
|
|
|
materialDict = {} # Store all imported materials as unique dict, names are key
|
2004-09-18 21:04:23 +00:00
|
|
|
lIdx = 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
|
|
|
print '\tfile length: %d' % len(fileLines)
|
2005-10-11 02:32:58 +00:00
|
|
|
|
|
|
|
while lIdx < len(fileLines):
|
|
|
|
# Ignore vert normals
|
|
|
|
if fileLines[lIdx].startswith('vn'):
|
|
|
|
lIdx+=1
|
|
|
|
continue
|
|
|
|
|
|
|
|
# Dont Bother splitting empty or comment lines.
|
|
|
|
if len(fileLines[lIdx]) == 0 or\
|
|
|
|
fileLines[lIdx][0] == '\n' or\
|
|
|
|
fileLines[lIdx][0] == '#':
|
|
|
|
pass
|
|
|
|
|
|
|
|
else:
|
|
|
|
fileLines[lIdx] = fileLines[lIdx].split()
|
|
|
|
l = fileLines[lIdx]
|
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
|
|
|
# Splitting may
|
|
|
|
if len(l) == 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
|
|
|
pass
|
2005-10-11 02:32:58 +00:00
|
|
|
# Verts
|
|
|
|
elif l[0] == 'v':
|
|
|
|
vertList.append( NMesh.Vert(float(l[1]), float(l[2]), float(l[3]) ) )
|
|
|
|
|
|
|
|
# UV COORDINATE
|
|
|
|
elif l[0] == 'vt':
|
|
|
|
uvMapList.append( (float(l[1]), float(l[2])) )
|
|
|
|
|
|
|
|
# Smoothing groups, make a list of unique.
|
|
|
|
elif l[0] == 's':
|
|
|
|
if len(l) > 1:
|
|
|
|
smoothingGroups['_'.join(l[1:])] = None # Can we assign something more usefull? cant use sets yet
|
|
|
|
|
|
|
|
# Keep Smoothing group line
|
|
|
|
nonVertFileLines.append(l)
|
|
|
|
|
|
|
|
# Smoothing groups, make a list of unique.
|
|
|
|
elif l[0] == 'usemtl':
|
|
|
|
if len(l) > 1:
|
|
|
|
materialDict['_'.join(l[1:])] = None # Can we assign something more usefull? cant use sets yet
|
|
|
|
|
|
|
|
# Keep Smoothing group line
|
|
|
|
nonVertFileLines.append(l)
|
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-10-11 02:32:58 +00:00
|
|
|
nonVertFileLines.append(l)
|
|
|
|
lIdx+=1
|
|
|
|
|
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
|
|
|
del fileLines
|
|
|
|
fileLines = nonVertFileLines
|
|
|
|
del nonVertFileLines
|
|
|
|
|
2005-06-12 05:54:15 +00:00
|
|
|
# Only want unique keys anyway
|
|
|
|
smoothingGroups['(null)'] = None # Make sure we have at least 1.
|
|
|
|
smoothingGroups = smoothingGroups.keys()
|
|
|
|
print '\tfound %d smoothing groups.' % (len(smoothingGroups) -1)
|
|
|
|
|
|
|
|
# Add materials to Blender for later is in teh OBJ
|
2005-10-11 02:32:58 +00:00
|
|
|
for k in materialDict.iterkeys():
|
2005-06-12 05:54:15 +00:00
|
|
|
materialDict[k] = Material.New(k)
|
|
|
|
|
|
|
|
|
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
|
|
|
# Make a list of all unused vert indicies that we can copy from
|
2005-06-12 05:54:15 +00:00
|
|
|
VERT_USED_LIST = [0]*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
|
|
|
|
# This is an issue with global vertex indicies being translated to per mesh indicies
|
|
|
|
# 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.
|
2005-06-12 05:54:15 +00:00
|
|
|
currentObjectName = 'unnamed_obj_0' # If we cant get one, use this
|
|
|
|
|
|
|
|
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.
|
|
|
|
currentMaterialMeshMapping = {} # Used to store material indicies so we dont have to search the mesh for materials every time.
|
|
|
|
|
|
|
|
# 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.
|
|
|
|
currentSmoothGroup = '(null)' # The Name of the current smooth group
|
|
|
|
|
|
|
|
# For direct accsess to the Current Meshes, Current Smooth Groups- Used verts.
|
|
|
|
# This is of course context based and changes on the fly.
|
|
|
|
currentUsedVertListSmoothGroup = VERT_USED_LIST[:]
|
|
|
|
|
|
|
|
# Set the initial '(null)' Smooth group, every mesh has one.
|
|
|
|
currentUsedVertList[currentSmoothGroup] = currentUsedVertListSmoothGroup
|
|
|
|
|
|
|
|
|
|
|
|
# 0:NMesh, 1:SmoothGroups[UsedVerts[0,0,0,0]], 2:materialMapping['matname':matIndexForThisNMesh]
|
|
|
|
meshDict[currentObjectName] = (currentMesh, currentUsedVertList, currentMaterialMeshMapping)
|
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
# Only show the bad uv error once
|
|
|
|
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
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
#currentMesh.verts.append(vertList[0]) # So we can sync with OBJ indicies where 1 is the first item.
|
2005-06-12 05:54:15 +00:00
|
|
|
if len(uvMapList) > 1:
|
|
|
|
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
|
|
|
|
2004-09-21 09:09:58 +00:00
|
|
|
#==================================================================================#
|
|
|
|
# Load all faces into objects, main loop #
|
|
|
|
#==================================================================================#
|
2005-10-11 02:32:58 +00:00
|
|
|
lIdx = 0
|
|
|
|
# Face and Object loading LOOP
|
|
|
|
while lIdx < len(fileLines):
|
|
|
|
l = fileLines[lIdx]
|
|
|
|
|
|
|
|
# FACE
|
|
|
|
if l[0] == 'f':
|
|
|
|
# Make a face with the correct material.
|
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
|
|
|
# Add material to mesh
|
|
|
|
if contextMeshMatIdx == -1:
|
|
|
|
tmpMatLs = currentMesh.materials
|
2004-09-21 09:09:58 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
# Set up vIdxLs : Verts
|
|
|
|
# Set up vtIdxLs : UV
|
|
|
|
# Start with a dummy objects so python accepts OBJs 1 is the first index.
|
|
|
|
vIdxLs = []
|
|
|
|
vtIdxLs = []
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
for v in l[1:]:
|
|
|
|
# OBJ files can have // or / to seperate vert/texVert/normal
|
|
|
|
# this is a bit of a pain but we must deal with it.
|
|
|
|
objVert = v.split('/')
|
2005-06-12 05:54:15 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
# Vert Index - OBJ supports negative index assignment (like python)
|
|
|
|
|
|
|
|
vIdxLs.append(int(objVert[0])-1)
|
|
|
|
if fHasUV:
|
|
|
|
# UV
|
|
|
|
index = 0 # Dummy var
|
|
|
|
if len(objVert) == 1:
|
|
|
|
index = vIdxLs[-1]
|
|
|
|
elif objVert[1]: # != '' # Its possible that theres no texture vert just he vert and normal eg 1//2
|
|
|
|
index = int(objVert[1])-1
|
2005-06-12 05:54:15 +00:00
|
|
|
|
2005-10-11 02:32:58 +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(0)
|
|
|
|
|
|
|
|
fHasUV = 0
|
2005-06-12 05:54:15 +00:00
|
|
|
|
2005-10-11 02:32:58 +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):
|
|
|
|
fHasUV = 0
|
|
|
|
|
|
|
|
badObjUvs +=1 # ERROR, Cont
|
|
|
|
# Quads only, we could import quads using the method below but it polite to import a quad as a quad.
|
|
|
|
if len(vIdxLs) == 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]
|
|
|
|
if currentUsedVertListSmoothGroup[vIdxLs[i]] == 0:
|
2005-10-11 02:32:58 +00:00
|
|
|
faceQuadVList[i] = vertList[vIdxLs[i]]
|
|
|
|
currentMesh.verts.append(faceQuadVList[i])
|
2005-06-12 05:54:15 +00:00
|
|
|
currentUsedVertListSmoothGroup[vIdxLs[i]] = len(currentMesh.verts)-1
|
|
|
|
else:
|
2005-10-11 02:32:58 +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
|
|
|
|
2005-06-12 05:54:15 +00:00
|
|
|
f = NMesh.Face(faceQuadVList)
|
2004-09-18 21:04:23 +00:00
|
|
|
# UV MAPPING
|
|
|
|
if fHasUV:
|
2005-06-12 05:54:15 +00:00
|
|
|
f.uv = [uvMapList[ vtIdxLs[0] ],uvMapList[ vtIdxLs[1] ],uvMapList[ vtIdxLs[2] ],uvMapList[ vtIdxLs[3] ]]
|
|
|
|
if 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
|
|
|
f.image = currentImg
|
|
|
|
else:
|
2005-06-12 05:54:15 +00:00
|
|
|
f.mode &= TEX_OFF_FLAG
|
|
|
|
|
|
|
|
f.mat = contextMeshMatIdx
|
|
|
|
f.smooth = currentSmooth
|
|
|
|
currentMesh.faces.append(f) # move the face onto the mesh
|
2005-10-11 02:32:58 +00:00
|
|
|
|
|
|
|
elif len(vIdxLs) >= 3: # This handles tri's and fans
|
|
|
|
for i in range(len(vIdxLs)-2):
|
|
|
|
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)]:
|
|
|
|
if currentUsedVertListSmoothGroup[vIdxLs[j]] == 0:
|
|
|
|
faceTriVList[k] = vertList[vIdxLs[j]]
|
|
|
|
currentMesh.verts.append(faceTriVList[k])
|
|
|
|
currentUsedVertListSmoothGroup[vIdxLs[j]] = len(currentMesh.verts)-1
|
2005-06-12 05:54:15 +00:00
|
|
|
else:
|
2005-10-11 02:32:58 +00:00
|
|
|
faceTriVList[k] = currentMesh.verts[currentUsedVertListSmoothGroup[vIdxLs[j]]]
|
2005-06-12 05:54:15 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
f = NMesh.Face(faceTriVList)
|
2005-06-12 05:54:15 +00:00
|
|
|
|
|
|
|
# UV MAPPING
|
|
|
|
if fHasUV:
|
|
|
|
f.uv = [uvMapList[vtIdxLs[0]], uvMapList[vtIdxLs[i+1]], uvMapList[vtIdxLs[i+2]]]
|
|
|
|
if currentImg:
|
|
|
|
f.image = currentImg
|
|
|
|
else:
|
|
|
|
f.mode &= TEX_OFF_FLAG
|
|
|
|
|
|
|
|
f.mat = contextMeshMatIdx
|
|
|
|
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
|
2005-10-11 02:32:58 +00:00
|
|
|
|
|
|
|
# FACE SMOOTHING
|
|
|
|
elif l[0] == 's':
|
|
|
|
# No value? then turn on.
|
|
|
|
if len(l) == 1:
|
|
|
|
currentSmooth = True
|
|
|
|
currentSmoothGroup = '(null)'
|
|
|
|
try:
|
|
|
|
currentUsedVertListSmoothGroup = currentUsedVertList[currentSmoothGroup]
|
|
|
|
except KeyError:
|
|
|
|
currentUsedVertListSmoothGroup = VERT_USED_LIST[:]
|
|
|
|
currentUsedVertList[currentSmoothGroup] = currentUsedVertListSmoothGroup
|
|
|
|
|
|
|
|
else:
|
|
|
|
if l[1] == 'off':
|
|
|
|
currentSmooth = False
|
2005-06-12 05:54:15 +00:00
|
|
|
currentSmoothGroup = '(null)'
|
2005-10-11 02:32:58 +00:00
|
|
|
# We all have a null group so dont need to try
|
|
|
|
currentUsedVertListSmoothGroup = currentUsedVertList['(null)']
|
|
|
|
else:
|
|
|
|
currentSmooth = True
|
|
|
|
currentSmoothGroup = '_'.join(l[1:])
|
|
|
|
|
|
|
|
# OBJECT / GROUP
|
|
|
|
elif l[0] == 'o' or l[0] == 'g':
|
|
|
|
|
|
|
|
# Forget about the current image
|
|
|
|
currentImg = None
|
|
|
|
|
|
|
|
# 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.)
|
|
|
|
if len(l) > 1:
|
|
|
|
currentObjectName = '_'.join(l[1:])
|
|
|
|
else: # No name given
|
|
|
|
# Make a new empty name
|
|
|
|
if l[0] == 'g': # Make a blank group name
|
|
|
|
currentObjectName = 'unnamed_grp_%d' % currentUnnamedGroupIdx
|
|
|
|
currentUnnamedGroupIdx +=1
|
|
|
|
else: # is an object.
|
|
|
|
currentObjectName = 'unnamed_ob_%d' % currentUnnamedObjectIdx
|
|
|
|
currentUnnamedObjectIdx +=1
|
|
|
|
|
|
|
|
|
|
|
|
# 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 len(l) == 1 or (not meshDict.has_key(currentObjectName)):
|
|
|
|
currentMesh = NMesh.GetRaw()
|
2005-06-12 05:54:15 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
currentUsedVertList = {}
|
2005-06-12 05:54:15 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
# Sg is a string
|
|
|
|
currentSmoothGroup = '(null)'
|
|
|
|
currentUsedVertListSmoothGroup = VERT_USED_LIST[:]
|
|
|
|
currentUsedVertList[currentSmoothGroup] = currentUsedVertListSmoothGroup
|
|
|
|
currentMaterialMeshMapping = {}
|
2005-06-12 05:54:15 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
meshDict[currentObjectName] = (currentMesh, currentUsedVertList, currentMaterialMeshMapping)
|
|
|
|
currentMesh.hasFaceUV(1)
|
|
|
|
contextMeshMatIdx = -1
|
2004-09-21 09:09:58 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
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)
|
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:
|
|
|
|
contextMeshMatIdx = currentMaterialMeshMapping[currentMat.name] #getMeshMaterialIndex(currentMesh, currentMat)
|
|
|
|
except KeyError:
|
|
|
|
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
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
# For new meshes switch smoothing groups to null
|
|
|
|
currentSmoothGroup = '(null)'
|
|
|
|
currentUsedVertListSmoothGroup = currentUsedVertList[currentSmoothGroup]
|
|
|
|
|
|
|
|
# MATERIAL
|
|
|
|
elif l[0] == 'usemtl':
|
|
|
|
if len(l) == 1 or l[1] == '(null)':
|
|
|
|
currentMat = nullMat # We know we have a null mat.
|
|
|
|
else:
|
|
|
|
currentMat = materialDict['_'.join(l[1:])]
|
|
|
|
try:
|
|
|
|
contextMeshMatIdx = currentMaterialMeshMapping[currentMat.name]
|
|
|
|
except KeyError:
|
|
|
|
contextMeshMatIdx = -1 #getMeshMaterialIndex(currentMesh, currentMat)
|
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':
|
|
|
|
currentImg = None
|
|
|
|
else:
|
|
|
|
# Load an image.
|
|
|
|
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)
|
|
|
|
currentImg = imageDict[newImgName]
|
|
|
|
|
|
|
|
except KeyError: # Not in dict, add for first time.
|
|
|
|
# Image has not been added, Try and load the image
|
|
|
|
currentImg = comprehansiveImageLoad(newImgName, DIR) # Use join in case of spaces
|
|
|
|
imageDict[newImgName] = currentImg
|
|
|
|
# These may be None, thats okay.
|
2005-06-12 05:54:15 +00:00
|
|
|
|
|
|
|
|
2004-09-21 09:09:58 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
# MATERIAL FILE
|
|
|
|
elif l[0] == 'mtllib':
|
|
|
|
mtl_fileName.append(' '.join(l[1:]) ) # SHOULD SUPPORT MULTIPLE MTL?
|
|
|
|
lIdx+=1
|
|
|
|
|
|
|
|
# Applies material properties to materials alredy on the mesh as well as Textures.
|
|
|
|
for mtl in mtl_fileName:
|
|
|
|
load_mtl(DIR, mtl, meshDict, materialDict)
|
|
|
|
|
|
|
|
|
|
|
|
importedObjects = []
|
|
|
|
for mk, me in meshDict.iteritems():
|
|
|
|
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
|
2005-05-30 02:26:40 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
name = getUniqueName(mk)
|
|
|
|
ob = NMesh.PutRaw(nme, name)
|
|
|
|
ob.name = name
|
2005-05-30 02:26:40 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
importedObjects.append(ob)
|
2005-05-30 02:26:40 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
# Select all imported objects.
|
|
|
|
for ob in importedObjects:
|
|
|
|
ob.sel = 1
|
|
|
|
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
|
|
|
|
|
|
|
|
# Batch directory loading.
|
|
|
|
def load_obj_dir(obj_dir):
|
|
|
|
|
|
|
|
# Strip file
|
|
|
|
obj_dir = stripFile(obj_dir)
|
|
|
|
time = sys.time()
|
|
|
|
|
|
|
|
objFiles = [f for f in os.listdir(obj_dir) if f.lower().endswith('obj')]
|
|
|
|
|
|
|
|
Window.DrawProgressBar(0, '')
|
|
|
|
count = 0
|
|
|
|
obj_len = len(objFiles)
|
|
|
|
for obj in objFiles:
|
|
|
|
count+=1
|
|
|
|
|
|
|
|
newScn = Scene.New(obj)
|
|
|
|
newScn.makeCurrent()
|
|
|
|
|
|
|
|
Window.DrawProgressBar((float(count)/obj_len) - 0.01, '%s: %i of %i' % (obj, count, obj_len))
|
|
|
|
|
|
|
|
load_obj(obj_dir + obj)
|
|
|
|
|
|
|
|
Window.DrawProgressBar(1, '')
|
|
|
|
print 'Total obj import "%s" dir: %.2f' % (obj_dir, sys.time() - time)
|
2004-08-17 04:26:00 +00:00
|
|
|
|
2004-11-30 02:27:46 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
def main():
|
|
|
|
TEXT_IMPORT = 'Import a Wavefront OBJ'
|
|
|
|
TEXT_BATCH_IMPORT = 'Import *.obj to Scenes'
|
|
|
|
|
|
|
|
if Window.GetKeyQualifiers() & Window.Qual.SHIFT:
|
|
|
|
if not os:
|
|
|
|
Draw.PupMenu('Module "os" not found, needed for batch load, using normal selector.')
|
|
|
|
Window.FileSelector(load_obj, TEXT_IMPORT)
|
|
|
|
else:
|
|
|
|
Window.FileSelector(load_obj_dir, TEXT_BATCH_IMPORT)
|
|
|
|
else:
|
|
|
|
Window.FileSelector(load_obj, TEXT_IMPORT)
|
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__':
|
|
|
|
main()
|