kopia lustrzana https://github.com/OpenDroneMap/ODM
Add draco compression
rodzic
53ec818f6d
commit
711a3f463d
|
@ -245,3 +245,14 @@ externalproject_add(lastools
|
|||
SOURCE_DIR ${SB_SOURCE_DIR}/lastools
|
||||
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${SB_INSTALL_DIR}
|
||||
)
|
||||
|
||||
externalproject_add(draco
|
||||
GIT_REPOSITORY https://github.com/google/draco
|
||||
GIT_SHALLOW ON
|
||||
GIT_TAG 1.5.5
|
||||
PREFIX ${SB_BINARY_DIR}/draco
|
||||
SOURCE_DIR ${SB_SOURCE_DIR}/draco
|
||||
CMAKE_ARGS -DDRACO_TRANSCODER_SUPPORTED=ON
|
||||
-DCMAKE_INSTALL_PREFIX:PATH=${SB_INSTALL_DIR}
|
||||
${WIN32_CMAKE_ARGS}
|
||||
)
|
||||
|
|
|
@ -461,6 +461,13 @@ def config(argv=None, parser=None):
|
|||
help=('Generate OBJs that have a single material and a single texture file instead of multiple ones. '
|
||||
'Default: %(default)s'))
|
||||
|
||||
parser.add_argument('--gltf',
|
||||
action=StoreTrue,
|
||||
nargs=0,
|
||||
default=False,
|
||||
help=('Generate single file Binary glTF (GLB) textured models. '
|
||||
'Default: %(default)s'))
|
||||
|
||||
parser.add_argument('--gcp',
|
||||
metavar='<path string>',
|
||||
action=StoreValue,
|
||||
|
|
|
@ -4,6 +4,8 @@ from rasterio.io import MemoryFile
|
|||
import warnings
|
||||
import numpy as np
|
||||
import pygltflib
|
||||
from opendm import system
|
||||
from opendm import io
|
||||
|
||||
warnings.filterwarnings("ignore", category=rasterio.errors.NotGeoreferencedWarning)
|
||||
|
||||
|
@ -108,7 +110,7 @@ def paddedBuffer(buf, boundary):
|
|||
pad = boundary - r
|
||||
return buf + b'\x00' * pad
|
||||
|
||||
def obj2glb(input_obj, output_glb, _info=print):
|
||||
def obj2glb(input_obj, output_glb, rtc=(None, None), draco_compression=True, _info=print):
|
||||
_info("Converting %s --> %s" % (input_obj, output_glb))
|
||||
obj = load_obj(input_obj, _info=_info)
|
||||
|
||||
|
@ -226,9 +228,29 @@ def obj2glb(input_obj, output_glb, _info=print):
|
|||
buffers=[pygltflib.Buffer(byteLength=len(binary))],
|
||||
)
|
||||
|
||||
if rtc != (None, None) and len(rtc) >= 2:
|
||||
gltf.extensionsUsed = ['CESIUM_RTC']
|
||||
gltf.extensions = {
|
||||
'CESIUM_RTC': {
|
||||
'center': [float(rtc[0]), float(rtc[1]), 0.0]
|
||||
}
|
||||
}
|
||||
|
||||
gltf.set_binary_blob(binary)
|
||||
|
||||
_info("Writing...")
|
||||
gltf.save(output_glb)
|
||||
_info("Wrote %s" % output_glb)
|
||||
|
||||
if draco_compression:
|
||||
_info("Compressing with draco")
|
||||
try:
|
||||
compressed_glb = io.related_file_path(output_glb, postfix="_compressed")
|
||||
system.run('draco_transcoder -i "{}" -o "{}" -qt 16 -qp 16'.format(output_glb, compressed_glb))
|
||||
if os.path.isfile(compressed_glb) and os.path.isfile(output_glb):
|
||||
os.remove(output_glb)
|
||||
os.rename(compressed_glb, output_glb)
|
||||
except Exception as e:
|
||||
log.ODM_WARNING("Cannot compress GLB with draco: %s" % str(e))
|
||||
|
||||
|
||||
|
|
|
@ -289,6 +289,7 @@ class ODM_Tree(object):
|
|||
|
||||
# texturing
|
||||
self.odm_textured_model_obj = 'odm_textured_model_geo.obj'
|
||||
self.odm_textured_model_glb = 'odm_textured_model_geo.glb'
|
||||
|
||||
# odm_georeferencing
|
||||
self.odm_georeferencing_coords = os.path.join(
|
||||
|
|
|
@ -8,6 +8,7 @@ from opendm import types
|
|||
from opendm.multispectral import get_primary_band_name
|
||||
from opendm.photo import find_largest_photo_dim
|
||||
from opendm.objpacker import obj_pack
|
||||
from opendm.gltf import obj2glb
|
||||
|
||||
class ODMMvsTexStage(types.ODM_Stage):
|
||||
def process(self, args, outputs):
|
||||
|
@ -129,26 +130,38 @@ class ODMMvsTexStage(types.ODM_Stage):
|
|||
'{nadirMode} '
|
||||
'{labelingFile} '
|
||||
'{maxTextureSize} '.format(**kwargs))
|
||||
|
||||
# Single material?
|
||||
if args.texturing_single_material and r['primary'] and (not r['nadir'] or args.skip_3dmodel):
|
||||
log.ODM_INFO("Packing to single material")
|
||||
|
||||
packed_dir = os.path.join(r['out_dir'], 'packed')
|
||||
if io.dir_exists(packed_dir):
|
||||
log.ODM_INFO("Removing old packed directory {}".format(packed_dir))
|
||||
shutil.rmtree(packed_dir)
|
||||
|
||||
try:
|
||||
obj_pack(os.path.join(r['out_dir'], tree.odm_textured_model_obj), packed_dir, _info=log.ODM_INFO)
|
||||
if r['primary'] and (not r['nadir'] or args.skip_3dmodel):
|
||||
# GlTF?
|
||||
if args.gltf:
|
||||
log.ODM_INFO("Generating glTF Binary")
|
||||
odm_textured_model_glb = os.path.join(r['out_dir'], tree.odm_textured_model_glb)
|
||||
|
||||
try:
|
||||
obj2glb(odm_textured_model_obj, odm_textured_model_glb, rtc=reconstruction.get_proj_offset(), _info=log.ODM_INFO)
|
||||
except Exception as e:
|
||||
log.ODM_WARNING(str(e))
|
||||
|
||||
# Single material?
|
||||
if args.texturing_single_material:
|
||||
log.ODM_INFO("Packing to single material")
|
||||
|
||||
packed_dir = os.path.join(r['out_dir'], 'packed')
|
||||
if io.dir_exists(packed_dir):
|
||||
log.ODM_INFO("Removing old packed directory {}".format(packed_dir))
|
||||
shutil.rmtree(packed_dir)
|
||||
|
||||
# Move packed/* into texturing folder
|
||||
system.delete_files(r['out_dir'], (".vec", ))
|
||||
system.move_files(packed_dir, r['out_dir'])
|
||||
if os.path.isdir(packed_dir):
|
||||
os.rmdir(packed_dir)
|
||||
except Exception as e:
|
||||
log.ODM_WARNING(str(e))
|
||||
try:
|
||||
obj_pack(os.path.join(r['out_dir'], tree.odm_textured_model_obj), packed_dir, _info=log.ODM_INFO)
|
||||
|
||||
# Move packed/* into texturing folder
|
||||
system.delete_files(r['out_dir'], (".vec", ))
|
||||
system.move_files(packed_dir, r['out_dir'])
|
||||
if os.path.isdir(packed_dir):
|
||||
os.rmdir(packed_dir)
|
||||
except Exception as e:
|
||||
log.ODM_WARNING(str(e))
|
||||
|
||||
|
||||
# Backward compatibility: copy odm_textured_model_geo.mtl to odm_textured_model.mtl
|
||||
# for certain older WebODM clients which expect a odm_textured_model.mtl
|
||||
|
|
Ładowanie…
Reference in New Issue