|
284 | 284 | var x=0, z=R2, newx, newz
|
285 | 285 | //var k = 1/Math.cos(dphi/2) // multiply z by k to stretch along the joint; only 1.00121, so approximate by 1
|
286 | 286 | 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++) { |
288 | 288 | //shape.push(vec(x,0,k*z-k*R2))
|
289 | 289 | shape.push(vec(x,0,z-R2)) // oval starts at outer edge of ring
|
290 | 290 | newx = x*cosd + z*sind
|
|
295 | 295 |
|
296 | 296 | var y=0, z=R1+R2, newy, newz
|
297 | 297 | var normals = []
|
298 |
| - for (var c=0; c<NC; c++) { |
| 298 | + for (var c=0; c<NC+1; c++) { |
299 | 299 | var r = vec(0, y, z) // vector from origin to outer edge of oval cross section
|
300 | 300 | normals.push(r) // use normal to contain the vector from origin to outer edge of the oval
|
301 | 301 |
|
|
306 | 306 | }
|
307 | 307 |
|
308 | 308 | 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 |
312 | 314 | var cnext = (c+1) % NC
|
313 | 315 | var v0 = shape[i]
|
314 | 316 | m.pos.push( v0.x,v0.y,v0.z )
|
315 | 317 |
|
316 | 318 | v0 = normals[c]
|
317 | 319 | m.normal.push( v0.x,v0.y,v0.z )
|
318 | 320 |
|
319 |
| - m.color.push( 1,1,1 ) |
| 321 | + m.color.push( 1, 1, 1 ) |
320 | 322 | m.opacity.push( 1 )
|
321 | 323 | m.shininess.push( 1 )
|
322 | 324 | m.emissive.push( 0 )
|
|
326 | 328 | v0 = shape[inext].sub(shape[i])
|
327 | 329 | m.bumpaxis.push( v0.x,v0.y,v0.z )
|
328 | 330 |
|
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 |
331 | 334 | }
|
| 335 | + m.index.length -= 6*(offset-1) // discard entire last band of indices |
332 | 336 | return m
|
333 | 337 | },
|
334 | 338 |
|
|
391 | 395 | v0 = normals[c*N+i]
|
392 | 396 | m.normal.push( v0.x,v0.y,v0.z )
|
393 | 397 |
|
394 |
| - m.color.push( 1,1,1 ) |
| 398 | + m.color.push( 1, 1, 1 ) |
395 | 399 | m.opacity.push( 1 )
|
396 | 400 | m.shininess.push( 1 )
|
397 | 401 | m.emissive.push( 0 )
|
|
0 commit comments