Cellnoise script (greeble (?) )

CELLNOISE_____________________Blender 2.28+

_ Jimmy Haze (script nr.2)
_ 9/2003
_
_ Thank’s to mr.Selleri (S68) for his wonderful “BWF”.py,
_ which inspired me to write this cellnoise script. _

1_ You have to download CGKit 1.0+ (by: Matthias Baas)

from : http://sourceforge.net/projects/cgkit/ 

2_ Install CGKit…

3_ then copy “noise.pyd” and “cgtypes.pyd”
(on my pc they were in : c:\Python\Lib\site-packages)
and paste to your blender directory.

Cellnoise produces a “blocky” deformed plane with 3 layers of noise,
you have control over frequency ,x-y-z offset, and randomised edges.

#############################################################
#############################################################
##
##                        CELLNOISE
##  _ Jimmy Haze
##  _ 9/2003
##  _
##  _ Thank's to mr.Selleri (S68) for his wonderful "BWF".py,
##  _ which inspired me to write this cellnoise script.
##  _ 
##
#############################################################
#############################################################
##
## 1_ You have to download CGKit 1.0+ (by: Matthias Baas) 
##                         ----------
##    from : www.sourceforge.net 
##           -------------------
##
## 2_ Install CGKit...
## 
## 3_ then copy "noise.pyd" and "cgtypes.pyd"
##    (on my pc they were in : c:\Python\Lib\site-packages\)
##    and paste to your blender directory.
##
#############################################################
#############################################################
#
import Blender
from Blender import *
from Blender.Draw import *
from Blender.BGL import *
from math import *
from whrandom import *
#

import noise 

#
#############################################################
#
#############################################################
xres=Create(32)
yres=Create(32)
cellf =Create(2)
cex =Create(1.0)
cey =Create(1.0)
cez =Create(0)
cezz =Create(0)
offz =Create(0)
offx =Create(0.0)
offy =Create(0.0)
offz1 =Create(1)
offz2 =Create(1)
rx=Create(0.0)
ry=Create(0.0)
rz=Create(0)
############################################################# 
#
#############################################################
def Cell():
   global cex, cey, cez, cezz, offx, offy, offz1, offz2
   global xres, yres, cellf, rx, ry, rz, offz
####
   me=NMesh.GetRaw() 
####
   i=0.0
   j=0.0
   x=0.0
   y=0.0
   z=0.0
   xmax = xres.val
   ymax = yres.val
########
   for i in range(0, xmax, 1):
       for j in range(0, ymax, 1):
           #
           xv = (i-xmax/2.0)/10.0
           yv = (j-ymax/2.0)/10.0
           #
           xn=(xv/2)*cex.val*cellf.val+offx.val
           xn+=0.25*rx.val*random()
           yn=(yv/2)*cey.val*cellf.val+offy.val
           yn+=0.25*ry.val*random()
           #
           xm=(xv/2)*cez.val*0.5*cellf.val+offz.val
           xm+=0.25*rx.val*random()
           ym=(yv/2)*cezz.val*0.5*cellf.val+offz.val
           ym+=0.25*ry.val*random()
           #                       
           vn= noise.cellnoise(xn,yn)
           vm= noise.cellnoise(xm,ym)
           vo= noise.noise(xm,yn)
           #
           z = vn *offz1.val
           z +=vm *offz2.val
           z +=0.2*rz.val*sin(vn/vm*rz.val<vo*2.0+1.5*rz.val)
           #
           #
           #
           v=NMesh.Vert(i, j, z)
           me.verts.append(v)
           #
########
   for i in range(0,ymax-1):
       for j in range(0,xmax-1):
           #
           a=i+j*ymax
           #
           f= NMesh.Face()
           f.v.append(me.verts[a])
           f.v.append(me.verts[a+ymax])
           f.v.append(me.verts[a+ymax+1])
           f.v.append(me.verts[a+1])
           #
           me.faces.append(f)
           # 

   NMesh.PutRaw(me, "Cellnoise", 1)
   Blender.Redraw()


