[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [18787] trunk/blender/release/scripts/ bpymodules/paths_svg2obj.py: patch for paths_svg2obj.py by author jms:
Remigiusz Fiedler
migius at 4d-vectors.de
Mon Feb 2 01:31:49 CET 2009
Revision: 18787
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18787
Author: migius
Date: 2009-02-02 01:31:46 +0100 (Mon, 02 Feb 2009)
Log Message:
-----------
patch for paths_svg2obj.py by author jms:
This patch solves some major problems of the svg script :
- reading of the inkscape svg format
- parsing of the scientific numbers
- redundant arc data in the same path for only one command "a"
- blending of curves after several files import and at the end a more correct management of the current point.
Modified Paths:
--------------
trunk/blender/release/scripts/bpymodules/paths_svg2obj.py
Modified: trunk/blender/release/scripts/bpymodules/paths_svg2obj.py
===================================================================
--- trunk/blender/release/scripts/bpymodules/paths_svg2obj.py 2009-02-01 19:53:24 UTC (rev 18786)
+++ trunk/blender/release/scripts/bpymodules/paths_svg2obj.py 2009-02-02 00:31:46 UTC (rev 18787)
@@ -1,7 +1,7 @@
# -*- coding: latin-1 -*-
"""
-SVG 2 OBJ translater, 0.5.9h
-Copyright (c) jm soler juillet/novembre 2004-april 2007,
+SVG 2 OBJ translater, 0.5.9n
+Copyright (c) jm soler juillet/novembre 2004-february 2009,
# ---------------------------------------------------------------
released under GNU Licence
for the Blender 2.42 Python Scripts Bundle.
@@ -20,7 +20,6 @@
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
MA 02111-1307, \xC9tats-Unis.
-
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
@@ -35,7 +34,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# ---------------------------------------------------------------
-
+#
#---------------------------------------------------------------------------
# Page officielle :
# http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_import_svg.htm
@@ -253,15 +252,27 @@
0.5.9h : - 2007/5/2
- script was updated with the modifs by cambo
- - removed all debug statements
+ - removed all debug statements
- correction of a zero division error in the calc_arc function.
+ 0.5.9f: - 2007/15/7
+ - Correction de plusieurs bugs sur l'attributions des couleurs et le nommage
+ des courbes
+
+ 0.5.9i : - ??/??/??
+ - Patch externe r\xE9alis\xE9 sur blender.org project.
+
+ 0.5.9j : - 08/11/2008
+ 0.5.9k : - 14/01/2009
+ 0.5.9l : - 31/01/2009
+ 0.5.9n : - 01/02/2009
+
==================================================================================
=================================================================================="""
SHARP_IMPORT=0
SCALE=1
scale_=1
-DEBUG = 0#print
+DEBUG = 0
DEVELOPPEMENT=0
TESTCOLOR=0
@@ -533,7 +544,7 @@
scene.objects.selected = []
if not SEPARATE_CURVES:
- c = Curve.New()
+ c = Curve.New()
c.setResolu(24)
MATNAME=[]
@@ -709,7 +720,6 @@
else : cx =float(prp['cx'])
if 'cy' not in prp: cy=0.0
else : cy =float(prp['cy'])
- #print prp.keys()
r = float(prp['r'])
D=['M',str(cx),str(cy+r),
'C',str(cx-r), str(cy+r*0.552),str(cx-0.552*r),str(cy+r), str(cx),str(cy+r),
@@ -852,7 +862,7 @@
#--------------------
# 0.3.9
#--------------------
-def curve_to_a(c,D,n0,CP): #A,a
+def curve_to_a(curves, c,D,n0,CP): #A,a
global SCALE
l=[float(D[c[1]+1]),float(D[c[1]+2]),float(D[c[1]+3]),
int(D[c[1]+4]),int(D[c[1]+5]),float(D[c[1]+6]),float(D[c[1]+7])]
@@ -866,8 +876,7 @@
POINTS= calc_arc (CP[0],CP[1],
l[0], l[1], l[2]*(PI / 180.0),
l[3], l[4],
- l[5], l[6] )
- #if DEBUG == 1 : print POINTS
+ l[5], l[6] )
for p in POINTS :
B=Bez()
B.co=[ p[2][0],p[2][1], p[0][0],p[0][1], p[1][0],p[1][1]]
@@ -881,16 +890,23 @@
BP.co[2]=BP.co[0]
BP.co[3]=BP.co[1]
CP=[l[5], l[6]]
+ #---------- 059m------------
+ if len(D)>c[1]+7 and D[c[1]+8] not in TAGcourbe :
+ c[1]+=7
+ curves,n0,CP=curve_to_a(curves, c, D, n0,CP)
+ #---------- 059m------------
return curves,n0,CP
-def move_to(c, D, n0,CP, proprietes):
+def move_to(curves, c, D, n0,CP, proprietes):
global DEBUG,TAGcourbe, LAST_ID
global USE_COLORS
l=[float(D[c[1]+1]),float(D[c[1]+2])]
+
if c[0]=='m':
l=[l[0]+CP[0],
l[1] + CP[1]]
+
if n0 in curves.ITEM:
n0+=1
CP=[l[0],l[1]]
@@ -917,14 +933,12 @@
B.co=[CP[0],CP[1],CP[0],CP[1],CP[0],CP[1]]
B.ha=['L','C']
B.tag=c[0]
- curves.ITEM[n0].beziers_knot.append(B)
- #if DEBUG==1: print curves.ITEM[n0], CP
+ curves.ITEM[n0].beziers_knot.append(B)
return curves,n0,CP
-def close_z(c,D,n0,CP): #Z,z
+def close_z(curves, c,D,n0,CP): #Z,z
curves.ITEM[n0].flagUV[0]=1
if len(curves.ITEM[n0].beziers_knot)>1:
- #print len(curves.ITEM[n0].beziers_knot)
BP=curves.ITEM[n0].beziers_knot[-1]
BP0=curves.ITEM[n0].beziers_knot[0]
if BP.tag in ['c','C','s','S',]:
@@ -936,7 +950,7 @@
n0-=1
return curves,n0,CP
-def curve_to_q(c,D,n0,CP): #Q,q
+def curve_to_q(curves, c,D,n0,CP): #Q,q
l=[float(D[c[1]+1]),float(D[c[1]+2]),float(D[c[1]+3]),float(D[c[1]+4])]
if c[0]=='q':
l=[l[0]+CP[0], l[1]+CP[1], l[2]+CP[0], l[3]+CP[1]]
@@ -948,15 +962,14 @@
BP.co[2]=BP.co[0]
BP.co[3]=BP.co[1]
curves.ITEM[n0].beziers_knot.append(B)
- #if DEBUG==1: print B.co,BP.co
CP=[l[2],l[3]]
#if DEBUG==1: pass
if len(D)>c[1]+5 and D[c[1]+5] not in TAGcourbe :
c[1]+=4
- curve_to_q(c, D, n0,CP)
+ curves,n0,CP=curve_to_q(curves, c, D, n0,CP)
return curves,n0,CP
-def curve_to_t(c,D,n0,CP): #T,t
+def curve_to_t(curves, c,D,n0,CP): #T,t
l=[float(D[c[1]+1]),float(D[c[1]+2])]
if c[0]=='t':
l=[l[0]+CP[0], l[1]+CP[1]]
@@ -970,11 +983,10 @@
BP.co[2]=l0[2]
BP.co[3]=l0[3]
curves.ITEM[n0].beziers_knot.append(B)
- #if DEBUG==1: print B.co,BP.co
CP=[l[0],l[1]]
if len(D)>c[1]+3 and D[c[1]+3] not in TAGcourbe :
c[1]+=4
- curve_to_t(c, D, n0,CP)
+ curves,n0,CP=curve_to_t(curves, c, D, n0,CP)
return curves,n0,CP
#--------------------
@@ -985,7 +997,7 @@
Y=l[3]-(l[1]-l[3])
return X,Y
-def curve_to_s(c,D,n0,CP): #S,s
+def curve_to_s(curves, c,D,n0,CP): #S,s
l=[float(D[c[1]+1]),
float(D[c[1]+2]),
float(D[c[1]+3]),
@@ -1003,17 +1015,16 @@
#--------------------
BP.co[2],BP.co[3]=build_SYMETRIC([BP.co[4],BP.co[5],BP.co[0],BP.co[1]])
curves.ITEM[n0].beziers_knot.append(B)
- #if DEBUG==1: print B.co,BP.co
#--------------------
# 0.4.3
#--------------------
CP=[l[2],l[3]]
if len(D)>c[1]+5 and D[c[1]+5] not in TAGcourbe :
c[1]+=4
- curve_to_c(c, D, n0,CP)
+ curves,n0,CP=curve_to_c(curves, c, D, n0,CP)
return curves,n0,CP
-def curve_to_c(c, D, n0,CP): #c,C
+def curve_to_c(curves, c, D, n0,CP): #c,C
l=[float(D[c[1]+1]),float(D[c[1]+2]),float(D[c[1]+3]),
float(D[c[1]+4]),float(D[c[1]+5]),float(D[c[1]+6])]
if c[0]=='c':
@@ -1030,6 +1041,8 @@
l[5],
l[2],
l[3]] #plus toucher au 2-3
+
+
B.ha=['C','C']
B.tag=c[0]
BP=curves.ITEM[n0].beziers_knot[-1]
@@ -1037,32 +1050,38 @@
BP.co[3]=l[1]
BP.ha[1]='C'
curves.ITEM[n0].beziers_knot.append(B)
- #if DEBUG==1: print B.co,BP.co
CP=[l[4],l[5]]
if len(D)>c[1]+7 and D[c[1]+7] not in TAGcourbe :
- c[1]+=6
- curve_to_c(c, D, n0,CP)
+ c[1]+=6
+ curves,n0,CP=curve_to_c(curves, c, D, n0,CP)
return curves,n0,CP
-def draw_line_l(c, D, n0,CP): #L,l
- l=[float(D[c[1]+1]),float(D[c[1]+2])]
+def draw_line_l(curves, c, D, n0,CP): #L,l
+
+ l=[float(D[c[1]+1]),float(D[c[1]+2])]
if c[0]=='l':
l=[l[0]+CP[0],
- l[1]+CP[1]]
+ l[1]+CP[1]]
B=Bez()
- B.co=[l[0],l[1],l[0],l[1],l[0],l[1]]
+ B.co=[l[0],l[1],
+ l[0],l[1],
+ l[0],l[1]]
+
B.ha=['L','L']
B.tag=c[0]
BP=curves.ITEM[n0].beziers_knot[-1]
BP.ha[1]='L'
+
curves.ITEM[n0].beziers_knot.append(B)
- CP=[B.co[0],B.co[1]]
+ CP=[B.co[4],B.co[5]]
+
if len(D)>c[1]+3 and D[c[1]+3] not in TAGcourbe :
c[1]+=2
- draw_line_l(c, D, n0,CP) #L
+ curves,n0,CP=draw_line_l(curves, c, D, n0,CP) #L
+
return curves,n0,CP
-def draw_line_h(c,D,n0,CP): #H,h
+def draw_line_h(curves, c,D,n0,CP): #H,h
if c[0]=='h':
l=[float(D[c[1]+1])+float(CP[0]),CP[1]]
else:
@@ -1077,7 +1096,7 @@
CP=[l[0],l[1]]
return curves,n0,CP
-def draw_line_v(c,D,n0,CP): #V, v
+def draw_line_v(curves, c,D,n0,CP): #V, v
if c[0]=='v':
l=[CP[0], float(D[c[1]+1])+CP[1]]
else:
@@ -1121,17 +1140,31 @@
tagTRANSFORM=0
def wash_DATA(ndata):
- if ndata:
- #if DEBUG==1: print ndata
+ if ndata:
ndata = ndata.strip()
+
if ndata[0]==',':ndata=ndata[1:]
if ndata[-1]==',':ndata=ndata[:-1]
+
#--------------------
# 0.4.0 : 'e'
#--------------------
- i = ndata.find('-')
- if i != -1 and ndata[i-1] not in ' ,e':
- ndata=ndata.replace('-',',-')
+ ni=0
+ i = ndata.find('-',ni)
+ if i != -1:
+ while i>-1 :
+ i = ndata.find('-',ni)
+ # 059l ------
+ if i>0 :
+ if ndata[i-1] not in [' ',',','e']:
+ ndata=ndata[:i]+','+ndata[i:]
+ ni=i+2
+ else:
+ ni=i+1
+ elif i>-1:
+ ni=1
+ # 059l ------
+
ndata=ndata.replace(',,',',')
ndata=ndata.replace(' ',',')
ndata=ndata.split(',')
@@ -1153,7 +1186,7 @@
# borner les differents segments qui devront etre
# traites
# pour cela construire une liste avec chaque
- # la position de chaqe emplacement tag de type
+ # position de chaque emplacement tag de type
# commande path...
# ----------------------------------------
tagplace=[]
@@ -1169,8 +1202,10 @@
# d'apparition des tags
#------------------------------------------
tagplace.sort()
+
+ tpn=range(len(tagplace))
- tpn=range(len(tagplace))
+
#--------------------
# 0.3.5 :: short data, only one tag
#--------------------
@@ -1179,14 +1214,18 @@
for t in tpn[:-1]:
DATA2.append(DATA[tagplace[t]:tagplace[t]+1])
ndata=DATA[tagplace[t]+1:tagplace[t+1]]
+
if DATA2[-1] not in ['z','Z'] :
ndata=wash_DATA(ndata)
DATA2.extend(ndata)
+
DATA2.append(DATA[tagplace[t+1]:tagplace[t+1]+1])
+
if DATA2[-1] not in ['z','Z'] and len(DATA)-1>=tagplace[t+1]+1:
ndata=DATA[tagplace[t+1]+1:]
ndata=wash_DATA(ndata)
DATA2.extend(ndata) #059a
+
else:
#--------------------
# 0.3.5 : short data,only one tag
@@ -1276,15 +1315,13 @@
nt0=txt[t0:t1+1]
t2=nt0[nt0.find('(')+1:-1]
val=nt0[:nt0.find('(')]
+
while t2.find(' ')!=-1:
t2=t2.replace(' ',' ')
+ while t2.find(', ')!=-1: #059l
+ t2=t2.replace(', ',',') #059l
+
t2=t2.replace(' ',',')
-
- """
- t2=t2.split(',')
- for index, t in enumerate(t2):
- t2[index]=float(t)
- """
t2=[float(t) for t in t2.split(',')]
if val=='rotate' :
@@ -1314,12 +1351,24 @@
i= i+6
Courbe[n].color=[int(pr[i:i+2],16),int(pr[i+2:i+4],16),int(pr[i+4:i+6],16)]
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list