A.N.T.(Another Noise Tool) v.0.3 interactive deformation.

A.N.T.(Another Noise Tool) v.0.3 ‘Mixed noise’+interactive deformation.


New: interactive deformation.


#!BPY

"""
Name: 'A.N.T.0.3'
Blender: 233
Group: 'Mesh'
Tip: 'A.N.T.0.3 , distort mesh with noise (interactive).'
"""

############################################################################
# A.N.T.(Another Noise Tool) v.0.3 'Mixed noise'+interactive deformation   #
# Jimmy Hazevoet , juli 2004                                               #
############################################################################
# Interactive mesh deform function copied from:                            #
#                                 Taper and Twist.py ( flippyneck / _Ph_ ) #
# Save and Load file function copied from: Tessalate.py ( JMS )            #
############################################################################

import Blender
from Blender import *
from Blender.Noise import *
from math import *
from Blender.Draw import *
from Blender.BGL import *

#---------------------------------------------------------------------
Pre_View = Create(0)
message = ""
#---------------------------------------------------------------------
dirpath=Blender.sys.dirname(Blender.Get('filename'))
print dirpath.replace('\\','/')+'/'
Terra_Path=dirpath.replace('\\','/')+'/'
#-------------------
class buttons:
   global Terra_Path
   def __init__(self):
      self.Record={}
      self.Record['Save']=Create(0)
      self.Record['Load']=Create(0)
      self.Record['SaveAs']=Create('ANT03Test.ant') #='Filename'
      self.path=Terra_Path
      self.buttonslist=[]
# Toggle #-----------------------------------------------------
      self.Effecttype = Create(1)  #= Effect direction (axis)
      self.N1_To = Create(1)       #= Toggle Noise 1
      self.Fi_To = Create(0)       #= Toggle Mixer/Filter
      self.N2_To = Create(0)       #= Toggle Noise 2
# Mixer #------------------------------------------------------
      self.PFunc = Create(1)      #= mix menu
      self.plev    =Create(10.0)  #= Plateau level
      self.slev    =Create(-10.0) #= Sea level
      self.iSca = Create(1.0)     #= Intensity scale1
      self.N2iSca = Create(1.0)   #= Intensity scale2
      self.sinus1  = Create(2.0)  #= a
      self.sinus2  = Create(2.0)  #= b
      self.Sci  = Create(4.0)     #= c
                                  #Preset formula (from math import*)
      self.S1string  = Create("a * n1") #= S1 ,string 1 (input)
      self.S2string  = Create("b * n2") #= S2 ,string 2 (input)
      self.zstring   = Create("S1+S2")  #= z  ,string result (output)
# Noise 1 #----------------------------------------------------
      self.NFunc = Create(1)      #= Noise function 1
      self.Sx = Create(1.0)       #= Scale X
      self.Sy = Create(1.0)       #= Scale Y
      self.Sz = Create(1.0)       #= Scale Z
      self.Lx = Create(0.0)       #= Loc. X
      self.Ly = Create(0.0)       #= Loc. Y
      self.Lz = Create(0.0)       #= Loc. Z
      self.NSize = Create(0.25)	  #= Noise size
      # self.iSca = Create(1.0)	  #= Intensity scale1
      self.NType = Create(1)      #= Musgrave noise
      self.BType = Create(1)      #= Basis noise
      self.Oc = Create(2.0)       #= Octaves
      self.La = Create(2.0)       #= Lacunarity
      self.Ga = Create(1.0)       #= Gain
      self.Ha = Create(1.0)       #= H
      self.Of = Create(1.0)       #= Offset
      self.BDist1 = Create(1)     #= Distortion noise
      self.DAmnt  = Create(1.0)	  #= Distortion Amount
      self.TDep  = Create(2)      #= Turbulence Depth
      self.TSH   = Create(0)      #= Soft/Hard
      self.Tamp  = Create(0.5)    #= Ampscale
      self.Tfrq  = Create(2.0)    #= Freqscale
# Noise 2 #------------------------------------------------------
      self.N2Func = Create(3)     #= Noise function 2
      self.N2Sx = Create(1.0)     #= Scale X
      self.N2Sy = Create(1.0)     #= Scale Y
      self.N2Sz = Create(1.0)     #= Scale Z
      self.N2Lx = Create(0.0)     #= Loc. X
      self.N2Ly = Create(0.0)     #= Loc. Y
      self.N2Lz = Create(0.0)     #= Loc. Z
      self.N2Size = Create(0.25)  #= Noise size
      # self.N2iSca = Create(1.0) #= Intensity scale2
      self.N2Type = Create(1)     #= Musgrave noise2
      self.N2BType = Create(1)    #= Basis noise2
      self.N2Oc = Create(2.0)     #= Octaves
      self.N2La = Create(2.0)     #= Lacunarity
      self.N2Ga = Create(1.0)     #= Gain
      self.N2Ha = Create(1.0)     #= H
      self.N2Of = Create(1.0)     #= Offset
      self.N2BDist1 = Create(1)   #= Distortion noise2
      self.N2DAmnt  = Create(1.0) #= Distortion Amount
      self.N2TDep  = Create(2)    #= Turbulence Depth
      self.N2TSH   = Create(0)    #= Soft/Hard
      self.N2Tamp  = Create(0.5)  #= Ampscale
      self.N2Tfrq  = Create(2.0)  #= Freqscale
