Wavefront obj import does not import vertex colors #104630

Closed
opened 2023-05-23 17:04:16 +02:00 by Koen-Van-Bastelaere · 4 comments

System Information
Operating system: Windows-10-10.0.22621-SP0 64 Bits
Graphics card: NVIDIA GeForce RTX 3080 Ti/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 531.79

Blender Version
Broken: version: 3.5.1, branch: blender-v3.5-release, commit date: 2023-04-24 18:11, hash: e1ccd9d4a1d3
Worked: never worked afaik

Addon Information
Name: Wavefront OBJ format (legacy) (3, 9, 0)
Author: Campbell Barton, Bastien Montagne

Short description of error
No error

Exact steps for others to reproduce the error
Open blender, go to the scripting tab, click on "+ New", type and execute:

import bpy
bpy.ops.import_scene.obj(filepath='<yourpath>\\tomtit.obj')

Go to "Geometry Nodes" tab and click on "Vertex", you will see that there is no color information
If you import the same file with "file" - "Import" - "Wavefront (.obj)" you will see in the "Geometry Nodes" tab that the color information is there.

**System Information** Operating system: Windows-10-10.0.22621-SP0 64 Bits Graphics card: NVIDIA GeForce RTX 3080 Ti/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 531.79 **Blender Version** Broken: version: 3.5.1, branch: blender-v3.5-release, commit date: 2023-04-24 18:11, hash: `e1ccd9d4a1d3` Worked: never worked afaik **Addon Information** Name: Wavefront OBJ format (legacy) (3, 9, 0) Author: Campbell Barton, Bastien Montagne **Short description of error** No error **Exact steps for others to reproduce the error** Open blender, go to the scripting tab, click on "+ New", type and execute: ``` import bpy bpy.ops.import_scene.obj(filepath='<yourpath>\\tomtit.obj') ``` Go to "Geometry Nodes" tab and click on "Vertex", you will see that there is no color information If you import the same file with "file" - "Import" - "Wavefront (.obj)" you will see in the "Geometry Nodes" tab that the color information is there.
4.0 MiB
Koen-Van-Bastelaere added the
Type
Report
Priority
Normal
Status
Needs Triage
labels 2023-05-23 17:04:17 +02:00

Why is the api obj import no wapper around the obj import C code in Blender?
Here is what I changed locally in import_obj.py to make it import the vertex color data:

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,
Why is the api obj import no wapper around the obj import C code in Blender? Here is what I changed locally in import_obj.py to make it import the vertex color data: ``` 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, ```
Member

Hi, have you tried using bpy.ops.wm.obj_import()?

Hi, have you tried using `bpy.ops.wm.obj_import()`?

No error

It appears that this report is a support request and not a bug report.

For help using Blender, please try one of the community websites: https://www.blender.org/community/

I'm closing it as this bug tracker is only for bugs and errors.

For more information on why this isn't considered a bug, visit: https://wiki.blender.org/wiki/Reference/Not_a_bug

> No error It appears that this report is a support request and not a bug report. For help using Blender, please try one of the community websites: https://www.blender.org/community/ I'm closing it as this bug tracker is only for bugs and errors. For more information on why this isn't considered a bug, visit: https://wiki.blender.org/wiki/Reference/Not_a_bug
Blender Bot added
Status
Archived
and removed
Status
Needs Triage
labels 2023-05-23 21:19:23 +02:00

@mano-wii Thanks! Is bpy.ops.import_scene.obj() deprecated? If so, can this information be added in the documentation?

@mano-wii Thanks! Is bpy.ops.import_scene.obj() deprecated? If so, can this information be added in the documentation?
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#104630
No description provided.