############################################################# 
# Gui  
############################################################# 
def Warn():
  BGL.glRasterPos2d(20, 230)
  Blender.Window.Redraw(Blender.Window.Const.TEXT)
####
def draw():
  global xres, yres, cex, cey, cez, cezz, cellf
  global offx, offy, offz, offz1, offz2, rx, ry, rz
####
  BGL.glClearColor(0.6, 0.6, 0.6, 1)
  BGL.glColor3f(1,1,1)
  BGL.glClear(BGL.GL_COLOR_BUFFER_BIT)
  #
  glColor3f(0.2, 0.3, 0.4)
  glRectf(5, 1, 265, 235)

  glColor3f(0.5, 0.5, 0.5)
  glRectf(10, 6, 260, 190)
  #
  BGL.glColor3f(0.8, 0.8, 0.8)
  BGL.glRasterPos2d(60, 210)
  Text("CELLNOISE")
  #
  rx=Number("raX=",2,20,170,65,15,rx.val,0.0,16.0,"X*random")
  ry=Number("raY=",2,92.5,170,65,15,ry.val,0.0,16.0,"Y*random")
  rz=Number("",2,165,170,85,15,rz.val,-96.0,96.0)
  cex=Number("X =",2,20,140,65,25,cex.val,0.0,16.0,"cell x freq.")
  cey=Number("Y =",2,92.5,140,65,25,cey.val,0.0,16.0,"cell y freq.")
  cez=Number("X2 =",2,165,140,85,25,cez.val,0.0,16.0,"cell x freq.")
  cezz=Number("Y2 =",2,165,110,85,25,cezz.val,0.0,16.0,"cell y freq.")
  offz=Number("XY2=",2,165,80,85,25,offz.val,-96.0,96.0,"cell xy offset")
  offx=Number("<X>=",2,20,80,65,25,offx.val,-96.0,96.0,"cell X offset")
  offy=Number("<Y>=",2,92.5,80,65,25,offy.val,-96.0,96.0,"cell Y offset")
  offz1=Number("Z1=",2,20,45,137.5,25,offz1.val,-32.0,32.0)
  offz2=Number("Z2=",2,165,45,85,25,offz2.val,-32.0,32.0)
  cellf=Number("frequency =",2,20,110,137.5,25,cellf.val,0.0,64.0,"freq.")
  xres=Number("X Size =",2,20, 10, 110, 25, xres.val, 2, 128)
  yres=Number("Y Size =",2,140, 10, 110, 25, yres.val, 2, 128)
  #
  Button("Exit ", 1, 165, 200, 85, 25)
###
def event(evt, val):
  if (evt== QKEY and not val):
      Exit() 

def bevent(evt):
  if   (evt== 1):
     Exit()
  elif (evt== 2):
     Cell()
     Draw()
  elif (evt== 3):
     Cell()
     Redraw()

Cell()
Register(draw, event, bevent)
Blender.Redraw()

It would be nice if someone post a cellnoise image.

D/Led CGKit 1.0.1 but there’s no .pyd files in there. In crc there’s a “noisemodule.cpp” file and in the main folder there’s a “CgTypes.pyx”. I changed the noisemodule (that’s what the error call is for) to ‘noise’ but it don’t work. But the mushrooms do :smiley:

%<

you can find an adjustment for dynoise.py at:
http://www.zoo-logique.org/3D.Blender/scripts_python/snippets/cellnoise.py
http://www.zoo-logique.org/3D.Blender/scripts_python/snippets/images/cellnoisetest.jpg

Strange…i have noise.pyd and cgtypes.pyd after installed CGKit 1.0.1
on my pc they were in : c:\Python\Lib\site-packages\

For the Blender World Forge script ( BWF from mr. Selleri (S68)) you need the .pyd’s too and it work’s all fine on my pc.

