[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2244] trunk/py/scripts/addons/ io_import_scene_lwo.py: Fixed the way Catmull-Clark edge weights are read and matched to an edge
Ken Nign
ken at virginpi.com
Fri Aug 12 08:32:21 CEST 2011
Revision: 2244
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2244
Author: ken9
Date: 2011-08-12 06:32:21 +0000 (Fri, 12 Aug 2011)
Log Message:
-----------
Fixed the way Catmull-Clark edge weights are read and matched to an edge
Modified Paths:
--------------
trunk/py/scripts/addons/io_import_scene_lwo.py
Modified: trunk/py/scripts/addons/io_import_scene_lwo.py
===================================================================
--- trunk/py/scripts/addons/io_import_scene_lwo.py 2011-08-11 23:28:34 UTC (rev 2243)
+++ trunk/py/scripts/addons/io_import_scene_lwo.py 2011-08-12 06:32:21 UTC (rev 2244)
@@ -35,7 +35,7 @@
# Copyright (c) Ken Nign 2010
# ken at virginpi.com
#
-# Version 1.2 - Sep 7, 2010
+# Version 1.3 - Aug 11, 2011
#
# Loads a LightWave .lwo object file, including the vertex maps such as
# UV, Morph, Color and Weight maps.
@@ -56,6 +56,8 @@
#
# History:
#
+# 1.3 Fixed CC Edge Weight loading.
+#
# 1.2 Added Absolute Morph and CC Edge Weight support.
# Made edge creation safer.
# 1.0 First Release
@@ -609,38 +611,34 @@
return # We just want the Catmull-Clark edge weights
offset+= name_len
- prev_pol= -1
- prev_pnt= -1
- prev_weight= 0.0
- first_pnt= -1
- poly_pnts= 0
+ # Some info: LW stores a face's points in a clock-wize order (with the
+ # normal pointing at you). This gives edges a 'direction' which is used
+ # when it comes to storing CC edge weight values. The weight is given
+ # to the point preceeding the edge that the weight belongs to.
while offset < chunk_len:
- pnt_id, pnt_id_len= read_vx(ew_bytes[offset:offset+4])
+ pnt_id, pnt_id_len = read_vx(ew_bytes[offset:offset+4])
offset+= pnt_id_len
pol_id, pol_id_len= read_vx(ew_bytes[offset:offset+4])
offset+= pol_id_len
-
weight,= struct.unpack(">f", ew_bytes[offset:offset+4])
offset+= 4
- if prev_pol == pol_id:
- # Points on the same poly should define an edge.
- object_layers[-1].edge_weights["{0} {1}".format(prev_pnt, pnt_id)]= weight
- poly_pnts += 1
+
+ face_pnts= object_layers[-1].pols[pol_id]
+ try:
+ # Find the point's location in the polygon's point list
+ first_idx= face_pnts.index(pnt_id)
+ except:
+ continue
+
+ # Then get the next point in the list, or wrap around to the first
+ if first_idx == len(face_pnts) - 1:
+ second_pnt= face_pnts[0]
else:
- if poly_pnts > 2:
- # Make an edge from the first and last points.
- object_layers[-1].edge_weights["{0} {1}".format(first_pnt, prev_pnt)]= prev_weight
- first_pnt= pnt_id
- prev_pol= pol_id
- poly_pnts= 1
+ second_pnt= face_pnts[first_idx + 1]
+
+ object_layers[-1].edge_weights["{0} {1}".format(second_pnt, pnt_id)]= weight
+
- prev_pnt= pnt_id
- prev_weight= weight
-
- if poly_pnts > 2:
- object_layers[-1].edge_weights["{0} {1}".format(first_pnt, prev_pnt)]= prev_weight
-
-
def read_pols(pol_bytes, object_layers):
'''Read the layer's polygons, each one is just a list of point indexes.'''
print("\tReading Layer ("+object_layers[-1].name+") Polygons")
@@ -1257,4 +1255,4 @@
bpy.types.INFO_MT_file_import.remove(menu_func)
if __name__ == "__main__":
- register()
+ register()
\ No newline at end of file
More information about the Bf-extensions-cvs
mailing list