Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/Book.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
id: pages
uses: actions/configure-pages@v5
- name: Build with mdBook
run: mdbook build
run: mdbook build book
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
Expand Down
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edition = "2021"

[dependencies]
clap = { version = "4.5.16", features = ["derive"] }
nalgebra = "0.33.2"
serde = { version = "1.0.213", features = ["derive"] }
serde_json = "1.0.132"
stl_io = "0.8.2"
Expand All @@ -16,6 +17,3 @@ path = "arcwelderlib-sys"
[features]
default = []
arcwelder = ["arcwelderlib-sys"]

[workspace]
members = ["arcwelderlib-sys"]
3 changes: 1 addition & 2 deletions book.toml → book/book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
authors = ["Craig M. Hamel", "Lucas K. Gallup"]
language = "en"
multilingual = false
src = "book/"
title = "slicey"

[build]
build-dir = "book/build/"
build-dir = "build"
create-missing = false

[rust]
Expand Down
Binary file added book/src/3DBenchy.stl
Binary file not shown.
1 change: 1 addition & 0 deletions book/SUMMARY.md → book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ Welcome to the slicey book
TODO break down documentation into DLP vs. FFF/SLA

- [Introduction](./introduction.md)
- [Geometry](./geometry.md)
15 changes: 15 additions & 0 deletions book/src/geometry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Geometry
The geometry module in slicey handles the necessary IO for working with geometry files such as STL files. Currently, only STL files are supported but we should plan on supporting 3mf files, among others.

The main hook for this (when working with STL files) is the following

