Newer
Older
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
# <pep8 compliant>
""" Get POV-Ray specific objects In and Out of Blender """
import bpy
from bpy_extras.object_utils import object_data_add
Maurice Raybaud
committed
from bpy_extras.io_utils import ImportHelper
from bpy.utils import register_class, unregister_class
from bpy.types import Operator
Maurice Raybaud
committed
from bpy.props import (
StringProperty,
BoolProperty,
IntProperty,
FloatProperty,
FloatVectorProperty,
EnumProperty,
from mathutils import Vector, Matrix
# import collections
Maurice Raybaud
committed
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
def write_object_modifiers(scene, ob, File):
"""Translate some object level POV statements from Blender UI
to POV syntax and write to exported file """
# Maybe return that string to be added instead of directly written.
'''XXX WIP
onceCSG = 0
for mod in ob.modifiers:
if onceCSG == 0:
if mod :
if mod.type == 'BOOLEAN':
if ob.pov.boolean_mod == "POV":
File.write("\tinside_vector <%.6g, %.6g, %.6g>\n" %
(ob.pov.inside_vector[0],
ob.pov.inside_vector[1],
ob.pov.inside_vector[2]))
onceCSG = 1
'''
if ob.pov.hollow:
File.write("\thollow\n")
if ob.pov.double_illuminate:
File.write("\tdouble_illuminate\n")
if ob.pov.sturm:
File.write("\tsturm\n")
if ob.pov.no_shadow:
File.write("\tno_shadow\n")
if ob.pov.no_image:
File.write("\tno_image\n")
if ob.pov.no_reflection:
File.write("\tno_reflection\n")
if ob.pov.no_radiosity:
File.write("\tno_radiosity\n")
if ob.pov.inverse:
File.write("\tinverse\n")
if ob.pov.hierarchy:
File.write("\thierarchy\n")
# XXX, Commented definitions
'''
if scene.pov.photon_enable:
File.write("photons {\n")
if ob.pov.target:
File.write("target %.4g\n"%ob.pov.target_value)
if ob.pov.refraction:
File.write("refraction on\n")
if ob.pov.reflection:
File.write("reflection on\n")
if ob.pov.pass_through:
File.write("pass_through\n")
File.write("}\n")
if ob.pov.object_ior > 1:
File.write("interior {\n")
File.write("ior %.4g\n"%ob.pov.object_ior)
if scene.pov.photon_enable and ob.pov.target and ob.pov.refraction and ob.pov.dispersion:
File.write("ior %.4g\n"%ob.pov.dispersion_value)
File.write("ior %s\n"%ob.pov.dispersion_samples)
if scene.pov.photon_enable == False:
File.write("caustics %.4g\n"%ob.pov.fake_caustics_power)
'''
Maurice Raybaud
committed
def pov_define_mesh(mesh, verts, edges, faces, name, hide_geometry=True):
Maurice Raybaud
committed
if mesh is None:
mesh = bpy.data.meshes.new(name)
mesh.from_pydata(verts, edges, faces)
mesh.update()
mesh.validate(
verbose=False
) # Set it to True to see debug messages (helps ensure you generate valid geometry).
Maurice Raybaud
committed
if hide_geometry:
mesh.vertices.foreach_set("hide", [True] * len(mesh.vertices))
mesh.edges.foreach_set("hide", [True] * len(mesh.edges))
mesh.polygons.foreach_set("hide", [True] * len(mesh.polygons))
return mesh
class POVRAY_OT_lathe_add(Operator):
"""Add the representation of POV lathe using a screw modifier."""
Maurice Raybaud
committed
bl_idname = "pov.addlathe"
bl_label = "Lathe"
bl_options = {'REGISTER', 'UNDO'}
Maurice Raybaud
committed
bl_description = "adds lathe"
def execute(self, context):
# ayers=[False]*20
# layers[0]=True
location=context.scene.cursor.location,
ob = context.view_layer.objects.active
ob_data = ob.data
ob.name = ob_data.name = "PovLathe"
ob_data.dimensions = '2D'
ob_data.transform(Matrix.Rotation(-pi / 2.0, 4, 'Z'))
ob.pov.object_as = 'LATHE'
self.report(
{'INFO'}, "This native POV-Ray primitive" "won't have any vertex to show in edit mode"
)
Maurice Raybaud
committed
ob.pov.curveshape = "lathe"
bpy.ops.object.modifier_add(type='SCREW')
mod = ob.modifiers[-1]
mod.axis = 'Y'
mod.show_render = False
Maurice Raybaud
committed
return {'FINISHED'}
def pov_superellipsoid_define(context, op, ob):
"""Create the proxy mesh of a POV superellipsoid using pov_superellipsoid_define()."""
Maurice Raybaud
committed
Maurice Raybaud
committed
u = op.se_u
v = op.se_v
n1 = op.se_n1
n2 = op.se_n2
edit = op.se_edit
se_param1 = n2 # op.se_param1
se_param2 = n1 # op.se_param2
Maurice Raybaud
committed
u = ob.pov.se_u
v = ob.pov.se_v
n1 = ob.pov.se_n1
n2 = ob.pov.se_n2
edit = ob.pov.se_edit
se_param1 = ob.pov.se_param1
se_param2 = ob.pov.se_param2
verts = []
stepSegment = 360 / v * pi / 180
stepRing = pi / u
angSegment = 0
angRing = -pi / 2
step = 0
for ring in range(0, u - 1):
for segment in range(0, v):
x = r * (abs(cos(angRing)) ** n1) * (abs(cos(angSegment)) ** n2)
if (cos(angRing) < 0 and cos(angSegment) > 0) or (
cos(angRing) > 0 and cos(angSegment) < 0
):
Loading
Loading full blame...