Skip to content
Snippets Groups Projects
shading_nodes.py 63.3 KiB
Newer Older
  • Learn to ignore specific revisions
  • # SPDX-License-Identifier: GPL-2.0-or-later
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
    
    # <pep8 compliant>
    """"Nodes based User interface for shaders exported to POV textures."""
    import bpy
    
    from bpy.utils import register_class, unregister_class
    from bpy.types import Menu, Node, NodeSocket, CompositorNodeTree, TextureNodeTree, Operator
    from bpy.props import (
        StringProperty,
        BoolProperty,
        IntProperty,
        FloatProperty,
        FloatVectorProperty,
        EnumProperty,
    )
    import nodeitems_utils
    from nodeitems_utils import NodeCategory, NodeItem
    
    
    
    # ---------------------------------------------------------------- #
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
    # Pov Nodes init
    
    # ---------------------------------------------------------------- #
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
    24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 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 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 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 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 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 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 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 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536
    
    
    class PovraySocketUniversal(NodeSocket):
        bl_idname = "PovraySocketUniversal"
        bl_label = "Povray Socket"
        value_unlimited: bpy.props.FloatProperty(default=0.0)
        value_0_1: bpy.props.FloatProperty(min=0.0, max=1.0, default=0.0)
        value_0_10: bpy.props.FloatProperty(min=0.0, max=10.0, default=0.0)
        value_000001_10: bpy.props.FloatProperty(min=0.000001, max=10.0, default=0.0)
        value_1_9: bpy.props.IntProperty(min=1, max=9, default=1)
        value_0_255: bpy.props.IntProperty(min=0, max=255, default=0)
        percent: bpy.props.FloatProperty(min=0.0, max=100.0, default=0.0)
    
        def draw(self, context, layout, node, text):
            space = context.space_data
            tree = space.edit_tree
            links = tree.links
            if self.is_linked:
                value = []
                for link in links:
                    if link.from_node == node:
                        inps = link.to_node.inputs
                        for inp in inps:
                            if inp.bl_idname == "PovraySocketFloat_0_1" and inp.is_linked:
                                prop = "value_0_1"
                                if prop not in value:
                                    value.append(prop)
                            if inp.bl_idname == "PovraySocketFloat_000001_10" and inp.is_linked:
                                prop = "value_000001_10"
                                if prop not in value:
                                    value.append(prop)
                            if inp.bl_idname == "PovraySocketFloat_0_10" and inp.is_linked:
                                prop = "value_0_10"
                                if prop not in value:
                                    value.append(prop)
                            if inp.bl_idname == "PovraySocketInt_1_9" and inp.is_linked:
                                prop = "value_1_9"
                                if prop not in value:
                                    value.append(prop)
                            if inp.bl_idname == "PovraySocketInt_0_255" and inp.is_linked:
                                prop = "value_0_255"
                                if prop not in value:
                                    value.append(prop)
                            if inp.bl_idname == "PovraySocketFloatUnlimited" and inp.is_linked:
                                prop = "value_unlimited"
                                if prop not in value:
                                    value.append(prop)
                if len(value) == 1:
                    layout.prop(self, "%s" % value[0], text=text)
                else:
                    layout.prop(self, "percent", text="Percent")
            else:
                layout.prop(self, "percent", text=text)
    
        def draw_color(self, context, node):
            return (1, 0, 0, 1)
    
    
    class PovraySocketFloat_0_1(NodeSocket):
        bl_idname = "PovraySocketFloat_0_1"
        bl_label = "Povray Socket"
        default_value: bpy.props.FloatProperty(
            description="Input node Value_0_1", min=0, max=1, default=0
        )
    
        def draw(self, context, layout, node, text):
            if self.is_linked:
                layout.label(text=text)
            else:
                layout.prop(self, "default_value", text=text, slider=True)
    
        def draw_color(self, context, node):
            return (0.5, 0.7, 0.7, 1)
    
    
    class PovraySocketFloat_0_10(NodeSocket):
        bl_idname = "PovraySocketFloat_0_10"
        bl_label = "Povray Socket"
        default_value: bpy.props.FloatProperty(
            description="Input node Value_0_10", min=0, max=10, default=0
        )
    
        def draw(self, context, layout, node, text):
            if node.bl_idname == "ShaderNormalMapNode" and node.inputs[2].is_linked:
                layout.label(text="")
                self.hide_value = True
            if self.is_linked:
                layout.label(text=text)
            else:
                layout.prop(self, "default_value", text=text, slider=True)
    
        def draw_color(self, context, node):
            return (0.65, 0.65, 0.65, 1)
    
    
    class PovraySocketFloat_10(NodeSocket):
        bl_idname = "PovraySocketFloat_10"
        bl_label = "Povray Socket"
        default_value: bpy.props.FloatProperty(
            description="Input node Value_10", min=-10, max=10, default=0
        )
    
        def draw(self, context, layout, node, text):
            if node.bl_idname == "ShaderNormalMapNode" and node.inputs[2].is_linked:
                layout.label(text="")
                self.hide_value = True
            if self.is_linked:
                layout.label(text=text)
            else:
                layout.prop(self, "default_value", text=text, slider=True)
    
        def draw_color(self, context, node):
            return (0.65, 0.65, 0.65, 1)
    
    
    class PovraySocketFloatPositive(NodeSocket):
        bl_idname = "PovraySocketFloatPositive"
        bl_label = "Povray Socket"
        default_value: bpy.props.FloatProperty(
            description="Input Node Value Positive", min=0.0, default=0
        )
    
        def draw(self, context, layout, node, text):
            if self.is_linked:
                layout.label(text=text)
            else:
                layout.prop(self, "default_value", text=text, slider=True)
    
        def draw_color(self, context, node):
            return (0.045, 0.005, 0.136, 1)
    
    
    class PovraySocketFloat_000001_10(NodeSocket):
        bl_idname = "PovraySocketFloat_000001_10"
        bl_label = "Povray Socket"
        default_value: bpy.props.FloatProperty(min=0.000001, max=10, default=0.000001)
    
        def draw(self, context, layout, node, text):
            if self.is_output or self.is_linked:
                layout.label(text=text)
            else:
                layout.prop(self, "default_value", text=text, slider=True)
    
        def draw_color(self, context, node):
            return (1, 0, 0, 1)
    
    
    class PovraySocketFloatUnlimited(NodeSocket):
        bl_idname = "PovraySocketFloatUnlimited"
        bl_label = "Povray Socket"
        default_value: bpy.props.FloatProperty(default=0.0)
    
        def draw(self, context, layout, node, text):
            if self.is_linked:
                layout.label(text=text)
            else:
                layout.prop(self, "default_value", text=text, slider=True)
    
        def draw_color(self, context, node):
            return (0.7, 0.7, 1, 1)
    
    
    class PovraySocketInt_1_9(NodeSocket):
        bl_idname = "PovraySocketInt_1_9"
        bl_label = "Povray Socket"
        default_value: bpy.props.IntProperty(
            description="Input node Value_1_9", min=1, max=9, default=6
        )
    
        def draw(self, context, layout, node, text):
            if self.is_linked:
                layout.label(text=text)
            else:
                layout.prop(self, "default_value", text=text)
    
        def draw_color(self, context, node):
            return (1, 0.7, 0.7, 1)
    
    
    class PovraySocketInt_0_256(NodeSocket):
        bl_idname = "PovraySocketInt_0_256"
        bl_label = "Povray Socket"
        default_value: bpy.props.IntProperty(min=0, max=255, default=0)
    
        def draw(self, context, layout, node, text):
            if self.is_linked:
                layout.label(text=text)
            else:
                layout.prop(self, "default_value", text=text)
    
        def draw_color(self, context, node):
            return (0.5, 0.5, 0.5, 1)
    
    
    class PovraySocketPattern(NodeSocket):
        bl_idname = "PovraySocketPattern"
        bl_label = "Povray Socket"
    
        default_value: bpy.props.EnumProperty(
            name="Pattern",
            description="Select the pattern",
            items=(
                ("boxed", "Boxed", ""),
                ("brick", "Brick", ""),
                ("cells", "Cells", ""),
                ("checker", "Checker", ""),
                ("granite", "Granite", ""),
                ("leopard", "Leopard", ""),
                ("marble", "Marble", ""),
                ("onion", "Onion", ""),
                ("planar", "Planar", ""),
                ("quilted", "Quilted", ""),
                ("ripples", "Ripples", ""),
                ("radial", "Radial", ""),
                ("spherical", "Spherical", ""),
                ("spotted", "Spotted", ""),
                ("waves", "Waves", ""),
                ("wood", "Wood", ""),
                ("wrinkles", "Wrinkles", ""),
            ),
            default="granite",
        )
    
        def draw(self, context, layout, node, text):
            if self.is_output or self.is_linked:
                layout.label(text="Pattern")
            else:
                layout.prop(self, "default_value", text=text)
    
        def draw_color(self, context, node):
            return (1, 1, 1, 1)
    
    
    class PovraySocketColor(NodeSocket):
        bl_idname = "PovraySocketColor"
        bl_label = "Povray Socket"
    
        default_value: FloatVectorProperty(
            precision=4,
            step=0.01,
            min=0,
            soft_max=1,
            default=(0.0, 0.0, 0.0),
            options={"ANIMATABLE"},
            subtype="COLOR",
        )
    
        def draw(self, context, layout, node, text):
            if self.is_output or self.is_linked:
                layout.label(text=text)
            else:
                layout.prop(self, "default_value", text=text)
    
        def draw_color(self, context, node):
            return (1, 1, 0, 1)
    
    
    class PovraySocketColorRGBFT(NodeSocket):
        bl_idname = "PovraySocketColorRGBFT"
        bl_label = "Povray Socket"
    
        default_value: FloatVectorProperty(
            precision=4,
            step=0.01,
            min=0,
            soft_max=1,
            default=(0.0, 0.0, 0.0),
            options={"ANIMATABLE"},
            subtype="COLOR",
        )
        f: bpy.props.FloatProperty(default=0.0, min=0.0, max=1.0)
        t: bpy.props.FloatProperty(default=0.0, min=0.0, max=1.0)
    
        def draw(self, context, layout, node, text):
            if self.is_output or self.is_linked:
                layout.label(text=text)
            else:
                layout.prop(self, "default_value", text=text)
    
        def draw_color(self, context, node):
            return (1, 1, 0, 1)
    
    
    class PovraySocketTexture(NodeSocket):
        bl_idname = "PovraySocketTexture"
        bl_label = "Povray Socket"
        default_value: bpy.props.IntProperty()
    
        def draw(self, context, layout, node, text):
            layout.label(text=text)
    
        def draw_color(self, context, node):
            return (0, 1, 0, 1)
    
    
    class PovraySocketTransform(NodeSocket):
        bl_idname = "PovraySocketTransform"
        bl_label = "Povray Socket"
        default_value: bpy.props.IntProperty(min=0, max=255, default=0)
    
        def draw(self, context, layout, node, text):
            layout.label(text=text)
    
        def draw_color(self, context, node):
            return (99 / 255, 99 / 255, 199 / 255, 1)
    
    
    class PovraySocketNormal(NodeSocket):
        bl_idname = "PovraySocketNormal"
        bl_label = "Povray Socket"
        default_value: bpy.props.IntProperty(min=0, max=255, default=0)
    
        def draw(self, context, layout, node, text):
            layout.label(text=text)
    
        def draw_color(self, context, node):
            return (0.65, 0.65, 0.65, 1)
    
    
    class PovraySocketSlope(NodeSocket):
        bl_idname = "PovraySocketSlope"
        bl_label = "Povray Socket"
        default_value: bpy.props.FloatProperty(min=0.0, max=1.0)
        height: bpy.props.FloatProperty(min=0.0, max=10.0)
        slope: bpy.props.FloatProperty(min=-10.0, max=10.0)
    
        def draw(self, context, layout, node, text):
            if self.is_output or self.is_linked:
                layout.label(text=text)
            else:
                layout.prop(self, "default_value", text="")
                layout.prop(self, "height", text="")
                layout.prop(self, "slope", text="")
    
        def draw_color(self, context, node):
            return (0, 0, 0, 1)
    
    
    class PovraySocketMap(NodeSocket):
        bl_idname = "PovraySocketMap"
        bl_label = "Povray Socket"
        default_value: bpy.props.StringProperty()
    
        def draw(self, context, layout, node, text):
            layout.label(text=text)
    
        def draw_color(self, context, node):
            return (0.2, 0, 0.2, 1)
    
    
    class PovrayShaderNodeCategory(NodeCategory):
        @classmethod
        def poll(cls, context):
            return context.space_data.tree_type == "ObjectNodeTree"
    
    
    class PovrayTextureNodeCategory(NodeCategory):
        @classmethod
        def poll(cls, context):
            return context.space_data.tree_type == "TextureNodeTree"
    
    
    class PovraySceneNodeCategory(NodeCategory):
        @classmethod
        def poll(cls, context):
            return context.space_data.tree_type == "CompositorNodeTree"
    
    
    node_categories = [
        PovrayShaderNodeCategory("SHADEROUTPUT", "Output", items=[NodeItem("PovrayOutputNode")]),
        PovrayShaderNodeCategory("SIMPLE", "Simple texture", items=[NodeItem("PovrayTextureNode")]),
        PovrayShaderNodeCategory(
            "MAPS",
            "Maps",
            items=[
                NodeItem("PovrayBumpMapNode"),
                NodeItem("PovrayColorImageNode"),
                NodeItem("ShaderNormalMapNode"),
                NodeItem("PovraySlopeNode"),
                NodeItem("ShaderTextureMapNode"),
                NodeItem("ShaderNodeValToRGB"),
            ],
        ),
        PovrayShaderNodeCategory(
            "OTHER",
            "Other patterns",
            items=[NodeItem("PovrayImagePatternNode"), NodeItem("ShaderPatternNode")],
        ),
        PovrayShaderNodeCategory("COLOR", "Color", items=[NodeItem("PovrayPigmentNode")]),
        PovrayShaderNodeCategory(
            "TRANSFORM",
            "Transform",
            items=[
                NodeItem("PovrayMappingNode"),
                NodeItem("PovrayMultiplyNode"),
                NodeItem("PovrayModifierNode"),
                NodeItem("PovrayTransformNode"),
                NodeItem("PovrayValueNode"),
            ],
        ),
        PovrayShaderNodeCategory(
            "FINISH",
            "Finish",
            items=[
                NodeItem("PovrayFinishNode"),
                NodeItem("PovrayDiffuseNode"),
                NodeItem("PovraySpecularNode"),
                NodeItem("PovrayPhongNode"),
                NodeItem("PovrayAmbientNode"),
                NodeItem("PovrayMirrorNode"),
                NodeItem("PovrayIridescenceNode"),
                NodeItem("PovraySubsurfaceNode"),
            ],
        ),
        PovrayShaderNodeCategory(
            "CYCLES",
            "Cycles",
            items=[
                NodeItem("ShaderNodeAddShader"),
                NodeItem("ShaderNodeAmbientOcclusion"),
                NodeItem("ShaderNodeAttribute"),
                NodeItem("ShaderNodeBackground"),
                NodeItem("ShaderNodeBlackbody"),
                NodeItem("ShaderNodeBrightContrast"),
                NodeItem("ShaderNodeBsdfAnisotropic"),
                NodeItem("ShaderNodeBsdfDiffuse"),
                NodeItem("ShaderNodeBsdfGlass"),
                NodeItem("ShaderNodeBsdfGlossy"),
                NodeItem("ShaderNodeBsdfHair"),
                NodeItem("ShaderNodeBsdfRefraction"),
                NodeItem("ShaderNodeBsdfToon"),
                NodeItem("ShaderNodeBsdfTranslucent"),
                NodeItem("ShaderNodeBsdfTransparent"),
                NodeItem("ShaderNodeBsdfVelvet"),
                NodeItem("ShaderNodeBump"),
                NodeItem("ShaderNodeCameraData"),
                NodeItem("ShaderNodeCombineHSV"),
                NodeItem("ShaderNodeCombineRGB"),
                NodeItem("ShaderNodeCombineXYZ"),
                NodeItem("ShaderNodeEmission"),
                NodeItem("ShaderNodeExtendedMaterial"),
                NodeItem("ShaderNodeFresnel"),
                NodeItem("ShaderNodeGamma"),
                NodeItem("ShaderNodeGeometry"),
                NodeItem("ShaderNodeGroup"),
                NodeItem("ShaderNodeHairInfo"),
                NodeItem("ShaderNodeHoldout"),
                NodeItem("ShaderNodeHueSaturation"),
                NodeItem("ShaderNodeInvert"),
                NodeItem("ShaderNodeLampData"),
                NodeItem("ShaderNodeLayerWeight"),
                NodeItem("ShaderNodeLightFalloff"),
                NodeItem("ShaderNodeLightPath"),
                NodeItem("ShaderNodeMapping"),
                NodeItem("ShaderNodeMaterial"),
                NodeItem("ShaderNodeMath"),
                NodeItem("ShaderNodeMixRGB"),
                NodeItem("ShaderNodeMixShader"),
                NodeItem("ShaderNodeNewGeometry"),
                NodeItem("ShaderNodeNormal"),
                NodeItem("ShaderNodeNormalMap"),
                NodeItem("ShaderNodeObjectInfo"),
                NodeItem("ShaderNodeOutput"),
                NodeItem("ShaderNodeOutputLamp"),
                NodeItem("ShaderNodeOutputLineStyle"),
                NodeItem("ShaderNodeOutputMaterial"),
                NodeItem("ShaderNodeOutputWorld"),
                NodeItem("ShaderNodeParticleInfo"),
                NodeItem("ShaderNodeRGB"),
                NodeItem("ShaderNodeRGBCurve"),
                NodeItem("ShaderNodeRGBToBW"),
                NodeItem("ShaderNodeScript"),
                NodeItem("ShaderNodeSeparateHSV"),
                NodeItem("ShaderNodeSeparateRGB"),
                NodeItem("ShaderNodeSeparateXYZ"),
                NodeItem("ShaderNodeSqueeze"),
                NodeItem("ShaderNodeSubsurfaceScattering"),
                NodeItem("ShaderNodeTangent"),
                NodeItem("ShaderNodeTexBrick"),
                NodeItem("ShaderNodeTexChecker"),
                NodeItem("ShaderNodeTexCoord"),
                NodeItem("ShaderNodeTexEnvironment"),
                NodeItem("ShaderNodeTexGradient"),
                NodeItem("ShaderNodeTexImage"),
                NodeItem("ShaderNodeTexMagic"),
                NodeItem("ShaderNodeTexMusgrave"),
                NodeItem("ShaderNodeTexNoise"),
                NodeItem("ShaderNodeTexPointDensity"),
                NodeItem("ShaderNodeTexSky"),
                NodeItem("ShaderNodeTexVoronoi"),
                NodeItem("ShaderNodeTexWave"),
                NodeItem("ShaderNodeTexture"),
                NodeItem("ShaderNodeUVAlongStroke"),
                NodeItem("ShaderNodeUVMap"),
                NodeItem("ShaderNodeValToRGB"),
                NodeItem("ShaderNodeValue"),
                NodeItem("ShaderNodeVectorCurve"),
                NodeItem("ShaderNodeVectorMath"),
                NodeItem("ShaderNodeVectorTransform"),
                NodeItem("ShaderNodeVolumeAbsorption"),
                NodeItem("ShaderNodeVolumeScatter"),
                NodeItem("ShaderNodeWavelength"),
                NodeItem("ShaderNodeWireframe"),
            ],
        ),
        PovrayTextureNodeCategory(
            "TEXTUREOUTPUT",
            "Output",
            items=[NodeItem("TextureNodeValToRGB"), NodeItem("TextureOutputNode")],
        ),
        PovraySceneNodeCategory("ISOSURFACE", "Isosurface", items=[NodeItem("IsoPropsNode")]),
        PovraySceneNodeCategory("FOG", "Fog", items=[NodeItem("PovrayFogNode")]),
    ]
    
    # -------- end nodes init
    # -------- nodes ui
    # -------- Nodes
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
    
    # 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 = \
    # "material.pov.material_use_nodes"
    # 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 NODE_MT_POV_map_create(Menu):
        """Create maps"""
    
        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(NODE_MT_POV_map_create.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")
    
    
    
    # -------- object
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
    
    
    class ObjectNodeTree(bpy.types.NodeTree):
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
    
        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'}:
                ma = ob.active_material
                if ma is not None:
                    nt_name = ma.node_tree
                    if nt_name != '':
                        return nt_name, ma, ma
            return (None, None, None)
    
        def update(self):
            self.refresh = True
    
    
    
    # -------- output # ---------------------------------------------------------------- #
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
    
    
    class PovrayOutputNode(Node, ObjectNodeTree):
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
    
        bl_idname = 'PovrayOutputNode'
        bl_label = 'Output'
        bl_icon = 'SHADING_TEXTURE'
    
        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 # ---------------------------------------------------------------- #
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
    class PovrayTextureNode(Node, ObjectNodeTree):
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
    
        bl_idname = 'PovrayTextureNode'
        bl_label = 'Simple texture'
        bl_icon = 'SHADING_TEXTURE'
    
        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):
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
    
        bl_idname = 'PovrayFinishNode'
        bl_label = 'Finish'
        bl_icon = 'SHADING_TEXTURE'
    
        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):
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
    
        bl_idname = 'PovrayDiffuseNode'
        bl_label = 'Diffuse'
        bl_icon = 'MATSPHERE'
    
        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):
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
    
        bl_idname = 'PovrayPhongNode'
        bl_label = 'Phong'
        bl_icon = 'MESH_UVSPHERE'
    
        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):
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
    
        bl_idname = 'PovraySpecularNode'
        bl_label = 'Specular'
        bl_icon = 'MESH_UVSPHERE'
    
        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):
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
    
        bl_idname = 'PovrayMirrorNode'
        bl_label = 'Mirror'
        bl_icon = 'SHADING_TEXTURE'
    
        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):
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
    
        bl_idname = 'PovrayAmbientNode'
        bl_label = 'Ambient'
        bl_icon = 'SHADING_SOLID'
    
        def init(self, context):
    
            self.inputs.new('PovraySocketColor', "Ambient")
    
            self.outputs.new('NodeSocketVector', "Ambient")
    
        def draw_label(self):
            return "Ambient"
    
    
    class PovrayIridescenceNode(Node, ObjectNodeTree):
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
    
        bl_idname = 'PovrayIridescenceNode'
        bl_label = 'Iridescence'
        bl_icon = 'MESH_UVSPHERE'
    
        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):
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
    
        bl_idname = 'PovraySubsurfaceNode'
        bl_label = 'Subsurface'
        bl_icon = 'MESH_UVSPHERE'
    
        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"
    
    
    
    # ---------------------------------------------------------------- #
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
    
    
    class PovrayMappingNode(Node, ObjectNodeTree):
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
    
        bl_idname = 'PovrayMappingNode'
        bl_label = 'Mapping'
        bl_icon = 'NODE_TEXTURE'
    
        warp_type: EnumProperty(
            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',
        )
    
        warp_orientation: EnumProperty(
            name="Warp Orientation",
            description="Select the orientation of warp",
            items=(('x', "X", ""), ('y', "Y", ""), ('z', "Z", "")),
            default='y',
        )
    
        warp_dist_exp: FloatProperty(
            name="Distance exponent", description="Distance exponent", min=0.0, max=100.0, default=1.0
        )
    
        warp_tor_major_radius: FloatProperty(
            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):
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
    
        bl_idname = 'PovrayMultiplyNode'
        bl_label = 'Multiply'
        bl_icon = 'SHADING_SOLID'
    
        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")
            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):
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
    
        bl_idname = 'PovrayTransformNode'
        bl_label = 'Transform'
        bl_icon = 'NODE_TEXTURE'
    
        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):
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
    
        bl_idname = 'PovrayValueNode'