Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to know how to make a mesh having Vertices and Faces by using python script from mathematical equations, for example, spherical harmonics, and so on.

If the sample code of an easy function is shown, the rest will be made by myself.

Ubuntu version: 12.04

Blender version: 2.62

Added Information (2013/08/02) :

I found very useful site,

Blender Python: Mathematical Mesh

Finally I got an example, this is the case of Normal Distribution.

import bpy
import math

# clear mesh and object
for item in bpy.context.scene.objects:
    if item.type == 'MESH':
for item in
    if item.type == 'MESH':
for item in
for item in

# mesh arrays
verts = []
faces = []

# mesh variables
numX = 100
numY = 100

# variance and scale variables
variance = .35
scale = 4

# fill verts array
for i in range (0, numX):
    for j in range(0,numY):
        # nomalize range
        u = 2*(i/numX-1/2)
        v = 2*(j/numY-1/2)

        s = variance
        x = scale*u
        y = scale*v
        z = scale*1/math.sqrt(2*math.pi*s*s)*math.exp(-(u*u+v*v)/(2*s*s))

        vert = (x,y,z)

# fill faces array
count = 0
for i in range (0, numY *(numX-1)):
    if count < numY-1:
        A = i
        B = i+1
        C = (i+numY)+1
        D = (i+numY)
        face = (A,B,C,D)
        count = count + 1
        count = 0

# create mesh and object
mesh ="wave")
object ="wave",mesh)

# set mesh location
object.location = bpy.context.scene.cursor_location

# create mesh from python data

Screenshot: Mesh Object by Python Script

share|improve this question

You should search in similar scripts. As you might know, Blender comes with addons written in Python. There are some available addons about the creation of meshes. You have to enable to use them, but they are installed on your computer. Search in /usr/share/blender/addons, to see them. Maybe you can do some reverse engenieering to answer your question.

Copy your own script to this folder. There is also "install from file" in preferences. You have to enable the scripts in preferences. It's a bit hidden. On the upper left of the default window you can see an exclamation mark. Click on it and select preferences from dropdown menu. Then you have to increase hight of this bar, to see the preferences. On screenshot you can see increased preferences bar. Select addon tab. On the right hand, you can mark "enable addon". To make this change permanent, you have to save them. I have forgotten about the shortcut, search for it, maybe its Ctrl+U.

Well, when I used Blender, there was an option to run Scripts. Now, I can see only a Console.

enter image description here

share|improve this answer
Thanks kleinempfaenger. I found those scripts , not in "/usr/share/blender/addons" , but in "/usr/lib/blender/scripts/addons". However, I can not understand well yet, so I'm waiting for any other replies. – vine_user Jul 28 '13 at 8:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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