This image is not cellnoise JMS !

It’s fine if you change the script…but it is no cellnoise.

I cant get your version of the script to work,not on 2.23 and not on 2.28

Cellnoise only works on Blender 2.27 and higher !!!

I agree, in fact this is not cellnoise.

( But it generate terrain for me on b2.23/2.25/2.27/2.28,
if i use the dynoise script not the so/dll… )

looks like it’s working. trying to figure this out. posting an image afterwards

EDIT
here it is. hope I did right.
http://files.blender3d.ch/temporary/cellnoise.jpg
http://files.blender3d.ch/temporary/cellnoise_settings.jpg

:smiley: :smiley: Chimera you got it right! This is cellnoise!
Thank’s for the image :smiley: :smiley:

kewl :smiley:

would be nice if you could post what the diffrent parameters do :). cuz I just dont get it… somehow

Best is to play with it,

raX=X random
raY=Y random
0=Z?offset
X =cell X frequency
Y =cell Y freq.
X2=cell X freq.
Y2 =cell Y freq.
XY2=cell XY offset
<X>=cell X offset
<Y>=cell Y offset
Z1=Z offset
Z2=Z2 offset
frequency = frequency
X Size = mesh size/resolution
Y Size = mesh size/resolution

Try this one with blender 2.23/2.25/2.26:
http://www.zoo-logique.org/3D.Blender/scripts_python/snippets/cellnoisebis.blend

:: plugin deluxe ::
:: needs nothing but python to work - no extra dynoise module - this can be handy if you have the .dll in your blender folder, to do other fine things ::

_here she goes::


##### CELLNOISE MX 2004 - compatible with 2.23 - 2.28 #####
'''self-standing script, requires python, no dynoise needed'''

'''
::once upon time, there was a fine young man called Jimmy Haze.
Supposedly inspired with great works of Mr. S68, he layed down
a script, which was to produce some extraordinary shapes - out
of thin data. Then a master of masters, the mighty *jms* came
along and saw a different kind of potential in this little cutie.
He twisted her with his mighty piton and pushed her in another
direction. Then, she fell right into my arms ...
Needless to say, after that, she was never quite the same again.
But, as with all things, I have lost my interest in her somehow.

Mean as mustard, she is now available for your pleasure, too.

btw: http://www.acidplanet.com/mauseoleum/ is ::the place to go::
'''

import Blender
from Blender import NMesh, Draw, BGL
from Blender.Draw import *
from Blender.BGL import *
from math import floor, pow, sin

xres	= Create(32)
yres	= Create(32)
cellf	= Create(2)
cex	= Create(1.0)
cey	= Create(1.0)
cez	= Create(0)
cezz	= Create(0)
offz	= Create(0)
offx	= Create(0.0)
offy	= Create(0.0)
offz1	= Create(1)
offz2	= Create(1)
rx	= Create(0.0)
ry	= Create(0.0)
rz	= Create(0)

