Code Monkey home page Code Monkey logo

Comments (7)

sweco-sekrsv avatar sweco-sekrsv commented on August 26, 2024 1

Most likely due to Blender 4.1. I was using the latest Blender 3.6.x release

from the_lightmapper.

jywarren avatar jywarren commented on August 26, 2024 1

https://wiki.blender.org/wiki/Reference/Release_Notes/4.0/Python_API

I think it would need to be:

if 'Occlusion' not in gltf_settings_node.items_tree:
  gltf_settings_node.node_tree.interface.new_socket(name="Occlusion", in_out='INPUT')

This worked!!

from the_lightmapper.

sweco-sekrsv avatar sweco-sekrsv commented on August 26, 2024

For anyone else struggling with this. I dug into the code and did some readup on the topic. This is how I changed the TLM_AddGLTFNode in tlm.py to get it working

class TLM_AddGLTFNode(bpy.types.Operator):
    bl_idname = "tlm.add_gltf_node"
    bl_label = "Add GLTF Node"
    bl_description = "Add to GLTF node to active material and connect lightmap if present"
    bl_options = {'REGISTER', 'UNDO'}

    def execute(self, context):

        scene = context.scene
        cycles = scene.cycles

        for obj in bpy.context.scene.objects:

            print("Iterating: " + obj.name)

            if obj.type == 'MESH' and obj.name in bpy.context.view_layer.objects:
                if obj.TLM_ObjectProperties.tlm_mesh_lightmap_use:

                    for slot in obj.material_slots:

                        material = slot.material

                        nodes = material.node_tree.nodes
                        # create group data
                        gltf_settings = bpy.data.node_groups.get('glTF Material Output')
                        if gltf_settings is None:
                            bpy.data.node_groups.new('glTF Material Output', 'ShaderNodeTree')

                        # add group to node tree
                        gltf_settings_node = nodes.get('glTF Material Output')
                        if gltf_settings_node is None:
                            gltf_settings_node = nodes.new('ShaderNodeGroup')
                            gltf_settings_node.name = 'glTF Material Output'
                            gltf_settings_node.node_tree = bpy.data.node_groups['glTF Material Output']

                        # create group inputs
                        if 'Occlusion' not in gltf_settings_node.node_tree.inputs:
                            gltf_settings_node.node_tree.inputs.new('NodeSocketFloat','Occlusion')                            

                        gltf_settings_node.location.y = 400

                        lightmapNode = nodes.get("TLM_Lightmap")

                        material.node_tree.links.remove(lightmapNode.outputs[0].links[0])
                        material.node_tree.links.new(lightmapNode.outputs[0], gltf_settings_node.inputs[0])
                        
                        #If the material have a node called "Lightmap_Multiplication" and it does have a input into Color2 called "Lightmap_BasecolorNode_A" remove both "Lightmap_BasecolorNode_A" and ""Lightmap_Multiplication". This needs to be done for materials that dont have a base texture but instead using a just a color
                        # Check if the "Lightmap_Multiplication" node exists
                        lightmap_multiplication_node = nodes.get("Lightmap_Multiplication")
                        if lightmap_multiplication_node is not None:
                            # Check if the "Lightmap_BasecolorNode_A" node is connected to the "Color2" input of the "Lightmap_Multiplication" node
                            color2_input = lightmap_multiplication_node.inputs.get("Color2")
                            if color2_input is not None and color2_input.is_linked:
                                lightmap_basecolor_node_a = color2_input.links[0].from_node
                                if lightmap_basecolor_node_a.name == "Lightmap_BasecolorNode_A":
                                    # Remove the "Lightmap_BasecolorNode_A" node
                                    nodes.remove(lightmap_basecolor_node_a)
                                    # Remove the "Lightmap_Multiplication" node
                                    nodes.remove(lightmap_multiplication_node)
                            else:
                                    # Remove the "Lightmap_Multiplication" node
                                    nodes.remove(lightmap_multiplication_node)


        return {'FINISHED'}

from the_lightmapper.

jywarren avatar jywarren commented on August 26, 2024

Hi, thank you! Here is the diff:

https://gist.github.com/jywarren/b021a934995eeb690352fe9004ae4aa1/revisions

Applied to this file:

https://github.com/Naxela/The_Lightmapper/blob/6e9e3a81d6ced3908b209205e1015860fe999d94/addon/operators/tlm.py#L2019C1-L2069C44

from the_lightmapper.

jywarren avatar jywarren commented on August 26, 2024

I'm now seeing a different error -

File "/Users/warren/Library/Application Support/Blender/4.1/scripts/addons/thelightmapper/addon/operators/tlm.py", line 1710, in execute if 'Occlusion' not in gltf_settings_node.node_tree.inputs:
^^^^^^^^^^^^^^^^^^^^
AttributeError: 'ShaderNode Tree' object has no attribute 'inputs'

from the_lightmapper.

jywarren avatar jywarren commented on August 26, 2024

Ah - noting I'm in Blender 4.1. I'm seeing some slightly different-looking naming conventions which could be related:

def lightmap_to_ao(material,lightmap_node):
nodes = material.node_tree.nodes
# -----------------------AO SETUP--------------------#
# create group data
gltf_settings = bpy.data.node_groups.get('glTF Settings')
if gltf_settings is None:
bpy.data.node_groups.new('glTF Settings', 'ShaderNodeTree')
# add group to node tree
ao_group = nodes.get('glTF Settings')
if ao_group is None:
ao_group = nodes.new('ShaderNodeGroup')
ao_group.name = 'glTF Settings'
ao_group.node_tree = bpy.data.node_groups['glTF Settings']
# create group inputs
if ao_group.inputs.get('Occlusion') is None:
ao_group.inputs.new('NodeSocketFloat','Occlusion')
# mulitply to control strength
mix_node = add_node(material,Shader_Node_Types.mix,"Adjust Lightmap")
mix_node.blend_type = "MULTIPLY"
mix_node.inputs["Fac"].default_value = 1
mix_node.inputs["Color2"].default_value = [3,3,3,1]
# position node
ao_group.location = (lightmap_node.location[0]+600,lightmap_node.location[1])
mix_node.location = (lightmap_node.location[0]+300,lightmap_node.location[1])
make_link(material,lightmap_node.outputs['Color'],mix_node.inputs['Color1'])
make_link(material,mix_node.outputs['Color'],ao_group.inputs['Occlusion'])

from the_lightmapper.

jywarren avatar jywarren commented on August 26, 2024

Just noting via this post:

in Blender 4.0 its inputs and outputs cannot be accessed anymore like this:

input_socket = groupTree.inputs.new('NodeSocketFloat', 'Input') 

instead,

the new python API:

tree.interface.new_socket(name="My Input", in_out='INPUT')

from the_lightmapper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.