Skip to content

Instantly share code, notes, and snippets.

@croxis
Created August 21, 2013 21:41
Show Gist options
  • Save croxis/6300617 to your computer and use it in GitHub Desktop.
Save croxis/6300617 to your computer and use it in GitHub Desktop.
def myNormalize(myVec):
myVec.normalize()
return myVec
def create_mesh(parentnp, debug=False):
'''This creates a simple 17x17 grid mesh for the sides of our cube.
The ultimate goal is to use a LOD system, probably based on quadtrees.
If debug is true then we get a color gradiant on our vertexes.'''
x = -1.0
y = -1.0
vertex_count = 0
u = 0.0
v = 0.0
WIDTH_STEP = 2/16.0
while y <= 1.0:
while x <= 1.0:
vertex.addData3f(x, y, 0)
normal.addData3f(myNormalize((Vec3(2*x-1, 2*y-1, 2*0-1))))
if debug:
color.addData4f(1.0, u, v, 1.0)
texcoord.addData2f(u, v)
vertex_count += 1
x += WIDTH_STEP
u += WIDTH_STEP/2.0
x = -1.0
u = 0
y += WIDTH_STEP
v += WIDTH_STEP/2.0
print vertex_count
triangles = []
for y in range(0, 16):
for x in range(0, 16):
v = 17 * y + x
tri = GeomTriangles(Geom.UHDynamic)
tri.addVertex(v)
tri.addVertex(v+1)
tri.addVertex(v+17)
tri.closePrimitive()
triangles.append(tri)
tri = GeomTriangles(Geom.UHDynamic)
tri.addVertex(v+1)
tri.addVertex(v+18)
tri.addVertex(v+17)
tri.closePrimitive()
triangles.append(tri)
mesh = Geom(vdata)
for t in triangles:
mesh.addPrimitive(t)
mnode = GeomNode('quadface')
mnode.addGeom(mesh)
nodePath = parentnp.attachNewNode(mnode)
return nodePath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment