Skip to content

Commit

Permalink
Merge pull request #100 from kiuber/patch-1
Browse files Browse the repository at this point in the history
Update stl_file to threemf_file for from_3mf
  • Loading branch information
unlimitedbacon authored Oct 3, 2024
2 parents 88a9b30 + fcaca8e commit 6bc9057
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .rpm/stl-thumb.spec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
%define debug_package %{nil}

Name: stl-thumb
Summary: A fast lightweight thumbnail generator for STL files
Summary: A fast lightweight thumbnail generator for 3D model(STL, OBJ, 3MF) files
Version: @@VERSION@@
Release: @@RELEASE@@%{?dist}
License: MIT
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
name = "stl-thumb"
version = "0.5.0"
authors = ["Tyler Anderson <[email protected]>"]
description = "A fast lightweight thumbnail generator for STL files"
description = "A fast lightweight thumbnail generator for 3D model(STL, OBJ, 3MF) files"
readme = "README.md"
repository = "https://github.com/unlimitedbacon/stl-thumb"
license = "MIT"
homepage = "https://github.com/unlimitedbacon/stl-thumb"
keywords = ["3d", "3dprinting", "stl"]
keywords = ["3d", "3dprinting", "stl", "obj", "3mf"]
categories = ["command-line-utilities", "graphics"]
exclude = [
"test_data/*"
Expand Down Expand Up @@ -63,8 +63,8 @@ harness = false
license-file = ["LICENSE", "3"]
depends = "libgl1, libc6, libgcc1, libosmesa6-dev"
extended-description = """\
Stl-thumb is a fast lightweight thumbnail generator for STL files. \
It can show previews for STL files in your file manager on Linux and Windows. \
Stl-thumb is a fast lightweight thumbnail generator for 3D model(STL, OBJ, 3MF) files. \
It can show previews for 3D model files in your file manager on Linux and Windows. \
It is written in Rust and uses OpenGL. """
section = "graphics"
priority = "optional"
Expand Down
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Documentation](https://img.shields.io/docsrs/stl-thumb/latest)](https://docs.rs/stl-thumb/latest/stl_thumb/)
[![Crates.io](https://img.shields.io/crates/v/stl-thumb.svg)](https://crates.io/crates/stl-thumb)

Stl-thumb is a fast lightweight thumbnail generator for STL files. It can show previews for STL files in your file manager on Linux and Windows. It is written in Rust and uses OpenGL.
Stl-thumb is a fast lightweight thumbnail generator for 3D model(STL, OBJ, 3MF) files. It can show previews for model files in your file manager on Linux and Windows. It is written in Rust and uses OpenGL.

![Screenshot](https://user-images.githubusercontent.com/3131268/116009182-f3f89c80-a5cc-11eb-817d-91e8a9fad279.png)

Expand Down Expand Up @@ -76,22 +76,22 @@ $ cargo generate-rpm
## Command Line Usage

```
$ stl-thumb <STL_FILE> [IMG_FILE]
$ stl-thumb <MODEL_FILE> [IMG_FILE]
```

### Options

| Option | Description |
| ------------- | ------------------------------------------------------- |
| <STL_FILE> | The STL file you want a picture of. Use - to read from stdin instead of a file. |
| <IMG_FILE> | The thumbnail image file that will be created. Use - to write to stdout instead of a file. |
| -s, --size \<size\> | Specify width of the image. It will always be a square. |
| Option | Description |
| ------------- |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| <MODEL_FILE> | The model file you want a picture of. Use - to read from stdin instead of a file. |
| <IMG_FILE> | The thumbnail image file that will be created. Use - to write to stdout instead of a file. |
| -s, --size \<size\> | Specify width of the image. It will always be a square. |
| -f, --format \<format\> | The format of the image file. If not specified it will be determined from the file extension, or default to PNG if there is no extension. Supported formats: PNG, JPEG, GIF, ICO, BMP |
| -m, --material \<ambient\> \<diffuse\> \<specular\> | Colors for rendering the mesh using the Phong reflection model. Requires 3 colors as rgb hex values: ambient, diffuse, and specular. Defaults to blue. |
| -b, --backround \<color> | The background color with transparency (rgba). Default is ffffff00. |
| -a, --antialiasing [none, fxaa] | Anti-aliasing method. Default is FXAA, which is fast but may introduce artifacts. |
| --recalc-normals | Force recalculation of face normals. Use when dealing with malformed STL files. |
| -x | Display the image in a window instead of saving a file. |
| -h, --help | Prints help information. |
| -V, --version | Prints version information. |
| -v[v][v] | Increase message verbosity. Levels: Errors, Warnings, Info, Debugging |
| -m, --material \<ambient\> \<diffuse\> \<specular\> | Colors for rendering the mesh using the Phong reflection model. Requires 3 colors as rgb hex values: ambient, diffuse, and specular. Defaults to blue. |
| -b, --backround \<color> | The background color with transparency (rgba). Default is ffffff00. |
| -a, --antialiasing [none, fxaa] | Anti-aliasing method. Default is FXAA, which is fast but may introduce artifacts. |
| --recalc-normals | Force recalculation of face normals. Use when dealing with malformed STL files. |
| -x | Display the image in a window instead of saving a file. |
| -h, --help | Prints help information. |
| -V, --version | Prints version information. |
| -v[v][v] | Increase message verbosity. Levels: Errors, Warnings, Info, Debugging |
4 changes: 2 additions & 2 deletions benches/benchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use stl_thumb::config::Config;

fn benchy_stl() {
let config = Config {
stl_filename: "test_data/3DBenchy.stl".to_string(),
model_filename: "test_data/3DBenchy.stl".to_string(),
img_filename: "benchy.png".to_string(),
width: 1024,
height: 768,
Expand All @@ -19,7 +19,7 @@ fn benchy_stl() {

fn benchy_obj() {
let config = Config {
stl_filename: "test_data/3DBenchy.obj".to_string(),
model_filename: "test_data/3DBenchy.obj".to_string(),
img_filename: "3DBenchy_obj.png".to_string(),
width: 1024,
height: 768,
Expand Down
4 changes: 2 additions & 2 deletions benches/cube.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use stl_thumb::config::Config;

fn cube() {
let config = Config {
stl_filename: "test_data/cube.stl".to_string(),
model_filename: "test_data/cube.stl".to_string(),
img_filename: "cube.png".to_string(),
width: 1024,
height: 768,
Expand All @@ -19,7 +19,7 @@ fn cube() {

fn cube_obj() {
let config = Config {
stl_filename: "test_data/cube.obj".to_string(),
model_filename: "test_data/cube.obj".to_string(),
img_filename: "cube_obj.png".to_string(),
width: 1024,
height: 768,
Expand Down
2 changes: 1 addition & 1 deletion benches/shipwreck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use stl_thumb::config::Config;

fn shipwreck() {
let config = Config {
stl_filename: "test_data/shipwreck.stl".to_string(),
model_filename: "test_data/shipwreck.stl".to_string(),
img_filename: "shipwreck.png".to_string(),
width: 1024,
height: 768,
Expand Down
10 changes: 5 additions & 5 deletions libstl_thumb.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ extern "C" {

/// Allows utilizing `stl-thumb` from C-like languages
///
/// This function renders an image of the file `stl_filename_c` and stores it into the buffer `buf_ptr`.
/// This function renders an image of the file `model_filename_c` and stores it into the buffer `buf_ptr`.
///
/// You must provide a memory buffer large enough to store the image. Images are written in 8-bit RGBA format,
/// so the buffer must be at least `width`*`height`*4 bytes in size. `stl_filename_c` is a pointer to a C string with
/// so the buffer must be at least `width`*`height`*4 bytes in size. `model_filename_c` is a pointer to a C string with
/// the file path.
///
/// Returns `true` if succesful and `false` if unsuccesful.
///
/// # Example in C
/// ```c
/// const char* stl_filename_c = "3DBenchy.stl";
/// const char* model_filename_c = "3DBenchy.stl";
/// int width = 256;
/// int height = 256;
///
/// int img_size = width * height * 4;
/// buf_ptr = (uchar *) malloc(img_size);
///
/// render_to_buffer(buf_ptr, width, height, stl_filename_c);
/// render_to_buffer(buf_ptr, width, height, model_filename_c);
/// ```
bool render_to_buffer(uint8_t *buf_ptr,
uint32_t width,
uint32_t height,
const char *stl_filename_c);
const char *model_filename_c);

#ifdef __cplusplus
} // extern "C"
Expand Down
12 changes: 6 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub enum AAMethod {

#[derive(Clone)]
pub struct Config {
pub stl_filename: String,
pub model_filename: String,
pub img_filename: String,
pub format: ImageFormat,
pub width: u32,
Expand All @@ -33,7 +33,7 @@ pub struct Config {
impl Default for Config {
fn default() -> Self {
Config {
stl_filename: "".to_string(),
model_filename: "".to_string(),
img_filename: "".to_string(),
format: ImageFormat::Png,
width: 1024,
Expand All @@ -59,7 +59,7 @@ impl Config {
.version(env!("CARGO_PKG_VERSION"))
.author(env!("CARGO_PKG_AUTHORS"))
.arg(
clap::Arg::new("STL_FILE")
clap::Arg::new("MODEL_FILE")
.help("STL file. Use - to read from stdin instead of a file.")
.required(true)
.index(1),
Expand Down Expand Up @@ -130,9 +130,9 @@ impl Config {
..Default::default()
};

c.stl_filename = matches
.remove_one::<String>("STL_FILE")
.expect("STL_FILE not provided");
c.model_filename = matches
.remove_one::<String>("MODEL_FILE")
.expect("MODEL_FILE not provided");
c.img_filename = matches
.remove_one::<String>("IMG_FILE")
.expect("IMG_FILE not provided");
Expand Down
40 changes: 20 additions & 20 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,9 @@ where
}

pub fn render_to_window(config: Config) -> Result<(), Box<dyn Error>> {
// Get geometry from STL file
// Get geometry from model file
// ==========================
let mesh = Mesh::load(&config.stl_filename, config.recalc_normals)?;
let mesh = Mesh::load(&config.model_filename, config.recalc_normals)?;

// Create GL context
// =================
Expand Down Expand Up @@ -323,9 +323,9 @@ pub fn render_to_window(config: Config) -> Result<(), Box<dyn Error>> {
}

pub fn render_to_image(config: &Config) -> Result<image::DynamicImage, Box<dyn Error>> {
// Get geometry from STL file
// Get geometry from model file
// =========================
let mesh = Mesh::load(&config.stl_filename, config.recalc_normals)?;
let mesh = Mesh::load(&config.model_filename, config.recalc_normals)?;

// Create GL context
// =================
Expand Down Expand Up @@ -414,36 +414,36 @@ pub fn render_to_file(config: &Config) -> Result<(), Box<dyn Error>> {

/// Allows utilizing `stl-thumb` from C-like languages
///
/// This function renders an image of the file `stl_filename_c` and stores it into the buffer `buf_ptr`.
/// This function renders an image of the file `model_filename_c` and stores it into the buffer `buf_ptr`.
///
/// You must provide a memory buffer large enough to store the image. Images are written in 8-bit RGBA format,
/// so the buffer must be at least `width`*`height`*4 bytes in size. `stl_filename_c` is a pointer to a C string with
/// so the buffer must be at least `width`*`height`*4 bytes in size. `model_filename_c` is a pointer to a C string with
/// the file path.
///
/// Returns `true` if succesful and `false` if unsuccesful.
///
/// # Example in C
/// ```c
/// const char* stl_filename_c = "3DBenchy.stl";
/// const char* model_filename_c = "3DBenchy.stl";
/// int width = 256;
/// int height = 256;
///
/// int img_size = width * height * 4;
/// buf_ptr = (uchar *) malloc(img_size);
///
/// render_to_buffer(buf_ptr, width, height, stl_filename_c);
/// render_to_buffer(buf_ptr, width, height, model_filename_c);
/// ```
///
/// # Safety
///
/// * `buf_ptr` _must_ point to a valid initialized buffer, at least `width * height * 4` bytes long.
/// * `stl_filename_c` must point to a valid null-terminated string.
/// * `model_filename_c` must point to a valid null-terminated string.
#[no_mangle]
pub unsafe extern "C" fn render_to_buffer(
buf_ptr: *mut u8,
width: u32,
height: u32,
stl_filename_c: *const c_char,
model_filename_c: *const c_char,
) -> bool {
// Workaround for issues with OpenGL 3.1 on Mesa 18.3
#[cfg(target_os = "linux")]
Expand All @@ -458,24 +458,24 @@ pub unsafe extern "C" fn render_to_buffer(
let buf = unsafe { slice::from_raw_parts_mut(buf_ptr, buf_size) };

// Check validity of provided file path string
let stl_filename_cstr = unsafe {
if stl_filename_c.is_null() {
error!("STL file path pointer is null");
let model_filename_cstr = unsafe {
if model_filename_c.is_null() {
error!("model file path pointer is null");
return false;
}
CStr::from_ptr(stl_filename_c)
CStr::from_ptr(model_filename_c)
};
let stl_filename_str = match stl_filename_cstr.to_str() {
let model_filename_str = match model_filename_cstr.to_str() {
Ok(s) => s,
Err(_) => {
error!("Invalid STL file path {:?}", stl_filename_cstr);
error!("Invalid model file path {:?}", model_filename_cstr);
return false;
}
};

// Setup configuration for the renderer
let config = Config {
stl_filename: stl_filename_str.to_string(),
model_filename: model_filename_str.to_string(),
width,
height,
..Default::default()
Expand Down Expand Up @@ -517,7 +517,7 @@ mod tests {
fn cube_stl() {
let img_filename = "cube-stl.png".to_string();
let config = Config {
stl_filename: "test_data/cube.stl".to_string(),
model_filename: "test_data/cube.stl".to_string(),
img_filename: img_filename.clone(),
format: image::ImageFormat::Png,
..Default::default()
Expand All @@ -542,7 +542,7 @@ mod tests {
fn cube_obj() {
let img_filename = "cube-obj.png".to_string();
let config = Config {
stl_filename: "test_data/cube.obj".to_string(),
model_filename: "test_data/cube.obj".to_string(),
img_filename: img_filename.clone(),
format: image::ImageFormat::Png,
..Default::default()
Expand All @@ -567,7 +567,7 @@ mod tests {
fn cube_3mf() {
let img_filename = "cube-3mf.png".to_string();
let config = Config {
stl_filename: "test_data/cube.3mf".to_string(),
model_filename: "test_data/cube.3mf".to_string(),
img_filename: img_filename.clone(),
format: image::ImageFormat::Png,
..Default::default()
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn main() {
.init()
.unwrap();

info!("STL File: {}", config.stl_filename);
info!("MODEL File: {}", config.model_filename);
info!("IMG File: {}", config.img_filename);

if config.visible {
Expand Down
Loading

0 comments on commit 6bc9057

Please sign in to comment.