Newer
Older
Maurice Raybaud
committed
bl_label = "Custom POV Code"
Campbell Barton
committed
COMPAT_ENGINES = {'POVRAY_RENDER'}
Maurice Raybaud
committed
def draw(self, context):
layout = self.layout
obj = context.object
Maurice Raybaud
committed
col.label(text="Replace properties with:")
Bastien Montagne
committed
col.prop(obj.pov, "replacement_text", text="")
Maurice Raybaud
committed
###############################################################################
# Add Povray Objects
###############################################################################
class POVRAY_MT_primitives_add_menu(bpy.types.Menu):
"""Define the menu with presets"""
bl_idname = "POVRAY_MT_primitives_add_menu"
bl_label = "Povray"
COMPAT_ENGINES = {'POVRAY_RENDER'}
@classmethod
def poll(cls, context):
engine = context.scene.render.engine
def draw(self,context):
layout = self.layout
layout.operator_context = 'INVOKE_REGION_WIN'
layout.menu(BasicShapesMenu.bl_idname, text = "Primitives",icon="GROUP")
layout.menu(ImportMenu.bl_idname, text = "Import",icon="IMPORT")
class BasicShapesMenu(bpy.types.Menu):
bl_idname = "POVRAY_MT_basic_shape_tools"
bl_label = "Basic_shapes"
def draw(self,context):
layout = self.layout
layout.operator_context = 'INVOKE_REGION_WIN'
layout.operator("pov.addplane", text="Infinite Plane",icon = 'MESH_PLANE')
layout.operator("pov.addbox", text="Box",icon = 'MESH_CUBE')
layout.operator("pov.addsphere", text="Sphere",icon = 'SOLID')
layout.operator("pov.addcylinder", text="Cylinder",icon="MESH_CYLINDER")
layout.operator("pov.cone_add", text="Cone",icon="MESH_CONE")
layout.operator("pov.addtorus", text="Torus",icon = 'MESH_TORUS')
layout.separator()
layout.operator("pov.addrainbow", text="Rainbow",icon="COLOR")
layout.operator("pov.addlathe", text="Lathe",icon = 'MOD_SCREW')
layout.operator("pov.addprism", text="Prism",icon = 'MOD_SOLIDIFY')
layout.operator("pov.addsuperellipsoid", text="Superquadric Ellipsoid",icon = 'MOD_SUBSURF')
layout.operator("pov.addheightfield", text="Height Field",icon="RNDCURVE")
layout.operator("pov.addspheresweep", text="Sphere Sweep",icon = 'FORCE_CURVE')
layout.separator()
layout.operator("pov.addblobsphere", text="Blob Sphere",icon = 'META_DATA')
layout.separator()
layout.operator("pov.addisosurfacebox", text="Isosurface Box",icon="META_CUBE")
layout.operator("pov.addisosurfacesphere", text="Isosurface Sphere",icon="META_BALL")
layout.operator("pov.addsupertorus", text="Supertorus",icon="SURFACE_NTORUS")
layout.separator()
layout.label(text = "Macro based")
layout.operator("pov.addpolygontocircle", text="Polygon To Circle Blending",icon="RETOPO")
layout.operator("pov.addloft", text="Loft",icon="SURFACE_NSURFACE")
Maurice Raybaud
committed
layout.separator()
# Warning if the Add Advanced Objects addon containing
# Add mesh extra objects is not enabled
if not check_add_mesh_extra_objects():
#col = box.column()
layout.label(text="Please enable Add Mesh: Extra Objects addon", icon="INFO")
#layout.separator()
layout.operator("preferences.addon_show",
Maurice Raybaud
committed
text="Go to Add Mesh: Extra Objects addon",
icon="PREFERENCES").module = "add_mesh_extra_objects"
#layout.separator()
return
else:
layout.operator("pov.addparametric", text="Parametric",icon = 'SCRIPTPLUGINS')
class ImportMenu(bpy.types.Menu):
bl_idname = "POVRAY_MT_import_tools"
bl_label = "Import"
def draw(self,context):
layout = self.layout
layout.operator_context = 'INVOKE_REGION_WIN'
Maurice Raybaud
committed
layout.operator("import_scene.pov",icon="FORCE_LENNARDJONES")
def menu_func_add(self, context):
engine = context.scene.render.engine
if engine == 'POVRAY_RENDER':
self.layout.menu("POVRAY_MT_primitives_add_menu", icon="PLUGIN")
def menu_func_import(self, context):
engine = context.scene.render.engine
if engine == 'POVRAY_RENDER':
Maurice Raybaud
committed
self.layout.operator("import_scene.pov",icon="FORCE_LENNARDJONES")
##############Nodes
# def find_node_input(node, name):
# for input in node.inputs:
# if input.name == name:
# return input
# def panel_node_draw(layout, id_data, output_type, input_name):
# if not id_data.use_nodes:
# #layout.operator("pov.material_use_nodes", icon='SOUND')#'NODETREE')
# #layout.operator("pov.use_shading_nodes", icon='NODETREE')
# layout.operator("WM_OT_context_toggle", icon='NODETREE').data_path = \
# return False
# ntree = id_data.node_tree
# node = find_node(id_data, output_type)
# if not node:
# layout.label(text="No output node")
# else:
# input = find_node_input(node, input_name)
# layout.template_node_view(ntree, node, input)
# return True
class NodeMapCreateMenu(bpy.types.Menu):
bl_idname = "POVRAY_MT_node_map_create"
bl_label = "Create map"
def draw(self,context):
layout = self.layout
layout.operator("node.map_create")
def menu_func_nodes(self, context):
ob = context.object
if hasattr(ob,'active_material'):
mat=context.object.active_material
if mat and context.space_data.tree_type == 'ObjectNodeTree':
self.layout.prop(mat.pov,"material_use_nodes")
self.layout.menu(NodeMapCreateMenu.bl_idname)
self.layout.operator("wm.updatepreviewkey")
if hasattr(mat,'active_texture') and context.scene.render.engine == 'POVRAY_RENDER':
tex=mat.active_texture
if tex and context.space_data.tree_type == 'TextureNodeTree':
self.layout.prop(tex.pov,"texture_use_nodes")
###############################################################################
# Camera Povray Settings
###############################################################################
Maurice Raybaud
committed
class CAMERA_PT_povray_cam_dof(CameraDataButtonsPanel, bpy.types.Panel):
bl_label = "POV-Ray Depth Of Field"
COMPAT_ENGINES = {'POVRAY_RENDER'}
def draw_header(self, context):
cam = context.camera
Bastien Montagne
committed
self.layout.prop(cam.pov, "dof_enable", text="")
def draw(self, context):
layout = self.layout
cam = context.camera
Bastien Montagne
committed
layout.active = cam.pov.dof_enable
Bastien Montagne
committed
layout.prop(cam.pov, "dof_aperture")
Campbell Barton
committed
Bastien Montagne
committed
col.prop(cam.pov, "dof_samples_min")
col.prop(cam.pov, "dof_variance")
Bastien Montagne
committed
col.prop(cam.pov, "dof_samples_max")
col.prop(cam.pov, "dof_confidence")
Maurice Raybaud
committed
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
class CAMERA_PT_povray_cam_nor(CameraDataButtonsPanel, bpy.types.Panel):
bl_label = "POV-Ray Perturbation"
COMPAT_ENGINES = {'POVRAY_RENDER'}
def draw_header(self, context):
cam = context.camera
self.layout.prop(cam.pov, "normal_enable", text="")
def draw(self, context):
layout = self.layout
cam = context.camera
layout.active = cam.pov.normal_enable
layout.prop(cam.pov,"normal_patterns")
layout.prop(cam.pov,"cam_normal")
layout.prop(cam.pov,"turbulence")
layout.prop(cam.pov,"scale")
Maurice Raybaud
committed
class CAMERA_PT_povray_replacement_text(CameraDataButtonsPanel, bpy.types.Panel):
bl_label = "Custom POV Code"
Campbell Barton
committed
COMPAT_ENGINES = {'POVRAY_RENDER'}
Maurice Raybaud
committed
def draw(self, context):
layout = self.layout
cam = context.camera
Maurice Raybaud
committed
col.label(text="Replace properties with:")
Bastien Montagne
committed
col.prop(cam.pov, "replacement_text", text="")
Maurice Raybaud
committed
Maurice Raybaud
committed
###############################################################################
# Text Povray Settings
###############################################################################
class TEXT_OT_povray_insert(bpy.types.Operator):
"""Tooltip"""
bl_idname = "text.povray_insert"
bl_label = "Insert"
filepath : bpy.props.StringProperty(name="Filepath", subtype='FILE_PATH')
Maurice Raybaud
committed
@classmethod
def poll(cls, context):
# context.area.type == 'TEXT_EDITOR'
return bpy.ops.text.insert.poll()
def execute(self, context):
if self.filepath and isfile(self.filepath):
file = open(self.filepath, "r")
bpy.ops.text.insert(text=file.read())
# places the cursor at the end without scrolling -.-
# context.space_data.text.write(file.read())
file.close()
return {'FINISHED'}
def validinsert(ext):
Maurice Raybaud
committed
class TEXT_MT_insert(bpy.types.Menu):
bl_label = "Insert"
bl_idname = "TEXT_MT_insert"
def draw(self, context):
pov_documents = locate_docpath()
prop = self.layout.operator("wm.path_open", text="Open folder", icon='FILE_FOLDER')
prop.filepath = pov_documents
self.layout.separator()
Maurice Raybaud
committed
list=[]
for root,dirs,files in os.walk(pov_documents):
list.append(root)
print(list)
self.path_menu(list,
"text.povray_insert",
#{"internal": True},
filter_ext= validinsert
)
Maurice Raybaud
committed
class TEXT_PT_povray_custom_code(TextButtonsPanel, bpy.types.Panel):
Campbell Barton
committed
COMPAT_ENGINES = {'POVRAY_RENDER'}
Maurice Raybaud
committed
def draw(self, context):
layout = self.layout
Maurice Raybaud
committed
pov_documents = locate_docpath()
Maurice Raybaud
committed
layout.label(text="Please configure ", icon="INFO")
layout.label(text="default pov include path ")
layout.label(text="in addon preferences")
#layout.separator()
layout.operator("preferences.addon_show",
Maurice Raybaud
committed
text="Go to Render: POV-Ray addon",
icon="PREFERENCES").module = "render_povray"
#layout.separator()
else:
#print(pov_documents)
layout.menu(TEXT_MT_insert.bl_idname)
Maurice Raybaud
committed
if text:
box = layout.box()
box.label('Source to render:', icon='RENDER_STILL')
row = box.row()
row.prop(text.pov, "custom_code",expand = True)
if text.pov.custom_code in {'3dview'}:
box.operator("render.render", icon='OUTLINER_DATA_POSE')
Maurice Raybaud
committed
if text.pov.custom_code in {'text'}:
rtext = bpy.context.space_data.text
box.operator("text.run", icon='POSE_DATA')
#layout.prop(text.pov, "custom_code")
elif text.pov.custom_code in {'both'}:
box.operator("render.render", icon='POSE_HLT')
layout.label(text="Please specify declared", icon="INFO")
layout.label(text="items in properties ")
Maurice Raybaud
committed
layout.label(text="replacement fields")
Maurice Raybaud
committed
###############################################
# Text editor templates from header menu
class TEXT_MT_templates_pov(bpy.types.Menu):
bl_label = "POV-Ray"
# We list templates on file evaluation, we can assume they are static data,
# and better avoid running this on every draw call.
import os
template_paths = [os.path.join(os.path.dirname(__file__), "templates_pov")]
def draw(self, context):
self.path_menu(
self.template_paths,
"text.open",
props_default={"internal": True},
)
def menu_func_templates(self, context):
# Do not depend on POV-Ray being active renderer here...
self.layout.menu("TEXT_MT_templates_pov")
WORLD_PT_POV_world,
POV_WORLD_MT_presets,
AddPresetWorld,
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
#RenderButtonsPanel,
#ModifierButtonsPanel,
#MaterialButtonsPanel,
#TextureButtonsPanel,
#ObjectButtonsPanel,
#CameraDataButtonsPanel,
#WorldButtonsPanel,
#TextButtonsPanel,
#PovDataButtonsPanel,
DATA_PT_POV_normals,
DATA_PT_POV_texture_space,
DATA_PT_POV_vertex_groups,
DATA_PT_POV_shape_keys,
DATA_PT_POV_uv_texture,
DATA_PT_POV_vertex_colors,
DATA_PT_POV_customdata,
#PovLampButtonsPanel,
LIGHT_PT_POV_preview,
LIGHT_PT_POV_light,
POV_LIGHT_MT_presets,
AddPresetLamp,
OBJECT_PT_povray_obj_rainbow,
RENDER_PT_povray_export_settings,
RENDER_PT_povray_render_settings,
RENDER_PT_povray_photons,
RENDER_PT_povray_antialias,
RENDER_PT_povray_radiosity,
POV_RADIOSITY_MT_presets,
AddPresetRadiosity,
RENDER_PT_povray_media,
MODIFIERS_PT_povray_modifiers,
MATERIAL_PT_POV_sss,
MATERIAL_PT_povray_activate_node,
MATERIAL_PT_povray_active_node,
MATERIAL_PT_POV_mirror,
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
MATERIAL_PT_povray_reflection,
MATERIAL_PT_povray_fade_color,
MATERIAL_PT_povray_caustics,
MATERIAL_PT_povray_replacement_text,
TEXTURE_PT_povray_type,
TEXTURE_PT_povray_preview,
TEXTURE_PT_povray_parameters,
TEXTURE_PT_povray_tex_gamma,
OBJECT_PT_povray_obj_parameters,
OBJECT_PT_povray_obj_sphere,
OBJECT_PT_povray_obj_cylinder,
OBJECT_PT_povray_obj_cone,
OBJECT_PT_povray_obj_superellipsoid,
OBJECT_PT_povray_obj_torus,
OBJECT_PT_povray_obj_supertorus,
OBJECT_PT_povray_obj_parametric,
OBJECT_PT_povray_replacement_text,
POVRAY_MT_primitives_add_menu,
BasicShapesMenu,
ImportMenu,
NodeMapCreateMenu,
CAMERA_PT_povray_cam_dof,
CAMERA_PT_povray_cam_nor,
CAMERA_PT_povray_replacement_text,
TEXT_OT_povray_insert,
TEXT_MT_insert,
TEXT_PT_povray_custom_code,
TEXT_MT_templates_pov,
)
def register():
#from bpy.utils import register_class
for cls in classes:
register_class(cls)
bpy.types.VIEW3D_MT_add.prepend(menu_func_add)
bpy.types.TOPBAR_MT_file_import.append(menu_func_import)
bpy.types.TEXT_MT_templates.append(menu_func_templates)
bpy.types.RENDER_PT_povray_radiosity.prepend(rad_panel_func)
bpy.types.LIGHT_PT_POV_light.prepend(light_panel_func)
#bpy.types.WORLD_PT_POV_world.prepend(world_panel_func)
# was used for parametric objects but made the other addon unreachable on
# unregister for other tools to use created a user action call instead
#addon_utils.enable("add_mesh_extra_objects", default_set=False, persistent=True)
#bpy.types.TEXTURE_PT_context_texture.prepend(TEXTURE_PT_povray_type)
def unregister():
#from bpy.utils import unregister_class
#bpy.types.TEXTURE_PT_context_texture.remove(TEXTURE_PT_povray_type)
#addon_utils.disable("add_mesh_extra_objects", default_set=False)
#bpy.types.WORLD_PT_POV_world.remove(world_panel_func)
bpy.types.LIGHT_PT_POV_light.remove(light_panel_func)
bpy.types.RENDER_PT_povray_radiosity.remove(rad_panel_func)
bpy.types.TEXT_MT_templates.remove(menu_func_templates)
bpy.types.TOPBAR_MT_file_import.remove(menu_func_import)
bpy.types.VIEW3D_MT_add.remove(menu_func_add)
for cls in reversed(classes):
unregister_class(cls)