Skip to content

Commit

Permalink
Implement KHR_draco_mesh_compression extension
Browse files Browse the repository at this point in the history
  • Loading branch information
pablode committed Nov 9, 2024
1 parent aeec120 commit 13a950e
Show file tree
Hide file tree
Showing 5 changed files with 305 additions and 8 deletions.
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

# Find USD - only non-monolithic builds have been tested.
find_package(pxr CONFIG REQUIRED)

Expand All @@ -14,9 +16,14 @@ find_package(pxr CONFIG REQUIRED)
find_package(MaterialX 1.38.6 REQUIRED HINTS ${pxr_DIR})

# We need to open PNG and JPEG files in order to read the number of channels
# for shading node creation. OIIO should be provided by the USD installation.
# for shading node creation. OIIO can be provided by the USD installation,
# otherwise we fall back to stb_image.
find_package(OpenImageIO HINTS ${pxr_DIR})

# Optionally support draco. See Finddraco.cmake for more information.
set(draco_ROOT ${pxr_DIR})
find_package(draco)

option(GUC_BUILD_EXECUTABLE "Build the guc executable." ON)
option(GUC_BUILD_USDGLTF "Build the Sdf file format plugin." OFF)

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ An example asset conversion is described in the [Structure Mapping](docs/Structu
Name | Status                        
------------------------------------|----------
EXT_meshopt_compression | ✅ Complete
KHR_draco_mesh_compression | ✅ Complete
KHR_lights_punctual | ✅ Partial <sup>1</sup>
KHR_materials_clearcoat | ✅ Complete
KHR_materials_emissive_strength | ✅ Complete
Expand Down
32 changes: 32 additions & 0 deletions cmake/Finddraco.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# Finds draco and populates following variables:
# DRACO_FOUND (draco_FOUND)
# DRACO_INCLUDE_DIR
# DRACO_LIBRARIES
#
# The reason why we ship our custom Find* file is that the draco version
# that USD uses, 1.3.6, has a broken CMake config file.
#
# This also caused trouble for USD, which is why it comes with a custom
# Find* script similar to this one. However, the script has two issues:
# 1) It specifies full file names, causing 'libdraco.1.dylib' to not
# be found on macOS.
# 2) It only finds the main draco lib, but not the decoder-specific
# lib which we need in guc.
#

find_path(DRACO_INCLUDE_DIR NAMES "draco/core/draco_version.h")

find_library(DRACO_LIBRARY NAMES draco PATH_SUFFIXES lib)
find_library(DRACO_DEC_LIBRARY NAMES dracodec PATH_SUFFIXES lib)

set(DRACO_LIBRARIES ${DRACO_LIBRARY} ${DRACO_DEC_LIBRARY})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(draco
REQUIRED_VARS
DRACO_INCLUDE_DIR
DRACO_DEC_LIBRARY
DRACO_LIBRARY
DRACO_LIBRARIES
)
18 changes: 16 additions & 2 deletions src/libguc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ else()
list(APPEND LIBGUC_SHARED_LIBRARIES $<BUILD_INTERFACE:stb_image>)
endif()

if(draco_FOUND)
list(APPEND LIBGUC_DEFINES "GUC_USE_DRACO")
list(APPEND LIBGUC_SHARED_LIBRARIES ${DRACO_LIBRARIES})
endif()

#
# libguc
#
Expand All @@ -75,10 +80,15 @@ add_library(
target_link_libraries(libguc PRIVATE ${LIBGUC_SHARED_LIBRARIES})

target_include_directories(libguc
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PUBLIC $<INSTALL_INTERFACE:include>
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

if(draco_FOUND)
target_include_directories(libguc PRIVATE ${DRACO_INCLUDE_DIRS})
endif()

set_target_properties(
libguc
PROPERTIES
Expand Down Expand Up @@ -156,6 +166,10 @@ if(GUC_BUILD_USDGLTF)

target_include_directories(usdGlTF PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include")

if(draco_FOUND)
target_include_directories(usdGlTF PRIVATE ${DRACO_INCLUDE_DIRS})
endif()

target_compile_definitions(
usdGlTF
PRIVATE
Expand Down
Loading

0 comments on commit 13a950e

Please sign in to comment.