1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
|
"""
#----------------------------------------------
# (c) jm soler juillet 2004, released under Blender Artistic Licence
# for the Blender 2.34 Python Scripts Bundle.
# update : 04/07/2006
#----------------------------------------------
# Page officielle :
# http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_import_gimp.htm
# Communiquer les problemes et erreurs sur:
# http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender
#---------------------------------------------
"""
SHARP_IMPORT=0
SCALE=1
import sys
#oldpath=sys.path
import Blender
BLversion=Blender.Get('version')
try:
import nt
os=nt
os.sep='\\'
except:
import posix
os=posix
os.sep='/'
def isdir(path):
try:
st = os.stat(path)
return 1
except:
return 0
def split(pathname):
if pathname.find(os.sep)!=-1:
k0=pathname.split(os.sep)
else:
if os.sep=='/':
k0=pathname.split('\\')
else:
k0=pathname.split('/')
directory=pathname.replace(k0[len(k0)-1],'')
Name=k0[len(k0)-1]
return directory, Name
def join(l0,l1):
return l0+os.sep+l1
os.isdir=isdir
os.split=split
os.join=join
def filtreFICHIER(nom):
f=open(nom,'r')
t=f.readlines()
f.close()
if len(t)==1 and t[0].find('\r'):
t=t[0].split('\r')
if len(t)>1 and t[1].find('#POINTS:')==0:
return t
else:
warning = "OK?%t| Not a valid file or an empty file ... " # if no %xN int is set, indices start from 1
result = Blender.Draw.PupMenu(warning)
return "false"
#===============================
# Data
#===============================
#===============================
# Blender Curve Data
#===============================
objBEZIER=0
objSURFACE=5
typBEZIER3D=1 #3D
typBEZIER2D=9 #2D
class Bez:
def __init__(self):
self.co=[]
self.ha=[0,0]
def echo(self):
#print 'co = ', self.co
#print 'ha = ', self.ha
pass
class ITEM:
def __init__(self):
self.type = typBEZIER3D,
self.pntsUV = [0,0]
self.resolUV = [32,0]
self.orderUV = [0,0]
self.flagUV = [0,0]
self.Origine = [0.0,0.0]
self.beziers_knot = []
class COURBE:
def __init__(self):
self.magic_number='3DG3'
self.type = objBEZIER
self.number_of_items = 0
self.ext1_ext2 = [0,0]
self.matrix = """0.0 0.0 1.0 0.0
0.0 1.0 0.0 0.0
0.0 0.0 1.0 0.0
0.0 0.0 0.0 1.0 """ #- right-handed object matrix. Used to determine position, rotation and size
self.ITEM = {}
courbes=COURBE()
PATTERN={}
BOUNDINGBOX={'rec':[],'coef':1.0}
npat=0
#=====================================================================
#======== name of the curve in the courbes dictionnary ===============
#=====================================================================
n0=0
#=====================================================================
#====================== current Point ================================
#=====================================================================
CP=[0.0,0.0] #currentPoint
def MINMAX(b):
global BOUNDINGBOX
r=BOUNDINGBOX['rec']
for m in range(0,len(b)-2,2):
#print m, m+1 , len(b)-1
#print b[m], r, r[0]
if float(b[m])<r[0]:
r[0]=float(b[m])
if float(b[m])>r[2]: r[2]=float(b[m])
if float(b[m+1])<r[1]: r[1]=float(b[m+1])
if float(b[m+1])>r[3]: r[3]=float(b[m+1])
#=====================================================================
#===== to compare last position to the original move to displacement =
#===== needed for cyclic efinition =================================
#=====================================================================
def test_egalitedespositions(f1,f2):
if f1[0]==f2[0] and f1[1]==f2[1]:
return Blender.TRUE
else:
return Blender.FALSE
def Open_GEOfile(dir,nom):
if BLversion>=233:
Blender.Load(dir+nom+'OOO.obj', 1)
BO=Blender.Object.Get()
BO[-1].LocZ=1.0
BO[-1].makeDisplayList()
Blender.Window.RedrawAll()
else:
print "Not yet implemented"
def create_GEOtext(courbes):
global SCALE, B, BOUNDINGBOX
r=BOUNDINGBOX['rec']
if SCALE==1:
SCALE=1.0
elif SCALE==2:
SCALE=r[2]-r[0]
elif SCALE==3:
SCALE=r[3]-r[1]
t=[]
t.append(courbes.magic_number+'\n')
t.append(str(courbes.type)+'\n')
t.append(str(courbes.number_of_items)+'\n')
t.append(str(courbes.ext1_ext2[0])+' '+str(courbes.ext1_ext2[1])+'\n')
t.append(courbes.matrix+'\n')
for k in courbes.ITEM.keys():
t.append("%s\n"%courbes.ITEM[k].type)
t.append("%s %s \n"%(courbes.ITEM[k].pntsUV[0],courbes.ITEM[k].pntsUV[1]))
t.append("%s %s \n"%(courbes.ITEM[k].resolUV[0],courbes.ITEM[k].resolUV[1]))
t.append("%s %s \n"%(courbes.ITEM[k].orderUV[0],courbes.ITEM[k].orderUV[1]))
t.append("%s %s \n"%(courbes.ITEM[k].flagUV[0],courbes.ITEM[k].flagUV[1]))
flag =0#courbes.ITEM[k].flagUV[0]
for k2 in range(flag,len(courbes.ITEM[k].beziers_knot)):
k1 =courbes.ITEM[k].beziers_knot[k2]
t.append("%4f 0.0 %4f \n"%(float(k1.co[0])/SCALE,float(k1.co[1])/SCALE))
t.append("%4f 0.0 %4f \n"%(float(k1.co[4])/SCALE,float(k1.co[5])/SCALE))
t.append("%4f 0.0 %4f \n"%(float(k1.co[2])/SCALE,float(k1.co[3])/SCALE))
t.append(str(k1.ha[0])+' '+str(k1.ha[1])+'\n')
return t
def save_GEOfile(dir,nom,t):
f=open(dir+nom+'OOO.obj','w')
f.writelines(t)
f.close()
#warning = "REMINDER : %t | Do not forget to rename your blender file NOW ! %x1"
#result = Blender.Draw.PupMenu(warning)
#=====================================================================
#===== GIMP format : DEBUT =========================
#=====================================================================
CLOSED=0
def mouvement_vers(l,l1,l2,n0):
global BOUNDINGBOX, CP
if l[1] == '3' :
n0+=1
courbes.ITEM[n0]=ITEM()
courbes.ITEM[n0].Origine=[l[-3],l[-1],]
courbes.ITEM[n0-1].beziers_knot[0].co[0]=CP[0]
courbes.ITEM[n0-1].beziers_knot[0].co[1]=CP[1]
CP=[l2[-3], l2[-1]]
elif l[1]=='1' and (n0 not in courbes.ITEM.keys()):
courbes.ITEM[n0]=ITEM()
courbes.ITEM[n0].Origine=[l[-3],l[-1],]
CP=[l2[-3], l2[-1]]
B=Bez()
B.co=[ CP[0],CP[1],
l1[-3], l1[-1],
l[-3], l[-1]]
CP=[l2[-3], l2[-1]]
if BOUNDINGBOX['rec']==[]:
BOUNDINGBOX['rec']=[float(l2[-3]), float(l2[-1]), float(l[-3]), float(l[-1])]
B.ha=[0,0]
"""
if len( courbes.ITEM[n0].beziers_knot)>=1:
courbes.ITEM[n0].beziers_knot[-1].co[2]=l1[-3]
courbes.ITEM[n0].beziers_knot[-1].co[3]=l1[-1]
"""
MINMAX(B.co)
courbes.ITEM[n0].beziers_knot.append(B)
return courbes,n0
Actions= { "1" : mouvement_vers,
"3" : mouvement_vers }
TAGcourbe=Actions.keys()
def scan_FILE(nom):
global CP, courbes, SCALE, MAX, MIN, CLOSED
dir,name=split(nom)
name=name.split('.')
#print name
n0=0
result=0
t=filtreFICHIER(nom)
if t!="false":
if not SHARP_IMPORT:
warning = "Select Size : %t| As is %x1 | Scale on Height %x2| Scale on Width %x3"
SCALE = Blender.Draw.PupMenu(warning)
npat=0
l=0
while l <len(t)-1 :
#print 'len(t)',len(t)
t[l].replace('\n','')
if t[l][0]!='%':
l0=t[l].split()
#print l0[0], l0[1]
if l0[0]=='TYPE:' and l0[1] in TAGcourbe:
#print l0[0], l0[1],
l1=t[l+1].split()
l2=t[l+2].split()
courbes,n0=Actions[l0[1]](l0,l1,l2,n0)
elif l0[0]=='#Point':
POINTS= int(l0[0])
elif l0[0]=='CLOSED:' and l0[1]=='1':
CLOSED=1
l=l+1;
courbes.number_of_items=len(courbes.ITEM.keys())
courbes.ITEM[n0].beziers_knot[0].co[0]=CP[0]
courbes.ITEM[n0].beziers_knot[0].co[1]=CP[1]
for k in courbes.ITEM.keys():
#print k
if CLOSED == 1:
B=Bez()
B.co=courbes.ITEM[k].beziers_knot[0].co[:]
B.ha=courbes.ITEM[k].beziers_knot[0].ha[:]
B.echo()
courbes.ITEM[k].beziers_knot.append(B)
courbes.ITEM[k].flagUV[0]=1
courbes.ITEM[k].pntsUV[0] =len(courbes.ITEM[k].beziers_knot)
if courbes.number_of_items>0:
t=create_GEOtext(courbes)
save_GEOfile(dir,name[0],t)
Open_GEOfile(dir,name[0])
# 0.1.8 ---------------------------------
Blender.Object.Get()[-1].setName(name[0])
# 0.1.8 ---------------------------------
else:
pass
#=====================================================================
#====================== GIMP Path format mouvements =========================
#=====================================================================
#=========================================================
# une sorte de contournement qui permet d'utiliser la fonction
# et de documenter les variables Window.FileSelector
#=========================================================
def fonctionSELECT(nom):
scan_FILE(nom)
#Blender.Window.FileSelector (fonctionSELECT, 'SELECT a GIMP Path FILE')
#sys.path=oldpath
|