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)
spherical_to_xyz(rr, theta, phi),
spherical_to_xyz(rr, 0, 180)
] : style=="octa"? [
for (tb=[0,1], i=[0:1:3]) let(
theta0 = (i+0.5)*360/4,
theta1 = (i+1.0)*360/4,
theta2 = (i+0.0)*360/4,
phi0 = tb? 0 : 180,
phi1 = 90
)
for (k = [0:1:octa_steps]) let(
u = k/octa_steps,
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=="octa"? let(
meridians = [
1,
for (i = [1:1:octa_steps]) i*4,
for (i = [octa_steps-1:-1:1]) i*4,
1,
]
) [
for (i=idx(meridians), j=[0:1:meridians[i]-1])
spherical_to_xyz(rr, j*360/meridians[i], i*180/(len(meridians)-1))
] : style=="icosa"? [
for (tb=[0,1], j=[0,2], i = [0:1:4]) let(
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,
pt = rot(ang2*v, v=ax2, p=vv0) * rr * (tb? -1 : 1)
) pt
] : assert(in_list(style,["orig","aligned","stagger","icosa"])),
] : assert(in_list(style,["orig","aligned","stagger","octa","icosa"])),
lv = len(verts),
faces = style=="orig"? [
[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(
pyr = [for (x=[0:1:octa_steps+1]) x],
tri = sum(pyr),
soff = cumsum(pyr)
meridians = [
0, 1,
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(
base = ((((tb*2) + j) * 4) + i) * tri
for (i=[0:1:3]) [0, 1+(i+1)%4, 1+i],
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 (l = [0:1:k]) let(
v1 = base + soff[k] + l,
v2 = base + soff[k+1] + l,
v3 = base + soff[k+1] + (l + 1),
faces = [
if(l>0) [v1-1,v1,v2],
[v1,v3,v2],
],
faces2 = (tb+j)%2? [for (f=faces) reverse(f)] : faces
) each faces2
for (j=[0:1:3], k=[0:1:m-1]) let(
m1 = meridians[i+1],
m2 = meridians[i+2],
p1 = offs[i+0] + (j*m1/4 + k+0) % m1,
p2 = offs[i+0] + (j*m1/4 + k+1) % m1,
p3 = offs[i+1] + (j*m2/4 + k+0) % m2,
p4 = offs[i+1] + (j*m2/4 + k+1) % m2,
p5 = offs[os-i+0] + (j*m1/4 + k+0) % m1,
p6 = offs[os-i+0] + (j*m1/4 + k+1) % m1,
p7 = offs[os-i-1] + (j*m2/4 + k+0) % m2,
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(
pyr = [for (x=[0:1:icosa_steps+1]) x],
tri = sum(pyr),

View file

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