# What is the 3D plotter package closest to the rgl R package?

**URL:** <https://discourse.julialang.org/t/what-is-the-3d-plotter-package-closest-to-the-rgl-r-package/79816>\
**Category:** Visualization\
**Tags:** package, glmakie\
**Created:** [April 22, 2022, 8:04am UTC](https://discourse.julialang.org/t/what-is-the-3d-plotter-package-closest-to-the-rgl-r-package/79816 "2022-04-22T08:04:38Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_stla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/_stla/32/35613_2.png) [@\_stla](https://discourse.julialang.org/u/_stla)\
**Post date:** [April 22, 2022, 8:04am UTC](https://discourse.julialang.org/t/what-is-the-3d-plotter-package-closest-to-the-rgl-r-package/79816/1 "2022-04-22T08:04:38Z")

</div>

Hello,

I took a look at the available 3D plotter package in Julia but at first glance they look complicated to me (maybe I mislooked). I’m looking for a package similar to the rgl R package, that is, you just have to enter the vertices coordinates and the indices of the triangle vertices. Is there such a package in Julia? I’m also comfortable with the Pyvista Python package.

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [April 22, 2022, 10:59am UTC](https://discourse.julialang.org/t/what-is-the-3d-plotter-package-closest-to-the-rgl-r-package/79816/2 "2022-04-22T10:59:34Z")

</div>

isn’t that just GLMakie? with some extra steps if you want with [GeometryBasics.jl · GeometryBasics.jl](https://juliageometry.github.io/GeometryBasics.jl/dev/) (not needed for basics stuff)

[https://juliadatascience.io/glmakie](https://juliadatascience.io/glmakie)

some extra geometry examples can be found here: [https://github.com/lazarusA/100daysOfMakie#21-meshes](https://github.com/lazarusA/100daysOfMakie#21-meshes)

---

<div class="post-metadata">

**Author:** ![\_stla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/_stla/32/35613_2.png) [@\_stla](https://discourse.julialang.org/u/_stla)\
**Post date:** [April 23, 2022, 8:47am UTC](https://discourse.julialang.org/t/what-is-the-3d-plotter-package-closest-to-the-rgl-r-package/79816/3 "2022-04-23T08:47:48Z")

</div>

Sorry but I understand nothing to the docs. Can someone show me a basic example, e.g. a tetrahedron or a cube?

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [April 23, 2022, 12:44pm UTC](https://discourse.julialang.org/t/what-is-the-3d-plotter-package-closest-to-the-rgl-r-package/79816/4 "2022-04-23T12:44:05Z")

</div>

A cube:

```julia
using GLMakie
mesh(Rect3f(Vec3f(-0.5), Vec3f(1)); color = :red)

```

 ![Screenshot 2022-04-23 at 14.42.35](https://global.discourse-cdn.com/julialang/original/3X/d/0/d09c3a5b60ea5383bc58fc5c3dfcd5072901f250.png)

of course you need to [install](https://github.com/JuliaPlots/Makie.jl#installation) GLMakie first.

Also, a pyramid

```julia
using GLMakie, GeometryBasics
mesh(Pyramid(Point3f(0), 1.0f0, 1.0f0); color = :gold, transparency =true)
wireframe!(Pyramid(Point3f(0), 1.0f0, 1.0f0); color=:black, 
    linewidth = 2, transparency = true)
current_figure()

```

 ![Screenshot 2022-04-23 at 14.49.06](https://global.discourse-cdn.com/julialang/original/3X/6/9/6907ce44b1f916e3119e8b4343896f0bdf58d126.png)

---

<div class="post-metadata">

**Author:** ![\_stla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/_stla/32/35613_2.png) [@\_stla](https://discourse.julialang.org/u/_stla)\
**Post date:** [June 22, 2022, 7:44am UTC](https://discourse.julialang.org/t/what-is-the-3d-plotter-package-closest-to-the-rgl-r-package/79816/5 "2022-06-22T07:44:09Z")

</div>

Thanks, and sorry for the late reply.

Here you use built-in functions Pyramid and Rect3f. Is it not possible to simply enter the vertices and the faces (given by vertex indices)?

---

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [June 22, 2022, 10:09am UTC](https://discourse.julialang.org/t/what-is-the-3d-plotter-package-closest-to-the-rgl-r-package/79816/6 "2022-06-22T10:09:12Z")

</div>

It is possible to provide the mesh vertices and faces, but I think the interface only supports triangular faces at the moment [mesh](https://makie.juliaplots.org/v0.15/examples/plotting_functions/mesh/index.html).  
See this issue for additional info [`mesh` fails on quadrilateral mesh · Issue #1677 · JuliaPlots/Makie.jl · GitHub](https://github.com/JuliaPlots/Makie.jl/issues/1677)

---

<div class="post-metadata">

**Author:** ![\_stla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/_stla/32/35613_2.png) [@\_stla](https://discourse.julialang.org/u/_stla)\
**Post date:** [July 4, 2022, 3:54pm UTC](https://discourse.julialang.org/t/what-is-the-3d-plotter-package-closest-to-the-rgl-r-package/79816/7 "2022-07-04T15:54:12Z")

</div>

Thank you. There’s an example. Looks like one cannot specify the per-vertex normals.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [July 4, 2022, 8:08pm UTC](https://discourse.julialang.org/t/what-is-the-3d-plotter-package-closest-to-the-rgl-r-package/79816/8 "2022-07-04T20:08:04Z")

</div>

Wouldn’t this fit your needs, especially this line suggests to me that per-point normals are being passed in:

```julia
gb_mesh = GeometryBasics.Mesh(meta(points; uv=uv_buff, normals), faces)

```

[https://makie.juliaplots.org/stable/examples/plotting\_functions/mesh/#using\_geometrybasicsmesh\_and\_buffersampler\_type](https://makie.juliaplots.org/stable/examples/plotting_functions/mesh/#using_geometrybasicsmesh_and_buffersampler_type)

---

<div class="post-metadata">

**Author:** ![\_stla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/_stla/32/35613_2.png) [@\_stla](https://discourse.julialang.org/u/_stla)\
**Post date:** [December 5, 2022, 9:58pm UTC](https://discourse.julialang.org/t/what-is-the-3d-plotter-package-closest-to-the-rgl-r-package/79816/9 "2022-12-05T21:58:26Z")

</div>

The code below plots a mesh defined by vertices and faces. Is there a way to have automatic normals? By “automatic normals” I mean for example the per-vertex normals obtained by averaging the normals of the incident faces of the vertices.

```julia
using GLMakie

function HopfTorusMeshHelper(u, cos_v, sin_v, nlobes, A)
    B = pi/2 - (pi/2 - A)*cos(u*nlobes)
    C = u + A*sin(2*u*nlobes)
    y1 = 1 + cos(B)
    y23 = sin(B) .* [cos(C), sin(C)]
    y2 = y23[1]
    y3 = y23[2]
    x1 = y3 .* cos_v + y2 .* sin_v
    x2 = y2 .* cos_v - y3 .* sin_v
    x3 = y1 .* sin_v
    x4 = y1 .* cos_v
    yden = sqrt(2*y1)
    return vcat(x1 ./ (yden .- x4), x2 ./ (yden .- x4), x3 ./ (yden .- x4)) 
end

function HopfTorusMesh(nu, nv; nlobes = 3, A = 0.44)
  vs = Array{Float64}(undef, nu*nv, 3)
  tris1 = Array{Int64}(undef, nu*nv, 3)
  tris2 = Array{Int64}(undef, nu*nv, 3)
  u_ = range(0, stop = 2*pi, length = nu+1)[2:(nu+1)]
  v_ = range(0, stop = 2*pi, length = nv+1)[2:(nv+1)]
  cos_v = cos.(v_)
  sin_v = sin.(v_)
  jp1_ = [(2:nv)..., 1]
  j_ = [(1:nv)...]
  for i in 1:(nu-1)
    i_nv = i*nv
    vs[(i_nv - nv + 1):i_nv, :] =
      HopfTorusMeshHelper(u_[i], cos_v, sin_v, nlobes, A)
    k1 = i_nv - nv
    k_ = k1 .+ j_
    l_ = k1 .+ jp1_
    m_ = i_nv .+ j_
    tris1[k_, :] = hcat(k_, l_, m_)
    tris2[k_, :] = hcat(l_, i_nv .+ jp1_, m_)
  end
  i_nv = nu*nv
  vs[(i_nv - nv + 1):i_nv, :] =
    HopfTorusMeshHelper(2*pi, cos_v, sin_v, nlobes, A)
  k1 = i_nv - nv
  k_ = k1 .+ j_
  l_ = k1 .+ jp1_
  tris1[k_, :] = hcat(k_, l_, j_)
  tris2[k_, :] = hcat(l_, jp1_, j_)
  return (vertices = vs, faces = vcat(tris1, tris2))
end

ht = HopfTorusMesh(200, 200)
mesh(ht.vertices, ht.faces)

```

---

<div class="post-metadata">

**Author:** ![\_stla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/_stla/32/35613_2.png) [@\_stla](https://discourse.julialang.org/u/_stla)\
**Post date:** [December 5, 2022, 10:32pm UTC](https://discourse.julialang.org/t/what-is-the-3d-plotter-package-closest-to-the-rgl-r-package/79816/10 "2022-12-05T22:32:15Z")

</div>

I think I found:

```julia
using GeometryBasics
vertices = map(Point3f, eachrow(ht.vertices))
faces = map(TriangleFace, eachrow(ht.faces))
nrmls = normals(vertices, faces)
gb_mesh = GeometryBasics.Mesh(meta(vertices; normals = nrmls), faces)

mesh(gb_mesh, color = "green")

```

But I don’t see any difference regarding the smoothness. It seems that Makie automatically adds the normals.
