Page MenuHome

Fix T71232: .X3D/.WRL imports without materials and textures
ClosedPublic

Authored by Max Schlecht (Bobbe) on Sep 4 2021, 6:31 PM.

Details

Summary

Fix T71232: .X3D/.WRL imports without materials and textures

When porting the x3d importer to 2.80, material and texture
importing didn't get ported. The old importer was using
Blender Render like materials, the new implementation uses
the standard node system via node_shader_utils.

Additionally this also adds a crude, text based method for
material/texture caching for WRL file (previously only
supported for X3D), fixes a possible StructRNA has been removed
error caused by the cache and assigns proper names to the
materials, if available.

Diff Detail

Event Timeline

Max Schlecht (Bobbe) requested review of this revision.Sep 4 2021, 6:31 PM
Max Schlecht (Bobbe) created this revision.

I decided to create a fix for T71232 because previous efforts, namely D7696, seem to have been abandoned.
In contrast to the aforementioned diff, this implements materials via the shader node system.

The desc based material caching only really works for referenced materials, because stuff like the line number are being used in the nodes __repr__ function. This could be improved by properly parsing and reformatting the node attributes, which would require a lot more effort/code though.

Importing a texture WRL file, also currently causes an AttributeError (in line 2827) atm, because Image doesn't have use_clamp_x and use_clamp_y anymore. This also gets fixed, by moving the mentioned code.

@Robert Guetzkow (rjg) Thanks for mentioning that issue related to texture importing! (I kind of expected something like that to exist, but didn't have time to look yet ^^) This should fix it completely.

Max Schlecht (Bobbe) retitled this revision from Fix T76656: .X3D/.WRL imports without materials and textures to Fix T71232: .X3D/.WRL imports without materials and textures.Sep 4 2021, 9:04 PM
Max Schlecht (Bobbe) edited the summary of this revision. (Show Details)

Add snippet which resets material_cache at the start of load_web3d.
Without this, doing:

  1. Import some .wrl/.x3d file (with a material)
  2. File -> New -> General
  3. Import the same .wrl/.x3d file again

will result in a StructRNA of type Material has been removed error (because references to deleted materials are still present in material_cache).

@Bastien Montagne (mont29) adding you as a reviewer because as far as I can tell, you've been doing the last few bigger fixes related to this file back in 2019.

Bastien Montagne (mont29) requested changes to this revision.Oct 20 2021, 9:27 AM

Thanks for the patch. Fixing such missing feature is much appreciated.

However, we have a generic framework in Blender to 'glue' IO scripts and nodal shaders together (modules/bpy_extras/node_shader_utils.py), used e.g. by OBJ or FBX exporters/importers. It would make much more sense to use that one, rather than writing another 'binding/conversion' code specific to x3d.

This revision now requires changes to proceed.Oct 20 2021, 9:27 AM

Thanks! Didn't know of node_shader_utils yet, that's really useful.

Max Schlecht (Bobbe) edited the summary of this revision. (Show Details)

Updated material creation to use the node_shader_utils module, reworded some comments, removed a supposed "fix" that didn't work.

Max Schlecht (Bobbe) edited the summary of this revision. (Show Details)Oct 24 2021, 7:50 PM

Generally looks fine, besides note below.

io_scene_x3d/import_x3d.py
2738

why not alpha < 1.0 ?

Bastien Montagne (mont29) requested changes to this revision.Oct 25 2021, 3:10 PM
This revision now requires changes to proceed.Oct 25 2021, 3:10 PM
Max Schlecht (Bobbe) marked an inline comment as done.EditedOct 25 2021, 5:54 PM

Generally looks fine, besides note below.

Thanks! Not sure why I did < 0.9999 to be honest, fixed ^^ (edit, actually just realized I took that over from the old code, so thats that)
(Also added shadow_method = "HASHED" to the other place where blend_method already got set before (line 3055)).

Thanks, LGTM, will commit now

This revision is now accepted and ready to land.Oct 27 2021, 12:23 PM

Committed, note that I added update of the addon version.

Hi,
Sorry I am new to this.
I'm using Blender version 2.93.5. Has the change been incorporated into this release yet?

I'm having problems importing materials of WRL file exported from PyMol.

Here attached is the file{F11808720}

Hi,
Sorry I am new to this.
I'm using Blender version 2.93.5. Has the change been incorporated into this release yet?

I'm having problems importing materials of WRL file exported from PyMol.

Here attached is the file{F11808720}

Hey,
no this is a new feature/development, and as such does not fit our requirements for LTS backporting. It will be in Blender 3.0, but not 2.93.

Hi Bastien,
Thanks for letting me know!

I checked on daily builds and found version 3.0.0 (Beta).
Does this incorporate the new feature?

I tried to load my file on Blender 3.0.0 but it still doesn't import correct materials.
The only difference seems to be that it applies a default material for each shape to be imported (spheres and cylinders in my case).

@Gianluca (Giagitom) Yes, current beta builds of 3.0 have that change.

If you have issues with it still, please create a bug report about it.

Sorry, it was a problem with my file that for some reason has the same color applied to all shapes. Tested with an other file and it works nicely!

Thanks again for your help @Bastien Montagne (mont29).