@@ -76,14 +76,14 @@ def create_plane(xsegs, ysegs)
7676 grid ( xsegs , ysegs ) do |x , y | # using JRubyArt grid method
7777 u = x / xsegs . to_f
7878 v = y / ysegs . to_f
79-
79+
8080 # generate positions for the vertices of each cell
8181 # (-0.5 to center the shape around the origin)
8282 positions << Vec3D . new ( u - 0.5 , v - 0.5 , 0 )
8383 positions << Vec3D . new ( u + usegsize - 0.5 , v - 0.5 , 0 )
8484 positions << Vec3D . new ( u + usegsize - 0.5 , v + vsegsize - 0.5 , 0 )
8585 positions << Vec3D . new ( u - 0.5 , v + vsegsize - 0.5 , 0 )
86-
86+
8787 # generate texture coordinates for the vertices of each cell
8888 tex_coords << Vec2D . new ( u , v )
8989 tex_coords << Vec2D . new ( u + usegsize , v )
@@ -95,19 +95,24 @@ def create_plane(xsegs, ysegs)
9595
9696 texture_mode ( NORMAL ) # set texture_mode to normalized (range 0 to 1)
9797 tex = images [ 0 ]
98-
99- mesh = create_shape # create the initial PShape
100- renderer = ShapeRender . new ( mesh ) # initialize the shape renderer
101- mesh . begin_shape ( QUADS ) # define the PShape type: QUADS
102- mesh . no_stroke
103- mesh . texture ( tex ) # set a texture to make a textured PShape
104- # put all the vertices, uv texture coordinates and normals into the PShape
105- positions . each_with_index do |p , i |
106- p . to_vertex_uv ( renderer , tex_coords [ i ] ) # NB: tex_coords as Vec2D
107- # p.to_vertex_uv(renderer, u, v) # u, v as floats is the alternate form
98+ # create the initial PShape
99+ create_shape . tap do |mesh |
100+ # initialize the shape renderer
101+ renderer = ShapeRender . new ( mesh )
102+ # define the PShape type: QUADS
103+ mesh . begin_shape ( QUADS )
104+ # set a texture to make a textured PShape
105+ mesh . no_stroke
106+ mesh . texture ( tex )
107+ # put all the vertices, uv texture coordinates and normals into the PShape
108+ positions . each_with_index do |p , i |
109+ # NB: tex_coords as Vec2D
110+ p . to_vertex_uv ( renderer , tex_coords [ i ] )
111+ # p.to_vertex_uv(renderer, u, v) # u, v as floats is the alternate form
112+ end
113+ mesh . end_shape
108114 end
109- mesh . end_shape
110- mesh # our work is done here, return DA MESH! -)
115+ # our work is done here, return DA MESH! -)
111116end
112117
113118def key_pressed
0 commit comments