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>
import bpy
from bpy.utils import register_class
from bpy.types import Node, ShaderNodeTree, CompositorNodeTree, TextureNodeTree#, NodeSocket
from bpy.props import (
StringProperty,
BoolProperty,
IntProperty,
FloatProperty,
FloatVectorProperty,
EnumProperty,
#PointerProperty,
#CollectionProperty,
)
class ObjectNodeTree(bpy.types.NodeTree):
'''Povray Material Nodes'''
bl_idname = 'ObjectNodeTree'
bl_label = 'Povray Object Nodes'
bl_icon = 'PLUGIN'
@classmethod
def poll(cls, context):
return context.scene.render.engine == 'POVRAY_RENDER'
@classmethod
def get_from_context(cls, context):
ob = context.active_object
if ob and ob.type not in {'LIGHT'}:
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
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
nt_name = ma.node_tree
if nt_name != '':
return nt_name, ma, ma
return (None, None, None)
def update(self):
self.refresh = True
################### output #############################################################################################
class PovrayOutputNode(Node, ObjectNodeTree):
'''Output'''
bl_idname = 'PovrayOutputNode'
bl_label = 'Output'
bl_icon = 'SOUND'
def init(self, context):
self.inputs.new('PovraySocketTexture', "Texture")
def draw_buttons(self, context, layout):
ob=context.object
layout.prop(ob.pov, "object_ior",slider=True)
def draw_buttons_ext(self, context, layout):
ob=context.object
layout.prop(ob.pov, "object_ior",slider=True)
def draw_label(self):
return "Output"
################### material ###########################################################################################
class PovrayTextureNode(Node, ObjectNodeTree):
'''Texture'''
bl_idname = 'PovrayTextureNode'
bl_label = 'Simple texture'
bl_icon = 'SOUND'
def init(self, context):
color=self.inputs.new('PovraySocketColor', "Pigment")
color.default_value=(1,1,1)
normal=self.inputs.new('NodeSocketFloat', "Normal")
normal.hide_value=True
finish=self.inputs.new('NodeSocketVector', "Finish")
finish.hide_value=True
self.outputs.new('PovraySocketTexture', "Texture")
def draw_label(self):
return "Simple texture"
class PovrayFinishNode(Node, ObjectNodeTree):
'''Finish'''
bl_idname = 'PovrayFinishNode'
bl_label = 'Finish'
bl_icon = 'SOUND'
def init(self, context):
self.inputs.new('PovraySocketFloat_0_1', "Emission")
ambient=self.inputs.new('NodeSocketVector', "Ambient")
ambient.hide_value=True
diffuse=self.inputs.new('NodeSocketVector', "Diffuse")
diffuse.hide_value=True
specular=self.inputs.new('NodeSocketVector', "Highlight")
specular.hide_value=True
mirror=self.inputs.new('NodeSocketVector', "Mirror")
mirror.hide_value=True
iridescence=self.inputs.new('NodeSocketVector', "Iridescence")
iridescence.hide_value=True
subsurface=self.inputs.new('NodeSocketVector', "Translucency")
subsurface.hide_value=True
self.outputs.new('NodeSocketVector', "Finish")
def draw_label(self):
return "Finish"
class PovrayDiffuseNode(Node, ObjectNodeTree):
'''Diffuse'''
bl_idname = 'PovrayDiffuseNode'
bl_label = 'Diffuse'
bl_icon = 'SOUND'
def init(self, context):
intensity=self.inputs.new('PovraySocketFloat_0_1', "Intensity")
intensity.default_value=0.8
albedo=self.inputs.new('NodeSocketBool', "Albedo")
albedo.default_value=False
brilliance=self.inputs.new('PovraySocketFloat_0_10', "Brilliance")
brilliance.default_value=1.8
self.inputs.new('PovraySocketFloat_0_1', "Crand")
self.outputs.new('NodeSocketVector', "Diffuse")
def draw_label(self):
return "Diffuse"
class PovrayPhongNode(Node, ObjectNodeTree):
'''Phong'''
bl_idname = 'PovrayPhongNode'
bl_label = 'Phong'
bl_icon = 'SOUND'
def init(self, context):
albedo=self.inputs.new('NodeSocketBool', "Albedo")
intensity=self.inputs.new('PovraySocketFloat_0_1', "Intensity")
intensity.default_value=0.8
phong_size=self.inputs.new('PovraySocketInt_0_256', "Size")
phong_size.default_value=60
metallic=self.inputs.new('PovraySocketFloat_0_1', "Metallic")
self.outputs.new('NodeSocketVector', "Phong")
def draw_label(self):
return "Phong"
class PovraySpecularNode(Node, ObjectNodeTree):
'''Specular'''
bl_idname = 'PovraySpecularNode'
bl_label = 'Specular'
bl_icon = 'SOUND'
def init(self, context):
albedo=self.inputs.new('NodeSocketBool', "Albedo")
intensity=self.inputs.new('PovraySocketFloat_0_1', "Intensity")
intensity.default_value=0.8
roughness=self.inputs.new('PovraySocketFloat_0_1', "Roughness")
roughness.default_value=0.02
metallic=self.inputs.new('PovraySocketFloat_0_1', "Metallic")
self.outputs.new('NodeSocketVector', "Specular")
def draw_label(self):
return "Specular"
class PovrayMirrorNode(Node, ObjectNodeTree):
'''Mirror'''
bl_idname = 'PovrayMirrorNode'
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
bl_label = 'Mirror'
bl_icon = 'SOUND'
def init(self, context):
color=self.inputs.new('PovraySocketColor', "Color")
color.default_value=(1,1,1)
metallic=self.inputs.new('PovraySocketFloat_0_1', "Metallic")
metallic.default_value=1.0
exponent=self.inputs.new('PovraySocketFloat_0_1', "Exponent")
exponent.default_value=1.0
self.inputs.new('PovraySocketFloat_0_1', "Falloff")
self.inputs.new('NodeSocketBool', "Fresnel")
self.inputs.new('NodeSocketBool', "Conserve energy")
self.outputs.new('NodeSocketVector', "Mirror")
def draw_label(self):
return "Mirror"
class PovrayAmbientNode(Node, ObjectNodeTree):
'''Ambient'''
bl_idname = 'PovrayAmbientNode'
bl_label = 'Ambient'
bl_icon = 'SOUND'
def init(self, context):
self.inputs.new('PovraySocketColor', "Ambient")
self.outputs.new('NodeSocketVector', "Ambient")
def draw_label(self):
return "Ambient"
class PovrayIridescenceNode(Node, ObjectNodeTree):
'''Iridescence'''
bl_idname = 'PovrayIridescenceNode'
bl_label = 'Iridescence'
bl_icon = 'SOUND'
def init(self, context):
amount=self.inputs.new('NodeSocketFloat', "Amount")
amount.default_value=0.25
thickness=self.inputs.new('NodeSocketFloat', "Thickness")
thickness.default_value=1
self.inputs.new('NodeSocketFloat', "Turbulence")
self.outputs.new('NodeSocketVector', "Iridescence")
def draw_label(self):
return "Iridescence"
class PovraySubsurfaceNode(Node, ObjectNodeTree):
'''Subsurface'''
bl_idname = 'PovraySubsurfaceNode'
bl_label = 'Subsurface'
bl_icon = 'SOUND'
def init(self, context):
translucency=self.inputs.new('NodeSocketColor', "Translucency")
translucency.default_value=(0,0,0,1)
energy=self.inputs.new('PovraySocketInt_0_256', "Energy")
energy.default_value=20
self.outputs.new('NodeSocketVector', "Translucency")
def draw_buttons(self, context, layout):
scene=context.scene
layout.prop(scene.pov, "sslt_enable",text="SSLT")
def draw_buttons_ext(self, context, layout):
scene=context.scene
layout.prop(scene.pov, "sslt_enable",text="SSLT")
def draw_label(self):
return "Subsurface"
#####################################################################################################
class PovrayMappingNode(Node, ObjectNodeTree):
'''Mapping'''
bl_idname = 'PovrayMappingNode'
bl_label = 'Mapping'
bl_icon = 'SOUND'
name="Warp Types",
description="Select the type of warp",
items=( ('cubic', "Cubic", ""), ('cylindrical', "Cylindrical", ""),('planar', "Planar", ""),
('spherical', "Spherical", ""),('toroidal', "Toroidal", ""),
('uv_mapping', "UV", ""),
('NONE', "None", "No indentation")),
default='NONE')
name="Warp Orientation",
description="Select the orientation of warp",
items=(('x', "X", ""), ('y', "Y", ""), ('z', "Z", "")),
default='y')
name="Distance exponent",
description="Distance exponent",
min=0.0, max=100.0, default=1.0)
warp_tor_major_radius: FloatProperty(
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
name="Major radius",
description="Torus is distance from major radius",
min=0.0, max=5.0, default=1.0)
def init(self, context):
self.outputs.new('NodeSocketVector', "Mapping")
def draw_buttons(self, context, layout):
column=layout.column()
column.prop(self,"warp_type",text="Warp type")
if self.warp_type in {'toroidal','spherical','cylindrical','planar'}:
column.prop(self,"warp_orientation",text="Orientation")
column.prop(self,"warp_dist_exp",text="Exponent")
if self.warp_type=='toroidal':
column.prop(self,"warp_tor_major_radius",text="Major R")
def draw_buttons_ext(self, context, layout):
column=layout.column()
column.prop(self,"warp_type",text="Warp type")
if self.warp_type in {'toroidal','spherical','cylindrical','planar'}:
column.prop(self,"warp_orientation",text="Orientation")
column.prop(self,"warp_dist_exp",text="Exponent")
if self.warp_type=='toroidal':
column.prop(self,"warp_tor_major_radius",text="Major R")
def draw_label(self):
return "Mapping"
class PovrayMultiplyNode(Node, ObjectNodeTree):
'''Multiply'''
bl_idname = 'PovrayMultiplyNode'
bl_label = 'Multiply'
bl_icon = 'SOUND'
amount_x : FloatProperty(
name="X",
description="Number of repeats",
min=1.0, max=10000.0, default=1.0)
amount_y : FloatProperty(
name="Y",
description="Number of repeats",
min=1.0, max=10000.0, default=1.0)
amount_z : FloatProperty(
name="Z",
description="Number of repeats",
min=1.0, max=10000.0, default=1.0)
def init(self, context):
self.outputs.new('NodeSocketVector', "Amount")
def draw_buttons(self, context, layout):
column=layout.column()
column.label(text="Amount")
row=column.row(align=True)
row.prop(self,"amount_x")
row.prop(self,"amount_y")
row.prop(self,"amount_z")
def draw_buttons_ext(self, context, layout):
column=layout.column()
column.label(text="Amount")
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
row=column.row(align=True)
row.prop(self,"amount_x")
row.prop(self,"amount_y")
row.prop(self,"amount_z")
def draw_label(self):
return "Multiply"
class PovrayTransformNode(Node, ObjectNodeTree):
'''Transform'''
bl_idname = 'PovrayTransformNode'
bl_label = 'Transform'
bl_icon = 'SOUND'
def init(self, context):
self.inputs.new('PovraySocketFloatUnlimited', "Translate x")
self.inputs.new('PovraySocketFloatUnlimited', "Translate y")
self.inputs.new('PovraySocketFloatUnlimited', "Translate z")
self.inputs.new('PovraySocketFloatUnlimited', "Rotate x")
self.inputs.new('PovraySocketFloatUnlimited', "Rotate y")
self.inputs.new('PovraySocketFloatUnlimited', "Rotate z")
sX = self.inputs.new('PovraySocketFloatUnlimited', "Scale x")
sX.default_value = 1.0
sY = self.inputs.new('PovraySocketFloatUnlimited', "Scale y")
sY.default_value = 1.0
sZ = self.inputs.new('PovraySocketFloatUnlimited', "Scale z")
sZ.default_value = 1.0
self.outputs.new('NodeSocketVector', "Transform")
def draw_label(self):
return "Transform"
class PovrayValueNode(Node, ObjectNodeTree):
'''Value'''
bl_idname = 'PovrayValueNode'
bl_label = 'Value'
bl_icon = 'SOUND'
def init(self, context):
self.outputs.new('PovraySocketUniversal', "Value")
def draw_label(self):
return "Value"
class PovrayModifierNode(Node, ObjectNodeTree):
'''Modifier'''
bl_idname = 'PovrayModifierNode'
bl_label = 'Modifier'
bl_icon = 'SOUND'
def init(self, context):
turb_x=self.inputs.new('PovraySocketFloat_0_10', "Turb X")
turb_x.default_value=0.1
turb_y=self.inputs.new('PovraySocketFloat_0_10', "Turb Y")
turb_y.default_value=0.1
turb_z=self.inputs.new('PovraySocketFloat_0_10', "Turb Z")
turb_z.default_value=0.1
octaves=self.inputs.new('PovraySocketInt_1_9', "Octaves")
octaves.default_value=1
lambat=self.inputs.new('PovraySocketFloat_0_10', "Lambda")
lambat.default_value=2.0
omega=self.inputs.new('PovraySocketFloat_0_10', "Omega")
omega.default_value=0.5
freq=self.inputs.new('PovraySocketFloat_0_10', "Frequency")
freq.default_value=2.0
self.inputs.new('PovraySocketFloat_0_10', "Phase")
self.outputs.new('NodeSocketVector', "Modifier")
def draw_label(self):
return "Modifier"
class PovrayPigmentNode(Node, ObjectNodeTree):
'''Pigment'''
bl_idname = 'PovrayPigmentNode'
bl_label = 'Color'
def init(self, context):
color = self.inputs.new('PovraySocketColor', "Color")
color.default_value = (1,1,1)
povfilter = self.inputs.new('PovraySocketFloat_0_1', "Filter")
transmit = self.inputs.new('PovraySocketFloat_0_1', "Transmit")
self.outputs.new('NodeSocketColor', "Pigment")
def draw_label(self):
return "Color"
class PovrayColorImageNode(Node, ObjectNodeTree):
'''ColorImage'''
bl_idname = 'PovrayColorImageNode'
bl_label = 'Image map'
map_type: bpy.props.EnumProperty(
name="Map type",
description="",
items=( ('uv_mapping', "UV", ""),
('0', "Planar", "Default planar mapping"),
('1', "Spherical", "Spherical mapping"),
('2', "Cylindrical", "Cylindrical mapping"),
('5', "Torroidal", "Torus or donut shaped mapping")),
image: StringProperty(maxlen=1024) # , subtype="FILE_PATH"
interpolate: EnumProperty(
description="Adding the interpolate keyword can smooth the jagged look of a bitmap",
items=(
('2', "Bilinear", "Gives bilinear interpolation"),
('4', "Normalized", "Gives normalized distance"),
),
premultiplied: BoolProperty(default=False)
once: BoolProperty(description="Not to repeat", default=False)
def init(self, context):
gamma=self.inputs.new('PovraySocketFloat_000001_10', "Gamma")
gamma.default_value=2.0
transmit=self.inputs.new('PovraySocketFloat_0_1', "Transmit")
povfilter=self.inputs.new('PovraySocketFloat_0_1', "Filter")
mapping=self.inputs.new('NodeSocketVector', "Mapping")
mapping.hide_value=True
transform=self.inputs.new('NodeSocketVector', "Transform")
transform.hide_value=True
modifier=self.inputs.new('NodeSocketVector', "Modifier")
modifier.hide_value=True
self.outputs.new('NodeSocketColor', "Pigment")
def draw_buttons(self, context, layout):
column=layout.column()
im=None
for image in bpy.data.images:
if image.name == self.image:
im=image
split.prop_search(self,"image",context.blend_data,"images",text="")
split.operator("pov.imageopen",text="",icon="FILEBROWSER")
column.prop(im,"source",text="")
column.prop(self,"map_type",text="")
column.prop(self,"interpolate",text="")
row=column.row()
row.prop(self,"premultiplied",text="Premul")
row.prop(self,"once",text="Once")
def draw_buttons_ext(self, context, layout):
column=layout.column()
im=None
for image in bpy.data.images:
if image.name == self.image:
im=image
split.prop_search(self,"image",context.blend_data,"images",text="")
split.operator("pov.imageopen",text="",icon="FILEBROWSER")
column.prop(im,"source",text="")
column.prop(self,"map_type",text="")
column.prop(self,"interpolate",text="")
row=column.row()
row.prop(self,"premultiplied",text="Premul")
row.prop(self,"once",text="Once")
def draw_label(self):
return "Image map"
class PovrayBumpMapNode(Node, ObjectNodeTree):
'''BumpMap'''
bl_idname = 'PovrayBumpMapNode'
bl_label = 'Bump map'
bl_icon = 'SOUND'
map_type : bpy.props.EnumProperty(
name="Map type",
description="",
items=(
('uv_mapping', "UV", ""),
('0', "Planar", "Default planar mapping"),
('1', "Spherical", "Spherical mapping"),
('2', "Cylindrical", "Cylindrical mapping"),
('5', "Torroidal", "Torus or donut shaped mapping")
),
image : StringProperty(maxlen=1024) # , subtype="FILE_PATH"
interpolate : EnumProperty(
description="Adding the interpolate keyword can smooth the jagged look of a bitmap",
items=(
('2', "Bilinear", "Gives bilinear interpolation"),
('4', "Normalized", "Gives normalized distance"),
),
once : BoolProperty(description="Not to repeat", default=False)
def init(self, context):
self.inputs.new('PovraySocketFloat_0_10', "Normal")
mapping=self.inputs.new('NodeSocketVector', "Mapping")
mapping.hide_value=True
transform=self.inputs.new('NodeSocketVector', "Transform")
transform.hide_value=True
modifier=self.inputs.new('NodeSocketVector', "Modifier")
modifier.hide_value=True
normal=self.outputs.new('NodeSocketFloat', "Normal")
normal.hide_value=True
def draw_buttons(self, context, layout):
column=layout.column()
im=None
for image in bpy.data.images:
if image.name == self.image:
im=image
split = column.split(percentage=0.8,align=True)
split.prop_search(self,"image",context.blend_data,"images",text="")
split.operator("pov.imageopen",text="",icon="FILEBROWSER")
column.prop(im,"source",text="")
column.prop(self,"map_type",text="")
column.prop(self,"interpolate",text="")
column.prop(self,"once",text="Once")
def draw_buttons_ext(self, context, layout):
column=layout.column()
im=None
for image in bpy.data.images:
if image.name == self.image:
im=image
split = column.split(percentage=0.8,align=True)
split.prop_search(self,"image",context.blend_data,"images",text="")
split.operator("pov.imageopen",text="",icon="FILEBROWSER")
column.prop(im,"source",text="")
column.prop(self,"map_type",text="")
column.prop(self,"interpolate",text="")
column.prop(self,"once",text="Once")
def draw_label(self):
return "Bump Map"
class PovrayImagePatternNode(Node, ObjectNodeTree):
'''ImagePattern'''
bl_idname = 'PovrayImagePatternNode'
bl_label = 'Image pattern'
bl_icon = 'SOUND'
map_type: bpy.props.EnumProperty(
name="Map type",
description="",
items=(
('uv_mapping', "UV", ""),
('0', "Planar", "Default planar mapping"),
('1', "Spherical", "Spherical mapping"),
('2', "Cylindrical", "Cylindrical mapping"),
('5', "Torroidal", "Torus or donut shaped mapping"),
),
image: StringProperty(maxlen=1024) # , subtype="FILE_PATH"
interpolate: EnumProperty(
description="Adding the interpolate keyword can smooth the jagged look of a bitmap",
items=(
('2', "Bilinear", "Gives bilinear interpolation"),
('4', "Normalized", "Gives normalized distance"),
),
premultiplied: BoolProperty(default=False)
once: BoolProperty(description="Not to repeat", default=False)
use_alpha: BoolProperty(default=True)
def init(self, context):
gamma=self.inputs.new('PovraySocketFloat_000001_10', "Gamma")
gamma.default_value=2.0
self.outputs.new('PovraySocketPattern', "Pattern")
def draw_buttons(self, context, layout):
column=layout.column()
im=None
for image in bpy.data.images:
if image.name == self.image:
im=image
split.prop_search(self,"image",context.blend_data,"images",text="")
split.operator("pov.imageopen",text="",icon="FILEBROWSER")
column.prop(im,"source",text="")
column.prop(self,"map_type",text="")
column.prop(self,"interpolate",text="")
row=column.row()
row.prop(self,"premultiplied",text="Premul")
row.prop(self,"once",text="Once")
column.prop(self,"use_alpha",text="Use alpha")
def draw_buttons_ext(self, context, layout):
column=layout.column()
im=None
for image in bpy.data.images:
if image.name == self.image:
im=image
split.prop_search(self,"image",context.blend_data,"images",text="")
split.operator("pov.imageopen",text="",icon="FILEBROWSER")
column.prop(im,"source",text="")
column.prop(self,"map_type",text="")
column.prop(self,"interpolate",text="")
row=column.row()
row.prop(self,"premultiplied",text="Premul")
row.prop(self,"once",text="Once")
def draw_label(self):
return "Image pattern"
class ShaderPatternNode(Node, ObjectNodeTree):
'''Pattern'''
bl_idname = 'ShaderPatternNode'
bl_label = 'Other patterns'
pattern : EnumProperty(
name="Pattern",
description="Agate, Crackle, Gradient, Pavement, Spiral, Tiling",
items=(('agate', "Agate", ""),('crackle', "Crackle", ""),('gradient', "Gradient", ""),
('pavement', "Pavement", ""),
('spiral1', "Spiral 1", ""),
('spiral2', "Spiral 2", ""),
('tiling', "Tiling", "")),
default='agate')
agate_turb : FloatProperty(
name="Agate turb",
description="Agate turbulence",
min=0.0, max=100.0, default=0.5)
crackle_form_x : FloatProperty(
name="X",
description="Form vector X",
min=-150.0, max=150.0, default=-1)
crackle_form_y : FloatProperty(
name="Y",
description="Form vector Y",
min=-150.0, max=150.0, default=1)
crackle_form_z : FloatProperty(
name="Z",
description="Form vector Z",
min=-150.0, max=150.0, default=0)
crackle_metric : FloatProperty(
name="Metric",
description="Crackle metric",
min=0.0, max=150.0, default=1)
crackle_solid : BoolProperty(
name="Solid",
description="Crackle solid",
default=False)
spiral_arms : FloatProperty(
name="Number",
description="",
tiling_number : IntProperty(
name="Number",
description="",
gradient_orient : EnumProperty(
name="Orient",
description="",
items=(('x', "X", ""),
('y', "Y", ""),
('z', "Z", "")),
def init(self, context):
pat = self.outputs.new('PovraySocketPattern', "Pattern")
def draw_buttons(self, context, layout):
layout.prop(self, "pattern",text="")
if self.pattern=='agate':
layout.prop(self, "agate_turb")
if self.pattern=='crackle':
layout.prop(self, "crackle_metric")
layout.prop(self, "crackle_solid")
layout.label(text="Form:")
layout.prop(self, "crackle_form_x")
layout.prop(self, "crackle_form_y")
layout.prop(self, "crackle_form_z")
if self.pattern in {"spiral1","spiral2"}:
layout.prop(self, "spiral_arms")
if self.pattern in {'tiling'}:
layout.prop(self, "tiling_number")
if self.pattern in {'gradient'}:
layout.prop(self, "gradient_orient")
def draw_buttons_ext(self, context, layout):
pass
def draw_label(self):
return "Other patterns"
class ShaderTextureMapNode(Node, ObjectNodeTree):
'''Texture Map'''
bl_idname = 'ShaderTextureMapNode'
bl_label = 'Texture map'
name="Y",
description="",
min=0.0000, max=1.0000, default=0.0525)
name="Mortar",
description="Mortar",
min=0.000, max=1.500, default=0.01)
def init(self, context):
mat = bpy.context.object.active_material
self.inputs.new('PovraySocketPattern', "")
color = self.inputs.new('NodeSocketColor', "Color ramp")
color.hide_value = True
for i in range(0,4):
transform=self.inputs.new('PovraySocketTransform', "Transform")
transform.hide_value=True
number = mat.pov.inputs_number
for i in range(number):
self.inputs.new('PovraySocketTexture', "%s"%i)
self.outputs.new('PovraySocketTexture', "Texture")
def draw_buttons(self, context, layout):
if self.inputs[0].default_value =='brick':
layout.prop(self, "brick_mortar")
layout.prop(self, "brick_size_x")
layout.prop(self, "brick_size_y")
layout.prop(self, "brick_size_z")
def draw_buttons_ext(self, context, layout):
if self.inputs[0].default_value =='brick':
layout.prop(self, "brick_mortar")
layout.prop(self, "brick_size_x")
layout.prop(self, "brick_size_y")
layout.prop(self, "brick_size_z")
def draw_label(self):
return "Texture map"
class ShaderNormalMapNode(Node, ObjectNodeTree):
'''Normal Map'''
bl_idname = 'ShaderNormalMapNode'
bl_label = 'Normal map'
brick_size_x : FloatProperty(
brick_size_y : FloatProperty(
name="Y",
description="",
min=0.0000, max=1.0000, default=0.0525)
brick_size_z : FloatProperty(
brick_mortar : FloatProperty(
name="Mortar",
description="Mortar",
min=0.000, max=1.500, default=0.01)
def init(self, context):
self.inputs.new('PovraySocketPattern', "")
normal = self.inputs.new('PovraySocketFloat_10', "Normal")
slope = self.inputs.new('PovraySocketMap', "Slope map")
for i in range(0,4):
transform=self.inputs.new('PovraySocketTransform', "Transform")
transform.hide_value=True
self.outputs.new('PovraySocketNormal', "Normal")
def draw_buttons(self, context, layout):
#for i, inp in enumerate(self.inputs):
if self.inputs[0].default_value =='brick':
layout.prop(self, "brick_mortar")
layout.label(text="Brick size:")
layout.prop(self, "brick_size_x")
layout.prop(self, "brick_size_y")
layout.prop(self, "brick_size_z")
def draw_buttons_ext(self, context, layout):
if self.inputs[0].default_value =='brick':
layout.prop(self, "brick_mortar")
layout.label(text="Brick size:")
layout.prop(self, "brick_size_x")
layout.prop(self, "brick_size_y")
layout.prop(self, "brick_size_z")
def draw_label(self):
return "Normal map"
class ShaderNormalMapEntryNode(Node, ObjectNodeTree):
'''Normal Map Entry'''
bl_idname = 'ShaderNormalMapEntryNode'
bl_label = 'Normal map entry'
def init(self, context):
self.inputs.new('PovraySocketFloat_0_1', "Stop")
self.inputs.new('PovraySocketFloat_0_1', "Gray")
def draw_label(self):
return "Normal map entry"
class IsoPropsNode(Node, CompositorNodeTree):
'''ISO Props'''
bl_idname = 'IsoPropsNode'
bl_label = 'Iso'
node_label : StringProperty(maxlen=1024)
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
def init(self, context):
ob = bpy.context.object
self.node_label = ob.name
textName = ob.pov.function_text
if textName:
text = bpy.data.texts[textName]
for line in text.lines:
split = line.body.split()
if split[0] == "#declare":
socket = self.inputs.new('NodeSocketFloat', "%s"%split[1])
value = split[3].split(";")
value = value[0]
socket.default_value=float(value)
def draw_label(self):
return self.node_label
class PovrayFogNode(Node, CompositorNodeTree):
'''Fog settings'''
bl_idname = 'PovrayFogNode'
bl_label = 'Fog'
def init(self, context):
color=self.inputs.new('NodeSocketColor', "Color")
color.default_value=(0.7,0.7,0.7,0.25)
self.inputs.new('PovraySocketFloat_0_1', "Filter")
distance = self.inputs.new('NodeSocketInt', "Distance")
distance.default_value=150
self.inputs.new('NodeSocketBool', "Ground")
fog_offset=self.inputs.new('NodeSocketFloat', "Offset")
fog_alt=self.inputs.new('NodeSocketFloat', "Altitude")
turb = self.inputs.new('NodeSocketVector', "Turbulence")
turb_depth=self.inputs.new('PovraySocketFloat_0_10', "Depth")
turb_depth.default_value=0.5
octaves=self.inputs.new('PovraySocketInt_1_9', "Octaves")
octaves.default_value=5
lambdat=self.inputs.new('PovraySocketFloat_0_10', "Lambda")
lambdat.default_value=1.25
omega=self.inputs.new('PovraySocketFloat_0_10', "Omega")
omega.default_value=0.35
translate = self.inputs.new('NodeSocketVector', "Translate")
rotate = self.inputs.new('NodeSocketVector', "Rotate")
scale = self.inputs.new('NodeSocketVector', "Scale")
scale.default_value=(1,1,1)
def draw_label(self):
return "Fog"
class PovraySlopeNode(Node, TextureNodeTree):
'''Output'''
bl_idname = 'PovraySlopeNode'
bl_label = 'Slope Map'
def init(self, context):
self.use_custom_color = True
self.color = (0,0.2,0)
slope = self.inputs.new('PovraySocketSlope', "0")
slope = self.inputs.new('PovraySocketSlope', "1")
slopemap = self.outputs.new('PovraySocketMap', "Slope map")
output.hide_value = True
def draw_buttons(self, context, layout):
layout.operator("pov.nodeinputadd")
row = layout.row()
row.label(text='Value')
row.label(text='Height')
row.label(text='Slope')
def draw_buttons_ext(self, context, layout):
layout.operator("pov.nodeinputadd")
row = layout.row()
row.label(text='Value')
row.label(text='Height')
row.label(text='Slope')
def draw_label(self):
return "Slope Map"
######################################## Texture nodes ###############################
class TextureOutputNode(Node, TextureNodeTree):
'''Output'''
bl_idname = 'TextureOutputNode'
bl_label = 'Color Map'
def init(self, context):
tex = bpy.context.object.active_material.active_texture
num_sockets = int(tex.pov.density_lines/32)
for i in range(num_sockets):
color = self.inputs.new('NodeSocketColor', "%s"%i)
color.hide_value = True
def draw_buttons(self, context, layout):
layout.label(text="Color Ramps:")
def draw_label(self):
return "Color Map"
##################################################################################
#################################Operators########################################
##################################################################################
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
class NODE_OT_iso_add(bpy.types.Operator):
bl_idname = "pov.nodeisoadd"
bl_label = "Create iso props"
def execute(self, context):
ob = bpy.context.object
if bpy.context.scene.use_nodes == False:
bpy.context.scene.use_nodes = True
tree = bpy.context.scene.node_tree
for node in tree.nodes:
if node.bl_idname == "IsoPropsNode" and node.label == ob.name:
tree.nodes.remove(node)
isonode = tree.nodes.new('IsoPropsNode')
isonode.location = (0,0)
isonode.label = ob.name
return {'FINISHED'}
class NODE_OT_map_create(bpy.types.Operator):
bl_idname = "node.map_create"
bl_label = "Create map"
def execute(self, context):
x = y = 0
space = context.space_data
tree = space.edit_tree
for node in tree.nodes:
if node.select == True:
x,y = node.location
node.select=False
tmap = tree.nodes.new('ShaderTextureMapNode')
tmap.location = (x - 200,y)
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_props_dialog(self)
def draw(self, context):
layout = self.layout
mat = context.object.active_material
layout.prop(mat.pov,"inputs_number")
class NODE_OT_povray_node_texture_map_add(bpy.types.Operator):
bl_idname = "pov.nodetexmapadd"
bl_label = "Texture map"
def execute(self, context):
tree=bpy.context.object.active_material.node_tree
tmap = tree.nodes.active
bpy.context.object.active_material.node_tree.nodes.active=tmap
el=tmap.color_ramp.elements.new(0.5)
for el in tmap.color_ramp.elements:
el.color=(0,0,0,1)
for inp in tmap.inputs:
tmap.inputs.remove(inp)
for outp in tmap.outputs:
tmap.outputs.remove(outp)
pattern=tmap.inputs.new('NodeSocketVector', "Pattern")
pattern.hide_value=True
for i in range(0,3):
tmap.inputs.new('NodeSocketColor', "Shader")
tmap.outputs.new('NodeSocketShader', "BSDF")
tmap.label="Texture Map"
return {'FINISHED'}
class NODE_OT_povray_node_output_add(bpy.types.Operator):
bl_idname = "pov.nodeoutputadd"
bl_label = "Output"
def execute(self, context):
tree=bpy.context.object.active_material.node_tree
tmap = tree.nodes.new('ShaderNodeOutputMaterial')
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
bpy.context.object.active_material.node_tree.nodes.active=tmap
for inp in tmap.inputs:
tmap.inputs.remove(inp)
tmap.inputs.new('NodeSocketShader', "Surface")
tmap.label="Output"
return {'FINISHED'}
class NODE_OT_povray_node_layered_add(bpy.types.Operator):
bl_idname = "pov.nodelayeredadd"
bl_label = "Layered material"
def execute(self, context):
tree=bpy.context.object.active_material.node_tree
tmap = tree.nodes.new('ShaderNodeAddShader')
bpy.context.object.active_material.node_tree.nodes.active=tmap
tmap.label="Layered material"
return {'FINISHED'}
class NODE_OT_povray_input_add(bpy.types.Operator):
bl_idname = "pov.nodeinputadd"
bl_label = "Add entry"
def execute(self, context):
node=bpy.context.object.active_material.node_tree.nodes.active
if node.type in {'VALTORGB'}:
number=1
for inp in node.inputs:
if inp.type=='SHADER':
number+=1
node.inputs.new('NodeSocketShader', "%s"%number)
els=node.color_ramp.elements
pos1=els[len(els)-1].position
pos2=els[len(els)-2].position
pos=(pos1-pos2)/2+pos2
el=els.new(pos)
if node.bl_idname == 'PovraySlopeNode':
number=len(node.inputs)
node.inputs.new('PovraySocketSlope', "%s"%number)
return {'FINISHED'}
class NODE_OT_povray_input_remove(bpy.types.Operator):
bl_idname = "pov.nodeinputremove"
bl_label = "Remove input"
def execute(self, context):
node=bpy.context.object.active_material.node_tree.nodes.active
if node.type in {'VALTORGB','ADD_SHADER'}:
number=len(node.inputs)-1
if number > 5:
inp=node.inputs[number]
node.inputs.remove(inp)
if node.type in {'VALTORGB'}:
els=node.color_ramp.elements
number=len(els)-2
el=els[number]
els.remove(el)
return {'FINISHED'}
class NODE_OT_povray_image_open(bpy.types.Operator):
bl_idname = "pov.imageopen"
bl_label = "Open"
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
name="File Path",
description="Open image",
maxlen=1024,
subtype='FILE_PATH',
)
def invoke(self, context, event):
context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'}
def execute(self, context):
im=bpy.data.images.load(self.filepath)
node=context.object.active_material.node_tree.nodes.active
node.image = im.name
return {'FINISHED'}
# class TEXTURE_OT_povray_open_image(bpy.types.Operator):
# bl_idname = "pov.openimage"
# bl_label = "Open Image"
# filepath = StringProperty(
# name="File Path",
# description="Open image",
# maxlen=1024,
# subtype='FILE_PATH',
# )
# def invoke(self, context, event):
# context.window_manager.fileselect_add(self)
# return {'RUNNING_MODAL'}
# def execute(self, context):
# im=bpy.data.images.load(self.filepath)
# tex = context.texture
# tex.pov.image = im.name
# view_layer = context.view_layer
# view_layer.update()
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
# return {'FINISHED'}
class PovrayPatternNode(bpy.types.Operator):
bl_idname = "pov.patternnode"
bl_label = "Pattern"
add=True
def execute(self, context):
space = context.space_data
tree = space.edit_tree
for node in tree.nodes:
node.select=False
if self.add==True:
tmap = tree.nodes.new('ShaderNodeValToRGB')
tmap.label="Pattern"
for inp in tmap.inputs:
tmap.inputs.remove(inp)
for outp in tmap.outputs:
tmap.outputs.remove(outp)
pattern = tmap.inputs.new('PovraySocketPattern', "Pattern")
pattern.hide_value = True
mapping=tmap.inputs.new('NodeSocketVector', "Mapping")
mapping.hide_value=True
transform=tmap.inputs.new('NodeSocketVector', "Transform")
transform.hide_value=True
modifier=tmap.inputs.new('NodeSocketVector', "Modifier")
modifier.hide_value=True
for i in range(0,2):
tmap.inputs.new('NodeSocketShader', "%s"%(i+1))
tmap.outputs.new('NodeSocketShader', "Material")
tmap.outputs.new('NodeSocketColor', "Color")
tree.nodes.active=tmap
self.add=False
aNode=tree.nodes.active
aNode.select=True
v2d = context.region.view2d
x, y = v2d.region_to_view(self.x, self.y)
aNode.location = (x, y)
def modal(self, context, event):
if event.type == 'MOUSEMOVE':
self.x = event.mouse_region_x
self.y = event.mouse_region_y
self.execute(context)
return {'RUNNING_MODAL'}
elif event.type == 'LEFTMOUSE':
return {'FINISHED'}
elif event.type in ('RIGHTMOUSE', 'ESC'):
return {'CANCELLED'}
return {'RUNNING_MODAL'}
def invoke(self, context, event):
context.window_manager.modal_handler_add(self)
return {'RUNNING_MODAL'}
class UpdatePreviewMaterial(bpy.types.Operator):
'''Operator update preview material'''
bl_idname = "node.updatepreview"
bl_label = "Update preview"
def execute(self, context):
ob=context.object
for obj in scene.objects:
if obj != ob:
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
def modal(self, context, event):
if event.type == 'RIGHTMOUSE':
self.execute(context)
return {'FINISHED'}
return {'PASS_THROUGH'}
def invoke(self, context, event):
context.window_manager.modal_handler_add(self)
return {'RUNNING_MODAL'}
class UpdatePreviewKey(bpy.types.Operator):
'''Operator update preview keymap'''
bl_idname = "wm.updatepreviewkey"
bl_label = "Activate RMB"
@classmethod
def poll(cls, context):
conf = context.window_manager.keyconfigs.active
mapstr = "Node Editor"
map = conf.keymaps[mapstr]
try:
map.keymap_items["node.updatepreview"]
return False
except:
return True
def execute(self, context):
conf = context.window_manager.keyconfigs.active
mapstr = "Node Editor"
map = conf.keymaps[mapstr]
map.keymap_items.new("node.updatepreview",type='RIGHTMOUSE',value="PRESS")
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
classes = (
ObjectNodeTree,
PovrayOutputNode,
PovrayTextureNode,
PovrayFinishNode,
PovrayDiffuseNode,
PovrayPhongNode,
PovraySpecularNode,
PovrayMirrorNode,
PovrayAmbientNode,
PovrayIridescenceNode,
PovraySubsurfaceNode,
PovrayMappingNode,
PovrayMultiplyNode,
PovrayTransformNode,
PovrayValueNode,
PovrayModifierNode,
PovrayPigmentNode,
PovrayColorImageNode,
PovrayBumpMapNode,
PovrayImagePatternNode,
ShaderPatternNode,
ShaderTextureMapNode,
ShaderNormalMapNode,
ShaderNormalMapEntryNode,
IsoPropsNode,
PovrayFogNode,
PovraySlopeNode,
TextureOutputNode,
NODE_OT_iso_add,
NODE_OT_map_create,
NODE_OT_povray_node_texture_map_add,
NODE_OT_povray_node_output_add,
NODE_OT_povray_node_layered_add,
NODE_OT_povray_input_add,
NODE_OT_povray_input_remove,
NODE_OT_povray_image_open,
PovrayPatternNode,
UpdatePreviewMaterial,
UpdatePreviewKey,
)
def register():
#from bpy.utils import register_class
for cls in classes:
register_class(cls)
def unregister():
from bpy.utils import unregister_class
for cls in classes:
unregister_class(cls)