The first uv layer will be overwritten by the second uv layer #104569

Closed
opened 2023-04-25 04:02:34 +02:00 by Mingfen Wang · 5 comments

System Information
Operating system: macOS-13.3.1-arm64-arm-64bit 64 Bits
Graphics card: Apple M1 Apple 4.1 Metal - 83.1

Blender Version
Broken: version: 3.5.0, branch: blender-v3.5-release, commit date: 2023-03-29 02:56, hash: 1be25cfff18b
Worked: (newest version of Blender that worked as expected)

Short description of error
The first uv layer will be overwritten by the second uv layer

Exact steps for others to reproduce the error
This issue only appears in Blender 3.5, Blender 2.93/3.3/3.4/3.6 alpha have no issues.

If I import two uv layers via Python script, the first uv layer will be overwritten by the second uv layer, while the second uv layer has no data at all; if I only import the first uv layer, the first uv layer will be correct, so I can confirm that the first uv layer is overwritten by the second uv layer.

Here is my code:

bm = bmesh.new()
bm.from_mesh(me)
for uv in node['UV']:
uv_name = uv[0]
uv_index = uv[1]
uvs = uv_dic[uv_index]
uv_layer = bm.loops.layers.uv.new(uv_name)
bm.faces.layers.face_map.verify()
for (i, f) in enumerate(bm.faces):
for (j, l) in enumerate(f.loops):
luv = l[uv_layer]
luv.uv = (uvs[i][j][0], uvs[i][j][1])
bm.to_mesh(me)
me.update()
bm.free

Note: node['UV'] is a list of uv name and uv index, uv_dic is a dictionary of the uv values.

**System Information** Operating system: macOS-13.3.1-arm64-arm-64bit 64 Bits Graphics card: Apple M1 Apple 4.1 Metal - 83.1 **Blender Version** Broken: version: 3.5.0, branch: blender-v3.5-release, commit date: 2023-03-29 02:56, hash: 1be25cfff18b Worked: (newest version of Blender that worked as expected) **Short description of error** The first uv layer will be overwritten by the second uv layer **Exact steps for others to reproduce the error** This issue only appears in Blender 3.5, Blender 2.93/3.3/3.4/3.6 alpha have no issues. If I import two uv layers via Python script, the first uv layer will be overwritten by the second uv layer, while the second uv layer has no data at all; if I only import the first uv layer, the first uv layer will be correct, so I can confirm that the first uv layer is overwritten by the second uv layer. Here is my code: bm = bmesh.new() bm.from_mesh(me) for uv in node['UV']: uv_name = uv[0] uv_index = uv[1] uvs = uv_dic[uv_index] uv_layer = bm.loops.layers.uv.new(uv_name) bm.faces.layers.face_map.verify() for (i, f) in enumerate(bm.faces): for (j, l) in enumerate(f.loops): luv = l[uv_layer] luv.uv = (uvs[i][j][0], uvs[i][j][1]) bm.to_mesh(me) me.update() bm.free Note: node['UV'] is a list of uv name and uv index, uv_dic is a dictionary of the uv values.
Mingfen Wang added the
Type
Report
Priority
Normal
Status
Needs Triage
labels 2023-04-25 04:02:35 +02:00
Member
Probably related to: https://projects.blender.org/blender/blender/issues/107500 https://projects.blender.org/blender/blender/issues/107491

Thanks for taking time making the report, but please provide a working script so we can properly replicate the issue.
Also note that you reported this issue in the blender-addons repository but no addons were reported.

Thanks for taking time making the report, but please provide a working script so we can properly replicate the issue. Also note that you reported this issue in the [blender-addons](https://projects.blender.org/blender/blender-addons) repository but no addons were reported.
Germano Cavalcante added
Status
Needs Information from User
and removed
Status
Needs Triage
labels 2023-05-13 00:19:21 +02:00
Author

Sorry I don't have a working script at present, for my add-on is so complicated that I can't make a simple testing script from the source code, I guess that the issue may be caused by this line:

luv = l[uv_layer]

Where luv should be a pointer of the uv layer by uv name, but luv was always wrongly mapped to the first uv layer in Blender 3.5, in other Blender versions(3.3/3.4/3.6 alpha) the mappings are correct.

Sorry I don't have a working script at present, for my add-on is so complicated that I can't make a simple testing script from the source code, I guess that the issue may be caused by this line: luv = l[uv_layer] Where luv should be a pointer of the uv layer by uv name, but luv was always wrongly mapped to the first uv layer in Blender 3.5, in other Blender versions(3.3/3.4/3.6 alpha) the mappings are correct.

OK. I took some time to complete the code myself. But I couldn't replicate the issue described. It worked normally as expected. So I'm going to assume that the problem is somewhere else, probably not a bug in Blender. So closing since this report also has no activity for more than a week.

import bpy
import bmesh
import numpy as np

node = {'UV':[("my_uv1", 0), ("my_uv2", 1)]}
me = bpy.context.object.data

uv1 = np.empty((len(me.polygons) * 4 * 2), dtype=np.float32)
me.uv_layers['UVMap'].uv.foreach_get('vector', uv1)
uv1.shape = (len(me.polygons), 4, 2)
uv2 = uv1.copy()
uv2 *= 2

uv_dic = (uv1, uv2)

bm = bmesh.new()
bm.from_mesh(me)
for uv in node['UV']:
    uv_name = uv[0]
    uv_index = uv[1]
    uvs = uv_dic[uv_index]
    uv_layer = bm.loops.layers.uv.new(uv_name)
    bm.faces.layers.face_map.verify()
    for (i, f) in enumerate(bm.faces):
        for (j, l) in enumerate(f.loops):
            luv = l[uv_layer]
            luv.uv = (uvs[i][j][0], uvs[i][j][1])

bm.to_mesh(me)
me.update()
bm.free
OK. I took some time to complete the code myself. But I couldn't replicate the issue described. It worked normally as expected. So I'm going to assume that the problem is somewhere else, probably not a bug in Blender. So closing since this report also has no activity for more than a week. ```py import bpy import bmesh import numpy as np node = {'UV':[("my_uv1", 0), ("my_uv2", 1)]} me = bpy.context.object.data uv1 = np.empty((len(me.polygons) * 4 * 2), dtype=np.float32) me.uv_layers['UVMap'].uv.foreach_get('vector', uv1) uv1.shape = (len(me.polygons), 4, 2) uv2 = uv1.copy() uv2 *= 2 uv_dic = (uv1, uv2) bm = bmesh.new() bm.from_mesh(me) for uv in node['UV']: uv_name = uv[0] uv_index = uv[1] uvs = uv_dic[uv_index] uv_layer = bm.loops.layers.uv.new(uv_name) bm.faces.layers.face_map.verify() for (i, f) in enumerate(bm.faces): for (j, l) in enumerate(f.loops): luv = l[uv_layer] luv.uv = (uvs[i][j][0], uvs[i][j][1]) bm.to_mesh(me) me.update() bm.free ```
Blender Bot added
Status
Archived
and removed
Status
Needs Information from User
labels 2023-05-22 16:29:48 +02:00
Author

I have just tested the code in Blender 3.5.0, the bug is still there, but after I upgraded to Blender 3.5.1, the bug has gone, so I confirmed that the bug has been fixed in Blender 3.5.1, it works correctly now:)

I have just tested the code in Blender 3.5.0, the bug is still there, but after I upgraded to Blender 3.5.1, the bug has gone, so I confirmed that the bug has been fixed in Blender 3.5.1, it works correctly now:)
Sign in to join this conversation.
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#104569
No description provided.