Newer
Older
# in case cursor has moved
Maurice Raybaud
committed
bpy.ops.object.mode_set(mode="EDIT")
bpy.ops.mesh.reveal()
bpy.ops.mesh.select_all(action="SELECT")
bpy.ops.mesh.delete(type="VERT")
bpy.ops.mesh.primitive_xyz_function_surface(
x_eq=x_eq,
y_eq=y_eq,
z_eq=z_eq,
range_u_min=u_min,
range_u_max=u_max,
range_v_min=v_min,
range_v_max=v_max,
)
bpy.ops.mesh.select_all(action="SELECT")
# extra work:
bpy.ops.transform.translate(value=(obloc - curloc), proportional_size=1)
# XXX TODO : https://devtalk.blender.org/t/bpy-ops-transform-rotate-option-axis/6235/7
# to complete necessary extra work rotation, after updating from blender version > 2.92
# update and uncomment below, but simple axis deprecated since 2.8
# bpy.ops.transform.rotate(axis=obrot, proportional_size=1)
bpy.ops.mesh.hide(unselected=False)
bpy.ops.object.mode_set(mode="OBJECT")
if not ob:
bpy.ops.mesh.primitive_xyz_function_surface(
x_eq=x_eq,
y_eq=y_eq,
z_eq=z_eq,
range_u_min=u_min,
range_u_max=u_max,
range_v_min=v_min,
range_v_max=v_max,
)
ob.name = ob.data.name = "PovParametric"
ob.pov.u_min = u_min
ob.pov.u_max = u_max
ob.pov.v_min = v_min
ob.pov.v_max = v_max
ob.pov.x_eq = x_eq
ob.pov.y_eq = y_eq
ob.pov.z_eq = z_eq
bpy.ops.object.mode_set(mode="EDIT")
bpy.ops.mesh.hide(unselected=False)
bpy.ops.object.mode_set(mode="OBJECT")
ob.data.auto_smooth_angle = 0.6
bpy.ops.object.shade_smooth()
ob.pov.object_as = "PARAMETRIC"
ob.update_tag() # as prop set via python not updated in depsgraph
return{'FINISHED'}
class POV_OT_parametric_add(Operator):
"""Add the representation of POV parametric surfaces using pov_parametric_define() function."""
Maurice Raybaud
committed
bl_idname = "pov.addparametric"
bl_label = "Parametric"
bl_description = "Add Paramertic"
bl_options = {'REGISTER', 'UNDO'}
COMPAT_ENGINES = {"POVRAY_RENDER"}
Maurice Raybaud
committed
# Keep in sync within model_properties.py section Parametric primitive
u_min: FloatProperty(name="U Min", description="", default=0.0)
v_min: FloatProperty(name="V Min", description="", default=0.0)
u_max: FloatProperty(name="U Max", description="", default=6.28)
v_max: FloatProperty(name="V Max", description="", default=12.57)
x_eq: StringProperty(maxlen=1024, default="cos(v)*(1+cos(u))*sin(v/8)")
y_eq: StringProperty(maxlen=1024, default="sin(u)*sin(v/8)+cos(v/8)*1.5")
z_eq: StringProperty(maxlen=1024, default="sin(v)*(1+cos(u))*sin(v/8)")
def execute(self, context):
Maurice Raybaud
committed
props = self.properties
u_min = props.u_min
v_min = props.v_min
u_max = props.u_max
v_max = props.v_max
x_eq = props.x_eq
y_eq = props.y_eq
z_eq = props.z_eq
Maurice Raybaud
committed
try:
pov_parametric_define(context, self, None)
self.report(
{"INFO"},
"This native POV-Ray primitive " "won't have any vertex to show in edit mode",
Maurice Raybaud
committed
)
except AttributeError:
self.report({"INFO"}, "Please enable Add Mesh: Extra Objects addon")
return {"FINISHED"}
Maurice Raybaud
committed
class POV_OT_parametric_update(Operator):
"""Update the representation of POV parametric surfaces.
Delete its previous proxy geometry and rerun pov_parametric_define() function
with the new parameters"""
Maurice Raybaud
committed
bl_idname = "pov.parametric_update"
bl_label = "Update"
bl_description = "Update parametric object"
bl_options = {'REGISTER', 'UNDO'}
COMPAT_ENGINES = {"POVRAY_RENDER"}
Maurice Raybaud
committed
@classmethod
def poll(cls, context):
engine = context.scene.render.engine
ob = context.object
return ob and ob.data and ob.type == "MESH" and engine in cls.COMPAT_ENGINES
Maurice Raybaud
committed
def execute(self, context):
pov_parametric_define(context, None, context.object)
return {"FINISHED"}
# -----------------------------------------------------------------------------
class POV_OT_polygon_to_circle_add(Operator):
"""Add the proxy mesh for POV Polygon to circle lofting macro"""
Maurice Raybaud
committed
bl_idname = "pov.addpolygontocircle"
bl_label = "Polygon To Circle Blending"
bl_description = "Add Polygon To Circle Blending Surface"
bl_options = {'REGISTER', 'UNDO'}
COMPAT_ENGINES = {"POVRAY_RENDER"}
# Keep in sync within model_properties.py section PolygonToCircle properties
polytocircle_resolution: IntProperty(
name="Resolution", description="", default=3, min=0, max=256
)
polytocircle_ngon: IntProperty(name="NGon", description="", min=3, max=64, default=5)
polytocircle_ngonR: FloatProperty(name="NGon Radius", description="", default=0.3)
polytocircle_circleR: FloatProperty(name="Circle Radius", description="", default=1.0)
def execute(self, context):
Maurice Raybaud
committed
props = self.properties
ngon = props.polytocircle_ngon
ngonR = props.polytocircle_ngonR
circleR = props.polytocircle_circleR
resolution = props.polytocircle_resolution
# layers = 20*[False]
# layers[0] = True
bpy.ops.mesh.primitive_circle_add(
vertices=ngon, radius=ngonR, fill_type="NGON", enter_editmode=True
Maurice Raybaud
committed
bpy.ops.transform.translate(value=(0, 0, 1))
bpy.ops.mesh.subdivide(number_cuts=resolution)
numCircleVerts = ngon + (ngon * resolution)
bpy.ops.mesh.select_all(action="DESELECT")
bpy.ops.mesh.primitive_circle_add(
vertices=numCircleVerts, radius=circleR, fill_type="NGON", enter_editmode=True
Maurice Raybaud
committed
bpy.ops.transform.translate(value=(0, 0, -1))
bpy.ops.mesh.select_all(action="SELECT")
Maurice Raybaud
committed
bpy.ops.mesh.bridge_edge_loops()
if ngon < 5:
bpy.ops.mesh.select_all(action="DESELECT")
bpy.ops.mesh.primitive_circle_add(
vertices=ngon, radius=ngonR, fill_type="TRIFAN", enter_editmode=True
Maurice Raybaud
committed
bpy.ops.transform.translate(value=(0, 0, 1))
bpy.ops.mesh.select_all(action="SELECT")
Maurice Raybaud
committed
bpy.ops.mesh.remove_doubles()
bpy.ops.object.mode_set(mode="OBJECT")
Maurice Raybaud
committed
ob = context.object
ob.name = "Polygon_To_Circle"
ob.pov.ngon = ngon
ob.pov.ngonR = ngonR
ob.pov.circleR = circleR
bpy.ops.object.mode_set(mode="EDIT")
bpy.ops.mesh.hide(unselected=False)
bpy.ops.object.mode_set(mode="OBJECT")
#ob.data.auto_smooth_angle = 0.1
#bpy.ops.object.shade_smooth()
ob.pov.object_as = "POLYCIRCLE"
ob.update_tag() # as prop set via python not updated in depsgraph
return {"FINISHED"}
POV_OT_lathe_add,
POV_OT_superellipsoid_add,
POV_OT_superellipsoid_update,
POV_OT_supertorus_add,
POV_OT_supertorus_update,
POV_OT_loft_add,
POV_OT_isosurface_add,
POV_OT_isosurface_update,
POV_OT_isosurface_box_add,
POV_OT_isosurface_sphere_add,
POV_OT_sphere_sweep_add,
POV_OT_blobsphere_add,
POV_OT_blobcapsule_add,
POV_OT_blobplane_add,
POV_OT_blobellipsoid_add,
POV_OT_blobcube_add,
POV_OT_height_field_add,
POV_OT_parametric_add,
POV_OT_parametric_update,
POV_OT_polygon_to_circle_add,
)
def register():
for cls in classes:
register_class(cls)
def unregister():