three-d
A renderer written in Rust which enables out-of-the-box build to both desktop (Rust + OpenGL) and web (Rust to WebAssembly using wasm-bindgen + WebGL2 bindings provided by the web-sys crate). This means you can develop a 3D application on desktop and easily deploy it on web!
https://asny.github.io/three-d/
Build and run an example, in this case 'hello_world':
console
$ cargo run --example hello_world --release
Build and generate web output (webassembly, javascript and html files) into the pkg folder:
console
$ wasm-pack build examples/hello_world --target web --out-name web --out-dir ../pkg
Install a server that properly defines the application/wasm
mime type for example:
console
$ npm install -g http-server
Start the server and go to http://localhost:8080 in a browser:
console
$ cd examples/
$ http-server
Build and run an example on desktop and also generate web output (webassembly, javascript and html files) into the pkg folder:
console
$ ./examples/hello_world/run
three-d
supports a custom format with the extension ".3d".
The advantages of the .3d format is that it is smaller in size than other open formats like obj and stl
and easier to read/write when you are using Rust or specifically the serde and bincode crates.
To create a .3d file, the easiest option is to create a CPUMesh:
```rust use three_d::*;
fn main() { // Create the cpu mesh (a single triangle) let indices = [0, 1, 2]; let positions = [-3.0, -1.0, 0.0, 3.0, -1.0, 0.0, 0.0, 2.0, 0.0]; let normals = [0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0]; let cpu_mesh = CPUMesh::new(&indices, &positions, &normals).unwrap();
// Save to a ".3d" file
cpu_mesh.to_file("foo.3d").unwrap();
// Load the ".3d" file into a cpu mesh and transform it into a mesh on the gpu that can be rendered
let mesh = CPUMesh::from_file("foo.3d").unwrap().to_mesh(&gl).unwrap();
} ```
If you want to load, create, combine or deform meshes and then save to ".3d" format, the tri-mesh crate is an option.
If you want to make your own reader/writer of the .3d format yourself, then take a look at the CPUMesh implementation.