Try to draw math functions - questions about AddMesh: extra objects scripts

Hi Blender forum - i’m a new member to this forum so I hope this is the right question for this section.

My goal is to draw meshes that can be described with various math functions. I believe i’ve found the perfect script for this - and it’s already installed: the “Add Mesh: extra objects” script.

I am able to draw the default objects - but the I cannot find any way to expose the scripts parameters so that i can adjust things. According to the documentation (below) they should appear in the tool bar -> object tools. Some controls do appear there - eg translate, scale,etc , but none of the script-specific parameters i’m looking for like radius, depth, or other details from the math functions that describe those objects.

how can i access the math functions so I can draw arbitrary functions?

thanks for any info.

Matt

Here’s the info on the script i’m using. Also i have Blender 2.61 on an iMAC.

http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Add_Mesh/Add_Extra

The options only appear once you add the object, until you make any other operations in blender. The appear at the bottom of the toolshelf (T) or by pressing F6. Make sure you have opened all the toolshelf. If you have a + symbol at the bottom, press on this to open the operator panel.

how can i access the math functions so I can draw arbitrary functions?
You’ll have to amend the addon python code.

Also: Addon python code is in your blender installation folder inside /scripts/addons folder. FYI Good Luck!

this is a scripted version, i made to NOT use the gui-interface
for some already known shapes.

Paste it into the text-editor in blender and run the script
(needs the extra-meshes-addon enabled …)

Not all are working, some are tryouts … and i never completed the settings
for those - for example there are different tests to generate
a “klein bottle” made out of 2 parts.

and some of those meshes were used in my “treadmill-video” and blend-file
in the python-part of the forum.


# a lot of samples are taken from
# http://www.3d-meier.de/tut3/Seite0.html
# and different samples from other (not noted) internet-resources ...
# --- ! needs the addon -extra-meshes- activated
#
import bpy

def create_mesh_object(context, verts, edges, faces, name):
    mesh = bpy.data.meshes.new(name)
    mesh.from_pydata(verts, edges, faces)
    mesh.update()
    from bpy_extras import object_utils
    obj = object_utils.object_data_add(context, mesh, operator=None)
    return obj


import add_mesh_extra_objects
# makePyramid( initialSize, stepHeight, stepWidth, numberSteps)
#(verts, faces) = add_mesh_extra_objects.add_mesh_pyramid.makePyramid(6., 0.2, 0.3, 10)

class helper:
    report = print

from math import pi

h = helper()
h.report("dummy")
(verts, faces) = add_mesh_extra_objects.add_mesh_3d_function_surface.xyz_function_surface_faces(
    h, "u", "v", "u*v", 0., 2., 32, False, 0., 2., 32, False,  
    "0", "0", "0", "0", "0", "0", 1, False)
print(faces)
#create_mesh_object(bpy.context, verts, [], faces, "dummy")

#some samples are taken from the wiki-page of the addon
# http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/Add_Mesh/Add_3d_Function_Surface
# while others are selected from different sources
#
samples=[]

