forked from bartvdbraak/blender
Scripts:
- Minor updates to the ac3d importer to support bad files (with more data than reported, this time) and properly handle texture paths with win separators ('\') and spaces. Again, thanks Melchior Franz for testing and reporting.
This commit is contained in:
parent
f95f812b2c
commit
b2ce8ec9c9
@ -10,7 +10,7 @@ Tip: 'Import an AC3D (.ac) file.'
|
|||||||
__author__ = "Willian P. Germano"
|
__author__ = "Willian P. Germano"
|
||||||
__url__ = ("blender", "elysiun", "AC3D's homepage, http://www.ac3d.org",
|
__url__ = ("blender", "elysiun", "AC3D's homepage, http://www.ac3d.org",
|
||||||
"PLib 3d gaming lib, http://plib.sf.net")
|
"PLib 3d gaming lib, http://plib.sf.net")
|
||||||
__version__ = "2.43 2007-01-28"
|
__version__ = "2.43 2007-02-12"
|
||||||
|
|
||||||
__bpydoc__ = """\
|
__bpydoc__ = """\
|
||||||
This script imports AC3D models into Blender.
|
This script imports AC3D models into Blender.
|
||||||
@ -41,10 +41,14 @@ users can configure (see config options above).
|
|||||||
# $Id$
|
# $Id$
|
||||||
#
|
#
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
# AC3DImport version 2.43 Jan 04, 2007
|
# AC3DImport version 2.43 Feb 12, 2007
|
||||||
# Program versions: Blender 2.43 and AC3Db files (means version 0xb)
|
# Program versions: Blender 2.43 and AC3Db files (means version 0xb)
|
||||||
# changed: updated for new Blender version, Mesh module
|
# changed: updated for new Blender version, Mesh module
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
|
# Thanks: Melchior Franz for extensive bug testing and reporting, making this
|
||||||
|
# version cope much better with old or bad .ac files, among other improvements;
|
||||||
|
# Stewart Andreason for reporting a serious crash.
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||||
#
|
#
|
||||||
# Copyright (C) 2004-2007: Willian P. Germano, wgermano _at_ ig.com.br
|
# Copyright (C) 2004-2007: Willian P. Germano, wgermano _at_ ig.com.br
|
||||||
@ -223,11 +227,16 @@ class AC3DImport:
|
|||||||
self.testAC3DImport()
|
self.testAC3DImport()
|
||||||
|
|
||||||
def parse_obj(self, value):
|
def parse_obj(self, value):
|
||||||
if self.kidsnumlist:
|
kidsnumlist = self.kidsnumlist
|
||||||
while not self.kidsnumlist[-1]:
|
if kidsnumlist:
|
||||||
self.kidsnumlist.pop()
|
while not kidsnumlist[-1]:
|
||||||
|
kidsnumlist.pop()
|
||||||
|
if kidsnumlist:
|
||||||
self.dad = self.dad.dad
|
self.dad = self.dad.dad
|
||||||
self.kidsnumlist[-1] -= 1
|
else:
|
||||||
|
inform('Ignoring unexpected data at end of file.')
|
||||||
|
return -1 # bad file with more objects than reported
|
||||||
|
kidsnumlist[-1] -= 1
|
||||||
new = Obj(AC_OB_TYPES[value])
|
new = Obj(AC_OB_TYPES[value])
|
||||||
new.dad = self.dad
|
new.dad = self.dad
|
||||||
new.name = value
|
new.name = value
|
||||||
@ -249,7 +258,8 @@ class AC3DImport:
|
|||||||
self.objlist[-1].data = data
|
self.objlist[-1].data = data
|
||||||
|
|
||||||
def parse_tex(self, value):
|
def parse_tex(self, value):
|
||||||
texture = value.split('"')[1]
|
line = self.lines[self.i - 1] # parse again to properly get paths with spaces
|
||||||
|
texture = line.split('"')[1]
|
||||||
self.objlist[-1].tex = texture
|
self.objlist[-1].tex = texture
|
||||||
|
|
||||||
def parse_texrep(self, trash):
|
def parse_texrep(self, trash):
|
||||||
@ -437,7 +447,9 @@ class AC3DImport:
|
|||||||
i += 1
|
i += 1
|
||||||
if kw:
|
if kw:
|
||||||
self.i = i
|
self.i = i
|
||||||
self.token[kw](line[1])
|
result = self.token[kw](line[1])
|
||||||
|
if result:
|
||||||
|
break # bad .ac file, stop parsing
|
||||||
i = self.i
|
i = self.i
|
||||||
line = lines[i].split()
|
line = lines[i].split()
|
||||||
|
|
||||||
@ -532,6 +544,7 @@ class AC3DImport:
|
|||||||
scene = self.scene
|
scene = self.scene
|
||||||
|
|
||||||
bl_images = {} # loaded texture images
|
bl_images = {} # loaded texture images
|
||||||
|
missing_textures = [] # textures we couldn't find
|
||||||
|
|
||||||
objlist = self.objlist[1:] # skip 'world'
|
objlist = self.objlist[1:] # skip 'world'
|
||||||
|
|
||||||
@ -624,27 +637,37 @@ class AC3DImport:
|
|||||||
|
|
||||||
img = None
|
img = None
|
||||||
if obj.tex != '':
|
if obj.tex != '':
|
||||||
baseimgname = bsys.basename(obj.tex)
|
|
||||||
if obj.tex in bl_images.keys():
|
if obj.tex in bl_images.keys():
|
||||||
img = bl_images[obj.tex]
|
img = bl_images[obj.tex]
|
||||||
|
elif obj.tex not in missing_textures:
|
||||||
|
texfname = None
|
||||||
|
objtex = obj.tex
|
||||||
|
baseimgname = bsys.basename(objtex)
|
||||||
|
if bsys.exists(objtex) == 1:
|
||||||
|
texfname = objtex
|
||||||
else:
|
else:
|
||||||
|
if baseimgname.find('\\') > 0:
|
||||||
|
baseimgname = bsys.basename(objtex.replace('\\','/'))
|
||||||
|
objtex = bsys.join(self.importdir, baseimgname)
|
||||||
|
if bsys.exists(objtex) == 1:
|
||||||
|
texfname = objtex
|
||||||
|
else:
|
||||||
|
objtex = bsys.join(TEXTURES_DIR, baseimgname)
|
||||||
|
if bsys.exists(objtex):
|
||||||
|
texfname = objtex
|
||||||
|
if texfname:
|
||||||
try:
|
try:
|
||||||
img = Image.Load(obj.tex)
|
img = Image.Load(texfname)
|
||||||
# Commented because it's unnecessary:
|
# Commented because it's unnecessary:
|
||||||
#img.xrep = int(obj.texrep[0])
|
#img.xrep = int(obj.texrep[0])
|
||||||
#img.yrep = int(obj.texrep[1])
|
#img.yrep = int(obj.texrep[1])
|
||||||
except:
|
|
||||||
try:
|
|
||||||
obj.tex = self.importdir + '/' + baseimgname
|
|
||||||
img = Image.Load(obj.tex)
|
|
||||||
except:
|
|
||||||
try:
|
|
||||||
obj.tex = TEXTURES_DIR + baseimgname
|
|
||||||
img = Image.Load(obj.tex)
|
|
||||||
except:
|
|
||||||
inform("Couldn't load texture: %s" % baseimgname)
|
|
||||||
if img:
|
if img:
|
||||||
bl_images[obj.tex] = img
|
bl_images[obj.tex] = img
|
||||||
|
except:
|
||||||
|
inform("Couldn't load texture: %s" % baseimgname)
|
||||||
|
else:
|
||||||
|
missing_textures.append(obj.tex)
|
||||||
|
inform("Couldn't find texture: %s" % baseimgname)
|
||||||
|
|
||||||
for i in range(facesnum):
|
for i in range(facesnum):
|
||||||
f = obj.flist_cfg[i]
|
f = obj.flist_cfg[i]
|
||||||
|
Loading…
Reference in New Issue
Block a user