Image density/height map to mesh generator

Overview

Image density/height map to mesh generator

crates-io version

About

Crates used to generate 2D mesh from images representing density/height map.

Algorithm gets source image:

image source

Converts it into density/height values (here from alpha channell):

image values

Next makes steepness values:

image steepness

And builds mesh based on the highest steepness points:

image mesh

Rust API

Important modules

Typical use case would be to use two of them to create mesh from images but in case you have your own image handler, you can stick to the core module and produce density maps by yourself.

Working with chunks

In the past, there was a way to optimize work with big maps using chunks - these chunks wasn't giving a reliable topology and had to be removed.

Real-time density mesh modifications

Imagine that you have a one big mesh, you want to modify variable size regions of this mesh and don't want to split it into chunks - for this use case there is specialized DensityMeshGenerator type. Keep in mind that at the moment, even if you change only really smart part of the map, whole mesh will be rebuilt so for big maps this might take long which means, for now you shouldn't use this crate for high performance, HD maps generation.

let image = DynamicImage::ImageRgba8(
    image::open("../resources/heightmap.png")
        .expect("Cannot open file")
        .to_rgba(),
);
let settings = GenerateDensityImageSettings::default();
let map = generate_densitymap_from_image(image.clone(), &settings)
    .expect("Cannot produce density map image");
let settings = GenerateDensityMeshSettings {
    points_separation: 16.0.into(),
    keep_invisible_triangles: true,
    ..Default::default()
};
let mut generator = DensityMeshGenerator::new(vec![], map, settings.clone());
generator.process_wait().expect("Cannot process changes");
generator
    .change_map(64, 64, 128, 128, vec![255; 128 * 128], settings.clone())
    .expect("Cannot change live mesh map region");
generator
    .process_wait()
    .expect("Cannot process live changes");
generator
    .change_map(384, 384, 64, 64, vec![0; 64 * 64], settings)
    .expect("Cannot change live mesh map region");
generator
    .process_wait()
    .expect("Cannot process live changes");
let mut image = DynamicImage::ImageRgba8(
    generate_image_from_densitymap(generator.map(), false).to_rgba(),
);
apply_mesh_on_map(&mut image, generator.mesh().unwrap());
image
    .save("../resources/heightmap.live.png")
    .expect("Cannot save output image");

With that we have added two solid rectangles and result looks like:

image live

Optimizations of map region changes

Previous versions had live mesh generator which regenerated only the parts of the mesh that given region has changed - for now this is not further supported because of corner case situations where mesh generation crashes internally making use of this feature unreliable. This feature wil be added later when it will be redesigned.

CLI

Install / Update

cargo install density-mesh-cli --force

Example

density-mesh mesh -i image.png -o mesh.obj --obj

Options

density-mesh-cli 1.4.0
Patryk 'PsichiX' Budzynski <[email protected]>
CLI app for density mesh generator

USAGE:
    density-mesh.exe [SUBCOMMAND]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

SUBCOMMANDS:
    help     Prints this message or the help of the given subcommand(s)
    image    Produce density map image
    mesh     Produce density mesh
density-mesh.exe-image
Produce density map image

USAGE:
    density-mesh.exe image [FLAGS] [OPTIONS] --input <PATH> --output <PATH>

FLAGS:
    -h, --help         Prints help information
    -s, --steepness    Produce steepness image
    -V, --version      Prints version information
        --verbose      Display settings used

OPTIONS:
        --density-source <NAME>    Density source: luma, luma-alpha, red, green, blue, alpha [default: luma-alpha]
    -i, --input <PATH>             Input image file
    -o, --output <PATH>            Output image file
        --scale <INTEGER>          Image scale [default: 1]
density-mesh.exe-mesh
Produce density mesh

USAGE:
    density-mesh.exe mesh [FLAGS] [OPTIONS] --input <PATH> --output <PATH> <--json|--json-pretty|--yaml|--obj|--png>

FLAGS:
    -h, --help                        Prints help information
        --json                        Produce JSON mesh
        --json-pretty                 Produce pretty JSON mesh
        --keep-invisible-triangles    Keep invisible triangles
        --obj                         Produce OBJ mesh
        --png                         Produce PNG mesh visualization
    -V, --version                     Prints version information
        --verbose                     Display settings used
        --yaml                        Produce YAML mesh

OPTIONS:
        --density-source <NAME>            Density source: luma, luma-alpha, red, green, blue, alpha [default: luma-
                                           alpha]
        --extrude-size <NUMBER>            Extrude size
    -i, --input <PATH>                     Input image file
        --max-iterations <INTEGER>         Maximum tries number when finding point to place [default: 32]
    -o, --output <PATH>                    Output mesh file
        --points-separation <NUMBER>       Points separation [default: 10]
        --scale <INTEGER>                  Image scale [default: 1]
        --steepness-threshold <NUMBER>     Steepness threshold [default: 0.01]
        --update-region-margin <NUMBER>    Margin around update region box [default: 0]
        --visibility-threshold <NUMBER>    VIsibility threshold [default: 0.01]
You might also like...
Lust is a static image server designed to automatically convert uploaded image to several formats and preset sizes
Lust is a static image server designed to automatically convert uploaded image to several formats and preset sizes

What is Lust? Lust is a static image server designed to automatically convert uploaded image to several formats and preset sizes with scaling in mind.

Save image from your clipboard 📋 as an image file directly from your command line! 🔥

Clpy 📋 Save copied image from clipboard as an image file directly from your command line! Note It works only on windows as of now. I'll be adding sup

Takes a folder of images (as a palette), and an image, and figures out how to tile the palette to resemble the image!
Takes a folder of images (as a palette), and an image, and figures out how to tile the palette to resemble the image!

Takes a folder of images (as a palette), and an image, and figures out how to tile the palette to resemble the image!

Rust Lean Image Viewer - Fast and configurable image viewer inspired by JPEGView by David Kleiner
Rust Lean Image Viewer - Fast and configurable image viewer inspired by JPEGView by David Kleiner

Rust Lean Image Viewer - Fast and configurable image viewer inspired by JPEGView by David Kleiner

Conference Monitoring Project based on Image Recognition that uses Rust Language and AWS Rekognition service to get the level of image similarity.

Conference Monitoring System based on Image Recognition in Rust This is a Conference Monitoring Project based on Image Recognition that uses Rust Lang

Image proxy and embed generator.
Image proxy and embed generator.

January Description Image proxy and metadata scraper. Features: Can scrape metadata from websites, e.g. OpenGraph Can scrape embeds from websites, e.g

Boot tools: loader, image generator, etc as a library crate

ArcBoot v0 A uefi bootloader for riscv, arm and x86. Comes in the form of a single executable. the source code contains a single executable target and

 A dynamic image generator.
A dynamic image generator.

dynimgen A dynamic image generator. How to use step 1: The designers export the design drawing as an svg file svg rect / image src="img.png"

Sūshì is a simple but customizable static site generator / blog generator written in Rust

sūshì Sūshì is a simple but customizable static site generator / blog generator written in Rust. Installation Install with Cargo (Recommended) cargo i

ASCII terminal hexagonal map  roguelike written in Rust
ASCII terminal hexagonal map roguelike written in Rust

rhex Contributors welcome! Rhex is looking for contributors. See Contributing page for details. Introduction Simple ASCII terminal hexagonal map rogue

A Bevy plugin for loading the LDtk 2D tile map format.
A Bevy plugin for loading the LDtk 2D tile map format.

bevy_ldtk ( Tileset from "Cavernas" by Adam Saltsman ) A Bevy plugin for loading LDtk tile maps. Usage use bevy::prelude::*; use bevy_ldtk::*; fn mai

Everyday-use client-side map-aware Arch Linux mirror ranking tool

Rate Arch Mirrors This is a tool, which fetches mirrors, skips outdated/syncing Arch Linux mirrors, then uses info about submarine cables and internet

Typed any map for rust

TypedMap TypedMap is a typed HashMap. It allows you to define different value type depending on a Key type. It's useful if you want to store different

Pitch-perfect copy of map generation algorithm from Slay the Spire

sts_map_oracle Pitch-perfect copy of map generation algorithm from Slay the Spire Usage Prints out map layouts in console for given seed: sts_map_orac

A unix-friendly map-reduce parallelization alternative

slb: sharded load balancer Like parallel --pipe --roundrobin but load balancing is performed based on input line hashing. When performing keyed aggreg

A simple Vec-based Map inspired on JavaScript for rust.

A simple alternative to HashMap inspired on JavaScript's Map.

A rusty, spiky, heat-seeking quake map parser.

Shalrath   A rusty, spiky, heat-seeking quake map parser shalrath is a rust representation, [nom] parser and string serializer for Quake map files. It

A program written in Rust, that allows the user to find the current location of the International Space Station and see it on a map.

ISS Location ViewFinder A program written in Rust, that allows the user to find the current location of the International Space Station and see it on

Firecracker takes your HTTP logs and uses them to map your API flows and to detect anomalies in them.
Firecracker takes your HTTP logs and uses them to map your API flows and to detect anomalies in them.

Who is BLST and what do we do? BLST (Business Logic Security Testing) is a startup company that's developing an automatic penetration tester, replacin

Comments
  • Hang while processing 2K by 16K map

    Hang while processing 2K by 16K map

    Trying out the map generator with the following code:

                    let map = DensityMap::new(extent.width as usize, extent.height as usize, 1, raw_data).unwrap();
                    let settings = GenerateDensityMeshSettings {
                        points_separation: 16.0.into(),
                        keep_invisible_triangles: false,
                        ..Default::default()
                    };
                    // create live density mesh.
                    let mut live = LiveDensityMesh::new(map, settings);
                    // perform initial processing.
                    live.process_wait().unwrap();
    

    The map is 2K by 16K. I waited for more than an hour for a release build, it hasn't finished. Here is the test file - vangers-density (I wasn't able to upload the lossless PNG version, since it's above 10Megs)

    opened by kvark 10
  • Getting quality results on 2K by 16K heightmap

    Getting quality results on 2K by 16K heightmap

    First results so far aren't very convincing. See https://github.com/kvark/vange-rs/pull/188 for the screenshot and the code.

    Does density-mesh expect a height map at all? It has a DensityMap that I'm constructing, but I don't have a density per pixel, I have a height. So maybe I'm not using this right at all. With the settings I got so far, it takes some time to build the mesh, and it doesn't look nearly correct. It's close to random.

    opened by kvark 0
  • Add support for updating variable size parts of the mesh (not related to chunks)

    Add support for updating variable size parts of the mesh (not related to chunks)

    Right now if you want to update part of the mesh, you have to split it into chunks and update whole chunk on input data change.

    It would be very beneficial for real time destructible meshes to update only the parts where new density/height map points to.

    enhancement 
    opened by PsichiX 0
Owner
Patryk Budzyński
Patryk Budzyński
A naive density-based clustering algorithm written in Rust

Density-based clustering This a pure Rust implementation of a naive density-based clustering algorithm similar to DBSCAN. Here, 50 points are located

chris m 0 Mar 19, 2020
Kernel density estimation in Rust.

kernel-density-estimation Kernel density estimation in Rust. Kernel density estimation (KDE) is a non-parametric method to estimate the probability de

Seaton Ullberg 16 Jan 16, 2023
SelfOrgMap 5 Nov 4, 2020
A purpose-built proxy for the Linkerd service mesh. Written in Rust.

This repo contains the transparent proxy component of Linkerd2. While the Linkerd2 proxy is heavily influenced by the Linkerd 1.X proxy, it comprises

Linkerd 1.7k Jan 7, 2023
Hybrid Traffic Mesh Proxy

Hybrid Traffic Mesh Proxy L7 proxy on kubernetes dependencies: routeagent: refresh proxy routes fetched with k8s sdk register routes curl -v --unix-s

Goku 1 Feb 11, 2022
Ultralight, security-first service mesh for Kubernetes. Main repo for Linkerd 2.x.

Linkerd ?? Welcome to Linkerd! ?? Linkerd is an ultralight, security-first service mesh for Kubernetes. Linkerd adds critical security, observability,

Linkerd 9.2k Jan 1, 2023
Apply a pixelation effect to any Bevy mesh or scene without post-processing.

Pixelate Mesh Apply a pixelation effect to any Bevy mesh or scene without post-processing. Usage Add the PixelateMeshPlugin, where you specify a compo

Jan Hohenheim 16 Mar 25, 2023
Implementation of Sunny's Mesh Security talk (Hackathon / Prototype status)

mesh-security (Hackathon / Prototype status) An implementation of Sunny's Mesh Security talk from Cosmoverse 2022. This should run on any CosmWasm ena

CosmWasm 83 Apr 17, 2023
Bevy Meshem is a Rust crate designed to provide meshing algorithms for voxel grids, enabling you to create cohesive 3D mesh structures from a grid of cubic voxels

Bevy Meshem Crates.io, docs Bevy Compatibility: Bevy Version bevy_meshem 0.11 main Bevy Meshem is a Rust crate designed to provide meshing algorithms

Adam 4 Aug 16, 2023
Work-in-Progress NES / Famicon Image Editor & Map Creator

NESImg An extremely work-in-progress tool for making NES/Famicom-compatible images. When faced with the challenge of formatting artwork in a way that

Katharos Technology 10 Nov 24, 2022