cdcseacave / openMVS

open Multi-View Stereo reconstruction library
http://cdcseacave.github.io
GNU Affero General Public License v3.0
3.31k stars 907 forks source link

Question : how to export GLTF/GLB files #1013

Open elMerzoukilzk opened 1 year ago

elMerzoukilzk commented 1 year ago

Is your feature request related to a problem? Please describe. Hi, After installing OpenMVS using vcpkg and following the steps in the tutorial_demo.py script, everything worked well up to Step 9: Texture Mesh.

To texture the mesh, I executed the following code:

Step 9: Texture Mesh

print("# Step 9: Texture Mesh") pTexture = subprocess.Popen([os.path.join(OPENMVS_BIN, "TextureMesh"), os.path.join(reconstruction_dir, "scene_dense_mesh_refine.mvs")]) pTexture.wait()

This generated three files: scene_dense_mesh_refine_texture.mvs, scene_dense_mesh_refine_texture.ply, and scene_dense_mesh_refine_texture.png. Now, I would like to export these files as .gltf or .glb format. I found that the GLTF format is supported from version 2.0 onwards.

If exporting to GLTF is not directly supported by OpenMVS, I would appreciate any suggestions on how to combine the .png texture image and .ply mesh into a single file. Thank you in advance for your assistance."

ghost commented 1 year ago

--export-type <type>, available types are ply, obj, glb and gltf.

print("# Step 9: Texture Mesh")
pTexture = subprocess.Popen([os.path.join(OPENMVS_BIN, "TextureMesh"),
os.path.join(reconstruction_dir, "scene_dense_mesh_refine.mvs"), "--export-type", "<type>"])
pTexture.wait()
elMerzoukilzk commented 1 year ago

Hi @4CJ7T, thank you for your response. I have received the following files: scene_dense_mesh_refine_texture.png, scene_dense_mesh_refine_texture.ply, scene_dense_mesh_refine_texture.mvs, and scene_dense_mesh_refine_texture.gltf. Is it possible to combine the mesh and texture into a single file that contains the complete 3D model, without the need for separate png and mesh files? Thank you.

ghost commented 1 year ago

Not in OpenMVS currently, the glTF type was implemented before glTF2, which added the option of storing textures in the file.

elMerzoukilzk commented 1 year ago

Hi @4CJ7T , thank you for responding. Could you please explain how to embed the texture directly within the GLB file instead of using references? If you have any ideas or Python code (not software) that can achieve this, I would greatly appreciate it. Thanks!

ghost commented 1 year ago
pip install aspose-3d
from argparse import ArgumentParser
from aspose.threed import Scene, FileFormat
from aspose.threed.formats import GltfSaveOptions
import os

parser = ArgumentParser()
parser.add_argument('--input', type=str, required=True, help='path to the input file')
parser.add_argument('--output', type=str, required=True, help='path to the output GLB file')
args = parser.parse_args()

os.chdir(os.path.dirname(args.input))

opt = GltfSaveOptions(FileFormat.GLTF2_BINARY)
opt.embed_assets = True

scn = Scene.from_file(args.input)
scn.save(args.output, opt)
anasel01 commented 1 year ago

Thank you so much @4CJ7T for your response. It worked!