Skip to content

Commit

Permalink
add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
besok committed Nov 25, 2024
1 parent 3a55977 commit a969175
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 148 deletions.
Empty file added CONTRIBUTING.md
Empty file.
149 changes: 9 additions & 140 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,147 +11,16 @@ Fully written in Rust for speed and safety.

# Features

## Data Loading and Creation.
- 🖼️ Interactive 3D visualization
- 📊 3D Data manipulation and analysis
- 🛠️ Mesh generation and manipulation
- 📂 Supports various scientific data formats

Tessellate supports a range of file formats commonly used in scientific computing,
including PLY (.ply), STL (.stl), OBJ (.obj).
You can directly read data from these files into the objects for visualization and analysis.
The project is in early development stage.

- Import Obj Files
- Import Ply Files
- Import Stl Files
The documentation is available [here](https://besok.github.io/tessellate/).

The details can be found in the [import_models](examples/import_models/README.md) example.
The module `files` provides functions to read and write mesh data from and to files.
# Contributing


## Mesh Manipulation.

### Creating Basic Geometries.

The library provides functions to create fundamental geometric shapes like:
spheres, cubes, cuboids, cylinders, cones, rings, spheres, torus, planes and more from scratch.
These objects serve as building blocks for more complex visualizations.
The detailed example can be found in the [basic_shapes](examples/basic_shapes/README.md) example.

### Creating parametric Geometric Objects

The library provides functions to create parametric geometric shapes like:
supertoroids, parametric ellipsoids, partial parametric ellisoids, pseudospheres,spirals and more.
The detailed example can be found in the [parametric_shapes](examples/parametric_shapes/README.md) example.

### Creating an Explicit Structured Grid
### Creating a Structured Surface
### Creating a Triangulated Surface
### Platonic Solids
### Point Cloud


## Filtering
### Boolean Operations.
### Extract Cell Centers
The library provides functions to extract the centers of polygons and edges.
The detailed example can be found in the [extract_cell_centers](examples/polygon_and_edges_centers/README.md) example.

### Clipping with a Surface, plane and boxes
### Collision Detection
### Volumetric Analysis
### Find and label connected regions.
### Decimate a mesh
### Extract Edges
The library provides functions to extract the edges of a polygons.
The detailed example can be found in the [extract_edges](examples/extract_edges/README.md) example.

### Extract Surface
### Gaussian Smoothing
### Geodesic Paths
### Interpolating
### Computing Mesh Quality
### Resampling
### Surface Smoothing
### Surface Reconstruction
### Voxelize a Surface Mesh
### Subdivide Cells

## Advanced
### Visualize the Moeller-Trumbore Algorithm
https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm
https://cadxfem.org/inf/Fast%20MinimumStorage%20RayTriangle%20Intersection.pdf

### Ray Tracing
### Project points to a plane and Tessellate
generate a 3D point cloud, project it to a plane, and tessellate it.

## Visualization.

### Interactive Plotting.
The library facilitates creating interactive 3D plots using a plotter object.

### Color Mapping.
Assign colors to data points based on scalar values associated with the data.

### Anti-Aliasing
### Measuring distances and angles
### Show Edges
### Legends and glyphs

### Lighting and Shading.
Control lighting effects and shading models to enhance the visual representation of your data.
Explore options like smooth shading, ambient lighting, and directional lighting.

### Applying Textures
### Transparency.
### Camera Control.
### Animations.

## Auxiliary Tools and Data Structures.

### KDTree.

The library provides a KDTree implementation for efficient nearest neighbor searches in 3D space.

```rust
use crate::mesh::bool::kdtree::KDTree;
use crate::mesh::parts::Vertex;
use crate::mesh::shape::cone::Cone;
use crate::mesh::HasMesh;

#[test]
fn kdtree_test() {
let cone = Cone::default();
let mesh = cone.mesh();
let kdtree: KDTree = mesh.try_into().unwrap();

let full_len = kdtree.nearest_neighbors(&Vertex::default(), None).count();
let part_len = kdtree.nearest_neighbors(&Vertex::default(), Some(0.7)).count();

assert_eq!(full_len, 62);
assert_eq!(part_len, 14);

}
```

### BSP Tree.

The library provides a BSP Tree implementation for efficient point-in-polygon tests and spatial partitioning of 3D objects.

```rust
fn bsp_tree_test() {
let cone = Cone::default();
let mesh = cone.mesh();
let bsp: BSPTree = mesh.try_into().unwrap();
for node in bsp.iter_inorder() {
println!("{:?}", node);
}
}
fn bsp_to_mesh_test() {
turn_on_test_logs();
let fig = Cone::default();
let mesh = fig.mesh();
let bsp: BSPTree = mesh.try_into().unwrap();

let bsp_mesh = &bsp.mesh(Default::default());
let planes = &bsp.plane_meshes(10.0,Color::default());

}
```
The project is very welcomed to contributions.
Please read the [Contributing Guidelines](./CONTRIBUTING.md) before contributing.
2 changes: 1 addition & 1 deletion docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
- [Clipping with a Surface, plane and boxes]()
- [Collision Detection]()
- [Volumetric Analysis]()
- [Find and label connected regions]()
- [Connectivity]()
- [Decimate a mesh]()
- [Extract Edges](./extract_edges.md)
- [Extract Surface]()
Expand Down
16 changes: 16 additions & 0 deletions examples/connectivity/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Connectivity

This example demonstrates how to create and visualize basic 3D shapes using the `tessellate` library.


## How to Run

To run this example, use the following command:

```sh
cargo run --example connectivity
```

## Screenshot
![Connectivity Example](screenshot.png)

93 changes: 93 additions & 0 deletions examples/connectivity/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
use glam::{Mat4, Quat, Vec3};
use tessellate::gpu::camera::position::CameraPosition;
use tessellate::gpu::options::{CameraOptions, GpuOptions, LightOptions};
use tessellate::mesh::material::{Color, RgbaColor};
use tessellate::mesh::parts::face::FaceType;
use tessellate::mesh::parts::vertex::Vertex;
use tessellate::mesh::shape::cone::Cone;
use tessellate::mesh::shape::cuboid::cube::Cube;
use tessellate::mesh::shape::cylinder::Cylinder;
use tessellate::mesh::shape::icosahedron::Icosahedron;
use tessellate::mesh::shape::pyramid::Pyramid;
use tessellate::mesh::shape::ring::Ring;
use tessellate::mesh::shape::sphere::Sphere;
use tessellate::mesh::shape::torus::Torus;
use tessellate::mesh::transform::Transform;
use tessellate::mesh::HasMesh;
use tessellate::{gpu, TessError, TessResult};
use tessellate::mesh::attributes::Attributes;

fn main() -> TessResult<()> {
let meshes = vec![
cube_color_every_side()?.into(),
green_sphere()?.into(),
cone()?.into(),
cyan_ico().into(),
ring().into(),
cylinder().into(),
pyramid()?.into(),
torus().into(),
];

let opts = GpuOptions::new(
CameraOptions::new_position(Vec3::new(0.0, 5.0, 10.0)),
LightOptions::new_position(Vec3::new(0.0, 5.0, 3.0)),
);

Ok(gpu::visualize(meshes, opts)?)
}

fn torus() -> Torus {
Torus::create(Vec3::new(0.0, -2.0, 2.0), 1.0, 0.5, 32, 32, Attributes::default())
}

fn cylinder() -> Cylinder {
Cylinder::create([0.0, 0.0, 4.0], 1.0, 1.0, 3, Attributes::default())
}

fn green_sphere() -> TessResult<Sphere> {
let mut sphere = Sphere::create_ico(Vertex::default(), 1.0, 3, RgbaColor::GREEN.into());
sphere.transform(Mat4::from_translation(Vec3::new(0.0, 1.0, 0.0)))?;
Ok(sphere)
}

fn cone() -> Result<Cone, TessError> {
let mut cone = Cone::default();

cone.transform(Mat4::from_rotation_translation(
Quat::from_rotation_x(30.0),
Vec3::new(0.0, 1.0, 1.0),
))?;
Ok(cone)
}

fn pyramid() -> Result<Pyramid, TessError> {
let mut pyramid = Pyramid::default();
pyramid.transform(Mat4::from_rotation_translation(
Quat::from_rotation_x(0.0),
Vec3::new(0.0, 1.0, -3.0),
))?;
Ok(pyramid)
}

fn ring() -> Ring {
Ring::create(Vec3::new(0.0, 4.0, 0.0), 1.0, 0.5, 4.0, 32, Color::default())
}

fn cyan_ico() -> Icosahedron {
Icosahedron::create([3.0, 2.0, 1.0], 1.0, RgbaColor::CYAN)
}

fn cube_color_every_side() -> Result<Cube, TessError> {
let mut cube = Cube::create(Vertex::default(), 1.0, FaceType::Quad, Color::default());
let colors = cube
.mesh()
.faces()
.iter()
.map(|_| RgbaColor::random())
.collect();

cube.mesh_mut().attributes_mut().set_color(Color::Face(colors));
cube.transform(Mat4::from_translation(Vec3::new(-3.0, -3.0, 0.0)))?;
Ok(cube)
}
Binary file added examples/connectivity/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions src/gpu/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ pub struct LightOptions {
diffuse: Vec3,
specular: Vec3,
show_source: bool,
background_color: RgbaColor,
}

impl Default for LightOptions {
Expand All @@ -153,6 +154,7 @@ impl Default for LightOptions {
diffuse: Vec3::new(0.8, 0.8, 0.8),
specular: Vec3::new(0.8, 0.8, 0.8),
show_source: false,
background_color: RgbaColor::WHITE,
}
}
}
Expand All @@ -164,13 +166,15 @@ impl LightOptions {
diffuse: Vec3,
specular: Vec3,
show_source: bool,
background_color: RgbaColor,
) -> Self {
Self {
position,
ambient,
diffuse,
specular,
show_source,
background_color,
}
}
pub fn new_position(position: Vec3) -> Self {
Expand Down Expand Up @@ -204,6 +208,11 @@ impl LightOptions {
self.show_source = show_source;
self
}

pub fn with_background_color(&mut self, background_color: RgbaColor) -> &Self {
self.background_color = background_color;
self
}
}

