Reorganize modules
This commit is contained in:
88
common/src/serde_impls.rs
Normal file
88
common/src/serde_impls.rs
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
use nalgebra::Vector3;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
pub mod vector3f {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
pub fn deserialize<'de, D>(deserializer: D) -> Result<Vector3<f32>, D::Error>
|
||||||
|
where
|
||||||
|
D: serde::Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let [x, y, z] = <[f32; 3]>::deserialize(deserializer)?;
|
||||||
|
Ok(Vector3::new(x, y, z))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn serialize<S>(data: &Vector3<f32>, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: serde::Serializer,
|
||||||
|
{
|
||||||
|
data.as_slice().serialize(serializer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod vector2u {
|
||||||
|
use nalgebra::Vector2;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
pub fn deserialize<'de, D>(deserializer: D) -> Result<Vector2<u32>, D::Error>
|
||||||
|
where
|
||||||
|
D: serde::Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let [x, y] = <[u32; 2]>::deserialize(deserializer)?;
|
||||||
|
Ok(Vector2::new(x, y))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn serialize<S>(data: &Vector2<u32>, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: serde::Serializer,
|
||||||
|
{
|
||||||
|
data.as_slice().serialize(serializer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod vector3_list {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
pub fn deserialize<'de, D>(deserializer: D) -> Result<Vec<Vector3<f32>>, D::Error>
|
||||||
|
where
|
||||||
|
D: serde::Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let data = Vec::<f32>::deserialize(deserializer)?;
|
||||||
|
Ok(data
|
||||||
|
.chunks(3)
|
||||||
|
.map(|chunk| Vector3::new(chunk[0], chunk[1], chunk[2]))
|
||||||
|
.collect())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn serialize<S>(data: &[Vector3<f32>], serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: serde::Serializer,
|
||||||
|
{
|
||||||
|
let out = data.iter().flat_map(|v| v.iter()).collect::<Vec<_>>();
|
||||||
|
out.serialize(serializer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod index_list {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
pub fn deserialize<'de, D>(deserializer: D) -> Result<Vec<[u32; 3]>, D::Error>
|
||||||
|
where
|
||||||
|
D: serde::Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let data = Vec::<u32>::deserialize(deserializer)?;
|
||||||
|
Ok(data
|
||||||
|
.chunks(3)
|
||||||
|
.map(|chunk| [chunk[0], chunk[1], chunk[2]])
|
||||||
|
.collect())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn serialize<S>(data: &[[u32; 3]], serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: serde::Serializer,
|
||||||
|
{
|
||||||
|
let out = data.iter().flat_map(|v| v.iter()).collect::<Vec<_>>();
|
||||||
|
out.serialize(serializer)
|
||||||
|
}
|
||||||
|
}
|
@@ -1,7 +1,7 @@
|
|||||||
use std::{
|
use std::{
|
||||||
fs,
|
fs,
|
||||||
net::{IpAddr, Ipv4Addr},
|
net::{IpAddr, Ipv4Addr},
|
||||||
path::Path,
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
@@ -18,6 +18,7 @@ pub struct Config {
|
|||||||
pub show_normals: bool,
|
pub show_normals: bool,
|
||||||
pub grid_size: f32,
|
pub grid_size: f32,
|
||||||
pub theme: Theme,
|
pub theme: Theme,
|
||||||
|
pub recent_projects: Vec<PathBuf>,
|
||||||
|
|
||||||
// Remote print settings
|
// Remote print settings
|
||||||
pub alert_print_completion: bool,
|
pub alert_print_completion: bool,
|
||||||
@@ -57,8 +58,11 @@ impl Default for Config {
|
|||||||
Self {
|
Self {
|
||||||
render_style: RenderStyle::Rended,
|
render_style: RenderStyle::Rended,
|
||||||
show_normals: false,
|
show_normals: false,
|
||||||
theme: Theme::Dark,
|
|
||||||
grid_size: 12.16,
|
grid_size: 12.16,
|
||||||
|
theme: Theme::Dark,
|
||||||
|
|
||||||
|
recent_projects: Vec::new(),
|
||||||
|
|
||||||
alert_print_completion: false,
|
alert_print_completion: false,
|
||||||
init_remote_print_at_startup: false,
|
init_remote_print_at_startup: false,
|
||||||
http_status_proxy: false,
|
http_status_proxy: false,
|
@@ -22,15 +22,11 @@ use slicer::{slicer::Slicer, Pos};
|
|||||||
use tracing::{info, warn};
|
use tracing::{info, warn};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::Config,
|
|
||||||
plugins::{
|
plugins::{
|
||||||
elephant_foot_fixer::{self},
|
elephant_foot_fixer::{self},
|
||||||
PluginManager,
|
PluginManager,
|
||||||
},
|
},
|
||||||
project::{BorrowedProject, OwnedProject},
|
|
||||||
remote_print::RemotePrint,
|
|
||||||
render::{camera::Camera, rendered_mesh::RenderedMesh},
|
render::{camera::Camera, rendered_mesh::RenderedMesh},
|
||||||
slice_operation::{SliceOperation, SliceResult},
|
|
||||||
ui::{
|
ui::{
|
||||||
drag_and_drop,
|
drag_and_drop,
|
||||||
popup::{Popup, PopupIcon, PopupManager},
|
popup::{Popup, PopupIcon, PopupManager},
|
||||||
@@ -41,6 +37,16 @@ use crate::{
|
|||||||
use common::config::{ExposureConfig, SliceConfig};
|
use common::config::{ExposureConfig, SliceConfig};
|
||||||
use goo_format::{File as GooFile, LayerEncoder, PreviewImage};
|
use goo_format::{File as GooFile, LayerEncoder, PreviewImage};
|
||||||
|
|
||||||
|
pub mod config;
|
||||||
|
pub mod project;
|
||||||
|
pub mod remote_print;
|
||||||
|
pub mod slice_operation;
|
||||||
|
use config::Config;
|
||||||
|
use remote_print::RemotePrint;
|
||||||
|
use slice_operation::{SliceOperation, SliceResult};
|
||||||
|
|
||||||
|
use project::{BorrowedProject, OwnedProject};
|
||||||
|
|
||||||
pub struct App {
|
pub struct App {
|
||||||
// todo: dock state in ui_state?
|
// todo: dock state in ui_state?
|
||||||
pub dock_state: DockState<Tab>,
|
pub dock_state: DockState<Tab>,
|
||||||
@@ -242,6 +248,8 @@ impl App {
|
|||||||
let mut file = File::open(path)?;
|
let mut file = File::open(path)?;
|
||||||
let project = OwnedProject::deserialize(&mut file)?;
|
let project = OwnedProject::deserialize(&mut file)?;
|
||||||
|
|
||||||
|
self.config.recent_projects.push(path.to_path_buf());
|
||||||
|
|
||||||
project.apply(self);
|
project.apply(self);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
@@ -1,10 +1,28 @@
|
|||||||
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
use egui::Color32;
|
use egui::Color32;
|
||||||
use nalgebra::Vector3;
|
use nalgebra::Vector3;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::render::rendered_mesh::RenderedMesh;
|
|
||||||
use slicer::mesh::Mesh;
|
use slicer::mesh::Mesh;
|
||||||
|
|
||||||
|
use crate::{app::App, render::rendered_mesh::RenderedMesh};
|
||||||
|
use common::config::SliceConfig;
|
||||||
|
|
||||||
|
const VERSION: u32 = 0;
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct BorrowedProject<'a> {
|
||||||
|
meshes: Vec<BorrowedProjectMesh<'a>>,
|
||||||
|
slice_config: &'a SliceConfig,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct OwnedProject {
|
||||||
|
meshes: Vec<OwnedProjectMesh>,
|
||||||
|
slice_config: SliceConfig,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct OwnedProjectMesh {
|
pub struct OwnedProjectMesh {
|
||||||
info: ProjectMeshInfo,
|
info: ProjectMeshInfo,
|
||||||
@@ -35,6 +53,51 @@ pub struct ProjectMeshInfo {
|
|||||||
rotation: Vector3<f32>,
|
rotation: Vector3<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> BorrowedProject<'a> {
|
||||||
|
pub fn new(meshes: &'a [RenderedMesh], slice_config: &'a SliceConfig) -> Self {
|
||||||
|
let meshes = meshes
|
||||||
|
.iter()
|
||||||
|
.map(BorrowedProjectMesh::from_rendered_mesh)
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
Self {
|
||||||
|
meshes,
|
||||||
|
slice_config,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn serialize<Writer: Write>(&self, writer: &mut Writer) -> Result<()> {
|
||||||
|
writer.write_all(&VERSION.to_le_bytes())?;
|
||||||
|
bincode::serialize_into(writer, self)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl OwnedProject {
|
||||||
|
pub fn deserialize<Reader: Read>(reader: &mut Reader) -> Result<Self> {
|
||||||
|
let mut version_bytes = [0; 4];
|
||||||
|
reader.read_exact(&mut version_bytes)?;
|
||||||
|
let version = u32::from_le_bytes(version_bytes);
|
||||||
|
|
||||||
|
if version != VERSION {
|
||||||
|
anyhow::bail!("Invalid version: Expected {VERSION} found {version}");
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(bincode::deserialize_from(reader)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn apply(self, app: &mut App) {
|
||||||
|
let mut meshes = app.meshes.write();
|
||||||
|
*meshes = self
|
||||||
|
.meshes
|
||||||
|
.into_iter()
|
||||||
|
.map(|mesh| mesh.into_rendered_mesh())
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
app.slice_config = self.slice_config;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl OwnedProjectMesh {
|
impl OwnedProjectMesh {
|
||||||
pub fn into_rendered_mesh(self) -> RenderedMesh {
|
pub fn into_rendered_mesh(self) -> RenderedMesh {
|
||||||
let mut mesh = Mesh::new_uncentred(self.vertices, self.faces, self.normals);
|
let mut mesh = Mesh::new_uncentred(self.vertices, self.faces, self.normals);
|
@@ -11,12 +11,8 @@ use wgpu::{DeviceDescriptor, Features, Limits, TextureFormat};
|
|||||||
const TEXTURE_FORMAT: TextureFormat = TextureFormat::Bgra8Unorm;
|
const TEXTURE_FORMAT: TextureFormat = TextureFormat::Bgra8Unorm;
|
||||||
|
|
||||||
mod app;
|
mod app;
|
||||||
mod config;
|
|
||||||
mod plugins;
|
mod plugins;
|
||||||
mod project;
|
|
||||||
mod remote_print;
|
|
||||||
mod render;
|
mod render;
|
||||||
mod slice_operation;
|
|
||||||
mod ui;
|
mod ui;
|
||||||
mod windows;
|
mod windows;
|
||||||
use app::App;
|
use app::App;
|
||||||
|
@@ -1,69 +0,0 @@
|
|||||||
use std::io::{Read, Write};
|
|
||||||
|
|
||||||
use anyhow::Result;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use crate::{app::App, render::rendered_mesh::RenderedMesh};
|
|
||||||
use common::config::SliceConfig;
|
|
||||||
|
|
||||||
use mesh::{BorrowedProjectMesh, OwnedProjectMesh};
|
|
||||||
mod mesh;
|
|
||||||
|
|
||||||
const VERSION: u32 = 0;
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
|
||||||
pub struct BorrowedProject<'a> {
|
|
||||||
meshes: Vec<BorrowedProjectMesh<'a>>,
|
|
||||||
slice_config: &'a SliceConfig,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
pub struct OwnedProject {
|
|
||||||
meshes: Vec<OwnedProjectMesh>,
|
|
||||||
slice_config: SliceConfig,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> BorrowedProject<'a> {
|
|
||||||
pub fn new(meshes: &'a [RenderedMesh], slice_config: &'a SliceConfig) -> Self {
|
|
||||||
let meshes = meshes
|
|
||||||
.iter()
|
|
||||||
.map(BorrowedProjectMesh::from_rendered_mesh)
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
Self {
|
|
||||||
meshes,
|
|
||||||
slice_config,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn serialize<Writer: Write>(&self, writer: &mut Writer) -> Result<()> {
|
|
||||||
writer.write_all(&VERSION.to_le_bytes())?;
|
|
||||||
bincode::serialize_into(writer, self)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl OwnedProject {
|
|
||||||
pub fn deserialize<Reader: Read>(reader: &mut Reader) -> Result<Self> {
|
|
||||||
let mut version_bytes = [0; 4];
|
|
||||||
reader.read_exact(&mut version_bytes)?;
|
|
||||||
let version = u32::from_le_bytes(version_bytes);
|
|
||||||
|
|
||||||
if version != VERSION {
|
|
||||||
anyhow::bail!("Invalid version: Expected {VERSION} found {version}");
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(bincode::deserialize_from(reader)?)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn apply(self, app: &mut App) {
|
|
||||||
let mut meshes = app.meshes.write();
|
|
||||||
*meshes = self
|
|
||||||
.meshes
|
|
||||||
.into_iter()
|
|
||||||
.map(|mesh| mesh.into_rendered_mesh())
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
app.slice_config = self.slice_config;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -6,7 +6,7 @@ use nalgebra::{Matrix4, Vector3};
|
|||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use wgpu::{CommandBuffer, CommandEncoder, Device, Queue, RenderPass};
|
use wgpu::{CommandBuffer, CommandEncoder, Device, Queue, RenderPass};
|
||||||
|
|
||||||
use crate::{config::Config, slice_operation::SliceOperation};
|
use crate::app::{config::Config, slice_operation::SliceOperation};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
camera::Camera,
|
camera::Camera,
|
||||||
|
@@ -41,7 +41,7 @@ pub fn ui(app: &mut App, ui: &mut Ui, _ctx: &Context) {
|
|||||||
.clicked();
|
.clicked();
|
||||||
|
|
||||||
if open {
|
if open {
|
||||||
ui.strong(&mesh.name);
|
ui.text_edit_singleline(&mut mesh.name);
|
||||||
} else {
|
} else {
|
||||||
ui.label(&mesh.name);
|
ui.label(&mesh.name);
|
||||||
}
|
}
|
||||||
@@ -66,10 +66,6 @@ pub fn ui(app: &mut App, ui: &mut Ui, _ctx: &Context) {
|
|||||||
});
|
});
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
|
|
||||||
ui.label("Name");
|
|
||||||
ui.text_edit_singleline(&mut mesh.name);
|
|
||||||
ui.end_row();
|
|
||||||
|
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.label("Position");
|
ui.label("Position");
|
||||||
ui.add_space(20.0);
|
ui.add_space(20.0);
|
||||||
|
@@ -12,9 +12,8 @@ use nalgebra::Vector2;
|
|||||||
use rfd::FileDialog;
|
use rfd::FileDialog;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
app::App,
|
app::{slice_operation::SliceResult, App},
|
||||||
render::slice_preview::SlicePreviewRenderCallback,
|
render::slice_preview::SlicePreviewRenderCallback,
|
||||||
slice_operation::SliceResult,
|
|
||||||
ui::{components::vec2_dragger, popup::Popup},
|
ui::{components::vec2_dragger, popup::Popup},
|
||||||
};
|
};
|
||||||
use common::serde::DynamicSerializer;
|
use common::serde::DynamicSerializer;
|
||||||
|
Reference in New Issue
Block a user