Fixed octahedral triangulated spheroid().

This commit is contained in:
Revar Desmera 2020-06-23 04:40:36 -07:00
parent 70b72dd3ac
commit 38b45544ee
2 changed files with 42 additions and 35 deletions

View file

@ -1207,23 +1207,16 @@ function spheroid(r, d, circum=false, style="aligned", anchor=CENTER, spin=0, or
for (j=[0:1:hsides-1]) let(theta = (j+((stagger && i%2!=0)?0.5:0))*360/hsides) for (j=[0:1:hsides-1]) let(theta = (j+((stagger && i%2!=0)?0.5:0))*360/hsides)
spherical_to_xyz(rr, theta, phi), spherical_to_xyz(rr, theta, phi),
spherical_to_xyz(rr, 0, 180) spherical_to_xyz(rr, 0, 180)
] : style=="octa"? [ ] : style=="octa"? let(
for (tb=[0,1], i=[0:1:3]) let( meridians = [
theta0 = (i+0.5)*360/4, 1,
theta1 = (i+1.0)*360/4, for (i = [1:1:octa_steps]) i*4,
theta2 = (i+0.0)*360/4, for (i = [octa_steps-1:-1:1]) i*4,
phi0 = tb? 0 : 180, 1,
phi1 = 90 ]
) ) [
for (k = [0:1:octa_steps]) let( for (i=idx(meridians), j=[0:1:meridians[i]-1])
u = k/octa_steps, spherical_to_xyz(rr, j*360/meridians[i], i*180/(len(meridians)-1))
phi = lerp(phi0, phi1, u)
)
for (l = [0:1:k]) let(
v = k? l/k : 0,
theta = lerp(theta1, theta2, v),
pt = spherical_to_xyz(rr,theta,phi)
) pt
] : style=="icosa"? [ ] : style=="icosa"? [
for (tb=[0,1], j=[0,2], i = [0:1:4]) let( for (tb=[0,1], j=[0,2], i = [0:1:4]) let(
theta0 = i*360/5, theta0 = i*360/5,
@ -1250,7 +1243,7 @@ function spheroid(r, d, circum=false, style="aligned", anchor=CENTER, spin=0, or
v = k? l/k : 0, v = k? l/k : 0,
pt = rot(ang2*v, v=ax2, p=vv0) * rr * (tb? -1 : 1) pt = rot(ang2*v, v=ax2, p=vv0) * rr * (tb? -1 : 1)
) pt ) pt
] : assert(in_list(style,["orig","aligned","stagger","icosa"])), ] : assert(in_list(style,["orig","aligned","stagger","octa","icosa"])),
lv = len(verts), lv = len(verts),
faces = style=="orig"? [ faces = style=="orig"? [
[for (i=[0:1:hsides-1]) hsides-i-1], [for (i=[0:1:hsides-1]) hsides-i-1],
@ -1278,24 +1271,38 @@ function spheroid(r, d, circum=false, style="aligned", anchor=CENTER, spin=0, or
] ]
) )
] : style=="octa"? let( ] : style=="octa"? let(
pyr = [for (x=[0:1:octa_steps+1]) x], meridians = [
tri = sum(pyr), 0, 1,
soff = cumsum(pyr) for (i = [1:1:octa_steps]) i*4,
for (i = [octa_steps-1:-1:1]) i*4,
1,
],
offs = cumsum(meridians),
pc = select(offs,-1)-1,
os = octa_steps * 2
) [ ) [
for (tb=[0,1], j=[0,1], i = [0:1:3]) let( for (i=[0:1:3]) [0, 1+(i+1)%4, 1+i],
base = ((((tb*2) + j) * 4) + i) * tri for (i=[0:1:3]) [pc-0, pc-(1+(i+1)%4), pc-(1+i)],
for (i=[1:1:octa_steps-1]) let(
m = meridians[i+2]/4
) )
for (k = [0:1:octa_steps-1]) for (j=[0:1:3], k=[0:1:m-1]) let(
for (l = [0:1:k]) let( m1 = meridians[i+1],
v1 = base + soff[k] + l, m2 = meridians[i+2],
v2 = base + soff[k+1] + l, p1 = offs[i+0] + (j*m1/4 + k+0) % m1,
v3 = base + soff[k+1] + (l + 1), p2 = offs[i+0] + (j*m1/4 + k+1) % m1,
faces = [ p3 = offs[i+1] + (j*m2/4 + k+0) % m2,
if(l>0) [v1-1,v1,v2], p4 = offs[i+1] + (j*m2/4 + k+1) % m2,
[v1,v3,v2], p5 = offs[os-i+0] + (j*m1/4 + k+0) % m1,
], p6 = offs[os-i+0] + (j*m1/4 + k+1) % m1,
faces2 = (tb+j)%2? [for (f=faces) reverse(f)] : faces p7 = offs[os-i-1] + (j*m2/4 + k+0) % m2,
) each faces2 p8 = offs[os-i-1] + (j*m2/4 + k+1) % m2
) each [
[p1, p4, p3],
if (k<m-1) [p1, p2, p4],
[p5, p7, p8],
if (k<m-1) [p5, p8, p6],
],
] : style=="icosa"? let( ] : style=="icosa"? let(
pyr = [for (x=[0:1:icosa_steps+1]) x], pyr = [for (x=[0:1:icosa_steps+1]) x],
tri = sum(pyr), tri = sum(pyr),

View file

@ -8,7 +8,7 @@
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
BOSL_VERSION = [2,0,368]; BOSL_VERSION = [2,0,369];
// Section: BOSL Library Version Functions // Section: BOSL Library Version Functions