@@ -76,14 +76,14 @@ def create_plane(xsegs, ysegs)
76
76
grid ( xsegs , ysegs ) do |x , y | # using JRubyArt grid method
77
77
u = x / xsegs . to_f
78
78
v = y / ysegs . to_f
79
-
79
+
80
80
# generate positions for the vertices of each cell
81
81
# (-0.5 to center the shape around the origin)
82
82
positions << Vec3D . new ( u - 0.5 , v - 0.5 , 0 )
83
83
positions << Vec3D . new ( u + usegsize - 0.5 , v - 0.5 , 0 )
84
84
positions << Vec3D . new ( u + usegsize - 0.5 , v + vsegsize - 0.5 , 0 )
85
85
positions << Vec3D . new ( u - 0.5 , v + vsegsize - 0.5 , 0 )
86
-
86
+
87
87
# generate texture coordinates for the vertices of each cell
88
88
tex_coords << Vec2D . new ( u , v )
89
89
tex_coords << Vec2D . new ( u + usegsize , v )
@@ -95,19 +95,24 @@ def create_plane(xsegs, ysegs)
95
95
96
96
texture_mode ( NORMAL ) # set texture_mode to normalized (range 0 to 1)
97
97
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
108
114
end
109
- mesh . end_shape
110
- mesh # our work is done here, return DA MESH! -)
115
+ # our work is done here, return DA MESH! -)
111
116
end
112
117
113
118
def key_pressed
0 commit comments