Open3D icon indicating copy to clipboard operation
Open3D copied to clipboard

Textures don't load with .gltf ?

Open nickponline opened this issue 3 years ago • 10 comments

Checklist

Describe the issue

Apparently Open3D has support for textures in .gltf (https://github.com/isl-org/Open3D/issues/1775#issuecomment-720813575) but when I render a 3D model it appears without texture and I see the following warning in the console.

FEngine (64 bits) created at 0x7f88fe000000 (threading is enabled)
FEngine resolved backend: OpenGL
[Open3D WARNING] Read geometry::Image failed: missing file extension.
[Open3D WARNING] Read geometry::Image failed: missing file extension.
[Open3D WARNING] Read geometry::Image failed: missing file extension.
[Open3D WARNING] Read geometry::Image failed: missing file extension.
[Open3D WARNING] Read geometry::Image failed: missing file extension.
[Open3D WARNING] Read geometry::Image failed: missing file extension.
[Open3D WARNING] Read geometry::Image failed: missing file extension.
[Open3D WARNING] Read geometry::Image failed: missing file extension.
[Open3D WARNING] Read geometry::Image failed: missing file extension.
[Open3D WARNING] Read geometry::Image failed: missing file extension.

Steps to reproduce the bug

import cv2
import glob
import numpy as np
import open3d as o3d

render = o3d.visualization.rendering.OffscreenRenderer(width=640, height=640)

# https://www.dropbox.com/s/b4ovqdaxvuwhkyj/house.gltf.zip?dl=0
mesh = o3d.io.read_triangle_mesh(f'house/model.gltf')
material = o3d.visualization.rendering.MaterialRecord() # Create material
render.scene.add_geometry(f'mesh', mesh, material)

cam = o3d.camera.PinholeCameraParameters()
cam.extrinsic = np.asarray([[1,0,0,0],[0,1,0,0],[0,0,1,150],[0,0,0,1]]) # Translate infront of camera by 5 unit
cam.intrinsic = o3d.camera.PinholeCameraIntrinsic(640, 640, 640, 640, 320, 320)
render.setup_camera(cam.intrinsic, cam.extrinsic)

# Render image
image = np.asarray(render.render_to_image())
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR) # Convert Open3D RGB to OpenCV BGR
cv2.imshow('image', image)
cv2.waitKey(0)

Error message

image

Expected behavior

Textured Screen Shot 2022-05-17 at 1 00 17 PM mesh.

Open3D, Python and System information

- Operating system: macOS 10.15
- Python version: Python 3.7.10
- Open3D version: 0.15.2+b48fef1
- System architecture: arm64
- Is this a remote workstation?: no
- How did you install Open3D?: pip
- Compiler version clang 10.0.0

Additional information

No response

nickponline avatar May 16 '22 19:05 nickponline

@germanros1987 I think you might be able to answer this.

nickponline avatar May 16 '22 19:05 nickponline

Could you provide the gltf file that caused the problem as well?

ShreyanshDarshan avatar Jun 16 '22 19:06 ShreyanshDarshan

@ShreyanshDarshan It's in the comment above: https://www.dropbox.com/s/b4ovqdaxvuwhkyj/house.gltf.zip?dl=0

nickponline avatar Jun 16 '22 20:06 nickponline

@ShreyanshDarshan The model is linked above, I notice that headless rendering doesn't seem to work with any GLFT files.

nickponline avatar Jul 09 '22 04:07 nickponline

Have you solved the problem?

lcc157 avatar Sep 05 '22 10:09 lcc157

Nope. Doesn't work.

nickponline avatar Sep 05 '22 16:09 nickponline

@nickponline Since GLTF models are typically complex models we have a different way of loading them. Try modifying the first 3 lines of code of your script to the following:

mesh = o3d.io.read_triangle_model(f'house/model.gltf')
render.scene.add_model(f'mesh', mesh)

With this modification I get the following result... 2022-09-06-235804_640x688_scrot

errissa avatar Sep 07 '22 04:09 errissa

@errissa Can you solve my problem. Thanks! [5505](5505)

lcc157 avatar Sep 07 '22 07:09 lcc157

@errissa Unfortunately I get model now but still no texture:

Output: image

Console output:

FEngine (64 bits) created at 0x7fc4df000000 (threading is enabled)
FEngine resolved backend: OpenGL
[Open3D WARNING] Read geometry::Image failed: missing file extension.
[Open3D WARNING] Read geometry::Image failed: missing file extension.
[Open3D WARNING] Read geometry::Image failed: missing file extension.
[Open3D WARNING] Read geometry::Image failed: missing file extension.
[Open3D WARNING] Read geometry::Image failed: missing file extension.
[Open3D WARNING] Read geometry::Image failed: missing file extension.
[Open3D WARNING] Read geometry::Image failed: missing file extension.
[Open3D WARNING] Read geometry::Image failed: missing file extension.
[Open3D WARNING] Read geometry::Image failed: missing file extension.
[Open3D WARNING] Read geometry::Image failed: missing file extension.

Code:

import cv2
import glob
import numpy as np
import open3d as o3d

render = o3d.visualization.rendering.OffscreenRenderer(width=640, height=640)

# https://www.dropbox.com/s/b4ovqdaxvuwhkyj/house.gltf.zip?dl=0
mesh = o3d.io.read_triangle_model(f'house/model.gltf')
render.scene.add_model(f'mesh', mesh)

cam = o3d.camera.PinholeCameraParameters()
cam.extrinsic = np.asarray([[1,0,0,0],[0,1,0,0],[0,0,1,150],[0,0,0,1]]) # Translate infront of camera by 5 unit
cam.intrinsic = o3d.camera.PinholeCameraIntrinsic(640, 640, 640, 640, 320, 320)
render.setup_camera(cam.intrinsic, cam.extrinsic)

# Render image
image = np.asarray(render.render_to_image())
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR) # Convert Open3D RGB to OpenCV BGR
cv2.imshow('image', image)
cv2.waitKey(0)

Directory structure:

(dev) [nickp@m1 offscreen-render (main ✗)]$ tree
.
├── house
│   ├── model.gltf
│   ├── scene_mesh_textured_material_00_map_Kd.jpg
│   ├── scene_mesh_textured_material_01_map_Kd.jpg
│   ├── scene_mesh_textured_material_02_map_Kd.jpg
│   ├── scene_mesh_textured_material_03_map_Kd.jpg
│   ├── scene_mesh_textured_material_04_map_Kd.jpg
│   ├── scene_mesh_textured_material_05_map_Kd.jpg
│   ├── scene_mesh_textured_material_06_map_Kd.jpg
│   ├── scene_mesh_textured_material_07_map_Kd.jpg
│   ├── scene_mesh_textured_material_08_map_Kd.jpg
│   └── scene_mesh_textured_material_09_map_Kd.jpg
└── main.py

1 directory, 12 files

nickponline avatar Sep 09 '22 16:09 nickponline

@nickponline This GLTF file appears to have the texture embedded directly in the GLTF. We recently added support for GLTF embedded textures so you will need to use the latest development version of Open3D to get this to work as expected. I generated the screenshot with the latest development version.

errissa avatar Sep 10 '22 00:09 errissa