* Fixed eekadoodle problem where faces with a zero index vert in the wrong place would reotate the UVs and VCols incorrectly
* Fixed an error that made IndexedLineSet and IndexedPointSet not load for x3d's * Added support for opening gzip x3d/wrl files
This commit is contained in:
@@ -810,17 +810,36 @@ class vrmlNode(object):
|
|||||||
self.fields.append(value)
|
self.fields.append(value)
|
||||||
i+=1
|
i+=1
|
||||||
|
|
||||||
|
def gzipOpen(path):
|
||||||
|
try: import gzip
|
||||||
|
except: gzip = None
|
||||||
|
|
||||||
|
data = None
|
||||||
|
if gzip:
|
||||||
|
try: data = gzip.open(path, 'r').read()
|
||||||
|
except: pass
|
||||||
|
else:
|
||||||
|
print '\tNote, gzip module could not be imported, compressed files will fail to load'
|
||||||
|
|
||||||
|
if data==None:
|
||||||
|
try: data = open(path, 'rU').read()
|
||||||
|
except: pass
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
def vrml_parse(path):
|
def vrml_parse(path):
|
||||||
'''
|
'''
|
||||||
Sets up the root node and returns it so load_web3d() can deal with the blender side of things.
|
Sets up the root node and returns it so load_web3d() can deal with the blender side of things.
|
||||||
Return root (vrmlNode, '') or (None, 'Error String')
|
Return root (vrmlNode, '') or (None, 'Error String')
|
||||||
'''
|
'''
|
||||||
try: f = open(path, 'rU')
|
data = gzipOpen(path)
|
||||||
except: return None, 'Failed to open file: ' + path
|
|
||||||
|
if data==None:
|
||||||
|
return None, 'Failed to open file: ' + path
|
||||||
|
|
||||||
# Stripped above
|
# Stripped above
|
||||||
lines[:] = vrmlFormat( f.read() )
|
lines[:] = vrmlFormat( data )
|
||||||
f.close()
|
|
||||||
lines.insert(0, '{')
|
lines.insert(0, '{')
|
||||||
lines.insert(0, 'dymmy_node')
|
lines.insert(0, 'dymmy_node')
|
||||||
lines.append('}')
|
lines.append('}')
|
||||||
@@ -933,7 +952,12 @@ def x3d_parse(path):
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
# Could add a try/except here, but a console error is more useful.
|
# Could add a try/except here, but a console error is more useful.
|
||||||
doc = xml.dom.minidom.parse(path)
|
data = gzipOpen(path)
|
||||||
|
|
||||||
|
if data==None:
|
||||||
|
return None, 'Failed to open file: ' + path
|
||||||
|
|
||||||
|
doc = xml.dom.minidom.parseString(data)
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -1094,7 +1118,7 @@ def importMesh_IndexedFaceSet(geom, bpyima):
|
|||||||
# VRML not x3d
|
# VRML not x3d
|
||||||
#coord = geom.getChildByName('coord') # 'Coordinate'
|
#coord = geom.getChildByName('coord') # 'Coordinate'
|
||||||
|
|
||||||
coord = geom.getChildBySpec('Coordinate') # 'Coordinate'
|
coord = geom.getChildBySpec('Coordinate') # works for x3d and vrml
|
||||||
|
|
||||||
if coord: ifs_points = coord.getFieldAsArray('point', 3)
|
if coord: ifs_points = coord.getFieldAsArray('point', 3)
|
||||||
else: coord = []
|
else: coord = []
|
||||||
@@ -1169,14 +1193,16 @@ def importMesh_IndexedFaceSet(geom, bpyima):
|
|||||||
# still will affect index ordering
|
# still will affect index ordering
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
face = []
|
face = []
|
||||||
fuvs = []
|
fuvs = []
|
||||||
orig_index = 0
|
orig_index = 0
|
||||||
for i, fi in enumerate(ifs_faces):
|
for i, fi in enumerate(ifs_faces):
|
||||||
# ifs_texfaces and ifs_faces should be aligned
|
# ifs_texfaces and ifs_faces should be aligned
|
||||||
if fi != -1:
|
if fi != -1:
|
||||||
face.append(int(fi)) # in rare cases this is a float
|
# face.append(int(fi)) # in rare cases this is a float
|
||||||
|
# EEKADOODLE!!!
|
||||||
|
# Annoyance where faces that have a zero index vert get rotated. This will then mess up UVs and VColors
|
||||||
|
face.append(int(fi)+1) # in rare cases this is a float, +1 because of stupid EEKADOODLE :/
|
||||||
|
|
||||||
if do_uvmap:
|
if do_uvmap:
|
||||||
if i >= len(ifs_texfaces):
|
if i >= len(ifs_texfaces):
|
||||||
@@ -1196,6 +1222,7 @@ def importMesh_IndexedFaceSet(geom, bpyima):
|
|||||||
|
|
||||||
bpymesh = bpy.data.meshes.new()
|
bpymesh = bpy.data.meshes.new()
|
||||||
|
|
||||||
|
bpymesh.verts.extend([(0,0,0)]) # EEKADOODLE
|
||||||
bpymesh.verts.extend(ifs_points)
|
bpymesh.verts.extend(ifs_points)
|
||||||
|
|
||||||
# print len(ifs_points), faces, edges, ngons
|
# print len(ifs_points), faces, edges, ngons
|
||||||
@@ -1336,10 +1363,14 @@ def importMesh_IndexedFaceSet(geom, bpyima):
|
|||||||
for i,c in enumerate(fcol):
|
for i,c in enumerate(fcol):
|
||||||
c.r, c.g, c.b = col
|
c.r, c.g, c.b = col
|
||||||
|
|
||||||
|
bpymesh.verts.delete([0,]) # EEKADOODLE
|
||||||
|
|
||||||
return bpymesh, ccw
|
return bpymesh, ccw
|
||||||
|
|
||||||
def importMesh_IndexedLineSet(geom):
|
def importMesh_IndexedLineSet(geom):
|
||||||
coord = geom.getChildByName('coord') # 'Coordinate'
|
# VRML not x3d
|
||||||
|
#coord = geom.getChildByName('coord') # 'Coordinate'
|
||||||
|
coord = geom.getChildBySpec('Coordinate') # works for x3d and vrml
|
||||||
if coord: points = coord.getFieldAsArray('point', 3)
|
if coord: points = coord.getFieldAsArray('point', 3)
|
||||||
else: points = []
|
else: points = []
|
||||||
|
|
||||||
@@ -1387,7 +1418,9 @@ def importMesh_IndexedLineSet(geom):
|
|||||||
|
|
||||||
|
|
||||||
def importMesh_PointSet(geom):
|
def importMesh_PointSet(geom):
|
||||||
coord = geom.getChildByName('coord') # 'Coordinate'
|
# VRML not x3d
|
||||||
|
#coord = geom.getChildByName('coord') # 'Coordinate'
|
||||||
|
coord = geom.getChildBySpec('Coordinate') # works for x3d and vrml
|
||||||
if coord: points = coord.getFieldAsArray('point', 3)
|
if coord: points = coord.getFieldAsArray('point', 3)
|
||||||
else: points = []
|
else: points = []
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user