samples.append( {"name":"Moebius", 
"x":"cos(u)*(1+v/2 *cos(u/2))", 
"y":"sin(u)*(1+v/2 *cos(u/2))", 
"z":"v/2 *sin(u/2)",
"umin": 0,
"umax": 2*pi,
"uwrap": True,
"vmin": -1,
"vmax": 1,
"vwrap": True,
} )
samples.append( {"name":"horn", 
"x":"(4+3*sin(v/3)*sin(u))*cos(v)", 
"y":"(4+3*sin(v/3)*sin(u))*sin(v)", 
"z":"3*sin(v/3)*cos(u)",
"umin": 0,
"umax": 2*pi,
"uwrap": False,
"vmin": 0,
"vmax": pi,
"vwrap": False,
} )
samples.append( {"name":"pillow", 
"x":"sin(u)*cos(v)", 
"y":"sin(v)", 
"z":"cos(u)",
"umin": 0,
"umax": 2*pi,
"uwrap": True,
"vmin": 0,
"vmax": 2*pi,
"vwrap": True,
} )
samples.append( {"name":"tyre_torus", 
"x":"(5+cos(u))*cos(v)", 
"y":"(5+cos(u))*sin(v)", 
"z":"2*sin(u)",
"umin": 0,
"umax": 2*pi,
"uwrap": True,
"vmin": 0,
"vmax": 2*pi,
"vwrap": True,
} )
samples.append( {"name":"8flat", 
"x":"sin(u)*sin(u)", 
"y":"sin(v)*cos(v)", 
"z":"cos(v)",
"umin": 0,
"umax": 2*pi,
"uwrap": True,
"vmin": 0,
"vmax": 2*pi,
"vwrap": True,
} )
samples.append( {"name":"WhitneyUmbrella", 
"x":"u*v", 
"y":"u", 
"z":"v*v",
"umin": -1.5,
"umax": 1.5,
"uwrap": False,
"vmin": -1.5,
"vmax": 1.5,
"vwrap": False,
} )
samples.append( {"name":"RightConoid", 
"x":"v*cos(u)", 
"y":"v*sin(u)", 
"z":"2*sin(u)",
"umin": 0,
"umax": 2*pi,
"uwrap": True,
"vmin": 0,
"vmax": 2*pi,
"vwrap": True,
} )
samples.append( {"name":"RomanSurface", 
"x":"3*cos(u)*cos(v)*sin(v)", 
"y":"3*sin(u)*cos(v)*sin(v)", 
"z":"3*cos(u)*sin(u)*cos(v)*cos(v)",
"umin": 0,
"umax": 2*pi,
"uwrap": True,
"vmin": 0,
"vmax": 2*pi,
"vwrap": True,
} )
samples.append( {"name":"UmbilicTorus", 
"x":"sin(u)*(7+cos(u/3-2*v)+2*cos(u/3+v))", 
"y":"cos(u)*(7+cos(u/3-2*v)+2*cos(u/3+v))", 
"z":"sin(u/3-2*v)+2*sin(u/3+v)",
"umin": -pi,
"umax": pi,
"uwrap": True,
"vmin": -pi,
"vmax": pi,
"vwrap": True,
} )
samples.append( {"name":"escargout", 
"afunc": "3",
"bfunc": "6",
"cfunc":"exp(u/(7*pi))",
"x":"a*(1-c)*cos(u)*cos(.5*v)**2", 
"y":"1-exp(u/(c*pi))-sin(v)+c*sin(v)", 
"z":"a*(-1+c)*sin(u)*cos(.5*v)**2",
"umin": 0,
"umax": 6*pi,
"uwrap": True,
"vmin": 0,
"vmax": 2*pi,
"vwrap": True,
} )
samples.append( {"name":"TrianglePillow", 
"x":"cos(u)", 
"y":"cos(v)", 
"z":"cos(u+v)",
"umin": -pi,
"umax": pi,
"uwrap": True,
"vmin": -pi,
"vmax": pi,
"vwrap": True,
} )
samples.append( {"name":"SnailSurface", 
"x":"u*cos(v)*sin(u)", 
"y":"u*cos(u)*cos(v)", 
"z":"-u*sin(v)",
"umin": 0,
"umax": 2*pi,
"uwrap": False,
"vmin": -pi,
"vmax": pi,
"vwrap": False,
} )
samples.append( {"name":"Horn", 
"afunc":"2",
"bfunc":"1.5",
"cfunc":"3",
"x":"(a+u*cos(v))*sin(b*pi*u)", 
"y":"(a+u*cos(v))*cos(b*pi*u)+c*u", 
"z":"u*sin(v)",
"umin": 0,
"umax": 1,
"uwrap": False,
"vmin": -pi,
"vmax": pi,
"vwrap": False,
} )
samples.append( {"name":"AppleSurface", 
"x":"cos(u)*(4+3.8*cos(v))", 
"y":"sin(u)*(4+3.8*cos(v))", 
"z":"(cos(v)+sin(v)-1)*(1+sin(v))*log(1-pi*v/10)+7.5*sin(v)",
"umin": 0,
"umax": 2*pi,
"uwrap": False,
"vmin": -pi,
"vmax": pi,
"vwrap": False,
} )
samples.append( {"name":"Trefoil", 
"x":"2*sin(3*u)/(2+cos(v))", 
"y":"2*(sin(u)+2*sin(2*u))/(2+cos(v+2*pi/3))", 
"z":"(cos(u)-2*cos(2*u))*(2+cos(v))*(2+cos(v+2*pi/3))/4",
"umin": -pi,
"umax": pi,
"uwrap": False,
"vmin": -pi,
"vmax": pi,
"vwrap": False,
} )
samples.append( {"name":"Kranz", 
"x":"cos(u+4)/3", 
"y":"cos(u)*sin(v)*cos(v)*sin(u)*cos(v)+0.5*cos(u)", 
"z":"cos(v)*sin(u)*cos(u)*sin(v)",
"umin": 0,
"umax": 2*pi,
"uwrap": True,
"vmin": 0,
"vmax": 2*pi,
"vwrap": True,
} )
samples.append( {"name":"AstrocerasShell", 
"afunc":"1.25",  #a
"bfunc":"1.25",  #b
"cfunc":"1.0",   #c
"ffunc":"3.5",   #h
"gfunc":"0.",    #k
"hfunc":".12",   #w
"x":"exp(h*u)*(f+a*cos(v))*cos(c*u)", 
"y":"1*exp(h*u)*(f+a*cos(v))*sin(c*u)", 
"z":"exp(h*u)*(g+b*sin(v))",
"umin": -40,
"umax": -1,
"uwrap": False,
"vmin": 0,
"vmax": 2*pi,
"vwrap": False,
"resolution": 128
} )
samples.append( {"name":"MyaArenariaShell", 
"afunc":"0.85",  #a
"bfunc":"1.6",  #b
"cfunc":"3.0",   #c
"ffunc":"0.9",   #h
"gfunc":"0.",    #k
"hfunc":"2.5",   #w
"x":"exp(h*u)*(f+a*cos(v))*cos(c*u)", 
"y":"1*exp(h*u)*(f+a*cos(v))*sin(c*u)", 
"z":"exp(h*u)*(g+b*sin(v))",
"umin": -1,
"umax": 0.52,
"uwrap": False,
"vmin": 0,
"vmax": 2*pi,
"vwrap": False,
"resolution": 32
} )
samples.append( {"name":"NaticaStellataShell", 
"afunc":"2.6",  #a
"bfunc":"2.4",  #b
"cfunc":"1.0",   #c
"ffunc":"1.25",   #h
"gfunc":"-2.8",    #k
"hfunc":".18",   #w
"x":"exp(h*u)*(f+a*cos(v))*cos(c*u)", 
"y":"1*exp(h*u)*(f+a*cos(v))*sin(c*u)", 
"z":"exp(h*u)*(g+b*sin(v))",
"umin": -20,
"umax": 1,
"uwrap": False,
"vmin": 0,
"vmax": 2*pi,
"vwrap": False,
"resolution": 128
} )
samples.append( {"name":"PseudohelicerasShell", #subcatenatum
"afunc":"1.6",  #a
"bfunc":"1.6",  #b
"cfunc":"1.0",   #c
"ffunc":"1.5",   #h
"gfunc":"-7.",    #k
"hfunc":"0.075",   #w
"x":"exp(h*u)*(f+a*cos(v))*cos(c*u)", 
"y":"1*exp(h*u)*(f+a*cos(v))*sin(c*u)", 
"z":"exp(h*u)*(g+b*sin(v))",
"umin": -50,
"umax": -1,
"uwrap": False,
"vmin": 0,
"vmax": 2*pi,
"vwrap": False,
"resolution": 128
} )
samples.append( {"name":"BulletNose", 
"afunc": "0.9",
"bfunc": "1.2",
"x":"a*cos(v)*cos(u)", 
"y":"-b/tan(v)", 
"z":"a*cos(v)*sin(u)",
"umin": 0,
"umax": 2*pi,
"uwrap": False,
"vmin": 0.25,
"vmax": pi/2,
"vwrap": False,
} )
samples.append( {"name":"Paprika",
"afunc": "2",
"bfunc": "1.9", 
"x":"cos(u)*(a+b*cos(v))+pow(v/pi,20)", 
"y":"sin(u)*(a+b*cos(v))+0.25*cos(5*u)", 
"z":"-2.3*log(1-v*0.3157)+6*sin(v)+2*cos(v)",
"umin": -pi,
"umax": pi,
"uwrap": False,
"vmin": -pi,
"vmax": pi,
"vwrap": False,
"resolution": 64
} )
samples.append( {"name":"Apple2",
"afunc": "5",
"bfunc": "4.8", 
"x":"cos(u)*(a+b*cos(v))+pow(v/pi,20)", 
"y":"sin(u)*(a+b*cos(v))+0.25*cos(5*u)", 
"z":"-2.3*log(1-v*0.3157)+6*sin(v)+2*cos(v)",
"umin": -pi,
"umax": pi,
"uwrap": False,
"vmin": -pi,
"vmax": pi,
"vwrap": False,
"resolution": 64
} )
samples.append( {"name":"TrefoilKnot", 
"afunc":"2",
"bfunc":"0.3",
"x":"(a+b*cos(u/2))*cos(u/3)+ b*cos(u/3)*cos(v-pi)", 
"y":"(a+b*cos(u/2))*sin(u/3) + b*sin(u/3)*cos(v-pi)", 
"z":"b+sin(u/2)+b*sin(v-pi)",
"umin": 0,
"umax": 12*pi,
"uwrap": False,
"vmin": 0,
"vmax": 2*pi,
"vwrap": True,
"resolution": 128
} )
samples.append( {"name":"Soucoupoid", 
"x":"cos(u)*cos(v)", 
"y":"pow(sin(u),3)", 
"z":"cos(u)*sin(v)",
"umin": -pi,
"umax": pi,
"uwrap": False,
"vmin": 0,
"vmax": pi,
"vwrap": False,
} )
samples.append( {"name":"Shell", 
"x":"", 
"y":"", 
"z":"",
"umin": 0,
"umax": 2*pi,
"uwrap": True,
"vmin": 0,
"vmax": 2*pi,
"vwrap": True,
} )
samples.pop()
def add_xyz_object(helper=h, param=samples[0], resolution=32):
    p = param
    afunc = "0"
    bfunc = "0"
    cfunc = "0"
    ffunc = "0"
    gfunc = "0"
    hfunc = "0"
    if "afunc" in p:
        afunc = p["afunc"]
    if "bfunc" in p:
        bfunc = p["bfunc"]
    if "cfunc" in p:
        cfunc = p["cfunc"]
    if "ffunc" in p:
        ffunc = p["ffunc"]
    if "gfunc" in p:
        gfunc = p["gfunc"]
    if "hfunc" in p:
        hfunc = p["hfunc"]
    if "resolution" in p:
        resolution = p["resolution"]
    (verts, faces) = add_mesh_extra_objects.add_mesh_3d_function_surface.xyz_function_surface_faces(
    h, p["x"], p["y"], p["z"], p["umin"], p["umax"], resolution, False, p["vmin"], p["vmax"], resolution, False,  
    afunc, bfunc, cfunc, ffunc, gfunc, hfunc, 1, False)
    create_mesh_object(bpy.context, verts, [], faces, p["name"])
    obj = bpy.context.active_object
    print(p)
    return(obj)