class NGEN:
	def __init__(self, seed=1):
		self.InitNoise(seed)

	def InitNoise(self, seed):
		self.IA		= 16807
		self.IM		= 2147483647
		self.AM		= 1.0/self.IM
		self.IQ		= 127773
		self.IR		= 2836
		self.MASK	= 123459876
		self.seed	= seed
		self.__InitFNoise()

	def __InitFNoise(self, MaxNoise=16):
		self.NK1	= MaxNoise+1
		self.NK2	= self.NK1*self.NK1
		self.NCUBE	= self.NK2*self.NK1
		self.NMask	= MaxNoise-1
		self.xyz1	= 1
		self.xy1z	= self.NK1
		self.xy1z1	= self.NK1+1
		self.x1yz	= self.NK2
		self.x1yz1	= self.NK2+1
		self.x1y1z	= self.NK2+self.NK1
		self.x1y1z1	= self.NK2+self.NK1+1
		self.NMTX	= []
		for i in range(self.NCUBE):
			self.NMTX.append(2.0*self.random()-1.0)
		for x in range(self.NK1):
			i	= x
			if i==MaxNoise: i=0
			for y in range(self.NK1):
				j	= y
				if j == MaxNoise: j=0
				for z in range(self.NK1):
					k	= z
					if k == MaxNoise: k=0
					self.NMTX[x*self.NK2 + y*self.NK1 + z] = self.NMTX[i*self.NK2 + j*self.NK1 + k]

	def FNoise(self, pos):
		x	= abs(pos[0])
		y	= abs(pos[1])
		z	= abs(pos[2])
		try:
			ix	= int(x) & self.NMask
			iy	= int(y) & self.NMask
			iz	= int(z) & self.NMask
		except:
			ix	= int(x % self.MaxNoise)
			iy	= int(y % self.MaxNoise)
			iz	= int(z % self.MaxNoise)
		ox	= x - floor(x)
		oy	= y - floor(y)
		oz	= z - floor(z)
		ox	= ox * ox * (3.0 - 2.0 * ox)
		IDX	= ix*self.NK2 + iy*self.NK1 + iz
		NS	= self.NMTX
		p000	= NS[IDX]
		p001	= NS[IDX + self.xyz1]
		p010	= NS[IDX + self.xy1z]
		p011	= NS[IDX + self.xy1z1]
		p00	= (NS[IDX + self.x1yz] - p000) * ox + p000
		p01	= (NS[IDX + self.x1yz1] - p001) * ox + p001
		p10	= (NS[IDX + self.x1y1z] - p010) * ox + p010
		p11	= (NS[IDX + self.x1y1z1] - p011) * ox + p011
		oy	= oy * oy * (3.0 - 2.0 * oy)
		p0	= (p10 - p00) * oy + p00
		p1	= (p11 - p01) * oy + p01
		return ((p1 - p0) * (oz * oz * (3.0 - 2.0 * oz)) + p0)

	def random(self):
		self.seed	^= self.MASK
		k		= self.seed / self.IQ
		self.seed	= self.IA * (self.seed - k*self.IQ) - self.IR*k
		if self.seed&lt;0: self.seed += self.IM
		R		= self.AM * self.seed
		self.seed	^= self.MASK
		return R

NG = NGEN()

def InitNoise(seed):	NG.InitNoise(seed)

def random():		return NG.random()

def Fna(i,j):
	xv	=	(i-xmax/2.0)/10.0
	yv	=	(j-ymax/2.0)/10.0
	xn	=	(xv/2)*cex.val*cellf.val+offx.val
	xn	+=	0.25*rx.val*random()
	yn	=	(yv/2)*cey.val*cellf.val+offy.val
	yn	+=	0.25*ry.val*random()
	xm	=	(xv/2)*cez.val*0.5*cellf.val+offz.val
	xm	+=	0.25*rx.val*random()
	ym	=	 (yv/2)*cezz.val*0.5*cellf.val+offz.val
	ym	+=	0.25*ry.val*random()
	pos	=	[xn,yn,0.0]
	vn	=	NG.FNoise(pos)
	pos	=	[xm,ym,0.0]
	vm	=	NG.FNoise(pos)
	pos	=	[xm,yn,0.0]
	vo	=	NG.FNoise(pos)
	z	=	vn *offz1.val
	z	+=	vm *offz2.val
	z	+=	0.2*rz.val*sin(vn/vm*rz.val&lt;vo*2.0+1.5*rz.val)
	v	=	NMesh.Vert(i, j, z)
	me.verts.append(v)

def Fnb(i,j):
	a	= i+j*ymax
	f	= NMesh.Face()
	f.v.append(me.verts[a])
	f.v.append(me.verts[a+ymax])
	f.v.append(me.verts[a+ymax+1])
	f.v.append(me.verts[a+1])
	me.faces.append(f)

