{"id":16711062,"url":"https://github.com/ianmackenzie/elm-3d-camera","last_synced_at":"2025-04-10T05:36:30.242Z","repository":{"id":57675116,"uuid":"86129917","full_name":"ianmackenzie/elm-3d-camera","owner":"ianmackenzie","description":"Camera type for doing 3D rendering in Elm","archived":false,"fork":false,"pushed_at":"2023-10-13T03:38:31.000Z","size":290,"stargazers_count":12,"open_issues_count":5,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-01T17:05:27.362Z","etag":null,"topics":["elm","matrix","opensolid","point","vector","webgl"],"latest_commit_sha":null,"homepage":"http://package.elm-lang.org/packages/ianmackenzie/elm-3d-camera/latest","language":"Elm","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ianmackenzie.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-03-25T03:36:03.000Z","updated_at":"2024-03-26T02:33:27.000Z","dependencies_parsed_at":"2024-10-12T20:10:46.117Z","dependency_job_id":"86626a93-e690-4520-ae11-1c1fbaa2c99a","html_url":"https://github.com/ianmackenzie/elm-3d-camera","commit_stats":{"total_commits":164,"total_committers":2,"mean_commits":82.0,"dds":"0.012195121951219523","last_synced_commit":"af6698c6c68fdf89678810f1f624de118d0947d3"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ianmackenzie%2Felm-3d-camera","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ianmackenzie%2Felm-3d-camera/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ianmackenzie%2Felm-3d-camera/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ianmackenzie%2Felm-3d-camera/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ianmackenzie","download_url":"https://codeload.github.com/ianmackenzie/elm-3d-camera/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248164473,"owners_count":21058152,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elm","matrix","opensolid","point","vector","webgl"],"created_at":"2024-10-12T20:10:39.728Z","updated_at":"2025-04-10T05:36:30.221Z","avatar_url":"https://github.com/ianmackenzie.png","language":"Elm","funding_links":[],"categories":[],"sub_categories":[],"readme":"## NOTE\n\n[`elm-3d-scene`](http://package.elm-lang.org/packages/ianmackenzie/elm-3d-scene/latest)\nhas not yet been updated to use `elm-3d-camera` 4.x, so in the meantime to avoid version conflicts\nyou'll likely want to install `elm-3d-scene` before `elm-3d-camera`, e.g.\n\n```\nelm install ianmackenzie/elm-3d-scene\nelm install ianmackenzie/elm-3d-camera\n```\n\nIf you do run into a problem, try manually adjusting the version of `elm-3d-camera` in `elm.json` to\n3.1.0 instead of 4.0.0.\n\n# elm-3d-camera\n\nThis package provides convenient ways to define and use perspective and\northographic cameras in 3D. It is based on [`elm-geometry`](http://package.elm-lang.org/packages/ianmackenzie/elm-geometry/latest)\nand is used heavily by [`elm-3d-scene`](http://package.elm-lang.org/packages/ianmackenzie/elm-3d-scene/latest).\nIt can also be used standalone to:\n\n  - Construct [WebGL](https://package.elm-lang.org/packages/elm-explorations/webgl/latest/)\n    model/view/projection matrices in a way that is more intuitive than using\n    [`elm-explorations/linear-algebra`](http://package.elm-lang.org/packages/elm-explorations/linear-algebra/latest)\n    directly\n  - Perform 3D-to-2D projection of various `elm-geometry` values (points, line segments, triangles).\n    This in turn allows you to do things like render simple 3D shapes by projecting them into 2D so\n    that they can be drawn with SVG instead of WebGL.\n    \n\n## Defining cameras\n\nThe functions in this package let you construct perspective or orthographic cameras in various\ndifferent ways, for example:\n\n```elm\nimport Angle\nimport Camera3d\nimport Length\nimport Point3d\n\nperspectiveCamera =\n    Camera3d.lookAt\n        { eyePoint = Point3d.meters 4 0 3\n        , focalPoint = Point3d.origin\n        , upDirection = Direction3d.positiveZ\n        , projection = Camera3d.Perspective\n        , fov = Camera3d.angle (Angle.degrees 30)\n        }\n```\n\nNote that there are no functions for transforming (translating, rotating etc.) cameras - cameras are\nintended to be 'throwaway' values that you would construct on the fly when doing some rendering. For\nexample, if in the above code you wanted to have an animated camera that tracked some moving object,\nyou might store the camera and object positions in your model as `Point3d` values but then recreate\nthe actual `Camera3d` value every frame.\n\n## WebGL rendering\n\nOnce you have a camera, you can use it to get WebGL view and projection\nmatrices:\n\n```elm\nimport WebGL.Matrices as WebGL\n\nviewMatrix =\n    WebGL.viewMatrix camera\n\nprojectionMatrix =\n    WebGL.projectionMatrix camera\n        { nearClipDepth = Length.meters 0.1\n        , farClipDepth = Length.meters 100\n        , aspectRatio = 16 / 9\n        }\n```\n\n## Projection to screen space\n\nYou can also use a `Camera3d` to project points, lines, and triangles from 3D to 2D. This allows you\nto, for example, do a perspective projection of 3D points and lines into 2D so that those points and\nlines can be rendered with SVG (taking advantage of SVG features like perfect circles and dashed\nlines which are difficult to do with WebGL):\n\n![Perspective projection](https://ianmackenzie.github.io/elm-3d-camera/1.0.0/projection.png)\n\nFirst, you must define the dimensions of the screen you want to project to; this should generally\nbe of the form\n\n```elm\nscreen =\n    Rectangle2d.from bottomLeftCorner topRightCorner\n```\n\nNote that if you want browser DOM coordinates directly, you'll probably want to use something like\n\n```elm\nscree =\n    Rectangle2d.from\n        (Point2d.pixels 0 clientHeight)\n        (Point2d.pixels clientWidth 0)\n```\n\nsince in HTML 0 is the top and positive Y is down. I personally generally prefer working in 2D\ncoordinate systems where positive Y is up (converting to DOM coordinates at the last possible\nmoment), so my code that projects from 3D to 2D looks like this:\n\n```elm\nimport Point3d.Projection as Point3d\nimport LineSegment3d.Projection as LineSegment3d\n\nscreen =\n    Rectangle2d.from Point2d.origin\n        (Point2d.pixels 800 600)\n\npoint2d =\n    point3d |\u003e Point3d.toScreenSpace camera screen\n\nlineSegment2d =\n    lineSegment3d\n        |\u003e LineSegment3d.toScreenSpace camera screen\n```\n\n(The [`Overlay.elm`](https://github.com/ianmackenzie/elm-3d-camera/blob/master/examples/Overlay.elm)\nexample uses an under-development `Drawing2d` module which works in a coordinate system where\npositive Y is up, converting to Y-down coordinates only when actually rendering to SVG internally.)\n\n## Roadmap\n\nA few more features are planned:\n\n  - More 3D-to-2D projections (directions, axes)\n  - Construction of 3D cut planes from 2D on-screen lines\n\n## Questions? Comments?\n\nPlease [open a new issue](https://github.com/ianmackenzie/elm-3d-camera/issues) if you\nrun into a bug, if any documentation is missing/incorrect/confusing, or if\nthere's a new feature that you would find useful. For general questions about\nusing `elm-3d-camera`, try:\n\n  - Joining the **#geometry** or **#webgl** channels on the [Elm Slack](http://elmlang.herokuapp.com/),\n    or sending me (**@ianmackenzie**) a message - even if you don't have any\n    particular questions right now, it would be great to know what you're hoping\n    to do with the package!  - Posting to the [Elm Discourse](https://discourse.elm-lang.org/) forums\n\nYou can also find me on Twitter ([@ianemackenzie](https://twitter.com/ianemackenzie)),\nwhere I occasionally post `elm-geometry`-related stuff like demos or new\nreleases. Have fun, and don't be afraid to ask for help!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fianmackenzie%2Felm-3d-camera","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fianmackenzie%2Felm-3d-camera","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fianmackenzie%2Felm-3d-camera/lists"}