[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34229] trunk/blender/release/scripts/op/ io_scene_x3d/import_x3d.py: x3d import tabs -> spaces

Campbell Barton ideasman42 at gmail.com
Mon Jan 10 14:16:04 CET 2011


Revision: 34229
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=34229
Author:   campbellbarton
Date:     2011-01-10 13:16:04 +0000 (Mon, 10 Jan 2011)
Log Message:
-----------
x3d import tabs -> spaces

Modified Paths:
--------------
    trunk/blender/release/scripts/op/io_scene_x3d/import_x3d.py

Modified: trunk/blender/release/scripts/op/io_scene_x3d/import_x3d.py
===================================================================
--- trunk/blender/release/scripts/op/io_scene_x3d/import_x3d.py	2011-01-10 13:11:56 UTC (rev 34228)
+++ trunk/blender/release/scripts/op/io_scene_x3d/import_x3d.py	2011-01-10 13:16:04 UTC (rev 34229)
@@ -1,78 +1,60 @@
-#!BPY
-"""
-Name: 'X3D & VRML97 (.x3d / wrl)...'
-Blender: 248
-Group: 'Import'
-Tooltip: 'Load an X3D or VRML97 file'
-"""
-
-# ***** BEGIN GPL LICENSE BLOCK *****
+# ##### BEGIN GPL LICENSE BLOCK #####
 #
-# (C) Copyright 2008 Paravizion
-# Written by Campbell Barton aka Ideasman42
+#  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 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.
 #
-# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 #
-# 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 *****
-# --------------------------------------------------------------------------
+# ##### END GPL LICENSE BLOCK #####
 
-__author__ = "Campbell Barton"
-__url__ = ['www.blender.org', 'blenderartists.org', 'http://wiki.blender.org/index.php/Scripts/Manual/Import/X3D_VRML97']
-__version__ = "0.1"
+# <pep8 compliant>
 
-__bpydoc__ = """\
-This script is an importer for the X3D and VRML97 file formats.
-"""
-
 DEBUG = False
 
 # This should work without a blender at all
 try:
-	from Blender.sys import exists
+    from Blender.sys import exists
 except:
-	from os.path import exists
+    from os.path import exists
 
 def baseName(path):
-	return path.split('/')[-1].split('\\')[-1]
+    return path.split('/')[-1].split('\\')[-1]
 
 def dirName(path):
-	return path[:-len(baseName(path))]
+    return path[:-len(baseName(path))]
 
 def imageConvertCompat(path):
-	
-	try:             import os
-	except:          return path
-	if os.sep=='\\': return path # assime win32 has quicktime, dont convert
-	
-	if path.lower().endswith('.gif'):
-		path_to = path[:-3] + 'png'
-		
-		'''
-		if exists(path_to):
-			return path_to
-		'''
-		# print '\n'+path+'\n'+path_to+'\n'
-		os.system('convert "%s" "%s"' % (path, path_to)) # for now just hope we have image magick
-		
-		if exists(path_to):
-			return path_to
-	
-	return path
 
+    try:             import os
+    except:          return path
+    if os.sep=='\\': return path # assime win32 has quicktime, dont convert
+
+    if path.lower().endswith('.gif'):
+        path_to = path[:-3] + 'png'
+
+        '''
+        if exists(path_to):
+            return path_to
+        '''
+        # print '\n'+path+'\n'+path_to+'\n'
+        os.system('convert "%s" "%s"' % (path, path_to)) # for now just hope we have image magick
+
+        if exists(path_to):
+            return path_to
+
+    return path
+
 # notes
-# transform are relative 
+# transform are relative
 # order dosnt matter for loc/size/rot
 # right handed rotation
 # angles are in radians
@@ -84,122 +66,122 @@
 
 
 def vrmlFormat(data):