add_xyz_object(param=samples[-1])

for i in range(len(samples)):
    if True or "NoDrop" in samples[i]["name"]:
        o = add_xyz_object(param=samples[i])
        print("this was:", o.name)
    
        if "Klein_" in o.name:
            print("2 parts .. no move")
        else:
            o.location[1] = 5 - (i % 5) * 2
            o.location[0] = -3
            o.location[2] = int(i/5) 


i like the pretzel !LOL

is it possible to make a line only for this pretzel shape

same shape as the orbit of the other moon on earth orbit that we don’t see !

and like the sea shells too

these are interesting general shapes
is there an addon script for these shapes for 2.6 with a menu ?

can be usefull for shapes in general !

merry christmass

Thanks for your helpful and quick reply. I am closer now but still missing something subtle.

1.) I realize now for arbitrary functions I will have to amend the python code. no problem.

2.) however for the included functions (eg gears, diamond, etc) i still am having trouble accessing the parameters inside toolbar-> object tools. I understand I have to add the object first. Also - i must be really close because i was able , once, to see the parameters for the diamond. But i can’t get it to happen again. Yes I checked that i’m opening the entire toolshelf - there is no plus sign.

I am doing it this way: draw the object, then select it with right-click. (i also tried selecting within the outliner). Then I hit ‘T’ and the toolshelf appears. I look at the entries in it - I see things like transform, shading, etc all those normal things. But the specific parameters to Diamond or Gear - I just am having trouble getting those to appear. Must be missing something subtle.

