Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
benediktschwab committed Jul 9, 2024
1 parent 221c7ff commit 0b957cc
Show file tree
Hide file tree
Showing 21 changed files with 307 additions and 116 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CI

on:
push:
branches:
- main
- develop
pull_request: {}


jobs:

build:
name: cargo build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Build
run: cargo build

test:
name: cargo test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt clippy
- name: rustfmt
run: cargo fmt --all -- --check
- name: clippy
run: cargo clippy
- name: test
run: cargo test --verbose
50 changes: 48 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
### JetBrains template
# Created by https://www.toptal.com/developers/gitignore/api/rust,macos,jetbrains+all
# Edit at https://www.toptal.com/developers/gitignore?templates=rust,macos,jetbrains+all

### JetBrains+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

Expand Down Expand Up @@ -77,7 +80,49 @@ fabric.properties
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### Rust template
### JetBrains+all Patch ###
# Ignore everything but code style settings and run configurations
# that are supposed to be shared within teams.

.idea/*

!.idea/codeStyles
!.idea/runConfigurations

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### macOS Patch ###
# iCloud generated files
*.icloud

### Rust ###
# Generated by Cargo
# will have compiled files and executables
debug/
Expand All @@ -93,3 +138,4 @@ Cargo.lock
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

# End of https://www.toptal.com/developers/gitignore/api/rust,macos,jetbrains+all
20 changes: 11 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ members = [
"crates/*"
]

resolver = "2"

[workspace.package]
version = "0.0.1-alpha.1"
authors = ["Benedikt Schwab"]
version = "0.0.1-alpha.3"
authors = ["Benedikt Schwab <[email protected]>"]
edition = "2021"
license = "MIT OR Apache-2.0"
repository = "https://github.com/tum-gis/egraphics"
repository = "https://github.com/envis-space/egraphics"

[workspace.dependencies]
thiserror = "1.0"
tracing = "0.1.30"
tracing-subscriber = "0.3.8"
gltf = "1.0.0"
gltf-json = "1.0.0"
nalgebra = "0.31.1"
thiserror = "1.0.61"
tracing = "0.1.40"
tracing-subscriber = "0.3.18"
gltf = "1.4.1"
gltf-json = "1.4.1"
nalgebra = "0.33.0"
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
# egraphics

A Rust library for processing graphics formats in 3D space.

> [!WARNING]
> The library is at an early stage of development.
## Contributing

The library is developed at the [TUM Chair of Geoinformatics](https://github.com/tum-gis) and contributions are highly welcome.
6 changes: 3 additions & 3 deletions crates/egraphics-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ authors.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true
description = "CLI tool for graphics data operations"
description = "CLI tool for processing graphics formats in 3D space."

[dependencies]
egraphics-core = { version = "0.0.1-alpha.1", path = "../egraphics-core", registry = "custom" }
egraphics-io = { version = "0.0.1-alpha.1", path = "../egraphics-io", registry = "custom" }
egraphics-core = { version = "0.0.1-alpha.3", path = "../egraphics-core" }
egraphics-io = { version = "0.0.1-alpha.3", path = "../egraphics-io" }

tracing = { workspace = true }
tracing-subscriber = { workspace = true }
10 changes: 10 additions & 0 deletions crates/egraphics-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# egraphics-cli

CLI tool for processing graphics formats in 3D space.

> [!WARNING]
> The library is at an early stage of development.
## Contributing

The library is developed at the [TUM Chair of Geoinformatics](https://github.com/tum-gis) and contributions are highly welcome.
3 changes: 2 additions & 1 deletion crates/egraphics-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ authors.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true
description = "Core of the egraphics library"
description = "Core primitives and operations for processing graphics formats in 3D space."


[dependencies]
thiserror = { workspace = true }
nalgebra = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
10 changes: 10 additions & 0 deletions crates/egraphics-core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# egraphics-core

Core primitives and operations for processing graphics formats in 3D space.

> [!WARNING]
> The library is at an early stage of development.
## Contributing

The library is developed at the [TUM Chair of Geoinformatics](https://github.com/tum-gis) and contributions are highly welcome.
10 changes: 10 additions & 0 deletions crates/egraphics-core/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use thiserror::Error;

#[derive(Error, Debug)]
pub enum Error {
#[error(transparent)]
Io(#[from] std::io::Error),

#[error("No triangle")]
NoElements,
}
24 changes: 12 additions & 12 deletions crates/egraphics-core/src/geometry/sample_geometry.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
use crate::geometry::geometry;
use crate::geometry::triangle;
use nalgebra;

pub fn generate_sample_triangle_mesh() -> geometry::TriangleMesh {
pub fn generate_sample_triangle_mesh() -> triangle::TriangleMesh {
let triangle_a_vertices = vec![
geometry::Vertex {
triangle::Vertex {
position: nalgebra::Point3::new(0.0, 0.5, 0.0),
color: nalgebra::Point3::new(1.0, 0.0, 0.0),
},
geometry::Vertex {
triangle::Vertex {
position: nalgebra::Point3::new(-0.5, -0.5, 0.0),
color: nalgebra::Point3::new(0.0, 1.0, 0.0),
},
geometry::Vertex {
triangle::Vertex {
position: nalgebra::Point3::new(0.5, -0.5, 0.0),
color: nalgebra::Point3::new(1.0, 1.0, 1.0),
},
];
let triangle_a = geometry::Triangle {
let triangle_a = triangle::Triangle {
vertices: triangle_a_vertices,
};

let triangle_b_vertices = vec![
geometry::Vertex {
triangle::Vertex {
position: nalgebra::Point3::new(3.0, 3.5, 3.0),
color: nalgebra::Point3::new(1.0, 0.0, 0.0),
},
geometry::Vertex {
triangle::Vertex {
position: nalgebra::Point3::new(2.5, 2.5, 3.0),
color: nalgebra::Point3::new(0.0, 1.0, 0.0),
},
geometry::Vertex {
triangle::Vertex {
position: nalgebra::Point3::new(3.5, 2.5, 3.0),
color: nalgebra::Point3::new(1.0, 1.0, 1.0),
},
];
let triangle_b = geometry::Triangle {
let triangle_b = triangle::Triangle {
vertices: triangle_b_vertices,
};

let triangle_list: Vec<geometry::Triangle> = vec![triangle_a, triangle_b];
let triangle_list: Vec<triangle::Triangle> = vec![triangle_a, triangle_b];

geometry::TriangleMesh {
triangle::TriangleMesh {
triangles: triangle_list,
}
}
15 changes: 13 additions & 2 deletions crates/egraphics-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
mod geometry;
mod error;
mod triangle;
mod triangle_mesh;

#[doc(inline)]
pub use geometry::geometry::*;
pub use error::Error;

#[doc(inline)]
pub use triangle::Triangle;

#[doc(inline)]
pub use triangle::Vertex;

#[doc(inline)]
pub use triangle_mesh::TriangleMesh;
77 changes: 77 additions & 0 deletions crates/egraphics-core/src/triangle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
use crate::Error;
use crate::Error::NoElements;
use std::mem;

#[derive(Copy, Clone, Debug, PartialEq)]
pub struct Vector3D {
x: f32,
y: f32,
z: f32,
}

impl Vector3D {
pub fn new(x: f32, y: f32, z: f32) -> Self {
Self { x, y, z }
}
}

#[derive(Copy, Clone, Debug, PartialEq)]
#[repr(C)]
pub struct Vertex {
pub(crate) position: nalgebra::Point3<f32>,
pub(crate) color: nalgebra::Point3<f32>,
}

impl Vertex {
pub fn new(position: nalgebra::Point3<f32>, color: nalgebra::Point3<f32>) -> Self {
Self { position, color }
}

pub fn position(&self) -> &nalgebra::Point3<f32> {
&self.position
}

pub fn color(&self) -> &nalgebra::Point3<f32> {
&self.color
}
}

#[derive(Clone, Debug, PartialEq)]
pub struct Triangle {
vertices: Vec<Vertex>,
}

impl Triangle {
pub fn new(vertices: Vec<Vertex>) -> Result<Self, Error> {
if vertices.is_empty() {
return Err(NoElements);
}

Ok(Self { vertices })
}

pub(crate) fn buffer_length(&self) -> u32 {
(self.vertices.len() * mem::size_of::<Vertex>()) as u32
}

pub(crate) fn len(&self) -> usize {
self.vertices.len()
}

pub(crate) fn get_vertices(&self) -> &Vec<Vertex> {
&self.vertices
}
}

impl From<Vec<nalgebra::Point3<f32>>> for Triangle {
fn from(item: Vec<nalgebra::Point3<f32>>) -> Self {
let vertices = item
.iter()
.map(|p| Vertex {
position: *p,
color: nalgebra::Point3::new(0.5, 0.5, 0.5),
})
.collect();
Triangle { vertices }
}
}
Loading

0 comments on commit 0b957cc

Please sign in to comment.