How to plot a 3D contour surface with Makie

Suppose I want to plot the solution to the equation -x^3+r*x+h=0 in 3D, with r and h on the X-Y plane, and x as the z-axis to demonstrate the cusp catastrophe in bifurcation. In Mathematica, I have something like this:

What would be the best way to make this 3D plot in Makie? It looks like surface requires x as a function of r and h, but the surface plot has regions with multiple ‘layers’, whereas contour3d plots lines if I’m not mistaken.

I don’t think this is entirely possible with Makie currently, but there is similar functionality for plotting isoregions that are close to what you want, see the documentation here: volume · Makie.

For your example, it would be something like

using GLMakie
f(r,h,x) = -x^3+r*x+h
var_range = range( -3 , 3 ; length = 100 )
F = [ f(r,h,x) for r in var_range, h in var_range, x in var_range ]

fig = Figure()
ax = Axis3( fig[1,1] , xlabel = "r" , ylabel = "h" , zlabel = "x" )
volume!( ax , var_range , var_range , var_range , F ; algorithm = :iso, isorange = 0.05, isovalue = 0.0 )
fig

The isovalueis the RHS of your equation (here, 0), and the isorange is a range of values close to the isovalue that will be included in the volume plot.

Edit: Using some other packages, there are ways of doing this:

using GeometryBasics
using MarchingCubes
using GLMakie

f(r,h,x) = -x^3+r*x+h
var_range = range( -3 , 3 ; length = 100 )
s = collect( var_range )

mcd = MC( F ; x = s , y = s , z = s )
march(mcd)
msh = MarchingCubes.makemesh(GeometryBasics, mcd)

fig = Figure()
ax = Axis3( fig[1,1] , xlabel = "r" , ylabel = "h" , zlabel = "x" )
mesh!( ax , msh ; color = :orange )
fig 

You might need to work on the shading, but something like this gets you the basic shape:

using GLMakie
F(h,r,x) = h + r*x - x^3
xs = ys = zs = range(-3, 3, length=100)
contour(xs, ys, zs, F, levels=[0])