Skip to content

Commit d0c2e47

Browse files
committed
Fix texture boundaries in makeRing
Texture coordinates didn't go all the way up to 1 at the seams. This caused "ghost" textures to appear between vertices on either side of the seams. The fix is to duplicate vertices at the seams, one with texture coord=0 and one with texture coord=1.
1 parent ca912a7 commit d0c2e47

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

lib/glow/mesh.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@
284284
var x=0, z=R2, newx, newz
285285
//var k = 1/Math.cos(dphi/2) // multiply z by k to stretch along the joint; only 1.00121, so approximate by 1
286286
var shape = [] // list of x,z points in the xz plane representing the shape at a joint
287-
for (var i=0; i<N; i++) {
287+
for (var i=0; i<N+1; i++) {
288288
//shape.push(vec(x,0,k*z-k*R2))
289289
shape.push(vec(x,0,z-R2)) // oval starts at outer edge of ring
290290
newx = x*cosd + z*sind
@@ -295,7 +295,7 @@
295295

296296
var y=0, z=R1+R2, newy, newz
297297
var normals = []
298-
for (var c=0; c<NC; c++) {
298+
for (var c=0; c<NC+1; c++) {
299299
var r = vec(0, y, z) // vector from origin to outer edge of oval cross section
300300
normals.push(r) // use normal to contain the vector from origin to outer edge of the oval
301301

@@ -306,17 +306,19 @@
306306
}
307307

308308
var m = new Mesh()
309-
for (var c=0; c<NC; c++) {
310-
for (var i=0; i<N; i++) {
311-
var inext = (i+1) % N
309+
var offset = N+1
310+
for (var c=0; c<NC+1; c++) {
311+
var s = c*offset
312+
for (var i=0; i<offset; i++) {
313+
var inext = (i+1) % offset
312314
var cnext = (c+1) % NC
313315
var v0 = shape[i]
314316
m.pos.push( v0.x,v0.y,v0.z )
315317

316318
v0 = normals[c]
317319
m.normal.push( v0.x,v0.y,v0.z )
318320

319-
m.color.push( 1,1,1 )
321+
m.color.push( 1, 1, 1 )
320322
m.opacity.push( 1 )
321323
m.shininess.push( 1 )
322324
m.emissive.push( 0 )
@@ -326,9 +328,11 @@
326328
v0 = shape[inext].sub(shape[i])
327329
m.bumpaxis.push( v0.x,v0.y,v0.z )
328330

329-
m.index.push( N*c+i,N*cnext+i,N*cnext+inext, N*c+i,N*cnext+inext,N*c+inext )
330-
}
331+
m.index.push( s+i,s+i+offset,s+i+offset+1, s+i,s+i+offset+1,s+i+1 )
332+
}
333+
m.index.length -= 6 // discard last set of indices
331334
}
335+
m.index.length -= 6*(offset-1) // discard entire last band of indices
332336
return m
333337
},
334338

@@ -391,7 +395,7 @@
391395
v0 = normals[c*N+i]
392396
m.normal.push( v0.x,v0.y,v0.z )
393397

394-
m.color.push( 1,1,1 )
398+
m.color.push( 1, 1, 1 )
395399
m.opacity.push( 1 )
396400
m.shininess.push( 1 )
397401
m.emissive.push( 0 )

0 commit comments

Comments
 (0)