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>
Maurice Raybaud
committed
############ To get POV-Ray specific objects In and Out of Blender ###########
import bpy
Maurice Raybaud
committed
from bpy_extras.io_utils import ImportHelper
from bpy_extras import object_utils
from math import atan, pi, degrees, sqrt, cos, sin
from bpy.props import (
StringProperty,
BoolProperty,
IntProperty,
FloatProperty,
FloatVectorProperty,
EnumProperty,
PointerProperty,
CollectionProperty,
)
Maurice Raybaud
committed
from mathutils import (
Vector,
)
#import collections
Maurice Raybaud
committed
def pov_define_mesh(mesh, verts, edges, faces, name, hide_geometry=True):
if mesh is None:
mesh = bpy.data.meshes.new(name)
mesh.from_pydata(verts, edges, faces)
mesh.update()
mesh.validate(False) # Set it to True to see debug messages (helps ensure you generate valid geometry).
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(bpy.types.Operator):
bl_idname = "pov.addlathe"
bl_label = "Lathe"
bl_options = {'REGISTER','UNDO'}
bl_description = "adds lathe"
def execute(self, context):
layers=[False]*20
layers[0]=True
bpy.ops.curve.primitive_bezier_curve_add(location=(0, 0, 0),
rotation=(0, 0, 0), layers=layers)
ob=context.scene.objects.active
ob.name = ob.data.name = "PovLathe"
ob.pov.object_as='LATHE'
bpy.ops.object.mode_set(mode='EDIT')
self.report({'INFO'}, "This native POV-Ray primitive "
Maurice Raybaud
committed
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
"won't have any vertex to show in edit mode")
bpy.ops.transform.rotate(value=-pi/2, axis=(0, 0, 1))
bpy.ops.object.mode_set(mode='OBJECT')
ob.pov.curveshape = "lathe"
bpy.ops.object.modifier_add(type='SCREW')
bpy.context.object.modifiers["Screw"].axis = 'Y'
bpy.context.object.modifiers["Screw"].show_render = False
return {'FINISHED'}
def pov_superellipsoid_define(context, op, ob):
if op:
mesh = None
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
else:
assert(ob)
mesh = ob.data
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 = []
r=1
stepSegment=360/v*pi/180
stepRing=pi/u
angSegment=0
angRing=-pi/2
step=0
for ring in range(0,u-1):
angRing += stepRing
for segment in range(0,v):
step += 1
angSegment += stepSegment
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):
x = -x
y = r*(abs(cos(angRing))**n1)*(abs(sin(angSegment))**n2)
if (cos(angRing) < 0 and sin(angSegment) > 0) or \
(cos(angRing) > 0 and sin(angSegment) < 0):
y = -y
z = r*(abs(sin(angRing))**n1)
if sin(angRing) < 0:
z = -z
x = round(x,4)
y = round(y,4)
z = round(z,4)
verts.append((x,y,z))
if edit == 'TRIANGLES':
verts.append((0,0,1))
verts.append((0,0,-1))
faces = []
for i in range(0,u-2):
m=i*v
for p in range(0,v):
if p < v-1:
face=(m+p,1+m+p,v+1+m+p,v+m+p)
if p == v-1:
face=(m+p,m,v+m,v+m+p)
faces.append(face)
if edit == 'TRIANGLES':
indexUp=len(verts)-2
indexDown=len(verts)-1
indexStartDown=len(verts)-2-v
for i in range(0,v):
if i < v-1:
face=(indexDown,i,i+1)
faces.append(face)
if i == v-1:
face=(indexDown,i,0)
faces.append(face)
for i in range(0,v):
if i < v-1:
face=(indexUp,i+indexStartDown,i+indexStartDown+1)
faces.append(face)
if i == v-1:
face=(indexUp,i+indexStartDown,indexStartDown)
faces.append(face)
if edit == 'NGONS':
face=[]
for i in range(0,v):
face.append(i)
faces.append(face)
face=[]
indexUp=len(verts)-1
for i in range(0,v):
face.append(indexUp-i)
faces.append(face)
mesh = pov_define_mesh(mesh, verts, [], faces, "SuperEllipsoid")
if not ob:
ob_base = object_utils.object_data_add(context, mesh, operator=None)
ob = ob_base.object
#engine = context.scene.render.engine what for?
ob = context.object
ob.name = ob.data.name = "PovSuperellipsoid"
ob.pov.object_as = 'SUPERELLIPSOID'
ob.pov.se_param1 = n2
ob.pov.se_param2 = n1
ob.pov.se_u = u
ob.pov.se_v = v
ob.pov.se_n1 = n1
ob.pov.se_n2 = n2
ob.pov.se_edit = edit
Loading
Loading full blame...