https://github.com/dragonfly-ai/mesh
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.
https://github.com/dragonfly-ai/mesh
3d-mesh 3d-mesh-generation 3d-mesh-models 3d-models bolt cube cylinder drum jvm mtl obj ply scala-3 scala-js scala-native scalajs screw
Last synced: about 1 month ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/dragonfly-ai/mesh
- Owner: dragonfly-ai
- License: apache-2.0
- Created: 2022-12-14T02:18:33.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2026-04-11T00:12:31.000Z (about 1 month ago)
- Last Synced: 2026-04-11T02:20:09.652Z (about 1 month ago)
- Topics: 3d-mesh, 3d-mesh-generation, 3d-mesh-models, 3d-models, bolt, cube, cylinder, drum, jvm, mtl, obj, ply, scala-3, scala-js, scala-native, scalajs, screw
- Language: Scala
- Homepage:
- Size: 1.21 MB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# 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
```scala
libraryDependencies += "ai.dragonfly" %%% "mesh" % ""
```
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:
```scala
// include these imports for all examples
import slash.vector.*
import slash.vector.Vec.*
import ai.dragonfly.mesh.shape.*
```
Plane
```scala
// 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
```scala
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
```scala
Cylinder() // default parameters
Cylinder(
angularSegments = 36,
sideSegments = 1,
baseSegments = 1,
capSegments = 1,
radius = 1.0,
height = 1.0
)
```
Drum
```scala
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
```scala
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
```scala
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:
```scala
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:
```scala
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:
```scala
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
)
```