Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors in Blender 4.2 #3

Open
supertobi opened this issue Nov 19, 2024 · 3 comments
Open

Errors in Blender 4.2 #3

supertobi opened this issue Nov 19, 2024 · 3 comments

Comments

@supertobi
Copy link

Hello,

I know this is an old script, and there was no development in the last years. But I like it and perhaps you could look into this error with the Blender version 4.2:
grafik

Btw. most of the script works "just" the colors are not there:
grafik

And the I have even a feature request. Would it be possible to load two images. One for the hight ond one for the color.

@supertobi
Copy link
Author

I replace this code

def color_block_mesh(context, props, colors: List[list]):
    bpy.ops.mesh.vertex_color_add()
    layer = context.object.data.vertex_colors[0].data

    i = 0
    for row in colors:
        for color in row:
            for _ in range(24):  # 6 faces, 4 vertices each
                layer[i].color = color
                i += 1

with this one, what do you think, is that the right solution?

def color_block_mesh(context, props, colors: List[list]):
    # Ensure we are in Object Mode before making changes
    bpy.ops.object.mode_set(mode='OBJECT')

    # Get the active object
    obj = context.object
    
    # Check if the object is a mesh
    if obj and obj.type == 'MESH':
        # Create a new vertex color layer if it doesn't exist
        if not obj.data.vertex_colors.get("Col"):
            obj.data.vertex_colors.new(name="Col")

        # Access the vertex color layer
        layer = obj.data.vertex_colors["Col"].data
        
        i = 0
        for row in colors:
            for color in row:
                for _ in range(24):  # 6 faces, 4 vertices each
                    layer[i].color = color
                    i += 1
    else:
        print("Active object is not a mesh.")

@supertobi
Copy link
Author

I think the same change needs to be done for color_plane_mesh

@supertobi
Copy link
Author

I created a PR to fix this issues. please review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant