Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Buerbaum <martin.buerbaum@gmx.at>2011-06-09 12:37:57 +0400
committerMartin Buerbaum <martin.buerbaum@gmx.at>2011-06-09 12:37:57 +0400
commit52ab7574530c227ecca903ca8ec59a7a00240c78 (patch)
tree6b8a7f85481605735aaf5b13d9d0f7fec13cdb82 /add_mesh_extra_objects
parent932fbe30a8a69cbe893caa95b79c52e3390d1459 (diff)
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.
Diffstat (limited to 'add_mesh_extra_objects')
-rw-r--r--add_mesh_extra_objects/add_mesh_3d_function_surface.py241
1 files changed, 180 insertions, 61 deletions
diff --git a/add_mesh_extra_objects/add_mesh_3d_function_surface.py b/add_mesh_extra_objects/add_mesh_3d_function_surface.py
index 7b0bd8c0..8965a820 100644
--- a/add_mesh_extra_objects/add_mesh_3d_function_surface.py
+++ b/add_mesh_extra_objects/add_mesh_3d_function_surface.py
@@ -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 @@ Z Function Surface
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 @@ and
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 @@ class AddZFunctionSurface(bpy.types.Operator):
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 @@ def xyz_function_surface_faces(self, x_eq, y_eq, z_eq,
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 @@ def xyz_function_surface_faces(self, x_eq, y_eq, z_eq,
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 @@ def xyz_function_surface_faces(self, x_eq, y_eq, z_eq,
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,28 +431,33 @@ def xyz_function_surface_faces(self, x_eq, y_eq, z_eq,
+ 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(range_u_step):
+ uNext = uN + 1
- for uN in range(1, range_u_step + 1):
- uThis = uN
+ if wrap_u and (uNext >= uRange):
+ uNext = 0
- if (uThis >= uRange):
- if wrap_u:
- uThis = 0
- else:
- continue
+ faces.append([(vNext * uRange) + uNext,
+ (vNext * uRange) + uN,
+ (vN * uRange) + uN,
+ (vN * uRange) + uNext])
- faces.append([(vThis * uRange) + uThis,
- (vThis * uRange) + uN - 1,
- ((vN - 1) * uRange) + uN - 1,
- ((vN - 1) * uRange) + uThis])
+ 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 @@ def xyz_function_surface_faces(self, x_eq, y_eq, z_eq,
# 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 @@ class AddXYZFunctionSurface(bpy.types.Operator):
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 @@ class AddXYZFunctionSurface(bpy.types.Operator):
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)
- def execute(self, context):
- verts, faces = xyz_function_surface_faces(
- self,
- self.x_eq,
- self.y_eq,
- self.z_eq,
- self.range_u_min,
- self.range_u_max,
- self.range_u_step,
- self.wrap_u,
- self.range_v_min,
- self.range_v_max,
- self.range_v_step,
- self.wrap_v)
-
- if not verts:
- return {'CANCELLED'}
+ 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)
- obj = create_mesh_object(context, verts, [], faces, "XYZ Function")
+ a_eq = StringProperty(name="A helper function",
+ description="Equation for a=F(u,v). Also available: n",
+ default="0")
- return {'FINISHED'}
+ 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):
+
+ for n in range(0, self.n_eq):
+
+ verts, faces = xyz_function_surface_faces(
+ self,
+ self.x_eq,
+ self.y_eq,
+ self.z_eq,
+ self.range_u_min,
+ self.range_u_max,
+ self.range_u_step,
+ self.wrap_u,
+ self.range_v_min,
+ self.range_v_max,
+ self.range_v_step,
+ self.wrap_v,
+ self.a_eq,
+ self.b_eq,
+ self.c_eq,
+ self.f_eq,
+ self.g_eq,
+ self.h_eq,
+ n,
+ self.close_v)
+
+ if not verts:
+ return {'CANCELLED'}
+
+ obj = create_mesh_object(context, verts, [], faces, "XYZ Function")
+
+ return {'FINISHED'}