Import_3ds: Improved distance cue node setup
[blender-addons.git] / render_povray / shading_properties.py
blob0e8435a7607503677393e02305c0ac7a382a7a3d
1 # SPDX-FileCopyrightText: 2021-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 """Declare shading properties exported to POV textures."""
6 import bpy
7 from bpy.utils import register_class, unregister_class
8 from bpy.types import PropertyGroup
9 from bpy.props import (
10 FloatVectorProperty,
11 StringProperty,
12 BoolProperty,
13 IntProperty,
14 FloatProperty,
15 EnumProperty,
16 PointerProperty,
20 def check_material(mat):
21 """Check that material node tree is not empty if use node button is on"""
22 if mat is not None:
23 return not mat.node_tree if mat.use_nodes else True
24 return False
27 def pov_context_tex_datablock(context):
28 """Texture context type recreated as deprecated in blender 2.8"""
30 idblock = context.brush
31 if idblock and context.scene.texture_context == "OTHER":
32 return idblock
34 # idblock = bpy.context.active_object.active_material
35 idblock = context.view_layer.objects.active.active_material
36 if idblock and context.scene.texture_context == "MATERIAL":
37 return idblock
39 idblock = context.scene.world
40 if idblock and context.scene.texture_context == "WORLD":
41 return idblock
43 idblock = context.light
44 if idblock and context.scene.texture_context == "LIGHT":
45 return idblock
47 if context.particle_system and context.scene.texture_context == "PARTICLES":
48 idblock = context.particle_system.settings
50 idblock = context.line_style
51 if idblock and context.scene.texture_context == "LINESTYLE":
52 return idblock
54 return idblock
57 def active_texture_name_from_uilist(self, context):
58 """Name created texture slots the same as created texture"""
59 idblock = pov_context_tex_datablock(context)
60 # mat = context.view_layer.objects.active.active_material
61 if idblock is not None:
62 index = idblock.pov.active_texture_index
63 name = idblock.pov_texture_slots[index].name
64 newname = idblock.pov_texture_slots[index].texture
65 tex = bpy.data.textures[name]
66 tex.name = newname
67 idblock.pov_texture_slots[index].name = newname
70 def active_texture_name_from_search(self, context):
71 """Texture rolldown to change the data linked by an existing texture"""
72 idblock = pov_context_tex_datablock(context)
73 # mat = context.view_layer.objects.active.active_material
74 if idblock is not None:
75 index = idblock.pov.active_texture_index
76 slot = idblock.pov_texture_slots[index]
77 name = slot.texture_search
79 try:
80 # tex = bpy.data.textures[name]
81 slot.name = name
82 slot.texture = name
83 # Switch paint brush to this texture so settings remain contextual
84 # bpy.context.tool_settings.image_paint.brush.texture = tex
85 # bpy.context.tool_settings.image_paint.brush.mask_texture = tex
86 except BaseException as e:
87 print(e.__doc__)
88 print("An exception occurred: {}".format(e))
91 def brush_texture_update(self, context):
93 """Brush texture rolldown must show active slot texture props"""
94 idblock = pov_context_tex_datablock(context)
95 if idblock is not None:
96 # mat = context.view_layer.objects.active.active_material
97 idblock = pov_context_tex_datablock(context)
98 slot = idblock.pov_texture_slots[idblock.pov.active_texture_index]
99 if tex := slot.texture:
100 # Switch paint brush to active texture so slot and settings remain contextual
101 # bpy.ops.pov.textureslotupdate()
102 bpy.context.tool_settings.image_paint.brush.texture = bpy.data.textures[tex]
103 bpy.context.tool_settings.image_paint.brush.mask_texture = bpy.data.textures[tex]
106 class RenderPovSettingsMaterial(PropertyGroup):
107 """Declare material level properties controllable in UI and translated to POV."""
109 # --------------------------- Begin Old Blender Internal Props --------------------------- #
110 # former Space properties from removed Blender Internal
111 use_limited_texture_context: BoolProperty(
112 name="",
113 description="Use the limited version of texture user (for ‘old shading’ mode)",
114 default=True,
116 texture_context: EnumProperty(
117 name="Texture context",
118 description="Type of texture data to display and edit",
119 items=(
120 ("MATERIAL", "", "Show material textures", "MATERIAL", 0), # "Show material textures"
121 ("WORLD", "", "Show world textures", "WORLD", 1), # "Show world textures"
122 ("LAMP", "", "Show lamp textures", "LIGHT", 2), # "Show lamp textures"
124 "PARTICLES",
126 "Show particles textures",
127 "PARTICLES",
129 ), # "Show particles textures"
131 "LINESTYLE",
133 "Show linestyle textures",
134 "LINE_DATA",
136 ), # "Show linestyle textures"
138 "OTHER",
140 "Show other data textures",
141 "TEXTURE_DATA",
143 ), # "Show other data textures"
145 default="MATERIAL",
148 active_texture_index: IntProperty(
149 name="Index for texture_slots", default=0, update=brush_texture_update
152 transparency_method: EnumProperty(
153 name="Specular Shader Model",
154 description="Method to use for rendering transparency",
155 items=(
156 ("MASK", "Mask", "Mask the background"),
157 ("Z_TRANSPARENCY", "Z Transparency", "Use alpha buffer for transparent faces"),
158 ("RAYTRACE", "Raytrace", "Use raytracing for transparent refraction rendering"),
160 default="MASK",
163 use_transparency: BoolProperty(
164 name="Transparency", description="Render material as transparent", default=False
167 alpha: FloatProperty(
168 name="Alpha",
169 description="Alpha transparency of the material",
170 min=0.0,
171 max=1.0,
172 soft_min=0.0,
173 soft_max=1.0,
174 default=1.0,
175 precision=3,
178 specular_alpha: FloatProperty(
179 name="Specular alpha",
180 description="Alpha transparency for specular areas",
181 min=0.0,
182 max=1.0,
183 soft_min=0.0,
184 soft_max=1.0,
185 default=1.0,
186 precision=3,
189 ambient: FloatProperty(
190 name="Ambient",
191 description="Amount of global ambient color the material receives",
192 min=0.0,
193 max=1.0,
194 soft_min=0.0,
195 soft_max=1.0,
196 default=1.0,
197 precision=3,
199 # TODO: replace by newer agnostic Material.diffuse_color and remove from pov panel
200 diffuse_color: FloatVectorProperty(
201 name="Diffuse color",
202 description="Diffuse color of the material",
203 precision=4,
204 step=0.01,
205 min=0, # max=inf, soft_max=1,
206 default=(0.6, 0.6, 0.6),
207 options={"ANIMATABLE"},
208 subtype="COLOR",
211 darkness: FloatProperty(
212 name="Darkness",
213 description="Minnaert darkness",
214 min=0.0,
215 max=2.0,
216 soft_min=0.0,
217 soft_max=2.0,
218 default=1.0,
219 precision=3,
222 diffuse_fresnel: FloatProperty(
223 name="Diffuse fresnel",
224 description="Power of Fresnel",
225 min=0.0,
226 max=5.0,
227 soft_min=0.0,
228 soft_max=5.0,
229 default=1.0,
230 precision=3,
233 diffuse_fresnel_factor: FloatProperty(
234 name="Diffuse fresnel factor",
235 description="Blending factor of Fresnel",
236 min=0.0,
237 max=5.0,
238 soft_min=0.0,
239 soft_max=5.0,
240 default=0.5,
241 precision=3,
244 diffuse_intensity: FloatProperty(
245 name="Diffuse intensity",
246 description="Amount of diffuse reflection multiplying color",
247 min=0.0,
248 max=1.0,
249 soft_min=0.0,
250 soft_max=1.0,
251 default=0.8,
252 precision=3,
255 diffuse_ramp_blend: EnumProperty(
256 name="Diffuse ramp blend",
257 description="Blending method of the ramp and the diffuse color",
258 items=(
259 ("MIX", "Mix", ""),
260 ("ADD", "Add", ""),
261 ("MULTIPLY", "Multiply", ""),
262 ("SUBTRACT", "Subtract", ""),
263 ("SCREEN", "Screen", ""),
264 ("DIVIDE", "Divide", ""),
265 ("DIFFERENCE", "Difference", ""),
266 ("DARKEN", "Darken", ""),
267 ("LIGHTEN", "Lighten", ""),
268 ("OVERLAY", "Overlay", ""),
269 ("DODGE", "Dodge", ""),
270 ("BURN", "Burn", ""),
271 ("HUE", "Hue", ""),
272 ("SATURATION", "Saturation", ""),
273 ("VALUE", "Value", ""),
274 ("COLOR", "Color", ""),
275 ("SOFT_LIGHT", "Soft light", ""),
276 ("LINEAR_LIGHT", "Linear light", ""),
278 default="MIX",
281 diffuse_ramp_factor: FloatProperty(
282 name="Factor",
283 description="Blending factor (also uses alpha in Colorband)",
284 min=0.0,
285 max=1.0,
286 soft_min=0.0,
287 soft_max=1.0,
288 default=1.0,
289 precision=3,
292 diffuse_ramp_input: EnumProperty(
293 name="Input",
294 description="How the ramp maps on the surface",
295 items=(
296 ("SHADER", "Shader", ""),
297 ("ENERGY", "Energy", ""),
298 ("NORMAL", "Normal", ""),
299 ("RESULT", "Result", ""),
301 default="SHADER",
304 diffuse_shader: EnumProperty(
305 name="Diffuse Shader Model",
306 description="How the ramp maps on the surface",
307 items=(
308 ("LAMBERT", "Lambert", "Use a Lambertian shader"),
309 ("OREN_NAYAR", "Oren-Nayar", "Use an Oren-Nayar shader"),
310 ("MINNAERT", "Minnaert", "Use a Minnaert shader"),
311 ("FRESNEL", "Fresnel", "Use a Fresnel shader"),
313 default="LAMBERT",
316 diffuse_toon_size: FloatProperty(
317 name="Size",
318 description="Size of diffuse toon area",
319 min=0.0,
320 max=3.14,
321 soft_min=0.0,
322 soft_max=3.14,
323 default=0.5,
324 precision=3,
327 diffuse_toon_smooth: FloatProperty(
328 name="Smooth",
329 description="Smoothness of diffuse toon area",
330 min=0.0,
331 max=1.0,
332 soft_min=0.0,
333 soft_max=1.0,
334 default=0.1,
335 precision=3,
338 emit: FloatProperty(
339 name="Emit",
340 description="Amount of light to emit",
341 min=0.0,
342 soft_min=0.0, # max=inf, soft_max=inf,
343 default=0.0,
344 precision=3,
347 mirror_color: FloatVectorProperty(
348 name="Mirror color",
349 description="Mirror color of the material",
350 precision=4,
351 step=0.01,
352 min=0, # max=inf, soft_max=1,
353 default=(0.6, 0.6, 0.6),
354 options={"ANIMATABLE"},
355 subtype="COLOR",
358 roughness: FloatProperty(
359 name="Roughness",
360 description="Oren-Nayar Roughness",
361 min=0.0,
362 max=3.14,
363 soft_min=0.0,
364 soft_max=3.14,
365 precision=3,
366 default=0.5,
369 halo: BoolProperty(name="Halo", description=" Halo settings for the material", default=False)
370 # (was readonly in Blender2.79, never None)
372 line_color: FloatVectorProperty(
373 name="Line color",
374 description="Line color used for Freestyle line rendering",
375 precision=4,
376 step=0.01,
377 min=0, # max=inf, soft_max=1,
378 default=(0.0, 0.0, 0.0),
379 options={"ANIMATABLE"},
380 subtype="COLOR",
383 # diffuse_ramp:
384 ## Color ramp used to affect diffuse shading
385 ## Type: ColorRamp, (readonly)
387 # cr_node = bpy.data.materials['Material'].node_tree.nodes['ColorRamp']
388 # layout.template_color_ramp(cr_node, "color_ramp", expand=True)
390 # ou
392 # class bpy.types.ColorRamp(bpy_struct)
394 line_priority: IntProperty(
395 name="Recursion Limit",
396 description="The line color of a higher priority is used at material boundaries",
397 min=0,
398 max=32767,
399 default=0,
402 specular_color: FloatVectorProperty(
403 name="Specular color",
404 description="Specular color of the material ",
405 precision=4,
406 step=0.01,
407 min=0.0,
408 soft_max=1.0,
409 default=(1.0, 1.0, 1.0),
410 options={"ANIMATABLE"},
411 subtype="COLOR",
413 specular_hardness: IntProperty(
414 name="Hardness",
415 description="How hard (sharp) the specular reflection is",
416 min=1,
417 max=511,
418 default=30,
420 # TODO: replace by newer agnostic Material.specular_intensity and remove from pov panel
421 specular_intensity: FloatProperty(
422 name="Intensity",
423 description="How intense (bright) the specular reflection is",
424 min=0.0,
425 max=1.0,
426 soft_min=0.0,
427 soft_max=1.0,
428 default=0.1,
429 precision=3,
432 specular_ior: FloatProperty(
433 name="IOR",
434 description="Specular index of refraction",
435 min=-10.0,
436 max=10.0,
437 soft_min=0.0,
438 soft_max=10.0,
439 default=1.0,
440 precision=3,
443 ior: FloatProperty(
444 name="IOR",
445 description="Index of refraction",
446 min=-10.0,
447 max=10.0,
448 soft_min=0.0,
449 soft_max=10.0,
450 default=1.0,
451 precision=3,
454 specular_shader: EnumProperty(
455 name="Specular Shader Model",
456 description="How the ramp maps on the surface",
457 items=(
458 ("COOKTORR", "CookTorr", "Use a Cook-Torrance shader"),
459 ("PHONG", "Phong", "Use a Phong shader"),
460 ("BLINN", "Blinn", "Use a Blinn shader"),
461 ("TOON", "Toon", "Use a Toon shader"),
462 ("WARDISO", "WardIso", "Use a Ward anisotropic shader"),
464 default="COOKTORR",
467 specular_slope: FloatProperty(
468 name="Slope",
469 description="The standard deviation of surface slope",
470 min=0.0,
471 max=0.4,
472 soft_min=0.0,
473 soft_max=0.4,
474 default=0.1,
475 precision=3,
478 specular_toon_size: FloatProperty(
479 name="Size",
480 description="Size of specular toon area",
481 min=0.0,
482 max=0.53,
483 soft_min=0.0,
484 soft_max=0.53,
485 default=0.5,
486 precision=3,
489 specular_toon_smooth: FloatProperty(
490 name="Smooth",
491 description="Smoothness of specular toon area",
492 min=0.0,
493 max=1.0,
494 soft_min=0.0,
495 soft_max=1.0,
496 default=0.1,
497 precision=3,
500 translucency: FloatProperty(
501 name="Translucency",
502 description="Amount of diffuse shading on the back side",
503 min=0.0,
504 max=1.0,
505 soft_min=0.0,
506 soft_max=1.0,
507 default=0.0,
508 precision=3,
511 transparency_method: EnumProperty(
512 name="Specular Shader Model",
513 description="Method to use for rendering transparency",
514 items=(
515 ("MASK", "Mask", "Mask the background"),
516 ("Z_TRANSPARENCY", "Z Transparency", "Use an ior of 1 for transparent faces"),
517 ("RAYTRACE", "Raytrace", "Use raytracing for transparent refraction rendering"),
519 default="MASK",
522 type: EnumProperty(
523 name="Type",
524 description="Material type defining how the object is rendered",
525 items=(
526 ("SURFACE", "Surface", "Render object as a surface"),
527 # TO UPDATE > USE wire MACRO AND CHANGE DESCRIPTION
528 ("WIRE", "Wire", "Render the edges of faces as wires (not supported in raytracing)"),
529 ("VOLUME", "Volume", "Render object as a volume"),
530 # TO UPDATE > USE halo MACRO AND CHANGE DESCRIPTION
531 ("HALO", "Halo", "Render object as halo particles"),
533 default="SURFACE",
536 use_cast_shadows: BoolProperty(
537 name="Cast", description="Allow this material to cast shadows", default=True
540 use_cast_shadows_only: BoolProperty(
541 name="Cast Only",
542 description="Make objects with this material "
543 "appear invisible (not rendered), only "
544 "casting shadows",
545 default=False,
548 use_cubic: BoolProperty(
549 name="Cubic Interpolation",
550 description="Use cubic interpolation for diffuse " "values, for smoother transitions",
551 default=False,
554 use_diffuse_ramp: BoolProperty(
555 name="Ramp", description="Toggle diffuse ramp operations", default=False
558 use_light_group_exclusive: BoolProperty(
559 name="Exclusive",
560 description="Material uses the light group exclusively"
561 "- these lamps are excluded from other "
562 "scene lighting",
563 default=False,
566 use_light_group_local: BoolProperty(
567 name="Local",
568 description="When linked in, material uses local light" " group with the same name",
569 default=False,
572 use_mist: BoolProperty(
573 name="Use Mist",
574 description="Use mist with this material " "(in world settings)",
575 default=True,
578 use_nodes: BoolProperty(
579 name="Nodes",
580 # Add Icon in UI or here? icon='NODES'
581 description="Use shader nodes to render the material",
582 default=False,
585 use_object_color: BoolProperty(
586 name="Object Color",
587 description="Modulate the result with a per-object color",
588 default=False,
591 use_only_shadow: BoolProperty(
592 name="Shadows Only",
593 description="Render shadows as the material’s alpha "
594 "value, making the material transparent "
595 "except for shadowed areas",
596 default=False,
599 use_shadeless: BoolProperty(
600 name="Shadeless",
601 description="Make this material insensitive to " "light or shadow",
602 default=False,
605 use_shadows: BoolProperty(
606 name="Receive", description="Allow this material to receive shadows", default=True
609 use_sky: BoolProperty(
610 name="Sky",
611 description="Render this material with zero alpha, "
612 "with sky background in place (scanline only)",
613 default=False,
616 use_specular_ramp: BoolProperty(
617 name="Ramp", description="Toggle specular ramp operations", default=False
620 use_tangent_shading: BoolProperty(
621 name="Tangent Shading",
622 description="Use the material’s tangent vector instead"
623 "of the normal for shading - for "
624 "anisotropic shading effects",
625 default=False,
628 use_transparent_shadows: BoolProperty(
629 name="Receive Transparent",
630 description="Allow this object to receive transparent " "shadows cast through other object",
631 default=False,
632 ) # linked to fake caustics
634 use_vertex_color_light: BoolProperty(
635 name="Vertex Color Light",
636 description="Add vertex colors as additional lighting",
637 default=False,
640 # TODO create interface:
641 use_vertex_color_paint: BoolProperty(
642 name="Vertex Color Paint",
643 description="Replace object base color with vertex "
644 "colors (multiply with ‘texture face’ "
645 "face assigned textures)",
646 default=False,
649 specular_ramp_blend: EnumProperty(
650 name="Specular ramp blend",
651 description="Blending method of the ramp and the specular color",
652 items=(
653 ("MIX", "Mix", ""),
654 ("ADD", "Add", ""),
655 ("MULTIPLY", "Multiply", ""),
656 ("SUBTRACT", "Subtract", ""),
657 ("SCREEN", "Screen", ""),
658 ("DIVIDE", "Divide", ""),
659 ("DIFFERENCE", "Difference", ""),
660 ("DARKEN", "Darken", ""),
661 ("LIGHTEN", "Lighten", ""),
662 ("OVERLAY", "Overlay", ""),
663 ("DODGE", "Dodge", ""),
664 ("BURN", "Burn", ""),
665 ("HUE", "Hue", ""),
666 ("SATURATION", "Saturation", ""),
667 ("VALUE", "Value", ""),
668 ("COLOR", "Color", ""),
669 ("SOFT_LIGHT", "Soft light", ""),
670 ("LINEAR_LIGHT", "Linear light", ""),
672 default="MIX",
675 specular_ramp_factor: FloatProperty(
676 name="Factor",
677 description="Blending factor (also uses alpha in Colorband)",
678 min=0.0,
679 max=1.0,
680 soft_min=0.0,
681 soft_max=1.0,
682 default=1.0,
683 precision=3,
686 specular_ramp_input: EnumProperty(
687 name="Input",
688 description="How the ramp maps on the surface",
689 items=(
690 ("SHADER", "Shader", ""),
691 ("ENERGY", "Energy", ""),
692 ("NORMAL", "Normal", ""),
693 ("RESULT", "Result", ""),
695 default="SHADER",
698 irid_enable: BoolProperty(
699 name="Iridescence coating",
700 description="Newton's thin film interference (like an oil slick on a puddle of "
701 "water or the rainbow hues of a soap bubble.)",
702 default=False,
705 mirror_use_IOR: BoolProperty(
706 name="Correct Reflection",
707 description="Use same IOR as raytrace transparency to calculate mirror reflections. "
708 "More physically correct",
709 default=False,
712 conserve_energy: BoolProperty(
713 name="Conserve Energy",
714 description="Light transmitted is more correctly reduced by mirror reflections, "
715 "also the sum of diffuse and translucency gets reduced below one ",
716 default=True,
719 irid_amount: FloatProperty(
720 name="amount",
721 description="Contribution of the iridescence effect to the overall surface color. "
722 "As a rule of thumb keep to around 0.25 (25% contribution) or less, "
723 "but experiment. If the surface is coming out too white, try lowering "
724 "the diffuse and possibly the ambient values of the surface",
725 min=0.0,
726 max=1.0,
727 soft_min=0.01,
728 soft_max=1.0,
729 default=0.25,
732 irid_thickness: FloatProperty(
733 name="thickness",
734 description="A very thin film will have a high frequency of color changes while a "
735 "thick film will have large areas of color",
736 min=0.0,
737 max=1000.0,
738 soft_min=0.1,
739 soft_max=10.0,
740 default=1,
743 irid_turbulence: FloatProperty(
744 name="turbulence",
745 description="This parameter varies the thickness",
746 min=0.0,
747 max=10.0,
748 soft_min=0.000,
749 soft_max=1.0,
750 default=0,
753 interior_fade_color: FloatVectorProperty(
754 name="Interior Fade Color",
755 description="Color of filtered attenuation for transparent " "materials",
756 precision=4,
757 step=0.01,
758 min=0.0,
759 soft_max=1.0,
760 default=(0, 0, 0),
761 options={"ANIMATABLE"},
762 subtype="COLOR",
765 caustics_enable: BoolProperty(
766 name="Caustics",
767 description="use only fake refractive caustics (default) or photon based "
768 "reflective/refractive caustics",
769 default=True,
772 fake_caustics: BoolProperty(
773 name="Fake Caustics",
774 description="use only (Fast) fake refractive caustics based on transparent shadows",
775 default=True
778 fake_caustics_power: FloatProperty(
779 name="Fake caustics power",
780 description="Values typically range from 0.0 to 1.0 or higher. Zero is no caustics. "
781 "Low, non-zero values give broad hot-spots while higher values give "
782 "tighter, smaller simulated focal points",
783 min=0.00,
784 max=10.0,
785 soft_min=0.00,
786 soft_max=5.0,
787 default=0.15,
790 refraction_caustics: BoolProperty(
791 name="Refractive Caustics",
792 description="hotspots of light focused when going through the material",
793 default=True,
796 photons_dispersion: FloatProperty(
797 name="Chromatic Dispersion",
798 description="Light passing through will be separated according to wavelength. "
799 "This ratio of refractive indices for violet to red controls how much "
800 "the colors are spread out 1 = no dispersion, good values are 1.01 to 1.1",
801 min=1.0000,
802 max=10.000,
803 soft_min=1.0000,
804 soft_max=1.1000,
805 precision=4,
806 default=1.0000,
809 photons_dispersion_samples: IntProperty(
810 name="Dispersion Samples",
811 description="Number of color-steps for dispersion",
812 min=2,
813 max=128,
814 default=7,
817 photons_reflection: BoolProperty(
818 name="Reflective Photon Caustics",
819 description="Use this to make your Sauron's ring ;-P",
820 default=False,
823 refraction_type: EnumProperty(
824 items=[
825 ("1", "Z Transparency Fake Caustics", "use fake caustics"),
826 ("2", "Raytrace Photons Caustics", "use photons for refractive caustics"),
828 name="Refraction Type:",
829 description="use fake caustics (fast) or true photons for refractive Caustics",
830 default="1",
833 # ------------------------------ CustomPOV Code ------------------------------ #
834 replacement_text: StringProperty(
835 name="Declared name:",
836 description="Type the variable name as declared either directly inlined "
837 "in your custom POV code from the text editor datablock (checked as a "
838 "source to render in it's side property panel), or this declaration can be "
839 "from an external .inc it points at. Here, name = texture {} expected",
840 default="",
843 # NODES
845 def use_material_nodes_callback(self, context):
846 """Identify if node has been added and if it is used yet or default"""
848 if hasattr(context.space_data, "tree_type"):
849 context.space_data.tree_type = "ObjectNodeTree"
850 mat = context.object.active_material
851 if mat.pov.material_use_nodes:
852 mat.use_nodes = True
853 tree = mat.node_tree
854 # tree.name = mat.name # XXX READONLY
855 links = tree.links
856 default = True
857 if len(tree.nodes) == 2:
858 o = 0
859 m = 0
860 for node in tree.nodes:
861 if node.type in {"OUTPUT", "MATERIAL"}:
862 tree.nodes.remove(node)
863 default = True
864 for node in tree.nodes:
865 if node.bl_idname == "PovrayOutputNode":
866 o += 1
867 elif node.bl_idname == "PovrayTextureNode":
868 m += 1
869 if o == 1 and m == 1:
870 default = False
871 elif len(tree.nodes) == 0:
872 default = True
873 else:
874 default = False
875 if default:
876 output = tree.nodes.new("PovrayOutputNode")
877 output.location = 200, 200
878 tmap = tree.nodes.new("PovrayTextureNode")
879 tmap.location = 0, 200
880 links.new(tmap.outputs[0], output.inputs[0])
881 tmap.select = True
882 tree.nodes.active = tmap
883 else:
884 mat.use_nodes = False
886 def use_texture_nodes_callback(self, context):
887 """Identify texture nodes by filtering out output and composite ones"""
889 tex = context.object.active_material.active_texture
890 if tex.pov.texture_use_nodes:
891 tex.use_nodes = True
892 if len(tex.node_tree.nodes) == 2:
893 for node in tex.node_tree.nodes:
894 if node.type in {"OUTPUT", "CHECKER"}:
895 tex.node_tree.nodes.remove(node)
896 else:
897 tex.use_nodes = False
899 def node_active_callback(self, context):
900 """Synchronize active node with material before getting it"""
902 items = [] # XXX comment out > remove?
903 mat = context.material
904 mat.node_tree.nodes # XXX comment out > remove?
905 for node in mat.node_tree.nodes:
906 node.select = False
907 for node in mat.node_tree.nodes:
908 if node.name == mat.pov.material_active_node:
909 node.select = True
910 mat.node_tree.nodes.active = node
912 return node
914 def node_enum_callback(self, context):
915 mat = context.material
916 nodes = mat.node_tree.nodes
917 return [("%s" % node.name, "%s" % node.name, "") for node in nodes]
919 def pigment_normal_callback(self, context):
920 render = context.scene.pov.render # XXX comment out > remove?
921 return (
922 [("pigment", "Pigment", ""), ("normal", "Normal", "")]
923 # XXX Find any other such traces of hgpovray experiment > remove or deploy ?
924 if render != "hgpovray"
925 else [
926 ("pigment", "Pigment", ""),
927 ("normal", "Normal", ""),
928 ("modulation", "Modulation", ""),
932 def glow_callback(self, context):
933 scene = context.scene
934 ob = context.object
935 ob.pov.mesh_write_as_old = ob.pov.mesh_write_as
936 if scene.pov.render == "uberpov" and ob.pov.glow:
937 ob.pov.mesh_write_as = "NONE"
938 else:
939 ob.pov.mesh_write_as = ob.pov.mesh_write_as_old
941 material_use_nodes: BoolProperty(
942 name="Use nodes", description="", update=use_material_nodes_callback, default=False
945 material_active_node: EnumProperty(
946 name="Active node", description="", items=node_enum_callback, update=node_active_callback
949 preview_settings: BoolProperty(name="Preview Settings", description="", default=False)
951 object_preview_transform: BoolProperty(name="Transform object", description="", default=False)
953 object_preview_scale: FloatProperty(name="XYZ", min=0.5, max=2.0, default=1.0)
955 object_preview_rotate: FloatVectorProperty(
956 name="Rotate", description="", min=-180.0, max=180.0, default=(0.0, 0.0, 0.0), subtype="XYZ"
959 object_preview_bgcontrast: FloatProperty(name="Contrast", min=0.0, max=1.0, default=0.5)
963 # ------------------------------ End Old Blender Internal Props ------------------------------ #
966 classes = (
967 RenderPovSettingsMaterial,
971 def register():
972 for cls in classes:
973 register_class(cls)
975 bpy.types.Material.pov = PointerProperty(type=RenderPovSettingsMaterial)
978 def unregister():
979 del bpy.types.Material.pov
981 for cls in reversed(classes):
982 unregister_class(cls)