{"id":20667890,"url":"https://github.com/statnmap/mesh2ray","last_synced_at":"2026-04-17T23:35:22.586Z","repository":{"id":117563092,"uuid":"180578530","full_name":"statnmap/mesh2ray","owner":"statnmap","description":"Transform mesh3d to ray* objects","archived":false,"fork":false,"pushed_at":"2019-07-24T21:51:52.000Z","size":1242,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-17T15:59:30.379Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/statnmap.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2019-04-10T12:37:30.000Z","updated_at":"2020-11-12T18:05:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"02d2d1a1-cc25-4422-aff8-335cbedb97c2","html_url":"https://github.com/statnmap/mesh2ray","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/statnmap/mesh2ray","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statnmap%2Fmesh2ray","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statnmap%2Fmesh2ray/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statnmap%2Fmesh2ray/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statnmap%2Fmesh2ray/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/statnmap","download_url":"https://codeload.github.com/statnmap/mesh2ray/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statnmap%2Fmesh2ray/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31950591,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-17T17:29:20.459Z","status":"ssl_error","status_checked_at":"2026-04-17T17:28:47.801Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2024-11-16T19:45:28.577Z","updated_at":"2026-04-17T23:35:22.555Z","avatar_url":"https://github.com/statnmap.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r setup, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"reference/figures/README-\",\n  out.width = \"100%\"\n)\n```\n[![Travis build status](https://travis-ci.org/statnmap/mesh2ray.svg?branch=master)](https://travis-ci.org/statnmap/mesh2ray)\n\n# mesh2ray\n\nThe goal of mesh2ray is to transform mesh3d to objects that can be used with ['rayshader'](https://github.com/tylermorganwall/rayshader) or ['rayrender'](https://github.com/tylermorganwall/rayrender).\n\nThe corresponding blog post is [Play with mesh3d, rayshader and rayrender](https://statnmap.com/2019-04-02-mesh3d-rayshader-and-rayrender/).  \n\n## Installation\n\nYou can install the released version of {mesh2ray} from Github\n\n``` r\n#install.packages(\"remotes\")\nremotes::install_github(\"statnmap/mesh2ray\")\n```\n\n## Play with mesh3d and ray's\n\n```{r example}\nlibrary(mesh2ray)\nlibrary(raster)\nlibrary(Rvcg)\nlibrary(magick)\nextraWD \u003c- \"reference/figures\"\n```\n\n## Transfrom mesh3d to raster and then {rayshader}\n\n```{r rayshader, eval=FALSE}\n# Create simple mesh\nsimple_mesh_orig \u003c- Rvcg::vcgIcosahedron()\n\n# 1. Cut it with a plane with {Morpho}\nv1 \u003c- c(0, 0, -0.5)\nv2 \u003c- c(1, 0, -0.5)\nv3 \u003c- c(0, 1, -0.5)\nsimple_mesh \u003c- Morpho::cutMeshPlane(simple_mesh_orig, v1, v2, v3)\n\n# _plot3d\nplot3d(simple_mesh, col = \"cyan\")\naspect3d(1, 1, 0.2)\nplot3d(simple_mesh, type = \"wire\", add = TRUE)\nplot3d(t(simple_mesh$vb), type = \"s\", radius = 0.1, add = TRUE)\nview3d(theta = 20, phi = -40, zoom = 0.5, fov = 80)\n# _snapshot\nrgl.snapshot(filename = file.path(extraWD, \"rayshader-simple-1-mesh.png\"))\nrgl::rgl.close()\n\n# 2. Project on raster\nsimple_r \u003c- mesh2ray::mesh_to_raster(simple_mesh, res = 26)\npng(filename = file.path(extraWD, \"rayshader-simple-2-raster.png\"))\nplot(simple_r)\ndev.off()\n\n# 3. raster to matrix\nsimple_ray \u003c- mesh2ray::stack_to_ray(simple_r)\n\n# 4. Rayshade matrix\nzscale \u003c- 0.4\nambmat \u003c- ambient_shade(simple_ray$elevation, zscale = zscale)\nraymat \u003c- ray_shade(simple_ray$elevation, zscale = zscale, lambert = TRUE,\n                    sunangle = 300)\n\nray_image \u003c- simple_ray$elevation %\u003e%\n  sphere_shade(texture = \"unicorn\") %\u003e%\n  add_shadow(raymat, max_darken = 0.1) %\u003e%\n  add_shadow(ambmat, max_darken = 0.5)\n\n# _plot 3d\nray_image %\u003e% \n  plot_3d(simple_ray$elevation, zscale = zscale, windowsize = c(1000, 1000),\n          soliddepth = -max(simple_ray$elevation, na.rm = TRUE)/zscale,\n          theta = -30, phi = 50, zoom = 0.7, fov = 20\n  )\n\n# _snapshot\nrgl.snapshot(filename = file.path(extraWD, \"rayshader-simple-3-ray3d.png\"))\nrgl::rgl.close()\n\n```\n\n```{r steprayshader, echo=FALSE}\n# Image montage\nimg_frames \u003c- list.files(extraWD, pattern = \"rayshader-simple\", full.names = TRUE)\nimage_append(image_scale(image_read(img_frames), \"400\"))\n```\n\n\n## Transfrom mesh3d to regular mesh then {rayrender}\n```{r rayrender, eval=FALSE}\n# Create simple mesh\nsimple_mesh \u003c- Rvcg::vcgIcosahedron()\n\n# _plot3d\nplot3d(simple_mesh, col = \"cyan\")\naspect3d(\"iso\")\nplot3d(simple_mesh, type = \"wire\", add = TRUE)\nplot3d(t(simple_mesh$vb), type = \"s\", radius = 0.1, add = TRUE)\nview3d(theta = 0, phi = 10, zoom = 0.6, fov = 80)\n# _snapshot\nrgl.snapshot(filename = file.path(extraWD, \"rayrender-simple-1-mesh.png\"))\nrgl::rgl.close()\n\n# 1. Uniformely resample mesh\n# _vcgUniformRemesh is included in mesh_to_cubes()\nsimple_resample \u003c- vcgUniformRemesh(simple_mesh, voxelSize = 0.5, multiSample = TRUE,\n                                discretize = TRUE)\n\nplot3d(simple_resample, col = \"cyan\")\naspect3d(\"iso\")\nplot3d(simple_resample, type = \"wire\", add = TRUE)\nplot3d(t(simple_resample$vb), type = \"s\", radius = 0.1, add = TRUE)\nview3d(theta = 0, phi = 10, zoom = 0.6, fov = 80)\n# _snapshot\nrgl.snapshot(filename = file.path(extraWD, \"rayrender-simple-2-regularmesh.png\"))\nrgl::rgl.close()\n\n# 2. Calculate cube positions in a specific scene\n# _vcgUniformRemesh is included in mesh_to_cubes()\nsimple_cubes \u003c- mesh2ray::mesh_to_cubes(simple_mesh, voxelSize = 0.5, scene_dim = c(80, 475))\n\n# 3. Draw with rayrender\n# _scene\nscene \u003c- generate_cornell(lightintensity = 10)\n# _add cubes on scene\nscene \u003c- mesh2ray::add_cubes_to_scene(scene, cubes = simple_cubes, \n                                      material = dielectric(color = \"green\"))\n# _draw scene /!\\ long calculation /!\\\nif (!file.exists(file.path(extraWD, \"rayrender-simple-3-scene.png\"))) {\n  options(cores = 4)\n  render_scene(scene, lookfrom = c(278, 278, -800) ,\n               lookat = c(278, 278, 0), fov = 40, ambient_light = FALSE,\n               samples = 500, parallel = TRUE, clamp_value = 5,\n               filename =  file.path(extraWD, \"rayrender-simple-3-scene.png\"))\n}\n\n```\n```{r steprayrender, echo=FALSE}\n# Image montage\nimg_frames \u003c- list.files(extraWD, pattern = \"rayrender-simple\", full.names = TRUE)\nimage_append(image_scale(image_read(img_frames), \"400\"))\n```\n\n\nThis package comes with a {pkgdown} documentation: https://statnmap.github.io/mesh2ray/\n\n\nPlease note that the 'mesh2ray' project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By contributing to this project, you agree to abide by its terms.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatnmap%2Fmesh2ray","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstatnmap%2Fmesh2ray","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatnmap%2Fmesh2ray/lists"}