thanks you guys.

by the way there is an addons with some math functions as equations you can add!
have to find which one but it has been there for a long time!

http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Add_Mesh/Add_3d_Function_Surface

there is another one if you add extra and check out the list there are 2 math functions whereh you can enter some math functions!

happy 2.6

AHA!! Got it working. Now I see what you were saying - the parameters only appear right after you add the objecting, and before you do other things. Works great now.

test-dr: thanks for that code I’m very interested to try that.

Even more! If you use the script and add the math functions - the author nicely exposed the math function itself and so you can actually go ahead and put in arbitrary functions specified right from the Blender interface - amazing and so nice. I just drew some sinc(x) functions and not am going to try a cycloid.

nice math site but in german

you can always use google to translate
i have some other sites for math in french and english too

there shoudl be a way to add the other XYZ script for math functions
but size would increase a lot i gess!

still don’t understand why these have not been done as an addon script
they are very interesting 3D shapes!

i’ll try to find some times during christmass holiday and see if i can make an addon menu script with this
i already have some good menus to work with so should be easy to do !

did you do the small functions for theses ?

thanks
merry christmas and a happy new year

ok i got a first version working with class
and all functions seems to work fine

addon for adding a new menu in add mesh menu
with something like 20 items!

with one parameter as property for number of segments!