```rust
# extern crate slicey;
# use slicey::geometry::STLMesh;
# use std;
pub fn main() {
let file_name = "./slicey/book/src/3DBenchy.stl";
// let mesh = STLMesh::new(file_name.to_string());
// println!("mesh = {:?}", mesh);
}
```
File renamed without changes.
Empty file added book/src/lib.rs
Empty file.
38 changes: 37 additions & 1 deletion src/geometry/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use nalgebra;
use std::env;
use std::fs::OpenOptions;
use std::path;
use stl_io::{
self,
IndexedTriangle,
Expand All @@ -15,6 +18,18 @@ type Faces = Vec<Face>;
type Triangles = Vec<Triangle>;
type Vertices = Vec<Vertex>;

pub trait RayIntersection {
fn ray_intersection(
&self,
point: &nalgebra::Point3::<f32>,
ray: &nalgebra::Vector3::<f32>
) -> bool {
true // todo
}
}

impl RayIntersection for Triangle {}

///
#[derive(Debug)]
pub struct BoundingBox {
Expand All @@ -40,7 +55,14 @@ impl STLMesh {
let mut file = OpenOptions::new()
.read(true)
.open(&file_name)
.unwrap();
// .unwrap();
.expect(
format!(
"Failed to open STL file. Path is {:?} and current dir is {:?}",
path::Path::new(&file_name),
env::current_dir().unwrap()
).as_str()
);
let stl = stl_io::read_stl(&mut file).unwrap();

// let triangles = STLMesh::_triangles(&stl);
Expand Down Expand Up @@ -86,6 +108,20 @@ impl STLMesh {
self.translate(0., 0., -bb.z_min);
}

pub fn is_inside(&self, point: nalgebra::Point3::<f32>) -> bool {
// arbitrary ray in +x direction
let ray = nalgebra::Vector3::<f32>::new(1., 0., 0.);

let mut count = 0;
for tri in self.triangles() {
if tri.ray_intersection(&point, &ray) {
count = count + 1;
}
}

count % 2 == 1
}

pub fn scale(&mut self, x: f32, y: f32, z: f32) -> () {
self.vertices = self.vertices
.iter_mut()
Expand Down
126 changes: 79 additions & 47 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,63 +1,95 @@
#[cfg(feature = "arcwelder")]
use arcwelderlib_sys::arcwelder;
use arcwelderlib_sys;

use clap::Parser;
use clap::{Parser, Subcommand};
use slicey::{
geometry::STLMesh,
settings::Settings,
slicer::Slicer
slicer::{
DLPSlicer,
FFFSlicer,
Slicer
}
};

// CLIP parser
/// CLIP parser
#[derive(Debug, Parser)]
#[command(version, about, long_about = None)]
// #[command(name = "slicey", about = "A slicey CLI example", version)]
struct CLIArgs {
/// Path to gcode to write file to
#[arg(short, long)]
gcode_file: String,
/// Paths to stl file/files
#[arg(short, long, value_delimiter = ',')]
stl_files: Vec<String>,
/// Path to settings file
#[arg(long)]
settings_file: String,
/// Whether or not to use arcwelder. Requires cargo build --features arcwelder
#[arg(long)]
arcwelder: bool
#[command(subcommand)]
command: Option<Commands>
}

fn main() {
let args = CLIArgs::parse();
println!("STL file = {:?}", args.stl_files);
let settings = Settings::new(&args.settings_file);
let mut stl_meshes: Vec<STLMesh> = args.stl_files
.iter()
.map(|x| STLMesh::new(x.clone()))
.collect();

let z_offset = -1.0 * stl_meshes[0].bounding_box().z_min;
let _ = stl_meshes[0].translate(20.0,20.0,z_offset);
let _ = stl_meshes[0].scale(10.0, 10.0, 10.0);
// let _ = stl_meshes[0].translate(0.0,0.0,-&stl_meshes[0].bounding_box().z_min);
// println!("Min Z: {:?}",stl_meshes[0].bounding_box().z_min);
// println!("Max Z: {:?}",stl_meshes[0].bounding_box().z_max);

// let bb = stl.bounding_box();

let slicer = Slicer::new(settings, stl_meshes);
let _ = slicer.slice(&args.gcode_file);

// arcwelder stuff
let arcwelder_enabled = cfg!(feature = "arcwelder");
if arcwelder_enabled {
println!("ArcWelder feature is enabled.");
} else {
println!("ArcWelder feature is NOT enabled.");
/// Subcommands
#[derive(Clone, Debug, Subcommand)]
enum Commands {
#[command(about = "DLP")]
DLP {
#[arg(short, long, value_delimiter = ',')]
stl_file: String,
#[arg(long)]
settings_file: String,
#[arg(short, long)]
image_folder: String
},
#[command(about = "DIW/FFF/SLA")]
FFF {
/// Path to gcode to write file to
#[arg(short, long)]
gcode_file: String,
/// Paths to stl file/files
#[arg(short, long, value_delimiter = ',')]
stl_files: Vec<String>,
/// Path to settings file
#[arg(long)]
settings_file: String,
/// Whether or not to use arcwelder. Requires cargo build --features arcwelder
#[arg(long)]
arcwelder: bool
}
}

fn main() {
let command = CLIArgs::parse();

match command.command {
Some(x) => match x {
Commands::DLP { stl_file, settings_file, image_folder } => {
let settings = Settings::new(&settings_file);
let stl_mesh = STLMesh::new(stl_file);
let slicer = DLPSlicer::new(settings, stl_mesh);
let _ = slicer.slice(&image_folder);
},
Commands::FFF { gcode_file, stl_files, settings_file, arcwelder } => {

println!("STL file = {:?}", stl_files);
let settings = Settings::new(&settings_file);
let mut stl_meshes: Vec<STLMesh> = stl_files
.iter()
.map(|x| STLMesh::new(x.clone()))
.collect();

let z_offset = -1.0 * stl_meshes[0].bounding_box().z_min;
let _ = stl_meshes[0].translate(20.0,20.0,z_offset);
let _ = stl_meshes[0].scale(10.0, 10.0, 10.0);

let slicer = FFFSlicer::new(settings, stl_meshes);
let _ = slicer.slice(&gcode_file);

// arcwelder stuff
let arcwelder_enabled = cfg!(feature = "arcwelder");
if arcwelder_enabled {
println!("ArcWelder feature is enabled.");
} else {
println!("ArcWelder feature is NOT enabled.");
}

#[cfg(feature = "arcwelder")]
if args.arcwelder {
arcwelder(&args.gcode_file, &args.gcode_file)
#[cfg(feature = "arcwelder")]
if arcwelder {
arcwelderlib_sys::arcwelder(&gcode_file, &gcode_file)
}
}
},
None => panic!("Need a subcommand!")
}
}
30 changes: 17 additions & 13 deletions src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,34 +50,35 @@ pub struct SkirtSettings {

}

#[derive(Clone, Debug, Deserialize)]
pub struct XYResolution {
pub x_pixels: i32,
pub y_pixels: i32,
pub x_pixel_resolution: f32,
pub y_pixel_resolution: f32
}

#[derive(Clone, Debug, Deserialize)]
pub struct Settings {
pub brim: BrimSettings,
pub infill: InfillSettings,
pub brim: Option<BrimSettings>,
pub infill: Option<InfillSettings>,
pub layer_height: LayerHeightSettings,
pub material: String,
pub name: String,
pub perimeter: PerimeterSettings,
pub skirt: SkirtSettings
pub perimeter: Option<PerimeterSettings>,
pub skirt: Option<SkirtSettings>,
pub xy_resolution: Option<XYResolution>
}

impl Settings {
pub fn new(file_name: &str) -> Self {
let file = File::open(file_name).unwrap();
// let mut data = String::new();
// file.read_to_string(&mut data).unwrap();
let reader = BufReader::new(file);
let json_settings: Settings =
serde_json::from_reader(reader).unwrap();
json_settings
}

// pub fn layer_heights(&self) -> Vec<f32> {
// let heights = vec![self.layer_height.layer_0_height];

// heights
// }

pub fn to_gcode_comment(&self) -> String {
let s = format!("{}", self);
s.lines()
Expand All @@ -91,8 +92,11 @@ impl fmt::Display for Settings {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let _ = write!(f, "{:?}\n", self.name);
let _ = write!(f, "Material = {:?}\n", self.material);
let _ = write!(f, "{:#?}\n", self.brim);
let _ = write!(f, "{:#?}\n", self.infill);
let _ = write!(f, "{:#?}\n", self.layer_height);
write!(f, "{:#?}\n", self.perimeter)
let _ = write!(f, "{:#?}\n", self.perimeter);
let _ = write!(f, "{:#?}\n", self.skirt);
write!(f, "{:#?}\n", self.xy_resolution)
}
}
Loading
Loading