mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-03-14 02:59:42 +01:00
improved solid sections performance
This commit is contained in:
parent
a7a93b8d0a
commit
96861fb862
@ -14,66 +14,109 @@
|
||||
include <__private__/__triangles_radial.scad>;
|
||||
include <__private__/__triangles_tape.scad>;
|
||||
|
||||
module polysections(sections, triangles = "RADIAL") {
|
||||
module tri_sections(tri1, tri2) {
|
||||
polyhedron(
|
||||
points = concat(tri1, tri2),
|
||||
faces = [
|
||||
[0, 1, 2],
|
||||
[3, 4, 5],
|
||||
[0, 1, 4], [1, 2, 5], [2, 0, 3],
|
||||
[0, 3, 4], [1, 4, 5], [2, 5, 3]
|
||||
]
|
||||
);
|
||||
module polysections(sections, triangles) {
|
||||
module solid_sections() {
|
||||
leng_sections = len(sections);
|
||||
leng_pts_section = len(sections[0]);
|
||||
|
||||
side_idxes = [
|
||||
for(j = [0:leng_pts_section:(leng_sections - 2) * leng_pts_section])
|
||||
for(i = [0:leng_pts_section - 1])
|
||||
[
|
||||
j + i,
|
||||
j + (i + 1) % leng_pts_section,
|
||||
j + (i + 1) % leng_pts_section + leng_pts_section ,
|
||||
j + i + leng_pts_section
|
||||
]
|
||||
];
|
||||
|
||||
first_idxes = [for(i = [0:leng_pts_section - 1]) i];
|
||||
|
||||
last_idxes = [
|
||||
for(i = [0:leng_pts_section - 1])
|
||||
i + leng_pts_section * (leng_sections - 1)
|
||||
];
|
||||
|
||||
v_pts = [
|
||||
for(section = sections)
|
||||
for(pt = section)
|
||||
pt
|
||||
];
|
||||
|
||||
polyhedron(
|
||||
v_pts,
|
||||
concat([first_idxes], side_idxes, [last_idxes])
|
||||
);
|
||||
}
|
||||
|
||||
function hollow_tris() =
|
||||
let(
|
||||
leng_section = len(sections[0]),
|
||||
inner_i_begin = leng_section / 2,
|
||||
idxes = concat(
|
||||
[
|
||||
for(i = [0:inner_i_begin - 1])
|
||||
let(n = inner_i_begin + i + 1)
|
||||
[i, inner_i_begin + i, n % inner_i_begin + inner_i_begin]
|
||||
],
|
||||
[
|
||||
for(i = [0:inner_i_begin - 1])
|
||||
let(n = inner_i_begin + i + 1)
|
||||
[i, i + 1, n % leng_section]
|
||||
module triangles_defined_sections() {
|
||||
module tri_sections(tri1, tri2) {
|
||||
polyhedron(
|
||||
points = concat(tri1, tri2),
|
||||
faces = [
|
||||
[0, 1, 2],
|
||||
[3, 4, 5],
|
||||
[0, 1, 4], [1, 2, 5], [2, 0, 3],
|
||||
[0, 3, 4], [1, 4, 5], [2, 5, 3]
|
||||
]
|
||||
)
|
||||
) idxes;
|
||||
);
|
||||
}
|
||||
|
||||
function hollow_tris() =
|
||||
let(
|
||||
leng_section = len(sections[0]),
|
||||
inner_i_begin = leng_section / 2,
|
||||
idxes = concat(
|
||||
[
|
||||
for(i = [0:inner_i_begin - 1])
|
||||
let(n = inner_i_begin + i + 1)
|
||||
[i, inner_i_begin + i, n % inner_i_begin + inner_i_begin]
|
||||
],
|
||||
[
|
||||
for(i = [0:inner_i_begin - 1])
|
||||
let(n = inner_i_begin + i + 1)
|
||||
[i, i + 1, n % leng_section]
|
||||
]
|
||||
)
|
||||
) idxes;
|
||||
|
||||
function tris() = triangles == "RADIAL" ? __triangles_radial(sections[0]) :
|
||||
(
|
||||
triangles == "HOLLOW" ? hollow_tris() : (
|
||||
triangles == "TAPE" ? __triangles_tape(sections[0]) : triangles
|
||||
)
|
||||
);
|
||||
|
||||
module two_sections(section1, section2) {
|
||||
for(idx = tris()) {
|
||||
// hull is for preventing from WARNING: Object may not be a valid 2-manifold
|
||||
hull() tri_sections(
|
||||
[
|
||||
section1[idx[0]],
|
||||
section1[idx[1]],
|
||||
section1[idx[2]]
|
||||
],
|
||||
[
|
||||
section2[idx[0]],
|
||||
section2[idx[1]],
|
||||
section2[idx[2]]
|
||||
]
|
||||
function tris() = triangles == "RADIAL" ? __triangles_radial(sections[0]) :
|
||||
(
|
||||
triangles == "HOLLOW" ? hollow_tris() : (
|
||||
triangles == "TAPE" ? __triangles_tape(sections[0]) : triangles
|
||||
)
|
||||
);
|
||||
|
||||
module two_sections(section1, section2) {
|
||||
for(idx = tris()) {
|
||||
// hull is for preventing from WARNING: Object may not be a valid 2-manifold
|
||||
hull() tri_sections(
|
||||
[
|
||||
section1[idx[0]],
|
||||
section1[idx[1]],
|
||||
section1[idx[2]]
|
||||
],
|
||||
[
|
||||
section2[idx[0]],
|
||||
section2[idx[1]],
|
||||
section2[idx[2]]
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for(i = [0:len(sections) - 2]) {
|
||||
two_sections(
|
||||
sections[i],
|
||||
sections[i + 1]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for(i = [0:len(sections) - 2]) {
|
||||
two_sections(
|
||||
sections[i],
|
||||
sections[i + 1]
|
||||
);
|
||||
//
|
||||
if(triangles == undef) {
|
||||
solid_sections();
|
||||
} else {
|
||||
triangles_defined_sections();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user