#scene #cad #import #3d #model

cad_import

A simple library for importing CAD data from different formats into a uniform in-memory structure

5 unstable releases

0.3.1 May 21, 2023
0.3.0 Mar 23, 2023
0.2.1 Feb 22, 2023
0.2.0 Feb 22, 2023
0.1.0 Jan 28, 2023

#1584 in Data structures


Used in cad_viewer

MIT license

105KB
2.5K SLoC

cad_import - Simple CAD Importer Library

A simple library for importing CAD data from different formats into a uniform in-memory structure.

The goals of this library is:

  • Supporting multiple 3D and CAD formats
  • Simple design and supporting
  • Representation in uniform in-memory structure

Supported formats

Changelog

For changes see Change Log


lib.rs:

cad_import is a library for loading various 3D and CAD file formats.

The library consists of a list of loaders registered in a loader manager and an unified in-memory structure to store the loaded CAD/3D-data.

Example

The following code prints a list of all registered loader to the console.

use cad_import::loader::Manager;

fn main() {
    let manager = Manager::new();

    for loader in manager.get_loader_list().iter() {
        let extensions: Vec<String> = loader.get_extensions_mime_type_map().keys().map(|s| s.clone()).collect();
        let extensions: String = extensions.join(",");
        let mime_types: String = loader.get_mime_types().join(",");
        println!(
            "Loader {}: Extensions=[{}], Mime-Types=[{}] ",
            loader.get_name(),
            extensions,
            mime_types
        );
    }
}

In order to load a specific file see the following code

use cad_import::loader::Manager;
use std::{fs::File, path::Path};
use std::env;

fn main() {
    let manager = Manager::new();
    let mime_type = "model/vnd.off";

    let loader = manager.get_loader_by_mime_type(mime_type).unwrap();

    let args: Vec<String> = env::args().collect();
    let args = &args[1..];

    if args.len() != 2 {
      println!("USAGE: <FILE-PATH>");
    } else {
        let file_path = Path::new(&args[1]);

        let cad_data = loader.read_file(&file_path, mime_type);
    }
}

Dependencies

~7MB
~134K SLoC