-	'''
-	Keep this as a valid vrml file, but format in a way we can predict.
-	'''
-	# Strip all commends - # not in strings - warning multiline strings are ignored.
-	def strip_comment(l):
-		#l = ' '.join(l.split())
-		l = l.strip()
-		
-		if l.startswith('#'):
-			return ''
-		
-		i = l.find('#')
-		
-		if i==-1:
-			return l
-		
-		# Most cases accounted for! if we have a comment at the end of the line do this...
-		#j = l.find('url "')
-		j = l.find('"')
-		
-		if j == -1: # simple no strings
-			return l[:i].strip()
-		
-		q = False
-		for i,c in enumerate(l):
-			if c == '"':
-				q = not q # invert
-			
-			elif c == '#':
-				if q==False:
-					return l[:i-1]
-		
-		return l
-	
-	data = '\n'.join([strip_comment(l) for l in data.split('\n') ]) # remove all whitespace
-	
-	EXTRACT_STRINGS = True # only needed when strings or filesnames containe ,[]{} chars :/
-	
-	if EXTRACT_STRINGS:
-		
-		# We need this so we can detect URL's
-		data = '\n'.join([' '.join(l.split()) for l in data.split('\n')]) # remove all whitespace
-		
-		string_ls = []
-		
-		#search = 'url "'
-		search = '"'
-		
-		ok = True
-		last_i = 0
-		while ok:
-			ok = False
-			i = data.find(search, last_i)
-			if i != -1:
-				
-				start = i + len(search) # first char after end of search
-				end = data.find('"', start)
-				if end != -1:
-					item = data[start:end]
-					string_ls.append( item )
-					data = data[:start] + data[end:]
-					ok = True # keep looking
-					
-					last_i = (end - len(item)) + 1
-					# print last_i, item, '|' + data[last_i] + '|'
-		
-	# done with messy extracting strings part
-	
-	
-	# Bad, dont take strings into account
-	'''
-	data = data.replace('#', '\n#')
-	data = '\n'.join([ll for l in data.split('\n') for ll in (l.strip(),) if not ll.startswith('#')]) # remove all whitespace
-	'''
-	data = data.replace('{', '\n{\n')
-	data = data.replace('}', '\n}\n')
-	data = data.replace('[', '\n[\n')
-	data = data.replace(']', '\n]\n')
-	data = data.replace(',', ' , ') # make sure comma's seperate
-	
-	if EXTRACT_STRINGS:
-		# add strings back in 
-		
-		search = '"' # fill in these empty strings
-		
-		ok = True
-		last_i = 0
-		while ok:
-			ok = False
-			i = data.find(search + '"', last_i)
-			# print i
-			if i != -1:
-				start = i + len(search) # first char after end of search
-				item = string_ls.pop(0)
-				# print item
-				data = data[:start] + item + data[start:]
-				
-				last_i = start + len(item) + 1
-				
-				ok = True
-	
-	
-	# More annoying obscure cases where USE or DEF are placed on a newline
-	# data = data.replace('\nDEF ', ' DEF ')
-	# data = data.replace('\nUSE ', ' USE ')
-	
-	data = '\n'.join([' '.join(l.split()) for l in data.split('\n')]) # remove all whitespace
-	
-	# Better to parse the file accounting for multiline arrays
-	'''
-	data = data.replace(',\n', ' , ') # remove line endings with commas
-	data = data.replace(']', '\n]\n') # very very annoying - but some comma's are at the end of the list, must run this again.
-	'''
-	
-	return [l for l in data.split('\n') if l]
+    '''
+    Keep this as a valid vrml file, but format in a way we can predict.
+    '''
+    # Strip all commends - # not in strings - warning multiline strings are ignored.
+    def strip_comment(l):
+        #l = ' '.join(l.split())
+        l = l.strip()
 
+        if l.startswith('#'):
+            return ''
+
+        i = l.find('#')
+
+        if i==-1:
+            return l
+
+        # Most cases accounted for! if we have a comment at the end of the line do this...
+        #j = l.find('url "')
+        j = l.find('"')
+
+        if j == -1: # simple no strings
+            return l[:i].strip()
+
+        q = False
+        for i,c in enumerate(l):
+            if c == '"':
+                q = not q # invert
+
+            elif c == '#':
+                if q==False:
+                    return l[:i-1]
+
+        return l
+
+    data = '\n'.join([strip_comment(l) for l in data.split('\n') ]) # remove all whitespace
+
+    EXTRACT_STRINGS = True # only needed when strings or filesnames containe ,[]{} chars :/
+
+    if EXTRACT_STRINGS:
+
+        # We need this so we can detect URL's
+        data = '\n'.join([' '.join(l.split()) for l in data.split('\n')]) # remove all whitespace
+
+        string_ls = []
+
+        #search = 'url "'
+        search = '"'
+
+        ok = True
+        last_i = 0
+        while ok:
+            ok = False
+            i = data.find(search, last_i)
+            if i != -1:
+
+                start = i + len(search) # first char after end of search
+                end = data.find('"', start)
+                if end != -1:
+                    item = data[start:end]
+                    string_ls.append( item )
+                    data = data[:start] + data[end:]
+                    ok = True # keep looking
+
+                    last_i = (end - len(item)) + 1
+                    # print last_i, item, '|' + data[last_i] + '|'
+
+    # done with messy extracting strings part
+
+
+    # Bad, dont take strings into account
+    '''
+    data = data.replace('#', '\n#')
+    data = '\n'.join([ll for l in data.split('\n') for ll in (l.strip(),) if not ll.startswith('#')]) # remove all whitespace
+    '''
+    data = data.replace('{', '\n{\n')
+    data = data.replace('}', '\n}\n')
+    data = data.replace('[', '\n[\n')
+    data = data.replace(']', '\n]\n')
+    data = data.replace(',', ' , ') # make sure comma's seperate
+
+    if EXTRACT_STRINGS:
+        # add strings back in
+
+        search = '"' # fill in these empty strings
+
+        ok = True
+        last_i = 0
+        while ok:
+            ok = False
+            i = data.find(search + '"', last_i)
+            # print i
+            if i != -1:
+                start = i + len(search) # first char after end of search
+                item = string_ls.pop(0)
+                # print item
+                data = data[:start] + item + data[start:]
+
+                last_i = start + len(item) + 1
+
+                ok = True
+
+
+    # More annoying obscure cases where USE or DEF are placed on a newline
+    # data = data.replace('\nDEF ', ' DEF ')
+    # data = data.replace('\nUSE ', ' USE ')
+
+    data = '\n'.join([' '.join(l.split()) for l in data.split('\n')]) # remove all whitespace
+
+    # Better to parse the file accounting for multiline arrays
+    '''

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list