but need to simplify code for calling the functions

what are the references for these functions ?

and what is the license we need to add now for these addon ?

should i open a new thread in python forum for this?

still working on the PDF doc for this !

happy 2.6

where did you get the apple shape ?

i can see one apple2 which is the trefoil func
but don’t see the other one so don’t know what the equation is for that one?

thanks

can you help with tihis shape like a crater

http://www.3d-meier.de/tut3/Seite132.html

how to write up the parameters

not certain how to proceed here !

thanks

3 other … with the settings:


samples.append( {"name":"AppleSurface", 
"x":"cos(u)*(4+3.8*cos(v))", 
"y":"sin(u)*(4+3.8*cos(v))", 
"z":"(cos(v)+sin(v)-1)*(1+sin(v))*log(1-pi*v/10)+7.5*sin(v)",
"umin": 0,
"umax": 2*pi,
"uwrap": False,
"vmin": -pi,
"vmax": pi,
"vwrap": False,
} )

samples.append( {"name":"Hexaedron", 
"x":"cos(v)**3*cos(u)**3", 
"y":"sin(u)**3", 
"z":"sin(v)**3*cos(u)**3",
"umin": -pi/2,
"umax": pi/2,
"uwrap": False,
"vmin": 0,
"vmax": 2*pi,
"vwrap": False,
} )
samples.append( {"name":"BagelShell", 
"afunc":"20*u**3 - 65*pi*u*u + 50*pi*pi*u - 16*pi**3",
"bfunc":"sqrt(8)",
"x":"(sqrt(2)*a*cos(u)*cos(v)*(3*cos(u)*cos(u)-1)-2*cos(2*u))/(80*pi**3*b)-(3*cos(u)-3)/4", 
"y":"a*sin(v)/(60*pi**3)", 
"z":"(sin(u)*cos(u)*cos(u)+sin(u))/4 - (sin(u)*cos(u))/2 - (sqrt(2)*a*sin(u)*cos(v))/(15*pi**3 *b)",
"umin": 0,
"umax": 2*pi,
"uwrap": True,
"vmin": 0,
"vmax": 2*pi,
"vwrap": True,
} )
samples.append( {"name":"AsymTorus", 
"afunc":"1.3",
"bfunc":"1.5",
"cfunc":"0.3",
"x":"(b+c*cos(v)*(a+sin(u)))*cos(u)", 
"y":"(b+c*cos(v)*(a+sin(u)))*sin(u)", 
"z":"c*sin(v)*(a+sin(u))",
"umin": 0,
"umax": 2*pi,
"uwrap": False,
"vmin": 0,
"vmax": 2*pi,
"vwrap": False,
} )


