项目作者: ianmackenzie

项目描述 :
Generic indexed triangular mesh data structure for Elm
高级语言: Elm
项目地址: git://github.com/ianmackenzie/elm-triangular-mesh.git
创建时间: 2017-08-07T14:15:28Z
项目社区:https://github.com/ianmackenzie/elm-triangular-mesh

开源协议:Mozilla Public License 2.0

下载


elm-triangular-mesh

This Elm package allows you to create and manipulate
indexed triangular meshes. A mesh contains an array of vertices which contain
the bulk of the mesh data; vertices can be of any type, so you can create meshes
from 2D or 3D points or have complex vertices of your own custom type that
include additional data such as colors, normal vectors, texture coordinates,
unique IDs, etc.

Mesh faces are defined by triples of integer indices specifying which three
vertices make up the face. This package has functionality for creating meshes in
various ways, extracting faces as index triples or vertex triples, extracting
edges as index pairs or vertex pairs, and combining multiple meshes.

For example, you might create a 2D mesh representing a single rectangle as:

  1. import TriangularMesh exposing (TriangularMesh)
  2. import Array
  3. mesh : TriangularMesh ( Float, Float )
  4. mesh =
  5. let
  6. vertices =
  7. Array.fromList
  8. [ ( 0, 0 )
  9. , ( 4, 0 )
  10. , ( 4, 3 )
  11. , ( 0, 3 )
  12. ]
  13. faceIndices =
  14. [ ( 0, 1, 2 )
  15. , ( 2, 3, 0 )
  16. ]
  17. in
  18. TriangularMesh.indexed vertices faceIndices

You could then do things like get the faces or edges of that mesh as tuples of
vertices:

  1. TriangularMesh.faceVertices mesh
  2. --> [ ( ( 0, 0 ), ( 4, 0 ), ( 4, 3 ) )
  3. --> , ( ( 4, 3 ), ( 0, 3 ), ( 0, 0 ) )
  4. --> ]
  5. TriangularMesh.edgeVertices mesh
  6. --> [ ( ( 0, 0 ), ( 4, 0 ) )
  7. --> , ( ( 0, 0 ), ( 4, 3 ) )
  8. --> , ( ( 0, 0 ), ( 0, 3 ) )
  9. --> , ( ( 4, 0 ), ( 4, 3 ) )
  10. --> , ( ( 4, 3 ), ( 0, 3 ) )
  11. --> ]

Documentation

Full API documentation
is available.

Questions? Comments?

Please open a new issue if you run
into a bug, if any documentation is missing/incorrect/confusing, or if there’s a
new feature that you would find useful. For general questions about using this
package, try:

You can also find me on Twitter (@ianemackenzie),
where I occasionally post geometry-related stuff like demos or new package
releases. Have fun, and don’t be afraid to ask for help!