Skip to content

Commit dc82aaa

Browse files
committed
Fix texture boundaries in makeRing_compound
makeRing changes propagated over to makeRing_compound.
1 parent d0c2e47 commit dc82aaa

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

lib/glow/mesh.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@
311311
var s = c*offset
312312
for (var i=0; i<offset; i++) {
313313
var inext = (i+1) % offset
314-
var cnext = (c+1) % NC
315314
var v0 = shape[i]
316315
m.pos.push( v0.x,v0.y,v0.z )
317316

@@ -355,7 +354,7 @@
355354
var x=0, z=R2, newx, newz
356355
//var k = 1/Math.cos(dphi/2) // multiply z by k to stretch along the joint; only 1.00121, so approximate by 1
357356
var shape = [] // list of x,z points in the xz plane representing the shape at a joint
358-
for (var i=0; i<N; i++) {
357+
for (var i=0; i<N+1; i++) {
359358
//shape.push(vec(x,0,k*z-k*R2))
360359
shape.push(vec(x,0,z-R2)) // oval starts at outer edge of ring
361360
newx = x*cosd + z*sind
@@ -367,11 +366,11 @@
367366
var y=0, z=0.5, newy, newz
368367
var pts = []
369368
var normals = []
370-
for (var c=0; c<NC; c++) {
369+
for (var c=0; c<NC+1; c++) {
371370
var r = vec(0, y*size.y, z*size.z) // vector from origin to outer edge of oval cross section
372371
var n = vec(0, y, z).norm() // outward-going normal to cross section
373372
var center = r.sub(n.multiply(R2)) // center of cross section
374-
for (var i=0; i<N; i++) {
373+
for (var i=0; i<N+1; i++) {
375374
var xc = shape[i].x
376375
var zc = shape[i].z
377376
var p = vec(xc,0,0).add(n.multiply(zc)).add(r)
@@ -385,14 +384,16 @@
385384
}
386385

387386
var m = new Mesh()
388-
for (var c=0; c<NC; c++) {
389-
for (var i=0; i<N; i++) {
390-
var inext = (i+1) % N
387+
var offset = N+1
388+
for (var c=0; c<NC+1; c++) {
389+
var s = c*offset
390+
for (var i=0; i<offset; i++) {
391+
var inext = (i+1) % offset
391392
var cnext = (c+1) % NC
392-
var v0 = pts[c*N+i]
393+
var v0 = pts[s+i]
393394
m.pos.push( v0.x,v0.y,v0.z )
394395

395-
v0 = normals[c*N+i]
396+
v0 = normals[s+i]
396397
m.normal.push( v0.x,v0.y,v0.z )
397398

398399
m.color.push( 1, 1, 1 )
@@ -402,12 +403,14 @@
402403

403404
m.texpos.push( i/N, c/NC )
404405

405-
v0 = pts[c*N+inext].sub(pts[c*N+i])
406+
v0 = pts[s+inext].sub(pts[s+i])
406407
m.bumpaxis.push( v0.x,v0.y,v0.z )
407408

408-
m.index.push( N*c+i,N*cnext+i,N*cnext+inext, N*c+i,N*cnext+inext,N*c+inext )
409+
m.index.push( s+i,s+i+offset,s+i+offset+1, s+i,s+i+offset+1,s+i+1 )
409410
}
411+
m.index.length -= 6 // discard last set of indices
410412
}
413+
m.index.length -= 6*(offset-1) // discard entire last band of indices
411414
return m
412415
},
413416

0 commit comments

Comments
 (0)