for writing down, its only some math,
… simple math …if known …
or magic if unknow … [:wink:

and for some objects, to get a smoother resolution,
set the the default “resolution=32” to something higher, like 64 …

i think i’m gone make a new script for sea shell only

on that math page there are enough math model to make something like 5 or more kind of sea shell!
these would make an interesting script

did you do anything for the klein bottle ?

still trying to figure out these funtions and relation to the math calculations!

thanks
happy 2.6

there is this oen for shell which does have any equations?

are there any or not ?

samples.append( {“name”:“Shell”,
“x”:"",
“y”:"",
“z”:"",
“umin”: 0,
“umax”: 2pi,
“uwrap”: True,
“vmin”: 0,
“vmax”: 2
pi,
“vwrap”: True,
} )

that bagel shape looks almost like a klein bottle !

happy 2.6

what is this var samples ?

it’s not a list !

i need to get access to the items inside so how can it get the func values
need to control the diameters for a sphere ect!

param=samples[i1]

also looks like i cannot get the last value for this samples[i1]
always out of index !

thanks
happy 2.6

lol …
… happy new year …

the last item of a list … thats a mystical thing,
some programers tend to increase it to be on the save side …
… to avoid an underflow …

OK! The last empty sample of the append structures …
… is only the sample with no special values … its the blueprint
to be used in dumb copy and paste fashion
… i fill it with some vars for an expression … but
if i dont copy it, then the blueprint will be lost …
thats why i have an sample at the end and
i “pop” it, because its only for the typing and filling in …

those, who know, will laugh and smile …
those, who wont, … will swear and condemn it …

happy new year

yes i saw this pop command and was wondering what it was doing in life!

don’t know but the last appended object is not seen and always give out of index!

like i need to add another one empty may be!

i’ll play some more

ok got a new script for only sea shells things

and i added some more 3D shapes in scripts got 30 now ! LOL

but need to find a way to change some parameters in the list
have to find a way to set these from properties in class

but goig nicely
some of the 3D shapes are amazing to see in viewport

i think i’m gone add some material and render in cycle just to see how good it looks and add this to the doc file !

happy cycles

code simplification

i got one class per 3D object and working fine

but need to remove what is not needed

like i got this right now but it should possible to call function with only the index i think
whch would reduce code lines


 
  i1=31
  if True or "NoDrop" in samples[i1]["name"]:
 
    print (" i1=",i1,' param =',samples[i1])
 
 
 
    o = add_xyz_object(helper=h,param=samples[i1],resolution=seg1)
    print(" i1=",i1,"This was  3D shape :", o.name)
 
    if "Klein_" in o.name:
     print("2 parts .. no move")
    else:
 
     o.location[0] = -3
     o.location[1] = 5 - (i1 % 5) * 2
     o.location[2] = int(i1/5)
 
 
 
 

are the lines for klein necessary here ?

and this if line is it necessary too?

if True or “NoDrop” in samples[i1][“name”]:

if these lines can be drop it will remove quit a lot of lines

thanks
happy 2.6