Ask Your Question

Revision history [back]

If you're looking for a WebGL-oriented approach, then use the json_repr of a 3D surface. This code

var('x y z')
p = implicit_plot3d(sqrt(3*x^2+y^2)-z, (x, -30, 30), (y, -30,30), (z, -10,40))

returns an array of vertices, faces and color as can be seen in this live example. The array can be saved to file using Python

f = open('data.json', 'w')

and imported into Unity. This will work for any surface composed of faces, but not for 3D lines and points.

One catch is that by default Sage returns quadrilateral faces instead of triangles. If Unity can't import quadrilateral faces you'll need to split the quads into triangles beforehand. That's pretty straightforward in either Python or JavaScript.