Web3DConsortium / BlenderX3DSupport

5 stars 3 forks source link

Diffuse Texture not exported to X3D ImageTexture node #2

Open npolys opened 3 years ago

npolys commented 3 years ago

See: https://developer.blender.org/T66534 address in simplest way possible -- Specifically, get the texture URL from Blender PBR nodes, and just use it "naively" for a diffuse texture in Appearance.texture in the X3D output. This Appearance model / node structure is valid in both X3D v3.3 and v4 .

vincentmarchetti commented 3 years ago

There is a Stack Overflow question posed 2 Jul 2021 at https://stackoverflow.com/questions/68230552/blender-to-x3d-texture-material-capability ; in which the poster asks for better documentation of the X3D export capabilities; this question documents the needs of users.

vincentmarchetti commented 2 years ago

Summary: This is an announcement of python scripts which restore the export of ImageTexture nodes in the X3D export of Blender models. This export capabilty was reported missing from the Blender 2.80 and later versions of Blender. The python scripts developed here have undergone preliminary testing for Blender 3.0.0; the latest public release. For those who have been missing this capability from Blender, you are invited to read the detailed description below, install the new python scripts in your Blender installation (at v 3.0 and beyond ); and report bugs to the Web3D Consortium Blender project; more generally whether these scripts meet the needs of your workflows in using image textures with X3D models edited in Blender.

Detailed Description

These X3D import/export scripts may be tested by replacing the Python code for the Blender 3.0 installation with the python scripts from Consortium github project. You will first need to location these scripts in your Blender 3.0 installation. Typical locations are:

Windows: C:\Program Files\Blender Foundation\Blender 3.0\3.0\scripts\addons\io_scene_x3d MacOS : /Applications/Blender.app/Contents/Resources/3.0/scripts/addons/io_scene_x3d Linux: (consult https://docs.blender.org/manual/en/latest/advanced/blender_directory_layout.html )

This folder should contain 3 Python source code files: init.py import_x3d.py export_x3d.py This folder may also contain a pycache folder, which should be deleted if you do replace these scripts.

These files need to be replaced with the corresponding files from the image_texture_export branch of the Web3DConsortium/BlenderX3DSupport github project ( https://github.com/Web3DConsortium/BlenderX3DSupport ). The web-page for viewing this branch and directory is https://github.com/Web3DConsortium/BlenderX3DSupport/tree/image_texture_export/io_scene_x3d from which this source may be copied into the Blender installation.

This implementation exports an X3D TextureImage node when an image is defined in the "Base Color" node of a "Principled BSDF" node [see https://docs.blender.org/manual/en/latest/render/shader_nodes/shader/principled.html ] defined in a Blender material. The name of the image referenced in the Base Color node is assumed to represent the name of the image file (including extension) -- specifically the base name of the file, not including names of enclosing directories. When the ImageTexture node is written to the exported X3D file this name of the image will be one of the entries in the url field of the ImageTexture node. The url field will also contain additional entries based on the filesystem path of the image file in the local computer; these urls will not be portable and may represent a security or privacy danger. Using the basename of the image file as the url supports the deployment of the image texture files in the same directory as the X3D file which uses them.

The specification of the image texture in the node-based Blender material is supported by the X3D import script distributed with Blender 3.0 ; the user should be able to do the 'round trip' workflow X3D File A ---> Blender import--> [Blender application, editing] ---> Blender export --> X3D File B without being concerned with the details of node-based materials.

This export implementation does not write the image file to the local file system as part of the export.

This export implementation does not support exporting a TextureTransform node in the Appearance node.

Potential Tests: If you are interested in participating in evaluating this code, the simplest test case will be an X3D file that uses an image texture, both located in the same directory on your local computer. After replacing the 'factory-installed' scripts as described above, import the X3D file; then export the Blender model into the same folder as the original file (which should also contain the image file). The proof in the pudding will be your ability to load the exported X3D file in an X3D browser and see the rendered texture.

A test may be run using the "Hello World" example from the X3D Archives at web3d.org : https://x3dgraphics.com/examples/X3dForWebAuthors/Chapter01TechnicalOverview/HelloWorldIndex.html

An additional test case, with a larger image texture and more complex geometry, can be downloaded from https://spri-open-resources.s3.us-east-2.amazonaws.com/Morse_Vale_Telegraph_Key_X3D.zip

Useful additional testing would include: -- Examples of X3D files which load multiple image files as textures. -- Examples of X3D files which use the TextureTransform node. -- Examples of files which repeat a texture in either the S or T axis, or both

Please report results of testing, bugs identified, and concrete proposals for changes in behavior to the issues section of the Web3DConsortium github project : https://github.com/Web3DConsortium/BlenderX3DSupport/issues/2

vincentmarchetti commented 2 years ago

In x3d-public email of 31 Jan 2022 Michalis K made these suggestions: -- make use of the "relative path" feature of Blender, see documentation for version 2.79 (may be semi-obsolete) https://docs.blender.org/manual/en/2.79/data_system/files/relative_paths.html . This feature uses filepath delimiter // to represent a relative path

-- Allow user to choose a subdirectory for images, urls in ImageTexture will be referenced to this subdirectory. This is what the glTF exporter does.

coderextreme commented 8 months ago

It will be important to test this feature in the io_scene_x3dv addon

vincentmarchetti commented 1 month ago

Work on this issue will continue with another example derived from a different workflow.

NPolys has submitted an example of a glTF file that contains an image texture, the generating software was QGIS ( https://www.qgis.org ; an open source geographic information system )

The glTF example provided by NPolys is now also available at https://spri-open-resources.s3.us-east-2.amazonaws.com/BlenderImageExport/v3.gltf

It is readily imported into blender 4.1, with an overhead camera added the resulting saved file is at:

https://spri-open-resources.s3.us-east-2.amazonaws.com/BlenderImageExport/overhead_camera_on_v3.blend

Using the Blender Render facilities shows the Image texture on the file.

Blender 4.1 exports the model to X3D , that export can be retrieved at https://spri-open-resources.s3.us-east-2.amazonaws.com/BlenderImageExport/overhead_camera_on_v3.x3d

Exported X3D does not include any image texture nor do the shapes define texture coordinates.

milestones of this further Blender work include

  1. Identifying and exporting the image data from Blender into an external .png file that can be referenced by URL from an X3D ImageTexture node -- see comment by coderextreme at https://github.com/Web3DConsortium/BlenderX3DSupport/issues/6#issue-1971648423 for code to save images
  2. extract the texture coordinates from Blender model and include those in each shape, for the X3D export.
coderextreme commented 1 month ago

Suggestion is to save off the texture file from Blender directly through the GUI, then include as an ImageTexture in appropriate place in X3D (hand edit). Possibly look into how glTF exports image texture. Perhaps other online resources are not as accurate or don’t even work in Python scripts (crashes for an unknown reason).

Note that creating ImageTexture code may add the element in many more places than you actually want. There needs to be more constraints on when an actual element gets created. This may be due to X3D blender import, or exporting textures for curves, surfaces and fonts as well as meshes.

On Thu, Jul 11, 2024 at 7:55 AM Vincent Marchetti @.***> wrote:

Work on this issue will continue with another example derived from a different workflow.

NPolys has submitted an example of a glTF file that contains an image texture, the generating software was QGIS ( https://www.qgis.org ; an open source geographic information system )

The glTF example provided by NPolys is now also available at

https://spri-open-resources.s3.us-east-2.amazonaws.com/BlenderImageExport/v3.gltf

It is readily imported into blender 4.1, with an overhead camera added the resulting saved file is at:

https://spri-open-resources.s3.us-east-2.amazonaws.com/BlenderImageExport/overhead_camera_on_v3.blend

Using the Blender Render facilities shows the Image texture on the file.

Blender 4.1 exports the model to X3D , that export can be retrieved at

https://spri-open-resources.s3.us-east-2.amazonaws.com/BlenderImageExport/overhead_camera_on_v3.x3d

Exported X3D does not include any image texture nor do the shapes define texture coordinates.

milestones of this further Blender work include

  1. Identifying and exporting the image data from Blender into an external .png file that can be referenced by URL from an X3D ImageTexture node -- see comment by coderextreme at #6 (comment) https://github.com/Web3DConsortium/BlenderX3DSupport/issues/6#issue-1971648423 for code to save images
  2. extract the texture coordinates from Blender model and include those in each shape, for the X3D export.

— Reply to this email directly, view it on GitHub https://github.com/Web3DConsortium/BlenderX3DSupport/issues/2#issuecomment-2222869040, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFMJ57IF5L4RA75DU6PX6LZLZ6FVAVCNFSM6AAAAABKW5WNLOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMRSHA3DSMBUGA . You are receiving this because you commented.Message ID: @.***>