mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-14 10:44:48 +02:00
optimization
This commit is contained in:
@@ -15,46 +15,49 @@ module sf_solidify(surface1, surface2, slicing = "SLASH", convexity = 1) {
|
|||||||
rows = len(surface1);
|
rows = len(surface1);
|
||||||
columns = len(surface1[0]);
|
columns = len(surface1[0]);
|
||||||
|
|
||||||
yi_range = [0:rows - 2];
|
// dimensionality reduction
|
||||||
xi_range = [0:columns - 2];
|
indices = [
|
||||||
|
for(y = [0:rows - 1])
|
||||||
module faces() {
|
[for(x = [0:columns - 1]) y * columns + x]
|
||||||
function xy_to_index(x, y, columns) = y * columns + x;
|
];
|
||||||
|
|
||||||
flatted_sf1 = flat(surface1);
|
flatted_sf1 = flat(surface1);
|
||||||
flatted_sf2 = flat(surface2);
|
flatted_sf2 = flat(surface2);
|
||||||
|
|
||||||
leng_pts = len(flatted_sf1);
|
leng_pts = len(flatted_sf1);
|
||||||
|
|
||||||
|
yi_range = [0:rows - 2];
|
||||||
|
xi_range = [0:columns - 2];
|
||||||
|
|
||||||
sf1_tri_faces1 = slicing == "SLASH" ? [
|
sf1_tri_faces1 = slicing == "SLASH" ? [
|
||||||
for(yi = yi_range, xi = xi_range)
|
for(yi = yi_range, xi = xi_range)
|
||||||
[
|
[
|
||||||
xy_to_index(xi, yi, columns),
|
indices[yi][xi],
|
||||||
xy_to_index(xi + 1, yi + 1, columns),
|
indices[yi + 1][xi + 1],
|
||||||
xy_to_index(xi + 1, yi, columns)
|
indices[yi][xi + 1]
|
||||||
]
|
]
|
||||||
] : [
|
] : [
|
||||||
for(yi = yi_range, xi = xi_range)
|
for(yi = yi_range, xi = xi_range)
|
||||||
[
|
[
|
||||||
xy_to_index(xi, yi, columns),
|
indices[yi][xi],
|
||||||
xy_to_index(xi, yi + 1, columns),
|
dim_reduce(xi, yi + 1, columns),
|
||||||
xy_to_index(xi + 1, yi, columns)
|
dim_reduce(xi + 1, yi, columns)
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
sf1_tri_faces2 = slicing == "SLASH" ? [
|
sf1_tri_faces2 = slicing == "SLASH" ? [
|
||||||
for(yi = yi_range, xi = xi_range)
|
for(yi = yi_range, xi = xi_range)
|
||||||
[
|
[
|
||||||
xy_to_index(xi, yi, columns),
|
indices[yi][xi],
|
||||||
xy_to_index(xi, yi + 1, columns),
|
indices[yi + 1][xi],
|
||||||
xy_to_index(xi + 1, yi + 1, columns)
|
indices[yi + 1][xi + 1]
|
||||||
]
|
]
|
||||||
] : [
|
] : [
|
||||||
for(yi = yi_range, xi = xi_range)
|
for(yi = yi_range, xi = xi_range)
|
||||||
[
|
[
|
||||||
xy_to_index(xi, yi + 1, columns),
|
indices[yi + 1][xi],
|
||||||
xy_to_index(xi + 1, yi + 1, columns),
|
indices[yi + 1][xi + 1],
|
||||||
xy_to_index(xi + 1, yi, columns)
|
indices[yi][xi + 1]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -72,8 +75,8 @@ module sf_solidify(surface1, surface2, slicing = "SLASH", convexity = 1) {
|
|||||||
side_faces1 = [
|
side_faces1 = [
|
||||||
for(xi = xi_range)
|
for(xi = xi_range)
|
||||||
let(
|
let(
|
||||||
idx1 = xy_to_index(xi, 0, columns),
|
idx1 = indices[0][xi],
|
||||||
idx2 = xy_to_index(xi + 1, 0, columns)
|
idx2 = indices[0][xi + 1]
|
||||||
)
|
)
|
||||||
[
|
[
|
||||||
idx1,
|
idx1,
|
||||||
@@ -87,8 +90,8 @@ module sf_solidify(surface1, surface2, slicing = "SLASH", convexity = 1) {
|
|||||||
for(yi = yi_range)
|
for(yi = yi_range)
|
||||||
let(
|
let(
|
||||||
xi = columns - 1,
|
xi = columns - 1,
|
||||||
idx1 = xy_to_index(xi, yi, columns),
|
idx1 = indices[yi][xi],
|
||||||
idx2 = xy_to_index(xi, yi + 1, columns)
|
idx2 = indices[yi + 1][xi]
|
||||||
)
|
)
|
||||||
[
|
[
|
||||||
idx1,
|
idx1,
|
||||||
@@ -102,8 +105,8 @@ module sf_solidify(surface1, surface2, slicing = "SLASH", convexity = 1) {
|
|||||||
for(xi = xi_range)
|
for(xi = xi_range)
|
||||||
let(
|
let(
|
||||||
yi = rows - 1,
|
yi = rows - 1,
|
||||||
idx1 = xy_to_index(xi, yi, columns),
|
idx1 = indices[yi][xi],
|
||||||
idx2 = xy_to_index(xi + 1, yi, columns)
|
idx2 = indices[yi][xi + 1]
|
||||||
)
|
)
|
||||||
[
|
[
|
||||||
idx2,
|
idx2,
|
||||||
@@ -116,8 +119,8 @@ module sf_solidify(surface1, surface2, slicing = "SLASH", convexity = 1) {
|
|||||||
side_faces4 = [
|
side_faces4 = [
|
||||||
for(yi = yi_range)
|
for(yi = yi_range)
|
||||||
let(
|
let(
|
||||||
idx1 = xy_to_index(0, yi, columns),
|
idx1 = indices[yi][0],
|
||||||
idx2 = xy_to_index(0, yi + 1, columns)
|
idx2 = indices[yi + 1][0]
|
||||||
)
|
)
|
||||||
[
|
[
|
||||||
idx2,
|
idx2,
|
||||||
@@ -127,30 +130,16 @@ module sf_solidify(surface1, surface2, slicing = "SLASH", convexity = 1) {
|
|||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
pts = concat(flatted_sf1, flatted_sf2);
|
polyhedron(
|
||||||
face_idxs = concat(
|
points = concat(flatted_sf1, flatted_sf2),
|
||||||
|
faces = concat(
|
||||||
sf1_tri_faces1, sf1_tri_faces2,
|
sf1_tri_faces1, sf1_tri_faces2,
|
||||||
sf2_tri_faces1, sf2_tri_faces2,
|
sf2_tri_faces1, sf2_tri_faces2,
|
||||||
side_faces1,
|
side_faces1,
|
||||||
side_faces2,
|
side_faces2,
|
||||||
side_faces3,
|
side_faces3,
|
||||||
side_faces4
|
side_faces4
|
||||||
);
|
),
|
||||||
|
|
||||||
polyhedron(
|
|
||||||
points = pts,
|
|
||||||
faces = face_idxs,
|
|
||||||
convexity = convexity
|
convexity = convexity
|
||||||
);
|
);
|
||||||
|
|
||||||
// hook for testing
|
|
||||||
test_surface_grapher_faces(pts, face_idxs);
|
|
||||||
}
|
|
||||||
|
|
||||||
faces();
|
|
||||||
}
|
|
||||||
|
|
||||||
// override it to test
|
|
||||||
module test_surface_grapher_faces(surface1, faces) {
|
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user