Code Monkey home page Code Monkey logo

mesh's Introduction

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
)

mesh's People

Contributors

dragonfly-ai avatar scala-steward avatar

Watchers

 avatar  avatar  avatar

Forkers

scala-steward

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.