Revision: 17099
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17099
Author:   campbellbarton
Date:     2008-10-18 11:04:25 +0200 (Sat, 18 Oct 2008)

Log Message:
-----------
* 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

Modified Paths:
--------------
    trunk/blender/release/scripts/import_web3d.py

Modified: trunk/blender/release/scripts/import_web3d.py
===================================================================
--- trunk/blender/release/scripts/import_web3d.py       2008-10-17 21:52:50 UTC 
(rev 17098)
+++ trunk/blender/release/scripts/import_web3d.py       2008-10-18 09:04:25 UTC 
(rev 17099)
@@ -810,17 +810,36 @@
                                                                
self.fields.append(value)
                                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):
        '''
        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')
        '''
-       try:    f = open(path, 'rU')
-       except: return None, 'Failed to open file: ' + path
+       data = gzipOpen(path)
        
+       if data==None:
+               return None, 'Failed to open file: ' + path
+       
        # Stripped above
-       lines[:] = vrmlFormat( f.read() )
-       f.close()
+       lines[:] = vrmlFormat( data )
+       
        lines.insert(0, '{')
        lines.insert(0, 'dymmy_node')
        lines.append('}')
@@ -933,9 +952,14 @@
        '''
        
        # 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:
                x3dnode = doc.getElementsByTagName('X3D')[0]
        except:
@@ -1094,7 +1118,7 @@
        # VRML not x3d
        #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)
        else:           coord = []
@@ -1168,7 +1192,6 @@
                        # faces with 1 verts? pfft!
                        # still will affect index ordering
                        pass
-               
        
        face = []
        fuvs = []
@@ -1176,7 +1199,10 @@
        for i, fi in enumerate(ifs_faces):
                # ifs_texfaces and ifs_faces should be aligned
                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 i >= len(ifs_texfaces):
@@ -1196,6 +1222,7 @@
        
        bpymesh = bpy.data.meshes.new()
        
+       bpymesh.verts.extend([(0,0,0)]) # EEKADOODLE
        bpymesh.verts.extend(ifs_points)
        
        # print len(ifs_points), faces, edges, ngons
@@ -1336,10 +1363,14 @@
                                        for i,c in enumerate(fcol):
                                                c.r, c.g, c.b = col
        
+       bpymesh.verts.delete([0,]) # EEKADOODLE
+       
        return bpymesh, ccw
 
 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)
        else:           points = []
        
@@ -1387,7 +1418,9 @@
 
 
 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)
        else:           points = []
        


_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to