Obj import does not import vertex color information #104621

Closed
opened 2023-05-22 15:44:39 +02:00 by Koen-Van-Bastelaere · 2 comments

If you do an obj import with a script using bpy.ops.import_scene.obj, the vertex color data is not imported.
If you import via the Blender GUI, the color data is imported

If you do an obj import with a script using bpy.ops.import_scene.obj, the vertex color data is not imported. If you import via the Blender GUI, the color data is imported

This report does not contain all the requested information, which is required for us to investigate the issue.

Please submit a new report and carefully follow the instructions. Be sure to provide system information, Blender version, the last Blender version which worked, and a .blend file with exact steps to reproduce the problem.

A guideline for making a good bug report can be found at https://wiki.blender.org/wiki/Process/Bug_Reports

This report does not contain all the requested information, which is required for us to investigate the issue. Please submit a new report and carefully follow the instructions. Be sure to provide system information, Blender version, the last Blender version which worked, and a .blend file with exact steps to reproduce the problem. A guideline for making a good bug report can be found at https://wiki.blender.org/wiki/Process/Bug_Reports
Blender Bot added the
Status
Archived
label 2023-05-22 22:19:30 +02:00

If someone would ever like to add the vertex color information for an obj file:
import_obj.py

471
- def split_mesh(verts_loc, faces, unique_materials, filepath, SPLIT_OB_OR_GROUP):
+ def split_mesh(verts_loc, verts_color, faces, unique_materials, filepath, SPLIT_OB_OR_GROUP):

473
-    Takes vert_loc and faces, and separates into multiple sets of
+    Takes vert_loc, verts_color and faces, and separates into multiple sets of

483
-        return [(verts_loc, faces, unique_materials, filename, use_verts_nor, use_verts_tex)]
+        return [(verts_loc, verts_color, faces, unique_materials, filename, use_verts_nor, use_verts_tex)]

512
-            (verts_split, faces_split, unique_materials_split, vert_remap,
-             use_verts_nor, use_verts_tex) = face_split_dict.setdefault(key, ([], [], {}, {}, [], []))
+            (verts_split, verts_color_split, faces_split, unique_materials_split, vert_remap,
+             use_verts_nor, use_verts_tex) = face_split_dict.setdefault(key, ([], [], [], {}, {}, [], []))

530
+                verts_color_split.append(verts_color[vert_idx])

539
-    return [(verts_split, faces_split, unique_materials_split, key_to_name(key), bool(use_vnor), bool(use_vtex))
-            for key, (verts_split, faces_split, unique_materials_split, _, use_vnor, use_vtex)
+    return [(verts_split, verts_color_split, faces_split, unique_materials_split, key_to_name(key), bool(use_vnor), bool(use_vtex))
+            for key, (verts_split, verts_color_split, faces_split, unique_materials_split, _, use_vnor, use_vtex)

547
+                verts_color,

685
+    if verts_color:
+        color_attr = me.color_attributes.new(name='Col', type='FLOAT_COLOR', domain='POINT')
+        color_layer = color_attr.data
+        for vertex_index, vertex in enumerate(me.vertices):
+            color = verts_color[vertex_index]
+            color_layer[vertex_index].color = (*color, 1.0)

949
+        verts_color = []

1035
+                            if line_start == b'v' and len(line_split) > 4:
+                                verts_color.append(list(map(float_func, line_split[4:7])))
+                            else:
+                                verts_color.append((0.0, 0.0, 0.0))

1244
-        for data in split_mesh(verts_loc, faces, unique_materials, filepath, SPLIT_OB_OR_GROUP):
-            verts_loc_split, faces_split, unique_materials_split, dataname, use_vnor, use_vtex = data
+        for data in split_mesh(verts_loc, verts_color, faces, unique_materials, filepath, SPLIT_OB_OR_GROUP):
+            verts_loc_split, verts_color_split, faces_split, unique_materials_split, dataname, use_vnor, use_vtex = data

1251
+                        verts_color_split,
If someone would ever like to add the vertex color information for an obj file: import_obj.py ``` 471 - def split_mesh(verts_loc, faces, unique_materials, filepath, SPLIT_OB_OR_GROUP): + def split_mesh(verts_loc, verts_color, faces, unique_materials, filepath, SPLIT_OB_OR_GROUP): 473 - Takes vert_loc and faces, and separates into multiple sets of + Takes vert_loc, verts_color and faces, and separates into multiple sets of 483 - return [(verts_loc, faces, unique_materials, filename, use_verts_nor, use_verts_tex)] + return [(verts_loc, verts_color, faces, unique_materials, filename, use_verts_nor, use_verts_tex)] 512 - (verts_split, faces_split, unique_materials_split, vert_remap, - use_verts_nor, use_verts_tex) = face_split_dict.setdefault(key, ([], [], {}, {}, [], [])) + (verts_split, verts_color_split, faces_split, unique_materials_split, vert_remap, + use_verts_nor, use_verts_tex) = face_split_dict.setdefault(key, ([], [], [], {}, {}, [], [])) 530 + verts_color_split.append(verts_color[vert_idx]) 539 - return [(verts_split, faces_split, unique_materials_split, key_to_name(key), bool(use_vnor), bool(use_vtex)) - for key, (verts_split, faces_split, unique_materials_split, _, use_vnor, use_vtex) + return [(verts_split, verts_color_split, faces_split, unique_materials_split, key_to_name(key), bool(use_vnor), bool(use_vtex)) + for key, (verts_split, verts_color_split, faces_split, unique_materials_split, _, use_vnor, use_vtex) 547 + verts_color, 685 + if verts_color: + color_attr = me.color_attributes.new(name='Col', type='FLOAT_COLOR', domain='POINT') + color_layer = color_attr.data + for vertex_index, vertex in enumerate(me.vertices): + color = verts_color[vertex_index] + color_layer[vertex_index].color = (*color, 1.0) 949 + verts_color = [] 1035 + if line_start == b'v' and len(line_split) > 4: + verts_color.append(list(map(float_func, line_split[4:7]))) + else: + verts_color.append((0.0, 0.0, 0.0)) 1244 - for data in split_mesh(verts_loc, faces, unique_materials, filepath, SPLIT_OB_OR_GROUP): - verts_loc_split, faces_split, unique_materials_split, dataname, use_vnor, use_vtex = data + for data in split_mesh(verts_loc, verts_color, faces, unique_materials, filepath, SPLIT_OB_OR_GROUP): + verts_loc_split, verts_color_split, faces_split, unique_materials_split, dataname, use_vnor, use_vtex = data 1251 + verts_color_split, ```
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 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#104621
No description provided.