3D Function Surface script (Blender 2.5x)

Version 0.2.1 of the script is now available.
Nothing visible to the user has been added.

  • Fixed some new API stuff. Mainly we now have the register/unregister functions.
  • Also the new() function for objects now accepts a mesh object.
  • Changed the script so it can be managed from the “Add-Ons” tab in the user preferences.
  • Added dummy “PLUGIN” icon.
  • Corrected FSF address.
  • Clean up of tooltips.

You can now add the script file in your .blender/scripts/addons/ directory and then enable/disable it in the User Preferences under Add-Ons.

Download links are available in the original post

Martin

Version 0.2.3 of the script is available.

  • Nothing important has changed (New feature of the Add-On registration) -> Use bl_addon_info for Add-On information.

Version 0.2.2 of the script is available.

  • Fixed Add-On registration text.

Download links are available in the original post

Version 0.3 of the script is available.

  • X,Y,Z Function Surface (by Ed Mackey & tuga3d). See Extensions_talk:2.5/Py/Scripts/Add_3d_Function_Surface for some examples what this can do :cool:
  • Renamed old function to “Z Function Surface”.
  • Align the geometry to the view if the user preference says so.
  • Store recall properties in newly created object. (Only usable in combination with the “Recall object operator” script enabled in the Add-Ons)

Download links are available in the original post

Thanks for sharing. It’s helping me to understand how to generate meshes inside Python. I see you could manage that well.

The part where you generate the geometry seems to be:

mesh.from_pydata(verts, [], faces)

I’m trying to use the same method but without much luck:


me_name = "mymesh"
me = bpy.data.meshes.new(me_name)

verts = [[0,0,0],[0,1,0],[1,1,0],[1,0,0]]

faces = [[0,1,2,3]]

me.from_pydata(verts, [], faces)

me.update()

ob_new = bpy.data.objects.new(me_name, 'MESH')
bpy.context.scene.objects.link(ob_new)

It gives me an error on the last line: “Error: Object “(null)” is not an Empty type and has no Object Data set.”

Any idea of what I’m doing wrong?

This should work:

me_name = "mymesh"
me = bpy.data.meshes.new(me_name)
 
verts = [(0,0,0), (0,1,0), (1,1,0), (1,0,0)]
 
faces = [[0,1,2,3]]
 
me.from_pydata(verts, [], faces)
 
me.update()
 
ob_new = bpy.data.objects.new(me_name, me)
 
bpy.context.scene.objects.link(ob_new)
  1. bpy.data.objects.new expects a name and a mesh object (not ‘MESH’ anymore - this was a change in the API).
  2. I suggest you use tuples “()” instead of lists “[]” for the vertices.
    It works either way, but there are always 3 of them and () is used for a fixed number of entries. See also http://news.e-scribe.com/397
    Faces can have 3 or 4 (or in the future maybe even more) entries, so lists work fine for that :smiley:

Martin

The problem was that I’m using Alpha2. I first tried it the same way you did it in your script and got an error telling me to put a “type”. I downloaded now a fresh build, and it worked fine.

About tuples, I knew they were faster but didn’t use them at all. It’ll be good to take them more into account and get things running faster when they are appropriate.

Thanks for the help!

Yes, the API changed in between.
This is to be expected in development this rapid :cool:

Speed is not the reason I suggest to use tuples for the vertex coordinates (np idea how much the performace hit actually is - probably pretty tiny for most applications.)
The reason is that you have a list with exactly 3 entries - always. :smiley:
In tuples you can rely on this fact, in lists you can not. [1]

Martin

[1] All of this is from my current knowledge of python. No guarantee that I’m right :wink:

I found an error in the code:

line 384 append() needs one argument, 3 given

you are trying to give it a tuple of append((x,y,y)) but instead you skipped a () pair so its append(x,y,z). This of course makes an error.

Change line 384:
verts.append(float(eval(*expr_args_x)), float(eval(*expr_args_y)), float(eval(*expr_args_z)))

to :
verts.append((float(eval(*expr_args_x)), float(eval(*expr_args_y)), float(eval(*expr_args_z))))

This will fix the X,Y,Z function

Wild_Doogy

Thanks for the report Wild Doogy.
Should be fixed in Blender SVN now. Will update git repository asap.
Regards,
Martin

Version 0.3.2 of the script is available.

  • Various fixes&streamlining by Campbell Barton:
    • r544 Compile expressions for faster execution
    • r544 Use operator reports for errors too
    • r544 Avoid type checks by converting to a float, errors converting to a float are reported too.
  • Fixed an error Campbell overlooked (appending tuples to an array, not single values)
  • Added ‘description’ field, updated ‘url’.
  • Made the script PEP8 compatible again.

Version 0.3.1

  • Use hidden “edit” property for “recall” operator.
  • Bugfix: “Z Function” was mixing up div_x and div_y

Download links are available in the original post

Hi Martin,

great addon! Thank you!

I’ve created a videotutorial about your addon yesterday. It’s in german, though.
I hope I pronounced your name correctly.

You can watch the tutorial on Youtube by typing in “BlenderEi” as the user name(can’t post links here).

