[][src]Struct density_mesh_core::live::LiveDensityMesh

pub struct LiveDensityMesh { /* fields omitted */ }

Density mesh with support for interactive region changes. This struct allows you to make changes without splitting mesh into chunks. Best for real-time applications.

Examples

use density_mesh_core::prelude::*;

let map = DensityMap::new(2, 4, 1, vec![255; 8]).unwrap();
let settings = GenerateDensityMeshSettings {
    points_separation: 0.5.into(),
    steepness_threshold: 0.0,
    keep_invisible_triangles: true,
    ..Default::default()
};
// create live density mesh.
let mut live = LiveDensityMesh::new(map, settings.clone());
// perform initial processing.
live.process_wait().unwrap();
// apply new data to inner density map region.
live.change_map(0, 2, 2, 2, vec![0; 4], settings);
// process changes.
live.process_wait().unwrap();
assert_eq!(live.map().values(), &[1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0]);
assert_eq!(live.mesh().unwrap(), &DensityMesh {
    points: vec![
        Coord { x: 1.0, y: 0.0 },
        Coord { x: 0.0, y: 0.0 },
        Coord { x: 1.0, y: 2.0 },
        Coord { x: 0.0, y: 2.0 },
        Coord { x: 1.0, y: 1.0 },
        Coord { x: 0.0, y: 1.0 },
        Coord { x: 0.0, y: 3.0 },
        Coord { x: 1.0, y: 3.0 },
        Coord { x: 1.0, y: 2.0 },
        Coord { x: 0.0, y: 2.0 },
    ],
    triangles: vec![
        Triangle { a: 2, b: 4, c: 3 },
        Triangle { a: 4, b: 5, c: 3 },
        Triangle { a: 4, b: 0, c: 5 },
        Triangle { a: 0, b: 1, c: 5 },
        Triangle { a: 6, b: 7, c: 8 },
        Triangle { a: 8, b: 9, c: 6 },
    ],
});

Implementations

impl LiveDensityMesh[src]

pub fn new(map: DensityMap, settings: GenerateDensityMeshSettings) -> Self[src]

Create new live density mesh instance.

Arguments

  • map - Density map.
  • settings - Density mesh generation settings.

Returns

Live density mesh instance.

pub fn map(&self) -> &DensityMap[src]

Get inner density map.

pub fn mesh(&self) -> Option<&DensityMesh>[src]

Get inner density mesh if one is already generated.

pub fn in_progress(&self) -> bool[src]

Tells if there are changes left to process.

pub fn change_map(
    &mut self,
    col: usize,
    row: usize,
    width: usize,
    height: usize,
    data: Vec<u8>,
    settings: GenerateDensityMeshSettings
) -> Result<(), DensityMapError>
[src]

Process pending changes.

Arguments

  • col - Density map destination column.
  • row - Density map destination row.
  • width - Source data unscaled width.
  • height - Source data unscaled height.
  • data - Source data buffer.
  • settings - Density mesh generation settings applied for this change.

Returns

Ok if successful or density map error.

pub fn process(&mut self) -> Result<LiveProcessStatus, GenerateDensityMeshError>[src]

Process all pending changes to internal mesh.

Returns

Result with process status (Ok), or density mesh generation error.

pub fn process_wait(&mut self) -> Result<(), GenerateDensityMeshError>[src]

Process all pending changes to internal mesh until it's done.

Returns

Ok when done, or density mesh generation error.

Trait Implementations

impl Clone for LiveDensityMesh[src]

impl Debug for LiveDensityMesh[src]

impl<'de> Deserialize<'de> for LiveDensityMesh[src]

impl PartialEq<LiveDensityMesh> for LiveDensityMesh[src]

impl Serialize for LiveDensityMesh[src]

impl StructuralPartialEq for LiveDensityMesh[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.