Creating a Mesh

< Previous | Contents | Manuals Home | Boris FX | Next >

Creating a Mesh

The following code creates a small planar mesh.

# ; Create Test Mesh import SyPy

hlev = SyPy.SyLevel() hlev.OpenExisting()

# hlev.OpenSynthEyes()


def WriteVerts(msh, hgrid, vgrid): vc = 1

for v in range(0, vgrid+1): for h in range(0, hgrid+1):

tu = float(h) / float(hgrid) tv = float(v) / float(vgrid)

pu = (tu - 0.5)*2 # raw image coordinates pv = (tv - 0.5)*2

msh.Call("SetVtx", vc, [pu, pv, 0])

msh.Call("SetVtxTexCo", vc, [tu, 1.0 - tv]) vc += 1

msh.Call("UpdateVtxs") msh.Call("UpdateTexCos")

def WriteFaces(msh, hgrid, vgrid): fc = 1

stride = hgrid+1

for v in range(0, vgrid): for h in range(0, hgrid):

vb = v*stride + h + 1; # Vertex numbers start at one msh.Call("SetFace", fc, [vb, vb+1, vb+stride+1]) msh.Call("SetFaceShow", fc, 3)

fc += 1

msh.Call("SetFace", fc, [vb, vb+stride+1, vb+stride]) msh.Call("SetFaceShow", fc, 6)

fc += 1


hlev.Begin()

msh = hlev.CreateNew("MESH") msh.nm = "My New Mesh" msh.kind = "Test"

hgrid = 16

vgrid = 9

WriteVerts(msh, hgrid, vgrid) WriteFaces(msh, hgrid, vgrid) hlev.Accept("Create test mesh")


©2024 Boris FX, Inc. — UNOFFICIAL — Converted from original PDF.