# Best way to import Sage 3D functions to cubes in Unity3D?

Hello everyone. I'm having a bit of trouble figuring out how to take a 3D function, say something like:

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

and have it translated and rendered inside of a transparent cube in Unity3D.

Is there a way to do this? If so, how? I have done some investigation by myself and I know that there is a Python interpreter asset for Unity but would Sage be able to run off of the interpreter?

I'm just very confused.

edit retag close merge delete

Sort by » oldest newest most voted Did you look at the doc of save ?

sage: var('x,y,z')
sage: P=implicit_plot3d(sqrt(3*x^2+y^2)-z, (x, -30, 30), (y, -30,30), (z, -10,40))
sage: P.save?


This offers several formats, such as .x3d that could be possible inputs for other 3d software.

more

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))
p.json_repr(p.default_render_params())


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')
f.write(str(p.json_repr(p.default_render_params())))
f.close()


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.

more