3
$\begingroup$

I would like to know if there is any way to use the "Add 3d Function Surface" addon via the python interface.

I have an equation that describes a surface in the three-dimensional space that I can use to make a mesh object as described in this answer. What I would like to know is if there is any way to do such a thing via the python interface.

As an example, I would like to be able to do something like:

def mysurface(u, v):
   return numpy.array([u*v, u-v, math.pow(u, 2)])

add_mesh_from_surface_equation(func = mysurface, urange = [0, 10], vrange = [0, 10], ustep = 0.01, vstep = 0.01)

Is it possible to do something like this?

$\endgroup$
  • $\begingroup$ The question you linked to creates a surface described by equations, yet your example code is making a surface based off a numpy array. Which are you trying to do? If you have actual equations, it should be very simple to call the functions used by the add3d surface function. $\endgroup$ – user2699 Oct 2 '14 at 18:49
  • $\begingroup$ As far as I understood from the question that I linked (and from using that addon) it is capable of making a 3D mesh out of a function that parametrizes a surface with a map from R^2 to R^3, i.e., (u, v) -> (x, y, z). You then specify some range and step and the mesh is built. mysurface(u, v) was intended to be that kind of function, mapping 2 values in 3. I just added numpy.array to make it clear it was a vector I meant, but please don't take it literally since I have no idea on how to actually do it! ;) $\endgroup$ – Matteo Monti Oct 2 '14 at 19:09
2
$\begingroup$

All of blender's plugins are python scripts, so I looked up the script and was going through it's code when I realized that was a really bad idea. If you grab the bottom of the top menu bar and pull down it gives you a list of all the commands blender has recently executed. Add a couple surfaces, and voila, it looks like these commands should be a good start to what you want:

bpy.ops.mesh.primitive_z_function_surface(div_x=20, div_y=17)
bpy.ops.mesh.primitive_xyz_function_surface(x_eq="cos(v)*(1+cos(u))*sin(v/3)", z_eq="sin(v)*(1.3+cos(u))*sin(v/8)")

They can be used in a script (blender's user interface uses python, so everything that shows up in the command list is valid python), just don't forget to import bpy.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.