mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-31 18:22:08 +02:00
refactor
This commit is contained in:
3
src/__comm__/_face_normal.scad
Normal file
3
src/__comm__/_face_normal.scad
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
function _face_normal(points) =
|
||||||
|
let(v = cross(points[2] - points[0], points[1] - points[0])) v / norm(v);
|
||||||
|
|
@@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
use <_face_normal.scad>;
|
||||||
use <../util/slice.scad>;
|
use <../util/slice.scad>;
|
||||||
use <../util/sort.scad>;
|
use <../util/sort.scad>;
|
||||||
use <../util/find_index.scad>;
|
use <../util/find_index.scad>;
|
||||||
@@ -24,9 +25,6 @@ function _connected_faces(faces, leng, leng_pts, cnt_faces, i = 0) =
|
|||||||
)
|
)
|
||||||
_connected_faces(faces, leng, leng_pts, n_cnt_faces, i + 1);
|
_connected_faces(faces, leng, leng_pts, n_cnt_faces, i + 1);
|
||||||
|
|
||||||
function face_normal(points) =
|
|
||||||
let(v = cross(points[2] - points[0], points[1] - points[0])) v / norm(v);
|
|
||||||
|
|
||||||
function _vertex_normals(points, faces) =
|
function _vertex_normals(points, faces) =
|
||||||
let(
|
let(
|
||||||
leng_pts = len(points),
|
leng_pts = len(points),
|
||||||
@@ -37,7 +35,7 @@ function _vertex_normals(points, faces) =
|
|||||||
let(
|
let(
|
||||||
face_normals = [
|
face_normals = [
|
||||||
for(face = cnn_faces[i])
|
for(face = cnn_faces[i])
|
||||||
face_normal([for(i = face) points[i]])
|
_face_normal([for(i = face) points[i]])
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
sum(face_normals) / len(face_normals)
|
sum(face_normals) / len(face_normals)
|
||||||
|
@@ -8,6 +8,7 @@
|
|||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
|
|
||||||
|
use <../__comm__/_face_normal.scad>;
|
||||||
use <../util/sort.scad>;
|
use <../util/sort.scad>;
|
||||||
use <../util/find_index.scad>;
|
use <../util/find_index.scad>;
|
||||||
use <../util/sum.scad>;
|
use <../util/sum.scad>;
|
||||||
@@ -40,9 +41,6 @@ module sf_thickenT(points, thickness, triangles = undef, direction = "BOTH") {
|
|||||||
)
|
)
|
||||||
_connected_tris(triangles, leng, leng_pts, n_cnt_tris, i + 1);
|
_connected_tris(triangles, leng, leng_pts, n_cnt_tris, i + 1);
|
||||||
|
|
||||||
function tri_normal(tri) =
|
|
||||||
let(v = cross(tri[2] - tri[0], tri[1] - tri[0])) v / norm(v);
|
|
||||||
|
|
||||||
leng_pts = len(points);
|
leng_pts = len(points);
|
||||||
cnn_tris = connected_tris(leng_pts, tris);
|
cnn_tris = connected_tris(leng_pts, tris);
|
||||||
|
|
||||||
@@ -50,7 +48,7 @@ module sf_thickenT(points, thickness, triangles = undef, direction = "BOTH") {
|
|||||||
dir_v = direction / norm(direction);
|
dir_v = direction / norm(direction);
|
||||||
mid = sort(points)[leng_pts / 2];
|
mid = sort(points)[leng_pts / 2];
|
||||||
tri = cnn_tris[find_index(points, function(p) p == mid)][0];
|
tri = cnn_tris[find_index(points, function(p) p == mid)][0];
|
||||||
nv = tri_normal([points[tri[0]], points[tri[1]], points[tri[2]]]);
|
nv = _face_normal([points[tri[0]], points[tri[1]], points[tri[2]]]);
|
||||||
pts = [for(p = points) p + dir_v * thickness];
|
pts = [for(p = points) p + dir_v * thickness];
|
||||||
|
|
||||||
if(nv * dir_v > 0) {
|
if(nv * dir_v > 0) {
|
||||||
@@ -66,7 +64,7 @@ module sf_thickenT(points, thickness, triangles = undef, direction = "BOTH") {
|
|||||||
let(
|
let(
|
||||||
normals = [
|
normals = [
|
||||||
for(tri = cnn_tris[i])
|
for(tri = cnn_tris[i])
|
||||||
tri_normal([
|
_face_normal([
|
||||||
points[tri[0]],
|
points[tri[0]],
|
||||||
points[tri[1]],
|
points[tri[1]],
|
||||||
points[tri[2]]]
|
points[tri[2]]]
|
||||||
|
Reference in New Issue
Block a user