Do you think you will keep updating the addon? That’d be awesome. Is it possible to convert the addon into a modifier? With an animatable ‘time-Variable’ for example? It’s a pity that your addon works destructable :wink:
I also noticed that in the XYZ-Function Surface points are not set to U-max and V-max respectively, because the loop in you script seems to start placing points from zero to the maximum - is this supposed to be like that? This is the only way, right?

All in all a really great tool. Helped me understanding maths pretty good.

Take care,
Adam

That’s a very nice, informative and in-depth video about the addon (and the math).

Yes, it’s pronounced correctly (the “ue” is really the german umlaut “ü” ;)).

I’m not sure why you can’t post links? It works for me.

For anybody interested, the video (in german, as BlenderEi mentioned) for this addon is here:

And BlenderEi’s other Blender videos (german) can be found here:
http://www.youtube.com/user/BlenderEi

Well, the addon is now in the blender-extension repository and is constantly updated (either by my of other blender python programmers).

I don’t update this thread as often because of this. You can still post here (or in the tracker for the script) to comment and report bugs respectively.

I have no plans to make this into a modifier (mostly for lack of skill and time), sorry. Would be pretty nice, and that’s also what I initially tried to do.

The script was non-destructible for some time, but the way it was done was not very good.

Short summary on the “why”:
A generic system/framework to re-create meshes even after performing a non-destructive action would be the saner solution. At least in comparison with the rather hack-ish python code I used for some time.
It’s definitely something I’d like to have for a script like this, since the parameters can get pretty complicated. Time will tell I guess, it would need some blender internal changes to make it work.

I do not know much about the code in the x,y,z script because I reuse a lot of code from a previous script (by Ed Mackey & tuga3d). I simply modified it to work in blender 2.5x.
[“pi” suggestion deleted, nevermind]
I’ll try to investigate this and find a fix (time permitted).

Cheers,
Martin

EDIT: I just saw that your input fields are sorted in a rather confusing way, I’d even say the look random.
What version of the script and blender are you using?

In the most recent version it should look something like this:

Z Function Surface
* Z Equation
* X Subdivisions
* Y Subdivisions
* X Size
* Y Size

X,Y,Z Function Surface
* X Equation
* Y Equation
* Z Equation
* U min
* U max
* U step
* U wrap
* V min
* V max
* V step
* V wrap

Version 0.3.6 of the script is available.

CHanges since 0.3.2

  • Hopefully fixed the uMax/vMax bug.
  • Lots of updates for the new Blender API
  • No more “recall”
  • and more…

Download links are available in the original post

Hi Martin,

thanks for your quick answer!

So you’re also german, eh? :wink: Now I noticed that you’re from vienna :smiley:

Also thanks for publishing the links. I assume that I can’t post links due to my first postings in the BlenderArtist board (i just joined two days ago). There is still this annoying error message, when I click “Preview Post”:

Ah, sure. Forgot about the fact, that there is the SVN Repository. That’s great. If I notice something weird about the addon, I will post it in the tracker. But since you fixed the input fields and the umax and vmax bug, this probably won’t happen. :slight_smile:

Now that’s cool. I agree with you, that hopefully soon with a stable Blender Python API there will be a chance of implementing your great addon as a modifier.

If I can improve upon something, don’t hesitate to tell me - I can cope with critique and I even want it :slight_smile:

Alright… …now comes the embarrasing part. :o I’m still using Blender 2.53.1, Revision 31745. I will now go and update Blender - I promise! :wink: Thanks for releasing a newer version of your addon so rapidly. You are great!

Wish you all the best and please keep on producing these great tools for our Blender 3D :slight_smile:
See you,
Adam

Thank you for your great introduction video, BlenderEi and thank you pontiac for all the good work on the script :slight_smile:

I have very high hopes on this plugin. It could be usefull both for creating marvelous looking plots and animated functions as background for mograph stuff…

He he, even your quoted URLs get ‘censored’ right now :smiley:
Yeah, I guess this will be corrected once you have been authorised by a moderator or something like that.

I edited out a suggestion concerning the umax bug, but a second later I realised that it does not work :o

That’s no thing to be embarrassed for. Especially with the fast development of v2.5x Blender. I myself can only keep up because I compile blender myself and can thus always keep up-to-date fairly easy.
Even then it’s going pretty fast :slight_smile:

Cheers,
Martin

I see you still have code referencing the magic “edit” property. Did you know that’s not necessary any more? You can simply create a new object each time your “execute” method is called, and Blender will take care of getting rid of the old one.

I know, I know :slight_smile: but I had no time to remove all that code yet. I’ll get around to do that sometime though.

The script refuses to be activated with the command line notice:

File “/home/julian/sources/Blender_2.5_debug/install/linux2/2.58/scripts/modules/addon_utils.py”, line 219, in enable
mod.register()
AttributeError: ‘module’ object has no attribute ‘register’

[Blender 2.58.0 R37753]

(works in 2.56a)

This script has been integrated into the “Extra Objects” Add-On already included into Blender.

Simply activate that script and you are good to go.
Add -> Extra Objects -> Math Function

I guess that means that I should add a comment in the first post to clarify that :slight_smile: