[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2026] trunk/py/scripts/addons/ add_mesh_extra_objects/add_mesh_3d_function_surface.py: Version 0.3. 8 of the "3D Function Surfaces" script.

Martin Buerbaum martin.buerbaum at gmx.at
Thu Jun 9 10:37:57 CEST 2011


Revision: 2026
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2026
Author:   pontiac
Date:     2011-06-09 08:37:57 +0000 (Thu, 09 Jun 2011)
Log Message:
-----------
Version 0.3.8 of the "3D Function Surfaces" script. Applied patch by Elod Csirmaz
* Modified the "Add X,Y,Z Function Surface" part:
* Changed how wrapping is done to avoid generating unnecessary vertices and make the result more intuitive.
* Added helper functions the results of which can be used in x(u,v), y(u,v), z(u,v).
* The script can now close the ends of an U-wrapped surface.
* It's now possible to create multiple objects with one set of formulae.

Modified Paths:
--------------
    trunk/py/scripts/addons/add_mesh_extra_objects/add_mesh_3d_function_surface.py

Modified: trunk/py/scripts/addons/add_mesh_extra_objects/add_mesh_3d_function_surface.py
===================================================================
--- trunk/py/scripts/addons/add_mesh_extra_objects/add_mesh_3d_function_surface.py	2011-06-09 07:28:28 UTC (rev 2025)
+++ trunk/py/scripts/addons/add_mesh_extra_objects/add_mesh_3d_function_surface.py	2011-06-09 08:37:57 UTC (rev 2026)
@@ -18,10 +18,10 @@
 """
 bl_info = {
     "name": "3D Function Surfaces",
-    "author": "Buerbaum Martin (Pontiac)",
-    "version": (0, 3, 7),
+    "author": "Buerbaum Martin (Pontiac), Elod Csirmaz",
+    "version": (0, 3, 8),
     "blender": (2, 5, 7),
-    "api": 35853,
+    "api": 37329,
     "location": "View3D > Add > Mesh",
     "description": "Create Objects using Math Formulas",
     "warning": "",
@@ -37,16 +37,16 @@
 This script lets the user create a surface where the z coordinate
 is a function of the x and y coordinates.
 
-    z = f(x,y)
+    z = F1(x,y)
 
 X,Y,Z Function Surface
 
 This script lets the user create a surface where the x, y and z
 coordinates are defiend by a function.
 
-    x = f(u,v)
-    y = f(u,v)
-    z = f(u,v)
+    x = F1(u,v)
+    y = F2(u,v)
+    z = F3(u,v)
 
 Usage:
 You have to activated the script in the "Add-Ons" tab (user preferences).
@@ -57,6 +57,21 @@
 menu.
 
 Version history:
+v0.3.8 - Patch by Elod Csirmaz
+    Modified the "Add X,Y,Z Function Surface" part:
+    Changed how wrapping is done to avoid
+    generating unnecessary vertices and make the result more intuitive.
+    Added helper functions the results of which can be used in
+    x(u,v), y(u,v), z(u,v).
+    The script can now close the ends of an U-wrapped surface.
+    It's now possible to create multiple objects with one set of formulae.
+v0.3.7
+    Removed the various "edit" properties - not used anymore.
+    Use generic tracker URL (Blender-Extensions r1369)
+    bl_addon_info now called bl_info
+    Removed align_matrix
+    create_mesh_object now doesn't handle editmode. (See create_mesh_object)
+    This script is now used by the "Extra Objects" script
 v0.3.6 - Various updates to match current Blender API.
     Removed recall functionality.
     Better code for align_matrix
@@ -311,7 +326,8 @@
 
 def xyz_function_surface_faces(self, x_eq, y_eq, z_eq,
     range_u_min, range_u_max, range_u_step, wrap_u,
-    range_v_min, range_v_max, range_v_step, wrap_v):
+    range_v_min, range_v_max, range_v_step, wrap_v,
+    a_eq, b_eq, c_eq, f_eq, g_eq, h_eq, n, close_v):
 
     verts = []
     faces = []
@@ -320,10 +336,18 @@
     uStep = (range_u_max - range_u_min) / range_u_step
     vStep = (range_v_max - range_v_min) / range_v_step
 
-    # Number of steps in the vertex creation loops
+    # Number of steps in the vertex creation loops.
+    # Number of steps is the number of faces
+    #   => Number of points is +1 unless wrapped.
     uRange = range_u_step + 1
     vRange = range_v_step + 1
 
+    if wrap_u:
+        uRange = uRange - 1
+
+    if wrap_v:
+        vRange = vRange - 1
+
     try:
         expr_args_x = (
             compile(x_eq, __file__.replace(".py", "_x.py"), 'eval'),
@@ -337,6 +361,30 @@
             compile(z_eq, __file__.replace(".py", "_z.py"), 'eval'),
             {"__builtins__": None},
             safe_dict)
+        expr_args_a = (
+            compile(a_eq, __file__.replace(".py", "_a.py"), 'eval'),
+            {"__builtins__": None},
+            safe_dict)
+        expr_args_b = (
+            compile(b_eq, __file__.replace(".py", "_b.py"), 'eval'),
+            {"__builtins__": None},
+            safe_dict)
+        expr_args_c = (
+            compile(c_eq, __file__.replace(".py", "_c.py"), 'eval'),
+            {"__builtins__": None},
+            safe_dict)
+        expr_args_f = (
+            compile(f_eq, __file__.replace(".py", "_f.py"), 'eval'),
+            {"__builtins__": None},
+            safe_dict)
+        expr_args_g = (
+            compile(g_eq, __file__.replace(".py", "_g.py"), 'eval'),
+            {"__builtins__": None},
+            safe_dict)
+        expr_args_h = (
+            compile(h_eq, __file__.replace(".py", "_h.py"), 'eval'),
+            {"__builtins__": None},
+            safe_dict)
     except:
         import traceback
         self.report({'ERROR'}, "Error parsing expression: "
@@ -352,8 +400,26 @@
             safe_dict['u'] = u
             safe_dict['v'] = v
 
-            # Try to evaluate the equation.
+            safe_dict['n'] = n
+
+            # Try to evaluate the equations.
             try:
+                a = float(eval(*expr_args_a))
+                b = float(eval(*expr_args_b))
+                c = float(eval(*expr_args_c))
+
+                safe_dict['a'] = a
+                safe_dict['b'] = b
+                safe_dict['c'] = c
+
+                f = float(eval(*expr_args_f))
+                g = float(eval(*expr_args_g))
+                h = float(eval(*expr_args_h))
+
+                safe_dict['f'] = f
+                safe_dict['g'] = g
+                safe_dict['h'] = h
+
                 verts.append((
                     float(eval(*expr_args_x)),
                     float(eval(*expr_args_y)),
@@ -365,29 +431,34 @@
                     + traceback.format_exc(limit=1))
                 return [], []
 
-    for vN in range(1, range_v_step + 1):
-        vThis = vN
+    for vN in range(range_v_step):
+        vNext = vN + 1
 
-        if (vThis >= vRange):
-            if wrap_v:
-                vThis = 0
-            else:
-                continue
+        if wrap_v and (vNext >= vRange):
+            vNext = 0
 
-        for uN in range(1, range_u_step + 1):
-            uThis = uN
+        for uN in range(range_u_step):
+            uNext = uN + 1
 
-            if (uThis >= uRange):
-                if wrap_u:
-                    uThis = 0
-                else:
-                    continue
+            if wrap_u and (uNext >= uRange):
+                uNext = 0
 
-            faces.append([(vThis * uRange) + uThis,
-                (vThis * uRange) + uN - 1,
-                ((vN - 1) * uRange) + uN - 1,
-                ((vN - 1) * uRange) + uThis])
+            faces.append([(vNext * uRange) + uNext,
+                (vNext * uRange) + uN,
+                (vN * uRange) + uN,
+                (vN * uRange) + uNext])
 
+    if close_v and wrap_u and (not wrap_v):
+        for uN in range(1, range_u_step - 1):
+            faces.append([
+                range_u_step - 1,
+                range_u_step - 1 - uN,
+                range_u_step - 2 - uN])
+            faces.append([
+                range_v_step * uRange,
+                range_v_step * uRange + uN,
+                range_v_step * uRange + uN + 1])
+
     return verts, faces
 
 
@@ -412,22 +483,25 @@
 # v max = 5*pi/2
 class AddXYZFunctionSurface(bpy.types.Operator):
     '''Add a surface defined defined by 3 functions:''' \
-    + ''' x=f(u,v), y=f(u,v) and z=f(u,v)'''
+    + ''' x=F1(u,v), y=F2(u,v) and z=F3(u,v)'''
     bl_idname = "mesh.primitive_xyz_function_surface"
     bl_label = "Add X,Y,Z Function Surface"
     bl_options = {'REGISTER', 'UNDO'}
 
-    x_eq = StringProperty(name="X Equation",
-        description="Equation for x=f(u,v)",
-        default="1.2**v*(sin(u)**2 *sin(v))")
+    x_eq = StringProperty(name="X equation",
+        description="Equation for x=F(u,v). " \
+            "Also available: n, a, b, c, f, g, h",
+        default="cos(v)*(1+cos(u))*sin(v/8)")
 
-    y_eq = StringProperty(name="Y Equation",
-        description="Equation for y=f(u,v)",
-        default="1.2**v*(sin(u)*cos(u))")
+    y_eq = StringProperty(name="Y equation",
+        description="Equation for y=F(u,v). " \
+            "Also available: n, a, b, c, f, g, h",
+        default="sin(u)*sin(v/8)+cos(v/8)*1.5")
 
-    z_eq = StringProperty(name="Z Equation",
-        description="Equation for z=f(u,v)",
-        default="1.2**v*(sin(u)**2 *cos(v))")
+    z_eq = StringProperty(name="Z equation",
+        description="Equation for z=F(u,v). " \
+            "Also available: n, a, b, c, f, g, h",
+        default="sin(v)*(1+cos(u))*sin(v/8)")
 
     range_u_min = FloatProperty(name="U min",
         description="Minimum U value. Lower boundary of U range.",
@@ -439,7 +513,7 @@
         description="Maximum U value. Upper boundary of U range.",
         min=0.00,
         max=100.00,
-        default=pi)
+        default=2 * pi)
 
     range_u_step = IntProperty(name="U step",
         description="U Subdivisions",
@@ -455,44 +529,89 @@
         description="Minimum V value. Lower boundary of V range.",
         min=-100.00,
         max=0.00,
-        default=-pi / 4)
+        default=0.00)
 
     range_v_max = FloatProperty(name="V max",
         description="Maximum V value. Upper boundary of V range.",
         min=0.00,
         max=100.00,
-        default=5 * pi / 2)
+        default=4 * pi)
 
     range_v_step = IntProperty(name="V step",
         description="V Subdivisions",
         min=1,
         max=1024,
-        default=32)
+        default=128)
 
     wrap_v = BoolProperty(name="V wrap",
         description="V Wrap around",
         default=False)
 
+    close_v = BoolProperty(name="Close V",
+        description="Create faces for first and last " \
+            "V values (only if U is wrapped)",
+        default=False)
+
+    n_eq = IntProperty(name="Number of objects (n=0..N-1)",
+        description="The parameter n will be the index " \
+            "of the current object, 0 to N-1",
+        min=1,
+        max=100,
+        default=1)
+
+    a_eq = StringProperty(name="A helper function",
+        description="Equation for a=F(u,v). Also available: n",
+        default="0")
+
+    b_eq = StringProperty(name="B helper function",
+        description="Equation for b=F(u,v). Also available: n",
+        default="0")
+
+    c_eq = StringProperty(name="C helper function",
+        description="Equation for c=F(u,v). Also available: n",
+        default="0")
+
+    f_eq = StringProperty(name="F helper function",
+        description="Equation for f=F(u,v). Also available: n, a, b, c",
+        default="0")
+
+    g_eq = StringProperty(name="G helper function",
+        description="Equation for g=F(u,v). Also available: n, a, b, c",
+        default="0")
+
+    h_eq = StringProperty(name="H helper function",
+        description="Equation for h=F(u,v). Also available: n, a, b, c",
+        default="0")
+
     def execute(self, context):

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list