Skip to content

Commit ca912a7

Browse files
committed
Simplify creation of ring vertices
1 parent 652d1ea commit ca912a7

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

lib/glow/mesh.js

Lines changed: 9 additions & 18 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 c=0; c<N; c++) {
287+
for (var i=0; i<N; 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
@@ -293,43 +293,37 @@
293293
z = newz
294294
}
295295

296-
var m = new Mesh()
297296
var y=0, z=R1+R2, newy, newz
298-
var pts = []
299297
var normals = []
300298
for (var c=0; c<NC; c++) {
301299
var r = vec(0, y, z) // vector from origin to outer edge of oval cross section
302-
for (var i=0; i<N; i++) {
303-
pts.push(shape[i])
304-
normals.push(r) // use normal to contain the vector from origin to outer edge of the oval
305-
}
300+
normals.push(r) // use normal to contain the vector from origin to outer edge of the oval
301+
306302
newy = y*cphi + z*sphi
307303
newz = z*cphi - y*sphi
308304
y = newy
309305
z = newz
310306
}
311-
307+
308+
var m = new Mesh()
312309
for (var c=0; c<NC; c++) {
313310
for (var i=0; i<N; i++) {
314311
var inext = (i+1) % N
315312
var cnext = (c+1) % NC
316-
var v0 = pts[c*N+i]
313+
var v0 = shape[i]
317314
m.pos.push( v0.x,v0.y,v0.z )
318315

319-
v0 = normals[c*N+i]
316+
v0 = normals[c]
320317
m.normal.push( v0.x,v0.y,v0.z )
321318

322319
m.color.push( 1,1,1 )
323-
324320
m.opacity.push( 1 )
325-
326321
m.shininess.push( 1 )
327-
328322
m.emissive.push( 0 )
329323

330324
m.texpos.push( i/N, c/NC )
331325

332-
v0 = pts[c*N+inext].sub(pts[c*N+i])
326+
v0 = shape[inext].sub(shape[i])
333327
m.bumpaxis.push( v0.x,v0.y,v0.z )
334328

335329
m.index.push( N*c+i,N*cnext+i,N*cnext+inext, N*c+i,N*cnext+inext,N*c+inext )
@@ -357,7 +351,7 @@
357351
var x=0, z=R2, newx, newz
358352
//var k = 1/Math.cos(dphi/2) // multiply z by k to stretch along the joint; only 1.00121, so approximate by 1
359353
var shape = [] // list of x,z points in the xz plane representing the shape at a joint
360-
for (var c=0; c<N; c++) {
354+
for (var i=0; i<N; i++) {
361355
//shape.push(vec(x,0,k*z-k*R2))
362356
shape.push(vec(x,0,z-R2)) // oval starts at outer edge of ring
363357
newx = x*cosd + z*sind
@@ -398,11 +392,8 @@
398392
m.normal.push( v0.x,v0.y,v0.z )
399393

400394
m.color.push( 1,1,1 )
401-
402395
m.opacity.push( 1 )
403-
404396
m.shininess.push( 1 )
405-
406397
m.emissive.push( 0 )
407398

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

0 commit comments

Comments
 (0)