impl LightOptions {
Expand All @@ -226,6 +235,10 @@ impl LightOptions {
pub fn show_source(&self) -> bool {
self.show_source
}

pub fn background_color(&self) -> &RgbaColor {
&self.background_color
}
}

impl Into<RgbaColor> for &LightOptions {
Expand Down
3 changes: 3 additions & 0 deletions src/gpu/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pub struct GpuHandler {
camera: Camera,
light: Light,
gui: GuiRenderer,
gpu_options: GpuOptions,
}

impl GpuHandler {
Expand All @@ -101,6 +102,7 @@ impl GpuHandler {
camera: Camera,
gui: GuiRenderer,
light: Light,
gpu_options: GpuOptions,
) -> Self {
Self {
window,
Expand All @@ -115,6 +117,7 @@ impl GpuHandler {
camera,
gui,
light,
gpu_options
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/gpu/processor/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ impl GpuProcessor {

Ok(GpuHandler::new(
window, instance, surface, device, queue, config, size, pipelines, gpu_meshes, camera,
gui, light,
gui, light, options,
))
}
}
Expand Down
13 changes: 7 additions & 6 deletions src/gpu/processor/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,19 @@ impl GpuHandler {
});

{
let b_color = self
.gpu_options
.light_opts()
.background_color()
.clone()
.into();
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color {
r: 0.1,
g: 0.2,
b: 1.0,
a: 1.0,
}),
load: wgpu::LoadOp::Clear(b_color),
store: wgpu::StoreOp::Store,
},
})],
Expand Down
Loading

0 comments on commit a969175

Please sign in to comment.