[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34243] trunk/blender/release/scripts: initial x3d/vrml importer port from 2.4x.
Campbell Barton
ideasman42 at gmail.com
Tue Jan 11 03:49:02 CET 2011
Revision: 34243
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=34243
Author: campbellbarton
Date: 2011-01-11 02:49:01 +0000 (Tue, 11 Jan 2011)
Log Message:
-----------
initial x3d/vrml importer port from 2.4x.
some files import now.
- no animation support yet
- no rad/deg conversion changes from 2.4x
- matrix multiplication still needs switching.
Modified Paths:
--------------
trunk/blender/release/scripts/op/io_scene_x3d/import_x3d.py
Added Paths:
-----------
trunk/blender/release/scripts/modules/image_utils.py
Added: trunk/blender/release/scripts/modules/image_utils.py
===================================================================
--- trunk/blender/release/scripts/modules/image_utils.py (rev 0)
+++ trunk/blender/release/scripts/modules/image_utils.py 2011-01-11 02:49:01 UTC (rev 34243)
@@ -0,0 +1,27 @@
+# ##### 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>
+
+def image_load(filepath, dirpath, place_holder=False, recursive=False, convert_callback=None):
+ import bpy
+ try:
+ return bpy.data.images.load(filepath)
+ except SystemError:
+ return bpy.data.images.new("Untitled", 128, 128)
+
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-11 02:30:01 UTC (rev 34242)
+++ trunk/blender/release/scripts/op/io_scene_x3d/import_x3d.py 2011-01-11 02:49:01 UTC (rev 34243)
@@ -21,10 +21,7 @@
DEBUG = False
# This should work without a blender at all
-try:
- from Blender.sys import exists
-except:
- from os.path import exists
+from os.path import exists
def baseName(path):
@@ -946,13 +943,13 @@
print(url)
urls = []
urls.append(url)
- urls.append(BPySys.caseInsensitivePath(urls[-1]))
+ urls.append(bpy.path.resolve_ncase(urls[-1]))
urls.append(dirName(self.getFilename()) + url)
- urls.append(BPySys.caseInsensitivePath(urls[-1]))
+ urls.append(bpy.path.resolve_ncase(urls[-1]))
urls.append(dirName(self.getFilename()) + baseName(url))
- urls.append(BPySys.caseInsensitivePath(urls[-1]))
+ urls.append(bpy.path.resolve_ncase(urls[-1]))
try:
url = [url for url in urls if exists(url)][0]
@@ -1192,7 +1189,7 @@
field_list = []
field_context = []
- for j in xrange(len(value)):
+ for j in range(len(value)):
if iskey(value[j]):
if field_context:
# this IS a key but the previous value was not a key, ot it was a defined field.
@@ -1421,16 +1418,14 @@
# NO BLENDER CODE ABOVE THIS LINE.
# -----------------------------------------------------------------------------------
import bpy
-import BPyImage
-import BPySys
-reload(BPySys)
-reload(BPyImage)
-import Blender
-from Blender import Texture, Material, Mathutils, Mesh, Types, Window
-from Blender.Mathutils import TranslationMatrix
-from Blender.Mathutils import RotationMatrix
-from Blender.Mathutils import Vector
-from Blender.Mathutils import Matrix
+import image_utils
+# import BPyImage
+# import BPySys
+# reload(BPySys)
+# reload(BPyImage)
+# import Blender
+# from Blender import Texture, Material, Mathutils, Mesh, Types, Window
+from mathutils import Vector, Matrix
RAD_TO_DEG = 57.29578
@@ -1439,7 +1434,7 @@
def translateRotation(rot):
''' axis, angle '''
- return RotationMatrix(rot[3] * RAD_TO_DEG, 4, 'r', Vector(rot[:3]))
+ return Matrix.Rotation(rot[3] * RAD_TO_DEG, 4, Vector(rot[:3]))
def translateScale(sca):
@@ -1458,7 +1453,7 @@
tx = node.getFieldAsFloatTuple('translation', None, ancestry) # (0.0, 0.0, 0.0)
if cent:
- cent_mat = TranslationMatrix(Vector(cent)).resize4x4()
+ cent_mat = Matrix.Translation(Vector(cent)).resize4x4()
cent_imat = cent_mat.copy().invert()
else:
cent_mat = cent_imat = None
@@ -1480,7 +1475,7 @@
scaori_mat = scaori_imat = None
if tx:
- tx_mat = TranslationMatrix(Vector(tx)).resize4x4()
+ tx_mat = Matrix.Translation(Vector(tx)).resize4x4()
else:
tx_mat = None
@@ -1502,13 +1497,13 @@
if cent:
# cent is at a corner by default
- cent_mat = TranslationMatrix(Vector(cent).resize3D()).resize4x4()
+ cent_mat = Matrix.Translation(Vector(cent).resize3D()).resize4x4()
cent_imat = cent_mat.copy().invert()
else:
cent_mat = cent_imat = None
if rot:
- rot_mat = RotationMatrix(rot * RAD_TO_DEG, 4, 'z') # translateRotation(rot)
+ rot_mat = Matrix.Rotation(rot * RAD_TO_DEG, 4, 'Z') # translateRotation(rot)
else:
rot_mat = None
@@ -1518,7 +1513,7 @@
sca_mat = None
if tx:
- tx_mat = TranslationMatrix(Vector(tx).resize3D()).resize4x4()
+ tx_mat = Matrix.Translation(Vector(tx).resize3D()).resize4x4()
else:
tx_mat = None
@@ -1598,11 +1593,11 @@
if vcolor:
# float to char
ifs_vcol = [(0, 0, 0)] # EEKADOODLE - vertex start at 1
- ifs_vcol.extend([[int(c * 256) for c in col] for col in vcolor.getFieldAsArray('color', 3, ancestry)])
+ ifs_vcol.extend([col for col in vcolor.getFieldAsArray('color', 3, ancestry)])
ifs_color_index = geom.getFieldAsArray('colorIndex', 0, ancestry)
if not ifs_vcol:
- vcolor_spot = [int(c * 256) for c in vcolor.getFieldAsFloatTuple('color', [], ancestry)]
+ vcolor_spot = vcolor.getFieldAsFloatTuple('color', [], ancestry)
# Convert faces into somthing blender can use
edges = []
@@ -1631,7 +1626,7 @@
elif l == 2:
edges.append(face)
elif l > 4:
- for i in xrange(2, len(face)):
+ for i in range(2, len(face)):
faces.append([face[0], face[i - 1], face[i]])
if do_uvmap:
faces_uv.append([fuvs[0], fuvs[i - 1], fuvs[i]])
@@ -1668,21 +1663,24 @@
add_face(face, fuvs, orig_index)
del add_face # dont need this func anymore
- bpymesh = bpy.data.meshes.new()
+ bpymesh = bpy.data.meshes.new(name="XXX")
- bpymesh.verts.extend([(0, 0, 0)]) # EEKADOODLE
- bpymesh.verts.extend(ifs_points)
+ # EEKADOODLE
+ bpymesh.vertices.add(1 + (len(ifs_points)))
+ bpymesh.vertices.foreach_set("co", [0, 0, 0] + [a for v in ifs_points for a in v]) # XXX25 speed
# print(len(ifs_points), faces, edges, ngons)
try:
- bpymesh.faces.extend(faces, smooth=True, ignoreDups=True)
+ bpymesh.faces.add(len(faces))
+ bpymesh.faces.foreach_set("vertices_raw", [a for f in faces for a in (f + [0] if len(f) == 3 else f)]) # XXX25 speed
except KeyError:
print("one or more vert indicies out of range. corrupt file?")
#for f in faces:
# bpymesh.faces.extend(faces, smooth=True)
- bpymesh.calcNormals()
+ # bpymesh.calcNormals()
+ bpymesh.update()
if len(bpymesh.faces) != len(faces):
print('\tWarning: adding faces did not work! file is invalid, not adding UVs or vcolors')
@@ -1694,17 +1692,18 @@
if coords_tex:
#print(ifs_texpoints)
# print(geom)
- bpymesh.faceUV = True
- for i, f in enumerate(bpymesh.faces):
+ uvlay = bpymesh.uv_textures.new()
+
+ for i, f in enumerate(uvlay.data):
f.image = bpyima
fuv = faces_uv[i] # uv indicies
for j, uv in enumerate(f.uv):
# print(fuv, j, len(ifs_texpoints))
try:
- uv[:] = ifs_texpoints[fuv[j]]
+ f.uv[j] = ifs_texpoints[fuv[j]] # XXX25, speedup
except:
print('\tWarning: UV Index out of range')
- uv[:] = ifs_texpoints[0]
+ f.uv[j] = ifs_texpoints[0] # XXX25, speedup
elif bpyima and len(bpymesh.faces):
# Oh Bugger! - we cant really use blenders ORCO for for texture space since texspace dosnt rotate.
@@ -1768,30 +1767,37 @@
# This should be safe because when 2 axies have the same length, the lower index will be used.
axis_v += 1
- bpymesh.faceUV = True
+ uvlay = bpymesh.uv_textures.new()
# HACK !!! - seems to be compatible with Cosmo though.
depth_v = depth_u = max(depth_v, depth_u)
- for f in bpymesh.faces:
+ bpymesh_vertices = bpymesh.vertices[:]
+ bpymesh_faces = bpymesh.faces[:]
+
+ for j, f in enumerate(uvlay.data):
f.image = bpyima
fuv = f.uv
+ f_v = bpymesh_faces[j].vertices[:] # XXX25 speed
- for i, v in enumerate(f):
- co = v.co
- fuv[i][:] = (co[axis_u] - min_u) / depth_u, (co[axis_v] - min_v) / depth_v
+ for i, v in enumerate(f_v):
+ co = bpymesh_vertices[v].co
+ fuv[i] = (co[axis_u] - min_u) / depth_u, (co[axis_v] - min_v) / depth_v
# Add vcote
if vcolor:
# print(ifs_vcol)
- bpymesh.vertexColors = True
+ collay = bpymesh.vertex_colors.new()
- for f in bpymesh.faces:
- fcol = f.col
+ for j, f in enumerate(collay.data):
+ fv = bpymesh.faces[j].vertices[:]
+ if len(fv) == 3: # XXX speed
+ fcol = f.color1, f.color2, f.color3
+ else:
+ fcol = f.color1, f.color2, f.color3, f.color4
if ifs_colorPerVertex:
- fv = f.verts
for i, c in enumerate(fcol):
- color_index = fv[i].index # color index is vert index
+ color_index = fv[i] # color index is vert index
if ifs_color_index:
try:
color_index = ifs_color_index[color_index]
@@ -1820,12 +1826,10 @@
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list