Hi everyone,
I’d like to display a TRIANGLE_STRIP
mesh as a PShape object but when doing so the mesh “closes” on itself (lines connecting the last points to the first points of the mesh appear)
Here’s an example to be as clear as possible:
Mesh computed in draw()
every frame (working correctly but slow)
add_library('peasycam')
scl = 10
def setup():
global n_rows, n_cols, terrain
size(1200, 800, P3D)
cam = PeasyCam(this, 1800)
n_cols, n_rows = width / scl, width / scl
terrain = [[0 for e in range(n_rows)] for f in range(n_cols)]
yoff = 0
for y in range(n_rows):
xoff = 0
for x in range(n_cols):
noiseDetail(8)
ny = map(y, 0, n_rows, 0, 1)
nx = map(x, 0, n_cols, 0, 2)
n_value = map(noise(nx*1.6, ny), 0, 1, -200, 1000)
terrain[x][y] = n_value
xoff += .014
yoff += .011
def draw():
background(240)
pushMatrix()
translate(-width/2, height/2, -width/2)
rotateX(PI/2)
for y in range(n_rows-1):
beginShape(TRIANGLE_STRIP)
fill(240)
for x in range(n_cols):
vertex(x * scl, y * scl, terrain[x][y] )
vertex(x * scl, (y + 1) * scl, terrain[x][y + 1] )
endShape()
popMatrix()
Mesh computed in setup()
and stored in a PShape object (not working correctly but fast)
add_library('peasycam')
scl = 10
def setup():
global mesh, n_rows, n_cols, terrain
size(1200, 800, P3D)
cam = PeasyCam(this, 1800)
n_cols, n_rows = width / scl, width / scl
terrain = [[0 for e in range(n_rows)] for f in range(n_cols)]
yoff = 0
for y in range(n_rows):
xoff = 0
for x in range(n_cols):
noiseDetail(8)
ny = map(y, 0, n_rows, 0, 1)
nx = map(x, 0, n_cols, 0, 2)
n_value = map(noise(nx*1.6, ny), 0, 1, -200, 1000)
terrain[x][y] = n_value
xoff += .014
yoff += .011
mesh = createShape()
for y in range(n_rows-1):
mesh.beginShape(TRIANGLE_STRIP)
mesh.fill(240)
for x in range(n_cols):
mesh.vertex(x * scl, y * scl, terrain[x][y] )
mesh.vertex(x * scl, (y + 1) * scl, terrain[x][y + 1] )
mesh.endShape()
def draw():
background(240)
pushMatrix()
translate(-width/2, height/2, -width/2)
rotateX(PI/2)
shape(mesh, 0, 0)
popMatrix()
I think the problem comes from the endShape()
function being called within the double for
loop and not ouside
of it but can’t seem to find a proper solution to this.