More small updates to the ac3d importer, to calculate normals for the created meshes and to avoid problems with older .ac files.
This commit is contained in:
Willian Padovani Germano 2007-01-16 00:50:31 +00:00
parent 72de9a64c9
commit feb63d7d3b

@ -26,14 +26,14 @@ Missing:<br>
The url tag is irrelevant for Blender. The url tag is irrelevant for Blender.
Known issues:<br> Known issues:<br>
None. - Some objects may be imported with wrong normals due to wrong information in the model itself. This can be noticed by strange shading, like darker than expected parts in the model. To fix this, select the mesh with wrong normals, enter edit mode and tell Blender to recalculate the normals, either to make them point outside (the usual case) or inside.<br>
Config Options:<br> Config Options:<br>
- textures dir (string): if non blank, when imported texture paths are - textures dir (string): if non blank, when imported texture paths are
wrong in the .ac file, Blender will also look for them at this dir. wrong in the .ac file, Blender will also look for them at this dir.
Notes:<br> Notes:<br>
- when looking for assigned textures, Blender tries in order: the actual - When looking for assigned textures, Blender tries in order: the actual
paths from the .ac file, the .ac file's dir and the default textures dir path paths from the .ac file, the .ac file's dir and the default textures dir path
users can configure (see config options above). users can configure (see config options above).
""" """
@ -95,6 +95,8 @@ def update_registry():
rd = Registry.GetKey('ac3d_import', True) rd = Registry.GetKey('ac3d_import', True)
if rd: if rd:
if 'GROUP' in rd:
update_registry()
TEXTURES_DIR = rd['TEXTURES_DIR'] TEXTURES_DIR = rd['TEXTURES_DIR']
else: update_registry() else: update_registry()
@ -454,16 +456,19 @@ class AC3DImport:
empty.select(True) empty.select(True)
o.bl_obj = empty o.bl_obj = empty
bl_children = [c.bl_obj for c in children] bl_children = [c.bl_obj for c in children if c.bl_obj != None]
o.bl_obj.makeParent(bl_children, 0, 1) o.bl_obj.makeParent(bl_children, 0, 1)
for child in children: for child in children:
blob = child.bl_obj
if not blob: continue
if child.loc: if child.loc:
child.bl_obj.setLocation(child.loc) blob.setLocation(child.loc)
if child.rot: if child.rot:
eul = euler_in_radians(child.rot.toEuler()) eul = euler_in_radians(child.rot.toEuler())
child.bl_obj.setEuler(eul) blob.setEuler(eul)
if child.size: if child.size:
child.bl_obj.size = child.size blob.size = child.size
newlist.append(o) newlist.append(o)
@ -542,79 +547,81 @@ class AC3DImport:
for e in obj.elist: for e in obj.elist:
mesh.edges.extend(e) mesh.edges.extend(e)
mesh.faces.extend(obj.flist_v) if obj.flist_v:
mesh.faces.extend(obj.flist_v)
mesh.faceUV = True
# checking if the .ac file had duplicate faces (Blender ignores them): # checking if the .ac file had duplicate faces (Blender ignores them):
if len(mesh.faces) != len(obj.flist_v): if len(mesh.faces) != len(obj.flist_v):
# it has, ugh. Let's clean the uv list: # it has, ugh. Let's clean the uv list:
lenfl = len(obj.flist_v) lenfl = len(obj.flist_v)
flist = obj.flist_v flist = obj.flist_v
uvlist = obj.flist_uv uvlist = obj.flist_uv
cfglist = obj.flist_cfg cfglist = obj.flist_cfg
for f in flist: for f in flist:
f.sort() f.sort()
for fi in range(lenfl - 1): for fi in range(lenfl - 1):
if flist[fi] in flist[fi+1:]: if flist[fi] in flist[fi+1:]:
uvlist.pop(fi) uvlist.pop(fi)
cfglist.pop(fi) cfglist.pop(fi)
if obj.flist_v: mesh.faceUV = True img = None
tex = None
img = None if obj.tex != '':
tex = None baseimgname = bsys.basename(obj.tex)
if obj.tex != '' and mesh.faceUV: if obj.tex in bl_images.keys():
baseimgname = bsys.basename(obj.tex) img = bl_images[obj.txt]
if obj.tex in bl_images.keys(): tex = bl_textures[img]
img = bl_images[obj.txt] else:
tex = bl_textures[img]
else:
try:
img = Image.Load(obj.tex)
# Commented because it's unnecessary:
#img.xrep = int(obj.texrep[0])
#img.yrep = int(obj.texrep[1])
except:
try: try:
obj.tex = self.importdir + '/' + baseimgname
img = Image.Load(obj.tex) img = Image.Load(obj.tex)
# Commented because it's unnecessary:
#img.xrep = int(obj.texrep[0])
#img.yrep = int(obj.texrep[1])
except: except:
try: try:
obj.tex = TEXTURES_DIR + baseimgname obj.tex = self.importdir + '/' + baseimgname
img = Image.Load(obj.tex) img = Image.Load(obj.tex)
except: except:
inform("Couldn't load texture: %s" % baseimgname) try:
obj.tex = TEXTURES_DIR + baseimgname
img = Image.Load(obj.tex)
except:
inform("Couldn't load texture: %s" % baseimgname)
if img:
bl_images[obj.tex] = img
i = 0
for f in obj.flist_cfg:
fmat = f[0]
is_smooth = f[1]
twoside = f[2]
bface = mesh.faces[i]
bface.smooth = is_smooth
if twoside: bface.mode |= FACE_TWOSIDE
if img: if img:
bl_images[obj.tex] = img bface.mode |= FACE_TEX
bface.image = img
bface.mat = objmat_indices.index(fmat)
fuv = obj.flist_uv[i]
if obj.texoff:
uoff = obj.texoff[0]
voff = obj.texoff[1]
urep = obj.texrep[0]
vrep = obj.texrep[1]
for uv in fuv:
uv[0] *= urep
uv[1] *= vrep
uv[0] += uoff
uv[1] += voff
i = 0 mesh.faces[i].uv = fuv
for f in obj.flist_cfg:
fmat = f[0]
is_smooth = f[1]
twoside = f[2]
bface = mesh.faces[i]
bface.smooth = is_smooth
if twoside: bface.mode |= FACE_TWOSIDE
if img:
bface.mode |= FACE_TEX
bface.image = img
bface.mat = objmat_indices.index(fmat)
fuv = obj.flist_uv[i]
if obj.texoff:
uoff = obj.texoff[0]
voff = obj.texoff[1]
urep = obj.texrep[0]
vrep = obj.texrep[1]
for uv in fuv:
uv[0] *= urep
uv[1] *= vrep
uv[0] += uoff
uv[1] += voff
mesh.faces[i].uv = fuv i += 1
i += 1 mesh.calcNormals()
mesh.mode = MESH_AUTOSMOOTH mesh.mode = MESH_AUTOSMOOTH
obj_idx += 1 obj_idx += 1
@ -633,4 +640,6 @@ def filesel_callback(filename):
endtime = bsys.time() - starttime endtime = bsys.time() - starttime
inform('Done! Data imported in %.3f seconds.\n' % endtime) inform('Done! Data imported in %.3f seconds.\n' % endtime)
Window.EditMode(0)
Window.FileSelector(filesel_callback, "Import AC3D", "*.ac") Window.FileSelector(filesel_callback, "Import AC3D", "*.ac")