def Cell():
	global cex, cey, cez, cezz, cellf, rx, ry, rz, me
	global offx, offy, offz, offz1, offz2, xmax, ymax

	me	= NMesh.GetRaw()
	i = 0.0; j = 0.0; x = 0.0; y = 0.0; z = 0.0
	xmax = xres.val; ymax = yres.val

	[Fna(i,j) for j in range(0,ymax,1) for i in range(0,xmax,1)]
	[Fnb(i,j) for j in range(0,xmax-1) for i in range(0,ymax-1)]

	NMesh.PutRaw(me, "Cellnoise", 1)
	Blender.Redraw()

def Warn():
	BGL.glRasterPos2d(20, 230)
	Blender.Window.Redraw(Blender.Window.Const.TEXT)

def draw():
	global cex, cey, cez, cezz, cellf, rx, ry, rz, me
	global offx, offy, offz, offz1, offz2, xres, yres

	BGL.glClearColor(0.8, 0.8, 0.8, 1)
	BGL.glColor3f(1,1,1)
	BGL.glClear(BGL.GL_COLOR_BUFFER_BIT)

	glColor3f(0.1, 0.3, 0.7)
	glRectf(5, 1, 265, 235)

	glColor3f(0.6, 0.6, 0.8)
	glRectf(10, 6, 260, 190)

	BGL.glColor3f(0.9, 0.9, 0.9)
	BGL.glRasterPos2d(25, 210)
	Text("CELLNOISE MX 2004")

	rx	= Number("raX =",2,20,170,65,15,rx.val,0.0,16.0,"X*random")
	ry	= Number("raY =",2,92.5,170,65,15,ry.val,0.0,16.0,"Y*random")
	rz	= Number("rZ =",2,165,170,85,15,rz.val,-96.0,96.0)
	cex	= Number("X =",2,20,140,65,25,cex.val,0.0,16.0,"cell x freq.")
	cey	= Number("Y =",2,92.5,140,65,25,cey.val,0.0,16.0,"cell y freq.")
	cez	= Number("X2 =",2,165,140,85,25,cez.val,0.0,16.0,"cell x freq.")
	cezz	= Number("Y2 =",2,165,110,85,25,cezz.val,0.0,16.0,"cell y freq.")
	offz	= Number("XY2 =",2,165,80,85,25,offz.val,-96.0,96.0,"cell xy offset")
	offx	= Number("dX =",2,20,80,65,25,offx.val,-96.0,96.0,"cell X offset")
	offy	= Number("dY =",2,92.5,80,65,25,offy.val,-96.0,96.0,"cell Y offset")
	offz1	= Number("Z1 =",2,20,45,137.5,25,offz1.val,-32.0,32.0)
	offz2	= Number("Z2 =",2,165,45,85,25,offz2.val,-32.0,32.0)
	cellf	= Number("frequency =",2,20,110,137.5,25,cellf.val,0.0,64.0,"freq.")
	xres	= Number("X Size =",2,20, 10, 110, 25, xres.val, 2, 128)
	yres	= Number("Y Size =",2,140, 10, 110, 25, yres.val, 2, 128)

	yres	= xres

	Button("Exit", 1, 165, 200, 85, 25)

def event(evt, val):
	if (evt == QKEY and not val):	Exit()

def bevent(evt):
	if	(evt == 1):	Exit()
	elif	(evt == 2):	Cell(); Draw()
	elif	(evt == 3):	Cell(); Redraw()

Cell()
Register(draw, event, bevent)
Blender.Redraw()

…enjoy, fix the line endings if you have problems…
she was tested with 223, 225, 228a and c under macroshaft windows

Sorry, but, as jimmy said : this is not CellNoise.

:slight_smile:

did you test it jms? well I will. but I guess you’re right :slight_smile:

EDIT
btw… :slight_smile: could anyone tell me what this is good for? I found this…

Returns a value between 0 and 1 from a pseudo-random integer lattice.

the question is… what this could be good for in real. I thought of a canyon somehow :wink: