Skip to content

EliCDavis/polyform

Repository files navigation

Polyform Banner Coverage Go Report Card CITATION.cff

Polyform is for loading, generating, editing, and exporting 3D geometry and it's associated data.

Overview

  • Formats
    • gltf - GLTF file format
    • obj - OBJ file format
    • ply - PLY file format
    • stl - STL file format
    • colmap - Utilities for loading COLMAP reconstruction data
    • opensfm - Utilities for loading OpenSFM reconstruction data
    • splat - Guassian splatting's SPLAT format
    • potree - Potree V2 file format
  • Modeling
    • meshops - All currently implemented algorithms for transforming meshes.
    • marching - Multi-threaded Cube Marching algorithm and utilities.
    • extrude - Functionality for generating geometry from 2D shapes.
    • repeat - Functionality for copying geometry in common patterns.
    • primitives - Functionality pertaining to generating common geometry.
    • triangulation - Generating meshes from a set of 2D points.
  • Drawing
    • coloring - Color utilities for blending multiple colors together using weights.
    • texturing - Traditional image processing utilities (common convolution kernels).
      • normals - Utilities for generating and editing normal maps.
  • Math
    • colors - Making working with golang colors not suck as much.
    • curves - Common curves used in animation like cubic bezier curves.
    • geometry - AABB, Line2D, Line3D, Plane, and Rays.
    • noise - Utilities around noise functions for common usecases like stacking multiple samples of perlin noise from different frequencies.
    • quaternion - Quaternion math and helper functions
    • sample - Serves as a group of definitions for defining a mapping from one numeric value to another
    • sdf - SDF implementations of different geometry primitives, along with common math functions. Basically slowly picking through Inigo Quilez's Distfunction article as I need them in my different projects.
  • Generator - Application scaffolding for editing and creating meshes
  • Trees - Implementation of common spatial partitioning trees.

Packages that have spawned from polyform's undertaking and have since been refactored into their own repositories:

  • Node Flow - Another Flow-based Node Graph Library
  • vector - Immutable vector math library
  • jbtf - GLTF-inspired JSON schema for embedding arbitrary binaries
  • iter - Iterator and utilities. Some inspiration from ReactiveX
  • quill - Scheduler of operations on in-memory data
  • sfm - Utilities for interacting with reconstruction data from different SFM programs
  • bitlib - Utilities for reading and writing binary data

Procedural Generation Examples

You can at the different projects under the examples folder for different examples on how to procedurally generate meshes.

Evergreen Trees

This was my submission for ProcJam 2022. Pretty much uses every bit of functionality available in this repository.

[Source Here]

Evergreen Tree Demo

Evergreen Terrain Demo

Other Examples

[Source Here] ufo [Source Here] candle
[Source Here] terrain [Source Here] terrain
[Source Here] plumbob [Source Here] oreo

Developing

If you so happen to want to build a configurator example, my preferred workflow is:

Set up the example to use the generator package that allows you to quickly spin up a web viewer to visualize the geoemetry of your program.

Use air to live reload the examples as you build them out. Set cmd = "go build -o ./tmp/main.exe ./examples/MY_EXAMPLE". Set include_ext = ["go", "tpl", "tmpl", "html", "js"].

air edit --port 8080

As you hit save on your go code, the webserver will restart, and the web page will automatically refresh itself.

If you want to mess with modern web browser features and need https, I recommend taking a look at https://github.com/FiloSottile/mkcert

mkcert -install
mkcert -key-file key.pem -cert-file cert.pem localhost
air edit --port 8080 --ssl

# And if you want to connect with your headset
air edit --port 8080 --ssl --host 0.0.0.0

WASM Dev

Install tinygo and binaryren

Compile the polywasm app

go install ./cmd/polywasm

Then build your example app

polywasm build --app-path ./examples/MY_EXAMPLE

Processing Example

Reads in a obj and applies the cube marching algorithm over the meshes 3D SDF.

package main

import (
  "github.com/EliCDavis/polyform/formats/obj"
  "github.com/EliCDavis/polyform/modeling"
  "github.com/EliCDavis/polyform/modeling/marching"
  "github.com/EliCDavis/polyform/modeling/meshops"
  "github.com/EliCDavis/vector"
)

func main() {
  loadedMesh, _ := obj.Load("test-models/stanford-bunny.obj")

  resolution := 10.
  scale := 12.

  transformedMesh := loadedMesh.Transform(
    meshops.Center3DTransformer{},
    meshops.Scale3DTransformer{Amount: vector3.Fill(scale)},
  )

  canvas := marching.NewMarchingCanvas(resolution)
  meshSDF := marching.Mesh(transformedMesh, .1, 10)
  canvas.AddFieldParallel(meshSDF)
  
  obj.Save("chunky-bunny.obj", canvas.MarchParallel(.3))
}

Results in:

Chunky Bunny

Todo List

Progress towards V1...

  • Finalize Material Definition (or remove and defer to file format specifications)
  • Finalize Node error propogation flow
  • Cleanup Node interface
  • Finalize package organization for node equivalent functionality (ie vector3 => vecn3)
  • Proper WASM Deployment

Things I want to implement eventually...

  • Cube Marching
  • Bezier Curves
  • Slice By Plane
  • Slice By Bounding Box
  • Constrained Delaunay Tesselation
  • Meshing Pipeline
  • Bones / Animations
  • Quadric Error Decimation
  • Proper Build Pipeline
  • Documentation Website
  • Primitive Meshes
    • Cube
    • Sphere
      • UV
      • Ico
      • Quad
    • Cylinder
    • Quad
    • Circle
    • Cone
    • Capsule
    • Hemisphere
    • Rounded Cube
  • SDFs
    • Box
    • Line
    • Plane
    • Sphere
    • Rounded Cylinder
    • Rounded Box
    • Torus
    • Box Frame
    • Cone
    • Rounded Cone
    • Elipsoid
    • Triangle
  • 3D Tesselation
  • Slice By Octree
  • Poisson Reconstruction
  • Buncha texture patterns
  • Noise...
    • Simplex
  • Splines...
    • Catmull
    • B Spline

Resources

Resources either directly contributing to the code, or are just interesting finds while researching.

Web Libraries

Libraries the Webviewer depends on in some capacity

Citiation

If Polyform contributes to an academic publication, cite it as:

@misc{polyform,
  title = {Polyform},
  author = {Eli Davis},
  note = {https://www.github.com/EliCDavis/polyform},
  year = {2024}
}