1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-23 14:54:12 +02:00

improved solid sections performance

This commit is contained in:
Justin Lin
2017-05-10 16:05:43 +08:00
parent a7a93b8d0a
commit 96861fb862

View File

@@ -14,66 +14,109 @@
include <__private__/__triangles_radial.scad>; include <__private__/__triangles_radial.scad>;
include <__private__/__triangles_tape.scad>; include <__private__/__triangles_tape.scad>;
module polysections(sections, triangles = "RADIAL") { module polysections(sections, triangles) {
module tri_sections(tri1, tri2) { module solid_sections() {
polyhedron( leng_sections = len(sections);
points = concat(tri1, tri2), leng_pts_section = len(sections[0]);
faces = [
[0, 1, 2], side_idxes = [
[3, 4, 5], for(j = [0:leng_pts_section:(leng_sections - 2) * leng_pts_section])
[0, 1, 4], [1, 2, 5], [2, 0, 3], for(i = [0:leng_pts_section - 1])
[0, 3, 4], [1, 4, 5], [2, 5, 3] [
] 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() = module triangles_defined_sections() {
let( module tri_sections(tri1, tri2) {
leng_section = len(sections[0]), polyhedron(
inner_i_begin = leng_section / 2, points = concat(tri1, tri2),
idxes = concat( faces = [
[ [0, 1, 2],
for(i = [0:inner_i_begin - 1]) [3, 4, 5],
let(n = inner_i_begin + i + 1) [0, 1, 4], [1, 2, 5], [2, 0, 3],
[i, inner_i_begin + i, n % inner_i_begin + inner_i_begin] [0, 3, 4], [1, 4, 5], [2, 5, 3]
],
[
for(i = [0:inner_i_begin - 1])
let(n = inner_i_begin + i + 1)
[i, i + 1, n % leng_section]
] ]
) );
) 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]) : function tris() = triangles == "RADIAL" ? __triangles_radial(sections[0]) :
( (
triangles == "HOLLOW" ? hollow_tris() : ( triangles == "HOLLOW" ? hollow_tris() : (
triangles == "TAPE" ? __triangles_tape(sections[0]) : triangles 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]]
]
); );
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( if(triangles == undef) {
sections[i], solid_sections();
sections[i + 1] } else {
); triangles_defined_sections();
} }
} }