Mobius band script

Quick byproduct script to create a mobius band:


import Blender
from Blender import NMesh,Object
from Blender.NMesh import Col
from math import *

# makes a mobius band sir doesn't it

mesh = NMesh.GetRaw()

w = 1.0
r = 1.0
dy = 10.0
turns = 0.5
dt = 0.0
x = 0.0
y = 0.0
z = 0.0
dv = 0
nverts = 0
f = NMesh.Face()
swap = 0
pv = NMesh.Vert(x,y,z)
v = NMesh.Vert(x,y,z)
nt = 1

for dr in range(0,360,1):
	a = dr*2*pi/360
	y = r * cos(a)
	z = r * sin(a) 
	x = -w/2
	for ddr in range(0,2,1):
		x += w * (ddr) 
		dt = dt + 2*pi/360*turns
		pv = v
		ly = 0-y
		lx = w * sin(dt) - x
		lz = w * cos(dt) - z
		aa = nt * a
		yy = ly * cos(aa) - lz * sin(aa)
		zz = lz * cos(aa) + ly * sin(aa)
		xx = lx * cos(aa) - ly * sin(aa)
		yy = lx * sin(aa) + ly * cos(aa)
		v = NMesh.Vert(xx,yy,zz)
		if (swap==1 and ddr==1):
			mesh.verts.append(v)
			mesh.verts.append(pv)
			f.v.append(v)
			f.v.append(pv)
		elif(swap==0):
			mesh.verts.append(v)
			f.v.append(v)
		dv += 1
		nverts +=1
	if(dv==4):
		mesh.faces.append(f)
		f = NMesh.Face()
		if(swap==1):
			f.v.append(v)
			f.v.append(pv)
		else:
			f.v.append(pv)
			f.v.append(v)		
		dv = 2
	swap = 1-swap


NMesh.PutRaw(mesh,"mobius",1)


Blender.Redraw()

I think this band is bit large, so I couldn’t find it that was generated by script at first.

The normals aren’t recalculated.

Very nice, but like YamYam, I couldn’t find it at first.

(edited to make it smaller - variables w and r now 1.0 not 100.0)

Normals are still the same:!

http://img.photobucket.com/albums/v332/R2Blend/notgoood.png

Only noticeable when subsurfed, and fixed when normals are re-calculated.