mirror of
https://github.com/hannobraun/Fornjot
synced 2025-08-10 11:16:10 +00:00
Merge pull request #456 from hannobraun/mesh
Move `Mesh` to `fj-interop`
This commit is contained in:
commit
8d2aba6737
@ -1,10 +1,11 @@
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use fj_interop::debug::DebugInfo;
|
||||
use fj_interop::{
|
||||
debug::DebugInfo,
|
||||
mesh::{Index, Mesh},
|
||||
};
|
||||
use fj_math::Triangle;
|
||||
use nalgebra::{vector, Point};
|
||||
|
||||
use crate::mesh::{Index, MeshMaker};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Vertices {
|
||||
vertices: Vec<Vertex>,
|
||||
@ -68,7 +69,7 @@ impl Vertices {
|
||||
|
||||
impl From<&Vec<Triangle<3>>> for Vertices {
|
||||
fn from(triangles: &Vec<Triangle<3>>) -> Self {
|
||||
let mut mesh = MeshMaker::new();
|
||||
let mut mesh = Mesh::new();
|
||||
|
||||
for triangle in triangles {
|
||||
let [a, b, c] = triangle.points();
|
||||
|
@ -3,7 +3,6 @@ mod camera;
|
||||
mod config;
|
||||
mod graphics;
|
||||
mod input;
|
||||
mod mesh;
|
||||
mod window;
|
||||
|
||||
use std::path::PathBuf;
|
||||
@ -11,6 +10,7 @@ use std::{collections::HashMap, time::Instant};
|
||||
|
||||
use fj_host::Model;
|
||||
use fj_interop::debug::DebugInfo;
|
||||
use fj_interop::mesh::Mesh;
|
||||
use fj_kernel::algorithms::triangulate;
|
||||
use fj_math::{Aabb, Scalar, Triangle};
|
||||
use fj_operations::ToShape as _;
|
||||
@ -28,7 +28,6 @@ use crate::{
|
||||
camera::Camera,
|
||||
config::Config,
|
||||
graphics::{DrawConfig, Renderer},
|
||||
mesh::MeshMaker,
|
||||
window::Window,
|
||||
};
|
||||
|
||||
@ -86,7 +85,7 @@ fn main() -> anyhow::Result<()> {
|
||||
let shape = model.load_once(¶meters)?;
|
||||
let shape = shape_processor.process(&shape);
|
||||
|
||||
let mut mesh_maker = MeshMaker::new();
|
||||
let mut mesh_maker = Mesh::new();
|
||||
|
||||
for triangle in shape.triangles {
|
||||
for vertex in triangle.points() {
|
||||
|
@ -3,3 +3,4 @@
|
||||
#![deny(missing_docs)]
|
||||
|
||||
pub mod debug;
|
||||
pub mod mesh;
|
||||
|
@ -1,24 +1,22 @@
|
||||
//! A triangle mesh
|
||||
|
||||
use std::{collections::HashMap, hash::Hash};
|
||||
|
||||
/// API for creating a mesh
|
||||
pub struct MeshMaker<V> {
|
||||
/// A triangle mesh
|
||||
pub struct Mesh<V> {
|
||||
vertices: Vec<V>,
|
||||
indices: Vec<Index>,
|
||||
|
||||
indices_by_vertex: HashMap<V, Index>,
|
||||
}
|
||||
|
||||
impl<V> MeshMaker<V>
|
||||
impl<V> Mesh<V>
|
||||
where
|
||||
V: Copy + Eq + Hash,
|
||||
{
|
||||
/// Create a new instance of `MeshMaker`
|
||||
/// Construct a new instance of `Mesh`
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
vertices: Vec::new(),
|
||||
indices: Vec::new(),
|
||||
indices_by_vertex: HashMap::new(),
|
||||
}
|
||||
Self::default()
|
||||
}
|
||||
|
||||
/// Add a vertex to the mesh
|
||||
@ -44,5 +42,17 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
// This needs to be a manual implementation. Deriving `Default` would require
|
||||
// `V` to be `Default` as well, even though that is not necessary.
|
||||
impl<V> Default for Mesh<V> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
vertices: Default::default(),
|
||||
indices: Default::default(),
|
||||
indices_by_vertex: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// An index that refers to a vertex in a mesh
|
||||
pub type Index = u32;
|
Loading…
x
Reference in New Issue
Block a user