# Getting 3D shapes without illumination

**URL:** <https://discourse.julialang.org/t/getting-3d-shapes-without-illumination/100091>\
**Category:** Visualization\
**Tags:** makie\
**Created:** [June 9, 2023, 10:06am UTC](https://discourse.julialang.org/t/getting-3d-shapes-without-illumination/100091 "2023-06-09T10:06:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![peremato](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peremato/32/29128_2.png) [@peremato](https://discourse.julialang.org/u/peremato)\
**Post date:** [June 9, 2023, 10:06am UTC](https://discourse.julialang.org/t/getting-3d-shapes-without-illumination/100091/1 "2023-06-09T10:06:48Z")

</div>

I am plotting with GLMakie my own 3D solids by defining `GeometryBasics.faces(...)` and `GeometryBasics.coordinates(...)` for each type. Then I plot the solids using a code like this:

```julia
   m = GeometryBasics.mesh(solid)
   points = GeometryBasics.coordinates(m)
   faces = GeometryBasics.faces(m)
   map!(c -> c * t, points, points) # apply some transformation to the points
   m = GeometryBasics.Mesh(points, faces) # remake a mesh with the moved points
   mesh!(s, m, color=color, transparency=true, visible=true)

```

It works but I get the 3D shapes without illumination. Like this:  
 ![Screen Shot 2023-06-09 at 11.47.42](https://global.discourse-cdn.com/julialang/original/3X/4/0/40b3be31bc7f97fdfe694214cad2403dc7871d66.png)

Does anybody know what I should do to get a more realistic display of my solids?

---

<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:** [June 9, 2023, 10:08am UTC](https://discourse.julialang.org/t/getting-3d-shapes-without-illumination/100091/2 "2023-06-09T10:08:44Z")

</div>

This happens when you have missing or inverted normals. I always forget what the command is to get them but that might help you google it 🙂

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [June 9, 2023, 10:18am UTC](https://discourse.julialang.org/t/getting-3d-shapes-without-illumination/100091/3 "2023-06-09T10:18:32Z")

</div>

This should work:

```julia
m = GeometryBasics.normal_mesh(solid)
points = GeometryBasics.coordinates(m)
faces = GeometryBasics.faces(m)
map!(c -> c * 0.1, points, points) # apply some transformation to the points
m = GeometryBasics.Mesh(meta(points; normals=normals(m), faces))

```

---

<div class="post-metadata">

**Author:** ![peremato](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peremato/32/29128_2.png) [@peremato](https://discourse.julialang.org/u/peremato)\
**Post date:** [June 9, 2023, 2:16pm UTC](https://discourse.julialang.org/t/getting-3d-shapes-without-illumination/100091/4 "2023-06-09T14:16:22Z")

</div>

Thanks, but it does not work. Perhaps I am missing something else.  
I am not able to construct a `normal_mesh` with my shapes, and therefore the `normals(m)` returns `nothing`.  
I was able to construct a `mesh` because I had the following functions defined I guess:

```julia
    function GeometryBasics.Tesselation(s::G4VSolid, nvertices::NTuple{N,<:Integer}) where N
        return Tesselation{3,Float64,typeof(s),N}(s, Int.(nvertices))
    end
    GeometryBasics.mesh(s::G4VSolid) = GeometryBasics.mesh(Tesselation(s, 64), facetype=typeof(first(GeometryBasics.faces(s))))

```

How can I do the equivalent for `normal_mesh`? BTW, I do not find any documentation on `normal_mesh`.

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [June 9, 2023, 2:25pm UTC](https://discourse.julialang.org/t/getting-3d-shapes-without-illumination/100091/5 "2023-06-09T14:25:39Z")

</div>

I see…

That’s not really what you should overload - sorry, this is badly documented, and don’t have time right now to document it 😉 Have to look at e.g. Sphere to see what to overload.

Anyways, the easiest solution to get things working is to just do this:

```julia
m = GeometryBasics.Mesh(meta(points; normals=normals(points, faces), faces))

```

---

<div class="post-metadata">

**Author:** ![peremato](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peremato/32/29128_2.png) [@peremato](https://discourse.julialang.org/u/peremato)\
**Post date:** [June 9, 2023, 2:45pm UTC](https://discourse.julialang.org/t/getting-3d-shapes-without-illumination/100091/6 "2023-06-09T14:45:28Z")

</div>

Thanks very much. It works if I put the parenthesis in the right position

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

```

I will have a look at the Sphere.
