Exception raised and failure in importing an X3D file with no Material node #95455

Closed
opened 2022-02-02 21:13:59 +01:00 by Vincent Marchetti · 16 comments

System Information
Operating system: MacOS 10.15.7
Graphics card: Intel Iris

Blender Version
Broken: 3.0.1

Addon Information
Name: Web3D X3D/VRML2 format (2, 3, 0)
Author: Campbell Barton, Bart, Bastien Montagne, Seva Alekseyev

Short description of error
Importing an X3D file with a shape that does not have a defined material, import fails and exception trace is printed to console, the exception assertion is:

D:\Dev\BlenderDev\blender\release\scripts\addons\io_scene_x3d\import_x3d.py:1277: DeprecationWarning: 'U' mode is deprecated
  filehandle = open(path, 'rU', encoding='utf-8', errors='surrogateescape')
Python: Traceback (most recent call last):
  File "D:\Dev\BlenderDev\blender\release\scripts\addons\io_scene_x3d\__init__.py", line 78, in execute
    return import_x3d.load(context, **keywords)
  File "D:\Dev\BlenderDev\blender\release\scripts\addons\io_scene_x3d\import_x3d.py", line 3658, in load
    load_web3d(context, filepath,
  File "D:\Dev\BlenderDev\blender\release\scripts\addons\io_scene_x3d\import_x3d.py", line 3557, in load_web3d
    importShape(bpycollection, node, ancestry, global_matrix)
  File "D:\Dev\BlenderDev\blender\release\scripts\addons\io_scene_x3d\import_x3d.py", line 3156, in importShape
    tex_has_alpha) = importShape_LoadAppearance(vrmlname, appr,
  File "D:\Dev\BlenderDev\blender\release\scripts\addons\io_scene_x3d\import_x3d.py", line 2984, in importShape_LoadAppearance
    (bpymat, bpyima, tex_has_alpha) = appearance_Create(vrmlname, material, tex_node, ancestry, node, is_vcol)
  File "D:\Dev\BlenderDev\blender\release\scripts\addons\io_scene_x3d\import_x3d.py", line 2895, in appearance_Create
    bpymat_wrap = appearance_CreateDefaultMaterial()
  File "D:\Dev\BlenderDev\blender\release\scripts\addons\io_scene_x3d\import_x3d.py", line 2764, in appearance_CreateDefaultMaterial
    bpymat_wrap.base_color = (0.8, 0.8, 0.8, 1.0)
  File "D:\Dev/BlenderDev/blender/release/scripts\modules\bpy_extras\node_shader_utils.py", line 36, in wrapper
    return func(self, *args, **kwargs)
  File "D:\Dev/BlenderDev/blender/release/scripts\modules\bpy_extras\node_shader_utils.py", line 277, in base_color_set
    self.material.diffuse_color = color
ValueError: bpy_struct: item.attr = val: sequences of dimension 0 should contain 4 items, not 5

Exact steps for others to reproduce the error

  • import of the attached file through {nav File > Import > X3D Extensible 3D} .
    Exception trace will appear in console
    basic_cube_no_material.x3d

Proposed diagnosis and solution
The exception is occurring in the import_x3d module, https://developer.blender.org/diffusion/BA/browse/master/io_scene_x3d/import_x3d.py
the appearance_CreateDefaultMaterial function; at line 2764 the base color is being set to (0.8,0.8,0.8,1.0), that is, an RGBA color.

In further processing, this value gets passed to utilty rgb_to_rgba in node_shader_utils.py ( https://developer.blender.org/diffusion/BS/browse/master/release/scripts/modules/bpy_extras/node_shader_utils.py )
Another value 1.0 is added t the color - tuple, leading to a invalid value of 5 numeric elements.

Proposed fixes:
In appearance_CreateDefaultMaterial function, initialize base_color to an RGB value (0.8,0.8,0.8)

OR

Modify the rgb_to_rgba utility so that it only appends an default ALPHA value to a tuple of 3 elements.

**System Information** Operating system: MacOS 10.15.7 Graphics card: Intel Iris **Blender Version** Broken: 3.0.1 **Addon Information** Name: Web3D X3D/VRML2 format (2, 3, 0) Author: Campbell Barton, Bart, Bastien Montagne, Seva Alekseyev **Short description of error** Importing an X3D file with a shape that does not have a defined material, import fails and exception trace is printed to console, the exception assertion is: ``` D:\Dev\BlenderDev\blender\release\scripts\addons\io_scene_x3d\import_x3d.py:1277: DeprecationWarning: 'U' mode is deprecated filehandle = open(path, 'rU', encoding='utf-8', errors='surrogateescape') Python: Traceback (most recent call last): File "D:\Dev\BlenderDev\blender\release\scripts\addons\io_scene_x3d\__init__.py", line 78, in execute return import_x3d.load(context, **keywords) File "D:\Dev\BlenderDev\blender\release\scripts\addons\io_scene_x3d\import_x3d.py", line 3658, in load load_web3d(context, filepath, File "D:\Dev\BlenderDev\blender\release\scripts\addons\io_scene_x3d\import_x3d.py", line 3557, in load_web3d importShape(bpycollection, node, ancestry, global_matrix) File "D:\Dev\BlenderDev\blender\release\scripts\addons\io_scene_x3d\import_x3d.py", line 3156, in importShape tex_has_alpha) = importShape_LoadAppearance(vrmlname, appr, File "D:\Dev\BlenderDev\blender\release\scripts\addons\io_scene_x3d\import_x3d.py", line 2984, in importShape_LoadAppearance (bpymat, bpyima, tex_has_alpha) = appearance_Create(vrmlname, material, tex_node, ancestry, node, is_vcol) File "D:\Dev\BlenderDev\blender\release\scripts\addons\io_scene_x3d\import_x3d.py", line 2895, in appearance_Create bpymat_wrap = appearance_CreateDefaultMaterial() File "D:\Dev\BlenderDev\blender\release\scripts\addons\io_scene_x3d\import_x3d.py", line 2764, in appearance_CreateDefaultMaterial bpymat_wrap.base_color = (0.8, 0.8, 0.8, 1.0) File "D:\Dev/BlenderDev/blender/release/scripts\modules\bpy_extras\node_shader_utils.py", line 36, in wrapper return func(self, *args, **kwargs) File "D:\Dev/BlenderDev/blender/release/scripts\modules\bpy_extras\node_shader_utils.py", line 277, in base_color_set self.material.diffuse_color = color ValueError: bpy_struct: item.attr = val: sequences of dimension 0 should contain 4 items, not 5 ``` **Exact steps for others to reproduce the error** - import of the attached file through {nav File > Import > X3D Extensible 3D} . Exception trace will appear in console [basic_cube_no_material.x3d](https://archive.blender.org/developer/F12846083/basic_cube_no_material.x3d) --- **Proposed diagnosis and solution** The exception is occurring in the import_x3d module, https://developer.blender.org/diffusion/BA/browse/master/io_scene_x3d/import_x3d.py the appearance_CreateDefaultMaterial function; at line 2764 the base color is being set to (0.8,0.8,0.8,1.0), that is, an RGBA color. In further processing, this value gets passed to utilty rgb_to_rgba in node_shader_utils.py ( https://developer.blender.org/diffusion/BS/browse/master/release/scripts/modules/bpy_extras/node_shader_utils.py ) Another value 1.0 is added t the color - tuple, leading to a invalid value of 5 numeric elements. Proposed fixes: In appearance_CreateDefaultMaterial function, initialize base_color to an RGB value (0.8,0.8,0.8) OR Modify the rgb_to_rgba utility so that it only appends an default ALPHA value to a tuple of 3 elements.

#95860 was marked as duplicate of this issue

#95860 was marked as duplicate of this issue

Added subscriber: @vmarchetti

Added subscriber: @vmarchetti

Added subscriber: @mano-wii

Added subscriber: @mano-wii

Changed status from 'Needs Triage' to: 'Needs User Info'

Changed status from 'Needs Triage' to: 'Needs User Info'

Start an import of the basic_cube_no_material.x3d file with menu Import > X3D Extensible 3D .

Where do I find this basic_cube_no_material.x3d? Did you forget to upload the file?
You can add it to the bug report by clicking on the upload button as shown in the screenshot below or via drag and drop.
2019_12_04_upload_icon_developer_blender_org.png

> Start an import of the basic_cube_no_material.x3d file with menu Import > X3D Extensible 3D . Where do I find this `basic_cube_no_material.x3d`? Did you forget to upload the file? You can add it to the bug report by clicking on the upload button as shown in the screenshot below or via drag and drop. ![2019_12_04_upload_icon_developer_blender_org.png](https://archive.blender.org/developer/F8190038/2019_12_04_upload_icon_developer_blender_org.png)

basic_cube_no_material.x3d

My apologies for my mistake. I have uploaded the file.

Thank You
Vince Marchetti

[basic_cube_no_material.x3d](https://archive.blender.org/developer/F12846083/basic_cube_no_material.x3d) My apologies for my mistake. I have uploaded the file. Thank You Vince Marchetti

Changed status from 'Needs User Info' to: 'Confirmed'

Changed status from 'Needs User Info' to: 'Confirmed'
Member

Added subscribers: @dscharstein, @PratikPB2123

Added subscribers: @dscharstein, @PratikPB2123
Member

Hi, can you submit a patch for your proposed fix?

Hi, can you submit a patch for your proposed fix?

Hmm, not sure how. Both Germano and I pointed out how to fix the code, isnt' that sufficient for someone to make the change?
Change line 2764 in addons/io_scene_x3d/import_x3d.py to provide only 3 values, not 4:

2764c2764
<     bpymat_wrap.base_color = (0.8, 0.8, 0.8, 1.0)
---
>     bpymat_wrap.base_color = (0.8, 0.8, 0.8)

Hmm, not sure how. Both Germano and I pointed out how to fix the code, isnt' that sufficient for someone to make the change? Change line 2764 in `addons/io_scene_x3d/import_x3d.py` to provide only 3 values, not 4: ``` 2764c2764 < bpymat_wrap.base_color = (0.8, 0.8, 0.8, 1.0) --- > bpymat_wrap.base_color = (0.8, 0.8, 0.8) ```

Added subscriber: @Mark-Blair

Added subscriber: @Mark-Blair

I have confirmed that this change fixes the issue for the bug I submitted as well. https://developer.blender.org/T102384

I have confirmed that this change fixes the issue for the bug I submitted as well. https://developer.blender.org/T102384
Submitted: https://developer.blender.org/D16453

This issue was referenced by 57aafe573a

This issue was referenced by 57aafe573af9fa2019db979e7ade11aec79ca6f9

This issue was referenced by 93f61d1ef7

This issue was referenced by 93f61d1ef75ce341f3789df9c7ea4cc0352a2fe4

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Germano Cavalcante self-assigned this 2022-11-21 12:54:14 +01:00
Sign in to join this conversation.
No Milestone
No project
6 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#95455
No description provided.