[Bf-extensions-cvs] [dc618d9] temp-x3d_import-T44758: - PEP8 compliance in my code, legacy code left intact - Fixed the straight spine extrusion bug (exception in the airplane model) - Texture/material caching
Seva Alekseyev
noreply at git.blender.org
Fri May 22 21:26:54 CEST 2015
Commit: dc618d925f79d94a0563f75ae4932d944b685107
Author: Seva Alekseyev
Date: Fri May 22 15:04:43 2015 -0400
Branches: temp-x3d_import-T44758
https://developer.blender.org/rBAdc618d925f79d94a0563f75ae4932d944b685107
- PEP8 compliance in my code, legacy code left intact
- Fixed the straight spine extrusion bug (exception in the airplane model)
- Texture/material caching
===================================================================
M io_scene_x3d/import_x3d.py
===================================================================
diff --git a/io_scene_x3d/import_x3d.py b/io_scene_x3d/import_x3d.py
index 7fbe381..76a4d81 100644
--- a/io_scene_x3d/import_x3d.py
+++ b/io_scene_x3d/import_x3d.py
@@ -1,3160 +1,3520 @@
-# ##### BEGIN GPL LICENSE BLOCK #####
-#
-# 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.
-#
-# 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.
-#
-# ##### END GPL LICENSE BLOCK #####
-
-# <pep8 compliant>
-
-DEBUG = False
-
-# This should work without a blender at all
-import os
-import shlex
-import math
-from math import sin, cos, pi
-
-EPSILON = 0.0000001 # Very crude.
-
-def imageConvertCompat(path):
-
- if os.sep == '\\':
- return path # assume 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 os.path.exists(path_to):
- return path_to
-
- return path
-
-# notes
-# transform are relative
-# order dosnt matter for loc/size/rot
-# right handed rotation
-# angles are in radians
-# rotation first defines axis then amount in radians
-
-
-# =============================== VRML Spesific
-
-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 is 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 separate
-
- 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]
-
-NODE_NORMAL = 1 # {}
-NODE_ARRAY = 2 # []
-NODE_REFERENCE = 3 # USE foobar
-# NODE_PROTO = 4 #
-
-lines = []
-
-
-def getNodePreText(i, words):
- # print(lines[i])
- use_node = False
- while len(words) < 5:
-
- if i >= len(lines):
- break
- '''
- elif lines[i].startswith('PROTO'):
- return NODE_PROTO, i+1
- '''
- elif lines[i] == '{':
- # words.append(lines[i]) # no need
- # print("OK")
- return NODE_NORMAL, i + 1
- elif lines[i].count('"') % 2 != 0: # odd number of quotes? - part of a string.
- # print('ISSTRING')
- break
- else:
- new_words = lines[i].split()
- if 'USE' in new_words:
- use_node = True
-
- words.extend(new_words)
- i += 1
-
- # Check for USE node - no {
- # USE #id - should always be on the same line.
- if use_node:
- # print('LINE', i, words[:words.index('USE')+2])
- words[:] = words[:words.index('USE') + 2]
- if lines[i] == '{' and lines[i + 1] == '}':
- # USE sometimes has {} after it anyway
- i += 2
- return NODE_REFERENCE, i
-
- # print("error value!!!", words)
- return 0, -1
-
-
-def is_nodeline(i, words):
-
- if not lines[i][0].isalpha():
- return 0, 0
-
- #if lines[i].startswith('field'):
- # return 0, 0
-
- # Is this a prototype??
- if lines[i].startswith('PROTO'):
- words[:] = lines[i].split()
- return NODE_NORMAL, i + 1 # TODO - assumes the next line is a '[\n', skip that
- if lines[i].startswith('EXTERNPROTO'):
- words[:] = lines[i].split()
- return NODE_ARRAY, i + 1 # TODO - assumes the next line is a '[\n', skip that
-
- '''
- proto_type, new_i = is_protoline(i, words, proto_field_defs)
- if new_i != -1:
- return proto_type, new_i
- '''
-
- # Simple "var [" type
- if lines[i + 1] == '[':
- if lines[i].count('"') % 2 == 0:
- words[:] = lines[i].split()
- return NODE_ARRAY, i + 2
-
- node_type, new_i = getNodePreText(i, words)
-
- if not node_type:
- if DEBUG:
- print("not node_type", lines[i])
- return 0, 0
-
- # Ok, we have a { after some values
- # Check the values are not fields
- for i, val in enumerate(words):
- if i != 0 and words[i - 1] in {'DEF', 'USE'}:
- # ignore anything after DEF, it is a ID and can contain any chars.
- pass
- elif val[0].isalpha() and val not in {'TRUE', 'FALSE'}:
- pass
- else:
- # There is a number in one of the values, therefor we are not a node.
- return 0, 0
-
- #if node_type==NODE_REFERENCE:
- # print(words, "REF_!!!!!!!")
- return node_type, new_i
-
-
-def is_numline(i):
- """
- Does this line start with a number?
- """
-
- # Works but too slow.
- '''
- l = lines[i]
- for w in l.split():
- if w==',':
- pass
- else:
- try:
- float(w)
- return True
-
- except:
- return False
-
- return False
- '''
-
- l = lines[i]
-
- line_start = 0
-
- if l.startswith(', '):
- line_start += 2
-
- line_end = len(l) - 1
- line_end_new = l.find(' ', line_start) # comma's always have a space before them
-
- if line_end_new != -1:
- line_end = line_end_new
-
- try:
- float(l[line_start:line_end]) # works for a float or int
- return True
- except:
- return False
-
-
-class vrmlNode(object):
- __slots__ = ('id',
- 'fields',
- 'proto_node',
- 'proto_field_defs',
- 'proto_fields',
- 'node_type',
- 'parent',
- 'children',
- 'parent',
- 'array_data',
- 'reference',
- 'lineno',
- 'filename',
- 'blendObject',
- 'DEF_NAMESPACE',
- 'ROUTE_IPO_NAMESPACE',
- 'PROTO_NAMESPACE',
- 'x3dNode',
- 'parsed')
-
- def __init__(self, parent, node_type, lineno):
- self.id = None
- self.node_type = node_type
- self.parent = parent
- self.blendObject = None
- self.x3dNode = None # for x3d import only
- self.parsed = None # We try to reuse objects in a smart way
- if parent:
- parent.children.append(self)
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list