Skip to content

A cross compiled Scala 3 library that provides accessible functionality to generate, manipulate, and export 3D mesh objects. Currently supports .PLY, and .OBJ/.MTL file formats.

License

Notifications You must be signed in to change notification settings

dragonfly-ai/mesh

Repository files navigation

mesh

   A cross compiled Scala 3 library that provides accessible functionality to generate, manipulate, and export triangular 3D mesh objects. Currently supports .PLY, and .OBJ/.MTL file formats.

sbt

libraryDependencies += "ai.dragonfly" %%% "mesh" % "<LATEST_VERSION>"

Features:

  • Fast, lightweight mesh generation for:
    • Plane
    • Cube
    • Cylinder
    • Drum
    • Threaded Bolt
    • Threaded Screw
  • Mesh file export to formats:
    • PLY
    • OBJ + MTL
  • Compiles to Scala JVM, Native, and JavaScript environments.

Examples:

// include these imports for all examples
import slash.vector.*
import slash.vector.Vec.*
import ai.dragonfly.mesh.shape.*

Plane

// Plane
Plane(
  Vec[3](0, 0, 1),  // first corner
  Vec[3](4, 0, 2),  // second corner
  Vec[3](0, 4, 3),  // third corner
  9,                // vertical segment count
  12                // horizontal segment count
)

Cube

Cube.minimal( 1.0 /* side length */ )  // minimal

Cube()  // default parameters

Cube(
  l = 1.0,         // side length
  n = 64,          // number of segments
  name = "Cube"    // mesh name
)

Cylinder

Cylinder() // default parameters

Cylinder(
  angularSegments = 36,
  sideSegments = 1,
  baseSegments = 1,
  capSegments = 1,
  radius = 1.0,
  height = 1.0
)

Drum

Drum() // default parameters

Drum(
  angularSegments = 12,
  sideSegments = 1,
  baseSegments = 1,
  capSegments = 1,
  baseRadius = 2.0,
  capRadius = 1.0,
  height = 1.0,
  name = "Drum"
)

Threaded Bolt

Bolt() // default parameters

Bolt(
  length = 10.0,
  threadsPerUnit = 3.0,
  threadThickness = 0.1,
  shankLength = 3.5,
  angularSegments = 12,
  threadRadius = 1.0,
  coreRadius = 0.85,
  name = "Bolt"
)

Threaded Screw

Screw() // default parameters

Screw(
  length = 7.0,
  threadsPerUnit = 2.0,
  threadThickness = 0.05,
  shankLength = 1.5,
  pointLength = 0.5,
  angularSegments = 12,
  threadRadius = 0.375,
  coreRadius = 0.25,
  name = "Screw"
)

Exporting to File Formats:

   The examples below demonstrate how to convert a mesh to a string that represents a PLY, MTL, or OBJ file, or how to write the mesh directly to an OutputStream.

PLY:

import ai.dragonfly.mesh.shape.*
import ai.dragonfly.mesh.io.PLY

val ply:String = PLY.fromMesh(  // generate a PLY file as a String
  Cube(),                       // a mesh
  vertexColorMapper = PLY.randomVertexColorMapper // a way to color the vertices.
)

val os:java.io.OutputStream = ...

PLY.writeMesh(     // write directly to an output Stream
  mesh = Cube(),   // a mesh
  out = os,        // an output stream
  vertexColorMapper = PLY.randomVertexColorMapper // a way to color the vertices.
)

MTL:

import ai.dragonfly.mesh.io.MTL

val material = MTL(
  name,
  diffuse,
  ambient = gray,
  specular = Specular(),
  dissolve = 1f
)

val mtl:String = material.mtl   // generate an MTL file as a String


val os:java.io.OutputStream = ...

MTL.writeMTL(material, os)      // write directly to an output Stream

OBJ:

import ai.dragonfly.mesh.shape.*
import ai.dragonfly.mesh.io.OBJ

val cube:Mesh = Cube()

val obj:String = OBJ.fromMesh(  // generate an OBJ file as a String
  mesh = cube,
  name = cube.name,
  comment = "cube",
  materialLibraryFile = "default.MTL",
  material = material,
  smooth = true
)

val os:java.io.OutputStream = ...

OBJ.writeMesh(   // write directly to an output Stream
  mesh = cube,
  out = os,
  name = cube.name,
  comment = "cube",
  materialLibraryFileName = "default.MTL",
  material = material
)

About

A cross compiled Scala 3 library that provides accessible functionality to generate, manipulate, and export 3D mesh objects. Currently supports .PLY, and .OBJ/.MTL file formats.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages