Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ FetchContent_Declare(glslang
GIT_REPOSITORY https://github.com/BabylonJS/glslang.git
GIT_TAG 284e4301e5a6b44b279635276588db7cdd942624
EXCLUDE_FROM_ALL)
FetchContent_Declare(draco
GIT_REPOSITORY https://github.com/google/draco.git
GIT_TAG 1.5.7
EXCLUDE_FROM_ALL)
FetchContent_Declare(meshoptimizer
GIT_REPOSITORY https://github.com/zeux/meshoptimizer.git
GIT_TAG v0.22
EXCLUDE_FROM_ALL)
FetchContent_Declare(googletest
URL "https://github.com/google/googletest/archive/refs/tags/v1.17.0.tar.gz"
EXCLUDE_FROM_ALL)
Expand Down Expand Up @@ -117,6 +125,7 @@ option(BABYLON_NATIVE_CHECK_THREAD_AFFINITY "Checks thread safety in the graphic
option(BABYLON_NATIVE_PLUGIN_EXTERNALTEXTURE "Include Babylon Native Plugin ExternalTexture." ON)
option(BABYLON_NATIVE_PLUGIN_NATIVECAMERA "Include Babylon Native Plugin NativeCamera." ON)
option(BABYLON_NATIVE_PLUGIN_NATIVECAPTURE "Include Babylon Native Plugin NativeCapture." ON)
option(BABYLON_NATIVE_PLUGIN_NATIVEDRACO "Include Babylon Native Plugin NativeDraco." ON)
option(BABYLON_NATIVE_PLUGIN_NATIVEENCODING "Include Babylon Native Plugin NativeEncoding." ON)
option(BABYLON_NATIVE_PLUGIN_NATIVEENGINE "Include Babylon Native Plugin NativeEngine." ON)
option(BABYLON_NATIVE_PLUGIN_NATIVEENGINE_WEBP "Enable WebP image parsing in NativeEngine (via bimg)." ON)
Expand All @@ -127,6 +136,7 @@ if(NOT BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES)
endif()
option(BABYLON_NATIVE_PLUGIN_NATIVEENGINE_COMPILESHADERS "Include Babylon Native Plugin NativeEngine - Compile Shaders." ON)
option(BABYLON_NATIVE_PLUGIN_NATIVEINPUT "Include Babylon Native Plugin NativeInput." ON)
option(BABYLON_NATIVE_PLUGIN_NATIVEMESHOPT "Include Babylon Native Plugin NativeMeshopt." ON)
option(BABYLON_NATIVE_PLUGIN_NATIVEOPTIMIZATIONS "Include Babylon Native Plugin NativeOptimizations." ON)
option(BABYLON_NATIVE_PLUGIN_NATIVETRACING "Include Babylon Native Plugin NativeTracing." ON)
option(BABYLON_NATIVE_PLUGIN_NATIVEXR "Include Babylon Native Plugin XR." ON)
Expand Down
53 changes: 53 additions & 0 deletions Dependencies/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,59 @@ if(NOT TARGET glslang)
set_property(TARGET SPIRV PROPERTY FOLDER Dependencies/glslang)
endif()

# --------------------------------------------------
# draco (mesh decompression, native replacement for the WASM decoder)
# --------------------------------------------------
if(BABYLON_NATIVE_PLUGIN_NATIVEDRACO AND NOT TARGET draco AND NOT TARGET draco_static)
set(DRACO_TESTS OFF CACHE BOOL "" FORCE)
set(DRACO_INSTALL OFF CACHE BOOL "" FORCE)
set(DRACO_BUILD_EXECUTABLES OFF CACHE BOOL "" FORCE)
set(DRACO_JS_GLUE OFF CACHE BOOL "" FORCE)

FetchContent_MakeAvailable_With_Message(draco)

# The combined draco library target is named `draco` for MSVC and
# `draco_static` for other toolchains (static build); `draco::draco` aliases
# whichever exists.
if(TARGET draco)
set(_draco_lib draco)
else()
set(_draco_lib draco_static)
endif()

# draco adds its include paths as PRIVATE (see cmake/draco_targets.cmake
# draco_add_library), so linking draco::draco does not expose the draco/*
# headers to consumers. Re-export them as PUBLIC on the combined target.
# The generated draco/draco_features.h is emitted under CMAKE_BINARY_DIR
# (draco uses ${CMAKE_BINARY_DIR} as its generated-sources root).
target_include_directories(${_draco_lib} SYSTEM PUBLIC
"${draco_SOURCE_DIR}"
"${draco_SOURCE_DIR}/src"
"${draco_BINARY_DIR}"
"${CMAKE_BINARY_DIR}")

# Assign IDE folders for whichever draco targets exist.
foreach(_draco_target IN ITEMS draco draco_static)
if(TARGET ${_draco_target})
set_property(TARGET ${_draco_target} PROPERTY FOLDER Dependencies/draco)
endif()
endforeach()
endif()

# --------------------------------------------------
# meshoptimizer (mesh decompression, native replacement for the WASM decoder)
# --------------------------------------------------
if(BABYLON_NATIVE_PLUGIN_NATIVEMESHOPT AND NOT TARGET meshoptimizer)
set(MESHOPT_BUILD_DEMO OFF CACHE BOOL "" FORCE)
set(MESHOPT_BUILD_GLTFPACK OFF CACHE BOOL "" FORCE)
set(MESHOPT_BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
set(MESHOPT_WERROR OFF CACHE BOOL "" FORCE)

FetchContent_MakeAvailable_With_Message(meshoptimizer)

set_property(TARGET meshoptimizer PROPERTY FOLDER Dependencies/meshoptimizer)
endif()

# --------------------------------------------------
# googletest
# --------------------------------------------------
Expand Down
10 changes: 10 additions & 0 deletions Embedding/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ if(BABYLON_NATIVE_PLUGIN_NATIVEENCODING)
target_link_libraries(Embedding PRIVATE NativeEncoding)
endif()

if(BABYLON_NATIVE_PLUGIN_NATIVEDRACO)
target_compile_definitions(Embedding PUBLIC BABYLON_NATIVE_PLUGIN_NATIVEDRACO=1)
target_link_libraries(Embedding PRIVATE NativeDraco)
endif()

if(BABYLON_NATIVE_PLUGIN_NATIVEMESHOPT)
target_compile_definitions(Embedding PUBLIC BABYLON_NATIVE_PLUGIN_NATIVEMESHOPT=1)
target_link_libraries(Embedding PRIVATE NativeMeshopt)
endif()

if(BABYLON_NATIVE_PLUGIN_NATIVEOPTIMIZATIONS)
target_compile_definitions(Embedding PUBLIC BABYLON_NATIVE_PLUGIN_NATIVEOPTIMIZATIONS=1)
target_link_libraries(Embedding PRIVATE NativeOptimizations)
Expand Down
12 changes: 12 additions & 0 deletions Embedding/Source/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
#if BABYLON_NATIVE_PLUGIN_NATIVEENGINE
#include <Babylon/Plugins/NativeEngine.h>
#endif
#if BABYLON_NATIVE_PLUGIN_NATIVEDRACO
#include <Babylon/Plugins/NativeDraco.h>
#endif
#if BABYLON_NATIVE_PLUGIN_NATIVEMESHOPT
#include <Babylon/Plugins/NativeMeshopt.h>
#endif
#if BABYLON_NATIVE_PLUGIN_NATIVECAMERA
#include <Babylon/Plugins/NativeCamera.h>
#endif
Expand Down Expand Up @@ -270,6 +276,12 @@ namespace Babylon::Embedding
#if BABYLON_NATIVE_PLUGIN_NATIVEENGINE
Babylon::Plugins::NativeEngine::Initialize(env);
#endif
#if BABYLON_NATIVE_PLUGIN_NATIVEDRACO
Babylon::Plugins::NativeDraco::Initialize(env);
#endif
#if BABYLON_NATIVE_PLUGIN_NATIVEMESHOPT
Babylon::Plugins::NativeMeshopt::Initialize(env);
#endif
#if BABYLON_NATIVE_PLUGIN_NATIVEOPTIMIZATIONS
Babylon::Plugins::NativeOptimizations::Initialize(env);
#endif
Expand Down
12 changes: 10 additions & 2 deletions Plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,26 @@ if(BABYLON_NATIVE_PLUGIN_NATIVECAPTURE)
add_subdirectory(NativeCapture)
endif()

if(BABYLON_NATIVE_PLUGIN_NATIVEDRACO)
add_subdirectory(NativeDraco)
endif()

if(BABYLON_NATIVE_PLUGIN_NATIVEENCODING)
add_subdirectory(NativeEncoding)
endif()

if(BABYLON_NATIVE_PLUGIN_NATIVEENGINE)
add_subdirectory(NativeEngine)
endif()
endif()

if(BABYLON_NATIVE_PLUGIN_NATIVEINPUT)
if(BABYLON_NATIVE_PLUGIN_NATIVEINPUT)
add_subdirectory(NativeInput)
endif()

if(BABYLON_NATIVE_PLUGIN_NATIVEMESHOPT)
add_subdirectory(NativeMeshopt)
endif()

if(BABYLON_NATIVE_PLUGIN_NATIVEOPTIMIZATIONS)
add_subdirectory(NativeOptimizations)
endif()
Expand Down
17 changes: 17 additions & 0 deletions Plugins/NativeDraco/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
set(SOURCES
"Include/Babylon/Plugins/NativeDraco.h"
"Source/NativeDraco.cpp")

add_library(NativeDraco ${SOURCES})
warnings_as_errors(NativeDraco)

target_include_directories(NativeDraco
PUBLIC "Include")

target_link_libraries(NativeDraco
PUBLIC napi
PRIVATE JsRuntimeInternal
PRIVATE draco::draco)

set_property(TARGET NativeDraco PROPERTY FOLDER Plugins)
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES})
12 changes: 12 additions & 0 deletions Plugins/NativeDraco/Include/Babylon/Plugins/NativeDraco.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <napi/env.h>
#include <Babylon/Api.h>

namespace Babylon::Plugins::NativeDraco
{
// Exposes `_native.decodeDracoMesh(dataView, attributes?)`, a synchronous
// native replacement for Babylon's WebAssembly Draco decoder. Babylon.js
// routes its DracoDecoder to this function when it is present.
void BABYLON_API Initialize(Napi::Env env);
}
Loading