# Save file#----------------------
   def prf_dump(self):
      global message
      n0=dir(self)
      f=open(self.path+self.Record['SaveAs'].val,'w')
      for n in n0:
         #print n0,
         if  (n.find('__')!=0 and n.find('prf_dump')==-1
            and n.find('prf_load')==-1 and n.find('prf_save')==-1
            and n.find('path')==-1) and n.find('Record')==-1:
            exec """l1=str(type(self.%s))"""%n
            l0=n+';'+l1+'
'
            f.write(l0)
            exec """f.write(str(self.%s))"""%n
            message = "  File Saved !"
            f.write('
')
      f.close()
# Load file#----------------------
   def prf_load(self):
      global message
      try:
         f=open(self.path+self.Record['SaveAs'].val,'r')
         buffer=f.readlines()
         f.close()
         for n in range(0,len(buffer),2):
            var=buffer[n].split(';')
            if var[0] not in self.buttonslist:
               self.buttonslist.append(var[0])
            if buffer[n].find("""<type 'str""")!=-1:
               exec """self.%s='''%s'''"""%(var[0],buffer[n+1][:-1])               
            elif buffer[n].find("""<type 'dict'>""")!=-1:
               exec """provdict=%s"""%buffer[n+1][:-1]
               for d in provdict.keys():
                  l00="""self.%s['%s'].val=%s"""%(var[0],d,provdict[d])
                  exec l00
            elif buffer[n].find("""<type 'Button'>""")!=-1:
                  exec """self.%s.val=%s"""%(var[0],buffer[n+1][:-1])
            message = " File Loaded !"
      except:
         message = "No such file !"
         print "File does not exist !"
B=buttons()

#----------------------------
#-------------------------------------------------------------------------
def reset_N1():
   global B
   B.Sx = Create(1.0)
   B.Sy = Create(1.0)
   B.Sz = Create(1.0)
   B.Lx = Create(0.0)
   B.Ly = Create(0.0) 
   B.Lz = Create(0.0)
   B.NSize = Create(0.25)
   B.iSca = Create(1.0)
   B.DAmnt = Create(1.0)
   B.BDist1 = Create(1)
   B.NType = Create(1)
   B.BType = Create(1)
   B.Oc = Create(2.0)
   B.La = Create(2.0)
   B.Ga = Create(1.0)
   B.Ha = Create(1.0)
   B.Of = Create(1.0)
   B.TDep  = Create(2)
   B.TSH   = Create(0)
   B.Tamp  = Create(0.5)
   B.Tfrq  = Create(2.0)
#---------------------------
def reset_N2():
   global B
   B.N2Sx = Create(1.0)
   B.N2Sy = Create(1.0)
   B.N2Sz = Create(1.0)
   B.N2Lx = Create(0.0)
   B.N2Ly = Create(0.0) 
   B.N2Lz = Create(0.0)
   B.N2Size = Create(0.25)
   B.N2iSca = Create(1.0)
   B.N2DAmnt = Create(1.0)
   B.N2BDist1 = Create(1)
   B.N2Type = Create(1)
   B.N2BType = Create(1)
   B.N2Oc = Create(2.0)
   B.N2La = Create(2.0)
   B.N2Ga = Create(1.0)
   B.N2Ha = Create(1.0)
   B.N2Of = Create(1.0)
   B.N2TDep  = Create(2)
   B.N2TSH   = Create(0)
   B.N2Tamp  = Create(0.5)
   B.N2Tfrq  = Create(2.0)
#---------------------------
def reset_Mixer():
   global B
   #B.PFunc   = Create(1)
   B.iSca   = Create(1.0)
   B.N2iSca = Create(1.0)
   B.sinus1  = Create(1.0)
   B.sinus2  = Create(1.0)
   B.Sci    = Create(2.0)
   B.S1string  = Create("0")
   B.S2string  = Create("0")
   B.zstring  = Create("0")
   B.plev = Create(10.0)
   B.slev = Create(-10.0)

#----------------------------
#-----------------------------------------------------------------------------
def Noise_func(x,y,z):
   global B, message

# n1 = Noise1-------------------------------------------
   x1 = (x / B.Sx.val + B.Lx.val) / B.NSize.val
   y1 = (y / B.Sy.val + B.Ly.val) / B.NSize.val
   z1 = (z / B.Sz.val + B.Lz.val) / B.NSize.val
   B0 = B.BType.val-1
   B1 = B.BDist1.val-1
   if B0 == 9: B0 = 14
   if B1 == 9: B1 = 14
   if (B.NFunc.val == 1):
      Ha1 = B.Ha.val
      La1 = B.La.val
      Oc1 = B.Oc.val
      Of1 = B.Of.val
      Ga1 = B.Ga.val
      if (B.NType.val == 1):
         no1 = multiFractal((x1,y1,z1),Ha1,La1,Oc1,B0)
      if (B.NType.val == 2):
         no1 = ridgedMFractal((x1,y1,z1),Ha1,La1,Oc1,Of1,Ga1,B0)
      if (B.NType.val == 3):
         no1 = hybridMFractal((x1,y1,z1),Ha1,La1,Oc1,Of1,Ga1,B0)
      if (B.NType.val == 4):
         no1 = heteroTerrain((x1,y1,z1),Ha1,La1,Oc1,Of1,B0)
      if (B.NType.val == 5):
         no1 = fBm((x1,y1,z1),Ha1,La1,Oc1,B0)
   if (B.NFunc.val == 2):
      no1 = vlNoise((x1,y1,z1),B.DAmnt.val,B1,B0)
   if (B.NFunc.val == 3):
      TD=B.TDep.val
      SH=B.TSH.val
      no1 = turbulence((x1,y1,z1),TD,SH,B0,B.Tamp.val,B.Tfrq.val)

   n1 = no1 * B.iSca.val/3

# n2 = Noise2-------------------------------------------
   x2 = (x / B.N2Sx.val + B.N2Lx.val) / B.N2Size.val
   y2 = (y / B.N2Sy.val + B.N2Ly.val) / B.N2Size.val
   z2 = (z / B.N2Sz.val + B.N2Lz.val) / B.N2Size.val
   N2B  = B.N2BType.val-1
   N2B1 = B.N2BDist1.val-1
   if N2B == 9: N2B =14
   if N2B1 == 9: N2B1 =14
   if (B.N2Func.val == 1):
      Ha2 = B.N2Ha.val
      La2 = B.N2La.val
      Oc2 = B.N2Oc.val
      Of2 = B.N2Of.val
      Ga2 = B.N2Ga.val
      if (B.N2Type.val == 1):
         no2 = multiFractal((x2,y2,z2),Ha2,La2,Oc2,N2B)
      if (B.N2Type.val == 2):
         no2 = ridgedMFractal((x2,y2,z2),Ha2,La2,Oc2,Of2,Ga2,N2B)
      if (B.N2Type.val == 3):
         no2 = hybridMFractal((x2,y2,z2),Ha2,La2,Oc2,Of2,Ga2,N2B)
      if (B.N2Type.val == 4):
         no2 = heteroTerrain((x2,y2,z2),Ha2,La2,Oc2,Of2,N2B)
      if (B.N2Type.val == 5):
         no2 = fBm((x2,y2,z2),Ha2,La2,Oc2,N2B)
   if (B.N2Func.val == 2):
      no2 = vlNoise((x2,y2,z2),B.N2DAmnt.val,N2B1,N2B)
   if (B.N2Func.val == 3):
      TD2=B.N2TDep.val
      SH2=B.N2TSH.val
      no2=turbulence((x2,y2,z2),TD2,SH2,N2B,B.N2Tamp.val,B.N2Tfrq.val)

   n2 = no2 * B.N2iSca.val/3

# Mix n1,n2-------------------------------------------
   if B.PFunc.val == 1:
      z = n1
   if B.PFunc.val == 2:
      z = n2
   if B.PFunc.val == 3:
      z = n1 + n2
   if B.PFunc.val == 4:
      z = n1 - n2
   if B.PFunc.val == 5:
      z = n1 * n2
   if B.PFunc.val == 6:
      z = n1 / n2
   if B.PFunc.val == 7:
      z = n1 > n2
   if B.PFunc.val > 7:
      a=B.sinus1.val
      b=B.sinus2.val
      c=B.Sci.val
   if B.PFunc.val == 8:
      z = sin(c*y-y/2+a)*n1 + cos(c*y-y/2+b)*n2
   if B.PFunc.val == 9:
      sq = c*sqrt((x-x/2)**2+(y-y/2)**2)
      z  = sin(a*sq)*n1 + cos(b*sq)*n2
   if B.PFunc.val == 10:
      sq = 4*sqrt((x-x/2)**2+(y-y/2)**2)
      spi = x*sin(a*2*sq)*n1 + y*cos(b*2*sq)*n2
      z = 0.25*spi*c
   if B.PFunc.val == 11:
      S1func = B.S1string.val
      S2func = B.S2string.val
      zfunc = B.zstring.val
      try:
         S1 = eval(S1func)
         S2 = eval(S2func)
         z = eval(zfunc)
      except:
         message = "error"

   return x,y,z

#----------------------------
# Mesh function ----------------------------------------------------------------
def func():
   global B, message

   try:
      obj=Blender.Object.GetSelected()[0]
   except:
      message = "Nothing sellect!"
      return 0
   if obj:
      dat = obj.getData()
      if type(dat) != Types.NMeshType:
         message = "Sellect a mesh!"
         return 0
      else:
         pass
      if obj != Blender.working_object:
         Blender.working_object = obj
         Blender.base_data = obj.getData()

      mesh=obj.getData()
      #--------------------------
      normals = []
      coordinates = []
      for v in mesh.verts:
         i = mesh.verts.index(v)
         normals.append([v.no[0],v.no[1],v.no[2]])
         coordinates.append([v.co[0],v.co[1],v.co[2]])
         NOISEF = Noise_func(v.co[0],v.co[1],v.co[2])
         z_result = NOISEF[2]

         if (z_result < B.slev.val): z_result = B.slev.val
         if (z_result > B.plev.val): z_result = B.plev.val

         if (B.Effecttype.val==1):
            for z in range(3): 
               v.co[z] = coordinates[i][z] + (z_result * normals[i][z])
         if (B.Effecttype.val==2):
            for c in range(2):
               v.co[c] = coordinates[i][c] + (z_result * normals[i][c])
         if (B.Effecttype.val==3):
            v.co[2] = coordinates[i][2] + (z_result * normals[i][2])
         if (B.Effecttype.val==4):
            v.co[1] = coordinates[i][1] + (z_result * normals[i][1])
         if (B.Effecttype.val==5):
            v.co[0] = coordinates[i][0] + (z_result * normals[i][0])

      mesh.update()
      obj.makeDisplayList()

#----------------------------
def restore(object):
   m=object.getData()
   m=Blender.base_data
   m.update()
   object.makeDisplayList()
#----------------------------
Blender.working_object=None
Blender.base_data=None

#----------------------------
# Preview ----------------------------------------------------------------------
def PreviewNoise():
   for x in range(-50, 50):
      for y in range(-50, 50):
         z=0.0
         poco = Noise_func(x/50.0, y/50.0, z/50.0)
         pointCol = poco[2]
         r = (pointCol+1.0)/2.0
         g = (pointCol+1.0)/2.0
         b = (pointCol+1.0)/2.0
         glColor3f(r,g,b)
         glRecti(x+190, y+470, x+191, y+471)

#----------------------------
# Box --------------------------------------------------
def Shadow_Box(x, y, w, h, r, g, b):
   glColor3f(r+0.075, g+0.075, b+0.075)
   glRecti(x+6, y-6, w+6, h-6)
   glColor3f(r+0.05, g+0.05, b+0.05)
   glRecti(x+5, y-5, w+5, h-5)
   glColor3f(r+0.025, g+0.025, b+0.025)
   glRecti(x+4, y-4, w+4, h-4)
   glColor3f(r, g, b)
   glRecti(x+3, y-3, w+3, h-3)
   glColor3f(r-0.025, g-0.025, b-0.025)
   glRecti(x+2, y-2, w+2, h-2)
   glColor3f(r-0.3, g-0.3, b-0.3)
   glRecti(x, y, w, h)
   glColor3f(r+0.2, g+0.2, b+0.2)
   glRecti(x+1, y+1, w-1, h-1)

#----------------------------
# G.U.I.------------------------------------------------------------------------
def gui():
   global B, Pre_View
   BGL.glClearColor(0.6, 0.6, 0.6, 1)
   BGL.glClear(BGL.GL_COLOR_BUFFER_BIT)

   Pre_View = Toggle("Preview", 3,240,380,50,15, Pre_View.val)
   if Pre_View.val == 1:
      Shadow_Box(10, 10, 370, 550, 0.5,0.5,0.5)
      glColor3f(0.35,0.45,0.55)
      glRecti(135, 415, 245, 525)
      PreviewNoise()
   else:
      Shadow_Box(10, 10, 370, 420, 0.5,0.5,0.5)

   glColor3f(1.0,0.0,0.0)
   glRasterPos2d(50, 400)
   Text(message)

   glColor3f(0.65,0.65,0.65)
   glRecti(240, 400, 340, 415)

   glColor3f(0.1,0.1,0.1)
   glRasterPos2d(260, 403)
   Text("A.N.T.v.0.3")


   BRSA=B.Record['SaveAs'].val
   B.Record['SaveAs']=String("File: ",3,40,360,200,20,BRSA,256)
   B.Record['Save']=Button("Save", 9, 40, 380, 100, 15)
   B.Record['Load']=Button("Load", 10, 140, 380, 100, 15)

   B.N1_To = Toggle("n1",31,40,330,100,20, B.N1_To.val)
   B.Fi_To = Toggle("Mix",33,140,330,100,20, B.Fi_To.val)
   B.N2_To = Toggle("n2",32,240,330,100,20, B.N2_To.val)
   #---------------------------------------------------------------------------
   if B.Fi_To.val == 1:
      Button("Reset Mix", 6, 240,360,100,20)

      Pf = "Mix type's%t|n1 %x1|n2 %x2|n1 + n2 %x3|n1 - n2%x4|n1 * n2%x5\
           |n1 / n2%x6|n1 > n2%x7|sinus1%x8|sinus2%x9|sinus3%x10|formula%x11"
      B.PFunc = Menu(Pf, 3, 140,160,100,20, B.PFunc.val)
      if B.PFunc.val == 1:
         B.iSca=Number("iScale n1: ",3,40,135,145,20,B.iSca.val,-10.0,10.0)
         B.NSize=Number("n1Size: ",3,40,160,90,20,B.NSize.val,0.001,20.0)
      if B.PFunc.val == 2:
         B.N2iSca=Number("iScale n2: ",3,195,135,145,20,B.N2iSca.val,-10.0,10.0)
         B.N2Size=Number("n2Size: ",3,250,160,90,20,B.N2Size.val,0.001,20.0)
      if B.PFunc.val > 2:
         B.iSca=Number("iScale n1: ",3,40,135,145,20,B.iSca.val,-10.0,10.0)
         B.NSize=Number("n1Size: ",3,40,160,90,20,B.NSize.val,0.001,20.0)
         B.N2iSca=Number("iScale n2: ",3,195,135,145,20,B.N2iSca.val,-10.0,10.0)
         B.N2Size=Number("n2Size: ",3,250,160,90,20,B.N2Size.val,0.001,20.0)
      if B.PFunc.val > 7:
         B.sinus1=Number("a : ",3,40,190,100,20,B.sinus1.val,-10.0,10.0)
         B.sinus2=Number("b : ",3,240,190,100,20,B.sinus2.val,-10.0,10.0)
         B.Sci = Number("c : ",3,150,190,80,20,B.Sci.val,-10.0,10.0)
      if B.PFunc.val > 10:
         B.S1string=String("S1 : ",3,40,270,300,20,B.S1string.val,256,"Input S1")
         B.S2string=String("S2 : ",3,40,250,300,20,B.S2string.val,256,"Input S2")
         B.zstring=String("z : ",3,40,220,300,20,B.zstring.val,256,"Output")

      B.slev=Number("Min.:",3,40,100,150,20,B.slev.val,-50.0,50.0,"Sealevel")
      B.plev=Number("Max.:",3,190,100,150,20,B.plev.val,-50.0,50.0,"Plateau")

   #---------------------------------------------------------------------------
   if B.N1_To.val == 1:
      Button("Reset n1", 4, 240,360,100,20)

      B.iSca = Number("iScale : ", 3,40,170,150,20,B.iSca.val,-10.0,10.0)
      B.NSize=Number("NoiseSize : ",3,190,170,150,20,B.NSize.val,0.001,10.0)
      B.Sx = Number("sizeX : ", 3, 190,140,150,20, B.Sx.val,0.0,10.0)
      B.Sy = Number("sizeY : ", 3, 190,120,150,20, B.Sy.val,0.0,10.0)
      B.Sz = Number("sizeZ : ", 3, 190,100,150,20, B.Sz.val,0.0,10.0)
      B.Lx = Number("ofsX : ", 3, 40,140,150,20, B.Lx.val,-1000.0,1000.0)
      B.Ly = Number("ofsY : ", 3, 40,120,150,20, B.Ly.val,-1000.0,1000.0)
      B.Lz = Number("ofsZ : ", 3, 40,100,150,20, B.Lz.val,-1000.0,1000.0)

      Nn="Noise 1 Type's%t|Musgrave 1%x1|DistortedNoise 1%x2|Turbulence 1%x3"
      B.NFunc = Menu(Nn, 3, 40,300,300,20, B.NFunc.val)
      if (B.NFunc.val == 1):
         Bn = "Noise Basis%t|Blender Original%x1|Original Perlin%x2\
               |Improved Perlin%x3|Voronoi_F1%x4|Voronoi_F2%x5\
               |Voronoi_F3%x6|Voronoi_F4%x7|Voronoi_F2-F1%x8\
               |Voronoi Crackle%x9|CellNoise%x10"
         B.BType = Menu(Bn, 3, 190,200,150,20, B.BType.val)
         Fn = "Musgrave Type's%t|MultiFractal%x1|RidgedMF%x2\
               |HybridMF%x3|HTerrain%x4|fBm%x5"
         B.NType = Menu(Fn, 3, 40,200,150,20, B.NType.val)
         B.Oc = Slider("Octs : ", 3, 40,230,150,20, B.Oc.val,0.0,8.0 ,0)
         B.La = Slider("Lacu : ", 3, 190,230,150,20, B.La.val,0.0,6.0 ,0)
         B.Ha = Slider("H : ", 3, 40,250,150,20, B.Ha.val,0.0,2.0 ,0)
         if (B.NType.val == 2):
            B.Of = Slider("Ofst : ",3,190,250,150,20,B.Of.val,0.0,6.0,0)
            B.Ga = Slider("Gain : ",3,40,270,150,20,B.Ga.val,0.0,6.0,0)
         if (B.NType.val == 3):
            B.Of = Slider("Ofst : ",3,190,250,150,20,B.Of.val,0.0,6.0,0)
            B.Ga = Slider("Gain : ",3,40,270,150,20,B.Ga.val,0.0,6.0,0)
         if (B.NType.val == 4):
            B.Of = Slider("Ofst : ",3,190,250,150,20,B.Of.val,0.0,6.0,0)

      if (B.NFunc.val == 2):
         Bn="Noise Basis%t|Blender Original%x1|Original Perlin%x2\
               |Improved Perlin%x3|Voronoi_F1%x4|Voronoi_F2%x5\
               |Voronoi_F3%x6|Voronoi_F4%x7|Voronoi_F2-F1%x8\
               |Voronoi Crackle%x9|CellNoise%x10"
         B.BType = Menu(Bn, 3, 190,200,150,20, B.BType.val)
         Bd1="Distortion Noise%t|Blender Original%x1|Original Perlin%x2\
               |Improved Perlin%x3|Voronoi_F1%x4|Voronoi_F2%x5\
               |Voronoi_F3%x6|Voronoi_F4%x7|Voronoi_F2-F1%x8\
               |Voronoi Crackle%x9|CellNoise%x10"
         B.BDist1 = Menu(Bd1, 3, 40,200,150,20, B.BDist1.val)
         damnt="Distortion Amount : "
         B.DAmnt = Slider(damnt,3,40,230,300,20,B.DAmnt.val,0.0,10.0, 0)

      if (B.NFunc.val == 3):
         Bn = "Noise Basis%t|Blender Original%x1|Original Perlin%x2\
            |Improved Perlin%x3|Voronoi_F1%x4|Voronoi_F2%x5\
            |Voronoi_F3%x6|Voronoi_F4%x7|Voronoi_F2-F1%x8\
            |Voronoi Crackle%x9|CellNoise%x10"
         B.BType = Menu(Bn, 3, 190,200,150,20, B.BType.val)
         B.TDep = Number("Depth : ",3,40,200,100,20,B.TDep.val,0.0,10.0)
         B.TSH = Toggle("S/H", 3, 140,200,50,20,B.TSH.val)
         B.Tamp = Number("Amp. : ",3,40,230,150,20,B.Tamp.val,0.0,10.0)
         B.Tfrq = Number("Freq. : ",3,190,230,150,20,B.Tfrq.val,0.0,10.0)

   #---------------------------------------------------------------------------
   if B.N2_To.val == 1:
      Button("Reset n2", 5, 240,360,100,20)

      B.N2iSca = Number("iScale : ",3,40,170,150,20,B.N2iSca.val,-10.0,10.0)
      B.N2Size=Number("NoiseSize : ",3,190,170,150,20,B.N2Size.val,0.001,10.0)
      B.N2Sx = Number("sizeX : ",3,190,140,150,20, B.N2Sx.val,0.0,10.0)
      B.N2Sy = Number("sizeY : ",3,190,120,150,20, B.N2Sy.val,0.0,10.0)
      B.N2Sz = Number("sizeZ : ",3,190,100,150,20, B.N2Sz.val,0.0,10.0)
      B.N2Lx = Number("ofsX : ",3,40,140,150,20, B.N2Lx.val,-1000.0,1000.0)
      B.N2Ly = Number("ofsY : ",3,40,120,150,20, B.N2Ly.val,-1000.0,1000.0)
      B.N2Lz = Number("ofsZ : ",3,40,100,150,20, B.N2Lz.val,-1000.0,1000.0)

      Nn2="Noise 2 Type's%t|Musgrave 2%x1|DistortedNoise 2%x2|Turbulence 2%x3"
      B.N2Func = Menu(Nn2, 3, 40,300,300,20, B.N2Func.val)
      if (B.N2Func.val == 1):
         Bn2="Noise Basis%t|Blender Original%x1|Original Perlin%x2\
               |Improved Perlin%x3|Voronoi_F1%x4|Voronoi_F2%x5\
               |Voronoi_F3%x6|Voronoi_F4%x7|Voronoi_F2-F1%x8\
               |Voronoi Crackle%x9|CellNoise%x10"
         B.N2BType=Menu(Bn2, 3, 190,200,150,20, B.N2BType.val)
         Fn2="Musgrave Type's%t|MultiFractal%x1|RidgedMF%x2\
               |HybridMF%x3|HTerrain%x4|fBm%x5"
         B.N2Type = Menu(Fn2, 3,40,200,150,20,B.N2Type.val)
         B.N2Oc = Slider("Octs : ",3,40,230,150,20,B.N2Oc.val,0.0,8.0,0)
         B.N2La = Slider("Lacu : ",3,190,230,150,20,B.N2La.val,0.0,6.0,0)
         B.N2Ha = Slider("H : ",3,40,250,150,20,B.N2Ha.val,0.0,2.0,0)
         if (B.N2Type.val == 2):
            B.N2Of = Slider("Ofst : ",3,190,250,150,20,B.N2Of.val,0.0,6.0,0)
            B.N2Ga = Slider("Gain : ",3,40,270,150,20,B.N2Ga.val,0.0,6.0,0)
         if (B.N2Type.val == 3):
            B.N2Of = Slider("Ofst : ",3,190,250,150,20,B.N2Of.val,0.0,6.0,0)
            B.N2Ga = Slider("Gain : ",3,40,270,150,20,B.N2Ga.val,0.0,6.0,0)
         if (B.N2Type.val == 4):
            B.N2Of = Slider("Ofst : ",3,190,250,150,20,B.N2Of.val,0.0,6.0,0)

      if (B.N2Func.val == 2):
         Bn2="Noise Basis%t|Blender Original%x1|Original Perlin%x2\
               |Improved Perlin%x3|Voronoi_F1%x4|Voronoi_F2%x5\
               |Voronoi_F3%x6|Voronoi_F4%x7|Voronoi_F2-F1%x8\
               |Voronoi Crackle%x9|CellNoise%x10"
         B.N2BType=Menu(Bn2, 3, 190,200,150,20, B.N2BType.val)
         Bd12="Distortion Noise%t|Blender Original%x1|Original Perlin%x2\
               |Improved Perlin%x3|Voronoi_F1%x4|Voronoi_F2%x5\
               |Voronoi_F3%x6|Voronoi_F4%x7|Voronoi_F2-F1%x8\
               |Voronoi Crackle%x9|CellNoise%x10"
         B.N2BDist1=Menu(Bd12, 3,40,200,150,20,B.N2BDist1.val)
         damnt2="Distortion Amount : "
         B.N2DAmnt=Slider(damnt2,3,40,230,300,20,B.N2DAmnt.val,0.0,10.0,0)

      if (B.N2Func.val == 3):
         Bn2="Noise Basis%t|Blender Original%x1|Original Perlin%x2\
               |Improved Perlin%x3|Voronoi_F1%x4|Voronoi_F2%x5\
               |Voronoi_F3%x6|Voronoi_F4%x7|Voronoi_F2-F1%x8\
               |Voronoi Crackle%x9|CellNoise%x10"
         B.N2BType=Menu(Bn2, 3,190,200,150,20, B.N2BType.val)
         B.N2TDep=Number("Depth : ",3,40,200,100,20,B.N2TDep.val,0.0,10.0)
         B.N2TSH=Toggle("S/H",3,140,200,50,20, B.N2TSH.val)
         B.N2Tamp=Number("Amp. : ",3,40,230,150,20,B.N2Tamp.val,0.0,10.0)
         B.N2Tfrq=Number("Freq. : ",3,190,230,150,20,B.N2Tfrq.val,0.0,10.0)

   efty="Direction %t|Normal %x1|X,Y %x2|Z %x3|Y %x4|X %x5"
   B.Effecttype = Menu(efty, 3, 40,70,300,20, B.Effecttype.val)

   Button("Redraw mesh", 3, 140,30,100,30)
   Button("Restore", 11, 250,30,90,30)
   Button("Apply", 12, 40,30,90,30)

   Button("Exit", 1, 290,380,50,15)

#---------------------------------------
def event(evt, val):
   global message
   if (evt == ESCKEY and not val):
      name = "OK?%t|Exit %x1"
      result = Blender.Draw.PupMenu(name)
      if result == 1:
         Exit()
#---------------------------------------
def bevent(evt):
   global B, message

   if evt == 1:
      name = "OK?%t|Exit %x1"
      result = Blender.Draw.PupMenu(name)
      if result == 1:
         Exit()

   if evt == 11:   # Restore mesh #
      if Blender.working_object:
         restore(Blender.working_object)
         message = "Mesh 'Restored'."
         Draw()
         return 0
   if evt == 12:   # Apply deformation #
      name = "OK?%t|Apply deformation %x1"
      result = Blender.Draw.PupMenu(name)
      if result == 1:
         obj=Blender.Object.GetSelected()[0]
         m=obj.getData()
         Blender.base_data=m
         restore(obj)
         message = "Mesh deformed."
         Redraw()
         return 0

   if evt == 4:
      message = ""
      name = "OK?%t|Reset Noise 1 %x1"
      result = Blender.Draw.PupMenu(name)
      if result == 1:
         reset_N1()
         Draw()
   if evt == 5:
      message = ""
      name = "OK?%t|Reset Noise 2 %x1"
      result = Blender.Draw.PupMenu(name)
      if result == 1:
         reset_N2()
         Draw()
   if evt == 6:
      message = ""
      name = "OK?%t|Reset Mixer %x1"
      result = Blender.Draw.PupMenu(name)
      if result == 1:
         reset_Mixer()
         Draw()

   if (evt == 31):
      message = ""
      if B.N1_To.val == 1:
         B.Fi_To.val = 0
         B.N2_To.val = 0
         Draw()
   if (evt == 32):
      message = ""
      if B.N2_To.val == 1:
         B.N1_To.val = 0
         B.Fi_To.val = 0
         Draw()
   if (evt == 33):
      message = ""
      if B.Fi_To.val == 1:
         B.N1_To.val = 0
         B.N2_To.val = 0
         Draw()

   if (evt==9):
      message = ""
      name = "OK?%t|Save %x1"
      result = Blender.Draw.PupMenu(name)
      if result == 1:
         B.prf_dump()
         Blender.Window.Redraw()
   if (evt==10):
      message = ""
      name = "OK?%t|Load %x1"
      result = Blender.Draw.PupMenu(name)
      if result == 1:
         B.prf_load()
         Blender.Window.Redraw()

   if Blender.working_object:
         restore(Blender.working_object)
   if evt == 3:   # Update #
      message = ""
      func()
      Draw()

Register(gui, event, bevent)

\

sweet! Finaly someone is playing with the auto redraw . Now only if you could get it to work with painting

Same problem with copying and pasting as before. Extra spaces

Copy/Paste in a text file and run it through that script to clear the whitespace at the end of each line.

filename = "test.txt"

file = open(filename, "r")
Lines = [l.rstrip() + "
" for l in file.readlines()]
file.close()

file = open(filename, "w")
file.writelines(Lines)
file.close()

Martin

theeth

Could you explain a little clearer, maybe step by step how I would use your little script.

Thanks :slight_smile:

Ken

Nice :smiley: .
But better if you change lines 377:


#----------------------------
def restore(object):
   m=object.getData()
   m=Blender.base_data
   m.update()
#----------------------------

by:


#----------------------------
def restore(object):
   m=object.getData()
   m=Blender.base_data
   m.update()
   object.makeDisplayList()
#----------------------------

:wink:

++
Ph
http://hp.home.chez.tiscali.fr/re_illusion/index.htm

mozilla ctrl-c —> Ctrl-shift-v in a blender script window works perfectly.

Extra spaces

http://www.liquidninja.com/metapad/

Jimmy Haze :smiley: Thanks I really like using this script, and it keps getting better. :smiley:

jms : thanks for the tip downloaded mozilla, and as you say works faultless, seems to be the size of font that IE uses. :smiley:

Ken

Sure.

1- Copy / Paste the script from the web into a text file (You can call it test.txt)
2- Create a py file and type in the script I just gave you
3- Place it in the same folder as the text file you want to clean
4- Run it (Windows user, it should work just by double clicking if Python is installed properly).
5- Your text file is now cleaned, you can open it in Blender and it will run without any problems (those caused by end of line whitespaces, mind you :wink: )

Martin

Thanks theeth.

ken

BTW this is what I get when I run it in ANT in blender even without running the space remover script on it first(which I could not get to work)

" Pf = "Mix type’s%t|n1 %x1|n2 %x2|n1 + n2 %x3|n1 - n2%x4|n1 * n2%x5
^
SyntaxError: invalid token

"

Martin this is confusing. I run this script from windows with test.txt in the same folder and I get a flashing dos screen. Then I tired running it from inside blender and I get:
“IOError: [Errno 2] No such file or directory: ‘test.txt’”

http://www.liquidninja.com/metapad/
ctrl-a, alt-w, nice and easy clean job

Yeah but I hate to have to download and install another program just to get one script to work.

no installation necessary. but then again, of course you don’t have to. that’s called freedom of choice.

I got it working just by manually going in and deleting all the extra space. As and aside does anyone know of a web site the explains the various noise fuctions used in this and other noise tool(Blender World Forge,Dynamica e.t.c) in a VERY simple way. I mean without the head long dive into higher math. I took math all the way up through differential equations in college. But that was 20 + years ago and that stuff comes back slowly.

great work!!

:expressionless: Sorry for the download problems.

:smiley: Thanks for the positive reactions.