Q Temporal Surfaces

I wrote a script to generate a qts as I call them with a given number of subdivisions…


the math:

the script:


import bpy
import mathutils
from mathutils import Vector

def createMeshFromData(name, origin, verts, faces):
# Create mesh and object
me = bpy.data.meshes.new(name+'Mesh')
ob = bpy.data.objects.new(name, me)
ob.location = origin
ob.show_name = True

# Link object to scene and make active
scn = bpy.context.scene
scn.objects.link(ob)
scn.objects.active = ob
ob.select = True

# Create mesh from given verts, faces.
me.from_pydata(verts, [], faces)
# Update mesh with new data
me.update() 
return ob

def qts(s, t, P, C):
point = [0,0,0]
for d in range(0, 3):
for j in range(0, 3):
for i in range(0, 3):
for b in range(0, 3):
for a in range(0, 3):
point[d]+= 1.0*s**i*t**j*P[b][a][d]*C[3*j+b][3*i+a]
return point 
def run(origo):
origin = Vector(origo)
P = (((-1, -1, 0),(0, -1, 2),(1, -1, 3)),((1, 0, 0),(0, 0, 1),(1, 0, 2)),((-1, 1, 0),(0, 1, 2),(1, 1, 1)))
C = [[1, 0, 0, -1.5, 2, -.5, .5, -1, .5],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[-1.5, 0,0, 2.25, -3, .75, -.75, 1.5, -.75],[2, 0, 0, -3, 4, -1, 1, -2, 1],[-.5, 0, 0, .75, -1, .25, -.25, .5, -.25],[.5, 0, 0, -.75, 1, -.25, .25, -.5, .25],[-1, 0, 0, 1.5, -2, .5, -.5, 1, -.5],[.5, 0, 0, -.75, 1, -.25, .25, -.5, .25]]
sample = [10, 10]
verts = []
for j in range(0, sample[1]+1):
for i in range(0, sample[0]+1):
t = 2.0*j/sample[1]
s = 2.0*i/sample[0]
verts.append(tuple(qts(s, t, P, C)))

verts = tuple(verts)
faces = []
for j in range(0, sample[1]):
for i in range(0, sample[0]):
faces.append(((sample[0]+1)*j + i, (sample[0]+1)*j+i+1, (sample[0]+1)*(j+1)+i+1, (sample[0]+1)*(j+1)+i))
faces = tuple(faces)
cone1 = createMeshFromData('DataCone', origin, verts, faces)

return

if __name__ == "__main__":
run((0,0,0))

Sir, you should put your code in-between tag [\CODE][/CODE] (please remove )


import bpy
import mathutils
from mathutils import Vector

def createMeshFromData(name, origin, verts, faces):
# Create mesh and object
me = bpy.data.meshes.new(name+'Mesh')
ob = bpy.data.objects.new(name, me)
ob.location = origin
ob.show_name = True

# Link object to scene and make active
scn = bpy.context.scene
scn.objects.link(ob)
scn.objects.active = ob
ob.select = True

# Create mesh from given verts, faces.
me.from_pydata(verts, [], faces)
# Update mesh with new data
me.update() 
return ob

def qts(s, t, P, C):
point = [0,0,0]
for d in range(0, 3):
for j in range(0, 3):
for i in range(0, 3):
for b in range(0, 3):
for a in range(0, 3):
point[d]+= 1.0*s**i*t**j*P[b][a][d]*C[3*j+b][3*i+a]
return point 
def run(origo):
origin = Vector(origo)
P = (((-1, -1, 0),(0, -1, 2),(1, -1, 3)),((1, 0, 0),(0, 0, 1),(1, 0, 2)),((-1, 1, 0),(0, 1, 2),(1, 1, 1)))
C = [[1, 0, 0, -1.5, 2, -.5, .5, -1, .5],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[-1.5, 0,0, 2.25, -3, .75, -.75, 1.5, -.75],[2, 0, 0, -3, 4, -1, 1, -2, 1],[-.5, 0, 0, .75, -1, .25, -.25, .5, -.25],[.5, 0, 0, -.75, 1, -.25, .25, -.5, .25],[-1, 0, 0, 1.5, -2, .5, -.5, 1, -.5],[.5, 0, 0, -.75, 1, -.25, .25, -.5, .25]]
sample = [10, 10]
verts = []
for j in range(0, sample[1]+1):
for i in range(0, sample[0]+1):
t = 2.0*j/sample[1]
s = 2.0*i/sample[0]
verts.append(tuple(qts(s, t, P, C)))

verts = tuple(verts)
faces = []
for j in range(0, sample[1]):
for i in range(0, sample[0]):
faces.append(((sample[0]+1)*j + i, (sample[0]+1)*j+i+1, (sample[0]+1)*(j+1)+i+1, (sample[0]+1)*(j+1)+i))
faces = tuple(faces)
cone1 = createMeshFromData('DataCone', origin, verts, faces)

return

if __name__ == "__main__":
run((0,0,0))

Tried running the script in text editor, got many “expected indent” and return errors, how should I try your script?