This is my first script,
it’s a mushroom creator…
Have fun !
#############################################################
##
## _mushroom_ 0.12
##
## _Jimmy Haze_ 24/9/2003
##
#############################################################
import Blender
from Blender import *
from Blender.Draw import *
from Blender.BGL import *
from math import *
from whrandom import random
#############################################################
#
#############################################################
#
resolc=Create(32)
#
cw=Create(1.5)
cl=Create(0.75)
cs=Create(1.0)
#
csinb=Create(0.0)
csinc=Create(0.0)
csind=Create(0.0)
#
che=Create(0.0)
#####
resols=Create(32)
#
sl=Create(2.0)
st=Create(0.5)
ss=Create(1.0)
#
ssinb=Create(0.0)
ssinc=Create(0.0)
ssind=Create(0.0)
#
randmc=Create(0.0)
randms=Create(0.0)
#
smooth=Create(0.0)
#
#############################################################
# Main function #
#############################################################
def create():
global resolc, cs, cw, cl, randmc, che
global resols, ss, sl, st, randms
global csinb, csinc, csind, ssinb, ssinc, ssind
global smooth
#############################################################################
# cap
########################
mec=NMesh.GetRaw()
i=0.0
j=0.0
n=resolc.val
###########################
for i in range(0,n):
for j in range(0,n):
#
fx=0.1*csinb.val*sin(i*csinc.val+csinc.val+j*csind.val+csind.val)
#
x=sin(j*pi*2/(n-1))*cos(-pi/2+i*pi/(n-1))*cw.val
x+= fx +0.1*randmc.val*random()
y=cos(j*pi*2/(n-1))*cos(-pi/2+i*pi/(n-1))*cw.val
y+= fx +0.1*randmc.val*random()
z=sin(-pi/2* cs.val *i*pi/(n+1))*cl.val
#
z=z+sl.val*ss.val+ss.val +che.val
#
#
v=NMesh.Vert(x,y,z)
mec.verts.append(v)
###############################################
n0=len(range(0,n))
for i in range(0,n-1):
for j in range(0,n-1):
#
f=NMesh.Face()
#
if smooth.val: f.smooth=1
#
f.v.append(mec.verts[i*n0+j])
f.v.append(mec.verts[i*n0+j+1])
f.v.append(mec.verts[(i+1)*n0+j+1])
f.v.append(mec.verts[(i+1)*n0+j])
#
mec.faces.append(f)
#
NMesh.PutRaw(mec,"cap",1)
#############################################################################
# stem
#######################
mes=NMesh.GetRaw()
i=0.0
j=0.0
n=resols.val
###########################
for i in range(0,n):
for j in range(0,n):
#
fxs=0.1*ssinb.val*sin(i*ssinc.val+ssinc.val+j*ssind.val+ssind.val)
#
x=sin(j*pi*2/(n-1))*cos(-pi/2+i*pi/(n-1))*st.val
x+= fxs +0.1*randms.val*random()
y=cos(j*pi*2/(n-1))*cos(-pi/2+i*pi/(n-1))*st.val
y+= fxs +0.1*randms.val*random()
z=sin(-pi/2-0.8+ss.val*i*pi/(n+1))*sl.val+fxs
#
z=z+sl.val
#
v=NMesh.Vert(x,y,z)
mes.verts.append(v)
########################################
n0=len(range(0,n))
for i in range(0,n-1):
for j in range(0,n-1):
#
f=NMesh.Face()
if smooth.val: f.smooth=1
f.v.append(mes.verts[i*n0+j])
f.v.append(mes.verts[i*n0+j+1])
f.v.append(mes.verts[(i+1)*n0+j+1])
f.v.append(mes.verts[(i+1)*n0+j])
#
mes.faces.append(f)
NMesh.PutRaw(mes,"mstem",1)
Blender.Redraw()
#############################################################
# Gui #
#############################################################
def Warn():
BGL.glRasterPos2d(5, 360)
Blender.Window.Redraw(Blender.Window.Const.TEXT)
###########
def draw():
global resolc, cs, cw, cl, randmc, che
global resols, ss, sl, st, randms
global csinb, csinc, csind, ssinb, ssinc, ssind
global smooth
####
BGL.glClearColor(0.6, 0.6, 0.6, 1)
BGL.glColor3f(1,1,1)
BGL.glClear(BGL.GL_COLOR_BUFFER_BIT)
##
glColor3f(0.7, 0.0, 0.0)
glRectf(5, 200, 215, 345)
glColor3f(0.8, 0.8, 0.8)
glRectf(5, 45, 215, 190)
##
BGL.glColor3f(0.0, 0.0, 0.0)
BGL.glRasterPos2d(5, 360)
Text("mushroom creator")
####
cw=Number("cap width = ",2,10, 325, 200, 15, cw.val, 0.2, 4.0)
cl=Number("cap length = ",2,10, 300, 200, 15, cl.val, 0.2, 4.0)
cs=Number("cap sharpness = ",2,10, 275, 200, 15, cs.val, 0.7, 1.0)
csinb=Number("sin=",2,10, 250, 60, 15, csinb.val, 0.0, 16.0,"sinus size")
csinc=Number("s b=",2,80, 250, 60, 15, csinc.val, 0.0, 32.0,"sinus x freq")
csind=Number("s c=",2,150, 250, 60, 15, csind.val, 0.0, 32.0,"sinus y freq")
randmc=Number("randomise cap =",2,10, 230, 130, 15, randmc.val, 0.0, 2.0)
che=Number("-Z+",2,150, 205, 60, 40, che.val, -12.0, 12.0,"cap Z offset")
resolc=Number("Resolution cap=",2,10, 205, 130, 20, resolc.val, 8, 64)
####
sl=Number("stem length = ",2,10, 170, 200, 15, sl.val, 0.2, 4.0)
st=Number("stem thikness = ",2,10, 145, 200, 15, st.val, 0.1, 2.0)
ss=Number("stem shape = ",2,10, 120, 200, 15, ss.val, 0.75, 1.5)
ssinb=Number("sin=",2,10, 95, 60, 15, ssinb.val, 0.0, 16.0," sinus size ")
ssinc=Number("s b = ",2,80, 95, 60, 15, ssinc.val, 0.0, 32.0," sinus x freq")
ssind=Number("s c = ",2,150, 95, 60, 15, ssind.val, 0.0, 32.0," sinus y freq")
randms=Number("randomise stem =",2,10, 75, 130, 15, randms.val, 0.0, 2.0)
resols=Number("Resolution stem=",2,10, 50, 130, 20, resols.val, 8, 64)
####
smooth=Toggle("smooth", 2, 10, 10, 60, 25, smooth.val)
Button("Exit ", 1, 150, 10, 60, 25, "EXIT")
####
def event(evt, val):
if (evt== QKEY and not val):
Exit()
def bevent(evt):
if (evt== 1):
Exit()
elif (evt== 2):
create()
Draw()
####
create()
Register(draw, event, bevent)
Blender.Redraw()
#############################
26/9/2003 updated
from:
fx=0.1csinb.valsin(icsinc.val+csind.valjcsinc.val+csind.val)
to:
fx=0.1csinb.valsin(icsinc.val+csinc.val+j*csind.val+csind.val)
I cant solve problem with normals
you have to recalc normals (edit mode, sellect all verts, hit Ctrl-N)